AddRouteWindow.xaml.cs 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. using System.Windows;
  7. using System.Windows.Controls;
  8. using System.Windows.Data;
  9. using System.Windows.Documents;
  10. using System.Windows.Input;
  11. using System.Windows.Media;
  12. using System.Windows.Media.Imaging;
  13. using System.Windows.Shapes;
  14. namespace Kusach
  15. {
  16. /// <summary>
  17. /// Логика взаимодействия для AddRouteWindow.xaml
  18. /// </summary>
  19. public partial class AddRouteWindow : Window
  20. {
  21. public AddRouteWindow()
  22. {
  23. InitializeComponent();
  24. }
  25. private void BackButton_Click(object sender, RoutedEventArgs e)
  26. {
  27. this.Close();
  28. }
  29. public void OnLoad(object sender, RoutedEventArgs e)
  30. {
  31. RouteNameBox.Focus();
  32. }
  33. private void AddUserButton_Click(object sender, RoutedEventArgs e)
  34. {
  35. if (RouteNameBox.Text == "")
  36. MessageBox.Show("Поля не могут быть пустыми.");
  37. else
  38. {
  39. try
  40. {
  41. Routes newRoute = new Routes()
  42. {
  43. IdRoute = cnt.db.Routes.Count() + 1,
  44. Name = RouteNameBox.Text
  45. };
  46. cnt.db.Routes.Add(newRoute);
  47. cnt.db.SaveChanges();
  48. this.Close();
  49. }
  50. catch
  51. {
  52. MessageBox.Show("Ошибка создания маршрута.");
  53. this.Close();
  54. }
  55. }
  56. }
  57. }
  58. }