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

📄 frmdevice.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 FrmDevice 
   Caption         =   "设备管理"
   ClientHeight    =   4785
   ClientLeft      =   60
   ClientTop       =   345
   ClientWidth     =   8940
   LinkTopic       =   "Form1"
   ScaleHeight     =   4785
   ScaleWidth      =   8940
   StartUpPosition =   2  '屏幕中心
   Begin VB.CommandButton Cmd_Reset 
      Caption         =   "重 置"
      Height          =   375
      Left            =   3720
      TabIndex        =   8
      Top             =   80
      Width           =   855
   End
   Begin VB.CommandButton Cmd_Search 
      Caption         =   "查 找"
      Height          =   375
      Left            =   2520
      TabIndex        =   7
      Top             =   80
      Width           =   855
   End
   Begin VB.CommandButton Cmd_Exit 
      Caption         =   "退 出"
      Height          =   375
      Left            =   7320
      TabIndex        =   6
      Top             =   4320
      Width           =   1095
   End
   Begin VB.CommandButton Cmd_Del 
      Caption         =   "删 除"
      Height          =   375
      Left            =   5040
      TabIndex        =   5
      Top             =   4320
      Width           =   1095
   End
   Begin VB.CommandButton Cmd_Modi 
      Caption         =   "修 改"
      Height          =   375
      Left            =   2760
      TabIndex        =   4
      Top             =   4320
      Width           =   1095
   End
   Begin VB.CommandButton Cmd_Add 
      Caption         =   "添 加"
      Height          =   375
      Left            =   480
      TabIndex        =   3
      Top             =   4320
      Width           =   1095
   End
   Begin VB.TextBox txtName 
      Height          =   270
      Left            =   1200
      TabIndex        =   2
      Top             =   120
      Width           =   975
   End
   Begin MSAdodcLib.Adodc Adodc1 
      Height          =   375
      Left            =   0
      Top             =   4440
      Visible         =   0   'False
      Width           =   2055
      _ExtentX        =   3625
      _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         =   ""
      OLEDBString     =   ""
      OLEDBFile       =   ""
      DataSourceName  =   ""
      OtherAttributes =   ""
      UserName        =   ""
      Password        =   ""
      RecordSource    =   ""
      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
   Begin MSDataGridLib.DataGrid DataGrid1 
      Height          =   3735
      Left            =   120
      TabIndex        =   0
      Top             =   480
      Width           =   8655
      _ExtentX        =   15266
      _ExtentY        =   6588
      _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 
         MarqueeStyle    =   3
         AllowRowSizing  =   -1  'True
         AllowSizing     =   -1  'True
         BeginProperty Column00 
         EndProperty
         BeginProperty Column01 
         EndProperty
      EndProperty
   End
   Begin VB.Label Label1 
      AutoSize        =   -1  'True
      Caption         =   "设备名称"
      Height          =   180
      Left            =   240
      TabIndex        =   1
      Top             =   120
      Width           =   720
   End
End
Attribute VB_Name = "FrmDevice"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Private SchCnd As String
Private Sub Cmd_Add_Click()
  '将Modify变量设置为False,表示当前状态为插入新记录
  FrmDeviceEdit.Modify = False
  FrmDeviceEdit.iFlag = 1 '为设备添加
  '初始化FrmDeviceEdit信息
  FrmDeviceEdit.txtId = ""              '设备编号
  FrmDeviceEdit.txtName = ""            '设备名称
  FrmDeviceEdit.txtModel = ""           '设备型号
  FrmDeviceEdit.dco_TypeId.Text = ""    '分类名称
  FrmDeviceEdit.txtPrice = 0            '单价
  FrmDeviceEdit.txtCount = 1            '数量
  FrmDeviceEdit.cob_Unit.Text = ""      '计量单位
  FrmDeviceEdit.txtCreateDate = Date                  '设置创建日期为当前日期
  FrmDeviceEdit.txtUserName = Trim(CurUser.UserName)  '读取当前用户名
  FrmDeviceEdit.txtCount.Enabled = False              '设备数量等于1,不能更改
  '启动编辑窗体
  FrmDeviceEdit.Show 1
  '刷新DataGrid表格的内容
  GridRefresh
End Sub

Private Sub Cmd_Del_Click()
  If Adodc1.Recordset.EOF = True Then
    MsgBox "请选择记录"
    Exit Sub
  End If
  If MsgBox("是否确定要删除 ", vbYesNo, "请确认") = vbNo Then
    Exit Sub
  End If
  MyDevice.Delete (Trim(Adodc1.Recordset.Fields(0)))  '删除设备信息
  GridRefresh  '刷新DataGrid表格的内容
End Sub

Private Sub Cmd_Exit_Click()
  Unload Me
End Sub

Private Sub GridRefresh()
  '判断是否有查询字段
  If Len(Trim(txtName)) = 0 Then
    SchCnd = ""
  Else   '设置查询条件
    SchCnd = " AND d.Name Like '%" + Trim(txtName) + "%'"
  End If
  Adodc1.ConnectionString = Conn    '设置连接字符串
  Adodc1.RecordSource = "SELECT d.Id AS 编号,d.Name AS 设备名称," _
     + "d.Model AS 设备型号,t.TypeName AS 分类,d.Price AS 单价," _
     + "d.DCount AS 数量,(d.Price*d.DCount) AS 总额,d.Unit AS 单位," _
     + "d.CreateDate AS 登记日期,d.Poster AS 登记人 " _
     + " FROM Device d,Types t WHERE d.TypeId=t.Id AND d.Flag=1 " _
     + SchCnd + " ORDER BY d.Id"
  Adodc1.Refresh
  Set DataGrid1.DataSource = Adodc1  '设置数据源
  DataGrid1.Columns(0).Width = 800   '设置列宽度
  DataGrid1.Columns(1).Width = 1200
  DataGrid1.Columns(2).Width = 1200
  DataGrid1.Columns(3).Width = 1200
  DataGrid1.Columns(4).Width = 1200
  DataGrid1.Columns(5).Width = 1000
  DataGrid1.Columns(6).Width = 1200
  DataGrid1.Columns(7).Width = 800
  DataGrid1.Columns(8).Width = 1200
  DataGrid1.Columns(9).Width = 1200
End Sub
  '修改
Private Sub Cmd_Modi_Click()
  If Adodc1.Recordset.EOF = True Then
    MsgBox "请选择记录"
    Exit Sub
  End If
  '将Modify变量设置为False,表示当前状态为插入新记录
  FrmDeviceEdit.Modify = True
  FrmDeviceEdit.iFlag = 1  '表示修改设备信息
  '初始化FrmDeviceEdit信息
  FrmDeviceEdit.OriId = Trim(Adodc1.Recordset.Fields(0))  '设备编号
  FrmDeviceEdit.txtId = Trim(Adodc1.Recordset.Fields(0))  '设备编号
  FrmDeviceEdit.txtName = Trim(Adodc1.Recordset.Fields(1)) '设备名称
  FrmDeviceEdit.txtModel = Trim(Adodc1.Recordset.Fields(2)) '设备型号
  FrmDeviceEdit.dco_TypeId.Text = Trim(Adodc1.Recordset.Fields(3)) '分类编号
  FrmDeviceEdit.txtPrice = Trim(Adodc1.Recordset.Fields(4))  '单价
  FrmDeviceEdit.txtCount = 1                                '数量
  FrmDeviceEdit.cob_Unit.Text = Trim(Adodc1.Recordset.Fields(7)) '计量单位
  FrmDeviceEdit.txtCreateDate = Trim(Adodc1.Recordset.Fields(8)) '创建时间
  FrmDeviceEdit.txtUserName = Trim(Adodc1.Recordset.Fields(9))   '创建人
  '编辑时设备编号和数量不能更改
  FrmDeviceEdit.txtId.Enabled = False
  FrmDeviceEdit.txtCount.Enabled = False
  '启动编辑窗体
  FrmDeviceEdit.Show 1
  GridRefresh '刷新DataGrid表格的内容
End Sub

Private Sub Cmd_Reset_Click()
  SchCnd = ""
  GridRefresh
End Sub

Private Sub Cmd_Search_Click()
  GridRefresh
End Sub

Private Sub Form_Load()
  GridRefresh
End Sub

⌨️ 快捷键说明

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