Hi...I am new to object oriented and also to n-tier.
I have developed a small program based on 3 tier structure. what i want is some help from professionals that either i worked well or there is a need of improvement.
here is the Common class which contains members.
Ist tier i.e. GUI
Business Process Layer
and last Data Access Layer
Thanks in advance
I have developed a small program based on 3 tier structure. what i want is some help from professionals that either i worked well or there is a need of improvement.
here is the Common class which contains members.
Code:
public class Common
{
public string Id;
public string Name;
public string Phone;
public int Salary;
}
Code:
private void button1_Click(object sender, EventArgs e)
{
Common Obj1 = new Common();
Obj1.Id = textBox1.Text;
Obj1.Name = textBox2.Text;
Obj1.Phone = textBox3.Text;
Obj1.Salary = Convert.ToInt16(textBox4.Text);
BPL Obj2 = new BPL();
Obj2.GetAllFrmPresentation(Obj1);
}
Code:
public class BPL
{
public void GetAllFrmPresentation(Common a)
{
//Suppose Tax rate is 15%
int tax;
tax = ((a.Salary * 15) / 100);
a.Salary = a.Salary - tax;
DAL Obj = new DAL();
Obj.GetAllFrmBPL(a);
}
}
and last Data Access Layer
Code:
public void GetAllFrmBPL(Common b)
{
SqlConnection con = new SqlConnection(ConnectionString);
SqlCommand objSql = new SqlCommand();
objSql.Connection = con;
objSql.CommandType = CommandType.Text;
objSql.CommandText = "INSERT INTO BasicInfo (_Id, _Name, _Phone, _Salary) VALUES (@Id, @Name, @Phone, @Salary);";
objSql.Connection = con;
objSql.Parameters.Add("@Id", SqlDbType.Int).Value = b.Id;
objSql.Parameters.Add("@Name", SqlDbType.NVarChar, 50).Value = b.Name;
objSql.Parameters.Add("@Phone", SqlDbType.NVarChar, 50).Value = b.Phone;
objSql.Parameters.Add("@Salary", SqlDbType.Int).Value = b.Salary;
try
{
con.Open();
objSql.ExecuteNonQuery();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
finally
{
con.Close();
}
}
Thanks in advance
Comment