Просмотр исходного кода

Добавление и редактирование

lizka.flex@outlook.com 2 лет назад
Родитель
Сommit
fb34349998
6 измененных файлов с 88 добавлено и 69 удалено
  1. 6 6
      Muzzle/Add.xaml
  2. 17 0
      Muzzle/Add.xaml.cs
  3. 30 23
      Muzzle/Pages/Main.xaml
  4. 4 12
      Muzzle/Pages/Main.xaml.cs
  5. 25 18
      Muzzle/Update.xaml
  6. 6 10
      Muzzle/Update.xaml.cs

+ 6 - 6
Muzzle/Add.xaml

@@ -10,19 +10,19 @@
         <StackPanel Orientation = "Vertical" >
             <StackPanel Orientation="Horizontal">
                 <Label Content = "Артикул" ></Label>
-                <TextBox Width="100" Height="15"></TextBox>
+                <TextBox x:Name="Art" Width="100" Height="15"></TextBox>
             </StackPanel>
             <StackPanel Orientation = "Horizontal" >
                 <Label Content="Наименование"></Label>
-                <TextBox Width = "100" Height="15"></TextBox>
+                <TextBox x:Name="Title" Width = "100" Height="15"></TextBox>
             </StackPanel>
             <StackPanel Orientation = "Horizontal" >
                 <Label Content="Тип продукта"></Label>
-                <ComboBox Width = "150" Height="15"></ComboBox>
+                <ComboBox  Width = "150" Height="15"></ComboBox>
             </StackPanel>
             <StackPanel Orientation = "Horizontal" >
                 <Label Content="Изображение"></Label>
-                <Button x:Name="btnImage" Content="Загрузить изображение" Width="150" Height="20"></Button>
+                <Button x:Name="btnImage" Content="Загрузить изображение" Width="150" Height="20" Background="White" BorderBrush="#FFFDBD40"></Button>
             </StackPanel>
             <StackPanel Orientation = "Horizontal" >
                 <Label Content="Количество человек для производства"></Label>
@@ -41,8 +41,8 @@
                 <TextBox Width = "300" Height="100"></TextBox>
             </StackPanel>
             <StackPanel Orientation="Vertical">
-                <Button x:Name="btnDob" Content="Добавить" Width="100" Height="20" HorizontalAlignment="Left" Margin="10,10,0,10"></Button>
-                <Button x:Name="btnNaz" Content="Назад" Width="100" Height="20" HorizontalAlignment="Left" Margin="10,0,0,0" Click="btnNaz_Click"></Button>
+                <Button x:Name="btnDob" Content="Добавить" Width="100" Height="20" HorizontalAlignment="Left" Margin="10,10,0,10" Background="White" BorderBrush="#FFFDBD40" Click="btnDob_Click"></Button>
+                <Button x:Name="btnNaz" Content="Назад" Width="100" Height="20" HorizontalAlignment="Left" Margin="10,0,0,0" Click="btnNaz_Click" Background="White" BorderBrush="#FFFDBD40"></Button>
             </StackPanel>
         </StackPanel>
     </Grid>

+ 17 - 0
Muzzle/Add.xaml.cs

@@ -11,6 +11,7 @@ using System.Windows.Input;
 using System.Windows.Media;
 using System.Windows.Media.Imaging;
 using System.Windows.Shapes;
+using Muzzle.Class;
 
 namespace Muzzle
 {
@@ -26,6 +27,7 @@ namespace Muzzle
         public Add()
         {
             InitializeComponent();
+
         }
 
         private void btnNaz_Click(object sender, RoutedEventArgs e)
@@ -37,5 +39,20 @@ namespace Muzzle
         {
 
         }
+
+        private void btnDob_Click(object sender, RoutedEventArgs e)
+        {
+     
+            BaseConnect.baseConnect.SaveChanges();//сонхронизировать с сервером
+            //создаем запись в таблице Users, соответствующую данной                 
+            Product data = new Product();
+            data.ArticleNumber = Art.Text;
+            data.Title = Title.Text;
+            //data.dr = dateBirth.SelectedDate.Value;
+            //data.gender = (int)listGenders.SelectedValue;
+            BaseConnect.baseConnect.Product.Add(data);
+            BaseConnect.baseConnect.SaveChanges();
+            MessageBox.Show("Данные записаны успешно");//обратная связь с пользователем
+        }
     }
 }

+ 30 - 23
Muzzle/Pages/Main.xaml

@@ -8,30 +8,36 @@
       d:DesignHeight="450" d:DesignWidth="800"
       Title="Main">
     <Page.Resources>
+        <Style TargetType="StackPanel" x:Key="SPstyle">
+            <Style.Triggers>
+                <DataTrigger Binding="{Binding TooOld}" Value="True">
+                    <Setter Property="Background" Value="#FFFDBD40"/>
+                </DataTrigger>
+            </Style.Triggers>
+        </Style>
         <DataTemplate x:Key="NamordnikInfo">
-            <Border BorderBrush="Black" BorderThickness="1" Margin="10">
-            <StackPanel Orientation="Horizontal" Width="800" Height="100" Margin="10">
-                <Image Source="{Binding Image}" Width="80" Height="80"/>
-                <StackPanel Margin="10" VerticalAlignment="Center" HorizontalAlignment="Left">
-                    <StackPanel Orientation="Horizontal">
-                        <TextBlock Text="{Binding Title}"/>
-                        <TextBlock Text=" | "/>
-                        <TextBlock Text="{Binding ProductType.Title}"/>
-                    </StackPanel>
-                    <StackPanel>
-                        <TextBlock Text="{Binding ArticleNumber}"/>
-                    </StackPanel>
-                    <StackPanel Orientation="Horizontal">
-                        <TextBlock Text="Материалы: "/>
-                        <TextBlock Text="{Binding Material.Title}"  Loaded="TextBlock_Loaded" Tag="{Binding ID}"/>
-                    </StackPanel>
+            <Border BorderBrush="#FFFDBD40" BorderThickness="1" Margin="10">
+                <StackPanel Orientation="Horizontal" Width="800" Height="100" Margin="10">
+                    <Image Source="{Binding Image}" Width="80" Height="80"/>
+                    <StackPanel Margin="10" VerticalAlignment="Center" HorizontalAlignment="Left">
                         <StackPanel Orientation="Horizontal">
-                            <Button x:Name="btnRed" Content="Редактировать" Width="100" Height="20" Margin="5" Click="btnIzmena_CLick"></Button>
+                            <TextBlock Text="{Binding Title}"/>
+                            <TextBlock Text=" | "/>
+                            <TextBlock Text="{Binding ProductType.Title}"/>
                         </StackPanel>
-                </StackPanel>
-                <TextBlock Text="{Binding Material.Cost}" Loaded="TextBlock_Loaded_1" Tag="{Binding ID}" VerticalAlignment="Center"/>
-                <TextBlock Text=" руб."  VerticalAlignment="Center"/>
-                    
+                        <StackPanel>
+                            <TextBlock Text="{Binding ArticleNumber}"/>
+                        </StackPanel>
+                        <StackPanel Orientation="Horizontal">
+                            <TextBlock Text="Материалы: "/>
+                            <TextBlock Text="{Binding Material.Title}" Loaded="TextBlock_Loaded" Tag="{Binding ID}"/>
+                        </StackPanel>
+                        <StackPanel Orientation="Horizontal">
+                            <Button x:Name="btnRed" Content="Редактировать" Width="100" Height="20" Margin="0,5,0,0" Click="btnIzmena_CLick" Background="White" BorderBrush="#FFFDBD40"></Button>
+                        </StackPanel>
+                    </StackPanel>
+                    <TextBlock Text="{Binding Material.Cost}" Loaded="TextBlock_Loaded_1" Tag="{Binding ID}" VerticalAlignment="Center"/>
+                    <TextBlock Text=" руб."  VerticalAlignment="Center"/>
                 </StackPanel>
             </Border>
         </DataTemplate>
@@ -53,11 +59,12 @@
                 <ComboBoxItem Content="Минимальная стоимость (по убыванию)"/>
             </ComboBox>
             <ComboBox x:Name="You" Width="190" Height="20" Margin="10,0,0,0" SelectionChanged="ComboBox_SelectionChanged"/>
-            
         </StackPanel>
+        
         <ListBox x:Name="listBoxNamordnik" Grid.Row="1" ItemTemplate="{StaticResource NamordnikInfo}"/>
+        
         <StackPanel Grid.Row="2" Margin="0,10,0,0">
-            <Button x:Name="btnDobby" Content="Добавить продукцию" Width="130" Height="20" Margin="0" Click="btnDobby_Click"></Button>
+            <Button x:Name="btnDobby" Content="Добавить продукцию" Width="200" Height="20" Margin="0" Click="btnDobby_Click" Background="White" BorderBrush="#FFFDBD40"></Button>
         </StackPanel>
     </Grid>
 </Page>

+ 4 - 12
Muzzle/Pages/Main.xaml.cs

@@ -1,18 +1,8 @@
-using System;
+using Muzzle.Class;
 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 Muzzle.Class;
 
 namespace Muzzle
 {
@@ -21,6 +11,7 @@ namespace Muzzle
     /// </summary>
     public partial class Main : Page
     {
+        int idProduct = 0;
         public static class Products
         {
             public static Frame frm;
@@ -44,6 +35,7 @@ namespace Muzzle
 
             //Сравнивает ID и заносит в одну строку все материалы, которые относятся к этому продукту
             int productID = (int)textBlock.Tag;
+            idProduct = productID;
             List<ProductMaterial> materials = BaseConnect.baseConnect.ProductMaterial.Where(x => x.ProductID == productID).ToList(); 
             string str = "";
             foreach (ProductMaterial pm in materials)
@@ -144,7 +136,7 @@ namespace Muzzle
 
         private void btnIzmena_CLick(object sender, RoutedEventArgs e)
         {
-            Update update = new Update();
+            Update update = new Update(idProduct);
             update.ShowDialog();
         }
     }       

+ 25 - 18
Muzzle/Update.xaml

@@ -9,40 +9,47 @@
     <Grid>
         <StackPanel Orientation = "Vertical" >
             <StackPanel Orientation="Horizontal">
-                <Label Content = "Артикул" ></Label>
-                <TextBox Width="100" Height="15"></TextBox>
+                <Label Content = "Артикул"/>
+                <TextBox x:Name="Art" Width="100" Height="15"/>
             </StackPanel>
             <StackPanel Orientation = "Horizontal" >
-                <Label Content="Наименование"></Label>
-                <TextBox Width = "100" Height="15"></TextBox>
+                <Label Content="Наименование"/>
+                <TextBox  x:Name="Title" Width = "100" Height="15"/>
             </StackPanel>
             <StackPanel Orientation = "Horizontal" >
-                <Label Content="Тип продукта"></Label>
-                <ComboBox Width = "150" Height="15"></ComboBox>
+                <Label Content="Тип продукта"/>
+                <ComboBox Width = "150" Height="15" >
+                    <ComboBox.Background>
+                        <LinearGradientBrush EndPoint="0,1" StartPoint="0,0">
+                            <GradientStop Color="#FFF0F0F0" Offset="0"/>
+                            <GradientStop Color="White" Offset="1"/>
+                        </LinearGradientBrush>
+                    </ComboBox.Background>
+                </ComboBox>
             </StackPanel>
             <StackPanel Orientation = "Horizontal" >
-                <Label Content="Изображение"></Label>
-                <Button x:Name="btnImage" Content="Загрузить изображение" Width="150" Height="20"></Button>
+                <Label Content="Изображение"/>
+                <Button x:Name="btnImage" Content="Изменить изображение" Width="150" Height="20" Background="White" BorderBrush="#FFFDBD40"/>
             </StackPanel>
             <StackPanel Orientation = "Horizontal" >
-                <Label Content="Количество человек для производства"></Label>
-                <TextBox Width = "100" Height="15"></TextBox>
+                <Label Content="Количество человек для производства"/>
+                <TextBox Width = "100" Height="15"/>
             </StackPanel>
             <StackPanel Orientation = "Horizontal" >
-                <Label Content="Номер производственого цеха"></Label>
-                <TextBox Width = "100" Height="15"></TextBox>
+                <Label Content="Номер производственого цеха"/>
+                <TextBox Width = "100" Height="15"/>
             </StackPanel>
             <StackPanel Orientation = "Horizontal" >
-                <Label Content="Минимальная стоимость для агента"></Label>
-                <TextBox Width = "100" Height="15"></TextBox>
+                <Label Content="Минимальная стоимость для агента"/>
+                <TextBox Width = "100" Height="15"/>
             </StackPanel>
             <StackPanel Orientation = "Horizontal" >
-                <Label Content="Описание"></Label>
-                <TextBox Width = "300" Height="100"></TextBox>
+                <Label Content="Описание"/>
+                <TextBox Width = "300" Height="100"/>
             </StackPanel>
             <StackPanel Orientation="Vertical">
-                <Button x:Name="btnDob" Content="Готово" Width="100" Height="20" HorizontalAlignment="Left" Margin="10,10,0,10"></Button>
-                <Button x:Name="btnNaz" Content="Назад" Width="100" Height="20" HorizontalAlignment="Left" Margin="10,0,0,0" Click="btnNaz_Click"></Button>
+                <Button x:Name="btnDob" Content="Готово" Width="100" Height="20" HorizontalAlignment="Left" Margin="10,10,0,10" Background="White" BorderBrush="#FFFDBD40"/>
+                <Button x:Name="btnNaz" Content="Назад" Width="100" Height="20" HorizontalAlignment="Left" Margin="10,0,0,0" Click="btnNaz_Click" Background="White" BorderBrush="#FFFDBD40"/>
             </StackPanel>
         </StackPanel>
     </Grid>

+ 6 - 10
Muzzle/Update.xaml.cs

@@ -1,16 +1,8 @@
-using System;
+using Muzzle.Class;
 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 Muzzle
 {
@@ -23,9 +15,13 @@ namespace Muzzle
         {
             public static Frame frm;
         }
-        public Update()
+        public Update(int idProduct)
         {
             InitializeComponent();
+            Product products = BaseConnect.baseConnect.Product.FirstOrDefault(x => x.ID == idProduct); //Изменили Where на FirstOrDefault для того, чтобы выбирать не все записи из таблицы, а конкретный продукт
+            Art.Text = products.ArticleNumber; //Считывание пОля из таблицы (вывод данных в поле в макете) 
+            Title.Text = products.Title;
+         
         }
         private void btnNaz_Click(object sender, RoutedEventArgs e)
         {