Пример #1
0
 private void addButton_Click(object sender, EventArgs e)
 {
     switch (entityType)
     {
         case EntityType.Classes:
             {
                 ClassEditForm classForm = new ClassEditForm();
                 if (!allSchools)
                 {
                     classForm.SchoolId = schoolId;
                 }
                 while (true)
                 {
                     try
                     {
                         classForm.ShowDialog();
                     }
                     catch (EmptyValueException) { }
                     if (!classForm.Cancel)
                     {
                         try
                         {
                             SchoolClassCustomEntity sc = new SchoolClassCustomEntity();
                             sc.AddValue(
                                 classForm.SchoolId,
                                 classForm.ClassTypeId,
                                 classForm.ClassName,
                                 classForm.BoysAmount,
                                 classForm.GirlsAmount);
                         }
                         catch (ValueAlreadyExistsException)
                         {
                             MessageBox.Show("Такое значение уже есть в базе");
                             continue;
                         }
                     }
                     break;
                 }
                 break;
             }
         case EntityType.Employees:
             {
                 EmployessEditForm empForm = new EmployessEditForm();
                 if (!allSchools)
                 {
                     empForm.SchoolId = schoolId;
                 }
                 while (true)
                 {
                     try
                     {
                         empForm.ShowDialog();
                     }
                     catch (EmptyValueException) { }
                     if (!empForm.Cancel)
                     {
                         try
                         {
                             string edu = empForm.Education;
                             EmployeeCustomEntity emp = new EmployeeCustomEntity();
                             emp.AddValue(
                                 empForm.SchoolId,
                                 empForm.EmployeeTypeId,
                                 empForm.EmpName,
                                 empForm.Gender,
                                 empForm.Address,
                                 empForm.Education,
                                 empForm.Category,
                                 empForm.SubjectId,
                                 empForm.DistrictId);
                         }
                         catch (ValueAlreadyExistsException)
                         {
                             MessageBox.Show("Такое значение уже есть в базе");
                             continue;
                         }
                     }
                     break;
                 }
                 break;
             }
         case EntityType.Quarters:
             {
                 SchoolQuartersEditForm scForm = new SchoolQuartersEditForm();
                 if (!allSchools)
                 {
                     scForm.SchoolId = schoolId;
                 }
                 while (true)
                 {
                     try
                     {
                         scForm.ShowDialog();
                     }
                     catch (EmptyValueException) { }
                     if (!scForm.Cancel)
                     {
                         try
                         {
                             SchoolQuartersCustomEntity sc = new SchoolQuartersCustomEntity();
                             sc.AddValue(
                                 scForm.SchoolId,
                                 scForm.QuartersTypeId,
                                 scForm.Area);
                         }
                         catch (ValueAlreadyExistsException)
                         {
                             MessageBox.Show("Такое значение уже есть в базе");
                             continue;
                         }
                     }
                     break;
                 }
                 break;
             }
         case EntityType.Schools:
             {
                 SchoolEditForm scForm = new SchoolEditForm();
                 while (true)
                 {
                     try
                     {
                         scForm.ShowDialog();
                     }
                     catch (EmptyValueException) { }
                     if (!scForm.Cancel)
                     {
                         try
                         {
                             SchoolCustomEntity sc = new SchoolCustomEntity();
                             sc.AddValue(
                                 scForm.SchoolName,
                                 scForm.IdSPType,
                                 scForm.IdSPBType,
                                 scForm.Amount,
                                 scForm.Address,
                                 scForm.DistrictId);
                         }
                         catch (ValueAlreadyExistsException)
                         {
                             MessageBox.Show("Такое значение уже есть в базе");
                             continue;
                         }
                     }
                     break;
                 }
                 break;
             }
         case EntityType.Tools:
             {
                 SchoolToolsEditForm stForm = new SchoolToolsEditForm();
                 if (!allSchools)
                 {
                     stForm.SchoolId = schoolId;
                 }
                 while (true)
                 {
                     try
                     {
                         stForm.ShowDialog();
                     }
                     catch (EmptyValueException) { }
                     if (!stForm.Cancel)
                     {
                         try
                         {
                             SchoolToolsCustomEntity st = new SchoolToolsCustomEntity();
                             st.AddValue(
                                 stForm.SchoolId,
                                 stForm.ToolTypeId,
                                 stForm.Amount);
                         }
                         catch (ValueAlreadyExistsException)
                         {
                             MessageBox.Show("Такое значение уже есть в базе");
                             continue;
                         }
                     }
                     break;
                 }
                 break;
             }
         case EntityType.Vehicles:
             {
                 SchoolVehiclesEditForm svForm = new SchoolVehiclesEditForm();
                 if (!allSchools)
                 {
                     svForm.idSchool = schoolId;
                 }
                 while (true)
                 {
                     try
                     {
                         svForm.ShowDialog();
                     }
                     catch (EmptyValueException) { }
                     if (!svForm.Cancel)
                     {
                         try
                         {
                             SchoolVehiclesCustomEntity sv = new SchoolVehiclesCustomEntity();
                             sv.AddValue(
                                 svForm.idSchool,
                                 svForm.idVehicleType,
                                 svForm.Amount);
                         }
                         catch (ValueAlreadyExistsException)
                         {
                             MessageBox.Show("Такое значение уже есть в базе");
                             continue;
                         }
                     }
                     break;
                 }
                 break;
             }
     }
     FillTable();
 }
Пример #2
0
 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();
 }
Пример #3
0
 private void deleteButton_Click(object sender, EventArgs e)
 {
     DialogResult result = MessageBox.Show("Все связанные записи также будут удалены. Продолжить?", "Подтвердите удаление", MessageBoxButtons.YesNoCancel);
     if (result == DialogResult.Yes)
     {
         int index = dataGridView1.SelectedCells[0].RowIndex;
         switch (entityType)
         {
             case EntityType.Classes:
                 {
                     SchoolClass schoolClass =
                         (from sc in EntitiesHolder.Entities.SchoolClass
                          select sc).ToArray()[index];
                     try
                     {
                         SchoolClassCustomEntity sc = new SchoolClassCustomEntity();
                         sc.DeleteValue(schoolClass.idClass);
                     }
                     catch { }
                     break;
                 }
             case EntityType.Employees:
                 {
                     Employee emp =
                         (from sc in EntitiesHolder.Entities.Employee
                          select sc).ToArray()[index];
                     try
                     {
                         EmployeeCustomEntity ee = new EmployeeCustomEntity();
                         ee.DeleteValue(emp.idEmployee);
                     }
                     catch { }
                     break;
                 }
             case EntityType.Quarters:
                 {
                     SchoolQuarters sq =
                         (from sc in EntitiesHolder.Entities.SchoolQuarters
                          select sc).ToArray()[index];
                     try
                     {
                         SchoolQuartersCustomEntity sqe = new SchoolQuartersCustomEntity();
                         sqe.DeleteValue(sq.idSchool, sq.idQuartersType);
                     }
                     catch { }
                     break;
                 }
             case EntityType.Schools:
                 {
                     School s =
                         (from sc in EntitiesHolder.Entities.School
                          select sc).ToArray()[index];
                     try
                     {
                         SchoolCustomEntity se = new SchoolCustomEntity();
                         se.DeleteValue(s.idSchool);
                     }
                     catch { }
                     break;
                 }
             case EntityType.Tools:
                 {
                     SchoolTools st =
                         (from sc in EntitiesHolder.Entities.SchoolTools
                          select sc).ToArray()[index];
                     try
                     {
                         SchoolToolsCustomEntity ste = new SchoolToolsCustomEntity();
                         ste.DeleteValue(st.idSchool, st.idToolType);
                     }
                     catch { }
                     break;
                 }
             case EntityType.Vehicles:
                 {
                     SchoolVehicles sv =
                         (from sc in EntitiesHolder.Entities.SchoolVehicles
                          select sc).ToArray()[index];
                     try
                     {
                         SchoolVehiclesCustomEntity sve = new SchoolVehiclesCustomEntity();
                         sve.DeleteValue(sv.idSchool, sv.idVehicleType);
                     }
                     catch { }
                     break;
                 }
         }
         FillTable();
     }
 }