📄 addcp.frm
字号:
VERSION 5.00
Begin VB.Form ADDCP
BorderStyle = 3 'Fixed Dialog
Caption = "添加同类产品"
ClientHeight = 3090
ClientLeft = 45
ClientTop = 330
ClientWidth = 5175
Icon = "ADDCP.frx":0000
LinkTopic = "Form1"
LockControls = -1 'True
MaxButton = 0 'False
MinButton = 0 'False
ScaleHeight = 3090
ScaleWidth = 5175
ShowInTaskbar = 0 'False
StartUpPosition = 2 'CenterScreen
Begin VB.Frame Frame1
Caption = "编辑区"
ForeColor = &H00C000C0&
Height = 1320
Left = 345
TabIndex = 5
Top = 720
Width = 4485
Begin VB.TextBox Text1
Height = 285
Left = 2130
TabIndex = 0
Top = 390
Width = 2295
End
Begin VB.TextBox Text2
Height = 285
Left = 2130
TabIndex = 8
Top = 795
Width = 1590
End
Begin VB.TextBox Text3
DataField = "品名"
DataSource = "Data1"
Height = 285
Left = 2130
TabIndex = 7
Top = 390
Visible = 0 'False
Width = 2295
End
Begin VB.TextBox Text4
DataField = "单价"
DataSource = "Data1"
Height = 285
Left = 2130
TabIndex = 6
Top = 795
Visible = 0 'False
Width = 1590
End
Begin VB.Label Label2
AutoSize = -1 'True
Caption = "产品编号,类名不需要:"
Height = 180
Left = 120
TabIndex = 10
Top = 435
Width = 1980
End
Begin VB.Label Label3
AutoSize = -1 'True
Caption = "产品单价:"
Height = 180
Left = 1200
TabIndex = 9
Top = 855
Width = 900
End
End
Begin VB.Data Data1
Caption = "Data1"
Connect = "Access"
DatabaseName = ""
DefaultCursorType= 0 'DefaultCursor
DefaultType = 2 'UseODBC
Exclusive = 0 'False
Height = 285
Left = -1125
Options = 0
ReadOnly = 0 'False
RecordsetType = 1 'Dynaset
RecordSource = ""
Top = 135
Width = 1140
End
Begin VB.CommandButton CloseForm
Cancel = -1 'True
Caption = "放弃(&C)"
Height = 390
Left = 2700
TabIndex = 3
Top = 2385
Width = 1065
End
Begin VB.CommandButton Sure
Caption = "确认(&S)"
Enabled = 0 'False
Height = 390
Left = 1185
TabIndex = 2
Top = 2385
Width = 1065
End
Begin VB.Line Line4
BorderColor = &H00FFFFFF&
X1 = 345
X2 = 4860
Y1 = 2085
Y2 = 2085
End
Begin VB.Line Line3
X1 = 345
X2 = 4845
Y1 = 2115
Y2 = 2115
End
Begin VB.Label ADDCPLM
AutoSize = -1 'True
Caption = "无类名"
BeginProperty Font
Name = "宋体"
Size = 14.25
Charset = 134
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
ForeColor = &H000000FF&
Height = 285
Left = 2145
TabIndex = 4
Top = 285
Width = 855
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
ForeColor = &H00800000&
Height = 285
Left = 1305
TabIndex = 1
Top = 285
Width = 915
End
End
Attribute VB_Name = "ADDCP"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Private Sub closeform_Click()
Unload Me
End Sub
Private Sub Form_Load()
'声明数据库路径
Data1.DatabaseName = appData
Data1.RecordSource = "cpk"
Text1.Text = ""
Text2.Text = ""
Dim Sb As String, Sn As Integer
Sb = cpform.DBGrid1.Text
Sn = InStr(1, Sb, "-", vbTextCompare)
If Sn = 0 Then
ADDCPLM.Caption = cpform.DBGrid1.Text
Else
ADDCPLM.Caption = Left(cpform.DBGrid1.Text, Sn - 1)
End If
End Sub
Private Sub Sure_Click()
Dim Fj
Fj = "品名='" & ADDCPLM.Caption & "-" & Trim(Text1.Text) & "'"
Data1.Recordset.FindFirst Fj
If Not Data1.Recordset.NoMatch Then
MsgBox "该产品的型号已经存在,请重新再来!" & Chr(10) & Chr(13) & "产品类型不能重复!", vbOKOnly + 32, "产品重复"
Exit Sub
Else
cpform.zs.Caption = Val(cpform.zs.Caption) + 1
End If
'添加新产品记录
Data1.Recordset.AddNew
'产品包括类名及产品代码
Text3.Text = ADDCPLM & "-" & Trim(Text1.Text)
Text4.Text = Text2.Text
Data1.Refresh
cpform.Data1.Refresh
cpform.Data1.Recordset.FindFirst Fj
Unload Me
End Sub
Private Sub Text1_Change()
If Trim(Text1.Text) <> "" And Val(Text2.Text) > 0 Then
Sure.Enabled = True
Else
Sure.Enabled = False
End If
End Sub
Private Sub Text1_KeyPress(KeyAscii As Integer)
If KeyAscii = 13 And Trim(Text1.Text) <> "" Then
Text2.SetFocus
End If
End Sub
Private Sub Text2_Change()
If Trim(Text1.Text) <> "" And Val(Text2.Text) > 0 Then
Sure.Enabled = True
Else
Sure.Enabled = False
End If
End Sub
Private Sub Text2_KeyPress(KeyAscii As Integer)
If KeyAscii = 13 Then
If Sure.Enabled = True Then
Sure.SetFocus
Else
Exit Sub
End If
End If
If KeyAscii = 8 Then
If Val(Trim(Text2.Text)) = 0 Then
KeyAscii = 0
Else
Text2.Text = Left(Text2.Text, (Len(Text2.Text) - 1))
Text2.SelStart = Len(Text2.Text)
End If
End If
If KeyAscii = 47 Or KeyAscii < 46 Or KeyAscii > 58 Then
KeyAscii = 0
End If
End Sub
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -