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