DataList.xaml.cs 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Net;
  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 Learn
  17. {
  18. /// <summary>
  19. /// Логика взаимодействия для DataList.xaml
  20. /// </summary>
  21. public partial class DataList : Page
  22. {
  23. bool flag = false;
  24. int countOfServices = 0;
  25. Entities DB = new Entities();
  26. public DataList()
  27. {
  28. InitializeComponent();
  29. ServiceData.ItemsSource = DB.Service.ToList();
  30. PromoFilter.ItemsSource = new List<string>() { "Все", "от 0% до 5%", "от 5% до 15%", "от 15% до 30%", "от 30% до 70%", "от 70% до 100%" };
  31. PromoFilter.SelectedIndex = 0;
  32. countOfServices = ServiceData.Items.Count;
  33. global.Text = "Количество записей " + countOfServices + " из " + DB.Service.Count();
  34. }
  35. public DataList(int i)
  36. {
  37. InitializeComponent();
  38. ServiceData.ItemsSource = DB.Service.ToList();
  39. PromoFilter.ItemsSource = new List<string>() { "Все", "от 0% до 5%", "от 5% до 15%", "от 15% до 30%", "от 30% до 70%", "от 70% до 100%" };
  40. PromoFilter.SelectedIndex = 0;
  41. countOfServices = ServiceData.Items.Count;
  42. global.Text = "Количество записей " + countOfServices + " из " + DB.Service.Count();
  43. flag = true;
  44. }
  45. private void Minutes(object sender, RoutedEventArgs e)
  46. {
  47. TextBlock min = (TextBlock)sender;
  48. int index = Convert.ToInt32(min.Uid);
  49. int mins = Convert.ToInt32(DB.Service.Where(x => x.ID == index).Select(x => x.DurationInSeconds).First()) / 60;
  50. min.Text = " за " + mins.ToString() + " минут";
  51. }
  52. private void Promo(object sender, RoutedEventArgs e)
  53. {
  54. TextBlock pro = (TextBlock)sender;
  55. int index = Convert.ToInt32(pro.Uid);
  56. int promo = Convert.ToInt32(Convert.ToDouble(DB.Service.Where(x => x.ID == index).Select(x => x.Discount).First()) * 100);
  57. if (promo > 0)
  58. {
  59. pro.Text = "* скидка " + promo + "%";
  60. }
  61. else
  62. {
  63. return;
  64. }
  65. }
  66. private void DelEditLoad(object sender, RoutedEventArgs e)
  67. {
  68. StackPanel deledit = (StackPanel)sender;
  69. if (flag == true)
  70. {
  71. deledit.Visibility = Visibility.Visible;
  72. }
  73. }
  74. private void AddS(object sender, RoutedEventArgs e)
  75. {
  76. Button add = (Button)sender;
  77. if (flag == true)
  78. {
  79. add.Visibility = Visibility.Visible;
  80. }
  81. }
  82. private void ViewR(object sender, RoutedEventArgs e)
  83. {
  84. Button view = (Button)sender;
  85. if (flag == true)
  86. {
  87. view.Visibility = Visibility.Visible;
  88. }
  89. }
  90. private void Strike(object sender, RoutedEventArgs e)
  91. {
  92. TextBlock OldPrice = (TextBlock)sender;
  93. int id = Convert.ToInt32(OldPrice.Uid);
  94. double enable = Convert.ToDouble(DB.Service.Where(x => x.ID == id).Select(x => x.Discount).First());
  95. if (enable != 0)
  96. {
  97. OldPrice.Visibility = Visibility.Visible;
  98. }
  99. else
  100. {
  101. OldPrice.Visibility = Visibility.Collapsed;
  102. }
  103. }
  104. private void PriceLoad(object sender, RoutedEventArgs e)
  105. {
  106. TextBlock Price = (TextBlock)sender;
  107. int id = Convert.ToInt32(Price.Uid);
  108. double disc = Convert.ToDouble(DB.Service.Where(x => x.ID == id).Select(x => x.Discount).First());
  109. double cost = Convert.ToDouble(DB.Service.Where(x => x.ID == id).Select(x => x.Cost).First());
  110. if (disc != 0)
  111. {
  112. Price.Text = Convert.ToString(cost - disc * cost + " рублей");
  113. }
  114. else
  115. {
  116. Price.Text = Convert.ToString(cost + " рублей");
  117. }
  118. }
  119. private void BackgroundLoad(object sender, RoutedEventArgs e)
  120. {
  121. Grid serv = (Grid)sender;
  122. int index = Convert.ToInt32(serv.Uid);
  123. if (DB.Service.Where(x => x.ID == index).Select(x => x.Discount).First() > 0)
  124. {
  125. serv.Background = new SolidColorBrush(Colors.LightGreen);
  126. }
  127. }
  128. private void Up_Checked(object sender, RoutedEventArgs e)
  129. {
  130. Filter();
  131. }
  132. private void Down_Checked(object sender, RoutedEventArgs e)
  133. {
  134. Filter();
  135. }
  136. private void PromoChange(object sender, RoutedEventArgs e)
  137. {
  138. Filter();
  139. }
  140. private void SearchChange(object sender, TextChangedEventArgs e)
  141. {
  142. Filter();
  143. }
  144. private void Filter()
  145. {
  146. List<Service> servs = DB.Service.ToList();
  147. if (Up.IsChecked == true)
  148. {
  149. servs = servs.OrderBy(x => x.Cost).ToList();
  150. }
  151. if (Down.IsChecked == true)
  152. {
  153. servs = servs.OrderByDescending(x => x.Cost).ToList();
  154. }
  155. switch (PromoFilter.SelectedIndex)
  156. {
  157. case 1:
  158. servs = servs.Where(x => x.Discount == null || (x.Discount >= 0 && x.Discount < 0.05)).ToList();
  159. break;
  160. case 2:
  161. servs = servs.Where(x => x.Discount >= 0.05 && x.Discount < 0.15).ToList();
  162. break;
  163. case 3:
  164. servs = servs.Where(x => x.Discount >= 0.15 && x.Discount < 0.30).ToList();
  165. break;
  166. case 4:
  167. servs = servs.Where(x => x.Discount >= 0.30 && x.Discount < 0.70).ToList();
  168. break;
  169. case 5:
  170. servs = servs.Where(x => x.Discount >= 0.70 && x.Discount < 1).ToList();
  171. break;
  172. default:
  173. break;
  174. }
  175. if (!string.IsNullOrWhiteSpace(Search.Text))
  176. {
  177. servs = servs.Where(x => x.Title.ToLower().Contains(Search.Text.ToLower())).ToList();
  178. }
  179. ServiceData.ItemsSource = servs;
  180. countOfServices = ServiceData.Items.Count;
  181. global.Text = "Количество записей " + countOfServices + " из " + DB.Service.Count();
  182. }
  183. private void RedServ(object sender, RoutedEventArgs e)
  184. {
  185. Button but = (Button)sender;
  186. int index = Convert.ToInt32(but.Uid);
  187. ReductAdd wns = new ReductAdd(index);
  188. wns.ShowDialog();
  189. }
  190. private void DeleteServ(object sender, RoutedEventArgs e)
  191. {
  192. Entities DB = new Entities();
  193. Button butt = (Button)sender;
  194. int index = Convert.ToInt32(butt.Uid);
  195. Service serv = DB.Service.Where(x => x.ID == index).FirstOrDefault();
  196. switch (MessageBox.Show("Удалить?", "Serv", MessageBoxButton.YesNo, MessageBoxImage.Question))
  197. {
  198. case MessageBoxResult.Yes:
  199. DB.Service.Remove(serv);
  200. MessageBox.Show("Удалено");
  201. DB.SaveChanges();
  202. MainFrame.mframe.Navigate(new DataList());
  203. break;
  204. case MessageBoxResult.No:
  205. MessageBox.Show("Вы отменили удаление");
  206. break;
  207. }
  208. }
  209. private void Add(object sender, RoutedEventArgs e)
  210. {
  211. ReductAdd wns = new ReductAdd();
  212. wns.ShowDialog();
  213. }
  214. private void MakeReg(object sender, RoutedEventArgs e)
  215. {
  216. Button butt = (Button)sender;
  217. int index = Convert.ToInt32(butt.Uid);
  218. AddRegistration wns = new AddRegistration(index);
  219. wns.ShowDialog();
  220. }
  221. private void Login(object sender, RoutedEventArgs e)
  222. {
  223. Login Auth = new Login();
  224. Auth.ShowDialog();
  225. }
  226. }
  227. }