Пример #1
0
        private void AddPatient_Click(object sender, EventArgs e)
        {
            EntityModelContainer container = new EntityModelContainer();

            int row = SearchResults.SelectedCells[0].RowIndex;

            Patient selectedPat =
                container.PatientSet.Find(int.Parse(SearchResults.Rows[row].Cells[0].Value.ToString()));

            AddDeviceForm newDeviceType = new AddDeviceForm();

            if (newDeviceType.ShowDialog() == DialogResult.OK)
            {
                DeviceFunction type  = newDeviceType.function;
                bool           exist = false;

                foreach (Device d in selectedPat.Device)
                {
                    if (d.Function == type)
                    {
                        exist = true;
                    }
                }

                if (exist)
                {
                    if (MessageBox.Show(
                            "Данный тип прибора уже закреплен за пациентом. Добавить пациента в список пациентов?", "",
                            MessageBoxButtons.YesNo) ==
                        DialogResult.Yes)
                    {
                        InformationSystem.AddDoctorPatientConnection(user, selectedPat);
                        this.Close();
                    }
                }
                else
                {
                    Device newDevice = InformationSystem.CreateDevice(selectedPat, type);
                    InformationSystem.AddDevice(newDevice, selectedPat);

                    InformationSystem.AddDoctorPatientConnection(user, selectedPat);
                    this.Close();
                }
            }

            container.SaveChanges();
        }