|
I am using Visual Studio 2010, Sql server Express Edition & C#.
I have develop a simple Master Detail application (mostly with the help of experts help from this forum) An Order system, and now I want to go one step further from simple application to N-Tier version.
Did some search on net and came up with Tutorial which guides me enough to create Order class which contains methods: -DataTable GetOrders(int OrdId) Retrieve order based on ID provided -int SaveData(string CustID, DateTime ShpDate, DateTime OrdDate) To save the order, This method has all Insert, Update, Delete command in it, using SqlAdapter.
Following the same pattern I've also created OrderDetails class for setting up line items for each order. OrderDetails also contains methods GetOrder & SaveData...
Now the main problem, what should I do to save the whole Order with OrderDetails? I know this is something I should wrap up in Transaction and create Relation after adding Data to Dataset...But not sure how to do it? any link/tutorial/sample/guidance will be highly appreciated.
I've not posted any code due to make this post clear...If required I will post the code immediately.
Thanks
Ahmed
|
|
|
|
|
"N-Tier" means usually "3-tier", which usually means having a GUI, a DAL, and a BO-layer. Take a look at some codegenerators, they usually come with templates to generate a lot of the scaffolding.
I suggest adding layers as you need them; the database is a DAL - it has abstracted away the data-saving and validation in abstraction that one can query using SQL. There are also some nice ORM-packages out there that automagically load datatables into BO's.
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
Thanks for your reply,
I've created DAL class for data access ofcourse, purpose of which is to provide Database connection and execute Sql commands or stored proc.
As mentioned in my question, I've created Order class which will access DAL class and Get and Save Order..
The problem I am facing is from OrderDetails class...
My approach is: On the Winform (which is I think Presentation layer) when user clicks save button It should do the following:
1-Create Order class instance (for eg. Order od = new Order()) and then call Order class SaveData method by providing parameters: Like od.SaveData(OrdId,CustId OrdDate, ShpDate)
Which then ultimately save the order Master data...Order master is bind to DataTable.
Now the problem: How should I save OrderDetails...which is in DataGridView name dgGrd, dgGrd is also bind to DataTable.
OrderDetails also have SaveData method which take parameters (ProductID, Quantity, UnitPrice)...How should I call SaveData method within Order class? How should I pass whole DataGridView DataTable to SaveData method of OrderDetails class?
I will be very much appreciate if you could help me to line up my coding, perhaps if you could provide a sample? showing N-Tier Master Detail...I am still at beginner learning stage...And still doing lots of net searching for answer..
Thanks in advance
Ahmed
|
|
|
|
|
ahmed_one wrote: I've created DAL class for data access ofcourse, purpose of which is to provide Database connection and execute Sql commands or stored proc. That means that the other two layers aren't allowed to touch the database.
ahmed_one wrote: Now the problem: How should I save OrderDetails...which is in DataGridView name dgGrd, dgGrd is also bind to DataTable. That's a problem indeed; one would use the Order and OrderDetails classes, not a DataTable. If the GUI has a datatable, then you have a data-access class in your UI (you'd have an element in the presentation layer that should not be known outside the DAL)
ahmed_one wrote: How should I call SaveData method within Order class? When the order is saved, foreach the details and save them under the correct order-Id.
ahmed_one wrote: I will be very much appreciate if you could help me to line up my coding I can help with specific questions; if you'd post a summary on how the order(detail) class looks and is saved and we'll look at it.
ahmed_one wrote: perhaps if you could provide a sample? The N-Tier architecture is a bit too elaborate to catch in a small sample.
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
Thank you very much for your reply...
I've modified my Order and OrderDetails class..Actually overall Project..
Now My form Master Fields bind to DataTable dt and Details DataGridView was bind to dtDet...
Then create relation for both tables
Then both tables added to Dataset...2 bindingSource bindMaster and bindDetail created...Set bindMaster datasource to Dt and bindDetail datasource to relation name. Pass the dataset to Order's SaveData method..
Both class's SaveData method are also modified to accept Dataset and DataTable....Also both classes now set up for Sql Insert/Update/Delete commands via SqlAdapter.
Now it works for Saving Order with order Details...Now I need to move one step further to use classes for search the orders by OrderID or OrderDate options...I guess this is not so difficult task as saving the order...
Thanks again for your guidance...I hope if I will stuck in future I will get help from here
Regards
Ahmed
|
|
|
|
|
ahmed_one wrote: Now it works for Saving Order with order Details Nice
ahmed_one wrote: Now I need to move one step further to use classes for search the orders by OrderID or OrderDate options The DataTable has a handy filter-method.
ahmed_one wrote: I hope if I will stuck in future I will get help from here That's the idea; and soon you'll be helping others to get unstuck
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
I've add SearchOrder method to Order class which take Id as parameter and retrieve records from Database, same method added to OrderDetails class. Difference is only return type, Order class method return Dataset because in Order class I've also retrieve OrderDetails (which return as DataTable) and add to Dataset of Order class SearchOrder method. Then I bind the WinForm with this DataSet...
I hope one day I will be competent enough to help others.
Thanks for your help and support.
regards
Ahmed
|
|
|
|
|
You're welcome 
|
|
|
|
|
|
You've come to the wrong forum. This is not the place to post your "jobs".
|
|
|
|
|
Dave Kreskowiak wrote:
You've come to the wrong forum website. This is not the place to post your "jobs". |
Never underestimate the power of stupid things in large numbers
--- Serious Sam
|
|
|
|
|
My bad! I'm picking my brain up off the floor now. I'm so clumsy with it sometimes.
|
|
|
|
|
I have that problem most days...
Never underestimate the power of stupid things in large numbers
--- Serious Sam
|
|
|
|
|
where can i get the .net framework Source code.i want it!thks.
|
|
|
|
|
Have you asked Microsoft nicely?
=========================================================
I'm an optoholic - my glass is always half full of vodka.
=========================================================
|
|
|
|
|
.NET is not open source, it is proprietary to Microsoft, who are unlikely to be willing to part with it.
However, you should be able to find the source to MONO - which is the Open Source version for Linux boxes. Google can help you. Be prepared for a significant sized download...
Never underestimate the power of stupid things in large numbers
--- Serious Sam
|
|
|
|
|
|
Hades hath skating rinks!
I am soooo tempted to download that - any idea how big it is? Chrome just says it's an ASPX file and doesn't give me a total size. And with a 3.5mb/s connection...
Never underestimate the power of stupid things in large numbers
--- Serious Sam
|
|
|
|
|
Took me a good hour on my 6mb connection, I downloaded it but I cannot figure out what actual type of file it is, tried zip and rar, no joy yet.
|
|
|
|
|
Interesting because I got the file "DotNet.msi", not an ASPX file.
|
|
|
|
|
What browser are you using?
|
|
|
|
|
|
Ah! IE does indeed get the name right - but no idea of size, or estimate of completion time.
Any idea how big it was (I'm trying the Net_4.msi since that's the version I use)?
Never underestimate the power of stupid things in large numbers
--- Serious Sam
|
|
|
|
|
Only 167MB - not as bad as I was expecting...
Never underestimate the power of stupid things in large numbers
--- Serious Sam
|
|
|
|
|
Well, source code does compress rather nicely being straight text and all.
|
|
|
|