123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111 |
- using Microsoft.Win32;
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- 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 WpfApp1.SQL;
- namespace WpfApp1.Windows
- {
- /// <summary>
- /// Логика взаимодействия для AddEditAgent.xaml
- /// </summary>
- public partial class AddEditAgent : Window, INotifyPropertyChanged
- {
- public event PropertyChangedEventHandler PropertyChanged;
- public Agent CurrentAgent { get; set; }
- public List<AgentType> AgentTypeList { get; set; }
- public string Name
- {
- get
- {
- return CurrentAgent.ID == 0 ? "Новый агенат" : "Редактировать агента";
- }
- }
- private IEnumerable<Agent> _AgentList;
- public IEnumerable<Agent> AgentList
- {
- get
- {
- return _AgentList;
- }
- set
- {
- _AgentList = value;
- }
- }
- public AddEditAgent(Agent agents)
- {
- InitializeComponent();
- DataContext = this;
- CurrentAgent = agents;
- AgentList = Core.DB.Agent.ToList();
- AgentTypeList = Core.DB.AgentType.ToList();
- //CurrentAgent = Core.DB.Agent.ToList();
- }
- private void AddImage_Click(object sender, RoutedEventArgs e)
- {
- OpenFileDialog GetImageDialog = new OpenFileDialog();
- GetImageDialog.Filter = "Файлы изображений: (*.png, *.jng)| *.png; *,jnp";
- GetImageDialog.InitialDirectory = Environment.CurrentDirectory;
- if (GetImageDialog.ShowDialog() == true)
- {
- CurrentAgent.Logo = GetImageDialog.FileName.Substring(Environment.CurrentDirectory.Length);
- PropertyChanged(this, new PropertyChangedEventArgs("AgentList"));
- }
- }
- private void AddButton_Click(object sender, RoutedEventArgs e)
- {
- if (CurrentAgent.ID == 0) Core.DB.Agent.Add(CurrentAgent);
- try
- {
- Core.DB.SaveChanges();
- }
- catch (Exception ex)
- {
- MessageBox.Show("Ошибка");
- return;
- }
- DialogResult = true;
- }
- private void DeleteButton_Click(object sender, RoutedEventArgs e)
- {
- if (MessageBox.Show("Ты уверен?", "Внимание", MessageBoxButton.YesNo, MessageBoxImage.Question) == MessageBoxResult.Yes)
- {
- try
- {
- if (CurrentAgent.ProductSale.Count > 0)
- {
- MessageBox.Show("Нелья удалять агент, если есть продаж агентов или история изменения приоритета");
- return;
- }
- Core.DB.Agent.Remove(CurrentAgent);
- Core.DB.SaveChanges();
- }
- catch (Exception ex)
- {
- MessageBox.Show(ex.Message, "Ошибка");
- }
- DialogResult = true;
- }
- }
- }
- }
|