1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495 |
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.Windows;
- using System.Windows.Controls;
- using System.Windows.Data;
- using System.Windows.Documents;
- using System.Windows.Input;
- using System.Windows.Media;
- using System.Windows.Media.Imaging;
- using System.Windows.Shapes;
- using DemoexamUser11.classes;
- namespace DemoexamUser11.windows
- {
- /// <summary>
- /// Логика взаимодействия для WindowEditAgent.xaml
- /// </summary>
- public partial class WindowEditAgent : Window
- {
- bool isNewAgent = false;
- Agent agent;
- List<AgentType> types = BaseConnector.BaseConnect.AgentType.ToList();
- public WindowEditAgent()
- {
- InitializeComponent();
- Title = "Добавление нового агента";
- isNewAgent = true;
- comboBoxAgentType.ItemsSource = types;
- comboBoxAgentType.SelectedValuePath = "ID";
- comboBoxAgentType.DisplayMemberPath = "Title";
- textBlockImagePath.Text = "/images/picture.png";
- }
- public WindowEditAgent(Agent agent)
- {
- InitializeComponent();
- Title = "Редактирование агента";
- this.agent = agent;
- comboBoxAgentType.ItemsSource = types;
- comboBoxAgentType.SelectedValuePath = "ID";
- comboBoxAgentType.DisplayMemberPath = "Title";
- comboBoxAgentType.SelectedValue = agent.AgentTypeID;
- }
- private void buttonSave_Click(object sender, RoutedEventArgs e)
- {
- try
- {
- if (isNewAgent == true)
- {
- int lastID = BaseConnector.BaseConnect.Agent.ToList().Last().ID + 1;
- BaseConnector.BaseConnect.Agent.Add(new Agent()
- {
- ID = lastID,
- Address = textBoxAddres.Text,
- Title = textBoxTitle.Text,
- AgentTypeID = Convert.ToInt32(comboBoxAgentType.SelectedValue),
- Priority = Convert.ToInt32(textBoxPriority.Text),
- Logo = textBlockImagePath.Text,
- INN = textBoxINN.Text,
- KPP = textBoxKPP.Text,
- DirectorName = textBoxNameDirector.Text,
- Phone = textBoxPhone.Text,
- Email = textBoxEmail.Text
- });
- BaseConnector.BaseConnect.SaveChanges();
- MessageBox.Show("Успешно добавлено!");
- }
- }
- catch
- {
- MessageBox.Show("Не удалось добавить агента!", "Ошибка", MessageBoxButton.OK, MessageBoxImage.Error);
- }
- }
- private void buttonDelete_Click(object sender, RoutedEventArgs e)
- {
- if (isNewAgent == false)
- {
- try
- {
- BaseConnector.BaseConnect.Agent.Remove(agent);
- BaseConnector.BaseConnect.SaveChanges();
- MessageBox.Show("Успех!");
- }
- catch
- {
- MessageBox.Show("Не удалось удалить агента!", "Ошибка", MessageBoxButton.OK, MessageBoxImage.Error);
- }
- }
- }
- }
- }
|