private void добавитьToolStripMenuItem_Click(object sender, EventArgs e) { Form regDocForm = new RegDocForm(); regDocForm.Owner = this; regDocForm.ShowDialog(); RefreshMenu(); }
public static bool DoctorRegistrationCall(object obj, out string login, out string password) { RegDocForm regForm = (RegDocForm)obj; login = ""; password = ""; using (ModelMedDBContainer db = new ModelMedDBContainer()) { Doctor newDoctor = new Doctor(); try { if (regForm.comboBoxGender.Text == "" || regForm.textSurname.Text == "" || regForm.textName.Text == "" || regForm.textBoxPassword2.Text == "" || regForm.textNation.Text == "" || regForm.textLiveAdress.Text == "" || regForm.textRegAdress.Text == "" || regForm.comboBoxDocType.Text == "" || regForm.textDocumentN.Text == "" || regForm.textBoxPassword1.Text == "" || regForm.comboBoxJob.Text == "" || regForm.textBoxEducation.Text == "" || regForm.textBoxBirthPlace.Text == "") { throw (new ArgumentNullException()); } if (!(nameCheck.IsMatch(regForm.textSurname.Text) && nameCheck.IsMatch(regForm.textName.Text))) { throw (new Exception("Имя, фамилия и отчество начинаются с заглавной буквы и могут содержать только буквы русского алфавита.")); } else if (regForm.textName2.Text != "" && nameCheck.IsMatch(regForm.textName2.Text)) { throw (new Exception("Имя, фамилия и отчество начинаются с заглавной буквы и могут содержать только буквы русского алфавита.")); } if (!(numCheck.IsMatch(regForm.textBoxInsuranceBillNum.Text))) { throw (new Exception("Номера документов могут содержать только цифры.")); } newDoctor.FullName = regForm.textSurname.Text + " " + regForm.textName.Text + " " + regForm.textName2.Text; newDoctor.Gender = regForm.comboBoxGender.Text; newDoctor.BirthDate = regForm.dateTimePickerBirthDate.Value.Date; newDoctor.Nationality = regForm.textNation.Text; newDoctor.LiveAdress = regForm.textLiveAdress.Text; newDoctor.RegAdress = regForm.textRegAdress.Text; newDoctor.RegDate = regForm.dateTimePickerRegDate.Value.Date; newDoctor.InsuranceBillNum = regForm.textBoxInsuranceBillNum.Text; newDoctor.Education = regForm.textBoxEducation.Text; newDoctor.Job = regForm.comboBoxJob.Text; newDoctor.Memberships = regForm.textBoxMemberships.Text; newDoctor.BirthPlace = regForm.textBoxBirthPlace.Text; newDoctor.NameHashID = newDoctor.FullName.GetHashCode(); try { long docNum = long.Parse(regForm.textDocumentN.Text); if (docNum < 0) { throw new FormatException(); } string docName = regForm.comboBoxDocType.Text; var doc = from d in db.DocumentsSet where (d.DocumentName == docName && d.DocumentNum == docNum) select d; if (doc.Count() == 0) { newDoctor.Documents = new Documents { DocumentName = docName, DocumentNum = docNum, Person = newDoctor } } ; else { throw new Exception("Данные документы уже приписаны к другой персоне"); } } catch (FormatException) { throw new Exception("В номере документа могут быть только цифры"); } catch (Exception a) { throw a; } if (regForm.textBoxPassword1.Text == regForm.textBoxPassword2.Text) { newDoctor.Password = regForm.textBoxPassword1.Text; } else { throw new Exception("Пароль не совпадает с введённым во второй раз"); } if (db.PersonSet.Find(newDoctor.BirthDate, newDoctor.NameHashID) != null) { throw new Exception("Данный человек уже зарегистрирован"); } newDoctor.FreeTimes = makeJob(new int[] { 0, 1, 2, 3, 4 }, DateTime.Today, newDoctor); newDoctor.WorkTimes = new List <WorkTime>(); newDoctor.DoctorRecord = new List <DoctorRecord>(); db.PersonSet.Add(newDoctor); db.SaveChanges(); login = newDoctor.FullName + "_" + newDoctor.BirthDate.ToShortDateString(); password = newDoctor.Password; return(true); } catch (ArgumentNullException) { MessageBox.Show("Заполните пустые поля, где не указано \"При наличии\""); return(false); } catch (ArgumentOutOfRangeException) { MessageBox.Show("Данные в полях выходят за границы возможных значений"); return(false); } catch (Exception a) { MessageBox.Show(a.Message); return(false); } } }