|
@@ -1,6 +1,7 @@
|
|
|
using PPPISI52.Windows;
|
|
|
using System;
|
|
|
using System.Collections.Generic;
|
|
|
+using System.Data.Entity.Core.Common.CommandTrees.ExpressionBuilder;
|
|
|
using System.Linq;
|
|
|
using System.Text;
|
|
|
using System.Threading.Tasks;
|
|
@@ -25,7 +26,8 @@ namespace PPPISI52.Pages
|
|
|
User current_user;
|
|
|
int all_items;
|
|
|
int showed_items;
|
|
|
- List<string> discount_d = new List<string>() { "Все диапозоны", "0-9,99%", "10-14,99%", "15% и более" };
|
|
|
+
|
|
|
+
|
|
|
public MainUserPage()
|
|
|
{
|
|
|
InitializeComponent();
|
|
@@ -35,74 +37,69 @@ namespace PPPISI52.Pages
|
|
|
public MainUserPage(User user)
|
|
|
{
|
|
|
InitializeComponent();
|
|
|
+ PP_PISIEntities DB = new PP_PISIEntities();
|
|
|
+ LVProducts.ItemsSource = DB.Product.ToList();
|
|
|
+
|
|
|
current_user = user;
|
|
|
DefaultData();
|
|
|
- TBUser.Text = user.UserName + " " + user.UserSurname + user.UserPatronymic;
|
|
|
+
|
|
|
List<Order> orders = Base.MyBase.Order.Where(x => x.UserID == user.UserID).ToList();
|
|
|
if (orders.Count > 0)
|
|
|
{
|
|
|
- BOrders.Visibility = Visibility.Visible;
|
|
|
+ BAddProduct.Visibility = Visibility.Visible;
|
|
|
}
|
|
|
- if (current_user.UserRole == 2)
|
|
|
+
|
|
|
+ List<ProductCategory> rl = DB.ProductCategory.ToList();
|
|
|
+ CBDiscount.Items.Add("Все отделы");
|
|
|
+ foreach (ProductCategory i in rl)
|
|
|
{
|
|
|
- BAddProduct.Visibility = Visibility.Visible;
|
|
|
+ CBDiscount.Items.Add(i.CategoryTitle);
|
|
|
+ }
|
|
|
+ CBDiscount.SelectedIndex = 0;
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ public void Filter()
|
|
|
+ {
|
|
|
+ PP_PISIEntities DB = new PP_PISIEntities();
|
|
|
+ List<Product> prFilter = new List<Product>();
|
|
|
+ List<ProductCategory> rl = DB.ProductCategory.ToList();
|
|
|
+ if (CBDiscount.SelectedIndex != 0)
|
|
|
+ {
|
|
|
+ List<ProductCategory> aut = DB.ProductCategory.ToList();
|
|
|
+ int index = Convert.ToInt32(aut.Where(x => x.CategoryID == CBDiscount.SelectedIndex).Select(x => x.CategoryID).FirstOrDefault());
|
|
|
+ prFilter = DB.Product.Where(x => x.ProductCategory == index).ToList();
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ prFilter = DB.Product.ToList();
|
|
|
}
|
|
|
+
|
|
|
+
|
|
|
+ LVProducts.ItemsSource = prFilter;
|
|
|
}
|
|
|
|
|
|
private void DefaultData()
|
|
|
{
|
|
|
products = Base.MyBase.Product.ToList();
|
|
|
LVProducts.ItemsSource = products;
|
|
|
- CBDiscount.ItemsSource = discount_d;
|
|
|
+
|
|
|
CBDiscount.SelectedIndex = 0;
|
|
|
- RBUsial.IsChecked = true;
|
|
|
+
|
|
|
all_items = products.Count;
|
|
|
showed_items = products.Count;
|
|
|
TBItems.Text = showed_items + "/" + all_items;
|
|
|
- BOrders.Visibility = Visibility.Collapsed;
|
|
|
+
|
|
|
TBSearch.Text = "";
|
|
|
}
|
|
|
|
|
|
- private void Border_Loaded(object sender, RoutedEventArgs e)
|
|
|
- {
|
|
|
- Border border = (Border)sender;
|
|
|
- Product product = Base.MyBase.Product.FirstOrDefault(x => x.ProductArticleNumber == border.Uid);
|
|
|
- if (product.ProductDiscountAmount > 15)
|
|
|
- {
|
|
|
- border.BorderBrush = (Brush)(new BrushConverter().ConvertFrom("#7fff00"));
|
|
|
- }
|
|
|
- }
|
|
|
+
|
|
|
|
|
|
- private void ProductCost_Loaded(object sender, RoutedEventArgs e)
|
|
|
- {
|
|
|
- TextBlock textBlock = (TextBlock)sender;
|
|
|
- Product product = Base.MyBase.Product.FirstOrDefault(x => x.ProductArticleNumber == textBlock.Uid);
|
|
|
- textBlock.Text = product.ProductCost.ToString().Substring(0, product.ProductCost.ToString().Length - 2);
|
|
|
- if (product.ProductDiscountAmount > 0)
|
|
|
- {
|
|
|
- textBlock.TextDecorations = TextDecorations.Strikethrough;
|
|
|
- }
|
|
|
- }
|
|
|
+
|
|
|
|
|
|
- private void ProductCost2_Loaded(object sender, RoutedEventArgs e)
|
|
|
- {
|
|
|
- TextBlock textBlock = (TextBlock)sender;
|
|
|
- Product product = Base.MyBase.Product.FirstOrDefault(x => x.ProductArticleNumber == textBlock.Uid);
|
|
|
- if (product.ProductDiscountAmount > 0)
|
|
|
- {
|
|
|
- textBlock.Text = (product.ProductCost - product.ProductCost * product.ProductDiscountAmount / 100).ToString().Substring(0, (product.ProductCost - product.ProductCost * product.ProductDiscountAmount / 100).ToString().Length - 2);
|
|
|
- }
|
|
|
- }
|
|
|
+
|
|
|
|
|
|
- private void ProductCost3_Loaded(object sender, RoutedEventArgs e)
|
|
|
- {
|
|
|
- TextBlock textBlock = (TextBlock)sender;
|
|
|
- Product product = Base.MyBase.Product.FirstOrDefault(x => x.ProductArticleNumber == textBlock.Uid);
|
|
|
- if (product.ProductDiscountAmount > 0)
|
|
|
- {
|
|
|
- textBlock.Text = "Скидка: " + product.ProductDiscountAmount.ToString() + "%";
|
|
|
- }
|
|
|
- }
|
|
|
+
|
|
|
|
|
|
private void Sort()
|
|
|
{
|
|
@@ -121,24 +118,9 @@ namespace PPPISI52.Pages
|
|
|
default: break;
|
|
|
}
|
|
|
|
|
|
- if (RBUP.IsChecked == true)
|
|
|
- {
|
|
|
- products = products.OrderBy(x => x.ProductCost).ToList();
|
|
|
- }
|
|
|
- if (RBDown.IsChecked == true)
|
|
|
- {
|
|
|
- products = products.OrderBy(x => x.ProductCost).ToList();
|
|
|
- products.Reverse();
|
|
|
- }
|
|
|
+
|
|
|
|
|
|
- if (RBDrop.IsChecked == true)
|
|
|
- {
|
|
|
- RBDrop.IsChecked = false;
|
|
|
- RBUsial.IsChecked = true;
|
|
|
- TBSearch.Text = string.Empty;
|
|
|
- CBDiscount.SelectedIndex = 0;
|
|
|
- products = Base.MyBase.Product.ToList();
|
|
|
- }
|
|
|
+
|
|
|
|
|
|
showed_items = products.Count();
|
|
|
TBItems.Text = showed_items + "/" + all_items;
|
|
@@ -146,6 +128,8 @@ namespace PPPISI52.Pages
|
|
|
LVProducts.ItemsSource = products;
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+
|
|
|
private void Search_TextChanged(object sender, TextChangedEventArgs e)
|
|
|
{
|
|
|
Sort();
|
|
@@ -160,13 +144,13 @@ namespace PPPISI52.Pages
|
|
|
{
|
|
|
Sort();
|
|
|
}
|
|
|
-
|
|
|
- private void ShowOrders_Click(object sender, RoutedEventArgs e)
|
|
|
+ private void CBFilterBreed_SelectionChanged(object sender, SelectionChangedEventArgs e)
|
|
|
{
|
|
|
- OrdersWindow ordersWindow = new OrdersWindow(current_user);
|
|
|
- ordersWindow.ShowDialog();
|
|
|
+ Filter();
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+
|
|
|
private void ContextMenu_Loaded(object sender, RoutedEventArgs e)
|
|
|
{
|
|
|
ContextMenu cm = (ContextMenu)sender;
|
|
@@ -176,13 +160,13 @@ namespace PPPISI52.Pages
|
|
|
private void EditProduct_Loaded(object sender, RoutedEventArgs e)
|
|
|
{
|
|
|
MenuItem menuItem = (MenuItem)sender;
|
|
|
- if (current_user == null || current_user.UserRole != 2) menuItem.Visibility = Visibility.Collapsed;
|
|
|
+ if (current_user == null );
|
|
|
}
|
|
|
|
|
|
private void DeleteProduct_Loaded(object sender, RoutedEventArgs e)
|
|
|
{
|
|
|
MenuItem menuItem = (MenuItem)sender;
|
|
|
- if (current_user == null || current_user.UserRole != 2) menuItem.Visibility = Visibility.Collapsed;
|
|
|
+ if (current_user == null );
|
|
|
}
|
|
|
|
|
|
private void EditProduct_Click(object sender, RoutedEventArgs e)
|
|
@@ -243,7 +227,7 @@ namespace PPPISI52.Pages
|
|
|
op.ProductCount = 1;
|
|
|
Base.MyBase.OrderProduct.Add(op);
|
|
|
Base.MyBase.SaveChanges();
|
|
|
- BOrders.Visibility = Visibility.Visible;
|
|
|
+
|
|
|
}
|
|
|
}
|
|
|
catch { }
|