日结账单说之前先说一下与报表设计器连接的日结账单表中的数据是怎么来的。我是在结账中写的代码。 请看下边:
Dim RemainCash As Double '上期余额,就是昨天的金额总和。
Dim RechargeCash As Double '今天结账的充值金额。
Dim ConsumeCash As Double ' 今天结账的消费金额。
Dim CancelCash As Double '今天结账的退卡金额。
Dim AllCash As Double '今天结账的金额总和。
Dim txtSQL As String
Dim mrc As ADODB.Recordset
'先删除今天的结账的记录。
txtSQL = "delete from CheckDay_Info where date='" & Date & "'"
Set mrc = ExecuteSQL(txtSQL, MsgText)
'算出上期余额,是从日结表中昨天的金额总和得来的。
Dim txtSQLCheckDay As String
Dim mrcCheckDay As ADODB.Recordset
txtSQLCheckDay = "select AllCash from CheckDay_Info where date='" & Date - 1 & "'"
Set mrcCheckDay = ExecuteSQL(txtSQLCheckDay, MsgText)
If mrcCheckDay.RecordCount = 0 Then
RemainCash = 0
Else
If IsNull(mrcCheckDay.Fields(0)) Then
RemainCash = 0
Else
RemainCash = mrcCheckDay.Fields(0)
End If
End If
'充值金额,是从充值表中整出今天的充值金额。
Dim txtSQLReCharg As String
Dim mrcReCharg As ADODB.Recordset
txtSQLReCharg = "select sum(addmoney) from ReCharge_Info where date='" & Date & "'and status='结账'"
Set mrcReCharg = ExecuteSQL(txtSQLReCharg, MsgText)
If mrcReCharg.RecordCount = 0 Then
RechargeCash = 0
Else
If IsNull(mrcReCharg.Fields(0)) Then
RechargeCash = 0
Else
RechargeCash = mrcReCharg.Fields(0)
End If
End If
'消费金额,从Line表中今天消费金额的总和。
Dim txtSQLLine As String
Dim mrcLine As ADODB.Recordset
txtSQLLine = "select sum(consume) from Line_Info where offdate='" & Date & "'"
Set mrcLine = ExecuteSQL(txtSQLLine, MsgText)
If mrcLine.RecordCount = 0 Then
ConsumeCash = 0
Else
If IsNull(mrcLine.Fields(0)) Then
ConsumeCash = 0
Else
ConsumeCash = mrcLine.Fields(0)
End If
End If
'退卡金额,在退卡表中得今天退卡金额的总和
Dim txtSQLCancel As String
Dim mrcCancel As ADODB.Recordset
txtSQLCancel = "select sum(CancelCash) from CancelCard_Info where Date='" & Date & "'and status='结账'"
Set mrcCancel = ExecuteSQL(txtSQLCancel, MsgText)
If mrcCancel.RecordCount = 0 Then
CancelCash = 0
Else
If IsNull(mrcCancel.Fields(0)) Then
CancelCash = 0
Else
CancelCash = mrcCancel.Fields(0)
End If
End If
'金额总和,上期余额加充值金额减退卡金额。
AllCash = RemainCash + RechargeCash - CancelCash
Dim txtSQLCheck As String
Dim mrcCheck As ADODB.Recordset
txtSQLCheck = "select * from CheckDay_Info"
Set mrcCheck = ExecuteSQL(txtSQLCheck, MsgText)
'将对应的数据写入日结表中。
mrcCheck.AddNew
mrcCheck.Fields(0) = RemainCash
mrcCheck.Fields(1) = RechargeCash
mrcCheck.Fields(2) = ConsumeCash
mrcCheck.Fields(3) = CancelCash
mrcCheck.Fields(4) = AllCash
mrcCheck.Fields(5) = Date
mrcCheck.Update
这是日结表的数据是要显示在日结账单中的数据。 下边看怎么将数据库的表与报表设计器连接的: 首先新建一个,在文件—新建向导。再连接:
将列名与标题行一一对应好
下边这样的:
这是与数据库的链接。
下边是与vb的链接代码:
Dim strSQL As String, strMsg As String
strSQL = "select * from CheckDay_info"
Set Report = New grproLibCtl.GridppReport '实例化模版
Report.LoadFromFile (App.Path & "\报表.grf") '加载模版
Report.DetailGrid.Recordset.ConnectionString = ConnectString() '连接数据源
Report.DetailGrid.Recordset.QuerySQL = strSQL '通过SELECT查询创建记录集
GRDisplayViewer1.Report = Report
GRDisplayViewer1.Start '开始打印
注意要提前声明一下。