MainPage.xaml.cs 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228
  1. using Namordnik.Class;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Linq;
  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 Namordnik.Pages
  17. {
  18. /// <summary>
  19. /// Логика взаимодействия для MainPage.xaml
  20. /// </summary>
  21. public partial class MainPage : Page
  22. {
  23. List<Product> ProductStart = BaseClass.Base.Product.ToList();
  24. PaginationClass pg = new PaginationClass();
  25. List<Product> PRFilter;
  26. public MainPage()
  27. {
  28. InitializeComponent();
  29. LVProdMat.ItemsSource = ProductStart;
  30. PRFilter = ProductStart;
  31. CBSort.Items.Add("Наименование");
  32. CBSort.Items.Add("Номер цеха");
  33. CBSort.Items.Add("Мин стоимость");
  34. List<ProductType> PT = BaseClass.Base.ProductType.ToList();
  35. CBFilter.Items.Add("Все записи");
  36. for (int i = 0; i < PT.Count; i++)
  37. {
  38. CBFilter.Items.Add(PT[i].Title);
  39. }
  40. CBFilter.SelectedIndex = 0;
  41. DataContext = pg;
  42. pg.CountPage = 15;
  43. pg.Countlist = PRFilter.Count;
  44. LVProdMat.ItemsSource = PRFilter.Skip(0).Take(pg.CountPage).ToList();
  45. }
  46. private void TextBlock_Loaded(object sender, RoutedEventArgs e)
  47. {
  48. TextBlock tb = (TextBlock)sender;
  49. int index = Convert.ToInt32(tb.Uid);
  50. List<ProductMaterial> TC = BaseClass.Base.ProductMaterial.Where(x => x.ProductID == index).ToList();
  51. string str = "Материалы: ";
  52. foreach (ProductMaterial item in TC)
  53. {
  54. str += item.Material.Title + ", ";
  55. }
  56. if (str == "Материалы: ")
  57. {
  58. tb.Text = str.Substring(0) + "-";
  59. }
  60. else
  61. {
  62. tb.Text = str.Substring(0, str.Length - 2);
  63. }
  64. }
  65. private void TextBlock_Loaded_1(object sender, RoutedEventArgs e)
  66. {
  67. TextBlock tb = (TextBlock)sender;
  68. int index = Convert.ToInt32(tb.Uid);
  69. List<ProductMaterial> PT = BaseClass.Base.ProductMaterial.Where(x => x.ProductID == index).ToList();
  70. int cost = 0;
  71. foreach (ProductMaterial item in PT)
  72. {
  73. cost += (int)item.Material.Cost;
  74. }
  75. tb.Text = cost + " руб.";
  76. }
  77. private void Filter()
  78. {
  79. PRFilter = ProductStart;
  80. int index = CBFilter.SelectedIndex;
  81. if (index != 0)
  82. {
  83. PRFilter = ProductStart.Where(x => x.ProductTypeID == index).ToList();
  84. }
  85. else
  86. {
  87. PRFilter = ProductStart;
  88. }
  89. if (!string.IsNullOrWhiteSpace(TBFilter.Text))
  90. {
  91. PRFilter = PRFilter.Where(x => x.Title.ToLower().Contains(TBFilter.Text)).ToList();
  92. }
  93. LVProdMat.ItemsSource = PRFilter;
  94. }
  95. private void TBFilter_TextChanged(object sender, TextChangedEventArgs e)
  96. {
  97. Filter();
  98. }
  99. private void CBFilter_SelectionChanged(object sender, SelectionChangedEventArgs e)
  100. {
  101. Filter();
  102. }
  103. private void BtnSortUp_Click(object sender, RoutedEventArgs e)
  104. {
  105. if (CBSort.SelectedIndex == 0)
  106. {
  107. PRFilter.Sort((x, y) => x.Title.CompareTo(y.Title));
  108. LVProdMat.Items.Refresh();
  109. }
  110. if (CBSort.SelectedIndex == 1)
  111. {
  112. PRFilter.Sort((x, y) => x.ProductionWorkshopNumber.CompareTo(y.ProductionWorkshopNumber));
  113. LVProdMat.Items.Refresh();
  114. }
  115. if (CBSort.SelectedIndex == 2)
  116. {
  117. PRFilter.Sort((x, y) => x.MinCostForAgent.CompareTo(y.MinCostForAgent));
  118. LVProdMat.Items.Refresh();
  119. }
  120. }
  121. private void BtnSortDown_Click(object sender, RoutedEventArgs e)
  122. {
  123. if (CBSort.SelectedIndex == 0)
  124. {
  125. PRFilter.Sort((x, y) => x.Title.CompareTo(y.Title));
  126. PRFilter.Reverse();
  127. LVProdMat.Items.Refresh();
  128. }
  129. if (CBSort.SelectedIndex == 1)
  130. {
  131. PRFilter.Sort((x, y) => x.ProductionWorkshopNumber.CompareTo(y.ProductionWorkshopNumber));
  132. PRFilter.Reverse();
  133. LVProdMat.Items.Refresh();
  134. }
  135. if (CBSort.SelectedIndex == 2)
  136. {
  137. PRFilter.Sort((x, y) => x.MinCostForAgent.CompareTo(y.MinCostForAgent));
  138. PRFilter.Reverse();
  139. LVProdMat.Items.Refresh();
  140. }
  141. }
  142. private void LVProdMat_SelectionChanged(object sender, SelectionChangedEventArgs e)
  143. {
  144. if (LVProdMat.SelectedIndex != -1)
  145. {
  146. Changed.Visibility = Visibility.Visible;
  147. WRDoc.Visibility = Visibility.Collapsed;
  148. }
  149. else
  150. {
  151. Changed.Visibility = Visibility.Collapsed;
  152. WRDoc.Visibility = Visibility.Visible;
  153. }
  154. }
  155. private void Changed_Click(object sender, RoutedEventArgs e)
  156. {
  157. var list = LVProdMat.SelectedItems;
  158. int sum = 0;
  159. foreach (Product PR in list)
  160. {
  161. sum += (int)PR.MinCostForAgent;
  162. }
  163. sum = sum / LVProdMat.SelectedItems.Count;
  164. ChangedWindow changedWindow = new ChangedWindow(sum);
  165. changedWindow.ShowDialog();
  166. foreach (Product PR in list)
  167. {
  168. PR.MinCostForAgent += changedWindow.srcost;
  169. }
  170. LVProdMat.Items.Refresh();
  171. }
  172. private void BtnAdd_Click(object sender, RoutedEventArgs e)
  173. {
  174. FrameClass.FrameMain.Navigate(new CreateOrUpdatePage());
  175. }
  176. private void BtnRed_Click(object sender, RoutedEventArgs e)
  177. {
  178. Button B = (Button)sender;
  179. int ind = Convert.ToInt32(B.Uid);
  180. Product PrUpdate = BaseClass.Base.Product.FirstOrDefault(y => y.ID == ind);
  181. FrameClass.FrameMain.Navigate(new CreateOrUpdatePage(PrUpdate));
  182. }
  183. private void GoPage_MouseDown(object sender, MouseButtonEventArgs e)
  184. {
  185. TextBlock tb = (TextBlock)sender;
  186. switch (tb.Uid) // определяем, куда конкретно было сделано нажатие
  187. {
  188. case "prev":
  189. pg.CurrentPage--;
  190. break;
  191. case "next":
  192. pg.CurrentPage++;
  193. break;
  194. default:
  195. pg.CurrentPage = Convert.ToInt32(tb.Text);
  196. break;
  197. }
  198. LVProdMat.ItemsSource = PRFilter.Skip(pg.CurrentPage * pg.CountPage - pg.CountPage).Take(pg.CountPage).ToList();
  199. }
  200. private void WRDoc_Click(object sender, RoutedEventArgs e)
  201. {
  202. FrameClass.FrameMain.Navigate(new Reports());
  203. }
  204. }
  205. }