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
- your presentation tier
mainwindow - dataaccesslayer
homedal.
the steps
- when click on
makebutton have now, create object ofbooktype , populate values. - you create object
homedalvar dal = new homedal()or using iocunity. - 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
Post a Comment