HElP!!! How to save parent and child data on single click

HElP!!! How to save parent and child data on single click

Old forum URL: forums.lhotka.net/forums/t/6795.aspx


khoogavin posted on Tuesday, April 14, 2009

How to save parent and child data on single click.

 

RockfordLhotka replied on Tuesday, April 14, 2009

This is the normal default behavior for CSLA objects. You can't actually call Save() on a child, you can only call Save() on a parent, and that will save the children too.

Please refer to Chapters 17 and 18 for much more detail.

khoogavin replied on Wednesday, April 15, 2009

Expert VB2005 Business Object (Second Edition).

This is the book we have. But we can't found the Chapter 17 and 18 in this book.

And the maximum Chapter in this book 12 only.

Can you give some example regarding this issue.

For our senario to create an Invoice, we need to create Invoice Header and Detail in single transaction but base on the example (ProjectTracker) , it'll insert the header and detail separately but this structure is not match for our senario.

Thanks and wait for your reply.

MarkD replied on Wednesday, April 15, 2009


You will want to look at Chapter 8 in the Expert VB2005 Business Objects (second edition).

In the DP_Update and DP_Insert of the parent, you'll have to call childCollection.Update

A sample of this can be found on page 435.

khoogavin replied on Saturday, April 18, 2009

The update command for detail row in grid worked now by using below command

Protected Sub QuotationDataSource_UpdateObject( _

ByVal sender As Object, ByVal e As Csla.Web.UpdateObjectArgs) _

Handles QuotationDataSource.UpdateObject

 

Dim obj As Quotation = GetQuotation()

Dim rid As Integer = CInt(e.Keys("QuotationID"))

Dim res As QuotationDetNew = obj.Quotation.GetItem(rid)

Csla.Data.DataMapper.Map(e.Values, res)

'e.RowsAffected = SaveQuotation(obj)

End Sub

 

But i facing a problem when i want to insert a detail row in grid (child)  such as quotation line items. Can somebody tell me how to save the key in values in grid instead direct to database. My problem code is below

 

QuotationDataSource_InsertObject

Dim res As QuotationDetNew = obj.Resources.GetItemDet("")

Dim res As QuotationDetNew = obj.Resources.GetItemDetCreate()

Csla.Data.DataMapper.Map(e.Values, res)

QuotaionDets.vb

Public Function GetItemDet(ByVal QuotationID As String) As QuotationDetNew

Return QuotationDetNew.AddQuotationDetNew()

End Function

 

QuotationDet.vb

Public Property UnitPrice() As Decimal

Get

CanReadProperty(True)

Return ms_UnitPrice

End Get

Set(ByVal Value As Decimal)

CanWriteProperty(True)

If ms_UnitPrice <> Value Then

ms_UnitPrice = Value

PropertyHasChanged()

End If

End Set

End Property

Public Property CostingLineNo() As String

Get

CanReadProperty(True)

Return ms_CostingLineNo

End Get

Set(ByVal Value As String)

CanWriteProperty(True)

If ms_CostingLineNo <> Value Then

ms_CostingLineNo = Value

PropertyHasChanged()

End If

End Set

End Property

 

Friend Shared Function AddQuotationDetNew() As QuotationDetNew

Return New QuotationDetNew("ABC")

End Function

 

Private Sub New(ByVal dr As String)

MarkAsChild()

End Sub

Am I miss out somethings? Hope to here your reply.

Thanks.

Copyright (c) Marimer LLC