[IDC Charging System] Abstraction

Source: Internet
Author: User

 

Is it null? In the beginning, I used isnull to judge one by one, but there are indeed many duplicates. We adhere to the principle that we must strive for abstraction while striving for different implementation methods for similar functions. Today is a summary. I hope you will give more valuable comments.

Abstraction is used to achieve better code reuse and facilitate future maintenance. We hope that we can have a deeper understanding of these issues when working on the cooperative edition.

 

Determine whether the user name exists

This can be a separate method or small class.

 

Judge whether it is empty

The following is a reference to Master Gao Xiaoqing's blog.

''' <Summary> ''' determines whether all controls on the form are empty ''' </Summary> ''' <remarks> Boolean </remarks> public class isright Public Function isnull (log as windows. forms. control. controlcollection) as Boolean dim conobject as new control dim flag as Boolean flag = true 'all controls have a value for each conobject in log' internally by default. If typeof (conobject) is textbox then if conobject. text. trim = "" then' tag indicates the msgbox (conobject. tag. tostring + "cannot be blank. Please enter complete", vbokonly, "prompt") conobject. focus () flag = false return flag exit function end if next return flag end function ''' <summary> ''' determines whether it is a number ''' </Summary> ''' <param name = "log"> </param> ''' <returns> </returns> ''' <remarks> Boolean </remarks> Public Function isnumberic (log as windows. forms. control. controlcollection) as Boolean dim conobject as new control dim flag as Boolean flag = true 'all controls have a value for each conobject in log' internally by default. If typeof (conobject) is textbox then if isnumeric (conobject. text) = false then' tag indicates the control msgbox (conobject. tag. tostring ++ "" + "enter a number", vbokonly, "prompt") conobject. focus () Flag = false return flag exit function end if next return flag end Function


 

Such a class can cyclically determine whether all controls are empty or numeric. Of course, after reading the code above, you will understand that we also need to write their own names for each space when designing the space, so as to give accurate prompts.

This class can be directly placed on the u layer.

Let's take a look at its client call.

        Dim MyObject As New IsRight        Dim MyObjectNum As New IsRight        If MyObject.isNull(Controls) = False Then            Exit Sub        End If        If MyObjectNum.IsNumberic(Controls) = False Then            Exit Sub        End If


 

 

Obtain database time

U Layer

Public Class GetTime    Shared Function GetDate() As Date        Dim getDate1 As New BLL.TimeBLL        Return getDate1.GetDate    End Function    Shared Function GetTime() As Date        Dim getTime1 As New BLL.TimeBLL        Return getTime1.GetTime    End FunctionEnd Class

 

Layer B is just a transfer and has no substantive content. Let's look at the code at Layer D. Can you find the key two sentences at a glance?

''' <Summary> ''' get date ''' </Summary> ''' <returns> </returns> ''' <remarks> </remarks> Public Function getdate () as date implements itime. getdate dim SQL as string 'defines the string variable SQL used to store the statements to be executed SQL = "select convert (varchar (100), getdate (), 23) "'Code for Date Acquisition dim primitive type as commandtype = commandtype. text 'commandtype specifies how to interpret the command string dim sqlhelper as new global. sqlhelper. sqlhelper instantiate the object dim dT as new datatable dim sqldate as string dt = sqlhelper. execselectno (SQL, commandtype. text) sqldate = DT. rows (0) (0 ). tostring return sqldate end function ''' <summary> ''' obtain time''' </Summary> ''' <returns> </returns> ''' <remarks> </remarks> Public Function gettime () as date implements itime. gettime dim SQL as string 'defines the string variable SQL used to store the statements to be executed SQL = "select convert (varchar (100), getdate (), 24) "dim primitive type as commandtype = commandtype. text 'commandtype specifies how to interpret the command string dim parameter as sqlparameter () 'sqlparameter to indicate the sqlcommand parameter, or it can be a paraming of parameter ={} dim sqlhelper as new global to the dataset column. sqlhelper. sqlhelper instantiate the object dim dT as new datatable dim sqltime as date dt = sqlhelper. execselectno (SQL, commandtype. text) sqltime = DT. rows (0) (0 ). tostring return sqltime end functionend class



 

 

The data room charging system is a system that we personally give life. Thanks to it, I started to think more about coding. We have a lot of room to think about how to make our code more flexible and robust. We will go farther and farther from codoon. In other words, I hope this article will inspire others. How did you abstract and optimize your IDC? You are welcome to leave your comments.

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.