Vous êtes sur la page 1sur 4

Private Sub cmdSave_Click()

If cIRowCount < 1 Then


MsgBox "Please enter item(s) before you can save this record.",
vbExclamation
NSPart.SetFocus
Exit Sub
End If

If toNumber(txtCT.Text) = 0 Then
MsgBox "Cash Tendered should greater than zero value.Please check it!",
vbExclamation
Exit Sub
End If

If toNumber(txtCT.Text) < toNumber(txtNetAmount.Text) Then


MsgBox "Cash Tendered should not be less than the Net Amount.Please check
it!", vbExclamation
Exit Sub
End If

If MsgBox("This save the record. Do you want to proceed?", vbQuestion +


vbYesNo) = vbNo Then Exit Sub

CN.BeginTrans

If State = AddStateMode Then


RS.AddNew
RS.Fields("SalesOrderID") = PK
RS.Fields("DateEncoded") = Format(Now, "M/d/yyyy")
RS.Fields("EncodedBy") = ACTIVE_USER.USERNAME

With Grid
For lngrow1 = .FixedRows To .Rows - 1
Set RSPartUpdate = New ADODB.Recordset
RSPartUpdate.Open "SELECT Spare_Parts.* FROM Spare_Parts WHERE
PartID ='" & .TextMatrix(lngrow1, 1) & "'", CN, adOpenDynamic, adLockOptimistic
RSPartUpdate![Inventory] = RSPartUpdate![Inventory] -
toNumber(.TextMatrix(lngrow1, 3))
RSPartUpdate![LastDateModified] = Now
RSPartUpdate![ModifiedBy] = ACTIVE_USER.USERNAME
RSPartUpdate.Update
Next lngrow1
End With

Else

RS.Fields("LastDateModified") = Now
RS.Fields("ModifiedBy") = ACTIVE_USER.USERNAME

If NSStatus.Text = "CL" And txtEntry(6).Text = "CANCELLED" Then


With Grid
For lngrow1 = .FixedRows To .Rows - 1
Set RSPartUpdate = New ADODB.Recordset
RSPartUpdate.Open "SELECT Spare_Parts.* FROM Spare_Parts WHERE
PartID ='" & .TextMatrix(lngrow1, 1) & "'", CN, adOpenDynamic, adLockOptimistic
RSPartUpdate![Inventory] = RSPartUpdate![Inventory] +
toNumber(.TextMatrix(lngrow1, 3))
RSPartUpdate![LastDateModified] = Now
RSPartUpdate![ModifiedBy] = ACTIVE_USER.USERNAME
RSPartUpdate.Update
Next lngrow1
End With
ElseIf NSStatus.Text = "OP" And txtEntry(6).Text = "OPEN" Then
With Grid
For lngrow1 = .FixedRows To .Rows - 1
Set RSPartUpdate = New ADODB.Recordset
RSPartUpdate.Open "SELECT Spare_Parts.* FROM Spare_Parts WHERE
PartID ='" & .TextMatrix(lngrow1, 1) & "'", CN, adOpenDynamic, adLockOptimistic
RSPartUpdate![Inventory] = RSPartUpdate![Inventory] -
toNumber(.TextMatrix(lngrow1, 3))
RSPartUpdate![LastDateModified] = Now
RSPartUpdate![ModifiedBy] = ACTIVE_USER.USERNAME
RSPartUpdate.Update
Next lngrow1
End With
ElseIf NSStatus.Text = "CM" And txtEntry(6).Text = "COMPLETED" Then
With Grid
For lngrow1 = .FixedRows To .Rows - 1
Set RSPartUpdate = New ADODB.Recordset
RSPartUpdate.Open "SELECT Spare_Parts.* FROM Spare_Parts WHERE
PartID ='" & .TextMatrix(lngrow1, 1) & "'", CN, adOpenDynamic, adLockOptimistic
RSPartUpdate![Inventory] = RSPartUpdate![Inventory] -
toNumber(.TextMatrix(lngrow1, 3))
RSPartUpdate![LastDateModified] = Now
RSPartUpdate![ModifiedBy] = ACTIVE_USER.USERNAME
RSPartUpdate.Update
Next lngrow1
End With
End If

With Grid2
For lngrow2 = .FixedRows To .Rows - 1
If .TextMatrix(lngrow2, 1) = "" Then
'DO NOTHING
Else
Set RSPartUpdate = New ADODB.Recordset
RSPartUpdate.Open "SELECT Spare_Parts.* FROM Spare_Parts WHERE
PartID ='" & .TextMatrix(lngrow2, 1) & "'", CN, adOpenDynamic, adLockOptimistic
RSPartUpdate![Inventory] = RSPartUpdate![Inventory] +
toNumber(.TextMatrix(lngrow2, 3))
RSPartUpdate![LastDateModified] = Now
RSPartUpdate![ModifiedBy] = ACTIVE_USER.USERNAME
RSPartUpdate.Update
End If
Next lngrow2
End With

End If

With RS
.Fields("CustomerID") = NSCustomer.Text
.Fields("CustomerName") = txtEntry(4).Text
.Fields("Address") = txtEntry(1).Text
.Fields("TelNo") = txtEntry(2).Text
.Fields("Date") = DTDP.Value
.Fields("SInstruction") = txtEntry(5).Text
.Fields("Salesman") = ACTIVE_USER.FULLNAME
.Fields("Remarks") = txtRemarks.Text
.Fields("FOP") = cmbFP.Text

.Fields("Gross") = txtGrossAmount.Text
.Fields("Discount") = txtDesc.Text
.Fields("TaxBase") = txtTaxBase.Text
.Fields("VAT") = txtVat.Text
.Fields("NetAmount") = txtNetAmount.Text
.Fields("CT") = txtCT.Text
.Fields("CA") = txtCA.Text
.Fields("StatusID") = NSStatus.Text
.Fields("StatusDesc") = txtEntry(6).Text

.Update
End With

DeleteItems

Dim c As Integer

With Grid

For c = 1 To cIRowCount
.Row = c
If State = AddStateMode Then
AddNew:
Dim RSSalesDetail As New Recordset

Set RSSalesDetail = New ADODB.Recordset


RSSalesDetail.CursorLocation = adUseClient
RSSalesDetail.Open "SELECT * FROM Sales_Order_Details ", CN,
adOpenStatic, adLockOptimistic

RSSalesDetail.AddNew

RSSalesDetail![SalesOrderID] = PK
RSSalesDetail![CustomerID] = NSCustomer.Text
RSSalesDetail![PartID] = .TextMatrix(c, 1)
RSSalesDetail![PartDescription] = .TextMatrix(c, 2)
RSSalesDetail![Qty] = toNumber(.TextMatrix(c, 3))
RSSalesDetail![UnitPrice] = toMoney(.TextMatrix(c, 4))
RSSalesDetail![GrossAmount] = toMoney(.TextMatrix(c, 5))

RSSalesDetail.Update

ElseIf State = EditStateMode Then

Set RSSalesDetail = New ADODB.Recordset


RSSalesDetail.CursorLocation = adUseClient
RSSalesDetail.Open "SELECT * FROM Sales_Order_Details WHERE
SalesOrderID=" & PK, CN, adOpenDynamic, adLockOptimistic

RSSalesDetail.Filter = "PartID = '" & .TextMatrix(c, 1) & "'"

If RSSalesDetail.RecordCount = 0 Then GoTo AddNew


RSSalesDetail![PartID] = .TextMatrix(c, 1)
RSSalesDetail![PartDescription] = .TextMatrix(c, 2)
RSSalesDetail![Qty] = toNumber(.TextMatrix(c, 3))
RSSalesDetail![UnitPrice] = toMoney(.TextMatrix(c, 4))
RSSalesDetail![GrossAmount] = toMoney(.TextMatrix(c, 5))
RSSalesDetail.Update

End If

Next c
End With

'Clear variables
c = 0

ResetEntry

CN.CommitTrans

HaveAction = True

If State = AddStateMode Then


MsgBox "New sales record has been successfully saved.", vbInformation

cmdPrintPreview_Click

Unload Me
Else
MsgBox "Changes in record has been successfully saved.", vbInformation
Unload Me
End If

Exit Sub

err:
CN.RollbackTrans
MsgBox "Error: " & err.Description, vbExclamation
Exit Sub
If err.Number = -2147217887 Then Resume Next
End Sub

Vous aimerez peut-être aussi