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

📄 formpec.frm

📁 运输管理系统
💻 FRM
📖 第 1 页 / 共 2 页
字号:
         Left            =   3240
         TabIndex        =   5
         Top             =   2760
         Width           =   1215
      End
      Begin VB.ComboBox CmbCarID 
         Height          =   300
         Left            =   -73440
         Style           =   2  'Dropdown List
         TabIndex        =   4
         Top             =   720
         Width           =   2175
      End
      Begin VB.ComboBox CmbDriverID 
         Height          =   300
         Left            =   -73440
         Style           =   2  'Dropdown List
         TabIndex        =   3
         Top             =   1200
         Width           =   2175
      End
      Begin MSComCtl2.DTPicker DTPQueDate 
         Height          =   375
         Left            =   2280
         TabIndex        =   2
         Top             =   1680
         Width           =   2175
         _ExtentX        =   3836
         _ExtentY        =   661
         _Version        =   393216
         Format          =   20774913
         CurrentDate     =   36526
      End
      Begin MSComCtl2.DTPicker DTPDate 
         Height          =   375
         Left            =   -69000
         TabIndex        =   20
         Top             =   720
         Width           =   2175
         _ExtentX        =   3836
         _ExtentY        =   661
         _Version        =   393216
         Format          =   20774913
         CurrentDate     =   38718
      End
      Begin VB.Label Label8 
         Caption         =   "违章原因:"
         Height          =   375
         Index           =   1
         Left            =   -74760
         TabIndex        =   29
         Top             =   1680
         Width           =   1455
      End
      Begin VB.Label Label10 
         Caption         =   "备注:"
         Height          =   375
         Index           =   0
         Left            =   -74760
         TabIndex        =   25
         Top             =   2040
         Width           =   735
      End
      Begin VB.Label Label8 
         Caption         =   "违章罚款(元):"
         Height          =   375
         Index           =   0
         Left            =   -70440
         TabIndex        =   24
         Top             =   1320
         Width           =   1455
      End
      Begin VB.Label Label4 
         Caption         =   "违章日期:"
         Height          =   255
         Index           =   0
         Left            =   -70440
         TabIndex        =   23
         Top             =   840
         Width           =   1215
      End
      Begin VB.Label Label2 
         Caption         =   "违章司机ID:"
         Height          =   255
         Index           =   0
         Left            =   -74760
         TabIndex        =   22
         Top             =   1200
         Width           =   1215
      End
      Begin VB.Label Label1 
         Caption         =   "违章车辆ID:"
         Height          =   255
         Index           =   0
         Left            =   -74760
         TabIndex        =   21
         Top             =   720
         Width           =   1215
      End
   End
End
Attribute VB_Name = "FormPec"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Explicit

'返回按钮
Private Sub CmdBack_Click()
    Me.LvResult.Visible = False
    Me.CmdBack.Visible = False
End Sub

'删除按钮
Private Sub CmdDel_Click()
    
    If MsgBox("确定要删除选定档案吗?", vbOKCancel, "删除违章记录") = vbOK Then
        Adodc1.Recordset.Delete
        MsgBox "删除成功!", , "删除违章记录"
        CmdEmpty_Click
    End If
    Exit Sub
    
End Sub

'清空按钮
Private Sub CmdEmpty_Click()
    Me.TxtReason.Text = ""
    Me.DTPDate.Value = Format(Now, "yyyy-mm-dd")
    Me.TxtPay.Text = ""
    Me.TxtRemark.Text = ""
End Sub

'修改按钮
Private Sub CmdMod_Click()
    DataGrid1.Columns(1).Text = Me.CmbCarID.Text
    DataGrid1.Columns(2).Text = Me.CmbDriverID.Text
    DataGrid1.Columns(3).Text = Me.TxtReason.Text
    DataGrid1.Columns(4).Text = Me.DTPDate.Value
    DataGrid1.Columns(5).Text = Me.TxtPay.Text
    DataGrid1.Columns(6).Text = Me.TxtRemark.Text
    MsgBox "修改成功", , "修改违章记录"
End Sub

'查询按钮
Private Sub CmdQue_Click()
Dim Questr As String
Dim RsQuery As New ADODB.Recordset
Dim LtItm As ListItem
Dim Remark As String
Dim i As Integer

    '按车辆ID查询
    If Me.OptQue(0).Value = True Then
        '判断查询条件
        If Me.TxtQueCar.Text = "" Then
            MsgBox "请输入要查询的车辆ID!", , "查询违章记录"
            Exit Sub
        End If
        
        '生成查询语句
        Questr = "select * from PecRec where PecCarID = " & Val(Me.TxtQueCar.Text)
        
    '按司机ID查询
    ElseIf Me.OptQue(1).Value = True Then
        '判断查询条件
        If Me.TxtQueDriver.Text = "" Then
            MsgBox "请输入要查询的司机ID!", , "查询违章记录"
            Exit Sub
        End If
        
        '生成查询语句
        Questr = "select * from PecRec where PecDriverID = " & Val(Me.TxtQueDriver.Text)

    '按违章日期查询
    ElseIf Me.OptQue(2).Value = True Then
        '生成查询语句
        Questr = "select * from PecRec where PecDate= #" & Me.DTPQueDate.Value & "#"
    
    '按备注查询
    ElseIf Me.OptQue(3).Value = True Then
        '替换单引号
        Remark = Replace(Trim(Me.TxtQueRemark.Text), "'", "''")
        '生成查询语句
        Questr = "select * from PecRec where Remark Like '%" & Remark & "%'"
    
    End If
    
    '打开数据集
    Debug.Print Questr
    RsQuery.Open Questr, DBCn, adOpenStatic, adLockOptimistic
    '显示查询结果
    If RsQuery.EOF Then
        MsgBox "数据库中没有符合要求的记录!", , "查询违章记录"
        Exit Sub
    End If
    Me.LvResult.Visible = True
    Me.CmdBack.Visible = True
   
    '清空列表
    Me.LvResult.ListItems.Clear
    '数据集指针指向第一个记录
    RsQuery.MoveFirst
    For i = 1 To RsQuery.RecordCount
        Set LtItm = Me.LvResult.ListItems.Add()
            LtItm.Text = RsQuery.Fields("PecID").Value
            LtItm.SubItems(1) = RsQuery.Fields("PecCarID").Value
            LtItm.SubItems(2) = RsQuery.Fields("PecDriverID").Value
            LtItm.SubItems(3) = RsQuery.Fields("PecReason").Value
            LtItm.SubItems(4) = RsQuery.Fields("PecDate").Value
            LtItm.SubItems(5) = RsQuery.Fields("PecCost").Value
            If RsQuery.Fields("Remark").Value <> "" Then
                LtItm.SubItems(6) = RsQuery.Fields("Remark").Value
            End If
        '数据集指针指向下一条记录
        RsQuery.MoveNext
    Next i
    '关闭数据集
    RsQuery.Close
    
End Sub

'DataGrid控件中的焦点变换
Private Sub DataGrid1_RowColChange(LastRow As Variant, ByVal LastCol As Integer)
    '检验是否为空行
    If DataGrid1.Columns(0).Text = "" Then
        Exit Sub
    End If
    '将DataGrid中数据读入各个控件显示
    Me.CmbCarID.Text = DataGrid1.Columns(1).Text
    Me.CmbDriverID.Text = DataGrid1.Columns(2).Text
    Me.TxtReason.Text = DataGrid1.Columns(3).Text
    Me.DTPDate.Value = DataGrid1.Columns(4).Text
    Me.TxtPay.Text = DataGrid1.Columns(5).Text
    Me.TxtRemark.Text = DataGrid1.Columns(6).Text
End Sub

Private Sub Form_Load()
Dim RsDB As New ADODB.Recordset
Dim i As Integer
    
    '初始化日期
    Me.DTPDate.Value = Format(Now, "yyyy-mm-dd")
    Me.DTPQueDate.Value = Format(Now, "yyyy-mm-dd")
    
    '初始化ADO控件,连接数据库,设置列首
    Adodc1.ConnectionString = CnStr
    Adodc1.RecordSource = "Select PecID as 违章记录号," & _
                                 "PecCarID as 违章车辆ID," & _
                                 "PecDriverID as 违章司机ID," & _
                                 "PecReason as 违章原因," & _
                                 "PecDate as 违章日期," & _
                                 "PecCost as 违章罚款," & _
                                 "Remark as 备注 " & _
                                 "From PecRec"
    Debug.Print Adodc1.RecordSource
    Set DataGrid1.DataSource = Adodc1   '不能缺少
    
    '读入已有车辆ID和司机ID
    RsDB.Open "select CarID from CarInfo order by CarID ", DBCn, adOpenStatic, adLockReadOnly, -1
    If RsDB.RecordCount > 0 Then
        If Not RsDB.BOF Then RsDB.MoveFirst
        For i = 1 To RsDB.RecordCount
            Me.CmbCarID.AddItem (RsDB.Fields("CarID").Value)
        If Not RsDB.EOF Then RsDB.MoveNext
        Next i
    Else
        MsgBox "还没有车辆档案,不能添加违章记录", , "车辆违章记录管理"
    End If
    RsDB.Close
    RsDB.Open "select DriverID from DriverInfo order by DriverID ", DBCn, adOpenStatic, adLockReadOnly, -1
    If RsDB.RecordCount > 0 Then
        If Not RsDB.BOF Then RsDB.MoveFirst
        For i = 1 To RsDB.RecordCount
            Me.CmbDriverID.AddItem (RsDB.Fields("DriverID").Value)
        If Not RsDB.EOF Then RsDB.MoveNext
        Next i
    Else
        MsgBox "还没有司机档案,不能添加违章记录", , "车辆违章记录管理"
    End If
    RsDB.Close
End Sub

'添加违章记录
Private Sub CmdAdd_Click()
Dim rsAdd As New ADODB.Recordset
Dim SqlStr As String

Dim Remark As String

    '首先检验输入
    '没有选择车辆ID
    If Len(Trim(Me.CmbCarID.Text)) <= 0 Then
        MsgBox "请选择车辆ID!", , "添加违章记录"
        Exit Sub
    End If
    '没有选择司机ID
    If Len(Trim(Me.CmbDriverID.Text)) <= 0 Then
        MsgBox "请选择司机ID!", , "添加违章记录"
        Exit Sub
    End If
    '没有违章原因
    If Len(Trim(Me.TxtReason.Text)) <= 0 Then
        MsgBox "请输入违章原因!", , "添加违章记录"
        Exit Sub
    End If
    '没有输入违章罚款
    If Len(Trim(Me.TxtPay.Text)) <= 0 Then
        MsgBox "请输入违章罚款!", , "添加违章记录"
        Exit Sub
    End If
        
    '检验完毕,数据入库,备注项可选
    If Me.TxtRemark.Text = vbNullString Then '没有备注项
        SqlStr = "INSERT INTO PecRec"
        SqlStr = SqlStr & "(PecCarID,PecDriverID,PecReason,PecDate,PecCost) "
        SqlStr = SqlStr & "VALUES ('" & Me.CmbCarID.Text & "',"
        SqlStr = SqlStr & "'" & Me.CmbDriverID.Text & "',"
        SqlStr = SqlStr & "'" & Me.TxtReason.Text & "',"
        SqlStr = SqlStr & "#" & Me.DTPDate.Value & "#,"
        SqlStr = SqlStr & "'" & Me.TxtPay.Text & "');"
        Debug.Print SqlStr
        DBCn.Execute SqlStr
        
    Else    '有备注项
        Remark = Replace(Trim(Me.TxtRemark.Text), "'", "''")
        SqlStr = "INSERT INTO PecRec"
        SqlStr = SqlStr & "(PecCarID,PecDriverID,PecReason,PecDate,PecCost,Remark) "
        SqlStr = SqlStr & "VALUES ('" & Me.CmbCarID.Text & "',"
        SqlStr = SqlStr & "'" & Me.CmbDriverID.Text & "',"
        SqlStr = SqlStr & "'" & Me.TxtReason.Text & "',"
        SqlStr = SqlStr & "#" & Me.DTPDate.Value & "#,"
        SqlStr = SqlStr & "'" & Me.TxtPay.Text & "',"
        SqlStr = SqlStr & "'" & Remark & "');"
        Debug.Print SqlStr
        DBCn.Execute SqlStr
        
    End If

    MsgBox "添加成功", , "添加违章记录"
    Adodc1.Refresh
End Sub

'设置焦点对应的单选按钮
Private Sub TxtQueCar_GotFocus()
    Me.OptQue(0).Value = True
    EmptyQue
End Sub
Private Sub TxtQueDriver_GotFocus()
    Me.OptQue(1).Value = True
    EmptyQue
End Sub
Private Sub DTPQueDate_Click()
    Me.OptQue(2).Value = True
    EmptyQue
End Sub
Private Sub TxtQueRemark_GotFocus()
    Me.OptQue(3).Value = True
    EmptyQue
End Sub

'清空查询内容函数
Private Sub EmptyQue()
    Me.TxtQueCar.Text = ""
    Me.TxtQueDriver.Text = ""
    Me.DTPQueDate.Value = "2006-1-1"
    Me.TxtQueRemark.Text = ""
End Sub






⌨️ 快捷键说明

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