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

📄 frmsalesman.frm

📁 超市的管理系统
💻 FRM
📖 第 1 页 / 共 2 页
字号:
        If MsgBox("确认要保存到数据库吗?", vbInformation + vbOKCancel, "保存确认!") = vbOK Then
        
            temp = frmQSale.MSFlexGrid1.TextMatrix(frmQSale.MSFlexGrid1.Row, 5)
        
            str1 = "update sales set productprice= " & "'" & TxtPrice.Text & "'" & "," & "saleamount=" & "'" & TxtAmount.Text & "'" & "where saleid=" & "'" & frmQSale.MSFlexGrid1.TextMatrix(frmQSale.MSFlexGrid1.Row, 6) & "'"
        
            QueryXFInfo (str1)
            
            str2 = "update salesinvoice set totalprices=" & "totalprices-" & Val(temp) & "+" & Val(TxtTotal.Text) & "where salesinvoiceid=" & "'" & frmQSale.TxtID.Text & "'"
            
            QueryXFInfo (str2)
            
            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 = TxtPrice.Text
            
            rct1.Fields.Item(3).Value = TxtAmount.Text
            
            rct2.MoveFirst
            
            Do While Not rct2.EOF
            
                If rct2.Fields.Item(0).Value = frmQSale.TxtID.Text Then         '根据销售单表中序号值找到相应的日期
            
                    rct1.Fields.Item(5).Value = rct2.Fields.Item(1).Value       '将日期赋值给销售表中的对应字段
                    
                    Exit Do
                    
                Else
                
                    rct2.MoveNext
                    
                End If
                
            Loop
            
            rct1.Fields.Item(6).Value = frmQSale.TxtID.Text
            
            rct1.UpdateBatch
            
            str2 = "update salesinvoice set totalprices=" & "totalprices+" & Val(TxtTotal.Text) & "where salesinvoiceid=" & "'" & frmQSale.TxtID.Text & "'"
            
            QueryXFInfo (str2)
           
            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 sales"
    
    Set rct1 = QueryXFInfo(str1)
    
    Dim str2 As String

    str2 = "select * from salesinvoice"
    
    Set rct2 = QueryXFInfo(str2)

    TxtID.Text = frmQSale.MSFlexGrid1.TextMatrix(frmQSale.MSFlexGrid1.Row, 1)
    
    TxtName.Text = frmQSale.MSFlexGrid1.TextMatrix(frmQSale.MSFlexGrid1.Row, 2)
    
    TxtPrice.Text = frmQSale.MSFlexGrid1.TextMatrix(frmQSale.MSFlexGrid1.Row, 3)
    
    TxtAmount.Text = frmQSale.MSFlexGrid1.TextMatrix(frmQSale.MSFlexGrid1.Row, 4)
    
    TxtTotal.Text = frmQSale.MSFlexGrid1.TextMatrix(frmQSale.MSFlexGrid1.Row, 5)
    
    TxtID.Enabled = False
    
    TxtName.Enabled = False
    
    TxtTotal.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
            
            TxtTotal.Text = Val(TxtPrice.Text) * Val(TxtAmount.Text)
            
            If Val(TxtTotal.Text) < 1 Then
                
                    TxtTotal.Text = "0" & Val(TxtTotal.Text)
                    
            End If
            
        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             '显示其响应的商品名称和单价
                        
                        TxtPrice.Text = rct.Fields.Item(2).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

Private Sub TxtPrice_LostFocus()

    If TxtPrice.Enabled = True Then

        If IsNumber(TxtPrice.Text) = True And TxtPrice.Text <> "0" Then
        
            TxtTotal.Text = Val(TxtPrice.Text) * Val(TxtAmount.Text)            '自动计算总金额
                
                If Val(TxtTotal.Text) < 1 Then
                
                    TxtTotal.Text = "0" & Val(TxtTotal.Text)
                    
                End If
            
        Else
        
            MsgBox "输入单价不合法,请重新输入!", vbInformation + vbOKOnly, "修改提示!"
            
            TxtPrice.Text = ""
            
            TxtPrice.SetFocus
            
            Exit Sub
    
        End If
        
    End If

End Sub

⌨️ 快捷键说明

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