Saving Child Records Under a Transaction


Author
Message
Geoff Hirst
Geoff Hirst
StrataFrame User (221 reputation)StrataFrame User (221 reputation)StrataFrame User (221 reputation)StrataFrame User (221 reputation)StrataFrame User (221 reputation)StrataFrame User (221 reputation)StrataFrame User (221 reputation)StrataFrame User (221 reputation)StrataFrame User (221 reputation)
Group: Forum Members
Posts: 123, Visits: 3.5K
Guys,

It's getting late into the day on Sunday and I have been trying to wrap an area of code into a transaction. Now, first up without the transaction everything works fine.

When the transaction is in place, it all SEEMS to work fine. With the exception that it is only saving a single child record.

Now, what I am doing is creating an invoice (with lines) from a job form. Basically creating an invoice record and copying the parts used on the job, to invoice lines. No rocket science. No business rules broken. It all saves fine.

Until I go look at the invoice and there is only the very first invoice line saved. I have been through heaps of other posts and I guess I am falling foul of some IsDirty rule, but I can't see where. For the time being I have removed the transactional code. I would rather it was there though, given that it's invoice production.

Try

With Inv

.Add()

.CustomerID = Me.Job1.CustomerID

.SiteID = Me.Job1.InstallationID

.InvoiceDate = Date.Today

.OrderReference = Me.Job1.OrderReference

.InvoiceTotal = Me.Job1.TotalJobCost

.Status = 1 '

.Printed = False

.Terms = 1

.PaymentDue = Date.Today

.FreeForm = String.Empty

.Notes = "All goods remain the property of " & " until paid for in full." & ControlChars.CrLf

.InvoiceTotal = Me.Job1.TotalJobCost

' BusinessLayer.TransactionBegin("", Data.IsolationLevel.ReadCommitted)

.InvoiceNumber = GetNextInvoiceNumber(False)

' If .Save(True) = MicroFour.StrataFrame.Data.SaveUndoResult.Success Then

Try

Me.JobLine1.MoveFirst()

Do

With invline

.Add()

' .InvoiceID = Inv.ID

.Partcode = Me.JobLine1.PartCode

.Qty = Me.JobLine1.Qty

.LineTotal = Me.JobLine1.LineTotal

If AlarmInstallation1.NewBuild = True Then

.VATCode = "E" ' exempt

Else

.VATCode = 1 ' normal

Using vcode As New VATCodes

vcode.FillByPrimaryKey(.VATCode)

If vcode.CurrentRowIndex > -1 Then

vatrt += (.LineTotal * vcode.VATRate / 100)

Else

vatrt += 0 ' if the vatcode doesn't exist then we can't calculate it.

End If

End Using

End If

Select Case .Save(False)

Case MicroFour.StrataFrame.Data.SaveUndoResult.AbortedWithBrokenRules

System.Diagnostics.Debug.WriteLine("BR")

Case MicroFour.StrataFrame.Data.SaveUndoResult.Cancelled

System.Diagnostics.Debug.WriteLine("cancelled")

Case MicroFour.StrataFrame.Data.SaveUndoResult.CompletedWithExceptions

System.Diagnostics.Debug.WriteLine("CWR")

Case MicroFour.StrataFrame.Data.SaveUndoResult.FailedWithExceptions

System.Diagnostics.Debug.WriteLine("fwe")

Case MicroFour.StrataFrame.Data.SaveUndoResult.Success

System.Diagnostics.Debug.WriteLine("amazing!")

End Select

End With

Loop Until Me.JobLine1.MoveNext = False

Catch ex As Exception

Throw ex

End Try

'Else

'MessageForm.ShowMessage("Broken Rules:" & Inv.BrokenRules.ToString)

'End If

' BusinessLayer.TransactionCommit("")

' finally mark the job as invoiced so it can't be invoiced again.

With Me.Job1

.Edit()

.Invoiced = True

.Save()

End With

.Edit()

.VAT = vatrt

.Save()

End With

Me.tsbInvoiceJob.Enabled = Not Job1.Invoiced

Catch ex As Exception

MessageForm.ShowMessage("Alarm64 Job", "An unexpected issue has occurred. An email has been created and sent to Alarm64 Support" _

, "7001", MessageFunction.OK, MessagingIcon.Information, MessagingSounds.Notify)

SendemailException(ex, Me, "7001")

'BusinessLayer.TransactionRollback("")

End Try

Thanks for any ideas.

Geoff

GO

Merge Selected

Merge into selected topic...



Merge into merge target...



Merge into a specific topic ID...





Similar Topics

Reading This Topic

Login

Explore
Messages
Mentions
Search