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

📄 frmslog.frm

📁 超市的管理系统
💻 FRM
📖 第 1 页 / 共 2 页
字号:
                
                    MSFlexGrid1.Col = 1
                        
                    MSFlexGrid1.Text = txtID.Text
                        
                    MSFlexGrid1.Col = 2
                        
                    MSFlexGrid1.Text = rct.Fields.Item(1).Value
                        
                    MSFlexGrid1.Col = 3
                    
                    If Val(rct.Fields.Item(2).Value) < 1 Then
                    
                        MSFlexGrid1.Text = "0" & rct.Fields.Item(2).Value
                        
                    Else
                        
                        MSFlexGrid1.Text = rct.Fields.Item(2).Value
                        
                    End If
                        
                    MSFlexGrid1.Col = 4
                    
                    If rct.Fields.Item(4) Like "*N*" Then           '判断销售数量是否可以是小数
                    
                        If Val(txtAmount.Text) < 1 Then
                        
                            MsgBox "销售数量输入不合法,请重新输入!", vbInformation + vbOKOnly, "错误提示!"
                            
                                txtAmount.Text = ""
                                
                                txtAmount.SetFocus
                                
                                If MSFlexGrid1.Rows > 2 Then
                                
                                    MSFlexGrid1.RemoveItem (MSFlexGrid1.Rows - 1)
                                    
                                    MSFlexGrid1.AddItem (Empty)
                                    
                                    n = n - 1
                                
                                    Exit Sub
                                    
                                Else
                                
                                    Call CmdClear_Click
                                    
                                    Exit Sub
                                    
                                End If
                                
                            Else
                    
                                MSFlexGrid1.Text = Int(Val(txtAmount.Text))
                                
                            End If
                        
                    Else
                    
                        If Val(txtAmount.Text) >= 1 Then
                    
                            MSFlexGrid1.Text = Val(txtAmount.Text)
                        
                        Else
                        
                            MSFlexGrid1.Text = "0" & Val(txtAmount.Text)            '如果数字类型常量的值小于1,在小数点前补0
                            
                        End If
                        
                    End If
                        
                    MSFlexGrid1.Col = 5
                        
                    TotalPrice = Val(rct.Fields.Item(2).Value) * Val(MSFlexGrid1.TextMatrix(MSFlexGrid1.Rows - 1, 4))
                    
                    If TotalPrice >= 1 Then
                    
                        MSFlexGrid1.Text = TotalPrice
                        
                    Else
                    
                        MSFlexGrid1.Text = "0" & TotalPrice
                         
                    End If
                    
                    MSFlexGrid1.Col = 6
                    
                    If (Val(sum) + TotalPrice) >= 1 Then
                    
                        MSFlexGrid1.Text = Val(sum) + TotalPrice
                    
                    Else
                    
                        MSFlexGrid1.Text = "0" & (Val(sum) + TotalPrice)
                        
                    End If
                    
                    sum = sum + TotalPrice
                        
                    rct.MoveFirst
                        
                    txtID.Text = ""
                        
                    txtAmount.Text = ""
                        
                    txtID.SetFocus
                        
                    MSFlexGrid1.AddItem (Empty)
                    
                    CmdClear.Enabled = True
                    
                    CmdDelete.Enabled = True
                        
                    Exit Sub
                    
                Else
                
                    MsgBox "该商品库存数量不足!", vbInformation + vbOKOnly, "输入提示!"
                    
                        txtID.Text = ""
                    
                        txtAmount.Text = ""
            
                        txtID.SetFocus
            
                        rct.MoveFirst

                        Exit Sub
                    
                End If
                    
            End If
                
        rct.MoveNext
        
        Loop
            
            MsgBox "数据库中无此商品记录,请重新核对!", vbInformation + vbOKOnly, "输入提示!"
            
            txtID.Text = ""
                    
            txtAmount.Text = ""
            
            txtID.SetFocus
            
            rct.MoveFirst
            
    Else
    
        MsgBox "购买数量不能为零!", vbInformation + vbOKOnly, "输入提示!"
                    
        txtAmount.Text = ""
                    
        txtAmount.SetFocus
    
    End If
    
Else
    
    MsgBox "商品编号购买数量不能为空,请重新输入!", vbInformation + vbOKOnly, "输入提示!"
        
    txtID.Text = ""
                
    txtAmount.Text = ""
        
    txtID.SetFocus
        
End If
                
End Sub

Private Sub Cmdgath_Click()

    MSFlexGrid1.AddItem (Empty)
    
    MSFlexGrid1.TextMatrix(MSFlexGrid1.Rows - 1, 0) = " "
    
    MSFlexGrid1.TextMatrix(MSFlexGrid1.Rows - 1, 1) = " "
    
    MSFlexGrid1.TextMatrix(MSFlexGrid1.Rows - 1, 2) = " "
    
    MSFlexGrid1.TextMatrix(MSFlexGrid1.Rows - 1, 3) = " "
    
    MSFlexGrid1.TextMatrix(MSFlexGrid1.Rows - 1, 4) = " "
    
    MSFlexGrid1.TextMatrix(MSFlexGrid1.Rows - 1, 5) = " "
    
    MSFlexGrid1.TextMatrix(MSFlexGrid1.Rows - 1, 6) = " "
    
    MSFlexGrid1.MergeCells = flexMergeFree                                    '合并两行显示总计金额
    
    MSFlexGrid1.MergeRow(MSFlexGrid1.Rows - 1) = True
    
    MSFlexGrid1.Row = MSFlexGrid1.Rows - 1
    
    MSFlexGrid1.RowHeight(MSFlexGrid1.Rows - 1) = 800
     
    MSFlexGrid1.Col = 0
    
    MSFlexGrid1.CellBackColor = QBColor(15)
    
    MSFlexGrid1.CellFontSize = 14
    
    MSFlexGrid1.Text = "金额总计为:" & sum & "元"
    
    CmdInput.Enabled = False
    
    CmdSave.Enabled = True
    
    CmdClear.Enabled = True
    
    CmdDelete.Enabled = False
    
End Sub

Private Sub CmdExit_Click()
    
    Unload Me

End Sub

Private Sub CmdDelete_Click()

    Dim intindex As Integer
    
    Dim temp As Single
    
    If MSFlexGrid1.Rows > 2 Then
    
        temp = Val(MSFlexGrid1.TextMatrix(MSFlexGrid1.Row, 5))                  '删除行的金额
        
         '依次将表格中所删记录后面的所有记录覆盖前一个记录,然后删除最后一个记录。
        
        For intindex = MSFlexGrid1.Row To MSFlexGrid1.Rows - 2
            
            MSFlexGrid1.TextMatrix(intindex, 1) = MSFlexGrid1.TextMatrix(intindex + 1, 1)
            
            MSFlexGrid1.TextMatrix(intindex, 2) = MSFlexGrid1.TextMatrix(intindex + 1, 2)
            
            MSFlexGrid1.TextMatrix(intindex, 3) = MSFlexGrid1.TextMatrix(intindex + 1, 3)
            
            MSFlexGrid1.TextMatrix(intindex, 4) = MSFlexGrid1.TextMatrix(intindex + 1, 4)
            
            MSFlexGrid1.TextMatrix(intindex, 5) = MSFlexGrid1.TextMatrix(intindex + 1, 5)
            
            MSFlexGrid1.TextMatrix(intindex, 6) = Val(MSFlexGrid1.TextMatrix(intindex + 1, 6)) - temp   '累计金额扣除删除行的金额
            
        Next intindex
    
        MSFlexGrid1.RemoveItem (MSFlexGrid1.Rows - 2)
    
        sum = sum - temp
    
        n = n - 1
        
    Else
    
        MsgBox "无记录可删除!", vbInformation + vbOKOnly, "删除提示!"
        
    End If

End Sub



Private Sub CmdSave_Click()

On Error GoTo error2


    Dim str1 As String
    
    Dim str2 As String

    Dim intindex As Integer
    
    Dim Id1 As Integer

    str1 = "select * from sales"

    Set rct1 = QueryXFInfo(str1)
    
    If rct1.EOF = True Then                          '销售表中如果没有记录,则表中序号从0计数,否则顺延上条记录的序号

        Id1 = 0

    Else

        rct1.MoveLast

        Id1 = rct1.Fields.Item(0).Value

    End If
    
    If MSFlexGrid1.TextMatrix(1, 0) <> "" Then

        For intindex = 1 To MSFlexGrid1.Rows - 3

            rct1.AddNew

            rct1.Fields.Item(0).Value = Id1 + 1

            rct1.Fields.Item(1).Value = MSFlexGrid1.TextMatrix(intindex, 1)

            rct1.Fields.Item(2).Value = MSFlexGrid1.TextMatrix(intindex, 3)

            rct1.Fields.Item(3).Value = MSFlexGrid1.TextMatrix(intindex, 4)

            rct1.Fields.Item(5).Value = txtDate.Text

            rct1.Fields.Item(6).Value = txtNumber.Text
            
            Id1 = Id1 + 1

            rct1.UpdateBatch
            
            rct.MoveFirst
            
            Do While Not rct.EOF
            
                If rct.Fields.Item(0).Value = MSFlexGrid1.TextMatrix(intindex, 1) Then
                    
                    '库存表中各商品库存量随销售数量变动
                    
                    rct.Fields.Item(3).Value = rct.Fields.Item(3).Value - Val(MSFlexGrid1.TextMatrix(intindex, 4))
                    
                    rct.UpdateBatch
                    
                    rct.MoveLast
                    
                End If
                
                rct.MoveNext
                
            Loop

        Next intindex
        
        rct2.AddNew
        
        rct2.Fields.Item(0) = txtNumber.Text
        
        rct2.Fields.Item(1) = txtDate.Text
        
        rct2.Fields.Item(2) = CSng(sum)
        
        rct2.UpdateBatch

        MsgBox "成功保存到数据库!", vbInformation + vbOKOnly, "保存成功!"

    Else

        MsgBox "无记录可保存!", vbInformation + vbOKOnly, "错误提示!"

    End If
    
    Call CmdClear_Click
    
    CmdDelete.Enabled = True
    
    rct.MoveFirst
    
    '保存完毕后,销售序号加1
    txtNumber.Text = "X" & Year(Date) & Month(Date) & Day(Date) & "N" & (Val(Right(txtNumber.Text, (Len(txtNumber.Text) - Len(Year(Date) & Month(Date) & Day(Date)) - 2))) + 1)
    
    CmdSave.Enabled = False

    Exit Sub

error2:

        MsgBox "错误代码:" & Err.Number & vbCrLf & _
        "错误描述:" & Err.Description, vbCritical + vbOKOnly, "错误!"

End Sub

Private Sub Form_Load()

    Dim str As String
    
    Dim str3 As String
    
    str3 = "X" & Year(Date) & Month(Date) & Day(Date)
    
    CmdSave.Enabled = False
    
    CmdClear.Enabled = False

    Call flexView
    
    str = "select * from storage"
    
    Set rct = QueryXFInfo(str)
    
    sum = 0
    
    txtDate.Text = Date
    
    str2 = "select * from salesInvoice"
    
    Set rct2 = QueryXFInfo(str2)
    
    
    If rct2.EOF = False Then           '销售序号表中无记录时,销售序号从0开始计数,否则按照日期进行依次排序

        rct2.MoveLast

        If Left((rct2.Fields.Item(0).Value), Len(str3)) = str3 Then
        
            txtNumber = "X" & Year(Date) & Month(Date) & Day(Date) & "N" & Val(Right((rct2.Fields.Item(0).Value), (Len(rct2.Fields.Item(0).Value) - Len(str3) - 1))) + 1
            
        Else
        
            txtNumber = "X" & Year(Date) & Month(Date) & Day(Date) & "N" & "1"
            
        End If
        
    Else
    
        txtNumber = "X" & Year(Date) & Month(Date) & Day(Date) & "N" & "1"
        
    End If
    
End Sub



Private Sub TxtAmount_LostFocus()

If txtAmount.Text <> "" Then

     If IsNumber(txtAmount.Text) = False Then
    
            MsgBox "销售数量输入不合法!", vbInformation + vbOKOnly, "输入提示!"
    
            txtAmount.Text = ""
    
            txtAmount.SetFocus
    
    End If
    
End If

End Sub


Private Sub txtID_LostFocus()

    If IsNumber(txtID.Text) = False Then

        MsgBox "商品编号输入不合法!", vbInformation + vbOKOnly, "输入提示!"

        txtID.Text = ""

        txtID.SetFocus

    End If
    

End Sub

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -