![](./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
```
```
## 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 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);
}
}
}
}
```