📄 leibie.frm
字号:
VERSION 5.00
Begin VB.Form leibie
Caption = "产品类别修改"
ClientHeight = 5730
ClientLeft = 60
ClientTop = 465
ClientWidth = 7875
LinkTopic = "Form1"
ScaleHeight = 5730
ScaleWidth = 7875
StartUpPosition = 3 '窗口缺省
Begin VB.Frame Frame1
Caption = "提示:"
Height = 3495
Left = 4920
TabIndex = 8
Top = 720
Width = 2655
Begin VB.Label Label4
Caption = " 删除类别只需要将修改名称清空即可,删除类别后,所删类别下的产品也将被删除"
Height = 1575
Left = 360
TabIndex = 9
Top = 840
Width = 1815
End
End
Begin VB.CommandButton Command2
Caption = "返 回"
Height = 735
Left = 4200
TabIndex = 7
Top = 4440
Width = 2175
End
Begin VB.CommandButton Command1
Caption = "执 行"
Height = 735
Left = 1080
TabIndex = 6
Top = 4440
Width = 2055
End
Begin VB.TextBox Text1
Height = 375
Left = 2160
TabIndex = 2
Top = 3240
Width = 2175
End
Begin VB.ListBox List1
BeginProperty Font
Name = "宋体"
Size = 12
Charset = 134
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 1020
ItemData = "leibie.frx":0000
Left = 2160
List = "leibie.frx":0010
TabIndex = 1
Top = 360
Width = 2175
End
Begin VB.ComboBox Combo1
Height = 300
Left = 2160
TabIndex = 0
Top = 2280
Width = 1935
End
Begin VB.Label Label3
Caption = "新名称:"
BeginProperty Font
Name = "宋体"
Size = 12
Charset = 134
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 375
Left = 720
TabIndex = 5
Top = 3360
Width = 1095
End
Begin VB.Label Label2
Caption = "原名称:"
BeginProperty Font
Name = "宋体"
Size = 12
Charset = 134
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 375
Left = 720
TabIndex = 4
Top = 2280
Width = 1095
End
Begin VB.Label Label1
Caption = "操作:"
BeginProperty Font
Name = "宋体"
Size = 12
Charset = 134
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 375
Left = 720
TabIndex = 3
Top = 480
Width = 615
End
End
Attribute VB_Name = "leibie"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Private Sub Command1_Click()
Text1 = Trim(Text1)
If Text1 = "" And List1.Selected(0) Then
Exit Sub
End If
If Text1 = "" And List1.Selected(2) Then
Exit Sub
End If
Dim rst As Recordset
Dim db As Connection
Set rst = New Recordset
Set db = New Connection
db.CursorLocation = adUseClient
db.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=Database.mdb;Persist Security Info=False"
If List1.Selected(0) Then
conn = "select * from 产品类别 where 类别名称 = '" & Text1 & "'"
Debug.Print conn
rst.Open conn, db, adOpenDynamic, adLockOptimistic
If rst.EOF Then
rst.Close
conn = "insert into 产品类别(类别名称) values ('" & Text1 & "')"
Debug.Print conn
rst.Open conn, db, adOpenDynamic, adLockOptimistic
MsgBox "添加成功"
Call dataz
Else
MsgBox "名称重复,请检查"
End If
End If
If List1.Selected(1) Then
If Text1 = "" Then
x = MsgBox("是否删除类别:" & Combo1.Text & "? 删除后将不能恢复!", vbOKCancel)
If x = 1 Then
conn = "delete from 产品类别 where 类别名称 = '" & Combo1 & "'"
rst.Open conn, db, adOpenDynamic, adLockOptimistic
MsgBox "删除成功"
Call dataz
End If
Else
conn = "select * from 产品类别 where 类别名称 = '" & Text1 & "'"
rst.Open conn, db, adOpenDynamic, adLockOptimistic
If rst.EOF Then
rst.Close
conn = "select * from 产品类别 where 类别名称 = '" & Combo1 & "'"
Debug.Print conn
rst.Open conn, db, adOpenDynamic, adLockOptimistic
If Not rst.EOF Then
rst.Close
conn = "update 产品类别 set 类别名称 = '" & Text1 & "' where 类别名称 = '" & Combo1 & "'"
Debug.Print conn
rst.Open conn, db, adOpenDynamic, adLockOptimistic
MsgBox "修改成功"
Combo1.Clear
Call dataz
Else
MsgBox "类别不存在,请检查"
End If
Else
MsgBox "名称重复,请检查"
End If
End If
End If
If List1.Selected(2) Then
conn = "select * from 生产厂家 where 品牌 = '" & Text1 & "'"
Debug.Print conn
rst.Open conn, db, adOpenDynamic, adLockOptimistic
If rst.EOF Then
rst.Close
conn = "insert into 生产厂家(品牌) values ('" & Text1 & "')"
Debug.Print conn
rst.Open conn, db, adOpenDynamic, adLockOptimistic
MsgBox "添加成功"
Call datay
Else
MsgBox "名称重复,请检查"
End If
End If
If List1.Selected(3) Then
If Text1 = "" Then
x = MsgBox("是否删除品牌:" & Combo1.Text & "? 删除后将不能恢复!", vbOKCancel)
If x = 1 Then
conn = "delete from 生产厂家 where 品牌 = '" & Combo1 & "'"
rst.Open conn, db, adOpenDynamic, adLockOptimistic
MsgBox "删除成功"
Call datay
End If
Else
conn = "select * from 生产厂家 where 品牌 = '" & Text1 & "'"
rst.Open conn, db, adOpenDynamic, adLockOptimistic
If rst.EOF Then
rst.Close
conn = "select * from 生产厂家 where 品牌 = '" & Combo1 & "'"
Debug.Print conn
rst.Open conn, db, adOpenDynamic, adLockOptimistic
If Not rst.EOF Then
rst.Close
conn = "update 生产厂家 set 品牌 = '" & Text1 & "' where 品牌 = '" & Combo1 & "'"
Debug.Print conn
rst.Open conn, db, adOpenDynamic, adLockOptimistic
MsgBox "修改成功"
Combo1.Clear
Call datay
Else
MsgBox "类别不存在,请检查"
End If
Else
MsgBox "名称重复,请检查"
End If
End If
End If
End Sub
Private Sub Command2_Click()
Unload Me
End Sub
Private Sub Form_Load()
List1.Selected(0) = True
Call dataz
End Sub
Private Sub List1_Click()
If List1.Selected(0) Then
Label2.Visible = False
Combo1.Visible = False
End If
If List1.Selected(1) Then
Call dataz
Label2.Visible = True
Combo1.Visible = True
End If
If List1.Selected(2) Then
Label2.Visible = False
Combo1.Visible = False
End If
If List1.Selected(3) Then
Call datay
Label2.Visible = True
Combo1.Visible = True
End If
End Sub
Private Sub dataz()
Combo1.Clear
Dim rst As Recordset
Dim db As Connection
Set rst = New Recordset
' Set rs2 = New Recordset
Set db = New Connection
conn = "select * from 产品类别"
db.CursorLocation = adUseClient
db.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=Database.mdb;Persist Security Info=False"
rst.Open conn, db, adOpenDynamic, adLockOptimistic
If Not rst.EOF Then
rst.MoveFirst
Combo1.Text = rst.Fields("类别名称")
Do Until rst.EOF
Combo1.AddItem rst.Fields("类别名称")
rst.MoveNext
Loop
Else
Combo1.Text = "无任何类别"
End If
db.Close
End Sub
Private Sub datay()
Combo1.Clear
Dim rst As Recordset
Dim db As Connection
Set rst = New Recordset
' Set rs2 = New Recordset
Set db = New Connection
conn = "select * from 生产厂家"
db.CursorLocation = adUseClient
db.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=Database.mdb;Persist Security Info=False"
rst.Open conn, db, adOpenDynamic, adLockOptimistic
If Not rst.EOF Then
rst.MoveFirst
Combo1.Text = rst.Fields("品牌")
Do Until rst.EOF
Combo1.AddItem rst.Fields("品牌")
rst.MoveNext
Loop
Else
Combo1.Text = "无任何品牌"
End If
db.Close
End Sub
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -