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
{
///
/// Логика взаимодействия для ShowAgentPage.xaml
///
public partial class ShowAgentPage : Page
{
List AgentStart = BaseClass.Base.Agent.ToList();
public ShowAgentPage()
{
InitializeComponent();
LVAgent.ItemsSource = BaseClass.Base.Agent.ToList();
CBFilter.Items.Add("Все типы");
List 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 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 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 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 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));
}
}
}