123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199 |
- 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.Navigation;
- using System.Windows.Shapes;
- namespace Golyshev43p180322
- {
- /// <summary>
- /// Логика взаимодействия для ShowAgentPage.xaml
- /// </summary>
- public partial class ShowAgentPage : Page
- {
- List<Agent> AgentStart = BaseClass.Base.Agent.ToList();
- public ShowAgentPage()
- {
- InitializeComponent();
- LVAgent.ItemsSource = BaseClass.Base.Agent.ToList();
- CBFilter.Items.Add("Все типы");
- List<AgentType> AT = BaseClass.Base.AgentType.ToList();
- foreach(AgentType s in AT)
- {
- CBFilter.Items.Add(s.Title);
- }
- CBFilter.SelectedIndex = 0;
- CBSort.Items.Add("Все типы");
- CBSort.Items.Add("Наименование");
- CBSort.Items.Add("Размер скидки");
- CBSort.Items.Add("Приоритет агента");
- CBSort.SelectedIndex = 0;
- }
- private void TBTypeTitle_Loaded(object sender, RoutedEventArgs e)
- {
- TextBlock tb = (TextBlock)sender;
- int index = Convert.ToInt32(tb.Uid);
- string typename = "";
- List<Agent> A = BaseClass.Base.Agent.Where(x => x.ID == index).ToList();
- foreach (Agent s in A)
- {
- typename += s.AgentType.Title + " | " + s.Title;
- }
- tb.Text = typename;
- }
- private void TBSellsPerYear_Loaded(object sender, RoutedEventArgs e)
- {
- TextBlock tb = (TextBlock)sender;
- int index = Convert.ToInt32(tb.Uid);
- DateTime dtnow = DateTime.Now;
- DateTime dt = dtnow.AddYears(-1);
- List<ProductSale> PS = BaseClass.Base.ProductSale.Where(x => x.SaleDate >= dt && x.SaleDate <= dtnow&&x.AgentID==index).ToList();
- int count = 0;
- foreach(ProductSale s in PS)
- {
- count += s.ProductCount;
- }
- string countdeals = count+ " продаж(и) за год";
- tb.Text = countdeals;
- }
- List<Agent> AgentFilter;
- private void Filter()
- {
- int index = CBFilter.SelectedIndex;
- if(index!=0)
- {
- AgentFilter = BaseClass.Base.Agent.Where(x => x.AgentTypeID ==index).ToList();
- }
- else
- {
- AgentFilter = AgentStart;
- }
- if(!string.IsNullOrWhiteSpace(TBTextFilter.Text))
- {
- AgentFilter = AgentFilter.Where(x => x.Title.ToLower().Contains(TBTextFilter.Text.ToLower()) || x.Phone.ToLower().Contains(TBTextFilter.Text.ToLower())).ToList();
- }
- LVAgent.ItemsSource = AgentFilter;
- }
- private void TBTextFilter_TextChanged(object sender, TextChangedEventArgs e)
- {
- Filter();
- }
- private void TBDiscount_Loaded(object sender, RoutedEventArgs e)
- {
- TextBlock tb = (TextBlock)sender;
- int index = Convert.ToInt32(tb.Uid);
- List<ProductSale> A = BaseClass.Base.ProductSale.Where(x => x.AgentID == index).ToList();
- double total = 0;
- foreach(ProductSale s in A)
- {
- total += (double)(s.ProductCount * s.Product.MinCostForAgent);
- }
- if(total<=10000)
- {
- tb.Text = "0%";
- }
- if(total>10000&&total<=50000)
- {
- tb.Text = "5%";
- }
- if (total > 50000 && total <= 150000)
- {
- tb.Text = "10%";
- }
- if (total > 150000 && total <= 500000)
- {
- tb.Text = "20%";
- }
- if (total > 500000)
- {
- tb.Text = "25%";
- }
- }
- private void Button_Click(object sender, RoutedEventArgs e)
- {
- if(CBSort.SelectedIndex==0)
- {
- AgentFilter.Sort((x, y) => x.ID.CompareTo(y.ID));
- LVAgent.Items.Refresh();
- }
- if (CBSort.SelectedIndex == 1)
- {
- AgentFilter.Sort((x, y) => x.Title.CompareTo(y.Title));
- LVAgent.Items.Refresh();
- }
- if (CBSort.SelectedIndex == 2)
- {
- AgentFilter.Sort((x, y) => x.ID.CompareTo(y.ID));
- LVAgent.Items.Refresh();
- }
- if (CBSort.SelectedIndex == 3)
- {
- AgentFilter.Sort((x, y) => x.Priority.CompareTo(y.Priority));
- LVAgent.Items.Refresh();
- }
- }
- private void Button_Click_1(object sender, RoutedEventArgs e)
- {
- if (CBSort.SelectedIndex == 0)
- {
- AgentFilter.Sort((x, y) => x.ID.CompareTo(y.ID));
- AgentFilter.Reverse();
- LVAgent.Items.Refresh();
- }
- if (CBSort.SelectedIndex == 1)
- {
- AgentFilter.Sort((x, y) => x.Title.CompareTo(y.Title));
- AgentFilter.Reverse();
- LVAgent.Items.Refresh();
- }
- if (CBSort.SelectedIndex == 2)
- {
- AgentFilter.Sort((x, y) => x.ID.CompareTo(y.ID));
- AgentFilter.Reverse();
- LVAgent.Items.Refresh();
- }
- if (CBSort.SelectedIndex == 3)
- {
- AgentFilter.Sort((x, y) => x.Priority.CompareTo(y.Priority));
- AgentFilter.Reverse();
- LVAgent.Items.Refresh();
- }
- }
- private void CBFilter_SelectionChanged(object sender, SelectionChangedEventArgs e)
- {
- Filter();
- }
- private void btnAddNewAgent_Click(object sender, RoutedEventArgs e)
- {
- FrameClass.MainFrame.Navigate(new CreateOrUpdate());
- }
- private void btnChange_Click(object sender, RoutedEventArgs e)
- {
- Button B = (Button)sender;
- int id = Convert.ToInt32(B.Uid);
- Agent AgentUpdate = BaseClass.Base.Agent.FirstOrDefault(x => x.ID == id);
- FrameClass.MainFrame.Navigate(new CreateOrUpdate(AgentUpdate));
- }
- }
- }
|