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

📄 frm_empman.frm

📁 vb与access数据库的操作实例
💻 FRM
字号:
VERSION 5.00
Object = "{67397AA1-7FB1-11D0-B148-00A0C922E820}#6.0#0"; "MSADODC.OCX"
Object = "{CDE57A40-8B86-11D0-B3C6-00A0C90AEA82}#1.0#0"; "MSDATGRD.OCX"
Begin VB.Form Frm_EmpMan 
   BorderStyle     =   1  'Fixed Single
   Caption         =   "房间信息管理"
   ClientHeight    =   5655
   ClientLeft      =   45
   ClientTop       =   330
   ClientWidth     =   10305
   LinkTopic       =   "Form1"
   LockControls    =   -1  'True
   MaxButton       =   0   'False
   MinButton       =   0   'False
   ScaleHeight     =   5655
   ScaleWidth      =   10305
   StartUpPosition =   1  '所有者中心
   Begin MSDataGridLib.DataGrid DataGrid1 
      Bindings        =   "Frm_EmpMan.frx":0000
      Height          =   4335
      Left            =   240
      TabIndex        =   4
      Top             =   240
      Width           =   9855
      _ExtentX        =   17383
      _ExtentY        =   7646
      _Version        =   393216
      AllowUpdate     =   0   'False
      HeadLines       =   1
      RowHeight       =   15
      BeginProperty HeadFont {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
         Name            =   "宋体"
         Size            =   9
         Charset         =   134
         Weight          =   400
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      BeginProperty Font {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
         Name            =   "宋体"
         Size            =   9
         Charset         =   134
         Weight          =   400
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      ColumnCount     =   2
      BeginProperty Column00 
         DataField       =   ""
         Caption         =   ""
         BeginProperty DataFormat {6D835690-900B-11D0-9484-00A0C91110ED} 
            Type            =   0
            Format          =   ""
            HaveTrueFalseNull=   0
            FirstDayOfWeek  =   0
            FirstWeekOfYear =   0
            LCID            =   2052
            SubFormatType   =   0
         EndProperty
      EndProperty
      BeginProperty Column01 
         DataField       =   ""
         Caption         =   ""
         BeginProperty DataFormat {6D835690-900B-11D0-9484-00A0C91110ED} 
            Type            =   0
            Format          =   ""
            HaveTrueFalseNull=   0
            FirstDayOfWeek  =   0
            FirstWeekOfYear =   0
            LCID            =   2052
            SubFormatType   =   0
         EndProperty
      EndProperty
      SplitCount      =   1
      BeginProperty Split0 
         BeginProperty Column00 
         EndProperty
         BeginProperty Column01 
         EndProperty
      EndProperty
   End
   Begin VB.CommandButton Cmd_Close 
      Caption         =   "退 出"
      Height          =   495
      Left            =   7320
      TabIndex        =   3
      Top             =   4920
      Width           =   1215
   End
   Begin VB.CommandButton Cmd_Del 
      Caption         =   "删 除"
      Height          =   495
      Left            =   5582
      TabIndex        =   2
      Top             =   4920
      Width           =   1215
   End
   Begin VB.CommandButton Cmd_Modi 
      Caption         =   "修 改"
      Height          =   495
      Left            =   3845
      TabIndex        =   1
      Top             =   4920
      Width           =   1215
   End
   Begin VB.CommandButton Cmd_Add 
      Caption         =   "添 加"
      Height          =   495
      Left            =   2108
      TabIndex        =   0
      Top             =   4920
      Width           =   1215
   End
   Begin MSAdodcLib.Adodc Adodc1 
      Height          =   375
      Left            =   0
      Top             =   0
      Visible         =   0   'False
      Width           =   2175
      _ExtentX        =   3836
      _ExtentY        =   661
      ConnectMode     =   0
      CursorLocation  =   3
      IsolationLevel  =   -1
      ConnectionTimeout=   15
      CommandTimeout  =   30
      CursorType      =   3
      LockType        =   3
      CommandType     =   8
      CursorOptions   =   0
      CacheSize       =   50
      MaxRecords      =   0
      BOFAction       =   0
      EOFAction       =   0
      ConnectStringType=   1
      Appearance      =   1
      BackColor       =   -2147483643
      ForeColor       =   -2147483640
      Orientation     =   0
      Enabled         =   -1
      Connect         =   "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=人事.mdb;Mode=ReadWrite;Persist Security Info=False"
      OLEDBString     =   "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=人事.mdb;Mode=ReadWrite;Persist Security Info=False"
      OLEDBFile       =   ""
      DataSourceName  =   ""
      OtherAttributes =   ""
      UserName        =   ""
      Password        =   ""
      RecordSource    =   "SELECT * FROM Employees"
      Caption         =   "Adodc1"
      BeginProperty Font {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
         Name            =   "宋体"
         Size            =   9
         Charset         =   134
         Weight          =   400
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      _Version        =   393216
   End
End
Attribute VB_Name = "Frm_EmpMan"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Private Sub RefreshData()
  '设置数据源
  Adodc1.RecordSource = "SELECT e.EmpId, e.EmpName As 员工姓名, e.Sex As 性别," _
            + " e.Title As 职务, e.Age As 年龄, e.Office_phone As 办公电话," _
            + " e.Mobile_phone As 移动电话, e.Salary As 工资, d.DepName As 部门名称" _
            + " FROM Employees e, Departments d WHERE e.DepId=d.DepId" _
            + " ORDER BY e.DepId"
  '刷新结果集
  Adodc1.Refresh
  '设置列宽度
  With DataGrid1
  .Columns(0).Width = 0
  .Columns(1).Width = 800
  .Columns(2).Width = 800
  .Columns(3).Width = 800
  .Columns(4).Width = 800
  .Columns(5).Width = 1500
  .Columns(6).Width = 2000
  .Columns(7).Width = 1200
  .Columns(8).Width = 1200
  End With
End Sub

Private Sub Cmd_Add_Click()
  With Frm_EmpEdit
  .Modify = False
  .Show 1
  End With
  '修改数据后刷新显示
  RefreshData
End Sub

Private Sub Cmd_Close_Click()
  End
End Sub

Private Sub Cmd_Del_Click()
  Dim TmpId As String   '保存选择的记录编号
  Dim Pos As Integer    '保存当前记录的位置
  
  If Adodc1.Recordset.EOF = True Then
    MsgBox "请选择要删除的记录"
    Exit Sub
  End If
  '保存当前的记录位置
  Pos = Adodc1.Recordset.AbsolutePosition
  '读取要删除数据的编号
  TmpId = Trim(Adodc1.Recordset.Fields(0))
  If MsgBox("是否删除当前行?", vbYesNo, "请确认") = vbYes Then
    MyEmp.Delete (TmpId)
    MsgBox ("数据已删除")
    '修改数据后刷新显示
    RefreshData

    '将光标移动到前一个记录或后一个记录
    If Pos - 2 >= 0 Then
      Adodc1.Recordset.Move Pos - 2
    Else
      If Pos - 1 < Adodc1.Recordset.RecordCount Then
        Adodc1.Recordset.Move Pos - 1
      End If
    End If
  End If
End Sub

Private Sub Cmd_Modi_Click()
  Dim Pos As Integer
  '判断是否选择了有效的数据
  If Adodc1.Recordset.EOF = True Then
    MsgBox "请选择要修改的记录"
    Exit Sub
  End If
  
  Adodc1.RecordSource = "SELECT e.EmpId, e.EmpName As 员工姓名, e.Sex As 性别," _
            + " e.Title As 职务, e.Age As 年龄, e.Office_phone As 办公电话," _
            + " e.Mobile_phone As 移动电话, e.Sallary As 工资, d.DepName As 部门名称" _
  
  '保存当前的记录位置
  Pos = Adodc1.Recordset.AbsolutePosition
  With Frm_EmpEdit
  '设置修改状态
  .Modify = True
  '设置OriId
  .OriId = Adodc1.Recordset.Fields(0)
  '读取员工姓名
  .txtEmpName = Trim(Adodc1.Recordset.Fields(1))
  '读取性别
  If InCombo(Trim(Adodc1.Recordset.Fields(2)), .cboSex) = True Then
    .cboSex.Text = Trim(Adodc1.Recordset.Fields(2))
  End If
  '读取职务
  .txtTitle = Trim(Adodc1.Recordset.Fields(3))
  '读取年龄
  .txtAge = Adodc1.Recordset.Fields(4)
  '读取办公电话
  If Trim(Adodc1.Recordset.Fields(5)) <> "" Then
    .txtOffice = Trim(Adodc1.Recordset.Fields(5))
  End If
  '读取移动电话
  If Trim(Adodc1.Recordset.Fields(6)) <> "" Then
    .txtMobile = Trim(Adodc1.Recordset.Fields(6))
  End If
  '工资
  .txtSallary = Adodc1.Recordset.Fields(7)
  '部门名称
  .DataCombo1.Text = Trim(Adodc1.Recordset.Fields(8))
  '启动房间信息编辑窗体
  .Show 1
  End With
  '修改数据后刷新显示
  RefreshData
  '恢复到回来的位置
  Adodc1.Recordset.Move Pos - 1
End Sub

Private Sub Form_Load()
  RefreshData
End Sub

⌨️ 快捷键说明

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