ServiceList.xaml.cs 9.0 KB

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