📄 staff.frm
字号:
VERSION 5.00
Begin VB.Form frmstaff
Caption = "员工信息"
ClientHeight = 5415
ClientLeft = 60
ClientTop = 450
ClientWidth = 3915
LinkTopic = "Form2"
ScaleHeight = 5415
ScaleWidth = 3915
StartUpPosition = 3 '窗口缺省
Begin VB.Frame fraInfo
Caption = "员工信息"
Height = 3375
Left = 0
TabIndex = 4
Top = 0
Width = 3615
Begin VB.TextBox txtItem
BeginProperty DataFormat
Type = 1
Format = "0"
HaveTrueFalseNull= 0
FirstDayOfWeek = 0
FirstWeekOfYear = 0
LCID = 2052
SubFormatType = 1
EndProperty
Height = 270
Index = 5
Left = 1080
MaxLength = 20
TabIndex = 3
Top = 2760
Width = 2055
End
Begin VB.TextBox txtItem
BeginProperty DataFormat
Type = 1
Format = "0"
HaveTrueFalseNull= 0
FirstDayOfWeek = 0
FirstWeekOfYear = 0
LCID = 2052
SubFormatType = 1
EndProperty
Height = 270
Index = 4
Left = 1080
MaxLength = 20
TabIndex = 5
Top = 2280
Width = 2055
End
Begin VB.TextBox txtItem
Height = 270
Index = 0
Left = 1080
MaxLength = 20
TabIndex = 9
Top = 360
Width = 2055
End
Begin VB.TextBox txtItem
Height = 270
Index = 1
Left = 1080
MaxLength = 20
TabIndex = 8
Top = 840
Width = 2055
End
Begin VB.TextBox txtItem
Height = 270
Index = 2
Left = 1080
MaxLength = 20
TabIndex = 7
Top = 1320
Width = 2055
End
Begin VB.TextBox txtItem
BeginProperty DataFormat
Type = 1
Format = "0"
HaveTrueFalseNull= 0
FirstDayOfWeek = 0
FirstWeekOfYear = 0
LCID = 2052
SubFormatType = 1
EndProperty
Height = 270
Index = 3
Left = 1080
MaxLength = 20
TabIndex = 6
Top = 1800
Width = 2055
End
Begin VB.Label lblFields
AutoSize = -1 'True
Caption = "职称:"
Height = 180
Index = 5
Left = 360
TabIndex = 16
Top = 2760
Width = 540
End
Begin VB.Label lblFields
AutoSize = -1 'True
Caption = "部门:"
Height = 180
Index = 4
Left = 360
TabIndex = 15
Top = 2280
Width = 540
End
Begin VB.Label lblFields
AutoSize = -1 'True
Caption = "性别:"
Height = 180
Index = 2
Left = 360
TabIndex = 14
Top = 1335
Width = 540
End
Begin VB.Label lblFields
AutoSize = -1 'True
Caption = "姓名:"
Height = 180
Index = 1
Left = 360
TabIndex = 13
Top = 840
Width = 540
End
Begin VB.Label lblFields
AutoSize = -1 'True
Caption = "工号:"
Height = 180
Index = 0
Left = 360
TabIndex = 12
Top = 360
Width = 540
End
Begin VB.Label lblFields
AutoSize = -1 'True
Caption = "年龄:"
Height = 180
Index = 3
Left = 360
TabIndex = 10
Top = 1800
Width = 540
End
End
Begin VB.Frame fraMemo
Caption = "备注信息"
Height = 1095
Left = 0
TabIndex = 2
Top = 3480
Width = 3612
Begin VB.TextBox txtItem
Height = 720
Index = 6
Left = 120
MultiLine = -1 'True
ScrollBars = 2 'Vertical
TabIndex = 11
Top = 240
Width = 3375
End
End
Begin VB.CommandButton cmdExit
Caption = "返回(&R)"
Height = 375
Left = 2160
TabIndex = 1
Top = 4680
Width = 975
End
Begin VB.CommandButton cmdSave
Caption = "保存(&S)"
Height = 375
Left = 480
TabIndex = 0
Top = 4680
Width = 975
End
End
Attribute VB_Name = "frmstaff"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Explicit
Dim mbChange As Boolean
Public mbAddMode As Boolean
Public mnSerial As Long
Private Sub cmdExit_Click()
If mbChange And cmdSave.Enabled Then
If MsgBox("保存当前记录的变化吗?", vbOKCancel + vbExclamation, "警告") = vbOK Then
Call cmdSave_Click
End If
End If
Unload Me
Unload frmstafflist
Load frmstafflist
frmstafflist.SQL = "select * from staff"
frmstafflist.Show
End Sub
Private Sub cmdSave_Click()
Dim strMsg As String
Dim rs As ADODB.Recordset
Dim strSQL As String
Dim i As Integer
For i = 0 To 5
If Trim(txtItem(i) & " ") = "" Then
Select Case i
Case 0
strMsg = "工号"
Case 1
strMsg = "姓名"
Case 2
strMsg = "性别"
Case 3
strMsg = "年龄"
Case 4
strMsg = "部门"
Case 5
strMsg = "职称"
End Select
strMsg = strMsg & "不能为空!"
MsgBox strMsg, vbOKOnly + vbExclamation, "警告"
txtItem(i).SetFocus
Exit Sub
End If
Next i
Set rs = New ADODB.Recordset
If mbAddMode Then
strSQL = "select * from staff where 工号 ='" & Trim(txtItem(0)) & "' "
rs.Open strSQL, gConn, adOpenStatic
If Not rs.EOF Then
MsgBox "已经存在相同内容的记录!", vbOKOnly + vbExclamation, "警告"
txtItem(0).SetFocus
rs.Close
Exit Sub
End If
rs.Close
Else
strSQL = "delete from staff where 顺序号 =" & Trim(mnSerial)
gConn.Execute strSQL
End If
strSQL = "select * from staff"
rs.Open strSQL, gConn, adOpenDynamic, adLockOptimistic
rs.AddNew
For i = 0 To rs.Fields.Count - 2
rs.Fields(i + 1) = txtItem(i)
Next i
rs.Update
rs.Close
If mbAddMode Then
mbChange = False
MsgBox "添加商品信息成功!继续添加下一条商品信息", vbOKOnly + vbExclamation, "添加商品信息"
Unload Me
Me.Show vbModal
Else
Unload Me
frmstafflist.SQL = "select * from staff"
frmstafflist.Show
End If
End Sub
Private Sub Form_GotFocus()
txtItem(Index).SelStart = 0
txtItem(Index).SelLength = Len(txtItem(Index))
End Sub
Private Sub Form_Load()
Dim strSQL As String
Dim i As Integer
Dim rs As New ADODB.Recordset
If mbAddMode Then
Me.Caption = Me.Caption & "添加"
Else
strSQL = "select * from staff where 顺序号 ='" & Trim(frmstafflist.grdList.TextMatrix(frmstafflist.grdList.Row, 1)) & "'"
rs.Open strSQL, gConn, adOpenKeyset
If rs.EOF = False Then
With rs
mnSerial = .Fields(0)
For i = 0 To .Fields.Count - 2
If Not IsNull(.Fields(i + 1)) Then
txtItem(i) = .Fields(i + 1)
End If
Next i
End With
End If
rs.Close
Me.Caption = Me.Caption & "修改"
End If
mbChange = False
End Sub
Private Sub txtItem_Change(Index As Integer)
mbChange = True
End Sub
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -