diff --git a/Shipyard/Shipyard.sln b/Shipyard/Shipyard.sln index 0f18d50..0657455 100644 --- a/Shipyard/Shipyard.sln +++ b/Shipyard/Shipyard.sln @@ -3,7 +3,15 @@ Microsoft Visual Studio Solution File, Format Version 12.00 # Visual Studio Version 17 VisualStudioVersion = 17.3.32825.248 MinimumVisualStudioVersion = 10.0.40219.1 -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Shipyard", "Shipyard\Shipyard.csproj", "{F45046BF-E3B3-4A5B-9C52-DB7B79330503}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ShipyardView", "Shipyard\ShipyardView.csproj", "{F45046BF-E3B3-4A5B-9C52-DB7B79330503}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ShipyardDataModels", "ShipyardDataModels\ShipyardDataModels.csproj", "{3D8C0572-F38C-42EA-BD75-DA8D2BB8661E}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ShipyardContracts", "ShipyardContracts\ShipyardContracts.csproj", "{DEFEFAE4-2EF8-4BF8-A738-EB1923F1A88C}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ShipyardBusinessLogic", "ShipyardBusinessLogic\ShipyardBusinessLogic.csproj", "{99BE41D5-FC49-464C-BF3B-B3902DCD5752}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ShipyardListImplement", "ShipyardListImplement»\ShipyardListImplement.csproj", "{47C73846-F085-4EB5-A8F4-78D1379AA405}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution @@ -15,6 +23,22 @@ Global {F45046BF-E3B3-4A5B-9C52-DB7B79330503}.Debug|Any CPU.Build.0 = Debug|Any CPU {F45046BF-E3B3-4A5B-9C52-DB7B79330503}.Release|Any CPU.ActiveCfg = Release|Any CPU {F45046BF-E3B3-4A5B-9C52-DB7B79330503}.Release|Any CPU.Build.0 = Release|Any CPU + {3D8C0572-F38C-42EA-BD75-DA8D2BB8661E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {3D8C0572-F38C-42EA-BD75-DA8D2BB8661E}.Debug|Any CPU.Build.0 = Debug|Any CPU + {3D8C0572-F38C-42EA-BD75-DA8D2BB8661E}.Release|Any CPU.ActiveCfg = Release|Any CPU + {3D8C0572-F38C-42EA-BD75-DA8D2BB8661E}.Release|Any CPU.Build.0 = Release|Any CPU + {DEFEFAE4-2EF8-4BF8-A738-EB1923F1A88C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {DEFEFAE4-2EF8-4BF8-A738-EB1923F1A88C}.Debug|Any CPU.Build.0 = Debug|Any CPU + {DEFEFAE4-2EF8-4BF8-A738-EB1923F1A88C}.Release|Any CPU.ActiveCfg = Release|Any CPU + {DEFEFAE4-2EF8-4BF8-A738-EB1923F1A88C}.Release|Any CPU.Build.0 = Release|Any CPU + {99BE41D5-FC49-464C-BF3B-B3902DCD5752}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {99BE41D5-FC49-464C-BF3B-B3902DCD5752}.Debug|Any CPU.Build.0 = Debug|Any CPU + {99BE41D5-FC49-464C-BF3B-B3902DCD5752}.Release|Any CPU.ActiveCfg = Release|Any CPU + {99BE41D5-FC49-464C-BF3B-B3902DCD5752}.Release|Any CPU.Build.0 = Release|Any CPU + {47C73846-F085-4EB5-A8F4-78D1379AA405}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {47C73846-F085-4EB5-A8F4-78D1379AA405}.Debug|Any CPU.Build.0 = Debug|Any CPU + {47C73846-F085-4EB5-A8F4-78D1379AA405}.Release|Any CPU.ActiveCfg = Release|Any CPU + {47C73846-F085-4EB5-A8F4-78D1379AA405}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/Shipyard/Shipyard/Form1.Designer.cs b/Shipyard/Shipyard/Form1.Designer.cs deleted file mode 100644 index be0ea64..0000000 --- a/Shipyard/Shipyard/Form1.Designer.cs +++ /dev/null @@ -1,39 +0,0 @@ -namespace Shipyard -{ - partial class Form1 - { - /// - /// 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.components = new System.ComponentModel.Container(); - this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.ClientSize = new System.Drawing.Size(800, 450); - this.Text = "Form1"; - } - - #endregion - } -} \ No newline at end of file diff --git a/Shipyard/Shipyard/Form1.cs b/Shipyard/Shipyard/Form1.cs deleted file mode 100644 index 5b3f544..0000000 --- a/Shipyard/Shipyard/Form1.cs +++ /dev/null @@ -1,10 +0,0 @@ -namespace Shipyard -{ - public partial class Form1 : Form - { - public Form1() - { - InitializeComponent(); - } - } -} \ No newline at end of file diff --git a/Shipyard/Shipyard/FormCreateOrder.Designer.cs b/Shipyard/Shipyard/FormCreateOrder.Designer.cs new file mode 100644 index 0000000..bb5c635 --- /dev/null +++ b/Shipyard/Shipyard/FormCreateOrder.Designer.cs @@ -0,0 +1,146 @@ +namespace ShipyardView +{ + partial class FormCreateOrder + { + /// + /// 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.labelShip = new System.Windows.Forms.Label(); + this.labelCount = new System.Windows.Forms.Label(); + this.labelPrice = new System.Windows.Forms.Label(); + this.TextBoxSum = new System.Windows.Forms.TextBox(); + this.TextBoxCount = new System.Windows.Forms.TextBox(); + this.ComboBoxShips = new System.Windows.Forms.ComboBox(); + this.ButtonSave = new System.Windows.Forms.Button(); + this.ButtonCancel = new System.Windows.Forms.Button(); + this.SuspendLayout(); + // + // labelShip + // + this.labelShip.AutoSize = true; + this.labelShip.Location = new System.Drawing.Point(33, 26); + this.labelShip.Name = "labelShip"; + this.labelShip.Size = new System.Drawing.Size(68, 20); + this.labelShip.TabIndex = 0; + this.labelShip.Text = "Изделие"; + // + // labelCount + // + this.labelCount.AutoSize = true; + this.labelCount.Location = new System.Drawing.Point(33, 69); + this.labelCount.Name = "labelCount"; + this.labelCount.Size = new System.Drawing.Size(90, 20); + this.labelCount.TabIndex = 1; + this.labelCount.Text = "Количество"; + // + // labelPrice + // + this.labelPrice.AutoSize = true; + this.labelPrice.Location = new System.Drawing.Point(33, 115); + this.labelPrice.Name = "labelPrice"; + this.labelPrice.Size = new System.Drawing.Size(55, 20); + this.labelPrice.TabIndex = 2; + this.labelPrice.Text = "Сумма"; + // + // TextBoxSum + // + this.TextBoxSum.Location = new System.Drawing.Point(137, 108); + this.TextBoxSum.Name = "TextBoxSum"; + this.TextBoxSum.Size = new System.Drawing.Size(294, 27); + this.TextBoxSum.TabIndex = 3; + // + // TextBoxCount + // + this.TextBoxCount.Location = new System.Drawing.Point(137, 62); + this.TextBoxCount.Name = "TextBoxCount"; + this.TextBoxCount.Size = new System.Drawing.Size(294, 27); + this.TextBoxCount.TabIndex = 4; + this.TextBoxCount.TextChanged += new System.EventHandler(this.TextBoxCount_TextChanged); + // + // ComboBoxShips + // + this.ComboBoxShips.FormattingEnabled = true; + this.ComboBoxShips.Location = new System.Drawing.Point(137, 18); + this.ComboBoxShips.Name = "ComboBoxShips"; + this.ComboBoxShips.Size = new System.Drawing.Size(294, 28); + this.ComboBoxShips.TabIndex = 5; + this.ComboBoxShips.SelectedIndexChanged += new System.EventHandler(this.ComboBoxShips_SelectedIndexChanged); + // + // 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(249, 154); + this.ButtonSave.Name = "ButtonSave"; + this.ButtonSave.Size = new System.Drawing.Size(94, 29); + this.ButtonSave.TabIndex = 6; + this.ButtonSave.Text = "Сохранить"; + this.ButtonSave.UseVisualStyleBackColor = true; + this.ButtonSave.Click += new System.EventHandler(this.ButtonSave_Click); + // + // 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(363, 154); + this.ButtonCancel.Name = "ButtonCancel"; + this.ButtonCancel.Size = new System.Drawing.Size(94, 29); + this.ButtonCancel.TabIndex = 7; + this.ButtonCancel.Text = "Отмена"; + this.ButtonCancel.UseVisualStyleBackColor = true; + this.ButtonCancel.Click += new System.EventHandler(this.ButtonCancel_Click); + // + // FormCreateOrder + // + this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(469, 193); + this.Controls.Add(this.ButtonCancel); + this.Controls.Add(this.ButtonSave); + this.Controls.Add(this.ComboBoxShips); + this.Controls.Add(this.TextBoxCount); + this.Controls.Add(this.TextBoxSum); + this.Controls.Add(this.labelPrice); + this.Controls.Add(this.labelCount); + this.Controls.Add(this.labelShip); + this.Name = "FormCreateOrder"; + this.Text = "Создание заказа"; + this.Load += new System.EventHandler(this.FormCreateOrder_Load); + this.ResumeLayout(false); + this.PerformLayout(); + + } + + #endregion + + private Label labelShip; + private Label labelCount; + private Label labelPrice; + private TextBox TextBoxSum; + private TextBox TextBoxCount; + private ComboBox ComboBoxShips; + private Button ButtonSave; + private Button ButtonCancel; + } +} \ No newline at end of file diff --git a/Shipyard/Shipyard/FormCreateOrder.cs b/Shipyard/Shipyard/FormCreateOrder.cs new file mode 100644 index 0000000..1cb08d9 --- /dev/null +++ b/Shipyard/Shipyard/FormCreateOrder.cs @@ -0,0 +1,126 @@ +using Microsoft.Extensions.Logging; +using ShipyardContracts.BindingModels; +using ShipyardContracts.BusinessLogicsContracts; +using ShipyardContracts.SearchModels; +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 ShipyardView +{ + public partial class FormCreateOrder : Form + { + private readonly ILogger _logger; + private readonly IShipLogic _logicS; + private readonly IOrderLogic _logicO; + public FormCreateOrder(ILogger logger, IShipLogic logicS, IOrderLogic logicO) + { + InitializeComponent(); + _logger = logger; + _logicS = logicS; + _logicO = logicO; + } + + private void FormCreateOrder_Load(object sender, EventArgs e) + { + _logger.LogInformation("Загрузка изделий для заказа"); + try + { + var list = _logicS.ReadList(null); + if (list != null) + { + ComboBoxShips.DisplayMember = "ShipName"; + ComboBoxShips.ValueMember = "Id"; + ComboBoxShips.DataSource = list; + ComboBoxShips.SelectedItem = null; + } + + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка загрузки списка кораблей"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + private void CalcSum() + { + if (ComboBoxShips.SelectedValue != null && + !string.IsNullOrEmpty(TextBoxCount.Text)) + { + try + { + int id = Convert.ToInt32(ComboBoxShips.SelectedValue); + var product = _logicS.ReadElement(new ShipSearchModel + { + Id = id + }); + int count = Convert.ToInt32(TextBoxCount.Text); + TextBoxSum.Text = Math.Round(count * (product?.Price ?? 0),2).ToString(); + _logger.LogInformation("Расчет суммы заказа"); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка расчета суммы заказа"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK,MessageBoxIcon.Error); + } + } + } + + private void TextBoxCount_TextChanged(object sender, EventArgs e) + { + CalcSum(); + } + + private void ComboBoxShips_SelectedIndexChanged(object sender, EventArgs e) + { + CalcSum(); + } + private void ButtonSave_Click(object sender, EventArgs e) + { + if (string.IsNullOrEmpty(TextBoxCount.Text)) + { + MessageBox.Show("Заполните поле Количество", "Ошибка",MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + if (ComboBoxShips.SelectedValue == null) + { + MessageBox.Show("Выберите изделие", "Ошибка",MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + _logger.LogInformation("Создание заказа"); + try + { + var operationResult = _logicO.CreateOrder(new OrderBindingModel + { + ShipId = Convert.ToInt32(ComboBoxShips.SelectedValue), + Count = Convert.ToInt32(TextBoxCount.Text), + Sum = Convert.ToDouble(TextBoxSum.Text) + }); + if (!operationResult) + { + throw new Exception("Ошибка при создании заказа.Дополнительная информация в логах."); + } + MessageBox.Show("Сохранение прошло успешно", "Сообщение",MessageBoxButtons.OK, MessageBoxIcon.Information); + DialogResult = DialogResult.OK; + Close(); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка создания заказа"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK,MessageBoxIcon.Error); + } + + } + private void ButtonCancel_Click(object sender, EventArgs e) + { + DialogResult = DialogResult.Cancel; + Close(); + } + } +} diff --git a/Shipyard/Shipyard/FormCreateOrder.resx b/Shipyard/Shipyard/FormCreateOrder.resx new file mode 100644 index 0000000..f298a7b --- /dev/null +++ b/Shipyard/Shipyard/FormCreateOrder.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/Shipyard/Shipyard/FormDetail.Designer.cs b/Shipyard/Shipyard/FormDetail.Designer.cs new file mode 100644 index 0000000..05b0549 --- /dev/null +++ b/Shipyard/Shipyard/FormDetail.Designer.cs @@ -0,0 +1,121 @@ +namespace Shipyard +{ + partial class FormDetail + { + /// + /// 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.ButtonCancel = new System.Windows.Forms.Button(); + this.ButtonSave = new System.Windows.Forms.Button(); + this.textBoxName = new System.Windows.Forms.TextBox(); + this.textBoxCost = new System.Windows.Forms.TextBox(); + this.LabelName = new System.Windows.Forms.Label(); + this.LabelCost = new System.Windows.Forms.Label(); + this.SuspendLayout(); + // + // 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(308, 103); + this.ButtonCancel.Name = "ButtonCancel"; + this.ButtonCancel.Size = new System.Drawing.Size(94, 29); + this.ButtonCancel.TabIndex = 0; + this.ButtonCancel.Text = "Отмена"; + this.ButtonCancel.UseVisualStyleBackColor = true; + this.ButtonCancel.Click += new System.EventHandler(this.ButtonCancel_Click); + // + // ButtonSave + // + this.ButtonSave.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); + this.ButtonSave.Location = new System.Drawing.Point(174, 103); + this.ButtonSave.Name = "ButtonSave"; + this.ButtonSave.Size = new System.Drawing.Size(111, 29); + this.ButtonSave.TabIndex = 1; + this.ButtonSave.Text = "Сохранить"; + this.ButtonSave.UseVisualStyleBackColor = true; + this.ButtonSave.Click += new System.EventHandler(this.ButtonSave_Click); + // + // textBoxName + // + this.textBoxName.Location = new System.Drawing.Point(128, 12); + this.textBoxName.Name = "textBoxName"; + this.textBoxName.Size = new System.Drawing.Size(274, 27); + this.textBoxName.TabIndex = 2; + // + // textBoxCost + // + this.textBoxCost.Location = new System.Drawing.Point(128, 54); + this.textBoxCost.Name = "textBoxCost"; + this.textBoxCost.Size = new System.Drawing.Size(157, 27); + this.textBoxCost.TabIndex = 3; + // + // LabelName + // + this.LabelName.AutoSize = true; + this.LabelName.Location = new System.Drawing.Point(31, 15); + this.LabelName.Name = "LabelName"; + this.LabelName.Size = new System.Drawing.Size(77, 20); + this.LabelName.TabIndex = 4; + this.LabelName.Text = "Название"; + // + // LabelCost + // + this.LabelCost.AutoSize = true; + this.LabelCost.Location = new System.Drawing.Point(31, 57); + this.LabelCost.Name = "LabelCost"; + this.LabelCost.Size = new System.Drawing.Size(45, 20); + this.LabelCost.TabIndex = 5; + this.LabelCost.Text = "Цена"; + // + // FormDetail + // + this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(414, 144); + this.Controls.Add(this.LabelCost); + this.Controls.Add(this.LabelName); + this.Controls.Add(this.textBoxCost); + this.Controls.Add(this.textBoxName); + this.Controls.Add(this.ButtonSave); + this.Controls.Add(this.ButtonCancel); + this.Name = "FormDetail"; + this.Text = "Деталь"; + this.Load += new System.EventHandler(this.FormDetail_Load); + this.ResumeLayout(false); + this.PerformLayout(); + + } + + #endregion + + private Button ButtonCancel; + private Button ButtonSave; + private TextBox textBoxName; + private TextBox textBoxCost; + private Label LabelName; + private Label LabelCost; + } +} \ No newline at end of file diff --git a/Shipyard/Shipyard/FormDetail.cs b/Shipyard/Shipyard/FormDetail.cs new file mode 100644 index 0000000..13d7e9c --- /dev/null +++ b/Shipyard/Shipyard/FormDetail.cs @@ -0,0 +1,87 @@ +using Microsoft.Extensions.Logging; +using ShipyardContracts.BindingModels; +using ShipyardContracts.BusinessLogicsContracts; +using ShipyardContracts.SearchModels; + +namespace Shipyard +{ + public partial class FormDetail : Form + { + private readonly ILogger _logger; + private readonly IDetailLogic _logic; + private int? _id; + public int Id { set { _id = value; } } + public FormDetail(ILogger logger, IDetailLogic logic) + { + InitializeComponent(); + _logger = logger; + _logic = logic; + } + + private void FormDetail_Load(object sender, EventArgs e) + { + if (_id.HasValue) + { + try + { + _logger.LogInformation(" "); + var view = _logic.ReadElement(new DetailSearchModel + { + Id = _id.Value + }); + if (view != null) + { + textBoxName.Text = view.DetailName; + textBoxCost.Text = view.Cost.ToString(); + } + } + catch (Exception ex) + { + _logger.LogError(ex, " "); + MessageBox.Show(ex.Message, "", MessageBoxButtons.OK, + MessageBoxIcon.Error); + } + } + } + + private void ButtonSave_Click(object sender, EventArgs e) + { + if (string.IsNullOrEmpty(textBoxName.Text)) + { + MessageBox.Show(" ", "", + MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + _logger.LogInformation(" "); + try + { + var model = new DetailBindingModel + { + Id = _id ?? 0, + DetailName = textBoxName.Text, + Cost = Convert.ToDouble(textBoxCost.Text) + }; + var operationResult = _id.HasValue ? _logic.Update(model) : + _logic.Create(model); + if (!operationResult) + { + throw new Exception(" . ."); + } + MessageBox.Show(" ", "", MessageBoxButtons.OK, MessageBoxIcon.Information); + DialogResult = DialogResult.OK; + Close(); + } + catch (Exception ex) + { + _logger.LogError(ex, " "); + MessageBox.Show(ex.Message, "", MessageBoxButtons.OK,MessageBoxIcon.Error); + } + } + + private void ButtonCancel_Click(object sender, EventArgs e) + { + DialogResult = DialogResult.Cancel; + Close(); + } + } +} \ No newline at end of file diff --git a/Shipyard/Shipyard/FormDetail.resx b/Shipyard/Shipyard/FormDetail.resx new file mode 100644 index 0000000..f298a7b --- /dev/null +++ b/Shipyard/Shipyard/FormDetail.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/Shipyard/Shipyard/FormDetails.Designer.cs b/Shipyard/Shipyard/FormDetails.Designer.cs new file mode 100644 index 0000000..782da5d --- /dev/null +++ b/Shipyard/Shipyard/FormDetails.Designer.cs @@ -0,0 +1,120 @@ +namespace ShipyardView +{ + partial class FormDetails + { + /// + /// 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.ButtonAdd = new System.Windows.Forms.Button(); + this.ButtonUpd = new System.Windows.Forms.Button(); + this.ButtonDel = new System.Windows.Forms.Button(); + this.ButtonRef = new System.Windows.Forms.Button(); + this.dataGridView = new System.Windows.Forms.DataGridView(); + ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit(); + this.SuspendLayout(); + // + // ButtonAdd + // + this.ButtonAdd.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); + this.ButtonAdd.Location = new System.Drawing.Point(647, 30); + this.ButtonAdd.Name = "ButtonAdd"; + this.ButtonAdd.Size = new System.Drawing.Size(141, 42); + this.ButtonAdd.TabIndex = 0; + this.ButtonAdd.Text = "Добавить"; + this.ButtonAdd.UseVisualStyleBackColor = true; + this.ButtonAdd.Click += new System.EventHandler(this.ButtonAdd_Click); + // + // ButtonUpd + // + this.ButtonUpd.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); + this.ButtonUpd.Location = new System.Drawing.Point(647, 91); + this.ButtonUpd.Name = "ButtonUpd"; + this.ButtonUpd.Size = new System.Drawing.Size(141, 42); + this.ButtonUpd.TabIndex = 1; + this.ButtonUpd.Text = "Изменить"; + this.ButtonUpd.UseVisualStyleBackColor = true; + this.ButtonUpd.Click += new System.EventHandler(this.ButtonUpd_Click); + // + // ButtonDel + // + this.ButtonDel.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); + this.ButtonDel.Location = new System.Drawing.Point(647, 151); + this.ButtonDel.Name = "ButtonDel"; + this.ButtonDel.Size = new System.Drawing.Size(141, 42); + this.ButtonDel.TabIndex = 2; + this.ButtonDel.Text = "Удалить"; + this.ButtonDel.UseVisualStyleBackColor = true; + this.ButtonDel.Click += new System.EventHandler(this.ButtonDel_Click); + // + // ButtonRef + // + this.ButtonRef.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); + this.ButtonRef.Location = new System.Drawing.Point(647, 214); + this.ButtonRef.Name = "ButtonRef"; + this.ButtonRef.Size = new System.Drawing.Size(141, 42); + this.ButtonRef.TabIndex = 3; + this.ButtonRef.Text = "Обновить"; + this.ButtonRef.UseVisualStyleBackColor = true; + this.ButtonRef.Click += new System.EventHandler(this.ButtonRef_Click); + // + // dataGridView + // + this.dataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; + this.dataGridView.Dock = System.Windows.Forms.DockStyle.Left; + this.dataGridView.Location = new System.Drawing.Point(0, 0); + this.dataGridView.Name = "dataGridView"; + this.dataGridView.RowHeadersWidth = 51; + this.dataGridView.RowTemplate.Height = 29; + this.dataGridView.Size = new System.Drawing.Size(627, 450); + this.dataGridView.TabIndex = 4; + // + // FormDetails + // + this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(800, 450); + this.Controls.Add(this.dataGridView); + this.Controls.Add(this.ButtonRef); + this.Controls.Add(this.ButtonDel); + this.Controls.Add(this.ButtonUpd); + this.Controls.Add(this.ButtonAdd); + this.Name = "FormDetails"; + this.Text = "Детали"; + this.Load += new System.EventHandler(this.FormDetails_Load); + ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).EndInit(); + this.ResumeLayout(false); + + } + + #endregion + + private Button ButtonAdd; + private Button ButtonUpd; + private Button ButtonDel; + private Button ButtonRef; + private DataGridView dataGridView; + } +} \ No newline at end of file diff --git a/Shipyard/Shipyard/FormDetails.cs b/Shipyard/Shipyard/FormDetails.cs new file mode 100644 index 0000000..bd83ec3 --- /dev/null +++ b/Shipyard/Shipyard/FormDetails.cs @@ -0,0 +1,114 @@ +using Microsoft.Extensions.Logging; +using Microsoft.VisualBasic.Logging; +using Shipyard; +using ShipyardContracts.BindingModels; +using ShipyardContracts.BusinessLogicsContracts; +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 ShipyardView +{ + public partial class FormDetails : Form + { + private readonly ILogger _logger; + private readonly IDetailLogic _logic; + public FormDetails(ILogger logger, IDetailLogic logic) + { + InitializeComponent(); + _logger = logger; + _logic = logic; + } + + private void FormDetails_Load(object sender, EventArgs e) + { + LoadData(); + } + private void LoadData() + { + try + { + var list = _logic.ReadList(null); + if (list != null) + { + dataGridView.DataSource = list; + dataGridView.Columns["Id"].Visible = false; + dataGridView.Columns["DetailName"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; + } + _logger.LogInformation("Загрузка деталей"); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка загрузки деталей"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void ButtonAdd_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormDetail)); + if (service is FormDetail form) + { + if (form.ShowDialog() == DialogResult.OK) + { + LoadData(); + } + } + } + + private void ButtonUpd_Click(object sender, EventArgs e) + { + if (dataGridView.SelectedRows.Count == 1) + { + var service = Program.ServiceProvider?.GetService(typeof(FormDetail)); + if (service is FormDetail form) + { + form.Id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); + if (form.ShowDialog() == DialogResult.OK) + { + LoadData(); + } + } + } + } + + private void ButtonDel_Click(object sender, EventArgs e) + { + if (dataGridView.SelectedRows.Count == 1) + { + if (MessageBox.Show("Удалить запись?", "Вопрос", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) + { + int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); + _logger.LogInformation("Удаление детали"); + try + { + if (!_logic.Delete(new DetailBindingModel + { + Id = id + })) + { + throw new Exception("Ошибка при удалении. Дополнительная информация в логах."); + } + LoadData(); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка удаления детали"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + } + } + + private void ButtonRef_Click(object sender, EventArgs e) + { + LoadData(); + } + } +} diff --git a/Shipyard/Shipyard/Form1.resx b/Shipyard/Shipyard/FormDetails.resx similarity index 100% rename from Shipyard/Shipyard/Form1.resx rename to Shipyard/Shipyard/FormDetails.resx diff --git a/Shipyard/Shipyard/FormMain.Designer.cs b/Shipyard/Shipyard/FormMain.Designer.cs new file mode 100644 index 0000000..adae0c6 --- /dev/null +++ b/Shipyard/Shipyard/FormMain.Designer.cs @@ -0,0 +1,182 @@ +namespace ShipyardView +{ + partial class FormMain + { + /// + /// 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.ButtonCreateOrder = new System.Windows.Forms.Button(); + this.ButtonTakeOrderInWork = new System.Windows.Forms.Button(); + this.ButtonOrderReady = new System.Windows.Forms.Button(); + this.ButtonIssuedOrder = new System.Windows.Forms.Button(); + this.ButtonRef = new System.Windows.Forms.Button(); + this.menuStrip1 = new System.Windows.Forms.MenuStrip(); + 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.menuStrip1.SuspendLayout(); + ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit(); + this.SuspendLayout(); + // + // ButtonCreateOrder + // + this.ButtonCreateOrder.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); + this.ButtonCreateOrder.Location = new System.Drawing.Point(961, 59); + this.ButtonCreateOrder.Name = "ButtonCreateOrder"; + this.ButtonCreateOrder.Size = new System.Drawing.Size(187, 29); + this.ButtonCreateOrder.TabIndex = 0; + this.ButtonCreateOrder.Text = "Создать заказ"; + this.ButtonCreateOrder.UseVisualStyleBackColor = true; + this.ButtonCreateOrder.Click += new System.EventHandler(this.ButtonCreateOrder_Click); + // + // ButtonTakeOrderInWork + // + this.ButtonTakeOrderInWork.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); + this.ButtonTakeOrderInWork.Location = new System.Drawing.Point(961, 125); + this.ButtonTakeOrderInWork.Name = "ButtonTakeOrderInWork"; + this.ButtonTakeOrderInWork.Size = new System.Drawing.Size(187, 29); + this.ButtonTakeOrderInWork.TabIndex = 1; + this.ButtonTakeOrderInWork.Text = "Отдать на выполнение"; + this.ButtonTakeOrderInWork.UseVisualStyleBackColor = true; + this.ButtonTakeOrderInWork.Click += new System.EventHandler(this.ButtonTakeOrderInWork_Click); + // + // ButtonOrderReady + // + this.ButtonOrderReady.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); + this.ButtonOrderReady.Location = new System.Drawing.Point(961, 194); + this.ButtonOrderReady.Name = "ButtonOrderReady"; + this.ButtonOrderReady.Size = new System.Drawing.Size(187, 29); + this.ButtonOrderReady.TabIndex = 2; + this.ButtonOrderReady.Text = "Заказ готов"; + this.ButtonOrderReady.UseVisualStyleBackColor = true; + this.ButtonOrderReady.Click += new System.EventHandler(this.ButtonOrderReady_Click); + // + // ButtonIssuedOrder + // + this.ButtonIssuedOrder.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); + this.ButtonIssuedOrder.Location = new System.Drawing.Point(961, 256); + this.ButtonIssuedOrder.Name = "ButtonIssuedOrder"; + this.ButtonIssuedOrder.Size = new System.Drawing.Size(187, 29); + this.ButtonIssuedOrder.TabIndex = 3; + this.ButtonIssuedOrder.Text = "Заказ выдан"; + this.ButtonIssuedOrder.UseVisualStyleBackColor = true; + this.ButtonIssuedOrder.Click += new System.EventHandler(this.ButtonIssuedOrder_Click); + // + // ButtonRef + // + this.ButtonRef.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); + this.ButtonRef.Location = new System.Drawing.Point(961, 324); + this.ButtonRef.Name = "ButtonRef"; + this.ButtonRef.Size = new System.Drawing.Size(187, 29); + this.ButtonRef.TabIndex = 4; + this.ButtonRef.Text = "Обновить список"; + this.ButtonRef.UseVisualStyleBackColor = true; + this.ButtonRef.Click += new System.EventHandler(this.ButtonRef_Click); + // + // menuStrip1 + // + this.menuStrip1.ImageScalingSize = new System.Drawing.Size(20, 20); + this.menuStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] { + this.ToolStripMenuItem}); + this.menuStrip1.Location = new System.Drawing.Point(0, 0); + this.menuStrip1.Name = "menuStrip1"; + this.menuStrip1.Size = new System.Drawing.Size(1160, 28); + this.menuStrip1.TabIndex = 5; + this.menuStrip1.Text = "menuStrip1"; + // + // ToolStripMenuItem + // + this.ToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] { + this.ДеталиToolStripMenuItem, + this.КораблиToolStripMenuItem}); + this.ToolStripMenuItem.Name = "ToolStripMenuItem"; + this.ToolStripMenuItem.Size = new System.Drawing.Size(117, 24); + this.ToolStripMenuItem.Text = "Справочники"; + // + // ДеталиToolStripMenuItem + // + this.ДеталиToolStripMenuItem.Name = "ДеталиToolStripMenuItem"; + this.ДеталиToolStripMenuItem.Size = new System.Drawing.Size(153, 26); + this.ДеталиToolStripMenuItem.Text = "Детали"; + this.ДеталиToolStripMenuItem.Click += new System.EventHandler(this.ДеталиToolStripMenuItem_Click); + // + // КораблиToolStripMenuItem + // + this.КораблиToolStripMenuItem.Name = "КораблиToolStripMenuItem"; + this.КораблиToolStripMenuItem.Size = new System.Drawing.Size(153, 26); + this.КораблиToolStripMenuItem.Text = "Корабли"; + this.КораблиToolStripMenuItem.Click += new System.EventHandler(this.КораблиToolStripMenuItem_Click); + // + // dataGridView + // + this.dataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; + this.dataGridView.Dock = System.Windows.Forms.DockStyle.Left; + this.dataGridView.Location = new System.Drawing.Point(0, 28); + this.dataGridView.Name = "dataGridView"; + this.dataGridView.RowHeadersWidth = 51; + this.dataGridView.RowTemplate.Height = 29; + this.dataGridView.Size = new System.Drawing.Size(933, 446); + this.dataGridView.TabIndex = 6; + // + // FormMain + // + this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(1160, 474); + this.Controls.Add(this.dataGridView); + this.Controls.Add(this.ButtonRef); + this.Controls.Add(this.ButtonIssuedOrder); + this.Controls.Add(this.ButtonOrderReady); + this.Controls.Add(this.ButtonTakeOrderInWork); + this.Controls.Add(this.ButtonCreateOrder); + this.Controls.Add(this.menuStrip1); + this.MainMenuStrip = this.menuStrip1; + this.Name = "FormMain"; + this.Text = "Верфь"; + this.Load += new System.EventHandler(this.FormMain_Load); + this.menuStrip1.ResumeLayout(false); + this.menuStrip1.PerformLayout(); + ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).EndInit(); + this.ResumeLayout(false); + this.PerformLayout(); + + } + + #endregion + + private Button ButtonCreateOrder; + private Button ButtonTakeOrderInWork; + private Button ButtonOrderReady; + private Button ButtonIssuedOrder; + private Button ButtonRef; + private MenuStrip menuStrip1; + private ToolStripMenuItem ToolStripMenuItem; + private ToolStripMenuItem ДеталиToolStripMenuItem; + private ToolStripMenuItem КораблиToolStripMenuItem; + private DataGridView dataGridView; + } +} \ No newline at end of file diff --git a/Shipyard/Shipyard/FormMain.cs b/Shipyard/Shipyard/FormMain.cs new file mode 100644 index 0000000..e1275ca --- /dev/null +++ b/Shipyard/Shipyard/FormMain.cs @@ -0,0 +1,159 @@ +using Microsoft.Extensions.Logging; +using Shipyard; +using ShipyardContracts.BindingModels; +using ShipyardContracts.BusinessLogicsContracts; +using ShipyardDataModels.Enums; +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 ShipyardView +{ + public partial class FormMain : Form + { + private readonly ILogger _logger; + private readonly IOrderLogic _orderLogic; + public FormMain(ILogger logger, IOrderLogic orderLogic) + { + InitializeComponent(); + _logger = logger; + _orderLogic = orderLogic; + + } + + private void FormMain_Load(object sender, EventArgs e) + { + LoadData(); + } + private void LoadData() + { + _logger.LogInformation("Загрузка заказов"); + try + { + var list = _orderLogic.ReadList(null); + if (list != null) + { + dataGridView.DataSource = list; + dataGridView.Columns["ShipId"].Visible = false; + } + _logger.LogInformation("Загрузка заказов"); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка загрузки заказов"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void ДеталиToolStripMenuItem_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormDetails)); + if (service is FormDetails form) + { + form.ShowDialog(); + } + } + + private void КораблиToolStripMenuItem_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormShips)); + if (service is FormShips form) + { + form.ShowDialog(); + } + } + + private void ButtonCreateOrder_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormCreateOrder)); + if (service is FormCreateOrder form) + { + form.ShowDialog(); + LoadData(); + } + } + + private void ButtonTakeOrderInWork_Click(object sender, EventArgs e) + { + if (dataGridView.SelectedRows.Count == 1) + { + int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); + _logger.LogInformation("Заказ №{id}. Меняется статус на 'В работе'", id); + try + { + var operationResult = _orderLogic.TakeOrderInWork(new OrderBindingModel{ Id = id , Count = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Count"].Value), Sum = double.Parse(dataGridView.SelectedRows[0].Cells["Sum"].Value.ToString()), Status = Enum.Parse(dataGridView.SelectedRows[0].Cells["Status"].Value.ToString()), ShipId = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["ShipId"].Value), DateCreate = DateTime.Parse(dataGridView.SelectedRows[0].Cells["DateCreate"].Value.ToString()), }); + if (!operationResult) + { + throw new Exception("Ошибка при сохранении. Дополнительная информация в логах."); + } + LoadData(); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка передачи заказа в работу"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + } + + private void ButtonOrderReady_Click(object sender, EventArgs e) + { + if (dataGridView.SelectedRows.Count == 1) + { + int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); + _logger.LogInformation("Заказ №{id}. Меняется статус на 'Готов'",id); + try + { + var operationResult = _orderLogic.FinishOrder(new OrderBindingModel { Id = id, Count = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Count"].Value), Sum = double.Parse(dataGridView.SelectedRows[0].Cells["Sum"].Value.ToString()), Status = Enum.Parse(dataGridView.SelectedRows[0].Cells["Status"].Value.ToString()), ShipId = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["ShipId"].Value), DateCreate = DateTime.Parse(dataGridView.SelectedRows[0].Cells["DateCreate"].Value.ToString()), }); + if (!operationResult) + { + throw new Exception("Ошибка при сохранении.Дополнительная информация в логах."); + } + LoadData(); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка отметки о готовности заказа"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK,MessageBoxIcon.Error); + } + } + } + + private void ButtonIssuedOrder_Click(object sender, EventArgs e) + { + if (dataGridView.SelectedRows.Count == 1) + { + int id =Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); + _logger.LogInformation("Заказ №{id}. Меняется статус на 'Выдан'",id); + try + { + var operationResult = _orderLogic.DeliveryOrder(new OrderBindingModel { Id = id, Count = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Count"].Value), Sum = double.Parse(dataGridView.SelectedRows[0].Cells["Sum"].Value.ToString()), Status = Enum.Parse(dataGridView.SelectedRows[0].Cells["Status"].Value.ToString()), ShipId = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["ShipId"].Value), DateCreate = DateTime.Parse(dataGridView.SelectedRows[0].Cells["DateCreate"].Value.ToString()), }); + if (!operationResult) + { + throw new Exception("Ошибка при сохранении. Дополнительная информация в логах."); + } + _logger.LogInformation("Заказ №{id} выдан", id); + LoadData(); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка отметки о выдачи заказа"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + } + + private void ButtonRef_Click(object sender, EventArgs e) + { + LoadData(); + } + } +} diff --git a/Shipyard/Shipyard/FormMain.resx b/Shipyard/Shipyard/FormMain.resx new file mode 100644 index 0000000..938108a --- /dev/null +++ b/Shipyard/Shipyard/FormMain.resx @@ -0,0 +1,63 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 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 + + + 17, 17 + + \ No newline at end of file diff --git a/Shipyard/Shipyard/FormShip.Designer.cs b/Shipyard/Shipyard/FormShip.Designer.cs new file mode 100644 index 0000000..55a8510 --- /dev/null +++ b/Shipyard/Shipyard/FormShip.Designer.cs @@ -0,0 +1,236 @@ +namespace ShipyardView +{ + partial class FormShip + { + /// + /// 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.labelName = new System.Windows.Forms.Label(); + this.labelPrice = new System.Windows.Forms.Label(); + this.textBoxName = new System.Windows.Forms.TextBox(); + this.textBoxPrice = new System.Windows.Forms.TextBox(); + this.groupBoxDetails = new System.Windows.Forms.GroupBox(); + this.dataGridView = new System.Windows.Forms.DataGridView(); + this.ID = new System.Windows.Forms.DataGridViewTextBoxColumn(); + this.Detail = new System.Windows.Forms.DataGridViewTextBoxColumn(); + this.Count = new System.Windows.Forms.DataGridViewTextBoxColumn(); + this.ButtonAdd = new System.Windows.Forms.Button(); + this.ButtonUpd = new System.Windows.Forms.Button(); + this.ButtonDel = new System.Windows.Forms.Button(); + this.ButtonRef = new System.Windows.Forms.Button(); + this.ButtonSave = new System.Windows.Forms.Button(); + this.ButtonCancel = new System.Windows.Forms.Button(); + this.groupBoxDetails.SuspendLayout(); + ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit(); + this.SuspendLayout(); + // + // labelName + // + this.labelName.AutoSize = true; + this.labelName.Location = new System.Drawing.Point(12, 9); + this.labelName.Name = "labelName"; + this.labelName.Size = new System.Drawing.Size(80, 20); + this.labelName.TabIndex = 0; + this.labelName.Text = "Название:"; + // + // labelPrice + // + this.labelPrice.AutoSize = true; + this.labelPrice.Location = new System.Drawing.Point(12, 44); + this.labelPrice.Name = "labelPrice"; + this.labelPrice.Size = new System.Drawing.Size(86, 20); + this.labelPrice.TabIndex = 1; + this.labelPrice.Text = "Стоимость:"; + // + // textBoxName + // + this.textBoxName.Location = new System.Drawing.Point(103, 6); + this.textBoxName.Name = "textBoxName"; + this.textBoxName.Size = new System.Drawing.Size(268, 27); + this.textBoxName.TabIndex = 2; + // + // textBoxPrice + // + this.textBoxPrice.Location = new System.Drawing.Point(103, 39); + this.textBoxPrice.Name = "textBoxPrice"; + this.textBoxPrice.Size = new System.Drawing.Size(158, 27); + this.textBoxPrice.TabIndex = 3; + // + // groupBoxDetails + // + this.groupBoxDetails.Controls.Add(this.ButtonRef); + this.groupBoxDetails.Controls.Add(this.ButtonDel); + this.groupBoxDetails.Controls.Add(this.ButtonUpd); + this.groupBoxDetails.Controls.Add(this.ButtonAdd); + this.groupBoxDetails.Controls.Add(this.dataGridView); + this.groupBoxDetails.Location = new System.Drawing.Point(12, 72); + this.groupBoxDetails.Name = "groupBoxDetails"; + this.groupBoxDetails.Size = new System.Drawing.Size(776, 310); + this.groupBoxDetails.TabIndex = 4; + this.groupBoxDetails.TabStop = false; + this.groupBoxDetails.Text = "Детали"; + // + // dataGridView + // + this.dataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; + this.dataGridView.Columns.AddRange(new System.Windows.Forms.DataGridViewColumn[] { + this.ID, + this.Detail, + this.Count}); + this.dataGridView.Location = new System.Drawing.Point(6, 26); + this.dataGridView.Name = "dataGridView"; + this.dataGridView.RowHeadersWidth = 51; + this.dataGridView.RowTemplate.Height = 29; + this.dataGridView.Size = new System.Drawing.Size(553, 278); + this.dataGridView.TabIndex = 0; + // + // ID + // + this.ID.HeaderText = "ID"; + this.ID.MinimumWidth = 6; + this.ID.Name = "ID"; + this.ID.Visible = false; + this.ID.Width = 125; + // + // Detail + // + this.Detail.AutoSizeMode = System.Windows.Forms.DataGridViewAutoSizeColumnMode.Fill; + this.Detail.HeaderText = "Деталь"; + this.Detail.MinimumWidth = 6; + this.Detail.Name = "Detail"; + // + // Count + // + this.Count.HeaderText = "Количество"; + this.Count.MinimumWidth = 6; + this.Count.Name = "Count"; + this.Count.Width = 125; + // + // ButtonAdd + // + this.ButtonAdd.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); + this.ButtonAdd.Location = new System.Drawing.Point(615, 26); + this.ButtonAdd.Name = "ButtonAdd"; + this.ButtonAdd.Size = new System.Drawing.Size(121, 50); + this.ButtonAdd.TabIndex = 1; + this.ButtonAdd.Text = "Добавить"; + this.ButtonAdd.UseVisualStyleBackColor = true; + this.ButtonAdd.Click += new System.EventHandler(this.ButtonAdd_Click); + // + // ButtonUpd + // + this.ButtonUpd.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); + this.ButtonUpd.Location = new System.Drawing.Point(615, 92); + this.ButtonUpd.Name = "ButtonUpd"; + this.ButtonUpd.Size = new System.Drawing.Size(121, 50); + this.ButtonUpd.TabIndex = 2; + this.ButtonUpd.Text = "Изменить"; + this.ButtonUpd.UseVisualStyleBackColor = true; + this.ButtonUpd.Click += new System.EventHandler(this.ButtonUpd_Click); + // + // ButtonDel + // + this.ButtonDel.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); + this.ButtonDel.Location = new System.Drawing.Point(615, 161); + this.ButtonDel.Name = "ButtonDel"; + this.ButtonDel.Size = new System.Drawing.Size(121, 50); + this.ButtonDel.TabIndex = 3; + this.ButtonDel.Text = "Удалить"; + this.ButtonDel.UseVisualStyleBackColor = true; + this.ButtonDel.Click += new System.EventHandler(this.ButtonDel_Click); + // + // ButtonRef + // + this.ButtonRef.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); + this.ButtonRef.Location = new System.Drawing.Point(615, 233); + this.ButtonRef.Name = "ButtonRef"; + this.ButtonRef.Size = new System.Drawing.Size(121, 50); + this.ButtonRef.TabIndex = 4; + this.ButtonRef.Text = "Обновить"; + this.ButtonRef.UseVisualStyleBackColor = true; + this.ButtonRef.Click += new System.EventHandler(this.ButtonRef_Click); + // + // ButtonSave + // + this.ButtonSave.Location = new System.Drawing.Point(579, 409); + this.ButtonSave.Name = "ButtonSave"; + this.ButtonSave.Size = new System.Drawing.Size(94, 29); + this.ButtonSave.TabIndex = 5; + this.ButtonSave.Text = "Сохранить"; + this.ButtonSave.UseVisualStyleBackColor = true; + this.ButtonSave.Click += new System.EventHandler(this.ButtonSave_Click); + // + // ButtonCancel + // + this.ButtonCancel.Location = new System.Drawing.Point(694, 409); + this.ButtonCancel.Name = "ButtonCancel"; + this.ButtonCancel.Size = new System.Drawing.Size(94, 29); + this.ButtonCancel.TabIndex = 6; + this.ButtonCancel.Text = "Отмена"; + this.ButtonCancel.UseVisualStyleBackColor = true; + this.ButtonCancel.Click += new System.EventHandler(this.ButtonCancel_Click); + // + // FormShip + // + this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(800, 450); + this.Controls.Add(this.ButtonCancel); + this.Controls.Add(this.ButtonSave); + this.Controls.Add(this.groupBoxDetails); + this.Controls.Add(this.textBoxPrice); + this.Controls.Add(this.textBoxName); + this.Controls.Add(this.labelPrice); + this.Controls.Add(this.labelName); + this.Name = "FormShip"; + this.Text = "Корабль"; + this.Load += new System.EventHandler(this.FormShip_Load); + this.groupBoxDetails.ResumeLayout(false); + ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).EndInit(); + this.ResumeLayout(false); + this.PerformLayout(); + + } + + #endregion + + private Label labelName; + private Label labelPrice; + private TextBox textBoxName; + private TextBox textBoxPrice; + private GroupBox groupBoxDetails; + private DataGridView dataGridView; + private DataGridViewTextBoxColumn ID; + private DataGridViewTextBoxColumn Detail; + private DataGridViewTextBoxColumn Count; + private Button ButtonRef; + private Button ButtonDel; + private Button ButtonUpd; + private Button ButtonAdd; + private Button ButtonSave; + private Button ButtonCancel; + } +} \ No newline at end of file diff --git a/Shipyard/Shipyard/FormShip.cs b/Shipyard/Shipyard/FormShip.cs new file mode 100644 index 0000000..28bb900 --- /dev/null +++ b/Shipyard/Shipyard/FormShip.cs @@ -0,0 +1,215 @@ +using Microsoft.Extensions.Logging; +using Shipyard; +using ShipyardContracts.BindingModels; +using ShipyardContracts.BusinessLogicsContracts; +using ShipyardContracts.SearchModels; +using ShipyardDataModels.Models; +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 ShipyardView +{ + public partial class FormShip : Form + { + private readonly ILogger _logger; + private readonly IShipLogic _logic; + private int? _id; + private Dictionary _shipDetails; + public int Id { set { _id = value; } } + public FormShip(ILogger logger, IShipLogic logic) + { + InitializeComponent(); + _logger = logger; + _logic = logic; + _shipDetails = new Dictionary(); + } + + private void FormShip_Load(object sender, EventArgs e) + { + if (_id.HasValue) + { + _logger.LogInformation("Загрузка изделия"); + try + { + var view = _logic.ReadElement(new ShipSearchModel + { + Id = _id.Value + }); + if (view != null) + { + textBoxName.Text = view.ShipName; + textBoxPrice.Text = view.Price.ToString(); + _shipDetails = view.ShipDetails ?? new Dictionary(); + LoadData(); + } + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка загрузки изделия"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK,MessageBoxIcon.Error); + } + } + + } + private void LoadData() + { + _logger.LogInformation("Загрузка деталей изделия"); + try + { + if (_shipDetails != null) + { + dataGridView.Rows.Clear(); + foreach (var pc in _shipDetails) + { + dataGridView.Rows.Add(new object[] { pc.Key,pc.Value.Item1.DetailName, pc.Value.Item2 }); + } + textBoxPrice.Text = CalcPrice().ToString(); + } + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка загрузки компонент изделия"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK,MessageBoxIcon.Error); + } + } + + private void ButtonAdd_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormShipDetail)); + if (service is FormShipDetail form) + { + if (form.ShowDialog() == DialogResult.OK) + { + if (form.DetailModel == null) + { + return; + } + _logger.LogInformation("Добавление нового детали:{ DetailName} - { Count}", form.DetailModel.DetailName, form.Count); + if (_shipDetails.ContainsKey(form.Id)) + { + _shipDetails[form.Id] = (form.DetailModel,form.Count); + } + else + { + _shipDetails.Add(form.Id, (form.DetailModel,form.Count)); + } + LoadData(); + } + } + } + + private void ButtonUpd_Click(object sender, EventArgs e) + { + if (dataGridView.SelectedRows.Count == 1) + { + var service = Program.ServiceProvider?.GetService(typeof(FormShipDetail)); + if (service is FormShipDetail form) + { + int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells[0].Value); + form.Id = id; + form.Count = _shipDetails[id].Item2; + if (form.ShowDialog() == DialogResult.OK) + { + if (form.DetailModel == null) + { + return; + } + _logger.LogInformation("Изменение детали: { DetailName} - { Count}", form.DetailModel.DetailName, form.Count); + _shipDetails[form.Id] = (form.DetailModel,form.Count); + LoadData(); + } + } + } + } + + private void ButtonDel_Click(object sender, EventArgs e) + { + if (dataGridView.SelectedRows.Count == 1) + { + if (MessageBox.Show("Удалить запись?", "Вопрос", + MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) + { + try + { + _logger.LogInformation("Удаление детали:{ DetailName} - { Count}", dataGridView.SelectedRows[0].Cells[1].Value); + _shipDetails?.Remove(Convert.ToInt32(dataGridView.SelectedRows[0].Cells[0].Value)); + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "Ошибка",MessageBoxButtons.OK, MessageBoxIcon.Error); + } + LoadData(); + } + } + } + private void ButtonRef_Click(object sender, EventArgs e) + { + LoadData(); + } + + private void ButtonSave_Click(object sender, EventArgs e) + { + if (string.IsNullOrEmpty(textBoxName.Text)) + { + MessageBox.Show("Заполните название", "Ошибка",MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + if (string.IsNullOrEmpty(textBoxPrice.Text)) + { + MessageBox.Show("Заполните цену", "Ошибка", MessageBoxButtons.OK,MessageBoxIcon.Error); + return; + } + if (_shipDetails == null || _shipDetails.Count == 0) + { + MessageBox.Show("Заполните компоненты", "Ошибка",MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + _logger.LogInformation("Сохранение изделия"); + try + { + var model = new ShipBindingModel + { + Id = _id ?? 0, + ShipName = textBoxName.Text, + Price = Convert.ToDouble(textBoxPrice.Text), + ShipDetails = _shipDetails + }; + var operationResult = _id.HasValue ? _logic.Update(model) : _logic.Create(model); + if (!operationResult) + { + throw new Exception("Ошибка при сохранении. Дополнительная информация в логах."); + } + MessageBox.Show("Сохранение прошло успешно", "Сообщение",MessageBoxButtons.OK, MessageBoxIcon.Information); + DialogResult = DialogResult.OK; + Close(); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка сохранения изделия"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK,MessageBoxIcon.Error); + } + } + + private void ButtonCancel_Click(object sender, EventArgs e) + { + DialogResult = DialogResult.Cancel; + Close(); + } + private double CalcPrice() + { + double price = 0; + foreach (var elem in _shipDetails) + { + price += ((elem.Value.Item1?.Cost ?? 0) * elem.Value.Item2); + } + return Math.Round(price * 1.1, 2); + } + } +} diff --git a/Shipyard/Shipyard/FormShip.resx b/Shipyard/Shipyard/FormShip.resx new file mode 100644 index 0000000..996823f --- /dev/null +++ b/Shipyard/Shipyard/FormShip.resx @@ -0,0 +1,78 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 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 + + + True + + + True + + + True + + + True + + + True + + + True + + \ No newline at end of file diff --git a/Shipyard/Shipyard/FormShipDetail.Designer.cs b/Shipyard/Shipyard/FormShipDetail.Designer.cs new file mode 100644 index 0000000..bc5c771 --- /dev/null +++ b/Shipyard/Shipyard/FormShipDetail.Designer.cs @@ -0,0 +1,121 @@ +namespace ShipyardView +{ + partial class FormShipDetail + { + /// + /// 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.ButtonSave = new System.Windows.Forms.Button(); + this.ButtonCancel = new System.Windows.Forms.Button(); + this.labelDetail = new System.Windows.Forms.Label(); + this.labelCount = new System.Windows.Forms.Label(); + this.textBoxCount = new System.Windows.Forms.TextBox(); + this.comboBoxDetail = new System.Windows.Forms.ComboBox(); + this.SuspendLayout(); + // + // 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(161, 116); + this.ButtonSave.Name = "ButtonSave"; + this.ButtonSave.Size = new System.Drawing.Size(94, 29); + this.ButtonSave.TabIndex = 0; + this.ButtonSave.Text = "Сохранить"; + this.ButtonSave.UseVisualStyleBackColor = true; + this.ButtonSave.Click += new System.EventHandler(this.ButtonSave_Click); + // + // 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(270, 116); + this.ButtonCancel.Name = "ButtonCancel"; + this.ButtonCancel.Size = new System.Drawing.Size(94, 29); + this.ButtonCancel.TabIndex = 1; + this.ButtonCancel.Text = "Отмена"; + this.ButtonCancel.UseVisualStyleBackColor = true; + this.ButtonCancel.Click += new System.EventHandler(this.ButtonCancel_Click); + // + // labelDetail + // + this.labelDetail.AutoSize = true; + this.labelDetail.Location = new System.Drawing.Point(12, 19); + this.labelDetail.Name = "labelDetail"; + this.labelDetail.Size = new System.Drawing.Size(57, 20); + this.labelDetail.TabIndex = 2; + this.labelDetail.Text = "Деталь"; + // + // labelCount + // + this.labelCount.AutoSize = true; + this.labelCount.Location = new System.Drawing.Point(12, 56); + this.labelCount.Name = "labelCount"; + this.labelCount.Size = new System.Drawing.Size(90, 20); + this.labelCount.TabIndex = 3; + this.labelCount.Text = "Количество"; + // + // textBoxCount + // + this.textBoxCount.Location = new System.Drawing.Point(112, 53); + this.textBoxCount.Name = "textBoxCount"; + this.textBoxCount.Size = new System.Drawing.Size(252, 27); + this.textBoxCount.TabIndex = 4; + // + // comboBoxDetail + // + this.comboBoxDetail.FormattingEnabled = true; + this.comboBoxDetail.Location = new System.Drawing.Point(112, 16); + this.comboBoxDetail.Name = "comboBoxDetail"; + this.comboBoxDetail.Size = new System.Drawing.Size(252, 28); + this.comboBoxDetail.TabIndex = 5; + // + // FormShipDetail + // + this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(376, 157); + this.Controls.Add(this.comboBoxDetail); + this.Controls.Add(this.textBoxCount); + this.Controls.Add(this.labelCount); + this.Controls.Add(this.labelDetail); + this.Controls.Add(this.ButtonCancel); + this.Controls.Add(this.ButtonSave); + this.Name = "FormShipDetail"; + this.Text = "Деталь корабля"; + this.ResumeLayout(false); + this.PerformLayout(); + + } + + #endregion + + private Button ButtonSave; + private Button ButtonCancel; + private Label labelDetail; + private Label labelCount; + private TextBox textBoxCount; + private ComboBox comboBoxDetail; + } +} \ No newline at end of file diff --git a/Shipyard/Shipyard/FormShipDetail.cs b/Shipyard/Shipyard/FormShipDetail.cs new file mode 100644 index 0000000..e447384 --- /dev/null +++ b/Shipyard/Shipyard/FormShipDetail.cs @@ -0,0 +1,89 @@ +using Microsoft.VisualBasic.Logging; +using ShipyardContracts.BusinessLogicsContracts; +using ShipyardContracts.ViewModels; +using ShipyardDataModels.Models; +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 ShipyardView +{ + public partial class FormShipDetail : Form + { + private readonly List? _list; + public int Id + { + get + { + return Convert.ToInt32(comboBoxDetail.SelectedValue); + } + set + { + comboBoxDetail.SelectedValue = value; + } + } + public IDetailModel? DetailModel + { + get + { + if (_list == null) + { + return null; + } + foreach (var elem in _list) + { + if (elem.Id == Id) + { + return elem; + } + } + return null; + } + } + public int Count + { + get { return Convert.ToInt32(textBoxCount.Text); } + set { textBoxCount.Text = value.ToString(); } + } + public FormShipDetail(IDetailLogic logic) + { + InitializeComponent(); + _list = logic.ReadList(null); + if (_list != null) + { + comboBoxDetail.DisplayMember = "DetailName"; + comboBoxDetail.ValueMember = "Id"; + comboBoxDetail.DataSource = _list; + comboBoxDetail.SelectedItem = null; + } + } + + private void ButtonSave_Click(object sender, EventArgs e) + { + if (string.IsNullOrEmpty(textBoxCount.Text)) + { + MessageBox.Show("Заполните поле Количество", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + if (comboBoxDetail.SelectedValue == null) + { + MessageBox.Show("Выберите компонент", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + DialogResult = DialogResult.OK; + Close(); + } + + private void ButtonCancel_Click(object sender, EventArgs e) + { + DialogResult = DialogResult.Cancel; + Close(); + } + } +} diff --git a/Shipyard/Shipyard/FormShipDetail.resx b/Shipyard/Shipyard/FormShipDetail.resx new file mode 100644 index 0000000..f298a7b --- /dev/null +++ b/Shipyard/Shipyard/FormShipDetail.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/Shipyard/Shipyard/FormShips.Designer.cs b/Shipyard/Shipyard/FormShips.Designer.cs new file mode 100644 index 0000000..66c2969 --- /dev/null +++ b/Shipyard/Shipyard/FormShips.Designer.cs @@ -0,0 +1,120 @@ +namespace ShipyardView +{ + partial class FormShips + { + /// + /// 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.ButtonAdd = new System.Windows.Forms.Button(); + this.ButtonUpd = new System.Windows.Forms.Button(); + this.ButtonDel = new System.Windows.Forms.Button(); + this.ButtonRef = new System.Windows.Forms.Button(); + this.dataGridView = new System.Windows.Forms.DataGridView(); + ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit(); + this.SuspendLayout(); + // + // ButtonAdd + // + this.ButtonAdd.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); + this.ButtonAdd.Location = new System.Drawing.Point(647, 46); + this.ButtonAdd.Name = "ButtonAdd"; + this.ButtonAdd.Size = new System.Drawing.Size(141, 42); + this.ButtonAdd.TabIndex = 1; + this.ButtonAdd.Text = "Добавить"; + this.ButtonAdd.UseVisualStyleBackColor = true; + this.ButtonAdd.Click += new System.EventHandler(this.ButtonAdd_Click); + // + // ButtonUpd + // + this.ButtonUpd.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); + this.ButtonUpd.Location = new System.Drawing.Point(647, 123); + this.ButtonUpd.Name = "ButtonUpd"; + this.ButtonUpd.Size = new System.Drawing.Size(141, 42); + this.ButtonUpd.TabIndex = 2; + this.ButtonUpd.Text = "Изменить"; + this.ButtonUpd.UseVisualStyleBackColor = true; + this.ButtonUpd.Click += new System.EventHandler(this.ButtonUpd_Click); + // + // ButtonDel + // + this.ButtonDel.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); + this.ButtonDel.Location = new System.Drawing.Point(647, 194); + this.ButtonDel.Name = "ButtonDel"; + this.ButtonDel.Size = new System.Drawing.Size(141, 42); + this.ButtonDel.TabIndex = 3; + this.ButtonDel.Text = "Удалить"; + this.ButtonDel.UseVisualStyleBackColor = true; + this.ButtonDel.Click += new System.EventHandler(this.ButtonDel_Click); + // + // ButtonRef + // + this.ButtonRef.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); + this.ButtonRef.Location = new System.Drawing.Point(647, 270); + this.ButtonRef.Name = "ButtonRef"; + this.ButtonRef.Size = new System.Drawing.Size(141, 42); + this.ButtonRef.TabIndex = 4; + this.ButtonRef.Text = "Обновить"; + this.ButtonRef.UseVisualStyleBackColor = true; + this.ButtonRef.Click += new System.EventHandler(this.ButtonRef_Click); + // + // dataGridView + // + this.dataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; + this.dataGridView.Dock = System.Windows.Forms.DockStyle.Left; + this.dataGridView.Location = new System.Drawing.Point(0, 0); + this.dataGridView.Name = "dataGridView"; + this.dataGridView.RowHeadersWidth = 51; + this.dataGridView.RowTemplate.Height = 29; + this.dataGridView.Size = new System.Drawing.Size(627, 450); + this.dataGridView.TabIndex = 5; + // + // FormShips + // + this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(800, 450); + this.Controls.Add(this.dataGridView); + this.Controls.Add(this.ButtonRef); + this.Controls.Add(this.ButtonDel); + this.Controls.Add(this.ButtonUpd); + this.Controls.Add(this.ButtonAdd); + this.Name = "FormShips"; + this.Text = "Корабли"; + this.Load += new System.EventHandler(this.FormShips_Load); + ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).EndInit(); + this.ResumeLayout(false); + + } + + #endregion + + private Button ButtonAdd; + private Button ButtonUpd; + private Button ButtonDel; + private Button ButtonRef; + private DataGridView dataGridView; + } +} \ No newline at end of file diff --git a/Shipyard/Shipyard/FormShips.cs b/Shipyard/Shipyard/FormShips.cs new file mode 100644 index 0000000..6cdf778 --- /dev/null +++ b/Shipyard/Shipyard/FormShips.cs @@ -0,0 +1,114 @@ +using Microsoft.Extensions.Logging; +using Shipyard; +using ShipyardContracts.BindingModels; +using ShipyardContracts.BusinessLogicsContracts; +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 ShipyardView +{ + public partial class FormShips : Form + { + private readonly ILogger _logger; + private readonly IShipLogic _logic; + public FormShips(ILogger logger, IShipLogic logic) + { + InitializeComponent(); + _logger = logger; + _logic = logic; + } + + private void FormShips_Load(object sender, EventArgs e) + { + LoadData(); + } + private void LoadData() + { + try + { + var list = _logic.ReadList(null); + if (list != null) + { + dataGridView.DataSource = list; + dataGridView.Columns["Id"].Visible = false; + dataGridView.Columns["ShipName"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; + dataGridView.Columns["ShipDetails"].Visible = false; + } + _logger.LogInformation("Загрузка кораблей"); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка загрузки кораблей"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void ButtonAdd_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormShip)); + if (service is FormShip form) + { + if (form.ShowDialog() == DialogResult.OK) + { + LoadData(); + } + } + } + + private void ButtonUpd_Click(object sender, EventArgs e) + { + if (dataGridView.SelectedRows.Count == 1) + { + var service = Program.ServiceProvider?.GetService(typeof(FormShip)); + if (service is FormShip form) + { + form.Id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); + if (form.ShowDialog() == DialogResult.OK) + { + LoadData(); + } + } + } + } + + private void ButtonDel_Click(object sender, EventArgs e) + { + if (dataGridView.SelectedRows.Count == 1) + { + if (MessageBox.Show("Удалить запись?", "Вопрос", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) + { + int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); + _logger.LogInformation("Удаление кораблика"); + try + { + if (!_logic.Delete(new ShipBindingModel + { + Id = id + })) + { + throw new Exception("Ошибка при удалении. Дополнительная информация в логах."); + } + LoadData(); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка удаления кораблика"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + } + } + + private void ButtonRef_Click(object sender, EventArgs e) + { + LoadData(); + } + } +} diff --git a/Shipyard/Shipyard/FormShips.resx b/Shipyard/Shipyard/FormShips.resx new file mode 100644 index 0000000..f298a7b --- /dev/null +++ b/Shipyard/Shipyard/FormShips.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/Shipyard/Shipyard/Program.cs b/Shipyard/Shipyard/Program.cs index c75af07..79780f2 100644 --- a/Shipyard/Shipyard/Program.cs +++ b/Shipyard/Shipyard/Program.cs @@ -1,7 +1,19 @@ +using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.Logging; +using NLog.Extensions.Logging; +using ShipyardBusinessLogic.BusinessLogics; +using ShipyardContracts.BusinessLogicsContracts; +using ShipyardContracts.StoragesContracts; +using ShipyardListImplement.Implements; +using ShipyardView; +using System.Drawing; + namespace Shipyard { internal static class Program { + private static ServiceProvider? _serviceProvider; + public static ServiceProvider? ServiceProvider => _serviceProvider; /// /// The main entry point for the application. /// @@ -11,7 +23,36 @@ namespace Shipyard // To customize application configuration such as set high DPI settings or default font, // see https://aka.ms/applicationconfiguration. ApplicationConfiguration.Initialize(); - Application.Run(new Form1()); + + var services = new ServiceCollection(); + ConfigureServices(services); + _serviceProvider = services.BuildServiceProvider(); + + Application.Run(_serviceProvider.GetRequiredService()); } + + private static void ConfigureServices(ServiceCollection services) + { + services.AddLogging(option => + { + option.SetMinimumLevel(LogLevel.Information); + option.AddNLog("nlog.config"); + }); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + } + } + } \ No newline at end of file diff --git a/Shipyard/Shipyard/Shipyard.csproj b/Shipyard/Shipyard/Shipyard.csproj deleted file mode 100644 index b57c89e..0000000 --- a/Shipyard/Shipyard/Shipyard.csproj +++ /dev/null @@ -1,11 +0,0 @@ - - - - WinExe - net6.0-windows - enable - true - enable - - - \ No newline at end of file diff --git a/Shipyard/Shipyard/ShipyardView.csproj b/Shipyard/Shipyard/ShipyardView.csproj new file mode 100644 index 0000000..e92290a --- /dev/null +++ b/Shipyard/Shipyard/ShipyardView.csproj @@ -0,0 +1,22 @@ + + + + WinExe + net6.0-windows + enable + true + enable + + + + + + + + + + + + + + \ No newline at end of file diff --git a/Shipyard/ShipyardBusinessLogic/BusinessLogics/DetailLogic.cs b/Shipyard/ShipyardBusinessLogic/BusinessLogics/DetailLogic.cs new file mode 100644 index 0000000..9f29390 --- /dev/null +++ b/Shipyard/ShipyardBusinessLogic/BusinessLogics/DetailLogic.cs @@ -0,0 +1,113 @@ +using ShipyardContracts.BusinessLogicsContracts; +using ShipyardContracts.StoragesContracts; +using ShipyardContracts.ViewModels; +using ShipyardContracts.SearchModels; +using ShipyardContracts.BindingModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Microsoft.Extensions.Logging; + +namespace ShipyardBusinessLogic.BusinessLogics +{ + public class DetailLogic:IDetailLogic + { + private readonly ILogger _logger; + private readonly IDetailStorage _detailStorage; + public DetailLogic(ILogger logger, IDetailStorage detailStorage) + { + _logger = logger; + _detailStorage = detailStorage; + } + public List? ReadList(DetailSearchModel? model) + { + _logger.LogInformation("ReadList. DetailName:{DetailName}. Id:{Id}", model?.DetailName, model?.Id); + var list = model == null ? _detailStorage.GetFullList() : _detailStorage.GetFilteredList(model); + if (list == null) + { + _logger.LogWarning("ReadList return null list"); + return null; + } + _logger.LogInformation("ReadList. Count:{Count}", list.Count); + return list; + } + public DetailViewModel? ReadElement(DetailSearchModel model) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + _logger.LogInformation("ReadElement. DetailName:{DetailName}. Id:{ Id}", model.DetailName, model.Id); + var element = _detailStorage.GetElement(model); + if (element == null) + { + _logger.LogWarning("ReadElement element not found"); + return null; + } + _logger.LogInformation("ReadElement find. Id:{Id}", element.Id); + return element; + } + public bool Create(DetailBindingModel model) + { + CheckModel(model); + if (_detailStorage.Insert(model) == null) + { + _logger.LogWarning("Insert operation failed"); + return false; + } + return true; + } + public bool Update(DetailBindingModel model) + { + CheckModel(model); + if (_detailStorage.Update(model) == null) + { + _logger.LogWarning("Update operation failed"); + return false; + } + return true; + } + public bool Delete(DetailBindingModel model) + { + CheckModel(model, false); + _logger.LogInformation("Delete. Id:{Id}", model.Id); + if (_detailStorage.Delete(model) == null) + { + _logger.LogWarning("Delete operation failed"); + return false; + } + return true; + } + private void CheckModel(DetailBindingModel model, bool withParams = true) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + if (!withParams) + { + return; + } + if (string.IsNullOrEmpty(model.DetailName)) + { + throw new ArgumentNullException("Нет названия компонента", + nameof(model.DetailName)); + } + if (model.Cost <= 0) + { + throw new ArgumentNullException("Цена компонента должна быть больше 0", nameof(model.Cost)); + } + _logger.LogInformation("Detail. DetailName:{DetailName}. Cost:{ Cost}. Id: { Id}", model.DetailName, model.Cost, model.Id); + var element = _detailStorage.GetElement(new DetailSearchModel + { + DetailName = model.DetailName + }); + if (element != null && element.Id != model.Id) + { + throw new InvalidOperationException("Компонент с таким названием уже есть"); + } + } + } +} diff --git a/Shipyard/ShipyardBusinessLogic/BusinessLogics/OrderLogic.cs b/Shipyard/ShipyardBusinessLogic/BusinessLogics/OrderLogic.cs new file mode 100644 index 0000000..189f0a3 --- /dev/null +++ b/Shipyard/ShipyardBusinessLogic/BusinessLogics/OrderLogic.cs @@ -0,0 +1,111 @@ +using Microsoft.Extensions.Logging; +using ShipyardContracts.BindingModels; +using ShipyardContracts.BusinessLogicsContracts; +using ShipyardContracts.SearchModels; +using ShipyardContracts.StoragesContracts; +using ShipyardContracts.ViewModels; +using ShipyardDataModels.Enums; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ShipyardBusinessLogic.BusinessLogics +{ + public class OrderLogic:IOrderLogic + { + private readonly ILogger _logger; + private readonly IOrderStorage _orderStorage; + public OrderLogic(ILogger logger, IOrderStorage orderStorage) + { + _logger = logger; + _orderStorage = orderStorage; + } + public List? ReadList(OrderSearchModel? model) + { + _logger.LogInformation("ReadList. Id:{Id}",model?.Id); + var list = model == null ? _orderStorage.GetFullList() : _orderStorage.GetFilteredList(model); + if (list == null) + { + _logger.LogWarning("ReadList return null list"); + return null; + } + _logger.LogInformation("ReadList. Count:{Count}", list.Count); + return list; + } + public bool CreateOrder(OrderBindingModel model) + { + CheckModel(model); + if (model.Status != OrderStatus.Неизвестен) + { + _logger.LogWarning("Insert operation failed. Order status incorrect."); + return false; + } + model.Status = OrderStatus.Принят; + if (_orderStorage.Insert(model) == null) + { + _logger.LogWarning("Insert operation failed"); + return false; + } + return true; + } + private void CheckModel(OrderBindingModel model, bool withParams = true) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + if (!withParams) + { + return; + } + if (model.ShipId < 0) + { + throw new ArgumentNullException("Некорректный идентификатор у корабля", nameof(model.ShipId)); + } + if (model.Count <= 0) + { + throw new ArgumentNullException("Количество изделий в заказе должно быть больше 0", nameof(model.Count)); + } + if (model.Sum <= 0) + { + throw new ArgumentNullException("Сумма заказа должна быть больше 0", nameof(model.Sum)); + } + _logger.LogInformation("Order. OrderID:{Id}. Sum:{ Sum}. ShipId: { ShipId}", model.Id, model.Sum, model.ShipId); + } + public bool StatusUpdate(OrderBindingModel model, OrderStatus newStatus) + { + CheckModel(model); + if (model.Status + 1 != newStatus) + { + _logger.LogWarning("Status update to " + newStatus.ToString() + " operation failed. Order status incorrect."); + return false; + } + model.Status = newStatus; + if (model.Status == OrderStatus.Выдан) model.DateImplement = DateTime.Now; + if (_orderStorage.Update(model) == null) + { + model.Status--; + _logger.LogWarning("Update operation failed"); + return false; + } + return true; + } + + public bool TakeOrderInWork(OrderBindingModel model) + { + return StatusUpdate(model, OrderStatus.Выполняется); + } + + public bool DeliveryOrder(OrderBindingModel model) + { + return StatusUpdate(model, OrderStatus.Выдан); + } + + public bool FinishOrder(OrderBindingModel model) + { + return StatusUpdate(model, OrderStatus.Готов); + } + } +} diff --git a/Shipyard/ShipyardBusinessLogic/BusinessLogics/ShipLogic.cs b/Shipyard/ShipyardBusinessLogic/BusinessLogics/ShipLogic.cs new file mode 100644 index 0000000..8409dcd --- /dev/null +++ b/Shipyard/ShipyardBusinessLogic/BusinessLogics/ShipLogic.cs @@ -0,0 +1,113 @@ +using Microsoft.Extensions.Logging; +using ShipyardContracts.BindingModels; +using ShipyardContracts.BusinessLogicsContracts; +using ShipyardContracts.SearchModels; +using ShipyardContracts.StoragesContracts; +using ShipyardContracts.ViewModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ShipyardBusinessLogic.BusinessLogics +{ + public class ShipLogic:IShipLogic + { + private readonly ILogger _logger; + private readonly IShipStorage _shipStorage; + public ShipLogic(ILogger logger, IShipStorage shipStorage) + { + _logger = logger; + _shipStorage = shipStorage; + } + public List? ReadList(ShipSearchModel? model) + { + _logger.LogInformation("ReadList. ShipName:{ShipName}. Id:{Id}", model?.ShipName, model?.Id); + var list = model == null ? _shipStorage.GetFullList() : _shipStorage.GetFilteredList(model); + if (list == null) + { + _logger.LogWarning("ReadList return null list"); + return null; + } + _logger.LogInformation("ReadList. Count:{Count}", list.Count); + return list; + } + public ShipViewModel? ReadElement(ShipSearchModel model) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + _logger.LogInformation("ReadElement. ShipName:{ShipName}. Id:{ Id}", model.ShipName, model.Id); + var element = _shipStorage.GetElement(model); + if (element == null) + { + _logger.LogWarning("ReadElement element not found"); + return null; + } + _logger.LogInformation("ReadElement find. Id:{Id}", element.Id); + return element; + } + public bool Create(ShipBindingModel model) + { + CheckModel(model); + if (_shipStorage.Insert(model) == null) + { + _logger.LogWarning("Insert operation failed"); + return false; + } + return true; + } + public bool Update(ShipBindingModel model) + { + CheckModel(model); + if (_shipStorage.Update(model) == null) + { + _logger.LogWarning("Update operation failed"); + return false; + } + return true; + } + public bool Delete(ShipBindingModel model) + { + CheckModel(model, false); + _logger.LogInformation("Delete. Id:{Id}", model.Id); + if (_shipStorage.Delete(model) == null) + { + _logger.LogWarning("Delete operation failed"); + return false; + } + return true; + } + private void CheckModel(ShipBindingModel model, bool withParams = true) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + if (!withParams) + { + return; + } + if (string.IsNullOrEmpty(model.ShipName)) + { + throw new ArgumentNullException("Нет названия компонента", + nameof(model.ShipName)); + } + if (model.Price <= 0) + { + throw new ArgumentNullException("Цена компонента должна быть больше 0", nameof(model.Price)); + } + _logger.LogInformation("Ship. ShipName:{ShipName}. Price:{Price}. Id: {Id}", model.ShipName, model.Price, model.Id); + var element = _shipStorage.GetElement(new ShipSearchModel + { + ShipName = model.ShipName + }); + if (element != null && element.Id != model.Id) + { + throw new InvalidOperationException("Компонент с таким названием уже есть"); + } + } + } +} diff --git a/Shipyard/ShipyardBusinessLogic/ShipyardBusinessLogic.csproj b/Shipyard/ShipyardBusinessLogic/ShipyardBusinessLogic.csproj new file mode 100644 index 0000000..e6df0f8 --- /dev/null +++ b/Shipyard/ShipyardBusinessLogic/ShipyardBusinessLogic.csproj @@ -0,0 +1,19 @@ + + + + net6.0 + enable + enable + + + + + + + + + + + + + diff --git a/Shipyard/ShipyardContracts/BindingModels/DetailBindingModel.cs b/Shipyard/ShipyardContracts/BindingModels/DetailBindingModel.cs new file mode 100644 index 0000000..73ef18e --- /dev/null +++ b/Shipyard/ShipyardContracts/BindingModels/DetailBindingModel.cs @@ -0,0 +1,16 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using ShipyardDataModels.Models; + +namespace ShipyardContracts.BindingModels +{ + public class DetailBindingModel : IDetailModel + { + public int Id { get; set; } + public string DetailName { get; set; } = string.Empty; + public double Cost { get; set; } + } +} diff --git a/Shipyard/ShipyardContracts/BindingModels/OrderBindingModel.cs b/Shipyard/ShipyardContracts/BindingModels/OrderBindingModel.cs new file mode 100644 index 0000000..b46f18b --- /dev/null +++ b/Shipyard/ShipyardContracts/BindingModels/OrderBindingModel.cs @@ -0,0 +1,21 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using ShipyardDataModels.Models; +using ShipyardDataModels.Enums; + +namespace ShipyardContracts.BindingModels +{ + public class OrderBindingModel : IOrderModel + { + public int Id { get; set; } + public int ShipId { get; set; } + public int Count { get; set; } + public double Sum { get; set; } + public OrderStatus Status { get; set; } = OrderStatus.Неизвестен; + public DateTime DateCreate { get; set; } = DateTime.Now; + public DateTime? DateImplement { get; set; } + } +} diff --git a/Shipyard/ShipyardContracts/BindingModels/ShipBindingModel.cs b/Shipyard/ShipyardContracts/BindingModels/ShipBindingModel.cs new file mode 100644 index 0000000..be0b03e --- /dev/null +++ b/Shipyard/ShipyardContracts/BindingModels/ShipBindingModel.cs @@ -0,0 +1,18 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using ShipyardDataModels.Models; + +namespace ShipyardContracts.BindingModels +{ + public class ShipBindingModel : IShipModel + { + public int Id { get; set; } + public string ShipName { get; set; } = String.Empty; + public double Price { get; set; } + public Dictionary ShipDetails { get; set; } = new(); + + } +} diff --git a/Shipyard/ShipyardContracts/BusinessLogicsContracts/IDetailLogic.cs b/Shipyard/ShipyardContracts/BusinessLogicsContracts/IDetailLogic.cs new file mode 100644 index 0000000..d382f13 --- /dev/null +++ b/Shipyard/ShipyardContracts/BusinessLogicsContracts/IDetailLogic.cs @@ -0,0 +1,20 @@ +using ShipyardContracts.BindingModels; +using ShipyardContracts.SearchModels; +using ShipyardContracts.ViewModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ShipyardContracts.BusinessLogicsContracts +{ + public interface IDetailLogic + { + List? ReadList(DetailSearchModel? model); + DetailViewModel? ReadElement(DetailSearchModel model); + bool Create(DetailBindingModel model); + bool Update(DetailBindingModel model); + bool Delete(DetailBindingModel model); + } +} diff --git a/Shipyard/ShipyardContracts/BusinessLogicsContracts/IOrderLogic.cs b/Shipyard/ShipyardContracts/BusinessLogicsContracts/IOrderLogic.cs new file mode 100644 index 0000000..584b926 --- /dev/null +++ b/Shipyard/ShipyardContracts/BusinessLogicsContracts/IOrderLogic.cs @@ -0,0 +1,20 @@ +using ShipyardContracts.BindingModels; +using ShipyardContracts.SearchModels; +using ShipyardContracts.ViewModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ShipyardContracts.BusinessLogicsContracts +{ + public interface IOrderLogic + { + List? ReadList(OrderSearchModel? model); + bool CreateOrder(OrderBindingModel model); + bool TakeOrderInWork(OrderBindingModel model); + bool FinishOrder(OrderBindingModel model); + bool DeliveryOrder(OrderBindingModel model); + } +} diff --git a/Shipyard/ShipyardContracts/BusinessLogicsContracts/IShipLogic.cs b/Shipyard/ShipyardContracts/BusinessLogicsContracts/IShipLogic.cs new file mode 100644 index 0000000..5edc2a2 --- /dev/null +++ b/Shipyard/ShipyardContracts/BusinessLogicsContracts/IShipLogic.cs @@ -0,0 +1,20 @@ +using ShipyardContracts.BindingModels; +using ShipyardContracts.SearchModels; +using ShipyardContracts.ViewModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ShipyardContracts.BusinessLogicsContracts +{ + public interface IShipLogic + { + List? ReadList(ShipSearchModel? model); + ShipViewModel? ReadElement(ShipSearchModel model); + bool Create(ShipBindingModel model); + bool Update(ShipBindingModel model); + bool Delete(ShipBindingModel model); + } +} diff --git a/Shipyard/ShipyardContracts/SearchModels/DetailSearchModel.cs b/Shipyard/ShipyardContracts/SearchModels/DetailSearchModel.cs new file mode 100644 index 0000000..d307d8c --- /dev/null +++ b/Shipyard/ShipyardContracts/SearchModels/DetailSearchModel.cs @@ -0,0 +1,14 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ShipyardContracts.SearchModels +{ + public class DetailSearchModel + { + public int? Id { get; set; } + public string? DetailName { get; set; } + } +} diff --git a/Shipyard/ShipyardContracts/SearchModels/OrderSearchModel.cs b/Shipyard/ShipyardContracts/SearchModels/OrderSearchModel.cs new file mode 100644 index 0000000..f2480a0 --- /dev/null +++ b/Shipyard/ShipyardContracts/SearchModels/OrderSearchModel.cs @@ -0,0 +1,13 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ShipyardContracts.SearchModels +{ + public class OrderSearchModel + { + public int? Id { get; set; } + } +} diff --git a/Shipyard/ShipyardContracts/SearchModels/ShipSearchModel.cs b/Shipyard/ShipyardContracts/SearchModels/ShipSearchModel.cs new file mode 100644 index 0000000..73cb0fc --- /dev/null +++ b/Shipyard/ShipyardContracts/SearchModels/ShipSearchModel.cs @@ -0,0 +1,14 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ShipyardContracts.SearchModels +{ + public class ShipSearchModel + { + public int? Id { get; set; } + public string? ShipName { get; set; } + } +} diff --git a/Shipyard/ShipyardContracts/ShipyardContracts.csproj b/Shipyard/ShipyardContracts/ShipyardContracts.csproj new file mode 100644 index 0000000..a70e98d --- /dev/null +++ b/Shipyard/ShipyardContracts/ShipyardContracts.csproj @@ -0,0 +1,19 @@ + + + + net6.0 + enable + enable + + + + + + + + + + + + + diff --git a/Shipyard/ShipyardContracts/StoragesContracts/IDetailStorage.cs b/Shipyard/ShipyardContracts/StoragesContracts/IDetailStorage.cs new file mode 100644 index 0000000..44afe39 --- /dev/null +++ b/Shipyard/ShipyardContracts/StoragesContracts/IDetailStorage.cs @@ -0,0 +1,22 @@ +using ShipyardContracts.BindingModels; +using ShipyardContracts.SearchModels; +using ShipyardContracts.ViewModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ShipyardContracts.StoragesContracts +{ + public interface IDetailStorage + { + List GetFullList(); + List GetFilteredList(DetailSearchModel model); + DetailViewModel? GetElement(DetailSearchModel model); + DetailViewModel? Insert(DetailBindingModel model); + DetailViewModel? Update(DetailBindingModel model); + DetailViewModel? Delete(DetailBindingModel model); + + } +} diff --git a/Shipyard/ShipyardContracts/StoragesContracts/IOrderStorage.cs b/Shipyard/ShipyardContracts/StoragesContracts/IOrderStorage.cs new file mode 100644 index 0000000..19e2146 --- /dev/null +++ b/Shipyard/ShipyardContracts/StoragesContracts/IOrderStorage.cs @@ -0,0 +1,21 @@ +using ShipyardContracts.BindingModels; +using ShipyardContracts.SearchModels; +using ShipyardContracts.ViewModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ShipyardContracts.StoragesContracts +{ + public interface IOrderStorage + { + List GetFullList(); + List GetFilteredList(OrderSearchModel model); + OrderViewModel? GetElement(OrderSearchModel model); + OrderViewModel? Insert(OrderBindingModel model); + OrderViewModel? Update(OrderBindingModel model); + OrderViewModel? Delete(OrderBindingModel model); + } +} diff --git a/Shipyard/ShipyardContracts/StoragesContracts/IShipStorage.cs b/Shipyard/ShipyardContracts/StoragesContracts/IShipStorage.cs new file mode 100644 index 0000000..1b74ccf --- /dev/null +++ b/Shipyard/ShipyardContracts/StoragesContracts/IShipStorage.cs @@ -0,0 +1,21 @@ +using ShipyardContracts.BindingModels; +using ShipyardContracts.SearchModels; +using ShipyardContracts.ViewModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ShipyardContracts.StoragesContracts +{ + public interface IShipStorage + { + List GetFullList(); + List GetFilteredList(ShipSearchModel model); + ShipViewModel? GetElement(ShipSearchModel model); + ShipViewModel? Insert(ShipBindingModel model); + ShipViewModel? Update(ShipBindingModel model); + ShipViewModel? Delete(ShipBindingModel model); + } +} diff --git a/Shipyard/ShipyardContracts/ViewModels/DetailViewModel.cs b/Shipyard/ShipyardContracts/ViewModels/DetailViewModel.cs new file mode 100644 index 0000000..f3ed480 --- /dev/null +++ b/Shipyard/ShipyardContracts/ViewModels/DetailViewModel.cs @@ -0,0 +1,21 @@ +using ShipyardDataModels.Models; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Linq; +using System.Runtime.CompilerServices; +using System.Text; +using System.Threading.Tasks; + +namespace ShipyardContracts.ViewModels +{ + public class DetailViewModel:IDetailModel + { + public int Id { get; set; } + [DisplayName("Название компонента")] + public string DetailName { get; set; } = string.Empty; + [DisplayName("Цена")] + public double Cost { get; set; } + + } +} diff --git a/Shipyard/ShipyardContracts/ViewModels/OrderViewModel.cs b/Shipyard/ShipyardContracts/ViewModels/OrderViewModel.cs new file mode 100644 index 0000000..d7e4250 --- /dev/null +++ b/Shipyard/ShipyardContracts/ViewModels/OrderViewModel.cs @@ -0,0 +1,30 @@ +using ShipyardDataModels.Enums; +using ShipyardDataModels.Models; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ShipyardContracts.ViewModels +{ + public class OrderViewModel:IOrderModel + { + [DisplayName("Номер")] + public int Id { get; set; } + public int ShipId { get; set; } + [DisplayName("Изделие")] + public string ShipName { get; set; } = string.Empty; + [DisplayName("Количество")] + public int Count { get; set; } + [DisplayName("Сумма")] + public double Sum { get; set; } + [DisplayName("Статус")] + public OrderStatus Status { get; set; } = OrderStatus.Неизвестен; + [DisplayName("Дата создания")] + public DateTime DateCreate { get; set; } = DateTime.Now; + [DisplayName("Дата выполнения")] + public DateTime? DateImplement { get; set; } + } +} diff --git a/Shipyard/ShipyardContracts/ViewModels/ShipViewModel.cs b/Shipyard/ShipyardContracts/ViewModels/ShipViewModel.cs new file mode 100644 index 0000000..0159d11 --- /dev/null +++ b/Shipyard/ShipyardContracts/ViewModels/ShipViewModel.cs @@ -0,0 +1,20 @@ +using ShipyardDataModels.Models; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ShipyardContracts.ViewModels +{ + public class ShipViewModel:IShipModel + { + public int Id { get; set; } + [DisplayName("Название изделия")] + public string ShipName { get; set; } = string.Empty; + [DisplayName("Цена")] + public double Price { get; set; } + public Dictionary ShipDetails { get; set; } = new(); + } +} diff --git a/Shipyard/ShipyardDataModels/Enums/OrderStatus.cs b/Shipyard/ShipyardDataModels/Enums/OrderStatus.cs new file mode 100644 index 0000000..63fadf9 --- /dev/null +++ b/Shipyard/ShipyardDataModels/Enums/OrderStatus.cs @@ -0,0 +1,17 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ShipyardDataModels.Enums +{ + public enum OrderStatus + { + Неизвестен = -1, + Принят = 0, + Выполняется = 1, + Готов = 2, + Выдан = 3 + } +} diff --git a/Shipyard/ShipyardDataModels/IId.cs b/Shipyard/ShipyardDataModels/IId.cs new file mode 100644 index 0000000..4927c2f --- /dev/null +++ b/Shipyard/ShipyardDataModels/IId.cs @@ -0,0 +1,7 @@ +namespace ShipyardDataModels +{ + public interface IId + { + int Id { get; } + } +} \ No newline at end of file diff --git a/Shipyard/ShipyardDataModels/Models/IDetailModel.cs b/Shipyard/ShipyardDataModels/Models/IDetailModel.cs new file mode 100644 index 0000000..dc8b27d --- /dev/null +++ b/Shipyard/ShipyardDataModels/Models/IDetailModel.cs @@ -0,0 +1,14 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ShipyardDataModels.Models +{ + public interface IDetailModel : IId + { + string DetailName { get; } + double Cost { get; } + } +} diff --git a/Shipyard/ShipyardDataModels/Models/IOrderModel.cs b/Shipyard/ShipyardDataModels/Models/IOrderModel.cs new file mode 100644 index 0000000..e85ed40 --- /dev/null +++ b/Shipyard/ShipyardDataModels/Models/IOrderModel.cs @@ -0,0 +1,19 @@ +using ShipyardDataModels.Enums; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ShipyardDataModels.Models +{ + public interface IOrderModel : IId + { + int ShipId { get; } + int Count { get; } + double Sum { get; } + OrderStatus Status { get; } + DateTime DateCreate { get; } + DateTime? DateImplement { get; } + } +} diff --git a/Shipyard/ShipyardDataModels/Models/IShipModel.cs b/Shipyard/ShipyardDataModels/Models/IShipModel.cs new file mode 100644 index 0000000..b7b8022 --- /dev/null +++ b/Shipyard/ShipyardDataModels/Models/IShipModel.cs @@ -0,0 +1,15 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ShipyardDataModels.Models +{ + public interface IShipModel : IId + { + string ShipName { get;} + double Price { get;} + Dictionary ShipDetails { get; } + } +} diff --git a/Shipyard/ShipyardDataModels/ShipyardDataModels.csproj b/Shipyard/ShipyardDataModels/ShipyardDataModels.csproj new file mode 100644 index 0000000..daf9ebc --- /dev/null +++ b/Shipyard/ShipyardDataModels/ShipyardDataModels.csproj @@ -0,0 +1,15 @@ + + + + net6.0 + enable + enable + + + + + + + + + diff --git a/Shipyard/ShipyardListImplement»/DataListSingleton.cs b/Shipyard/ShipyardListImplement»/DataListSingleton.cs new file mode 100644 index 0000000..fd368be --- /dev/null +++ b/Shipyard/ShipyardListImplement»/DataListSingleton.cs @@ -0,0 +1,26 @@ +using ShipyardListImplement.Models; + +namespace ShipyardListImplement +{ + public class DataListSingleton + { + private static DataListSingleton? _instance; + public List Details { get; set; } + public List Orders { get; set; } + public List Ships { get; set; } + private DataListSingleton() + { + Details = new List(); + Orders = new List(); + Ships = new List(); + } + public static DataListSingleton GetInstance() + { + if (_instance == null) + { + _instance = new DataListSingleton(); + } + return _instance; + } + } +} \ No newline at end of file diff --git a/Shipyard/ShipyardListImplement»/Implements/DetailStorage.cs b/Shipyard/ShipyardListImplement»/Implements/DetailStorage.cs new file mode 100644 index 0000000..e36a321 --- /dev/null +++ b/Shipyard/ShipyardListImplement»/Implements/DetailStorage.cs @@ -0,0 +1,109 @@ +using ShipyardContracts.BindingModels; +using ShipyardContracts.SearchModels; +using ShipyardContracts.StoragesContracts; +using ShipyardContracts.ViewModels; +using ShipyardListImplement.Models; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ShipyardListImplement.Implements +{ + public class DetailStorage:IDetailStorage + { + private readonly DataListSingleton _source; + public DetailStorage() + { + _source=DataListSingleton.GetInstance(); + } + public List GetFullList() + { + var result = new List(); + foreach (var detail in _source.Details) + { + result.Add(detail.GetViewModel); + } + return result; + } + public List GetFilteredList(DetailSearchModel model) + { + var result = new List(); + if (string.IsNullOrEmpty(model.DetailName)) + { + return result; + } + foreach (var detail in _source.Details) + { + if (detail.DetailName.Contains(model.DetailName)) + { + result.Add(detail.GetViewModel); + } + } + return result; + } + public DetailViewModel? GetElement(DetailSearchModel model) + { + if (string.IsNullOrEmpty(model.DetailName) && !model.Id.HasValue) + { + return null; + } + foreach (var detail in _source.Details) + { + if ((!string.IsNullOrEmpty(model.DetailName) && + detail.DetailName == model.DetailName) || + (model.Id.HasValue && detail.Id == model.Id)) + { + return detail.GetViewModel; + } + } + return null; + } + public DetailViewModel? Insert(DetailBindingModel model) + { + model.Id = 1; + foreach (var component in _source.Details) + { + if (model.Id <= component.Id) + { + model.Id = component.Id + 1; + } + } + var newDetail = Detail.Create(model); + if (newDetail == null) + { + return null; + } + _source.Details.Add(newDetail); + return newDetail.GetViewModel; + } + public DetailViewModel? Update(DetailBindingModel model) + { + foreach (var detail in _source.Details) + { + if (detail.Id == model.Id) + { + detail.Update(model); + return detail.GetViewModel; + } + } + return null; + } + public DetailViewModel? Delete(DetailBindingModel model) + { + for (int i = 0; i < _source.Details.Count; ++i) + { + if (_source.Details[i].Id == model.Id) + { + var element = _source.Details[i]; + _source.Details.RemoveAt(i); + return element.GetViewModel; + } + } + return null; + } + + } +} diff --git a/Shipyard/ShipyardListImplement»/Implements/OrderStorage.cs b/Shipyard/ShipyardListImplement»/Implements/OrderStorage.cs new file mode 100644 index 0000000..b1f2b33 --- /dev/null +++ b/Shipyard/ShipyardListImplement»/Implements/OrderStorage.cs @@ -0,0 +1,105 @@ +using ShipyardContracts.BindingModels; +using ShipyardContracts.SearchModels; +using ShipyardContracts.StoragesContracts; +using ShipyardContracts.ViewModels; +using ShipyardListImplement.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ShipyardListImplement.Implements +{ + public class OrderStorage:IOrderStorage + { + private readonly DataListSingleton _source; + public OrderStorage() + { + _source = DataListSingleton.GetInstance(); + } + public List GetFullList() + { + var result = new List(); + foreach (var order in _source.Orders) + { + result.Add(order.GetViewModel); + } + return result; + } + public List GetFilteredList(OrderSearchModel model) + { + var result = new List(); + if (!model.Id.HasValue) + { + return result; + } + foreach (var order in _source.Orders) + { + if (order.Id==model.Id) + { + result.Add(order.GetViewModel); + } + } + return result; + } + public OrderViewModel? GetElement(OrderSearchModel model) + { + if (!model.Id.HasValue) + { + return null; + } + foreach (var order in _source.Orders) + { + if (model.Id.HasValue && order.Id == model.Id) + { + return order.GetViewModel; + } + } + return null; + } + public OrderViewModel? Insert(OrderBindingModel model) + { + model.Id = 1; + foreach (var order in _source.Orders) + { + if (model.Id <= order.Id) + { + model.Id = order.Id + 1; + } + } + var newOrder = Order.Create(model); + if (newOrder == null) + { + return null; + } + _source.Orders.Add(newOrder); + return newOrder.GetViewModel; + } + public OrderViewModel? Update(OrderBindingModel model) + { + foreach (var order in _source.Orders) + { + if (order.Id == model.Id) + { + order.Update(model); + return order.GetViewModel; + } + } + return null; + } + public OrderViewModel? Delete(OrderBindingModel model) + { + for (int i = 0; i < _source.Orders.Count; ++i) + { + if (_source.Orders[i].Id == model.Id) + { + var element = _source.Orders[i]; + _source.Orders.RemoveAt(i); + return element.GetViewModel; + } + } + return null; + } + } +} diff --git a/Shipyard/ShipyardListImplement»/Implements/ShipStorage.cs b/Shipyard/ShipyardListImplement»/Implements/ShipStorage.cs new file mode 100644 index 0000000..7cc20a9 --- /dev/null +++ b/Shipyard/ShipyardListImplement»/Implements/ShipStorage.cs @@ -0,0 +1,107 @@ +using ShipyardContracts.BindingModels; +using ShipyardContracts.SearchModels; +using ShipyardContracts.StoragesContracts; +using ShipyardContracts.ViewModels; +using ShipyardListImplement.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ShipyardListImplement.Implements +{ + public class ShipStorage:IShipStorage + { + private readonly DataListSingleton _source; + public ShipStorage() + { + _source = DataListSingleton.GetInstance(); + } + public List GetFullList() + { + var result = new List(); + foreach (var ship in _source.Ships) + { + result.Add(ship.GetViewModel); + } + return result; + } + public List GetFilteredList(ShipSearchModel model) + { + var result = new List(); + if (string.IsNullOrEmpty(model.ShipName)) + { + return result; + } + foreach (var ship in _source.Ships) + { + if (ship.ShipName.Contains(model.ShipName)) + { + result.Add(ship.GetViewModel); + } + } + return result; + } + public ShipViewModel? GetElement(ShipSearchModel model) + { + if (string.IsNullOrEmpty(model.ShipName) && !model.Id.HasValue) + { + return null; + } + foreach (var ship in _source.Ships) + { + if ((!string.IsNullOrEmpty(model.ShipName) && + ship.ShipName == model.ShipName) || + (model.Id.HasValue && ship.Id == model.Id)) + { + return ship.GetViewModel; + } + } + return null; + } + public ShipViewModel? Insert(ShipBindingModel model) + { + model.Id = 1; + foreach (var ship in _source.Ships) + { + if (model.Id <= ship.Id) + { + model.Id = ship.Id + 1; + } + } + var newShip = Ship.Create(model); + if (newShip == null) + { + return null; + } + _source.Ships.Add(newShip); + return newShip.GetViewModel; + } + public ShipViewModel? Update(ShipBindingModel model) + { + foreach (var ship in _source.Ships) + { + if (ship.Id == model.Id) + { + ship.Update(model); + return ship.GetViewModel; + } + } + return null; + } + public ShipViewModel? Delete(ShipBindingModel model) + { + for (int i = 0; i < _source.Ships.Count; ++i) + { + if (_source.Ships[i].Id == model.Id) + { + var element = _source.Ships[i]; + _source.Ships.RemoveAt(i); + return element.GetViewModel; + } + } + return null; + } + } +} diff --git a/Shipyard/ShipyardListImplement»/Models/Detail.cs b/Shipyard/ShipyardListImplement»/Models/Detail.cs new file mode 100644 index 0000000..2e7bc87 --- /dev/null +++ b/Shipyard/ShipyardListImplement»/Models/Detail.cs @@ -0,0 +1,48 @@ +using ShipyardContracts.BindingModels; +using ShipyardContracts.ViewModels; +using ShipyardDataModels.Models; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ShipyardListImplement.Models +{ + public class Detail:IDetailModel + { + public int Id { get; private set; } + public string DetailName { get; private set; } = string.Empty; + public double Cost { get; set; } + public static Detail? Create(DetailBindingModel? model) + { + if (model == null) + { + return null; + } + return new Detail() + { + Id = model.Id, + DetailName = model.DetailName, + Cost = model.Cost + }; + } + public void Update(DetailBindingModel? model) + { + if (model == null) + { + return; + } + DetailName = model.DetailName; + Cost = model.Cost; + } + public DetailViewModel GetViewModel => new() + { + Id = Id, + DetailName = DetailName, + Cost = Cost + }; + + } +} diff --git a/Shipyard/ShipyardListImplement»/Models/Order.cs b/Shipyard/ShipyardListImplement»/Models/Order.cs new file mode 100644 index 0000000..0d60465 --- /dev/null +++ b/Shipyard/ShipyardListImplement»/Models/Order.cs @@ -0,0 +1,68 @@ +using ShipyardContracts.BindingModels; +using ShipyardContracts.ViewModels; +using ShipyardDataModels.Enums; +using ShipyardDataModels.Models; +using System; +using System.Collections.Generic; +using System.Diagnostics; +using System.Linq; +using System.Reflection; +using System.Text; +using System.Threading.Tasks; + +namespace ShipyardListImplement.Models +{ + public class Order: IOrderModel + { + public int Id { get; private set; } + public int ShipId { get; private set; } + 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 static Order? Create(OrderBindingModel? model) + { + if (model == null) + { + return null; + } + return new Order() + { + Id = model.Id, + ShipId = model.ShipId, + Count = model.Count, + Sum = model.Sum, + Status = model.Status, + DateCreate = model.DateCreate, + DateImplement = model.DateImplement + }; + } + public void Update(OrderBindingModel? model) + { + if (model == null) + { + return; + } + Id = model.Id; + ShipId = model.ShipId; + Count = model.Count; + Sum = model.Sum; + Status = model.Status; + DateCreate = model.DateCreate; + DateImplement = model.DateImplement; + } + public OrderViewModel GetViewModel => new() + { + Id = Id, + ShipId = ShipId, + Count = Count, + Sum = Sum, + Status = Status, + DateCreate = DateCreate, + DateImplement = DateImplement + }; + + } +} diff --git a/Shipyard/ShipyardListImplement»/Models/Ship.cs b/Shipyard/ShipyardListImplement»/Models/Ship.cs new file mode 100644 index 0000000..4c526b3 --- /dev/null +++ b/Shipyard/ShipyardListImplement»/Models/Ship.cs @@ -0,0 +1,51 @@ +using ShipyardContracts.BindingModels; +using ShipyardContracts.ViewModels; +using ShipyardDataModels.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ShipyardListImplement.Models +{ + public class Ship:IShipModel + { + public int Id { get; private set; } + public string ShipName { get; private set; } = string.Empty; + public double Price { get; private set; } + public Dictionary ShipDetails { get; private set; } = new Dictionary(); + public static Ship? Create(ShipBindingModel? model) + { + if (model == null) + { + return null; + } + return new Ship() + { + Id = model.Id, + ShipName = model.ShipName, + Price = model.Price, + ShipDetails = model.ShipDetails + }; + } + public void Update(ShipBindingModel? model) + { + if (model == null) + { + return; + } + ShipName = model.ShipName; + Price = model.Price; + ShipDetails = model.ShipDetails; + } + public ShipViewModel GetViewModel => new() + { + Id = Id, + ShipName = ShipName, + Price = Price, + ShipDetails = ShipDetails + }; + + } +} diff --git a/Shipyard/ShipyardListImplement»/ShipyardListImplement.csproj b/Shipyard/ShipyardListImplement»/ShipyardListImplement.csproj new file mode 100644 index 0000000..c7524df --- /dev/null +++ b/Shipyard/ShipyardListImplement»/ShipyardListImplement.csproj @@ -0,0 +1,21 @@ + + + + net6.0 + ShipyardListImplement_ + enable + enable + + + + + + + + + + + + + +