База данных для хранения и обработки информации, которая требуется типичной психиатрической больнице, страница 2

                      if (!e.Data.GetDataPresent(DataFormats.FileDrop))

                              return;

                      string[] files = (string[])e.Data.GetData(DataFormats.FileDrop);

                      try

                      {

                              BackgroundImage = DbHelper.StretchBitmap(new Bitmap(files[0]));

                      }

                      catch (Exception excpt)

                      {

                              Program.ShowError(this, excpt.Message);

                      }

               }

               private void CustomizedImage_DragEnter(object sender, DragEventArgs e)

               {

                      if (e.Data.GetDataPresent(DataFormats.FileDrop))

                              e.Effect = DragDropEffects.Copy;

                      else

                              e.Effect = DragDropEffects.None;

               }

       }

}

namespace MentalHospital

{

       public partial class AddPatientForm : Form

       {

               List<DbDisease> _allDiseases = null;

               List<DbPerson> _allPersons = null;

               public AddPatientForm()

               {

                      InitializeComponent();

                      RefreshData();

                      //employeeImage.BackgroundImage = Properties.Resources.No_Image;

               }

               private void btnCancel_Click(object sender, EventArgs e)

               {

                      Close();

               }

               private void newHuman_CheckedChanged(object sender, EventArgs e)

               {

                      tableLayoutHumanInfo.Enabled = newHuman.Checked;

               }

               private void humanInBase_CheckedChanged(object sender, EventArgs e)

               {

                      cmbPersons.Enabled = humanInBase.Checked;

               }

               public void RefreshData()

               {

                      _allDiseases = DbHelper.GetAllDiseasesList();

                      _allPersons = DbHelper.GetAllPersons();

                      cmbDiseases.DataSource = _allDiseases;

                      cmbDiseases.SelectedIndex = -1;

                      cmbPersons.DataSource = _allPersons;

                      cmbPersons.SelectedIndex = -1;

                      txtName.AutoCompleteCustomSource.Clear();

                      txtSurname.AutoCompleteCustomSource.Clear();

                      txtPatronymic.AutoCompleteCustomSource.Clear();

                      foreach (DbPerson person in _allPersons)

                      {

                              txtName.AutoCompleteCustomSource.Add(person.Name);

                              txtSurname.AutoCompleteCustomSource.Add(person.Surname);

                              if (person.Patronymic != null) txtPatronymic.AutoCompleteCustomSource.Add(person.Patronymic);

                      }

               }

               private void cmbPersons_SelectedIndexChanged(object sender, EventArgs e)

               {

                      if (cmbPersons.SelectedIndex == -1)

                      {

                              txtName.Text = "";

                              txtSurname.Text = "";

                              txtPatronymic.Text = "";

                              txtPassport.Text = "";

                      }

                      else

                      {

                              DbPerson currentPerson = cmbPersons.SelectedItem as DbPerson;

                              txtName.Text = currentPerson.Name;

                              txtSurname.Text = currentPerson.Surname;

                              txtPatronymic.Text = currentPerson.Patronymic;

                              txtPassport.Text = currentPerson.Passport;

                      }

               }

               private void btnAdd_Click(object sender, EventArgs e)

               {

                      TextBox[] notEmptyFields = { txtName, txtSurname, txtPassport };

                      foreach (TextBox tb in notEmptyFields)

                      {

                              if (tb.Text != "") continue;

                              Program.ShowError(this, "Заполните пожалуйста все обязательные поля!");

                              tb.Focus();

                              return;

                      }

                      if (cmbDiseases.SelectedIndex == -1) { Program.ShowError(this, "Болезнь пациента не определена."); return; }

                      try

                      {

                              DbPatient patient = new DbPatient();

                              patient.Name = txtName.Text;

                             patient.Surname = txtSurname.Text;

                              patient.Patronymic = txtPatronymic.Text;

                              patient.Passport = txtPassport.Text;

                              patient.DiseaseID = (cmbDiseases.SelectedItem as DbDisease).Id;

                              patient.PlacementDate = DateTime.Now;

                              if (newHuman.Checked)

                              {

                                     DbHelper.AddNewPatient(patient);

                              }

                              else

                              {

                                     if (cmbPersons.SelectedItem == null) { Program.ShowError(this, "Человек не выбран!"); return; }

                                     patient.ID = (cmbPersons.SelectedItem as DbPerson).ID;

                                     DbHelper.AddNewPatientFromExistingPerson(patient);

                              }

                              DialogResult = DialogResult.OK;

                              Close();

                      }

                      catch (Exception excpt)

                      {