Browse Source

Добавление агента

Barsik Kato 2 năm trước cách đây
mục cha
commit
58117c2bf9

+ 1 - 1
Session1/Pages/AgentList.xaml

@@ -49,7 +49,7 @@
         </StackPanel>
         </StackPanel>
         <ListBox x:Name="agentList" Grid.Row="1" ItemTemplate="{DynamicResource lbItem}" SelectionChanged="agentList_SelectionChanged" SelectionMode="Extended" MouseDoubleClick="agentList_MouseDoubleClick"></ListBox>
         <ListBox x:Name="agentList" Grid.Row="1" ItemTemplate="{DynamicResource lbItem}" SelectionChanged="agentList_SelectionChanged" SelectionMode="Extended" MouseDoubleClick="agentList_MouseDoubleClick"></ListBox>
         <StackPanel Grid.Row="2" Orientation="Horizontal">
         <StackPanel Grid.Row="2" Orientation="Horizontal">
-            <Button x:Name="addAgent">Добавить</Button>
+            <Button x:Name="addAgent" Click="addAgent_Click">Добавить</Button>
             <Button x:Name="changePriority" Visibility="Hidden" Click="ChangePriority_Click">Изменить приоритет на ...</Button>
             <Button x:Name="changePriority" Visibility="Hidden" Click="ChangePriority_Click">Изменить приоритет на ...</Button>
         </StackPanel>
         </StackPanel>
         
         

+ 7 - 0
Session1/Pages/AgentList.xaml.cs

@@ -102,5 +102,12 @@ namespace Session1
             editAgent.ShowDialog();
             editAgent.ShowDialog();
             UnitedChange();
             UnitedChange();
         }
         }
+
+        private void addAgent_Click(object sender, RoutedEventArgs e)
+        {
+            AddAgent addAgent = new AddAgent();
+            addAgent.ShowDialog();
+            UnitedChange();
+        }
     }
     }
 }
 }

+ 7 - 0
Session1/Session1.csproj

@@ -112,6 +112,9 @@
     <Compile Include="Supplier.cs">
     <Compile Include="Supplier.cs">
       <DependentUpon>Model1.tt</DependentUpon>
       <DependentUpon>Model1.tt</DependentUpon>
     </Compile>
     </Compile>
+    <Compile Include="Windows\AddAgent.xaml.cs">
+      <DependentUpon>AddAgent.xaml</DependentUpon>
+    </Compile>
     <Compile Include="Windows\ChangePriority.xaml.cs">
     <Compile Include="Windows\ChangePriority.xaml.cs">
       <DependentUpon>ChangePriority.xaml</DependentUpon>
       <DependentUpon>ChangePriority.xaml</DependentUpon>
     </Compile>
     </Compile>
@@ -135,6 +138,10 @@
       <SubType>Designer</SubType>
       <SubType>Designer</SubType>
       <Generator>MSBuild:Compile</Generator>
       <Generator>MSBuild:Compile</Generator>
     </Page>
     </Page>
+    <Page Include="Windows\AddAgent.xaml">
+      <SubType>Designer</SubType>
+      <Generator>MSBuild:Compile</Generator>
+    </Page>
     <Page Include="Windows\ChangePriority.xaml">
     <Page Include="Windows\ChangePriority.xaml">
       <SubType>Designer</SubType>
       <SubType>Designer</SubType>
       <Generator>MSBuild:Compile</Generator>
       <Generator>MSBuild:Compile</Generator>

+ 59 - 0
Session1/Windows/AddAgent.xaml

@@ -0,0 +1,59 @@
+<Window x:Class="Session1.AddAgent"
+        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:Session1"
+        mc:Ignorable="d"
+        Title="AddAgent" Height="470" Width="800">
+    <Grid>
+        <Grid.ColumnDefinitions>
+            <ColumnDefinition Width="191*"/>
+            <ColumnDefinition Width="227*"/>
+            <ColumnDefinition Width="252*"/>
+        </Grid.ColumnDefinitions>
+        <GroupBox Header="Изображение">
+            <StackPanel Grid.Column="0" VerticalAlignment="Center">
+                <Image x:Name="agentImg" Height="150" Width="150"></Image>
+                <TextBox x:Name="imgPath" Width="150"></TextBox>
+                <Button x:Name="addImage" Width="150" Click="addImage_Click">Добавить изображение</Button>
+            </StackPanel>
+        </GroupBox>
+        <GroupBox Header="Основные данные" Grid.Column="1">
+            <StackPanel VerticalAlignment="Center">
+                <GroupBox Header="Наименование">
+                    <TextBox x:Name="agentName" Width="150"></TextBox>
+                </GroupBox>
+                <GroupBox Header="Тип агента">
+                    <ComboBox x:Name="agentType" Width="150"></ComboBox>
+                </GroupBox>
+                <GroupBox Header="Приоритет">
+                    <TextBox x:Name="agentPriority" Width="150"></TextBox>
+                </GroupBox>
+                <GroupBox Header="Адрес">
+                    <TextBox x:Name="agentAddress" Width="150"></TextBox>
+                </GroupBox>
+                <GroupBox Header="ИНН">
+                    <TextBox x:Name="agentINN" Width="150"></TextBox>
+                </GroupBox>
+                <GroupBox Header="КПП">
+                    <TextBox x:Name="agentKPP" Width="150"></TextBox>
+                </GroupBox>
+                <GroupBox Header="Директор">
+                    <TextBox x:Name="agentDirector" Width="150"></TextBox>
+                </GroupBox>
+                <GroupBox Header="Телефон">
+                    <TextBox x:Name="agentPhone" Width="150"></TextBox>
+                </GroupBox>
+                <GroupBox Header="Почта">
+                    <TextBox x:Name="agentEmail" Width="150"></TextBox>
+                </GroupBox>
+                <Button x:Name="save" Click="save_Click">Сохранить</Button>
+                <Button x:Name="cancel" Click="cancel_Click">Отмена</Button>
+            </StackPanel>
+        </GroupBox>
+        <GroupBox Header="История реализации" Grid.Column="2">
+            <ListView x:Name="historyBox"></ListView>
+        </GroupBox>
+    </Grid>
+</Window>

+ 67 - 0
Session1/Windows/AddAgent.xaml.cs

@@ -0,0 +1,67 @@
+using Microsoft.Win32;
+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.Shapes;
+
+namespace Session1
+{
+    /// <summary>
+    /// Логика взаимодействия для AddAgent.xaml
+    /// </summary>
+    public partial class AddAgent : Window
+    {
+        public AddAgent()
+        {
+            InitializeComponent();
+        }
+
+        private void save_Click(object sender, RoutedEventArgs e)
+        {
+            Agent newAgent = new Agent();
+            newAgent.Logo = imgPath.Text = newAgent.Logo;
+            newAgent.Title = agentName.Text;
+            newAgent.AgentTypeID = ((AgentType)agentType.SelectedItem).ID;
+            newAgent.Priority = Convert.ToInt32(agentPriority.Text);
+            newAgent.Address = agentAddress.Text;
+            newAgent.INN = agentINN.Text;
+            newAgent.KPP = agentKPP.Text;
+            newAgent.Phone = agentPhone.Text;
+            newAgent.DirectorName = agentDirector.Text;
+            newAgent.Email = agentEmail.Text;
+            try
+            {
+                BaseConnect.baseModel.SaveChanges();
+                MessageBox.Show("Данные успешно изменены.");
+                Close();
+            }
+            catch
+            {
+                MessageBox.Show("Не удалось изменить данные.");
+            }
+        }
+
+        private void cancel_Click(object sender, RoutedEventArgs e)
+        {
+            Close();
+        }
+
+        private void addImage_Click(object sender, RoutedEventArgs e)
+        {
+            OpenFileDialog openFileDialog = new OpenFileDialog();
+            openFileDialog.Filter = "*.jpg | *.png";
+            openFileDialog.ShowDialog();
+            string filePath = openFileDialog.FileName;
+            imgPath.Text = filePath;
+        }
+    }
+}