tags:

views:

305

answers:

1

Hello all, Somebody please help me how to store the value dynamically using arraylist.Every time i want to add patient details. Here is my code layer wise:

PatientDataLayer:

public class PatientData
{
    public string str = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString.ToString();
    public int AddPatient(Patient obj)
    {
        using (var con = new SqlConnection(str))
        {
            using (var com = new SqlCommand("AddPatient", con))
            {
                com.CommandType = CommandType.StoredProcedure;
                com.Parameters.AddWithValue("@Name", obj.Name);
                com.Parameters.AddWithValue("@Address", obj.Address);
                com.Parameters.AddWithValue("@DateOfBirth", obj.DateOfBirth);
                com.Parameters.AddWithValue("@Phone", obj.Phone);
                com.Parameters.AddWithValue("@EmergencyContact", obj.EmergencyContact);
                com.Parameters.AddWithValue("@DateOfRegistration", obj.DateOfRegistration);
                con.Open();
                com.ExecuteNonQuery();
                con.Close();
                return 0;                       
            }
        }
    }

PatientBusinessLayer:

public class PatientBusiness
{
    public void Add(Patient obj)
    {      
        PatientData pd = new PatientData();
        pd.AddPatient(obj);      
    }   
}

Patient.aspx.cs:

 protected void BtnAdd_Click(object sender, EventArgs e)
    {
        if (!Page.IsValid)   //validating the page
            return;
        string name = TxtName.Text;
        string address = TxtAddress.Text;
        DateTime dateofbirth =Convert.ToDateTime(TxtDateOfBirth.Text);
        int phone = Convert.ToInt32(TxtPhone.Text);
        int emergencyno=Convert.ToInt32(TxtContact.Text);
        DateTime registrationdate =Convert.ToDateTime(TxtRegistrationDate.Text);
        PatientBusiness PB = new PatientBusiness();
        Patient obj = new Patient();
        try
        {
            obj.Name = name;
            obj.Address = address;
            obj.DateOfBirth = dateofbirth;
            obj.Phone = phone;
            obj.EmergencyContact = emergencyno;
            obj.DateOfRegistration = registrationdate;
            PB.Add(obj);
            LblMessage.Text = "Patient has been added successfully";
            TxtName.Text = "";
            TxtAddress.Text = "";
            TxtDateOfBirth.Text = "";
            TxtPhone.Text = "";
            TxtContact.Text = "";
            TxtRegistrationDate.Text = "";
        }
        catch (Exception ee)
        {
            LblMessage.Text = ee.Message.ToString();
        }
        finally
        {
            PB = null;
        }   
    }

Thanks, Masum

+1  A: 

I don't understand your question but after reviewing your code, I can only recommand you to consider using an ObjectDataSource combined with a FormView and stop doing "business stuff" in code behind.

Fabian Vilers
I don't see any "business stuff" in the code-behind - only moving data from the controls to the entity and calling the business layers' Add method...
configurator
What I mean is that the presentation layer is not the best place to create entities. The PL should not worry on how to do it but rather give the business layer all the data and let it do the job.
Fabian Vilers