123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183 |
- using System.ComponentModel;
- using System.Security.Cryptography.X509Certificates;
- using System.Text;
- 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;
- using Dapper;
- using MySqlConnector;
- namespace wpf_connection3
- {
- public partial class MainWindow : Window,
- INotifyPropertyChanged
- {
- private int _currentPage = 1;
- public int currentPage
- {
- get
- {
- return _currentPage;
- }
- set
- {
- _currentPage = value;
- Invalidate();
- }
- }
- public List<string> pageList { get; set; } = new List<string>();
- private int productCount;
- public IEnumerable<Product> productList
- {
- get
- {
- switch (sortType)
- {
- case 0:
- Globals.dataProvider.setOrder("");
- break;
- case 1:
- Globals.dataProvider.setOrder("Title");
- break;
- case 2:
- Globals.dataProvider.setOrder("Title DESC");
- break;
- case 3:
- Globals.dataProvider.setOrder("ProductionWorkshopNumber");
- break;
- case 4:
- Globals.dataProvider.setOrder("ProductionWorkshopNumber DESC");
- break;
- case 5:
- Globals.dataProvider.setOrder("MaterialCost");
- break;
- case 6:
- Globals.dataProvider.setOrder("MaterialCost DESC");
- break;
- }
- Globals.dataProvider.clearFilter();
- if (productTypeFilterId > 0)
- Globals.dataProvider.addFilter(
- "ProductTypeID = @ProductTypeID",
- new { ProductTypeID = productTypeFilterId }
- );
- if (searchFilter.Length > 0)
- {
- Globals.dataProvider.addFilter(
- //"(Title LIKE @search OR Description LIKE @search)",
- "(Title LIKE @search)",
- new { search = $"%{searchFilter}%" }
- );
- }
- var result = Globals.dataProvider.getProduct(currentPage);
- productCount = Globals.dataProvider.getProductCount();
- pageList.Clear();
- pageList.Add("<");
- for (int i = 1; i < (productCount / Globals.PAGE_LEN) + 1; i++)
- {
- pageList.Add(i.ToString());
- }
- pageList.Add(">");
- // PageListListBox.ItemsSource = pageList;
- Invalidate("pageList");
- return result;
- }
- }
- private void ExitButton_Click(object sender, RoutedEventArgs e)
- {
- Application.Current.Shutdown();
- }
- public MainWindow()
- {
- InitializeComponent();
- DataContext = this;
- Globals.dataProvider = new DBDataProvider();
- productTypeList = Globals.dataProvider.getProductTypes().ToList();
- productTypeList.Insert(0, new ProductType { Title = "Все типы продукции" });
- }
- public event PropertyChangedEventHandler? PropertyChanged;
- private void Invalidate(string propertyName = "productList")
- {
- if (PropertyChanged != null)
- PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
- }
- private void TextBlock_PreviewMouseDown(object sender, MouseButtonEventArgs e)
- {
- switch ((sender as TextBlock).Text)
- {
- case "<":
- if (currentPage > 1) currentPage--;
- return;
- case ">":
- if (currentPage < productCount / Globals.PAGE_LEN) currentPage++;
- return;
- default:
- currentPage = Convert.ToInt32(
- (sender as TextBlock).Text);
- return;
- }
- }
- public string[] sortList { get; set; } =
- {
- "Без сортировки",
- "название по убыванию",
- "название по возрастанию",
- "номер цеха по убыванию",
- "номер цеха по возрастанию",
- "цена по убыванию",
- "цена по возрастанию"
- };
- private int sortType = 0;
- private void SortTypeComboBox_SelectionChanged(
- object? sender,
- SelectionChangedEventArgs e)
- {
- if (SortTypeComboBox != null)
- {
- sortType = SortTypeComboBox.SelectedIndex;
- Invalidate();
- }
- }
- public List<ProductType> productTypeList { get; set; }
- private int productTypeFilterId = 0;
- private void ProductTypeFilter_SelectionChanged(object sender, SelectionChangedEventArgs e)
- {
- // запоминаем ID выбранного типа
- productTypeFilterId = (ProductTypeFilter.SelectedItem as ProductType).ID;
- Invalidate();
- }
- private string searchFilter = "";
- private void searchFilterTextBox_KeyUp(object sender, KeyEventArgs e)
- {
- if (searchFilterTextBox.Text != null && searchFilterTextBox.Text != "")
- {
- searchFilter = searchFilterTextBox.Text;
- Invalidate();
- }
- }
- }
- }
|