private void Window_Loaded(object sender, RoutedEventArgs e) { try { using (WFAEntity.API.MyDBContext objectMyDBContext = new WFAEntity.API.MyDBContext()) { try { if (objectMyDBContext.Database.Exists() == false) { WFAEntity.API.DatabaseRequest.Fill(); //objectMyDBContext.Database.Create(); //WFAEntity.API.Employees objectUser = new WFAEntity.API.Employees(); //objectUser.Name = "user name"; //objectUser.Login = "******"; //objectUser.Password = "******"; //objectMyDBContext.Employees.Add(objectUser); objectMyDBContext.SaveChanges(); } //WFAEntity.API.DatabaseRequest.Fill(); } catch (Exception ex) { MessageBox.Show(ex.Message, "Создание базы данных"); } } } catch (Exception ex) { MessageBox.Show(ex.Message, "Подключение к базе данных"); } this.ShowAll(); }
private void ButtonAddEditServices_Click(object sender, RoutedEventArgs e) { if (!IsEdit) { if (textBlockAddEditName.Text != string.Empty) { WFAEntity.API.Other_services objectServices = new WFAEntity.API.Other_services( textBlockAddEditName.Text, textBlockAddEditThe_cost.Text, (WFAEntity.API.Employees)ComboBoxAddEditName.SelectedItem ); try { using (WFAEntity.API.MyDBContext objectMyDBContext = new WFAEntity.API.MyDBContext()) { objectMyDBContext.Other_services.Add(objectServices); objectMyDBContext.SaveChanges(); } MessageBox.Show("Услуга добавлена"); this.DialogResult = true; } catch (Exception ex) { MessageBox.Show(ex.Message, "ОШИБКА", MessageBoxButton.OK, MessageBoxImage.Error); } } else { MessageBox.Show("Заполните все поля!", "Ошибка!"); this.DialogResult = false; } } }
private void deleteSkatesButton_Click(object sender, RoutedEventArgs e) { if (SkatesGrid.SelectedItems.Count > 0) { for (int i = 0; i < SkatesGrid.SelectedItems.Count; i++) { WFAEntity.API.Skates_hire objectSkates = SkatesGrid.SelectedItems[i] as WFAEntity.API.Skates_hire; // if (objectSkates != null) try { using (WFAEntity.API.MyDBContext objectMyDBContext = new WFAEntity.API.MyDBContext()) { WFAEntity.API.Skates_hire Skates = WFAEntity.API.DatabaseRequest.GetSkatesById(objectMyDBContext, objectSkates.ID_skates_hire); objectMyDBContext.Skates_hire.Attach(Skates); objectMyDBContext.Skates_hire.Remove(Skates); objectMyDBContext.SaveChanges(); } //this.ShowAll(SELECTED_TAB.STUDENT); } catch (Exception ex) { MessageBox.Show(ex.Message, "ОШИБКА", MessageBoxButton.OK, MessageBoxImage.Error); } } } }
private void deleteTicketButton_Click(object sender, RoutedEventArgs e) { // var itm = (Ticket)TicketsGrid.SelectedItem; // var tmp = ( //from tmpTicket in MyDBContext.DBContext.Ticket.ToList<Ticket>() //where tmpTicket.ID_Ticket == itm.ID_Ticket //select tmpTicket // ).ToList(); // MyDBContext.DBContext.Ticket.Remove(tmp[0]); // MyDBContext.DBContext.SaveChanges(); // ShowAll(); if (TicketsGrid.SelectedItems.Count > 0) { for (int i = 0; i < TicketsGrid.SelectedItems.Count; i++) { WFAEntity.API.Ticket objectSkatesTicket = TicketsGrid.SelectedItems[i] as WFAEntity.API.Ticket; //if (objectSkates != null) try { using (WFAEntity.API.MyDBContext objectMyDBContext = new WFAEntity.API.MyDBContext()) { //WFAEntity.API.Ticket Skates = WFAEntity.API.DatabaseRequest.GetSkatesById(objectMyDBContext, objectSkates.ID_skates_hire); //objectMyDBContext.Skates_hire.Attach(Skates); //objectMyDBContext.Skates_hire.Remove(Skates); objectMyDBContext.SaveChanges(); } //this.ShowAll(SELECTED_TAB.STUDENT); } catch (Exception ex) { MessageBox.Show(ex.Message, "ОШИБКА", MessageBoxButton.OK, MessageBoxImage.Error); } } } }
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); } } } }
private void ButtonAddEditSkates_Click(object sender, RoutedEventArgs e) { if (!IsEdit) { if (textBlockAddEditSize.Text != string.Empty) { using (WFAEntity.API.MyDBContext objectMyDBContext = new WFAEntity.API.MyDBContext()) { WFAEntity.API.Skates_hire objectSkates = new WFAEntity.API.Skates_hire( textBlockAddEditSize.Text, textBlockAddEditTime.Text, textBlockAddEditCount.Text, textBlockAddEditType.Text, (WFAEntity.API.Employees)ComboBoxAddEditEmployess.SelectedItem ); try { objectMyDBContext.Skates_hire.Add(objectSkates); 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.Skates_hire objectSkates = new WFAEntity.API.Skates_hire( textBlockAddEditSize.Text, textBlockAddEditTime.Text, textBlockAddEditType.Text, textBlockAddEditCount.Text, (WFAEntity.API.Employees)ComboBoxAddEditEmployess.SelectedItem ); try { objectMyDBContext.Skates_hire.AddOrUpdate(EditSkates); objectMyDBContext.SaveChanges(); MessageBox.Show("Клиент Редактирован"); this.DialogResult = true; AF.ShowAll(); } catch (Exception ex) { MessageBox.Show(ex.Message, "ОШИБКА", MessageBoxButton.OK, MessageBoxImage.Error); } } } }
private void ButtonAddEditShedule_Click(object sender, RoutedEventArgs e) { if (!IsEdit) { if (textBlockAddEditDate.Text != string.Empty) { using (WFAEntity.API.MyDBContext objectMyDBContext = new WFAEntity.API.MyDBContext()) { WFAEntity.API.MK_schedule objectShedule = new WFAEntity.API.MK_schedule( textBlockAddEditDate.Text, textBlockAddEditPrice.Text, textBlockAddEditStart.Text, textBlockAddEditEnd.Text, (WFAEntity.API.Employees)ComboBoxAddEditEmployees.SelectedItem, (WFAEntity.API.Other_services)ComboBoxAddEditServices.SelectedItem ); try { objectMyDBContext.MK_schedule.Add(objectShedule); 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.MK_schedule objectShedule = new WFAEntity.API.MK_schedule(); objectShedule.Date = textBlockAddEditDate.Text; objectShedule.Price = textBlockAddEditPrice.Text; objectShedule.Start_time = textBlockAddEditStart.Text; objectShedule.End_time = textBlockAddEditEnd.Text; try { objectMyDBContext.MK_schedule.AddOrUpdate(EditShedule); objectMyDBContext.SaveChanges(); MessageBox.Show("Расписание Редактировано"); this.DialogResult = true; AF.ShowAll(); } catch (Exception ex) { MessageBox.Show(ex.Message, "ОШИБКА", MessageBoxButton.OK, MessageBoxImage.Error); } } } }
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); } } } }
private void ButtonAddEditGroup_Click(object sender, RoutedEventArgs e) { if (!IsEdit) { if (textBlockAddEditSurname.Text != string.Empty) { using (WFAEntity.API.MyDBContext objectMyDBContext = new WFAEntity.API.MyDBContext()) { WFAEntity.API.Client objectClient = new WFAEntity.API.Client(); objectClient.Surname = textBlockAddEditSurname.Text; objectClient.Name = textBlockAddEditName.Text; objectClient.Patronymic = textBlockAddEditPatronymic.Text; objectClient.Address = textBlockAddEditAdress.Text; objectClient.Number = textBlockAddEditTelephone.Text; try { objectMyDBContext.Client.Add(objectClient); 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.Client objectClient = new WFAEntity.API.Client(); EditClient.Surname = textBlockAddEditSurname.Text; EditClient.Name = textBlockAddEditName.Text; EditClient.Patronymic = textBlockAddEditPatronymic.Text; EditClient.Address = textBlockAddEditAdress.Text; EditClient.Number = textBlockAddEditTelephone.Text; try { objectMyDBContext.Client.AddOrUpdate(EditClient); objectMyDBContext.SaveChanges(); MessageBox.Show("Клиент Редактирован"); this.DialogResult = true; AF.ShowAll(); } catch (Exception ex) { MessageBox.Show(ex.Message, "ОШИБКА", MessageBoxButton.OK, MessageBoxImage.Error); } } } }