From df6465ba4f316e5056430ff5aeb598a2d3c6b600 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=93=D0=B0=D0=BB=D0=B8=D0=BD=D0=B0=20=D0=A4=D0=B5=D0=B4?= =?UTF-8?q?=D0=BE=D1=80=D0=B5=D0=BD=D0=BA=D0=BE?= Date: Sun, 28 Apr 2024 00:54:51 +0400 Subject: [PATCH] =?UTF-8?q?=D1=81=D0=BB=D0=B5=D0=BF=D0=BE=D0=B9=20=D0=B7?= =?UTF-8?q?=D0=B0=D1=85=D0=BE=D0=B4=D0=B8=D1=82=20=D0=B2=20=D0=B1=D0=B0?= =?UTF-8?q?=D1=80=20=D0=B8=20=D0=B3=D0=BE=D0=B2=D0=BE=D1=80=D0=B8=D1=82:?= =?UTF-8?q?=20=20=D0=B2=D1=81=D0=B5=D0=BC=20=D0=BF=D1=80=D0=B8=D0=B2=D0=B5?= =?UTF-8?q?=D1=82=20=D0=BA=D0=BE=D0=B3=D0=BE=20=D0=BD=D0=B5=20=D0=B2=D0=B8?= =?UTF-8?q?=D0=B4=D0=B5=D0=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../CarpentryWorkshop/FormMain.Designer.cs | 1 + .../CarpentryWorkshop/FormMain.cs | 4 +- .../CarpentryWorkshop/FormShop.Designer.cs | 4 +- .../CarpentryWorkshop/FormShop.cs | 83 +++++++----- .../CarpentryWorkshop/FormShops.Designer.cs | 14 +- .../CarpentryWorkshop/FormShops.cs | 48 ++++--- .../FormWoodSale.Designer.cs | 127 ++++++++++++++++++ .../CarpentryWorkshop/FormWoodSale.cs | 96 +++++++++++++ .../CarpentryWorkshop/FormWoodSale.resx | 120 +++++++++++++++++ .../CarpentryWorkshop/Program.cs | 2 +- .../Models/Shop.cs | 29 ++-- 11 files changed, 444 insertions(+), 84 deletions(-) create mode 100644 CarpentryWorkshop/CarpentryWorkshop/FormWoodSale.Designer.cs create mode 100644 CarpentryWorkshop/CarpentryWorkshop/FormWoodSale.cs create mode 100644 CarpentryWorkshop/CarpentryWorkshop/FormWoodSale.resx diff --git a/CarpentryWorkshop/CarpentryWorkshop/FormMain.Designer.cs b/CarpentryWorkshop/CarpentryWorkshop/FormMain.Designer.cs index 758713b..e50250d 100644 --- a/CarpentryWorkshop/CarpentryWorkshop/FormMain.Designer.cs +++ b/CarpentryWorkshop/CarpentryWorkshop/FormMain.Designer.cs @@ -95,6 +95,7 @@ продажиToolStripMenuItem.Name = "продажиToolStripMenuItem"; продажиToolStripMenuItem.Size = new Size(180, 22); продажиToolStripMenuItem.Text = "Продажи"; + продажиToolStripMenuItem.Click += продажиToolStripMenuItem_Click; // // dataGridView // diff --git a/CarpentryWorkshop/CarpentryWorkshop/FormMain.cs b/CarpentryWorkshop/CarpentryWorkshop/FormMain.cs index 9976417..e7ad7c8 100644 --- a/CarpentryWorkshop/CarpentryWorkshop/FormMain.cs +++ b/CarpentryWorkshop/CarpentryWorkshop/FormMain.cs @@ -171,8 +171,8 @@ namespace CarpentryWorkshopView } private void продажиToolStripMenuItem_Click(object sender, EventArgs e) { - var service = Program.ServiceProvider?.GetService(typeof(FormSell)); - if (service is FormSell form) + var service = Program.ServiceProvider?.GetService(typeof(FormWoodSale)); + if (service is FormWoodSale form) { form.ShowDialog(); } diff --git a/CarpentryWorkshop/CarpentryWorkshop/FormShop.Designer.cs b/CarpentryWorkshop/CarpentryWorkshop/FormShop.Designer.cs index cc496e7..5a8b4ca 100644 --- a/CarpentryWorkshop/CarpentryWorkshop/FormShop.Designer.cs +++ b/CarpentryWorkshop/CarpentryWorkshop/FormShop.Designer.cs @@ -103,7 +103,7 @@ SaveButton.TabIndex = 6; SaveButton.Text = "Сохранить"; SaveButton.UseVisualStyleBackColor = true; - SaveButton.Click += SaveButton_Click; + SaveButton.Click += ButtonSave_Click; // // CancelButton // @@ -113,7 +113,7 @@ CancelButton.TabIndex = 7; CancelButton.Text = "Отмена"; CancelButton.UseVisualStyleBackColor = true; - CancelButton.Click += CancelButton_Click; + CancelButton.Click += ButtonCancel_Click; // // DataGridView // diff --git a/CarpentryWorkshop/CarpentryWorkshop/FormShop.cs b/CarpentryWorkshop/CarpentryWorkshop/FormShop.cs index 2ca553e..0de17b6 100644 --- a/CarpentryWorkshop/CarpentryWorkshop/FormShop.cs +++ b/CarpentryWorkshop/CarpentryWorkshop/FormShop.cs @@ -3,77 +3,78 @@ using CarpentryWorkshopContracts.BusinessLogicsContracts; using CarpentryWorkshopContracts.SearchModels; using CarpentryWorkshopDataModels.Models; using Microsoft.Extensions.Logging; +using System.Windows.Forms; namespace CarpentryWorkshopView { public partial class FormShop : Form { private readonly ILogger _logger; + private readonly IShopLogic _logic; - public int? _id; - private Dictionary _woods; + + private int? _id; + + private Dictionary _shopWoods; + + public int Id { set { _id = value; } } + public FormShop(ILogger logger, IShopLogic logic) { InitializeComponent(); _logger = logger; _logic = logic; + _shopWoods = new Dictionary(); } private void FormShop_Load(object sender, EventArgs e) { if (_id.HasValue) { - _logger.LogInformation("Загрузка магазина"); + _logger.LogInformation("Shop loading"); try { - var shop = _logic.ReadElement(new ShopSearchModel { Id = _id }); - if (shop != null) + var view = _logic.ReadElement(new ShopSearchModel { Id = _id.Value }); + if (view != null) { - NameTextBox.Text = shop.ShopName; - AddressTextBox.Text = shop.Address; - DateTimePicker.Text = shop.DateOpen.ToString(); - CapacityUpDown.Value = shop.WoodMaxCount; - _woods = shop.ShopWoods; + NameTextBox.Text = view.ShopName; + AddressTextBox.Text = view.Address; + DateTimePicker.Value = view.DateOpen; + CapacityUpDown.Text = view.WoodMaxCount.ToString(); + _shopWoods = view.ShopWoods ?? new Dictionary(); + LoadData(); } - LoadData(); } catch (Exception ex) { - _logger.LogError(ex, "Ошибка загрузки магазина"); - MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, - MessageBoxIcon.Error); + _logger.LogError(ex, "Shop loading error"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); } } } private void LoadData() { - _logger.LogInformation("Загрузка товаров магазина"); + _logger.LogInformation("Shop ice creams loading"); try { - if (_woods != null) + if (_shopWoods != null) { - foreach (var wood in _woods) + DataGridView.Rows.Clear(); + foreach (var wood in _shopWoods) { - DataGridView.Rows.Add(new object[] { wood.Key, wood.Value.Item1.WoodName, wood.Value.Item1.Price, wood.Value.Item2 }); + DataGridView.Rows.Add(new object[] { wood.Key, wood.Value.Item1.WoodName, wood.Value.Item2 }); } } } catch (Exception ex) { - _logger.LogError(ex, "Ошибка загрузки изделий магазина"); - MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, - MessageBoxIcon.Error); + _logger.LogError(ex, "Shop ice creams loading error"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); } } - private void CancelButton_Click(object sender, EventArgs e) - { - DialogResult = DialogResult.Cancel; - Close(); - } - - private void SaveButton_Click(object sender, EventArgs e) + private void ButtonSave_Click(object sender, EventArgs e) { if (string.IsNullOrEmpty(NameTextBox.Text)) { @@ -85,7 +86,17 @@ namespace CarpentryWorkshopView MessageBox.Show("Заполните адрес", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } - _logger.LogInformation("Сохранение магазина"); + if (string.IsNullOrEmpty(DateTimePicker.Text)) + { + MessageBox.Show("Заполните дату", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + if (string.IsNullOrEmpty(CapacityUpDown.Text)) + { + MessageBox.Show("Заполните максимальное количество", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + _logger.LogInformation("Shop saving"); try { var model = new ShopBindingModel @@ -93,9 +104,9 @@ namespace CarpentryWorkshopView Id = _id ?? 0, ShopName = NameTextBox.Text, Address = AddressTextBox.Text, - DateOpen = DateTimePicker.Value.Date, - WoodMaxCount = Convert.ToInt32(CapacityUpDown.Value), - ShopWoods = _woods + DateOpen = DateTimePicker.Value, + WoodMaxCount = Convert.ToInt32(CapacityUpDown.Text), + ShopWoods = _shopWoods }; var operationResult = _id.HasValue ? _logic.Update(model) : _logic.Create(model); if (!operationResult) @@ -108,9 +119,15 @@ namespace CarpentryWorkshopView } catch (Exception ex) { - _logger.LogError(ex, "Ошибка сохранения магазина"); + _logger.LogError(ex, "Shop saving error"); MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); } } + + private void ButtonCancel_Click(object sender, EventArgs e) + { + DialogResult = DialogResult.Cancel; + Close(); + } } } diff --git a/CarpentryWorkshop/CarpentryWorkshop/FormShops.Designer.cs b/CarpentryWorkshop/CarpentryWorkshop/FormShops.Designer.cs index ec39f29..b1ec242 100644 --- a/CarpentryWorkshop/CarpentryWorkshop/FormShops.Designer.cs +++ b/CarpentryWorkshop/CarpentryWorkshop/FormShops.Designer.cs @@ -52,7 +52,7 @@ AddButton.TabIndex = 1; AddButton.Text = "Добавить"; AddButton.UseVisualStyleBackColor = true; - AddButton.Click += AddButton_Click; + AddButton.Click += ButtonAdd_Click; // // UpdateButton // @@ -62,7 +62,7 @@ UpdateButton.TabIndex = 2; UpdateButton.Text = "Изменить"; UpdateButton.UseVisualStyleBackColor = true; - UpdateButton.Click += UpdateButton_Click; + UpdateButton.Click += ButtonEdit_Click; // // RefreshButton // @@ -72,7 +72,7 @@ RefreshButton.TabIndex = 3; RefreshButton.Text = "Обновить"; RefreshButton.UseVisualStyleBackColor = true; - RefreshButton.Click += RefreshButton_Click; + RefreshButton.Click += ButtonUpd_Click; // // DeleteButton // @@ -82,7 +82,7 @@ DeleteButton.TabIndex = 4; DeleteButton.Text = "Удалить"; DeleteButton.UseVisualStyleBackColor = true; - DeleteButton.Click += DeleteButton_Click; + DeleteButton.Click += ButtonDel_Click; // // ShopsForm // @@ -94,9 +94,9 @@ Controls.Add(UpdateButton); Controls.Add(AddButton); Controls.Add(DataGridView); - Name = "ShopsForm"; - Text = "ShopsForm"; - Load += ShopsForm_Load; + Name = "FormShops"; + Text = "FormShops"; + Load += FormShops_Load; ((System.ComponentModel.ISupportInitialize)DataGridView).EndInit(); ResumeLayout(false); } diff --git a/CarpentryWorkshop/CarpentryWorkshop/FormShops.cs b/CarpentryWorkshop/CarpentryWorkshop/FormShops.cs index cbe1cd6..76ae5c2 100644 --- a/CarpentryWorkshop/CarpentryWorkshop/FormShops.cs +++ b/CarpentryWorkshop/CarpentryWorkshop/FormShops.cs @@ -2,19 +2,28 @@ using CarpentryWorkshopContracts.BindingModels; using CarpentryWorkshopContracts.BusinessLogicsContracts; using Microsoft.Extensions.Logging; +using System.Windows.Forms; namespace CarpentryWorkshopView { public partial class FormShops : Form { private readonly ILogger _logger; + private readonly IShopLogic _logic; + public FormShops(ILogger logger, IShopLogic logic) { InitializeComponent(); _logger = logger; _logic = logic; } + + private void FormShops_Load(object sender, EventArgs e) + { + LoadData(); + } + private void LoadData() { try @@ -25,25 +34,18 @@ namespace CarpentryWorkshopView DataGridView.DataSource = list; DataGridView.Columns["Id"].Visible = false; DataGridView.Columns["ShopName"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; - DataGridView.Columns["Address"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; - DataGridView.Columns["DateOpen"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; DataGridView.Columns["ShopWoods"].Visible = false; } - _logger.LogInformation("Загрузка магазинов"); + _logger.LogInformation("Shops loading"); } catch (Exception ex) { - _logger.LogError(ex, "Ошибка загрузки магазинов"); + _logger.LogError(ex, "Shops loading error"); MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); } } - private void ShopsForm_Load(object sender, EventArgs e) - { - LoadData(); - } - - private void AddButton_Click(object sender, EventArgs e) + private void ButtonAdd_Click(object sender, EventArgs e) { var service = Program.ServiceProvider?.GetService(typeof(FormShop)); if (service is FormShop form) @@ -55,15 +57,14 @@ namespace CarpentryWorkshopView } } - private void UpdateButton_Click(object sender, EventArgs e) + private void ButtonEdit_Click(object sender, EventArgs e) { if (DataGridView.SelectedRows.Count == 1) { var service = Program.ServiceProvider?.GetService(typeof(FormShop)); if (service is FormShop form) { - var tmp = Convert.ToInt32(DataGridView.SelectedRows[0].Cells["Id"].Value); - 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) { LoadData(); @@ -72,25 +73,17 @@ namespace CarpentryWorkshopView } } - private void RefreshButton_Click(object sender, EventArgs e) - { - LoadData(); - } - - private void DeleteButton_Click(object sender, EventArgs e) + 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("Удаление магазина"); + _logger.LogInformation("Deletion of shop"); try { - if (!_logic.Delete(new ShopBindingModel - { - Id = id - })) + if (!_logic.Delete(new ShopBindingModel { Id = id })) { throw new Exception("Ошибка при удалении. Дополнительная информация в логах."); } @@ -98,11 +91,16 @@ namespace CarpentryWorkshopView } catch (Exception ex) { - _logger.LogError(ex, "Ошибка удаления магазина"); + _logger.LogError(ex, "Shop deletion error"); MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); } } } } + + private void ButtonUpd_Click(object sender, EventArgs e) + { + LoadData(); + } } } diff --git a/CarpentryWorkshop/CarpentryWorkshop/FormWoodSale.Designer.cs b/CarpentryWorkshop/CarpentryWorkshop/FormWoodSale.Designer.cs new file mode 100644 index 0000000..df9ee7a --- /dev/null +++ b/CarpentryWorkshop/CarpentryWorkshop/FormWoodSale.Designer.cs @@ -0,0 +1,127 @@ +namespace CarpentryWorkshopView +{ + partial class FormWoodSale + { + /// + /// 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); + } + + #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() + { + buttonCancel = new Button(); + buttonSale = new Button(); + textBoxCount = new TextBox(); + labelCount = new Label(); + comboBoxWood = new ComboBox(); + labelWood = new Label(); + SuspendLayout(); + // + // buttonCancel + // + buttonCancel.Location = new Point(253, 83); + buttonCancel.Margin = new Padding(4, 3, 4, 3); + buttonCancel.Name = "buttonCancel"; + buttonCancel.Size = new Size(88, 27); + buttonCancel.TabIndex = 17; + buttonCancel.Text = "Отмена"; + buttonCancel.UseVisualStyleBackColor = true; + buttonCancel.Click += ButtonCancel_Click; + // + // buttonSale + // + buttonSale.Location = new Point(159, 83); + buttonSale.Margin = new Padding(4, 3, 4, 3); + buttonSale.Name = "buttonSale"; + buttonSale.Size = new Size(88, 27); + buttonSale.TabIndex = 16; + buttonSale.Text = "Продать"; + buttonSale.UseVisualStyleBackColor = true; + buttonSale.Click += ButtonSale_Click; + // + // textBoxCount + // + textBoxCount.Location = new Point(101, 51); + textBoxCount.Margin = new Padding(4, 3, 4, 3); + textBoxCount.Name = "textBoxCount"; + textBoxCount.Size = new Size(252, 23); + textBoxCount.TabIndex = 15; + // + // labelCount + // + labelCount.AutoSize = true; + labelCount.Location = new Point(13, 54); + labelCount.Margin = new Padding(4, 0, 4, 0); + labelCount.Name = "labelCount"; + labelCount.Size = new Size(78, 15); + labelCount.TabIndex = 14; + labelCount.Text = "Количество :"; + // + // comboBoxWood + // + comboBoxWood.DropDownStyle = ComboBoxStyle.DropDownList; + comboBoxWood.FormattingEnabled = true; + comboBoxWood.Location = new Point(101, 15); + comboBoxWood.Margin = new Padding(4, 3, 4, 3); + comboBoxWood.Name = "comboBoxWood"; + comboBoxWood.Size = new Size(252, 23); + comboBoxWood.TabIndex = 13; + // + // labelWood + // + labelWood.AutoSize = true; + labelWood.Location = new Point(13, 19); + labelWood.Margin = new Padding(4, 0, 4, 0); + labelWood.Name = "labelWood"; + labelWood.Size = new Size(80, 15); + labelWood.TabIndex = 12; + labelWood.Text = "Изделие :"; + // + // FormWoodSale + // + AutoScaleDimensions = new SizeF(7F, 15F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(373, 123); + Controls.Add(buttonCancel); + Controls.Add(buttonSale); + Controls.Add(textBoxCount); + Controls.Add(labelCount); + Controls.Add(comboBoxWood); + Controls.Add(labelWood); + Name = "FormWoodSale"; + StartPosition = FormStartPosition.CenterScreen; + Text = "Продажа изделий"; + Load += FormWoodSale_Load; + ResumeLayout(false); + PerformLayout(); + } + + #endregion + + private Button buttonCancel; + private Button buttonSale; + private TextBox textBoxCount; + private Label labelCount; + private ComboBox comboBoxWood; + private Label labelWood; + } +} \ No newline at end of file diff --git a/CarpentryWorkshop/CarpentryWorkshop/FormWoodSale.cs b/CarpentryWorkshop/CarpentryWorkshop/FormWoodSale.cs new file mode 100644 index 0000000..3d7352c --- /dev/null +++ b/CarpentryWorkshop/CarpentryWorkshop/FormWoodSale.cs @@ -0,0 +1,96 @@ +using CarpentryWorkshopContracts.BindingModels; +using CarpentryWorkshopContracts.BusinessLogicsContracts; +using Microsoft.Extensions.Logging; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; + +namespace CarpentryWorkshopView +{ + public partial class FormWoodSale : Form + { + private readonly ILogger _logger; + + private readonly IWoodLogic _logicWood; + + private readonly IShopLogic _logicShop; + + public FormWoodSale(ILogger logger, IWoodLogic logicWood, IShopLogic logicShop) + { + InitializeComponent(); + _logger = logger; + _logicWood = logicWood; + _logicShop = logicShop; + } + + private void FormWoodSale_Load(object sender, EventArgs e) + { + _logger.LogInformation("Ice creams loading"); + try + { + var list = _logicWood.ReadList(null); + if (list != null) + { + comboBoxWood.DisplayMember = "WoodName"; + comboBoxWood.ValueMember = "Id"; + comboBoxWood.DataSource = list; + comboBoxWood.SelectedItem = null; + } + } + catch (Exception ex) + { + _logger.LogError(ex, "Ice creams loading error"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void ButtonSale_Click(object sender, EventArgs e) + { + if (comboBoxWood.SelectedValue == null) + { + MessageBox.Show("Выберите мороженое", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + if (string.IsNullOrEmpty(textBoxCount.Text)) + { + MessageBox.Show("Заполните поле Количество", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + _logger.LogInformation("Ice cream sale"); + try + { + var operationResult = _logicShop.MakeSell( + new WoodBindingModel + { + Id = Convert.ToInt32(comboBoxWood.SelectedValue) + }, + Convert.ToInt32(textBoxCount.Text) + ); + if (!operationResult) + { + throw new Exception("Ошибка при продаже."); + } + MessageBox.Show("Продажа прошла успешно", "Сообщение", MessageBoxButtons.OK, MessageBoxIcon.Information); + DialogResult = DialogResult.OK; + Close(); + } + catch (Exception ex) + { + _logger.LogError(ex, "Wood sale error"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void ButtonCancel_Click(object sender, EventArgs e) + { + DialogResult = DialogResult.Cancel; + Close(); + } + } +} diff --git a/CarpentryWorkshop/CarpentryWorkshop/FormWoodSale.resx b/CarpentryWorkshop/CarpentryWorkshop/FormWoodSale.resx new file mode 100644 index 0000000..1af7de1 --- /dev/null +++ b/CarpentryWorkshop/CarpentryWorkshop/FormWoodSale.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/CarpentryWorkshop/CarpentryWorkshop/Program.cs b/CarpentryWorkshop/CarpentryWorkshop/Program.cs index 9b7966a..7989730 100644 --- a/CarpentryWorkshop/CarpentryWorkshop/Program.cs +++ b/CarpentryWorkshop/CarpentryWorkshop/Program.cs @@ -56,7 +56,7 @@ namespace CarpentryWorkshop services.AddTransient(); services.AddTransient(); services.AddTransient(); - services.AddTransient(); + services.AddTransient(); } } } \ No newline at end of file diff --git a/CarpentryWorkshop/CarpentryWorkshopFileImplement/Models/Shop.cs b/CarpentryWorkshop/CarpentryWorkshopFileImplement/Models/Shop.cs index f396abb..6a19218 100644 --- a/CarpentryWorkshop/CarpentryWorkshopFileImplement/Models/Shop.cs +++ b/CarpentryWorkshop/CarpentryWorkshopFileImplement/Models/Shop.cs @@ -21,7 +21,8 @@ namespace CarpentryWorkshopFileImplement.Models if (_shopWoods == null) { var source = DataFileSingleton.GetInstance(); - _shopWoods = Woods.ToDictionary(x => x.Key, y => ((source.Woods.FirstOrDefault(z => z.Id == y.Key) as IWoodModel)!, y.Value)); + _shopWoods = Woods.ToDictionary(x => x.Key, + y => ((source.Woods.FirstOrDefault(z => z.Id == y.Key) as IWoodModel)!, y.Value)); } return _shopWoods; } @@ -52,15 +53,15 @@ namespace CarpentryWorkshopFileImplement.Models { return null; } - return new() + return new Shop() { Id = Convert.ToInt32(element.Attribute("Id")!.Value), ShopName = element.Element("ShopName")!.Value, Address = element.Element("Address")!.Value, DateOpen = Convert.ToDateTime(element.Element("DateOpen")!.Value), - Woods = element.Element("ShopWoods")!.Elements("ShopWood")!.ToDictionary(x => Convert.ToInt32(x.Element("Key")?.Value), - x => Convert.ToInt32(x.Element("Value")?.Value)), - WoodMaxCount = Convert.ToInt32(element.Element("WoodMaxCount")!.Value) + WoodMaxCount = Convert.ToInt32(element.Element("WoodMaxCount")!.Value), + Woods = element.Element("ShopWoods")!.Elements("ShopWood") + .ToDictionary(x => Convert.ToInt32(x.Element("Key")?.Value), x => Convert.ToInt32(x.Element("Value")?.Value)) }; } @@ -89,14 +90,14 @@ namespace CarpentryWorkshopFileImplement.Models }; public XElement GetXElement => new("Shop", - new XAttribute("Id", Id), - new XElement("ShopName", ShopName), - new XElement("Address", Address), - new XElement("DateOpen", DateOpen.ToString()), - new XElement("WoodMaxCount", WoodMaxCount), - new XElement("ShopWoods", Woods - .Select(x => new XElement("ShopWood", - new XElement("Key", x.Key), - new XElement("Value", x.Value))).ToArray())); + new XAttribute("Id", Id), + new XElement("ShopName", ShopName), + new XElement("Address", Address), + new XElement("DateOpen", DateOpen.ToString()), + new XElement("WoodMaxCount", WoodMaxCount.ToString()), + new XElement("ShopWoods", + Woods.Select(x => new XElement("ShopWood", + new XElement("Key", x.Key), + new XElement("Value", x.Value))).ToArray())); } }