📄 form1.frm
字号:
VERSION 5.00
Begin VB.Form form1
BorderStyle = 3 'Fixed Dialog
Caption = "添加产品信息信息"
ClientHeight = 4260
ClientLeft = 3030
ClientTop = 2400
ClientWidth = 8220
LinkTopic = "Form1"
MaxButton = 0 'False
MinButton = 0 'False
ScaleHeight = 4260
ScaleWidth = 8220
ShowInTaskbar = 0 'False
Begin VB.CommandButton cmdExit
Caption = "返回 (&X)"
Height = 375
Left = 4320
TabIndex = 4
Top = 2880
Width = 1335
End
Begin VB.CommandButton cmd
Caption = "保存 (&S)"
Height = 375
Left = 2160
TabIndex = 0
Top = 2880
Width = 1215
End
Begin VB.Frame Frame1
Caption = "产品信息"
Height = 2295
Index = 0
Left = 480
TabIndex = 5
Top = 240
Width = 7095
Begin VB.ComboBox Combo1
Height = 300
Left = 1680
TabIndex = 9
Top = 600
Width = 1815
End
Begin VB.TextBox txtItem
Height = 375
Index = 3
Left = 4560
MaxLength = 10
TabIndex = 3
Top = 1320
Width = 1815
End
Begin VB.TextBox txtItem
Height = 375
Index = 2
Left = 1680
MaxLength = 12
TabIndex = 1
Top = 1320
Width = 1815
End
Begin VB.TextBox txtItem
Height = 375
Index = 1
Left = 4560
MaxLength = 8
TabIndex = 2
Top = 480
Width = 1815
End
Begin VB.Label Label2
Caption = "价 格"
Height = 255
Index = 1
Left = 840
TabIndex = 10
Top = 1440
Width = 615
End
Begin VB.Label Label2
Caption = "库 存 量"
Height = 255
Index = 3
Left = 3600
TabIndex = 8
Top = 1440
Width = 735
End
Begin VB.Label Label2
Caption = "产品编号"
Height = 255
Index = 0
Left = 840
TabIndex = 7
Top = 600
Width = 735
End
Begin VB.Label Label2
Caption = "产品名称"
Height = 255
Index = 2
Left = 3600
TabIndex = 6
Top = 600
Width = 855
End
End
End
Attribute VB_Name = "form1"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Explicit
Public mrc As ADODB.Recordset
Public txtSQL As String
Public cpbh As String
Private Sub Check1_Click()
If Check1.Value = 0 Then
Image1.Picture = Nothing
Command1.Visible = False
Else
If flagadd = 1 Or flagadd = 2 Then
Command1.Visible = True
End If
End If
End Sub
Private Sub cmdExit_Click()
Unload Me
End Sub
Private Sub cmd_Click()
Dim Count As Integer
Dim sMeg As String
Dim mrcc As ADODB.Recordset
Dim MsgText As String
Dim cpbh, cpmc As String
Dim jg As Double
Dim kcl As Integer
Dim cnn As ADODB.Connection
Dim cmdupdate As New ADODB.Command
Dim cmddele As New ADODB.Command
Select Case flagadd
Case 1
If Trim(Combo1.Text & " ") = "" Then
sMeg = "产品编号"
End If
For Count = 1 To 3
If Trim(txtItem(Count) & " ") = "" Then
Select Case Count
Case 1
sMeg = "产品名称"
Case 2
sMeg = "产品价格"
Case 3
sMeg = "产品库存量"
End Select
sMeg = sMeg & "不能为空!"
MsgBox sMeg, vbOKOnly + vbExclamation, "警告"
txtItem(Count).SetFocus
Exit Sub
End If
Next Count
cpbh = Combo1.Text
Combo1.AddItem Trim(cpbh)
cpmc = txtItem(1).Text
jg = CDbl(txtItem(2).Text)
kcl = CInt(txtItem(3).Text)
txtSQL = "select * from cp where cpbh='" & Trim(Combo1.Text) & "'"
Set mrc = ExecuteSQL(txtSQL)
If mrc.EOF = False Then
MsgBox "此产品编号已存在!", vbOKOnly + vbExclamation, "警告"
Combo1.SetFocus
mrc.Close
Else
Set cnn = New ADODB.Connection
cnn.Open ConnectString
cnn.Execute "exec cp_insert '" & cpbh & "','" & cpmc & "'," & jg & "," & kcl
cnn.Close
MsgBox "数据已保存!", vbOKOnly + vbExclamation, "提示"
Combo1.Text = ""
For Count = 1 To 3
txtItem(Count).Text = ""
Next Count
End If
Case 2
cpbh = Combo1.Text
cpmc = txtItem(1).Text
jg = CDbl(txtItem(2).Text)
kcl = CInt(txtItem(3).Text)
Set cnn = New ADODB.Connection
cnn.Open ConnectString
Set cmdupdate.ActiveConnection = cnn
cmdupdate.CommandText = "cp_update"
cmdupdate.CommandType = adCmdStoredProc
cmdupdate.Parameters.Append cmdupdate.CreateParameter("cpbh0", adChar, adParamInput, 6, cpbh)
cmdupdate.Parameters.Append cmdupdate.CreateParameter("cpmc0", adChar, adParamInput, 12, cpmc)
cmdupdate.Parameters.Append cmdupdate.CreateParameter("jg0", adDouble, adParamInput, , jg)
cmdupdate.Parameters.Append cmdupdate.CreateParameter("kcl0", adInteger, adParamInput, , kcl)
cmdupdate.Parameters.Append cmdupdate.CreateParameter("flag", adInteger, adParamOutput)
cmdupdate.Execute
If cmdupdate("flag") = 1 Then
MsgBox "数据已更新!", vbOKOnly + vbExclamation, "提示"
Else
MsgBox "数据更新不成功!", vbOKOnly + vbExclamation, "提示"
cnn.Close
End If
Case 3
cpbh = Combo1.Text
Set cnn = New ADODB.Connection
cnn.Open ConnectString
Set cmddele.ActiveConnection = cnn
cmddele.CommandText = "cp_delete"
cmddele.CommandType = adCmdStoredProc
cmddele.Parameters.Append cmdupdate.CreateParameter("cpbh0", adChar, adParamInput, 6, cpbh)
cmddele.Parameters.Append cmddele.CreateParameter("flag", adInteger, adParamOutput)
cmddele.Execute
If cmddele("flag") = 1 Then
MsgBox "记录已被删除!", vbOKOnly + vbExclamation, "提示"
For Count = 0 To Combo1.ListCount - 1
If Combo1.List(Count) = Combo1.Text And Combo1.Text <> "" Then
Combo1.RemoveItem Count
Combo1.Text = ""
End If
Next Count
For Count = 1 To 3
txtItem(Count).Text = ""
Next Count
End If
cnn.Close
End Select
End Sub
Private Sub Combo1_Click()
Dim strText, MsgText As String
Dim cpbh As String
strText = Combo1.Text
cpbh = Combo1.Text
txtSQL = "select * from cp where cpbh='" & strText & "'"
Set mrc = ExecuteSQL(txtSQL)
If Not mrc.EOF Then
txtItem(1).Text = mrc.Fields(1)
txtItem(2).Text = mrc.Fields(2)
txtItem(3).Text = mrc.Fields(3)
End If
mrc.Close
Combo1.SetFocus
End Sub
Private Sub Combo1_KeyPress(KeyAscii As Integer)
Dim MsgText As String
If KeyAscii = 13 And flagadd = 1 Then '添加产品信息
txtSQL = "select * from cp where cpbh='" & Trim(Combo1.Text) & "'"
Set mrc = ExecuteSQL(txtSQL)
If mrc.EOF = False Then
MsgBox "此产品编号已存在!", vbOKOnly + vbExclamation, "警告"
Combo1.SetFocus
mrc.Close
Else
txtItem(1).SetFocus
End If
End If
End Sub
Private Sub Form_Activate()
Dim MsgText As String
Dim ftag As Integer
ftag = 0
txtSQL = "select * from cp"
Set mrc = ExecuteSQL(txtSQL)
If Not mrc.EOF Then
Do While Not mrc.EOF
Combo1.AddItem Trim(mrc.Fields(0))
If ftag = 0 Then
ftag = 1
End If
Combo1.Text = mrc.Fields(0)
cpbh = Combo1.Text
txtItem(1).Text = mrc.Fields(1)
txtItem(2).Text = mrc.Fields(2)
txtItem(3).Text = mrc.Fields(3)
mrc.MoveNext
Loop
End If
mrc.Close
Combo1.SetFocus
End Sub
Private Sub Form_Load()
Me.Caption = "产品信息"
Select Case flagadd
Case 1
Me.Caption = Me.Caption & "添加"
cmd.Caption = "保存 (&S)"
Case 2
Me.Caption = Me.Caption & "修改"
cmd.Caption = "更新 (&U)"
Case 3
Me.Caption = Me.Caption & "删除"
cmd.Caption = "删除 (&D)"
'Case 4
' Me.Caption = Me.Caption & "查询"
' cmd.Visible = False
' cmd.Enabled = False
' Label2(1).Visible = True
' Label1.Visible = True
End Select
End Sub
Private Sub txtItem_KeyDown(Index As Integer, KeyCode As Integer, Shift As Integer)
Select Case Index
Case 0
If KeyCode = 13 Then
txtItem(1).SetFocus
End If
Case 1
If KeyCode = 13 Then
txtItem(2).SetFocus
End If
Case 2
If KeyCode = 13 Then
txtItem(3).SetFocus
End If
End Select
End Sub
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -