SMART CLIENT save architecture

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

We have a smart client but we have some difficulties with saving our
business objects. We would like to have one save method on the client side.
But our problem is that we can't find a good method to find out wathever we
should do an insert or an update on our server side.
What possibilities do you suggest to do this ...
thx in advance!!
 
To have a single save you can have a abstract class (object) that runs a
save, and then derive all other business objects from this abstract class.
So you put your save code here.. If the save is going to have different
implementation for each object, but same method signature, then define
interface and make all your business objects implement interface.. Whatever
fits you best, make a call.

For the server side.. DataAdapaters are the best way to interact with a DB
to insert and retrieve data

HTH
VJ
 
I am doing what you're talking about. Check out "Doing Objects in VB2005"
by Deborah Kurata. It just came out. It illustrates how to split your app
into layers, and then do updates on the business layer. Even if you are a
C# developer, this book can be really helpful to you. It's very pragmatic
and if you do the follow-along work, you end up building an entire
application.

I have a base class that all of my business objects inherit. It has a
property called EntityState that keeps track of the state of my object,
which matches the RowState of a DataSet.

Public Enum EntityStateEnum
Unchanged
Added
Deleted
Modified
End Enum

Private _EntityState As EntityStateEnum
Protected Property EntityState() As EntityStateEnum
Get
Return _EntityState
End Get
Private Set(ByVal value As EntityStateEnum)
_EntityState = value
End Set
End Property

'You can use this to check and see if anything has changed.
Protected ReadOnly Property IsDirty() As Boolean
Get
Return Me.EntityState <> EntityStateEnum.Unchanged
End Get
End Property

Protected Sub DataStateChanged(ByVal dataState As EntityStateEnum)
'if the state is deleted, mark it as deleted
'if they are adding a new one, mark it as an add so
' the stored procedure knows to insert it
If dataState = EntityStateEnum.Deleted _
Or dataState = EntityStateEnum.Added Then
Me.EntityState = dataState
End If
If Me.EntityState = EntityStateEnum.Unchanged _
OrElse dataState = EntityStateEnum.Unchanged Then
'they are changing it from add or change or delete back to
unchanged
'or from unchanged to something else
Me.EntityState = dataState
End If
End Sub

In my business object's class, I set dataSetChanged:
-- in the Create method, if adding, set it to Added
-- in the Create method, if it already exists, set it to Unchanged
-- in the Delete method, set it to Delete
-- in every property, if they change a value, set it to Modified.

When I call my Save routine, it calls my SP and passes in this EntityState
as a parameter; it is used in the SP to decide whether to Insert, Update,
or Delete the record. My SP contains all three queries.

Hope this helps.
Robin S.
Ts'i mahnu uterna ot twan ot geifur hingts uto.
 
Back
Top