⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 main_yggl_addmodify.frm

📁 人事管理系统
💻 FRM
📖 第 1 页 / 共 2 页
字号:
         Left            =   540
         TabIndex        =   33
         Top             =   3135
         Width           =   570
      End
      Begin VB.Label Label17 
         Caption         =   "最高学历:"
         Height          =   225
         Left            =   6255
         TabIndex        =   32
         Top             =   2805
         Width           =   900
      End
      Begin VB.Label Label16 
         Caption         =   "专业:"
         Height          =   225
         Left            =   3915
         TabIndex        =   31
         Top             =   2805
         Width           =   555
      End
      Begin VB.Label Label15 
         Caption         =   "毕业院校:"
         Height          =   225
         Left            =   165
         TabIndex        =   28
         Top             =   2805
         Width           =   930
      End
      Begin VB.Label Label14 
         Caption         =   "家庭地址:"
         Height          =   225
         Left            =   150
         TabIndex        =   27
         Top             =   2430
         Width           =   930
      End
      Begin VB.Label Label13 
         Caption         =   "手机号码:"
         Height          =   225
         Left            =   2865
         TabIndex        =   26
         Top             =   2100
         Width           =   930
      End
      Begin VB.Label Label12 
         Caption         =   "联系电话:"
         Height          =   225
         Left            =   135
         TabIndex        =   21
         Top             =   2085
         Width           =   930
      End
      Begin VB.Label Label11 
         Caption         =   "籍贯:"
         Height          =   225
         Left            =   3165
         TabIndex        =   20
         Top             =   1725
         Width           =   540
      End
      Begin VB.Label Label10 
         Caption         =   "政治面貌:"
         Height          =   195
         Left            =   2865
         TabIndex        =   19
         Top             =   1365
         Width           =   915
      End
      Begin VB.Label Label9 
         Caption         =   "婚姻状况:"
         Height          =   225
         Left            =   225
         TabIndex        =   17
         Top             =   1350
         Width           =   930
      End
      Begin VB.Label Label7 
         Caption         =   "民族:"
         Height          =   195
         Left            =   4470
         TabIndex        =   16
         Top             =   990
         Width           =   570
      End
      Begin VB.Label Label6 
         Caption         =   "出生年月:"
         Height          =   195
         Left            =   120
         TabIndex        =   15
         Top             =   990
         Width           =   915
      End
      Begin VB.Label Label5 
         Caption         =   "身份证号:"
         Height          =   195
         Left            =   2865
         TabIndex        =   11
         Top             =   630
         Width           =   915
      End
      Begin VB.Label Label4 
         Caption         =   "性别:"
         Height          =   225
         Left            =   420
         TabIndex        =   9
         Top             =   600
         Width           =   570
      End
      Begin VB.Label Label3 
         Caption         =   "照片"
         Height          =   450
         Left            =   7110
         TabIndex        =   8
         Top             =   840
         Width           =   285
      End
      Begin VB.Label Label2 
         Caption         =   "姓名:"
         Height          =   195
         Left            =   3120
         TabIndex        =   7
         Top             =   300
         Width           =   585
      End
      Begin VB.Label Label1 
         Caption         =   "编号:"
         Height          =   195
         Left            =   405
         TabIndex        =   6
         Top             =   300
         Width           =   585
      End
   End
End
Attribute VB_Name = "main_yggl_addmodify"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Explicit
Dim i As Integer     '定义整型变量
Dim rs1 As New ADODB.Recordset     '定义数据集对象
Public photoFilename As String
Dim mst As New ADODB.Stream
Private Sub Form_Activate()
  txt1(1).SetFocus
End Sub
Private Sub Form_Load()
  '在Combo1中添加性别
  Combo1.AddItem ("男")
  Combo1.AddItem ("女")
  Combo1.ListIndex = 0
  '在Combo2中添加民族
  Combo2.AddItem ("汉族")
  Combo2.AddItem ("回族")
  Combo2.AddItem ("满族")
  Combo2.AddItem ("蒙古族")
  Combo2.AddItem ("朝鲜族")
  Combo2.ListIndex = 0
  '在Combo3中添加婚姻状况
  Combo3.AddItem ("未婚")
  Combo3.AddItem ("已婚")
  Combo3.AddItem ("再婚")
  Combo3.ListIndex = 0
  '在Combo4中添加政治面貌
  Combo4.AddItem ("团员")
  Combo4.AddItem ("共产党员")
  Combo4.ListIndex = 0
  '在Combo5中添加最高学历
  Combo5.AddItem ("中专")
  Combo5.AddItem ("高中")
  Combo5.AddItem ("大专")
  Combo5.AddItem ("本科")
  Combo5.AddItem ("硕士研究生")
  Combo5.AddItem ("博士研究生")
  Combo5.ListIndex = 2
  '在Combo6中添加职位
  Combo6.AddItem ("无")
  Combo6.AddItem ("经理")
  Combo6.AddItem ("副经理")
  Combo6.AddItem ("部门经理")
  Combo6.ListIndex = 0
  '在Combo7中添加职称
  Combo7.AddItem ("无")
  Combo7.AddItem ("初级")
  Combo7.AddItem ("中级")
  Combo7.AddItem ("高级")
  Combo7.ListIndex = 0
  If blnAddRS = True Then
    Me.Caption = "添加员工信息"
    rs1.Open "select * from 员工信息表 order by 编号", cnn, adOpenKeyset, adLockOptimistic
    If rs1.RecordCount > 0 Then
       rs1.MoveLast
       txt1(0) = Format(Val(rs1.Fields("编号")) + 1, "00000")
    Else
       txt1(0) = "00001"
    End If
    rs1.Close
  Else
     Me.Caption = "修改员工信息"
     With main_yggl_modify.Adodc1.Recordset
     If .RecordCount > 0 Then
         txt1(0) = .Fields("编号")
         txt1(1) = .Fields("姓名")
         Combo1.Text = .Fields("性别")
         txt1(2) = .Fields("身份证号")
         DTP1.Value = .Fields("出生年月")
         txt1(13) = .Fields("年龄")
         Combo2 = .Fields("民族")
         Combo3 = .Fields("婚姻状况")
         Combo4 = .Fields("政治面貌")
         DTP2.Value = .Fields("入党团时间")
         txt1(3) = .Fields("籍贯")
         txt1(4) = .Fields("联系电话")
         txt1(5) = .Fields("手机号码")
         txt1(6) = .Fields("家庭地址")
         txt1(7) = .Fields("毕业院校")
         txt1(8) = .Fields("专业")
         Combo5 = .Fields("最高学历")
         txt1(9) = .Fields("特长")
         DTP3.Value = .Fields("参加工作时间")
         txt1(10) = .Fields("总工龄")
         Set PicPhoto.DataSource = main_yggl_modify.Adodc1
         PicPhoto.DataField = "照片"
          If .Fields("照片") Is Nothing Then
           PicPhoto.Picture = LoadPicture()
         End If
         DataCombo1 = .Fields("部门")
         Combo6 = .Fields("职务")
         Combo7 = .Fields("职称")
         txt1(11) = .Fields("基本工资")
         DTP4.Value = .Fields("入职时间")
         txt1(12) = .Fields("本单位工龄")
    End If
    End With
  End If
End Sub
Private Sub Combo1_KeyDown(KeyCode As Integer, Shift As Integer)
  If KeyCode = vbKeyReturn Then txt1(2).SetFocus
End Sub
Private Sub Combo2_KeyDown(KeyCode As Integer, Shift As Integer)
  If KeyCode = vbKeyReturn Then Combo3.SetFocus
End Sub

Private Sub Combo3_KeyDown(KeyCode As Integer, Shift As Integer)
  If KeyCode = vbKeyReturn Then Combo4.SetFocus
End Sub

Private Sub Combo4_KeyDown(KeyCode As Integer, Shift As Integer)
  If KeyCode = vbKeyReturn Then DTP2.SetFocus
End Sub

Private Sub Combo5_KeyDown(KeyCode As Integer, Shift As Integer)
  If KeyCode = vbKeyReturn Then txt1(9).SetFocus
End Sub

Private Sub Combo6_KeyDown(KeyCode As Integer, Shift As Integer)
  If KeyCode = vbKeyReturn Then Combo7.SetFocus
End Sub

Private Sub Combo7_KeyDown(KeyCode As Integer, Shift As Integer)
  If KeyCode = vbKeyReturn Then txt1(11).SetFocus
End Sub
Private Sub DataCombo1_KeyDown(KeyCode As Integer, Shift As Integer)
  If KeyCode = vbKeyReturn Then Combo6.SetFocus
End Sub
Private Sub DTP1_Change()
  txt1(13) = DateDiff("yyyy", DTP1.Value, Date)
End Sub
Private Sub DTP1_KeyDown(KeyCode As Integer, Shift As Integer)
  If KeyCode = vbKeyReturn Then Combo2.SetFocus
End Sub
Private Sub DTP2_KeyDown(KeyCode As Integer, Shift As Integer)
  If KeyCode = vbKeyReturn Then txt1(3).SetFocus
End Sub
Private Sub DTP3_Change()
  txt1(10) = Val(Left(Date, 4)) - Val(Left(DTP3, 4))
End Sub
Private Sub DTP3_KeyDown(KeyCode As Integer, Shift As Integer)
  If KeyCode = vbKeyReturn Then txt1(10).SetFocus
End Sub
Private Sub DTP4_KeyDown(KeyCode As Integer, Shift As Integer)
  If KeyCode = vbKeyReturn Then txt1(12).SetFocus
End Sub
Private Sub DTP5_KeyDown(KeyCode As Integer, Shift As Integer)
  If KeyCode = vbKeyReturn Then txt1(16).SetFocus
End Sub
Private Sub PicPhoto_KeyDown(KeyCode As Integer, Shift As Integer)
  If KeyCode = vbKeyReturn Then DTP2.SetFocus
End Sub
Private Sub Txt1_GotFocus(Index As Integer)
  txt1(Index).BackColor = &HFFFF00
  txt1(Index).SelStart = 0
  txt1(Index).SelLength = Len(txt1(Index))
End Sub
Private Sub Txt1_LostFocus(Index As Integer)
  txt1(Index).BackColor = &H80000005
End Sub
Private Sub Txt1_KeyDown(Index As Integer, KeyCode As Integer, Shift As Integer)
  '回车获得焦点
  If KeyCode = vbKeyReturn And Index > 2 And Index < 8 Then txt1(Index + 1).SetFocus
  If KeyCode = vbKeyReturn And Index = 1 Then Combo1.SetFocus
  If KeyCode = vbKeyReturn And Index = 2 Then DTP1.SetFocus
  If KeyCode = vbKeyReturn And Index = 8 Then Combo5.SetFocus
  If KeyCode = vbKeyReturn And Index = 9 Then DTP3.SetFocus
  If KeyCode = vbKeyReturn And Index = 10 Then DataCombo1.SetFocus
  If KeyCode = vbKeyReturn And Index = 11 Then DTP4.SetFocus
  If KeyCode = vbKeyReturn And Index = 12 Then CmdSave.SetFocus
End Sub
Private Sub cmdPhotoAdd_Click()
  With CommonDialog1
       .DialogTitle = "选择要加入的职工相片"      '设置对话框标题栏上的文字
       .Filter = "jpg图片|*.jpg"          '设置文件类型
       .ShowOpen            '显示"打开"对话框
       PicPhoto.Picture = LoadPicture(.FileName)     '显示照片
       photoFilename = .FileName         '给变量photoFilename赋值
  End With
End Sub

Private Sub CmdSave_Click()
  Dim A As Long              '定义长整型变量
  If blnAddRS = False Then            '标记为False,修改状态
    A = MsgBox("您确实要修改这条数据吗?", vbYesNo)     '弹出提示框
    If A = vbYes Then             '如果单击"是"按钮
     '按"编号"检索数据
     rs1.Open "select * from 员工信息表 where 编号='" + txt1(0).Text + "'", cnn, adOpenKeyset, adLockOptimistic
   '如果数据存在,则修改它,将控件中的数据依依赋值给相应的字段
   If rs1.RecordCount > 0 Then
    rs1.Fields("编号") = txt1(0)
    rs1.Fields("姓名") = txt1(1)
    rs1.Fields("性别") = Combo1.Text
    rs1.Fields("身份证号") = txt1(2)
    rs1.Fields("出生年月") = DTP1.Value
    rs1.Fields("年龄") = Val(txt1(13))
    rs1.Fields("民族") = Combo2
    rs1.Fields("婚姻状况") = Combo3
    rs1.Fields("政治面貌") = Combo4
    rs1.Fields("入党团时间") = DTP2.Value
    rs1.Fields("籍贯") = txt1(3)
    rs1.Fields("联系电话") = txt1(4)
    rs1.Fields("手机号码") = txt1(5)
    rs1.Fields("家庭地址") = txt1(6)
    rs1.Fields("毕业院校") = txt1(7)
    rs1.Fields("专业") = txt1(8)
    rs1.Fields("最高学历") = Combo5
    rs1.Fields("特长") = txt1(9)
    rs1.Fields("参加工作时间") = DTP3.Value
    rs1.Fields("总工龄") = Val(txt1(10))
    mst.Type = adTypeBinary
    mst.Open
    If photoFilename <> "" Then mst.LoadFromFile photoFilename
    rs1.Fields("照片") = mst.Read
    rs1.Fields("部门") = DataCombo1
    rs1.Fields("职务") = Combo6
    rs1.Fields("职称") = Combo7
    rs1.Fields("基本工资") = Val(txt1(11))
    rs1.Fields("入职时间") = DTP4.Value
    rs1.Fields("本单位工龄") = Val(txt1(12))
    rs1.Update          '更新表中数据
    rs1.Close           '关闭数据集对象
    mst.Close          '关闭Stream对象
    main_yggl_modify.Adodc1.Refresh     '刷新数据表
    Unload Me          '卸载窗体
   End If
   End If
  Else            '标记为True,添加状态
    If txt1(1).Text = "" Then       '如果姓名为空
       MsgBox "姓名不允许为空!"     '则弹出提示框
       Exit Sub
    End If
    '添加新员工,将控件中的数据依依赋值给相应的字段
    rs1.Open "select * from 员工信息表", cnn, adOpenKeyset, adLockOptimistic
    rs1.AddNew          '添加新记录
    rs1.Fields("编号") = txt1(0)
    rs1.Fields("姓名") = txt1(1)
    rs1.Fields("性别") = Combo1.Text
    rs1.Fields("身份证号") = txt1(2)
    rs1.Fields("出生年月") = DTP1.Value
    rs1.Fields("年龄") = Val(txt1(13))
    rs1.Fields("民族") = Combo2
    rs1.Fields("婚姻状况") = Combo3
    rs1.Fields("政治面貌") = Combo4
    rs1.Fields("入党团时间") = DTP2.Value
    rs1.Fields("籍贯") = txt1(3)
    rs1.Fields("联系电话") = txt1(4)
    rs1.Fields("手机号码") = txt1(5)
    rs1.Fields("家庭地址") = txt1(6)
    rs1.Fields("毕业院校") = txt1(7)
    rs1.Fields("专业") = txt1(8)
    rs1.Fields("最高学历") = Combo5
    rs1.Fields("特长") = txt1(9)
    rs1.Fields("参加工作时间") = DTP3.Value
    rs1.Fields("总工龄") = Val(txt1(10))
    mst.Type = adTypeBinary
    mst.Open
    If photoFilename <> "" Then mst.LoadFromFile photoFilename
    rs1.Fields("照片") = mst.Read
    rs1.Fields("部门") = DataCombo1
    rs1.Fields("职务") = Combo6
    rs1.Fields("职称") = Combo7
    rs1.Fields("基本工资") = Val(txt1(11))
    rs1.Fields("入职时间") = DTP4.Value
    rs1.Fields("本单位工龄") = Val(txt1(12))
    rs1.Update              '保存记录
    rs1.Close               '关闭数据集对象
    mst.Close              '关闭Stream对象
    '数据添加完后,继续添加新数据,自动生成编号,初始化控件
    rs1.Open "select * from 员工信息表 order by 编号", cnn, adOpenKeyset, adLockOptimistic
    If rs1.RecordCount > 0 Then           '如果表中有记录
       rs1.MoveLast             '则将记录指针移到最后
       txt1(0) = Format(Val(rs1.Fields("编号")) + 1, "00000")    '设置编号
    Else                '如果表中没有记录
       txt1(0) = "00001"            '设置第一个默认编号为"00001"
    End If
    rs1.Close               '关闭数据集对象
    '清空文本框中的数据
    For i = 1 To txt1.UBound - 1
      txt1(i).Text = ""
    Next i
  End If
End Sub
Private Sub CmdEnd_Click()
  Unload Me
End Sub


⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -