diff --git a/PrecastConcretePlant/PrecastConcretePlant.sln b/PrecastConcretePlant/PrecastConcretePlant.sln index d5142f6..667360b 100644 --- a/PrecastConcretePlant/PrecastConcretePlant.sln +++ b/PrecastConcretePlant/PrecastConcretePlant.sln @@ -7,11 +7,13 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "PrecastConcretePlantView", EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "PrecastConcretePlantDataModels", "PrecastConcretePlantDataModels\PrecastConcretePlantDataModels.csproj", "{AFE873D8-CDF1-4780-A98B-058EF19F37D8}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PrecastConcretePlantContracts", "PrecastConcretePlantContracts\PrecastConcretePlantContracts.csproj", "{163A22A6-D3C3-478F-9DAF-DA03FBF2AF48}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "PrecastConcretePlantContracts", "PrecastConcretePlantContracts\PrecastConcretePlantContracts.csproj", "{163A22A6-D3C3-478F-9DAF-DA03FBF2AF48}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PrecastConcretePlantBusinessLogic", "PrecastConcretePlantBusinessLogic\PrecastConcretePlantBusinessLogic.csproj", "{BD35E396-4E8B-4400-9569-FDDC602FDEDF}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "PrecastConcretePlantBusinessLogic", "PrecastConcretePlantBusinessLogic\PrecastConcretePlantBusinessLogic.csproj", "{BD35E396-4E8B-4400-9569-FDDC602FDEDF}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PrecastConcretePlantListImplement", "PrecastConcretePlantListImplement\PrecastConcretePlantListImplement.csproj", "{0A99F76D-7163-4E8E-B109-70B811BACE94}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "PrecastConcretePlantListImplement", "PrecastConcretePlantListImplement\PrecastConcretePlantListImplement.csproj", "{0A99F76D-7163-4E8E-B109-70B811BACE94}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PrecastConcretePlantFileImplement", "PrecastConcretePlantFileImplement\PrecastConcretePlantFileImplement.csproj", "{29844787-85D7-4BE5-B39E-EC9C98D200BB}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution @@ -39,6 +41,10 @@ Global {0A99F76D-7163-4E8E-B109-70B811BACE94}.Debug|Any CPU.Build.0 = Debug|Any CPU {0A99F76D-7163-4E8E-B109-70B811BACE94}.Release|Any CPU.ActiveCfg = Release|Any CPU {0A99F76D-7163-4E8E-B109-70B811BACE94}.Release|Any CPU.Build.0 = Release|Any CPU + {29844787-85D7-4BE5-B39E-EC9C98D200BB}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {29844787-85D7-4BE5-B39E-EC9C98D200BB}.Debug|Any CPU.Build.0 = Debug|Any CPU + {29844787-85D7-4BE5-B39E-EC9C98D200BB}.Release|Any CPU.ActiveCfg = Release|Any CPU + {29844787-85D7-4BE5-B39E-EC9C98D200BB}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/PrecastConcretePlant/PrecastConcretePlant/FormComponents.cs b/PrecastConcretePlant/PrecastConcretePlant/FormComponents.cs index aff7825..29062ff 100644 --- a/PrecastConcretePlant/PrecastConcretePlant/FormComponents.cs +++ b/PrecastConcretePlant/PrecastConcretePlant/FormComponents.cs @@ -23,6 +23,7 @@ namespace PrecastConcretePlantView InitializeComponent(); _logger = logger; _logic = logic; + LoadData(); } private void FormComponents_Load(object sender, EventArgs e) diff --git a/PrecastConcretePlant/PrecastConcretePlant/FormMain.Designer.cs b/PrecastConcretePlant/PrecastConcretePlant/FormMain.Designer.cs index f4d7170..e07bf37 100644 --- a/PrecastConcretePlant/PrecastConcretePlant/FormMain.Designer.cs +++ b/PrecastConcretePlant/PrecastConcretePlant/FormMain.Designer.cs @@ -32,6 +32,7 @@ this.СправочникиToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.ИзделияToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.КомпонентыToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.магазиныToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.DataGridView = new System.Windows.Forms.DataGridView(); this.CreateOrderButton = new System.Windows.Forms.Button(); this.TakeOrderInWorkButton = new System.Windows.Forms.Button(); @@ -39,7 +40,7 @@ this.IssuedOrderButton = new System.Windows.Forms.Button(); this.UpdateListButton = new System.Windows.Forms.Button(); this.ButtonAddReinforcedInShop = new System.Windows.Forms.Button(); - this.магазиныToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.SellReinforcedButton = new System.Windows.Forms.Button(); this.MenuStrip.SuspendLayout(); ((System.ComponentModel.ISupportInitialize)(this.DataGridView)).BeginInit(); this.SuspendLayout(); @@ -67,17 +68,24 @@ // ИзделияToolStripMenuItem // this.ИзделияToolStripMenuItem.Name = "ИзделияToolStripMenuItem"; - this.ИзделияToolStripMenuItem.Size = new System.Drawing.Size(180, 22); + this.ИзделияToolStripMenuItem.Size = new System.Drawing.Size(145, 22); this.ИзделияToolStripMenuItem.Text = "Изделия"; this.ИзделияToolStripMenuItem.Click += new System.EventHandler(this.ИзделияToolStripMenuItem_Click); // // КомпонентыToolStripMenuItem // this.КомпонентыToolStripMenuItem.Name = "КомпонентыToolStripMenuItem"; - this.КомпонентыToolStripMenuItem.Size = new System.Drawing.Size(180, 22); + this.КомпонентыToolStripMenuItem.Size = new System.Drawing.Size(145, 22); this.КомпонентыToolStripMenuItem.Text = "Компоненты"; this.КомпонентыToolStripMenuItem.Click += new System.EventHandler(this.КомпонентыToolStripMenuItem_Click); // + // магазиныToolStripMenuItem + // + this.магазиныToolStripMenuItem.Name = "магазиныToolStripMenuItem"; + this.магазиныToolStripMenuItem.Size = new System.Drawing.Size(145, 22); + this.магазиныToolStripMenuItem.Text = "Магазины"; + this.магазиныToolStripMenuItem.Click += new System.EventHandler(this.магазиныToolStripMenuItem_Click); + // // DataGridView // this.DataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; @@ -147,18 +155,22 @@ this.ButtonAddReinforcedInShop.UseVisualStyleBackColor = true; this.ButtonAddReinforcedInShop.Click += new System.EventHandler(this.ButtonAddReinforcedInShop_Click); // - // магазиныToolStripMenuItem + // SellReinforcedButton // - this.магазиныToolStripMenuItem.Name = "магазиныToolStripMenuItem"; - this.магазиныToolStripMenuItem.Size = new System.Drawing.Size(180, 22); - this.магазиныToolStripMenuItem.Text = "Магазины"; - this.магазиныToolStripMenuItem.Click += new System.EventHandler(this.магазиныToolStripMenuItem_Click); + this.SellReinforcedButton.Location = new System.Drawing.Point(905, 276); + this.SellReinforcedButton.Name = "SellReinforcedButton"; + this.SellReinforcedButton.Size = new System.Drawing.Size(125, 29); + this.SellReinforcedButton.TabIndex = 8; + this.SellReinforcedButton.Text = "Продать изделие"; + this.SellReinforcedButton.UseVisualStyleBackColor = true; + this.SellReinforcedButton.Click += new System.EventHandler(this.SellReinforcedButton_Click); // // FormMain // this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.ClientSize = new System.Drawing.Size(1042, 450); + this.Controls.Add(this.SellReinforcedButton); this.Controls.Add(this.ButtonAddReinforcedInShop); this.Controls.Add(this.UpdateListButton); this.Controls.Add(this.IssuedOrderButton); @@ -192,5 +204,6 @@ private Button UpdateListButton; private Button ButtonAddReinforcedInShop; private ToolStripMenuItem магазиныToolStripMenuItem; + private Button SellReinforcedButton; } } \ No newline at end of file diff --git a/PrecastConcretePlant/PrecastConcretePlant/FormMain.cs b/PrecastConcretePlant/PrecastConcretePlant/FormMain.cs index 5ecb94c..f62fdd6 100644 --- a/PrecastConcretePlant/PrecastConcretePlant/FormMain.cs +++ b/PrecastConcretePlant/PrecastConcretePlant/FormMain.cs @@ -26,6 +26,7 @@ namespace PrecastConcretePlantView InitializeComponent(); _logger = logger; _orderLogic = orderLogic; + LoadData(); } private void FormMain_Load(object sender, EventArgs e) @@ -167,7 +168,7 @@ namespace PrecastConcretePlantView try { var operationResult = _orderLogic.DeliveryOrder(new OrderBindingModel - { + { Id = id, ReinforcedId = Convert.ToInt32(DataGridView.SelectedRows[0].Cells["ReinforcedId"].Value), ReinforcedName = DataGridView.SelectedRows[0].Cells["ReinforcedName"].Value.ToString(), @@ -215,5 +216,15 @@ namespace PrecastConcretePlantView form.ShowDialog(); } } + + private void SellReinforcedButton_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormSellReinforced)); + + if (service is FormSellReinforced form) + { + form.ShowDialog(); + } + } } } diff --git a/PrecastConcretePlant/PrecastConcretePlant/FormReinforceds.cs b/PrecastConcretePlant/PrecastConcretePlant/FormReinforceds.cs index 84c4dea..e52aca8 100644 --- a/PrecastConcretePlant/PrecastConcretePlant/FormReinforceds.cs +++ b/PrecastConcretePlant/PrecastConcretePlant/FormReinforceds.cs @@ -23,6 +23,7 @@ namespace PrecastConcretePlantView InitializeComponent(); _logger = logger; _logic = logic; + LoadData(); } private void FormComponents_Load(object sender, EventArgs e) diff --git a/PrecastConcretePlant/PrecastConcretePlant/FormSellReinforced.Designer.cs b/PrecastConcretePlant/PrecastConcretePlant/FormSellReinforced.Designer.cs new file mode 100644 index 0000000..f09082b --- /dev/null +++ b/PrecastConcretePlant/PrecastConcretePlant/FormSellReinforced.Designer.cs @@ -0,0 +1,119 @@ +namespace PrecastConcretePlantView +{ + partial class FormSellReinforced + { + /// + /// 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() + { + this.ReinforcedLabel = new System.Windows.Forms.Label(); + this.QuantityLabel = new System.Windows.Forms.Label(); + this.ReindorcedСomboBox = new System.Windows.Forms.ComboBox(); + this.QuantityTextBox = new System.Windows.Forms.TextBox(); + this.SaveButton = new System.Windows.Forms.Button(); + this.ButtonCancel = new System.Windows.Forms.Button(); + this.SuspendLayout(); + // + // ReinforcedLabel + // + this.ReinforcedLabel.AutoSize = true; + this.ReinforcedLabel.Location = new System.Drawing.Point(12, 18); + this.ReinforcedLabel.Name = "ReinforcedLabel"; + this.ReinforcedLabel.Size = new System.Drawing.Size(56, 15); + this.ReinforcedLabel.TabIndex = 0; + this.ReinforcedLabel.Text = "Изделие:"; + // + // QuantityLabel + // + this.QuantityLabel.AutoSize = true; + this.QuantityLabel.Location = new System.Drawing.Point(12, 51); + this.QuantityLabel.Name = "QuantityLabel"; + this.QuantityLabel.Size = new System.Drawing.Size(75, 15); + this.QuantityLabel.TabIndex = 1; + this.QuantityLabel.Text = "Количество:"; + // + // ReindorcedСomboBox + // + this.ReindorcedСomboBox.FormattingEnabled = true; + this.ReindorcedСomboBox.Location = new System.Drawing.Point(88, 15); + this.ReindorcedСomboBox.Name = "ReindorcedСomboBox"; + this.ReindorcedСomboBox.Size = new System.Drawing.Size(184, 23); + this.ReindorcedСomboBox.TabIndex = 2; + // + // QuantityTextBox + // + this.QuantityTextBox.Location = new System.Drawing.Point(88, 48); + this.QuantityTextBox.Name = "QuantityTextBox"; + this.QuantityTextBox.Size = new System.Drawing.Size(184, 23); + this.QuantityTextBox.TabIndex = 3; + // + // SaveButton + // + this.SaveButton.Location = new System.Drawing.Point(72, 100); + this.SaveButton.Name = "SaveButton"; + this.SaveButton.Size = new System.Drawing.Size(97, 29); + this.SaveButton.TabIndex = 4; + this.SaveButton.Text = "Сохранить"; + this.SaveButton.UseVisualStyleBackColor = true; + this.SaveButton.Click += new System.EventHandler(this.SaveButton_Click); + // + // ButtonCancel + // + this.ButtonCancel.Location = new System.Drawing.Point(175, 100); + this.ButtonCancel.Name = "ButtonCancel"; + this.ButtonCancel.Size = new System.Drawing.Size(97, 29); + this.ButtonCancel.TabIndex = 5; + this.ButtonCancel.Text = "Отмена"; + this.ButtonCancel.UseVisualStyleBackColor = true; + this.ButtonCancel.Click += new System.EventHandler(this.ButtonCancel_Click); + // + // FormSellReinforced + // + this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(284, 141); + this.Controls.Add(this.ButtonCancel); + this.Controls.Add(this.SaveButton); + this.Controls.Add(this.QuantityTextBox); + this.Controls.Add(this.ReindorcedСomboBox); + this.Controls.Add(this.QuantityLabel); + this.Controls.Add(this.ReinforcedLabel); + this.Name = "FormSellReinforced"; + this.Text = "Продать Изделие"; + this.ResumeLayout(false); + this.PerformLayout(); + + } + + #endregion + + private Label ReinforcedLabel; + private Label QuantityLabel; + private ComboBox ReindorcedСomboBox; + private TextBox QuantityTextBox; + private Button SaveButton; + private Button ButtonCancel; + } +} \ No newline at end of file diff --git a/PrecastConcretePlant/PrecastConcretePlant/FormSellReinforced.cs b/PrecastConcretePlant/PrecastConcretePlant/FormSellReinforced.cs new file mode 100644 index 0000000..4188396 --- /dev/null +++ b/PrecastConcretePlant/PrecastConcretePlant/FormSellReinforced.cs @@ -0,0 +1,94 @@ +using Microsoft.Extensions.Logging; +using PrecastConcretePlantContracts.BusinessLogicsContracts; +using PrecastConcretePlantContracts.SearchModels; + +namespace PrecastConcretePlantView +{ + public partial class FormSellReinforced : Form + { + private readonly ILogger _logger; + private readonly IReinforcedLogic _logicReinforced; + private readonly IShopLogic _logicShop; + public FormSellReinforced(ILogger logger, IReinforcedLogic logicReinforced, IShopLogic logicShop) + { + InitializeComponent(); + _logger = logger; + _logicReinforced = logicReinforced; + _logicShop = logicShop; + LoadData(); + } + + private void FormSellReinforced_Load(object sender, EventArgs e) + { + LoadData(); + } + + private void LoadData() + { + _logger.LogInformation("Loading reinforcediss for sale."); + + try + { + var list = _logicReinforced.ReadList(null); + if (list != null) + { + ReindorcedСomboBox.DisplayMember = "ReinforcedName"; + ReindorcedСomboBox.ValueMember = "Id"; + ReindorcedСomboBox.DataSource = list; + ReindorcedСomboBox.SelectedItem = null; + } + } + catch (Exception ex) + { + _logger.LogError(ex, "List loading error."); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void SaveButton_Click(object sender, EventArgs e) + { + if (string.IsNullOrEmpty(QuantityTextBox.Text)) + { + MessageBox.Show("Укажите количество", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + + if (ReindorcedСomboBox.SelectedValue == null) + { + MessageBox.Show("Выберите изделие", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + + _logger.LogInformation("Product sale."); + + try + { + var operationResult = _logicShop.SellReinforced(_logicReinforced.ReadElement(new ReinforcedSearchModel() + { + Id = Convert.ToInt32(ReindorcedСomboBox.SelectedValue) + })!, Convert.ToInt32(QuantityTextBox.Text)); + + if (!operationResult) + { + throw new Exception("Ошибка при продаже изделия. Дополнительная информация в логах."); + } + + MessageBox.Show("Сохранение прошло успешно", "Сообщение", MessageBoxButtons.OK, MessageBoxIcon.Information); + DialogResult = DialogResult.OK; + + Close(); + } + catch (Exception ex) + { + _logger.LogError(ex, "Product 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/PrecastConcretePlant/PrecastConcretePlant/FormSellReinforced.resx b/PrecastConcretePlant/PrecastConcretePlant/FormSellReinforced.resx new file mode 100644 index 0000000..f298a7b --- /dev/null +++ b/PrecastConcretePlant/PrecastConcretePlant/FormSellReinforced.resx @@ -0,0 +1,60 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 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/PrecastConcretePlant/PrecastConcretePlant/FormShop.Designer.cs b/PrecastConcretePlant/PrecastConcretePlant/FormShop.Designer.cs index 16290c0..ca6cec6 100644 --- a/PrecastConcretePlant/PrecastConcretePlant/FormShop.Designer.cs +++ b/PrecastConcretePlant/PrecastConcretePlant/FormShop.Designer.cs @@ -40,26 +40,28 @@ this.buttonCancel = new System.Windows.Forms.Button(); this.buttonSave = new System.Windows.Forms.Button(); this.textBoxDateOpening = new System.Windows.Forms.DateTimePicker(); + this.ReinforcedMaxCountLable = new System.Windows.Forms.Label(); + this.VolumeNumericUpDown = new System.Windows.Forms.NumericUpDown(); ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit(); + ((System.ComponentModel.ISupportInitialize)(this.VolumeNumericUpDown)).BeginInit(); this.SuspendLayout(); // // label1 // this.label1.AutoSize = true; - this.label1.Location = new System.Drawing.Point(12, 9); + this.label1.Location = new System.Drawing.Point(14, 12); this.label1.Name = "label1"; - this.label1.Size = new System.Drawing.Size(116, 15); + this.label1.Size = new System.Drawing.Size(150, 20); this.label1.TabIndex = 0; this.label1.Text = "Название магазина:"; // // comboBoxShop // - this.comboBoxShop.FormattingEnabled = true; - this.comboBoxShop.Location = new System.Drawing.Point(12, 27); + this.comboBoxShop.Location = new System.Drawing.Point(14, 39); + this.comboBoxShop.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); this.comboBoxShop.Name = "comboBoxShop"; - this.comboBoxShop.Size = new System.Drawing.Size(141, 23); - this.comboBoxShop.TabIndex = 1; - this.comboBoxShop.SelectedIndexChanged += new System.EventHandler(this.ComboBoxShop_SelectedIndexChanged); + this.comboBoxShop.Size = new System.Drawing.Size(138, 28); + this.comboBoxShop.TabIndex = 12; // // dataGridView // @@ -71,59 +73,68 @@ this.PastryName, this.Price, this.Count}); - this.dataGridView.Location = new System.Drawing.Point(12, 64); + this.dataGridView.Location = new System.Drawing.Point(14, 155); + this.dataGridView.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); this.dataGridView.Name = "dataGridView"; + this.dataGridView.RowHeadersWidth = 51; this.dataGridView.RowTemplate.Height = 25; - this.dataGridView.Size = new System.Drawing.Size(583, 213); + this.dataGridView.Size = new System.Drawing.Size(666, 332); this.dataGridView.TabIndex = 2; // // PastryName // this.PastryName.AutoSizeMode = System.Windows.Forms.DataGridViewAutoSizeColumnMode.Fill; this.PastryName.HeaderText = "Имя изделия"; + this.PastryName.MinimumWidth = 6; this.PastryName.Name = "PastryName"; // // Price // this.Price.HeaderText = "Цена"; + this.Price.MinimumWidth = 6; this.Price.Name = "Price"; + this.Price.Width = 125; // // Count // this.Count.HeaderText = "Количество"; + this.Count.MinimumWidth = 6; this.Count.Name = "Count"; + this.Count.Width = 125; // // label2 // this.label2.AutoSize = true; - this.label2.Location = new System.Drawing.Point(159, 9); + this.label2.Location = new System.Drawing.Point(182, 12); this.label2.Name = "label2"; - this.label2.Size = new System.Drawing.Size(97, 15); + this.label2.Size = new System.Drawing.Size(124, 20); this.label2.TabIndex = 3; this.label2.Text = "Адрес магазина:"; // // label3 // this.label3.AutoSize = true; - this.label3.Location = new System.Drawing.Point(386, 9); + this.label3.Location = new System.Drawing.Point(441, 12); this.label3.Name = "label3"; - this.label3.Size = new System.Drawing.Size(100, 15); + this.label3.Size = new System.Drawing.Size(126, 20); this.label3.TabIndex = 4; this.label3.Text = "Время открытия:"; // // textBoxAddress // - this.textBoxAddress.Location = new System.Drawing.Point(159, 27); + this.textBoxAddress.Location = new System.Drawing.Point(182, 36); + this.textBoxAddress.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); this.textBoxAddress.Name = "textBoxAddress"; - this.textBoxAddress.Size = new System.Drawing.Size(221, 23); + this.textBoxAddress.Size = new System.Drawing.Size(252, 27); this.textBoxAddress.TabIndex = 5; // // 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(492, 283); + this.buttonCancel.Location = new System.Drawing.Point(562, 495); + this.buttonCancel.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); this.buttonCancel.Name = "buttonCancel"; - this.buttonCancel.Size = new System.Drawing.Size(103, 23); + this.buttonCancel.Size = new System.Drawing.Size(118, 31); this.buttonCancel.TabIndex = 7; this.buttonCancel.Text = "Отмена"; this.buttonCancel.UseVisualStyleBackColor = true; @@ -132,9 +143,10 @@ // 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(366, 284); + this.buttonSave.Location = new System.Drawing.Point(418, 496); + this.buttonSave.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); this.buttonSave.Name = "buttonSave"; - this.buttonSave.Size = new System.Drawing.Size(120, 22); + this.buttonSave.Size = new System.Drawing.Size(137, 29); this.buttonSave.TabIndex = 8; this.buttonSave.Text = "Сохранить"; this.buttonSave.UseVisualStyleBackColor = true; @@ -142,16 +154,36 @@ // // textBoxDateOpening // - this.textBoxDateOpening.Location = new System.Drawing.Point(386, 27); + this.textBoxDateOpening.Location = new System.Drawing.Point(441, 36); + this.textBoxDateOpening.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); this.textBoxDateOpening.Name = "textBoxDateOpening"; - this.textBoxDateOpening.Size = new System.Drawing.Size(200, 23); + this.textBoxDateOpening.Size = new System.Drawing.Size(228, 27); this.textBoxDateOpening.TabIndex = 9; // + // ReinforcedMaxCountLable + // + this.ReinforcedMaxCountLable.AutoSize = true; + this.ReinforcedMaxCountLable.Location = new System.Drawing.Point(14, 71); + this.ReinforcedMaxCountLable.Name = "ReinforcedMaxCountLable"; + this.ReinforcedMaxCountLable.Size = new System.Drawing.Size(177, 20); + this.ReinforcedMaxCountLable.TabIndex = 10; + this.ReinforcedMaxCountLable.Text = "Вместимость магазина: "; + // + // VolumeNumericUpDown + // + this.VolumeNumericUpDown.Location = new System.Drawing.Point(14, 95); + this.VolumeNumericUpDown.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); + this.VolumeNumericUpDown.Name = "VolumeNumericUpDown"; + this.VolumeNumericUpDown.Size = new System.Drawing.Size(161, 27); + this.VolumeNumericUpDown.TabIndex = 11; + // // FormShop // - this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); + this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.ClientSize = new System.Drawing.Size(607, 317); + this.ClientSize = new System.Drawing.Size(694, 540); + this.Controls.Add(this.VolumeNumericUpDown); + this.Controls.Add(this.ReinforcedMaxCountLable); this.Controls.Add(this.textBoxDateOpening); this.Controls.Add(this.buttonSave); this.Controls.Add(this.buttonCancel); @@ -161,10 +193,12 @@ this.Controls.Add(this.dataGridView); this.Controls.Add(this.comboBoxShop); this.Controls.Add(this.label1); + this.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); this.Name = "FormShop"; this.Text = "Просмотр изделий магазина"; this.Load += new System.EventHandler(this.FormShop_Load); ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).EndInit(); + ((System.ComponentModel.ISupportInitialize)(this.VolumeNumericUpDown)).EndInit(); this.ResumeLayout(false); this.PerformLayout(); @@ -184,5 +218,7 @@ private DataGridViewTextBoxColumn Price; private DataGridViewTextBoxColumn Count; private DateTimePicker textBoxDateOpening; + private Label ReinforcedMaxCountLable; + private NumericUpDown VolumeNumericUpDown; } } \ No newline at end of file diff --git a/PrecastConcretePlant/PrecastConcretePlant/FormShop.cs b/PrecastConcretePlant/PrecastConcretePlant/FormShop.cs index fd2db82..17af0d7 100644 --- a/PrecastConcretePlant/PrecastConcretePlant/FormShop.cs +++ b/PrecastConcretePlant/PrecastConcretePlant/FormShop.cs @@ -1,6 +1,7 @@ using Microsoft.Extensions.Logging; using PrecastConcretePlantContracts.BindingModels; using PrecastConcretePlantContracts.BusinessLogicsContracts; +using PrecastConcretePlantContracts.SearchModels; using PrecastConcretePlantContracts.ViewModels; using PrecastConcretePlantDataModels.Models; using System; @@ -19,125 +20,75 @@ namespace ConfectioneryView { public partial class FormShop : Form { - private readonly List? _listShops; private readonly IShopLogic _logic; private readonly ILogger _logger; - - public int Id - { - get; set; - } - - private IShopModel? GetShop(int id) - { - if (_listShops == null) - { - return null; - } - foreach (var elem in _listShops) - { - if (elem.Id == id) - { - return elem; - } - } - return null; - } - + private int? _id; + private Dictionary _listShops; + public int Id { set { _id = value; } } public FormShop(ILogger logger, IShopLogic logic) { InitializeComponent(); _logger = logger; - _listShops = logic.ReadList(null); + _listShops = new(); _logic = logic; - if (_listShops != null) - { - comboBoxShop.DisplayMember = "Reinforcedies"; - comboBoxShop.ValueMember = "Id"; - comboBoxShop.DataSource = _listShops; - comboBoxShop.SelectedItem = null; - } } private void LoadData(bool extendDate = true) { + _logger.LogInformation("Загрузка изделий магазина"); try { - var model = GetShop(extendDate ? Id : Convert.ToInt32(comboBoxShop.SelectedValue)); - if (model != null) - { - comboBoxShop.Text = model.Name; - textBoxAddress.Text = model.Address; - textBoxDateOpening.Text = Convert.ToString(model.DateOpening); + if (_listShops != null) + { dataGridView.Rows.Clear(); - foreach (var el in model.Reinforcedies.Values) + foreach (var elem in _listShops) { - dataGridView.Rows.Add(new object[]{el.Item1.ReinforcedName, el.Item1.Price, el.Item2 }); + dataGridView.Rows.Add(new object[] { elem.Key, elem.Value.Item1.ReinforcedName, elem.Value.Item2 }); } } - _logger.LogInformation("Загрузка магазинов"); } catch (Exception ex) { - _logger.LogError(ex, "Ошибка загрузки магазинов"); - MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, - MessageBoxIcon.Error); + _logger.LogError(ex, "Ошибка загрузки изделий магазина"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); } } - private void ComboBoxShop_SelectedIndexChanged(object sender, EventArgs e) - { - LoadData(false); - } - private void ButtonSave_Click(object sender, EventArgs e) { if (string.IsNullOrEmpty(comboBoxShop.Text)) { - MessageBox.Show("Заполните название", "Ошибка", - MessageBoxButtons.OK, MessageBoxIcon.Error); + MessageBox.Show("Заполните название", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } if (string.IsNullOrEmpty(textBoxAddress.Text)) { - MessageBox.Show("Заполните адрес", "Ошибка", MessageBoxButtons.OK, - MessageBoxIcon.Error); + MessageBox.Show("Заполните адрес", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } - _logger.LogInformation("Сохранение изделия"); + _logger.LogInformation("Сохранение магазина"); try { - DateTime.TryParse(textBoxDateOpening.Text, out var dateTime); - ShopBindingModel model = new() + var model = new ShopBindingModel { + Id = _id ?? 0, Name = comboBoxShop.Text, Address = textBoxAddress.Text, - DateOpening = dateTime + DateOpening = textBoxDateOpening.Value.Date, + ReinforcedMaxCount = (int)VolumeNumericUpDown.Value }; - var vmodel = GetShop(Id); - bool operationResult = false; - - if (vmodel != null) - { - model.Id = vmodel.Id; - operationResult = _logic.Update(model); - } - else - { - operationResult = _logic.Create(model); - } + var operationResult = _id.HasValue ? _logic.Update(model) : _logic.Create(model); if (!operationResult) { throw new Exception("Ошибка при сохранении. Дополнительная информация в логах."); } - MessageBox.Show("Сохранение прошло успешно", "Сообщение", - MessageBoxButtons.OK, MessageBoxIcon.Information); + MessageBox.Show("Сохранение прошло успешно", "Сообщение", MessageBoxButtons.OK, MessageBoxIcon.Information); DialogResult = DialogResult.OK; Close(); } catch (Exception ex) { - _logger.LogError(ex, "Ошибка сохранения изделия"); + _logger.LogError(ex, "Ошибка сохранения магазина"); MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); } } @@ -150,7 +101,32 @@ namespace ConfectioneryView private void FormShop_Load(object sender, EventArgs e) { - LoadData(); + if (_id.HasValue) + { + _logger.LogInformation("Загрузка магазина"); + try + { + var view = _logic.ReadElement(new ShopSearchModel + { + Id = _id.Value + }); + if (view != null) + { + comboBoxShop.Text = view.Name; + textBoxAddress.Text = view.Address; + textBoxDateOpening.Text = view.DateOpening.ToString(); + VolumeNumericUpDown.Value = view.ReinforcedMaxCount; + _listShops = view.ShopReinforcedies ?? new Dictionary(); + LoadData(); + } + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка загрузки магазина"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, + MessageBoxIcon.Error); + } + } } } } diff --git a/PrecastConcretePlant/PrecastConcretePlant/FormShop.resx b/PrecastConcretePlant/PrecastConcretePlant/FormShop.resx index 63a5b60..36577c7 100644 --- a/PrecastConcretePlant/PrecastConcretePlant/FormShop.resx +++ b/PrecastConcretePlant/PrecastConcretePlant/FormShop.resx @@ -1,64 +1,4 @@ - - - + @@ -117,14 +57,10 @@ System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - + True - - + + True - - - True - + \ No newline at end of file diff --git a/PrecastConcretePlant/PrecastConcretePlant/FormShops.cs b/PrecastConcretePlant/PrecastConcretePlant/FormShops.cs index 3967822..c00af8d 100644 --- a/PrecastConcretePlant/PrecastConcretePlant/FormShops.cs +++ b/PrecastConcretePlant/PrecastConcretePlant/FormShops.cs @@ -29,7 +29,7 @@ namespace ConfectioneryView dataGridView.DataSource = list; dataGridView.Columns["Id"].Visible = false; - dataGridView.Columns["Reinforcedies"].Visible = false; + dataGridView.Columns["ShopReinforcedies"].Visible = false; dataGridView.Columns["Name"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; } diff --git a/PrecastConcretePlant/PrecastConcretePlant/PrecastConcretePlantView.csproj b/PrecastConcretePlant/PrecastConcretePlant/PrecastConcretePlantView.csproj index 367b809..5ce7825 100644 --- a/PrecastConcretePlant/PrecastConcretePlant/PrecastConcretePlantView.csproj +++ b/PrecastConcretePlant/PrecastConcretePlant/PrecastConcretePlantView.csproj @@ -38,6 +38,7 @@ + diff --git a/PrecastConcretePlant/PrecastConcretePlant/Program.cs b/PrecastConcretePlant/PrecastConcretePlant/Program.cs index 06ff656..8ab1233 100644 --- a/PrecastConcretePlant/PrecastConcretePlant/Program.cs +++ b/PrecastConcretePlant/PrecastConcretePlant/Program.cs @@ -2,10 +2,10 @@ using PrecastConcretePlantBusinessLogic.BusinessLogic; using Microsoft.Extensions.DependencyInjection; using PrecastConcretePlantContracts.BusinessLogicsContracts; using PrecastConcretePlantContracts.StoragesContracts; -using PrecastConcretePlantListImplement.Implements; using Microsoft.Extensions.Logging; using NLog.Extensions.Logging; using PrecastConcretePlantBusinessLogic.PrecastConcretePlantBusinessLogic.BusinessLogic; +using PrecastConcretePlantFileImplement.Implements; using ConfectioneryView; namespace PrecastConcretePlantView @@ -49,6 +49,7 @@ namespace PrecastConcretePlantView services.AddTransient(); services.AddTransient(); services.AddTransient(); + services.AddTransient(); services.AddTransient(); } } diff --git a/PrecastConcretePlant/PrecastConcretePlantBusinessLogic/BusinessLogic/OrderLogic.cs b/PrecastConcretePlant/PrecastConcretePlantBusinessLogic/BusinessLogic/OrderLogic.cs index d308c19..fc3415c 100644 --- a/PrecastConcretePlant/PrecastConcretePlantBusinessLogic/BusinessLogic/OrderLogic.cs +++ b/PrecastConcretePlant/PrecastConcretePlantBusinessLogic/BusinessLogic/OrderLogic.cs @@ -17,11 +17,14 @@ namespace PrecastConcretePlantBusinessLogic.BusinessLogic { private readonly ILogger _logger; private readonly IOrderStorage _orderStorage; - - public OrderLogic(ILogger logger, IOrderStorage orderStorage) + private readonly IShopLogic _shopLogic; + private readonly IReinforcedStorage _reinforcedStorage; + public OrderLogic(ILogger logger, IOrderStorage orderStorage, IReinforcedStorage reinforcedStorage, IShopLogic shopLogic) { _logger = logger; _orderStorage = orderStorage; + _shopLogic = shopLogic; + _reinforcedStorage = reinforcedStorage; } public bool CreateOrder(OrderBindingModel model) @@ -48,9 +51,14 @@ namespace PrecastConcretePlantBusinessLogic.BusinessLogic public bool StatusUpdate(OrderBindingModel model, OrderStatus newStatus) { - CheckModel(model); + var viewModel = _orderStorage.GetElement(new OrderSearchModel { Id = model.Id }); - if (model.Status + 1 != newStatus) + if (viewModel == null) + { + throw new ArgumentNullException(nameof(model)); + } + + if (viewModel.Status + 1 != newStatus) { _logger.LogWarning("Status update to " + newStatus.ToString() + " operation failed. Order status incorrect."); return false; @@ -58,13 +66,34 @@ namespace PrecastConcretePlantBusinessLogic.BusinessLogic model.Status = newStatus; - if (model.Status == OrderStatus.Выдан) + if (model.Status == OrderStatus.Готов) + { model.DateImplement = DateTime.Now; + var reinforced = _reinforcedStorage.GetElement(new() { Id = viewModel.ReinforcedId }); + + if (reinforced == null) + { + throw new ArgumentNullException(nameof(reinforced)); + } + + if (!_shopLogic.AddReinforced(reinforced, viewModel.Count)) + { + throw new Exception($"AddReinforced operation failed. Shop is full."); + } + } + else + { + model.DateImplement = viewModel.DateImplement; + } + + CheckModel(model, false); + if (_orderStorage.Update(model) == null) { model.Status--; _logger.LogWarning("Update operation failed"); + return false; } diff --git a/PrecastConcretePlant/PrecastConcretePlantBusinessLogic/BusinessLogic/ShopLogic.cs b/PrecastConcretePlant/PrecastConcretePlantBusinessLogic/BusinessLogic/ShopLogic.cs index 4022fa5..4e6aaa7 100644 --- a/PrecastConcretePlant/PrecastConcretePlantBusinessLogic/BusinessLogic/ShopLogic.cs +++ b/PrecastConcretePlant/PrecastConcretePlantBusinessLogic/BusinessLogic/ShopLogic.cs @@ -25,7 +25,7 @@ namespace PrecastConcretePlantBusinessLogic.BusinessLogic } public List? ReadList(ShopSearchModel? model) { - _logger.LogInformation("ReadList. ShopName:{ShopName}.Id:{ Id} ", + _logger.LogInformation("ReadList. Name:{Name}.Id:{ Id} ", model?.Name, model?.Id); var list = (model == null) ? _shopStorage.GetFullList() : _shopStorage.GetFilteredList(model); @@ -43,7 +43,7 @@ namespace PrecastConcretePlantBusinessLogic.BusinessLogic { throw new ArgumentNullException(nameof(model)); } - _logger.LogInformation("ReadElement. ShopName:{ShopName}.Id:{ Id}", + _logger.LogInformation("ReadElement. Name:{Name}.Id:{ Id}", model.Name, model.Id); var element = _shopStorage.GetElement(model); if (element == null) @@ -57,7 +57,7 @@ namespace PrecastConcretePlantBusinessLogic.BusinessLogic public bool Create(ShopBindingModel model) { CheckModel(model); - model.Reinforcedies = new(); + model.ShopReinforcedies = new(); if (_shopStorage.Insert(model) == null) { _logger.LogWarning("Insert operation failed"); @@ -65,6 +65,10 @@ namespace PrecastConcretePlantBusinessLogic.BusinessLogic } return true; } + public bool SellReinforced(IReinforcedModel reinforced, int count) + { + return _shopStorage.SellReinforced(reinforced, count); + } public bool Update(ShopBindingModel model) { CheckModel(model, false); @@ -73,6 +77,7 @@ namespace PrecastConcretePlantBusinessLogic.BusinessLogic throw new ArgumentNullException("Нет названия магазина", nameof(model.Name)); } + if (_shopStorage.Update(model) == null) { _logger.LogWarning("Update operation failed"); @@ -106,7 +111,11 @@ namespace PrecastConcretePlantBusinessLogic.BusinessLogic throw new ArgumentNullException("Нет названия магазина", nameof(model.Name)); } - _logger.LogInformation("Shop. ShopName:{0}.Address:{1}. Id: {2}", + if (model.ReinforcedMaxCount < 0) + { + throw new ArgumentException("Максимальное количество изделий в магазине не может быть меньше нуля", nameof(model.ReinforcedMaxCount)); + } + _logger.LogInformation("Shop. Name:{0}.Address:{1}. Id: {2}", model.Name, model.Address, model.Id); var element = _shopStorage.GetElement(new ShopSearchModel { @@ -124,43 +133,95 @@ namespace PrecastConcretePlantBusinessLogic.BusinessLogic { throw new ArgumentNullException(nameof(model)); } + if (count <= 0) { - throw new ArgumentException("Количество добавляемого изделия должно быть больше 0", nameof(count)); + throw new ArgumentException("Количество изделий должно быть больше 0", nameof(count)); } - _logger.LogInformation("AddReinforcedInShop. ShopName:{ShopName}.Id:{ Id}", - model.Name, model.Id); + + _logger.LogInformation("AddReinforced. Name:{Name}.Id:{ Id}", model.Name, model.Id); var element = _shopStorage.GetElement(model); + if (element == null) { - _logger.LogWarning("AddReinforcedInShop element not found"); + _logger.LogWarning("AddReinforced element not found"); return false; } - _logger.LogInformation("AddReinforcedInShop find. Id:{Id}", element.Id); - - if (element.Reinforcedies.TryGetValue(reinforced.Id, out var pair)) + if (element.ReinforcedMaxCount - element.ShopReinforcedies.Select(x => x.Value.Item2).Sum() < count) { - element.Reinforcedies[reinforced.Id] = (reinforced, count + pair.Item2); - _logger.LogInformation( - "AddReinforcedInShop. Has been added {count} {reinforced} in {ShopName}", - count, reinforced.ReinforcedName, element.Name); + throw new ArgumentNullException("Магазин переполнен", nameof(count)); + } + + _logger.LogInformation("AddReinforced find. Id:{Id}", element.Id); + + if (element.ShopReinforcedies.TryGetValue(reinforced.Id, out var pair)) + { + element.ShopReinforcedies[reinforced.Id] = (reinforced, count + pair.Item2); + _logger.LogInformation("AddReinforced. Added {count} {reinforced} to '{Name}' shop", count, reinforced.ReinforcedName, element.Name); } else { - element.Reinforcedies[reinforced.Id] = (reinforced, count); - _logger.LogInformation( - "AddReinforcedInShop. Has been added {count} new Reinforced {reinforced} in {ShopName}", - count, reinforced.ReinforcedName, element.Name); + element.ShopReinforcedies[reinforced.Id] = (reinforced, count); + _logger.LogInformation("AddReinforced. Added {count} new reinforced {reinforced} to '{Name}' shop", count, reinforced.ReinforcedName, element.Name); } + _shopStorage.Update(new() { Id = element.Id, Address = element.Address, Name = element.Name, DateOpening = element.DateOpening, - Reinforcedies = element.Reinforcedies + ReinforcedMaxCount = element.ReinforcedMaxCount, + ShopReinforcedies = element.ShopReinforcedies, }); + + return true; + } + public bool AddReinforced(IReinforcedModel reinforced, int count) + { + if (reinforced == null) + { + throw new ArgumentNullException(nameof(reinforced)); + } + + if (count <= 0) + { + throw new ArgumentException("Количество добавляемого изделия должно быть больше 0", nameof(count)); + } + + var freePlaces = _shopStorage.GetFullList() + .Select(x => x.ReinforcedMaxCount - x.ShopReinforcedies + .Select(p => p.Value.Item2).Sum()).Sum() - count; + + if (freePlaces < 0) + { + _logger.LogInformation("AddReinforced. Failed to add reinforced to shop. It's full."); + return false; + } + + foreach (var shop in _shopStorage.GetFullList()) + { + var temp = Math.Min(count, shop.ReinforcedMaxCount - shop.ShopReinforcedies.Select(x => x.Value.Item2).Sum()); + + if (temp <= 0) + { + continue; + } + + if (!AddReinforced(new() { Id = shop.Id }, reinforced, temp)) + { + _logger.LogWarning("An error occurred while adding reinforced to shops"); + return false; + } + + count -= temp; + + if (count == 0) + { + return true; + } + } return true; } } diff --git a/PrecastConcretePlant/PrecastConcretePlantContracts/BindingModels/ShopBindingModel.cs b/PrecastConcretePlant/PrecastConcretePlantContracts/BindingModels/ShopBindingModel.cs index e589473..2c89326 100644 --- a/PrecastConcretePlant/PrecastConcretePlantContracts/BindingModels/ShopBindingModel.cs +++ b/PrecastConcretePlant/PrecastConcretePlantContracts/BindingModels/ShopBindingModel.cs @@ -15,12 +15,10 @@ namespace PrecastConcretePlantContracts.BindingModels public DateTime DateOpening { get; set; } = DateTime.Now; - public Dictionary Reinforcedies - { - get; - set; - } = new(); + public Dictionary ShopReinforcedies { get; set; } = new(); + public int Id { get; set; } + public int ReinforcedMaxCount { get; set; } } } diff --git a/PrecastConcretePlant/PrecastConcretePlantContracts/BusinessLogicsContracts/IShopLogic.cs b/PrecastConcretePlant/PrecastConcretePlantContracts/BusinessLogicsContracts/IShopLogic.cs index f1a5e90..f55386f 100644 --- a/PrecastConcretePlant/PrecastConcretePlantContracts/BusinessLogicsContracts/IShopLogic.cs +++ b/PrecastConcretePlant/PrecastConcretePlantContracts/BusinessLogicsContracts/IShopLogic.cs @@ -18,5 +18,8 @@ namespace PrecastConcretePlantContracts.BusinessLogicsContracts bool Update(ShopBindingModel model); bool Delete(ShopBindingModel model); bool AddReinforced(ShopSearchModel model, IReinforcedModel reinforced, int count); + bool AddReinforced(IReinforcedModel reinforced, int quantity); + bool SellReinforced(IReinforcedModel reinforced, int quantity); + } } diff --git a/PrecastConcretePlant/PrecastConcretePlantContracts/StoragesContracts/IShopStorage.cs b/PrecastConcretePlant/PrecastConcretePlantContracts/StoragesContracts/IShopStorage.cs index e8efac3..142cb4f 100644 --- a/PrecastConcretePlant/PrecastConcretePlantContracts/StoragesContracts/IShopStorage.cs +++ b/PrecastConcretePlant/PrecastConcretePlantContracts/StoragesContracts/IShopStorage.cs @@ -1,6 +1,7 @@ using PrecastConcretePlantContracts.BindingModels; using PrecastConcretePlantContracts.SearchModels; using PrecastConcretePlantContracts.ViewModels; +using PrecastConcretePlantDataModels.Models; using System; using System.Collections.Generic; using System.Linq; @@ -17,5 +18,6 @@ namespace PrecastConcretePlantContracts.StoragesContracts ShopViewModel? Insert(ShopBindingModel model); ShopViewModel? Update(ShopBindingModel model); ShopViewModel? Delete(ShopBindingModel model); + bool SellReinforced(IReinforcedModel model, int quantity); } } diff --git a/PrecastConcretePlant/PrecastConcretePlantContracts/ViewModels/ShopViewModel.cs b/PrecastConcretePlant/PrecastConcretePlantContracts/ViewModels/ShopViewModel.cs index 9527906..1708dfc 100644 --- a/PrecastConcretePlant/PrecastConcretePlantContracts/ViewModels/ShopViewModel.cs +++ b/PrecastConcretePlant/PrecastConcretePlantContracts/ViewModels/ShopViewModel.cs @@ -17,13 +17,13 @@ namespace PrecastConcretePlantContracts.ViewModels public string Address { get; set; } = string.Empty; [DisplayName("Время открытия")] - public DateTime DateOpening { get; set; } = DateTime.Now; + public DateTime DateOpening { get; set; } + + [DisplayName("Вместимость магазина")] + public int ReinforcedMaxCount { get; set; } + + public Dictionary ShopReinforcedies { get; set; } = new(); - public Dictionary Reinforcedies - { - get; - set; - } = new(); public int Id { get; set; } } diff --git a/PrecastConcretePlant/PrecastConcretePlantDataModels/Models/IShopModel.cs b/PrecastConcretePlant/PrecastConcretePlantDataModels/Models/IShopModel.cs index d2ff837..42ac617 100644 --- a/PrecastConcretePlant/PrecastConcretePlantDataModels/Models/IShopModel.cs +++ b/PrecastConcretePlant/PrecastConcretePlantDataModels/Models/IShopModel.cs @@ -11,6 +11,7 @@ namespace PrecastConcretePlantDataModels.Models string Name { get; } string Address { get; } DateTime DateOpening { get; } - Dictionary Reinforcedies { get; } + Dictionary ShopReinforcedies { get; } + public int ReinforcedMaxCount { get; } } } diff --git a/PrecastConcretePlant/PrecastConcretePlantFileImplement/DataFileSingleton.cs b/PrecastConcretePlant/PrecastConcretePlantFileImplement/DataFileSingleton.cs new file mode 100644 index 0000000..b68cfdd --- /dev/null +++ b/PrecastConcretePlant/PrecastConcretePlantFileImplement/DataFileSingleton.cs @@ -0,0 +1,67 @@ + +using PrecastConcretePlantFileImplement.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Xml.Linq; + +namespace PrecastConcretePlantFileImplement +{ + public class DataFileSingleton + { + private static DataFileSingleton? instance; + private readonly string ComponentFileName = "Component.xml"; + private readonly string OrderFileName = "Order.xml"; + private readonly string ReinforcedFileName = "Reinforced.xml"; + private readonly string ShopFileName = "Shop.xml"; + public List Components { get; private set; } + public List Orders { get; private set; } + public List Reinforceds { get; private set; } + public List Shops { 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 SaveReinforceds() => SaveData(Reinforceds, ReinforcedFileName, + "Reinforceds", x => x.GetXElement); + public void SaveOrders() => SaveData(Orders, OrderFileName, "Orders", x + => x.GetXElement); + public void SaveShops() => SaveData(Shops, ShopFileName, "Shops", x => x.GetXElement); + private DataFileSingleton() + { + Components = LoadData(ComponentFileName, "Component", x => + Component.Create(x)!)!; + Reinforceds = LoadData(ReinforcedFileName, "Reinforced", x => + Reinforced.Create(x)!)!; + Orders = LoadData(OrderFileName, "Order", x => Order.Create(x)!)!; + Shops = LoadData(ShopFileName, "Shop", x => Shop.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/PrecastConcretePlant/PrecastConcretePlantFileImplement/Implements/ComponentStorage.cs b/PrecastConcretePlant/PrecastConcretePlantFileImplement/Implements/ComponentStorage.cs new file mode 100644 index 0000000..507b5ee --- /dev/null +++ b/PrecastConcretePlant/PrecastConcretePlantFileImplement/Implements/ComponentStorage.cs @@ -0,0 +1,77 @@ +using PrecastConcretePlantContracts.BindingModels; +using PrecastConcretePlantContracts.SearchModels; +using PrecastConcretePlantContracts.StoragesContracts; +using PrecastConcretePlantContracts.ViewModels; +using PrecastConcretePlantFileImplement.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace PrecastConcretePlantFileImplement.Implements +{ + public class ComponentStorage : IComponentStorage + { + private readonly DataFileSingleton source; + public ComponentStorage() + { + source = DataFileSingleton.GetInstance(); + } + public List GetFullList() + { + return source.Components.Select(x => x.GetViewModel).ToList(); + } + public List GetFilteredList(ComponentSearchModel model) + { + if (string.IsNullOrEmpty(model.ComponentName)) + { + return new(); + } + return source.Components.Where(x => x.ComponentName.Contains(model.ComponentName)).Select(x => x.GetViewModel).ToList(); + } + public ComponentViewModel? GetElement(ComponentSearchModel model) + { + if (string.IsNullOrEmpty(model.ComponentName) && !model.Id.HasValue) + { + return null; + } + return source.Components.FirstOrDefault(x =>(!string.IsNullOrEmpty(model.ComponentName) && x.ComponentName == model.ComponentName) ||(model.Id.HasValue && x.Id == model.Id)) ?.GetViewModel; + } + public ComponentViewModel? Insert(ComponentBindingModel model) + { + model.Id = source.Components.Count > 0 ? source.Components.Max(x => x.Id) + 1 : 1; + var newComponent = Component.Create(model); + if (newComponent == null) + { + return null; + } + source.Components.Add(newComponent); + source.SaveComponents(); + return newComponent.GetViewModel; + } + public ComponentViewModel? Update(ComponentBindingModel model) + { + var component = source.Components.FirstOrDefault(x => x.Id == model.Id); + if (component == null) + { + return null; + } + component.Update(model); + source.SaveComponents(); + return component.GetViewModel; + } + public ComponentViewModel? Delete(ComponentBindingModel model) + { + var element = source.Components.FirstOrDefault(x => x.Id == + model.Id); + if (element != null) + { + source.Components.Remove(element); + source.SaveComponents(); + return element.GetViewModel; + } + return null; + } + } +} diff --git a/PrecastConcretePlant/PrecastConcretePlantFileImplement/Implements/OrderStorage.cs b/PrecastConcretePlant/PrecastConcretePlantFileImplement/Implements/OrderStorage.cs new file mode 100644 index 0000000..e88ba0d --- /dev/null +++ b/PrecastConcretePlant/PrecastConcretePlantFileImplement/Implements/OrderStorage.cs @@ -0,0 +1,94 @@ +using PrecastConcretePlantContracts.BindingModels; +using PrecastConcretePlantContracts.SearchModels; +using PrecastConcretePlantContracts.StoragesContracts; +using PrecastConcretePlantContracts.ViewModels; +using PrecastConcretePlantFileImplement.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace PrecastConcretePlantFileImplement.Implements +{ + public class OrderStorage : IOrderStorage + { + private readonly DataFileSingleton source; + + public OrderStorage() + { + source = DataFileSingleton.GetInstance(); + } + + public OrderViewModel? Delete(OrderBindingModel model) + { + var element = source.Orders.FirstOrDefault(x => x.Id == model.Id); + + if (element != null) + { + source.Orders.Remove(element); + source.SaveOrders(); + + return element.GetViewModel; + } + + return null; + } + + public OrderViewModel? GetElement(OrderSearchModel model) + { + if (!model.Id.HasValue) + { + return null; + } + + return source.Orders.FirstOrDefault(x => (model.Id.HasValue && x.Id == model.Id))?.GetViewModel; + } + + public List GetFilteredList(OrderSearchModel model) + { + if (!model.Id.HasValue) + { + return new(); + } + + return source.Orders.Where(x => x.Id == model.Id).Select(x => x.GetViewModel).ToList(); + } + + public List GetFullList() + { + return source.Orders.Select(x => x.GetViewModel).ToList(); + } + + public OrderViewModel? Insert(OrderBindingModel model) + { + model.Id = source.Orders.Count > 0 ? source.Orders.Max(x => x.Id) + 1 : 1; + var newOrder = Order.Create(model); + + if (newOrder == null) + { + return null; + } + + source.Orders.Add(newOrder); + source.SaveOrders(); + + return newOrder.GetViewModel; + } + + public OrderViewModel? Update(OrderBindingModel model) + { + var order = source.Orders.FirstOrDefault(x => x.Id == model.Id); + + if (order == null) + { + return null; + } + + order.Update(model); + source.SaveOrders(); + + return order.GetViewModel; + } + } +} diff --git a/PrecastConcretePlant/PrecastConcretePlantFileImplement/Implements/ReinforcedStorage.cs b/PrecastConcretePlant/PrecastConcretePlantFileImplement/Implements/ReinforcedStorage.cs new file mode 100644 index 0000000..b68cfdb --- /dev/null +++ b/PrecastConcretePlant/PrecastConcretePlantFileImplement/Implements/ReinforcedStorage.cs @@ -0,0 +1,94 @@ +using PrecastConcretePlantContracts.BindingModels; +using PrecastConcretePlantContracts.SearchModels; +using PrecastConcretePlantContracts.StoragesContracts; +using PrecastConcretePlantContracts.ViewModels; +using PrecastConcretePlantFileImplement.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace PrecastConcretePlantFileImplement.Implements +{ + public class ReinforcedStorage : IReinforcedStorage + { + private readonly DataFileSingleton source; + + public ReinforcedStorage() + { + source = DataFileSingleton.GetInstance(); + } + + public ReinforcedViewModel? Delete(ReinforcedBindingModel model) + { + var element = source.Reinforceds.FirstOrDefault(x => x.Id == model.Id); + + if (element != null) + { + source.Reinforceds.Remove(element); + source.SaveReinforceds(); + + return element.GetViewModel; + } + + return null; + } + + public ReinforcedViewModel? GetElement(ReinforcedSearchModel model) + { + if (string.IsNullOrEmpty(model.ReinforcedName) && !model.Id.HasValue) + { + return null; + } + + return source.Reinforceds.FirstOrDefault(x => (!string.IsNullOrEmpty(model.ReinforcedName) && x.ReinforcedName == model.ReinforcedName) || (model.Id.HasValue && x.Id == model.Id))?.GetViewModel; + } + + public List GetFilteredList(ReinforcedSearchModel model) + { + if (string.IsNullOrEmpty(model.ReinforcedName)) + { + return new(); + } + + return source.Reinforceds.Where(x => x.ReinforcedName.Contains(model.ReinforcedName)).Select(x => x.GetViewModel).ToList(); + } + + public List GetFullList() + { + return source.Reinforceds.Select(x => x.GetViewModel).ToList(); + } + + public ReinforcedViewModel? Insert(ReinforcedBindingModel model) + { + model.Id = source.Reinforceds.Count > 0 ? source.Reinforceds.Max(x => x.Id) + 1 : 1; + var newReinforced = Reinforced.Create(model); + + if (newReinforced == null) + { + return null; + } + + source.Reinforceds.Add(newReinforced); + source.SaveReinforceds(); + + return newReinforced.GetViewModel; + } + + public ReinforcedViewModel? Update(ReinforcedBindingModel model) + { + var reinforced = source.Reinforceds.FirstOrDefault(x => x.Id == model.Id); + + if (reinforced == null) + { + return null; + } + + reinforced.Update(model); + source.SaveReinforceds(); + + return reinforced.GetViewModel; + } + } +} diff --git a/PrecastConcretePlant/PrecastConcretePlantFileImplement/Implements/ShopStorage.cs b/PrecastConcretePlant/PrecastConcretePlantFileImplement/Implements/ShopStorage.cs new file mode 100644 index 0000000..19f21ac --- /dev/null +++ b/PrecastConcretePlant/PrecastConcretePlantFileImplement/Implements/ShopStorage.cs @@ -0,0 +1,112 @@ +using PrecastConcretePlantContracts.BindingModels; +using PrecastConcretePlantContracts.SearchModels; +using PrecastConcretePlantContracts.StoragesContracts; +using PrecastConcretePlantContracts.ViewModels; +using PrecastConcretePlantDataModels.Models; +using PrecastConcretePlantFileImplement.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace PrecastConcretePlantFileImplement.Implements +{ + public class ShopStorage : IShopStorage + { + private readonly DataFileSingleton source; + + public ShopStorage() + { + source = DataFileSingleton.GetInstance(); + } + public ShopViewModel? Delete(ShopBindingModel model) + { + var element = source.Shops.FirstOrDefault(x => x.Id == model.Id); + if (element != null) + { + source.Shops.Remove(element); + source.SaveShops(); + return element.GetViewModel; + } + return null; + } + + public ShopViewModel? GetElement(ShopSearchModel model) + { + if (string.IsNullOrEmpty(model.Name) && !model.Id.HasValue) + { + return null; + } + return source.Shops.FirstOrDefault(x => + (!string.IsNullOrEmpty(model.Name) && x.Name == + model.Name) || (model.Id.HasValue && x.Id == model.Id))?.GetViewModel; + } + + public List GetFilteredList(ShopSearchModel model) + { + if (string.IsNullOrEmpty(model.Name)) + { + return new(); + } + return source.Shops.Where(x => x.Name.Contains(model.Name)).Select(x => x.GetViewModel).ToList(); + } + + public List GetFullList() + { + return source.Shops.Select(x => x.GetViewModel).ToList(); + } + + public ShopViewModel? Insert(ShopBindingModel model) + { + model.Id = source.Shops.Count > 0 ? source.Shops.Max(x => x.Id) + 1 : 1; + var newShop = Shop.Create(model); + if (newShop == null) + { + return null; + } + source.Shops.Add(newShop); + source.SaveShops(); + return newShop.GetViewModel; + } + + public bool SellReinforced(IReinforcedModel model, int quantity) + { + if (source.Shops.Select(x => x.ShopReinforcedies.FirstOrDefault(y => y.Key == model.Id).Value.Item2).Sum() < quantity) + { + return false; + } + foreach (var shop in source.Shops.Where(x => x.ShopReinforcedies.ContainsKey(model.Id))) + { + int QuantityInCurrentShop = shop.ShopReinforcedies[model.Id].Item2; + if (QuantityInCurrentShop <= quantity) + { + shop.ShopReinforcedies.Remove(model.Id); + quantity -= QuantityInCurrentShop; + } + else + { + shop.ShopReinforcedies[model.Id] = (shop.ShopReinforcedies[model.Id].Item1, QuantityInCurrentShop - quantity); + quantity = 0; + } + if (quantity == 0) + { + return true; + } + } + return false; + } + + public ShopViewModel? Update(ShopBindingModel model) + { + var shop = source.Shops.FirstOrDefault(x => x.Id == model.Id); + if (shop == null) + { + return null; + } + shop.Update(model); + source.SaveShops(); + return shop.GetViewModel; + } + } +} diff --git a/PrecastConcretePlant/PrecastConcretePlantFileImplement/Models/Component.cs b/PrecastConcretePlant/PrecastConcretePlantFileImplement/Models/Component.cs new file mode 100644 index 0000000..82f5656 --- /dev/null +++ b/PrecastConcretePlant/PrecastConcretePlantFileImplement/Models/Component.cs @@ -0,0 +1,66 @@ +using PrecastConcretePlantContracts.BindingModels; +using PrecastConcretePlantContracts.ViewModels; +using PrecastConcretePlantDataModels.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Xml.Linq; + +namespace PrecastConcretePlantFileImplement.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("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())); + } + +} diff --git a/PrecastConcretePlant/PrecastConcretePlantFileImplement/Models/Order.cs b/PrecastConcretePlant/PrecastConcretePlantFileImplement/Models/Order.cs new file mode 100644 index 0000000..4ff623a --- /dev/null +++ b/PrecastConcretePlant/PrecastConcretePlantFileImplement/Models/Order.cs @@ -0,0 +1,111 @@ +using PrecastConcretePlantContracts.BindingModels; +using PrecastConcretePlantContracts.ViewModels; +using PrecastConcretePlantDataModels.Enums; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Xml.Linq; + +namespace PrecastConcretePlantFileImplement.Models +{ + public class Order : IOrderModel + { + public int ReinforcedId { get; private set; } + + public string ReinforcedName { get; private set; } = string.Empty; + + public int Count { get; private set; } + + public double Sum { get; private set; } + + public OrderStatus Status { get; private set; } = OrderStatus.Неизвестен; + + public DateTime DateCreate { get; private set; } = DateTime.Now; + + public DateTime? DateImplement { get; private set; } + + public int Id { get; private set; } + + public static Order? Create(OrderBindingModel model) + { + if (model == null) + { + return null; + } + return new Order() + { + Id = model.Id, + ReinforcedId = model.ReinforcedId, + ReinforcedName = model.ReinforcedName, + Count = model.Count, + Sum = model.Sum, + Status = model.Status, + DateCreate = model.DateCreate, + DateImplement = model.DateImplement + }; + } + + public static Order? Create(XElement element) + { + if (element == null) + { + return null; + } + + var order = new Order() + { + Id = Convert.ToInt32(element.Attribute("Id")!.Value), + ReinforcedId = Convert.ToInt32(element.Element("ReinforcedId")!.Value), + ReinforcedName = element.Element("ReinforcedName")!.Value, + Count = Convert.ToInt32(element.Element("Count")!.Value), + Sum = Convert.ToDouble(element.Element("Sum")!.Value), + Status = (OrderStatus)Enum.Parse(typeof(OrderStatus), element.Element("Status")!.Value), + DateCreate = DateTime.ParseExact(element.Element("DateCreate")!.Value, "G", null) + }; + + DateTime.TryParse(element.Element("DateImplement")!.Value, out DateTime dateImpl); + order.DateImplement = dateImpl; + + return order; + } + + public void Update(OrderBindingModel model) + { + if (model == null) + { + return; + } + ReinforcedId = model.ReinforcedId; + ReinforcedName = model.ReinforcedName; + Count = model.Count; + Sum = model.Sum; + Status = model.Status; + DateCreate = model.DateCreate; + DateImplement = model.DateImplement; + } + + public OrderViewModel GetViewModel => new() + { + Id = Id, + ReinforcedId = ReinforcedId, + ReinforcedName = ReinforcedName, + Count = Count, + Sum = Sum, + Status = Status, + DateCreate = DateCreate, + DateImplement = DateImplement + }; + + public XElement GetXElement => new("Order", + new XAttribute("Id", Id), + new XElement("ReinforcedName", ReinforcedName), + new XElement("ReinforcedId", ReinforcedId.ToString()), + new XElement("Count", Count.ToString()), + new XElement("Sum", Sum.ToString()), + new XElement("Status", Status.ToString()), + new XElement("DateCreate", DateCreate.ToString()), + new XElement("DateImplement", DateImplement.ToString())); + } +} diff --git a/PrecastConcretePlant/PrecastConcretePlantFileImplement/Models/Reinforced.cs b/PrecastConcretePlant/PrecastConcretePlantFileImplement/Models/Reinforced.cs new file mode 100644 index 0000000..68ee806 --- /dev/null +++ b/PrecastConcretePlant/PrecastConcretePlantFileImplement/Models/Reinforced.cs @@ -0,0 +1,100 @@ +using PrecastConcretePlantContracts.BindingModels; +using PrecastConcretePlantContracts.ViewModels; +using PrecastConcretePlantDataModels.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Xml.Linq; + +namespace PrecastConcretePlantFileImplement.Models +{ + public class Reinforced : IReinforcedModel + { + public int Id { get; private set; } + public string ReinforcedName { get; private set; } = string.Empty; + public double Price { get; private set; } + public Dictionary Components { get; private set; } = new(); + private Dictionary? _reinforcedComponents = + null; + public Dictionary ReinforcedComponents + { + get + { + if (_reinforcedComponents == null) + { + var source = DataFileSingleton.GetInstance(); + _reinforcedComponents = Components.ToDictionary(x => x.Key, y => + ((source.Components.FirstOrDefault(z => z.Id == y.Key) as IComponentModel)!, + y.Value)); + } + return _reinforcedComponents; + } + } + public static Reinforced? Create(ReinforcedBindingModel model) + { + if (model == null) + { + return null; + } + return new Reinforced() + { + Id = model.Id, + ReinforcedName = model.ReinforcedName, + Price = model.Price, + Components = model.ReinforcedComponents.ToDictionary(x => x.Key, x + => x.Value.Item2) + }; + } + public static Reinforced? Create(XElement element) + { + if (element == null) + { + return null; + } + return new Reinforced() + { + Id = Convert.ToInt32(element.Attribute("Id")!.Value), + ReinforcedName = element.Element("ReinforcedName")!.Value, + Price = Convert.ToDouble(element.Element("Price")!.Value), + Components = + element.Element("ReinforcedComponents")!.Elements("ReinforcedComponent") + .ToDictionary(x => + Convert.ToInt32(x.Element("Key")?.Value), x => + Convert.ToInt32(x.Element("Value")?.Value)) + }; + } + public void Update(ReinforcedBindingModel model) + { + if (model == null) + { + return; + } + ReinforcedName = model.ReinforcedName; + Price = model.Price; + Components = model.ReinforcedComponents.ToDictionary(x => x.Key, x => + x.Value.Item2); + _reinforcedComponents = null; + } + public ReinforcedViewModel GetViewModel => new() + { + Id = Id, + ReinforcedName = ReinforcedName, + Price = Price, + ReinforcedComponents = ReinforcedComponents + }; + public XElement GetXElement => new("Reinforced", + new XAttribute("Id", Id), + new XElement("ReinforcedName", ReinforcedName), + new XElement("Price", Price.ToString()), + new XElement("ReinforcedComponents", Components.Select(x => + new XElement("ReinforcedComponent", + + new XElement("Key", x.Key), + + new XElement("Value", x.Value))) + + .ToArray())); + } +} diff --git a/PrecastConcretePlant/PrecastConcretePlantFileImplement/Models/Shop.cs b/PrecastConcretePlant/PrecastConcretePlantFileImplement/Models/Shop.cs new file mode 100644 index 0000000..d262c11 --- /dev/null +++ b/PrecastConcretePlant/PrecastConcretePlantFileImplement/Models/Shop.cs @@ -0,0 +1,107 @@ +using PrecastConcretePlantContracts.BindingModels; +using PrecastConcretePlantContracts.ViewModels; +using PrecastConcretePlantDataModels.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Xml.Linq; + +namespace PrecastConcretePlantFileImplement.Models +{ + public class Shop : IShopModel + { + public string Name { get; private set; } = string.Empty; + public string Address { get; private set; } = string.Empty; + + public DateTime DateOpening { get; private set; } + public Dictionary Reinforcedies { get; private set; } = new(); + + public Dictionary _shopReinforcedies = null; + public Dictionary ShopReinforcedies + { + get + { + if (_shopReinforcedies == null) + { + var source = DataFileSingleton.GetInstance(); + _shopReinforcedies = Reinforcedies.ToDictionary(x => x.Key, y => ((source.Reinforceds.FirstOrDefault(z => z.Id == y.Key) as IReinforcedModel)!, y.Value)); + } + return _shopReinforcedies; + } + } + + public int Id { get; private set; } + + public int ReinforcedMaxCount { get; private set; } + + public static Shop? Create(ShopBindingModel? model) + { + if (model == null) + { + return null; + } + return new Shop() + { + Id = model.Id, + Name = model.Name, + Address = model.Address, + ReinforcedMaxCount = model.ReinforcedMaxCount, + DateOpening = model.DateOpening, + Reinforcedies = model.ShopReinforcedies.ToDictionary(x => x.Key, x => x.Value.Item2) + }; + } + public static Shop? Create(XElement element) + { + if (element == null) + { + return null; + } + return new() + { + Id = Convert.ToInt32(element.Attribute("Id")!.Value), + Name = element.Element("Name")!.Value, + Address = element.Element("Address")!.Value, + DateOpening = Convert.ToDateTime(element.Element("DateOpening")!.Value), + ReinforcedMaxCount = Convert.ToInt32(element.Element("ReinforcedMaxCount")!.Value), + Reinforcedies = element.Element("ShopReinforcedies")!.Elements("Reinforced").ToDictionary( + x => Convert.ToInt32(x.Element("Key")?.Value), + x => Convert.ToInt32(x.Element("Value")?.Value)) + }; + } + public void Update(ShopBindingModel? model) + { + if (model == null) + { + return; + } + Name = model.Name; + Address = model.Address; + DateOpening = model.DateOpening; + ReinforcedMaxCount = model.ReinforcedMaxCount; + Reinforcedies = model.ShopReinforcedies.ToDictionary(x => x.Key, x => x.Value.Item2); + _shopReinforcedies = null; + } + public ShopViewModel GetViewModel => new() + { + Id = Id, + Name = Name, + Address = Address, + ShopReinforcedies = ShopReinforcedies, + DateOpening = DateOpening, + ReinforcedMaxCount = ReinforcedMaxCount, + }; + public XElement GetXElement => new("Shop", + new XAttribute("Id", Id), + new XElement("Name", Name), + new XElement("Address", Address), + new XElement("DateOpening", DateOpening), + new XElement("ReinforcedMaxCount", ReinforcedMaxCount), + new XElement("ShopReinforcedies", Reinforcedies + .Select(x => new XElement("Reinforced", + new XElement("Key", x.Key), + new XElement("Value", x.Value)) + ).ToArray())); + } +} diff --git a/PrecastConcretePlant/PrecastConcretePlantFileImplement/PrecastConcretePlantFileImplement.csproj b/PrecastConcretePlant/PrecastConcretePlantFileImplement/PrecastConcretePlantFileImplement.csproj new file mode 100644 index 0000000..d3856ff --- /dev/null +++ b/PrecastConcretePlant/PrecastConcretePlantFileImplement/PrecastConcretePlantFileImplement.csproj @@ -0,0 +1,15 @@ + + + + net6.0 + enable + enable + + + + + + + + + diff --git a/PrecastConcretePlant/PrecastConcretePlantListImplement/Implements/ShopStorage.cs b/PrecastConcretePlant/PrecastConcretePlantListImplement/Implements/ShopStorage.cs index 4922ebe..5a8cbb5 100644 --- a/PrecastConcretePlant/PrecastConcretePlantListImplement/Implements/ShopStorage.cs +++ b/PrecastConcretePlant/PrecastConcretePlantListImplement/Implements/ShopStorage.cs @@ -2,6 +2,7 @@ using PrecastConcretePlantContracts.SearchModels; using PrecastConcretePlantContracts.StoragesContracts; using PrecastConcretePlantContracts.ViewModels; +using PrecastConcretePlantDataModels.Models; using PrecastConcretePlantListImplement.Models; using System; using System.Collections.Generic; @@ -32,7 +33,10 @@ namespace PrecastConcretePlantListImplement.Implements } return null; } - + public bool SellReinforced(IReinforcedModel model, int quantity) + { + throw new NotImplementedException(); + } public ShopViewModel? GetElement(ShopSearchModel model) { if (string.IsNullOrEmpty(model.Name) && !model.Id.HasValue) diff --git a/PrecastConcretePlant/PrecastConcretePlantListImplement/Models/Shop.cs b/PrecastConcretePlant/PrecastConcretePlantListImplement/Models/Shop.cs index 07bbef3..a8895f2 100644 --- a/PrecastConcretePlant/PrecastConcretePlantListImplement/Models/Shop.cs +++ b/PrecastConcretePlant/PrecastConcretePlantListImplement/Models/Shop.cs @@ -17,11 +17,7 @@ namespace PrecastConcretePlantListImplement.Models public DateTime DateOpening { get; private set; } - public Dictionary Reinforcedies - { - get; - private set; - } = new(); + public Dictionary ShopReinforcedies { get; private set; } = new(); public int Id { get; private set; } @@ -37,7 +33,7 @@ namespace PrecastConcretePlantListImplement.Models Name = model.Name, Address = model.Address, DateOpening = model.DateOpening, - Reinforcedies = new() + ShopReinforcedies = new() }; } public void Update(ShopBindingModel? model) @@ -49,15 +45,16 @@ namespace PrecastConcretePlantListImplement.Models Name = model.Name; Address = model.Address; DateOpening = model.DateOpening; - Reinforcedies = model.Reinforcedies; + ShopReinforcedies = model.ShopReinforcedies; } public ShopViewModel GetViewModel => new() { Id = Id, Name = Name, Address = Address, - Reinforcedies = Reinforcedies, + ShopReinforcedies = ShopReinforcedies, DateOpening = DateOpening, }; + public int ReinforcedMaxCount => throw new NotImplementedException(); } }