📄 frm_hpout.frm
字号:
End
End
Begin VB.Label Label11
Caption = "借货人"
Height = 255
Left = 3675
TabIndex = 27
Top = 5160
Width = 660
End
Begin VB.Label Label10
Caption = "借货单位"
Height = 225
Left = 5220
TabIndex = 25
Top = 5160
Width = 840
End
Begin VB.Label Label9
ForeColor = &H00C00000&
Height = 315
Left = 90
TabIndex = 23
Top = 5160
Width = 3675
End
End
Attribute VB_Name = "frm_hpout"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Dim Moneys As Single
Dim i As Integer '运用在FOR循环中的变量
Dim StrTemp '用于显示编号信息的变量
Dim StrNum As Long '用于显示编号信息的变量
Dim ETemp As Integer '定义一个日志标识变量
'*** “添加”货品借出信息按钮的事件过程 ***
Private Sub Cmd_Add_Click()
For i = 0 To 5
Text1(i).Text = ""
Next i
Adodc1.RecordSource = "select * from tb_hpout order by ID"
Adodc1.Refresh
If Adodc1.Recordset.RecordCount > 0 Then
Adodc1.Recordset.MoveLast '将数据库中的记录移向最后一条
StrNum = Val(Adodc1.Recordset.Fields("ID")) + 1 '将记录编号的值加1
Select Case Len(Trim(StrNum)) '位数不足则补0
Case 1
StrTemp = "00000"
Case 2
StrTemp = "0000"
Case 3
StrTemp = "000"
Case 4
StrTemp = "00"
Case 5
StrTemp = "0"
Case 6
StrTemp = ""
End Select
Text1(0).Text = "JC" & Trim(StrTemp) & Trim(Str(StrNum))
Else
Text1(0).Text = "JC000001" '如果数据库中没有记录,则给编号赋一个初值
StrNum = 1
End If
Text1(1).SetFocus
Cmd_Save.Enabled = True
Cmd_Del.Enabled = False
End Sub
'*** “删除”货品借出信息按钮的事件过程 ***
Private Sub Cmd_del_Click()
rtn = SetWindowPos(Me.hwnd, -2, 0, 0, 0, 0, 3) '运用API函数SetWindowPos,来实现取消窗体置前的功能
If Adodc1.Recordset.EOF = False Then
c = MsgBox("您确认要删除该记录吗?", 17, "删除提示信息")
If c = vbOK Then
Adodc1.Recordset.Delete '删除货品借出信息
Adodc1.Refresh
Call main
adoRs.Open "select * from tb_KCXX where KC_name='" + Text1(2).Text + "' and KC_UNIT ='" + Combo1.Text + "' and KC_Price=" & Val(Text1(4).Text) & "", adoCon, adOpenKeyset, adLockOptimistic
If adoRs.RecordCount > 0 Then
Dim SNum As Integer
'重新计算库存货品的数量
SNum = Val(adoRs.Fields("KC_Num")) + Val(Text1(3).Text)
'修改该货品的库存数量
Set adoRs = adoCon.Execute("UPDATE tb_KCXX SET KC_Num='" + Str(SNum) + "' where KC_name='" + Text1(2).Text + "' and KC_UNIT ='" + Combo1.Text + "' and KC_Price=" & Val(Text1(4).Text) & "")
End If
adoCon.Close
ETemp = 1 '设置删除标识
Call joinRZ '调用添加日志过程
For i = 0 To 5
Text1(i).Text = ""
Next i
Cmd_Del.Enabled = False
End If
Else
MsgBox "当前数据库中已经没有可删除的记录", 64, "提示信息"
End If
Call TRefresh '调用数据刷新过程
End Sub
Private Sub Cmd_exit_Click()
Unload Me
End Sub
'*** “保存”货品借出信息按钮的事件过程 ***
Private Sub Cmd_save_Click()
rtn = SetWindowPos(Me.hwnd, -2, 0, 0, 0, 0, 3) '运用API函数SetWindowPos,来实现取消窗体置前的功能
Adodc1.RecordSource = "select * from tb_hpout where P_ID='" + Text1(0) + "'" '判断要保存的信息在数据库中是否已经存在
Adodc1.Refresh
If Adodc1.Recordset.RecordCount > 0 Then
MsgBox "该信息已经存在,信息保存不成功", 64, "保存信息提示"
Call TRefresh '调用数据刷新过程
Else
c = MsgBox("您确认要保存该信息吗?", 33, "保存信息提示")
If c = vbOK Then
'限制输入的信息不能为空值
If Text1(1).Text = "" Or Text1(3).Text = "" Or Text1(4).Text = "" Or Text2.Text = "" Or Text3.Text = "" Then
MsgBox "借货人信息、借货单位信息、货品数量、单价或名称不能为空值!", 48, "保存信息提示"
Else
'IsNumeric函数用于判断输入的信息是否为数值型数据,关于该函数的具体用法请参阅明日公司《Visual Basic 编程词典》中的函数应用部分 网址 www.cccxy.com
If Not IsNumeric(Text1(3).Text) Or Not IsNumeric(Text1(4).Text) Then
MsgBox "输入的货品数量或单价必须为数值型数据", 48, "保存信息提示"
Else
Call main '调用公共模块中连接数据库函数
'查询库存数据表当中是否存在要保存的货品编号记录
adoRs.Open "select * from tb_KCXX where KC_ids='" + Text1(1).Text + "'", adoCon, adOpenKeyset, adLockOptimistic
If adoRs.RecordCount > 0 Then
Dim SNum As Integer
'计算库存中的货品数量
SNum = Val(adoRs.Fields("KC_Num")) - Val(Text1(3).Text)
If SNum >= 0 Then
NumId = Val(Mid(Text1(0).Text, 2, Len(Text1(0).Text)))
Moneys = Val(Text1(3).Text) * Val(Text1(4).Text)
'保存货品借出信息
Set adoRs = adoCon.Execute("insert into tb_hpout (ID,P_ID,P_ids,P_name,P_UNIT,P_Num,P_Price,P_Money,P_Date,P_People,P_Remark,P_thr,P_thdw) values(" & StrNum & ",'" & Text1(0).Text & "','" & Text1(1).Text & "','" & Text1(2).Text & "','" & Combo1.Text & "','" & Text1(3).Text & "','" & Text1(4).Text & "','" & Moneys & "','" & Str(DTPicker1.Value) & "','" & Name1 & "','" & Text1(5).Text & "','" & Text3.Text & "','" & Text2.Text & "')")
'修改库存中相应货品的数量
Set adoRs = adoCon.Execute("UPDATE tb_KCXX SET KC_Num='" + Str(SNum) + "' where KC_ids='" + Text1(1).Text + "'")
MsgBox "信息保存成功", 64, "保存信息提示"
Cmd_Save.Enabled = False
Else
Dim Strs As String
Strs = "该货品的库存数量为 " & adoRs.Fields("kc_num") & " ,货品借出数量不应大于其库存数量"
MsgBox Strs, 48, "提示信息"
End If
End If
adoCon.Close
End If
End If
Else
End If
End If
Call TRefresh
End Sub
Private Sub Combo1_KeyDown(KeyCode As Integer, Shift As Integer)
If KeyCode = 13 Then
Text1(3).SetFocus
End If
End Sub
Private Sub DataGrid1_Click()
Call JionBack
Cmd_Del.Enabled = True
Cmd_Save.Enabled = False
End Sub
Private Sub DTPicker1_KeyDown(KeyCode As Integer, Shift As Integer)
If KeyCode = 13 Then '如果按下的是回车键,则光标落到文本框当中
Text1(5).SetFocus
End If
End Sub
Private Sub Form_Load()
rtn = SetWindowPos(Me.hwnd, -1, 0, 0, 0, 0, 3) '运用API函数SetWindowPos,来实现使窗体置前的功能
'利用代码连接数据库
Adodc1.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & App.Path & "\db_kcgl.mdb;Persist Security Info=False"
Adodc1.RecordSource = "select * from tb_hpout" '连接货品借出数据表
Adodc1.Refresh
Set DataGrid1.DataSource = Adodc1
Me.Left = (Screen.Width - Me.Width) / 2 '使窗体居中
Me.Top = (Screen.Height - Me.Height) / 2
DTPicker1.Value = Date
End Sub
Private Sub Text1_KeyDown(Index As Integer, KeyCode As Integer, Shift As Integer)
If KeyCode = 13 Then
If Index = 1 Then '如果光标落在第二个文本框当中,则调用frm_Tout窗体
frm_Tout.Show
frm_Tout.Left = 4100
frm_Tout.Top = 2750
frm_Tout.DataGrid1.SetFocus '光标直接落在frm_Tout窗体的DataGrid1控件当中
ElseIf Index = 2 Then
Combo1.SetFocus
ElseIf Index = 3 Then
Text1(4).SetFocus
ElseIf Index = 4 Then
DTPicker1.SetFocus
ElseIf Index = 5 Then
Text3.SetFocus
End If
End If
End Sub
'*** 自定义数据反绑定过程 ***
Private Sub JionBack()
Dim SLen As Integer
If Adodc1.Recordset.RecordCount > 0 Then
StrNum = Val(Adodc1.Recordset.Fields("P_ID"))
'Len函数用于取字符串的长度,Trim函数用于去除字符串中的空格,关于这两个函数的具体用法请参阅明日公司《Visual Basic 编程词典》中的函数应用部分 网址 www.cccxy.com
SLen = Len(Trim(StrNum))
Select Case SLen '位数不足则补0
Case 1
StrTemp = "00000"
Case 2
StrTemp = "0000"
Case 3
StrTemp = "000"
Case 4
StrTemp = "00"
Case 5
StrTemp = "0"
Case 6
StrTemp = ""
End Select
On Error Resume Next '执行错误处理
Text1(0).Text = Adodc1.Recordset(1) '将数据信息赋值到文本框当中
Text1(1).Text = Adodc1.Recordset(2)
Text1(2).Text = Adodc1.Recordset(3)
Combo1.Text = Adodc1.Recordset(4)
Text1(3).Text = Adodc1.Recordset(5)
Text1(4).Text = Adodc1.Recordset(6)
DTPicker1.Value = Adodc1.Recordset(8)
Text1(5).Text = Adodc1.Recordset(10)
Text2.Text = Adodc1.Recordset(12)
Text3.Text = Adodc1.Recordset(11)
End If
End Sub
'*** 自定义数据刷新过程 ***
Private Sub TRefresh()
Adodc1.RecordSource = "select * from tb_hpout order by P_ID"
Adodc1.Refresh
End Sub
'*** 自定义添加日志过程 ***
Private Sub joinRZ()
'添加系统日志
Open (App.Path & "\系统日志.ini") For Input As #1
Do While Not EOF(1)
Line Input #1, Intext
TStr = TStr + Intext + Chr(13) + Chr(10)
Loop
Close #1
If ETemp = 0 Then '添加修改信息日志
TStr = TStr + " " + Name1 + " " + Format(Now, "yyyy-mm-dd hh:mm:ss") + " " + "修改票号 " + Text1(0).Text + "(" + Text1(2).Text + ")" + Chr(13) + Chr(10)
ElseIf ETemp = 1 Then '添加删除信息日志
TStr = TStr + " " + Name1 + " " + Format(Now, "yyyy-mm-dd hh:mm:ss") + " " + "删除票号 " + Text1(0).Text + "(" + Text1(2).Text + ")" + Chr(13) + Chr(10)
End If
Open (App.Path & "\系统日志.ini") For Output As #1 '将日志信息保存到文件当中
Print #1, TStr
Close #1
End Sub
Private Sub Text2_KeyDown(KeyCode As Integer, Shift As Integer)
If KeyCode = 13 Then
Call Cmd_save_Click
Cmd_Add.SetFocus
End If
End Sub
Private Sub Text3_KeyDown(KeyCode As Integer, Shift As Integer)
If KeyCode = 13 Then
Text2.SetFocus
End If
End Sub
Private Sub Timer1_Timer() '通过时钟控件随时检测数据库中记录的条数
If Adodc1.Recordset.RecordCount > 0 Then
Label9.Caption = "目前数据库中共有 " & Adodc1.Recordset.RecordCount & " 条借出货品数据"
End If
End Sub
Private Sub Form_Unload(Cancel As Integer)
frm_main.Enabled = True
End Sub
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -