Query means to find, find, refers to a certain or a few places to find their own information, if I want to search my own blog, called the first snow love, I in the search box Baidu input Ding Three words, there will be how the surprise waiting for me?
Ah oh, this information is not what I want, so I search again, "Ding Langfang Normal University Csdn" results such as the following:
Obviously, this is not the result I want, I went on to search, "Ding Langfang Normal University csdn snow Love";
In my understanding, the combination of query is through the condition layer limit, step by step accurate, get the answer we want, in the computer room charge system, there are several combinations of query, next, students basic information maintenance as an example, commentary combination query. In the second room charge system, I did not according to the original Hu Yang version of the template, the original through the card number, student number, name, gender, department, grade, class number seven fields, to query, the operator is equal to, greater than, less than, not equal to, but, in real life which has sex more than what, name less than what conditions So I once again designed a window, from which four field names are selected as a combination of query conditions to simplify the combination of query difficulty, the main interface design such as the following:
Next, take a look at our detailed implementation process, first the entity layer---e layer;
<span style= "FONT-SIZE:18PX;" >public Class studentinfo public studentno as String ' field public property _studentno as Strin G ' Property Get Return studentno End get Set (value as String) Studentno = Value End Set End Property public Cardno As String public property _cardno As String Get Return Cardno End Get Set (value as String) Cardno = value End Set End Property publ IC Studentname As String public property _studentname As String get Return studentname End get Set (value As String) Studentname = value End Set End Property public sex as String publ IC Property _sex As String get Return sex End Get Set (value as String) Sex = VA Lue End Set End Property Public department as String public property _department Get Return Department End Get Set (value) department = Value End Set End Property Pu Blic Grade as String public property _grade get Return grade End Get Set (value) Grade = value End Set End Property public Stuclass as String public property _stuclass Get Return Stuclass End Get Set (value) Stuclass = value End Set End Property publ IC Remark as String public property _remark get Return remark End Get Set (value) Remark = value End Set End Property public Handler as String public property _handler Get Return Handler End Get Set (value) Handler = value End Set End Propertyend class& Lt;/span>
data Access Layer---d layer
<span style= "FONT-SIZE:18PX;" >imports System.Data.SqlClientPublic Class Stubainforpreservedao public Function query (ByVal cmbOperator1 as String, ByVal Cardno As String, ByVal CmbOperator2 as String, ByVal Studentno as String, ByVal CmbOperator3 as String, ByVal Depa Rtment As String, ByVal CmbOperator4 as String, ByVal grade as String) as DataTable Dim db as New Entity.dbutil ' instance Database connection Dim DT as new DataTable ' instantiation of DataTable Using Conn as New SqlConnection (db.connstring) Conn. Open () ' Opens database connection Dim sql As String Dim cmd As SqlCommand Dim dataadp ter as New SqlDataAdapter Dim dst As New DataSet Dim flag (3) as Boolean ' define label sql = "Select Studentno,cardno,studentname,sex,department,grade,class,remark,handler from Student_info where" If Not (Cardno = "") Then ' false multiplication number is not empty, run the following SQL statement sql = SQL& "Studentno" & CmbOperator1 & "'" & Cardno & "'" flag (0) = True End If If not (Studentno = "") Then ' assuming the study number is not empty, and the card number is not empty, run the first SQL statement, assuming that the study number is not empty, the card number is empty run the second SQL statement flag (1) = True If flag (0) = True then sql = SQL & "and Studentno" & CmbOperator2 & "'" & Studentno & "'" Else sql = SQL & "Studentno" & CmbOperator2 & "'" & Studentno & ' "End If End if if not (department =" ") Then ' assume that the system is not empty, and that the number and the card number have a Select, or two to run the first SQL statement, otherwise run the second SQL statement flag (2) = True If Flag (0) = True Or flag (1) = True Then sql = SQL & "and Department" & CmbOperator3 & "'" & Department & "'" Else sql = SQL & "department" & CmbOperator3 & "'" & Department & "'" End If EndIf if not (Grade = "") Then ' assumes the grade is not empty, and the number, card number, the system has one is selected, or one or two is selected to run the first SQL statement, otherwise run the second sentence flag (3) = True If Flag (0) = TRUE or flag (1) = TRUE or flag (2) = true Then sql = SQL & "and Grade "& CmbOperator4 &" "& Grade &" ' "Else sql = SQL &" Grade "& Amp CmbOperator4 & "'" & Grade & "'" End If End If cmd = New SqlCommand (SQL, conn) Dataadpter.selectcommand = cmd Dataadpter.fill (DST, "student_info") dt = DST. Tables ("Student_info") end Using Return DT End FunctionEnd class</span>
business Logic Layer---b layer;
<span style= "FONT-SIZE:18PX;" >public Class stubainforpreservemanager Public Function query (ByVal cmbOperator1 As String, ByVal Cardno as String , ByVal CmbOperator2 As String, ByVal Studentno as String, ByVal CmbOperator3 As String, ByVal department as String, ByVal CmbOperator4 As String, ByVal grade as String) as DataTable Dim Stubainforpreservedao as New DAL. Stubainforpreservedao ' call D-layer Return stubainforpreservedao.query (CmbOperator1, Cardno, CmbOperator2, Studentno, CmbOperator3, department, CmbOperator4, Grade) End functionend class</span>
Display Layer---u layer;
<span style= "FONT-SIZE:18PX;" >imports bllpublic Class frmstubainforpreserve Private Sub btninquery_click (sender as Object, e as EventArgs) Handle S Btninquery.click Dim Stubainforpreservemanager as New BLL. Stubainforpreservemanager ' calls the B-layer Dim dt as New DataTable dt = Stubainforpreservemanager.query (cmboperator1.t Ext, Txtcardno.text, Cmboperator2.text, Txtstuno.text, Cmboperator3.text, Txtdepartment.text, CmbOperator4.Text, Txtgrade.text) Datagridview1.autogeneratecolumns = True ' Create the column yourself Datagridview1.datasource = DT Datag Ridview1.columns (0). HeaderText = "study number" shows the relevant information in DataGridView Datagridview1.columns (1). HeaderText = "card number" Datagridview1.columns (2). HeaderText = "Name" Datagridview1.columns (3). HeaderText = "Gender" Datagridview1.columns (4). HeaderText = "department" datagridview1.columns (5). HeaderText = "Grade" Datagridview1.columns (6). HeaderText = "Class" Datagridview1.columns (7). HeaderText = "Remarks" End Sub Private Sub frmstubainforpreserve_load (sender as Object, e as EventArgs) Handles MyBase.Load Cmboperat Or1. Enabled = False ' window loading, need to pay attention to some of the details of the problem, for example, those buttons can point, those cannot point txtcardno.text = "" txtcardno.enabled = Fa LSE CMBOPERATOR1.ITEMS.ADD ("=") CmbOperator1.Items.Add (">") cmbOperator1.Items.Add ("<") CMBOPERATOR1.ITEMS.ADD ("<>") cmboperator1.selectedindex = 0 cmboperator2.enabled = False txtstu No.text = "" txtstuno.enabled = False cmbOperator2.Items.Add ("=") CmbOperator2.Items.Add (">") CMBOPERATOR2.ITEMS.ADD ("<") CmbOperator2.Items.Add ("<>") Cmboperator2.selectedindex = 0 C Mboperator3.enabled = False Txtdepartment.text = "" txtdepartment.enabled = False cmboperator3.items. ADD ("=") cmbOperator3.Items.Add ("<>") cmboperator3.selectedindex = 0 cmboperator4.enabled = Fal Se txtgrade.text = "" txtgrade.enabled = False cmbOperator4.Items.Add ("=") cmbOperator4.Items.Add ("<>") Cmboperator4.selectedindex = 0 End Sub Private Sub Btnexit_click (sender as Object, e as EventArgs) Handles Btnexi T.click ' exit button Me.close () End Sub Private Sub Chkcardno_click (sender as Object, e as EventArgs) Han DLEs Chkcardno.click ' False multiplication is selected, then Txtcardno and CmbOperator1 can point no to the point, and the contents of the text box itself, restore the default value If chkcardno.checked then Txtcardno.enabled = True cmboperator1.enabled = True Else txtcardno.enabled = False cmboperator1.enabled = False Txtcardno.text = "" Cmboperator1.selectedindex = 0 End I F End Sub Private Sub Chkstuno_click (sender as Object, e as EventArgs) Handles Chkstuno.click If Chkstuno.che Cked then txtstuno.enabled = True cmboperator2.enabled = True Else txtstuno.enable D = False CMBoperator2.enabled = False Txtstuno.text = "" Cmboperator2.selectedindex = 0 End If End Sub Private Sub Chkdepartment_click (sender as Object, e as EventArgs) Handles Chkdepartment.click If Chkdepartme Nt. Checked then txtdepartment.enabled = True cmboperator3.enabled = True Else Txtdepa Rtment. Enabled = False cmboperator3.enabled = False Txtdepartment.text = "" Cmboperator3.selecte Dindex = 0 End If End Sub Private Sub Chkgrade_click (sender as Object, e as EventArgs) Handles Chkgrade.click If chkgrade.checked Then txtgrade.enabled = True cmboperator4.enabled = True Else Txtgrade.enabled = False cmboperator4.enabled = False Txtgrade.text = "" Cmbopera Tor4. SelectedIndex = 0 End If End subend class</span>
Performance effects such as the following:
Since this student basic information maintenance on the temporary, start knocking students basic information maintenance, do not know where to start, all kinds of entanglements, all kinds of escape, all kinds of don't want to knock, but, I have grown up, I can no longer by my own temperament to do things, I have to do for my own responsibility, walked past, Is it really that difficult? I think the taste of the only people who have passed through can be really clear.
Previously saw Miss Rice to a blog post such comments, the main content of this blog, I do not know, as if to solve a problem, and then successfully solve a blog post, rice Teacher said, this process is not very dependent, to, this process is not only dependant, and exercise people, test us face the new knowledge of the mentality, is a drag and drag, This goal red and red, or frankly face, two days to three combination of query one by one, computer room charge system is not finished, to be continued ...
Vb. NET edition room charge system---combination query