Vb. NET Edition computer room charge System---Report

Source: Internet
Author: User
Tags date1 rowcount

Report, the report of the table, simply said: The report is to use tables, charts and other formats to dynamically display data, can be expressed as: "report = multiple formats + Dynamic Data." In the absence of computers, people used paper and pens to record data.

For example: Folk often said that the tofu account, is selling tofu every day to sell their own tofu in a book, and then every month to summarize the calculation, in this case, the report data and report format is tightly combined, are in the same book. Data can only have a form of expression that can be understood by almost only the person who is accounting, and this form is difficult to modify.

VB version of the computer room charge system report is used by the third party Grid++report,. NET version of the computer room fee system, the use of the Report Designer, the implementation process is as follows:

Part I: Adding datasets

A, right click Add---New Project;

B. Select the form application and rename;

C, the interface layout is as follows, wherein ReportViewer has a refresh, printing, printing layout and other functions, so it is not necessary to take out alone when a small function realized. PS, here Add a DataGridView control, set to not be visible, she has what magical role nie, ' (*∩_∩*), we can take the amount of the day, the amount of refund, the amount of consumption displayed on this control, for example, take the amount of money, her calculation is the control of all the rows, It is not convenient to add the Sixth column in Line table, namely Consumemoney.

D, right click Add---New Project;

E, reoprting---statements;

Part II: Connecting the database

A. Select a data source

B. Select a database type

C. Select a Database model

d, select the database connection;

E. Save the connection string to the application configuration file;

F, add Connection

G. Select database objects

The third part, the design report;

A, add a table header

B. Select a report

Part IV: Code Implementation section

First, the entity layer;

<span style= "FONT-SIZE:18PX;" >public Class checkdayinfo public rechargecash as Integer ' field public property _rechargecash A            S integer ' Property Get Return rechargecash End get Set (value as Integer) Rechargecash = value End Set End Property public Consumecash as Integer public property _consumecash as Integer get Return consumecash End get Set (value as Integer) Rechargecash = val            UE End Set End Property public Cancelcash As Integer public property _cancelcash As Integer Get Return Cancelcash End Get Set (value as Integer) Cancelcash = value End Set End Property public Allcash As Integer public property _allcash As Integer Get Return allcash E nd Get Set (value as Integer) Allcash = value End Set End Property public Ddate as STring Public Property _date As String get Return ddate End Get Set (value as String) Ddate = value End Set End Propertyend class</span>
Layer D

<span style= "FONT-SIZE:18PX;" >imports System.Data.SqlClientPublic Class Daybilldao public Function queryrechargecash (ByVal date1 as String) as Da Tatable ' in recharge this table query charge amount Dim db As New Entity.dbutil ' Instantiate a new database connection Dim dt As New DataTable ' instantiate D layer A DataTable is an object of this class Using conn as New SqlConnection (db.connstring) Conn.            Open () Dim sql As String Dim cmd As New SqlCommand Dim dataAdapter As New SqlDataAdapter Dim DST as New DataSet sql = "SELECT * from Recharge_info where [email protected]" ' from recharge Info This table finds the recharge amount, depending on the date of the selection cmd = New SqlCommand (SQL, conn) cmd. Parameters.Add (New SqlParameter ("@date", date1)) Dataadapter.selectcommand = cmd DataAdapter.Fill (ds T, "recharge_info") dt = DST. Tables ("Recharge_info") Return DT End Using End Function Public function querycancelcash (ByVal dat E2 as String) as DatatabLe ' Check the refund amount in the card table is the balance Dim db As New Entity.dbutil Dim dt As New DataTable Using Conn as new SqlConnect Ion (DB.CONNSTRING) Conn.            Open () Dim sql As String Dim cmd As New SqlCommand Dim dataAdapter As New SqlDataAdapter Dim DST as New DataSet sql = "SELECT * from Card_info where [email protected]" "Select the refund amount from the card table , according to the date of the relevant judgment cmd = New SqlCommand (SQL, conn) cmd. Parameters.Add (New SqlParameter ("@date", date2)) Dataadapter.selectcommand = cmd DataAdapter.Fill (ds T, "card_info") dt = DST. Tables ("Card_info") Return DT End Using End Function Public function Queryconsumecash (ByVal date3 As String) as DataTable query consumption amount from Line table Dim db As New Entity.dbutil Dim dt As New DataTable Using con N as New SqlConnection (db.connstring) Conn. Open () Dim sql As String Dim cmd As New SqlCommand           Dim dataAdapter As New SqlDataAdapter Dim dst As new DataSet sql = "SELECT * FROM Line_in FO where [email protected] "' Find the consumption amount in the Line table cmd = New SqlCommand (SQL, conn) cmd. Parameters.Add (New SqlParameter ("@date", date3)) Dataadapter.selectcommand = cmd DataAdapter.Fill (ds T, "line_info") dt = DST. Tables ("Line_info") Return DT end Using End Function public Sub Insertdaybill (ByVal checkdayinfo A s entity.checkdayinfo) ' If, I say if ah, if there is no record in the day bill, we need to insert a new record in the daily checkout order, if so, we can update Dim DB as new Entity.dbutil U Sing Conn as New SqlConnection (db.connstring) Conn. Open () Dim sql As String Dim cmd As New SqlCommand sql = "INSERT INTO Checkday_info value S (@rechargeCash, @consumeCash, @cancelCash, @allCash, @date) "cmd = New SqlCommand (SQL, conn) cmd. Parameters.Add (New SqlParameter ("@rechargeCash", Checkdayinfo.recharGecash)) cmd. Parameters.Add (New SqlParameter ("@consumeCash", Checkdayinfo.consumecash)) cmd. Parameters.Add (New SqlParameter ("@cancelCash", Checkdayinfo.cancelcash)) cmd. Parameters.Add (New SqlParameter ("@allCash", Checkdayinfo.allcash)) cmd. Parameters.Add (New SqlParameter ("@date", checkdayinfo.ddate)) cmd. ExecuteNonQuery () End Using End Sub public Sub Updatedaybill (ByVal checkdayinfo as Entity.checkdayinfo) ' Update Day knot The contents of the bill Dim db As New Entity.dbutil Dim dt As New DataTable Using Conn as new SqlConnection (Db.connst RING) Conn. Open () Dim sql As String Dim cmd As New SqlCommand sql = "Update Checkday_inf o Set [email protected],[email protected],[email protected],[email protected] where [email  protected] "cmd = New SqlCommand (SQL, conn) cmd. Parameters.Add (New SqlParameter ("@rechargeCash", checkdayinfo.reChargecash)) cmd. Parameters.Add (New SqlParameter ("@consumeCash", Checkdayinfo.consumecash)) cmd. Parameters.Add (New SqlParameter ("@cancelCash", Checkdayinfo.cancelcash)) cmd. Parameters.Add (New SqlParameter ("@allCash", Checkdayinfo.allcash)) cmd. Parameters.Add (New SqlParameter ("@date", checkdayinfo.ddate)) cmd. ExecuteNonQuery () End Using end Sub public Function querycheckday (ByVal date1 as String) as Entity.checkdayin Fo ' Query the relevant information on the daily checkout list, decide whether we insert a record in the U layer, or update a record Dim db As New Entity.dbutil Dim checkdayinfo As New Entity.c Heckdayinfo Using Conn as New SqlConnection (db.connstring) Conn.  Open () Dim sql As String Dim cmd As SqlCommand Dim reader As SqlDataReader sql = "SELECT * from Checkday_info where [email protected]" cmd = New SqlCommand (SQL, conn) CMD.P Arameters. ADD (New SqlParameter ("date", date1)) reader= cmd. ExecuteReader If (reader. Read ()) Then Checkdayinfo.rechargecash = reader. Getdecimal (reader. GetOrdinal ("Rechargecash")) Checkdayinfo.consumecash = reader. Getdecimal (reader. GetOrdinal ("Consumecash")) Checkdayinfo.cancelcash = reader. Getdecimal (reader. GetOrdinal ("Cancelcash")) Checkdayinfo.allcash = reader. Getdecimal (reader. GetOrdinal ("Allcash")) Checkdayinfo.ddate = reader. GetString (reader.  GetOrdinal ("date")) Else Checkdayinfo = Nothing End If End Using Return Checkdayinfo End FunctionEnd class</span>
B-Layer

<span style= "FONT-SIZE:18PX;" >public Class Daybillmanager public Function queryrechargecash (ByVal date1 as String) as DataTable ' in recharge this table queries the collection Information about the amount to Dim Daybilldao as New DAL. Daybilldao Return Daybilldao.queryrechargecash (date1) End function Public Function Querycancelcash (ByVal date 2 as String) as DataTable queries the refund amount from the card table is the balance Dim Daybilldao as New DAL.  Daybilldao Return Daybilldao.querycancelcash (date2) End function Public Function Queryconsumecash (ByVal date3 As String) as DataTable query the consumption amount from the Line table Dim Daybilldao as New DAL. Daybilldao Return Daybilldao.queryconsumecash (date3) End Function public Sub inserdaybill (ByVal checkdayinfo As Entity.checkdayinfo) ' If there is no information in the day bill, we need to insert a Dim Daybilldao as New DAL. Daybilldao Daybilldao.insertdaybill (checkdayinfo) End Sub Public Sub Updatedaybill (ByVal Checkdayinfo as Enti Ty. Checkdayinfo) ' If there is information in the daily checkout order, we only need to update the Dim Daybilldao as New DAL.   Daybilldao     Daybilldao.updatedaybill (checkdayinfo) End Sub public Function querycheckday (ByVal date1 as String) as Entity.c Heckdayinfo ' Find the relevant information in the daily checkout order, if there is no information, we need to insert a message, if there is, we need to update a message Dim Daybilldao as New DAL. Daybilldao Return daybilldao.querycheckday (date1) End functionend class</span>
U-Layer

<span style= "FONT-SIZE:18PX;" >public Class frmdaybill Private Sub frmdaybill_load (sender as Object, e as EventArgs) Handles MyBase.Load Ca ll write () ' TODO: This line of code loads the data into the table "Dataset1.checkday_info".        You can move or delete it as needed.        Me.CheckDay_infoTableAdapter.Fill (Me.DataSet1.CheckDay_info, CStr (Format (Dtpdate.value, "YYYY-MM-DD"))) Me.ReportViewer1.RefreshReport () End Sub Public Sub write () ' Here, add a DataGridView to display the relevant information in DataGridView, when displayed in the report Wait, we just need to add a loop to the Dim Daybill as New BLL.         Daybillmanager Dim dt1 as New DataTable dt1 = Daybill.queryrechargecash (Format (Dtpdate.value, "YYYY-MM-DD")) DGV. AutoGenerateColumns = True DGV. DataSource = Dt1 Dim i As Integer ' defines the variable Dim rechargecash As Decimal for i = 0 to DGV. The amount of RowCount-1 ' recharge equals the sum of the columns in all rows of Datagirdview, where the column is the second column in Recharge_info (Rechargeamount) (the day's Oh) Rechargecash = Rechargecash + DGV. Rows (i). Cells (2). Value Next I Dim CancelcaSH as Decimal dt1 = Daybill.querycancelcash (Format (Dtpdate.value, "Yyyy-mm-dd")) DGV. DataSource = dt1 for i = 0 to DGV. RowCount-1 ' The amount returned is equal to the sum of the columns in all rows of Datagirdview, where the column is the second column in Card_info balance, which is the return amount Cancelcash = Cancelcash + DGV.R OWS (i). Cells (2). Value Next i Dim consumecash as Decimal dt1 = Daybill.queryconsumecash (Format (Dtpdate.value, "yyyy-mm -dd ")) DGV. DataSource = dt1 for i = 0 to DGV. RowCount-1 ' consumption equals the sum of the columns in all rows in DataGridView, where the column is the sixth column in Line_info Consumemoney, which is the consumption amount Consumecash = Consumeca SH + DGV. Rows (i). Cells (6). Value Next i Dim allcash as Decimal allcash = Rechargecash-cancelcash ' Total amount, equal to recharge amount minus refund amount D Im Encheck as new entity.checkdayinfo ' encapsulated entity Dim enCheck1 as new Entity.checkdayinfo Encheck1.rechargeca SH = rechargecash Encheck1.cancelcash = Cancelcash Encheck1.consumecash = Consumecash Encheck1.allcas H = Allcash EnCheck1.  Ddate = CSTR (Format (dtpdate.value, "Yyyy-mm-dd")) Encheck = daybill.querycheckday (Format (dtpdate.value, "yyyy-mm-dd ")) ' If there is no record in Encheck, we will insert a bar, otherwise update if (Encheck is nothing) then Daybill.inserdaybill (ENCHECK1) El Se daybill.updatedaybill (enCheck1) End If End Sub Private Sub dtpdate_valuechanged (sender as Objec T, e as EventArgs) Handles dtpdate.valuechanged ' Invoke Form Load event call Frmdaybill_load (sender, E) End subend class&lt ;/span>
final running result;

After the advent of computers, we use computers to process data and interface design functions to generate and display reports. The main feature of the report on the computer is that the data is dynamic, the format is diversified, and the report data and the report format are completely separated, the user can modify the data only, or only modify the format. Report classification Excel, Word editing software: they can make a very complex report format, but because they do not define a specific report structure to dynamically load the report data, all such software data are already defined, static, can not be changed dynamically. They have no way to realize the "data dynamic" feature of the report software. Since then, the function of the day end, the computer room charge system is not finished, to be continued ...

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.