ListMaterial.xaml.cs 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Security.Cryptography;
  5. using System.Text;
  6. using System.Threading.Tasks;
  7. using System.Windows;
  8. using System.Windows.Controls;
  9. using System.Windows.Data;
  10. using System.Windows.Documents;
  11. using System.Windows.Input;
  12. using System.Windows.Media;
  13. using System.Windows.Media.Imaging;
  14. using System.Windows.Navigation;
  15. using System.Windows.Shapes;
  16. namespace WpfApp1
  17. {
  18. /// <summary>
  19. /// Логика взаимодействия для ListMaterial.xaml
  20. /// </summary>
  21. public partial class ListMaterial : Page
  22. {
  23. public ListMaterial()
  24. {
  25. InitializeComponent();
  26. lvMaterials.ItemsSource = Base.BD.Material.ToList();
  27. List<MaterialType> materialTypes = Base.BD.MaterialType.ToList();
  28. cbFilter.Items.Add("Все типы");
  29. foreach(MaterialType materialType in materialTypes)
  30. {
  31. cbFilter.Items.Add(materialType.Title);
  32. }
  33. cbFilter.SelectedIndex = 0;
  34. cbSort.SelectedIndex = 0;
  35. CountRecords.Text = Base.BD.Material.ToList().Count + " из " + Base.BD.Material.ToList().Count;
  36. }
  37. private void Filter()
  38. {
  39. List<Material> materials = Base.BD.Material.ToList();
  40. if (tbSearch.Text != "")
  41. {
  42. materials = materials.Where(x => x.Title.ToLower().Contains(tbSearch.Text.ToLower())).ToList();
  43. List<Material> materials1 = Base.BD.Material.Where(x => x.Description.ToLower().Contains(tbSearch.Text.ToLower())).ToList();
  44. foreach (Material material in materials1)
  45. {
  46. materials.Add(material);
  47. }
  48. materials = materials.Distinct().ToList();
  49. }
  50. if(cbFilter.SelectedIndex != 0 && cbFilter.SelectedIndex != 0)
  51. {
  52. materials = materials.Where(x => x.MaterialType.Title == cbFilter.SelectedValue).ToList();
  53. }
  54. switch(cbSort.SelectedIndex)
  55. {
  56. case 1:
  57. materials = materials.OrderBy(x => x.Title).ToList();
  58. break;
  59. case 2:
  60. materials = materials.OrderByDescending(x => x.Title).ToList();
  61. break;
  62. case 3:
  63. materials = materials.OrderBy(x => x.CountinStock).ToList();
  64. break;
  65. case 4:
  66. materials = materials.OrderByDescending(x => x.CountinStock).ToList();
  67. break;
  68. case 5:
  69. materials = materials.OrderBy(x => x.Cost).ToList();
  70. break;
  71. case 6:
  72. materials = materials.OrderByDescending(x => x.Cost).ToList();
  73. break;
  74. }
  75. lvMaterials.ItemsSource = materials;
  76. if(materials.Count == 0)
  77. {
  78. MessageBox.Show("Результат не найден");
  79. }
  80. CountRecords.Text = materials.Count + " из " + Base.BD.Material.ToList().Count;
  81. }
  82. private void tbSearch_SelectionChanged(object sender, RoutedEventArgs e)
  83. {
  84. Filter();
  85. }
  86. private void cbSort_SelectionChanged(object sender, SelectionChangedEventArgs e)
  87. {
  88. Filter();
  89. }
  90. private void lvMaterials_PreviewMouseUp(object sender, MouseButtonEventArgs e)
  91. {
  92. if (lvMaterials.SelectedItems.Count > 1)
  93. {
  94. changeMinCost.Visibility = Visibility.Visible;
  95. }
  96. else
  97. {
  98. changeMinCost.Visibility = Visibility.Hidden;
  99. }
  100. }
  101. private void changeMinCost_Click(object sender, RoutedEventArgs e)
  102. {
  103. List<Material> materials = new List<Material>();
  104. foreach(Material material in lvMaterials.SelectedItems)
  105. {
  106. materials.Add(material);
  107. }
  108. ChangeMinCount changeMinCount = new ChangeMinCount(materials);
  109. changeMinCount.ShowDialog();
  110. lvMaterials.ItemsSource = Base.BD.Material.ToList();
  111. changeMinCost.Visibility = Visibility.Hidden;
  112. }
  113. }
  114. }