Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Pass business object between winforms
Message
De
07/10/2004 15:04:06
 
 
À
Tous
Information générale
Forum:
ASP.NET
Catégorie:
The Mere Mortals .NET Framework
Titre:
Pass business object between winforms
Divers
Thread ID:
00949687
Message ID:
00949687
Vues:
67
I have a Winforms question.

I have a maintenance-type form that displays one record at a time. (No list, just one textbox per field.)

From this form, I want to open a second form, which will be a lookup form. The lookup form will just present a non-editable grid of records, and allow the user to select the one to open back in the main form.

When I open the lookup form, I would like to pass it the DataSet from the main form (from the primary business object). Since both forms need access to the same set of records, this seems to make more sense than having the lookup form hit the database to pull back a second copy of the same set of records.

In my first form, I have this basic code:
public class StoreCard : MyCompany.WarehouseSystem.Forms.mcCardForm
{
	private Store oStore;
	private DataSet dsStores;
	...
	public StoreCard()
	{
		this.oStore = (Store)this.RegisterPrimaryBizObj(new Store());
		InitializeComponent();
		this.NavControl = this.txtStoreNo;
		this.dsStores = this.oStore.GetStores();
	}
	...
}
Now, on to my question. In the lookup form, I plan to setup the constructor to take a business object as a parameter, like this:
public class StoreLookup : MyCompany.WarehouseSystem.Forms.mcLookupForm
{
	private Store oStore;
	private DataSet dsStores;
	...
	public StoreLookup(Store store)
	{
		oStore = (Store)this.RegisterPrimaryBizObj(store);
		InitializeComponent();
		this.dsStores = this.oStore.GetCurrentDataSet();
	}
	...
}
Is this the correct way to register the primary business object in this case: passing the already-instantiated store object to this.RegisterPrimaryBizObj and storing the return value in the form-level oStore variable?

Seems like this would have the same basic effect, but I'm hard-pressed to say one is better than the other:
public class StoreLookup : MyCompany.WarehouseSystem.Forms.mcLookupForm
{
	private Store oStore;
	private DataSet dsStores;
	...
	public StoreLookup(Store store)
	{
		oStore = store;
		this.RegisterPrimaryBizObj(oStore);
		InitializeComponent();
		this.dsStores = this.oStore.GetCurrentDataSet();
	}
	...
}
Also, big-picture, do you see any problems with this basic strategy? I'm striving to do things in the "MM.NET way" as much as possible. Am I missing a slicker approach to sharing the business object between forms?

Thanks,
Ric
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform