c# - Sending data from childwindow to parentwindow -


i did small library homedal have class functions connect,disconnect,add,delete,showbooks etc. manage database.

now i'm doing client in wpf. in mainwindow, have variable of class homedal, , have button "add new record". clicking on button opens new window, have textboxes describe new record , button "make". clicking "make" button, close second window.

i want use variable homedal in mainwindow run 1 of functions doesn't work, , application crashes.

below function have in second window:

private void btnokclicked(object sender, routedeventargs e) {     mainwindow test = (mainwindow)this.parent;     book newbook = new book()     {         tytul = tbtytul.text,         autor = tbautor.text,         cena = int32.parse(tbcena.text),         przeczytane = tbprzeczytane.text     };     test.sqlconn.insertbook(newbook);     this.close(); }    

any tip why program crashes?

since have dal layer in application, suggest following based on

  1. your presentation tier mainwindow
  2. dataaccesslayer homedal.

the steps

  • when click on make button have now, create object of book type , populate values.
  • you create object homedal var dal = new homedal() or using ioc unity.
  • then pass newly created book object dal dal layer can persist data in database.

note: page object created each request , not have mix data access presentation tier, given have dal layer.

in case, sample this

 private void btnokclicked(object sender, routedeventargs e) {     book newbook = new book()     {         tytul = tbtytul.text,         autor = tbautor.text,         cena = int32.parse(tbcena.text),         przeczytane = tbprzeczytane.text     };     var dal = new homedal(); // pass initialization parameters if required dal self initialize.     var newbookid = dal.createbook(newbook);     // use mechanism show newly created book id user or else redirect user grid shows books sorted creation date book created shown first one.  }    

please let know understanding of implementation , share ideas.


Comments

Popular posts from this blog

SPSS keyboard combination alters encoding -

Add new record to the table by click on the button in Microsoft Access -

CSS3 Transition to highlight new elements created in JQuery -