|
@@ -20,9 +20,129 @@ namespace WriteErase.Pages
|
|
|
/// </summary>
|
|
|
public partial class Guest : Page
|
|
|
{
|
|
|
+
|
|
|
+ TradeEntities DB = new TradeEntities();
|
|
|
+
|
|
|
public Guest()
|
|
|
{
|
|
|
InitializeComponent();
|
|
|
+ ProductList.ItemsSource = DB.Product.ToList();
|
|
|
+ FilterByPromo.ItemsSource = new List<string>() { "Все", "Скаидка 0-9,99%", "Скидка 10-14,99%", "Скидка 15% и более" };
|
|
|
+ SortByName.ItemsSource = new List<string>() { "Без сортировки", "По имени А-Я", "По имени Я-А" };
|
|
|
+ SortByName.SelectedIndex = 0;
|
|
|
+ FilterByPromo.SelectedIndex = 0;
|
|
|
+ }
|
|
|
+
|
|
|
+ public Guest(int id)
|
|
|
+ {
|
|
|
+ InitializeComponent();
|
|
|
+ ProductList.ItemsSource = DB.Product.ToList();
|
|
|
+ User user = DB.User.Where(x => x.UserID == id).FirstOrDefault();
|
|
|
+ if (user.UserRole == 1)
|
|
|
+ {
|
|
|
+ ButtonsForAdmin.Visibility = Visibility.Visible;
|
|
|
+ }
|
|
|
+ FilterByPromo.ItemsSource = new List<string>() { "Все", "Скидка 0-9,99%", "Скидка 10-14,99%", "Скидка 15% и более" };
|
|
|
+ SortByName.ItemsSource = new List<string>() { "Без сортировки", "По имени А-Я", "По имени Я-А" };
|
|
|
+ SortByName.SelectedIndex = 0;
|
|
|
+ FilterByPromo.SelectedIndex = 0;
|
|
|
+ }
|
|
|
+
|
|
|
+ public void BackgroundLoad(object sender, RoutedEventArgs e)
|
|
|
+ {
|
|
|
+ Grid bgr = (Grid)sender;
|
|
|
+ string Article = bgr.Uid.ToString();
|
|
|
+ Product pr = DB.Product.Where(x => x.ProductArticleNumber == Article).FirstOrDefault();
|
|
|
+ if (pr.ProductMaxDiscountAmount > 15)
|
|
|
+ {
|
|
|
+ bgr.Background = (SolidColorBrush)new BrushConverter().ConvertFrom("#76e383");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ public void StrikePrice(object sender, RoutedEventArgs e)
|
|
|
+ {
|
|
|
+ TextBlock tb = (TextBlock)sender;
|
|
|
+ string Article = tb.Uid.ToString();
|
|
|
+ Product pr = DB.Product.Where(x => x.ProductArticleNumber == Article).FirstOrDefault();
|
|
|
+ tb.Text = "Цена: " + string.Format("{0:C2}", pr.ProductCost);
|
|
|
+ if (pr.ProductMaxDiscountAmount > 0)
|
|
|
+ {
|
|
|
+ tb.TextDecorations = TextDecorations.Strikethrough;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ public void PromoPrice(object sender, RoutedEventArgs e)
|
|
|
+ {
|
|
|
+ TextBlock tb = (TextBlock)sender;
|
|
|
+ string Article = tb.Uid.ToString();
|
|
|
+ Product pr = DB.Product.Where(x => x.ProductArticleNumber == Article).FirstOrDefault();
|
|
|
+ if (pr.ProductMaxDiscountAmount > 0)
|
|
|
+ {
|
|
|
+ tb.Text = "Цена: " + string.Format("{0:C2}", (pr.ProductCost - (pr.ProductCost / 100 * pr.ProductMaxDiscountAmount)));
|
|
|
+ tb.FontWeight = FontWeights.Bold;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private void Photo(object sender, RoutedEventArgs e)
|
|
|
+ {
|
|
|
+ Image pic = (Image)sender;
|
|
|
+ string Article = pic.Uid.ToString();
|
|
|
+ string photoPath = DB.Product.Where(x => x.ProductArticleNumber == Article).Select(x => x.ProductPhoto).FirstOrDefault();
|
|
|
+ if (photoPath != null && photoPath != "")
|
|
|
+ {
|
|
|
+ pic.Source = new BitmapImage(new Uri(Environment.CurrentDirectory + "\\Picture\\" + photoPath, UriKind.RelativeOrAbsolute));
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ pic.Source = new BitmapImage(new Uri(Environment.CurrentDirectory + "\\Picture\\picture.png", UriKind.RelativeOrAbsolute));
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private void Filter()
|
|
|
+ {
|
|
|
+ List<Product> products = DB.Product.ToList();
|
|
|
+ if (SortByName.SelectedIndex != 0)
|
|
|
+ {
|
|
|
+ switch (SortByName.SelectedIndex)
|
|
|
+ {
|
|
|
+ case 1:
|
|
|
+ products = products.OrderBy(x => x.ProductName).ToList();
|
|
|
+ break;
|
|
|
+ case 2:
|
|
|
+ products = products.OrderByDescending(x => x.ProductName).ToList();
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (FilterByPromo.SelectedIndex != 0)
|
|
|
+ {
|
|
|
+ switch (FilterByPromo.SelectedIndex)
|
|
|
+ {
|
|
|
+ case 1:
|
|
|
+ products = products.Where(x => x.ProductMaxDiscountAmount >= 0 && x.ProductMaxDiscountAmount < 10).ToList();
|
|
|
+ break;
|
|
|
+ case 2:
|
|
|
+ products = products.Where(x => x.ProductMaxDiscountAmount >= 10 && x.ProductMaxDiscountAmount < 15).ToList();
|
|
|
+ break;
|
|
|
+ case 3:
|
|
|
+ products = products.Where(x => x.ProductMaxDiscountAmount >= 15).ToList();
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (!string.IsNullOrEmpty(SearchByName.Text))
|
|
|
+ {
|
|
|
+ products = products.Where(x => x.ProductName.ToUpper().Contains(SearchByName.Text.ToUpper())).ToList();
|
|
|
+ }
|
|
|
+ ProductList.ItemsSource = products;
|
|
|
+ }
|
|
|
+
|
|
|
+ private void SortFilterChanged(object sender, SelectionChangedEventArgs e)
|
|
|
+ {
|
|
|
+ Filter();
|
|
|
+ }
|
|
|
+
|
|
|
+ private void SearchChanged(object sender, TextChangedEventArgs e)
|
|
|
+ {
|
|
|
+ Filter();
|
|
|
}
|
|
|
}
|
|
|
}
|