private void buttonSaveData_Click(object sender, EventArgs e) { DateTime birthDate = new DateTime(); if (!(textBoxBirthYear.Text.Trim().Equals("") && textBoxBirthMonth.Text.Trim().Equals("") && textBoxBirthDay.Text.Trim().Equals(""))) { try { birthDate = new DateTime(Int32.Parse(textBoxBirthYear.Text.Trim()), Int32.Parse(textBoxBirthMonth.Text.Trim()), Int32.Parse(textBoxBirthDay.Text.Trim())); } catch (Exception exxx) { MessageBox.Show("Sorry - but the date is not correct" + exxx.ToString()); return; } } DateTime? waitListDate = null; if (!string.IsNullOrWhiteSpace(labelWaitListDateValue.Text)) { waitListDate = DateTime.Parse(labelWaitListDateValue.Text, DateTimeFormatInfo.InvariantInfo); } if (listBoxSex.SelectedItems.Count == 0) { MessageBox.Show("No gender is selected"); return; } if (listBoxAmbulant.SelectedItems.Count == 0) { MessageBox.Show("Ambulant is not selected"); return; } if (listBoxResidentOfAsmara.SelectedItems.Count == 0) { MessageBox.Show("Resident of Asmara is not selected"); return; } if (listBoxFinished.SelectedItems.Count == 0) { MessageBox.Show("Finished is not selected"); return; } if (listBoxLinz.SelectedItems.Count == 0) { MessageBox.Show("Linz is not selected"); return; } Sex sex = (Sex)Enum.Parse(new Sex().GetType(), this.listBoxSex.Text); Ambulant ambulant = (Ambulant)Enum.Parse(new Ambulant().GetType(), this.listBoxAmbulant.Text); ResidentOfAsmara residentOfAsmara = (ResidentOfAsmara)Enum.Parse(new ResidentOfAsmara().GetType(), this.listBoxResidentOfAsmara.Text); Finished finished = (Finished)Enum.Parse(new Finished().GetType(), this.listBoxFinished.Text); Linz linz = (Linz)Enum.Parse(new Linz().GetType(), this.listBoxLinz.Text); long pId; if (currentPatient == null) pId = 0; else pId = currentPatient.Id; int weight; try { weight = Int32.Parse(textBoxWeight.Text.Trim()); } catch (Exception) { weight = 0; if (textBoxWeight.Text.Trim().Equals("")){ weight = 0; }else{ MessageBox.Show("In the weight field has to be a integer number"); return; } } if (this.patComp.DoesPhoneExist(this.textBoxPhone.Text.Trim())) { IList<PatientData> patients = this.patComp.FindPatientByPhone(this.textBoxPhone.Text.Trim()); if (!(patients.Count == 1 && currentPatient != null && patients[0].Id == currentPatient.Id)) { StringBuilder sb = new StringBuilder(); foreach (PatientData pd in patients) { sb.Append(Environment.NewLine + "-----------------------------------" + Environment.NewLine).Append(pd.ToLineBreakedString()).Append(Environment.NewLine); } DialogResult res = MessageBox.Show("This phone Number is already stored." + Environment.NewLine + "Do you want to add the Patient anyway?" + "Patient(s):" + sb.ToString(), "Warning!", MessageBoxButtons.YesNo); if (res == DialogResult.No) { return; } } } PatientData patient = new PatientData(pId, textBoxFirstName.Text.Trim(), textBoxSurname.Text.Trim(), birthDate, sex, textBoxPhone.Text.Trim(), weight, textBoxAddress.Text.Trim(), residentOfAsmara, ambulant, finished, linz, waitListDate); IList<DiagnoseGroupData> diagnoseGroups = new List<DiagnoseGroupData>(); foreach (DiagnoseGroupData dg in listBoxAssignedDiagnoseGroups.Items) { diagnoseGroups.Add(dg); } NewPatientStoreEventArgs e2 = new NewPatientStoreEventArgs(patient, diagnoseGroups); Store(this, e2); }
/////////// Helper Methods END private void patientStore(object sender, NewPatientStoreEventArgs e) { if (e.Patient.Id == 0) { //new Patient this.currentPatient = patComp.InsertPatient(e.Patient); Clear(null); this.newVisit.Location = getTopMaskLocation(); this.newVisit.CurrentPatient = this.currentPatient; this.newVisit.Init(null); this.Controls.Add(this.newVisit); this.newVisit.TextBoxCauseOfVisit.Focus(); } else { //update Patient currentPatient = e.Patient; patComp.UpdatePatient(e.Patient); this.newPatientControl.Enabled = false; } IList<DiagnoseGroupData> oldAssignedDiagnoseGroups = patComp.FindDiagnoseGroupIdByPatientId(currentPatient.Id); foreach(DiagnoseGroupData dgd in oldAssignedDiagnoseGroups) { if (!e.DiagnoseGroups.Contains(dgd)) { patComp.RemovePatientFromDiagnoseGroup(currentPatient.Id, dgd.DiagnoseGroupDataID); } } foreach (DiagnoseGroupData dgd in e.DiagnoseGroups) { if (!oldAssignedDiagnoseGroups.Contains(dgd)) { patComp.AssignPatientToDiagnoseGroup(currentPatient.Id, dgd.DiagnoseGroupDataID); } } }