when the control was originally selected as the Display container for the table, it also tried to use the MSHFlexGrid control. After all, the first time the computer room charging system used the control. I don't judge the quality of the control.
MSHFlexGrid this control, similar to the Excel , you need to loop the assignment and then show it. I'm not sure how long it's been running. It always feels like a waste. It then touches a DataGridView control, and although the table is displayed in similar ways, the usage is almost the same.
in the three-tier architecture of the computer room charging system, a lot of data passing the time entity or table. For the delivery of the table, the table is displayed directly through a control. Therefore, the computer room charge system, the use of DataGridView as a table container.
DataGridView as a method of display:
Now that you want to use it as a table, you must have a header, a data source, and so on.
if it is convenient for the diagram, use DataGridView , you can set the data source DataSource to set up to display the data information, so that, when used, slightly add some restrictions, you can do the query.
before knowing the method above, I have considered a problem, as the query shows the table, has been from D layer, and the table is processed and transmitted back to U layer up, in this case, to direct the return of the dataTable as a data source, the same can be achieved. This eliminates issues such as setting up data sources, testing links, and so on.
between the three tiers is the DataTable , the DataTable as a virtual table, after the virtual table is optimized, passed directly to the DataGridView display. If the field in the database is inconsistent with the field being displayed, it is passed as the return value after it is processed by the SQL statement.
in Tangled DataGrid control, List of prime issues. Directly using the SQL statement to optimize, then directly using the DataGrid display.
Next look at a query balance instance implementation process:
U-Layer:
Private Sub Btnquery_click (sender as Object, e as EventArgs) Handles btnquery.click ' Verify that two text boxes are empty Dim MyObject as New Uicommonfunction if Myobject.verifynull (Controls) = False then Exit Sub End if Dim querybll as New BL L.SQLQUERYRECORDBLL Try Dim dtrechargelog as New DataTable dtrechargelog = Querybll.queryrechargelog ( Txtcardno.text) Datagrid.datasource = Dtrechargelog Catch ex as Exception MessageBox.Show (ex. Message.tostring ()) End Try End Sub
A public function is used in the U layer:
' <summary> ' Verify that the text box is empty ' </summary> ' <param name= ' log ' ></param> ' <ret Urns></returns> ' <remarks></remarks> public Function verifynull (log as Windows.Forms.Control . ControlCollection) As Boolean Dim objcon As New Control Dim flag As Boolean = True ' Default all text boxes are not empty ' start Detects whether each control is empty for every objcon in log if TypeOf (Objcon) is a TextBox and objcon.visible = True Then If Objcon.text = "Then MsgBox (objCon.Tag.ToString &" cannot be empty, please enter full ", vbOKOnly," hint ") Objcon.focus () flag = False Return flag End If ElseIf TypeOf (Objcon) is a ComboBox and objcon.visible = True then If objcon.text = "Then MsgBox (objCon.Tag.ToString & "cannot be empty, please enter full", vbOKOnly, "hint") Objcon.focus () Flag = False Return flag End If End If Next objcon Return True End Function
after Call Layer B
"< Summary> ' Get top record ' </summary> ' <param name= ' Cardno ' ></param> ' <returns>& Lt;/returns> ' <remarks></remarks> public Function queryrechargelog (Cardno as String) as DataTable Dim istudent as Idal. Istudent istudent = Factory.DBFactory.CreateStudent Dim irechargelog as Idal. Irechargelog Irechargelog = Factory.DBFactory.CreateRechargeLog Dim dtstudent as New DataTable Dtstud ent = istudent.querystudent (Cardno) ' verifies that the user's card number exists if DtStudent.Rows.Count = 0 Then Throw New excep tion ("card number does not exist") End If Dim dtrechargelog as New DataTable dtrechargelog = Irechargelog.getrechargelog (c Ardno) Return dtrechargelog End Function
after , the processing of the table is optimized for processing using SQL statements:
' <summary> ' for the specified time period, "</summary>" <param name= "Stime" > Start date </param> ' ' <param name= ' etime ' > End date </param> ' <returns></returns> ' <remarks></remarks& Gt Public Function getrechargeindate (stime As String, ETime as String) as DataTable Implements Idal. Irechargelog.getrechargeindate Dim strSQL as String = "Select Identity (int,1,1) as serial number, Cardno as card number, Addcash as recharge amount, Date as, time as, UserId as operator, status as state into #1 from Recharge_info where date between @sTime and @eTime select * From #1 drop table #1 "Dim Sqlparams as SqlParameter () = {New SqlParameter (" @sTime ", stime), New SqlParameter ("@eTime", ETime)} Dim Helper As New SqlHelper Dim dtrechargelog As New DataTable Dtrechargelog = helper. Query (strSQL, CommandType.Text, sqlparams) Return dtrechargelog End Function
Interface and factory, similar to the previous demo, add it yourself.
DataGridView as a tabular control, you can design the template in advance, then display it, or just use it as a container. SQL statements can handle a lot of things that can be directly displayed after background processing.
There are many places for table operations, which can be solved with the knowledge of SQL processing. The View virtual table is a good application.