private void btnBookAppointment_Click(object sender, EventArgs e)
 {
     if (valid())
     {
         Patient objPatient = new Patient();
         objPatient.Firstname              = txtFirstname.Text;
         objPatient.Lastname               = txtLastname.Text;
         objPatient.Addresslineone         = txtAppartmentNo.Text;
         objPatient.Addresslinetwo         = txtStreet.Text;
         objPatient.City                   = txtCity.Text;
         objProvience.ProvienceDescription = cbProvience.SelectedItem.ToString();
         objPatient.ProvienceId            = objProvience.GetProvienceId(objProvience);
         objPatient.Postalcode             = txtPostalCode.Text;
         objPatient.Dob         = dtDateofbirth.Value;
         objPatient.Email       = txtEmail.Text;
         objPatient.Contactno   = txtContactNo.Text;
         objPatient.Datecreated = System.DateTime.Now;
         objPatient.Createdby   = this.sessionKey;
         int patientid = objPatient.InsertPatient(objPatient);
         if (patientid > 0)
         {
             objDoctor.Firstname = cbDoctor.SelectedItem.ToString().Split(' ')[0];
             objDoctor.Lastname  = cbDoctor.SelectedItem.ToString().Split(' ')[1];
             int doctorid = objDoctor.GetDoctorId(objDoctor);
             if (doctorid > 0)
             {
                 Appointment objAppointment = new Appointment();
                 objAppointment.Patientid       = patientid;
                 objAppointment.Doctorid        = doctorid;
                 objAppointment.Appointmentdate = dtAppointmentDate.Value;
                 objAppointment.Appointmenttime = cbAppointmentTime.SelectedItem.ToString();
                 objAppointment.Datecreated     = System.DateTime.Now;
                 objAppointment.Createdby       = this.sessionKey;
                 int appointmentid = objAppointment.InsertAppointment(objAppointment);
                 if (appointmentid > 0)
                 {
                     for (int i = 0; i < lbProcedureList.SelectedItems.Count; i++)
                     {
                         PatientHistory objPatientHistory = new PatientHistory();
                         objPatientHistory.Patientid       = patientid;
                         objPatientHistory.Appointmentid   = appointmentid;
                         objPatientHistory.Doctorid        = doctorid;
                         objProcedure.Proceduredescription = lbProcedureList.SelectedItems[i].ToString();
                         objPatientHistory.Procedureid     = objProcedure.GetProcedureId(objProcedure);
                         objPatientHistory.Datecreated     = System.DateTime.Now;
                         objPatientHistory.Createdby       = this.sessionKey;
                         int patienthistoryid = objPatientHistory.InsertPatientHistory(objPatientHistory);
                     }
                 }
             }
         }
         DisplayMessage("Appointment Booked.", "Successful..!!", MessageBoxButtons.OKCancel, MessageBoxIcon.Warning, MessageBoxDefaultButton.Button2);
         Clear();
     }
 }
 private void btnBookAppointment_Click(object sender, EventArgs e)
 {
     if (valid())
     {
         objPatient.Firstname = cbPatient.SelectedItem.ToString().Split(' ')[0];
         objPatient.Lastname  = cbPatient.SelectedItem.ToString().Split(' ')[1];
         int patientid = objPatient.GetPatientId(objPatient);
         if (patientid > 0)
         {
             objDoctor.Firstname = cbDoctor.SelectedItem.ToString().Split(' ')[0];
             objDoctor.Lastname  = cbDoctor.SelectedItem.ToString().Split(' ')[1];
             int doctorid = objDoctor.GetDoctorId(objDoctor);
             if (doctorid > 0)
             {
                 Appointment objAppointment = new Appointment();
                 objAppointment.Patientid       = patientid;
                 objAppointment.Doctorid        = doctorid;
                 objAppointment.Appointmentdate = dtAppointmentDate.Value;
                 objAppointment.Appointmenttime = cbAppointmentTime.SelectedItem.ToString();
                 objAppointment.Datecreated     = System.DateTime.Now;
                 objAppointment.Createdby       = this.sessionKey;
                 int appointmentid = objAppointment.InsertAppointment(objAppointment);
                 if (appointmentid > 0)
                 {
                     for (int i = 0; i < lbProcedureList.SelectedItems.Count; i++)
                     {
                         PatientHistory objPatientHistory = new PatientHistory();
                         objPatientHistory.Patientid       = patientid;
                         objPatientHistory.Appointmentid   = appointmentid;
                         objPatientHistory.Doctorid        = doctorid;
                         objProcedure.Proceduredescription = lbProcedureList.SelectedItems[i].ToString();
                         objPatientHistory.Procedureid     = objProcedure.GetProcedureId(objProcedure);
                         objPatientHistory.Datecreated     = System.DateTime.Now;
                         objPatientHistory.Createdby       = this.sessionKey;
                         int patienthistoryid = objPatientHistory.InsertPatientHistory(objPatientHistory);
                     }
                 }
             }
         }
         DisplayMessage("Appointment Booked.", "Successful..!!", MessageBoxButtons.OKCancel, MessageBoxIcon.Warning, MessageBoxDefaultButton.Button2);
         ClearPatientDetails();
         Clear();
     }
 }