Ejemplo n.º 1
0
 private void ButtonAddEditTicket_Click(object sender, RoutedEventArgs e)
 {
     if (!IsEdit)
     {
         if (textBlockAddEditCost.Text != string.Empty)
         {
             using (WFAEntity.API.MyDBContext objectMyDBContext =
                        new WFAEntity.API.MyDBContext())
             {
                 WFAEntity.API.Ticket objectTicket = new WFAEntity.API.Ticket(
                     textBlockAddEditCost.Text,
                     textBlockAddEditAmount.Text,
                     textBlockAddEditStatus.Text,
                     (WFAEntity.API.Client)ComboBoxAddEditClient.SelectedItem,
                     (WFAEntity.API.MK_schedule)ComboBoxAddEditShedule.SelectedItem,
                     (WFAEntity.API.Other_services)ComboBoxAddEditServices.SelectedItem,
                     (WFAEntity.API.Skates_hire)ComboBoxAddEditSkates.SelectedItem
                     );
                 try
                 {
                     objectMyDBContext.Ticket.Add(objectTicket);
                     objectMyDBContext.SaveChanges();
                     MessageBox.Show("Билет добавлен");
                     this.DialogResult = true;
                     AF.ShowAll();
                 }
                 catch (Exception ex)
                 {
                     MessageBox.Show(ex.Message, "ОШИБКА", MessageBoxButton.OK, MessageBoxImage.Error);
                 }
             }
         }
         else
         {
             MessageBox.Show("Заполните все поля!", "Ошибка!");
             this.DialogResult = false;
         }
     }
     else
     {
         using (WFAEntity.API.MyDBContext objectMyDBContext =
                    new WFAEntity.API.MyDBContext())
         {
             WFAEntity.API.Employees objectTicket = new WFAEntity.API.Employees();
             EditTicket.Cost   = textBlockAddEditCost.Text;
             EditTicket.Amount = textBlockAddEditAmount.Text;
             EditTicket.Status = textBlockAddEditStatus.Text;
             try
             {
                 objectMyDBContext.Ticket.AddOrUpdate(EditTicket);
                 objectMyDBContext.SaveChanges();
                 MessageBox.Show("Билет Редактирован");
                 this.DialogResult = true;
                 AF.ShowAll();
             }
             catch (Exception ex)
             {
                 MessageBox.Show(ex.Message, "ОШИБКА", MessageBoxButton.OK, MessageBoxImage.Error);
             }
         }
     }
 }
Ejemplo n.º 2
0
 private void ButtonAddEditEmployees_Click(object sender, RoutedEventArgs e)
 {
     if (!IsEdit)
     {
         if (textBlockAddEditSurname.Text != string.Empty)
         {
             using (WFAEntity.API.MyDBContext objectMyDBContext =
                        new WFAEntity.API.MyDBContext())
             {
                 WFAEntity.API.Employees objectEmployees = new WFAEntity.API.Employees();
                 objectEmployees.ID_employees = objectMyDBContext.Employees.Count();
                 objectEmployees.ID_employees++;
                 objectEmployees.Surname    = textBlockAddEditSurname.Text;
                 objectEmployees.Name       = textBlockAddEditName.Text;
                 objectEmployees.Patronymic = textBlockAddEditPatronymic.Text;
                 objectEmployees.Address    = textBlockAddEditAddress.Text;
                 objectEmployees.Telephone  = textBlockAddEditTelephone.Text;
                 objectEmployees.Position   = textBlockAddEditPosition.Text;
                 objectEmployees.Date       = textBlockAddEditDate.Text;
                 objectEmployees.Password   = textBlockAddEditPassword.Text;
                 objectEmployees.Login      = textBlockAddEditLogin.Text;
                 try
                 {
                     objectMyDBContext.Employees.Add(objectEmployees);
                     objectMyDBContext.SaveChanges();
                     MessageBox.Show("Сотрудник добавлен");
                     this.DialogResult = true;
                     AF.ShowAll();
                 }
                 catch (Exception ex)
                 {
                     MessageBox.Show(ex.Message, "ОШИБКА", MessageBoxButton.OK, MessageBoxImage.Error);
                 }
             }
         }
         else
         {
             MessageBox.Show("Заполните все поля!", "Ошибка!");
             this.DialogResult = false;
         }
     }
     else
     {
         using (WFAEntity.API.MyDBContext objectMyDBContext =
                    new WFAEntity.API.MyDBContext())
         {
             WFAEntity.API.Employees objectEmployees = new WFAEntity.API.Employees();
             EditEmployees.Surname    = textBlockAddEditSurname.Text;
             EditEmployees.Name       = textBlockAddEditName.Text;
             EditEmployees.Patronymic = textBlockAddEditPatronymic.Text;
             EditEmployees.Address    = textBlockAddEditAddress.Text;
             EditEmployees.Telephone  = textBlockAddEditTelephone.Text;
             EditEmployees.Position   = textBlockAddEditPosition.Text;
             EditEmployees.Date       = textBlockAddEditDate.Text;
             EditEmployees.Login      = textBlockAddEditLogin.Text;
             EditEmployees.Password   = textBlockAddEditPassword.Text;
             try
             {
                 objectMyDBContext.Employees.AddOrUpdate(EditEmployees);
                 objectMyDBContext.SaveChanges();
                 MessageBox.Show("Клиент Редактирован");
                 this.DialogResult = true;
                 AF.ShowAll();
             }
             catch (Exception ex)
             {
                 MessageBox.Show(ex.Message, "ОШИБКА", MessageBoxButton.OK, MessageBoxImage.Error);
             }
         }
     }
 }