private void AddDevice_Click(object sender, EventArgs e) { int row = PatientsList.SelectedCells[0].RowIndex; int userCode = int.Parse(PatientsList.Rows[row].Cells[0].Value.ToString()); Patient selectedPat = _container.PatientSet.Find(userCode); AddDeviceForm newDeviceType = new AddDeviceForm(); if (newDeviceType.ShowDialog() != DialogResult.Cancel) { DeviceFunction type = newDeviceType.function; bool exist = false; foreach (Device d in selectedPat.Device) { if (d.Function == type) { exist = true; } } if (exist) { MessageBox.Show("Данный тип прибора уже закреплен за пациентом."); } else { Device newDevice = InformationSystem.CreateDevice(selectedPat, type); InformationSystem.AddDevice(newDevice, selectedPat); } } }
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(); }