private void btnAddRecord_Click(object sender, EventArgs e) { bool DOB_valid; bool exp_valid; bool pass=false; //check whether Insurance numer exits dictionary = new Dictionary<string, string>(); dictionary.Add("@insuranceNumber", txtInsuranceNumber.Text); dc = new DatabaseConnector(); dtInsurance = dc.getData("CheckInsuranceExists", dictionary); int ins_exist = int.Parse(dtInsurance.Rows[0][0].ToString()); //create new patient Patient patient = new Patient(); patient.firstName = txtFirstName.Text; patient.lastName = txtLastName.Text; patient.dob = txtDOB.Text; patient.gender = cmbxGender.GetItemText(cmbxGender.SelectedItem); //create new insurance Insurance insurance = new Insurance(); insurance.timestamp = (DateTime.Now).ToString(); insurance.insNumber = txtInsuranceNumber.Text; insurance.versionCode = txtVersionCode.Text; insurance.expDate = txtInsuranceExpDate.Text; //create new allergy Allergy allergy = new Allergy(); allergy.name = txtAllergyName.Text; allergy.category = txtAllergyCatergory.Text; //create new allergy-patient PatientAllergy ptAllgergy = new PatientAllergy(); //ins number : number only //ins vc : character only //no blank: name, dob Phone phone = new Phone(); phone.type = cmbxPhoneType.GetItemText(cmbxPhoneType.SelectedItem); phone.phoneNumber = txtPhoneNumber.Text; Email email = new Email(); email.type = cmbxEmailType.GetItemText(cmbxEmailType.SelectedItem); email.email = txtEmail.Text; Address address = new Address(); address.type = cmbxAddressType.GetItemText(cmbxAddressType.SelectedItem); address.address = txtAddress.Text; address.city = txtCity.Text; address.province = txtProvince.Text; address.postalCode = txtPostalCode.Text; DOB_valid = DOB_validation(); exp_valid = exp_validation(); if (DOB_valid == true && exp_valid == true && ins_exist == 0 && txtInsuranceNumber.TextLength == 10) { pass = true; } if (pass == true ) { insertPatient(patient); patient.patientID = getPtIdfromPatienTbl(); insurance.patientID = patient.patientID; phone.patientID = patient.patientID; email.patientID = patient.patientID; address.patientID = patient.patientID; insertInsurance(insurance); if (getAllergyIdfromAllergyTbl() != 0) { ptAllgergy.patientId = patient.patientID; ptAllgergy.allergyId = getAllergyIdfromAllergyTbl(); insertPatientAllergy(ptAllgergy); } else { insertAllergy(allergy); ptAllgergy.patientId = patient.patientID; ptAllgergy.allergyId = getAllergyIdfromAllergyTbl2(); insertPatientAllergy(ptAllgergy); } insertPhone(phone); insertAdress(address); insertEmail(email); clearText(); MessageBox.Show("Patient was registed"); } else if (txtInsuranceNumber.TextLength != 10) //number incorrect of left blank { MessageBox.Show("Please insert correct insurance number"); } else if (ins_exist != 0) { MessageBox.Show("Insurance Number already exists"); } else if (DOB_valid == false) { MessageBox.Show("D.O.B not valid"); } else if (exp_valid == false) { MessageBox.Show("Insurance Expiry Date not valid"); } }
private static void insertPatient(Patient patient) { myConnection.Open(); SqlCommand cmd = new SqlCommand("insert into Patient(registratonDate, lastName, giveMiddleName, dateOfBirth, gender) values(@reg_date,@pt_lName, @pt_fName, @dob, @gender);"); cmd.Connection = myConnection; cmd.Parameters.AddWithValue("@reg_date", (DateTime.Now).ToString()); cmd.Parameters.AddWithValue("@pt_lName", patient.lastName); cmd.Parameters.AddWithValue("@pt_fName", patient.firstName); cmd.Parameters.AddWithValue("@dob", patient.dob); cmd.Parameters.AddWithValue("@gender", patient.gender); cmd.CommandType = CommandType.Text; cmd.ExecuteNonQuery(); myConnection.Close(); }