From 6b9f987f44af6e10a4450d236bf15f4298d559eb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=94=D0=B0=D0=BD=D0=B8=D1=8F=D1=80=20=D0=90=D0=B3=D0=BB?= =?UTF-8?q?=D0=B8=D1=83=D0=BB=D0=BB=D0=BE=D0=B2?= Date: Sat, 4 Mar 2023 22:53:49 +0400 Subject: [PATCH] =?UTF-8?q?=D0=9F=D0=B5=D1=80=D0=B5=D0=B8=D0=BC=D0=B5?= =?UTF-8?q?=D0=BD=D0=BE=D0=B2=D0=B0=D0=BD=D0=B0=20=D0=BE=D0=B1=D1=80=D0=B0?= =?UTF-8?q?=D1=82=D0=BD=D0=BE=20=D1=81=D0=BB=D1=83=D1=87=D0=B0=D0=B9=D0=BD?= =?UTF-8?q?=D0=B0=D1=8F=20=D0=BF=D0=B5=D1=80=D0=B5=D0=BC=D0=B5=D0=BD=D0=BD?= =?UTF-8?q?=D0=B0=D1=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ConfectionaryBusinessLogic/ComponentLogic.cs | 205 ++++---- ConfectionaryFileImplement/Component.cs | 102 ++-- .../DataFileSingleton.cs | 84 ++-- Confectionery/FormComponents.cs | 194 ++++---- Confectionery/FormPastry.Designer.cs | 454 +++++++++--------- Confectionery/FormPastry.cs | 410 ++++++++-------- Confectionery/FormPastryComponent.cs | 144 +++--- .../20230219142123_InitialCreate.Designer.cs | 226 ++++----- .../20230219142123_InitialCreate.cs | 214 ++++----- .../ConfectioneryDatabaseModelSnapshot.cs | 222 ++++----- 10 files changed, 1127 insertions(+), 1128 deletions(-) diff --git a/ConfectionaryBusinessLogic/ComponentLogic.cs b/ConfectionaryBusinessLogic/ComponentLogic.cs index 8e0237a..01d69fc 100644 --- a/ConfectionaryBusinessLogic/ComponentLogic.cs +++ b/ConfectionaryBusinessLogic/ComponentLogic.cs @@ -7,107 +7,106 @@ using Microsoft.Extensions.Logging; namespace ConfectioneryBusinessLogic.BusinessLogics { - public class ComponentLogic : IComponentLogic - { - private readonly ILogger _logger; - private readonly IComponentStorage _componentStorage; - public ComponentLogic(ILogger logger, IComponentStorage componentStorage) - { - _logger = logger; - _componentStorage = componentStorage; - } - public List? ReadList(ComponentSearchModel? model) - { - _logger.LogInformation("ReadList. PastryName:{PastryName}.Id:{ Id} ", - model?.ComponentName, model?.Id); - var list = (model == null) ? _componentStorage.GetFullList() : - _componentStorage.GetFilteredList(model); - if (list == null) - { - _logger.LogWarning("ReadList return null list"); - return null; - } - _logger.LogInformation("ReadList. Count:{Count}", list.Count); - return list; - } - public ComponentViewModel? ReadElement(ComponentSearchModel model) - { - if (model == null) - { - throw new ArgumentNullException(nameof(model)); - } - _logger.LogInformation("ReadElement. PastryName:{PastryName}.Id:{ Id}", - model.ComponentName, model.Id); - var element = _componentStorage.GetElement(model); - if (element == null) - { - _logger.LogWarning("ReadElement element not found"); - return null; - } - _logger.LogInformation("ReadElement find. Id:{Id}", element.Id); - return element; - } - public bool Create(ComponentBindingModel model) - { - CheckModel(model); - if (_componentStorage.Insert(model) == null) - { - _logger.LogWarning("Insert operation failed"); - return false; - } - return true; - } - public bool Update(ComponentBindingModel model) - { - CheckModel(model); - if (_componentStorage.Update(model) == null) - { - _logger.LogWarning("Update operation failed"); - return false; - } - return true; - } - public bool Delete(ComponentBindingModel model) - { - CheckModel(model, false); - _logger.LogInformation("Delete. Id:{Id}", model.Id); - if (_componentStorage.Delete(model) == null) - { - _logger.LogWarning("Delete operation failed"); - return false; - } - return true; - } - private void CheckModel(ComponentBindingModel model, bool withParams = - true) - { - if (model == null) - { - throw new ArgumentNullException(nameof(model)); - } - if (!withParams) - { - return; - } - if (string.IsNullOrEmpty(model.ComponentName)) - { - throw new ArgumentNullException("Нет названия компонента", - nameof(model.ComponentName)); - } - if (model.Cost <= 0) - { - throw new ArgumentNullException("Цена компонента должна быть больше 0", nameof(model.Cost)); - } - _logger.LogInformation("Components. PastryName:{PastryName}.Cost:{ Cost}. Id: { Id}", - model.ComponentName, model.Cost, model.Id); - var element = _componentStorage.GetElement(new ComponentSearchModel - { - ComponentName = model.ComponentName - }); - if (element != null && element.Id != model.Id) - { - throw new InvalidOperationException("Компонент с таким названием уже есть"); - } - } - } + public class ComponentLogic : IComponentLogic + { + private readonly ILogger _logger; + private readonly IComponentStorage _componentStorage; + public ComponentLogic(ILogger logger, IComponentStorage componentStorage) + { + _logger = logger; + _componentStorage = componentStorage; + } + public List? ReadList(ComponentSearchModel? model) + { + _logger.LogInformation("ReadList. ComponentName:{ComponentName}.Id:{ Id} ", + model?.ComponentName, model?.Id); + var list = (model == null) ? _componentStorage.GetFullList() : + _componentStorage.GetFilteredList(model); + if (list == null) + { + _logger.LogWarning("ReadList return null list"); + return null; + } + _logger.LogInformation("ReadList. Count:{Count}", list.Count); + return list; + } + public ComponentViewModel? ReadElement(ComponentSearchModel model) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + _logger.LogInformation("ReadElement. ComponentName:{ComponentName}.Id:{ Id}", + model.ComponentName, model.Id); + var element = _componentStorage.GetElement(model); + if (element == null) + { + _logger.LogWarning("ReadElement element not found"); + return null; + } + _logger.LogInformation("ReadElement find. Id:{Id}", element.Id); + return element; + } + public bool Create(ComponentBindingModel model) + { + CheckModel(model); + if (_componentStorage.Insert(model) == null) + { + _logger.LogWarning("Insert operation failed"); + return false; + } + return true; + } + public bool Update(ComponentBindingModel model) + { + CheckModel(model); + if (_componentStorage.Update(model) == null) + { + _logger.LogWarning("Update operation failed"); + return false; + } + return true; + } + public bool Delete(ComponentBindingModel model) + { + CheckModel(model, false); + _logger.LogInformation("Delete. Id:{Id}", model.Id); + if (_componentStorage.Delete(model) == null) + { + _logger.LogWarning("Delete operation failed"); + return false; + } + return true; + } + private void CheckModel(ComponentBindingModel model, bool withParams = true) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + if (!withParams) + { + return; + } + if (string.IsNullOrEmpty(model.ComponentName)) + { + throw new ArgumentNullException("Нет названия компонента", + nameof(model.ComponentName)); + } + if (model.Cost <= 0) + { + throw new ArgumentNullException("Цена компонента должна быть больше 0", nameof(model.Cost)); + } + _logger.LogInformation("Component. ComponentName:{ComponentName}.Cost:{ Cost}. Id: { Id}", + model.ComponentName, model.Cost, model.Id); + var element = _componentStorage.GetElement(new ComponentSearchModel + { + ComponentName = model.ComponentName + }); + if (element != null && element.Id != model.Id) + { + throw new InvalidOperationException("Компонент с таким названием уже есть"); + } + } + } } \ No newline at end of file diff --git a/ConfectionaryFileImplement/Component.cs b/ConfectionaryFileImplement/Component.cs index e5adaa5..e6f43e5 100644 --- a/ConfectionaryFileImplement/Component.cs +++ b/ConfectionaryFileImplement/Component.cs @@ -6,55 +6,55 @@ using System.Xml.Linq; namespace ConfectioneryFileImplement.Models { - public class Component : IComponentModel - { - public int Id { get; private set; } - public string ComponentName { get; private set; } = string.Empty; - public double Cost { get; set; } - public static Component? Create(ComponentBindingModel model) - { - if (model == null) - { - return null; - } - return new Component() - { - Id = model.Id, - ComponentName = model.ComponentName, - Cost = model.Cost - }; - } - public static Component? Create(XElement element) - { - if (element == null) - { - return null; - } - return new Component() - { - Id = Convert.ToInt32(element.Attribute("Id")!.Value), - ComponentName = element.Element("PastryName")!.Value, - Cost = Convert.ToDouble(element.Element("Cost")!.Value) - }; - } - public void Update(ComponentBindingModel model) - { - if (model == null) - { - return; - } - ComponentName = model.ComponentName; - Cost = model.Cost; - } - public ComponentViewModel GetViewModel => new() - { - Id = Id, - ComponentName = ComponentName, - Cost = Cost - }; - public XElement GetXElement => new("Components", - new XAttribute("Id", Id), - new XElement("PastryName", ComponentName), - new XElement("Cost", Cost.ToString())); - } + public class Component : IComponentModel + { + public int Id { get; private set; } + public string ComponentName { get; private set; } = string.Empty; + public double Cost { get; set; } + public static Component? Create(ComponentBindingModel model) + { + if (model == null) + { + return null; + } + return new Component() + { + Id = model.Id, + ComponentName = model.ComponentName, + Cost = model.Cost + }; + } + public static Component? Create(XElement element) + { + if (element == null) + { + return null; + } + return new Component() + { + Id = Convert.ToInt32(element.Attribute("Id")!.Value), + ComponentName = element.Element("ComponentName")!.Value, + Cost = Convert.ToDouble(element.Element("Cost")!.Value) + }; + } + public void Update(ComponentBindingModel model) + { + if (model == null) + { + return; + } + ComponentName = model.ComponentName; + Cost = model.Cost; + } + public ComponentViewModel GetViewModel => new() + { + Id = Id, + ComponentName = ComponentName, + Cost = Cost + }; + public XElement GetXElement => new("Component", + new XAttribute("Id", Id), + new XElement("ComponentName", ComponentName), + new XElement("Cost", Cost.ToString())); + } } \ No newline at end of file diff --git a/ConfectionaryFileImplement/DataFileSingleton.cs b/ConfectionaryFileImplement/DataFileSingleton.cs index 19bce37..2116a4a 100644 --- a/ConfectionaryFileImplement/DataFileSingleton.cs +++ b/ConfectionaryFileImplement/DataFileSingleton.cs @@ -3,48 +3,48 @@ using System.Xml.Linq; namespace ConfectioneryFileImplement { - public class DataFileSingleton - { - private static DataFileSingleton? instance; - private readonly string ComponentFileName = "Components.xml"; - private readonly string OrderFileName = "Order.xml"; - private readonly string PastryFileName = "Pastry.xml"; - public List Components { get; private set; } - public List Orders { get; private set; } - public List Pastries { get; private set; } + public class DataFileSingleton + { + private static DataFileSingleton? instance; + private readonly string ComponentFileName = "Component.xml"; + private readonly string OrderFileName = "Order.xml"; + private readonly string PastryFileName = "Pastry.xml"; + public List Components { get; private set; } + public List Orders { get; private set; } + public List Pastries { get; private set; } - public static DataFileSingleton GetInstance() - { - if (instance == null) - { - instance = new DataFileSingleton(); - } - return instance; - } - public void SaveComponents() => SaveData(Components, ComponentFileName, "Components", x => x.GetXElement); - public void SavePastries() => SaveData(Pastries, PastryFileName, "Components", x => x.GetXElement); - public void SaveOrders() => SaveData(Orders, OrderFileName, "Orders", x => x.GetXElement); + public static DataFileSingleton GetInstance() + { + if (instance == null) + { + instance = new DataFileSingleton(); + } + return instance; + } + public void SaveComponents() => SaveData(Components, ComponentFileName, "Components", x => x.GetXElement); + public void SavePastries() => SaveData(Pastries, PastryFileName, "Pastries", x => x.GetXElement); + public void SaveOrders() => SaveData(Orders, OrderFileName, "Orders", x => x.GetXElement); - private DataFileSingleton() - { - Components = LoadData(ComponentFileName, "Components", x => Component.Create(x)!)!; - Pastries = LoadData(PastryFileName, "Pastry", x => Pastry.Create(x)!)!; - Orders = LoadData(OrderFileName, "Order", x => Order.Create(x)!)!; - } - private static List? LoadData(string filename, string xmlNodeName, Func selectFunction) - { - if (File.Exists(filename)) - { - return XDocument.Load(filename)?.Root?.Elements(xmlNodeName)?.Select(selectFunction)?.ToList(); - } - return new List(); - } - private static void SaveData(List data, string filename, string xmlNodeName, Func selectFunction) - { - if (data != null) - { - new XDocument(new XElement(xmlNodeName, data.Select(selectFunction).ToArray())).Save(filename); - } - } - } + private DataFileSingleton() + { + Components = LoadData(ComponentFileName, "Component", x => Component.Create(x)!)!; + Pastries = LoadData(PastryFileName, "Pastry", x => Pastry.Create(x)!)!; + Orders = LoadData(OrderFileName, "Order", x => Order.Create(x)!)!; + } + private static List? LoadData(string filename, string xmlNodeName, Func selectFunction) + { + if (File.Exists(filename)) + { + return XDocument.Load(filename)?.Root?.Elements(xmlNodeName)?.Select(selectFunction)?.ToList(); + } + return new List(); + } + private static void SaveData(List data, string filename, string xmlNodeName, Func selectFunction) + { + if (data != null) + { + new XDocument(new XElement(xmlNodeName, data.Select(selectFunction).ToArray())).Save(filename); + } + } + } } diff --git a/Confectionery/FormComponents.cs b/Confectionery/FormComponents.cs index 2f20d12..160d4d2 100644 --- a/Confectionery/FormComponents.cs +++ b/Confectionery/FormComponents.cs @@ -4,101 +4,101 @@ using Microsoft.Extensions.Logging; namespace ConfectioneryView { - public partial class FormComponents : Form - { - private readonly ILogger _logger; - private readonly IComponentLogic _logic; - public FormComponents(ILogger logger, IComponentLogic logic) - { - InitializeComponent(); - _logger = logger; - _logic = logic; - } - private void FormComponents_Load(object sender, EventArgs e) - { - LoadData(); - } - private void LoadData() - { - try - { - var list = _logic.ReadList(null); - if (list != null) - { - dataGridView.DataSource = list; - dataGridView.Columns["Id"].Visible = false; - dataGridView.Columns["ComponentName"].AutoSizeMode = - DataGridViewAutoSizeColumnMode.Fill; - } - _logger.LogInformation("Загрузка компонентов"); - } - catch (Exception ex) - { - _logger.LogError(ex, "Ошибка загрузки компонентов"); - MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, - MessageBoxIcon.Error); - } - } - private void ButtonAdd_Click(object sender, EventArgs e) - { - var service = - Program.ServiceProvider?.GetService(typeof(FormComponent)); - if (service is FormComponent form) - { - if (form.ShowDialog() == DialogResult.OK) - { - LoadData(); - } - } - } - private void ButtonUpd_Click(object sender, EventArgs e) - { - if (dataGridView.SelectedRows.Count == 1) - { - var service = Program.ServiceProvider?.GetService(typeof(FormComponent)); - if (service is FormComponent form) - { - form.Id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); - if (form.ShowDialog() == DialogResult.OK) - { - LoadData(); - } - } - } - } - private void ButtonDel_Click(object sender, EventArgs e) - { - if (dataGridView.SelectedRows.Count == 1) - { - if (MessageBox.Show("Удалить запись?", "Вопрос", - MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) - { - int id = - Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); - _logger.LogInformation("Удаление компонента"); - try - { - if (!_logic.Delete(new ComponentBindingModel - { - Id = id - })) - { - throw new Exception("Ошибка при удалении. Дополнительная информация в логах."); - } - LoadData(); - } - catch (Exception ex) - { - _logger.LogError(ex, "Ошибка удаления компонента"); - MessageBox.Show(ex.Message, "Ошибка", - MessageBoxButtons.OK, MessageBoxIcon.Error); - } - } - } - } - private void ButtonRef_Click(object sender, EventArgs e) - { - LoadData(); - } - } + public partial class FormComponents : Form + { + private readonly ILogger _logger; + private readonly IComponentLogic _logic; + public FormComponents(ILogger logger, IComponentLogic logic) + { + InitializeComponent(); + _logger = logger; + _logic = logic; + } + private void FormComponents_Load(object sender, EventArgs e) + { + LoadData(); + } + private void LoadData() + { + try + { + var list = _logic.ReadList(null); + if (list != null) + { + dataGridView.DataSource = list; + dataGridView.Columns["Id"].Visible = false; + dataGridView.Columns["ComponentName"].AutoSizeMode = + DataGridViewAutoSizeColumnMode.Fill; + } + _logger.LogInformation("Загрузка компонентов"); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка загрузки компонентов"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, + MessageBoxIcon.Error); + } + } + private void ButtonAdd_Click(object sender, EventArgs e) + { + var service = + Program.ServiceProvider?.GetService(typeof(FormComponent)); + if (service is FormComponent form) + { + if (form.ShowDialog() == DialogResult.OK) + { + LoadData(); + } + } + } + private void ButtonUpd_Click(object sender, EventArgs e) + { + if (dataGridView.SelectedRows.Count == 1) + { + var service = Program.ServiceProvider?.GetService(typeof(FormComponent)); + if (service is FormComponent form) + { + form.Id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); + if (form.ShowDialog() == DialogResult.OK) + { + LoadData(); + } + } + } + } + private void ButtonDel_Click(object sender, EventArgs e) + { + if (dataGridView.SelectedRows.Count == 1) + { + if (MessageBox.Show("Удалить запись?", "Вопрос", + MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) + { + int id = + Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); + _logger.LogInformation("Удаление компонента"); + try + { + if (!_logic.Delete(new ComponentBindingModel + { + Id = id + })) + { + throw new Exception("Ошибка при удалении. Дополнительная информация в логах."); + } + LoadData(); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка удаления компонента"); + MessageBox.Show(ex.Message, "Ошибка", + MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + } + } + private void ButtonRef_Click(object sender, EventArgs e) + { + LoadData(); + } + } } diff --git a/Confectionery/FormPastry.Designer.cs b/Confectionery/FormPastry.Designer.cs index cdd39b4..926fec5 100644 --- a/Confectionery/FormPastry.Designer.cs +++ b/Confectionery/FormPastry.Designer.cs @@ -1,236 +1,236 @@ namespace ConfectioneryView { - partial class FormPastry - { - /// - /// Required designer variable. - /// - private System.ComponentModel.IContainer components = null; + partial class FormPastry + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; - /// - /// Clean up any resources being used. - /// - /// true if managed resources should be disposed; otherwise, false. - protected override void Dispose(bool disposing) - { - if (disposing && (components != null)) - { - components.Dispose(); - } - base.Dispose(disposing); - } + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } - #region Windows Form Designer generated code + #region Windows Form Designer generated code - /// - /// Required method for Designer support - do not modify - /// the contents of this method with the code editor. - /// - private void InitializeComponent() - { - this.label1 = new System.Windows.Forms.Label(); - this.label2 = new System.Windows.Forms.Label(); - this.groupBox1 = new System.Windows.Forms.GroupBox(); - this.buttonRef = new System.Windows.Forms.Button(); - this.buttonDel = new System.Windows.Forms.Button(); - this.buttonUpd = new System.Windows.Forms.Button(); - this.buttonAdd = new System.Windows.Forms.Button(); - this.dataGridView = new System.Windows.Forms.DataGridView(); - this.id = new System.Windows.Forms.DataGridViewTextBoxColumn(); - this.Component = new System.Windows.Forms.DataGridViewTextBoxColumn(); - this.Count = new System.Windows.Forms.DataGridViewTextBoxColumn(); - this.textBoxName = new System.Windows.Forms.TextBox(); - this.textBoxPrice = new System.Windows.Forms.TextBox(); - this.buttonCancel = new System.Windows.Forms.Button(); - this.buttonSave = new System.Windows.Forms.Button(); - this.groupBox1.SuspendLayout(); - ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit(); - this.SuspendLayout(); - // - // label1 - // - this.label1.AutoSize = true; - this.label1.Location = new System.Drawing.Point(12, 9); - this.label1.Name = "label1"; - this.label1.Size = new System.Drawing.Size(62, 15); - this.label1.TabIndex = 0; - this.label1.Text = "Название:"; - // - // label2 - // - this.label2.AutoSize = true; - this.label2.Location = new System.Drawing.Point(12, 40); - this.label2.Name = "label2"; - this.label2.Size = new System.Drawing.Size(70, 15); - this.label2.TabIndex = 1; - this.label2.Text = "Стоимость:"; - // - // groupBox1 - // - this.groupBox1.AutoSizeMode = System.Windows.Forms.AutoSizeMode.GrowAndShrink; - this.groupBox1.Controls.Add(this.buttonRef); - this.groupBox1.Controls.Add(this.buttonDel); - this.groupBox1.Controls.Add(this.buttonUpd); - this.groupBox1.Controls.Add(this.buttonAdd); - this.groupBox1.Controls.Add(this.dataGridView); - this.groupBox1.Location = new System.Drawing.Point(12, 67); - this.groupBox1.Name = "groupBox1"; - this.groupBox1.RightToLeft = System.Windows.Forms.RightToLeft.No; - this.groupBox1.Size = new System.Drawing.Size(776, 330); - this.groupBox1.TabIndex = 2; - this.groupBox1.TabStop = false; - this.groupBox1.Text = "Компоненты:"; - // - // buttonRef - // - 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.Name = "buttonRef"; - this.buttonRef.Size = new System.Drawing.Size(90, 37); - this.buttonRef.TabIndex = 4; - this.buttonRef.Text = "Обновить"; - this.buttonRef.UseVisualStyleBackColor = true; - this.buttonRef.Click += new System.EventHandler(this.ButtonRef_Click); - // - // buttonDel - // - 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.Name = "buttonDel"; - this.buttonDel.Size = new System.Drawing.Size(90, 33); - this.buttonDel.TabIndex = 3; - this.buttonDel.Text = "Удалить"; - this.buttonDel.UseVisualStyleBackColor = true; - this.buttonDel.Click += new System.EventHandler(this.ButtonDel_Click); - // - // buttonUpd - // - 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.Name = "buttonUpd"; - this.buttonUpd.Size = new System.Drawing.Size(90, 34); - this.buttonUpd.TabIndex = 2; - this.buttonUpd.Text = "Изменить"; - this.buttonUpd.UseVisualStyleBackColor = true; - this.buttonUpd.Click += new System.EventHandler(this.ButtonUpd_Click); - // - // buttonAdd - // - this.buttonAdd.Location = new System.Drawing.Point(680, 62); - this.buttonAdd.Name = "buttonAdd"; - this.buttonAdd.Size = new System.Drawing.Size(90, 30); - this.buttonAdd.TabIndex = 1; - this.buttonAdd.Text = "Добавить"; - this.buttonAdd.UseVisualStyleBackColor = true; - this.buttonAdd.Click += new System.EventHandler(this.ButtonAdd_Click); - // - // dataGridView - // - this.dataGridView.AutoSizeColumnsMode = System.Windows.Forms.DataGridViewAutoSizeColumnsMode.ColumnHeader; - this.dataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; - this.dataGridView.Columns.AddRange(new System.Windows.Forms.DataGridViewColumn[] { - this.id, - this.Component, - this.Count}); - this.dataGridView.Location = new System.Drawing.Point(7, 22); - this.dataGridView.Name = "dataGridView"; - this.dataGridView.RowTemplate.Height = 25; - this.dataGridView.Size = new System.Drawing.Size(571, 302); - this.dataGridView.TabIndex = 0; - // - // id - // - this.id.HeaderText = "id"; - this.id.Name = "id"; - this.id.Visible = false; - // - // Components - // - this.Component.AutoSizeMode = System.Windows.Forms.DataGridViewAutoSizeColumnMode.Fill; - this.Component.FillWeight = 1000F; - this.Component.HeaderText = "Компонент"; - this.Component.Name = "Components"; - // - // Count - // - this.Count.HeaderText = "Количество"; - this.Count.Name = "Count"; - this.Count.Width = 97; - // - // textBoxName - // - this.textBoxName.Location = new System.Drawing.Point(89, 9); - this.textBoxName.Name = "textBoxName"; - this.textBoxName.Size = new System.Drawing.Size(170, 23); - this.textBoxName.TabIndex = 3; - // - // textBoxPrice - // - this.textBoxPrice.Location = new System.Drawing.Point(89, 38); - this.textBoxPrice.Name = "textBoxPrice"; - this.textBoxPrice.Size = new System.Drawing.Size(120, 23); - this.textBoxPrice.TabIndex = 4; - // - // buttonCancel - // - 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.Name = "buttonCancel"; - this.buttonCancel.Size = new System.Drawing.Size(90, 35); - this.buttonCancel.TabIndex = 5; - this.buttonCancel.Text = "Отмена"; - this.buttonCancel.UseVisualStyleBackColor = true; - this.buttonCancel.Click += new System.EventHandler(this.ButtonCancel_Click); - // - // buttonSave - // - 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.Name = "buttonSave"; - this.buttonSave.Size = new System.Drawing.Size(90, 35); - this.buttonSave.TabIndex = 6; - this.buttonSave.Text = "Сохранить"; - this.buttonSave.UseVisualStyleBackColor = true; - this.buttonSave.Click += new System.EventHandler(this.ButtonSave_Click); - // - // FormPastry - // - this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); - this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.ClientSize = new System.Drawing.Size(800, 450); - this.Controls.Add(this.buttonSave); - this.Controls.Add(this.buttonCancel); - this.Controls.Add(this.textBoxPrice); - this.Controls.Add(this.textBoxName); - this.Controls.Add(this.groupBox1); - this.Controls.Add(this.label2); - this.Controls.Add(this.label1); - this.Name = "FormPastry"; - this.Text = "Кондитерское изделие"; - this.Load += new System.EventHandler(this.FormPastry_Load); - this.groupBox1.ResumeLayout(false); - ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).EndInit(); - this.ResumeLayout(false); - this.PerformLayout(); + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + this.label1 = new System.Windows.Forms.Label(); + this.label2 = new System.Windows.Forms.Label(); + this.groupBox1 = new System.Windows.Forms.GroupBox(); + this.buttonRef = new System.Windows.Forms.Button(); + this.buttonDel = new System.Windows.Forms.Button(); + this.buttonUpd = new System.Windows.Forms.Button(); + this.buttonAdd = new System.Windows.Forms.Button(); + this.dataGridView = new System.Windows.Forms.DataGridView(); + this.id = new System.Windows.Forms.DataGridViewTextBoxColumn(); + this.Component = new System.Windows.Forms.DataGridViewTextBoxColumn(); + this.Count = new System.Windows.Forms.DataGridViewTextBoxColumn(); + this.textBoxName = new System.Windows.Forms.TextBox(); + this.textBoxPrice = new System.Windows.Forms.TextBox(); + this.buttonCancel = new System.Windows.Forms.Button(); + this.buttonSave = new System.Windows.Forms.Button(); + this.groupBox1.SuspendLayout(); + ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit(); + this.SuspendLayout(); + // + // label1 + // + this.label1.AutoSize = true; + this.label1.Location = new System.Drawing.Point(12, 9); + this.label1.Name = "label1"; + this.label1.Size = new System.Drawing.Size(62, 15); + this.label1.TabIndex = 0; + this.label1.Text = "Название:"; + // + // label2 + // + this.label2.AutoSize = true; + this.label2.Location = new System.Drawing.Point(12, 40); + this.label2.Name = "label2"; + this.label2.Size = new System.Drawing.Size(70, 15); + this.label2.TabIndex = 1; + this.label2.Text = "Стоимость:"; + // + // groupBox1 + // + this.groupBox1.AutoSizeMode = System.Windows.Forms.AutoSizeMode.GrowAndShrink; + this.groupBox1.Controls.Add(this.buttonRef); + this.groupBox1.Controls.Add(this.buttonDel); + this.groupBox1.Controls.Add(this.buttonUpd); + this.groupBox1.Controls.Add(this.buttonAdd); + this.groupBox1.Controls.Add(this.dataGridView); + this.groupBox1.Location = new System.Drawing.Point(12, 67); + this.groupBox1.Name = "groupBox1"; + this.groupBox1.RightToLeft = System.Windows.Forms.RightToLeft.No; + this.groupBox1.Size = new System.Drawing.Size(776, 330); + this.groupBox1.TabIndex = 2; + this.groupBox1.TabStop = false; + this.groupBox1.Text = "Компоненты:"; + // + // buttonRef + // + 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.Name = "buttonRef"; + this.buttonRef.Size = new System.Drawing.Size(90, 37); + this.buttonRef.TabIndex = 4; + this.buttonRef.Text = "Обновить"; + this.buttonRef.UseVisualStyleBackColor = true; + this.buttonRef.Click += new System.EventHandler(this.ButtonRef_Click); + // + // buttonDel + // + 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.Name = "buttonDel"; + this.buttonDel.Size = new System.Drawing.Size(90, 33); + this.buttonDel.TabIndex = 3; + this.buttonDel.Text = "Удалить"; + this.buttonDel.UseVisualStyleBackColor = true; + this.buttonDel.Click += new System.EventHandler(this.ButtonDel_Click); + // + // buttonUpd + // + 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.Name = "buttonUpd"; + this.buttonUpd.Size = new System.Drawing.Size(90, 34); + this.buttonUpd.TabIndex = 2; + this.buttonUpd.Text = "Изменить"; + this.buttonUpd.UseVisualStyleBackColor = true; + this.buttonUpd.Click += new System.EventHandler(this.ButtonUpd_Click); + // + // buttonAdd + // + this.buttonAdd.Location = new System.Drawing.Point(680, 62); + this.buttonAdd.Name = "buttonAdd"; + this.buttonAdd.Size = new System.Drawing.Size(90, 30); + this.buttonAdd.TabIndex = 1; + this.buttonAdd.Text = "Добавить"; + this.buttonAdd.UseVisualStyleBackColor = true; + this.buttonAdd.Click += new System.EventHandler(this.ButtonAdd_Click); + // + // dataGridView + // + this.dataGridView.AutoSizeColumnsMode = System.Windows.Forms.DataGridViewAutoSizeColumnsMode.ColumnHeader; + this.dataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; + this.dataGridView.Columns.AddRange(new System.Windows.Forms.DataGridViewColumn[] { + this.id, + this.Component, + this.Count}); + this.dataGridView.Location = new System.Drawing.Point(7, 22); + this.dataGridView.Name = "dataGridView"; + this.dataGridView.RowTemplate.Height = 25; + this.dataGridView.Size = new System.Drawing.Size(571, 302); + this.dataGridView.TabIndex = 0; + // + // id + // + this.id.HeaderText = "id"; + this.id.Name = "id"; + this.id.Visible = false; + // + // Component + // + this.Component.AutoSizeMode = System.Windows.Forms.DataGridViewAutoSizeColumnMode.Fill; + this.Component.FillWeight = 1000F; + this.Component.HeaderText = "Компонент"; + this.Component.Name = "Component"; + // + // Count + // + this.Count.HeaderText = "Количество"; + this.Count.Name = "Count"; + this.Count.Width = 97; + // + // textBoxName + // + this.textBoxName.Location = new System.Drawing.Point(89, 9); + this.textBoxName.Name = "textBoxName"; + this.textBoxName.Size = new System.Drawing.Size(170, 23); + this.textBoxName.TabIndex = 3; + // + // textBoxPrice + // + this.textBoxPrice.Location = new System.Drawing.Point(89, 38); + this.textBoxPrice.Name = "textBoxPrice"; + this.textBoxPrice.Size = new System.Drawing.Size(120, 23); + this.textBoxPrice.TabIndex = 4; + // + // buttonCancel + // + 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.Name = "buttonCancel"; + this.buttonCancel.Size = new System.Drawing.Size(90, 35); + this.buttonCancel.TabIndex = 5; + this.buttonCancel.Text = "Отмена"; + this.buttonCancel.UseVisualStyleBackColor = true; + this.buttonCancel.Click += new System.EventHandler(this.ButtonCancel_Click); + // + // buttonSave + // + 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.Name = "buttonSave"; + this.buttonSave.Size = new System.Drawing.Size(90, 35); + this.buttonSave.TabIndex = 6; + this.buttonSave.Text = "Сохранить"; + this.buttonSave.UseVisualStyleBackColor = true; + this.buttonSave.Click += new System.EventHandler(this.ButtonSave_Click); + // + // FormPastry + // + this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(800, 450); + this.Controls.Add(this.buttonSave); + this.Controls.Add(this.buttonCancel); + this.Controls.Add(this.textBoxPrice); + this.Controls.Add(this.textBoxName); + this.Controls.Add(this.groupBox1); + this.Controls.Add(this.label2); + this.Controls.Add(this.label1); + this.Name = "FormPastry"; + this.Text = "Кондитерское изделие"; + this.Load += new System.EventHandler(this.FormPastry_Load); + this.groupBox1.ResumeLayout(false); + ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).EndInit(); + this.ResumeLayout(false); + this.PerformLayout(); - } + } - #endregion + #endregion - private Label label1; - private Label label2; - private GroupBox groupBox1; - private TextBox textBoxName; - private TextBox textBoxPrice; - private Button buttonRef; - private Button buttonDel; - private Button buttonUpd; - private Button buttonAdd; - private DataGridView dataGridView; - private DataGridViewTextBoxColumn id; - private DataGridViewTextBoxColumn Component; - private DataGridViewTextBoxColumn Count; - private Button buttonCancel; - private Button buttonSave; - } + private Label label1; + private Label label2; + private GroupBox groupBox1; + private TextBox textBoxName; + private TextBox textBoxPrice; + private Button buttonRef; + private Button buttonDel; + private Button buttonUpd; + private Button buttonAdd; + private DataGridView dataGridView; + private DataGridViewTextBoxColumn id; + private DataGridViewTextBoxColumn Component; + private DataGridViewTextBoxColumn Count; + private Button buttonCancel; + private Button buttonSave; + } } \ No newline at end of file diff --git a/Confectionery/FormPastry.cs b/Confectionery/FormPastry.cs index 7caf7e6..3b7bd3f 100644 --- a/Confectionery/FormPastry.cs +++ b/Confectionery/FormPastry.cs @@ -6,208 +6,208 @@ using Microsoft.Extensions.Logging; namespace ConfectioneryView { - public partial class FormPastry : Form - { - private readonly ILogger _logger; - private readonly IPastryLogic _logic; - private int? _id; - private Dictionary _pastryComponents; - public int Id { set { _id = value; } } - public FormPastry(ILogger logger, IPastryLogic logic) - { - InitializeComponent(); - _logger = logger; - _logic = logic; - _pastryComponents = new Dictionary(); - } - private void FormPastry_Load(object sender, EventArgs e) - { - if (_id.HasValue) - { - _logger.LogInformation("Загрузка изделия"); - try - { - var view = _logic.ReadElement(new PastrySearchModel - { - Id = _id.Value - }); - if (view != null) - { - textBoxName.Text = view.PastryName; - textBoxPrice.Text = view.Price.ToString(); - _pastryComponents = view.PastryComponents ?? new - Dictionary(); - LoadData(); - } - } - catch (Exception ex) - { - _logger.LogError(ex, "Ошибка загрузки изделия"); - MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, - MessageBoxIcon.Error); - } - } - } - private void LoadData() - { - _logger.LogInformation("Загрузка компонент изделия"); - try - { - if (_pastryComponents != null) - { - dataGridView.Rows.Clear(); - foreach (var pc in _pastryComponents) - { - dataGridView.Rows.Add(new object[] { pc.Key, pc.Value.Item1.ComponentName, pc.Value.Item2 }); - } - textBoxPrice.Text = CalcPrice().ToString(); - } - } - catch (Exception ex) - { - _logger.LogError(ex, "Ошибка загрузки компонент изделия"); - MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, - MessageBoxIcon.Error); - } - } - private void ButtonAdd_Click(object sender, EventArgs e) - { - var service = - Program.ServiceProvider?.GetService(typeof(FormPastryComponent)); - if (service is FormPastryComponent form) - { - if (form.ShowDialog() == DialogResult.OK) - { - if (form.ComponentModel == null) - { - return; - } - _logger.LogInformation("Добавление нового компонента: { PastryName}- { Count}", - form.ComponentModel.ComponentName, form.Count); - if (_pastryComponents.ContainsKey(form.Id)) - { - _pastryComponents[form.Id] = (form.ComponentModel, - form.Count); - } - else - { - _pastryComponents.Add(form.Id, (form.ComponentModel, - form.Count)); - } - LoadData(); - } - } - } - private void ButtonUpd_Click(object sender, EventArgs e) - { - if (dataGridView.SelectedRows.Count == 1) - { - var service = Program.ServiceProvider?.GetService(typeof(FormPastryComponent)); - if (service is FormPastryComponent form) - { - int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells[0].Value); - form.Id = id; - form.Count = _pastryComponents[id].Item2; - if (form.ShowDialog() == DialogResult.OK) - { - if (form.ComponentModel == null) - { - return; - } - _logger.LogInformation("Изменение компонента: { PastryName} - { Count} ", - form.ComponentModel.ComponentName, form.Count); - _pastryComponents[id] = (form.ComponentModel, form.Count); - LoadData(); - } - } - } - } - private void ButtonDel_Click(object sender, EventArgs e) - { - if (dataGridView.SelectedRows.Count == 1) - { - if (MessageBox.Show("Удалить запись?", "Вопрос", - MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) - { - try - { - _logger.LogInformation("Удаление компонента: { PastryName}- { Count}", - dataGridView.SelectedRows[0].Cells[1].Value); - _pastryComponents?.Remove(Convert.ToInt32(dataGridView.SelectedRows[0].Cells[0].Value)); - } - catch (Exception ex) - { - MessageBox.Show(ex.Message, "Ошибка", - MessageBoxButtons.OK, MessageBoxIcon.Error); - } - LoadData(); - } - } - } - private void ButtonRef_Click(object sender, EventArgs e) - { - LoadData(); - } - private void ButtonSave_Click(object sender, EventArgs e) - { - if (string.IsNullOrEmpty(textBoxName.Text)) - { - MessageBox.Show("Заполните название", "Ошибка", - MessageBoxButtons.OK, MessageBoxIcon.Error); - return; - } - if (string.IsNullOrEmpty(textBoxPrice.Text)) - { - MessageBox.Show("Заполните цену", "Ошибка", MessageBoxButtons.OK, - MessageBoxIcon.Error); - return; - } - if (_pastryComponents == null || _pastryComponents.Count == 0) - { - MessageBox.Show("Заполните компоненты", "Ошибка", - MessageBoxButtons.OK, MessageBoxIcon.Error); - return; - } - _logger.LogInformation("Сохранение изделия"); - try - { - var model = new PastryBindingModel - { - Id = _id ?? 0, - PastryName = textBoxName.Text, - Price = Convert.ToDouble(textBoxPrice.Text), - PastryComponents = _pastryComponents - }; - var operationResult = _id.HasValue ? _logic.Update(model) : - _logic.Create(model); - if (!operationResult) - { - throw new Exception("Ошибка при сохранении. Дополнительная информация в логах."); - } - MessageBox.Show("Сохранение прошло успешно", "Сообщение", - MessageBoxButtons.OK, MessageBoxIcon.Information); - DialogResult = DialogResult.OK; - Close(); - } - catch (Exception ex) - { - _logger.LogError(ex, "Ошибка сохранения изделия"); - MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); - } - } - private void ButtonCancel_Click(object sender, EventArgs e) - { - DialogResult = DialogResult.Cancel; - Close(); - } - private double CalcPrice() - { - double price = 0; - foreach (var elem in _pastryComponents) - { - price += ((elem.Value.Item1?.Cost ?? 0) * elem.Value.Item2); - } - return Math.Round(price * 1.1, 2); - } - } -} + public partial class FormPastry : Form + { + private readonly ILogger _logger; + private readonly IPastryLogic _logic; + private int? _id; + private Dictionary _pastryComponents; + public int Id { set { _id = value; } } + public FormPastry(ILogger logger, IPastryLogic logic) + { + InitializeComponent(); + _logger = logger; + _logic = logic; + _pastryComponents = new Dictionary(); + } + private void FormPastry_Load(object sender, EventArgs e) + { + if (_id.HasValue) + { + _logger.LogInformation("Загрузка изделия"); + try + { + var view = _logic.ReadElement(new PastrySearchModel + { + Id = _id.Value + }); + if (view != null) + { + textBoxName.Text = view.PastryName; + textBoxPrice.Text = view.Price.ToString(); + _pastryComponents = view.PastryComponents ?? new + Dictionary(); + LoadData(); + } + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка загрузки изделия"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, + MessageBoxIcon.Error); + } + } + } + private void LoadData() + { + _logger.LogInformation("Загрузка компонент изделия"); + try + { + if (_pastryComponents != null) + { + dataGridView.Rows.Clear(); + foreach (var pc in _pastryComponents) + { + dataGridView.Rows.Add(new object[] { pc.Key, pc.Value.Item1.ComponentName, pc.Value.Item2 }); + } + textBoxPrice.Text = CalcPrice().ToString(); + } + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка загрузки компонент изделия"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, + MessageBoxIcon.Error); + } + } + private void ButtonAdd_Click(object sender, EventArgs e) + { + var service = + Program.ServiceProvider?.GetService(typeof(FormPastryComponent)); + if (service is FormPastryComponent form) + { + if (form.ShowDialog() == DialogResult.OK) + { + if (form.ComponentModel == null) + { + return; + } + _logger.LogInformation("Добавление нового компонента: { ComponentName}- { Count}", + form.ComponentModel.ComponentName, form.Count); + if (_pastryComponents.ContainsKey(form.Id)) + { + _pastryComponents[form.Id] = (form.ComponentModel, + form.Count); + } + else + { + _pastryComponents.Add(form.Id, (form.ComponentModel, + form.Count)); + } + LoadData(); + } + } + } + private void ButtonUpd_Click(object sender, EventArgs e) + { + if (dataGridView.SelectedRows.Count == 1) + { + var service = Program.ServiceProvider?.GetService(typeof(FormPastryComponent)); + if (service is FormPastryComponent form) + { + int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells[0].Value); + form.Id = id; + form.Count = _pastryComponents[id].Item2; + if (form.ShowDialog() == DialogResult.OK) + { + if (form.ComponentModel == null) + { + return; + } + _logger.LogInformation("Изменение компонента: { ComponentName} - { Count} ", + form.ComponentModel.ComponentName, form.Count); + _pastryComponents[id] = (form.ComponentModel, form.Count); + LoadData(); + } + } + } + } + private void ButtonDel_Click(object sender, EventArgs e) + { + if (dataGridView.SelectedRows.Count == 1) + { + if (MessageBox.Show("Удалить запись?", "Вопрос", + MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) + { + try + { + _logger.LogInformation("Удаление компонента: { ComponentName}- { Count}", + dataGridView.SelectedRows[0].Cells[1].Value); + _pastryComponents?.Remove(Convert.ToInt32(dataGridView.SelectedRows[0].Cells[0].Value)); + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "Ошибка", + MessageBoxButtons.OK, MessageBoxIcon.Error); + } + LoadData(); + } + } + } + private void ButtonRef_Click(object sender, EventArgs e) + { + LoadData(); + } + private void ButtonSave_Click(object sender, EventArgs e) + { + if (string.IsNullOrEmpty(textBoxName.Text)) + { + MessageBox.Show("Заполните название", "Ошибка", + MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + if (string.IsNullOrEmpty(textBoxPrice.Text)) + { + MessageBox.Show("Заполните цену", "Ошибка", MessageBoxButtons.OK, + MessageBoxIcon.Error); + return; + } + if (_pastryComponents == null || _pastryComponents.Count == 0) + { + MessageBox.Show("Заполните компоненты", "Ошибка", + MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + _logger.LogInformation("Сохранение изделия"); + try + { + var model = new PastryBindingModel + { + Id = _id ?? 0, + PastryName = textBoxName.Text, + Price = Convert.ToDouble(textBoxPrice.Text), + PastryComponents = _pastryComponents + }; + var operationResult = _id.HasValue ? _logic.Update(model) : + _logic.Create(model); + if (!operationResult) + { + throw new Exception("Ошибка при сохранении. Дополнительная информация в логах."); + } + MessageBox.Show("Сохранение прошло успешно", "Сообщение", + MessageBoxButtons.OK, MessageBoxIcon.Information); + DialogResult = DialogResult.OK; + Close(); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка сохранения изделия"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + private void ButtonCancel_Click(object sender, EventArgs e) + { + DialogResult = DialogResult.Cancel; + Close(); + } + private double CalcPrice() + { + double price = 0; + foreach (var elem in _pastryComponents) + { + price += ((elem.Value.Item1?.Cost ?? 0) * elem.Value.Item2); + } + return Math.Round(price * 1.1, 2); + } + } +} \ No newline at end of file diff --git a/Confectionery/FormPastryComponent.cs b/Confectionery/FormPastryComponent.cs index c7dffc4..2ac9bdd 100644 --- a/Confectionery/FormPastryComponent.cs +++ b/Confectionery/FormPastryComponent.cs @@ -4,76 +4,76 @@ using ConfectioneryDataModels.Models; namespace ConfectioneryView { - public partial class FormPastryComponent : Form - { - private readonly List? _list; - public int Id - { - get - { - return Convert.ToInt32(comboBoxComponent.SelectedValue); - } - set - { - comboBoxComponent.SelectedValue = value; - } - } - public IComponentModel? ComponentModel - { - get - { - if (_list == null) - { - return null; - } - foreach (var elem in _list) - { - if (elem.Id == Id) - { - return elem; - } - } - return null; - } - } - public int Count - { - get { return Convert.ToInt32(textBoxCount.Text); } - set { textBoxCount.Text = value.ToString(); } - } - public FormPastryComponent(IComponentLogic logic) - { - InitializeComponent(); - _list = logic.ReadList(null); - if (_list != null) - { - comboBoxComponent.DisplayMember = "PastryName"; - comboBoxComponent.ValueMember = "Id"; - comboBoxComponent.DataSource = _list; - comboBoxComponent.SelectedItem = null; - } - } - private void ButtonSave_Click(object sender, EventArgs e) - { - if (string.IsNullOrEmpty(textBoxCount.Text)) - { - MessageBox.Show("Заполните поле Количество", "Ошибка", - MessageBoxButtons.OK, MessageBoxIcon.Error); - return; - } - if (comboBoxComponent.SelectedValue == null) - { - MessageBox.Show("Выберите компонент", "Ошибка", - MessageBoxButtons.OK, MessageBoxIcon.Error); - return; - } - DialogResult = DialogResult.OK; - Close(); - } - private void ButtonCancel_Click(object sender, EventArgs e) - { - DialogResult = DialogResult.Cancel; - Close(); - } - } + public partial class FormPastryComponent : Form + { + private readonly List? _list; + public int Id + { + get + { + return Convert.ToInt32(comboBoxComponent.SelectedValue); + } + set + { + comboBoxComponent.SelectedValue = value; + } + } + public IComponentModel? ComponentModel + { + get + { + if (_list == null) + { + return null; + } + foreach (var elem in _list) + { + if (elem.Id == Id) + { + return elem; + } + } + return null; + } + } + public int Count + { + get { return Convert.ToInt32(textBoxCount.Text); } + set { textBoxCount.Text = value.ToString(); } + } + public FormPastryComponent(IComponentLogic logic) + { + InitializeComponent(); + _list = logic.ReadList(null); + if (_list != null) + { + comboBoxComponent.DisplayMember = "ComponentName"; + comboBoxComponent.ValueMember = "Id"; + comboBoxComponent.DataSource = _list; + comboBoxComponent.SelectedItem = null; + } + } + private void ButtonSave_Click(object sender, EventArgs e) + { + if (string.IsNullOrEmpty(textBoxCount.Text)) + { + MessageBox.Show("Заполните поле Количество", "Ошибка", + MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + if (comboBoxComponent.SelectedValue == null) + { + MessageBox.Show("Выберите компонент", "Ошибка", + MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + DialogResult = DialogResult.OK; + Close(); + } + private void ButtonCancel_Click(object sender, EventArgs e) + { + DialogResult = DialogResult.Cancel; + Close(); + } + } } \ No newline at end of file diff --git a/ConfectioneryDatabaseImplement/Migrations/20230219142123_InitialCreate.Designer.cs b/ConfectioneryDatabaseImplement/Migrations/20230219142123_InitialCreate.Designer.cs index 2b69cfd..b9a1952 100644 --- a/ConfectioneryDatabaseImplement/Migrations/20230219142123_InitialCreate.Designer.cs +++ b/ConfectioneryDatabaseImplement/Migrations/20230219142123_InitialCreate.Designer.cs @@ -11,161 +11,161 @@ using Microsoft.EntityFrameworkCore.Storage.ValueConversion; namespace ConfectioneryDatabaseImplement.Migrations { - [DbContext(typeof(ConfectioneryDatabase))] - [Migration("20230219142123_InitialCreate")] - partial class InitialCreate - { - /// - protected override void BuildTargetModel(ModelBuilder modelBuilder) - { + [DbContext(typeof(ConfectioneryDatabase))] + [Migration("20230219142123_InitialCreate")] + partial class InitialCreate + { + /// + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { #pragma warning disable 612, 618 - modelBuilder - .HasAnnotation("ProductVersion", "7.0.3") - .HasAnnotation("Relational:MaxIdentifierLength", 128); + modelBuilder + .HasAnnotation("ProductVersion", "7.0.3") + .HasAnnotation("Relational:MaxIdentifierLength", 128); - SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder); + SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder); - modelBuilder.Entity("ConfectioneryDatabaseImplement.Models.Components", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("int"); + modelBuilder.Entity("ConfectioneryDatabaseImplement.Models.Component", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); - b.Property("PastryName") - .IsRequired() - .HasColumnType("nvarchar(max)"); + b.Property("ComponentName") + .IsRequired() + .HasColumnType("nvarchar(max)"); - b.Property("Cost") - .HasColumnType("float"); + b.Property("Cost") + .HasColumnType("float"); - b.HasKey("Id"); + b.HasKey("Id"); - b.ToTable("Components"); - }); + b.ToTable("Components"); + }); - modelBuilder.Entity("ConfectioneryDatabaseImplement.Models.Order", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("int"); + modelBuilder.Entity("ConfectioneryDatabaseImplement.Models.Order", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); - b.Property("Count") - .HasColumnType("int"); + b.Property("Count") + .HasColumnType("int"); - b.Property("DateCreate") - .HasColumnType("datetime2"); + b.Property("DateCreate") + .HasColumnType("datetime2"); - b.Property("DateImplement") - .HasColumnType("datetime2"); + b.Property("DateImplement") + .HasColumnType("datetime2"); - b.Property("PastryId") - .HasColumnType("int"); + b.Property("PastryId") + .HasColumnType("int"); - b.Property("Status") - .HasColumnType("int"); + b.Property("Status") + .HasColumnType("int"); - b.Property("Sum") - .HasColumnType("float"); + b.Property("Sum") + .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 => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("int"); + modelBuilder.Entity("ConfectioneryDatabaseImplement.Models.Pastry", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); - b.Property("PastryName") - .IsRequired() - .HasColumnType("nvarchar(max)"); + b.Property("PastryName") + .IsRequired() + .HasColumnType("nvarchar(max)"); - b.Property("Price") - .HasColumnType("float"); + b.Property("Price") + .HasColumnType("float"); - b.HasKey("Id"); + b.HasKey("Id"); - b.ToTable("Components"); - }); + b.ToTable("Pastries"); + }); - modelBuilder.Entity("ConfectioneryDatabaseImplement.Models.PastryComponent", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("int"); + modelBuilder.Entity("ConfectioneryDatabaseImplement.Models.PastryComponent", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); - b.Property("ComponentId") - .HasColumnType("int"); + b.Property("ComponentId") + .HasColumnType("int"); - b.Property("Count") - .HasColumnType("int"); + b.Property("Count") + .HasColumnType("int"); - b.Property("PastryId") - .HasColumnType("int"); + b.Property("PastryId") + .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 => - { - b.HasOne("ConfectioneryDatabaseImplement.Models.Pastry", "Pastry") - .WithMany("Orders") - .HasForeignKey("PastryId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); + modelBuilder.Entity("ConfectioneryDatabaseImplement.Models.Order", b => + { + b.HasOne("ConfectioneryDatabaseImplement.Models.Pastry", "Pastry") + .WithMany("Orders") + .HasForeignKey("PastryId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); - b.Navigation("Pastry"); - }); + b.Navigation("Pastry"); + }); - modelBuilder.Entity("ConfectioneryDatabaseImplement.Models.PastryComponent", b => - { - b.HasOne("ConfectioneryDatabaseImplement.Models.Components", "Components") - .WithMany("PastryComponents") - .HasForeignKey("ComponentId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); + modelBuilder.Entity("ConfectioneryDatabaseImplement.Models.PastryComponent", b => + { + b.HasOne("ConfectioneryDatabaseImplement.Models.Component", "Component") + .WithMany("PastryComponents") + .HasForeignKey("ComponentId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); - b.HasOne("ConfectioneryDatabaseImplement.Models.Pastry", "Pastry") - .WithMany("Components") - .HasForeignKey("PastryId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); + b.HasOne("ConfectioneryDatabaseImplement.Models.Pastry", "Pastry") + .WithMany("Components") + .HasForeignKey("PastryId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); - b.Navigation("Components"); + b.Navigation("Component"); - b.Navigation("Pastry"); - }); + b.Navigation("Pastry"); + }); - modelBuilder.Entity("ConfectioneryDatabaseImplement.Models.Components", b => - { - b.Navigation("PastryComponents"); - }); + modelBuilder.Entity("ConfectioneryDatabaseImplement.Models.Component", b => + { + b.Navigation("PastryComponents"); + }); - modelBuilder.Entity("ConfectioneryDatabaseImplement.Models.Pastry", b => - { - b.Navigation("Components"); + modelBuilder.Entity("ConfectioneryDatabaseImplement.Models.Pastry", b => + { + b.Navigation("Components"); - b.Navigation("Orders"); - }); + b.Navigation("Orders"); + }); #pragma warning restore 612, 618 - } - } + } + } } diff --git a/ConfectioneryDatabaseImplement/Migrations/20230219142123_InitialCreate.cs b/ConfectioneryDatabaseImplement/Migrations/20230219142123_InitialCreate.cs index d99ff99..111f7e1 100644 --- a/ConfectioneryDatabaseImplement/Migrations/20230219142123_InitialCreate.cs +++ b/ConfectioneryDatabaseImplement/Migrations/20230219142123_InitialCreate.cs @@ -5,121 +5,121 @@ using Microsoft.EntityFrameworkCore.Migrations; namespace ConfectioneryDatabaseImplement.Migrations { - /// - public partial class InitialCreate : Migration - { - /// - protected override void Up(MigrationBuilder migrationBuilder) - { - migrationBuilder.CreateTable( - name: "Components", - columns: table => new - { - Id = table.Column(type: "int", nullable: false) - .Annotation("SqlServer:Identity", "1, 1"), - ComponentName = table.Column(type: "nvarchar(max)", nullable: false), - Cost = table.Column(type: "float", nullable: false) - }, - constraints: table => - { - table.PrimaryKey("PK_Components", x => x.Id); - }); + /// + public partial class InitialCreate : Migration + { + /// + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.CreateTable( + name: "Components", + columns: table => new + { + Id = table.Column(type: "int", nullable: false) + .Annotation("SqlServer:Identity", "1, 1"), + ComponentName = table.Column(type: "nvarchar(max)", nullable: false), + Cost = table.Column(type: "float", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_Components", x => x.Id); + }); - migrationBuilder.CreateTable( - name: "Components", - columns: table => new - { - Id = table.Column(type: "int", nullable: false) - .Annotation("SqlServer:Identity", "1, 1"), - PastryName = table.Column(type: "nvarchar(max)", nullable: false), - Price = table.Column(type: "float", nullable: false) - }, - constraints: table => - { - table.PrimaryKey("PK_Pastries", x => x.Id); - }); + migrationBuilder.CreateTable( + name: "Pastries", + columns: table => new + { + Id = table.Column(type: "int", nullable: false) + .Annotation("SqlServer:Identity", "1, 1"), + PastryName = table.Column(type: "nvarchar(max)", nullable: false), + Price = table.Column(type: "float", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_Pastries", x => x.Id); + }); - migrationBuilder.CreateTable( - name: "Orders", - columns: table => new - { - Id = table.Column(type: "int", nullable: false) - .Annotation("SqlServer:Identity", "1, 1"), - PastryId = table.Column(type: "int", nullable: false), - Count = table.Column(type: "int", nullable: false), - Sum = table.Column(type: "float", nullable: false), - Status = table.Column(type: "int", nullable: false), - DateCreate = table.Column(type: "datetime2", nullable: false), - DateImplement = table.Column(type: "datetime2", nullable: true) - }, - constraints: table => - { - table.PrimaryKey("PK_Orders", x => x.Id); - table.ForeignKey( - name: "FK_Orders_Pastries_PastryId", - column: x => x.PastryId, - principalTable: "Components", - principalColumn: "Id", - onDelete: ReferentialAction.Cascade); - }); + migrationBuilder.CreateTable( + name: "Orders", + columns: table => new + { + Id = table.Column(type: "int", nullable: false) + .Annotation("SqlServer:Identity", "1, 1"), + PastryId = table.Column(type: "int", nullable: false), + Count = table.Column(type: "int", nullable: false), + Sum = table.Column(type: "float", nullable: false), + Status = table.Column(type: "int", nullable: false), + DateCreate = table.Column(type: "datetime2", nullable: false), + DateImplement = table.Column(type: "datetime2", nullable: true) + }, + constraints: table => + { + table.PrimaryKey("PK_Orders", x => x.Id); + table.ForeignKey( + name: "FK_Orders_Pastries_PastryId", + column: x => x.PastryId, + principalTable: "Pastries", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + }); - migrationBuilder.CreateTable( - name: "PastryComponents", - columns: table => new - { - Id = table.Column(type: "int", nullable: false) - .Annotation("SqlServer:Identity", "1, 1"), - PastryId = table.Column(type: "int", nullable: false), - ComponentId = table.Column(type: "int", nullable: false), - Count = table.Column(type: "int", nullable: false) - }, - constraints: table => - { - table.PrimaryKey("PK_PastryComponents", x => x.Id); - table.ForeignKey( - name: "FK_PastryComponents_Components_ComponentId", - column: x => x.ComponentId, - principalTable: "Components", - principalColumn: "Id", - onDelete: ReferentialAction.Cascade); - table.ForeignKey( - name: "FK_PastryComponents_Pastries_PastryId", - column: x => x.PastryId, - principalTable: "Components", - principalColumn: "Id", - onDelete: ReferentialAction.Cascade); - }); + migrationBuilder.CreateTable( + name: "PastryComponents", + columns: table => new + { + Id = table.Column(type: "int", nullable: false) + .Annotation("SqlServer:Identity", "1, 1"), + PastryId = table.Column(type: "int", nullable: false), + ComponentId = table.Column(type: "int", nullable: false), + Count = table.Column(type: "int", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_PastryComponents", x => x.Id); + table.ForeignKey( + name: "FK_PastryComponents_Components_ComponentId", + column: x => x.ComponentId, + principalTable: "Components", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + table.ForeignKey( + name: "FK_PastryComponents_Pastries_PastryId", + column: x => x.PastryId, + principalTable: "Pastries", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + }); - migrationBuilder.CreateIndex( - name: "IX_Orders_PastryId", - table: "Orders", - column: "PastryId"); + migrationBuilder.CreateIndex( + name: "IX_Orders_PastryId", + table: "Orders", + column: "PastryId"); - migrationBuilder.CreateIndex( - name: "IX_PastryComponents_ComponentId", - table: "PastryComponents", - column: "ComponentId"); + migrationBuilder.CreateIndex( + name: "IX_PastryComponents_ComponentId", + table: "PastryComponents", + column: "ComponentId"); - migrationBuilder.CreateIndex( - name: "IX_PastryComponents_PastryId", - table: "PastryComponents", - column: "PastryId"); - } + migrationBuilder.CreateIndex( + name: "IX_PastryComponents_PastryId", + table: "PastryComponents", + column: "PastryId"); + } - /// - protected override void Down(MigrationBuilder migrationBuilder) - { - migrationBuilder.DropTable( - name: "Orders"); + /// + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropTable( + name: "Orders"); - migrationBuilder.DropTable( - name: "PastryComponents"); + migrationBuilder.DropTable( + name: "PastryComponents"); - migrationBuilder.DropTable( - name: "Components"); + migrationBuilder.DropTable( + name: "Components"); - migrationBuilder.DropTable( - name: "Components"); - } - } + migrationBuilder.DropTable( + name: "Pastries"); + } + } } diff --git a/ConfectioneryDatabaseImplement/Migrations/ConfectioneryDatabaseModelSnapshot.cs b/ConfectioneryDatabaseImplement/Migrations/ConfectioneryDatabaseModelSnapshot.cs index 8bcb3ae..b05a982 100644 --- a/ConfectioneryDatabaseImplement/Migrations/ConfectioneryDatabaseModelSnapshot.cs +++ b/ConfectioneryDatabaseImplement/Migrations/ConfectioneryDatabaseModelSnapshot.cs @@ -10,159 +10,159 @@ using Microsoft.EntityFrameworkCore.Storage.ValueConversion; namespace ConfectioneryDatabaseImplement.Migrations { - [DbContext(typeof(ConfectioneryDatabase))] - partial class ConfectioneryDatabaseModelSnapshot : ModelSnapshot - { - protected override void BuildModel(ModelBuilder modelBuilder) - { + [DbContext(typeof(ConfectioneryDatabase))] + partial class ConfectioneryDatabaseModelSnapshot : ModelSnapshot + { + protected override void BuildModel(ModelBuilder modelBuilder) + { #pragma warning disable 612, 618 - modelBuilder - .HasAnnotation("ProductVersion", "7.0.3") - .HasAnnotation("Relational:MaxIdentifierLength", 128); + modelBuilder + .HasAnnotation("ProductVersion", "7.0.3") + .HasAnnotation("Relational:MaxIdentifierLength", 128); - SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder); + SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder); - modelBuilder.Entity("ConfectioneryDatabaseImplement.Models.Components", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("int"); + modelBuilder.Entity("ConfectioneryDatabaseImplement.Models.Component", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); - b.Property("PastryName") - .IsRequired() - .HasColumnType("nvarchar(max)"); + b.Property("ComponentName") + .IsRequired() + .HasColumnType("nvarchar(max)"); - b.Property("Cost") - .HasColumnType("float"); + b.Property("Cost") + .HasColumnType("float"); - b.HasKey("Id"); + b.HasKey("Id"); - b.ToTable("Components"); - }); + b.ToTable("Components"); + }); - modelBuilder.Entity("ConfectioneryDatabaseImplement.Models.Order", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("int"); + modelBuilder.Entity("ConfectioneryDatabaseImplement.Models.Order", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); - b.Property("Count") - .HasColumnType("int"); + b.Property("Count") + .HasColumnType("int"); - b.Property("DateCreate") - .HasColumnType("datetime2"); + b.Property("DateCreate") + .HasColumnType("datetime2"); - b.Property("DateImplement") - .HasColumnType("datetime2"); + b.Property("DateImplement") + .HasColumnType("datetime2"); - b.Property("PastryId") - .HasColumnType("int"); + b.Property("PastryId") + .HasColumnType("int"); - b.Property("Status") - .HasColumnType("int"); + b.Property("Status") + .HasColumnType("int"); - b.Property("Sum") - .HasColumnType("float"); + b.Property("Sum") + .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 => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("int"); + modelBuilder.Entity("ConfectioneryDatabaseImplement.Models.Pastry", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); - b.Property("PastryName") - .IsRequired() - .HasColumnType("nvarchar(max)"); + b.Property("PastryName") + .IsRequired() + .HasColumnType("nvarchar(max)"); - b.Property("Price") - .HasColumnType("float"); + b.Property("Price") + .HasColumnType("float"); - b.HasKey("Id"); + b.HasKey("Id"); - b.ToTable("Components"); - }); + b.ToTable("Pastries"); + }); - modelBuilder.Entity("ConfectioneryDatabaseImplement.Models.PastryComponent", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("int"); + modelBuilder.Entity("ConfectioneryDatabaseImplement.Models.PastryComponent", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); - b.Property("ComponentId") - .HasColumnType("int"); + b.Property("ComponentId") + .HasColumnType("int"); - b.Property("Count") - .HasColumnType("int"); + b.Property("Count") + .HasColumnType("int"); - b.Property("PastryId") - .HasColumnType("int"); + b.Property("PastryId") + .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 => - { - b.HasOne("ConfectioneryDatabaseImplement.Models.Pastry", "Pastry") - .WithMany("Orders") - .HasForeignKey("PastryId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); + modelBuilder.Entity("ConfectioneryDatabaseImplement.Models.Order", b => + { + b.HasOne("ConfectioneryDatabaseImplement.Models.Pastry", "Pastry") + .WithMany("Orders") + .HasForeignKey("PastryId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); - b.Navigation("Pastry"); - }); + b.Navigation("Pastry"); + }); - modelBuilder.Entity("ConfectioneryDatabaseImplement.Models.PastryComponent", b => - { - b.HasOne("ConfectioneryDatabaseImplement.Models.Components", "Components") - .WithMany("PastryComponents") - .HasForeignKey("ComponentId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); + modelBuilder.Entity("ConfectioneryDatabaseImplement.Models.PastryComponent", b => + { + b.HasOne("ConfectioneryDatabaseImplement.Models.Component", "Component") + .WithMany("PastryComponents") + .HasForeignKey("ComponentId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); - b.HasOne("ConfectioneryDatabaseImplement.Models.Pastry", "Pastry") - .WithMany("Components") - .HasForeignKey("PastryId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); + b.HasOne("ConfectioneryDatabaseImplement.Models.Pastry", "Pastry") + .WithMany("Components") + .HasForeignKey("PastryId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); - b.Navigation("Components"); + b.Navigation("Component"); - b.Navigation("Pastry"); - }); + b.Navigation("Pastry"); + }); - modelBuilder.Entity("ConfectioneryDatabaseImplement.Models.Components", b => - { - b.Navigation("PastryComponents"); - }); + modelBuilder.Entity("ConfectioneryDatabaseImplement.Models.Component", b => + { + b.Navigation("PastryComponents"); + }); - modelBuilder.Entity("ConfectioneryDatabaseImplement.Models.Pastry", b => - { - b.Navigation("Components"); + modelBuilder.Entity("ConfectioneryDatabaseImplement.Models.Pastry", b => + { + b.Navigation("Components"); - b.Navigation("Orders"); - }); + b.Navigation("Orders"); + }); #pragma warning restore 612, 618 - } - } + } + } }