Data center billing system for VB. NET --- Report

Source: Internet
Author: User
Tags date1

Data center billing system for VB. NET --- Report

A report is a report form. Simply put, a report dynamically displays data in tables, charts, and other formats. It can be expressed: "Report = diverse formats + Dynamic Data ". Before computers do, people use paper and pen to record data.

For example, the bean curd account that people often say is to record the bean curd that they sell in a notebook every day, and then calculate it every month. In this case, the report data and report format are closely integrated in the same notebook. Data can only have a form that can be understood by almost only accounting personnel, and this form is difficult to modify.

The Report of the data center billing system for VB uses the third-party Grid ++ Report and the. NET data center charging system. The Report designer is used to implement the following process:

Part 1: Add a dataset

A. Right-click Add-create a project;

B. Select the form application and rename it;

C. The interface layout is as follows. ReportViewer comes with functions such as refresh, print, and print layout, so you don't have to use it as a small function. Ps, add a DataGridView control here and set it to invisible. What's the magical effect of nie, '(* blank _ blank *)', we can charge the amount on the day, refund amount. The consumption amount is displayed on this control. For example, for the consumption amount, her calculation result is all the rows of the control. In addition, the sixth column in the line table is the sum of the consumeMoney, is it very convenient.

D. Right-click Add --- create a project;

E. Reoprting --- Report;

Part 2: connect to the database

A. Select a data source

B. Select a database type.

C. Select a database model

D. Select database connection;

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

F. Add a connection

G. Select database objects.

Part 3: Design reports;

A. Add a header

B. Select a report

Part 4: code implementation

First, the entity layer;

<Span style = "font-size: 18px; "> Public Class CheckDayinfo Public rechargeCash As Integer" field Public Property _ rechargeCash As Integer "attribute 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 = value 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 End 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 able query the amount charged in the recharge table Dim db As New Entity. dbutil 'instantiate a New database connection Dim dt As New able able' instantiate an object of the D-layer DataTable 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 date = @ date" 'find the recharge amount from the rechargeinfo table, select cmd = New SqlCommand (SQL, conn) cmd Based on the date. parameters. add (New SqlParameter ("@ date", date1) dataAdapter. selectCommand = cmd dataAdapter. fill (dst, "Recharge_info") dt = dst. tables ("Recharge_info") Return dt End Using End Function Public Function queryCancelCash (ByVal date2 As String) As able 'query the refund amount in the card table, that is, the balance Dim db As New Entity. dbutil Dim dt As New DataTable 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 card_info where returnDate = @ date" 'select the refund amount from the card table, judge cmd = New SqlCommand (SQL, conn) cmd Based on the date. parameters. add (New SqlParameter ("@ date", date2) dataAdapter. selectCommand = cmd dataAdapter. fill (dst, "card_info") dt = dst. tables ("card_info") Return dt End Using End Function Public Function queryConsumeCash (ByVal date3 As String) As DataTable 'query the consumption amount in the line table Dim db As New Entity. dbutil Dim dt As New DataTable 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 line_info where offdate = @ date" 'query the consumption amount in the line table cmd = New SqlCommand (SQL, conn) cmd. parameters. add (New SqlParameter ("@ date", date3) dataAdapter. selectCommand = cmd dataAdapter. fill (dst, "line_info") dt = dst. tables ("line_info") Return dt End Using End Function Public Sub insertDayBill (ByVal checkDayinfo As Entity. checkDayinfo) 'If, I mean, if there is no record in the daily statement, we need to insert a new record in the daily statement. If yes, we can update Dim db As New Entity. dbutil Using conn As New SqlConnection (db. connstring) conn. open () Dim SQL As String Dim cmd As New SqlCommand SQL = "insert into CheckDay_info values (@ 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 the contents of the Daily Statement Dim db As New Entity. dbutil Dim dt As New DataTable Using conn As New SqlConnection (db. connstring) conn. open () Dim SQL As String Dim cmd As New SqlCommand SQL = "update CheckDay_info set rechargeCash = @ rechargeCash, consumeCash = @ consumeCash, cancelCash = @ cancelCash, allCash = @ allCash where date = @ 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 Function queryCheckDay (ByVal date1 As String) As Entity. checkdayinfo' queries the information in the Daily Statement and determines whether to insert a record at the U layer or update a record Dim db As New Entity. dbutil Dim CheckDayinfo As New Entity. checkDayinfo 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 date = @ date" cmd = New SqlCommand (SQL, conn) cmd. parameters. 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>
Layer B

<Span style = "font-size: 18px;"> Public Class DayBillManager Public Function queryRechargeCash (ByVal date1 As String) as able 'query the collected amount in the recharge table Dim DayBillDAO As New DAL. dayBillDAO Return DayBillDAO. queryRechargeCash (date1) End Function Public Function queryCancelCash (ByVal date2 As String) As able 'query the refund amount from the card table, that 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 Dim DayBillDAO As New DAL from the line table. dayBillDAO Return DayBillDAO. queryConsumeCash (date3) End Function Public Sub inserDayBill (ByVal checkDayinfo As Entity. checkDayinfo) 'if there is no information in the daily statement, we need to insert a Dim DayBillDAO As New DAL. dayBillDAO. insertDayBill (checkDayinfo) End Sub Public Sub updateDayBill (ByVal checkDayinfo As Entity. checkDayinfo) 'if there is information in the daily statement, we only need to update Dim DayBillDAO As New DAL. dayBillDAO. updateDayBill (checkDayinfo) End Sub Public Function queryCheckDay (ByVal date1 As String) As Entity. checkDayinfo 'query the information in the daily statement. If there is no information, we need to insert a message. If yes, we need to update the information 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 Call write () 'todo: This line of code loads 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, a dview is added to display the relevant information in the DataGridView, we only need to use a loop to add 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 Dim rechargeCash As Decimal For I = 0 To dgv. rowCount-1 'Recharge amount is equal to the sum of columns in all rows of irdview dview. The column here is recharge_info's second column (rechargeAmount) (today'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 'Refund amount is equal to the sum of columns in all rows of irdview dview. Here, the column is the second column of balance in card_info, that is, the refund amount is cancelCash = cancelCash + dgv. rows (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 amount is equal to the sum of columns in all rows in the dview. The column here is the sixth column consumeMoney in line_info, that is, the consumption amount consumeCash = consumeCash + dgv. rows (I ). cells (6 ). value Next I Dim allCash As Decimal allCash = rechargeCash-cancelCash 'total amount, equal to the recharge amount minus the refunded amount Dim enCheck As New Entity. checkDayinfo 'encapsulate Entity Dim enCheck1 As New Entity. checkDayinfo enCheck1.rechargeCash = rechargeCash enCheck1.cancelCash = cancelCash enCheck1.consumeCash = consumeCash enCheck1.allCash = allCash enCheck1.Ddate = CStr (Format (dtpDate. value, "yyyy-MM-dd") enCheck = daybill. queryCheckDay (Format (dtpDate. value, "yyyy-MM-dd") 'If no record exists in enCheck, we insert one. Otherwise, If (enCheck Is Nothing) Then daybill Is updated. inserDayBill (enCheck1) Else daybill. updateDayBill (enCheck1) End If End Sub Private Sub dtpDate_ValueChanged (sender As Object, e As EventArgs) Handles dtpDate. valueChanged 'Call the form loading event Call frmDayBill_Load (sender, e) End SubEnd Class </span>
Final running result;

After the computer appears, we use the computer's data processing and interface design functions to generate and display reports. A report on a computer is characterized by dynamic data and diversified formats. In addition, the report data is completely separated from the report format. You can modify only the data or only the format. Report classification EXCEL, WORD, and other editing software: they can make very complex report formats, but since they do not have a dedicated report structure to dynamically load report data, data in all such software is defined, static, and cannot be changed dynamically. They cannot achieve the "Data Dynamic" feature of the report software. Since then, the day-end functions have come to an end, and the data room charging system is not complete. 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.