RobinS
Mon Feb 19 21:23:11 CST 2007
That's cool, and thanks for the link. I'll check it out. Maybe it'll be
easier than what I'm doing!
Robin S.
------------------------------
"alee via DotNetMonster.com" <u31808@uwe> wrote in message
news:6e1149f77b46a@uwe...
> Hello Robins,
>
> I already solved the problem. I literally followed the similar steps you
> took with one exception. That is I found a good VB.NET article from the
> following URL:
>
>
http://blogs.msdn.com/vbteam/archive/2005/04/14/TableAdaptersAndObjects.aspx
>
> Other than that I created one base class to hand entitystate (unchanged,
> modified, added,
> deleted) for all my entity classes to inherit from, and
> one extended BaseList class which extends the BindingList<T> to support
> all
> the
> entity state updates with a built in property DeletedRows, which is
> updated
> by
> the entitystate management code in the base class.
>
> By doing this, the Winform application simply uses the entity class
> object
> without any
> modifications.
>
> Thanks for your suggestions and comments.
>
> Cheers and Best regards,
>
> Alan L.
>
>
> RobinS wrote:
>>> Robin,
>>>
>>[quoted text clipped - 44 lines]
>>>
>>> Alan L.
>>
>>There's no such thing as a small example for this stuff. ;-)
>>
>>When I first tried to figure out how to make a list of my objects, show
>>them in a DataGridView, and support updating, it took me a few days, and
>>the help of those two books that I listed. I'm not using table adapters
>>or
>>data adapters or datasets to do my updates, I'm handling them myself
>>through my business class.
>>
>>The RowState stuff and methodology for updating, I got from Deborah
>>Kurata's "Doing Objects in VB2005". This is the book that taught me how
>>to
>>segment my application into 3 layers. I call a Stored Procedure in my
>>DataAccess layer to do the updates one object at a time, and have the SP
>>check the rowstate to determine which SQL statement in the SP to run,
>>just
>>like the data adapters work.
>>
>>I have a base class from which I derive all of my business layer objects.
>>In that class, I have a rowstate enumerator defined with the items
>>Unchanged, Added, Deleted, and Modified.
>>
>>When I load each object, I set it to unchanged, because it hasn't been
>>changed yet.
>> me.DataStateChanged(EntityStateEnum.Unchanged)
>>
>>In my class, in the Set for each property, if the value is changed, I
>>have
>>a call:
>> DataStateChanged(EntityStateEnum.Modified)
>>
>>When they add a new row:
>> DataStateChanged(EntityStateEnum.Added)
>>
>>When they delete a row, I check and make sure it's not one they have
>>added
>>that hasn't been committed yet. If it is, I just remove it. If it's not,
>>I
>>save it to a different list (so it doesn't show up in the grid) and do:
>> DataStateChanged(EntityStateEnum.Deleted)
>>I process these separately from the add/change list that is displayed to
>>the user.
>>
>>This is the method used to change the state of my object. You have to be
>>careful; you can't just arbitrarily change it. For example, if they add a
>>row, and then before committing the changes, they change a field in the
>>row, you don't want it marked as Modified, you want it to still be marked
>>as Added because it hasn't been added yet.
>>
>> 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
>>
>>A rowstate to expose this property (which is private):
>> Public ReadOnly Property RowState() as EntityStateEnum
>> Get
>> Return Me.EntityState
>> End Get
>> End Property
>>
>>I hope this helps. If you want to know how to bind a list of objects to a
>>DataGridView, and handle the updates w/o casting to a dataset, post your
>>e-mail address in some format I can recognize and I'll send you an
>>example.
>>It is not trivial the first time you do it. There may also be a way to do
>>it better, but I haven't had time to revisit it. It works, and works
>>well,
>>and that's all I need.
>>
>>Robin S.
>
> --
> Message posted via
http://www.dotnetmonster.com
>