⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 frm_kcpd.frm

📁 vb+aceess制作的库存管理系统
💻 FRM
📖 第 1 页 / 共 3 页
字号:
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_kcpd order by pd_ID"
        Adodc1.Refresh
           If Adodc1.Recordset.RecordCount > 0 Then
               Adodc1.Recordset.MoveLast                             '将数据库中的记录移向下一条
               StrNum = Val(Adodc1.Recordset.Fields("PD_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 = "Q" & Trim(StrTemp) & Trim(Str(StrNum))
           Else
               Text1(0).Text = "L000001"    '给库存盘点编号赋一个初值
               StrNum = 1
           End If
   Text1(1).SetFocus
   Cmd_Save.Enabled = True
   Cmd_Del.Enabled = False
   Cmd_Edit.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
                      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_edit_Click()
  rtn = SetWindowPos(Me.hwnd, -2, 0, 0, 0, 0, 3)     '运用API函数SetWindowPos,来实现取消窗体置前的功能
   If Text1(0).Text = "" Or Text1(1).Text = "" Then
      MsgBox "请选择需要改动的记录信息!", 48, "信息提示"
   Else
        c = MsgBox("确认要修改该记录吗?", 33, "修改信息提示")
           If c = vbOK Then
           '限制某些输入项不为空值
               If Text1(1).Text = "" Or Text1(3).Text = "" Or Text1(4).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                     '调用公共模块中的连接数据库函数
                            '修改库存盘点信息
                            Set adoRs = adoCon.Execute("UPDATE tb_kcpd SET pd_Name='" + Text1(1).Text + "',pd_SPEC='" + Text1(2).Text + "',pd_UNIT='" + Combo1.Text + "',pd_Num=" + Text1(3).Text + ",pd_dj=" + Text1(4).Text + ",pd_Date='" + Str(DTPicker1.Value) + "',pd_Remark='" + Text1(5).Text + "',PD_Mpeople='" + Text2.Text + "',PD_HPYC='" + Combo2.Text + "',PD_Mpeoples='" + Name1 + "',PD_mdate='" + Str(Now) + "' where pd_ID=" + Str(StrNum) + "")
                            ETemp = 0                   '设置修改标识
                            Call joinRZ                 '调用添加日志过程
                            MsgBox "信息修改成功", 64, "修改信息提示"
                            Cmd_Edit.Enabled = False
                          adoCon.Close                  '关闭数据连接
                      End If
                End If
            Else
            End If
   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_kcpd where pd_ID=" + Str(StrNum) + ""   '判断所要保存的数据信息在数据库中是否存在
  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 = "" Then
                  MsgBox "货品数量、单价、名称或者盘点员信息不能为空值!", 48, "保存信息提示"
               Else
                      If Not IsNumeric(Text1(3).Text) Or Not IsNumeric(Text1(4).Text) Then
                         MsgBox "输入的货品数量或单价必须为数值型数据", 48, "保存信息提示"
                      Else
                            Call main                                             '调用公共模块中的连接数据库函数
                               NumId = Val(Mid(Text1(0).Text, 2, Len(Text1(0).Text)))
                               '保存库存盘点信息
                               Set adoRs = adoCon.Execute("insert into tb_KCPD (pd_ID,pd_Name,pd_SPEC,pd_UNIT,pd_Num,pd_dj,pd_Date,PD_Mpeople,PD_HPYC,PD_Nums,PD_remark) values(" & StrNum & ",'" & Text1(1).Text & "','" & Text1(2).Text & "','" & Combo1.Text & "','" & Text1(3).Text & "','" & Text1(4).Text & "','" & Str(DTPicker1.Value) & "','" & Text2.Text & "','" & Combo2.Text & "'," & Text3.Text & ",'" & Text1(5).Text & "')")
                                  MsgBox "信息保存成功", 64, "保存信息提示"
                                  Cmd_Save.Enabled = False
                                 Call TRefresh                                     '调用数据刷新过程
                               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 Combo2_Click()
  If Combo2.Text <> "正常" Then
     Text3.Enabled = True
     Text3.SetFocus
  Else
     Text3.Enabled = False
  End If
End Sub

Private Sub Combo2_KeyDown(KeyCode As Integer, Shift As Integer)
   If KeyCode = 13 Then
     Call Cmd_save_Click
   End If
End Sub

Private Sub DataGrid1_Click()
  Call JionBack                                    '调用数据反绑定过程
  Cmd_Del.Enabled = True
  Cmd_Edit.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_kcpd"    '连接库存盘点数据表
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_Change(Index As Integer)
   Call main
   If Index = 3 Then
      adoRs.Open "select * from tb_KCXX where KC_name='" + Text1(1).Text + "' and KC_SPEC='" + Text1(2).Text + "' and KC_UNIT ='" + Combo1.Text + "'", adoCon, adOpenKeyset, adLockOptimistic
      If adoRs.RecordCount > 0 Then
         Dim SNum As Integer
         '重新计算库存货品的数量
         On Error GoTo x
         SNum = Val(adoRs.Fields("KC_Num")) - Val(Text1(3).Text)
         If SNum < 0 Then
           Combo2.Text = "报益"
           Text3.Text = Abs(SNum)     '取绝对值
         ElseIf SNum > 0 Then
           Combo2.Text = "报损"
           Text3.Text = SNum
         ElseIf SNum = 0 Then
           Combo2.Text = "正常"
           Text3.Text = 0
         End If
      End If
   End If
   adoCon.Close
x:
   Exit Sub
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
      ElseIf Index = 1 Then
          Text1(2).SetFocus
      ElseIf Index = 2 Then
          Combo1.SetFocus
      ElseIf Index = 3 Then
          Text1(4).SetFocus
      ElseIf Index = 4 Then
          DTPicker1.SetFocus
      ElseIf Index = 5 Then
          Text2.SetFocus
      End If
  End If
End Sub
Private Sub Text2_KeyDown(KeyCode As Integer, Shift As Integer)
   If KeyCode = 13 Then
     Combo2.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 JionBack()
Dim SLen As Integer
  If Adodc1.Recordset.RecordCount > 0 Then
      StrNum = Val(Adodc1.Recordset.Fields("pd_ID"))
      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 = "Q" & Trim(StrTemp) & Trim(Str(StrNum))
     Text1(1).Text = Adodc1.Recordset(1)                       '将数值信息反绑定到文本框当中
     Text1(2).Text = Adodc1.Recordset(2)
     Combo1.Text = Adodc1.Recordset(3)
     Text1(3).Text = Adodc1.Recordset(4)
     Text1(4).Text = Adodc1.Recordset(5)
     DTPicker1.Value = Adodc1.Recordset(7)
     Text1(5).Text = Adodc1.Recordset("pd_remark")
     Text2.Text = Adodc1.Recordset.Fields("PD_Mpeople")
     Combo2.Text = Adodc1.Recordset.Fields("PD_HPYC")
  End If
End Sub
'*** 自定义一个数据刷新的事件过程 ***
Private Sub TRefresh()
    Adodc1.RecordSource = "select * from tb_kcpd order by pd_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(1).Text + ")" + Chr(13) + Chr(10)
        ElseIf ETemp = 1 Then                  '添加保存信息日志
            TStr = TStr + "   " + Name1 + "               " + Format(Now, "yyyy-mm-dd hh:mm:ss") + "            " + "删除票号 " + Text1(0).Text + "(" + Text1(1).Text + ")" + Chr(13) + Chr(10)
        End If
      Open (App.Path & "\系统日志.ini") For Output As #1           '将日志信息保存到文件当中
      Print #1, TStr
      Close #1
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 + -