tags:

views:

78

answers:

3

I did this code in my presentation layer but i don't know how to do it on 3 tier . . Please help, i'm stack with this problem. form1_Load() { cboStatus(); GetlistView(); }

region "FILL combo"

    public void cboStatus()
    {

        try
        {
          SqlConnection conn = new SqlConnection(connStr);
            SqlCommand sqlcom = new SqlCommand("sp_loadStatus",conn);
            sqlcom.CommandType = CommandType.StoredProcedure;
            SqlDataReader dr = null;
            conn.Open();
            dr = sqlcom.ExecuteReader();
            cmbStatus.Items.Clear();
            while (dr.Read())
            {
                 cmbStatus.Items.Add((dr["StatusDescription"]));
            }

            if (conn.State == ConnectionState.Open) conn.Close();
        }
        catch (Exception ex)
        {
            MessageBox.Show("Error Occurred:" + ex);
        }
        finally
        {

        }
    }

    #endregion

    #region "fill listview"
    public void GetlistView()
    {

        int i = 0;

        SqlConnection sqlcon = new SqlConnection(connStr);
       lstBF.Items.Clear();
        SqlCommand sqlcom = new SqlCommand("sp_LoadNew", sqlcon);
        sqlcom.CommandType = CommandType.StoredProcedure;
        SqlDataReader dr;
        lstBF.Items.Clear();
        sqlcon.Open();
        dr = sqlcom.ExecuteReader();

        while (dr.Read())
        {

            lstBF.Items.Add(dr["SerialNumber"].ToString());
            lstBF.Items[i].SubItems.Add(dr["PartNumber"].ToString());
            lstBF.Items[i].SubItems.Add(dr["StatusDescription"].ToString());
            lstBF.Items[i].SubItems.Add(dr["CustomerName"].ToString());
            lstBF.Items[i].SubItems.Add(dr["DateCreated"].ToString());
            lstBF.Items[i].SubItems.Add(dr["CreatedBy"].ToString());
            lstBF.Items[i].SubItems.Add(dr["ModifiedBy"].ToString());


            i = i + 1;
        }

        if (sqlcon.State == ConnectionState.Open) sqlcon.Close();
    }



    #endregion
+1  A: 

To start out, you would put this code in a separate file or project and call that the DataLayer. Instead of binding to your listview, you would return a data reader. Then, you would create a business layer that has some business classes. In this case you could start with "Part" or "Order". That would contain the properties from your data table as properties on the class. Then, create a controller that would output a list of your Parts or Orders and pass them back to the presentation layer.

This way is one example and allows you to maintain separation of your presentation and data.

MCain
I ca now Bind my Combo box using tier....:) Last problem is Listview/Listbox.
Crimsonland
+1  A: 

There are probably a handful of things you can do, but I think the most basic would be to make Business objects (C# Class) that represent Status and whatever you are displaying in your ListView (probably a Product of some sort).

Your Data Tier should have the Data Access code (SqlConnection and such) that builds collections of Statuses and Products.

Your Business Tier will take care of any business logic (which you don't have much here, which is fine).

Your Presentation Tier will Bind the UI Controls to the collections returned from the Data Tier (via the Business Tier).

Really, your Business objects are Business Tier entities.

From there, you can expand to make Data Access classes that correspond to your Business objects and such.

Here's a good tech article to get you started: http://msdn.microsoft.com/en-us/library/ms973279.aspx

Chris Dwyer
A: 

Can i have any example please..

Crimsonland
N-Tier architecture is complex enough that a simple example won't really help you. Take some time to read a few articles online about it, including the one I posted above.
Chris Dwyer
:) Your Right...I dig into other sites but i cant see clear picture how to do it. what is common thing is insert/delete/update using n tier that i successfully created. What really make it hard for me is my problem on my post. :)
Crimsonland