报表。即报告情况的表格,简单的说:报表就是用表格、图表等格式来动态显示数据。能够用公式表示为:“报表 = 多样的格式 + 动态的数据”。 在没有计算机曾经。人们利用纸和笔来记录数据。
比方:民间经常说的豆腐帐,就是卖豆腐的每天将自己的卖出的豆腐记在一个本子上,然后每月都要汇总算算。这样的情况下。报表数据和报表格式是紧密结合在一起的,都在同一个本子上。数据也仅仅能有一种差点儿仅仅有记帐的人才干理解的表现形式,且这样的形式难于改动。
VB版机房收费系统的报表採用的是第三方的Grid++Report,.NET版机房收费系统。採用了自带的报表设计器,实现步骤例如以下:第一部分:加入数据集
a、右击加入---新建项目;
b、选择窗口应用程序and重命名;
c、界面布局例如以下,当中ReportViewer自带具有刷新、打印、打印布局等功能,所以就不用再独自拿出来当一个小功能实现了。ps,这里加入一个DataGridView控件,设置为不可见,她有什么奇妙的作用nie,`(*∩_∩*)′ ,我们能够把当天收取金额,退还金额,消费金额显示在这个控件上,例如拿消费金额来说,她的计算结果就是该控件全部的行,加上line表中第六列即consumeMoney相加,是不是非常方便。
d、右击加入---新建项目。
e、Reoprting---报表;
第二部分:连接数据库
a、选择数据源
b、选择数据库类型
c、选择数据库模型
d、选择数据库连接。
e、将连接字符串保存到应用程序配置文件里。
f、加入连接
g、选择数据库对象
第三部分。设计报表;
a、加入表头
b、选择报表
第四部分:代码实现部分
首先。实体层;
<span style="font-size:18px;">Public Class CheckDayinfo Public rechargeCash As Integer '字段 Public Property _rechargeCash As Integer '属性 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 Property End Class</span>D层
<span style="font-size:18px;">Imports System.Data.SqlClient Public Class DayBillDAO Public Function queryRechargeCash(ByVal date1 As String) As DataTable '在recharge这张表中查询收取金额 Dim db As New Entity.Dbutil '实例化一个新的数据库连接 Dim dt As New DataTable '实例化D层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 Recharge_info where date=@date" '从rechargeinfo这张表中查找充值金额,依据日期进行相关选择 cmd = New SqlCommand(sql, conn) cmd.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 DataTable '在卡表中查询退还金额也就是剩余金额 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 " '从卡表中选择退还金额。依据日期进行相关推断 cmd = New SqlCommand(sql, conn) cmd.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 '从line表中查询消费金额 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 " '从line表中查找消费金额 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) '假设,我说的是假设啊。假设日结账单里面没有记录,我们须要在日结账单里面插入一条新的记录,假设有,我们更新就可以 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) '更新日结账单里面的内容 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 '查询日结账单中的相关信息,决定我们在U层的时候究竟是插入一条记录呢,还是更新一条记录 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 Function End Class </span>B层
<span style="font-size:18px;">Public Class DayBillManager Public Function queryRechargeCash(ByVal date1 As String) As DataTable '在recharge这张表中查询收取金额的相关信息 Dim DayBillDAO As New DAL.DayBillDAO Return DayBillDAO.queryRechargeCash(date1) End Function Public Function queryCancelCash(ByVal date2 As String) As DataTable '从卡表中查询退还金额也就是剩余金额 Dim DayBillDAO As New DAL.DayBillDAO Return DayBillDAO.queryCancelCash(date2) End Function Public Function queryConsumeCash(ByVal date3 As String) As DataTable '从line表查询消费金额 Dim DayBillDAO As New DAL.DayBillDAO Return DayBillDAO.queryConsumeCash(date3) End Function Public Sub inserDayBill(ByVal checkDayinfo As Entity.CheckDayinfo) '假设日结账单里面没有信息。我们须要插入一条 Dim DayBillDAO As New DAL.DayBillDAO DayBillDAO.insertDayBill(checkDayinfo) End Sub Public Sub updateDayBill(ByVal checkDayinfo As Entity.CheckDayinfo) '假设日结账单里面有信息,我们仅仅须要更新就可以 Dim DayBillDAO As New DAL.DayBillDAO DayBillDAO.updateDayBill(checkDayinfo) End Sub Public Function queryCheckDay(ByVal date1 As String) As Entity.CheckDayinfo '查找日结账单中的相关信息,假设没有信息,我们须要插入一条信息,假设有,我们须要更新一条信息 Dim DayBillDAO As New DAL.DayBillDAO Return DayBillDAO.queryCheckDay(date1) End Function End Class </span>U层
<span style="font-size:18px;">Public Class frmDayBill Private Sub frmDayBill_Load(sender As Object, e As EventArgs) Handles MyBase.Load Call write() 'TODO: 这行代码将数据载入到表“DataSet1.CheckDay_info”中。最后执行结果;您能够依据须要移动或删除它。
Me.CheckDay_infoTableAdapter.Fill(Me.DataSet1.CheckDay_info, CStr(Format(dtpDate.Value, "yyyy-MM-dd"))) Me.ReportViewer1.RefreshReport() End Sub Public Sub write() '在这里,加入了一个DataGridView把相关信息显示在DataGridView中,在报表中显示的时候,我们仅仅须要用一个循环进行相加就可以 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 '定义变量 Dim rechargeCash As Decimal For i = 0 To dgv.RowCount - 1 '充值的金额等于DataGirdView全部的行中的列相加。这里的列即recharge_info中的第二列(rechargeAmount)(当天的哦) 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 '退还的金额等于DataGirdView全部的行中的列相加,这里的列即card_info中的第二列balance,也就是退还金额 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 '消费的金额等于DataGridView中全部的行中的列相加,这里的列即line_info中的第六列consumeMoney,也就是消费金额 consumeCash = consumeCash + dgv.Rows(i).Cells(6).Value Next i Dim allCash As Decimal allCash = rechargeCash - cancelCash '总金额。等于充值金额减去退还金额 Dim enCheck As New Entity.CheckDayinfo '封装实体 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 ")) '假设enCheck中没有记录,我们就插入一条,否则更新 If (enCheck Is Nothing) Then daybill.inserDayBill(enCheck1) Else daybill.updateDayBill(enCheck1) End If End Sub Private Sub dtpDate_ValueChanged(sender As Object, e As EventArgs) Handles dtpDate.ValueChanged '调用窗口载入事件 Call frmDayBill_Load(sender, e) End Sub End Class</span>
计算机出现之后,我们利用计算机处理数据和界面设计的功能来生成、展示报表。计算机上的报表的主要特点是数据动态化。格式多样化,而且实现报表数据和报表格式的全然分离。用户能够仅仅改动数据,或者仅仅改动格式。报表分类EXCEL、WORD等编辑软件:它们能够做出非常复杂的报表格式,可是因为它们未定义专门的报表结构来动态的载入报表数据。全部这类软件中的数据都是已经定义好的。静态的,不能动态变化的。
它们没有办法实现报表软件的“数据动态化”特性。自此,日结的功能告一段落。机房收费系统未完,待续......