📄 addpay.frm
字号:
VERSION 5.00
Begin VB.Form AddPay
Caption = "添加"
ClientHeight = 4020
ClientLeft = 60
ClientTop = 450
ClientWidth = 3675
LinkTopic = "Form1"
ScaleHeight = 4020
ScaleWidth = 3675
StartUpPosition = 3 'Windows Default
Begin VB.Frame Frame1
Caption = "添加工资记录"
Height = 3735
Left = 120
TabIndex = 0
Top = 120
Width = 3375
Begin VB.CommandButton Command2
Caption = "取消"
Height = 495
Left = 1800
TabIndex = 11
Top = 2880
Width = 1215
End
Begin VB.CommandButton Command1
Caption = "确定"
Height = 495
Left = 360
TabIndex = 10
Top = 2880
Width = 1215
End
Begin VB.ComboBox Combo2
Height = 300
Left = 1920
TabIndex = 7
Text = "Combo2"
Top = 2160
Width = 855
End
Begin VB.ComboBox Combo1
Height = 300
ItemData = "AddPay.frx":0000
Left = 360
List = "AddPay.frx":0002
TabIndex = 6
Text = "Combo1"
Top = 2138
Width = 1215
End
Begin VB.TextBox Text2
Height = 270
Left = 360
TabIndex = 3
Text = "Text2"
Top = 1440
Width = 2655
End
Begin VB.TextBox Text1
Height = 270
Left = 360
TabIndex = 1
Text = "Text1"
Top = 720
Width = 2655
End
Begin VB.Label Label5
Caption = "月"
Height = 255
Left = 2880
TabIndex = 9
Top = 2190
Width = 255
End
Begin VB.Label Label4
Caption = "年"
Height = 255
Left = 1680
TabIndex = 8
Top = 2190
Width = 255
End
Begin VB.Label Label3
Caption = "工资月份"
Height = 255
Left = 360
TabIndex = 5
Top = 1800
Width = 1215
End
Begin VB.Label Label2
Caption = "月工资"
Height = 255
Left = 360
TabIndex = 4
Top = 1200
Width = 1215
End
Begin VB.Label Label1
Caption = "职工ID"
Height = 255
Left = 360
TabIndex = 2
Top = 480
Width = 2175
End
End
End
Attribute VB_Name = "AddPay"
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
Dim paydate As String '工资月份
If Text1.Text = "" Then '确保需要填写的文本框都填写正确的信息
MsgBox "职工ID不能为空!", vbCritical
Text1.SetFocus
Exit Sub
End If
If Text2.Text = "" Then
MsgBox "月工资不能为空!", vbCritical
Text2.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
paydate = Combo1.List(Combo1.ListIndex) & "-" & Combo2.List(Combo2.ListIndex)
'组合年份和月份
If DbHandle.DbConnection Then
sql = "TBL_USER" '查找职工表,确定输入职工ID是存在的.
rs.CursorType = adOpenDynamic
rs.LockType = adLockOptimistic
rs.Filter = "USER_ID='" & Text1.Text & "'"
rs.Open sql, DbFinance
If DbHandle.resultcount(rs) <> 1 Then '不存在则提示出错,退出
MsgBox "错误,不存在的职工ID号!", vbExclamation
Text1.SetFocus
rs.Close
Set rs = Nothing
DbHandle.DbClose
Exit Sub
End If
rs.Close
sql = "TBL_PAY" '搜索月工资表确保输入的工资记录是不存在的
rs.CursorType = adOpenDynamic
rs.LockType = adLockOptimistic
rs.Filter = "PAY_USER='" & Text1.Text & "' AND PAY_DATE='" & paydate & "'"
rs.Open sql, DbFinance
If DbHandle.resultcount(rs) = 1 Then '存在则提示出错,退出
MsgBox "工资记录已经存在!", vbExclamation
rs.Close
DbHandle.DbClose
Exit Sub
Else '不存在则新添加工资记录
rs.Close
rs.Filter = ""
rs.Open sql, DbFinance
rs.AddNew
rs("PAY_USER") = Text1.Text '职工ID
rs("PAY_DATE") = paydate '发放工资月份
rs("PAY_MONEY") = Val(Text2.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 i As Long
Me.Left = (Screen.Width - Me.ScaleWidth) / 2 '窗体居中化
Me.Top = (Screen.Height - Me.ScaleHeight) / 2
For i = 2003 To 2030 '下拉列表设置显示年份是2003-2030年间
Combo1.AddItem Trim(Str(i))
Next i
For i = 1 To 12 '下拉列表设置显示月份是1-12月间
Combo2.AddItem Trim(Str(i))
Next i
Text1.Text = "" '初始化窗体元素属性
Text2.Text = ""
Combo1.Text = ""
Combo2.Text = ""
End Sub
Private Sub Form_Unload(Cancel As Integer)
On Error Resume Next
DbHandle.DbClose '关闭窗体时关闭数据库连接
End Sub
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -