|
BOOK: ASP.NET 2.0 Website Programming Problem Design Solution ISBN: 978-0-7645-8464-0 | This is the forum to discuss the Wrox book ASP.NET 2.0 Website Programming: Problem - Design - Solution by Marco Bellinaso; ISBN: 9780764584640 |
|
Welcome to the p2p.wrox.com Forums.
You are currently viewing the BOOK: ASP.NET 2.0 Website Programming Problem Design Solution ISBN: 978-0-7645-8464-0 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
|
|
|
|
November 21st, 2007, 07:02 PM
|
Authorized User
|
|
Join Date: Nov 2007
Posts: 76
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
single submit to related tables
ok, so i have this form which feeds a lot of tables. typical setup is header fields followed by contact details. the contact details go into a contactdetails table, the header fields go into a header table. i need the newly inserted id from the header so that i can put it into the [related] details table. trouble is this all happens on a single submit button. how does tbh handle this situation?
thanks for any help.
|
November 22nd, 2007, 06:25 AM
|
Friend of Wrox
|
|
Join Date: Mar 2007
Posts: 488
Thanks: 2
Thanked 11 Times in 10 Posts
|
|
forumuser - look at the BLL/store/order.cs class. it uses transactionscope to allow the order header and items to be inserted as a single transaction. this will probably be your closest example and will be easily modelled for your own use. look at InsertOrder and UpdateOrder for examples of useage.
jimi
http://www.originaltalent.com
|
November 22nd, 2007, 12:10 PM
|
Authorized User
|
|
Join Date: Nov 2007
Posts: 76
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
thanks jimi. that was roughly what i was looking for. here's another...
i have a usercontrol [an ascx file, for contact details] inside a nested formview, which has it's own objdatasource, that feeds a table [ContactDetails]. when i submit the form, the parent formview goes to a table [Report] and returns the ID of the newly inserted row. i use that ID to insert the contact details into the ContactDetails table. how do i access the contact details which were entered into the user control which is nested inside it's own formview inside the parent formview? this is transactional and the transaction [using transactionscope] takes place in the BLL class for the parent formview.
does this all make sense? this is me trying to re-model an already working form which currently uses datasets. seemed sooooo much more intuitive using datasets! :)
some code, [the formviews are not nested here]:
<asp:FormView ID="fvContactDetails" runat="server" DataSourceID="dsContactDetails" DefaultMode="In sert" Width="100%">
<InsertItemTemplate>
<uc1:UCContactDetails id="UCContactDetails" runat="server"></uc1:UCContactDetails>
</InsertItemTemplate>
</asp:FormView>
<asp:FormView ID="fvReport" runat="server" DataSourceID="dsReport" DataKeyNames="ReportID" DefaultMode="Insert" Width="100%">
<InsertItemTemplate>
<fieldset><legend>Report Header</legend>
<ol>
<li>
etc etc
</fieldset>
</InsertItemTemplate>
</asp:FormView>
in the BLL:
[DataObjectMethod(DataObjectMethodType.Insert, true)]
public static int InsertReport(DateTime? date, string time, string details,
string happened, string scene, string action)
{
using (TransactionScope scope = new TransactionScope())
{
int newReportID = SiteProvider.Report.InsertReport(new ReportsEntity(
0,
date,
time,
details,
happened,
scene,
action));
// Insert the contact details. Some dummy data....
//ContactDetailsEntity contactDetail =
// new ContactDetailsEntity(0, newReportID, 1, 1, 2, "ghfds", "hgfsd", "sdfg", "qwer", "sadf", "876 8756",
// "5432 5432", "qwer@ytre");
//SiteProvider.ContactDetails.InsertContactDetail(co ntactDetail);
/////////////////////////////////
Need to get the UCContactDetails fields here to create a ContactDetails for insertion
/////////////////////////////////
PurgeCacheItems("Report_Reports");
scope.Complete();
return newReportID;
}
}
|
November 22nd, 2007, 04:31 PM
|
Authorized User
|
|
Join Date: Nov 2007
Posts: 76
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
i can do all this nicely out in the UI code-behind by removing the objectdatasources and formviews [they use reflection anyway!!!] and manually handling the submit/postback:
protected void btnSubmit_Click(object sender, EventArgs e)
{
if (Page.IsValid)
{
using (TransactionScope scope = new TransactionScope())
{
int newID =
Report.InsertReport(Convert.ToDateTime(Date.Text), Time.Text,
Details.Text,
Where.Text, Scene.Text, Action.Text);
ContactDetail.InsertContactDetail(newID, 1, 1, 1, UCContactDetails.name, UCContactDetails.address1,
UCContactDetails.address2, UCContactDetails.town,
UCContactDetails.postcode, UCContactDetails.telephone,
UCContactDetails.mobile, UCContactDetails.email);
scope.Complete();
}
}
}
is this a reasonable way to go with this architecture? thanks.
|
November 23rd, 2007, 06:09 AM
|
Friend of Wrox
|
|
Join Date: Mar 2007
Posts: 488
Thanks: 2
Thanked 11 Times in 10 Posts
|
|
Quote:
quote:Originally posted by forumuser
i can do all this nicely out in the UI code-behind by removing the objectdatasources and formviews [they use reflection anyway!!!] and manually handling the submit/postback:
protected void btnSubmit_Click(object sender, EventArgs e)
{
if (Page.IsValid)
{
using (TransactionScope scope = new TransactionScope())
{
int newID =
Report.InsertReport(Convert.ToDateTime(Date.Text), Time.Text,
Details.Text,
Where.Text, Scene.Text, Action.Text);
ContactDetail.InsertContactDetail(newID, 1, 1, 1, UCContactDetails.name, UCContactDetails.address1,
UCContactDetails.address2, UCContactDetails.town,
UCContactDetails.postcode, UCContactDetails.telephone,
UCContactDetails.mobile, UCContactDetails.email);
scope.Complete();
}
}
}
is this a reasonable way to go with this architecture? thanks.
|
how about moving that code to your report.cs file and in the report.cs class, have an additional method signiture called something like public static bool InsertReport(Reportdetails repDetails, Contactdetails conDetails) and call that from the UI as a single line (after populating the psuedo Reportdetails and Contactdetails objects). that way, you get the reuse from other forms (and/or input sources).
just a thought as you are probably merging the responsibilities of the UI and BLL otherwise.
jimi
http://www.originaltalent.com
|
November 23rd, 2007, 11:30 AM
|
Authorized User
|
|
Join Date: Nov 2007
Posts: 76
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
much better thanks. it hadn't felt quite right putting that out in the code-behind. that is the first part of the form done.
|
November 23rd, 2007, 12:10 PM
|
Friend of Wrox
|
|
Join Date: Mar 2007
Posts: 488
Thanks: 2
Thanked 11 Times in 10 Posts
|
|
Quote:
quote:Originally posted by forumuser
much better thanks. it hadn't felt quite right putting that out in the code-behind. that is the first part of the form done.
|
yep, makes sense. how does it 'feel' i.e. are you starting to get a handle on how it all fits together?? you sound as tho' you've picked up the concepts fairly quickly (i know you've obviously got experience in asp (and c# ??)) and should be at a stage where you've got a 'mindmap' of how subsequent form/functionality will fit together. i did read earlier the comment:
seemed sooooo much more intuitive using datasets! :)
i think that once you start to (and i hate this expression) 'leverage' reuse and inherit various bits of logic, then you really start to see how the race is really won. unfortunately, all that is never obvious in the 1st cut of the code. i think your next 'form' will seem so much easier, even if it's actually technically more demanding - well, hopefully :)
ok, let me know how you progress...
jimi
http://www.originaltalent.com
|
November 23rd, 2007, 12:32 PM
|
Authorized User
|
|
Join Date: Nov 2007
Posts: 76
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
how does it 'feel'? hard to say at the moment. i seem to spend all my time writing overloads and swapping out inline sql for stored proc calls. [mind you, i can deal with that via the templates ultimately]. i think that getting rid of the objectdatasources and formviews has helped immensely, apart from the obvious performance gains [and the sad fact that a formview spits out an html table!!!] - and the fact that it screws up all the code-behind control references!.
i still have unanswered questions. eg that first part of the form also includes a checkboxlist [i had conveniently forgotten about it] fed from a dropdowntable. selected items go into a table related to the main report table. q: where do i do this? out in the ui, where i can use the generated methods, or pass the selected items into the bll [as a concatenated string, as an arraylist, as a hash table?] and overload another method etc etc. these are design decisions that at first glance seem to suggest that the best approach is the messiest, ie pass the items down to the bll etc etc.
anyway, progress is being made, no little thanks to your good self. - those beers are adding up.
EDIT: thinking about it i guess it's obvious that it has to go to the BLL along with the other stuff since it has to partake in that transaction.
|
November 28th, 2007, 01:19 PM
|
Friend of Wrox
|
|
Join Date: Mar 2007
Posts: 488
Thanks: 2
Thanked 11 Times in 10 Posts
|
|
forumuser - your 'edit' thought is indeed correct.
hope it's all 'flowing' for you. haven't been able to do much on this stuff for the past week due to work but intend to set some time aside before the big 'X' arrives...
catch you soon
jimi
http://www.originaltalent.com
|
November 29th, 2007, 06:13 PM
|
Authorized User
|
|
Join Date: Nov 2007
Posts: 76
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
hi jimi. two steps forward, one step back is how it seems at the moment. the beerhouse files don't really approach the complexity of the typical form that i have to deal with and so it's a bit like feeling the way forward in the dark. still, progress is being made although i can't claim to fully understand what's going on in it's entirety yet.
i've decided to use objectdatasources for my 'index' pages - lists of form summaries. that seems to suit, unlike the forms themselves where the data structures and html are far too complex. it's better to deal with these manually in the code-behind.
hope you're having a good runup to xmas.
|
|
|