FirehouseWindow.xaml.cs 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Data.Entity.Validation;
  4. using System.Linq;
  5. using System.Text;
  6. using System.Threading.Tasks;
  7. using System.Windows;
  8. using System.Windows.Controls;
  9. using System.Windows.Data;
  10. using System.Windows.Documents;
  11. using System.Windows.Input;
  12. using System.Windows.Media;
  13. using System.Windows.Media.Imaging;
  14. using System.Windows.Shapes;
  15. namespace Firewatch_2._0
  16. {
  17. /// <summary>
  18. /// Логика взаимодействия для FirehouseWindow.xaml
  19. /// </summary>
  20. public partial class FirehouseWindow : Window
  21. {
  22. dbData db = new dbData();
  23. public FirehouseWindow()
  24. {
  25. InitializeComponent();
  26. DataContext = new Firehouse();
  27. }
  28. public FirehouseWindow(Firehouse firehouse)
  29. {
  30. InitializeComponent();
  31. DataContext = firehouse;
  32. }
  33. private void Firehouse_OK(object sender, RoutedEventArgs e)
  34. {
  35. if (DataContext is Firehouse firehouse && firehouse.Firehouse_ID == 0)
  36. {
  37. Helper.context.Firehouses.Add(firehouse);
  38. }
  39. try
  40. {
  41. Helper.context.SaveChanges();
  42. }
  43. catch (DbEntityValidationException ex)
  44. {
  45. foreach (DbEntityValidationResult validationError in ex.EntityValidationErrors)
  46. {
  47. MessageBox.Show("Object: " + validationError.Entry.Entity.ToString());
  48. foreach (DbValidationError err in validationError.ValidationErrors)
  49. {
  50. MessageBox.Show(err.ErrorMessage + "");
  51. }
  52. }
  53. }
  54. Close();
  55. }
  56. private void Firehouse_Close(object sender, RoutedEventArgs e)
  57. {
  58. Close();
  59. }
  60. }
  61. }