Databinding entity with old and new value

Posts   
 
    
G.I.
User
Posts: 172
Joined: 09-Jun-2005
# Posted on: 13-Jul-2005 14:58:25   

Hi,

I have a grid bound to a customer. This grid has some readonly cells and some editable cells. Now my customer has a field name CustomerNo.

What I want is that in the grid there is a cell with header (Old CustomerNo) which shows the value of the customerNo in the database.

I also want a cell with the header New CustomerNo which the user can enter a value and also store this value somehow in the entity.

Is this possible? If yes, how? I'm using Infragistics by the way ....

Gr.,

G.I.

Fishy avatar
Fishy
User
Posts: 392
Joined: 15-Apr-2004
# Posted on: 13-Jul-2005 17:50:41   

I think you can add an unbound column and then in the initializerowlayout event grab the value of the customerno and place it in the unbound column.

G.I.
User
Posts: 172
Joined: 09-Jun-2005
# Posted on: 14-Jul-2005 14:41:24   

Yeah, that is easy, but what I want is to be able to keep the collection with the entities (which could be updated in the grid) and keep this in Session, than if you return to the page, I can read the collection back from the session, and show it in the grid again.

But that way I might already have changed the value, which makes it impossible to show it again with unbound column.

What I was thinking about, is using Customer Properties on the fields of which I have to keep the old values and store this old values in the properties and bind this somehow to the datagrid?

Or is it impossible to bind these, and do I have to set these cell values in the initialize_row event?

Does anyone have experience with this?

Gr.,

G.I.

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39933
Joined: 17-Aug-2003
# Posted on: 15-Jul-2005 10:20:47   

If you want to add new fields to an entity, you of course have to store the value somewhere, you can do that in a normal private variable. When you add a property to an entity to access the private variable, you'll see that property in the grid: all properties which aren't marked 'browsable(false)' are visable.

Please see in the documentation: "Using the generated code - Adding your own code to the generated classes" for more details about adding your own properties to generated code.

Frans Bouma | Lead developer LLBLGen Pro
G.I.
User
Posts: 172
Joined: 09-Jun-2005
# Posted on: 22-Jul-2005 15:41:57   

Ok...I have taken a look at it, and I don't really know how to do this.

What I want is:

Add a field to the entity, named OldCounter. At InitClass I want fill this field with the value of the field Counter

If I'm right: To make sure I won't loose these changes when generating new code, I have to derive from my entity and make a new class and add the code in there...

But how do I add new fields, also get the fieldIndex, so I can compare on it, etc. So I want almost the same functionality on this new field, except that I don't read/write from the database for this field.

Do you have an example somewhere, or paste some code here?

Gr.,

G.I.

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39933
Joined: 17-Aug-2003
# Posted on: 24-Jul-2005 11:55:28   

G.I. wrote:

Ok...I have taken a look at it, and I don't really know how to do this.

What I want is:

Add a field to the entity, named OldCounter. At InitClass I want fill this field with the value of the field Counter

If I'm right: To make sure I won't loose these changes when generating new code, I have to derive from my entity and make a new class and add the code in there...

No, you don't have to do that, please check 'Using the generated code - Adding your own code to the generated classes" for ideas how to add your own code to the entities safely.

But how do I add new fields, also get the fieldIndex, so I can compare on it, etc. So I want almost the same functionality on this new field, except that I don't read/write from the database for this field.

That's not possible. Entity fields which are used to form the entity's data, and which are thus stored in the db, are stored inside the fields object. Fields which aren't stored in the db, are thus available at runtime after the entity has been fetched or filled with data, and are normal properties added to the entity class.

Frans Bouma | Lead developer LLBLGen Pro
G.I.
User
Posts: 172
Joined: 09-Jun-2005
# Posted on: 25-Jul-2005 10:45:18   

Ok...I've been playing around this weekend and I have add two new private members, 2 new properties, added code for serialization/deserialization, but now I have one thing I wasn't able to do:

When I get a collection of entities, simply using getMulti, I want to have to new properties already filled with values. Simply put, I have a property called OldCounter which I want to be filled with the same value as the property Counter which is fetched from the database.

So I thought I could program this in the InitClassFetch function, simply in the usercode say:

 _oldCounter = Counter

But the value _oldCounter isn't being filled with the Counter value.

Am I putting this code at the wrong place? Or is this simply not possible and do I have to loop all over the collection after fetching to set these old values?

Gr.,

G.I.

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39933
Joined: 17-Aug-2003
# Posted on: 25-Jul-2005 12:27:36   

In selfservicing, at the moment this isnt' possible, InitClassFetch initializes the entity class when it is fetched using the constructor, e.g. CustomerEntity c = new CustomerEntity("foo");

For now, loop over it, these silly issues will be addressed in 1.0.2005.1, sorry for that.

Frans Bouma | Lead developer LLBLGen Pro
G.I.
User
Posts: 172
Joined: 09-Jun-2005
# Posted on: 25-Jul-2005 14:37:06   

Ok, but I have been thinking to switch my application towards Adapter, since I am using some objects in session in my web application and I am creating a business layer which I eventually will be using for several applications, including client windows applications, which makes it perfectly to use webservices or .Net Remoting and then it's great to be prepared for that already. Will it be possible to do what I want using adapter than? Is it also this initfuncion or another place?

Is there actually a performance penalty using Adapter or is that negligable?

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39933
Joined: 17-Aug-2003
# Posted on: 25-Jul-2005 15:02:43   

G.I. wrote:

Ok, but I have been thinking to switch my application towards Adapter, since I am using some objects in session in my web application and I am creating a business layer which I eventually will be using for several applications, including client windows applications, which makes it perfectly to use webservices or .Net Remoting and then it's great to be prepared for that already. Will it be possible to do what I want using adapter than? Is it also this initfuncion or another place?

In Adapter, you can add your code to InitClassEmpty. Please see this thread: http://www.llblgen.com/tinyforum/Messages.aspx?ThreadID=3194

Is there actually a performance penalty using Adapter or is that negligable?

They're on par in speed. In some areas selfservicing is a fraction faster, in other areas adapter is, but this is not noticable.

The validation hooks in the framework as well as hooks for adding your own code when some action happens aren't widely available in both paradigms, adapter has more hooks than selfservicing. In selfservicing for example, the entity is first created, then its fields object is filled with data. In adapter the fields object is first created, it's filled with data and then that's offered to the entity factory. This will be made the same in 1.0.2005.1, so selfservicing has more ways to add init code, and to make inheritance code work in selfservicing.

Frans Bouma | Lead developer LLBLGen Pro