![](./scrs/1.jpg)
![](./scrs/2.jpg)
## Naterial.cs

```
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace wpf_connection3.model
{
    public class Material
    {
        public int ID { get; set; }
        public string Title { get; set; }
        public override string ToString()
        {
            return Title;
        }
    }
}

```

## Product,cs

```
public class Product
    {
        public int ID { get; set; }
        public string Title { get; set; }
        public string? Image { get; set; }
        public int ProductTypeID { get; set; }
        public string ProductTypeTitle { get; set; }
        public string ArticleNumber { get; set; }
        public double? MaterialCost { get; set; }
        public string? MaterialString { get; set; }
        public string Description { get; set; }
        public Uri? ImageBitmap
        {
            get
            {
                var imageName = Environment.CurrentDirectory + (Image ?? "");
                return System.IO.File.Exists(imageName) ? new Uri(imageName) : null;
            }
        }
        public int? LastMonthSaleQuantity { get; set; }
        public int ProductionPersonCount { get; set; }
        public int ProductionWorkshopNumber { get; set; }
        public decimal MinCostForAgent { get; set; }

        public string BackgroundColor

        {
            get
            {
                // возвращаем цвет, в зависимости от количества продаж 
                if (LastMonthSaleQuantity == null || LastMonthSaleQuantity == 0) return "#FF0900"; // не белый
                return "#21B50A"; // не розовый
            }
        }
    }
```

## edit.material.xaml

```
<Window x:Class="wpf_connection3.Windows.EditingMaterialWindow"
        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:wpf_connection3.Windows"
        mc:Ignorable="d"
       Title="Добавление материала" Height="170" Width="400">
    <Grid>
        <StackPanel
            Orientation="Vertical"
            HorizontalAlignment="Center">
            <Label
                    Content="Материал"/>
            <ComboBox
                    Name="MaterialTypeComboBox"
                    Width="200"
                    ItemsSource="{Binding MaterialList}"
                    SelectedIndex="0"/>
            <Label
                    Content="Количество"/>
            <TextBox
                    Width="200"
                    Text="0"
                    x:Name="CountTextBox"/>
            <Button
                    Name="SaveButton"
                    Content="Добавить материал"
                    Margin="0,15"
                    Click="SaveButton_Click"/>
        </StackPanel>
    </Grid>
</Window>

```

## edit.material.cs


```
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.Media.Media3D;
using System.Windows.Shapes;
using wpf_connection3.model;

namespace wpf_connection3.Windows
{

    public partial class EditingMaterialWindow : Window
    {
        public List<model.Material> MaterialList { get; set; }
        public int ID { get; set; }
        public EditingMaterialWindow(int currentProductID)
        {
            InitializeComponent();
            ID = currentProductID;
            DataContext = this;
            MaterialList = Globals.dataProvider.getMaterials();
        }

        private void SaveButton_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                var material = new ProductMaterial();
                material.ProductId = ID;
                material.Count = Convert.ToInt32(CountTextBox.Text);
                material.MaterialId = (MaterialTypeComboBox.SelectedItem as model.Material).ID;
                Globals.dataProvider.addProductMaterial(material);
                DialogResult = true;
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
    }
}

```