This commit is contained in:
Данияр Аглиуллов 2023-03-04 23:34:50 +04:00
commit 667748c3ee
10 changed files with 1054 additions and 1055 deletions

View File

@ -7,107 +7,106 @@ using Microsoft.Extensions.Logging;
namespace ConfectioneryBusinessLogic.BusinessLogics namespace ConfectioneryBusinessLogic.BusinessLogics
{ {
public class ComponentLogic : IComponentLogic public class ComponentLogic : IComponentLogic
{ {
private readonly ILogger _logger; private readonly ILogger _logger;
private readonly IComponentStorage _componentStorage; private readonly IComponentStorage _componentStorage;
public ComponentLogic(ILogger<ComponentLogic> logger, IComponentStorage componentStorage) public ComponentLogic(ILogger<ComponentLogic> logger, IComponentStorage componentStorage)
{ {
_logger = logger; _logger = logger;
_componentStorage = componentStorage; _componentStorage = componentStorage;
} }
public List<ComponentViewModel>? ReadList(ComponentSearchModel? model) public List<ComponentViewModel>? ReadList(ComponentSearchModel? model)
{ {
_logger.LogInformation("ReadList. PastryName:{PastryName}.Id:{ Id} ", _logger.LogInformation("ReadList. ComponentName:{ComponentName}.Id:{ Id} ",
model?.ComponentName, model?.Id); model?.ComponentName, model?.Id);
var list = (model == null) ? _componentStorage.GetFullList() : var list = (model == null) ? _componentStorage.GetFullList() :
_componentStorage.GetFilteredList(model); _componentStorage.GetFilteredList(model);
if (list == null) if (list == null)
{ {
_logger.LogWarning("ReadList return null list"); _logger.LogWarning("ReadList return null list");
return null; return null;
} }
_logger.LogInformation("ReadList. Count:{Count}", list.Count); _logger.LogInformation("ReadList. Count:{Count}", list.Count);
return list; return list;
} }
public ComponentViewModel? ReadElement(ComponentSearchModel model) public ComponentViewModel? ReadElement(ComponentSearchModel model)
{ {
if (model == null) if (model == null)
{ {
throw new ArgumentNullException(nameof(model)); throw new ArgumentNullException(nameof(model));
} }
_logger.LogInformation("ReadElement. PastryName:{PastryName}.Id:{ Id}", _logger.LogInformation("ReadElement. ComponentName:{ComponentName}.Id:{ Id}",
model.ComponentName, model.Id); model.ComponentName, model.Id);
var element = _componentStorage.GetElement(model); var element = _componentStorage.GetElement(model);
if (element == null) if (element == null)
{ {
_logger.LogWarning("ReadElement element not found"); _logger.LogWarning("ReadElement element not found");
return null; return null;
} }
_logger.LogInformation("ReadElement find. Id:{Id}", element.Id); _logger.LogInformation("ReadElement find. Id:{Id}", element.Id);
return element; return element;
} }
public bool Create(ComponentBindingModel model) public bool Create(ComponentBindingModel model)
{ {
CheckModel(model); CheckModel(model);
if (_componentStorage.Insert(model) == null) if (_componentStorage.Insert(model) == null)
{ {
_logger.LogWarning("Insert operation failed"); _logger.LogWarning("Insert operation failed");
return false; return false;
} }
return true; return true;
} }
public bool Update(ComponentBindingModel model) public bool Update(ComponentBindingModel model)
{ {
CheckModel(model); CheckModel(model);
if (_componentStorage.Update(model) == null) if (_componentStorage.Update(model) == null)
{ {
_logger.LogWarning("Update operation failed"); _logger.LogWarning("Update operation failed");
return false; return false;
} }
return true; return true;
} }
public bool Delete(ComponentBindingModel model) public bool Delete(ComponentBindingModel model)
{ {
CheckModel(model, false); CheckModel(model, false);
_logger.LogInformation("Delete. Id:{Id}", model.Id); _logger.LogInformation("Delete. Id:{Id}", model.Id);
if (_componentStorage.Delete(model) == null) if (_componentStorage.Delete(model) == null)
{ {
_logger.LogWarning("Delete operation failed"); _logger.LogWarning("Delete operation failed");
return false; return false;
} }
return true; return true;
} }
private void CheckModel(ComponentBindingModel model, bool withParams = private void CheckModel(ComponentBindingModel model, bool withParams = true)
true) {
{ if (model == null)
if (model == null) {
{ throw new ArgumentNullException(nameof(model));
throw new ArgumentNullException(nameof(model)); }
} if (!withParams)
if (!withParams) {
{ return;
return; }
} if (string.IsNullOrEmpty(model.ComponentName))
if (string.IsNullOrEmpty(model.ComponentName)) {
{ throw new ArgumentNullException("Нет названия компонента",
throw new ArgumentNullException("Нет названия компонента", nameof(model.ComponentName));
nameof(model.ComponentName)); }
} if (model.Cost <= 0)
if (model.Cost <= 0) {
{ throw new ArgumentNullException("Цена компонента должна быть больше 0", nameof(model.Cost));
throw new ArgumentNullException("Цена компонента должна быть больше 0", nameof(model.Cost)); }
} _logger.LogInformation("Component. ComponentName:{ComponentName}.Cost:{ Cost}. Id: { Id}",
_logger.LogInformation("Components. PastryName:{PastryName}.Cost:{ Cost}. Id: { Id}", model.ComponentName, model.Cost, model.Id);
model.ComponentName, model.Cost, model.Id); var element = _componentStorage.GetElement(new ComponentSearchModel
var element = _componentStorage.GetElement(new ComponentSearchModel {
{ ComponentName = model.ComponentName
ComponentName = model.ComponentName });
}); if (element != null && element.Id != model.Id)
if (element != null && element.Id != model.Id) {
{ throw new InvalidOperationException("Компонент с таким названием уже есть");
throw new InvalidOperationException("Компонент с таким названием уже есть"); }
} }
} }
}
} }

View File

@ -6,55 +6,55 @@ using System.Xml.Linq;
namespace ConfectioneryFileImplement.Models namespace ConfectioneryFileImplement.Models
{ {
public class Component : IComponentModel public class Component : IComponentModel
{ {
public int Id { get; private set; } public int Id { get; private set; }
public string ComponentName { get; private set; } = string.Empty; public string ComponentName { get; private set; } = string.Empty;
public double Cost { get; set; } public double Cost { get; set; }
public static Component? Create(ComponentBindingModel model) public static Component? Create(ComponentBindingModel model)
{ {
if (model == null) if (model == null)
{ {
return null; return null;
} }
return new Component() return new Component()
{ {
Id = model.Id, Id = model.Id,
ComponentName = model.ComponentName, ComponentName = model.ComponentName,
Cost = model.Cost Cost = model.Cost
}; };
} }
public static Component? Create(XElement element) public static Component? Create(XElement element)
{ {
if (element == null) if (element == null)
{ {
return null; return null;
} }
return new Component() return new Component()
{ {
Id = Convert.ToInt32(element.Attribute("Id")!.Value), Id = Convert.ToInt32(element.Attribute("Id")!.Value),
ComponentName = element.Element("PastryName")!.Value, ComponentName = element.Element("ComponentName")!.Value,
Cost = Convert.ToDouble(element.Element("Cost")!.Value) Cost = Convert.ToDouble(element.Element("Cost")!.Value)
}; };
} }
public void Update(ComponentBindingModel model) public void Update(ComponentBindingModel model)
{ {
if (model == null) if (model == null)
{ {
return; return;
} }
ComponentName = model.ComponentName; ComponentName = model.ComponentName;
Cost = model.Cost; Cost = model.Cost;
} }
public ComponentViewModel GetViewModel => new() public ComponentViewModel GetViewModel => new()
{ {
Id = Id, Id = Id,
ComponentName = ComponentName, ComponentName = ComponentName,
Cost = Cost Cost = Cost
}; };
public XElement GetXElement => new("Components", public XElement GetXElement => new("Component",
new XAttribute("Id", Id), new XAttribute("Id", Id),
new XElement("PastryName", ComponentName), new XElement("ComponentName", ComponentName),
new XElement("Cost", Cost.ToString())); new XElement("Cost", Cost.ToString()));
} }
} }

View File

@ -6,7 +6,7 @@ namespace ConfectioneryFileImplement
public class DataFileSingleton public class DataFileSingleton
{ {
private static DataFileSingleton? instance; private static DataFileSingleton? instance;
private readonly string ComponentFileName = "Components.xml"; private readonly string ComponentFileName = "Component.xml";
private readonly string OrderFileName = "Order.xml"; private readonly string OrderFileName = "Order.xml";
private readonly string PastryFileName = "Pastry.xml"; private readonly string PastryFileName = "Pastry.xml";
private readonly string ClientFileName = "Client.xml"; private readonly string ClientFileName = "Client.xml";
@ -24,13 +24,13 @@ namespace ConfectioneryFileImplement
return instance; return instance;
} }
public void SaveComponents() => SaveData(Components, ComponentFileName, "Components", x => x.GetXElement); public void SaveComponents() => SaveData(Components, ComponentFileName, "Components", x => x.GetXElement);
public void SavePastries() => SaveData(Pastries, PastryFileName, "Components", x => x.GetXElement); public void SavePastries() => SaveData(Pastries, PastryFileName, "Pastries", x => x.GetXElement);
public void SaveOrders() => SaveData(Orders, OrderFileName, "Orders", x => x.GetXElement); public void SaveOrders() => SaveData(Orders, OrderFileName, "Orders", x => x.GetXElement);
public void SaveClients() => SaveData(Orders, OrderFileName, "Clients", x => x.GetXElement); public void SaveClients() => SaveData(Orders, OrderFileName, "Clients", x => x.GetXElement);
private DataFileSingleton() private DataFileSingleton()
{ {
Components = LoadData(ComponentFileName, "Components", x => Component.Create(x)!)!; Components = LoadData(ComponentFileName, "Component", x => Component.Create(x)!)!;
Pastries = LoadData(PastryFileName, "Pastry", x => Pastry.Create(x)!)!; Pastries = LoadData(PastryFileName, "Pastry", x => Pastry.Create(x)!)!;
Orders = LoadData(OrderFileName, "Order", x => Order.Create(x)!)!; Orders = LoadData(OrderFileName, "Order", x => Order.Create(x)!)!;
Clients = LoadData(ClientFileName, "Client", x => Client.Create(x)!)!; Clients = LoadData(ClientFileName, "Client", x => Client.Create(x)!)!;

View File

@ -4,101 +4,101 @@ using Microsoft.Extensions.Logging;
namespace ConfectioneryView namespace ConfectioneryView
{ {
public partial class FormComponents : Form public partial class FormComponents : Form
{ {
private readonly ILogger _logger; private readonly ILogger _logger;
private readonly IComponentLogic _logic; private readonly IComponentLogic _logic;
public FormComponents(ILogger<FormComponents> logger, IComponentLogic logic) public FormComponents(ILogger<FormComponents> logger, IComponentLogic logic)
{ {
InitializeComponent(); InitializeComponent();
_logger = logger; _logger = logger;
_logic = logic; _logic = logic;
} }
private void FormComponents_Load(object sender, EventArgs e) private void FormComponents_Load(object sender, EventArgs e)
{ {
LoadData(); LoadData();
} }
private void LoadData() private void LoadData()
{ {
try try
{ {
var list = _logic.ReadList(null); var list = _logic.ReadList(null);
if (list != null) if (list != null)
{ {
dataGridView.DataSource = list; dataGridView.DataSource = list;
dataGridView.Columns["Id"].Visible = false; dataGridView.Columns["Id"].Visible = false;
dataGridView.Columns["ComponentName"].AutoSizeMode = dataGridView.Columns["ComponentName"].AutoSizeMode =
DataGridViewAutoSizeColumnMode.Fill; DataGridViewAutoSizeColumnMode.Fill;
} }
_logger.LogInformation("Загрузка компонентов"); _logger.LogInformation("Загрузка компонентов");
} }
catch (Exception ex) catch (Exception ex)
{ {
_logger.LogError(ex, "Ошибка загрузки компонентов"); _logger.LogError(ex, "Ошибка загрузки компонентов");
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK,
MessageBoxIcon.Error); MessageBoxIcon.Error);
} }
} }
private void ButtonAdd_Click(object sender, EventArgs e) private void ButtonAdd_Click(object sender, EventArgs e)
{ {
var service = var service =
Program.ServiceProvider?.GetService(typeof(FormComponent)); Program.ServiceProvider?.GetService(typeof(FormComponent));
if (service is FormComponent form) if (service is FormComponent form)
{ {
if (form.ShowDialog() == DialogResult.OK) if (form.ShowDialog() == DialogResult.OK)
{ {
LoadData(); LoadData();
} }
} }
} }
private void ButtonUpd_Click(object sender, EventArgs e) private void ButtonUpd_Click(object sender, EventArgs e)
{ {
if (dataGridView.SelectedRows.Count == 1) if (dataGridView.SelectedRows.Count == 1)
{ {
var service = Program.ServiceProvider?.GetService(typeof(FormComponent)); var service = Program.ServiceProvider?.GetService(typeof(FormComponent));
if (service is FormComponent form) if (service is FormComponent form)
{ {
form.Id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); form.Id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value);
if (form.ShowDialog() == DialogResult.OK) if (form.ShowDialog() == DialogResult.OK)
{ {
LoadData(); LoadData();
} }
} }
} }
} }
private void ButtonDel_Click(object sender, EventArgs e) private void ButtonDel_Click(object sender, EventArgs e)
{ {
if (dataGridView.SelectedRows.Count == 1) if (dataGridView.SelectedRows.Count == 1)
{ {
if (MessageBox.Show("Удалить запись?", "Вопрос", if (MessageBox.Show("Удалить запись?", "Вопрос",
MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
{ {
int id = int id =
Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value);
_logger.LogInformation("Удаление компонента"); _logger.LogInformation("Удаление компонента");
try try
{ {
if (!_logic.Delete(new ComponentBindingModel if (!_logic.Delete(new ComponentBindingModel
{ {
Id = id Id = id
})) }))
{ {
throw new Exception("Ошибка при удалении. Дополнительная информация в логах."); throw new Exception("Ошибка при удалении. Дополнительная информация в логах.");
} }
LoadData(); LoadData();
} }
catch (Exception ex) catch (Exception ex)
{ {
_logger.LogError(ex, "Ошибка удаления компонента"); _logger.LogError(ex, "Ошибка удаления компонента");
MessageBox.Show(ex.Message, "Ошибка", MessageBox.Show(ex.Message, "Ошибка",
MessageBoxButtons.OK, MessageBoxIcon.Error); MessageBoxButtons.OK, MessageBoxIcon.Error);
} }
} }
} }
} }
private void ButtonRef_Click(object sender, EventArgs e) private void ButtonRef_Click(object sender, EventArgs e)
{ {
LoadData(); LoadData();
} }
} }
} }

View File

@ -1,236 +1,236 @@
namespace ConfectioneryView namespace ConfectioneryView
{ {
partial class FormPastry partial class FormPastry
{ {
/// <summary> /// <summary>
/// Required designer variable. /// Required designer variable.
/// </summary> /// </summary>
private System.ComponentModel.IContainer components = null; private System.ComponentModel.IContainer components = null;
/// <summary> /// <summary>
/// Clean up any resources being used. /// Clean up any resources being used.
/// </summary> /// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param> /// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing) protected override void Dispose(bool disposing)
{ {
if (disposing && (components != null)) if (disposing && (components != null))
{ {
components.Dispose(); components.Dispose();
} }
base.Dispose(disposing); base.Dispose(disposing);
} }
#region Windows Form Designer generated code #region Windows Form Designer generated code
/// <summary> /// <summary>
/// Required method for Designer support - do not modify /// Required method for Designer support - do not modify
/// the contents of this method with the code editor. /// the contents of this method with the code editor.
/// </summary> /// </summary>
private void InitializeComponent() private void InitializeComponent()
{ {
this.label1 = new System.Windows.Forms.Label(); this.label1 = new System.Windows.Forms.Label();
this.label2 = new System.Windows.Forms.Label(); this.label2 = new System.Windows.Forms.Label();
this.groupBox1 = new System.Windows.Forms.GroupBox(); this.groupBox1 = new System.Windows.Forms.GroupBox();
this.buttonRef = new System.Windows.Forms.Button(); this.buttonRef = new System.Windows.Forms.Button();
this.buttonDel = new System.Windows.Forms.Button(); this.buttonDel = new System.Windows.Forms.Button();
this.buttonUpd = new System.Windows.Forms.Button(); this.buttonUpd = new System.Windows.Forms.Button();
this.buttonAdd = new System.Windows.Forms.Button(); this.buttonAdd = new System.Windows.Forms.Button();
this.dataGridView = new System.Windows.Forms.DataGridView(); this.dataGridView = new System.Windows.Forms.DataGridView();
this.id = new System.Windows.Forms.DataGridViewTextBoxColumn(); this.id = new System.Windows.Forms.DataGridViewTextBoxColumn();
this.Component = new System.Windows.Forms.DataGridViewTextBoxColumn(); this.Component = new System.Windows.Forms.DataGridViewTextBoxColumn();
this.Count = new System.Windows.Forms.DataGridViewTextBoxColumn(); this.Count = new System.Windows.Forms.DataGridViewTextBoxColumn();
this.textBoxName = new System.Windows.Forms.TextBox(); this.textBoxName = new System.Windows.Forms.TextBox();
this.textBoxPrice = new System.Windows.Forms.TextBox(); this.textBoxPrice = new System.Windows.Forms.TextBox();
this.buttonCancel = new System.Windows.Forms.Button(); this.buttonCancel = new System.Windows.Forms.Button();
this.buttonSave = new System.Windows.Forms.Button(); this.buttonSave = new System.Windows.Forms.Button();
this.groupBox1.SuspendLayout(); this.groupBox1.SuspendLayout();
((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit(); ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit();
this.SuspendLayout(); this.SuspendLayout();
// //
// label1 // label1
// //
this.label1.AutoSize = true; this.label1.AutoSize = true;
this.label1.Location = new System.Drawing.Point(12, 9); this.label1.Location = new System.Drawing.Point(12, 9);
this.label1.Name = "label1"; this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(62, 15); this.label1.Size = new System.Drawing.Size(62, 15);
this.label1.TabIndex = 0; this.label1.TabIndex = 0;
this.label1.Text = "Название:"; this.label1.Text = "Название:";
// //
// label2 // label2
// //
this.label2.AutoSize = true; this.label2.AutoSize = true;
this.label2.Location = new System.Drawing.Point(12, 40); this.label2.Location = new System.Drawing.Point(12, 40);
this.label2.Name = "label2"; this.label2.Name = "label2";
this.label2.Size = new System.Drawing.Size(70, 15); this.label2.Size = new System.Drawing.Size(70, 15);
this.label2.TabIndex = 1; this.label2.TabIndex = 1;
this.label2.Text = "Стоимость:"; this.label2.Text = "Стоимость:";
// //
// groupBox1 // groupBox1
// //
this.groupBox1.AutoSizeMode = System.Windows.Forms.AutoSizeMode.GrowAndShrink; this.groupBox1.AutoSizeMode = System.Windows.Forms.AutoSizeMode.GrowAndShrink;
this.groupBox1.Controls.Add(this.buttonRef); this.groupBox1.Controls.Add(this.buttonRef);
this.groupBox1.Controls.Add(this.buttonDel); this.groupBox1.Controls.Add(this.buttonDel);
this.groupBox1.Controls.Add(this.buttonUpd); this.groupBox1.Controls.Add(this.buttonUpd);
this.groupBox1.Controls.Add(this.buttonAdd); this.groupBox1.Controls.Add(this.buttonAdd);
this.groupBox1.Controls.Add(this.dataGridView); this.groupBox1.Controls.Add(this.dataGridView);
this.groupBox1.Location = new System.Drawing.Point(12, 67); this.groupBox1.Location = new System.Drawing.Point(12, 67);
this.groupBox1.Name = "groupBox1"; this.groupBox1.Name = "groupBox1";
this.groupBox1.RightToLeft = System.Windows.Forms.RightToLeft.No; this.groupBox1.RightToLeft = System.Windows.Forms.RightToLeft.No;
this.groupBox1.Size = new System.Drawing.Size(776, 330); this.groupBox1.Size = new System.Drawing.Size(776, 330);
this.groupBox1.TabIndex = 2; this.groupBox1.TabIndex = 2;
this.groupBox1.TabStop = false; this.groupBox1.TabStop = false;
this.groupBox1.Text = "Компоненты:"; this.groupBox1.Text = "Компоненты:";
// //
// buttonRef // buttonRef
// //
this.buttonRef.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); this.buttonRef.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
this.buttonRef.Location = new System.Drawing.Point(680, 207); this.buttonRef.Location = new System.Drawing.Point(680, 207);
this.buttonRef.Name = "buttonRef"; this.buttonRef.Name = "buttonRef";
this.buttonRef.Size = new System.Drawing.Size(90, 37); this.buttonRef.Size = new System.Drawing.Size(90, 37);
this.buttonRef.TabIndex = 4; this.buttonRef.TabIndex = 4;
this.buttonRef.Text = "Обновить"; this.buttonRef.Text = "Обновить";
this.buttonRef.UseVisualStyleBackColor = true; this.buttonRef.UseVisualStyleBackColor = true;
this.buttonRef.Click += new System.EventHandler(this.ButtonRef_Click); this.buttonRef.Click += new System.EventHandler(this.ButtonRef_Click);
// //
// buttonDel // buttonDel
// //
this.buttonDel.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); this.buttonDel.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
this.buttonDel.Location = new System.Drawing.Point(680, 158); this.buttonDel.Location = new System.Drawing.Point(680, 158);
this.buttonDel.Name = "buttonDel"; this.buttonDel.Name = "buttonDel";
this.buttonDel.Size = new System.Drawing.Size(90, 33); this.buttonDel.Size = new System.Drawing.Size(90, 33);
this.buttonDel.TabIndex = 3; this.buttonDel.TabIndex = 3;
this.buttonDel.Text = "Удалить"; this.buttonDel.Text = "Удалить";
this.buttonDel.UseVisualStyleBackColor = true; this.buttonDel.UseVisualStyleBackColor = true;
this.buttonDel.Click += new System.EventHandler(this.ButtonDel_Click); this.buttonDel.Click += new System.EventHandler(this.ButtonDel_Click);
// //
// buttonUpd // buttonUpd
// //
this.buttonUpd.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); this.buttonUpd.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
this.buttonUpd.Location = new System.Drawing.Point(680, 108); this.buttonUpd.Location = new System.Drawing.Point(680, 108);
this.buttonUpd.Name = "buttonUpd"; this.buttonUpd.Name = "buttonUpd";
this.buttonUpd.Size = new System.Drawing.Size(90, 34); this.buttonUpd.Size = new System.Drawing.Size(90, 34);
this.buttonUpd.TabIndex = 2; this.buttonUpd.TabIndex = 2;
this.buttonUpd.Text = "Изменить"; this.buttonUpd.Text = "Изменить";
this.buttonUpd.UseVisualStyleBackColor = true; this.buttonUpd.UseVisualStyleBackColor = true;
this.buttonUpd.Click += new System.EventHandler(this.ButtonUpd_Click); this.buttonUpd.Click += new System.EventHandler(this.ButtonUpd_Click);
// //
// buttonAdd // buttonAdd
// //
this.buttonAdd.Location = new System.Drawing.Point(680, 62); this.buttonAdd.Location = new System.Drawing.Point(680, 62);
this.buttonAdd.Name = "buttonAdd"; this.buttonAdd.Name = "buttonAdd";
this.buttonAdd.Size = new System.Drawing.Size(90, 30); this.buttonAdd.Size = new System.Drawing.Size(90, 30);
this.buttonAdd.TabIndex = 1; this.buttonAdd.TabIndex = 1;
this.buttonAdd.Text = "Добавить"; this.buttonAdd.Text = "Добавить";
this.buttonAdd.UseVisualStyleBackColor = true; this.buttonAdd.UseVisualStyleBackColor = true;
this.buttonAdd.Click += new System.EventHandler(this.ButtonAdd_Click); this.buttonAdd.Click += new System.EventHandler(this.ButtonAdd_Click);
// //
// dataGridView // dataGridView
// //
this.dataGridView.AutoSizeColumnsMode = System.Windows.Forms.DataGridViewAutoSizeColumnsMode.ColumnHeader; this.dataGridView.AutoSizeColumnsMode = System.Windows.Forms.DataGridViewAutoSizeColumnsMode.ColumnHeader;
this.dataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; this.dataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
this.dataGridView.Columns.AddRange(new System.Windows.Forms.DataGridViewColumn[] { this.dataGridView.Columns.AddRange(new System.Windows.Forms.DataGridViewColumn[] {
this.id, this.id,
this.Component, this.Component,
this.Count}); this.Count});
this.dataGridView.Location = new System.Drawing.Point(7, 22); this.dataGridView.Location = new System.Drawing.Point(7, 22);
this.dataGridView.Name = "dataGridView"; this.dataGridView.Name = "dataGridView";
this.dataGridView.RowTemplate.Height = 25; this.dataGridView.RowTemplate.Height = 25;
this.dataGridView.Size = new System.Drawing.Size(571, 302); this.dataGridView.Size = new System.Drawing.Size(571, 302);
this.dataGridView.TabIndex = 0; this.dataGridView.TabIndex = 0;
// //
// id // id
// //
this.id.HeaderText = "id"; this.id.HeaderText = "id";
this.id.Name = "id"; this.id.Name = "id";
this.id.Visible = false; this.id.Visible = false;
// //
// Components // Component
// //
this.Component.AutoSizeMode = System.Windows.Forms.DataGridViewAutoSizeColumnMode.Fill; this.Component.AutoSizeMode = System.Windows.Forms.DataGridViewAutoSizeColumnMode.Fill;
this.Component.FillWeight = 1000F; this.Component.FillWeight = 1000F;
this.Component.HeaderText = "Компонент"; this.Component.HeaderText = "Компонент";
this.Component.Name = "Components"; this.Component.Name = "Component";
// //
// Count // Count
// //
this.Count.HeaderText = "Количество"; this.Count.HeaderText = "Количество";
this.Count.Name = "Count"; this.Count.Name = "Count";
this.Count.Width = 97; this.Count.Width = 97;
// //
// textBoxName // textBoxName
// //
this.textBoxName.Location = new System.Drawing.Point(89, 9); this.textBoxName.Location = new System.Drawing.Point(89, 9);
this.textBoxName.Name = "textBoxName"; this.textBoxName.Name = "textBoxName";
this.textBoxName.Size = new System.Drawing.Size(170, 23); this.textBoxName.Size = new System.Drawing.Size(170, 23);
this.textBoxName.TabIndex = 3; this.textBoxName.TabIndex = 3;
// //
// textBoxPrice // textBoxPrice
// //
this.textBoxPrice.Location = new System.Drawing.Point(89, 38); this.textBoxPrice.Location = new System.Drawing.Point(89, 38);
this.textBoxPrice.Name = "textBoxPrice"; this.textBoxPrice.Name = "textBoxPrice";
this.textBoxPrice.Size = new System.Drawing.Size(120, 23); this.textBoxPrice.Size = new System.Drawing.Size(120, 23);
this.textBoxPrice.TabIndex = 4; this.textBoxPrice.TabIndex = 4;
// //
// buttonCancel // buttonCancel
// //
this.buttonCancel.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); this.buttonCancel.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
this.buttonCancel.Location = new System.Drawing.Point(692, 403); this.buttonCancel.Location = new System.Drawing.Point(692, 403);
this.buttonCancel.Name = "buttonCancel"; this.buttonCancel.Name = "buttonCancel";
this.buttonCancel.Size = new System.Drawing.Size(90, 35); this.buttonCancel.Size = new System.Drawing.Size(90, 35);
this.buttonCancel.TabIndex = 5; this.buttonCancel.TabIndex = 5;
this.buttonCancel.Text = "Отмена"; this.buttonCancel.Text = "Отмена";
this.buttonCancel.UseVisualStyleBackColor = true; this.buttonCancel.UseVisualStyleBackColor = true;
this.buttonCancel.Click += new System.EventHandler(this.ButtonCancel_Click); this.buttonCancel.Click += new System.EventHandler(this.ButtonCancel_Click);
// //
// buttonSave // buttonSave
// //
this.buttonSave.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); this.buttonSave.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
this.buttonSave.Location = new System.Drawing.Point(596, 403); this.buttonSave.Location = new System.Drawing.Point(596, 403);
this.buttonSave.Name = "buttonSave"; this.buttonSave.Name = "buttonSave";
this.buttonSave.Size = new System.Drawing.Size(90, 35); this.buttonSave.Size = new System.Drawing.Size(90, 35);
this.buttonSave.TabIndex = 6; this.buttonSave.TabIndex = 6;
this.buttonSave.Text = "Сохранить"; this.buttonSave.Text = "Сохранить";
this.buttonSave.UseVisualStyleBackColor = true; this.buttonSave.UseVisualStyleBackColor = true;
this.buttonSave.Click += new System.EventHandler(this.ButtonSave_Click); this.buttonSave.Click += new System.EventHandler(this.ButtonSave_Click);
// //
// FormPastry // FormPastry
// //
this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(800, 450); this.ClientSize = new System.Drawing.Size(800, 450);
this.Controls.Add(this.buttonSave); this.Controls.Add(this.buttonSave);
this.Controls.Add(this.buttonCancel); this.Controls.Add(this.buttonCancel);
this.Controls.Add(this.textBoxPrice); this.Controls.Add(this.textBoxPrice);
this.Controls.Add(this.textBoxName); this.Controls.Add(this.textBoxName);
this.Controls.Add(this.groupBox1); this.Controls.Add(this.groupBox1);
this.Controls.Add(this.label2); this.Controls.Add(this.label2);
this.Controls.Add(this.label1); this.Controls.Add(this.label1);
this.Name = "FormPastry"; this.Name = "FormPastry";
this.Text = "Кондитерское изделие"; this.Text = "Кондитерское изделие";
this.Load += new System.EventHandler(this.FormPastry_Load); this.Load += new System.EventHandler(this.FormPastry_Load);
this.groupBox1.ResumeLayout(false); this.groupBox1.ResumeLayout(false);
((System.ComponentModel.ISupportInitialize)(this.dataGridView)).EndInit(); ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).EndInit();
this.ResumeLayout(false); this.ResumeLayout(false);
this.PerformLayout(); this.PerformLayout();
} }
#endregion #endregion
private Label label1; private Label label1;
private Label label2; private Label label2;
private GroupBox groupBox1; private GroupBox groupBox1;
private TextBox textBoxName; private TextBox textBoxName;
private TextBox textBoxPrice; private TextBox textBoxPrice;
private Button buttonRef; private Button buttonRef;
private Button buttonDel; private Button buttonDel;
private Button buttonUpd; private Button buttonUpd;
private Button buttonAdd; private Button buttonAdd;
private DataGridView dataGridView; private DataGridView dataGridView;
private DataGridViewTextBoxColumn id; private DataGridViewTextBoxColumn id;
private DataGridViewTextBoxColumn Component; private DataGridViewTextBoxColumn Component;
private DataGridViewTextBoxColumn Count; private DataGridViewTextBoxColumn Count;
private Button buttonCancel; private Button buttonCancel;
private Button buttonSave; private Button buttonSave;
} }
} }

View File

@ -6,208 +6,208 @@ using Microsoft.Extensions.Logging;
namespace ConfectioneryView namespace ConfectioneryView
{ {
public partial class FormPastry : Form public partial class FormPastry : Form
{ {
private readonly ILogger _logger; private readonly ILogger _logger;
private readonly IPastryLogic _logic; private readonly IPastryLogic _logic;
private int? _id; private int? _id;
private Dictionary<int, (IComponentModel, int)> _pastryComponents; private Dictionary<int, (IComponentModel, int)> _pastryComponents;
public int Id { set { _id = value; } } public int Id { set { _id = value; } }
public FormPastry(ILogger<FormPastry> logger, IPastryLogic logic) public FormPastry(ILogger<FormPastry> logger, IPastryLogic logic)
{ {
InitializeComponent(); InitializeComponent();
_logger = logger; _logger = logger;
_logic = logic; _logic = logic;
_pastryComponents = new Dictionary<int, (IComponentModel, int)>(); _pastryComponents = new Dictionary<int, (IComponentModel, int)>();
} }
private void FormPastry_Load(object sender, EventArgs e) private void FormPastry_Load(object sender, EventArgs e)
{ {
if (_id.HasValue) if (_id.HasValue)
{ {
_logger.LogInformation("Загрузка изделия"); _logger.LogInformation("Загрузка изделия");
try try
{ {
var view = _logic.ReadElement(new PastrySearchModel var view = _logic.ReadElement(new PastrySearchModel
{ {
Id = _id.Value Id = _id.Value
}); });
if (view != null) if (view != null)
{ {
textBoxName.Text = view.PastryName; textBoxName.Text = view.PastryName;
textBoxPrice.Text = view.Price.ToString(); textBoxPrice.Text = view.Price.ToString();
_pastryComponents = view.PastryComponents ?? new _pastryComponents = view.PastryComponents ?? new
Dictionary<int, (IComponentModel, int)>(); Dictionary<int, (IComponentModel, int)>();
LoadData(); LoadData();
} }
} }
catch (Exception ex) catch (Exception ex)
{ {
_logger.LogError(ex, "Ошибка загрузки изделия"); _logger.LogError(ex, "Ошибка загрузки изделия");
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK,
MessageBoxIcon.Error); MessageBoxIcon.Error);
} }
} }
} }
private void LoadData() private void LoadData()
{ {
_logger.LogInformation("Загрузка компонент изделия"); _logger.LogInformation("Загрузка компонент изделия");
try try
{ {
if (_pastryComponents != null) if (_pastryComponents != null)
{ {
dataGridView.Rows.Clear(); dataGridView.Rows.Clear();
foreach (var pc in _pastryComponents) foreach (var pc in _pastryComponents)
{ {
dataGridView.Rows.Add(new object[] { pc.Key, pc.Value.Item1.ComponentName, pc.Value.Item2 }); dataGridView.Rows.Add(new object[] { pc.Key, pc.Value.Item1.ComponentName, pc.Value.Item2 });
} }
textBoxPrice.Text = CalcPrice().ToString(); textBoxPrice.Text = CalcPrice().ToString();
} }
} }
catch (Exception ex) catch (Exception ex)
{ {
_logger.LogError(ex, "Ошибка загрузки компонент изделия"); _logger.LogError(ex, "Ошибка загрузки компонент изделия");
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK,
MessageBoxIcon.Error); MessageBoxIcon.Error);
} }
} }
private void ButtonAdd_Click(object sender, EventArgs e) private void ButtonAdd_Click(object sender, EventArgs e)
{ {
var service = var service =
Program.ServiceProvider?.GetService(typeof(FormPastryComponent)); Program.ServiceProvider?.GetService(typeof(FormPastryComponent));
if (service is FormPastryComponent form) if (service is FormPastryComponent form)
{ {
if (form.ShowDialog() == DialogResult.OK) if (form.ShowDialog() == DialogResult.OK)
{ {
if (form.ComponentModel == null) if (form.ComponentModel == null)
{ {
return; return;
} }
_logger.LogInformation("Добавление нового компонента: { PastryName}- { Count}", _logger.LogInformation("Добавление нового компонента: { ComponentName}- { Count}",
form.ComponentModel.ComponentName, form.Count); form.ComponentModel.ComponentName, form.Count);
if (_pastryComponents.ContainsKey(form.Id)) if (_pastryComponents.ContainsKey(form.Id))
{ {
_pastryComponents[form.Id] = (form.ComponentModel, _pastryComponents[form.Id] = (form.ComponentModel,
form.Count); form.Count);
} }
else else
{ {
_pastryComponents.Add(form.Id, (form.ComponentModel, _pastryComponents.Add(form.Id, (form.ComponentModel,
form.Count)); form.Count));
} }
LoadData(); LoadData();
} }
} }
} }
private void ButtonUpd_Click(object sender, EventArgs e) private void ButtonUpd_Click(object sender, EventArgs e)
{ {
if (dataGridView.SelectedRows.Count == 1) if (dataGridView.SelectedRows.Count == 1)
{ {
var service = Program.ServiceProvider?.GetService(typeof(FormPastryComponent)); var service = Program.ServiceProvider?.GetService(typeof(FormPastryComponent));
if (service is FormPastryComponent form) if (service is FormPastryComponent form)
{ {
int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells[0].Value); int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells[0].Value);
form.Id = id; form.Id = id;
form.Count = _pastryComponents[id].Item2; form.Count = _pastryComponents[id].Item2;
if (form.ShowDialog() == DialogResult.OK) if (form.ShowDialog() == DialogResult.OK)
{ {
if (form.ComponentModel == null) if (form.ComponentModel == null)
{ {
return; return;
} }
_logger.LogInformation("Изменение компонента: { PastryName} - { Count} ", _logger.LogInformation("Изменение компонента: { ComponentName} - { Count} ",
form.ComponentModel.ComponentName, form.Count); form.ComponentModel.ComponentName, form.Count);
_pastryComponents[id] = (form.ComponentModel, form.Count); _pastryComponents[id] = (form.ComponentModel, form.Count);
LoadData(); LoadData();
} }
} }
} }
} }
private void ButtonDel_Click(object sender, EventArgs e) private void ButtonDel_Click(object sender, EventArgs e)
{ {
if (dataGridView.SelectedRows.Count == 1) if (dataGridView.SelectedRows.Count == 1)
{ {
if (MessageBox.Show("Удалить запись?", "Вопрос", if (MessageBox.Show("Удалить запись?", "Вопрос",
MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
{ {
try try
{ {
_logger.LogInformation("Удаление компонента: { PastryName}- { Count}", _logger.LogInformation("Удаление компонента: { ComponentName}- { Count}",
dataGridView.SelectedRows[0].Cells[1].Value); dataGridView.SelectedRows[0].Cells[1].Value);
_pastryComponents?.Remove(Convert.ToInt32(dataGridView.SelectedRows[0].Cells[0].Value)); _pastryComponents?.Remove(Convert.ToInt32(dataGridView.SelectedRows[0].Cells[0].Value));
} }
catch (Exception ex) catch (Exception ex)
{ {
MessageBox.Show(ex.Message, "Ошибка", MessageBox.Show(ex.Message, "Ошибка",
MessageBoxButtons.OK, MessageBoxIcon.Error); MessageBoxButtons.OK, MessageBoxIcon.Error);
} }
LoadData(); LoadData();
} }
} }
} }
private void ButtonRef_Click(object sender, EventArgs e) private void ButtonRef_Click(object sender, EventArgs e)
{ {
LoadData(); LoadData();
} }
private void ButtonSave_Click(object sender, EventArgs e) private void ButtonSave_Click(object sender, EventArgs e)
{ {
if (string.IsNullOrEmpty(textBoxName.Text)) if (string.IsNullOrEmpty(textBoxName.Text))
{ {
MessageBox.Show("Заполните название", "Ошибка", MessageBox.Show("Заполните название", "Ошибка",
MessageBoxButtons.OK, MessageBoxIcon.Error); MessageBoxButtons.OK, MessageBoxIcon.Error);
return; return;
} }
if (string.IsNullOrEmpty(textBoxPrice.Text)) if (string.IsNullOrEmpty(textBoxPrice.Text))
{ {
MessageBox.Show("Заполните цену", "Ошибка", MessageBoxButtons.OK, MessageBox.Show("Заполните цену", "Ошибка", MessageBoxButtons.OK,
MessageBoxIcon.Error); MessageBoxIcon.Error);
return; return;
} }
if (_pastryComponents == null || _pastryComponents.Count == 0) if (_pastryComponents == null || _pastryComponents.Count == 0)
{ {
MessageBox.Show("Заполните компоненты", "Ошибка", MessageBox.Show("Заполните компоненты", "Ошибка",
MessageBoxButtons.OK, MessageBoxIcon.Error); MessageBoxButtons.OK, MessageBoxIcon.Error);
return; return;
} }
_logger.LogInformation("Сохранение изделия"); _logger.LogInformation("Сохранение изделия");
try try
{ {
var model = new PastryBindingModel var model = new PastryBindingModel
{ {
Id = _id ?? 0, Id = _id ?? 0,
PastryName = textBoxName.Text, PastryName = textBoxName.Text,
Price = Convert.ToDouble(textBoxPrice.Text), Price = Convert.ToDouble(textBoxPrice.Text),
PastryComponents = _pastryComponents PastryComponents = _pastryComponents
}; };
var operationResult = _id.HasValue ? _logic.Update(model) : var operationResult = _id.HasValue ? _logic.Update(model) :
_logic.Create(model); _logic.Create(model);
if (!operationResult) if (!operationResult)
{ {
throw new Exception("Ошибка при сохранении. Дополнительная информация в логах."); throw new Exception("Ошибка при сохранении. Дополнительная информация в логах.");
} }
MessageBox.Show("Сохранение прошло успешно", "Сообщение", MessageBox.Show("Сохранение прошло успешно", "Сообщение",
MessageBoxButtons.OK, MessageBoxIcon.Information); MessageBoxButtons.OK, MessageBoxIcon.Information);
DialogResult = DialogResult.OK; DialogResult = DialogResult.OK;
Close(); Close();
} }
catch (Exception ex) catch (Exception ex)
{ {
_logger.LogError(ex, "Ошибка сохранения изделия"); _logger.LogError(ex, "Ошибка сохранения изделия");
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
} }
} }
private void ButtonCancel_Click(object sender, EventArgs e) private void ButtonCancel_Click(object sender, EventArgs e)
{ {
DialogResult = DialogResult.Cancel; DialogResult = DialogResult.Cancel;
Close(); Close();
} }
private double CalcPrice() private double CalcPrice()
{ {
double price = 0; double price = 0;
foreach (var elem in _pastryComponents) foreach (var elem in _pastryComponents)
{ {
price += ((elem.Value.Item1?.Cost ?? 0) * elem.Value.Item2); price += ((elem.Value.Item1?.Cost ?? 0) * elem.Value.Item2);
} }
return Math.Round(price * 1.1, 2); return Math.Round(price * 1.1, 2);
} }
} }
} }

View File

@ -4,76 +4,76 @@ using ConfectioneryDataModels.Models;
namespace ConfectioneryView namespace ConfectioneryView
{ {
public partial class FormPastryComponent : Form public partial class FormPastryComponent : Form
{ {
private readonly List<ComponentViewModel>? _list; private readonly List<ComponentViewModel>? _list;
public int Id public int Id
{ {
get get
{ {
return Convert.ToInt32(comboBoxComponent.SelectedValue); return Convert.ToInt32(comboBoxComponent.SelectedValue);
} }
set set
{ {
comboBoxComponent.SelectedValue = value; comboBoxComponent.SelectedValue = value;
} }
} }
public IComponentModel? ComponentModel public IComponentModel? ComponentModel
{ {
get get
{ {
if (_list == null) if (_list == null)
{ {
return null; return null;
} }
foreach (var elem in _list) foreach (var elem in _list)
{ {
if (elem.Id == Id) if (elem.Id == Id)
{ {
return elem; return elem;
} }
} }
return null; return null;
} }
} }
public int Count public int Count
{ {
get { return Convert.ToInt32(textBoxCount.Text); } get { return Convert.ToInt32(textBoxCount.Text); }
set { textBoxCount.Text = value.ToString(); } set { textBoxCount.Text = value.ToString(); }
} }
public FormPastryComponent(IComponentLogic logic) public FormPastryComponent(IComponentLogic logic)
{ {
InitializeComponent(); InitializeComponent();
_list = logic.ReadList(null); _list = logic.ReadList(null);
if (_list != null) if (_list != null)
{ {
comboBoxComponent.DisplayMember = "PastryName"; comboBoxComponent.DisplayMember = "ComponentName";
comboBoxComponent.ValueMember = "Id"; comboBoxComponent.ValueMember = "Id";
comboBoxComponent.DataSource = _list; comboBoxComponent.DataSource = _list;
comboBoxComponent.SelectedItem = null; comboBoxComponent.SelectedItem = null;
} }
} }
private void ButtonSave_Click(object sender, EventArgs e) private void ButtonSave_Click(object sender, EventArgs e)
{ {
if (string.IsNullOrEmpty(textBoxCount.Text)) if (string.IsNullOrEmpty(textBoxCount.Text))
{ {
MessageBox.Show("Заполните поле Количество", "Ошибка", MessageBox.Show("Заполните поле Количество", "Ошибка",
MessageBoxButtons.OK, MessageBoxIcon.Error); MessageBoxButtons.OK, MessageBoxIcon.Error);
return; return;
} }
if (comboBoxComponent.SelectedValue == null) if (comboBoxComponent.SelectedValue == null)
{ {
MessageBox.Show("Выберите компонент", "Ошибка", MessageBox.Show("Выберите компонент", "Ошибка",
MessageBoxButtons.OK, MessageBoxIcon.Error); MessageBoxButtons.OK, MessageBoxIcon.Error);
return; return;
} }
DialogResult = DialogResult.OK; DialogResult = DialogResult.OK;
Close(); Close();
} }
private void ButtonCancel_Click(object sender, EventArgs e) private void ButtonCancel_Click(object sender, EventArgs e)
{ {
DialogResult = DialogResult.Cancel; DialogResult = DialogResult.Cancel;
Close(); Close();
} }
} }
} }

View File

@ -11,161 +11,161 @@ using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
namespace ConfectioneryDatabaseImplement.Migrations namespace ConfectioneryDatabaseImplement.Migrations
{ {
[DbContext(typeof(ConfectioneryDatabase))] [DbContext(typeof(ConfectioneryDatabase))]
[Migration("20230219142123_InitialCreate")] [Migration("20230219142123_InitialCreate")]
partial class InitialCreate partial class InitialCreate
{ {
/// <inheritdoc /> /// <inheritdoc />
protected override void BuildTargetModel(ModelBuilder modelBuilder) protected override void BuildTargetModel(ModelBuilder modelBuilder)
{ {
#pragma warning disable 612, 618 #pragma warning disable 612, 618
modelBuilder modelBuilder
.HasAnnotation("ProductVersion", "7.0.3") .HasAnnotation("ProductVersion", "7.0.3")
.HasAnnotation("Relational:MaxIdentifierLength", 128); .HasAnnotation("Relational:MaxIdentifierLength", 128);
SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder); SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder);
modelBuilder.Entity("ConfectioneryDatabaseImplement.Models.Components", b => modelBuilder.Entity("ConfectioneryDatabaseImplement.Models.Component", b =>
{ {
b.Property<int>("Id") b.Property<int>("Id")
.ValueGeneratedOnAdd() .ValueGeneratedOnAdd()
.HasColumnType("int"); .HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id")); SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<string>("PastryName") b.Property<string>("ComponentName")
.IsRequired() .IsRequired()
.HasColumnType("nvarchar(max)"); .HasColumnType("nvarchar(max)");
b.Property<double>("Cost") b.Property<double>("Cost")
.HasColumnType("float"); .HasColumnType("float");
b.HasKey("Id"); b.HasKey("Id");
b.ToTable("Components"); b.ToTable("Components");
}); });
modelBuilder.Entity("ConfectioneryDatabaseImplement.Models.Order", b => modelBuilder.Entity("ConfectioneryDatabaseImplement.Models.Order", b =>
{ {
b.Property<int>("Id") b.Property<int>("Id")
.ValueGeneratedOnAdd() .ValueGeneratedOnAdd()
.HasColumnType("int"); .HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id")); SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<int>("Count") b.Property<int>("Count")
.HasColumnType("int"); .HasColumnType("int");
b.Property<DateTime>("DateCreate") b.Property<DateTime>("DateCreate")
.HasColumnType("datetime2"); .HasColumnType("datetime2");
b.Property<DateTime?>("DateImplement") b.Property<DateTime?>("DateImplement")
.HasColumnType("datetime2"); .HasColumnType("datetime2");
b.Property<int>("PastryId") b.Property<int>("PastryId")
.HasColumnType("int"); .HasColumnType("int");
b.Property<int>("Status") b.Property<int>("Status")
.HasColumnType("int"); .HasColumnType("int");
b.Property<double>("Sum") b.Property<double>("Sum")
.HasColumnType("float"); .HasColumnType("float");
b.HasKey("Id"); b.HasKey("Id");
b.HasIndex("PastryId"); b.HasIndex("PastryId");
b.ToTable("Orders"); b.ToTable("Orders");
}); });
modelBuilder.Entity("ConfectioneryDatabaseImplement.Models.Pastry", b => modelBuilder.Entity("ConfectioneryDatabaseImplement.Models.Pastry", b =>
{ {
b.Property<int>("Id") b.Property<int>("Id")
.ValueGeneratedOnAdd() .ValueGeneratedOnAdd()
.HasColumnType("int"); .HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id")); SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<string>("PastryName") b.Property<string>("PastryName")
.IsRequired() .IsRequired()
.HasColumnType("nvarchar(max)"); .HasColumnType("nvarchar(max)");
b.Property<double>("Price") b.Property<double>("Price")
.HasColumnType("float"); .HasColumnType("float");
b.HasKey("Id"); b.HasKey("Id");
b.ToTable("Components"); b.ToTable("Pastries");
}); });
modelBuilder.Entity("ConfectioneryDatabaseImplement.Models.PastryComponent", b => modelBuilder.Entity("ConfectioneryDatabaseImplement.Models.PastryComponent", b =>
{ {
b.Property<int>("Id") b.Property<int>("Id")
.ValueGeneratedOnAdd() .ValueGeneratedOnAdd()
.HasColumnType("int"); .HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id")); SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<int>("ComponentId") b.Property<int>("ComponentId")
.HasColumnType("int"); .HasColumnType("int");
b.Property<int>("Count") b.Property<int>("Count")
.HasColumnType("int"); .HasColumnType("int");
b.Property<int>("PastryId") b.Property<int>("PastryId")
.HasColumnType("int"); .HasColumnType("int");
b.HasKey("Id"); b.HasKey("Id");
b.HasIndex("ComponentId"); b.HasIndex("ComponentId");
b.HasIndex("PastryId"); b.HasIndex("PastryId");
b.ToTable("PastryComponents"); b.ToTable("PastryComponents");
}); });
modelBuilder.Entity("ConfectioneryDatabaseImplement.Models.Order", b => modelBuilder.Entity("ConfectioneryDatabaseImplement.Models.Order", b =>
{ {
b.HasOne("ConfectioneryDatabaseImplement.Models.Pastry", "Pastry") b.HasOne("ConfectioneryDatabaseImplement.Models.Pastry", "Pastry")
.WithMany("Orders") .WithMany("Orders")
.HasForeignKey("PastryId") .HasForeignKey("PastryId")
.OnDelete(DeleteBehavior.Cascade) .OnDelete(DeleteBehavior.Cascade)
.IsRequired(); .IsRequired();
b.Navigation("Pastry"); b.Navigation("Pastry");
}); });
modelBuilder.Entity("ConfectioneryDatabaseImplement.Models.PastryComponent", b => modelBuilder.Entity("ConfectioneryDatabaseImplement.Models.PastryComponent", b =>
{ {
b.HasOne("ConfectioneryDatabaseImplement.Models.Components", "Components") b.HasOne("ConfectioneryDatabaseImplement.Models.Component", "Component")
.WithMany("PastryComponents") .WithMany("PastryComponents")
.HasForeignKey("ComponentId") .HasForeignKey("ComponentId")
.OnDelete(DeleteBehavior.Cascade) .OnDelete(DeleteBehavior.Cascade)
.IsRequired(); .IsRequired();
b.HasOne("ConfectioneryDatabaseImplement.Models.Pastry", "Pastry") b.HasOne("ConfectioneryDatabaseImplement.Models.Pastry", "Pastry")
.WithMany("Components") .WithMany("Components")
.HasForeignKey("PastryId") .HasForeignKey("PastryId")
.OnDelete(DeleteBehavior.Cascade) .OnDelete(DeleteBehavior.Cascade)
.IsRequired(); .IsRequired();
b.Navigation("Components"); b.Navigation("Component");
b.Navigation("Pastry"); b.Navigation("Pastry");
}); });
modelBuilder.Entity("ConfectioneryDatabaseImplement.Models.Components", b => modelBuilder.Entity("ConfectioneryDatabaseImplement.Models.Component", b =>
{ {
b.Navigation("PastryComponents"); b.Navigation("PastryComponents");
}); });
modelBuilder.Entity("ConfectioneryDatabaseImplement.Models.Pastry", b => modelBuilder.Entity("ConfectioneryDatabaseImplement.Models.Pastry", b =>
{ {
b.Navigation("Components"); b.Navigation("Components");
b.Navigation("Orders"); b.Navigation("Orders");
}); });
#pragma warning restore 612, 618 #pragma warning restore 612, 618
} }
} }
} }

View File

@ -5,121 +5,121 @@ using Microsoft.EntityFrameworkCore.Migrations;
namespace ConfectioneryDatabaseImplement.Migrations namespace ConfectioneryDatabaseImplement.Migrations
{ {
/// <inheritdoc /> /// <inheritdoc />
public partial class InitialCreate : Migration public partial class InitialCreate : Migration
{ {
/// <inheritdoc /> /// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder) protected override void Up(MigrationBuilder migrationBuilder)
{ {
migrationBuilder.CreateTable( migrationBuilder.CreateTable(
name: "Components", name: "Components",
columns: table => new columns: table => new
{ {
Id = table.Column<int>(type: "int", nullable: false) Id = table.Column<int>(type: "int", nullable: false)
.Annotation("SqlServer:Identity", "1, 1"), .Annotation("SqlServer:Identity", "1, 1"),
ComponentName = table.Column<string>(type: "nvarchar(max)", nullable: false), ComponentName = table.Column<string>(type: "nvarchar(max)", nullable: false),
Cost = table.Column<double>(type: "float", nullable: false) Cost = table.Column<double>(type: "float", nullable: false)
}, },
constraints: table => constraints: table =>
{ {
table.PrimaryKey("PK_Components", x => x.Id); table.PrimaryKey("PK_Components", x => x.Id);
}); });
migrationBuilder.CreateTable( migrationBuilder.CreateTable(
name: "Components", name: "Pastries",
columns: table => new columns: table => new
{ {
Id = table.Column<int>(type: "int", nullable: false) Id = table.Column<int>(type: "int", nullable: false)
.Annotation("SqlServer:Identity", "1, 1"), .Annotation("SqlServer:Identity", "1, 1"),
PastryName = table.Column<string>(type: "nvarchar(max)", nullable: false), PastryName = table.Column<string>(type: "nvarchar(max)", nullable: false),
Price = table.Column<double>(type: "float", nullable: false) Price = table.Column<double>(type: "float", nullable: false)
}, },
constraints: table => constraints: table =>
{ {
table.PrimaryKey("PK_Pastries", x => x.Id); table.PrimaryKey("PK_Pastries", x => x.Id);
}); });
migrationBuilder.CreateTable( migrationBuilder.CreateTable(
name: "Orders", name: "Orders",
columns: table => new columns: table => new
{ {
Id = table.Column<int>(type: "int", nullable: false) Id = table.Column<int>(type: "int", nullable: false)
.Annotation("SqlServer:Identity", "1, 1"), .Annotation("SqlServer:Identity", "1, 1"),
PastryId = table.Column<int>(type: "int", nullable: false), PastryId = table.Column<int>(type: "int", nullable: false),
Count = table.Column<int>(type: "int", nullable: false), Count = table.Column<int>(type: "int", nullable: false),
Sum = table.Column<double>(type: "float", nullable: false), Sum = table.Column<double>(type: "float", nullable: false),
Status = table.Column<int>(type: "int", nullable: false), Status = table.Column<int>(type: "int", nullable: false),
DateCreate = table.Column<DateTime>(type: "datetime2", nullable: false), DateCreate = table.Column<DateTime>(type: "datetime2", nullable: false),
DateImplement = table.Column<DateTime>(type: "datetime2", nullable: true) DateImplement = table.Column<DateTime>(type: "datetime2", nullable: true)
}, },
constraints: table => constraints: table =>
{ {
table.PrimaryKey("PK_Orders", x => x.Id); table.PrimaryKey("PK_Orders", x => x.Id);
table.ForeignKey( table.ForeignKey(
name: "FK_Orders_Pastries_PastryId", name: "FK_Orders_Pastries_PastryId",
column: x => x.PastryId, column: x => x.PastryId,
principalTable: "Components", principalTable: "Pastries",
principalColumn: "Id", principalColumn: "Id",
onDelete: ReferentialAction.Cascade); onDelete: ReferentialAction.Cascade);
}); });
migrationBuilder.CreateTable( migrationBuilder.CreateTable(
name: "PastryComponents", name: "PastryComponents",
columns: table => new columns: table => new
{ {
Id = table.Column<int>(type: "int", nullable: false) Id = table.Column<int>(type: "int", nullable: false)
.Annotation("SqlServer:Identity", "1, 1"), .Annotation("SqlServer:Identity", "1, 1"),
PastryId = table.Column<int>(type: "int", nullable: false), PastryId = table.Column<int>(type: "int", nullable: false),
ComponentId = table.Column<int>(type: "int", nullable: false), ComponentId = table.Column<int>(type: "int", nullable: false),
Count = table.Column<int>(type: "int", nullable: false) Count = table.Column<int>(type: "int", nullable: false)
}, },
constraints: table => constraints: table =>
{ {
table.PrimaryKey("PK_PastryComponents", x => x.Id); table.PrimaryKey("PK_PastryComponents", x => x.Id);
table.ForeignKey( table.ForeignKey(
name: "FK_PastryComponents_Components_ComponentId", name: "FK_PastryComponents_Components_ComponentId",
column: x => x.ComponentId, column: x => x.ComponentId,
principalTable: "Components", principalTable: "Components",
principalColumn: "Id", principalColumn: "Id",
onDelete: ReferentialAction.Cascade); onDelete: ReferentialAction.Cascade);
table.ForeignKey( table.ForeignKey(
name: "FK_PastryComponents_Pastries_PastryId", name: "FK_PastryComponents_Pastries_PastryId",
column: x => x.PastryId, column: x => x.PastryId,
principalTable: "Components", principalTable: "Pastries",
principalColumn: "Id", principalColumn: "Id",
onDelete: ReferentialAction.Cascade); onDelete: ReferentialAction.Cascade);
}); });
migrationBuilder.CreateIndex( migrationBuilder.CreateIndex(
name: "IX_Orders_PastryId", name: "IX_Orders_PastryId",
table: "Orders", table: "Orders",
column: "PastryId"); column: "PastryId");
migrationBuilder.CreateIndex( migrationBuilder.CreateIndex(
name: "IX_PastryComponents_ComponentId", name: "IX_PastryComponents_ComponentId",
table: "PastryComponents", table: "PastryComponents",
column: "ComponentId"); column: "ComponentId");
migrationBuilder.CreateIndex( migrationBuilder.CreateIndex(
name: "IX_PastryComponents_PastryId", name: "IX_PastryComponents_PastryId",
table: "PastryComponents", table: "PastryComponents",
column: "PastryId"); column: "PastryId");
} }
/// <inheritdoc /> /// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder) protected override void Down(MigrationBuilder migrationBuilder)
{ {
migrationBuilder.DropTable( migrationBuilder.DropTable(
name: "Orders"); name: "Orders");
migrationBuilder.DropTable( migrationBuilder.DropTable(
name: "PastryComponents"); name: "PastryComponents");
migrationBuilder.DropTable( migrationBuilder.DropTable(
name: "Components"); name: "Components");
migrationBuilder.DropTable( migrationBuilder.DropTable(
name: "Components"); name: "Pastries");
} }
} }
} }

View File

@ -10,17 +10,17 @@ using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
namespace ConfectioneryDatabaseImplement.Migrations namespace ConfectioneryDatabaseImplement.Migrations
{ {
[DbContext(typeof(ConfectioneryDatabase))] [DbContext(typeof(ConfectioneryDatabase))]
partial class ConfectioneryDatabaseModelSnapshot : ModelSnapshot partial class ConfectioneryDatabaseModelSnapshot : ModelSnapshot
{ {
protected override void BuildModel(ModelBuilder modelBuilder) protected override void BuildModel(ModelBuilder modelBuilder)
{ {
#pragma warning disable 612, 618 #pragma warning disable 612, 618
modelBuilder modelBuilder
.HasAnnotation("ProductVersion", "7.0.3") .HasAnnotation("ProductVersion", "7.0.3")
.HasAnnotation("Relational:MaxIdentifierLength", 128); .HasAnnotation("Relational:MaxIdentifierLength", 128);
SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder); SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder);
modelBuilder.Entity("ConfectioneryDatabaseImplement.Models.Client", b => modelBuilder.Entity("ConfectioneryDatabaseImplement.Models.Client", b =>
{ {
@ -28,7 +28,7 @@ namespace ConfectioneryDatabaseImplement.Migrations
.ValueGeneratedOnAdd() .ValueGeneratedOnAdd()
.HasColumnType("int"); .HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id")); SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<string>("ClientFIO") b.Property<string>("ClientFIO")
.IsRequired() .IsRequired()
@ -59,21 +59,21 @@ namespace ConfectioneryDatabaseImplement.Migrations
.IsRequired() .IsRequired()
.HasColumnType("nvarchar(max)"); .HasColumnType("nvarchar(max)");
b.Property<double>("Cost") b.Property<double>("Cost")
.HasColumnType("float"); .HasColumnType("float");
b.HasKey("Id"); b.HasKey("Id");
b.ToTable("Components"); b.ToTable("Components");
}); });
modelBuilder.Entity("ConfectioneryDatabaseImplement.Models.Order", b => modelBuilder.Entity("ConfectioneryDatabaseImplement.Models.Order", b =>
{ {
b.Property<int>("Id") b.Property<int>("Id")
.ValueGeneratedOnAdd() .ValueGeneratedOnAdd()
.HasColumnType("int"); .HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id")); SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<int>("ClientId") b.Property<int>("ClientId")
.HasColumnType("int"); .HasColumnType("int");
@ -81,75 +81,75 @@ namespace ConfectioneryDatabaseImplement.Migrations
b.Property<int>("Count") b.Property<int>("Count")
.HasColumnType("int"); .HasColumnType("int");
b.Property<DateTime>("DateCreate") b.Property<DateTime>("DateCreate")
.HasColumnType("datetime2"); .HasColumnType("datetime2");
b.Property<DateTime?>("DateImplement") b.Property<DateTime?>("DateImplement")
.HasColumnType("datetime2"); .HasColumnType("datetime2");
b.Property<int>("PastryId") b.Property<int>("PastryId")
.HasColumnType("int"); .HasColumnType("int");
b.Property<int>("Status") b.Property<int>("Status")
.HasColumnType("int"); .HasColumnType("int");
b.Property<double>("Sum") b.Property<double>("Sum")
.HasColumnType("float"); .HasColumnType("float");
b.HasKey("Id"); b.HasKey("Id");
b.HasIndex("ClientId"); b.HasIndex("ClientId");
b.HasIndex("PastryId"); b.HasIndex("PastryId");
b.ToTable("Orders"); b.ToTable("Orders");
}); });
modelBuilder.Entity("ConfectioneryDatabaseImplement.Models.Pastry", b => modelBuilder.Entity("ConfectioneryDatabaseImplement.Models.Pastry", b =>
{ {
b.Property<int>("Id") b.Property<int>("Id")
.ValueGeneratedOnAdd() .ValueGeneratedOnAdd()
.HasColumnType("int"); .HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id")); SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<string>("PastryName") b.Property<string>("PastryName")
.IsRequired() .IsRequired()
.HasColumnType("nvarchar(max)"); .HasColumnType("nvarchar(max)");
b.Property<double>("Price") b.Property<double>("Price")
.HasColumnType("float"); .HasColumnType("float");
b.HasKey("Id"); b.HasKey("Id");
b.ToTable("Pastries"); b.ToTable("Pastries");
}); });
modelBuilder.Entity("ConfectioneryDatabaseImplement.Models.PastryComponent", b => modelBuilder.Entity("ConfectioneryDatabaseImplement.Models.PastryComponent", b =>
{ {
b.Property<int>("Id") b.Property<int>("Id")
.ValueGeneratedOnAdd() .ValueGeneratedOnAdd()
.HasColumnType("int"); .HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id")); SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<int>("ComponentId") b.Property<int>("ComponentId")
.HasColumnType("int"); .HasColumnType("int");
b.Property<int>("Count") b.Property<int>("Count")
.HasColumnType("int"); .HasColumnType("int");
b.Property<int>("PastryId") b.Property<int>("PastryId")
.HasColumnType("int"); .HasColumnType("int");
b.HasKey("Id"); b.HasKey("Id");
b.HasIndex("ComponentId"); b.HasIndex("ComponentId");
b.HasIndex("PastryId"); b.HasIndex("PastryId");
b.ToTable("PastryComponents"); b.ToTable("PastryComponents");
}); });
modelBuilder.Entity("ConfectioneryDatabaseImplement.Models.Order", b => modelBuilder.Entity("ConfectioneryDatabaseImplement.Models.Order", b =>
{ {
@ -178,16 +178,16 @@ namespace ConfectioneryDatabaseImplement.Migrations
.OnDelete(DeleteBehavior.Cascade) .OnDelete(DeleteBehavior.Cascade)
.IsRequired(); .IsRequired();
b.HasOne("ConfectioneryDatabaseImplement.Models.Pastry", "Pastry") b.HasOne("ConfectioneryDatabaseImplement.Models.Pastry", "Pastry")
.WithMany("Components") .WithMany("Components")
.HasForeignKey("PastryId") .HasForeignKey("PastryId")
.OnDelete(DeleteBehavior.Cascade) .OnDelete(DeleteBehavior.Cascade)
.IsRequired(); .IsRequired();
b.Navigation("Component"); b.Navigation("Component");
b.Navigation("Pastry"); b.Navigation("Pastry");
}); });
modelBuilder.Entity("ConfectioneryDatabaseImplement.Models.Client", b => modelBuilder.Entity("ConfectioneryDatabaseImplement.Models.Client", b =>
{ {
@ -199,13 +199,13 @@ namespace ConfectioneryDatabaseImplement.Migrations
b.Navigation("PastryComponents"); b.Navigation("PastryComponents");
}); });
modelBuilder.Entity("ConfectioneryDatabaseImplement.Models.Pastry", b => modelBuilder.Entity("ConfectioneryDatabaseImplement.Models.Pastry", b =>
{ {
b.Navigation("Components"); b.Navigation("Components");
b.Navigation("Orders"); b.Navigation("Orders");
}); });
#pragma warning restore 612, 618 #pragma warning restore 612, 618
} }
} }
} }