瀏覽代碼

добавление без проверок

Lolli Di 2 年之前
父節點
當前提交
aa6ef527d3

+ 41 - 0
WhiteList/AddAndRedactAgent.xaml

@@ -0,0 +1,41 @@
+<Window x:Class="WhiteList.AddAndRedactAgent"
+        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:WhiteList"
+        mc:Ignorable="d"
+        Title="Приятный шелест" Icon="Images/Приятный шелест.png" MinWidth="800" MinHeight="700" Height="700" Width="800">
+    <Grid>
+        <StackPanel Orientation="Vertical">
+            <StackPanel Orientation="Horizontal">
+                <TextBlock>Название*</TextBlock>
+                <TextBox Name="TextBoxTitle"/>
+                <ComboBox Name="ComboBoxType"/>
+            </StackPanel>
+            <StackPanel Orientation="Horizontal">
+                <TextBlock>Приоритет*</TextBlock>
+                <TextBox Name="TextBoxPriority" Width="70"/>
+                <TextBlock>Адрес</TextBlock>
+                <TextBox Name="TextBoxAdres" Width="450"/>
+            </StackPanel>
+            <StackPanel Orientation="Horizontal">
+                <TextBlock>ИНН*</TextBlock>
+                <TextBox Name="TextBoxINN" Width="120"/>
+                <TextBlock>КПП</TextBlock>
+                <TextBox Name="TextBoxKPP" Width="120"/>
+                <TextBlock>Имя директора</TextBlock>
+                <TextBox Name="TextBoxNameDirector" Width="250"/>
+            </StackPanel>
+            <StackPanel Orientation="Horizontal">
+                <TextBlock>Телефон*</TextBlock>
+                <TextBox Name="TextBoxPhone" Width="200"/>
+                <TextBlock>Почта</TextBlock>
+                <TextBox Name="TextBoxEmail" Width="200"/>
+            </StackPanel>
+            <Button Click="Save_Click">
+                <TextBlock>Сохранить</TextBlock>
+            </Button>
+        </StackPanel>
+    </Grid>
+</Window>

+ 59 - 0
WhiteList/AddAndRedactAgent.xaml.cs

@@ -0,0 +1,59 @@
+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 WhiteList
+{
+    /// <summary>
+    /// Логика взаимодействия для AddAndRedactAgent.xaml
+    /// </summary>
+    public partial class AddAndRedactAgent : Window
+    {
+        public AddAndRedactAgent()
+        {
+            InitializeComponent();
+            foreach(AgentType at in DB.dbCon.AgentType.ToList())
+            {
+                ComboBoxType.Items.Add(at.Title);
+            }
+        }
+
+        private void Save_Click(object sender, RoutedEventArgs e)
+        {
+            try
+            {
+                int idType = DB.dbCon.AgentType.FirstOrDefault(x => x.Title == ComboBoxType.SelectedValue.ToString()).ID;
+                Agent a = new Agent() //создаем агента
+                {
+                    Title = TextBoxTitle.Text,
+                    AgentTypeID = idType,
+                    Address = TextBoxAdres.Text,
+                    INN = TextBoxINN.Text,
+                    KPP = TextBoxKPP.Text,
+                    DirectorName = TextBoxNameDirector.Text,
+                    Phone = TextBoxPhone.Text,
+                    Email = TextBoxEmail.Text,
+                    Priority = Convert.ToInt32(TextBoxPriority.Text)
+                };
+                DB.dbCon.Agent.Add(a);
+                DB.dbCon.SaveChanges(); //сохраняем
+                MessageBox.Show("Данные добавлены!");
+                Close();
+            }
+            catch(Exception ee)
+            {
+                MessageBox.Show(ee.Message, "Ошибка");
+            }
+        }
+    }
+}

+ 1 - 0
WhiteList/App.xaml

@@ -9,6 +9,7 @@
             <Setter Property="FontSize" Value="20"/>
             <Setter Property="Margin" Value="5"/>
             <Setter Property="TextWrapping" Value="Wrap"/>
+            <Setter Property="VerticalAlignment" Value="Center"/>
         </Style>
         <Style TargetType="Button">
             <Setter Property="Margin" Value="10"/>

+ 1 - 1
WhiteList/ChangePriority.xaml

@@ -5,7 +5,7 @@
         xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
         xmlns:local="clr-namespace:WhiteList"
         mc:Ignorable="d"
-        Title="ChangePriority" MinHeight="200" MinWidth="350" MaxHeight="200" MaxWidth="350">
+         Title="Приятный шелест" Icon="Images/Приятный шелест.png" MinHeight="200" MinWidth="350" MaxHeight="200" MaxWidth="350">
     <Grid>
         <StackPanel>
             <TextBox Name="TextBoxNewPriority" TextChanged="TextBoxNewPriority_TextChanged"></TextBox>

+ 4 - 1
WhiteList/MainWindow.xaml

@@ -41,9 +41,12 @@
                 </ListView.ItemTemplate>
             </ListView>
             <StackPanel Orientation="Horizontal">
-                <Button Name="BtnChangePriority" Visibility="Hidden" Width="210" Click="ChangePriority_Click">
+                <Button Name="BtnChangePriority" Visibility="Collapsed" Width="210" Click="ChangePriority_Click">
                     <TextBlock>Изменить приоритет на</TextBlock>
                 </Button>
+                <Button Click="Add_Click">
+                    <TextBlock>Добавить</TextBlock>
+                </Button>
             </StackPanel>
         </StackPanel>
     </Grid>

+ 11 - 1
WhiteList/MainWindow.xaml.cs

@@ -88,8 +88,18 @@ namespace WhiteList
             }
             else
             {
-                BtnChangePriority.Visibility = Visibility.Hidden;
+                BtnChangePriority.Visibility = Visibility.Collapsed;
             }
         }
+
+        private void Add_Click(object sender, RoutedEventArgs e)
+        {
+            AddAndRedactAgent w = new AddAndRedactAgent();
+            w.Owner = this;
+            w.Visibility = Visibility.Visible;
+            w.WindowStartupLocation = WindowStartupLocation.CenterOwner;
+            w.ShowDialog();
+            Filt();
+        }
     }
 }

+ 7 - 0
WhiteList/WhiteList.csproj

@@ -64,6 +64,9 @@
       <Generator>MSBuild:Compile</Generator>
       <SubType>Designer</SubType>
     </ApplicationDefinition>
+    <Compile Include="AddAndRedactAgent.xaml.cs">
+      <DependentUpon>AddAndRedactAgent.xaml</DependentUpon>
+    </Compile>
     <Compile Include="Agent.cs">
       <DependentUpon>Model1.tt</DependentUpon>
     </Compile>
@@ -116,6 +119,10 @@
     <Compile Include="sysdiagrams.cs">
       <DependentUpon>Model1.tt</DependentUpon>
     </Compile>
+    <Page Include="AddAndRedactAgent.xaml">
+      <SubType>Designer</SubType>
+      <Generator>MSBuild:Compile</Generator>
+    </Page>
     <Page Include="ChangePriority.xaml">
       <SubType>Designer</SubType>
       <Generator>MSBuild:Compile</Generator>