hash-0d9KD93k12Ll32Ii3202.txt 42 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770
  1. /////////////// ОБЩЕЕ //////////////
  2. internal class BaseClass
  3. {
  4. public static CookersShopEntities BD;
  5. }
  6. internal class FrameClass
  7. {
  8. public static Frame MainFrame;
  9. public static string loginAutorizate;
  10. }
  11. public MainWindow()
  12. {
  13. InitializeComponent();
  14. BaseClass.BD = new CookersShopEntities();
  15. FrameClass.MainFrame = fMain;
  16. FrameClass.MainFrame.Navigate(new MainPage());
  17. }
  18. <Grid>
  19. <Grid.RowDefinitions>
  20. <RowDefinition></RowDefinition>
  21. </Grid.RowDefinitions>
  22. <Frame Grid.Row="0" Name="fMain" NavigationUIVisibility="Hidden"></Frame>
  23. </Grid>
  24. /////////// AUTORIZATE ///////////////
  25. <Grid>
  26. <Grid.RowDefinitions>
  27. <RowDefinition Height="40"></RowDefinition>
  28. <RowDefinition></RowDefinition>
  29. </Grid.RowDefinitions>
  30. <Button Grid.Row="0" Style="{DynamicResource MainButtonStyle}" Margin="0,0,20,0" VerticalAlignment="Top" HorizontalAlignment="Right" Content="Вернуться на главную" FontSize="12" FontFamily="Roboto" FontWeight="DemiBold" Click="Button_Click" Padding="2"></Button>
  31. <StackPanel Grid.Row="1" VerticalAlignment="Center" HorizontalAlignment="Center" Margin="0 -40 0 0">
  32. <TextBlock FontSize="48" FontFamily="Roboto" HorizontalAlignment="Center" VerticalAlignment="Top" FontWeight="UltraBold">Авторизация</TextBlock>
  33. <GroupBox Header="Введите логин" Width="270">
  34. <TextBox Name="tbLogin" MaxLength="25"></TextBox>
  35. </GroupBox>
  36. <GroupBox Header="Введите пароль" Width="270">
  37. <PasswordBox Name="pbPassword" MaxLength="40"></PasswordBox>
  38. </GroupBox>
  39. <Button Style="{DynamicResource AcceptButtonStyle}" Margin="0,10,0,0" Padding="7 3 7 3" HorizontalAlignment="Center" VerticalAlignment="Center" Name="bRegistration" Content="Авторизоваться" Click="bRegistration_Click"></Button>
  40. </StackPanel>
  41. </Grid>
  42. public AutoPage()
  43. {
  44. InitializeComponent();
  45. //На случай сноса админского пароля
  46. //Users searchUser = BaseClass.BD.Users.FirstOrDefault(x => x.login == "admin");
  47. //var pass = "admin";
  48. //searchUser.password = pass.GetHashCode();
  49. //BaseClass.BD.SaveChanges();
  50. }
  51. private void Button_Click(object sender, RoutedEventArgs e)
  52. {
  53. FrameClass.MainFrame.Navigate(new MainPage());
  54. }
  55. private void bRegistration_Click(object sender, RoutedEventArgs e)
  56. {
  57. if (tbLogin.Text == "") MessageBox.Show("Заполните поле логина!", "", MessageBoxButton.OK, MessageBoxImage.Error); // Проверка на заполнение Логина
  58. else if (pbPassword.Password == "") MessageBox.Show("Заполните поле логина!", "", MessageBoxButton.OK, MessageBoxImage.Error); // Проверка на заполнение Пароля
  59. else
  60. {
  61. int pass = pbPassword.Password.GetHashCode();
  62. Users searchUser = BaseClass.BD.Users.FirstOrDefault(x => x.login == tbLogin.Text);
  63. if (searchUser == null) MessageBox.Show("Такого пользователя не существует!", "", MessageBoxButton.OK, MessageBoxImage.Error);
  64. else
  65. {
  66. Users autoUser = BaseClass.BD.Users.FirstOrDefault(x => x.login == tbLogin.Text && x.password == pass);
  67. if (autoUser == null)
  68. {
  69. MessageBox.Show("Неправильно введён пароль!", "", MessageBoxButton.OK, MessageBoxImage.Error);
  70. }
  71. else
  72. {
  73. switch (autoUser.role)
  74. {
  75. // Обычный пользователь (0)
  76. case 0:
  77. FrameClass.loginAutorizate = tbLogin.Text;
  78. FrameClass.MainFrame.Navigate(new mainPageUsers());
  79. break;
  80. // Администратор (1)
  81. case 1:
  82. FrameClass.loginAutorizate = tbLogin.Text;
  83. FrameClass.MainFrame.Navigate(new AdminPanel());
  84. break;
  85. default: MessageBox.Show("Произошла неизвестная ошибка!\nПерезайдите в приложение!", "Ошибка", MessageBoxButton.OK, MessageBoxImage.Error); break;
  86. }
  87. }
  88. }
  89. }
  90. }
  91. //////////// REGISTRATION CODE //////////////////
  92. private void bRegistration_Click(object sender, RoutedEventArgs e)
  93. {
  94. if (tbName.Text == "") MessageBox.Show("Заполните поле имени!", "", MessageBoxButton.OK, MessageBoxImage.Error);
  95. else if (tbSurname.Text == "") MessageBox.Show("Заполните поле фамилии!", "", MessageBoxButton.OK, MessageBoxImage.Error);
  96. else if (tbNumber.Text == "") MessageBox.Show("Заполните поле номера телефона!", "", MessageBoxButton.OK, MessageBoxImage.Error);
  97. else if (tbLogin.Text == "") MessageBox.Show("Заполните поле логина!", "", MessageBoxButton.OK, MessageBoxImage.Error);
  98. else if (pbPassword.Password == "") MessageBox.Show("Заполните поле пароля!", "", MessageBoxButton.OK, MessageBoxImage.Error);
  99. else if (rbMan.IsChecked != true && rbWoman.IsChecked != true) MessageBox.Show("Убедитесь, что Вы выбрали пол!", "", MessageBoxButton.OK, MessageBoxImage.Error);
  100. else if (tbNumber.Text.Length != 11) MessageBox.Show("Проверьте правильность введенного номера телефона!\nПримеры правильного формата:\n • 79101426789\n • 89101426789", "", MessageBoxButton.OK, MessageBoxImage.Error);
  101. else
  102. {
  103. string checkPassword = pbPassword.Password;
  104. Users searchUser = BaseClass.BD.Users.FirstOrDefault(x => x.login == tbLogin.Text);
  105. if (searchUser != null) MessageBox.Show("Такой пользователь уже существует!", "", MessageBoxButton.OK, MessageBoxImage.Error);
  106. else if (CheckPass(checkPassword) == false)
  107. MessageBox.Show("Ваш пароль очень простой!", "", MessageBoxButton.OK, MessageBoxImage.Error);
  108. else
  109. {
  110. int tempGender = 0;
  111. if (rbMan.IsChecked == true)
  112. tempGender = 1;
  113. if (rbWoman.IsChecked == true)
  114. tempGender = 2;
  115. Users user = new Users()
  116. {
  117. name_user = tbName.Text,
  118. surname_user = tbSurname.Text,
  119. gender = tempGender,
  120. login = tbLogin.Text,
  121. password = pbPassword.Password.GetHashCode(),
  122. phone = tbNumber.Text,
  123. date_reg = Convert.ToDateTime(DateTime.Today),
  124. role = 0,
  125. privilege = null
  126. };
  127. BaseClass.BD.Users.Add(user);
  128. BaseClass.BD.SaveChanges();
  129. MessageBox.Show("Вы зарегистрировались!");
  130. FrameClass.MainFrame.Navigate(new AutoPage());
  131. }
  132. }
  133. }
  134. ////////////// INPUT PRODUCT XAML ///////////////
  135. <Page.Resources>
  136. <BitmapImage x:Key="noimage" UriSource="/Resources/noimage.png"/>
  137. </Page.Resources>
  138. <Grid>
  139. <Grid.RowDefinitions>
  140. <RowDefinition Height="40"></RowDefinition>
  141. <RowDefinition Height="370"></RowDefinition>
  142. <RowDefinition Height="40"></RowDefinition>
  143. </Grid.RowDefinitions>
  144. <TextBlock Grid.Row="0" FontSize="28" HorizontalAlignment="Center" VerticalAlignment="Top" FontFamily="Roboto" FontWeight="Bold">Товар</TextBlock>
  145. <StackPanel Orientation="Horizontal" VerticalAlignment="Top" HorizontalAlignment="Right">
  146. <Button x:Name="AddProduct" Style="{DynamicResource AcceptButtonStyle}" Grid.Row="0" Margin="0,0,20,0" Content="Добавить товар" FontSize="12" FontFamily="Roboto" FontWeight="DemiBold" Padding="3" Click="AddProduct_Click"></Button>
  147. <Button x:Name="BackMain" Style="{DynamicResource MainButtonStyle}" Grid.Row="0" Margin="0,0,20,0" Content="Вернуться назад" FontSize="12" FontFamily="Roboto" FontWeight="DemiBold" Padding="2" Click="BackMain_Click"></Button>
  148. </StackPanel>
  149. <ListView Grid.Row="1" Name="listProduct" ScrollViewer.HorizontalScrollBarVisibility="Disabled">
  150. <ListView.ItemsPanel>
  151. <ItemsPanelTemplate>
  152. <WrapPanel HorizontalAlignment="Center"></WrapPanel>
  153. </ItemsPanelTemplate>
  154. </ListView.ItemsPanel>
  155. <ListView.ItemTemplate>
  156. <DataTemplate>
  157. <Border Padding="5" CornerRadius="5" BorderThickness="1" BorderBrush="#304FFE">
  158. <Grid Name="gridProduct" Width="250" Height="auto">
  159. <StackPanel>
  160. <TextBlock FontFamily="Roboto" Text="{Binding name}" FontSize="16" FontWeight="Bold" TextDecorations="{x:Null}"/>
  161. <Image Width="100" Height="100" Source="{Binding image_product, TargetNullValue={StaticResource noimage}}" HorizontalAlignment="Center" VerticalAlignment="Center"/>
  162. <TextBlock FontFamily="Roboto" Text="{Binding Manufacturers.manufacturer_name, StringFormat=Производитель: {0}}" FontSize="14"/>
  163. <TextBlock Uid="{Binding product_code}" Name="price" Loaded="price_Loaded" FontFamily="Roboto" FontSize="14"></TextBlock>
  164. <TextBlock Text="{Binding amount, StringFormat=Количество: {0}}" FontFamily="Roboto" FontSize="14"/>
  165. <TextBlock Uid="{Binding product_code}" Name="ratingProduct" Loaded="rate_Loaded" FontFamily="Roboto" FontSize="18"/>
  166. <StackPanel HorizontalAlignment="Right" VerticalAlignment="Bottom" Orientation="Horizontal">
  167. <Button Uid="{Binding product_code}" Style="{DynamicResource AcceptButtonStyle}" Margin="3" FontSize="12" FontFamily="Roboto" FontWeight="DemiBold" Padding="2" Click="Button_Click_1">Изменить</Button>
  168. <Button Uid="{Binding product_code}" Style="{DynamicResource ExitButtonStyle}" Margin="3" FontSize="12" FontFamily="Roboto" FontWeight="DemiBold" Padding="2" Click="Button_Click">Удалить</Button>
  169. </StackPanel>
  170. </StackPanel>
  171. </Grid>
  172. </Border>
  173. </DataTemplate>
  174. </ListView.ItemTemplate>
  175. </ListView>
  176. <WrapPanel Grid.Row="2">
  177. <StackPanel Orientation="Horizontal" Grid.Row="2" HorizontalAlignment="Left" VerticalAlignment="Center" Margin="10 0 45 0">
  178. <TextBlock Text="Общая сумма товаров: " FontSize="14" FontFamily="Roboto" FontWeight="DemiBold" Loaded="TextBlock_Loaded"></TextBlock>
  179. </StackPanel>
  180. <StackPanel Orientation="Vertical" Height="40" HorizontalAlignment="Left" Margin="15 0 0 0">
  181. <TextBlock Text="Фильтр" HorizontalAlignment="Center" FontFamily="Roboto" FontSize="12" Margin="0 0 0 2"></TextBlock>
  182. <StackPanel Orientation="Horizontal" Height="20" HorizontalAlignment="Center" Margin="0 0 0 0">
  183. <ComboBox x:Name="Filter" Height="20" Width="120" VerticalContentAlignment="Center" Margin="0 0 0 0" FontSize="12" SelectionChanged="Filter_SelectionChanged">
  184. <Label Content="Все товары" FontFamily="Roboto" FontSize="12"/>
  185. <Label Content="Со скидкой" FontFamily="Roboto" FontSize="12"/>
  186. <Label Content="Без скидок" FontFamily="Roboto" FontSize="12"/>
  187. </ComboBox>
  188. <CheckBox x:Name="cbFilter" Content="С оценками" Margin="10 0 0 0" FontFamily="Roboto" FontSize="12" HorizontalAlignment="Center" VerticalAlignment="Center" Checked="cbFilter_Checked" Unchecked="cbFilter_Unchecked"></CheckBox>
  189. <TextBox x:Name="Search" Width="150" Margin="10 0 0 0" FontFamily="Roboto" FontSize="12" TextChanged="Search_TextChanged"></TextBox>
  190. </StackPanel>
  191. </StackPanel>
  192. <StackPanel Orientation="Vertical" Height="40" HorizontalAlignment="Left" Margin="15 0 0 0">
  193. <TextBlock Text="Сортировка" HorizontalAlignment="Center" FontFamily="Roboto" FontSize="12" Margin="0 0 0 2"></TextBlock>
  194. <ComboBox x:Name="Sortirovka" Height="20" Width="120" VerticalContentAlignment="Center" Margin="0 0 0 0" FontSize="12" SelectionChanged="Sortirovka_SelectionChanged">
  195. <Label Content="По умолчанию" FontFamily="Roboto" FontSize="12"/>
  196. <Label Content="По возрастанию цены" FontFamily="Roboto" FontSize="12"/>
  197. <Label Content="По убыванию цены" FontFamily="Roboto" FontSize="12"/>
  198. </ComboBox>
  199. </StackPanel>
  200. </WrapPanel>
  201. </Grid>
  202. ////////////// INPUT PRODUCT CODE ///////////////
  203. public aListProduct()
  204. {
  205. InitializeComponent();
  206. listProduct.ItemsSource = BaseClass.BD.Products.ToList();
  207. Filter.SelectedIndex = 0;
  208. Sortirovka.SelectedIndex = 0;
  209. }
  210. private void BackMain_Click(object sender, RoutedEventArgs e)
  211. {
  212. FrameClass.MainFrame.Navigate(new AdminPanel());
  213. }
  214. private void Button_Click(object sender, RoutedEventArgs e)
  215. {
  216. Button btn = (Button)sender;
  217. int index = Convert.ToInt32(btn.Uid);
  218. Products products = BaseClass.BD.Products.FirstOrDefault(x => x.product_code == index);
  219. BaseClass.BD.Products.Remove(products);
  220. BaseClass.BD.SaveChanges();
  221. FrameClass.MainFrame.Navigate(new aListProduct());
  222. }
  223. private void price_Loaded(object sender, RoutedEventArgs e)
  224. {
  225. TextBlock tb = (TextBlock)sender;
  226. int index = Convert.ToInt32(tb.Uid);
  227. int disc = 0;
  228. int price = 0;
  229. List<Products> DC = BaseClass.BD.Products.Where(x => x.product_code == index).ToList();
  230. foreach(Products Product in DC)
  231. {
  232. disc = Convert.ToInt32(Product.discount);
  233. price = Convert.ToInt32(Product.price);
  234. }
  235. if(disc <=0)
  236. tb.Text = "Цена: " + price.ToString() + "₽";
  237. if(disc > 0)
  238. {
  239. price = price * (100 - disc) / 100;
  240. tb.Text = "Цена: " + price.ToString() + "₽";
  241. tb.FontWeight = FontWeights.Bold;
  242. tb.Foreground = Brushes.Red;
  243. }
  244. }
  245. private void rate_Loaded(object sender, RoutedEventArgs e)
  246. {
  247. TextBlock tb = (TextBlock)sender;
  248. int index = Convert.ToInt32(tb.Uid);
  249. int rateID = 0;
  250. List<Products> DC = BaseClass.BD.Products.Where(x => x.product_code == index).ToList();
  251. foreach (Products Product in DC)
  252. rateID = Convert.ToInt32(Product.rate);
  253. List<Ratings> RN = BaseClass.BD.Ratings.Where(x => x.rate == rateID).ToList();
  254. foreach (Ratings Ratings in RN)
  255. {
  256. if (Ratings.rating == 5)
  257. tb.Text = "★★★★★";
  258. else if (Ratings.rating == 4)
  259. tb.Text = "★★★★";
  260. else if (Ratings.rating == 3)
  261. tb.Text = "★★★";
  262. else if (Ratings.rating == 2)
  263. tb.Text = "★★";
  264. else if (Ratings.rating == 1)
  265. tb.Text = "★";
  266. else
  267. {
  268. tb.Text = "Рейтинг: 0";
  269. tb.Foreground = Brushes.DarkGray;
  270. }
  271. tb.Foreground = Brushes.DarkOrange;
  272. }
  273. }
  274. private void TextBlock_Loaded(object sender, RoutedEventArgs e)
  275. {
  276. TextBlock tb = (TextBlock)sender;
  277. int allSumProduct = 0;
  278. List<Products> DC = BaseClass.BD.Products.ToList();
  279. foreach (Products Product in DC)
  280. allSumProduct += Convert.ToInt32(Product.price * Product.amount);
  281. tb.Text = "Общая сумма товаров\n(без учета скидок): " + allSumProduct.ToString();
  282. }
  283. private void Button_Click_1(object sender, RoutedEventArgs e)
  284. {
  285. Button btn = (Button)sender;
  286. int index = Convert.ToInt32(btn.Uid);
  287. Products product = BaseClass.BD.Products.FirstOrDefault(x => x.product_code == index);
  288. FrameClass.MainFrame.Navigate(new UpdateProduct(product));
  289. }
  290. private void AddProduct_Click(object sender, RoutedEventArgs e)
  291. {
  292. FrameClass.MainFrame.Navigate(new UpdateProduct());
  293. }
  294. void SearchMainMethod()
  295. {
  296. string strSearch = Search.Text.ToLower();
  297. var regexSearch = new Regex($@"(^({strSearch}).*)");
  298. if (Sortirovka.SelectedIndex == 0)
  299. {
  300. if (cbFilter.IsChecked == true)
  301. {
  302. if (Filter.SelectedIndex == 0)
  303. {
  304. listProduct.ItemsSource = BaseClass.BD.Products.ToList().Where(x => regexSearch.IsMatch(x.name.ToLower()) == true && x.rate != null);
  305. }
  306. else if (Filter.SelectedIndex == 1)
  307. {
  308. listProduct.ItemsSource = BaseClass.BD.Products.ToList().Where(x => regexSearch.IsMatch(x.name.ToLower()) == true && x.discount > 0 && x.rate != null);
  309. }
  310. else
  311. {
  312. listProduct.ItemsSource = BaseClass.BD.Products.ToList().Where(x => regexSearch.IsMatch(x.name.ToLower()) == true && x.discount == 0 && x.rate != null);
  313. }
  314. }
  315. else
  316. {
  317. if (Filter.SelectedIndex == 0)
  318. {
  319. listProduct.ItemsSource = BaseClass.BD.Products.ToList().Where(x => regexSearch.IsMatch(x.name.ToLower()) == true);
  320. }
  321. else if (Filter.SelectedIndex == 1)
  322. {
  323. listProduct.ItemsSource = BaseClass.BD.Products.ToList().Where(x => regexSearch.IsMatch(x.name.ToLower()) == true && x.discount > 0);
  324. }
  325. else
  326. {
  327. listProduct.ItemsSource = BaseClass.BD.Products.ToList().Where(x => regexSearch.IsMatch(x.name.ToLower()) == true && x.discount == 0);
  328. }
  329. }
  330. }
  331. else if (Sortirovka.SelectedIndex == 1)
  332. {
  333. if (cbFilter.IsChecked == true)
  334. {
  335. if (Filter.SelectedIndex == 0)
  336. {
  337. listProduct.ItemsSource = BaseClass.BD.Products.OrderBy(x => x.price * (100 - x.discount) / 100).ToList().Where(x => regexSearch.IsMatch(x.name.ToLower()) == true && x.rate != null);
  338. }
  339. else if (Filter.SelectedIndex == 1)
  340. {
  341. listProduct.ItemsSource = BaseClass.BD.Products.OrderBy(x => x.price * (100 - x.discount) / 100).ToList().Where(x => regexSearch.IsMatch(x.name.ToLower()) == true && x.discount > 0 && x.rate != null);
  342. }
  343. else
  344. {
  345. listProduct.ItemsSource = BaseClass.BD.Products.OrderBy(x => x.price * (100 - x.discount) / 100).ToList().Where(x => regexSearch.IsMatch(x.name.ToLower()) == true && x.discount == 0 && x.rate != null);
  346. }
  347. }
  348. else
  349. {
  350. if (Filter.SelectedIndex == 0)
  351. {
  352. listProduct.ItemsSource = BaseClass.BD.Products.OrderBy(x => x.price * (100 - x.discount) / 100).ToList().Where(x => regexSearch.IsMatch(x.name.ToLower()) == true);
  353. }
  354. else if (Filter.SelectedIndex == 1)
  355. {
  356. listProduct.ItemsSource = BaseClass.BD.Products.OrderBy(x => x.price * (100 - x.discount) / 100).ToList().Where(x => regexSearch.IsMatch(x.name.ToLower()) == true && x.discount > 0);
  357. }
  358. else
  359. {
  360. listProduct.ItemsSource = BaseClass.BD.Products.OrderBy(x => x.price * (100 - x.discount) / 100).ToList().Where(x => regexSearch.IsMatch(x.name.ToLower()) == true && x.discount == 0);
  361. }
  362. }
  363. }
  364. else if (Sortirovka.SelectedIndex == 2)
  365. {
  366. if (cbFilter.IsChecked == true)
  367. {
  368. if (Filter.SelectedIndex == 0)
  369. {
  370. listProduct.ItemsSource = BaseClass.BD.Products.OrderByDescending(x => x.price * (100 - x.discount) / 100).ToList().Where(x => regexSearch.IsMatch(x.name.ToLower()) == true && x.rate != null);
  371. }
  372. else if (Filter.SelectedIndex == 1)
  373. {
  374. listProduct.ItemsSource = BaseClass.BD.Products.OrderByDescending(x => x.price * (100 - x.discount) / 100).ToList().Where(x => regexSearch.IsMatch(x.name.ToLower()) == true && x.discount > 0 && x.rate != null);
  375. }
  376. else
  377. {
  378. listProduct.ItemsSource = BaseClass.BD.Products.OrderByDescending(x => x.price * (100 - x.discount) / 100).ToList().Where(x => regexSearch.IsMatch(x.name.ToLower()) == true && x.discount == 0 && x.rate != null);
  379. }
  380. }
  381. else
  382. {
  383. if (Filter.SelectedIndex == 0)
  384. {
  385. listProduct.ItemsSource = BaseClass.BD.Products.OrderByDescending(x => x.price * (100 - x.discount) / 100).ToList().Where(x => regexSearch.IsMatch(x.name.ToLower()) == true);
  386. }
  387. else if (Filter.SelectedIndex == 1)
  388. {
  389. listProduct.ItemsSource = BaseClass.BD.Products.OrderByDescending(x => x.price * (100 - x.discount) / 100).ToList().Where(x => regexSearch.IsMatch(x.name.ToLower()) == true && x.discount > 0);
  390. }
  391. else
  392. {
  393. listProduct.ItemsSource = BaseClass.BD.Products.OrderByDescending(x => x.price * (100 - x.discount) / 100).ToList().Where(x => regexSearch.IsMatch(x.name.ToLower()) == true && x.discount == 0);
  394. }
  395. }
  396. }
  397. }
  398. ///////////// GRID INPUT XAML //////////////////
  399. <Grid>
  400. <Grid.RowDefinitions>
  401. <RowDefinition Height="40"></RowDefinition>
  402. <RowDefinition Height="370"></RowDefinition>
  403. <RowDefinition Height="40"></RowDefinition>
  404. </Grid.RowDefinitions>
  405. <TextBlock Grid.Row="0" FontSize="28" HorizontalAlignment="Center" VerticalAlignment="Top" FontFamily="Roboto" FontWeight="Bold">Пользователи</TextBlock>
  406. <Button x:Name="BackMain" Style="{DynamicResource MainButtonStyle}" Grid.Row="0" Margin="0,0,20,0" VerticalAlignment="Top" HorizontalAlignment="Right" Content="Вернуться назад" FontSize="12" FontFamily="Roboto" FontWeight="DemiBold" Click="BackMain_Click" Padding="2"></Button>
  407. <DataGrid Name="dgUser" Grid.Row="1" Margin="10,2,10,2" AutoGenerateColumns="False" CanUserAddRows="False" GridLinesVisibility="Horizontal" CanUserResizeColumns="False" CanUserResizeRows="False" CanUserSortColumns="False" CanUserDeleteRows="False" CanUserReorderColumns="False" IsReadOnly="True" HorizontalAlignment="Center">
  408. <DataGrid.Columns>
  409. <DataGridTextColumn Header="Логин" Binding="{Binding login}" Width="auto"></DataGridTextColumn>
  410. <DataGridTextColumn Header="Имя" Binding="{Binding name_user}" Width="*"></DataGridTextColumn>
  411. <DataGridTextColumn Header="Фамилия" Binding="{Binding surname_user}" Width="*"></DataGridTextColumn>
  412. <DataGridTextColumn Header="Пол" Binding="{Binding Genders.name_gender}" Width="75"></DataGridTextColumn>
  413. <DataGridTextColumn Header="Номер" Binding="{Binding phone}" Width="80"></DataGridTextColumn>
  414. <DataGridTextColumn Header="Дата регистрации" Binding="{Binding date_reg, StringFormat=dd.MM.yyyy}" Width="*"></DataGridTextColumn>
  415. <DataGridTextColumn Header="Привилегия" Binding="{Binding Privilage.name_privilage}" Width="78"></DataGridTextColumn>
  416. <DataGridTextColumn Header="Роль" Binding="{Binding Roles.name_role}" Width="*"></DataGridTextColumn>
  417. </DataGrid.Columns>
  418. </DataGrid>
  419. <WrapPanel Grid.Row="2">
  420. <StackPanel Orientation="Vertical" Height="40" HorizontalAlignment="Left" Margin="15 0 0 0">
  421. <TextBlock Text="Сортировка по фамилии" HorizontalAlignment="Center" FontFamily="Roboto" FontSize="12" Margin="0 0 0 2"></TextBlock>
  422. <ComboBox x:Name="VozrastYbivan" Height="20" Width="120" VerticalContentAlignment="Center" Margin="0 0 0 0" SelectionChanged="VozrastYbivan_SelectionChanged" FontSize="12">
  423. <Label Content="По умолчанию" FontFamily="Roboto" FontSize="12"/>
  424. <Label Content="По возрастанию" FontFamily="Roboto" FontSize="12"/>
  425. <Label Content="По убыванию" FontFamily="Roboto" FontSize="12"/>
  426. </ComboBox>
  427. </StackPanel>
  428. <StackPanel Orientation="Horizontal" Height="40" HorizontalAlignment="Left" Margin="15 0 0 0">
  429. <TextBox x:Name="Search" Width="150" Height="25" VerticalContentAlignment="Center" TextChanged="Search_TextChanged"></TextBox>
  430. <StackPanel HorizontalAlignment="Center" Margin="10 0 0 0">
  431. <TextBlock Text="Фильтровать по полю" HorizontalAlignment="Center" FontFamily="Roboto" FontSize="12" Margin="0 0 0 2"></TextBlock>
  432. <ComboBox x:Name="typeSearch" Height="20" Width="80" VerticalContentAlignment="Center" Margin="0 0 0 0" FontSize="12" SelectionChanged="typeSearch_SelectionChanged">
  433. <Label Content="Имя" FontFamily="Roboto" FontSize="12"/>
  434. <Label Content="Фамилия" FontFamily="Roboto" FontSize="12"/>
  435. </ComboBox>
  436. </StackPanel>
  437. </StackPanel>
  438. <StackPanel Orientation="Vertical" Width="150" VerticalAlignment="Center" Margin="10 0 0 0">
  439. <TextBlock Text="Фильтрация по полу" HorizontalAlignment="Center" FontFamily="Roboto" FontSize="14"></TextBlock>
  440. <StackPanel Orientation="Horizontal" HorizontalAlignment="Center">
  441. <CheckBox Name="rbMan" Content="Мужской" FontFamily="Roboto" Checked="rbMan_Checked" Unchecked="rbMan_Unchecked"></CheckBox>
  442. <CheckBox Name="rbWoman" Content="Женский" FontFamily="Roboto" Margin="10 0 0 0" Checked="rbWoman_Checked" Unchecked="rbWoman_Unchecked"></CheckBox>
  443. </StackPanel>
  444. </StackPanel>
  445. <StackPanel Orientation="Vertical" Height="25" Width="70" Margin=" 15 10 0 0">
  446. <Button Name="ButtonRefresh" Style="{DynamicResource AcceptButtonStyle}" FontFamily="Roboto" FontSize="12" Padding="2 0 2 0" Content="Сброс" Height="19" Width="70" Click="ButtonRefresh_Click" FontWeight="Bold"></Button>
  447. </StackPanel>
  448. </WrapPanel>
  449. </Grid>
  450. //////////////////// GRID INPUT CODE ////////////////
  451. public aListUser()
  452. {
  453. InitializeComponent();
  454. dgUser.ItemsSource = BaseClass.BD.Users.ToList();
  455. typeSearch.SelectedIndex = 0;
  456. VozrastYbivan.SelectedIndex = 0;
  457. }
  458. private void BackMain_Click(object sender, RoutedEventArgs e)
  459. {
  460. FrameClass.MainFrame.Navigate(new AdminPanel());
  461. }
  462. private void Search_TextChanged(object sender, TextChangedEventArgs e)
  463. {
  464. SearchMainMethod();
  465. }
  466. private void ButtonRefresh_Click(object sender, RoutedEventArgs e)
  467. {
  468. rbWoman.IsChecked = false;
  469. rbMan.IsChecked = false;
  470. Search.Clear();
  471. VozrastYbivan.SelectedIndex = 0;
  472. typeSearch.SelectedIndex = 0;
  473. dgUser.ItemsSource = BaseClass.BD.Users.ToList();
  474. }
  475. //////////// UPDATE PRODUCT /////////////
  476. Products PRODUCT;
  477. bool flagUpdate = false;
  478. string path;
  479. public void uploadFields()
  480. {
  481. cbManufacturer.ItemsSource = BaseClass.BD.Manufacturers.ToList();
  482. cbManufacturer.SelectedValuePath = "manufacturer_code";
  483. cbManufacturer.DisplayMemberPath = "manufacturer_name";
  484. cbManufacturer.SelectedIndex = 0;
  485. tbDiscount.Text = "0";
  486. }
  487. public UpdateProduct()
  488. {
  489. InitializeComponent();
  490. uploadFields();
  491. }
  492. public UpdateProduct(Products product)
  493. {
  494. InitializeComponent();
  495. uploadFields();
  496. flagUpdate = true;
  497. PRODUCT = product;
  498. tbName.Text = PRODUCT.name;
  499. tbPrice.Text = Convert.ToString(PRODUCT.price);
  500. tbAmount.Text = Convert.ToString(PRODUCT.amount);
  501. cbManufacturer.SelectedIndex = PRODUCT.manufacturer_code - 1;
  502. tbDescription.Text = PRODUCT.description;
  503. tbDiscount.Text = Convert.ToString(PRODUCT.discount);
  504. if (product.image_product != null)
  505. {
  506. BitmapImage img = new BitmapImage(new Uri(product.image_product, UriKind.RelativeOrAbsolute));
  507. imgProduct.Source = img;
  508. }
  509. }
  510. private void BackMain_Click(object sender, RoutedEventArgs e)
  511. {
  512. FrameClass.MainFrame.Navigate(new aListProduct());
  513. }
  514. private void bRegistration_Click(object sender, RoutedEventArgs e)
  515. {
  516. try
  517. {
  518. if (flagUpdate == false)
  519. {
  520. PRODUCT = new Products();
  521. }
  522. PRODUCT.name = tbName.Text;
  523. PRODUCT.description = tbDescription.Text;
  524. PRODUCT.price = Convert.ToInt32(tbPrice.Text);
  525. PRODUCT.amount = Convert.ToInt32(tbAmount.Text);
  526. PRODUCT.manufacturer_code = cbManufacturer.SelectedIndex + 1;
  527. PRODUCT.discount = Convert.ToInt32(tbDiscount.Text);
  528. if (path!= null)
  529. {
  530. PRODUCT.image_product = path;
  531. }
  532. if (flagUpdate == false)
  533. {
  534. BaseClass.BD.Products.Add(PRODUCT);
  535. }
  536. BaseClass.BD.SaveChanges();
  537. MessageBox.Show("Информация добавлена");
  538. }
  539. catch
  540. {
  541. MessageBox.Show("Что-то пошло не по плану");
  542. }
  543. }
  544. private void bSavePhoto_Click(object sender, RoutedEventArgs e)
  545. {
  546. try
  547. {
  548. OpenFileDialog OFD = new OpenFileDialog();
  549. OFD.ShowDialog();
  550. path = OFD.FileName;
  551. string[] arrayPath = path.Split('\\');
  552. path = "\\" + arrayPath[arrayPath.Length - 2] + "\\" + arrayPath[arrayPath.Length - 1];
  553. BitmapImage bi3 = new BitmapImage();
  554. bi3.BeginInit();
  555. bi3.UriSource = new Uri("\\Resources\\icons8-new-100.png", UriKind.Relative);
  556. bi3.EndInit();
  557. imgProduct.Source = bi3;
  558. }
  559. catch { }
  560. }
  561. /////////// СТИЛИ /////////////
  562. <Application.Resources>
  563. <SolidColorBrush x:Key="PrimaryBlueColor" Color="#304FFE"></SolidColorBrush>
  564. <SolidColorBrush x:Key="PrimaryTextColor" Color="White"></SolidColorBrush>
  565. <SolidColorBrush x:Key="ButtonMouseOverColor" Color="#0026CA"></SolidColorBrush>
  566. <SolidColorBrush x:Key="ButtonPressedColor" Color="#7a7cff"></SolidColorBrush>
  567. <SolidColorBrush x:Key="PrimaryDarkTextColor" Color="#0026ca"></SolidColorBrush>
  568. <SolidColorBrush x:Key="ButtonBorderBrushColor" Color="#0026ca"></SolidColorBrush>
  569. <SolidColorBrush x:Key="PrimaryRedColor" Color="#f21818"></SolidColorBrush>
  570. <SolidColorBrush x:Key="ButtonMouseOverColorRed" Color="#de1414"></SolidColorBrush>
  571. <SolidColorBrush x:Key="ButtonPressedColorRed" Color="#f05454"></SolidColorBrush>
  572. <Style x:Key="AcceptButtonStyle" TargetType="{x:Type Button}">
  573. <Setter Property="Background" Value="{DynamicResource PrimaryBlueColor}"></Setter>
  574. <Setter Property="Foreground" Value="{DynamicResource PrimaryTextColor}"></Setter>
  575. <Setter Property="FontWeight" Value="SemiBold"></Setter>
  576. <Setter Property="Padding" Value="12 6 12 6"></Setter>
  577. <Setter Property="BorderThickness" Value="0"></Setter>
  578. <Setter Property="MaxHeight" Value="70"></Setter>
  579. <Setter Property="Width" Value="auto"></Setter>
  580. <Setter Property="HorizontalContentAlignment" Value="Center"></Setter>
  581. <Setter Property="VerticalContentAlignment" Value="Center"></Setter>
  582. <Setter Property="Template">
  583. <Setter.Value>
  584. <ControlTemplate TargetType="{x:Type Button}">
  585. <Border x:Name="btnBorder" CornerRadius="5"
  586. Background="{TemplateBinding Background}"
  587. Width="{TemplateBinding Width}"
  588. MaxHeight="{TemplateBinding MaxHeight }"
  589. BorderThickness="{TemplateBinding BorderThickness}"
  590. SnapsToDevicePixels="True"
  591. Padding="{TemplateBinding Padding}">
  592. <ContentPresenter x:Name="ContentPresenter" Focusable="False"
  593. HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
  594. VerticalAlignment="{TemplateBinding VerticalContentAlignment}"
  595. Margin="{TemplateBinding Padding}"
  596. SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"></ContentPresenter>
  597. </Border>
  598. <ControlTemplate.Triggers>
  599. <Trigger Property="IsMouseOver" Value="True">
  600. <Setter TargetName="btnBorder" Property="Background" Value="{DynamicResource ButtonMouseOverColor}"></Setter>
  601. </Trigger>
  602. <Trigger Property="IsPressed" Value="True">
  603. <Setter TargetName="btnBorder" Property="Background" Value="{DynamicResource ButtonPressedColor}"></Setter>
  604. </Trigger>
  605. </ControlTemplate.Triggers>
  606. </ControlTemplate>
  607. </Setter.Value>
  608. </Setter>
  609. </Style>
  610. <Style x:Key="MainButtonStyle" TargetType="{x:Type Button}">
  611. <Setter Property="Background" Value="Transparent"></Setter>
  612. <Setter Property="BorderBrush" Value="{DynamicResource PrimaryBlueColor}"></Setter>
  613. <Setter Property="Foreground" Value="{DynamicResource PrimaryBlueColor}"></Setter>
  614. <Setter Property="FontWeight" Value="ExtraBold"></Setter>
  615. <Setter Property="Padding" Value="11 5.2"></Setter>
  616. <Setter Property="BorderThickness" Value="2"></Setter>
  617. <Setter Property="MaxHeight" Value="70"></Setter>
  618. <Setter Property="Width" Value="auto"></Setter>
  619. <Setter Property="HorizontalContentAlignment" Value="Center"></Setter>
  620. <Setter Property="VerticalContentAlignment" Value="Center"></Setter>
  621. <Setter Property="Template">
  622. <Setter.Value>
  623. <ControlTemplate TargetType="{x:Type Button}">
  624. <Border x:Name="btnBorder" CornerRadius="5"
  625. Background="{TemplateBinding Background}"
  626. Width="{TemplateBinding Width}"
  627. BorderBrush="{TemplateBinding BorderBrush}"
  628. MaxHeight="{TemplateBinding MaxHeight }"
  629. BorderThickness="{TemplateBinding BorderThickness}"
  630. SnapsToDevicePixels="True"
  631. Padding="{TemplateBinding Padding}">
  632. <ContentPresenter x:Name="ContentPresenter" Focusable="False"
  633. HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
  634. VerticalAlignment="{TemplateBinding VerticalContentAlignment}"
  635. Margin="{TemplateBinding Padding}"
  636. SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"></ContentPresenter>
  637. </Border>
  638. <ControlTemplate.Triggers>
  639. <Trigger Property="IsMouseOver" Value="True">
  640. <Setter TargetName="btnBorder" Property="Background" Value="{DynamicResource ButtonMouseOverColor}"></Setter>
  641. <Setter TargetName="btnBorder" Property="BorderBrush" Value="{DynamicResource PrimaryBlueColor}"></Setter>
  642. <Setter Property="Foreground" Value="{DynamicResource PrimaryTextColor}"></Setter>
  643. </Trigger>
  644. <Trigger Property="IsPressed" Value="True">
  645. <Setter TargetName="btnBorder" Property="Background" Value="{DynamicResource ButtonPressedColor}"></Setter>
  646. <Setter TargetName="btnBorder" Property="BorderBrush" Value="{DynamicResource PrimaryBlueColor}"></Setter>
  647. <Setter Property="Foreground" Value="{DynamicResource PrimaryTextColor}"></Setter>
  648. </Trigger>
  649. </ControlTemplate.Triggers>
  650. </ControlTemplate>
  651. </Setter.Value>
  652. </Setter>
  653. </Style>
  654. <Style x:Key="ExitButtonStyle" TargetType="{x:Type Button}">
  655. <Setter Property="Background" Value="{DynamicResource PrimaryRedColor}"></Setter>
  656. <Setter Property="Foreground" Value="{DynamicResource PrimaryTextColor}"></Setter>
  657. <Setter Property="FontWeight" Value="SemiBold"></Setter>
  658. <Setter Property="Padding" Value="12 6 12 6"></Setter>
  659. <Setter Property="BorderThickness" Value="0"></Setter>
  660. <Setter Property="MaxHeight" Value="70"></Setter>
  661. <Setter Property="Width" Value="auto"></Setter>
  662. <Setter Property="HorizontalContentAlignment" Value="Center"></Setter>
  663. <Setter Property="VerticalContentAlignment" Value="Center"></Setter>
  664. <Setter Property="Template">
  665. <Setter.Value>
  666. <ControlTemplate TargetType="{x:Type Button}">
  667. <Border x:Name="btnBorder" CornerRadius="5"
  668. Background="{TemplateBinding Background}"
  669. Width="{TemplateBinding Width}"
  670. MaxHeight="{TemplateBinding MaxHeight }"
  671. BorderThickness="{TemplateBinding BorderThickness}"
  672. SnapsToDevicePixels="True"
  673. Padding="{TemplateBinding Padding}">
  674. <ContentPresenter x:Name="ContentPresenter" Focusable="False"
  675. HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
  676. VerticalAlignment="{TemplateBinding VerticalContentAlignment}"
  677. Margin="{TemplateBinding Padding}"
  678. SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"></ContentPresenter>
  679. </Border>
  680. <ControlTemplate.Triggers>
  681. <Trigger Property="IsMouseOver" Value="True">
  682. <Setter TargetName="btnBorder" Property="Background" Value="{DynamicResource ButtonMouseOverColorRed}"></Setter>
  683. </Trigger>
  684. <Trigger Property="IsPressed" Value="True">
  685. <Setter TargetName="btnBorder" Property="Background" Value="{DynamicResource ButtonPressedColorRed}"></Setter>
  686. </Trigger>
  687. </ControlTemplate.Triggers>
  688. </ControlTemplate>
  689. </Setter.Value>
  690. </Setter>
  691. </Style>
  692. </Application.Resources>