📄 c工资计发维护.frm
字号:
Top = 4920
Width = 800
End
Begin VB.CommandButton CmdCancel
BackColor = &H00C0C0C0&
Caption = "取消"
Height = 360
Left = 3480
Style = 1 'Graphical
TabIndex = 1
Top = 4920
Width = 800
End
Begin VB.CommandButton CmdSave
BackColor = &H00C0C0C0&
Caption = "保存"
Height = 360
Left = 2640
Style = 1 'Graphical
TabIndex = 0
Top = 4920
Width = 800
End
End
Attribute VB_Name = "C工资计发维护"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Explicit
Dim rs As ADODB.Recordset
Dim SQL As String
Dim msg As String
Dim Index As Integer
Public flag As String '判断是新增记录还是修改记录
Dim YGGZ As Integer '保存计发ID
Private Sub Form_Load()
'初始化员工IDComboBox
Dim rst As ADODB.Recordset
Dim GZID As String '保存工资等级ID
GZID = ""
SQL = " select * from 员工录用信息表 "
Set rst = SelectSQL(SQL, msg)
If rst.RecordCount = 0 Then
MsgBox ("请先建立员工基本信息!")
Exit Sub
Else
Do While Not rst.BOF And Not rst.EOF
'添加到ComboBox列表
Me.CboYGID.AddItem (rst.Fields("员工ID") & rst.Fields("姓名"))
rst.MoveNext '指向下一条记录
Loop
Me.CboYGID.ListIndex = 0 '默认ComboBox
'查询当前员工的工资等级
SQL = " Select a.工资等级ID from 职务信息表 a iNNER JOIN 员工录用信息表 b "
SQL = SQL & "ON a.职务名称=b.受聘职务 "
SQL = SQL & "where b.员工ID='" & Left(Trim(CboYGID.Text), 8) & "'"
Set rst = Nothing
Set rst = SelectSQL(SQL, msg)
GZID = rst.Fields(0)
'在相关控件中显示该员工工资等级相关信息
SQL = " select * from 工资标准信息表 where 工资等级ID='" & GZID & "'"
Set rst = Nothing
Set rst = SelectSQL(SQL, msg)
If rst.RecordCount = 0 Then
MsgBox ("请先建立工资标准信息!")
Exit Sub
Else
txtGZ.Text = rst.Fields("工资等级ID") & rst.Fields("等级名称")
txt(0).Text = rst.Fields("底薪")
txt(1).Text = rst.Fields("补贴")
txt(2).Text = rst.Fields("奖金")
txt(3).Text = rst.Fields("车补")
txt(4).Text = rst.Fields("房补")
txt(7).Text = rst.Fields("养老金")
txt(8).Text = rst.Fields("医疗保险")
txt(9).Text = rst.Fields("住房公积金")
End If
End If
'查询当前员工的考勤考核信息
SQL = " select * from 考勤考核信息表 where "
SQL = SQL & "员工ID='" & Left(Trim(CboYGID.Text), 8) & "'"
Set rst = Nothing
Set rst = SelectSQL(SQL, msg)
CboDate.Clear
If rst.RecordCount = 0 Then
'当前员工没有进行考勤考核是,默认扣考费、加班费
MsgBox "改员工还没有进行考勤考核,请先进行考勤考核!"
txt(5).Text = 0
txt(6).Text = 0
Else
Do While Not rst.BOF And Not rst.EOF
'添加到ComboBox列表
Me.CboDate.AddItem (rst.Fields("考核日期"))
rst.MoveNext '指向下一条记录
Loop
Me.CboDate.ListIndex = 0 '默认ComboBox
End If
'判断是添加还是修改
If flag = "Add" Then
Me.Caption = "工资计发信息添加"
FrameGZ.Caption = "工资计发信息添加"
SQL = "select * from 工资计发信息表 "
Set rs = SelectSQL(SQL, msg)
CmdAdd.Visible = True
CmdSave.Enabled = False
CmdCancel.Enabled = False
FrameGZ.Enabled = False
Else
Me.Caption = "工资计发信息修改"
FrameGZ.Caption = "工资计发信息修改"
CmdAdd.Visible = False
CboYGID.Enabled = False
txtGZ.Enabled = False
txt(0).Enabled = False
Call ShowData '显示数据
End If
End Sub
Private Sub ShowData()
'在控件中显示数据
YGGZ = c工资计发.YGGZ '得到当前修改的计发ID
SQL = " select * from 工资计发信息表 where 计发ID=" & YGGZ
Set rs = SelectSQL(SQL, msg)
'为控件赋值
If rs.RecordCount = 1 Then
'保证记录中的所属部门ID与ComboBox中的值相一致
For Index = 0 To CboYGID.ListCount - 1
If rs.Fields("员工ID") = Left(Trim(Me.CboYGID.List(Index)), 8) Then
Me.CboYGID.ListIndex = Index
Exit For
End If
Next Index
'显示工资等级相关信息
txtGZ.Text = rs.Fields("工资等级ID")
For Index = 0 To 10
txt(Index) = rs.Fields(Index + 3)
Next Index
'计算税率
txt(11).Text = CDbl(rs.Fields("所得税")) / CDbl(rs.Fields("税前小计"))
txt(12).Text = rs.Fields("应发工资")
Me.DTPicker1.value = rs.Fields("计发日期")
Else
MsgBox ("工资计发信息检索出错!")
End If
End Sub
Private Sub CmdAdd_Click()
'添加操作
Me.CboYGID.ListIndex = 0
Me.DTPicker1.Refresh
CmdAdd.Enabled = False
CmdSave.Enabled = True
CmdCancel.Enabled = True
FrameGZ.Enabled = True
End Sub
Private Sub CmdSave_Click()
'保存操作
On Error GoTo ErrMsg '出错处理
If Not CheckData Then Exit Sub '如果数据不合法就退出
Call Sum '计算税前小计、应发工资
If flag = "Modify" Then '如果是修改数据
msg = MsgBox("您确实要修改这条数据吗?", vbYesNo)
If msg = vbYes Then
Call setData '为字段设置数据
Else
Exit Sub
End If
ElseIf flag = "Add" Then '如果是添加新数据
rs.AddNew
Call setData '为字段设置数据
End If
rs.Update '更新数据
If flag = "Add" Then
MsgBox ("成功添加数据!")
CmdAdd.Enabled = True
CmdSave.Enabled = False
CmdCancel.Enabled = False
Else
MsgBox ("成功更新数据!")
End If
Call c工资计发.ReLoad
Exit Sub
ErrMsg: '报告出错信息
MsgBox Err.Description, vbExclamation, "出错"
End Sub
Private Function CheckData() As Boolean
'检查数据的合法性
Dim rst As ADODB.Recordset
Dim msgt As String
msgt = ""
'检查数据
If Trim(Me.CboYGID.Text) = "" Then '检查员工ID是否为空
msgt = "员工ID为空; "
ElseIf Trim(Me.txtGZ.Text) = "" Then '检查工资等级ID是否为空
msgt = msgt & "工资等级ID为空; "
ElseIf Trim(Me.txt(0).Text) = "" Then '检查底薪是否为空
msgt = msgt & "底薪为空; "
End If
For Index = 0 To 12 '检查数据是否合法
If txt(Index).Text <> "" Then
If Not IsNumeric(txt(Index).Text) Then
msgt = msgt & "数据不合法;"
txt(Index).SetFocus
txt(Index).SelStart = 0
txt(Index).SelLength = Len(txt(Index).Text)
Exit Function
End If
End If
Next Index
If Not msgt = "" Then '如果错误消息不为空,给出错误提示
MsgBox (msgt)
CheckData = False '返回False
Exit Function
End If
CheckData = True '合法返回True
End Function
Private Sub setData()
'为字段设置数据
rs.Fields("员工ID") = Left(Trim(Me.CboYGID.Text), 8)
rs.Fields("工资等级ID") = Left(Trim(Me.txtGZ.Text), 4)
For Index = 0 To 10
If IsNumeric(txt(Index).Text) Then
rs.Fields(Index + 3) = Trim(Me.txt(Index).Text)
Else
rs.Fields(Index + 3) = 0
End If
Next Index
'所得税=税前小计*税率
rs.Fields("所得税") = Str(CDbl(Trim(txt(10).Text)) * CDbl(Trim(txt(11).Text)))
rs.Fields("应发工资") = Trim(txt(12).Text)
rs.Fields("计发日期") = Me.DTPicker1.value
End Sub
Private Sub cmdCancel_Click()
'取消操作
If flag = "Add" Then
'重置控件
Call CmdAdd_Click
CmdAdd.Enabled = True
Else
Call ShowData '重新显示数据
End If
End Sub
Private Sub CboDate_Click()
'不同的考勤考核日期,有不同的扣考费、加班费
Dim rst As ADODB.Recordset
SQL = " select * from 考勤考核信息表 where 考核日期='" & CboDate.Text & "'"
Set rst = SelectSQL(SQL, msg)
txt(5).Text = rst.Fields("扣考核")
txt(6).Text = rst.Fields("加班费")
Call Sum '计算税前小计、应发工资
End Sub
Private Sub CboYGID_click()
'不同的员工有着不同的工资等级信息、考期考核信息
Dim rst As ADODB.Recordset
Dim GZID As String '保存工资等级ID
GZID = ""
'查询当前员工的工资等级ID
SQL = " Select a.工资等级ID from 职务信息表 a iNNER JOIN 员工录用信息表 b "
SQL = SQL & "ON a.职务名称=b.受聘职务 where b.员工ID='" & Left(Trim(CboYGID.Text), 8) & "'"
Set rst = SelectSQL(SQL, msg)
If rst.RecordCount = 0 Then
MsgBox ("请先建立职务信息!")
Else
GZID = rst.Fields(0) '取工资等级ID的值
End If
'在相关控件中显示工资等级信息
Set rst = Nothing
SQL = " select * from 工资标准信息表 where 工资等级ID='" & GZID & "'"
Set rst = SelectSQL(SQL, msg)
If rst.RecordCount = 0 Then
MsgBox ("请先建立工资标准信息!")
Exit Sub
Else
txtGZ.Text = rst.Fields("工资等级ID") & rst.Fields("等级名称")
txt(0).Text = rst.Fields("底薪")
txt(1).Text = rst.Fields("补贴")
txt(2).Text = rst.Fields("奖金")
txt(3).Text = rst.Fields("车补")
txt(4).Text = rst.Fields("房补")
txt(7).Text = rst.Fields("养老金")
txt(8).Text = rst.Fields("医疗保险")
txt(9).Text = rst.Fields("住房公积金")
End If
'在相关控件中显示考勤考核信息
Set rst = Nothing
'查询当前员工的考勤考核信息
SQL = " select * from 考勤考核信息表 where "
SQL = SQL & "员工ID='" & Left(Trim(CboYGID.Text), 8) & "'"
Set rst = SelectSQL(SQL, msg)
CboDate.Clear
If rst.RecordCount = 0 Then
MsgBox "改员工还没有进行考勤考核,请先进行考勤考核!"
txt(5).Text = 0
txt(6).Text = 0
Else
Do While Not rst.BOF And Not rst.EOF
'添加到ComboBox列表
Me.CboDate.AddItem (rst.Fields("考核日期"))
rst.MoveNext '指向下一条记录
Loop
Me.CboDate.ListIndex = 0 '默认ComboBox
rst.Close
End If
Call Sum '给税前小计、应发工资重新赋值
End Sub
Private Sub txt_Change(Index As Integer)
Call Sum '计算税前小计、应发工资
End Sub
Private Sub Sum()
'计算税前小计、应发工资
Dim Sum As Double
Sum = 0
For Index = 0 To 4
If Not IsNumeric(txt(Index).Text) Then
Me.txt(Index).Text = 0
Else
Sum = Sum + CDbl(txt(Index).Text)
End If
Next Index
If Not IsNumeric(txt(5).Text) Then
Me.txt(5).Text = 0
Else
Sum = Sum - CDbl(txt(5).Text)
End If
If Not IsNumeric(txt(6).Text) Then
Me.txt(6).Text = 0
Else
Sum = Sum + CDbl(txt(6).Text)
End If
For Index = 7 To 9
If Not IsNumeric(txt(Index).Text) Then
Me.txt(Index).Text = 0
Else
Sum = Sum - CDbl(txt(Index).Text)
End If
Next Index
txt(10).Text = Str$(Sum)
If Not IsNumeric(txt(11).Text) Then
txt(11).Text = 0
Else
Sum = Sum * (1 - CDbl(txt(11).Text))
If Sum > 0 Then
txt(12).Text = Str$(Sum * (1 - CDbl(txt(11).Text)))
Else
txt(12).Text = 0
End If
End If
End Sub
Private Sub CmdExit_Click()
'退出操作
B员工基本信息.Enabled = True
Unload Me
End Sub
Private Sub Form_Unload(Cancel As Integer)
'退出操作
c工资计发.Enabled = True
rs.Close
Unload Me
Unload c工资计发
c工资计发.Show
End Sub
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -