AddCur.frm
上传用户:cntx88
上传日期:2022-08-07
资源大小:169k
文件大小:10k
- VERSION 5.00
- Object = "{86CF1D34-0C5F-11D2-A9FC-0000F8754DA1}#2.0#0"; "MSCOMCT2.OCX"
- Begin VB.Form AddCur
- Caption = "添加报销记录"
- ClientHeight = 7005
- ClientLeft = 60
- ClientTop = 450
- ClientWidth = 7830
- LinkTopic = "Form1"
- ScaleHeight = 7005
- ScaleWidth = 7830
- StartUpPosition = 3 'Windows Default
- Begin VB.Frame Frame1
- Caption = "报销记录添加"
- Height = 6735
- Left = 120
- TabIndex = 0
- Top = 120
- Width = 7575
- Begin VB.CommandButton Command2
- Caption = "放弃退出"
- Height = 495
- Left = 4080
- TabIndex = 15
- Top = 6120
- Width = 3135
- End
- Begin VB.CommandButton Command1
- Caption = "确定提交"
- Height = 495
- Left = 360
- TabIndex = 14
- Top = 6120
- Width = 3135
- End
- Begin VB.ComboBox Combo2
- Height = 300
- Left = 5160
- TabIndex = 13
- Text = "Combo2"
- Top = 1200
- Width = 2175
- End
- Begin VB.TextBox Text4
- Height = 4215
- Left = 120
- MultiLine = -1 'True
- TabIndex = 6
- Text = "AddCur.frx":0000
- Top = 1800
- Width = 7215
- End
- Begin VB.ComboBox Combo1
- Height = 300
- Left = 2640
- TabIndex = 5
- Text = "Combo1"
- Top = 600
- Width = 2175
- End
- Begin MSComCtl2.DTPicker DTPicker1
- Height = 255
- Left = 2640
- TabIndex = 4
- Top = 1200
- Width = 2175
- _ExtentX = 3836
- _ExtentY = 450
- _Version = 393216
- Format = 662831105
- CurrentDate = 38012
- End
- Begin VB.TextBox Text3
- Height = 270
- Left = 120
- TabIndex = 3
- Text = "Text3"
- Top = 1200
- Width = 2175
- End
- Begin VB.TextBox Text2
- Height = 270
- Left = 5160
- TabIndex = 2
- Text = "Text2"
- Top = 600
- Width = 2175
- End
- Begin VB.TextBox Text1
- Height = 270
- Left = 120
- TabIndex = 1
- Text = "Text1"
- Top = 600
- Width = 2175
- End
- Begin VB.Label Label7
- Caption = "报销说明"
- Height = 255
- Left = 120
- TabIndex = 16
- Top = 1560
- Width = 1815
- End
- Begin VB.Label Label6
- Caption = "报销部门"
- Height = 255
- Left = 5160
- TabIndex = 12
- Top = 960
- Width = 1815
- End
- Begin VB.Label Label5
- Caption = "报销人ID编号"
- Height = 255
- Left = 120
- TabIndex = 11
- Top = 960
- Width = 1815
- End
- Begin VB.Label Label4
- Caption = "报销日期"
- Height = 255
- Left = 2640
- TabIndex = 10
- Top = 960
- Width = 1815
- End
- Begin VB.Label Label3
- Caption = "报销金额"
- Height = 255
- Left = 5160
- TabIndex = 9
- Top = 360
- Width = 1815
- End
- Begin VB.Label Label2
- Caption = "报销类别"
- Height = 255
- Left = 2640
- TabIndex = 8
- Top = 360
- Width = 1815
- End
- Begin VB.Label Label1
- Caption = "报销单号"
- Height = 255
- Left = 120
- TabIndex = 7
- Top = 360
- Width = 1815
- End
- End
- End
- Attribute VB_Name = "AddCur"
- Attribute VB_GlobalNameSpace = False
- Attribute VB_Creatable = False
- Attribute VB_PredeclaredId = True
- Attribute VB_Exposed = False
- Option Explicit
- Private Sub Command1_Click()
- Dim sql As String
- Dim rs As New ADODB.Recordset
-
- If Text1.Text = "" Then '判断报销单编号输入框不为空
- MsgBox "报销单编号不能为空!", vbCritical
- Text1.SetFocus
- Exit Sub
- End If
- If Text2.Text = "" Then '判断报销金额输入框不为空
- MsgBox "报销金额不能为空!", vbCritical
- Text2.SetFocus
- Exit Sub
- End If
- If Text3.Text = "" Then '判断报销人ID输入框不为空
- MsgBox "报销人ID不能为空! ", vbCritical
- Text3.SetFocus
- Exit Sub
- End If
- If Text4.Text = "" Then '判断报销说明输入框不为空
- MsgBox "报销说明不能为空!", vbCritical
- Text4.SetFocus
- Exit Sub
- End If
- If Not IsNumeric(Text2.Text) Then '判断资产数目必须是数字
- MsgBox "资产数目必须是数字!", vbCritical
- Text2.SetFocus
- Exit Sub
- End If
- If Combo1.ListIndex = -1 Then '判断报销类别下拉列表必须选择
- MsgBox "报销类别必须选择!", vbCritical
- Combo1.SetFocus
- Exit Sub
- End If
- If Combo2.ListIndex = -1 Then '判断部门下拉列表必须选择
- MsgBox "部门必须选择!", vbCritical
- Combo2.SetFocus
- Exit Sub
- End If
-
- If DbHandle.DbConnection Then '打开DSN数据库源连接
- sql = "TBL_CUR" '对流动资产表进行操作
- rs.CursorType = adOpenDynamic
- rs.LockType = adLockOptimistic
- rs.Filter = "CUR_ID='" & Text1.Text & "'" '选择指定ID的记录
- rs.Open sql, DbFinance
- If DbHandle.resultcount(rs) = 1 Then '如果记录已经存在则提示对话框并且关闭数据库
- MsgBox "报销单编号已经存在!", vbExclamation
- rs.Close
- DbHandle.DbClose
- Exit Sub
- End If
- rs.Close
- sql = "TBL_USER" '如果记录不存在打开职工表进一步验证职工ID号是否存在
- rs.CursorType = adOpenDynamic
- rs.LockType = adLockOptimistic
- rs.Filter = "USER_ID='" & Text3.Text & "'"
- rs.Open sql, DbFinance
- If DbHandle.resultcount(rs) <> 1 Then '如果职工ID记录不存在则提示错误对话框并且关闭数据库
- MsgBox "错误,不存在的职工ID号!", vbExclamation
- Text3.SetFocus
- rs.Close
- Set rs = Nothing '释放结果记录集
- DbHandle.DbClose
- Exit Sub
- Else
- rs.Close
- sql = "TBL_CUR" '如果职工和报销单号都没有问题就打开流动资产表添加新记录
- rs.Filter = ""
- rs.Open sql, DbFinance
- rs.AddNew
- rs("CUR_ID") = Text1.Text '报销单编号
- rs("CUR_TYPE") = Combo1.ItemData(Combo1.ListIndex) '报销类别
- rs("CUR_MONEY") = Val(Text2.Text) '报销金额
- rs("CUR_USER") = Text3.Text '报销职工的ID
- rs("CUR_DATE") = Me.DTPicker1.Value '报销时间
- rs("CUR_PART") = Combo2.ItemData(Combo2.ListIndex) '报销部门
- rs("CUR_REMARK") = Text4.Text '报销说明
- rs.Update
- rs.Close
- End If
- DbHandle.DbClose
- MsgBox "报销记录成功添加!"
- Unload Me
- Else '数据库打开失败则提示并关闭数据库
- MsgBox "数据库错误!", vbExclamation
- DbHandle.DbClose
- End
- End If
- End Sub
- Private Sub Command2_Click()
- Unload Me '取消添加并且返回主窗体
- End Sub
- Private Sub Form_Load()
- Dim sql As String
- Dim rs As New ADODB.Recordset
-
- Me.Left = (Screen.Width - Me.ScaleWidth) / 2 '居中显示当前窗体
- Me.Top = (Screen.Height - Me.ScaleHeight) / 2
- If DbHandle.DbConnection Then '打开数据库连接
- sql = "TBL_CURTYPE" '将报销类别从数据库中取出来并且显示在下拉列表中
- rs.CursorType = adOpenDynamic
- rs.LockType = adLockOptimistic
- rs.Filter = ""
- rs.Open sql, DbFinance
-
- Do While rs.EOF = False '从查找出来的结果集中循环加入下拉列表中,并且记录每个报销类别编号
- Combo1.AddItem (rs("CURTYPE_NAME"))
- Combo1.ItemData(Combo1.NewIndex) = rs("CURTYPE_ID")
- rs.MoveNext
- Loop
- rs.Close
- Set rs = Nothing '添加完成释放结果集
- DbHandle.DbClose
- Else '打开数据库失败弹出错误窗体
- MsgBox "数据库错误!", vbExclamation
- DbHandle.DbClose
- End
- End If
- If DbHandle.DbConnection Then '再次打开数据库提取部门信息
- sql = "TBL_PART" '对部门表进行全部选择
- rs.CursorType = adOpenDynamic
- rs.LockType = adLockOptimistic
- rs.Filter = ""
- rs.Open sql, DbFinance
-
- Do While rs.EOF = False '对选择出来的部门结果集遍历,加入下拉列表中
- Combo2.AddItem (rs("PART_NAME"))
- Combo2.ItemData(Combo2.NewIndex) = rs("PART_ID")
- rs.MoveNext
- Loop
- rs.Close '完成下拉列表的动态添加,释放结果集资源,关闭数据库连接
- Set rs = Nothing
- DbHandle.DbClose
- Else '打开数据库失败弹出错误窗体
- MsgBox "数据库错误!", vbExclamation
- DbHandle.DbClose
- End
- End If
- Text1.Text = "" '初始化窗体元素属性
- Text2.Text = ""
- Text3.Text = ""
- Text4.Text = ""
- Text4.MaxLength = 100
- Combo1.Text = ""
- Combo2.Text = ""
- End Sub