Žiadny popis

1 f9436ed81a 1 1 mesiac pred
.vs f9436ed81a 1 1 mesiac pred
foto f9436ed81a 1 1 mesiac pred
scrs f9436ed81a 1 1 mesiac pred
wpf_connection3 f9436ed81a 1 1 mesiac pred
readme.md f9436ed81a 1 1 mesiac pred
wpf_connection3.sln f9436ed81a 1 1 mesiac pred

readme.md

Mainwindow.xaml.cs

using System.ComponentModel;
using System.Security.Cryptography.X509Certificates;
using System.Text;
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;
using Dapper;
using MySqlConnector;
using wpf_connection3.Windows;

namespace wpf_connection3
{


    public partial class MainWindow : Window,
        INotifyPropertyChanged



    {

        private int _currentPage = 1;
        public int currentPage
        { get
            {
                return _currentPage;
            }

            set
            {
                _currentPage = value;
                Invalidate("productList");
            }
        }

        public List<string> pageList { get; set; } = new List<string>();
        private int productCount;


        public IEnumerable<Product> productList
        {
            get
            {
                switch (sortType)
                {
                    case 0:
                        Globals.dataProvider.setOrder("");
                        break;
                    case 1:
                        Globals.dataProvider.setOrder("Title");
                        break;
                    case 2:
                        Globals.dataProvider.setOrder("Title DESC");
                        break;
                    case 3:
                        Globals.dataProvider.setOrder("ProductionWorkshopNumber");
                        break;
                    case 4:
                        Globals.dataProvider.setOrder("ProductionWorkshopNumber DESC");
                        break;
                    case 5:
                        Globals.dataProvider.setOrder("MaterialCost");
                        break;
                    case 6:
                        Globals.dataProvider.setOrder("MaterialCost DESC");
                        break;
                }
                Globals.dataProvider.clearFilter();
                if (productTypeFilterId > 0)
                    Globals.dataProvider.addFilter(
                        "ProductTypeID = @ProductTypeID",
                        new { ProductTypeID = productTypeFilterId }
                    );
                if (searchFilter.Length > 0)
                {
                    Globals.dataProvider.addFilter(
                        //"(Title LIKE @search OR Description LIKE @search)",
                        "(Title LIKE @search)",
                        new { search = $"%{searchFilter}%" }
                    );
                }
                var result = Globals.dataProvider.getProduct(currentPage);
                productCount = Globals.dataProvider.getProductCount();
                pageList.Clear();
                pageList.Add("<");
                for (int i = 1; i < (productCount / Globals.PAGE_LEN) + 1; i++)
                {
                    pageList.Add(i.ToString());
                }
                pageList.Add(">");
                // PageListListBox.ItemsSource = pageList;
                Invalidate("pageList");
                return result;
            }

        }

        private void ExitButton_Click(object sender, RoutedEventArgs e)
        {
            Application.Current.Shutdown();

        }
        public MainWindow()
        {
            InitializeComponent();
            DataContext = this;
            Globals.dataProvider = new DBDataProvider();
            productTypeList = Globals.dataProvider.getProductTypes().ToList();
            productTypeList.Insert(0, new ProductType { Title = "Все типы продукции" });

        }
        public event PropertyChangedEventHandler? PropertyChanged;
        private void Invalidate(string element)
        {
            if (PropertyChanged != null)
                PropertyChanged(this, new PropertyChangedEventArgs(element));
        }

        private void TextBlock_PreviewMouseDown(object sender, MouseButtonEventArgs e)
        {
            switch ((sender as TextBlock).Text)
            {
                case "<":
                    if (currentPage > 1) currentPage--;
                    return;

                case ">":
                    if (currentPage < productCount / Globals.PAGE_LEN) currentPage++;
                    return;

                default:
                    currentPage = Convert.ToInt32(
                        (sender as TextBlock).Text);
                    return;
            }
        }
        public string[] sortList { get; set; } =

        {
            "Без сортировки",
            "название по убыванию",
            "название по возрастанию",
            "номер цеха по убыванию",
            "номер цеха по возрастанию",
            "цена по убыванию",
            "цена по возрастанию"
        };
        private int sortType = 0;

        private void SortTypeComboBox_SelectionChanged(
            object? sender,
            SelectionChangedEventArgs e)
        {
            if (SortTypeComboBox != null)
            {
                sortType = SortTypeComboBox.SelectedIndex;
                Invalidate("productList");
            }
        }
        public List<ProductType> productTypeList { get; set; }
        private int productTypeFilterId = 0;

        private void ProductTypeFilter_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            // запоминаем ID выбранного типа
            productTypeFilterId = (ProductTypeFilter.SelectedItem as ProductType).ID;
            Invalidate("productList");
        }

        private string searchFilter = "";
        private void searchFilterTextBox_KeyUp(object sender, KeyEventArgs e)
        {
            if (searchFilterTextBox.Text != null && searchFilterTextBox.Text != "")
            {
                searchFilter = searchFilterTextBox.Text;
                Invalidate("productList");
            }
        }
        public int productsSelectedCount = 0;
        private void ProductListBox_OnSelectionChanged(
            object? sender,
            SelectionChangedEventArgs e)
        {
            if (ProductListBox != null)
            {
                productsSelectedCount = ProductListBox.SelectedItems.Count;
                Invalidate("costChangeButtonVisible");
            }
        }
        public string costChangeButtonVisible
        {
            get
            {
                return productsSelectedCount > 1 ? "Visible" : "Hidden";
            }
        }

        private void CostChangeButton_Click(object sender, RoutedEventArgs e)
        {
            decimal sum = 0;
            List<int> idList = new List<int>();
            foreach (Product item in ProductListBox.SelectedItems)
            {
                sum += item.MinCostForAgent;
                idList.Add(item.ID);
            }

            // создаём окно, передавая ему среднюю цену    
            var newWindow = new EnterMinCostForAgentWindow(
                sum / ProductListBox.SelectedItems.Count);

            try
            {
                if ((bool)newWindow.ShowDialog())
                {
                    Globals.dataProvider.setMinCostForAgent(
                        newWindow.Result,
                        idList.ToArray());
                    Invalidate("productList");
                }
            }

            catch { MessageBox.Show("Чото не то"); }

        }

        private void searchFilterTextBox_TextChanged(object sender, TextChangedEventArgs e)
        {

        }
    }
    

}

MainWindow.xaml

<Window x:Class="wpf_connection3.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
        xmlns:local="clr-namespace:wpf_connection3"
        mc:Ignorable="d"
        Background="PeachPuff"
        Title="MainWindow" Height="450" Width="800">

    <Grid ShowGridLines="True">
        <Grid.RowDefinitions>
            <RowDefinition Height="auto"/>
            <RowDefinition />
            <RowDefinition Height="50"/>
        </Grid.RowDefinitions>
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="200"/>
            <ColumnDefinition/>
        </Grid.ColumnDefinitions>


        <ListBox 
            Name="ProductListBox"
SelectionMode="Multiple"
SelectionChanged="ProductListBox_OnSelectionChanged"
Grid.Row="1"
Grid.Column="1"
Background="White"
ItemsSource="{Binding productList}" 
            ScrollViewer.HorizontalScrollBarVisibility="Disabled" Margin="3,3,0,0"  RenderTransformOrigin="0.5,0.5">


            <ListBox.ItemContainerStyle>
                <Style 
            TargetType="ListBoxItem">
                    <Setter 
                Property="HorizontalContentAlignment"
                Value="Stretch" />
                </Style>
            </ListBox.ItemContainerStyle>

            <ListBox.ItemTemplate>
                <DataTemplate>
                    <Border 
        BorderThickness="1" 
        BorderBrush="Black" 
        Background="{Binding BackgroundColor}"
                        CornerRadius="5">

                        <Grid 
Margin="10" 
HorizontalAlignment="Stretch">

                            <Grid.ColumnDefinitions>
                                <ColumnDefinition Width="64"/>
                                <ColumnDefinition Width="*"/>
                                <ColumnDefinition Width="auto"/>
                            </Grid.ColumnDefinitions>

                            <Image
                            Width="64" 
                            Height="64"
                            Source="{Binding ImageBitmap}" HorizontalAlignment="Center"/>

                            <StackPanel
                            Grid.Column="1"
                            Margin="5"
                            Orientation="Vertical">

                                <TextBlock
                                Text="{Binding Title}"/>
                                <TextBlock
                                Text="{Binding ArticleNumber}"/>
                            </StackPanel>

                            <TextBlock
                            Grid.Column="2"
                        Text="{Binding ProductTypeID}"/>

                        </Grid>

                    </Border>
                </DataTemplate>
            </ListBox.ItemTemplate>

        </ListBox>

        <WrapPanel
    Grid.Column="1" 
    Orientation="Horizontal" 
             Background="MediumPurple"
    ItemHeight="50">



            <ComboBox
    Width="140"
                 
    x:Name="ProductTypeFilter"
    SelectedIndex="0"
    SelectionChanged="ProductTypeFilter_SelectionChanged"
    ItemsSource="{Binding productTypeList}" Margin="0,15,0,15"/>

            <ComboBox
        Name="SortTypeComboBox"
        SelectedIndex="0"
        VerticalContentAlignment="Center"
        MinWidth="200"
        SelectionChanged="SortTypeComboBox_SelectionChanged"
                Height="20"
        ItemsSource="{Binding sortList}"/>

            <TextBox
Width="200"
VerticalAlignment="Center"
x:Name="searchFilterTextBox" 
                 Background="Cyan"
                Height="30"
KeyUp="searchFilterTextBox_KeyUp" TextChanged="searchFilterTextBox_TextChanged"/>
        </WrapPanel>

        <ListBox
x:Name="PageListListBox"
ItemsSource="{Binding pageList}"
Grid.Column="1"
             Background="Aqua"
Grid.Row="2">

            <ListBox.ItemsPanel>
                <ItemsPanelTemplate>
                    <WrapPanel 
            HorizontalAlignment="Left" />
                </ItemsPanelTemplate>
            </ListBox.ItemsPanel>

            <ListBox.ItemTemplate>
                <DataTemplate>
                    <TextBlock 
            Margin="5"
            Text="{Binding}" 
            PreviewMouseDown="TextBlock_PreviewMouseDown"/>
                </DataTemplate>
            </ListBox.ItemTemplate>
        </ListBox>

        <Image 
            Grid.Row="0"
            Grid.RowSpan="2"
            
        Source="foto\1.jpg" 
            
        />
        <StackPanel 
            Grid.Row="2"
        Orientation="Vertical"
        
        VerticalAlignment="Bottom">
            <Button 
            x:Name="ExitButton"
            Content="Выход" 
            Click="ExitButton_Click"
                Background="HotPink"
            Height="20"/>
        </StackPanel>

        <WrapPanel
Orientation="Horizontal"
Grid.Column="1"
MinHeight="50">
        </WrapPanel>

        <Button
    x:Name="CostChangeButton"
    Visibility="{Binding costChangeButtonVisible}"     Content="Изменить стоимость на..."
            Click="CostChangeButton_Click"
            Background="MediumPurple"
            />
    </Grid>

</Window>

EnterMinCostForAgentWindow

<Window x:Class="wpf_connection3.Windows.EnterMinCostForAgentWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
        xmlns:local="clr-namespace:wpf_connection3.Windows"
        mc:Ignorable="d"
        Title="Лайф стайл доги стайл" Height="450" Width="800"

        Background="White">
   
    <Grid>
        <StackPanel
            
            Height="auto"
    Orientation="Vertical" Margin="0,50,0,0">

            <TextBox
        Name="CostTextBox"
        />
            <Button
                Height="50"
                Background="AliceBlue"
        Content="Изменить"
                Click="Button_Click"
                />
        </StackPanel>
    </Grid>
</Window>