AddAndRedactAgent.xaml.cs 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  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 WhiteList
  15. {
  16. /// <summary>
  17. /// Логика взаимодействия для AddAndRedactAgent.xaml
  18. /// </summary>
  19. public partial class AddAndRedactAgent : Window
  20. {
  21. public AddAndRedactAgent()
  22. {
  23. InitializeComponent();
  24. foreach(AgentType at in DB.dbCon.AgentType.ToList())
  25. {
  26. ComboBoxType.Items.Add(at.Title);
  27. }
  28. }
  29. private void Save_Click(object sender, RoutedEventArgs e)
  30. {
  31. try
  32. {
  33. int idType = DB.dbCon.AgentType.FirstOrDefault(x => x.Title == ComboBoxType.SelectedValue.ToString()).ID;
  34. Agent a = new Agent() //создаем агента
  35. {
  36. Title = TextBoxTitle.Text,
  37. AgentTypeID = idType,
  38. Address = TextBoxAdres.Text,
  39. INN = TextBoxINN.Text,
  40. KPP = TextBoxKPP.Text,
  41. DirectorName = TextBoxNameDirector.Text,
  42. Phone = TextBoxPhone.Text,
  43. Email = TextBoxEmail.Text,
  44. Priority = Convert.ToInt32(TextBoxPriority.Text)
  45. };
  46. DB.dbCon.Agent.Add(a);
  47. DB.dbCon.SaveChanges(); //сохраняем
  48. MessageBox.Show("Данные добавлены!");
  49. Close();
  50. }
  51. catch(Exception ee)
  52. {
  53. MessageBox.Show(ee.Message, "Ошибка");
  54. }
  55. }
  56. }
  57. }