📄 frmproduct1.frm
字号:
VERSION 5.00
Begin VB.Form frmProduct1
Caption = "商品信息"
ClientHeight = 3996
ClientLeft = 48
ClientTop = 348
ClientWidth = 3852
LinkTopic = "Form1"
ScaleHeight = 3996
ScaleWidth = 3852
StartUpPosition = 1 'CenterOwner
Begin VB.CommandButton cmdSave
Caption = "保存 (&S)"
Height = 375
Left = 240
TabIndex = 4
Top = 3360
Width = 1215
End
Begin VB.CommandButton cmdExit
Caption = "返回 (&X)"
Height = 375
Left = 2280
TabIndex = 5
Top = 3360
Width = 1215
End
Begin VB.TextBox txtNo
Height = 270
Left = 360
TabIndex = 11
TabStop = 0 'False
Top = 4320
Visible = 0 'False
Width = 735
End
Begin VB.Frame Frame1
Caption = "备注信息"
Height = 972
Left = 120
TabIndex = 10
Top = 2040
Width = 3612
Begin VB.TextBox txtItem
Height = 600
Index = 3
Left = 120
MultiLine = -1 'True
ScrollBars = 2 'Vertical
TabIndex = 3
Top = 240
Width = 3252
End
End
Begin VB.Frame Frame2
Caption = "商品信息"
Height = 1812
Left = 120
TabIndex = 6
Top = 120
Width = 3612
Begin VB.TextBox txtItem
Height = 270
Index = 2
Left = 1080
MaxLength = 20
TabIndex = 2
Top = 1320
Width = 2172
End
Begin VB.TextBox txtItem
Height = 270
Index = 1
Left = 1080
MaxLength = 20
TabIndex = 1
Top = 840
Width = 2172
End
Begin VB.TextBox txtItem
Height = 270
Index = 0
Left = 1080
MaxLength = 20
TabIndex = 0
Top = 360
Width = 2172
End
Begin VB.Label Label2
Caption = "商品名称:"
Height = 252
Index = 3
Left = 240
TabIndex = 9
Top = 360
Width = 972
End
Begin VB.Label Label2
Caption = "商品规格:"
Height = 252
Index = 4
Left = 240
TabIndex = 8
Top = 840
Width = 972
End
Begin VB.Label Label2
Caption = "计量单位:"
Height = 252
Index = 5
Left = 240
TabIndex = 7
Top = 1320
Width = 972
End
End
End
Attribute VB_Name = "frmProduct1"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Explicit
'是否改动过记录,ture为改过
Dim mblChange As Boolean
Public txtSQL As String
Private Sub cmdExit_Click()
If mblChange And cmdSave.Enabled Then
If MsgBox("保存当前记录的变化吗?", vbOKCancel + vbExclamation, "警告") = vbOK Then
'保存
Call cmdSave_Click
End If
End If
Unload Me
End Sub
Private Sub cmdSave_Click()
Dim intCount As Integer
Dim sMeg As String
Dim mrc As ADODB.Recordset
Dim MsgText As String
For intCount = 0 To 3
If Trim(txtItem(intCount) & " ") = "" Then
Select Case intCount
Case 0
sMeg = "商品名称"
Case 1
sMeg = "商品规格"
Case 2
sMeg = "计量单位"
End Select
sMeg = sMeg & "不能为空!"
MsgBox sMeg, vbOKOnly + vbExclamation, "警告"
txtItem(intCount).SetFocus
Exit Sub
End If
Next intCount
If gintGmode = 1 Then
txtSQL = "select * from products where ProductName ='" & Trim(txtItem(0)) & "' and Spec = '" & Trim(txtItem(1)) & "'"
Set mrc = ExecuteSQL(txtSQL, MsgText)
If mrc.EOF = False Then
MsgBox "已经存在相同内容的记录!", vbOKOnly + vbExclamation, "警告"
txtItem(0).SetFocus
Exit Sub
End If
mrc.Close
End If
If gintGmode = 2 Then
'先删除已有记录
txtSQL = "delete from products where ProductID ='" & Trim(txtNo) & "'"
Set mrc = ExecuteSQL(txtSQL, MsgText)
End If
'再加入新记录
txtSQL = "select * from products"
Set mrc = ExecuteSQL(txtSQL, MsgText)
mrc.AddNew
mrc.Fields(0) = txtNo
For intCount = 0 To 3
mrc.Fields(intCount + 1) = txtItem(intCount)
Next intCount
mrc.Update
mrc.Close
If gintGmode = 1 Then
For intCount = 0 To 3
txtItem(intCount) = ""
Next intCount
mblChange = False
MsgBox "添加商品信息成功!", vbOKOnly + vbExclamation, "添加商品信息"
Unload Me
If flagGedit Then
Unload frmProduct
frmProduct.txtSQL = "select * from products"
frmProduct.Show
End If
ElseIf gintGmode = 2 Then
Unload Me
If flagGedit Then
Unload frmProduct
End If
frmProduct.txtSQL = "select * from products"
frmProduct.Show
End If
End Sub
Private Sub Form_Load()
Dim sSql As String
Dim intCount As Integer
Dim MsgText As String
Dim mrcc As ADODB.Recordset
If gintGmode = 1 Then
Me.Caption = Me.Caption & "添加"
txtNo = GetRkno()
ElseIf gintGmode = 2 Then
Set mrcc = ExecuteSQL(txtSQL, MsgText)
If mrcc.EOF = False Then
With mrcc
txtNo = .Fields(0)
For intCount = 0 To 3
If Not IsNull(.Fields(intCount + 1)) Then
txtItem(intCount) = .Fields(intCount + 1)
End If
Next intCount
End With
End If
mrcc.Close
Me.Caption = Me.Caption & "修改"
End If
mblChange = False
End Sub
Private Sub Form_Unload(Cancel As Integer)
gintGmode = 0
End Sub
Private Sub txtItem_Change(Index As Integer)
'有变化设置gblchange
mblChange = True
End Sub
Private Sub txtItem_GotFocus(Index As Integer)
txtItem(Index).SelStart = 0
txtItem(Index).SelLength = Len(txtItem(Index))
End Sub
Private Sub txtItem_KeyDown(Index As Integer, KeyCode As Integer, Shift As Integer)
EnterToTab KeyCode
End Sub
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -