Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. N-Tier C# Master Detail

N-Tier C# Master Detail

Scheduled Pinned Locked Moved C#
csharphelptutorialannouncementdatabase
8 Posts 2 Posters 1 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    ahmed_one
    wrote on last edited by
    #1

    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

    L 1 Reply Last reply
    0
    • A ahmed_one

      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

      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #2

      "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 :suss: If you can't read my code, try converting it here[^]

      A 1 Reply Last reply
      0
      • L Lost User

        "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 :suss: If you can't read my code, try converting it here[^]

        A Offline
        A Offline
        ahmed_one
        wrote on last edited by
        #3

        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

        L 1 Reply Last reply
        0
        • A ahmed_one

          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

          L Offline
          L Offline
          Lost User
          wrote on last edited by
          #4

          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 :suss: If you can't read my code, try converting it here[^]

          A 1 Reply Last reply
          0
          • L Lost User

            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 :suss: If you can't read my code, try converting it here[^]

            A Offline
            A Offline
            ahmed_one
            wrote on last edited by
            #5

            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

            L 1 Reply Last reply
            0
            • A ahmed_one

              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

              L Offline
              L Offline
              Lost User
              wrote on last edited by
              #6

              ahmed_one wrote:

              Now it works for Saving Order with order Details

              Nice :cool:

              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 :-D

              Bastard Programmer from Hell :suss: If you can't read my code, try converting it here[^]

              A 1 Reply Last reply
              0
              • L Lost User

                ahmed_one wrote:

                Now it works for Saving Order with order Details

                Nice :cool:

                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 :-D

                Bastard Programmer from Hell :suss: If you can't read my code, try converting it here[^]

                A Offline
                A Offline
                ahmed_one
                wrote on last edited by
                #7

                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

                L 1 Reply Last reply
                0
                • A ahmed_one

                  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

                  L Offline
                  L Offline
                  Lost User
                  wrote on last edited by
                  #8

                  You're welcome :)

                  1 Reply Last reply
                  0
                  Reply
                  • Reply as topic
                  Log in to reply
                  • Oldest to Newest
                  • Newest to Oldest
                  • Most Votes


                  • Login

                  • Don't have an account? Register

                  • Login or register to search.
                  • First post
                    Last post
                  0
                  • Categories
                  • Recent
                  • Tags
                  • Popular
                  • World
                  • Users
                  • Groups