private void setButton_Click(object sender, EventArgs e) { int index = dataGridView1.SelectedCells[0].RowIndex; switch (entityType) { case EntityType.Classes: { SchoolClass schoolClass = (from sc in EntitiesHolder.Entities.SchoolClass select sc).ToArray()[index]; ClassEditForm classForm = new ClassEditForm( schoolClass.idSchool, schoolClass.idClassType, schoolClass.nameClass, schoolClass.boysAmount, schoolClass.girlsAmount); while (true) { try { classForm.ShowDialog(); } catch (EmptyValueException) { } if (!classForm.Cancel) { try { SchoolClassCustomEntity sc = new SchoolClassCustomEntity(); sc.SetValue( schoolClass.idClass, classForm.SchoolId, classForm.ClassTypeId, classForm.ClassName, classForm.BoysAmount, classForm.GirlsAmount); } catch (CapacityOverflowException) { MessageBox.Show("Достигнуто предельное число записей"); return; } catch (ValueAlreadyExistsException) { MessageBox.Show("Такое значение уже есть в базе"); continue; } } break; } break; } case EntityType.Employees: { Employee emp = (from sc in EntitiesHolder.Entities.Employee select sc).ToArray()[index]; EmployessEditForm empForm = new EmployessEditForm( emp.nameEmployee, emp.gender.Value, emp.idSchool.Value, emp.idEmployeeType.Value, emp.address, emp.education, emp.idSubject.Value, emp.rank.Value, emp.idDistrict.Value); while (true) { try { empForm.ShowDialog(); } catch (EmptyValueException) { } if (!empForm.Cancel) { try { EmployeeCustomEntity em = new EmployeeCustomEntity(); em.SetValue( emp.idEmployee, empForm.SchoolId, empForm.EmployeeTypeId, empForm.EmpName, empForm.Gender, empForm.Address, empForm.Education, empForm.Category, empForm.SubjectId, empForm.DistrictId); } catch (CapacityOverflowException) { MessageBox.Show("Достигнуто предельное число записей"); return; } catch (ValueAlreadyExistsException) { MessageBox.Show("Такое значение уже есть в базе"); continue; } } break; } break; } case EntityType.Quarters: { SchoolQuarters sq = (from sc in EntitiesHolder.Entities.SchoolQuarters select sc).ToArray()[index]; SchoolQuartersEditForm sqForm = new SchoolQuartersEditForm( sq.idSchool, sq.idQuartersType, sq.area.Value); while (true) { try { sqForm.ShowDialog(); } catch (EmptyValueException) { } if (!sqForm.Cancel) { try { SchoolQuartersCustomEntity sqe = new SchoolQuartersCustomEntity(); sqe.SetValue( sq.idSchool, sq.idQuartersType, sqForm.Area); } catch (CapacityOverflowException) { MessageBox.Show("Достигнуто предельное число записей"); return; } catch (ValueAlreadyExistsException) { MessageBox.Show("Такое значение уже есть в базе"); continue; } } break; } break; } case EntityType.Schools: { School s = (from sc in EntitiesHolder.Entities.School select sc).ToArray()[index]; SchoolEditForm sForm = new SchoolEditForm( s.nameSchool, s.idSchoolPropertyType.Value, s.idSchoolBuildingPropertyType.Value, s.computersAmount.Value, s.address, s.idDistrict.Value); while (true) { try { sForm.ShowDialog(); } catch (EmptyValueException) { } if (!sForm.Cancel) { try { SchoolCustomEntity se = new SchoolCustomEntity(); se.SetValue( s.idSchool, sForm.SchoolName, sForm.IdSPType, sForm.IdSPBType, sForm.Amount, sForm.Address, sForm.DistrictId); } catch (CapacityOverflowException) { MessageBox.Show("Достигнуто предельное число записей"); return; } catch (ValueAlreadyExistsException) { MessageBox.Show("Такое значение уже есть в базе"); continue; } } break; } break; } case EntityType.Tools: { SchoolTools st = (from sc in EntitiesHolder.Entities.SchoolTools select sc).ToArray()[index]; SchoolToolsEditForm stForm = new SchoolToolsEditForm( st.idSchool, st.idToolType, st.amount.Value); while (true) { try { stForm.ShowDialog(); } catch (EmptyValueException) { } if (!stForm.Cancel) { try { SchoolToolsCustomEntity ste = new SchoolToolsCustomEntity(); ste.SetValue( st.idSchool, st.idToolType, stForm.Amount); } catch (CapacityOverflowException) { MessageBox.Show("Достигнуто предельное число записей"); return; } catch (ValueAlreadyExistsException) { MessageBox.Show("Такое значение уже есть в базе"); continue; } } break; } break; } case EntityType.Vehicles: { SchoolVehicles sv = (from sc in EntitiesHolder.Entities.SchoolVehicles select sc).ToArray()[index]; SchoolVehiclesEditForm svForm = new SchoolVehiclesEditForm( sv.idSchool, sv.idVehicleType, sv.amount.Value); while (true) { try { svForm.ShowDialog(); } catch (EmptyValueException) { } if (!svForm.Cancel) { try { SchoolVehiclesCustomEntity sve = new SchoolVehiclesCustomEntity(); sve.AddValue( sv.idSchool, sv.idVehicleType, svForm.Amount); } catch (CapacityOverflowException) { MessageBox.Show("Достигнуто предельное число записей"); return; } catch (ValueAlreadyExistsException) { MessageBox.Show("Такое значение уже есть в базе"); continue; } } break; } break; } } FillTable(); }