📄 frmstockman.frm
字号:
VERSION 5.00
Begin VB.Form frmStockMOD
BackColor = &H00C0FFFF&
BorderStyle = 1 'Fixed Single
Caption = "修改进货记录"
ClientHeight = 4980
ClientLeft = 45
ClientTop = 435
ClientWidth = 5010
Icon = "frmStockMan.frx":0000
LinkTopic = "Form2"
MaxButton = 0 'False
MDIChild = -1 'True
MinButton = 0 'False
ScaleHeight = 4980
ScaleWidth = 5010
Begin VB.Frame Frame1
BackColor = &H00C0FFFF&
Height = 3375
Left = 360
TabIndex = 2
Top = 360
Width = 4335
Begin VB.TextBox TxtID
BeginProperty Font
Name = "宋体"
Size = 12
Charset = 134
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 375
Left = 1680
TabIndex = 6
Top = 480
Width = 2175
End
Begin VB.TextBox TxtName
BeginProperty Font
Name = "宋体"
Size = 12
Charset = 134
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 375
Left = 1680
TabIndex = 5
Top = 1140
Width = 2175
End
Begin VB.TextBox TxtAmount
BeginProperty Font
Name = "宋体"
Size = 12
Charset = 134
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 375
Left = 1680
TabIndex = 4
Top = 1800
Width = 2175
End
Begin VB.TextBox TxtCompany
BeginProperty Font
Name = "宋体"
Size = 12
Charset = 134
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 375
Left = 1680
TabIndex = 3
Top = 2520
Width = 2175
End
Begin VB.Label Label1
AutoSize = -1 'True
BackStyle = 0 'Transparent
Caption = "商品编号"
BeginProperty Font
Name = "宋体"
Size = 12
Charset = 134
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 240
Left = 360
TabIndex = 10
Top = 540
Width = 960
End
Begin VB.Label Label2
BackStyle = 0 'Transparent
Caption = "商品名称"
BeginProperty Font
Name = "宋体"
Size = 12
Charset = 134
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 240
Left = 360
TabIndex = 9
Top = 1215
Width = 960
End
Begin VB.Label Label3
AutoSize = -1 'True
BackStyle = 0 'Transparent
Caption = "厂商编号"
BeginProperty Font
Name = "宋体"
Size = 12
Charset = 134
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 240
Left = 360
TabIndex = 8
Top = 2580
Width = 960
End
Begin VB.Label Label4
AutoSize = -1 'True
BackStyle = 0 'Transparent
Caption = "进货数量"
BeginProperty Font
Name = "宋体"
Size = 12
Charset = 134
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 240
Left = 360
TabIndex = 7
Top = 1860
Width = 960
End
End
Begin VB.CommandButton CmdSave
Caption = "保 存(&S)"
BeginProperty Font
Name = "幼圆"
Size = 10.5
Charset = 134
Weight = 700
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 495
Left = 600
TabIndex = 1
Top = 4080
Width = 1575
End
Begin VB.CommandButton CmdExit
Caption = "退 出(&E)"
BeginProperty Font
Name = "幼圆"
Size = 10.5
Charset = 134
Weight = 700
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 495
Left = 2640
TabIndex = 0
Top = 4080
Width = 1575
End
End
Attribute VB_Name = "frmStockMOD"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Dim rct As New ADODB.Recordset '声明连接到库存表的记录集
Dim rct1 As New ADODB.Recordset '声明连接到进货表的记录集
Dim rct2 As New ADODB.Recordset '声明连接到进货单表的记录集
Private Sub CmdExit_Click()
Unload Me
End Sub
Private Sub CmdSave_Click()
Dim str1 As String
Dim id As Integer
If TxtAmount.Text = "" Then
MsgBox "进货数量不能为空,请重新输入!", vbInformation + vbOKOnly, "修改提示!"
TxtAmount.Text = ""
TxtAmount.SetFocus
Exit Sub
End If
If TxtID.Enabled = False Then '修改记录功能
If MsgBox("确认要保存到数据库吗?", vbInformation + vbOKCancel, "保存确认!") = vbOK Then
str1 = "update stock set stockamount= " & "'" & TxtAmount.Text & "'" & "where stockid=" & "'" & frmQStock.MSFlexGrid1.TextMatrix(frmQStock.MSFlexGrid1.Row, 5) & "'"
QueryXFInfo (str1)
MsgBox "已成功到数据库!", vbInformation + vbOKOnly, "保存提示!"
Else
Exit Sub
End If
Else '添加记录功能
If MsgBox("确认要保存到数据库吗?", vbInformation + vbOKCancel, "保存确认!") = vbOK Then
rct1.MoveLast
id = rct1.Fields.Item(0).Value
rct1.AddNew
rct1.Fields.Item(0).Value = id + 1
rct1.Fields.Item(1).Value = TxtID.Text
rct1.Fields.Item(2).Value = TxtAmount.Text
rct2.MoveFirst
Do While Not rct2.EOF
If rct2.Fields.Item(0).Value = frmQStock.TxtID.Text Then '根据进货单表中序号值找到相应的日期
rct1.Fields.Item(3).Value = rct2.Fields.Item(1).Value '将日期赋值给进货表中的对应字段
Exit Do
Else
rct2.MoveNext
End If
Loop
rct1.Fields.Item(4).Value = TxtCompany.Text
rct1.Fields.Item(5).Value = frmQStock.TxtID.Text
rct1.UpdateBatch
MsgBox "已成功到数据库!", vbInformation + vbOKOnly, "保存提示!"
Else
Exit Sub
End If
End If
End Sub
Private Sub Form_Load()
Dim str As String
str = "select * from storage"
Set rct = QueryXFInfo(str)
Dim str1 As String
str1 = "select * from stock"
Set rct1 = QueryXFInfo(str1)
Dim str2 As String
str2 = "select * from stockinvoice"
Set rct2 = QueryXFInfo(str2)
TxtID.Text = frmQStock.MSFlexGrid1.TextMatrix(frmQStock.MSFlexGrid1.Row, 1)
TxtName.Text = frmQStock.MSFlexGrid1.TextMatrix(frmQStock.MSFlexGrid1.Row, 2)
TxtAmount.Text = frmQStock.MSFlexGrid1.TextMatrix(frmQStock.MSFlexGrid1.Row, 3)
TxtCompany.Text = frmQStock.MSFlexGrid1.TextMatrix(frmQStock.MSFlexGrid1.Row, 4)
TxtID.Enabled = False
TxtName.Enabled = False
TxtCompany.Enabled = False
End Sub
'判断文本框输入的合法性
Private Sub TxtAmount_LostFocus()
rct.MoveFirst
If TxtAmount.Text <> "" Then
If IsNumber(TxtAmount.Text) = True And TxtAmount.Text <> "0" Then
Do While Not rct.EOF
If rct.Fields.Item(0).Value = TxtID.Text Then
If rct.Fields.Item(4) Like "*N*" Then '判断销售数量是否可以是小数
If Val(TxtAmount.Text) < 1 Then
MsgBox "销售数量输入不合法,请重新输入!", vbInformation + vbOKOnly, "修改提示!"
TxtAmount.Text = ""
TxtAmount.SetFocus
Exit Sub
Else
TxtAmount.Text = Int(Val(TxtAmount.Text))
End If
Else
If Val(TxtAmount.Text < 1) Then
TxtAmount.Text = "0" & Val(TxtAmount.Text)
End If
End If
Exit Do
Else
rct.MoveNext
End If
Loop
Else
MsgBox "销售输入数量不合法,请重新输入!", vbInformation + vbOKOnly, "修改提示!"
TxtAmount.Text = ""
TxtAmount.SetFocus
Exit Sub
End If
End If
End Sub
Private Sub txtID_LostFocus()
If TxtID.Enabled = True Then
If TxtID.Text <> "" Then
rct.MoveFirst
If IsNumber(TxtID.Text) = True Then
Do While Not rct.EOF
If rct.Fields.Item(0).Value = TxtID.Text Then '从库存记录中找到符合条件的记录
TxtName.Text = rct.Fields.Item(1).Value '显示起相应的商品名称和厂商编号
TxtCompany.Text = rct.Fields.Item(5).Value
Exit Sub
Else
rct.MoveNext
End If
Loop
MsgBox "数据库中无此商品记录,请重新核对!", vbInformation + vbOKOnly, "输入提示!"
TxtID.Text = ""
TxtID.SetFocus
Exit Sub
Else
MsgBox "商品编号输入不合法!", vbInformation + vbOKOnly, "输入提示!"
TxtID.Text = ""
TxtID.SetFocus
Exit Sub
End If
End If
End If
End Sub
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -