Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <Page
- xmlns:materialDesign="http://materialdesigninxaml.net/winfx/xaml/themes"
- xml:lang="ru-RU"
- TextElement.Foreground="{DynamicResource MaterialDesignBody}"
- TextElement.FontWeight="Regular"
- TextElement.FontSize="12"
- TextOptions.TextFormattingMode="Ideal"
- TextOptions.TextRenderingMode="Auto"
- Background="{DynamicResource MaterialDesignPaper}"
- FontFamily="{DynamicResource MaterialDesignFont}"
- xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
- xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
- xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
- xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
- xmlns:local="clr-namespace:IgrushkiShop.Pages"
- xmlns:Models="clr-namespace:IgrushkiShop.Models" x:Class="IgrushkiShop.Pages.ProductsPage"
- mc:Ignorable="d"
- Title="ProductsPage">
- <Page.Resources>
- <CollectionViewSource x:Key="productViewSource" d:DesignSource="{d:DesignInstance {x:Type Models:Product}, CreateList=True}"/>
- </Page.Resources>
- <Grid DataContext="{StaticResource productViewSource}">
- <Button Content="Добавить" HorizontalAlignment="Left" Margin="10,0,0,10" VerticalAlignment="Bottom" Width="103" Click="Button_Click"/>
- <Button Content="Удалить" HorizontalAlignment="Right" Margin="0,0,118,10" Width="93" Height="32" VerticalAlignment="Bottom" Click="Button_Click_1"/>
- <Button Content="Изменить" HorizontalAlignment="Right" Margin="0,0,10,10" VerticalAlignment="Bottom" Width="103" Click="Button_Click_2"/>
- <TextBox x:Name="SearchTb" HorizontalAlignment="Right" Height="23" Margin="0,10,10,0" TextChanged="TextBox_TextChanged" VerticalAlignment="Top" Width="144"/>
- <DataGrid CanUserAddRows="False" x:Name="productDataGrid" AutoGenerateColumns="False" EnableRowVirtualization="True" ItemsSource="{Binding}" Margin="10,38,10,47" RowDetailsVisibilityMode="VisibleWhenSelected">
- <DataGrid.Columns>
- <DataGridTextColumn x:Name="nameColumn" Binding="{Binding Name}" Header="Наименование" Width="*" IsReadOnly="True"/>
- <DataGridTextColumn x:Name="costColumn" Binding="{Binding Cost}" Header="Цена" Width="*" IsReadOnly="True"/>
- <DataGridTextColumn x:Name="allCategsColumn" Binding="{Binding AllCategs}" Header="Категории" Width="*" IsReadOnly="True"/>
- <DataGridTextColumn x:Name="descriptionColumn" Binding="{Binding Description}" Header="Описание" Width="*" IsReadOnly="True"/>
- <DataGridTextColumn x:Name="maxSell" Binding="{Binding CostWithSell}" Header="Цена со скидкой" Width="*" IsReadOnly="True"/>
- </DataGrid.Columns>
- </DataGrid>
- <Label Content="Поиск:" HorizontalAlignment="Right" VerticalAlignment="Top" Margin="0,9,159,0"/>
- </Grid>
- </Page>
- using IgrushkiShop.Models;
- using IgrushkiShop.Views;
- using System;
- using System.Collections.Generic;
- using System.Collections.ObjectModel;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.Windows;
- using System.Windows.Controls;
- using System.Windows.Data;
- using System.Windows.Documents;
- using System.Windows.Input;
- using System.Windows.Media;
- using System.Windows.Media.Imaging;
- using System.Windows.Navigation;
- using System.Windows.Shapes;
- namespace IgrushkiShop.Pages
- {
- /// <summary>
- /// Логика взаимодействия для ProductsPage.xaml
- /// </summary>
- public partial class ProductsPage : Page, System.ComponentModel.INotifyPropertyChanged
- {
- private ObservableCollection<Product> _Data = new ObservableCollection<Product>();
- public ObservableCollection<Product> Data
- {
- get => _Data;
- set
- {
- if (_Data != value)
- {
- _Data = value;
- OnPropertyChanged("Data");
- }
- }
- }
- #region INotRel
- public event System.ComponentModel.PropertyChangedEventHandler PropertyChanged;
- public void OnPropertyChanged([System.Runtime.CompilerServices.CallerMemberName] string name = "") => PropertyChanged?.Invoke(this, new System.ComponentModel.PropertyChangedEventArgs(name));
- #endregion
- public ProductsPage()
- {
- InitializeComponent();
- productDataGrid.ItemsSource = Data;
- Refresh();
- }
- void Refresh(string text = "")
- {
- Data.Clear();
- if (text == "")
- MainWindow.Ent.Product.Select(x => x).ToList().ForEach((asd) => Data.Add(asd));
- else
- MainWindow.Ent.Product.Where(x => x.Name.ToLower().Contains(text.ToLower())).ToList().ForEach((asd) => Data.Add(asd));
- }
- private void TextBox_TextChanged(object sender, TextChangedEventArgs e)
- {
- if (string.IsNullOrWhiteSpace((sender as TextBox).Text))
- Refresh();
- else
- Refresh((sender as TextBox).Text);
- }
- private void Button_Click(object sender, RoutedEventArgs e)
- {
- ProductView subs = new ProductView();
- subs.Closed += (asd, dsa) =>
- {
- SearchTb.Text = "&";
- SearchTb.Text = "";
- };
- subs.ShowDialog();
- }
- private void Button_Click_1(object sender, RoutedEventArgs e)
- {
- if (productDataGrid.SelectedItem == null)
- {
- MessageBox.Show("Не выбран элемент для удаления!");
- return;
- }
- var Subject = productDataGrid.SelectedItem as Product;
- if (MessageBox.Show("Вы уверены что хотите удалить данный элемент?", "Внимание!", MessageBoxButton.YesNo) == MessageBoxResult.Yes)
- {
- try
- {
- MainWindow.Ent.Product.Remove(Subject);
- MainWindow.Ent.SaveChanges();
- SearchTb.Text = "&";
- SearchTb.Text = "";
- }
- catch
- {
- MessageBox.Show("Произошла ошибка удаления!");
- }
- }
- }
- private void Button_Click_2(object sender, RoutedEventArgs e)
- {
- if (productDataGrid.SelectedItem == null)
- {
- MessageBox.Show("Не выбран элемент для изменения!");
- return;
- }
- var Subject = productDataGrid.SelectedItem as Product;
- ProductView subs = new ProductView(Subject);
- subs.Closed += (asd, dsa) =>
- {
- SearchTb.Text = "&";
- SearchTb.Text = "";
- };
- subs.ShowDialog();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement