Explorar el Código

молодец, главное начать

Алёна Плотникова hace 2 años
padre
commit
d4559d3f80

+ 1 - 1
kursach_2.0/Windows/Handbooks.xaml

@@ -62,7 +62,7 @@
                             <ColumnDefinition/>
                             <ColumnDefinition/>
                         </Grid.ColumnDefinitions>
-                        <Button Content="Добавить" Grid.Column="0" Margin="15"/>
+                        <Button Content="Добавить" Grid.Column="0" Margin="15" Click="InsertProduct"/>
                         <Button Content="Изменить" Grid.Column="1" Margin="15"/>
                         <Button Content="Удалить" Grid.Column="2" Margin="15"/>
                         <Button Content="Экспорт" Grid.Column="3" Margin="15"/>

+ 10 - 1
kursach_2.0/Windows/Handbooks.xaml.cs

@@ -28,18 +28,27 @@ namespace kursach_2._0.Windows
         }
 
         // вывод данных
-        private void Load()
+        public void Load()
         {
             productsDG.ItemsSource = _context.products.ToList();
             distributorDG.ItemsSource = _context.distributors.ToList();
             employeesDG.ItemsSource = _context.employees.ToList();
         }
 
+        // кнопка домой
         private void HomeClick(object sender, MouseButtonEventArgs e)
         {
             Windows.Menu menu = new Windows.Menu();
             menu.Show();
             Close();
         }
+
+        // кнопка добавить
+        private void InsertProduct(object sender, RoutedEventArgs e)
+        {
+            Windows.product_insert PI = new Windows.product_insert();
+            PI.Owner = this;
+            PI.Show();
+        }
     }
 }

+ 72 - 0
kursach_2.0/Windows/product_insert.xaml

@@ -0,0 +1,72 @@
+<Window x:Class="kursach_2._0.Windows.product_insert"
+        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:kursach_2._0.Windows"
+        mc:Ignorable="d"
+        Title="Дилерская компания" Height="450" Width="450" MinHeight="450" MinWidth="450">
+    <Grid>
+        <Grid.ColumnDefinitions>
+            <ColumnDefinition/>
+            <ColumnDefinition Width="2*"/>
+        </Grid.ColumnDefinitions>
+        
+        <Grid.RowDefinitions>
+            <RowDefinition/>
+            <RowDefinition/>
+            <RowDefinition/>
+            <RowDefinition/>
+            <RowDefinition/>
+            <RowDefinition/>
+            <RowDefinition/>
+            <RowDefinition/>
+        </Grid.RowDefinitions>
+
+        <Label Grid.Column="0" Grid.Row="0"
+               Content="Номер дистрибьютора" 
+               FontFamily="Montserrat Light" FontSize="11" 
+               HorizontalAlignment="Right" VerticalAlignment="Center"/>
+        <Label Grid.Column="0" Grid.Row="1"
+               Content="Наименование товара"
+               FontFamily="Montserrat Light" FontSize="11" 
+               HorizontalAlignment="Right" VerticalAlignment="Center"/>
+        <Label Grid.Column="0" Grid.Row="2"
+               Content="Тип товара"
+               FontFamily="Montserrat Light" FontSize="11" 
+               HorizontalAlignment="Right" VerticalAlignment="Center"/>
+        <Label Grid.Column="0" Grid.Row="3"
+               Content="Дата производства"
+               FontFamily="Montserrat Light" FontSize="11" 
+               HorizontalAlignment="Right" VerticalAlignment="Center"/>
+        <Label Grid.Column="0" Grid.Row="4"
+               Content="Гарантия"
+               FontFamily="Montserrat Light" FontSize="11" 
+               HorizontalAlignment="Right" VerticalAlignment="Center"/>
+        <Label Grid.Column="0" Grid.Row="5"
+               Content="Оптовая цена"
+               FontFamily="Montserrat Light" FontSize="11" 
+               HorizontalAlignment="Right" VerticalAlignment="Center"/>
+        <Label Grid.Column="0" Grid.Row="6"
+               Content="Розничная цена"
+               FontFamily="Montserrat Light" FontSize="11" 
+               HorizontalAlignment="Right" VerticalAlignment="Center"/>
+
+        <TextBox x:Name="TB_id_distributor" Grid.Column="1" Grid.Row="0" Margin="15" 
+                 VerticalContentAlignment="Center" HorizontalContentAlignment="Right" FontFamily="Montserrat Light"/>
+        <TextBox x:Name="TB_product_name" Grid.Column="1" Grid.Row="1" Margin="15"
+                 VerticalContentAlignment="Center" HorizontalContentAlignment="Right" FontFamily="Montserrat Light"/>
+        <TextBox x:Name="TB_product_type" Grid.Column="1" Grid.Row="2" Margin="15"
+                 VerticalContentAlignment="Center" HorizontalContentAlignment="Right" FontFamily="Montserrat Light"/>
+        <DatePicker x:Name="DP_production_date" Grid.Column="1" Grid.Row="3" Margin="15"/>
+        <TextBox x:Name="TB_warranty" Grid.Column="1" Grid.Row="4" Margin="15"
+                 VerticalContentAlignment="Center" HorizontalContentAlignment="Right" FontFamily="Montserrat Light"/>
+        <TextBox x:Name="TB_wholesale_price" Grid.Column="1" Grid.Row="5" Margin="15"
+                 VerticalContentAlignment="Center" HorizontalContentAlignment="Right" FontFamily="Montserrat Light"/>
+        <TextBox x:Name="TB_retail_price" Grid.Column="1" Grid.Row="6" Margin="15"
+                 VerticalContentAlignment="Center" HorizontalContentAlignment="Right" FontFamily="Montserrat Light"/>
+
+        <Button x:Name="ButtonOK" Grid.ColumnSpan="2" Grid.Row="7" Margin="150, 10"
+                Content="Ок" FontFamily="Montserrat Medium" Click="ButtonOK_Click"/>
+    </Grid>
+</Window>

+ 61 - 0
kursach_2.0/Windows/product_insert.xaml.cs

@@ -0,0 +1,61 @@
+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 kursach_2._0.Windows
+{
+    /// <summary>
+    /// Логика взаимодействия для product_insert.xaml
+    /// </summary>
+    public partial class product_insert : Window
+    {
+        private dealerContext _context;
+        public product_insert()
+        {
+            InitializeComponent();
+            _context = new dealerContext();
+
+            DP_production_date.SelectedDate = DateTime.Today;
+        }
+
+        private void ButtonOK_Click(object sender, RoutedEventArgs e)
+        {
+            InsertProduct(TB_id_distributor.Text, TB_product_name.Text, TB_product_type.Text, (DateTime)DP_production_date.SelectedDate,
+                TB_warranty.Text, TB_wholesale_price.Text, TB_retail_price.Text);
+            
+            // обновить то бишь Load
+        }
+        public bool InsertProduct(string id_distributor, string product_name, string product_type, 
+            DateTime production_date, string warranty, string wholesale_price, string retail_price)
+        {
+            if (string.IsNullOrWhiteSpace(product_name) || string.IsNullOrWhiteSpace(product_type) || (string.IsNullOrWhiteSpace(warranty)))
+                return false;
+
+            products products = new products()
+            {
+                id_distributor = int.Parse(id_distributor),
+                product_name = product_name,
+                product_type = product_type,
+                production_date = production_date,
+                warranty = warranty,
+                wholesale_price = int.Parse(wholesale_price),
+                retail_price = int.Parse(retail_price)
+            };
+
+            _context.products.Add(products);
+            _context.SaveChanges();
+            
+            return true;
+        }
+    }
+}

+ 7 - 0
kursach_2.0/kursach_2.0.csproj

@@ -115,6 +115,9 @@
     <Compile Include="Windows\Menu.xaml.cs">
       <DependentUpon>Menu.xaml</DependentUpon>
     </Compile>
+    <Compile Include="Windows\product_insert.xaml.cs">
+      <DependentUpon>product_insert.xaml</DependentUpon>
+    </Compile>
     <Compile Include="Windows\Profile.xaml.cs">
       <DependentUpon>Profile.xaml</DependentUpon>
     </Compile>
@@ -150,6 +153,10 @@
       <SubType>Designer</SubType>
       <Generator>MSBuild:Compile</Generator>
     </Page>
+    <Page Include="Windows\product_insert.xaml">
+      <SubType>Designer</SubType>
+      <Generator>MSBuild:Compile</Generator>
+    </Page>
     <Page Include="Windows\Profile.xaml">
       <SubType>Designer</SubType>
       <Generator>MSBuild:Compile</Generator>