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 { /// /// Логика взаимодействия для AddEditAgent.xaml /// public partial class AddEditAgent : Window, INotifyPropertyChanged { public event PropertyChangedEventHandler PropertyChanged; public Agent CurrentAgent { get; set; } public List AgentTypeList { get; set; } public string Name { get { return CurrentAgent.ID == 0 ? "Новый агенат" : "Редактировать агента"; } } private IEnumerable _AgentList; public IEnumerable 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; } } } }