diff --git a/JewelryStore/Form1.Designer.cs b/JewelryStore/Form1.Designer.cs deleted file mode 100644 index d1c38a9..0000000 --- a/JewelryStore/Form1.Designer.cs +++ /dev/null @@ -1,39 +0,0 @@ -namespace JewelryStore -{ - 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/JewelryStore/Form1.cs b/JewelryStore/Form1.cs deleted file mode 100644 index f3212bd..0000000 --- a/JewelryStore/Form1.cs +++ /dev/null @@ -1,10 +0,0 @@ -namespace JewelryStore -{ - public partial class Form1 : Form - { - public Form1() - { - InitializeComponent(); - } - } -} \ No newline at end of file diff --git a/JewelryStore/FormComponent.Designer.cs b/JewelryStore/FormComponent.Designer.cs new file mode 100644 index 0000000..759487b --- /dev/null +++ b/JewelryStore/FormComponent.Designer.cs @@ -0,0 +1,119 @@ +namespace JewelryStore +{ + partial class FormComponent + { + /// + /// 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.labelName = new System.Windows.Forms.Label(); + this.labelCost = new System.Windows.Forms.Label(); + this.textBoxName = new System.Windows.Forms.TextBox(); + this.textBoxCost = new System.Windows.Forms.TextBox(); + this.SuspendLayout(); + // + // buttonSave + // + this.buttonSave.Location = new System.Drawing.Point(554, 353); + this.buttonSave.Name = "buttonSave"; + this.buttonSave.Size = new System.Drawing.Size(112, 34); + this.buttonSave.TabIndex = 0; + this.buttonSave.Text = "Сохранить"; + this.buttonSave.UseVisualStyleBackColor = true; + this.buttonSave.Click += new System.EventHandler(this.buttonSave_Click); + // + // buttonCancel + // + this.buttonCancel.Location = new System.Drawing.Point(676, 353); + this.buttonCancel.Name = "buttonCancel"; + this.buttonCancel.Size = new System.Drawing.Size(112, 34); + this.buttonCancel.TabIndex = 1; + this.buttonCancel.Text = "Отмена"; + this.buttonCancel.UseVisualStyleBackColor = true; + this.buttonCancel.Click += new System.EventHandler(this.buttonCancel_Click); + // + // labelName + // + this.labelName.AutoSize = true; + this.labelName.Location = new System.Drawing.Point(90, 113); + this.labelName.Name = "labelName"; + this.labelName.Size = new System.Drawing.Size(94, 25); + this.labelName.TabIndex = 2; + this.labelName.Text = "Название:"; + // + // labelCost + // + this.labelCost.AutoSize = true; + this.labelCost.Location = new System.Drawing.Point(90, 160); + this.labelCost.Name = "labelCost"; + this.labelCost.Size = new System.Drawing.Size(57, 25); + this.labelCost.TabIndex = 3; + this.labelCost.Text = "Цена:"; + // + // textBoxName + // + this.textBoxName.Location = new System.Drawing.Point(212, 113); + this.textBoxName.Name = "textBoxName"; + this.textBoxName.Size = new System.Drawing.Size(150, 31); + this.textBoxName.TabIndex = 4; + // + // textBoxCost + // + this.textBoxCost.Location = new System.Drawing.Point(212, 160); + this.textBoxCost.Name = "textBoxCost"; + this.textBoxCost.Size = new System.Drawing.Size(150, 31); + this.textBoxCost.TabIndex = 5; + // + // FormComponent + // + this.AutoScaleDimensions = new System.Drawing.SizeF(10F, 25F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(800, 450); + this.Controls.Add(this.textBoxCost); + this.Controls.Add(this.textBoxName); + this.Controls.Add(this.labelCost); + this.Controls.Add(this.labelName); + this.Controls.Add(this.buttonCancel); + this.Controls.Add(this.buttonSave); + this.Name = "FormComponent"; + this.Text = "Компонент"; + this.Load += new System.EventHandler(this.FormComponent_Load); + this.ResumeLayout(false); + this.PerformLayout(); + + } + + #endregion + + private Button buttonSave; + private Button buttonCancel; + private Label labelName; + private Label labelCost; + private TextBox textBoxName; + private TextBox textBoxCost; + } +} \ No newline at end of file diff --git a/JewelryStore/FormComponent.cs b/JewelryStore/FormComponent.cs new file mode 100644 index 0000000..7495460 --- /dev/null +++ b/JewelryStore/FormComponent.cs @@ -0,0 +1,92 @@ +using Microsoft.Extensions.Logging; +using JewelryStoreContracts.BindingModels; +using JewelryStoreContracts.BusinessLogicsContracts; +using JewelryStoreContracts.SearchModels; + + +namespace JewelryStore +{ + public partial class FormComponent : Form + { + private readonly ILogger _logger; + private readonly IComponentLogic _logic; + private int? _id; + public int Id { set { _id = value; } } + public FormComponent(ILogger logger, IComponentLogic + logic) + { + InitializeComponent(); + _logger = logger; + _logic = logic; + } + private void FormComponent_Load(object sender, EventArgs e) + { + if (_id.HasValue) + { + try + { + _logger.LogInformation(" "); + var view = _logic.ReadElement(new ComponentSearchModel + { + Id = + _id.Value + }); + if (view != null) + { + textBoxName.Text = view.ComponentName; + 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 ComponentBindingModel + { + Id = _id ?? 0, + ComponentName = 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/JewelryStore/FormComponent.resx b/JewelryStore/FormComponent.resx new file mode 100644 index 0000000..f298a7b --- /dev/null +++ b/JewelryStore/FormComponent.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/JewelryStore/FormComponents.Designer.cs b/JewelryStore/FormComponents.Designer.cs new file mode 100644 index 0000000..7156e1f --- /dev/null +++ b/JewelryStore/FormComponents.Designer.cs @@ -0,0 +1,116 @@ +namespace JewelryStore +{ + partial class FormComponents + { + /// + /// 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.dataGridView = new System.Windows.Forms.DataGridView(); + this.buttonAdd = new System.Windows.Forms.Button(); + this.buttonChange = new System.Windows.Forms.Button(); + this.buttonDelete = new System.Windows.Forms.Button(); + this.buttonUpdate = new System.Windows.Forms.Button(); + ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit(); + this.SuspendLayout(); + // + // 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 = 62; + this.dataGridView.RowTemplate.Height = 33; + this.dataGridView.Size = new System.Drawing.Size(459, 488); + this.dataGridView.TabIndex = 0; + // + // buttonAdd + // + this.buttonAdd.Location = new System.Drawing.Point(480, 25); + this.buttonAdd.Name = "buttonAdd"; + this.buttonAdd.Size = new System.Drawing.Size(112, 34); + this.buttonAdd.TabIndex = 1; + this.buttonAdd.Text = "Добавить"; + this.buttonAdd.UseVisualStyleBackColor = true; + this.buttonAdd.Click += new System.EventHandler(this.buttonAdd_Click); + // + // buttonChange + // + this.buttonChange.Location = new System.Drawing.Point(481, 67); + this.buttonChange.Name = "buttonChange"; + this.buttonChange.Size = new System.Drawing.Size(112, 34); + this.buttonChange.TabIndex = 2; + this.buttonChange.Text = "Изменить"; + this.buttonChange.UseVisualStyleBackColor = true; + this.buttonChange.Click += new System.EventHandler(this.buttonChange_Click); + // + // buttonDelete + // + this.buttonDelete.Location = new System.Drawing.Point(481, 107); + this.buttonDelete.Name = "buttonDelete"; + this.buttonDelete.Size = new System.Drawing.Size(112, 34); + this.buttonDelete.TabIndex = 3; + this.buttonDelete.Text = "Удалить"; + this.buttonDelete.UseVisualStyleBackColor = true; + this.buttonDelete.Click += new System.EventHandler(this.buttonDelete_Click); + // + // buttonUpdate + // + this.buttonUpdate.Location = new System.Drawing.Point(481, 147); + this.buttonUpdate.Name = "buttonUpdate"; + this.buttonUpdate.Size = new System.Drawing.Size(112, 34); + this.buttonUpdate.TabIndex = 4; + this.buttonUpdate.Text = "Обновить"; + this.buttonUpdate.UseVisualStyleBackColor = true; + this.buttonUpdate.Click += new System.EventHandler(this.buttonUpdate_Click); + // + // FormComponents + // + this.AutoScaleDimensions = new System.Drawing.SizeF(10F, 25F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(614, 488); + this.Controls.Add(this.buttonUpdate); + this.Controls.Add(this.buttonDelete); + this.Controls.Add(this.buttonChange); + this.Controls.Add(this.buttonAdd); + this.Controls.Add(this.dataGridView); + this.Name = "FormComponents"; + this.Text = "Компоненты"; + this.Load += new System.EventHandler(this.FormComponents_Load); + ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).EndInit(); + this.ResumeLayout(false); + + } + + #endregion + + private DataGridView dataGridView; + private Button buttonAdd; + private Button buttonChange; + private Button buttonDelete; + private Button buttonUpdate; + } +} \ No newline at end of file diff --git a/JewelryStore/FormComponents.cs b/JewelryStore/FormComponents.cs new file mode 100644 index 0000000..76cf58a --- /dev/null +++ b/JewelryStore/FormComponents.cs @@ -0,0 +1,121 @@ + +using JewelryStore; +using JewelryStoreContracts.BindingModels; +using JewelryStoreContracts.BusinessLogicsContracts; +using Microsoft.Extensions.Logging; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; + +namespace JewelryStore +{ + public partial class FormComponents : Form + { + private readonly ILogger _logger; + private readonly IComponentLogic _logic; + public FormComponents(ILogger logger, IComponentLogic logic) + { + InitializeComponent(); + _logger = logger; + _logic = logic; + } + + private void FormComponents_Load(object sender, EventArgs e) + { + LoadData(); + } + private void LoadData() + { + try + { + var list = _logic.ReadList(null); + if (list != null) + { + dataGridView.DataSource = list; + dataGridView.Columns["Id"].Visible = false; + dataGridView.Columns["ComponentName"].AutoSizeMode = + DataGridViewAutoSizeColumnMode.Fill; + } + _logger.LogInformation("Загрузка компонентов"); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка загрузки компонентов"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, + MessageBoxIcon.Error); + } + } + + private void buttonAdd_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormComponent)); + if (service is FormComponent form) + { + if (form.ShowDialog() == DialogResult.OK) + { + LoadData(); + } + } + } + + private void buttonUpdate_Click(object sender, EventArgs e) + { + LoadData(); + } + + private void buttonDelete_Click(object sender, EventArgs e) + { + if (dataGridView.SelectedRows.Count == 1) + { + if (MessageBox.Show("Удалить запись?", "Вопрос", + MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) + { + int id = + Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); + _logger.LogInformation("Удаление компонента"); + try + { + if (!_logic.Delete(new ComponentBindingModel + { + Id = id + })) + { + throw new Exception("Ошибка при удалении. Дополнительная информация в логах."); + } + LoadData(); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка удаления компонента"); + MessageBox.Show(ex.Message, "Ошибка", + MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + } + + } + + private void buttonChange_Click(object sender, EventArgs e) + { + if (dataGridView.SelectedRows.Count == 1) + { + var service = + Program.ServiceProvider?.GetService(typeof(FormComponent)); + if (service is FormComponent form) + { + form.Id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); + if (form.ShowDialog() == DialogResult.OK) + { + LoadData(); + } + } + } + } + } +} \ No newline at end of file diff --git a/JewelryStore/Form1.resx b/JewelryStore/FormComponents.resx similarity index 100% rename from JewelryStore/Form1.resx rename to JewelryStore/FormComponents.resx diff --git a/JewelryStore/FormCreateOrder.Designer.cs b/JewelryStore/FormCreateOrder.Designer.cs new file mode 100644 index 0000000..57c334d --- /dev/null +++ b/JewelryStore/FormCreateOrder.Designer.cs @@ -0,0 +1,144 @@ +namespace JewelryStore +{ + 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.comboBoxJewel = new System.Windows.Forms.ComboBox(); + this.labelJewel = new System.Windows.Forms.Label(); + this.labelCount = new System.Windows.Forms.Label(); + this.labelSum = new System.Windows.Forms.Label(); + this.textBoxCount = new System.Windows.Forms.TextBox(); + this.textBoxSum = new System.Windows.Forms.TextBox(); + this.buttonSave = new System.Windows.Forms.Button(); + this.buttonCancel = new System.Windows.Forms.Button(); + this.SuspendLayout(); + // + // comboBoxJewel + // + this.comboBoxJewel.FormattingEnabled = true; + this.comboBoxJewel.Location = new System.Drawing.Point(115, 14); + this.comboBoxJewel.Name = "comboBoxJewel"; + this.comboBoxJewel.Size = new System.Drawing.Size(250, 33); + this.comboBoxJewel.TabIndex = 0; + // + // labelJewel + // + this.labelJewel.AutoSize = true; + this.labelJewel.Location = new System.Drawing.Point(12, 22); + this.labelJewel.Name = "labelJewel"; + this.labelJewel.Size = new System.Drawing.Size(80, 25); + this.labelJewel.TabIndex = 1; + this.labelJewel.Text = "Изделие"; + // + // labelCount + // + this.labelCount.AutoSize = true; + this.labelCount.Location = new System.Drawing.Point(12, 67); + this.labelCount.Name = "labelCount"; + this.labelCount.Size = new System.Drawing.Size(107, 25); + this.labelCount.TabIndex = 2; + this.labelCount.Text = "Количество"; + // + // labelSum + // + this.labelSum.AutoSize = true; + this.labelSum.Location = new System.Drawing.Point(12, 118); + this.labelSum.Name = "labelSum"; + this.labelSum.Size = new System.Drawing.Size(67, 25); + this.labelSum.TabIndex = 3; + this.labelSum.Text = "Сумма"; + // + // textBoxCount + // + this.textBoxCount.Location = new System.Drawing.Point(115, 64); + this.textBoxCount.Name = "textBoxCount"; + this.textBoxCount.Size = new System.Drawing.Size(250, 31); + this.textBoxCount.TabIndex = 4; + this.textBoxCount.TextChanged += new System.EventHandler(this.textBoxCount_TextChanged); + // + // textBoxSum + // + this.textBoxSum.Location = new System.Drawing.Point(115, 115); + this.textBoxSum.Name = "textBoxSum"; + this.textBoxSum.ReadOnly = true; + this.textBoxSum.Size = new System.Drawing.Size(250, 31); + this.textBoxSum.TabIndex = 5; + // + // buttonSave + // + this.buttonSave.Location = new System.Drawing.Point(31, 161); + this.buttonSave.Name = "buttonSave"; + this.buttonSave.Size = new System.Drawing.Size(112, 34); + this.buttonSave.TabIndex = 6; + this.buttonSave.Text = "Сохранить"; + this.buttonSave.UseVisualStyleBackColor = true; + this.buttonSave.Click += new System.EventHandler(this.buttonSave_Click); + // + // buttonCancel + // + this.buttonCancel.Location = new System.Drawing.Point(253, 161); + this.buttonCancel.Name = "buttonCancel"; + this.buttonCancel.Size = new System.Drawing.Size(112, 34); + 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(10F, 25F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(401, 207); + this.Controls.Add(this.buttonCancel); + this.Controls.Add(this.buttonSave); + this.Controls.Add(this.textBoxSum); + this.Controls.Add(this.textBoxCount); + this.Controls.Add(this.labelSum); + this.Controls.Add(this.labelCount); + this.Controls.Add(this.labelJewel); + this.Controls.Add(this.comboBoxJewel); + this.Name = "FormCreateOrder"; + this.Text = "Заказ"; + this.Load += new System.EventHandler(this.OrderForm_Load); + this.ResumeLayout(false); + this.PerformLayout(); + + } + + #endregion + + private ComboBox comboBoxJewel; + private Label labelJewel; + private Label labelCount; + private Label labelSum; + private TextBox textBoxCount; + private TextBox textBoxSum; + private Button buttonSave; + private Button buttonCancel; + } +} \ No newline at end of file diff --git a/JewelryStore/FormCreateOrder.cs b/JewelryStore/FormCreateOrder.cs new file mode 100644 index 0000000..b6c1d21 --- /dev/null +++ b/JewelryStore/FormCreateOrder.cs @@ -0,0 +1,127 @@ +using JewelryStoreContracts.BindingModels; +using JewelryStoreContracts.BusinessLogicsContracts; +using JewelryStoreContracts.SearchModels; +using Microsoft.Extensions.Logging; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; + +namespace JewelryStore +{ + public partial class FormCreateOrder : Form + { + private readonly ILogger _logger; + private readonly IJewelLogic _logicP; + private readonly IOrderLogic _logicO; + public FormCreateOrder(ILogger logger, IJewelLogic logicP, IOrderLogic logicO) + { + InitializeComponent(); + _logger = logger; + _logicP = logicP; + _logicO = logicO; + } + + private void OrderForm_Load(object sender, EventArgs e) + { + _logger.LogInformation("Загрузка драгоценностей для заказа"); + try + { + var list = _logicP.ReadList(null); + if (list != null) + { + comboBoxJewel.DisplayMember = "Драгоценность"; + comboBoxJewel.ValueMember = "Id"; + comboBoxJewel.DataSource = list.Select(c => c.JewelName).ToList(); + comboBoxJewel.SelectedItem = null; + } + + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка загрузки списка драгоценностей"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + private void CalcSum() + { + if (comboBoxJewel.SelectedValue != null && !string.IsNullOrEmpty(textBoxCount.Text)) + { + try + { + int id = Convert.ToInt32(comboBoxJewel.SelectedIndex) + 1; + var Jewel = _logicP.ReadElement(new JewelSearchModel + { + Id = id + }); + int count = Convert.ToInt32(textBoxCount.Text); + textBoxSum.Text = Math.Round(count * (Jewel?.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 buttonSave_Click(object sender, EventArgs e) + { + if (string.IsNullOrEmpty(textBoxCount.Text)) + { + MessageBox.Show("Заполните поле Количество", "Ошибка", + MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + if (comboBoxJewel.SelectedValue == null) + { + MessageBox.Show("Выберите драгоценность", "Ошибка", + MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + _logger.LogInformation("Создание заказа"); + try + { + var operationResult = _logicO.CreateOrder(new OrderBindingModel + { + JewelId = Convert.ToInt32(comboBoxJewel.SelectedIndex) + 1, + JewelName = comboBoxJewel.SelectedValue.ToString(), + 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/JewelryStore/FormCreateOrder.resx b/JewelryStore/FormCreateOrder.resx new file mode 100644 index 0000000..1af7de1 --- /dev/null +++ b/JewelryStore/FormCreateOrder.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/JewelryStore/FormJewel.Designer.cs b/JewelryStore/FormJewel.Designer.cs new file mode 100644 index 0000000..3111cd6 --- /dev/null +++ b/JewelryStore/FormJewel.Designer.cs @@ -0,0 +1,232 @@ +namespace JewelryStore +{ + partial class FormJewel + { + /// + /// 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.groupBoxComponent = new System.Windows.Forms.GroupBox(); + this.buttonUpdate = new System.Windows.Forms.Button(); + this.buttonDelete = new System.Windows.Forms.Button(); + this.buttonChange = new System.Windows.Forms.Button(); + this.buttonAdd = new System.Windows.Forms.Button(); + this.dataGridView = new System.Windows.Forms.DataGridView(); + this.buttonSave = new System.Windows.Forms.Button(); + this.buttonCancel = new System.Windows.Forms.Button(); + this.ID = new System.Windows.Forms.DataGridViewTextBoxColumn(); + this.ColumnComponent = new System.Windows.Forms.DataGridViewTextBoxColumn(); + this.ColumnCount = new System.Windows.Forms.DataGridViewTextBoxColumn(); + this.groupBoxComponent.SuspendLayout(); + ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit(); + this.SuspendLayout(); + // + // labelName + // + this.labelName.AutoSize = true; + this.labelName.Location = new System.Drawing.Point(19, 19); + this.labelName.Name = "labelName"; + this.labelName.Size = new System.Drawing.Size(94, 25); + this.labelName.TabIndex = 0; + this.labelName.Text = "Название:"; + // + // labelPrice + // + this.labelPrice.AutoSize = true; + this.labelPrice.Location = new System.Drawing.Point(19, 59); + this.labelPrice.Name = "labelPrice"; + this.labelPrice.Size = new System.Drawing.Size(108, 25); + this.labelPrice.TabIndex = 1; + this.labelPrice.Text = "Стоимость: "; + // + // textBoxName + // + this.textBoxName.Location = new System.Drawing.Point(119, 16); + this.textBoxName.Name = "textBoxName"; + this.textBoxName.Size = new System.Drawing.Size(340, 31); + this.textBoxName.TabIndex = 2; + // + // textBoxPrice + // + this.textBoxPrice.Location = new System.Drawing.Point(119, 53); + this.textBoxPrice.Name = "textBoxPrice"; + this.textBoxPrice.Size = new System.Drawing.Size(150, 31); + this.textBoxPrice.TabIndex = 3; + // + // groupBoxComponent + // + this.groupBoxComponent.Controls.Add(this.buttonUpdate); + this.groupBoxComponent.Controls.Add(this.buttonDelete); + this.groupBoxComponent.Controls.Add(this.buttonChange); + this.groupBoxComponent.Controls.Add(this.buttonAdd); + this.groupBoxComponent.Controls.Add(this.dataGridView); + this.groupBoxComponent.Location = new System.Drawing.Point(14, 108); + this.groupBoxComponent.Name = "groupBoxComponent"; + this.groupBoxComponent.Size = new System.Drawing.Size(763, 330); + this.groupBoxComponent.TabIndex = 4; + this.groupBoxComponent.TabStop = false; + this.groupBoxComponent.Text = "Компоненты"; + // + // buttonUpdate + // + this.buttonUpdate.Location = new System.Drawing.Point(604, 164); + this.buttonUpdate.Name = "buttonUpdate"; + this.buttonUpdate.Size = new System.Drawing.Size(112, 34); + this.buttonUpdate.TabIndex = 4; + this.buttonUpdate.Text = "Обновить"; + this.buttonUpdate.UseVisualStyleBackColor = true; + this.buttonUpdate.Click += new System.EventHandler(this.buttonUpdate_Click); + // + // buttonDelete + // + this.buttonDelete.Location = new System.Drawing.Point(604, 124); + this.buttonDelete.Name = "buttonDelete"; + this.buttonDelete.Size = new System.Drawing.Size(112, 34); + this.buttonDelete.TabIndex = 3; + this.buttonDelete.Text = "Удалить"; + this.buttonDelete.UseVisualStyleBackColor = true; + this.buttonDelete.Click += new System.EventHandler(this.buttonDelete_Click); + // + // buttonChange + // + this.buttonChange.Location = new System.Drawing.Point(602, 81); + this.buttonChange.Name = "buttonChange"; + this.buttonChange.Size = new System.Drawing.Size(112, 34); + this.buttonChange.TabIndex = 2; + this.buttonChange.Text = "Изменить"; + this.buttonChange.UseVisualStyleBackColor = true; + this.buttonChange.Click += new System.EventHandler(this.buttonChange_Click); + // + // buttonAdd + // + this.buttonAdd.Location = new System.Drawing.Point(602, 35); + this.buttonAdd.Name = "buttonAdd"; + this.buttonAdd.Size = new System.Drawing.Size(112, 34); + this.buttonAdd.TabIndex = 1; + this.buttonAdd.Text = "Добавить"; + this.buttonAdd.UseVisualStyleBackColor = true; + this.buttonAdd.Click += new System.EventHandler(this.buttonAdd_Click); + // + // dataGridView + // + this.dataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; + this.dataGridView.Columns.AddRange(new System.Windows.Forms.DataGridViewColumn[] { + this.ID, + this.ColumnComponent, + this.ColumnCount}); + this.dataGridView.Location = new System.Drawing.Point(25, 30); + this.dataGridView.Name = "dataGridView"; + this.dataGridView.RowHeadersWidth = 62; + this.dataGridView.RowTemplate.Height = 33; + this.dataGridView.Size = new System.Drawing.Size(554, 281); + this.dataGridView.TabIndex = 0; + // + // buttonSave + // + this.buttonSave.Location = new System.Drawing.Point(431, 452); + this.buttonSave.Name = "buttonSave"; + this.buttonSave.Size = new System.Drawing.Size(112, 34); + 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(562, 454); + this.buttonCancel.Name = "buttonCancel"; + this.buttonCancel.Size = new System.Drawing.Size(112, 34); + this.buttonCancel.TabIndex = 6; + this.buttonCancel.Text = "Отмена"; + this.buttonCancel.UseVisualStyleBackColor = true; + this.buttonCancel.Click += new System.EventHandler(this.buttonCancel_Click); + // + // ID + // + this.ID.HeaderText = "Column1"; + this.ID.MinimumWidth = 8; + this.ID.Name = "ID"; + this.ID.Visible = false; + this.ID.Width = 150; + // + // ColumnComponent + // + this.ColumnComponent.HeaderText = "Компонент"; + this.ColumnComponent.MinimumWidth = 8; + this.ColumnComponent.Name = "ColumnComponent"; + this.ColumnComponent.Width = 150; + // + // ColumnCount + // + this.ColumnCount.HeaderText = "Количество"; + this.ColumnCount.MinimumWidth = 8; + this.ColumnCount.Name = "ColumnCount"; + this.ColumnCount.Width = 150; + // + // FormJewel + // + this.AutoScaleDimensions = new System.Drawing.SizeF(10F, 25F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(800, 495); + this.Controls.Add(this.buttonCancel); + this.Controls.Add(this.buttonSave); + this.Controls.Add(this.groupBoxComponent); + this.Controls.Add(this.textBoxPrice); + this.Controls.Add(this.textBoxName); + this.Controls.Add(this.labelPrice); + this.Controls.Add(this.labelName); + this.Name = "FormJewel"; + this.Text = "Драгоценность"; + this.Load += new System.EventHandler(this.FormJewel_Load); + this.groupBoxComponent.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 groupBoxComponent; + private Button buttonUpdate; + private Button buttonDelete; + private Button buttonChange; + private Button buttonAdd; + private DataGridView dataGridView; + private Button buttonSave; + private Button buttonCancel; + private DataGridViewTextBoxColumn ID; + private DataGridViewTextBoxColumn ColumnComponent; + private DataGridViewTextBoxColumn ColumnCount; + } +} \ No newline at end of file diff --git a/JewelryStore/FormJewel.cs b/JewelryStore/FormJewel.cs new file mode 100644 index 0000000..584076e --- /dev/null +++ b/JewelryStore/FormJewel.cs @@ -0,0 +1,228 @@ +using JewelryStoreContracts.BindingModels; +using JewelryStoreContracts.BusinessLogicsContracts; +using JewelryStoreContracts.SearchModels; +using JewelryStoreDataModels.Models; +using Microsoft.Extensions.Logging; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; + +namespace JewelryStore +{ + public partial class FormJewel : Form + { + private readonly ILogger _logger; + private readonly IJewelLogic _logic; + private int? _id; + private Dictionary _JewelComponents; + public int Id { set { _id = value; } } + public FormJewel(ILogger logger, IJewelLogic logic) + { + InitializeComponent(); + _logger = logger; + _logic = logic; + _JewelComponents = new Dictionary(); + } + + private void FormJewel_Load(object sender, EventArgs e) + { + if (_id.HasValue) + { + _logger.LogInformation("Загрузка драгоценности"); + try + { + var view = _logic.ReadElement(new JewelSearchModel + { + Id = _id.Value + }); + if (view != null) + { + textBoxName.Text = view.JewelName; + textBoxPrice.Text = view.Price.ToString(); + _JewelComponents = view.JewelComponents ?? new + Dictionary(); + LoadData(); + } + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка загрузки драгоценности"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, + MessageBoxIcon.Error); + } + } + + } + private void LoadData() + { + _logger.LogInformation("Загрузка компонент драгоценности"); + try + { + if (_JewelComponents != null) + { + dataGridView.Rows.Clear(); + foreach (var pc in _JewelComponents) + { + dataGridView.Rows.Add(new object[] { pc.Key,pc.Value.Item1.ComponentName, pc.Value.Item2 }); + } + textBoxPrice.Text = CalcPrice().ToString(); + } + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка загрузки компонент драгоценности"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, + MessageBoxIcon.Error); + } + } + + private void buttonAdd_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormJewelComponent)); + if (service is FormJewelComponent form) + { + if (form.ShowDialog() == DialogResult.OK) + { + if (form.ComponentModel == null) + { + return; + } + _logger.LogInformation("Добавление нового компонента:{ ComponentName} - { Count}", form.ComponentModel.ComponentName, form.Count); + if (_JewelComponents.ContainsKey(form.Id)) + { + _JewelComponents[form.Id] = (form.ComponentModel, form.Count); + } + else + { + _JewelComponents.Add(form.Id, (form.ComponentModel, form.Count)); + } + LoadData(); + } + } + + } + + private void buttonChange_Click(object sender, EventArgs e) + { + if (dataGridView.SelectedRows.Count == 1) + { + var service = Program.ServiceProvider?.GetService(typeof(FormJewelComponent)); + if (service is FormJewelComponent form) + { + int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells[0].Value); + form.Id = id; + form.Count = _JewelComponents[id].Item2; + if (form.ShowDialog() == DialogResult.OK) + { + if (form.ComponentModel == null) + { + return; + } + _logger.LogInformation("Изменение компонента: { ComponentName} - { Count}", form.ComponentModel.ComponentName, form.Count); + _JewelComponents[form.Id] = (form.ComponentModel, form.Count); + LoadData(); + } + } + } + + } + + private void buttonDelete_Click(object sender, EventArgs e) + { + if (dataGridView.SelectedRows.Count == 1) + { + if (MessageBox.Show("Удалить запись?", "Вопрос", + MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) + { + try + { + _logger.LogInformation("Удаление компонента: { ComponentName} - { Count}", dataGridView.SelectedRows[0].Cells[1].Value); + _JewelComponents?.Remove(Convert.ToInt32(dataGridView.SelectedRows[0].Cells[0].Value)); + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "Ошибка", + MessageBoxButtons.OK, MessageBoxIcon.Error); + } + LoadData(); + } + } + + } + + private void buttonUpdate_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 (_JewelComponents == null || _JewelComponents.Count == 0) + { + MessageBox.Show("Заполните компоненты", "Ошибка", + MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + _logger.LogInformation("Сохранение драгоценности"); + try + { + var model = new JewelBindingModel + { + Id = _id ?? 0, + JewelName = textBoxName.Text, + Price = Convert.ToDouble(textBoxPrice.Text), + JewelComponents = _JewelComponents + }; + 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 _JewelComponents) + { + price += ((elem.Value.Item1?.Cost ?? 0) * elem.Value.Item2); + } + return Math.Round(price * 1.1, 2); + } + } +} diff --git a/JewelryStore/FormJewel.resx b/JewelryStore/FormJewel.resx new file mode 100644 index 0000000..bb23025 --- /dev/null +++ b/JewelryStore/FormJewel.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 + + + True + + \ No newline at end of file diff --git a/JewelryStore/FormJewelComponent.Designer.cs b/JewelryStore/FormJewelComponent.Designer.cs new file mode 100644 index 0000000..7283393 --- /dev/null +++ b/JewelryStore/FormJewelComponent.Designer.cs @@ -0,0 +1,119 @@ +namespace JewelryStore +{ + partial class FormJewelComponent + { + /// + /// 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.comboBoxComponent = new System.Windows.Forms.ComboBox(); + this.textBoxCount = new System.Windows.Forms.TextBox(); + this.labelComponent = new System.Windows.Forms.Label(); + this.labelCount = new System.Windows.Forms.Label(); + this.buttonSave = new System.Windows.Forms.Button(); + this.buttonCancel = new System.Windows.Forms.Button(); + this.SuspendLayout(); + // + // comboBoxComponent + // + this.comboBoxComponent.FormattingEnabled = true; + this.comboBoxComponent.Location = new System.Drawing.Point(148, 10); + this.comboBoxComponent.Name = "comboBoxComponent"; + this.comboBoxComponent.Size = new System.Drawing.Size(182, 33); + this.comboBoxComponent.TabIndex = 0; + // + // textBoxCount + // + this.textBoxCount.Location = new System.Drawing.Point(150, 53); + this.textBoxCount.Name = "textBoxCount"; + this.textBoxCount.Size = new System.Drawing.Size(150, 31); + this.textBoxCount.TabIndex = 1; + // + // labelComponent + // + this.labelComponent.AutoSize = true; + this.labelComponent.Location = new System.Drawing.Point(16, 18); + this.labelComponent.Name = "labelComponent"; + this.labelComponent.Size = new System.Drawing.Size(103, 25); + this.labelComponent.TabIndex = 2; + this.labelComponent.Text = "Компонент"; + // + // labelCount + // + this.labelCount.AutoSize = true; + this.labelCount.Location = new System.Drawing.Point(16, 57); + this.labelCount.Name = "labelCount"; + this.labelCount.Size = new System.Drawing.Size(112, 25); + this.labelCount.TabIndex = 3; + this.labelCount.Text = "Количество "; + // + // buttonSave + // + this.buttonSave.Location = new System.Drawing.Point(75, 99); + this.buttonSave.Name = "buttonSave"; + this.buttonSave.Size = new System.Drawing.Size(112, 34); + this.buttonSave.TabIndex = 4; + this.buttonSave.Text = "Сохранить"; + this.buttonSave.UseVisualStyleBackColor = true; + this.buttonSave.Click += new System.EventHandler(this.buttonSave_Click); + // + // buttonCancel + // + this.buttonCancel.Location = new System.Drawing.Point(206, 99); + this.buttonCancel.Name = "buttonCancel"; + this.buttonCancel.Size = new System.Drawing.Size(112, 34); + this.buttonCancel.TabIndex = 5; + this.buttonCancel.Text = "Отменить"; + this.buttonCancel.UseVisualStyleBackColor = true; + this.buttonCancel.Click += new System.EventHandler(this.buttonCancel_Click); + // + // FormJewelComponent + // + this.AutoScaleDimensions = new System.Drawing.SizeF(10F, 25F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(426, 142); + this.Controls.Add(this.buttonCancel); + this.Controls.Add(this.buttonSave); + this.Controls.Add(this.labelCount); + this.Controls.Add(this.labelComponent); + this.Controls.Add(this.textBoxCount); + this.Controls.Add(this.comboBoxComponent); + this.Name = "FormJewelComponent"; + this.Text = "Компонент драгоценности"; + this.ResumeLayout(false); + this.PerformLayout(); + + } + + #endregion + + private ComboBox comboBoxComponent; + private TextBox textBoxCount; + private Label labelComponent; + private Label labelCount; + private Button buttonSave; + private Button buttonCancel; + } +} \ No newline at end of file diff --git a/JewelryStore/FormJewelComponent.cs b/JewelryStore/FormJewelComponent.cs new file mode 100644 index 0000000..1ec6c3b --- /dev/null +++ b/JewelryStore/FormJewelComponent.cs @@ -0,0 +1,92 @@ +using JewelryStoreContracts.BusinessLogicsContracts; +using JewelryStoreContracts.ViewModels; +using JewelryStoreDataModels.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 JewelryStore +{ + public partial class FormJewelComponent : Form + { + private readonly List? _list; + public int Id + { + get + { + return Convert.ToInt32(comboBoxComponent.SelectedValue); + } + set + { + comboBoxComponent.SelectedValue = value; + } + } + public IComponentModel? ComponentModel + { + get + { + if (_list == null) + { + return null; + } + foreach (var elem in _list) + { + if (elem.Id == Id) + { + return elem; + } + } + return null; + } + } + public int Count + { + get { return Convert.ToInt32(textBoxCount.Text); } + set { textBoxCount.Text = value.ToString(); } + } + + public FormJewelComponent(IComponentLogic logic) + { + InitializeComponent(); + _list = logic.ReadList(null); + if (_list != null) + { + comboBoxComponent.DisplayMember = "ComponentName"; + comboBoxComponent.ValueMember = "Id"; + comboBoxComponent.DataSource = _list; + comboBoxComponent.SelectedItem = null; + } + } + + private void buttonSave_Click(object sender, EventArgs e) + { + if (string.IsNullOrEmpty(textBoxCount.Text)) + { + MessageBox.Show("Заполните поле Количество", "Ошибка", + MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + if (comboBoxComponent.SelectedValue == null) + { + MessageBox.Show("Выберите компонент", "Ошибка", + MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + DialogResult = DialogResult.OK; + Close(); + + } + + private void buttonCancel_Click(object sender, EventArgs e) + { + DialogResult = DialogResult.Cancel; + Close(); + } + } +} diff --git a/JewelryStore/FormJewelComponent.resx b/JewelryStore/FormJewelComponent.resx new file mode 100644 index 0000000..f298a7b --- /dev/null +++ b/JewelryStore/FormJewelComponent.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/JewelryStore/FormJewels.Designer.cs b/JewelryStore/FormJewels.Designer.cs new file mode 100644 index 0000000..54f228a --- /dev/null +++ b/JewelryStore/FormJewels.Designer.cs @@ -0,0 +1,121 @@ +namespace JewelryStore +{ + partial class FormJewels + { + /// + /// 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.DataGridView = new System.Windows.Forms.DataGridView(); + this.AddButton = new System.Windows.Forms.Button(); + this.ChangeButton = new System.Windows.Forms.Button(); + this.DeleteButton = new System.Windows.Forms.Button(); + this.UpdateButton = new System.Windows.Forms.Button(); + ((System.ComponentModel.ISupportInitialize)(this.DataGridView)).BeginInit(); + this.SuspendLayout(); + // + // DataGridView + // + this.DataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; + this.DataGridView.Location = new System.Drawing.Point(1, 2); + this.DataGridView.Margin = new System.Windows.Forms.Padding(4, 5, 4, 5); + this.DataGridView.Name = "DataGridView"; + this.DataGridView.RowHeadersWidth = 62; + this.DataGridView.RowTemplate.Height = 25; + this.DataGridView.Size = new System.Drawing.Size(597, 547); + this.DataGridView.TabIndex = 0; + // + // AddButton + // + this.AddButton.Location = new System.Drawing.Point(615, 12); + this.AddButton.Margin = new System.Windows.Forms.Padding(4, 5, 4, 5); + this.AddButton.Name = "AddButton"; + this.AddButton.Size = new System.Drawing.Size(171, 39); + this.AddButton.TabIndex = 1; + this.AddButton.Text = "Добавить"; + this.AddButton.UseVisualStyleBackColor = true; + this.AddButton.Click += new System.EventHandler(this.AddButton_Click); + // + // ChangeButton + // + this.ChangeButton.Location = new System.Drawing.Point(615, 110); + this.ChangeButton.Margin = new System.Windows.Forms.Padding(4, 5, 4, 5); + this.ChangeButton.Name = "ChangeButton"; + this.ChangeButton.Size = new System.Drawing.Size(171, 39); + this.ChangeButton.TabIndex = 2; + this.ChangeButton.Text = "Изменить"; + this.ChangeButton.UseVisualStyleBackColor = true; + this.ChangeButton.Click += new System.EventHandler(this.ChangeButton_Click); + // + // DeleteButton + // + this.DeleteButton.Location = new System.Drawing.Point(615, 209); + this.DeleteButton.Margin = new System.Windows.Forms.Padding(4, 5, 4, 5); + this.DeleteButton.Name = "DeleteButton"; + this.DeleteButton.Size = new System.Drawing.Size(171, 39); + this.DeleteButton.TabIndex = 3; + this.DeleteButton.Text = "Удалить"; + this.DeleteButton.UseVisualStyleBackColor = true; + this.DeleteButton.Click += new System.EventHandler(this.DeleteButton_Click); + // + // UpdateButton + // + this.UpdateButton.Location = new System.Drawing.Point(615, 310); + this.UpdateButton.Margin = new System.Windows.Forms.Padding(4, 5, 4, 5); + this.UpdateButton.Name = "UpdateButton"; + this.UpdateButton.Size = new System.Drawing.Size(171, 39); + this.UpdateButton.TabIndex = 4; + this.UpdateButton.Text = "Обновить"; + this.UpdateButton.UseVisualStyleBackColor = true; + this.UpdateButton.Click += new System.EventHandler(this.UpdateButton_Click); + // + // FormJewels + // + this.AutoScaleDimensions = new System.Drawing.SizeF(10F, 25F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(805, 563); + this.Controls.Add(this.UpdateButton); + this.Controls.Add(this.DeleteButton); + this.Controls.Add(this.ChangeButton); + this.Controls.Add(this.AddButton); + this.Controls.Add(this.DataGridView); + this.Margin = new System.Windows.Forms.Padding(4, 5, 4, 5); + this.Name = "FormJewels"; + this.Text = "Драгоценности"; + this.Load += new System.EventHandler(this.FormJewels_Load); + ((System.ComponentModel.ISupportInitialize)(this.DataGridView)).EndInit(); + this.ResumeLayout(false); + + } + + #endregion + + private DataGridView DataGridView; + private Button AddButton; + private Button ChangeButton; + private Button DeleteButton; + private Button UpdateButton; + } +} \ No newline at end of file diff --git a/JewelryStore/FormJewels.cs b/JewelryStore/FormJewels.cs new file mode 100644 index 0000000..bea74a4 --- /dev/null +++ b/JewelryStore/FormJewels.cs @@ -0,0 +1,121 @@ +using Microsoft.Extensions.Logging; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; +using JewelryStore; +using JewelryStoreContracts.BindingModels; +using JewelryStoreContracts.BusinessLogicsContracts; +namespace JewelryStore +{ + public partial class FormJewels : Form //TODO + { + private readonly ILogger _logger; + private readonly IJewelLogic _logic; + + public FormJewels(ILogger logger, IJewelLogic logic) + { + InitializeComponent(); + _logger = logger; + _logic = logic; + } + + private void LoadData() + { + try + { + var list = _logic.ReadList(null); + + if (list != null) + { + DataGridView.DataSource = list; + DataGridView.Columns["Id"].Visible = false; + DataGridView.Columns["JewelName"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; + } + + _logger.LogInformation("Загрузка компонентов"); + + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка загрузки компонентов"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void AddButton_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormJewel)); + + if (service is FormJewel form) + { + if (form.ShowDialog() == DialogResult.OK) + { + LoadData(); + } + } + } + private void ChangeButton_Click(object sender, EventArgs e) + { + if (DataGridView.SelectedRows.Count == 1) + { + var service = Program.ServiceProvider?.GetService(typeof(FormJewel)); + + if (service is FormJewel form) + { + form.Id = Convert.ToInt32(DataGridView.SelectedRows[0].Cells["Id"].Value); + + if (form.ShowDialog() == DialogResult.OK) + { + LoadData(); + } + } + } + } + private void DeleteButton_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 JewelBindingModel + { + Id = id + })) + { + throw new Exception("Ошибка при удалении. Дополнительная информация в логах."); + } + + LoadData(); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка удаления компонента"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + } + } + private void UpdateButton_Click(object sender, EventArgs e) + { + LoadData(); + } + + + private void FormJewels_Load(object sender, EventArgs e) + { + LoadData(); + } + + } +} diff --git a/JewelryStore/FormJewels.resx b/JewelryStore/FormJewels.resx new file mode 100644 index 0000000..1af7de1 --- /dev/null +++ b/JewelryStore/FormJewels.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/JewelryStore/FormMain.Designer.cs b/JewelryStore/FormMain.Designer.cs new file mode 100644 index 0000000..4988313 --- /dev/null +++ b/JewelryStore/FormMain.Designer.cs @@ -0,0 +1,176 @@ +namespace JewelryStore +{ + 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.buttonReady = new System.Windows.Forms.Button(); + this.dataGridView = new System.Windows.Forms.DataGridView(); + this.buttonCreate = new System.Windows.Forms.Button(); + this.buttonToWork = new System.Windows.Forms.Button(); + this.buttonPut = new System.Windows.Forms.Button(); + this.buttonRefresh = new System.Windows.Forms.Button(); + this.menuStrip = 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(); + ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit(); + this.menuStrip.SuspendLayout(); + this.SuspendLayout(); + // + // buttonReady + // + this.buttonReady.Location = new System.Drawing.Point(1273, 225); + this.buttonReady.Name = "buttonReady"; + this.buttonReady.Size = new System.Drawing.Size(215, 34); + this.buttonReady.TabIndex = 3; + this.buttonReady.Text = "Заказ готов"; + this.buttonReady.UseVisualStyleBackColor = true; + this.buttonReady.Click += new System.EventHandler(this.buttonReady_Click); + // + // dataGridView + // + this.dataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; + this.dataGridView.Location = new System.Drawing.Point(9, 52); + this.dataGridView.Name = "dataGridView"; + this.dataGridView.RowHeadersWidth = 62; + this.dataGridView.RowTemplate.Height = 33; + this.dataGridView.Size = new System.Drawing.Size(1227, 386); + this.dataGridView.TabIndex = 0; + // + // buttonCreate + // + this.buttonCreate.Location = new System.Drawing.Point(1273, 52); + this.buttonCreate.Name = "buttonCreate"; + this.buttonCreate.Size = new System.Drawing.Size(215, 34); + this.buttonCreate.TabIndex = 1; + this.buttonCreate.Text = "Создать заказ"; + this.buttonCreate.UseVisualStyleBackColor = true; + this.buttonCreate.Click += new System.EventHandler(this.buttonCreate_Click); + // + // buttonToWork + // + this.buttonToWork.Location = new System.Drawing.Point(1273, 137); + this.buttonToWork.Name = "buttonToWork"; + this.buttonToWork.Size = new System.Drawing.Size(215, 34); + this.buttonToWork.TabIndex = 2; + this.buttonToWork.Text = "Отдать на выполнение"; + this.buttonToWork.UseVisualStyleBackColor = true; + this.buttonToWork.Click += new System.EventHandler(this.buttonToWork_Click); + // + // buttonPut + // + this.buttonPut.Location = new System.Drawing.Point(1273, 308); + this.buttonPut.Name = "buttonPut"; + this.buttonPut.Size = new System.Drawing.Size(215, 34); + this.buttonPut.TabIndex = 4; + this.buttonPut.Text = "Заказ выдан"; + this.buttonPut.UseVisualStyleBackColor = true; + this.buttonPut.Click += new System.EventHandler(this.buttonPut_Click); + // + // buttonRefresh + // + this.buttonRefresh.Location = new System.Drawing.Point(1273, 389); + this.buttonRefresh.Name = "buttonRefresh"; + this.buttonRefresh.Size = new System.Drawing.Size(215, 34); + this.buttonRefresh.TabIndex = 5; + this.buttonRefresh.Text = "Обновить список"; + this.buttonRefresh.UseVisualStyleBackColor = true; + this.buttonRefresh.Click += new System.EventHandler(this.buttonRefresh_Click); + // + // menuStrip + // + this.menuStrip.ImageScalingSize = new System.Drawing.Size(24, 24); + this.menuStrip.Items.AddRange(new System.Windows.Forms.ToolStripItem[] { + this.справочникиToolStripMenuItem}); + this.menuStrip.Location = new System.Drawing.Point(0, 0); + this.menuStrip.Name = "menuStrip"; + this.menuStrip.Size = new System.Drawing.Size(1530, 33); + this.menuStrip.TabIndex = 6; + this.menuStrip.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(139, 29); + this.справочникиToolStripMenuItem.Text = "Справочники"; + // + // компонентыToolStripMenuItem + // + this.компонентыToolStripMenuItem.Name = "компонентыToolStripMenuItem"; + this.компонентыToolStripMenuItem.Size = new System.Drawing.Size(240, 34); + this.компонентыToolStripMenuItem.Text = "Компоненты"; + this.компонентыToolStripMenuItem.Click += new System.EventHandler(this.компонентыToolStripMenuItem_Click); + // + // изделияToolStripMenuItem + // + this.изделияToolStripMenuItem.Name = "изделияToolStripMenuItem"; + this.изделияToolStripMenuItem.Size = new System.Drawing.Size(240, 34); + this.изделияToolStripMenuItem.Text = "Драгоценности"; + this.изделияToolStripMenuItem.Click += new System.EventHandler(this.драгоценностиToolStripMenuItem_Click); + // + // FormMain + // + this.AutoScaleDimensions = new System.Drawing.SizeF(10F, 25F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(1530, 450); + this.Controls.Add(this.buttonRefresh); + this.Controls.Add(this.buttonPut); + this.Controls.Add(this.buttonReady); + this.Controls.Add(this.buttonToWork); + this.Controls.Add(this.buttonCreate); + this.Controls.Add(this.dataGridView); + this.Controls.Add(this.menuStrip); + this.MainMenuStrip = this.menuStrip; + this.Name = "FormMain"; + this.Text = "Изготовление Драгоценностей"; + this.Load += new System.EventHandler(this.FormMain_Load); + ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).EndInit(); + this.menuStrip.ResumeLayout(false); + this.menuStrip.PerformLayout(); + this.ResumeLayout(false); + this.PerformLayout(); + + } + + #endregion + + private DataGridView dataGridView; + private Button buttonCreate; + private Button buttonToWork; + private Button buttonPut; + private Button buttonRefresh; + private MenuStrip menuStrip; + private ToolStripMenuItem справочникиToolStripMenuItem; + private ToolStripMenuItem компонентыToolStripMenuItem; + private ToolStripMenuItem изделияToolStripMenuItem; + private Button buttonReady; + } +} \ No newline at end of file diff --git a/JewelryStore/FormMain.cs b/JewelryStore/FormMain.cs new file mode 100644 index 0000000..3baf773 --- /dev/null +++ b/JewelryStore/FormMain.cs @@ -0,0 +1,193 @@ +using JewelryStoreContracts.BindingModels; +using JewelryStoreContracts.BusinessLogicsContracts; +using JewelryStoreDataModels.Enums; +using Microsoft.Extensions.Logging; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; + +namespace JewelryStore +{ + 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["JewelId"].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(FormComponents)); + if (service is FormComponents form) + { + form.ShowDialog(); + } + } + + private void драгоценностиToolStripMenuItem_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormJewels)); + + if (service is FormJewels form) + { + form.ShowDialog(); + } + } + + private void buttonCreate_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormCreateOrder)); + if (service is FormCreateOrder form) + { + form.ShowDialog(); + LoadData(); + } + } + + private void buttonToWork_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, + JewelId = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["JewelId"].Value), + JewelName = dataGridView.SelectedRows[0].Cells["JewelName"].Value.ToString(), + Status = Enum.Parse(dataGridView.SelectedRows[0].Cells["Status"].Value.ToString()), + Count = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Count"].Value), + Sum = double.Parse(dataGridView.SelectedRows[0].Cells["Sum"].Value.ToString()), + 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 buttonReady_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, + JewelId = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["JewelId"].Value), + JewelName = dataGridView.SelectedRows[0].Cells["JewelName"].Value.ToString(), + Status = Enum.Parse(dataGridView.SelectedRows[0].Cells["Status"].Value.ToString()), + Count = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Count"].Value), + Sum = double.Parse(dataGridView.SelectedRows[0].Cells["Sum"].Value.ToString()), + 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 buttonPut_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, + JewelId = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["JewelId"].Value), + JewelName = dataGridView.SelectedRows[0].Cells["JewelName"].Value.ToString(), + Status = Enum.Parse(dataGridView.SelectedRows[0].Cells["Status"].Value.ToString()), + Count = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Count"].Value), + Sum = double.Parse(dataGridView.SelectedRows[0].Cells["Sum"].Value.ToString()), + 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 buttonRefresh_Click(object sender, EventArgs e) + { + LoadData(); + } + } +} diff --git a/JewelryStore/FormMain.resx b/JewelryStore/FormMain.resx new file mode 100644 index 0000000..81a9e3d --- /dev/null +++ b/JewelryStore/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/JewelryStore/JewelryStore.csproj b/JewelryStore/JewelryStore.csproj index b57c89e..90bafab 100644 --- a/JewelryStore/JewelryStore.csproj +++ b/JewelryStore/JewelryStore.csproj @@ -8,4 +8,15 @@ enable + + + + + + + + + + + \ No newline at end of file diff --git a/JewelryStore/JewelryStore.sln b/JewelryStore/JewelryStore.sln index e6cc653..08fec75 100644 --- a/JewelryStore/JewelryStore.sln +++ b/JewelryStore/JewelryStore.sln @@ -3,7 +3,15 @@ Microsoft Visual Studio Solution File, Format Version 12.00 # Visual Studio Version 17 VisualStudioVersion = 17.4.33122.133 MinimumVisualStudioVersion = 10.0.40219.1 -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "JewelryStore", "JewelryStore.csproj", "{F1AEB85A-E5E1-4B07-8D6B-E46870480FFA}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "JewelryStore", "JewelryStore.csproj", "{F1AEB85A-E5E1-4B07-8D6B-E46870480FFA}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "JewelryStoreContracts", "..\JewelryStoreContracts\JewelryStoreContracts.csproj", "{763B1FD7-7D30-4689-869C-1FEAD240B29B}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "JewelryStoreDataModels", "..\JewelryStoreDataModels\JewelryStoreDataModels.csproj", "{84BF2156-F821-46F4-8EED-F371084C0129}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "JewelryStoreBusinessLogic", "..\JewelryStoreBusinessLogic\JewelryStoreBusinessLogic.csproj", "{DA57067F-F3ED-4B1C-B56F-52856FC2E93D}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "JewelryStoreListImplement", "..\JewelryStoreListImplement\JewelryStoreListImplement.csproj", "{B8C8AA30-FC16-4331-B456-CD16C3C97B25}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution @@ -15,6 +23,22 @@ Global {F1AEB85A-E5E1-4B07-8D6B-E46870480FFA}.Debug|Any CPU.Build.0 = Debug|Any CPU {F1AEB85A-E5E1-4B07-8D6B-E46870480FFA}.Release|Any CPU.ActiveCfg = Release|Any CPU {F1AEB85A-E5E1-4B07-8D6B-E46870480FFA}.Release|Any CPU.Build.0 = Release|Any CPU + {763B1FD7-7D30-4689-869C-1FEAD240B29B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {763B1FD7-7D30-4689-869C-1FEAD240B29B}.Debug|Any CPU.Build.0 = Debug|Any CPU + {763B1FD7-7D30-4689-869C-1FEAD240B29B}.Release|Any CPU.ActiveCfg = Release|Any CPU + {763B1FD7-7D30-4689-869C-1FEAD240B29B}.Release|Any CPU.Build.0 = Release|Any CPU + {84BF2156-F821-46F4-8EED-F371084C0129}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {84BF2156-F821-46F4-8EED-F371084C0129}.Debug|Any CPU.Build.0 = Debug|Any CPU + {84BF2156-F821-46F4-8EED-F371084C0129}.Release|Any CPU.ActiveCfg = Release|Any CPU + {84BF2156-F821-46F4-8EED-F371084C0129}.Release|Any CPU.Build.0 = Release|Any CPU + {DA57067F-F3ED-4B1C-B56F-52856FC2E93D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {DA57067F-F3ED-4B1C-B56F-52856FC2E93D}.Debug|Any CPU.Build.0 = Debug|Any CPU + {DA57067F-F3ED-4B1C-B56F-52856FC2E93D}.Release|Any CPU.ActiveCfg = Release|Any CPU + {DA57067F-F3ED-4B1C-B56F-52856FC2E93D}.Release|Any CPU.Build.0 = Release|Any CPU + {B8C8AA30-FC16-4331-B456-CD16C3C97B25}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {B8C8AA30-FC16-4331-B456-CD16C3C97B25}.Debug|Any CPU.Build.0 = Debug|Any CPU + {B8C8AA30-FC16-4331-B456-CD16C3C97B25}.Release|Any CPU.ActiveCfg = Release|Any CPU + {B8C8AA30-FC16-4331-B456-CD16C3C97B25}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/JewelryStore/Program.cs b/JewelryStore/Program.cs index c4650cd..4a4a47e 100644 --- a/JewelryStore/Program.cs +++ b/JewelryStore/Program.cs @@ -1,17 +1,56 @@ +using JewelryStoreContracts.BusinessLogicsContracts; +using JewelryStoreContracts.StoragesContracts; +using JewelryStoreBusinessLogic.BusinessLogics; +using JewelryStoreListImplement.Implements; + +using Microsoft.Extensions.DependencyInjection; +using System.Drawing; +using Microsoft.Extensions.Logging; +using NLog.Extensions.Logging; + + namespace JewelryStore { internal static class Program { + private static ServiceProvider? _serviceProvider; + public static ServiceProvider? ServiceProvider => _serviceProvider; /// - /// The main entry point for the application. + /// The main entry point for the application. /// [STAThread] static void Main() { - // To customize application configuration such as set high DPI settings or default font, - // see https://aka.ms/applicationconfiguration. - ApplicationConfiguration.Initialize(); - Application.Run(new Form1()); + // To customize application configuration such as set high DPI + //settings or default font, + // see https://aka.ms/applicationconfiguration. + ApplicationConfiguration.Initialize(); + 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/JewelryStoreBusinessLogic/BusinessLogics/ComponentLogic.cs b/JewelryStoreBusinessLogic/BusinessLogics/ComponentLogic.cs new file mode 100644 index 0000000..ea507ce --- /dev/null +++ b/JewelryStoreBusinessLogic/BusinessLogics/ComponentLogic.cs @@ -0,0 +1,117 @@ +using JewelryStoreContracts.BindingModels; +using JewelryStoreContracts.BusinessLogicsContracts; +using JewelryStoreContracts.SearchModels; +using JewelryStoreContracts.StoragesContracts; +using JewelryStoreContracts.ViewModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Microsoft.Extensions.Logging; + + +namespace JewelryStoreBusinessLogic.BusinessLogics +{ + public class ComponentLogic : IComponentLogic + { + private readonly ILogger _logger; + private readonly IComponentStorage _componentStorage; + public ComponentLogic(ILogger logger, IComponentStorage + componentStorage) + { + _logger = logger; + _componentStorage = componentStorage; + } + public List? ReadList(ComponentSearchModel? model) + { + _logger.LogInformation("ReadList. ComponentName:{ComponentName}.Id:{ Id}", model?.ComponentName, model?.Id); + var list = model == null ? _componentStorage.GetFullList() :_componentStorage.GetFilteredList(model); + if (list == null) + { + _logger.LogWarning("ReadList return null list"); + return null; + } + _logger.LogInformation("ReadList. Count:{Count}", list.Count); + return list; + } + public ComponentViewModel? ReadElement(ComponentSearchModel model) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + _logger.LogInformation("ReadElement. ComponentName:{ComponentName}.Id:{ Id}", model.ComponentName, model.Id); + var element = _componentStorage.GetElement(model); + if (element == null) + { + _logger.LogWarning("ReadElement element not found"); + return null; + } + _logger.LogInformation("ReadElement find. Id:{Id}", element.Id); + return element; + } + public bool Create(ComponentBindingModel model) + { + CheckModel(model); + if (_componentStorage.Insert(model) == null) + { + _logger.LogWarning("Insert operation failed"); + return false; + } + return true; + } + public bool Update(ComponentBindingModel model) + { + CheckModel(model); + if (_componentStorage.Update(model) == null) + { + _logger.LogWarning("Update operation failed"); + return false; + } + return true; + } + public bool Delete(ComponentBindingModel model) + { + CheckModel(model, false); + _logger.LogInformation("Delete. Id:{Id}", model.Id); + if (_componentStorage.Delete(model) == null) + { + _logger.LogWarning("Delete operation failed"); + return false; + } + return true; + } + private void CheckModel(ComponentBindingModel model, bool withParams = + true) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + if (!withParams) + { + return; + } + if (string.IsNullOrEmpty(model.ComponentName)) + { + throw new ArgumentNullException("Нет названия компонента", + nameof(model.ComponentName)); + } + if (model.Cost <= 0) + { + throw new ArgumentNullException("Цена компонента должна быть больше 0", nameof(model.Cost)); + } + _logger.LogInformation("Component. ComponentName:{ComponentName}. Cost:{ Cost}. Id: { Id}", model.ComponentName, model.Cost, model.Id); + var element = _componentStorage.GetElement(new ComponentSearchModel + { + ComponentName = model.ComponentName + }); + if (element != null && element.Id != model.Id) + { + throw new InvalidOperationException("Компонент с таким названием уже есть"); + } + } + } + +} diff --git a/JewelryStoreBusinessLogic/BusinessLogics/JewelLogic.cs b/JewelryStoreBusinessLogic/BusinessLogics/JewelLogic.cs new file mode 100644 index 0000000..27b6d07 --- /dev/null +++ b/JewelryStoreBusinessLogic/BusinessLogics/JewelLogic.cs @@ -0,0 +1,120 @@ +using JewelryStoreContracts.BindingModels; +using JewelryStoreContracts.BusinessLogicsContracts; +using JewelryStoreContracts.SearchModels; +using JewelryStoreContracts.StoragesContracts; +using JewelryStoreContracts.ViewModels; +using Microsoft.Extensions.Logging; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace JewelryStoreBusinessLogic.BusinessLogics +{ + public class JewelLogic : IJewelLogic // TODO реализовать интерфейс идентично componentLogic + { + private readonly ILogger _logger; + private readonly IJewelStorage _jewelStorage; + + public JewelLogic(ILogger logger, IJewelStorage jewelStorage) + { + _logger = logger; + _jewelStorage= jewelStorage; + } + + public bool Create(JewelBindingModel model) + { + CheckModel(model); + if (_jewelStorage.Insert(model) == null) + { + _logger.LogWarning("Insert operation failed"); + return false; + } + return true; + } + + public bool Delete(JewelBindingModel model) + { + CheckModel(model, false); + _logger.LogInformation("Delete. Id:{Id}", model.Id); + if (_jewelStorage.Delete(model) == null) + { + _logger.LogWarning("Delete operation failed"); + return false; + } + return true; + } + + public JewelViewModel? ReadElement(JewelSearchModel model) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + _logger.LogInformation("ReadElement. JewelName:{JewelName}.Id:{ Id}", model.JewelName, model.Id); + var element = _jewelStorage.GetElement(model); + if (element == null) + { + _logger.LogWarning("ReadElement element not found"); + return null; + } + _logger.LogInformation("ReadElement find. Id:{Id}", element.Id); + return element; + } + + public List? ReadList(JewelSearchModel? model) + { + _logger.LogInformation("ReadList. JewelName:{JeweltName}.Id:{ Id}", model?.JewelName, model?.Id); + var list = model == null ? _jewelStorage.GetFullList() : _jewelStorage.GetFilteredList(model); + if (list == null) + { + _logger.LogWarning("ReadList return null list"); + return null; + } + _logger.LogInformation("ReadList. Count:{Count}", list.Count); + return list; + } + + public bool Update(JewelBindingModel model) + { + CheckModel(model); + if (_jewelStorage.Update(model) == null) + { + _logger.LogWarning("Update operation failed"); + return false; + } + return true; + } + private void CheckModel(JewelBindingModel model, bool withParams = + true) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + if (!withParams) + { + return; + } + if (string.IsNullOrEmpty(model.JewelName)) + { + throw new ArgumentNullException("Нет названия драгоценности", + nameof(model.JewelName)); + } + if (model.Price <= 0) + { + throw new ArgumentNullException("Цена драгоценности должна быть больше 0", nameof(model.Price)); + } + _logger.LogInformation("Jewel. JewelName:{JewelName}. Price:{ Price}. Id: { Id}", model.JewelName, model.Price, model.Id); + var element = _jewelStorage.GetElement(new JewelSearchModel + { + JewelName = model.JewelName + }); + if (element != null && element.Id != model.Id) + { + throw new InvalidOperationException("Драгоценность с таким названием уже есть"); + } + } + } +} diff --git a/JewelryStoreBusinessLogic/BusinessLogics/OrderLogic.cs b/JewelryStoreBusinessLogic/BusinessLogics/OrderLogic.cs new file mode 100644 index 0000000..6bcfa52 --- /dev/null +++ b/JewelryStoreBusinessLogic/BusinessLogics/OrderLogic.cs @@ -0,0 +1,130 @@ +using JewelryStoreContracts.BindingModels; +using JewelryStoreContracts.BusinessLogicsContracts; +using JewelryStoreContracts.SearchModels; +using JewelryStoreContracts.StoragesContracts; +using JewelryStoreContracts.ViewModels; +using JewelryStoreDataModels.Enums; +using Microsoft.Extensions.Logging; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace JewelryStoreBusinessLogic.BusinessLogics +{ + public class OrderLogic : IOrderLogic //TODO реализовать интерфейс + { + // Класс с логикой для заказов будет отвечать за получение списка заказов, + //создания заказа и смены его статусов.Следует учитывать, что у заказа можно + //менять статус на новый, если его текущий статус предшествует новому + //(например, в статус «Готов» можно переводить, если заказ находится в статусе + //«Выполняется»). + private readonly ILogger _logger; + private readonly IOrderStorage _orderStorage; + public OrderLogic(ILogger logger, IOrderStorage orderStorage) + { + _logger = logger; + _orderStorage = orderStorage; + } + + public bool CreateOrder(OrderBindingModel model) + { + CheckModel(model); + if (model.Status != OrderStatus.Неизвестен) return false; + model.Status = OrderStatus.Принят; + if (_orderStorage.Insert(model) == null) + { + _logger.LogWarning("Insert operation failed"); + return false; + } + return true; + } + + public bool DeliveryOrder(OrderBindingModel model) + { + CheckModel(model); + if (model.Status != OrderStatus.Готов) return false; + + model.Status = OrderStatus.Выдан; + model.DateImplement = DateTime.Now; + if (_orderStorage.Update(model) == null) + { + _logger.LogWarning("Update operation failed"); + return false; + } + return true; + } + + public bool FinishOrder(OrderBindingModel model) + { + CheckModel(model); + if (model.Status != OrderStatus.Выполняется) return false; + + model.Status = OrderStatus.Готов; + if (_orderStorage.Update(model) == null) + { + _logger.LogWarning("Update operation failed"); + return false; + } + return true; + } + + public List? ReadList(OrderSearchModel? model) + { + _logger.LogInformation("ReadList. OrderId:{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 TakeOrderInWork(OrderBindingModel model) + { + CheckModel(model); + if (model.Status != OrderStatus.Принят) return false; + model.Status = OrderStatus.Выполняется; + if (_orderStorage.Update(model) == null) + { + _logger.LogWarning("Update 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.JewelId < 0) + { + throw new ArgumentNullException("Некорректный идентификатор драгоценности", nameof(model.JewelId)); + } + + 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}. JewelId: { JewelId}", model.Id, model.Sum, model.JewelId); + } + + } +} diff --git a/JewelryStoreBusinessLogic/JewelryStoreBusinessLogic.csproj b/JewelryStoreBusinessLogic/JewelryStoreBusinessLogic.csproj new file mode 100644 index 0000000..7e1df35 --- /dev/null +++ b/JewelryStoreBusinessLogic/JewelryStoreBusinessLogic.csproj @@ -0,0 +1,17 @@ + + + + net6.0 + enable + enable + + + + + + + + + + + diff --git a/JewelryStoreContracts/BindingModels/ComponentBindingModel.cs b/JewelryStoreContracts/BindingModels/ComponentBindingModel.cs new file mode 100644 index 0000000..f2f424e --- /dev/null +++ b/JewelryStoreContracts/BindingModels/ComponentBindingModel.cs @@ -0,0 +1,17 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using JewelryStoreDataModels.Models; + +namespace JewelryStoreContracts.BindingModels +{ + public class ComponentBindingModel : IComponentModel + { + public int Id { get; set; } + public string ComponentName { get; set; } = string.Empty; + public double Cost { get; set; } + } + +} diff --git a/JewelryStoreContracts/BindingModels/JewelBindingModel.cs b/JewelryStoreContracts/BindingModels/JewelBindingModel.cs new file mode 100644 index 0000000..cb6965c --- /dev/null +++ b/JewelryStoreContracts/BindingModels/JewelBindingModel.cs @@ -0,0 +1,17 @@ +using JewelryStoreDataModels.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace JewelryStoreContracts.BindingModels +{ + public class JewelBindingModel : IJewelModel + { + public int Id { get; set; } + public string JewelName { get; set; } = string.Empty; + public double Price { get; set; } + public Dictionary JewelComponents { get; set;} = new(); + } +} diff --git a/JewelryStoreContracts/BindingModels/OrderBindingModel.cs b/JewelryStoreContracts/BindingModels/OrderBindingModel.cs new file mode 100644 index 0000000..37e87a9 --- /dev/null +++ b/JewelryStoreContracts/BindingModels/OrderBindingModel.cs @@ -0,0 +1,23 @@ +using JewelryStoreDataModels.Enums; +using JewelryStoreDataModels.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace JewelryStoreContracts.BindingModels +{ + public class OrderBindingModel : IOrderModel + { + public int Id { get; set; } + public int JewelId { get; set; } + public string JewelName { 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/JewelryStoreContracts/BusinessLogicsContracts/IComponentLogic.cs b/JewelryStoreContracts/BusinessLogicsContracts/IComponentLogic.cs new file mode 100644 index 0000000..17cc2cd --- /dev/null +++ b/JewelryStoreContracts/BusinessLogicsContracts/IComponentLogic.cs @@ -0,0 +1,21 @@ +using JewelryStoreContracts.BindingModels; +using JewelryStoreContracts.SearchModels; +using JewelryStoreContracts.ViewModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace JewelryStoreContracts.BusinessLogicsContracts +{ + public interface IComponentLogic + { + List? ReadList(ComponentSearchModel? model); + ComponentViewModel? ReadElement(ComponentSearchModel model); + bool Create(ComponentBindingModel model); + bool Update(ComponentBindingModel model); + bool Delete(ComponentBindingModel model); + } + +} diff --git a/JewelryStoreContracts/BusinessLogicsContracts/IJewelLogic.cs b/JewelryStoreContracts/BusinessLogicsContracts/IJewelLogic.cs new file mode 100644 index 0000000..8a67266 --- /dev/null +++ b/JewelryStoreContracts/BusinessLogicsContracts/IJewelLogic.cs @@ -0,0 +1,23 @@ +using JewelryStoreContracts.SearchModels; +using JewelryStoreContracts.ViewModels; +using JewelryStoreContracts.BindingModels; + +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace JewelryStoreContracts.BusinessLogicsContracts +{ + public interface IJewelLogic + { + List? ReadList(JewelSearchModel? model); + JewelViewModel? ReadElement(JewelSearchModel model); + bool Create(JewelBindingModel model); + bool Update(JewelBindingModel model); + + bool Delete(JewelBindingModel model); + } + +} diff --git a/JewelryStoreContracts/BusinessLogicsContracts/IOrderLogic.cs b/JewelryStoreContracts/BusinessLogicsContracts/IOrderLogic.cs new file mode 100644 index 0000000..a403f30 --- /dev/null +++ b/JewelryStoreContracts/BusinessLogicsContracts/IOrderLogic.cs @@ -0,0 +1,20 @@ +using JewelryStoreContracts.BindingModels; +using JewelryStoreContracts.SearchModels; +using JewelryStoreContracts.ViewModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace JewelryStoreContracts.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/JewelryStoreContracts/JewelryStoreContracts.csproj b/JewelryStoreContracts/JewelryStoreContracts.csproj new file mode 100644 index 0000000..3c67a42 --- /dev/null +++ b/JewelryStoreContracts/JewelryStoreContracts.csproj @@ -0,0 +1,13 @@ + + + + net6.0 + enable + enable + + + + + + + diff --git a/JewelryStoreContracts/SearchModels/ComponentSearchModel.cs b/JewelryStoreContracts/SearchModels/ComponentSearchModel.cs new file mode 100644 index 0000000..7c626d0 --- /dev/null +++ b/JewelryStoreContracts/SearchModels/ComponentSearchModel.cs @@ -0,0 +1,14 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace JewelryStoreContracts.SearchModels +{ + public class ComponentSearchModel + { + public int? Id { get; set; } + public string? ComponentName { get; set; } + } +} diff --git a/JewelryStoreContracts/SearchModels/JewelSearchModel.cs b/JewelryStoreContracts/SearchModels/JewelSearchModel.cs new file mode 100644 index 0000000..568af39 --- /dev/null +++ b/JewelryStoreContracts/SearchModels/JewelSearchModel.cs @@ -0,0 +1,14 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace JewelryStoreContracts.SearchModels +{ + public class JewelSearchModel + { + public int? Id { get; set; } + public string? JewelName { get; set; } + } +} diff --git a/JewelryStoreContracts/SearchModels/OrderSearchModel.cs b/JewelryStoreContracts/SearchModels/OrderSearchModel.cs new file mode 100644 index 0000000..14133ed --- /dev/null +++ b/JewelryStoreContracts/SearchModels/OrderSearchModel.cs @@ -0,0 +1,13 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace JewelryStoreContracts.SearchModels +{ + public class OrderSearchModel + { + public int? Id { get; set; } + } +} diff --git a/JewelryStoreContracts/StoragesContracts/IComponentStorage.cs b/JewelryStoreContracts/StoragesContracts/IComponentStorage.cs new file mode 100644 index 0000000..2fd9c29 --- /dev/null +++ b/JewelryStoreContracts/StoragesContracts/IComponentStorage.cs @@ -0,0 +1,22 @@ +using JewelryStoreContracts.BindingModels; +using JewelryStoreContracts.SearchModels; +using JewelryStoreContracts.ViewModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace JewelryStoreContracts.StoragesContracts +{ + + public interface IComponentStorage + { + List GetFullList(); + List GetFilteredList(ComponentSearchModel model); + ComponentViewModel? GetElement(ComponentSearchModel model); + ComponentViewModel? Insert(ComponentBindingModel model); + ComponentViewModel? Update(ComponentBindingModel model); + ComponentViewModel? Delete(ComponentBindingModel model); + } +} diff --git a/JewelryStoreContracts/StoragesContracts/IJewelStorage.cs b/JewelryStoreContracts/StoragesContracts/IJewelStorage.cs new file mode 100644 index 0000000..16fef58 --- /dev/null +++ b/JewelryStoreContracts/StoragesContracts/IJewelStorage.cs @@ -0,0 +1,23 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using JewelryStoreContracts.BindingModels; +using JewelryStoreContracts.SearchModels; +using JewelryStoreContracts.ViewModels; + + +namespace JewelryStoreContracts.StoragesContracts +{ + public interface IJewelStorage + { + List GetFullList(); + List GetFilteredList(JewelSearchModel model); + JewelViewModel? GetElement(JewelSearchModel model); + JewelViewModel? Insert(JewelBindingModel model); + JewelViewModel? Update(JewelBindingModel model); + JewelViewModel? Delete(JewelBindingModel model); + } + +} diff --git a/JewelryStoreContracts/StoragesContracts/IOrderStorage.cs b/JewelryStoreContracts/StoragesContracts/IOrderStorage.cs new file mode 100644 index 0000000..3fb94e2 --- /dev/null +++ b/JewelryStoreContracts/StoragesContracts/IOrderStorage.cs @@ -0,0 +1,22 @@ +using JewelryStoreContracts.BindingModels; +using JewelryStoreContracts.SearchModels; +using JewelryStoreContracts.ViewModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace JewelryStoreContracts.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/JewelryStoreContracts/ViewModels/ComponentViewModel.cs b/JewelryStoreContracts/ViewModels/ComponentViewModel.cs new file mode 100644 index 0000000..dcd3252 --- /dev/null +++ b/JewelryStoreContracts/ViewModels/ComponentViewModel.cs @@ -0,0 +1,19 @@ +using JewelryStoreDataModels.Models; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace JewelryStoreContracts.ViewModels +{ + public class ComponentViewModel : IComponentModel + { + public int Id { get; set; } + [DisplayName("Название компонента")] + public string ComponentName { get; set; } = string.Empty; + [DisplayName("Цена")] + public double Cost { get; set; } + } +} diff --git a/JewelryStoreContracts/ViewModels/JewelViewModel.cs b/JewelryStoreContracts/ViewModels/JewelViewModel.cs new file mode 100644 index 0000000..f09420f --- /dev/null +++ b/JewelryStoreContracts/ViewModels/JewelViewModel.cs @@ -0,0 +1,25 @@ +using JewelryStoreDataModels.Models; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace JewelryStoreContracts.ViewModels +{ + public class JewelViewModel : IJewelModel + { + public int Id { get; set; } + [DisplayName("Название драгоценности")] + public string JewelName { get; set; } = string.Empty; + [DisplayName("Цена")] + public double Price { get; set; } + public Dictionary JewelComponents + { + get; + set; + } = new(); + } + +} diff --git a/JewelryStoreContracts/ViewModels/OrderViewModel.cs b/JewelryStoreContracts/ViewModels/OrderViewModel.cs new file mode 100644 index 0000000..ed81bd4 --- /dev/null +++ b/JewelryStoreContracts/ViewModels/OrderViewModel.cs @@ -0,0 +1,33 @@ +using JewelryStoreDataModels.Enums; +using JewelryStoreDataModels.Models; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace JewelryStoreContracts.ViewModels +{ + public class OrderViewModel : IOrderModel + { + [DisplayName("Номер")] + public int Id { get; set; } + public int JewelId { get; set; } + + [DisplayName("Драгоценность")] + public string JewelName { 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/JewelryStoreDataModels/Enums/OrderStatus.cs b/JewelryStoreDataModels/Enums/OrderStatus.cs new file mode 100644 index 0000000..7dd5f25 --- /dev/null +++ b/JewelryStoreDataModels/Enums/OrderStatus.cs @@ -0,0 +1,17 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace JewelryStoreDataModels.Enums +{ + public enum OrderStatus + { + Неизвестен = -1, + Принят = 0, + Выполняется = 1, + Готов = 2, + Выдан = 3 + } +} diff --git a/JewelryStoreDataModels/IId.cs b/JewelryStoreDataModels/IId.cs new file mode 100644 index 0000000..0c72069 --- /dev/null +++ b/JewelryStoreDataModels/IId.cs @@ -0,0 +1,7 @@ +namespace JewelryStoreDataModels +{ + public interface IId + { + int Id { get; } + } +} \ No newline at end of file diff --git a/JewelryStoreDataModels/JewelryStoreDataModels.csproj b/JewelryStoreDataModels/JewelryStoreDataModels.csproj new file mode 100644 index 0000000..132c02c --- /dev/null +++ b/JewelryStoreDataModels/JewelryStoreDataModels.csproj @@ -0,0 +1,9 @@ + + + + net6.0 + enable + enable + + + diff --git a/JewelryStoreDataModels/Models/IComponentModel.cs b/JewelryStoreDataModels/Models/IComponentModel.cs new file mode 100644 index 0000000..99b9ee7 --- /dev/null +++ b/JewelryStoreDataModels/Models/IComponentModel.cs @@ -0,0 +1,16 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Security.Cryptography; +using System.Text; +using System.Threading.Tasks; + +namespace JewelryStoreDataModels.Models +{ + public interface IComponentModel : IId + { + string ComponentName { get; } + double Cost { get; } + } + +} diff --git a/JewelryStoreDataModels/Models/IJewelModel.cs b/JewelryStoreDataModels/Models/IJewelModel.cs new file mode 100644 index 0000000..f4922b6 --- /dev/null +++ b/JewelryStoreDataModels/Models/IJewelModel.cs @@ -0,0 +1,16 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Security.Cryptography; +using System.Text; +using System.Threading.Tasks; + +namespace JewelryStoreDataModels.Models +{ + public interface IJewelModel : IId + { + string JewelName { get; } + double Price { get; } + Dictionary JewelComponents { get; } + } +} diff --git a/JewelryStoreDataModels/Models/IOrderModel.cs b/JewelryStoreDataModels/Models/IOrderModel.cs new file mode 100644 index 0000000..7de0c62 --- /dev/null +++ b/JewelryStoreDataModels/Models/IOrderModel.cs @@ -0,0 +1,24 @@ +using JewelryStoreDataModels.Enums; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Security.Cryptography; +using System.Text; +using System.Threading.Tasks; + +namespace JewelryStoreDataModels.Models +{ + public interface IOrderModel : IId + { + int JewelId { get; } + string JewelName { get; } + + + int Count { get; } + double Sum { get; } + OrderStatus Status { get; } + DateTime DateCreate { get; } + DateTime? DateImplement { get; } + } + +} diff --git a/JewelryStoreListImplement/DataListSingleton.cs b/JewelryStoreListImplement/DataListSingleton.cs new file mode 100644 index 0000000..1b280c4 --- /dev/null +++ b/JewelryStoreListImplement/DataListSingleton.cs @@ -0,0 +1,31 @@ +using JewelryStoreListImplement.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace JewelryStoreListImplement +{ + public class DataListSingleton + { + private static DataListSingleton? _instance; + public List Components { get; set; } + public List Orders { get; set; } + public List Jewels { get; set; } + private DataListSingleton() + { + Components = new List(); + Orders = new List(); + Jewels = new List(); + } + public static DataListSingleton GetInstance() + { + if (_instance == null) + { + _instance = new DataListSingleton(); + } + return _instance; + } + } +} diff --git a/JewelryStoreListImplement/Implements/ComponentStorage .cs b/JewelryStoreListImplement/Implements/ComponentStorage .cs new file mode 100644 index 0000000..b6270b0 --- /dev/null +++ b/JewelryStoreListImplement/Implements/ComponentStorage .cs @@ -0,0 +1,108 @@ +using JewelryStoreContracts.BindingModels; +using JewelryStoreContracts.SearchModels; +using JewelryStoreContracts.StoragesContracts; +using JewelryStoreContracts.ViewModels; +using JewelryStoreListImplement.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace JewelryStoreListImplement.Implements +{ + public class ComponentStorage : IComponentStorage + { + private readonly DataListSingleton _source; + public ComponentStorage() + { + _source = DataListSingleton.GetInstance(); + } + public List GetFullList() + { + var result = new List(); + foreach (var component in _source.Components) + { + result.Add(component.GetViewModel); + } + return result; + } + public List GetFilteredList(ComponentSearchModel + model) + { + var result = new List(); + if (string.IsNullOrEmpty(model.ComponentName)) + { + return result; + } + foreach (var component in _source.Components) + { + if (component.ComponentName.Contains(model.ComponentName)) + { + result.Add(component.GetViewModel); + } + } + return result; + } + public ComponentViewModel? GetElement(ComponentSearchModel model) + { + if (string.IsNullOrEmpty(model.ComponentName) && !model.Id.HasValue) + { + return null; + } + foreach (var component in _source.Components) + { + if ((!string.IsNullOrEmpty(model.ComponentName) && + component.ComponentName == model.ComponentName) || + (model.Id.HasValue && component.Id == model.Id)) + { + return component.GetViewModel; + } + } + return null; + } + public ComponentViewModel? Insert(ComponentBindingModel model) + { + model.Id = 1; + foreach (var component in _source.Components) + { + if (model.Id <= component.Id) + { + model.Id = component.Id + 1; + } + } + var newComponent = Component.Create(model); + if (newComponent == null) + { + return null; + } + _source.Components.Add(newComponent); + return newComponent.GetViewModel; + } + public ComponentViewModel? Update(ComponentBindingModel model) + { + foreach (var component in _source.Components) + { + if (component.Id == model.Id) + { + component.Update(model); + return component.GetViewModel; + } + } + return null; + } + public ComponentViewModel? Delete(ComponentBindingModel model) + { + for (int i = 0; i < _source.Components.Count; ++i) + { + if (_source.Components[i].Id == model.Id) + { + var element = _source.Components[i]; + _source.Components.RemoveAt(i); + return element.GetViewModel; + } + } + return null; + } + } +} diff --git a/JewelryStoreListImplement/Implements/JewelStorage.cs b/JewelryStoreListImplement/Implements/JewelStorage.cs new file mode 100644 index 0000000..e09b4ab --- /dev/null +++ b/JewelryStoreListImplement/Implements/JewelStorage.cs @@ -0,0 +1,112 @@ +using JewelryStoreContracts.BindingModels; +using JewelryStoreContracts.SearchModels; +using JewelryStoreContracts.StoragesContracts; +using JewelryStoreContracts.ViewModels; +using JewelryStoreListImplement.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace JewelryStoreListImplement.Implements +{ + public class JewelStorage : IJewelStorage // TODO реализовать интерфейс + { + private readonly DataListSingleton _source; + public JewelStorage() + { + _source = DataListSingleton.GetInstance(); + } + public JewelViewModel? Delete(JewelBindingModel model) + { + for (int i = 0; i < _source.Jewels.Count; ++i) + { + if (_source.Jewels[i].Id == model.Id) + { + var element = _source.Jewels[i]; + _source.Jewels.RemoveAt(i); + return element.GetViewModel; + } + } + return null; + } + + public JewelViewModel? GetElement(JewelSearchModel model) + { + if (string.IsNullOrEmpty(model.JewelName) && !model.Id.HasValue) + { + return null; + } + foreach (var jewel in _source.Jewels) + { + if ((!string.IsNullOrEmpty(model.JewelName) && + jewel.JewelName == model.JewelName) || + (model.Id.HasValue && jewel.Id == model.Id)) + { + return jewel.GetViewModel; + } + } + return null; + } + + public List GetFilteredList(JewelSearchModel model) + { + var result = new List(); + if (string.IsNullOrEmpty(model.JewelName)) + { + return result; + } + foreach (var jewel in _source.Jewels) + { + if (jewel.JewelName.Contains(model.JewelName)) + { + result.Add(jewel.GetViewModel); + } + } + return result; + } + + public List GetFullList() + { + var result = new List(); + foreach (var jewel in _source.Jewels) + { + result.Add(jewel.GetViewModel); + } + return result; + } + + public JewelViewModel? Insert(JewelBindingModel model) + { + model.Id = 1; + foreach (var jewel in _source.Jewels) + { + if (model.Id <= jewel.Id) + { + model.Id = jewel.Id + 1; + } + } + var newJewel = Jewel.Create(model); + if (newJewel == null) + { + return null; + } + _source.Jewels.Add(newJewel); + return newJewel.GetViewModel; + } + + public JewelViewModel? Update(JewelBindingModel model) + { + foreach (var jewel in _source.Jewels) + { + if (jewel.Id == model.Id) + { + jewel.Update(model); + return jewel.GetViewModel; + } + } + return null; + } + } +} diff --git a/JewelryStoreListImplement/Implements/OrderStorage.cs b/JewelryStoreListImplement/Implements/OrderStorage.cs new file mode 100644 index 0000000..ae9c7db --- /dev/null +++ b/JewelryStoreListImplement/Implements/OrderStorage.cs @@ -0,0 +1,110 @@ +using JewelryStoreContracts.BindingModels; +using JewelryStoreContracts.SearchModels; +using JewelryStoreContracts.StoragesContracts; +using JewelryStoreContracts.ViewModels; +using JewelryStoreListImplement.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace JewelryStoreListImplement.Implements +{ + public class OrderStorage : IOrderStorage // TODO реализовать интерфейс + { + private readonly DataListSingleton _source; + public OrderStorage() + { + _source = DataListSingleton.GetInstance(); + } + 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; + } + + 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 List GetFilteredList(OrderSearchModel model) + { + var result = new List(); + if (model == null) + { + return result; + } + foreach (var order in _source.Orders) + { + if (order.Id == model.Id) + { + result.Add(order.GetViewModel); + } + } + return result; + } + + public List GetFullList() + { + var result = new List(); + foreach (var order in _source.Orders) + { + result.Add(order.GetViewModel); + } + return result; + } + + 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; + } + } +} diff --git a/JewelryStoreListImplement/JewelryStoreListImplement.csproj b/JewelryStoreListImplement/JewelryStoreListImplement.csproj new file mode 100644 index 0000000..783cc4d --- /dev/null +++ b/JewelryStoreListImplement/JewelryStoreListImplement.csproj @@ -0,0 +1,14 @@ + + + + net6.0 + enable + enable + + + + + + + + diff --git a/JewelryStoreListImplement/Models/Component.cs b/JewelryStoreListImplement/Models/Component.cs new file mode 100644 index 0000000..be9adee --- /dev/null +++ b/JewelryStoreListImplement/Models/Component.cs @@ -0,0 +1,47 @@ +using JewelryStoreContracts.BindingModels; +using JewelryStoreContracts.ViewModels; +using JewelryStoreDataModels.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace JewelryStoreListImplement.Models +{ + public class Component : IComponentModel + { + public int Id { get; private set; } + public string ComponentName { get; private set; } = string.Empty; + public double Cost { get; set; } + public static Component? Create(ComponentBindingModel? model) + { + if (model == null) + { + return null; + } + return new Component() + { + Id = model.Id, + ComponentName = model.ComponentName, + Cost = model.Cost + }; + } + public void Update(ComponentBindingModel? model) + { + if (model == null) + { + return; + } + ComponentName = model.ComponentName; + Cost = model.Cost; + } + public ComponentViewModel GetViewModel => new() + { + Id = Id, + ComponentName = ComponentName, + Cost = Cost + }; + } + +} diff --git a/JewelryStoreListImplement/Models/Jewel.cs b/JewelryStoreListImplement/Models/Jewel.cs new file mode 100644 index 0000000..2ba83ef --- /dev/null +++ b/JewelryStoreListImplement/Models/Jewel.cs @@ -0,0 +1,55 @@ +using JewelryStoreDataModels.Models; +using JewelryStoreContracts.ViewModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using JewelryStoreContracts.BindingModels; + +namespace JewelryStoreListImplement.Models +{ + public class Jewel: IJewelModel + { + public int Id { get; private set; } + public string JewelName { get; private set; } = string.Empty; + public double Price { get; private set; } + public Dictionary JewelComponents + { + get; + private set; + } = new Dictionary(); + public static Jewel? Create(JewelBindingModel? model) + { + if (model == null) + { + return null; + } + return new Jewel() + { + Id = model.Id, + JewelName = model.JewelName, + Price = model.Price, + JewelComponents = model.JewelComponents + }; + } + public void Update(JewelBindingModel? model) + { + if (model == null) + { + return; + } + JewelName = model.JewelName; + Price = model.Price; + JewelComponents = model.JewelComponents; + } + public JewelViewModel GetViewModel => new() + { + Id = Id, + JewelName = JewelName, + Price = Price, + JewelComponents = JewelComponents + }; + + } +} diff --git a/JewelryStoreListImplement/Models/Order.cs b/JewelryStoreListImplement/Models/Order.cs new file mode 100644 index 0000000..12349c8 --- /dev/null +++ b/JewelryStoreListImplement/Models/Order.cs @@ -0,0 +1,73 @@ +using JewelryStoreContracts.BindingModels; +using JewelryStoreContracts.ViewModels; +using JewelryStoreDataModels.Enums; +using JewelryStoreDataModels.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace JewelryStoreListImplement.Models +{ + public class Order : IOrderModel // TODO Класс для модели сущности «Заказ» разработать самостоятельно + { + public int JewelId { get; private set; } + public string JewelName { 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 int Id { get; private set; } + public static Order? Create(OrderBindingModel? model) + { + if (model == null) + { + return null; + } + return new Order() + { + Id = model.Id, + JewelId = model.JewelId, + JewelName = model.JewelName, + Count = model.Count, + Sum = model.Sum, + Status = model.Status, + DateCreate = model.DateCreate, + DateImplement = model.DateImplement + }; + } + public void Update(OrderBindingModel? model) + { + if (model == null) + { + return; + } + JewelId = model.JewelId; + JewelName = model.JewelName; + Count = model.Count; + Sum = model.Sum; + Status = model.Status; + DateCreate = model.DateCreate; + DateImplement = model.DateImplement; + } + public OrderViewModel GetViewModel => new() + { + Id = Id, + JewelId = JewelId, + JewelName = JewelName, + Count = Count, + Sum = Sum, + Status = Status, + DateCreate = DateCreate, + DateImplement = DateImplement + }; + } +}