123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238 |
- 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 Практическая__5
- {
- /// <summary>
- /// Логика взаимодействия для JewelryMain.xaml
- /// </summary>
- public partial class JewelryMain : Page
- {
- public JewelryMain()
- {
- InitializeComponent();
- init();
- }
- private void init()
- {
- JewelryList.ItemsSource = BaseConnect.kotBase.tbJewelry.ToList();
- List<tbTypeJewelry> typeJewelry = BaseConnect.kotBase.tbTypeJewelry.ToList();
- tbTypeJewelry all = new tbTypeJewelry()
- {
- idType = 0,
- nameType = "Все типы"
- };
- CBType.Items.Add(all);
- foreach (tbTypeJewelry type in typeJewelry)
- {
- CBType.Items.Add(type);
- }
- CBType.DisplayMemberPath = "nameType";
- CBType.SelectedValuePath = "idType";
- }
- private void CompositionJewelryLoaded(object sender, RoutedEventArgs e)
- {
- TextBlock tbk = (TextBlock)sender;
- int index = Convert.ToInt32(tbk.Uid);
- List<tbCompositionJewelry> list = BaseConnect.kotBase.tbCompositionJewelry.Where(tb => tb.idJewelry == index).ToList();
- if (list.Count > 0)
- {
- string value = "";
- foreach (tbCompositionJewelry a in list)
- {
- value += a.tbBatchMaterial.tbMaterial.nameMaterial + ", ";
- }
- value = value.Remove(value.Length - 2);
- tbk.Text = value;
- }
- else tbk.Text = "Состовляющие украшения неизвестны";
- }
- private void OtherPriceLoaded(object sender, RoutedEventArgs e)
- {
- TextBlock tbk = (TextBlock)sender;
- int index = Convert.ToInt32(tbk.Uid);
- List<tbCompositionJewelry> list = BaseConnect.kotBase.tbCompositionJewelry.Where(tb => tb.idJewelry == index).ToList();
- if (list.Count > 0)
- {
- double sum = 0;
- foreach (tbCompositionJewelry a in list)
- {
- tbBatchMaterial price = BaseConnect.kotBase.tbBatchMaterial.Where(tb => tb.idBatch == a.idBatch).ToList().Last();
- if (price != null)
- {
- sum += price.price * a.count;
- }
- }
- tbk.Text = "Себестоимость изделия " + sum + " тыс. руб";
- }
- }
- private void BTBackClick(object sender, RoutedEventArgs e)
- {
- FrameClass.frameMain.NavigationService.Navigate(new AdminMain());
- }
- private void BTAddClick(object sender, RoutedEventArgs e)
- {
- FrameClass.frameMain.NavigationService.Navigate(new JewelryAdd());
- }
- private void BtnDelJewelryClick(object sender, RoutedEventArgs e)
- {
- Button btn = (Button)sender;
- int index = Convert.ToInt32(btn.Uid);
- tbJewelry thisJewelry = BaseConnect.kotBase.tbJewelry.Where(tb => tb.idJewelry == index).ToList().LastOrDefault();
- MessageBoxResult result = MessageBox.Show("Вы действительно хотите Удалить это украшение?", "Удалить украшение", MessageBoxButton.YesNo, MessageBoxImage.Question);
- if (result == MessageBoxResult.Yes)
- {
- BaseConnect.kotBase.tbJewelry.Remove(thisJewelry);
- BaseConnect.kotBase.SaveChanges();
- FrameClass.frameMain.NavigationService.Navigate(new JewelryMain());
- MessageBox.Show("Украшение успешно удалено!");
- }
- }
- private void BtnEditJewelryClick(object sender, RoutedEventArgs e)
- {
- Button btn = (Button)sender;
- int index = Convert.ToInt32(btn.Uid);
- MessageBoxResult result = MessageBox.Show("Вы действительно хотите Отредактировать это украшение?", "Редактировать информацию об украшении", MessageBoxButton.YesNo, MessageBoxImage.Question);
- if (result == MessageBoxResult.Yes)
- {
- FrameClass.frameMain.NavigationService.Navigate(new JewelryAdd(index));
- }
- }
- private void BTFilterClick(object sender, RoutedEventArgs e)
- {
- if (GFilter.Visibility == Visibility.Visible)
- {
- GFilter.Visibility = Visibility.Collapsed;
- }
- else
- {
- GFilter.Visibility = Visibility.Visible;
- }
- }
- private void Filter()
- {
- List<tbJewelry> listJewelry = new List<tbJewelry>();
- //тип украшения
- tbTypeJewelry thisType = (tbTypeJewelry)CBType.SelectedItem;
- if(CBType.SelectedIndex != 0)
- {
- listJewelry = BaseConnect.kotBase.tbJewelry.Where(tb => tb.tbTypeJewelry.nameType == thisType.nameType).ToList();
- }
- else
- {
- listJewelry = BaseConnect.kotBase.tbJewelry.ToList();
- }
- //поиск по названию
- if (!string.IsNullOrWhiteSpace(TBSearchName.Text)) // если строка не пустая и если она не состоит из пробелов
- {
- listJewelry = listJewelry.Where(tb => tb.name.ToLower().Contains(TBSearchName.Text.ToLower())).ToList();
- }
- //наличие в магазине
- if (CBAvailability.IsChecked == true)
- {
- List<tbOrderItems> OrderItems = BaseConnect.kotBase.tbOrderItems.ToList();
- List<tbJewelry> newList = new List<tbJewelry>();
- foreach(tbJewelry jewelry in listJewelry)
- {
- tbOrderItems availability = OrderItems.Where(tb => tb.idJewelry == jewelry.idJewelry).FirstOrDefault();
- if (availability == null)
- {
- newList.Add(jewelry);
- }
- }
- listJewelry = newList;
- }
- //сортировка
- if(RBPriceUp.IsChecked == true)
- {
- listJewelry.Sort((tb, tb2) => tb.price.CompareTo(tb2.price));
- }
- if(RBPriceDown.IsChecked == true)
- {
- listJewelry.Sort((tb, tb2) => tb.price.CompareTo(tb2.price));
- listJewelry.Reverse();
- }
- //запись о количестве используемых материалов
- foreach(tbJewelry element in listJewelry)
- {
- List<tbCompositionJewelry> composition = BaseConnect.kotBase.tbCompositionJewelry.Where(tb => tb.idJewelry == element.idJewelry).ToList();
- if(composition != null)
- {
- element.count = composition.Count;
- }
- else
- {
- element.count = 0;
- }
- }
- if(RBCountUp.IsChecked == true)
- {
- listJewelry.Sort((tb, tb2) => tb.count.CompareTo(tb2.count));
- }
- if(RBCountDown.IsChecked == true)
- {
- listJewelry.Sort((tb, tb2) => tb.count.CompareTo(tb2.count));
- listJewelry.Reverse();
- }
- JewelryList.ItemsSource = listJewelry;
- }
- private void CountChecked(object sender, RoutedEventArgs e)
- {
- Filter();
- }
- private void PriceChecked(object sender, RoutedEventArgs e)
- {
- Filter();
- }
- private void AvailabilityChecked(object sender, RoutedEventArgs e)
- {
- Filter();
- }
- private void AvailabilityUnchecked(object sender, RoutedEventArgs e)
- {
- Filter();
- }
- private void CBTypeSelectionChanged(object sender, SelectionChangedEventArgs e)
- {
- Filter();
- }
- private void TBSearchNameTextChanged(object sender, TextChangedEventArgs e)
- {
- Filter();
- }
- }
- }
|