123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770 |
- /////////////// ОБЩЕЕ //////////////
- internal class BaseClass
- {
- public static CookersShopEntities BD;
- }
- internal class FrameClass
- {
- public static Frame MainFrame;
- public static string loginAutorizate;
- }
- public MainWindow()
- {
- InitializeComponent();
- BaseClass.BD = new CookersShopEntities();
- FrameClass.MainFrame = fMain;
- FrameClass.MainFrame.Navigate(new MainPage());
- }
- <Grid>
- <Grid.RowDefinitions>
-
- <RowDefinition></RowDefinition>
- </Grid.RowDefinitions>
- <Frame Grid.Row="0" Name="fMain" NavigationUIVisibility="Hidden"></Frame>
- </Grid>
- /////////// AUTORIZATE ///////////////
- <Grid>
- <Grid.RowDefinitions>
- <RowDefinition Height="40"></RowDefinition>
- <RowDefinition></RowDefinition>
- </Grid.RowDefinitions>
- <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>
- <StackPanel Grid.Row="1" VerticalAlignment="Center" HorizontalAlignment="Center" Margin="0 -40 0 0">
- <TextBlock FontSize="48" FontFamily="Roboto" HorizontalAlignment="Center" VerticalAlignment="Top" FontWeight="UltraBold">Авторизация</TextBlock>
- <GroupBox Header="Введите логин" Width="270">
- <TextBox Name="tbLogin" MaxLength="25"></TextBox>
- </GroupBox>
- <GroupBox Header="Введите пароль" Width="270">
- <PasswordBox Name="pbPassword" MaxLength="40"></PasswordBox>
- </GroupBox>
- <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>
- </StackPanel>
- </Grid>
- public AutoPage()
- {
- InitializeComponent();
- //На случай сноса админского пароля
- //Users searchUser = BaseClass.BD.Users.FirstOrDefault(x => x.login == "admin");
- //var pass = "admin";
- //searchUser.password = pass.GetHashCode();
- //BaseClass.BD.SaveChanges();
- }
- private void Button_Click(object sender, RoutedEventArgs e)
- {
- FrameClass.MainFrame.Navigate(new MainPage());
- }
- private void bRegistration_Click(object sender, RoutedEventArgs e)
- {
- if (tbLogin.Text == "") MessageBox.Show("Заполните поле логина!", "", MessageBoxButton.OK, MessageBoxImage.Error); // Проверка на заполнение Логина
- else if (pbPassword.Password == "") MessageBox.Show("Заполните поле логина!", "", MessageBoxButton.OK, MessageBoxImage.Error); // Проверка на заполнение Пароля
- else
- {
- int pass = pbPassword.Password.GetHashCode();
- Users searchUser = BaseClass.BD.Users.FirstOrDefault(x => x.login == tbLogin.Text);
- if (searchUser == null) MessageBox.Show("Такого пользователя не существует!", "", MessageBoxButton.OK, MessageBoxImage.Error);
- else
- {
- Users autoUser = BaseClass.BD.Users.FirstOrDefault(x => x.login == tbLogin.Text && x.password == pass);
- if (autoUser == null)
- {
- MessageBox.Show("Неправильно введён пароль!", "", MessageBoxButton.OK, MessageBoxImage.Error);
- }
- else
- {
- switch (autoUser.role)
- {
- // Обычный пользователь (0)
- case 0:
- FrameClass.loginAutorizate = tbLogin.Text;
- FrameClass.MainFrame.Navigate(new mainPageUsers());
- break;
- // Администратор (1)
- case 1:
- FrameClass.loginAutorizate = tbLogin.Text;
- FrameClass.MainFrame.Navigate(new AdminPanel());
- break;
- default: MessageBox.Show("Произошла неизвестная ошибка!\nПерезайдите в приложение!", "Ошибка", MessageBoxButton.OK, MessageBoxImage.Error); break;
- }
- }
- }
- }
- }
- //////////// REGISTRATION CODE //////////////////
- private void bRegistration_Click(object sender, RoutedEventArgs e)
- {
- if (tbName.Text == "") MessageBox.Show("Заполните поле имени!", "", MessageBoxButton.OK, MessageBoxImage.Error);
- else if (tbSurname.Text == "") MessageBox.Show("Заполните поле фамилии!", "", MessageBoxButton.OK, MessageBoxImage.Error);
- else if (tbNumber.Text == "") MessageBox.Show("Заполните поле номера телефона!", "", MessageBoxButton.OK, MessageBoxImage.Error);
- else if (tbLogin.Text == "") MessageBox.Show("Заполните поле логина!", "", MessageBoxButton.OK, MessageBoxImage.Error);
- else if (pbPassword.Password == "") MessageBox.Show("Заполните поле пароля!", "", MessageBoxButton.OK, MessageBoxImage.Error);
- else if (rbMan.IsChecked != true && rbWoman.IsChecked != true) MessageBox.Show("Убедитесь, что Вы выбрали пол!", "", MessageBoxButton.OK, MessageBoxImage.Error);
- else if (tbNumber.Text.Length != 11) MessageBox.Show("Проверьте правильность введенного номера телефона!\nПримеры правильного формата:\n • 79101426789\n • 89101426789", "", MessageBoxButton.OK, MessageBoxImage.Error);
- else
- {
- string checkPassword = pbPassword.Password;
- Users searchUser = BaseClass.BD.Users.FirstOrDefault(x => x.login == tbLogin.Text);
- if (searchUser != null) MessageBox.Show("Такой пользователь уже существует!", "", MessageBoxButton.OK, MessageBoxImage.Error);
- else if (CheckPass(checkPassword) == false)
- MessageBox.Show("Ваш пароль очень простой!", "", MessageBoxButton.OK, MessageBoxImage.Error);
- else
- {
- int tempGender = 0;
- if (rbMan.IsChecked == true)
- tempGender = 1;
- if (rbWoman.IsChecked == true)
- tempGender = 2;
- Users user = new Users()
- {
- name_user = tbName.Text,
- surname_user = tbSurname.Text,
- gender = tempGender,
- login = tbLogin.Text,
- password = pbPassword.Password.GetHashCode(),
- phone = tbNumber.Text,
- date_reg = Convert.ToDateTime(DateTime.Today),
- role = 0,
- privilege = null
- };
- BaseClass.BD.Users.Add(user);
- BaseClass.BD.SaveChanges();
- MessageBox.Show("Вы зарегистрировались!");
- FrameClass.MainFrame.Navigate(new AutoPage());
- }
- }
- }
- ////////////// INPUT PRODUCT XAML ///////////////
- <Page.Resources>
- <BitmapImage x:Key="noimage" UriSource="/Resources/noimage.png"/>
- </Page.Resources>
- <Grid>
- <Grid.RowDefinitions>
- <RowDefinition Height="40"></RowDefinition>
- <RowDefinition Height="370"></RowDefinition>
- <RowDefinition Height="40"></RowDefinition>
- </Grid.RowDefinitions>
- <TextBlock Grid.Row="0" FontSize="28" HorizontalAlignment="Center" VerticalAlignment="Top" FontFamily="Roboto" FontWeight="Bold">Товар</TextBlock>
- <StackPanel Orientation="Horizontal" VerticalAlignment="Top" HorizontalAlignment="Right">
- <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>
- <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>
- </StackPanel>
- <ListView Grid.Row="1" Name="listProduct" ScrollViewer.HorizontalScrollBarVisibility="Disabled">
- <ListView.ItemsPanel>
- <ItemsPanelTemplate>
- <WrapPanel HorizontalAlignment="Center"></WrapPanel>
- </ItemsPanelTemplate>
- </ListView.ItemsPanel>
- <ListView.ItemTemplate>
- <DataTemplate>
- <Border Padding="5" CornerRadius="5" BorderThickness="1" BorderBrush="#304FFE">
- <Grid Name="gridProduct" Width="250" Height="auto">
- <StackPanel>
- <TextBlock FontFamily="Roboto" Text="{Binding name}" FontSize="16" FontWeight="Bold" TextDecorations="{x:Null}"/>
- <Image Width="100" Height="100" Source="{Binding image_product, TargetNullValue={StaticResource noimage}}" HorizontalAlignment="Center" VerticalAlignment="Center"/>
- <TextBlock FontFamily="Roboto" Text="{Binding Manufacturers.manufacturer_name, StringFormat=Производитель: {0}}" FontSize="14"/>
- <TextBlock Uid="{Binding product_code}" Name="price" Loaded="price_Loaded" FontFamily="Roboto" FontSize="14"></TextBlock>
- <TextBlock Text="{Binding amount, StringFormat=Количество: {0}}" FontFamily="Roboto" FontSize="14"/>
- <TextBlock Uid="{Binding product_code}" Name="ratingProduct" Loaded="rate_Loaded" FontFamily="Roboto" FontSize="18"/>
- <StackPanel HorizontalAlignment="Right" VerticalAlignment="Bottom" Orientation="Horizontal">
- <Button Uid="{Binding product_code}" Style="{DynamicResource AcceptButtonStyle}" Margin="3" FontSize="12" FontFamily="Roboto" FontWeight="DemiBold" Padding="2" Click="Button_Click_1">Изменить</Button>
- <Button Uid="{Binding product_code}" Style="{DynamicResource ExitButtonStyle}" Margin="3" FontSize="12" FontFamily="Roboto" FontWeight="DemiBold" Padding="2" Click="Button_Click">Удалить</Button>
- </StackPanel>
- </StackPanel>
- </Grid>
- </Border>
- </DataTemplate>
- </ListView.ItemTemplate>
- </ListView>
- <WrapPanel Grid.Row="2">
- <StackPanel Orientation="Horizontal" Grid.Row="2" HorizontalAlignment="Left" VerticalAlignment="Center" Margin="10 0 45 0">
- <TextBlock Text="Общая сумма товаров: " FontSize="14" FontFamily="Roboto" FontWeight="DemiBold" Loaded="TextBlock_Loaded"></TextBlock>
- </StackPanel>
- <StackPanel Orientation="Vertical" Height="40" HorizontalAlignment="Left" Margin="15 0 0 0">
- <TextBlock Text="Фильтр" HorizontalAlignment="Center" FontFamily="Roboto" FontSize="12" Margin="0 0 0 2"></TextBlock>
- <StackPanel Orientation="Horizontal" Height="20" HorizontalAlignment="Center" Margin="0 0 0 0">
- <ComboBox x:Name="Filter" Height="20" Width="120" VerticalContentAlignment="Center" Margin="0 0 0 0" FontSize="12" SelectionChanged="Filter_SelectionChanged">
- <Label Content="Все товары" FontFamily="Roboto" FontSize="12"/>
- <Label Content="Со скидкой" FontFamily="Roboto" FontSize="12"/>
- <Label Content="Без скидок" FontFamily="Roboto" FontSize="12"/>
- </ComboBox>
- <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>
- <TextBox x:Name="Search" Width="150" Margin="10 0 0 0" FontFamily="Roboto" FontSize="12" TextChanged="Search_TextChanged"></TextBox>
- </StackPanel>
- </StackPanel>
- <StackPanel Orientation="Vertical" Height="40" HorizontalAlignment="Left" Margin="15 0 0 0">
- <TextBlock Text="Сортировка" HorizontalAlignment="Center" FontFamily="Roboto" FontSize="12" Margin="0 0 0 2"></TextBlock>
- <ComboBox x:Name="Sortirovka" Height="20" Width="120" VerticalContentAlignment="Center" Margin="0 0 0 0" FontSize="12" SelectionChanged="Sortirovka_SelectionChanged">
- <Label Content="По умолчанию" FontFamily="Roboto" FontSize="12"/>
- <Label Content="По возрастанию цены" FontFamily="Roboto" FontSize="12"/>
- <Label Content="По убыванию цены" FontFamily="Roboto" FontSize="12"/>
- </ComboBox>
- </StackPanel>
- </WrapPanel>
- </Grid>
- ////////////// INPUT PRODUCT CODE ///////////////
- public aListProduct()
- {
- InitializeComponent();
- listProduct.ItemsSource = BaseClass.BD.Products.ToList();
- Filter.SelectedIndex = 0;
- Sortirovka.SelectedIndex = 0;
- }
- private void BackMain_Click(object sender, RoutedEventArgs e)
- {
- FrameClass.MainFrame.Navigate(new AdminPanel());
- }
- private void Button_Click(object sender, RoutedEventArgs e)
- {
- Button btn = (Button)sender;
- int index = Convert.ToInt32(btn.Uid);
- Products products = BaseClass.BD.Products.FirstOrDefault(x => x.product_code == index);
- BaseClass.BD.Products.Remove(products);
- BaseClass.BD.SaveChanges();
- FrameClass.MainFrame.Navigate(new aListProduct());
- }
- private void price_Loaded(object sender, RoutedEventArgs e)
- {
- TextBlock tb = (TextBlock)sender;
- int index = Convert.ToInt32(tb.Uid);
- int disc = 0;
- int price = 0;
- List<Products> DC = BaseClass.BD.Products.Where(x => x.product_code == index).ToList();
- foreach(Products Product in DC)
- {
- disc = Convert.ToInt32(Product.discount);
- price = Convert.ToInt32(Product.price);
- }
- if(disc <=0)
- tb.Text = "Цена: " + price.ToString() + "₽";
- if(disc > 0)
- {
- price = price * (100 - disc) / 100;
- tb.Text = "Цена: " + price.ToString() + "₽";
- tb.FontWeight = FontWeights.Bold;
- tb.Foreground = Brushes.Red;
- }
- }
- private void rate_Loaded(object sender, RoutedEventArgs e)
- {
- TextBlock tb = (TextBlock)sender;
- int index = Convert.ToInt32(tb.Uid);
- int rateID = 0;
- List<Products> DC = BaseClass.BD.Products.Where(x => x.product_code == index).ToList();
- foreach (Products Product in DC)
- rateID = Convert.ToInt32(Product.rate);
- List<Ratings> RN = BaseClass.BD.Ratings.Where(x => x.rate == rateID).ToList();
- foreach (Ratings Ratings in RN)
- {
- if (Ratings.rating == 5)
- tb.Text = "★★★★★";
- else if (Ratings.rating == 4)
- tb.Text = "★★★★";
- else if (Ratings.rating == 3)
- tb.Text = "★★★";
- else if (Ratings.rating == 2)
- tb.Text = "★★";
- else if (Ratings.rating == 1)
- tb.Text = "★";
- else
- {
- tb.Text = "Рейтинг: 0";
- tb.Foreground = Brushes.DarkGray;
- }
- tb.Foreground = Brushes.DarkOrange;
- }
- }
- private void TextBlock_Loaded(object sender, RoutedEventArgs e)
- {
- TextBlock tb = (TextBlock)sender;
- int allSumProduct = 0;
- List<Products> DC = BaseClass.BD.Products.ToList();
- foreach (Products Product in DC)
- allSumProduct += Convert.ToInt32(Product.price * Product.amount);
- tb.Text = "Общая сумма товаров\n(без учета скидок): " + allSumProduct.ToString();
- }
- private void Button_Click_1(object sender, RoutedEventArgs e)
- {
- Button btn = (Button)sender;
- int index = Convert.ToInt32(btn.Uid);
- Products product = BaseClass.BD.Products.FirstOrDefault(x => x.product_code == index);
- FrameClass.MainFrame.Navigate(new UpdateProduct(product));
- }
- private void AddProduct_Click(object sender, RoutedEventArgs e)
- {
- FrameClass.MainFrame.Navigate(new UpdateProduct());
- }
- void SearchMainMethod()
- {
- string strSearch = Search.Text.ToLower();
- var regexSearch = new Regex($@"(^({strSearch}).*)");
- if (Sortirovka.SelectedIndex == 0)
- {
- if (cbFilter.IsChecked == true)
- {
- if (Filter.SelectedIndex == 0)
- {
- listProduct.ItemsSource = BaseClass.BD.Products.ToList().Where(x => regexSearch.IsMatch(x.name.ToLower()) == true && x.rate != null);
- }
- else if (Filter.SelectedIndex == 1)
- {
- listProduct.ItemsSource = BaseClass.BD.Products.ToList().Where(x => regexSearch.IsMatch(x.name.ToLower()) == true && x.discount > 0 && x.rate != null);
- }
- else
- {
- listProduct.ItemsSource = BaseClass.BD.Products.ToList().Where(x => regexSearch.IsMatch(x.name.ToLower()) == true && x.discount == 0 && x.rate != null);
- }
- }
- else
- {
- if (Filter.SelectedIndex == 0)
- {
- listProduct.ItemsSource = BaseClass.BD.Products.ToList().Where(x => regexSearch.IsMatch(x.name.ToLower()) == true);
- }
- else if (Filter.SelectedIndex == 1)
- {
- listProduct.ItemsSource = BaseClass.BD.Products.ToList().Where(x => regexSearch.IsMatch(x.name.ToLower()) == true && x.discount > 0);
- }
- else
- {
- listProduct.ItemsSource = BaseClass.BD.Products.ToList().Where(x => regexSearch.IsMatch(x.name.ToLower()) == true && x.discount == 0);
- }
- }
- }
- else if (Sortirovka.SelectedIndex == 1)
- {
- if (cbFilter.IsChecked == true)
- {
- if (Filter.SelectedIndex == 0)
- {
- 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);
- }
- else if (Filter.SelectedIndex == 1)
- {
- 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);
- }
- else
- {
- 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);
- }
- }
- else
- {
- if (Filter.SelectedIndex == 0)
- {
- listProduct.ItemsSource = BaseClass.BD.Products.OrderBy(x => x.price * (100 - x.discount) / 100).ToList().Where(x => regexSearch.IsMatch(x.name.ToLower()) == true);
- }
- else if (Filter.SelectedIndex == 1)
- {
- 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);
- }
- else
- {
- 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);
- }
- }
- }
- else if (Sortirovka.SelectedIndex == 2)
- {
- if (cbFilter.IsChecked == true)
- {
- if (Filter.SelectedIndex == 0)
- {
- 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);
- }
- else if (Filter.SelectedIndex == 1)
- {
- 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);
- }
- else
- {
- 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);
- }
- }
- else
- {
- if (Filter.SelectedIndex == 0)
- {
- listProduct.ItemsSource = BaseClass.BD.Products.OrderByDescending(x => x.price * (100 - x.discount) / 100).ToList().Where(x => regexSearch.IsMatch(x.name.ToLower()) == true);
- }
- else if (Filter.SelectedIndex == 1)
- {
- 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);
- }
- else
- {
- 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);
- }
- }
- }
- }
- ///////////// GRID INPUT XAML //////////////////
- <Grid>
- <Grid.RowDefinitions>
- <RowDefinition Height="40"></RowDefinition>
- <RowDefinition Height="370"></RowDefinition>
- <RowDefinition Height="40"></RowDefinition>
- </Grid.RowDefinitions>
- <TextBlock Grid.Row="0" FontSize="28" HorizontalAlignment="Center" VerticalAlignment="Top" FontFamily="Roboto" FontWeight="Bold">Пользователи</TextBlock>
- <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>
- <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">
- <DataGrid.Columns>
- <DataGridTextColumn Header="Логин" Binding="{Binding login}" Width="auto"></DataGridTextColumn>
- <DataGridTextColumn Header="Имя" Binding="{Binding name_user}" Width="*"></DataGridTextColumn>
- <DataGridTextColumn Header="Фамилия" Binding="{Binding surname_user}" Width="*"></DataGridTextColumn>
- <DataGridTextColumn Header="Пол" Binding="{Binding Genders.name_gender}" Width="75"></DataGridTextColumn>
- <DataGridTextColumn Header="Номер" Binding="{Binding phone}" Width="80"></DataGridTextColumn>
- <DataGridTextColumn Header="Дата регистрации" Binding="{Binding date_reg, StringFormat=dd.MM.yyyy}" Width="*"></DataGridTextColumn>
- <DataGridTextColumn Header="Привилегия" Binding="{Binding Privilage.name_privilage}" Width="78"></DataGridTextColumn>
- <DataGridTextColumn Header="Роль" Binding="{Binding Roles.name_role}" Width="*"></DataGridTextColumn>
- </DataGrid.Columns>
- </DataGrid>
- <WrapPanel Grid.Row="2">
- <StackPanel Orientation="Vertical" Height="40" HorizontalAlignment="Left" Margin="15 0 0 0">
- <TextBlock Text="Сортировка по фамилии" HorizontalAlignment="Center" FontFamily="Roboto" FontSize="12" Margin="0 0 0 2"></TextBlock>
- <ComboBox x:Name="VozrastYbivan" Height="20" Width="120" VerticalContentAlignment="Center" Margin="0 0 0 0" SelectionChanged="VozrastYbivan_SelectionChanged" FontSize="12">
- <Label Content="По умолчанию" FontFamily="Roboto" FontSize="12"/>
- <Label Content="По возрастанию" FontFamily="Roboto" FontSize="12"/>
- <Label Content="По убыванию" FontFamily="Roboto" FontSize="12"/>
- </ComboBox>
- </StackPanel>
- <StackPanel Orientation="Horizontal" Height="40" HorizontalAlignment="Left" Margin="15 0 0 0">
- <TextBox x:Name="Search" Width="150" Height="25" VerticalContentAlignment="Center" TextChanged="Search_TextChanged"></TextBox>
- <StackPanel HorizontalAlignment="Center" Margin="10 0 0 0">
- <TextBlock Text="Фильтровать по полю" HorizontalAlignment="Center" FontFamily="Roboto" FontSize="12" Margin="0 0 0 2"></TextBlock>
- <ComboBox x:Name="typeSearch" Height="20" Width="80" VerticalContentAlignment="Center" Margin="0 0 0 0" FontSize="12" SelectionChanged="typeSearch_SelectionChanged">
- <Label Content="Имя" FontFamily="Roboto" FontSize="12"/>
- <Label Content="Фамилия" FontFamily="Roboto" FontSize="12"/>
- </ComboBox>
- </StackPanel>
- </StackPanel>
- <StackPanel Orientation="Vertical" Width="150" VerticalAlignment="Center" Margin="10 0 0 0">
- <TextBlock Text="Фильтрация по полу" HorizontalAlignment="Center" FontFamily="Roboto" FontSize="14"></TextBlock>
- <StackPanel Orientation="Horizontal" HorizontalAlignment="Center">
- <CheckBox Name="rbMan" Content="Мужской" FontFamily="Roboto" Checked="rbMan_Checked" Unchecked="rbMan_Unchecked"></CheckBox>
- <CheckBox Name="rbWoman" Content="Женский" FontFamily="Roboto" Margin="10 0 0 0" Checked="rbWoman_Checked" Unchecked="rbWoman_Unchecked"></CheckBox>
- </StackPanel>
- </StackPanel>
- <StackPanel Orientation="Vertical" Height="25" Width="70" Margin=" 15 10 0 0">
- <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>
- </StackPanel>
- </WrapPanel>
- </Grid>
- //////////////////// GRID INPUT CODE ////////////////
- public aListUser()
- {
- InitializeComponent();
- dgUser.ItemsSource = BaseClass.BD.Users.ToList();
- typeSearch.SelectedIndex = 0;
- VozrastYbivan.SelectedIndex = 0;
- }
- private void BackMain_Click(object sender, RoutedEventArgs e)
- {
- FrameClass.MainFrame.Navigate(new AdminPanel());
- }
- private void Search_TextChanged(object sender, TextChangedEventArgs e)
- {
- SearchMainMethod();
- }
- private void ButtonRefresh_Click(object sender, RoutedEventArgs e)
- {
- rbWoman.IsChecked = false;
- rbMan.IsChecked = false;
- Search.Clear();
- VozrastYbivan.SelectedIndex = 0;
- typeSearch.SelectedIndex = 0;
- dgUser.ItemsSource = BaseClass.BD.Users.ToList();
- }
- //////////// UPDATE PRODUCT /////////////
- Products PRODUCT;
- bool flagUpdate = false;
- string path;
- public void uploadFields()
- {
- cbManufacturer.ItemsSource = BaseClass.BD.Manufacturers.ToList();
- cbManufacturer.SelectedValuePath = "manufacturer_code";
- cbManufacturer.DisplayMemberPath = "manufacturer_name";
- cbManufacturer.SelectedIndex = 0;
- tbDiscount.Text = "0";
- }
- public UpdateProduct()
- {
- InitializeComponent();
- uploadFields();
- }
- public UpdateProduct(Products product)
- {
- InitializeComponent();
- uploadFields();
- flagUpdate = true;
- PRODUCT = product;
- tbName.Text = PRODUCT.name;
- tbPrice.Text = Convert.ToString(PRODUCT.price);
- tbAmount.Text = Convert.ToString(PRODUCT.amount);
- cbManufacturer.SelectedIndex = PRODUCT.manufacturer_code - 1;
- tbDescription.Text = PRODUCT.description;
- tbDiscount.Text = Convert.ToString(PRODUCT.discount);
- if (product.image_product != null)
- {
- BitmapImage img = new BitmapImage(new Uri(product.image_product, UriKind.RelativeOrAbsolute));
- imgProduct.Source = img;
- }
- }
- private void BackMain_Click(object sender, RoutedEventArgs e)
- {
- FrameClass.MainFrame.Navigate(new aListProduct());
- }
- private void bRegistration_Click(object sender, RoutedEventArgs e)
- {
- try
- {
- if (flagUpdate == false)
- {
- PRODUCT = new Products();
- }
- PRODUCT.name = tbName.Text;
- PRODUCT.description = tbDescription.Text;
- PRODUCT.price = Convert.ToInt32(tbPrice.Text);
- PRODUCT.amount = Convert.ToInt32(tbAmount.Text);
- PRODUCT.manufacturer_code = cbManufacturer.SelectedIndex + 1;
- PRODUCT.discount = Convert.ToInt32(tbDiscount.Text);
- if (path!= null)
- {
- PRODUCT.image_product = path;
- }
- if (flagUpdate == false)
- {
- BaseClass.BD.Products.Add(PRODUCT);
- }
- BaseClass.BD.SaveChanges();
- MessageBox.Show("Информация добавлена");
- }
- catch
- {
- MessageBox.Show("Что-то пошло не по плану");
- }
- }
- private void bSavePhoto_Click(object sender, RoutedEventArgs e)
- {
- try
- {
- OpenFileDialog OFD = new OpenFileDialog();
- OFD.ShowDialog();
- path = OFD.FileName;
- string[] arrayPath = path.Split('\\');
- path = "\\" + arrayPath[arrayPath.Length - 2] + "\\" + arrayPath[arrayPath.Length - 1];
- BitmapImage bi3 = new BitmapImage();
- bi3.BeginInit();
- bi3.UriSource = new Uri("\\Resources\\icons8-new-100.png", UriKind.Relative);
- bi3.EndInit();
- imgProduct.Source = bi3;
- }
- catch { }
- }
- /////////// СТИЛИ /////////////
- <Application.Resources>
- <SolidColorBrush x:Key="PrimaryBlueColor" Color="#304FFE"></SolidColorBrush>
- <SolidColorBrush x:Key="PrimaryTextColor" Color="White"></SolidColorBrush>
- <SolidColorBrush x:Key="ButtonMouseOverColor" Color="#0026CA"></SolidColorBrush>
- <SolidColorBrush x:Key="ButtonPressedColor" Color="#7a7cff"></SolidColorBrush>
- <SolidColorBrush x:Key="PrimaryDarkTextColor" Color="#0026ca"></SolidColorBrush>
- <SolidColorBrush x:Key="ButtonBorderBrushColor" Color="#0026ca"></SolidColorBrush>
- <SolidColorBrush x:Key="PrimaryRedColor" Color="#f21818"></SolidColorBrush>
- <SolidColorBrush x:Key="ButtonMouseOverColorRed" Color="#de1414"></SolidColorBrush>
- <SolidColorBrush x:Key="ButtonPressedColorRed" Color="#f05454"></SolidColorBrush>
- <Style x:Key="AcceptButtonStyle" TargetType="{x:Type Button}">
- <Setter Property="Background" Value="{DynamicResource PrimaryBlueColor}"></Setter>
- <Setter Property="Foreground" Value="{DynamicResource PrimaryTextColor}"></Setter>
- <Setter Property="FontWeight" Value="SemiBold"></Setter>
- <Setter Property="Padding" Value="12 6 12 6"></Setter>
- <Setter Property="BorderThickness" Value="0"></Setter>
- <Setter Property="MaxHeight" Value="70"></Setter>
- <Setter Property="Width" Value="auto"></Setter>
- <Setter Property="HorizontalContentAlignment" Value="Center"></Setter>
- <Setter Property="VerticalContentAlignment" Value="Center"></Setter>
- <Setter Property="Template">
- <Setter.Value>
- <ControlTemplate TargetType="{x:Type Button}">
- <Border x:Name="btnBorder" CornerRadius="5"
- Background="{TemplateBinding Background}"
- Width="{TemplateBinding Width}"
- MaxHeight="{TemplateBinding MaxHeight }"
- BorderThickness="{TemplateBinding BorderThickness}"
- SnapsToDevicePixels="True"
- Padding="{TemplateBinding Padding}">
- <ContentPresenter x:Name="ContentPresenter" Focusable="False"
- HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
- VerticalAlignment="{TemplateBinding VerticalContentAlignment}"
- Margin="{TemplateBinding Padding}"
- SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"></ContentPresenter>
- </Border>
- <ControlTemplate.Triggers>
- <Trigger Property="IsMouseOver" Value="True">
- <Setter TargetName="btnBorder" Property="Background" Value="{DynamicResource ButtonMouseOverColor}"></Setter>
- </Trigger>
- <Trigger Property="IsPressed" Value="True">
- <Setter TargetName="btnBorder" Property="Background" Value="{DynamicResource ButtonPressedColor}"></Setter>
- </Trigger>
- </ControlTemplate.Triggers>
- </ControlTemplate>
- </Setter.Value>
- </Setter>
- </Style>
- <Style x:Key="MainButtonStyle" TargetType="{x:Type Button}">
- <Setter Property="Background" Value="Transparent"></Setter>
- <Setter Property="BorderBrush" Value="{DynamicResource PrimaryBlueColor}"></Setter>
- <Setter Property="Foreground" Value="{DynamicResource PrimaryBlueColor}"></Setter>
- <Setter Property="FontWeight" Value="ExtraBold"></Setter>
- <Setter Property="Padding" Value="11 5.2"></Setter>
- <Setter Property="BorderThickness" Value="2"></Setter>
- <Setter Property="MaxHeight" Value="70"></Setter>
- <Setter Property="Width" Value="auto"></Setter>
- <Setter Property="HorizontalContentAlignment" Value="Center"></Setter>
- <Setter Property="VerticalContentAlignment" Value="Center"></Setter>
- <Setter Property="Template">
- <Setter.Value>
- <ControlTemplate TargetType="{x:Type Button}">
- <Border x:Name="btnBorder" CornerRadius="5"
- Background="{TemplateBinding Background}"
- Width="{TemplateBinding Width}"
- BorderBrush="{TemplateBinding BorderBrush}"
- MaxHeight="{TemplateBinding MaxHeight }"
- BorderThickness="{TemplateBinding BorderThickness}"
- SnapsToDevicePixels="True"
- Padding="{TemplateBinding Padding}">
- <ContentPresenter x:Name="ContentPresenter" Focusable="False"
- HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
- VerticalAlignment="{TemplateBinding VerticalContentAlignment}"
- Margin="{TemplateBinding Padding}"
- SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"></ContentPresenter>
- </Border>
- <ControlTemplate.Triggers>
- <Trigger Property="IsMouseOver" Value="True">
- <Setter TargetName="btnBorder" Property="Background" Value="{DynamicResource ButtonMouseOverColor}"></Setter>
- <Setter TargetName="btnBorder" Property="BorderBrush" Value="{DynamicResource PrimaryBlueColor}"></Setter>
- <Setter Property="Foreground" Value="{DynamicResource PrimaryTextColor}"></Setter>
- </Trigger>
- <Trigger Property="IsPressed" Value="True">
- <Setter TargetName="btnBorder" Property="Background" Value="{DynamicResource ButtonPressedColor}"></Setter>
- <Setter TargetName="btnBorder" Property="BorderBrush" Value="{DynamicResource PrimaryBlueColor}"></Setter>
- <Setter Property="Foreground" Value="{DynamicResource PrimaryTextColor}"></Setter>
- </Trigger>
- </ControlTemplate.Triggers>
- </ControlTemplate>
- </Setter.Value>
- </Setter>
- </Style>
- <Style x:Key="ExitButtonStyle" TargetType="{x:Type Button}">
- <Setter Property="Background" Value="{DynamicResource PrimaryRedColor}"></Setter>
- <Setter Property="Foreground" Value="{DynamicResource PrimaryTextColor}"></Setter>
- <Setter Property="FontWeight" Value="SemiBold"></Setter>
- <Setter Property="Padding" Value="12 6 12 6"></Setter>
- <Setter Property="BorderThickness" Value="0"></Setter>
- <Setter Property="MaxHeight" Value="70"></Setter>
- <Setter Property="Width" Value="auto"></Setter>
- <Setter Property="HorizontalContentAlignment" Value="Center"></Setter>
- <Setter Property="VerticalContentAlignment" Value="Center"></Setter>
- <Setter Property="Template">
- <Setter.Value>
- <ControlTemplate TargetType="{x:Type Button}">
- <Border x:Name="btnBorder" CornerRadius="5"
- Background="{TemplateBinding Background}"
- Width="{TemplateBinding Width}"
- MaxHeight="{TemplateBinding MaxHeight }"
- BorderThickness="{TemplateBinding BorderThickness}"
- SnapsToDevicePixels="True"
- Padding="{TemplateBinding Padding}">
- <ContentPresenter x:Name="ContentPresenter" Focusable="False"
- HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
- VerticalAlignment="{TemplateBinding VerticalContentAlignment}"
- Margin="{TemplateBinding Padding}"
- SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"></ContentPresenter>
- </Border>
- <ControlTemplate.Triggers>
- <Trigger Property="IsMouseOver" Value="True">
- <Setter TargetName="btnBorder" Property="Background" Value="{DynamicResource ButtonMouseOverColorRed}"></Setter>
- </Trigger>
- <Trigger Property="IsPressed" Value="True">
- <Setter TargetName="btnBorder" Property="Background" Value="{DynamicResource ButtonPressedColorRed}"></Setter>
- </Trigger>
- </ControlTemplate.Triggers>
- </ControlTemplate>
- </Setter.Value>
- </Setter>
- </Style>
- </Application.Resources>
|