|
@@ -11,6 +11,7 @@ using System.Windows.Input;
|
|
|
using System.Windows.Media;
|
|
|
using System.Windows.Media.Imaging;
|
|
|
using System.Windows.Shapes;
|
|
|
+using DemoexamUser11.classes;
|
|
|
|
|
|
namespace DemoexamUser11.windows
|
|
|
{
|
|
@@ -19,9 +20,76 @@ namespace DemoexamUser11.windows
|
|
|
/// </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);
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
}
|