前言:
机房重构结账部分涉及到购卡,退卡,充值表的查询,以及汇总和结账。下面就说一下购卡,退卡以及充值和汇总是怎么样用DataGridView来实现的。这次的结账页面只走了两次七层结构,其余均是绑定数据源来实现的。
内容:
一、获取操作员用户名
获取操作员用户名用的是comboBox控件,本次直接采用窗体加载显示。
直接查询级别为操作员的用户,然后循环加载到comboBox控件中,然后走七层查询User表。
Private Sub frmAdadcount_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Dim facade As New Facade.SelectOpFacade
Dim table As New DataTable
Dim user As New Entity.Entity
Dim i As Integer
user.Level = "操作员"
table = facade.selectOpfacade(user)
For i = 1 To table.Rows.Count
cmdUserID.Items.Add(Convert.ToString(table.Rows(i - 1).Item(0)))
Next
FillByToolStrip1.Hide() '隐藏工具栏
'清空DataGridView表中数据()
While (DataGridView1.RowCount > 0)
DataGridView1.Rows.Remove(DataGridView1.Rows(0))
End While
End Sub
二、根据选择的操作员显示该操作员进行的购卡,充值以及退卡,同时计算出汇总中需要的购卡数,退卡数,总售卡数以及充值金额,退卡金额,应收金额。
DataGridView绑定数据源:http://blog.csdn.net/tgbyn/article/details/74858291
Private Sub cmdUserID_SelectedIndexChanged(sender As Object, e As EventArgs) Handles cmdUserID.SelectedIndexChanged
Dim facade As New Facade.SelectOpFacade
Dim table As New DataTable
Dim user As New Entity.Entity
Dim RechargeMoney As Integer
Dim CancelMoney As Integer
Dim TotalMoney As Integer
UserIDToolStripTextBox.Text = cmdUserID.Text '传入的操作员
Try
'绑定数据源,查询各个表数据
Me.Y_Card_InfoTableAdapter.Fill(Me.Register.Y_Card_Info, UserIDToolStripTextBox.Text) '注册表
Me.Y_ReCharge_InfoTableAdapter.Fill(Me.Recharge.Y_ReCharge_Info, UserIDToolStripTextBox.Text) '充值表
Me.Y_CancelCard_InfoTableAdapter.Fill(Me.CancelCard.Y_CancelCard_Info, UserIDToolStripTextBox.Text) '退卡表
txtRegister.Text = DataGridView1.RowCount '获取注册卡张数
txtCancelCard.Text = DataGridView3.RowCount '获取退卡张数
txtTotal.Text = txtRegister.Text - txtCancelCard.Text '总售卡张数
'通过查询DataGridView每一条充值金额,获取总充值金额
For i = 0 To DataGridView2.RowCount - 1
RechargeMoney = RechargeMoney + DataGridView2.Rows(i).Cells(1).Value '计算充值金额
Next
'通过查询DataGridView每一条退卡金额,获取总退卡金额
For i = 0 To DataGridView3.RowCount - 1
CancelMoney = CancelMoney + DataGridView3.Rows(i).Cells(1).Value '计算退卡金额
Next
TotalMoney = RechargeMoney - CancelMoney '应收金额
txtRechargeCash.Text = RechargeMoney '充值金额
txtCancelCash.Text = CancelMoney '退卡金额
txtActualCash.Text = TotalMoney '应收金额
Catch ex As System.Exception
System.Windows.Forms.MessageBox.Show(ex.Message)
End Try
End Sub
三、结账
将汇总页面获得的充值金额,退卡金额,应收金额等,更新进结账表;同时将注册表,退卡表,充值表状态更改为已结账。
'结账
Private Sub btnAcount_Click(sender As Object, e As EventArgs) Handles btnAcount.Click
Dim adcount As New Entity.EntityAdCount
Dim flag As Integer
Dim facade As New Facade.AdcountFacade
adcount.RechCash = txtRechargeCash.Text
adcount.CancelCash = txtCancelCash.Text
adcount.CheckCash = txtActualCash.Text
adcount.Checkdate = Format(Now, "yyyy-MM-dd HH:mm:ss")
adcount.UserID = cmdUserID.Text
flag = facade.adcountbFacade(adcount)
If flag > 0 Then
MsgBox("结账成功!")
End If
End Sub
存储过程
ALTER PROCEDURE [dbo].[proc_Account]
@UserID varchar(11),
@CheckCash numeric(10, 2),
@RechCash numeric(10, 2),
@CancelCash numeric(10, 2),
@Checkdate datetime
as
declare @Is varchar(20)
BEGIN
set @Is = '未结账'
update Y_ReCharge_Info set IsCheck='已结账' where UserID=@UserID and IsCheck=@Is
update Y_CancelCard_Info set IsCheck='已结账' where UserID=@UserID and IsCheck=@Is
update Y_Card_Info set IsCheck='已结账' where UserID=@UserID and IsCheck=@Is
insert into Y_Check_Info(UserID,CheckCash,RechCash,CancelCash,Checkdate)values(@UserID,@CheckCash,@RechCash,@CancelCash,@Checkdate)
---exec('select * from Bill_Info')
END
总结
看了不少人的博客,他们查询 充值金额,退卡金额,应收金额等都是走的七层查询出来的,其实直接获取表中的字段进行相加也是可以得到想要的东西。多一点思考,总会发现新东西,继续加油。