📄 frmedit.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 frmEdit
BorderStyle = 3 'Fixed Dialog
Caption = "入库修改"
ClientHeight = 7740
ClientLeft = 45
ClientTop = 330
ClientWidth = 9660
LinkTopic = "Form5"
MaxButton = 0 'False
MDIChild = -1 'True
MinButton = 0 'False
ScaleHeight = 7740
ScaleWidth = 9660
ShowInTaskbar = 0 'False
Begin VB.Frame Frame4
Caption = "产品查询"
Height = 855
Left = 240
TabIndex = 16
Top = 120
Width = 9015
Begin VB.CommandButton cmdClear
Caption = "清空"
Height = 495
Left = 6120
TabIndex = 24
Top = 240
Width = 1695
End
Begin VB.TextBox txtName
Height = 495
Left = 2160
TabIndex = 18
Top = 240
Width = 1695
End
Begin VB.CommandButton cmdQuery
Caption = "查询"
Default = -1 'True
Height = 495
Left = 4200
TabIndex = 17
Top = 240
Width = 1575
End
Begin VB.Label Label5
Caption = "名称"
Height = 375
Left = 600
TabIndex = 19
Top = 360
Width = 1215
End
End
Begin VB.Frame Frame3
Caption = "查询结果"
Height = 2415
Left = 240
TabIndex = 14
Top = 1080
Width = 9015
Begin MSDataGridLib.DataGrid DataGrid1
Height = 2055
Left = 240
TabIndex = 15
Top = 240
Width = 8415
_ExtentX = 14843
_ExtentY = 3625
_Version = 393216
AllowUpdate = 0 'False
Enabled = -1 'True
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
End
Begin VB.Frame Frame2
Height = 855
Left = 240
TabIndex = 9
Top = 6120
Width = 9015
Begin VB.CommandButton cmdCancel
Caption = "取消"
Height = 495
Left = 4800
TabIndex = 13
Top = 240
Width = 1575
End
Begin VB.CommandButton cmdUpdate
Caption = "保存"
Height = 495
Left = 2805
TabIndex = 12
Top = 240
Width = 1575
End
Begin VB.CommandButton cmdEdit
Caption = "修改"
Height = 495
Left = 840
TabIndex = 11
Top = 240
Width = 1575
End
Begin VB.CommandButton cmdClose
Caption = "关闭"
Height = 495
Left = 6720
TabIndex = 10
Top = 240
Width = 1575
End
End
Begin VB.Frame Frame1
Caption = "产品修改"
Height = 1815
Left = 240
TabIndex = 0
Top = 3600
Width = 9015
Begin VB.TextBox txtFields
Height = 495
Index = 5
Left = 7080
TabIndex = 22
Top = 960
Width = 1695
End
Begin VB.TextBox txtFields
Height = 495
Index = 4
Left = 4200
TabIndex = 21
Top = 960
Width = 1815
End
Begin VB.TextBox txtFields
Height = 495
Index = 3
Left = 1080
TabIndex = 4
Top = 960
Width = 1815
End
Begin VB.TextBox txtFields
Height = 495
Index = 2
Left = 7080
TabIndex = 3
Top = 240
Width = 1695
End
Begin VB.TextBox txtFields
Height = 495
Index = 1
Left = 4200
TabIndex = 2
Top = 240
Width = 1815
End
Begin VB.TextBox txtFields
Height = 495
Index = 0
Left = 1080
TabIndex = 1
Top = 240
Width = 1815
End
Begin VB.Label Label7
Caption = "经手人"
Height = 375
Left = 6120
TabIndex = 23
Top = 960
Width = 855
End
Begin VB.Label Label6
Caption = "入库数量"
Height = 495
Left = 6120
TabIndex = 20
Top = 360
Width = 735
End
Begin VB.Label Label1
Caption = "产品名称"
Height = 375
Left = 240
TabIndex = 8
Top = 360
Width = 975
End
Begin VB.Label Label2
Caption = "产品价格"
Height = 495
Left = 3240
TabIndex = 7
Top = 360
Width = 975
End
Begin VB.Label Label3
Caption = "产品描述"
Height = 495
Left = 240
TabIndex = 6
Top = 1080
Width = 975
End
Begin VB.Label Label4
Caption = "其它"
Height = 375
Left = 3240
TabIndex = 5
Top = 1080
Width = 735
End
End
Begin MSAdodcLib.Adodc Adodc1
Height = 495
Left = 240
Top = 5520
Width = 9015
_ExtentX = 15901
_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 = ""
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 = "frmEdit"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Private Sub cmdEdit_Click()
'如果有错则转入出错处理部分
On Error GoTo EditErr
'设置按钮状态,添加按钮为禁用
SetButtons False
Exit Sub
EditErr:
'显示出错信息
MsgBox Err.Description
End Sub
Private Sub cmdCancel_Click()
On Error GoTo CancelErr
Adodc1.Recordset.CancelBatch adAffectAll
'设置按钮状态,添加按钮为真
SetButtons True
'显示操作信息
MsgBox "取消成功!", vbExclamation + vbOKOnly, "产品修改"
Exit Sub
CancelErr:
'显示出错信息
MsgBox Err.Description
End Sub
Private Sub cmdClear_Click()
'清空查询条件
txtName.Text = ""
'设置鼠标焦点
txtName.SetFocus
End Sub
Private Sub cmdClose_Click()
'释放窗体本身
Unload Me
End Sub
Private Sub cmdUpdate_Click()
On Error GoTo UpdateErr
'条件判断保证输入的合理性
'如果名称文本框为空,则显示提示信息并返回
If Trim(txtFields(0).Text) = "" Then
MsgBox "名称不能为空", vbExclamation + vbOKOnly, "警告"
'设置鼠标焦点
txtFields(0).SetFocus
Exit Sub
End If
'判断价格文本框不能为空
If Trim(txtFields(1).Text) = "" Then
MsgBox "价格不能为空", vbExclamation + vbOKOnly, "警告"
'设置鼠标焦点
txtFields(1).SetFocus
Exit Sub
End If
'判断价格文本框必须为数字
If Not IsNumeric(Trim(txtFields(1).Text)) Then
MsgBox "价格必须为数字", vbExclamation + vbOKOnly, "警告"
'设置鼠标焦点
txtFields(1).SetFocus
'使文本变为选中状态
'设置选择的起始位置和选择的长度
txtFields(1).SelStart = 0
txtFields(1).SelLength = Len(txtFields(1).Text)
Exit Sub
End If
'判断入库数量文本框输入必须为数字
If Not IsNumeric(Trim(txtFields(2).Text)) Then
MsgBox "入库数量必须为数字", vbExclamation + vbOKOnly, "警告"
'设置鼠标焦点
txtFields(2).SetFocus
'使文本变为选中状态
'设置选择的起始位置和选择的长度
txtFields(2).SelStart = 0
txtFields(2).SelLength = Len(txtFields(2).Text)
Exit Sub
End If
'保存adodc1的记录集的修改
Adodc1.Recordset.UpdateBatch adAffectAll
'保存后,设置按钮状态
SetButtons True
'显示操作信息
MsgBox "保存成功!", vbExclamation + vbOKOnly, "产品修改"
Exit Sub
UpdateErr:
MsgBox Err.Description
End Sub
Private Sub cmdQuery_Click()
Dim strSQL As String
'判断名称文本框不能为空
If Trim(txtName.Text) = "" Then
MsgBox "查询名称不能为空!", vbOKOnly + vbExclamation, "警告!"
'设置鼠标焦点
txtName.SetFocus
Exit Sub
End If
strSQL = "Select * From product Where 名称 like " + "'" + _
Replace(Trim(txtName.Text), "'", "''", 1) + "%'"
'设置Adodc1的命令类型和记录源
Adodc1.CommandType = adCmdText
Adodc1.RecordSource = strSQL
'刷新Adodc1
Adodc1.Refresh
End Sub
Private Sub Form_Load()
'设置Adodc1的连接字符串和记录源
Adodc1.ConnectionString = ConnectString
Adodc1.RecordSource = "Select * From product "
'将文本框和Adodc1绑定
Dim i As Integer
For i = 1 To 6
'设置文本框的数据源
Set txtFields(i - 1).DataSource = Adodc1
'设置文本框的数据绑定字段
txtFields(i - 1).DataField = Adodc1.Recordset.Fields(i).Name
Next i
'设置DataGrid1的数据源
Set DataGrid1.DataSource = Adodc1
'设置按钮状态
SetButtons True
End Sub
'设置按钮和文本的使用状态
'添加按钮可用时,保存取消两个按钮禁用
'点击添加按钮后,添加按钮禁用,保存取消两个按钮可用
'点击保存取消两个按钮之一后,添加按钮又可用,保存取消两个按钮禁用
'对于文本框,点击添加按钮后可以使用,否则则禁用
Private Sub SetButtons(bVal As Boolean)
cmdEdit.Enabled = bVal
cmdUpdate.Enabled = Not bVal
cmdCancel.Enabled = Not bVal
cmdClose.Enabled = bVal
Dim i As Integer
For i = 0 To 5
txtFields(i).Enabled = Not bVal
Next i
End Sub
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -