NewAgent.xaml.cs 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. using Microsoft.Win32;
  2. using System;
  3. using System.Collections.Generic;
  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 Demoexample
  16. {
  17. /// <summary>
  18. /// Логика взаимодействия для NewAgent.xaml
  19. /// </summary>
  20. public partial class NewAgent : Window
  21. {
  22. string imgg = " ";
  23. public Agent buffer;
  24. public NewAgent()
  25. {
  26. InitializeComponent();
  27. Type.ItemsSource = DataBase.BaseModel.AgentType.ToList();
  28. Type.SelectedValuePath = "ID";
  29. Type.DisplayMemberPath = "Title";
  30. Type.SelectedIndex = 1;
  31. }
  32. private void newImg_Click(object sender, RoutedEventArgs e)
  33. {
  34. OpenFileDialog openFileDialog = new OpenFileDialog();
  35. openFileDialog.DefaultExt = ".jpg";
  36. openFileDialog.Filter = "Изображение | *.jpg; *.png";
  37. var result = openFileDialog.ShowDialog();
  38. if (result == true)
  39. {
  40. imgg = openFileDialog.FileName;
  41. imgnew.Source = BitmapFrame.Create(new Uri(imgg));
  42. }
  43. }
  44. private void add_Click(object sender, RoutedEventArgs e)
  45. {
  46. List<Agent> pro = DataBase.BaseModel.Agent.ToList();
  47. if(Convert.ToInt32(prioritey.Text)<0 && Convert.ToInt32(prioritey.Text) % 10==0)
  48. {
  49. throw new Exception("Приоритет не может быть отрицательным");
  50. }
  51. Agent agent = new Agent()
  52. {
  53. Title = name.Text,
  54. AgentTypeID = Type.SelectedIndex,
  55. Priority = Convert.ToInt32(prioritey.Text),
  56. Logo = imgg,
  57. Address = address.Text,
  58. INN = inn.Text,
  59. KPP = kpp.Text,
  60. DirectorName = director.Text,
  61. Phone = telephone.Text,
  62. Email = email.Text
  63. };
  64. DataBase.BaseModel.Agent.Add(agent);
  65. DataBase.BaseModel.SaveChanges();
  66. DataBase.BaseModel = new user32Entities();
  67. new MainWindow().Show();
  68. this.Close();
  69. }
  70. }
  71. }