Ver Fonte

почти готовая первая страница

Priquo há 2 anos atrás
pai
commit
09eee391fa

+ 15 - 3
DemoexamUser11/App.config

@@ -1,11 +1,23 @@
 <?xml version="1.0" encoding="utf-8"?>
 <configuration>
-  
-  
+  <configSections>
+    <!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 -->
+    <section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
+  </configSections>
   <startup>
     <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.7.2" />
   </startup>
   <connectionStrings>
-    <add name="user11Entities" connectionString="metadata=res://*/ModelBase.csdl|res://*/ModelBase.ssdl|res://*/ModelBase.msl;provider=System.Data.SqlClient;provider connection string=&quot;data source=ngknn.ru;initial catalog=user11;persist security info=True;user id=User11;password=wsruser11;MultipleActiveResultSets=True;App=EntityFramework&quot;" providerName="System.Data.EntityClient" />
+    <add name="user11Entities" connectionString="metadata=res://*/Model1.csdl|res://*/Model1.ssdl|res://*/Model1.msl;provider=System.Data.SqlClient;provider connection string=&quot;data source=ngknn.ru;initial catalog=user11;persist security info=True;user id=User11;password=wsruser11;MultipleActiveResultSets=True;App=EntityFramework&quot;" providerName="System.Data.EntityClient" />
   </connectionStrings>
+  <entityFramework>
+    <defaultConnectionFactory type="System.Data.Entity.Infrastructure.LocalDbConnectionFactory, EntityFramework">
+      <parameters>
+        <parameter value="mssqllocaldb" />
+      </parameters>
+    </defaultConnectionFactory>
+    <providers>
+      <provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
+    </providers>
+  </entityFramework>
 </configuration>

+ 54 - 39
DemoexamUser11/DemoexamUser11.csproj

@@ -35,6 +35,12 @@
     <WarningLevel>4</WarningLevel>
   </PropertyGroup>
   <ItemGroup>
+    <Reference Include="EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089, processorArchitecture=MSIL">
+      <HintPath>..\packages\EntityFramework.6.2.0\lib\net45\EntityFramework.dll</HintPath>
+    </Reference>
+    <Reference Include="EntityFramework.SqlServer, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089, processorArchitecture=MSIL">
+      <HintPath>..\packages\EntityFramework.6.2.0\lib\net45\EntityFramework.SqlServer.dll</HintPath>
+    </Reference>
     <Reference Include="System" />
     <Reference Include="System.ComponentModel.DataAnnotations" />
     <Reference Include="System.Data" />
@@ -59,49 +65,64 @@
       <SubType>Designer</SubType>
     </ApplicationDefinition>
     <Compile Include="Agent.cs">
-      <DependentUpon>ModelBase.tt</DependentUpon>
+      <DependentUpon>Model1.tt</DependentUpon>
     </Compile>
+    <Compile Include="classes\AgentPartial.cs" />
     <Compile Include="AgentPriorityHistory.cs">
-      <DependentUpon>ModelBase.tt</DependentUpon>
+      <DependentUpon>Model1.tt</DependentUpon>
     </Compile>
     <Compile Include="AgentType.cs">
-      <DependentUpon>ModelBase.tt</DependentUpon>
+      <DependentUpon>Model1.tt</DependentUpon>
     </Compile>
     <Compile Include="classes\BaseConnector.cs" />
+    <Compile Include="classes\PageLoader.cs" />
     <Compile Include="Material.cs">
-      <DependentUpon>ModelBase.tt</DependentUpon>
+      <DependentUpon>Model1.tt</DependentUpon>
     </Compile>
     <Compile Include="MaterialCountHistory.cs">
-      <DependentUpon>ModelBase.tt</DependentUpon>
+      <DependentUpon>Model1.tt</DependentUpon>
     </Compile>
     <Compile Include="MaterialType.cs">
-      <DependentUpon>ModelBase.tt</DependentUpon>
+      <DependentUpon>Model1.tt</DependentUpon>
+    </Compile>
+    <Compile Include="Model1.Context.cs">
+      <AutoGen>True</AutoGen>
+      <DesignTime>True</DesignTime>
+      <DependentUpon>Model1.Context.tt</DependentUpon>
+    </Compile>
+    <Compile Include="Model1.cs">
+      <AutoGen>True</AutoGen>
+      <DesignTime>True</DesignTime>
+      <DependentUpon>Model1.tt</DependentUpon>
     </Compile>
-    <Compile Include="ModelBase.cs">
+    <Compile Include="Model1.Designer.cs">
       <AutoGen>True</AutoGen>
       <DesignTime>True</DesignTime>
-      <DependentUpon>ModelBase.tt</DependentUpon>
+      <DependentUpon>Model1.edmx</DependentUpon>
+    </Compile>
+    <Compile Include="pages\AgentsList.xaml.cs">
+      <DependentUpon>AgentsList.xaml</DependentUpon>
     </Compile>
     <Compile Include="Product.cs">
-      <DependentUpon>ModelBase.tt</DependentUpon>
+      <DependentUpon>Model1.tt</DependentUpon>
     </Compile>
     <Compile Include="ProductCostHistory.cs">
-      <DependentUpon>ModelBase.tt</DependentUpon>
+      <DependentUpon>Model1.tt</DependentUpon>
     </Compile>
     <Compile Include="ProductMaterial.cs">
-      <DependentUpon>ModelBase.tt</DependentUpon>
+      <DependentUpon>Model1.tt</DependentUpon>
     </Compile>
     <Compile Include="ProductSale.cs">
-      <DependentUpon>ModelBase.tt</DependentUpon>
+      <DependentUpon>Model1.tt</DependentUpon>
     </Compile>
     <Compile Include="ProductType.cs">
-      <DependentUpon>ModelBase.tt</DependentUpon>
+      <DependentUpon>Model1.tt</DependentUpon>
     </Compile>
     <Compile Include="Shop.cs">
-      <DependentUpon>ModelBase.tt</DependentUpon>
+      <DependentUpon>Model1.tt</DependentUpon>
     </Compile>
     <Compile Include="Supplier.cs">
-      <DependentUpon>ModelBase.tt</DependentUpon>
+      <DependentUpon>Model1.tt</DependentUpon>
     </Compile>
     <Page Include="MainWindow.xaml">
       <Generator>MSBuild:Compile</Generator>
@@ -115,18 +136,12 @@
       <DependentUpon>MainWindow.xaml</DependentUpon>
       <SubType>Code</SubType>
     </Compile>
+    <Page Include="pages\AgentsList.xaml">
+      <SubType>Designer</SubType>
+      <Generator>MSBuild:Compile</Generator>
+    </Page>
   </ItemGroup>
   <ItemGroup>
-    <Compile Include="ModelBase.Context.cs">
-      <AutoGen>True</AutoGen>
-      <DesignTime>True</DesignTime>
-      <DependentUpon>ModelBase.Context.tt</DependentUpon>
-    </Compile>
-    <Compile Include="ModelBase.Designer.cs">
-      <AutoGen>True</AutoGen>
-      <DesignTime>True</DesignTime>
-      <DependentUpon>ModelBase.edmx</DependentUpon>
-    </Compile>
     <Compile Include="Properties\AssemblyInfo.cs">
       <SubType>Code</SubType>
     </Compile>
@@ -144,12 +159,12 @@
       <Generator>ResXFileCodeGenerator</Generator>
       <LastGenOutput>Resources.Designer.cs</LastGenOutput>
     </EmbeddedResource>
-    <EntityDeploy Include="ModelBase.edmx">
+    <EntityDeploy Include="Model1.edmx">
       <Generator>EntityModelCodeGenerator</Generator>
-      <LastGenOutput>ModelBase.Designer.cs</LastGenOutput>
+      <LastGenOutput>Model1.Designer.cs</LastGenOutput>
     </EntityDeploy>
-    <None Include="ModelBase.edmx.diagram">
-      <DependentUpon>ModelBase.edmx</DependentUpon>
+    <None Include="Model1.edmx.diagram">
+      <DependentUpon>Model1.edmx</DependentUpon>
     </None>
     <None Include="packages.config" />
     <None Include="Properties\Settings.settings">
@@ -297,22 +312,22 @@
     <Resource Include="agents\agent_99.png" />
   </ItemGroup>
   <ItemGroup>
-    <Folder Include="pages\" />
+    <Resource Include="images\picture.png" />
   </ItemGroup>
   <ItemGroup>
-    <Content Include="ModelBase.Context.tt">
+    <Service Include="{508349B6-6B84-4DF5-91F0-309BEEBAD82D}" />
+  </ItemGroup>
+  <ItemGroup>
+    <Content Include="Model1.Context.tt">
       <Generator>TextTemplatingFileGenerator</Generator>
-      <LastGenOutput>ModelBase.Context.cs</LastGenOutput>
-      <DependentUpon>ModelBase.edmx</DependentUpon>
+      <LastGenOutput>Model1.Context.cs</LastGenOutput>
+      <DependentUpon>Model1.edmx</DependentUpon>
     </Content>
-    <Content Include="ModelBase.tt">
+    <Content Include="Model1.tt">
       <Generator>TextTemplatingFileGenerator</Generator>
-      <DependentUpon>ModelBase.edmx</DependentUpon>
-      <LastGenOutput>ModelBase.cs</LastGenOutput>
+      <DependentUpon>Model1.edmx</DependentUpon>
+      <LastGenOutput>Model1.cs</LastGenOutput>
     </Content>
   </ItemGroup>
-  <ItemGroup>
-    <Service Include="{508349B6-6B84-4DF5-91F0-309BEEBAD82D}" />
-  </ItemGroup>
   <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
 </Project>

+ 4 - 0
DemoexamUser11/MainWindow.xaml.cs

@@ -12,6 +12,8 @@ using System.Windows.Media;
 using System.Windows.Media.Imaging;
 using System.Windows.Navigation;
 using System.Windows.Shapes;
+using DemoexamUser11.pages;
+using DemoexamUser11.classes;
 
 namespace DemoexamUser11
 {
@@ -23,6 +25,8 @@ namespace DemoexamUser11
         public MainWindow()
         {
             InitializeComponent();
+            framePager.Navigate(new AgentsList());
+            PageLoader.MainFraim = framePager;
         }
     }
 }

+ 0 - 0
DemoexamUser11/ModelBase.Context.cs → DemoexamUser11/Model1.Context.cs


+ 1 - 1
DemoexamUser11/ModelBase.Context.tt → DemoexamUser11/Model1.Context.tt

@@ -2,7 +2,7 @@
 <#@ include file="EF6.Utility.CS.ttinclude"#><#@
  output extension=".cs"#><#
 
-const string inputFile = @"ModelBase.edmx";
+const string inputFile = @"Model1.edmx";
 var textTransform = DynamicTextTransformation.Create(this);
 var code = new CodeGenerationTools(this);
 var ef = new MetadataTools(this);

+ 1 - 1
DemoexamUser11/ModelBase.Designer.cs → DemoexamUser11/Model1.Designer.cs

@@ -1,4 +1,4 @@
-// Создание кода T4 для модели "\\main\RDP\Экзамен\11\Desktop\Демоэкзамен Проба 18.03.2022\DemoexamUser11\DemoexamUser11\ModelBase.edmx" включено. 
+// Создание кода T4 для модели "Y:\DemoexamUser11\DemoexamUser11\Model1.edmx" включено. 
 // Чтобы включить формирование кода прежних версий, измените значение свойства "Стратегия создания кода" конструктора
 // на "Legacy ObjectContext". Это свойство доступно в окне "Свойства", если модель
 // открыта в конструкторе.

+ 0 - 0
DemoexamUser11/ModelBase.cs → DemoexamUser11/Model1.cs


+ 0 - 0
DemoexamUser11/ModelBase.edmx → DemoexamUser11/Model1.edmx


+ 1 - 1
DemoexamUser11/ModelBase.edmx.diagram → DemoexamUser11/Model1.edmx.diagram

@@ -4,7 +4,7 @@
   <edmx:Designer xmlns="http://schemas.microsoft.com/ado/2009/11/edmx">
     <!-- Diagram content (shape and connector positions) -->
     <edmx:Diagrams>
-      <Diagram DiagramId="78dcb6e4f56849b4a71c2599f025409d" Name="Diagram1">
+      <Diagram DiagramId="8e3279c9000e436ba59a2511af2599cb" Name="Diagram1">
         <EntityTypeShape EntityType="user11Model.Agent" Width="1.5" PointX="3" PointY="13.125" IsExpanded="true" />
         <EntityTypeShape EntityType="user11Model.AgentPriorityHistory" Width="1.5" PointX="5.25" PointY="16.75" IsExpanded="true" />
         <EntityTypeShape EntityType="user11Model.AgentType" Width="1.5" PointX="0.75" PointY="14.25" IsExpanded="true" />

+ 1 - 1
DemoexamUser11/ModelBase.tt → DemoexamUser11/Model1.tt

@@ -2,7 +2,7 @@
 <#@ include file="EF6.Utility.CS.ttinclude"#><#@ 
  output extension=".cs"#><#
 
-const string inputFile = @"ModelBase.edmx";
+const string inputFile = @"Model1.edmx";
 var textTransform = DynamicTextTransformation.Create(this);
 var code = new CodeGenerationTools(this);
 var ef = new MetadataTools(this);

+ 38 - 0
DemoexamUser11/classes/AgentPartial.cs

@@ -0,0 +1,38 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace DemoexamUser11
+{
+    public partial class Agent
+    {
+        public string ImagePath { get => Logo == "" ? "/images/picture.png" : Logo; }
+        public string Type { get => AgentType.Title; }
+        public string SaleYear { get => ProductSale.Where(x => x.AgentID == ID && DateTime.Now.Year - x.SaleDate.Year < 2).ToList().Count.ToString() + " продаж за год"; }
+        public string PriorityText { get => "Приоритетность: " + Priority; }
+        public string Descount
+        {
+            get
+            {
+                List<ProductSale> productSales = ProductSale.Where(x => x.AgentID == ID).ToList();
+                int summ = 0;
+                int descount = 0;
+                foreach (var productSale in productSales)
+                {
+                    summ += productSale.ProductCount;
+                }
+                if (summ > 10000 && summ < 50000)
+                    descount = 5;
+                else if (summ > 50000 && summ < 150000)
+                    descount = 10;
+                else if (summ > 150000 && summ < 500000)
+                    descount = 20;
+                else if (summ > 500000)
+                    descount = 25;
+                return descount.ToString();
+            }
+        }
+    }
+}

+ 14 - 0
DemoexamUser11/classes/PageLoader.cs

@@ -0,0 +1,14 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using System.Windows.Controls;
+
+namespace DemoexamUser11.classes
+{
+    public static class PageLoader
+    {
+        public static Frame MainFraim;
+    }
+}

BIN
DemoexamUser11/images/picture.png


+ 1 - 0
DemoexamUser11/packages.config

@@ -1,4 +1,5 @@
 <?xml version="1.0" encoding="utf-8"?>
 <packages>
+  <package id="EntityFramework" version="6.2.0" targetFramework="net472" />
   <package id="EntityFramework.ru" version="6.2.0" targetFramework="net472" />
 </packages>

+ 43 - 0
DemoexamUser11/pages/AgentsList.xaml

@@ -0,0 +1,43 @@
+<Page x:Class="DemoexamUser11.pages.AgentsList"
+      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:DemoexamUser11.pages"
+      mc:Ignorable="d" 
+      d:DesignHeight="450" d:DesignWidth="800"
+      Title="AgentsList">
+    <Page.Resources>
+        <DataTemplate x:Key="listItemTemplate">
+            <Border BorderBrush="Black" BorderThickness="1" Height="120">
+                <StackPanel Orientation="Horizontal" >
+                    <Image Source="{Binding ImagePath}" Height="120" Width="120"/>
+                    <StackPanel Orientation="Vertical" Margin="5 10" Width="600">
+                        <StackPanel Orientation="Horizontal">
+                            <TextBlock Text="{Binding Type}" FontSize="20" Margin="0 3" Width="70"/>
+                            <TextBlock Text="|  " FontSize="20" Margin="0 3"/>
+                            <TextBlock Text="{Binding Title}" FontSize="20" Margin="0 3" Width="200"/>
+                            <TextBlock Text="{Binding Descount}" FontSize="25" Margin="200 0 0 0"/>
+                        </StackPanel>
+                        <TextBlock Text="{Binding SaleYear}" FontSize="16" Margin="0 3"/>
+                        <TextBlock Text="{Binding Phone}" FontSize="16" Margin="0 3"/>
+                        <TextBlock Text="{Binding PriorityText}" FontSize="16" />
+                    </StackPanel>
+                </StackPanel>
+            </Border>
+        </DataTemplate>
+    </Page.Resources>
+    <Grid>
+        <Grid.RowDefinitions>
+            <RowDefinition Height="13*"/>
+            <RowDefinition Height="137*"/>
+        </Grid.RowDefinitions>
+        <StackPanel Orientation="Horizontal" Grid.Row="0">
+            <TextBox x:Name="textBoxSearch" Width="250" Height="25" Margin="10 0" TextChanged="Search"/>
+            <ComboBox x:Name="comboBoxSort" Width="150" Height="25" SelectionChanged="Filter"/>
+            <Button x:Name="buttomBigger" Content="Изменить порядок" Height="25" Click="buttomBigger_Click"/>
+            <ComboBox x:Name="comboBoxFilter" Width="150" Height="25" Margin="10 0" SelectionChanged="Filter"/>
+        </StackPanel>
+        <ListBox x:Name="listBoxAgents" ItemTemplate="{StaticResource listItemTemplate}" Grid.Row="1"/>
+    </Grid>
+</Page>

+ 107 - 0
DemoexamUser11/pages/AgentsList.xaml.cs

@@ -0,0 +1,107 @@
+using System;
+using System.Collections.Generic;
+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;
+using DemoexamUser11.classes;
+
+namespace DemoexamUser11.pages
+{
+    /// <summary>
+    /// Логика взаимодействия для AgentsList.xaml
+    /// </summary>
+    public partial class AgentsList : Page
+    {
+        List<string> sortList = new List<string>() { "Наименование", "Размер скидки", "Приоритет" };
+        List<Agent> agents = BaseConnector.BaseConnect.Agent.ToList();
+        List<Agent> agentsForFilters = BaseConnector.BaseConnect.Agent.ToList();
+        List<AgentType> agentTypes = BaseConnector.BaseConnect.AgentType.ToList();        
+        public AgentsList()
+        {
+            InitializeComponent();
+            listBoxAgents.ItemsSource = agents;
+
+            agentTypes.Add(new AgentType { ID = 9999, Title = "Все типы" });
+            comboBoxFilter.ItemsSource = agentTypes;
+            comboBoxFilter.DisplayMemberPath = "Title";
+            comboBoxFilter.SelectedValuePath = "ID";
+            comboBoxFilter.SelectedIndex = comboBoxFilter.Items.Count - 1;
+
+            comboBoxSort.ItemsSource = sortList;
+        }
+
+        private void Search(object sender, TextChangedEventArgs e)
+        {
+            if (textBoxSearch.Text.Replace(" ", "") != "")
+            {
+                try
+                {
+                    agentsForFilters = agentsForFilters.Where(x => x.Title.Contains(textBoxSearch.Text) || x.Phone.Contains(textBoxSearch.Text) || x.Email.Contains(textBoxSearch.Text)).ToList();
+                    listBoxAgents.ItemsSource = agentsForFilters;
+                }
+                catch
+                {
+                    MessageBox.Show("Не удалось выполнить поиск!");
+                }
+            }
+            if (textBoxSearch.Text.Replace(" ", "") == "" && (int)comboBoxFilter.SelectedValue == 9999)
+            {
+                listBoxAgents.ItemsSource = agents;
+                agentsForFilters = BaseConnector.BaseConnect.Agent.ToList();
+            }
+            else if (textBoxSearch.Text.Replace(" ", "") == "" && (int)comboBoxFilter.SelectedValue != 9999)
+            {
+                listBoxAgents.ItemsSource = agents.Where(x => x.AgentTypeID == (int)comboBoxFilter.SelectedValue).ToList();
+                agentsForFilters = BaseConnector.BaseConnect.Agent.ToList();
+            }
+        }
+
+        private void Filter(object sender, SelectionChangedEventArgs e)
+        {
+            if (comboBoxFilter.SelectedItem != null && (int)comboBoxFilter.SelectedValue != 9999)
+            {
+                agentsForFilters = agentsForFilters.Where(x => x.AgentTypeID == (int)comboBoxFilter.SelectedValue).ToList();
+            }
+            if ((int)comboBoxFilter.SelectedValue == 9999)
+                agentsForFilters = BaseConnector.BaseConnect.Agent.ToList();
+            if (comboBoxSort.SelectedItem != null)
+            {
+                switch (comboBoxSort.SelectedValue)
+                {
+                    case "Наименование":
+                        agentsForFilters.Sort(delegate(Agent a1, Agent a2) 
+                        { 
+                            return a1.Title.CompareTo(a2.Title); 
+                        });
+                        break;
+                    case "Размер скидки":
+                        break;
+                    case "Приоритет":
+                        agentsForFilters.Sort(delegate (Agent a1, Agent a2)
+                        {
+                            return a1.Priority.CompareTo(a2.Priority);
+                        });
+                        break;
+                }
+            }
+            
+            listBoxAgents.ItemsSource = agentsForFilters;
+        }
+
+        private void buttomBigger_Click(object sender, RoutedEventArgs e)
+        {
+            agentsForFilters.Reverse();
+            listBoxAgents.ItemsSource = agentsForFilters;
+            listBoxAgents.Items.Refresh();
+        }
+    }
+}