// Main Function private void AddnewPatient_saveAndConfirm_button_Click(object sender, EventArgs e) { int ID = 0, Age; String Name, Home_no = "", Mobile_no, Address, Cheif_comp, Medical_Alr, Comments, Sex, RelativeMarriage; DateTime VisitDate, BirthDate; byte[] PatientPhoto; var newPatient = new Patient_info(); // Re-validate if (!DataValidation()) { return; } try { ID = Int32.Parse(Patient_ID_textBox.Text); Age = Int32.Parse(Age_textBox.Text); Name = Patient_name_textBox.Text; Home_no = Homenum_textBox.Text; Mobile_no = Mobile_textBox.Text; Address = Address_textBox.Text; Cheif_comp = Chief_Complaint_textBox.Text; Medical_Alr = Medical_alert_textBox.Text; VisitDate = Convert.ToDateTime(Visit_date_textBox.Text); BirthDate = Convert.ToDateTime(DateOfBirth_textBox.Text); PatientPhoto = imageToByteArray(Patient_Picture); Comments = Comments_textbox.Text; Sex = Sex_Combobox.Text; RelativeMarriage = Realative_Marriage_comboBox.Text; // Main Panel /////////////////////////////// newPatient.Patient_ID = ID; newPatient.Patient_name = Name; newPatient.Visit_date = VisitDate; newPatient.Age = Age; newPatient.Home_number = Home_no; newPatient.Phone_number = Mobile_no; newPatient.Birth_date = BirthDate; newPatient.Patient_image = PatientPhoto; newPatient.Sex = Sex; newPatient.Relative_marriage = RelativeMarriage; newPatient.Address = Address; newPatient.Cheif_complaint = Cheif_comp; newPatient.Medical_alert = Medical_Alr; newPatient.D_DMF = D; newPatient.M_DMF = M; newPatient.F_DMF = F; newPatient.DMF = DMF; newPatient.dd_dmf = d; newPatient.mm_dmf = m; newPatient.ff_dmf = f; newPatient.C_dmf = _dmf; newPatient.D_DEF = _D; newPatient.E_DEF = E; newPatient.F_DEF = _F; newPatient.DEF = DEF; if (Comments.Length != 0) { newPatient.Comments = Comments; } /////////////////////////////////////////// // Diagnosis and Treatment Plans panel ////////////////////////////////////////// var Dcount = (from o in DataEntiry.Diagnoses select o).Count(); int Dtemp = Dcount + 1; foreach (List <String> row in DiagnosisAndTPs_table) { var DiagnosisObject = new Diagnosis(); DiagnosisObject.Diagnose_ID = Dtemp; DiagnosisObject.Diagnose = row[0]; DiagnosisObject.Treatment_Plan = row[1]; newPatient.Diagnoses.Add(DiagnosisObject); Dtemp++; } ///////////////////////////////////////// // Patinet's X-ray images //////////////////////////////////////// // Byte[] XrayImage; MemoryStream ms; int index = 0; var Xcount = (from o in DataEntiry.X_ray_images select o).Count(); int Xtemp = Xcount + 1; foreach (Bitmap img in Patient_Xray_images) { var XrayimageObject = new X_ray_images(); ms = new MemoryStream(); img.Save(ms, img.RawFormat); XrayimageObject.Xray_image = ms.ToArray(); XrayimageObject.Image_name = XrayImagesNames[index]; XrayimageObject.Xray_images_ID = Xtemp; newPatient.X_ray_images.Add(XrayimageObject); index++; Xtemp++; } ///////////////////////////////////////// // Dates And Procedures Panel //////////////////////////////////////// var DAcount = (from o in DataEntiry.Dates select o).Count(); int DAtemp = DAcount + 1; foreach (List <String> row in DatesAndProc_table) { var DatesObject = new Date(); DatesObject.Dates_ID = DAtemp; DatesObject.Date1 = Convert.ToDateTime(row[0]); DatesObject.Doctor_name = row[1]; DatesObject.Procedures = row[2]; DatesObject.Procedure_Comment = row[3]; if (row[4].Length != 0) { DatesObject.Medication = row[4]; } DatesObject.Supervisor_signature = row[5]; newPatient.Dates.Add(DatesObject); DAtemp++; } } catch (Exception) { MessageBox.Show("Please press Check Data Button before Saving"); return; } DataEntiry.Patient_info.Add(newPatient); try { DataEntiry.SaveChanges(); } catch (Exception ex) { Exception exeption = ex; MessageBox.Show("Something wrong with saving the changes in the DBcontext"); return; } // Check if exist string SqlCommand = "SELECT * FROM Patient_info WHERE Patient_ID = " + ID.ToString() + " AND Home_number = " + Home_no.ToString() + " "; BSS.DataSource = Con.GetData(SqlCommand); Check = (DataTable)BSS.DataSource; if (Check.Rows.Count != 0) { MessageBox.Show("The patient was added successfully"); NewPatientWasAdded = true; Add_new_Patient Reset = new Add_new_Patient(); this.Close(); this.Dispose(); Reset.Show(); } else { MessageBox.Show("Failed to add the patient file"); } }
// Show Add new Patient Form private void AddnewPatientButton_Click(object sender, EventArgs e) { Add_new_Patient addNewPatient = new Add_new_Patient(); addNewPatient.Show(); }
// Main Function private void AddnewPatient_saveAndConfirm_button_Click(object sender, EventArgs e) { int ID = 0, Age; String Name, Home_no = "", Mobile_no, Address, Cheif_comp, Medical_Alr, Comments, Sex, RelativeMarriage; DateTime VisitDate, BirthDate; byte[] PatientPhoto; var newPatient = new Patient_info(); // Re-validate if (!DataValidation()) return; try { ID = Int32.Parse(Patient_ID_textBox.Text); Age = Int32.Parse(Age_textBox.Text); Name = Patient_name_textBox.Text; Home_no = Homenum_textBox.Text; Mobile_no = Mobile_textBox.Text; Address = Address_textBox.Text; Cheif_comp = Chief_Complaint_textBox.Text; Medical_Alr = Medical_alert_textBox.Text; VisitDate = Convert.ToDateTime(Visit_date_textBox.Text); BirthDate = Convert.ToDateTime(DateOfBirth_textBox.Text); PatientPhoto = imageToByteArray(Patient_Picture); Comments = Comments_textbox.Text; Sex = Sex_Combobox.Text; RelativeMarriage = Realative_Marriage_comboBox.Text; // Main Panel /////////////////////////////// newPatient.Patient_ID = ID; newPatient.Patient_name = Name; newPatient.Visit_date = VisitDate; newPatient.Age = Age; newPatient.Home_number = Home_no; newPatient.Phone_number = Mobile_no; newPatient.Birth_date = BirthDate; newPatient.Patient_image = PatientPhoto; newPatient.Sex = Sex; newPatient.Relative_marriage = RelativeMarriage; newPatient.Address = Address; newPatient.Cheif_complaint = Cheif_comp; newPatient.Medical_alert = Medical_Alr; newPatient.D_DMF = D; newPatient.M_DMF = M; newPatient.F_DMF = F; newPatient.DMF = DMF; newPatient.dd_dmf = d; newPatient.mm_dmf = m; newPatient.ff_dmf = f; newPatient.C_dmf = _dmf; newPatient.D_DEF = _D; newPatient.E_DEF = E; newPatient.F_DEF = _F; newPatient.DEF = DEF; if (Comments.Length != 0) newPatient.Comments = Comments; /////////////////////////////////////////// // Diagnosis and Treatment Plans panel ////////////////////////////////////////// var Dcount = (from o in DataEntiry.Diagnoses select o).Count(); int Dtemp = Dcount + 1; foreach (List<String> row in DiagnosisAndTPs_table) { var DiagnosisObject = new Diagnosis(); DiagnosisObject.Diagnose_ID = Dtemp; DiagnosisObject.Diagnose = row[0]; DiagnosisObject.Treatment_Plan = row[1]; newPatient.Diagnoses.Add(DiagnosisObject); Dtemp++; } ///////////////////////////////////////// // Patinet's X-ray images //////////////////////////////////////// // Byte[] XrayImage; MemoryStream ms; int index = 0; var Xcount = (from o in DataEntiry.X_ray_images select o).Count(); int Xtemp = Xcount + 1; foreach (Bitmap img in Patient_Xray_images) { var XrayimageObject = new X_ray_images(); ms = new MemoryStream(); img.Save(ms, img.RawFormat); XrayimageObject.Xray_image = ms.ToArray(); XrayimageObject.Image_name = XrayImagesNames[index]; XrayimageObject.Xray_images_ID = Xtemp; newPatient.X_ray_images.Add(XrayimageObject); index++; Xtemp++; } ///////////////////////////////////////// // Dates And Procedures Panel //////////////////////////////////////// var DAcount = (from o in DataEntiry.Dates select o).Count(); int DAtemp = DAcount + 1; foreach (List<String> row in DatesAndProc_table) { var DatesObject = new Date(); DatesObject.Dates_ID = DAtemp; DatesObject.Date1 = Convert.ToDateTime(row[0]); DatesObject.Doctor_name = row[1]; DatesObject.Procedures = row[2]; DatesObject.Procedure_Comment = row[3]; if (row[4].Length != 0) DatesObject.Medication = row[4]; DatesObject.Supervisor_signature = row[5]; newPatient.Dates.Add(DatesObject); DAtemp++; } } catch (Exception) { MessageBox.Show("Please press Check Data Button before Saving"); return; } DataEntiry.Patient_info.Add(newPatient); try { DataEntiry.SaveChanges(); } catch (Exception ex) { Exception exeption = ex; MessageBox.Show("Something wrong with saving the changes in the DBcontext"); return; } // Check if exist string SqlCommand = "SELECT * FROM Patient_info WHERE Patient_ID = "+ID.ToString()+" AND Home_number = "+ Home_no.ToString()+" "; BSS.DataSource = Con.GetData(SqlCommand); Check = (DataTable)BSS.DataSource; if (Check.Rows.Count != 0 ) { MessageBox.Show("The patient was added successfully"); NewPatientWasAdded = true; Add_new_Patient Reset = new Add_new_Patient(); this.Close(); this.Dispose(); Reset.Show(); } else MessageBox.Show("Failed to add the patient file"); }