Пример #1
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();
     }
 }