📄 form_incomeadd1.frm
字号:
End If
' 产品编号取条形码中的3到7位
Data1.RecordSource = "select * from hpos_products where (hpos_products.productCode ='" + Mid(text1.Text, g_barcode_product_start, g_barcode_weight_start - g_barcode_product_start) + "')"
Data1.Refresh
With Data1.Recordset
If Data1.Recordset.RecordCount > 0 Then
If Data1.Recordset.Fields("productCode") <> "" Then
'赋值给mf1表格
If IsNumeric(Mid(text1.Text, g_barcode_weight_start, g_barcode_length - g_barcode_weight_start)) Then
mf1.TextMatrix(mf1.Row, 6) = Format(Val(Mid(text1.Text, g_barcode_weight_start, g_barcode_length - g_barcode_weight_start)) / g_barcode_weight_base, "#0.00")
End If
If Not IsNull(.Fields("productName")) Then
mf1.TextMatrix(mf1.Row, 2) = .Fields("productName")
End If
If Not IsNull(.Fields("productModel")) Then
mf1.TextMatrix(mf1.Row, 3) = .Fields("productModel")
End If
If Not IsNull(.Fields("productSpecs")) Then
mf1.TextMatrix(mf1.Row, 4) = .Fields("productSpecs")
End If
If Not IsNull(.Fields("productUnit")) Then
mf1.TextMatrix(mf1.Row, 5) = .Fields("productUnit")
End If
If Not IsNull(.Fields("price")) Then
mf1.TextMatrix(mf1.Row, 7) = .Fields("price")
End If
If IsNumeric(mf1.TextMatrix(mf1.Row, 6)) And IsNumeric(mf1.TextMatrix(mf1.Row, 7)) Then
mf1.TextMatrix(mf1.Row, 8) = Val(mf1.TextMatrix(mf1.Row, 7)) * Val(mf1.TextMatrix(mf1.Row, 6))
mf1.TextMatrix(mf1.Row, 8) = Format(mf1.TextMatrix(mf1.Row, 8), "#0.00")
End If
mf1.TextMatrix(mf1.Row, 9) = "0.00"
mf1.TextMatrix(mf1.Row, 10) = "1"
mf1.TextMatrix(mf1.Row, 11) = "0.00"
If Not IsNull(.Fields("productId")) Then
mf1.TextMatrix(mf1.Row, 13) = .Fields("productId")
End If
text1.Text = mf1.Text '赋值给text1
' mf1.Row = mf1.Row + 1: mf1.Col = 1 '到达第5列
grid1.Visible = False
End If
Else
MsgBox "无此商品编号!", vbCritical, "警告"
grid1.Visible = False 'grid1不可见
If mf1.Row > 1 Then
' mf1.Row = mf1.Row - 1
text1.Visible = True
text1.SetFocus
text1.SelStart = 0
text1.SelLength = Len(text1.Text)
Exit Sub
End If
End If
End With
fillTotalDataFromDtlData
Call frm_main.movereturn '调用函数
mf1.Row = mf1.Row + 1: mf1.col = 1
End Sub
Private Sub text1_Change()
gridCustomer.Visible = False
mf1.Text = text1.Text '赋值给mf1.text
text1.Visible = True
If mf1.col = 1 Then
If Len(Trim(text1.Text)) = g_barcode_length Then
' Call fillDataFromBarcode
Call fillTotalDataFromDtlData
End If
End If
' 净重和价格变化时更新金额
If mf1.col = 6 Or mf1.col = 7 Then
If text1.Text <> "" And Not IsNumeric(text1.Text) Then
MsgBox "净重/价格必须为数值!", vbCritical, "输入错误"
text1.SetFocus
Exit Sub
End If
If IsNumeric(mf1.TextMatrix(mf1.Row, 6)) And IsNumeric(mf1.TextMatrix(mf1.Row, 7)) Then
mf1.TextMatrix(mf1.Row, 8) = Val(mf1.TextMatrix(mf1.Row, 6)) * Val(mf1.TextMatrix(mf1.Row, 7))
mf1.TextMatrix(mf1.Row, 8) = Format(mf1.TextMatrix(mf1.Row, 8), "#0.00")
End If
fillTotalDataFromDtlData
End If
' 轴重和件数变化时候更新总轴重
If mf1.col = 9 Or mf1.col = 10 Then
If text1.Text <> "" And Not IsNumeric(text1.Text) Then
MsgBox "件数/轴重必须为数值!", vbCritical, "输入错误"
text1.SetFocus
Exit Sub
End If
If IsNumeric(mf1.TextMatrix(mf1.Row, 9)) And IsNumeric(mf1.TextMatrix(mf1.Row, 10)) Then
mf1.TextMatrix(mf1.Row, 11) = Val(mf1.TextMatrix(mf1.Row, 9)) * Val(mf1.TextMatrix(mf1.Row, 10))
mf1.TextMatrix(mf1.Row, 11) = Format(mf1.TextMatrix(mf1.Row, 11), "#0.00")
End If
fillTotalDataFromDtlData
End If
End Sub
Private Sub Comdj_Click()
isAdd = True
'设置控件有效或无效
enableControls (True)
'清空数据
txtSupplier.Text = ""
txtBillId.Text = ""
supplierName.Text = ""
handler.Text = g_userName
' billNo.Text = ""
billDate.Text = CStr(Now)
text1.Text = ""
clearData mf1
clearData msfgTtl
supplierName.SetFocus
billNo.Text = getNextBillNo("hpos_StockIncomeBill_Master", "billNo")
End Sub
Private Sub Combc_Click()
Set rs1 = g_db.OpenRecordset("hpos_StockIncomeBill_Dtl", dbOpenTable)
Set rsMaster = g_db.OpenRecordset("hpos_StockIncomeBill_Master", dbOpenTable)
Dim hasDtl As Boolean
Dim billId As String
hasDtl = False
billId = CStr(getNextPK("hpos_StockIncomeBill_Master", "billId")) 'billNo.Text
txtBillId.Text = billId
Dim rsTmp As Recordset
' Set rsTmp = g_db.OpenRecordset("select fullName,orgId,orgCode,shortenedform from hpos_organization where orgType=1 and orgId=" + txtSupplier.Text + " and ((fullName = " + "'" + supplierName.Text + "" + "'" + ")or (shortenedform = " + "'" + supplierName.Text + "" + "'" + ")) order by fullName")
Set rsTmp = g_db.OpenRecordset("select fullName,orgId,orgCode,shortenedform from hpos_organization " _
& "where orgType=1 and ((fullName = " + "'" + supplierName.Text + "" + "'" + ")) order by fullName")
If rsTmp.EOF Then
MsgBox "无此供应商,请按【PageDown】键选择!", vbCritical, "数据无效"
txtSupplier.Text = ""
supplierName.Text = ""
supplierName.SetFocus
supplierName.SelStart = 0
supplierName.SelLength = Len(supplierName.Text)
Exit Sub
Else
txtSupplier.Text = rsTmp.Fields("orgId")
End If
If billNo.Text = "" Then
MsgBox "单据编号不能为空!", vbCritical, "数据无效"
billNo.SetFocus
Exit Sub
End If
Set rsTmp = g_db.OpenRecordset("select * from hpos_StockIncomeBill_Master where billType=" + CStr(m_billType) + " and billNo='" & billNo.Text & "'")
If rsTmp.RecordCount > 0 Then
MsgBox "单据编号已经存在,请输入其它!", vbCritical, "数据无效"
billNo.SetFocus
Exit Sub
End If
rsTmp.Close
For i = mf1.FixedRows To mf1.Rows - mf1.FixedRows
If mf1.TextMatrix(i, 13) <> "" And mf1.TextMatrix(i, 6) <> "" Then
hasDtl = True
rs1.AddNew
If billNo.Text <> "" Then rs1.Fields("billId") = billId
rs1.Fields("dtlId") = billId & i
' 产品ID
If mf1.TextMatrix(i, 13) <> "" Then rs1.Fields("productId") = mf1.TextMatrix(i, 13)
' 条形码
If mf1.TextMatrix(i, 1) <> "" Then rs1.Fields("barcode") = mf1.TextMatrix(i, 1)
If mf1.TextMatrix(i, 6) <> "" Then rs1.Fields("qty") = mf1.TextMatrix(i, 6)
If mf1.TextMatrix(i, 7) <> "" Then rs1.Fields("price") = mf1.TextMatrix(i, 7)
If mf1.TextMatrix(i, 9) <> "" Then rs1.Fields("axesWeight") = mf1.TextMatrix(i, 9)
If mf1.TextMatrix(i, 10) <> "" Then rs1.Fields("pieceQty") = mf1.TextMatrix(i, 10)
If mf1.TextMatrix(i, 12) <> "" Then rs1.Fields("comment") = mf1.TextMatrix(i, 12)
rs1.Update '更新表
End If
Next i
If Not hasDtl Then
MsgBox "没有数据可保存,请输入明细!", vbCritical, "警告"
Exit Sub
End If
If hasDtl Then
rsMaster.AddNew
' 店铺(仓库)标识
rsMaster.Fields("store") = g_store
rsMaster.Fields("billType") = m_billType
' 单据ID--主关键字
If billNo.Text <> "" Then rsMaster.Fields("billId") = billId
If supplierName.Text <> "" Then rsMaster.Fields("supplier") = txtSupplier.Text
If handler.Text <> "" Then rsMaster.Fields("handler") = handler.Text
If billDate.Text <> "" Then rsMaster.Fields("billDate") = CDate(billDate.Text) ' Now 'billDate.Text
If billNo.Text <> "" Then rsMaster.Fields("billNo") = billNo.Text
rsMaster.Update
End If
rsMaster.Close
rs1.Close
MsgBox "保存成功!", vbInformation, "提示"
isAdd = False
'清空数据
clearData mf1
clearData msfgTtl
supplierName.Text = "": handler.Text = ""
billNo.Text = ""
text1.Visible = False: gridCustomer.Visible = False '设置控件不可见
enableControls (False)
End Sub
Private Sub Comqx_Click() '取消操作
supplierName.Text = "": handler.Text = ""
clearData mf1
enableControls (False)
End Sub
Private Sub Comend_Click()
frm_main.Enabled = True
Unload Me
End Sub
Private Sub text1_Validate(Cancel As Boolean)
If Len(Trim(text1.Text)) = g_barcode_length And mf1.col = 1 Then
Call fillDataFromBarcode
mf1.Row = mf1.Row - 1
ElseIf mf1.col = 1 And Trim(text1.Text) <> "" Then
MsgBox "条形码长度必须为" & CStr(g_barcode_length) & "位", vbCritical, "警告"
Cancel = True
End If
End Sub
' 校验某列的数据输入是否有效;diffRow:0-表示当前行,-1表示上一行,1表示下一行。
Private Function checkData(col As Integer, colName As String, diffRow As Integer) As Boolean
If mf1.Row > mf1.FixedRows - 1 Then
If Not Trim(mf1.TextMatrix(mf1.Row, 1)) = "" And (mf1.col = col Or mf1.col = 1) And Not IsNumeric(Mid(Trim(mf1.TextMatrix(mf1.Row, 1)), g_barcode_weight_start, g_barcode_length - g_barcode_weight_start)) Then
MsgBox colName + "必须为数值!", vbCritical, "输入错误"
If mf1.Row > 1 Then
mf1.Row = mf1.Row + diffRow
text1.Visible = True
text1.SetFocus
text1.SelStart = 0
text1.SelLength = Len(text1.Text)
Exit Function
End If
checkData = False
Else
checkData = True
End If
End If
End Function
Private Sub clearData(msfg As MSFlexGrid)
For R = msfg.FixedRows To msfg.Rows - msfg.FixedRows
For C = msfg.FixedCols To msfg.Cols - msfg.FixedCols
msfg.TextMatrix(R, C) = ""
Next
Next
End Sub
' 计算累计净重和轴重
Private Sub fillTotalDataFromDtlData()
clearData msfgTtl
For R = mf1.FixedRows To mf1.Rows - mf1.FixedRows
' 只对存在的物料进行净重、轴重等的累加
If mf1.TextMatrix(R, 13) <> "" Then
For i = msfgTtl.FixedRows To msfgTtl.Rows - msfgTtl.FixedRows
If msfgTtl.TextMatrix(i, 10) = mf1.TextMatrix(R, 13) Then
'对于存在的物料(productId相等)净重、轴重等累加
msfgTtl.TextMatrix(i, 6) = Format(Val(msfgTtl.TextMatrix(i, 6)) + Val(mf1.TextMatrix(R, 6)), "#0.00") '净重
msfgTtl.TextMatrix(i, 7) = Format(Val(msfgTtl.TextMatrix(i, 7)) + Val(mf1.TextMatrix(R, 8)), "#0.00") '金额
msfgTtl.TextMatrix(i, 8) = Format(Val(msfgTtl.TextMatrix(i, 8)) + Val(mf1.TextMatrix(R, 10)), "#0.00") '件数
msfgTtl.TextMatrix(i, 9) = Format(Val(msfgTtl.TextMatrix(i, 9)) + Val(mf1.TextMatrix(R, 11)), "#0.00") '轴重
Exit For
Else '对于没有的物料新增一行并填充数据
If msfgTtl.TextMatrix(i, 10) = "" Then
' msfgTtl.Rows = msfgTtl.Rows + 1
msfgTtl.TextMatrix(i, 1) = Mid(mf1.TextMatrix(R, 1), g_barcode_product_start, g_barcode_weight_start - g_barcode_product_start)
For col = 2 To 6
msfgTtl.TextMatrix(i, col) = mf1.TextMatrix(R, col)
Next
msfgTtl.TextMatrix(i, 6) = mf1.TextMatrix(R, 6) '净重
msfgTtl.TextMatrix(i, 7) = mf1.TextMatrix(R, 8) '金额
msfgTtl.TextMatrix(i, 8) = mf1.TextMatrix(R, 10) '件数
msfgTtl.TextMatrix(i, 9) = mf1.TextMatrix(R, 11) '轴重
msfgTtl.TextMatrix(i, 10) = mf1.TextMatrix(R, 13) ' productId
Exit For
End If
End If
Next
End If
Next
End Sub
' 激活或者去活相关控件
Private Sub enableControls(flag As Boolean)
supplierName.Enabled = flag
handler.Enabled = flag
billNo.Enabled = flag
' 网格
text1.Enabled = flag
mf1.Enabled = flag
msfgTtl.Enabled = flag
' 按钮
Combc.Enabled = flag
Comqx.Enabled = flag
Comdj.Enabled = Not flag
End Sub
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -