c# - The best way to pass SDF objects between forms -


I want to find the best way to pass the object from SQL Server CE database into my desktop Winforms application to reduce memory. Am use

I have a local database connected to the project by a .sdf generated DBML.

In addition I have 4 forms:

  1. Mainform - A main parent form with the button to select the product object.
  2. ProductSelectForm - Form to select the product from the database. > Main Product Format - MDI children displaying information and charts about the selected product and button to edit this information.
  3. ProductForm - The form can add or edit new product about the selected product.

    I see two options: either to pass the item ID or pass the item object.

    Based on the example given below, by ID or by object: What would be the best way to pass the information between the form?

    Perhaps other recommendations?

    M Ann form:

      Public ManForm () {Initialize Component (); } Private Zero ProductSelectBarButton_ItemClick (Object Sender, ItemClickEventArgs e) {ProductSelectForm PSF = New ProductSelectForm (); If (psf. Shodiology () == Dialog Result. OK) {Main Productform MPF = New MainPaintForm (PSF Product Selected); MPF.MdiParent = This; MPF.Show (); } PSF.Dispose (); }   

    ProductSelectForm: public product ProductSelected = null; Public Product Styleform () {Initial Group (); } Private Zero OKButton_Click (Object Sender, EventArgs e) {var ActiveItem = ProductGrid.GetFocusedRowCellValue ("Product_ID"); Selected from the product = db.product. Where (x = & gt; x.Product_ID == (at) active item). Single (); This.Close (); }

    Main product form:

      public product cProduct; Public MainProductForm (Product Products) {InitializeComponent (); CProduct = Products; this. Text = cProduct.Product_Name; } Private Zero ProductEditBarButton_ItemClick (Object Sender, ItemClickEventArgs E) {ProductForm PF = New ProductForm (EditMode.Edit, cProduct.Product_ID); PF.ShowDialog (); PF.Dispose (); Form_Refresh (); }   

    Product Form:

      Private Products T = Null; Private editing mode method; Added public product product = faucet; Public product format (edit mode mode): this (mode, 0) {} public product format (edit mode mode, int id) {initialization (); Mode = mode; Switch (mode) {case (EditMode.Add): T = new product (); break; Case (EditMode.Edit): T = CurrentState.cdb.Product.Where (x => x.Product_ID == ID). Single (); Name Edit. Text = t. Product_name; break; }} Private Zero OKButton_Click (Object Sender, EventArgs e) {T.Product_Name = NameEdit.Text; If (mode == EditMode.Add) {DB.Product.InsertOnSubmit (T); } DB. SubmitChanges (); If (mode == EditMode.Add) ProductAdded = DB.Product.Where (x => x.Product_ID == T.Product_ID). Single (); This.Close (); }}    

    If you pass by ID, then each form will return data It is a lot of work for both the PC and for the developer from the database, the possibility of your product is completely negligible memory footprint. So if you have a memory-challenging system (and today means half -One-phone or break-calculator or something else), so if you are not programming in any way Create a system that uses little more memory in favor of lower battery use and few errors due to developer are not needed to change the wheel again in every form.

Comments

Popular posts from this blog

java - ImportError: No module named py4j.java_gateway -

python - Receiving "KeyError" after decoding json result from url -

.net - Creating a new Queue Manager and Queue in Websphere MQ (using C#) -