123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240 |
- using System.ComponentModel;
- using System.Diagnostics;
- using System.Windows;
- using System.Windows.Controls;
- using System.Windows.Input;
- using WpfApp2.model;
- using CsvHelper;
- namespace WpfApp2
- {
- /// <summary>
- /// Interaction logic for MainWindow.xaml
- /// </summary>
- public partial class MainWindow : Window, INotifyPropertyChanged
- {
- public event PropertyChangedEventHandler PropertyChanged;
- private void Invalidate()
- {
- if (PropertyChanged != null)
- PropertyChanged(this, new PropertyChangedEventArgs("SparesList"));
- }
- public string selectedDetail = "Деталь";
- public SparesPrice? selectedPrice = null;
- public string selectedType = "Тип ТС";
-
-
- private IEnumerable<Spares> _SparesList;
- public IEnumerable<Spares> SparesList
- {
- get
- {
- var res = _SparesList;
- res = res
-
- .Where(c => (c.detail == selectedDetail || selectedDetail == "Деталь"))
- .Where(c => (selectedPrice == null || (c.price >= selectedPrice.PriceFrom && c.price < selectedPrice.PriceTo)))
- .Where(c => (c.type == selectedType || selectedType == "Тип ТС"));
- if (searchFilter != "")
- res = res.Where(c => c.name.IndexOf(
- searchFilter,
- StringComparison.OrdinalIgnoreCase) >= 0);
- if (sortAsc) res = res.OrderBy(c => c.price);
- else res = res.OrderByDescending(c => c.price);
- return res;
- }
- set
- {
- _SparesList = value;
- }
- }
-
- public List<SparesDetail> SparesDetailList { get; set; }
- public List<SparesPrice> SparesPriceList { get; set; }
- public List<SparesType> SparesTypeList { get; set; }
- public MainWindow()
- {
- InitializeComponent();
- DataContext = this;
- Globals.dataProvider = new LocalDataProvider();
- SparesList = Globals.dataProvider.getSpares();
- SparesDetailList = Globals.dataProvider.getDetail().ToList();
- SparesDetailList.Insert(0, new SparesDetail { title = "Деталь" });
- SparesPriceList = Globals.dataProvider.getPrice().ToList();
- SparesTypeList = Globals.dataProvider.getType().ToList();
- SparesTypeList.Insert(0, new SparesType { title = "Тип ТС" });
- Globals.dataProvider = new CSVDataProvider();
- SparesList = Globals.dataProvider.getSpares();
- }
- private bool sortAsc = true;
- private void RadioButton_Checked(object sender, RoutedEventArgs e)
- {
- sortAsc = (sender as RadioButton).Tag.ToString() == "1";
- Invalidate();
- }
- private void ExitButton_Click(object sender, RoutedEventArgs e)
- {
- Application.Current.Shutdown();
- }
- private void DetailFilterComboBox_SelectionChanged_1(object sender, System.Windows.Controls.SelectionChangedEventArgs e)
- {
- selectedDetail = (DetailFilterComboBox.SelectedItem as SparesDetail).title;
- Invalidate();
- }
- private void PriceFilterComboBox_SelectionChanged_2(object sender, System.Windows.Controls.SelectionChangedEventArgs e)
- {
- selectedPrice = PriceFilterComboBox.SelectedItem as SparesPrice;
- Invalidate();
- }
- private void TypeFilterComboBox_SelectionChanged_3(object sender, System.Windows.Controls.SelectionChangedEventArgs e)
- {
- selectedType = (TypeFilterComboBox.SelectedItem as SparesType).title;
- Invalidate();
- }
- private string searchFilter = "";
- private void SearchFilter_KeyUp(object sender, KeyEventArgs e)
- {
- searchFilter = SearchFilterTextBox.Text;
- Invalidate();
- }
- }
-
- interface IDataProvider
- {
- IEnumerable<Spares> getSpares();
- IEnumerable<SparesDetail> getDetail();
- IEnumerable<SparesPrice> getPrice();
- IEnumerable<SparesType> getType();
- }
- public class LocalDataProvider : IDataProvider
- {
- public IEnumerable<SparesDetail> getDetail()
- {
- return new SparesDetail[]
- {
- new SparesDetail()
- {
- title="Двигатель"
- },
- new SparesDetail()
- {
- title="КПП"
- },
- new SparesDetail()
- {
- title="Подвеска"
- },
- new SparesDetail()
- {
- title="Стекла"
- },
- new SparesDetail()
- {
- title="Колеса"
- },
- };
- }
- public IEnumerable<SparesPrice> getPrice()
- {
- return new SparesPrice[]
- {
- new SparesPrice()
- {
- title="Все цены",
- PriceFrom=0,
- PriceTo=99999999
- },
- new SparesPrice()
- {
- title="БУ",
- PriceFrom=0,
- PriceTo=10000
- },
- new SparesPrice()
- {
- title="Дешевая",
- PriceFrom=10000,
- PriceTo=20000
- },
- new SparesPrice()
- {
- title="Средняя",
- PriceFrom=20000,
- PriceTo=50000
- },
- new SparesPrice()
- {
- title="Элитная",
- PriceFrom=50000,
- PriceTo=99999999
- }
- };
- }
- public IEnumerable<SparesType> getType()
- {
- return new SparesType[]
- {
- new SparesType()
- {
- title="Легкая"
- },
- new SparesType()
- {
- title="Грузовая"
- },
- };
- }
- public IEnumerable<Spares> getSpares()
- {
- return new Spares[]{
- new Spares{
- type="Легкая",
- name="Двигатель МБ140(ОК2281.4)",
- price = 72000,
- detail="Двигатель"},
- new Spares{
- type="Легкая",
- name="КПП 5-СТ РС-ПДР",
- price = 20000,
- detail="КПП"},
- new Spares{
- type="Грузовая",
- name="Подвеска ПДРС1337",
- price = 15000,
- detail="Подвеска"},
- new Spares{
- type="Легкая",
- name="Шина 15-Р",
- price = 3000,
- detail="Колеса"},
- new Spares{
- type="Грузовая",
- name="Лобовое стекло СТ150",
- price = 40000,
- detail="Стекла"},
- };
- }
- }
-
- }
|