.Net Program Source Code Generator TCDesigner
 

Support: Using the generated code in WebForms 

We recommend adding a “business tier” between your WebForms and the generated data access layer. This is the classic 3-tier design consisting of a User Interface Tier, a Business Tier, and a Data Tier. A Business Tier provides a place to implement data validation and other business rules specific to your solution. In addition to the sample code below, a complete WebForms project can be found in the samples folder where TCDesigner is installed.

This example assumes you have a WebForm for updating a record from the Customers table. On that form is a text box for each field in the table and a Save button. To tie everything together, create a business tier class called Bcustomer. Add a public method to Bcustomer called SaveCustomer. SaveCustomer receives one argument as input of type DBCustomersRow. This is sample code only. You should always implement error handling in your production code.

Click here to download a sample WebForms project.

In Your WebForm:

private void cmdSave_Click(object sender, System.EventArgs e)
{
    // create instance of Customer Row (generated)
    DBCustomersRow objRow = new DBCustomersRow();
    // create instance of Customer business class (generated)
    BCustomers objBiz = new BCustomers();

    // Fill in the Row to be saved
    objRow.CustomerID = Convert.ToString ( txtCustomerID.Text );
    objRow.CompanyName = Convert.ToString ( txtCompanyName.Text );
    objRow.ContactName = Convert.ToString ( txtContactName.Text );
    objRow.ContactTitle = Convert.ToString ( txtContactTitle.Text );
    objRow.Address = Convert.ToString ( txtAddress.Text );
    objRow.City = Convert.ToString ( txtCity.Text );
    objRow.Region = Convert.ToString ( txtRegion.Text );
    objRow.PostalCode = Convert.ToString ( txtPostalCode.Text );
    objRow.Country = Convert.ToString ( txtCountry.Text );
    objRow.Phone = Convert.ToString ( txtPhone.Text );
    objRow.Fax = Convert.ToString ( txtFax.Text );
    //call saverow method in business class

    bool bRet = objBiz.SaveRow ( objRow );
}

In Your Bcustomer business tier class:

public bool SaveCustomer ( DBCustomersRow rowToSave )
{
    // create a connection object
    DBConn objConn = new DBConn();

    // create an instance of the Customers data access class
    DACustomer objCustomer = new DACustomer();

    // call SaveRow method inside
    // Customers data access class (generated)

    bool bRet = objCustomer.Saverow( objConn, rowToSave );

    return bRet;
}

©2004 Program Solutions LLC. All rights reserved. Terms of Use | Privacy Statement
TCDesigner