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

📄 empinput.frm

📁 汽车维修管理软件。其中包含三个编辑控件。
💻 FRM
字号:
VERSION 5.00
Object = "{831FDD16-0C5C-11D2-A9FC-0000F8754DA1}#2.0#0"; "MSCOMCTL.OCX"
Begin VB.Form EmpInput 
   BorderStyle     =   1  'Fixed Single
   Caption         =   "员工、维修人员档案"
   ClientHeight    =   6525
   ClientLeft      =   1380
   ClientTop       =   1485
   ClientWidth     =   9675
   LinkTopic       =   "Form1"
   MaxButton       =   0   'False
   MDIChild        =   -1  'True
   MinButton       =   0   'False
   ScaleHeight     =   6525
   ScaleWidth      =   9675
   Begin VB.TextBox EmpName 
      Height          =   270
      Left            =   7080
      MaxLength       =   50
      TabIndex        =   3
      Top             =   1920
      Width           =   2415
   End
   Begin VB.TextBox EmpCode 
      Height          =   270
      Left            =   7080
      MaxLength       =   10
      TabIndex        =   2
      Top             =   1320
      Width           =   2415
   End
   Begin MSComctlLib.ImageList ImageList 
      Left            =   0
      Top             =   1080
      _ExtentX        =   1005
      _ExtentY        =   1005
      BackColor       =   -2147483643
      ImageWidth      =   16
      ImageHeight     =   15
      MaskColor       =   12632256
      _Version        =   393216
      BeginProperty Images {2C247F25-8591-11D1-B16A-00C0F0283628} 
         NumListImages   =   8
         BeginProperty ListImage1 {2C247F27-8591-11D1-B16A-00C0F0283628} 
            Picture         =   "EmpInput.frx":0000
            Key             =   ""
         EndProperty
         BeginProperty ListImage2 {2C247F27-8591-11D1-B16A-00C0F0283628} 
            Picture         =   "EmpInput.frx":0542
            Key             =   ""
         EndProperty
         BeginProperty ListImage3 {2C247F27-8591-11D1-B16A-00C0F0283628} 
            Picture         =   "EmpInput.frx":0A84
            Key             =   ""
         EndProperty
         BeginProperty ListImage4 {2C247F27-8591-11D1-B16A-00C0F0283628} 
            Picture         =   "EmpInput.frx":0FC6
            Key             =   ""
         EndProperty
         BeginProperty ListImage5 {2C247F27-8591-11D1-B16A-00C0F0283628} 
            Picture         =   "EmpInput.frx":1418
            Key             =   ""
         EndProperty
         BeginProperty ListImage6 {2C247F27-8591-11D1-B16A-00C0F0283628} 
            Picture         =   "EmpInput.frx":152A
            Key             =   ""
         EndProperty
         BeginProperty ListImage7 {2C247F27-8591-11D1-B16A-00C0F0283628} 
            Picture         =   "EmpInput.frx":1A6C
            Key             =   ""
         EndProperty
         BeginProperty ListImage8 {2C247F27-8591-11D1-B16A-00C0F0283628} 
            Picture         =   "EmpInput.frx":1FAE
            Key             =   ""
         EndProperty
      EndProperty
   End
   Begin MSComctlLib.Toolbar Toolbar 
      Align           =   1  'Align Top
      Height          =   615
      Left            =   0
      TabIndex        =   0
      Top             =   0
      Width           =   9675
      _ExtentX        =   17066
      _ExtentY        =   1085
      ButtonWidth     =   820
      ButtonHeight    =   926
      AllowCustomize  =   0   'False
      Appearance      =   1
      ImageList       =   "ImageList"
      _Version        =   393216
      BeginProperty Buttons {66833FE8-8583-11D1-B16A-00C0F0283628} 
         NumButtons      =   12
         BeginProperty Button1 {66833FEA-8583-11D1-B16A-00C0F0283628} 
            Caption         =   "打印"
            ImageIndex      =   1
         EndProperty
         BeginProperty Button2 {66833FEA-8583-11D1-B16A-00C0F0283628} 
            Caption         =   "预览"
            ImageIndex      =   2
         EndProperty
         BeginProperty Button3 {66833FEA-8583-11D1-B16A-00C0F0283628} 
            Style           =   4
         EndProperty
         BeginProperty Button4 {66833FEA-8583-11D1-B16A-00C0F0283628} 
            Caption         =   "增加"
            ImageIndex      =   3
         EndProperty
         BeginProperty Button5 {66833FEA-8583-11D1-B16A-00C0F0283628} 
            Caption         =   "修改"
            ImageIndex      =   4
         EndProperty
         BeginProperty Button6 {66833FEA-8583-11D1-B16A-00C0F0283628} 
            Caption         =   "删除"
            ImageIndex      =   5
         EndProperty
         BeginProperty Button7 {66833FEA-8583-11D1-B16A-00C0F0283628} 
            Caption         =   "放弃"
            ImageIndex      =   6
         EndProperty
         BeginProperty Button8 {66833FEA-8583-11D1-B16A-00C0F0283628} 
            Caption         =   "保存"
            ImageIndex      =   7
         EndProperty
         BeginProperty Button9 {66833FEA-8583-11D1-B16A-00C0F0283628} 
            Style           =   3
         EndProperty
         BeginProperty Button10 {66833FEA-8583-11D1-B16A-00C0F0283628} 
            Caption         =   "过滤"
            ImageIndex      =   8
         EndProperty
         BeginProperty Button11 {66833FEA-8583-11D1-B16A-00C0F0283628} 
            Style           =   4
         EndProperty
         BeginProperty Button12 {66833FEA-8583-11D1-B16A-00C0F0283628} 
            Caption         =   "退出"
         EndProperty
      EndProperty
      BorderStyle     =   1
   End
   Begin MSComctlLib.TreeView m_Tree 
      Height          =   5775
      Left            =   0
      TabIndex        =   1
      Top             =   720
      Width           =   5895
      _ExtentX        =   10398
      _ExtentY        =   10186
      _Version        =   393217
      LabelEdit       =   1
      Style           =   7
      Appearance      =   1
   End
   Begin VB.Label NameLabel 
      Caption         =   "人员姓名"
      Height          =   255
      Left            =   6120
      TabIndex        =   5
      Top             =   1920
      Width           =   855
   End
   Begin VB.Label CodeLabel 
      Caption         =   "人员编号"
      Height          =   255
      Left            =   6120
      TabIndex        =   4
      Top             =   1320
      Width           =   855
   End
End
Attribute VB_Name = "EmpInput"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Private m_DoMode As WorkMode
Private m_OldCode As String
Private m_OldName As String
Event EndWindow()
Private Sub ShowData()
Dim ObjNode As Node
Dim re As ADODB.Recordset
m_Tree.Nodes.Clear
If g_Conn Is Nothing Then
Set g_Conn = New ADODB.Connection
With g_Conn
    .Provider = g_Provider
    .CommandTimeout = 7
    .ConnectionTimeout = 10
    .Open g_DataSource
End With
End If
If g_Conn.State = adStateClosed Then
   g_Conn.Open g_DataSource
End If
Set ObjNode = m_Tree.Nodes.Add(, , "r", "维修人员档案")
Set re = g_Conn.Execute("SELECT Code,Name FROM Employees ORDER BY Code")
If Not (re.BOF And re.EOF) Then re.MoveFirst
While Not re.EOF
    m_Tree.Nodes.Add "r", tvwChild, "r" & re.Fields(0).Value, re.Fields(0).Value _
                      & "  " & re.Fields(1).Value
    re.MoveNext
Wend
Set re = Nothing
m_Tree.Nodes.Item(1).Expanded = True
End Sub


Private Sub Form_Load()
EmpCode.Locked = True
EmpName.Locked = True
Toolbar.Buttons(8).Enabled = False
ShowData
End Sub

Private Sub Form_Unload(Cancel As Integer)
RaiseEvent EndWindow
End Sub
Private Sub m_Tree_Click()
Dim FindCode As String
Dim re As ADODB.Recordset
FindCode = Right$(m_Tree.SelectedItem.Key, Len(m_Tree.SelectedItem.Key) - 1)
If FindCode <> "" Then
   Set re = SQLFind(FindCode, "Employees", "Code", FT_CHAR)
   If Not (re.BOF And re.EOF) Then
      m_OldCode = re.Fields(1).Value
      m_OldName = re.Fields(2).Value
      EmpCode.Text = m_OldCode
      EmpName.Text = m_OldName
   Else
      Dim SelectNode As Node
      MsgBox "该记录已被删除", vbInformation Or vbOKOnly, "提示"
      m_Tree.Nodes.Remove m_Tree.SelectedItem.Index
      EmpCode.Text = ""
      EmpName.Text = ""
      End If
 '     Set re = Nothing
End If
End Sub

Private Sub Toolbar_ButtonClick(ByVal Button As MSComctlLib.Button)
Select Case Button.Index
       Case 1 'Print
       Case 2 'PrintViwe
       Case 4 'Add
             Button.Enabled = False
             Toolbar.Buttons(8).Enabled = True
             Toolbar.Buttons(5).Enabled = False
             Toolbar.Buttons(6).Enabled = False
             m_Tree.Enabled = False
             SetEditState False
             EmpCode.Text = ""
             EmpName.Text = ""
             m_DoMode = WM_ADD
             EmpCode.SetFocus
       Case 5 'Edit
             Button.Enabled = False
             Toolbar.Buttons(4).Enabled = False
             Toolbar.Buttons(6).Enabled = False
             Toolbar.Buttons(8).Enabled = True
             m_Tree.Enabled = False
             SetEditState False
             m_DoMode = WM_EDIT
             EmpCode.SetFocus
       Case 6 'Delete
            m_DoMode = WM_DELETE
            Delete
            ShowData
       Case 7 'Esc
            m_DoMode = WM_NOTHING
            Toolbar.Buttons(4).Enabled = True
            Toolbar.Buttons(5).Enabled = True
            Toolbar.Buttons(6).Enabled = True
            Toolbar.Buttons(8).Enabled = False
            m_Tree.Enabled = True
            ShowData
       Case 8 'Save
            If Save() Then
               Button.Enabled = False
               Toolbar.Buttons(4).Enabled = True
               Toolbar.Buttons(5).Enabled = True
               Toolbar.Buttons(6).Enabled = True
               m_Tree.Enabled = True
               SetEditState True
            End If
       Case 10 'Find
       Case 12 'Exit
           Unload Me
End Select
End Sub
Private Sub SetEditState(ByVal pState As Boolean)
EmpCode.Locked = pState
EmpName.Locked = pState
End Sub
Private Function Save() As Boolean
Dim TempCode As String, TempName As String
Dim comm As ADODB.Command
Dim t_emp As TEmployees
TempCode = Trim$(EmpCode.Text)
If TempCode = "" Then
   MsgBox "人员编号不能为空", vbCritical Or vbOKOnly, "错误"
   EmpCode.SetFocus
   Save = False
   Exit Function
End If
Set t_emp = New TEmployees
If Not t_emp.Find(m_OldCode, Find_From_Code) Then
   Save = False
   Exit Function
End If
If Not SQLFindIsNull(t_emp.Id, "WorkMain", "EmpId", FT_NUMBER) Then
   If (TempCode <> m_OldCode And m_DoMode = WM_EDIT) Or m_DoMode = WM_ADD Then
       MsgBox "该人员以使用,故不能修改", vbCritical Or vbOKOnly, "错误"
      ' EmpCode.SetFocus
       Exit Function
   End If
End If
Set t_emp = Nothing
TempName = Trim$(EmpName.Text)
If TempName = "" Then
   MsgBox "人员姓名不能为空", vbCritical Or vbOKOnly, "错误"
   EmpName.SetFocus
   Save = False
   Exit Function
End If
If Not SQLFindIsNull(TempCode, "Employees", "Code", FT_CHAR) Then
   If (TempCode <> m_OldCode And m_DoMode = WM_EDIT) Or m_DoMode = WM_ADD Then
       MsgBox "维修人员代码重复", vbCritical Or vbOKOnly, "错误"
       EmpCode.SetFocus
       Exit Function
   End If
End If
If Not SQLFindIsNull(TempName, "Employees", "Name", FT_CHAR) Then
   If (TempName <> m_OldName And m_DoMode = WM_EDIT) Or m_DoMode = WM_ADD Then
       MsgBox "维修人员名称重复", vbCritical Or vbOKOnly, "错误"
       EmpName.SetFocus
       Exit Function
   End If
End If

If g_Conn Is Nothing Then
Set g_Conn = New ADODB.Connection
With g_Conn
    .Provider = g_Provider
    .CommandTimeout = 7
    .ConnectionTimeout = 10
    .Open g_DataSource
End With
End If
If g_Conn.State = adStateClosed Then
   g_Conn.Open g_DataSource
End If
Set comm = New ADODB.Command
comm.CommandType = adCmdText
comm.ActiveConnection = g_Conn
Select Case m_DoMode
     Case WM_ADD
          comm.CommandText = "INSERT INTO Employees (Code,Name) VALUES ('" _
                             & TempCode & "','" & TempName & "')"
     Case WM_EDIT
          comm.CommandText = "UPDATE Employees SET Code='" & TempCode _
                              & "',Name='" & TempName & "' WHERE Code='" & m_OldCode & "'"
End Select
On Error GoTo EmpSaveErr
comm.Execute , , adExecuteNoRecords
Save = True
ShowData
m_Tree.Nodes.Item(1).Expanded = True
Exit Function
EmpSaveErr:
MsgBox "数据保存错误", vbCritical Or vbOKOnly, "错误"
Save = False
End Function
Private Sub Delete()
If m_OldCode <> "" Then
   Dim t_emp As New TEmployees
   If t_emp.Find(m_OldCode, Find_From_Code) Then
      If Not SQLFindIsNull(t_emp.Id, "WorkMain", "EmpId", FT_NUMBER) Then
          MsgBox "该人员以使用,故不能删除", vbCritical Or vbOKOnly, "错误"
         Exit Sub
      Else
         Dim comm As ADODB.Command
         If g_Conn Is Nothing Then
            Set g_Conn = New ADODB.Connection
            With g_Conn
                .Provider = g_Provider
                .CommandTimeout = 7
                .ConnectionTimeout = 10
                .Open g_DataSource
            End With
         End If
         If g_Conn.State = adStateClosed Then
            g_Conn.Open g_DataSource
         End If
         Set comm = New ADODB.Command
         comm.CommandType = adCmdText
         comm.ActiveConnection = g_Conn
         comm.CommandText = "DELETE Employees WHERE AutoId=" & CStr(t_emp.Id) '问题在啦里
         comm.Execute , , adExecuteNoRecords
         Set comm = Nothing
      End If
   End If
Else
   MsgBox "请选择要删除的员工项目", vbCritical Or vbOKOnly, "错误"
End If
End Sub

⌨️ 快捷键说明

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