// Main Function
        private void AddnewPatient_saveAndConfirm_button_Click(object sender, EventArgs e)
        {
            // re-validate
            if (!DataValidation())
                return;

            List<Control> ChangedControls = _dirtyTracker.GetListOfDirtyControls();
           
            Patient = DataUpdater.Patient_info.Where(i => i.Patient_ID == EPatient_ID).FirstOrDefault();

            

            #region Basic info 

            if (ChangedControls.Contains(Patient_ID_textBox))
            {
              ID = Int32.Parse(Patient_ID_textBox.Text);
              Patient.Patient_ID = ID;
            }

            if (ChangedControls.Contains(Age_textBox))
            {
                int Age;
                Age = Int32.Parse(Age_textBox.Text); 
                Patient.Age = Age;
            }
 
            if (ChangedControls.Contains(Sex_Combobox))
            {
                Patient.Sex = Sex_Combobox.Text;
            }


            if (ChangedControls.Contains(DateOfBirth_textBox))
            {
                DateTime BD = DateTime.Parse(DateOfBirth_textBox.Text);
                Patient.Birth_date = BD;
            }
           

            if (ChangedControls.Contains(Visit_date_textBox))
            {
                DateTime VD = DateTime.Parse(Visit_date_textBox.Text);
                Patient.Visit_date = VD;
            }
           

            if (ChangedControls.Contains(Patient_name_textBox))
            {
                Patient.Patient_name = Patient_name_textBox.Text;
            }

            if (ChangedControls.Contains(Homenum_textBox))
            {
                Patient.Home_number = Homenum_textBox.Text;
            }

            if (ChangedControls.Contains(Mobile_textBox))
            {
                Patient.Phone_number = Mobile_textBox.Text;
            }

            if (ChangedControls.Contains(Realative_Marriage_comboBox))
            {
                Patient.Relative_marriage = Realative_Marriage_comboBox.Text;
            }

            if (ChangedControls.Contains(Address_textBox))
            {
                Patient.Address = Address_textBox.Text;
            }

            if (ChangedControls.Contains(Chief_Complaint_textBox))
            {
                Patient.Cheif_complaint = Chief_Complaint_textBox.Text;
            }

            if (ChangedControls.Contains(Medical_alert_textBox))
            {
                Patient.Medical_alert = Medical_alert_textBox.Text;
            }

            if (Profile_Picture != null)
            {
                Patient.Patient_image = imageToByteArray(Profile_Picture) ;
            }

            if (AddnewXrayImagesIsPressed)
            {
                // Patinet's X-ray images
                ////////////////////////////////////////
                // Byte[] XrayImage;

                MemoryStream ms;
                int ix = 0;
                var Xcount = (from o in DataUpdater.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.Patient_ID = ID;
                    XrayimageObject.Xray_image = ms.ToArray();
                    XrayimageObject.Image_name = XrayImagesNames[ix];
                    XrayimageObject.Xray_images_ID = Xtemp;
                    DataUpdater.X_ray_images.Add(XrayimageObject);
                    ix++;
                    Xtemp++;
                }
            }

            if (ChangedControls.Contains(DMF_D_textBox))
            {
                Patient.D_DMF = D;
            }

            if (ChangedControls.Contains(DMF_M_textbox))
            {
                Patient.M_DMF = M;
            }

            if (ChangedControls.Contains(DMF_F_textBox))
            {
                Patient.F_DMF = F;
            }

            if (ChangedControls.Contains(DMF_D_textBox) || ChangedControls.Contains(DMF_M_textbox) || ChangedControls.Contains(DMF_F_textBox))
            {
                Patient.DMF = DMF; 
            }

            if (ChangedControls.Contains(_dmf_d_textBox))
            {
                Patient.dd_dmf = d;
            }

            if (ChangedControls.Contains(_dmf_m_textBox))
            {
                Patient.mm_dmf = m;
            }

            if (ChangedControls.Contains(_dmf_f_textBox))
            {
                Patient.ff_dmf = f;
            }

            if (ChangedControls.Contains(_dmf_d_textBox) || ChangedControls.Contains(_dmf_m_textBox) || ChangedControls.Contains(_dmf_f_textBox))
            {
                Patient.C_dmf = _dmf;
            }

            if (ChangedControls.Contains(DEF_D_textBox))
            {
                Patient.D_DEF = _D;
            }

            if (ChangedControls.Contains(DEF_E_textBox))
            {
                Patient.E_DEF = E;
            }

            if (ChangedControls.Contains(DEF_F_textbox))
            {
                Patient.F_DEF = _F;
            }

            if (ChangedControls.Contains(DEF_D_textBox) || ChangedControls.Contains(DEF_E_textBox) || ChangedControls.Contains(DEF_F_textbox))
            {
                Patient.DEF = DEF;
            }

            #endregion
            ////////////////////////////////////////////////////////////////

            #region Diagnosis And Treatment Plans

            if (DiagnosisAndTPsIsChanged && DiagnosisAndTPsIsPressed)
            {
                int index = 0;
                var Query = from P in DataUpdater.Diagnoses.Where(P => P.Patient_ID == ID) select P;
                if (Updated_DiagnosisAndTPs_table.Count == EDiagnosisAndTPs_table.Count)
                {
                    // Update
                    foreach (var item in Query)
                    {
                        List<String> row = Updated_DiagnosisAndTPs_table[index];
                        item.Diagnose = row[0];
                        item.Treatment_Plan = row[1];
                        index++;
                    }
                }

                // increase
                if (Updated_DiagnosisAndTPs_table.Count > EDiagnosisAndTPs_table.Count)
                {
                    //update
                    foreach (var item in Query)
                    {
                        List<String> row = Updated_DiagnosisAndTPs_table[index];
                        item.Diagnose = row[0];
                        item.Treatment_Plan = row[1];
                        index++;
                    }

                    // create
                    var Dcount = (from o in DataUpdater.Diagnoses select o).Count();
                    int Dtemp = Dcount + 1;
                    for (int i = index; i < Updated_DiagnosisAndTPs_table.Count; i++)
                    {
                        List<String> row = Updated_DiagnosisAndTPs_table[i];
                        var DiagnosisObject = new Diagnosis();

                        DiagnosisObject.Patient_ID = ID;
                        DiagnosisObject.Diagnose_ID = Dtemp;
                        DiagnosisObject.Diagnose = row[0];
                        DiagnosisObject.Treatment_Plan = row[1];

                        DataUpdater.Diagnoses.Add(DiagnosisObject);
                        Dtemp++;
                    }
                }

                // decrease
                if (Updated_DiagnosisAndTPs_table.Count < EDiagnosisAndTPs_table.Count)
                {
                    // update
                    foreach (var item in Query)
                    {
                        
                        if (index < Updated_DiagnosisAndTPs_table.Count)
                        {
                            var checkItem = DataUpdater.Diagnoses.Create();
                            List<String> row = Updated_DiagnosisAndTPs_table[index];
                            checkItem.Diagnose = row[0];
                            checkItem.Treatment_Plan = row[2];

                            if (item.Diagnose == checkItem.Diagnose && item.Treatment_Plan == checkItem.Treatment_Plan)               
                            {
                                index++;
                                continue;
                            }
                            else 
                            {
                                item.Diagnose = row[0];
                                item.Treatment_Plan = row[1];
                            }
                        }
                        else
                        {
                            // delete
                            DataUpdater.Diagnoses.Remove(item);
                        }
                        index++;
                    }
                }
            }

            #endregion

            ////////////////////////////////////////////////////////////////
            #region Dates And Procedures
            if (DatesAndProceduresIsChanged && DatesAndProceduresIsPressed)
            {
                int index = 0;
                var Query = from P in DataUpdater.Dates.Where(P => P.Patient_ID == ID) select P;
                if (Updated_DatesAndProc_table.Count == EDatesAndProc_table.Count)
                {
                    foreach (var item in Query)
                    {
                        List<String> row = Updated_DatesAndProc_table[index];
                        item.Date1 = DateTime.Parse(row[0]);
                        item.Doctor_name = row[1];
                        item.Procedures = row[2];
                        item.Procedure_Comment = row[3];
                        if (row[4].Length != 0)
                            item.Medication = row[4];
                        item.Supervisor_signature = row[5];
                        index++;
                    }
                }

                if (Updated_DatesAndProc_table.Count > EDatesAndProc_table.Count)
                {
                    foreach (var item in Query)
                    {
                        List<String> row = Updated_DatesAndProc_table[index];
                        item.Date1 = DateTime.Parse(row[0]);
                        item.Doctor_name = row[1];
                        item.Procedures = row[2];
                        item.Procedure_Comment = row[3];
                        if (row[4].Length != 0)
                            item.Medication = row[4];
                        item.Supervisor_signature = row[5];
                        index++;
                    }


                    var Dcount = (from o in DataUpdater.Dates select o).Count();
                    int Dtemp = Dcount + 1;
                    for (int i = index; i < Updated_DatesAndProc_table.Count; i++)
                    {
                        List<String> row = Updated_DatesAndProc_table[i];
                        var DatesObject = new Date();

                        DatesObject.Patient_ID = ID;
                        DatesObject.Dates_ID = Dtemp;
                        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];

                        DataUpdater.Dates.Add(DatesObject);
                        Dtemp++;
                    }
                }

                if (Updated_DatesAndProc_table.Count < EDatesAndProc_table.Count)
                {
                    // update
                    foreach (var item in Query)
                    {
                        if (index < Updated_DatesAndProc_table.Count)
                        {
                            var checkItem = DataUpdater.Dates.Create();
                            List<String> row = Updated_DatesAndProc_table[index];
                            checkItem.Date1 = DateTime.Parse(row[0]);
                            checkItem.Doctor_name = row[1];
                            checkItem.Procedures = row[2];
                            checkItem.Procedure_Comment = row[3];
                            if (row[4].Length != 0)
                                checkItem.Medication = row[4];
                            checkItem.Supervisor_signature = row[5];

                            if (item.Date1 == checkItem.Date1 && item.Doctor_name == checkItem.Doctor_name &&
                                item.Procedures == checkItem.Procedures && item.Procedure_Comment == checkItem.Procedure_Comment
                                && item.Medication == checkItem.Medication && item.Supervisor_signature == checkItem.Supervisor_signature)
                                
                            {
                                 index++;
                                 continue;
                            }
                            else
                            {
                                item.Date1 = DateTime.Parse(row[0]);
                                item.Doctor_name = row[1];
                                item.Procedures = row[2];
                                item.Procedure_Comment = row[3];
                                if (row[4].Length != 0)
                                    item.Medication = row[4];
                                item.Supervisor_signature = row[5];
                            }
                        }
                        else
                        {
                            // delete
                            DataUpdater.Dates.Remove(item);
                        }
                        index++;
                    }
                }
            }
            #endregion

            try
            {
                DataUpdater.SaveChanges();
            }
            catch (Exception ex)
            {
                Exception see = ex;
                MessageBox.Show("There was a problem while saving in the DBcontext\n" + ex.Message);
                return;
            }

            AddNewPatientSaveAndConfirmIsPressed = true;
            MessageBox.Show("The Patient was edited successfully");

            EditedPatient = new Patient_Profile_Viewer(Int32.Parse(Patient_ID_textBox.Text));
            this.Close();
            EditedPatient.Show();

        }
Esempio n. 2
0
        // 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");
            }
        }
        // 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");
        }