ソースを参照

Удаление

Алексей Колесов 2 年 前
コミット
9724a6b600

+ 29 - 3
ProbnikDemo/AddAgent.xaml.cs

@@ -1,4 +1,5 @@
-using System;
+using Microsoft.Win32;
+using System;
 using System.Collections.Generic;
 using System.Linq;
 using System.Text;
@@ -19,19 +20,44 @@ namespace ProbnikDemo
     /// </summary>
     public partial class AddAgent : Window
     {
+        string ImgPath ="";
         public AddAgent()
         {
             InitializeComponent();
-            C
+            ComboType.ItemsSource = BaseConnect.BaseModel.AgentType.Where(x=>x.ID>0).ToList();
+            ComboType.SelectedValuePath = "ID";
+            ComboType.DisplayMemberPath = "Title";
+           
         }
 
         private void BtnImg_Click(object sender, RoutedEventArgs e)
-        {
+        { 
 
+            OpenFileDialog openFileDialog = new OpenFileDialog();
+            openFileDialog.DefaultExt = ".jpg";
+            openFileDialog.Filter = "Изображения | *.jpg;  *.png";
+            var result = openFileDialog.ShowDialog();
+            if (result != null)
+            {
+                ImgPath = openFileDialog.FileName;
+                IMG.Source = BitmapFrame.Create(new Uri(openFileDialog.FileName));
+            }
         }
 
         private void BtnAdd_Click(object sender, RoutedEventArgs e)
         {
+            try
+            {
+
+
+                Agent agent = new Agent() { Title = TxtTitle.Text, Address = TxtAdress.Text, AgentTypeID = Convert.ToInt32(ComboType.SelectedValue), Email = TxtEmail.Text, INN = TxtINN.Text, KPP = TxtKPP.Text, Priority = Convert.ToInt32(TxtPriority.Text), Logo = ImgPath, Phone = TxtPhone.Text, DirectorName = TxtDirector.Text };
+                BaseConnect.BaseModel.Agent.Add(agent);
+                BaseConnect.BaseModel.SaveChanges();
+            }
+            catch
+            {
+                MessageBox.Show("Ошибка");
+            }
 
         }
     }

+ 2 - 1
ProbnikDemo/Pages/PgListAgent.xaml

@@ -10,7 +10,7 @@
     <Page.Resources>
         <DataTemplate x:Key="DT">
             <Border BorderBrush="Black" BorderThickness="1" Width="1200">
-                <StackPanel Orientation="Horizontal">
+                <StackPanel Orientation="Horizontal" Uid="{Binding ID}" MouseLeftButtonDown="StackPanel_MouseLeftButtonDown">
                     <Image Source="{Binding Logo}" Width="100" Height="100"></Image>
                     <StackPanel Orientation="Vertical">
                         <StackPanel Orientation="Horizontal">
@@ -64,6 +64,7 @@
 
                 </ComboBox>
             </GroupBox>
+            <Button x:Name="BtnGoAdd" Click="BtnGoAdd_Click" Content="Добавить агента" Width="150" Height="30"></Button>
         </StackPanel>
     </Grid>
 </Page>

+ 15 - 1
ProbnikDemo/Pages/PgListAgent.xaml.cs

@@ -82,6 +82,20 @@ namespace ProbnikDemo
             }
 
             }
-            
+
+        private void BtnGoAdd_Click(object sender, RoutedEventArgs e)
+        {
+            new AddAgent().ShowDialog();
+        }
+
+        private void StackPanel_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
+        {
+            StackPanel stackPanel = (StackPanel)sender;
+            int id = Convert.ToInt32(stackPanel.Uid);
+            new PgChange(BaseConnect.BaseModel.Agent.FirstOrDefault(x => x.ID == id)).ShowDialog() ;
+
+
+               
         }
     }
+    }

+ 54 - 0
ProbnikDemo/PgChange.xaml

@@ -0,0 +1,54 @@
+<Window x:Class="ProbnikDemo.PgChange"
+        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:ProbnikDemo"
+        mc:Ignorable="d"
+        Title="PgChange" Height="450" Width="800">
+    <Grid Margin="0,0,-8,-235">
+        <StackPanel Orientation="Vertical">
+            <GroupBox Header="Наименование">
+                <TextBox x:Name="TxtTitle"></TextBox>
+
+            </GroupBox>
+
+            <GroupBox Header="Тип агента">
+                <ComboBox x:Name="ComboType"></ComboBox>
+            </GroupBox>
+
+            <GroupBox Header="Адрес">
+                <TextBox x:Name="TxtAdress"></TextBox>
+            </GroupBox>
+            <GroupBox Header="ИНН">
+                <TextBox x:Name="TxtINN"></TextBox>
+            </GroupBox>
+            <GroupBox Header="КПП">
+                <TextBox x:Name="TxtKPP"></TextBox>
+            </GroupBox>
+            <GroupBox Header="Имя директора">
+                <TextBox x:Name="TxtDirector"></TextBox>
+            </GroupBox>
+            <GroupBox Header="Телефон">
+                <TextBox x:Name="TxtPhone"></TextBox>
+            </GroupBox>
+
+            <GroupBox Header="Email">
+                <TextBox x:Name="TxtEmail"></TextBox>
+            </GroupBox>
+
+
+            <GroupBox Header="Приоритет">
+                <TextBox x:Name="TxtPriority"></TextBox>
+            </GroupBox>
+
+
+            <StackPanel Orientation="Vertical" HorizontalAlignment="Left" Width="792">
+                <Image x:Name="IMG" Width="150" Height="150"></Image>
+                <Button Content="Добавить фото" x:Name="BtnImg" Click="BtnImg_Click" ></Button>
+            </StackPanel>
+
+            <Button  Content="Удалить  агента" x:Name="BtnDel" Click="BtnDel_Click" Margin="20,20,20,20"></Button>
+        </StackPanel>
+    </Grid>
+</Window>

+ 48 - 0
ProbnikDemo/PgChange.xaml.cs

@@ -0,0 +1,48 @@
+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 ProbnikDemo
+{
+    /// <summary>
+    /// Логика взаимодействия для PgChange.xaml
+    /// </summary>
+    public partial class PgChange : Window
+    {
+        Agent agent1 = new Agent();
+        public PgChange(Agent agent)
+        {
+            InitializeComponent();
+            agent1 = agent;
+        }
+
+        private void BtnDel_Click(object sender, RoutedEventArgs e)
+        {
+            try
+            {
+                BaseConnect.BaseModel.Agent.Remove(agent1);
+                BaseConnect.BaseModel.SaveChanges();
+            }
+            catch
+            {
+                MessageBox.Show("Ошибка");
+            }
+
+        }
+
+        private void BtnImg_Click(object sender, RoutedEventArgs e)
+        {
+
+        }
+    }
+}

+ 7 - 0
ProbnikDemo/ProbnikDemo.csproj

@@ -95,6 +95,10 @@
       <SubType>Designer</SubType>
       <Generator>MSBuild:Compile</Generator>
     </Page>
+    <Page Include="PgChange.xaml">
+      <SubType>Designer</SubType>
+      <Generator>MSBuild:Compile</Generator>
+    </Page>
   </ItemGroup>
   <ItemGroup>
     <Compile Include="Model1.Context.cs">
@@ -116,6 +120,9 @@
     <Compile Include="Pages\PgListAgent.xaml.cs">
       <DependentUpon>PgListAgent.xaml</DependentUpon>
     </Compile>
+    <Compile Include="PgChange.xaml.cs">
+      <DependentUpon>PgChange.xaml</DependentUpon>
+    </Compile>
     <Compile Include="Product.cs">
       <DependentUpon>Model1.tt</DependentUpon>
     </Compile>