📄 form12.frm
字号:
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
ForeColor = &H00C00000&
Height = 240
Left = 195
TabIndex = 23
Top = 135
Width = 8355
End
End
Attribute VB_Name = "form12"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Dim j As Integer '用于FOR循环中的变量
Dim StrNum As Long '定义一个用于保存编号信息的变量
Dim j1, j2, j3 As Integer
Dim xx As String '定义保存选中要删除设备数量的变量
Dim count1 As Integer '控制全局变量count2只能获得最旧值
Dim c
'*** “添加”供应商信息按钮的事件过程 ***
Private Sub Cmd_Add_Click()
'On Error Resume Next
j1 = 1: j2 = 1: j3 = 1
Adodc1.RecordSource = "select * from ruku order by 业务编号"
Adodc1.Refresh
If Adodc1.Recordset.RecordCount > 0 Then
Adodc1.Recordset.MoveLast
StrNum = Val(Adodc1.Recordset.Fields("业务编号")) + 1
Text1(0).Text = Trim(Str(StrNum))
'''''''''''''***'''''''''''''
If count1 = 0 Then
count12 = StrNum
count1 = count1 + 1
End If
''''''''''''''***'''''''''''''
Else
count1 = 1
count12 = 1
Text1(0).Text = "1" '如果数据库中没有记录,则给供应商编号赋一个初值
End If
Text1(1).SetFocus
cmd_save.Enabled = True
cmd_del.Enabled = False
For j = 1 To 3
Text1(j).Text = ""
Next j
For j = 5 To 9
Text1(j).Text = ""
Next j
End Sub
'*** “删除”供应商信息按钮的事件过程 ***
Private Sub Cmd_del_Click()
If Text1(2).Text = "" Then
MsgBox "请选择您要删除的记录!", 48, "提示"
Exit Sub
End If
If count1 = 0 Then '排除刚启动窗体时的删除'''''''''''''
MsgBox "您只能删除本次所添加的记录,不能删除以前记录!", 48, "提示"
Exit Sub
End If
If Text1(0).Text < count12 Then
MsgBox "您只能删除本次所添加的记录,不能删除以前记录!", 48, "提示"
Exit Sub
End If
''''''''''''''''''''''''''''''''''''''''
If Adodc1.Recordset.EOF = False Then
c = MsgBox("您确认要删除该记录吗?", 17, "删除提示信息")
If c = vbOK Then
xx = Text1(3).Text ' 当删除该记录时,应先将该设备的数量留下来'
Adodc1.Recordset.Delete '删除所选中的记录信息
Adodc1.Refresh
Call main
adoRs.Open "select * from jiben_kc where 名称='" + Text1(1).Text + "' and 类别='" + Text1(2).Text + "'", adoCon, adOpenKeyset, adLockOptimistic
If adoRs.RecordCount > 0 Then
Dim SNum As Integer
'重新计算库存货品的数量
SNum = Val(adoRs.Fields("数量")) - Val(xx)
'修改该货品的库存数量
Set adoRs = adoCon.Execute("UPDATE jiben_kc SET 数量='" + Str(SNum) + "' where 名称='" + Text1(1).Text + "' and 类别='" + Text1(2).Text + "'")
End If
adoCon.Close
For j = 0 To 3
Text1(j).Text = ""
Next j
For j = 5 To 9
Text1(j).Text = ""
Next j
cmd_del.Enabled = False
End If
Call main '将库存中数量为0的货品清除掉
adoRs.Open "select * from jiben_kc ", adoCon, adOpenKeyset, adLockOptimistic
If adoRs.RecordCount > 0 Then
Set adoRs = adoCon.Execute("delete from jiben_kc where 数量='" + Str(0) + "'")
End If
adoCon.Close
Else
MsgBox "当前数据库中已经没有可删除的记录", 64, "提示信息"
End If
Call TRefresh '调用数据刷新过程
End Sub
Private Sub Cmd_exit_Click()
Unload Me
End Sub
'*** “保存”供应商信息按钮的事件过程 ***
Private Sub Cmd_save_Click()
c = MsgBox("您确认要保存该信息吗?", 33, "保存信息提示")
If c = vbOK Then
'限制输入的部分信息不能为空值
If Text1(1).Text = "" Or Text1(3).Text = "" Or Text1(5).Text = "" Or Text1(8).Text = "" Then
MsgBox "输入信息不完全!", 48, "保存信息提示"
Else
'IsNumeric函数用于判断输入的信息是否为数值型数据
If Not IsNumeric(Text1(3).Text) Or Not IsNumeric(Text1(5).Text) Or Not IsNumeric(Text1(6).Text) Then
MsgBox "输入的货品数量或单价必须为数值型数据", 48, "保存信息提示"
Else
Call main '调用公共模块中的连接数据库过程
Text1(6).Text = Val(Text1(3).Text) * Val(Text1(5).Text)
'保存货品入库信息
Set adoRs = adoCon.Execute("insert into ruku values('" & Text1(0).Text & "','" & Text1(1).Text & "','" & Text1(2).Text & "','" & Text1(3).Text & "','" & Combo1.Text & "','" & Text1(5).Text & "','" & Text1(6).Text & "','" & Text1(7).Text & "','" & Str(DTPicker1.Value) & "','" & Text1(8).Text & "','" & Text1(9).Text & "')")
'保存货品入库库存信息
adoRs.Open "select * from jiben_kc where 名称='" + Text1(1).Text + "' and 类别='" + Text1(2).Text + "'", adoCon, adOpenKeyset, adLockOptimistic
If adoRs.RecordCount > 0 Then
Dim SNum As Integer
'重新计算库存货品的数量
SNum = Val(adoRs.Fields("数量")) + Val(Text1(3).Text)
'修改该货品的库存数量
Set adoRs = adoCon.Execute("UPDATE jiben_kc SET 数量='" + Str(SNum) + "' where 名称='" + Text1(1).Text + "' and 类别='" + Text1(2).Text + "'")
Else
Adodc2.RecordSource = "select * from jiben_kc order by 编号"
Adodc2.Refresh
If Adodc2.Recordset.RecordCount > 0 Then
Adodc2.Recordset.MoveLast
StrNum = Val(Adodc2.Recordset.Fields("编号")) + 1
'如果库存中没有该货品的信息,则将入库货品信息保存到库存当中
Set adoRs = adoCon.Execute("insert into jiben_kc values(" & StrNum & ",'" & Text1(1).Text & "','" & Text1(2).Text & "','" & Text1(3).Text & "','" & Combo1.Text & "','" & Text1(5).Text & "','" & Text1(6).Text & "')")
Else
StrNum = 1
'如果库存中没有记录,则将入库货品信息保存到库存当中
Set adoRs = adoCon.Execute("insert into jiben_kc values(" & StrNum & ",'" & Text1(1).Text & "','" & Text1(2).Text & "','" & Text1(3).Text & "','" & Combo1.Text & "','" & Text1(5).Text & "','" & Text1(6).Text & "')")
End If
End If
MsgBox "信息保存成功", 64, "保存信息提示"
cmd_save.Enabled = False
Call TRefresh '调用数据刷新过程
adoCon.Close
End If
End If
Else
End If
Call TRefresh '调用数据刷新过程
End Sub
Private Sub Command2_Click()
tb = "ruku"
riqi = "入库日期"
Form17.Show 1
i = 1
End Sub
Private Sub DataGrid1_RowColChange(LastRow As Variant, ByVal LastCol As Integer)
Call JionBack '调用数据信息反绑定过程
cmd_del.Enabled = True
cmd_save.Enabled = False
End Sub
Private Sub Form_Load()
count1 = 0
Me.Left = (Screen.Width - Me.Width) / 2
Me.Top = (Screen.Height - Me.Height) / 2
j1 = 1
j2 = 1
j3 = 1
Combo1.ListIndex = 0
Text1(2).Text = ""
Text1(7).Text = ""
Text1(8).Text = ""
End Sub
'*** 自定义数据信息反绑定的过程 ***
Private Sub JionBack()
On Error Resume Next '执行错误处理
Dim SLen As Integer
If Adodc1.Recordset.RecordCount > 0 Then
StrNum = Val(Adodc1.Recordset.Fields("编号"))
'将数据信息反绑定到文本框当中
Text1(0).Text = Trim(Adodc1.Recordset(0))
Text1(1).Text = Trim(Adodc1.Recordset(1))
Text1(2).Text = Trim(Adodc1.Recordset(2))
Text1(3).Text = Trim(Adodc1.Recordset(3))
Combo1.Text = Trim(Adodc1.Recordset(4))
Text1(5).Text = Trim(Adodc1.Recordset(5))
Text1(6).Text = Trim(Adodc1.Recordset(6))
Text1(7).Text = Trim(Adodc1.Recordset(7))
DTPicker1.Value = Str(Adodc1.Recordset(8))
Text1(8).Text = Trim(Adodc1.Recordset(9))
Text1(9).Text = Trim(Adodc1.Recordset(10))
End If
End Sub
'*** 自定义数据刷新的过程 ***
Private Sub TRefresh()
Adodc1.RecordSource = "select * from ruku order by 业务编号"
Adodc1.Refresh
End Sub
Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)
sql = ""
End Sub
Private Sub Form_Unload(Cancel As Integer)
Form2.Enabled = True
count12 = count12 + 1
i = 0
End Sub
Private Sub Text1_click(Index As Integer) ''***************方便鼠标********
If Index = 2 Then
With Form9
.Frame2.Visible = False
.Frame3.Visible = True
End With
Form9.Show 1
End If
If Index = 7 Then
Load Form8
With Form8
.Frame2.Visible = False
.Frame3.Visible = True
End With
Form8.Show 1
End If
If Index = 8 Then
Load Form11
With Form11
.Frame2.Visible = False
.Frame3.Visible = True
End With
Form11.Show 1
End If
End Sub
Private Sub Text1_GotFocus(Index As Integer) '*************方便键盘操作,其中J1 J2 J3 为了不死循环****
If j1 = 1 And Index = 2 Then
j1 = 2
With Form9
.Frame2.Visible = False
.Frame3.Visible = True
End With
Form9.Show 1
End If
If j2 = 1 And Index = 7 Then
j2 = 2
Load Form8
With Form8
.Frame2.Visible = False
.Frame3.Visible = True
End With
Form8.Show 1
End If
If j3 = 1 And Index = 8 Then
j3 = 2
Load Form11
With Form11
.Frame2.Visible = False
.Frame3.Visible = True
End With
Form11.Show 1
End If
End Sub
Private Sub Text1_LostFocus(Index As Integer)
If Index = 5 Then
If Not IsNumeric(Text1(3).Text) Or Not IsNumeric(Text1(5).Text) Then
MsgBox "输入的货品数量或单价必须为数值型数据", 48, "保存信息提示"
Text1(3).Text = ""
Text1(5).Text = ""
Exit Sub
End If
If Text1(5) = "" Or Text1(3) = "" Then
MsgBox "请认真填写!", vbInformation, "错误信息"
Exit Sub
End If
Text1(6).Text = Val(Text1(3).Text * Text1(5).Text)
End If
End Sub
Private Sub Timer1_Timer() '通过时钟控件随时检测数据库中记录的条数
If Adodc1.Recordset.RecordCount > 0 Then
Label13.Caption = "目前数据库中共有 " & Adodc1.Recordset.RecordCount & " 条入库数据"
Else: Label13.Caption = "目前数据库中尚没有入库记录"
End If
End Sub
Private Sub Form_Activate()
'sql1 = "select * from " & sql
If i = 1 Then
If sql <> "" Then
Adodc1.RecordSource = sql1
Adodc1.Refresh
If Adodc1.Recordset.RecordCount > 0 Then
Call JionBack
Adodc1.Recordset.Update
Else
MsgBox "没有找到符合条件的记录!", , "提示窗口"
End If
End If
End If
End Sub
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -