📄 formcar.frm
字号:
Top = 1200
Width = 1215
End
Begin VB.Label Label4
Caption = "购买日期:"
Height = 255
Index = 0
Left = 240
TabIndex = 18
Top = 1800
Width = 1215
End
Begin VB.Label Label10
Caption = "备注:"
Height = 375
Index = 0
Left = 240
TabIndex = 17
Top = 2400
Width = 735
End
End
Begin VB.Frame Frame1
Height = 3615
Left = 120
TabIndex = 21
Top = 4320
Width = 10815
Begin MSAdodcLib.Adodc Adodc1
Height = 495
Left = 7920
Top = 2400
Visible = 0 'False
Width = 2175
_ExtentX = 3836
_ExtentY = 873
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
Bindings = "FormCar.frx":0182
Height = 3135
Left = 120
TabIndex = 22
Top = 240
Width = 10575
_ExtentX = 18653
_ExtentY = 5530
_Version = 393216
ColumnHeaders = -1 'True
HeadLines = 1
RowHeight = 15
AllowAddNew = -1 'True
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
End
End
Attribute VB_Name = "FormCar"
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()
On Error GoTo Err:
If MsgBox("确定要删除选定档案吗?", vbOKCancel, "删除档案") = vbOK Then
Adodc1.Recordset.Delete
MsgBox "删除成功!", , "删除档案"
CmdEmpty_Click
End If
Exit Sub
Err:
MsgBox "其他表中包含相关记录,不能删除!", , "删除档案"
End Sub
'清空按钮
Private Sub CmdEmpty_Click()
Me.TxtCarNum.Text = ""
Me.TxtTeam.Text = ""
Me.DTPBuy.Value = "2000-1-1"
Me.OptCheck(0).Value = True
Me.OptIns(0).Value = True
Me.TxtRemark.Text = ""
End Sub
'修改按钮
Private Sub CmdMod_Click()
DataGrid1.Columns(1).Text = Me.TxtCarNum.Text
DataGrid1.Columns(2).Text = Me.TxtTeam.Text
DataGrid1.Columns(3).Text = Me.DTPBuy.Value
If Me.OptCheck(0).Value = True Then
DataGrid1.Columns(4).Text = 0
Else
DataGrid1.Columns(4).Text = -1
End If
If Me.OptIns(0).Value = True Then
DataGrid1.Columns(5).Text = 0
Else
DataGrid1.Columns(5).Text = -1
End If
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
'按车号查询
If Me.OptQue(0).Value = True Then
'判断查询条件
If Me.TxtQueCarNum.Text = "" Then
MsgBox "请输入要查询的车号!", , "查询车辆档案"
Exit Sub
End If
'生成查询语句
Questr = "select * from CarInfo where CarNum Like '%" & Me.TxtQueCarNum.Text & "%'"
'按是否年检查询
ElseIf Me.OptQue(1).Value = True Then
'生成查询语句
If Me.OptQueCheck(0).Value = True Then
Questr = "select * from CarInfo where CarCheck = 0"
Else
Questr = "select * from CarInfo where CarCheck = -1"
End If
'按是否车险查询
ElseIf Me.OptQue(2).Value = True Then
'生成查询语句
If Me.OptQueIns(0).Value = True Then
Questr = "select * from CarInfo where CarIns = 0"
Else
Questr = "select * from CarInfo where CarIns = -1"
End If
'按备注查询
ElseIf Me.OptQue(3).Value = True Then
'替换单引号
Remark = Replace(Trim(Me.TxtQueRemark.Text), "'", "''")
'生成查询语句
Questr = "select * from DriverInfo where Remark Like '%" & Remark & "%'"
End If
'打开数据集
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("CarID").Value
LtItm.SubItems(1) = RsQuery.Fields("CarNum").Value
LtItm.SubItems(2) = RsQuery.Fields("CarTeam").Value
LtItm.SubItems(3) = RsQuery.Fields("CarDate").Value
If RsQuery.Fields("CarCheck").Value = 0 Then
LtItm.SubItems(4) = "是"
Else
LtItm.SubItems(4) = "否"
End If
If RsQuery.Fields("CarIns").Value = 0 Then
LtItm.SubItems(5) = "是"
Else
LtItm.SubItems(5) = "否"
End If
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.TxtCarNum.Text = DataGrid1.Columns(1).Text
Me.TxtTeam.Text = DataGrid1.Columns(2).Text
Me.DTPBuy.Value = DataGrid1.Columns(3).Text
If DataGrid1.Columns(4).Text = 0 Then
Me.OptCheck(0).Value = True
Else
Me.OptCheck(1).Value = True
End If
If DataGrid1.Columns(5).Text = 0 Then
Me.OptIns(0).Value = True
Else
Me.OptIns(1).Value = True
End If
Me.TxtRemark.Text = DataGrid1.Columns(6).Text
End Sub
Private Sub Form_Load()
'初始化ADO控件,连接数据库,设置列首
Adodc1.ConnectionString = CnStr
Adodc1.RecordSource = "Select CarID as 车辆ID," & _
"CarNum as 车号," & _
"CarTeam as 隶属车队名," & _
"CarDate as 购买日期," & _
"CarCheck as 年检," & _
"CarIns as 车险," & _
"Remark as 备注 " & _
"From CarInfo"
Debug.Print Adodc1.RecordSource
Set DataGrid1.DataSource = Adodc1 '不能缺少
End Sub
'添加车辆档案
Private Sub CmdAdd_Click()
Dim rsAdd As New ADODB.Recordset
Dim SqlStr As String
Dim check As Integer
Dim ins As Integer
Dim Remark As String
'首先检验输入
'没有输入车号
If Len(Trim(Me.TxtCarNum.Text)) <= 0 Then
MsgBox "请输入车号!", , "添加车辆档案"
Exit Sub
End If
'没有输入隶属车队名
If Len(Trim(Me.TxtTeam.Text)) <= 0 Then
MsgBox "请输入隶属车队名!", , "添加车辆档案"
Exit Sub
End If
'检验完毕,数据入库
If Me.OptCheck(0).Value = True Then
check = 0
Else
check = -1
End If
If Me.OptIns(0).Value = True Then
ins = 0
Else
ins = -1
End If
'备注项可选
If Me.TxtRemark.Text = vbNullString Then '没有备注项
SqlStr = "INSERT INTO CarInfo"
SqlStr = SqlStr & "(CarNum,CarTeam,CarDate,CarCheck,CarIns) "
SqlStr = SqlStr & "VALUES ('" & Me.TxtCarNum.Text & "',"
SqlStr = SqlStr & "'" & Me.TxtTeam.Text & "',"
SqlStr = SqlStr & "#" & Me.DTPBuy.Value & "#,"
SqlStr = SqlStr & check & ","
SqlStr = SqlStr & ins & ");"
Debug.Print SqlStr
DBCn.Execute SqlStr
Else '有备注项
Remark = Replace(Trim(Me.TxtRemark.Text), "'", "''")
SqlStr = "INSERT INTO CarInfo"
SqlStr = SqlStr & "(CarNum,CarTeam,CarDate,CarCheck,CarIns,Remark) "
SqlStr = SqlStr & "VALUES ('" & Me.TxtCarNum.Text & "',"
SqlStr = SqlStr & "'" & Me.TxtTeam.Text & "',"
SqlStr = SqlStr & "#" & Me.DTPBuy.Value & "#,"
SqlStr = SqlStr & check & ","
SqlStr = SqlStr & ins & ","
SqlStr = SqlStr & "'" & Remark & "');"
Debug.Print SqlStr
DBCn.Execute SqlStr
End If
MsgBox "添加成功", , "添加车辆档案"
Adodc1.Refresh
End Sub
'设置焦点对应的单选按钮
Private Sub TxtQueCarNum_GotFocus()
Me.OptQue(0).Value = True
EmptyQue
End Sub
Private Sub OptQueCheck_GotFocus(Index As Integer)
Me.OptQue(1).Value = True
EmptyQue
End Sub
Private Sub OptQueIns_Click(Index As Integer)
Me.OptQue(2).Value = True
EmptyQue
End Sub
Private Sub TxtQueRemark_GotFocus()
Me.OptQue(3).Value = True
EmptyQue
End Sub
'清空查询内容函数
Private Sub EmptyQue()
Me.TxtQueCarNum.Text = ""
Me.TxtQueRemark.Text = ""
End Sub
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -