Example #1
0
        private void btnSave_Click(object sender, EventArgs e)
        {
            if (GlobalVariables.Is_Edit == false)
            {
                int flag = 0;
                if (String.IsNullOrEmpty(txtPatientCode.Text))
                {
                    DialogResult error = new DialogResult();
                    error = MessageBox.Show(resourceManager.GetString("msgPatient", GlobalVariables.uiLanguage), resourceManager.GetString("msgWarning", GlobalVariables.uiLanguage), MessageBoxButtons.OK, MessageBoxIcon.Warning);
                }
                else if (DateTime.Compare(clndrBirthday.Value, DateTime.Now) > 0)
                {
                    DialogResult error = new DialogResult();
                    error = MessageBox.Show(resourceManager.GetString("msgDate", GlobalVariables.uiLanguage), resourceManager.GetString("msgWarning", GlobalVariables.uiLanguage), MessageBoxButtons.OK, MessageBoxIcon.Warning);
                }
                else
                {
                    using (VivosEntities db = new VivosEntities())
                    {
                        List <Patient> patientList = (from x in db.Patients select x).ToList();
                        Patient        new_patient = new Patient();
                        for (int i = 0; i < patientList.Count; i++)
                        {
                            if (patientList[i].Code == txtPatientCode.Text)
                            {
                                flag = 1;
                                break;
                            }
                        }
                        if (flag == 0)
                        {
                            new_patient.Code       = txtPatientCode.Text.ToString();
                            new_patient.Id         = Guid.NewGuid();
                            new_patient.DoctorId   = GlobalVariables.LoginID;
                            new_patient.IsApproved = true;
                            new_patient.EntryDate  = DateTime.Now;

                            string[] doğumTarihi  = (clndrBirthday.Value.ToString()).Split(' ');
                            string[] sistemTarihi = (DateTime.Now.ToString()).Split(' ');
                            if (doğumTarihi[0] == sistemTarihi[0])
                            {
                                new_patient.DateOfBirth = null;
                            }
                            else
                            {
                                new_patient.DateOfBirth = clndrBirthday.Value;
                            }
                            new_patient.Notes = txtDescription.Text.ToString();
                            db.Patients.Add(new_patient);
                            db.SaveChanges();
                            DialogResult information = new DialogResult();
                            information = MessageBox.Show(resourceManager.GetString("msgPatientAdded", GlobalVariables.uiLanguage), resourceManager.GetString("msgInformation", GlobalVariables.uiLanguage), MessageBoxButtons.OK, MessageBoxIcon.Information);
                        }
                        else if (flag == 1)
                        {
                            MessageBox.Show(resourceManager.GetString("msgUserExists", GlobalVariables.uiLanguage));
                        }
                    }
                }
            }
            else
            {
                if (String.IsNullOrEmpty(txtPatientCode.Text))
                {
                    DialogResult error = new DialogResult();
                    error = MessageBox.Show(resourceManager.GetString("msgPatient", GlobalVariables.uiLanguage), resourceManager.GetString("msgWarning", GlobalVariables.uiLanguage), MessageBoxButtons.OK, MessageBoxIcon.Warning);
                }
                else if (DateTime.Compare(clndrBirthday.Value, DateTime.Now) > 0)
                {
                    DialogResult error = new DialogResult();
                    error = MessageBox.Show(resourceManager.GetString("msgDate", GlobalVariables.uiLanguage), resourceManager.GetString("msgWarning", GlobalVariables.uiLanguage), MessageBoxButtons.OK, MessageBoxIcon.Warning);
                }
                else
                {
                    int flag1 = 0;
                    using (VivosEntities db = new VivosEntities())
                    {
                        Patient patient = (from x in db.Patients where x.Id == GlobalVariables.Edit_ID select x).SingleOrDefault();
                        if (patient != null)
                        {
                            if (patient.Code == txtPatientCode.Text)
                            {
                                string[] doğumTarihi  = (clndrBirthday.Value.ToString()).Split(' ');
                                string[] sistemTarihi = (DateTime.Now.ToString()).Split(' ');
                                if (doğumTarihi[0] == sistemTarihi[0])
                                {
                                    patient.DateOfBirth = null;
                                }
                                else
                                {
                                    patient.DateOfBirth = clndrBirthday.Value;
                                }
                                patient.Notes = txtDescription.Text.ToString();
                                db.SaveChanges();
                                DialogResult information = new DialogResult();
                                information = MessageBox.Show(resourceManager.GetString("msgPatientEdited", GlobalVariables.uiLanguage), resourceManager.GetString("msgInformation", GlobalVariables.uiLanguage), MessageBoxButtons.OK, MessageBoxIcon.Information);
                            }
                            else
                            {
                                List <Patient> patientList = (from x in db.Patients select x).ToList();
                                for (int i = 0; i < patientList.Count; i++)
                                {
                                    if (patientList[i].Code == txtPatientCode.Text)
                                    {
                                        flag1 = 1;
                                        break;
                                    }
                                }
                                if (flag1 == 0)
                                {
                                    patient.Code = txtPatientCode.Text;
                                    string[] doğumTarihi  = (clndrBirthday.Value.ToString()).Split(' ');
                                    string[] sistemTarihi = (DateTime.Now.ToString()).Split(' ');
                                    if (doğumTarihi[0] == sistemTarihi[0])
                                    {
                                        patient.DateOfBirth = null;
                                    }
                                    else
                                    {
                                        patient.DateOfBirth = clndrBirthday.Value;
                                    }
                                    patient.Notes = txtDescription.Text.ToString();
                                    db.SaveChanges();
                                    DialogResult information = new DialogResult();
                                    information = MessageBox.Show(resourceManager.GetString("msgPatientEdited", GlobalVariables.uiLanguage), resourceManager.GetString("msgInformation", GlobalVariables.uiLanguage), MessageBoxButtons.OK, MessageBoxIcon.Information);
                                }
                                else if (flag1 == 1)
                                {
                                    MessageBox.Show(resourceManager.GetString("msgUserExists", GlobalVariables.uiLanguage));
                                }
                            }
                        }
                    }
                }
            }
        }
Example #2
0
        private void patients_datagrid_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {
            if (e.ColumnIndex == 4)
            {
                try
                {
                    Guid id = Guid.Parse(patients_datagrid.Rows[e.RowIndex].Cells[0].Value.ToString());
                    find_notes(id);
                }
                catch (Exception)
                {
                }
            }
            else if (e.ColumnIndex == 5)
            {
                try
                {
                    GlobalVariables.Session_ID = Guid.Parse(patients_datagrid.Rows[e.RowIndex].Cells[0].Value.ToString());
                    GlobalVariables.Is_Session = true;
                    using (VivosEntities db = new VivosEntities())
                    {
                        List <Patient> patientlist1 = (from x in db.Patients where x.Id == GlobalVariables.Session_ID select x).ToList();
                        GlobalVariables.Session_ID_name = patientlist1[0].Code;
                    }
                    GlobalVariables.Sessions_Search_Flag = 0;
                    Sessions_Page sessions = new Sessions_Page();
                    this.Hide();
                    sessions.Show();
                }
                catch (Exception)
                {
                }
            }
            else if (e.ColumnIndex == 6)
            {
                try
                {
                    GlobalVariables.Edit_ID = Guid.Parse(patients_datagrid.Rows[e.RowIndex].Cells[0].Value.ToString());
                    GlobalVariables.Is_Edit = true;
                    New_Patient_Page yeni_danısan = new New_Patient_Page();
                    this.Hide();
                    yeni_danısan.Show();
                }
                catch (Exception)
                {
                }
            }
            else if (e.ColumnIndex == 7)
            {
                try
                {
                    DialogResult delete = new DialogResult();
                    delete = MessageBox.Show(resourceManager.GetString("msgIsPatientDeleted", GlobalVariables.uiLanguage), resourceManager.GetString("msgWarning", GlobalVariables.uiLanguage), MessageBoxButtons.YesNo, MessageBoxIcon.Information);
                    if (delete == DialogResult.Yes)
                    {
                        GlobalVariables.Edit_ID = Guid.Parse(patients_datagrid.Rows[e.RowIndex].Cells[0].Value.ToString());
                        using (VivosEntities db = new VivosEntities())
                        {
                            List <Session> sessionList = (from x in db.Sessions where x.PatientId == GlobalVariables.Edit_ID select x).ToList();
                            Session[]      sessions    = new Session[sessionList.Count];

                            for (int i = 0; i < sessions.Length; i++)
                            {
                                sessions[i] = sessionList[i];
                                db.Sessions.Remove(sessions[i]);
                            }
                            Patient patient = db.Patients.First(x => x.Id == GlobalVariables.Edit_ID);

                            db.Patients.Remove(patient);
                            db.SaveChanges();
                            GlobalVariables.Patients_Search_Flag = 0;
                            string key = null;
                            fill_datagrid(key);
                            DialogResult information = new DialogResult();
                            information = MessageBox.Show(resourceManager.GetString("msgPatientDeleted", GlobalVariables.uiLanguage), resourceManager.GetString("msgInformation", GlobalVariables.uiLanguage), MessageBoxButtons.OK, MessageBoxIcon.Information);
                        }
                    }
                }
                catch (Exception)
                {
                }
            }
        }