Dim RawmaterialID As String
Dim cRealQuantity As Double
'1.เลือกส่วนประกอบของสินค้าที่เป็นวัตถุดิบและจำนวนวัตถุดิบ
Dim pas = db.Components.FirstOrDefault(Function(id) id.ProductID = ProductID)
RawmaterialID = CStr(Convert.ToInt32(pas.RawMaterialID))
cRealQuantity = Convert.ToInt32(pas.RealQuantity * Amount)
'2.เลือกวัตถุดิบและจำนวนวัถุดิบในสาขาของตัวเอง
Dim psms = From psm In db.RawMaterialOnBranches
Where psm.RawMaterialID = RawmaterialID
Where psm.BranchID = BizConfig.BranchID
If psms IsNot Nothing Then
For Each pi In psms
Dim sRawmaterial = pi.RawMaterialID
Dim sRealQuantity = pi.RealQuantity
'นำ 1 และ 2 มาลบกัน
Dim pis = db.RawMaterialOnBranches.FirstOrDefault(Function(id) id.RawMaterialID = RawmaterialID)
CurrentRealQuantity = CDbl(Convert.ToInt32(sRealQuantity - cRealQuantity))
pi.RealQuantity = Convert.ToInt32(CurrentRealQuantity)
If pis IsNot Nothing Then
End If
Next
End If
End If
Next
db.CashSales.InsertOnSubmit(cs)
db.SubmitChanges()
ts.Complete()
End Using
End If
ขอบคุณล่วงหน้านะครับ
Tag : .NET, Ms SQL Server 2008, VB.NET, VS 2012 (.NET 4.x)
Dim pas = db.Components.FirstOrDefault(Function(id) id.ProductID = ProductID)
cRawmaterial = CStr(Convert.ToInt32(pas.RawMaterialID))
OldRealQuantity = Convert.ToInt32(pas.RealQuantity)
Dim psms = From psm In db.RawMaterialOnBranches _
Where psm.RawMaterialID = cRawmaterial And psm.BranchID = BizConfig.BranchID
If psms IsNot Nothing Then
For Each pi In psms
oOldRealQuantity = Convert.ToInt32(pi.RealQuantity)
pi.RealQuantity = CType(Convert.ToDouble(oOldRealQuantity - OldRealQuantity), Integer)
Next
End If
End If
Next
db.CashSales.InsertOnSubmit(cs)
db.SubmitChanges()
ts.Complete()