📄 frmproduct.frm
字号:
VERSION 5.00
Begin VB.Form frmProduct
BorderStyle = 1 'Fixed Single
Caption = "车站管理"
ClientHeight = 4830
ClientLeft = 45
ClientTop = 435
ClientWidth = 5700
LinkTopic = "Form1"
MaxButton = 0 'False
MDIChild = -1 'True
MinButton = 0 'False
ScaleHeight = 4830
ScaleWidth = 5700
Begin VB.TextBox txtId
BeginProperty Font
Name = "宋体"
Size = 10.5
Charset = 134
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 315
Left = 3600
TabIndex = 6
Top = 3240
Visible = 0 'False
Width = 1275
End
Begin VB.TextBox txtProduct
BeginProperty Font
Name = "宋体"
Size = 10.5
Charset = 134
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 315
Left = 360
TabIndex = 5
Top = 840
Width = 2000
End
Begin VB.ListBox LisProduct
BeginProperty Font
Name = "宋体"
Size = 10.5
Charset = 134
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 3000
Left = 360
TabIndex = 4
Top = 1560
Width = 2955
End
Begin VB.CommandButton Command3
Caption = "删 除"
Height = 375
Left = 4080
TabIndex = 3
Top = 2040
Width = 1005
End
Begin VB.CommandButton Command2
Caption = "修 改"
Height = 375
Left = 4080
TabIndex = 2
Top = 1440
Width = 1005
End
Begin VB.CommandButton Command1
Caption = "新 增"
Height = 375
Left = 4080
TabIndex = 1
Top = 840
Width = 1005
End
Begin VB.Label Label1
AutoSize = -1 'True
Caption = "品 名 管 理"
BeginProperty Font
Name = "宋体"
Size = 14.25
Charset = 134
Weight = 700
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 285
Left = 2040
TabIndex = 0
Top = 240
Width = 2190
End
End
Attribute VB_Name = "frmProduct"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Dim arrProduct
Private Sub Command1_Click()
'检查是否为空
If Trim(txtProduct.Text) <> "" Then
'检查是否重复
Dim i As Integer
Dim isfind As Boolean
isfind = False
For i = 0 To UBound(arrProduct)
If txtProduct.Text = arrProduct(i) Then
isfind = True
End If
Next
If isfind = False Then
'取得最大ID
Dim inum As Integer
Dim strsql As String
Dim DB As New clsDataBase
Dim rs As New ADODB.Recordset
strsql = "SELECT MAX(ID) AS MAXID FROM Product"
Set rs = sys.DB.OpenRecordSet(strsql)
If Not IsNull(rs(0)) Then
ID = rs(0) + 1
Else
ID = 0
End If
txtId.Text = ID
MyVar = MsgBox("确认增加?", vbOKCancel, "信息提示")
If MyVar = vbOK Then
'插入数据
strsql = "INSERT INTO Product (ID,NAME) VALUES (" & sys.TextTolong(txtId) & "," & sys.StrToInsert(txtProduct) & ")"
sys.DB.ExecuteSQL (strsql)
MsgBox "操作成功!"
Unload Me
End If
Else
MsgBox "已经存在该品名!"
End If
Else
MsgBox "品名不能为空!"
End If
End Sub
Private Sub Command2_Click()
'检查是否为空
If Trim(txtProduct.Text) <> "" Then
'检查是否重复
Dim i As Integer
Dim isfind As Boolean
isfind = False
For i = 0 To UBound(arrProduct)
If txtProduct.Text = arrProduct(i) Then
isfind = True
End If
Next
If isfind = False Then
MyVar = MsgBox("确认修改?", vbOKCancel, "信息提示")
If MyVar = vbOK Then
'更新数据
strsql = "UPDATE Product SET NAME= " & sys.StrToInsert(txtProduct) & " WHERE ID =" & sys.TextTolong(txtId)
sys.DB.ExecuteSQL (strsql)
MsgBox "操作成功!"
Unload Me
End If
Else
MsgBox "已经存在该品名!"
End If
Else
MsgBox "品名不能为空!"
End If
End Sub
Private Sub Command3_Click()
'检查是否为空
If Trim(txtProduct.Text) <> "" Then
'检查数据库是否使用该记录
strsql = "SELECT COUNT(PRODUCTNAME) AS SProduct FROM TRAFFIC WHERE PRODUCTNAME =" & sys.TextTolong(txtId)
Set rs = sys.DB.OpenRecordSet(strsql)
If sys.TextTolong(rs("SProduct")) > 0 Then
MsgBox "对不起,系统中有运单使用该品名,该品不能删除!"
Else
MyVar = MsgBox("确认删除?", vbOKCancel, "信息提示")
If MyVar = vbOK Then
'删除数据
strsql = "DELETE FROM Product WHERE ID =" & sys.TextTolong(txtId)
sys.DB.ExecuteSQL (strsql)
MsgBox "操作成功!"
Unload Me
End If
End If
Else
MsgBox "品名不能为空!"
End If
End Sub
Private Sub Form_Load()
Me.Top = 0
Me.Left = 0
Me.Width = MainForm.Width * 0.4
Me.Height = MainForm.Height * 0.6
'初始化品
Dim inum As Integer
Dim strsql As String
Dim DB As New clsDataBase
Dim rs As New ADODB.Recordset
ReDim arrProduct(0) As String
strsql = "SELECT * FROM Product"
Set rs = sys.DB.OpenRecordSet(strsql)
If Not (rs.BOF) Or (rs.EOF) Then
inum = 0
Do While Not rs.EOF
ReDim Preserve arrProduct(inum)
arrProduct(inum) = rs("NAME")
LisProduct.AddItem (rs("NAME"))
LisProduct.ItemData(inum) = rs("ID")
rs.MoveNext
inum = inum + 1
Loop
End If
End Sub
Private Sub LisProduct_Click()
If LisProduct.ListIndex <> -1 Then
txtId.Text = LisProduct.ItemData(LisProduct.ListIndex)
txtProduct.Text = LisProduct.Text
End If
End Sub
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -