diff --git a/JewelryStore/FormImplementer.Designer.cs b/JewelryStore/FormImplementer.Designer.cs new file mode 100644 index 0000000..e29f282 --- /dev/null +++ b/JewelryStore/FormImplementer.Designer.cs @@ -0,0 +1,167 @@ +namespace JewelryStore +{ + partial class FormImplementer + { + /// + /// 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.FIOTextBox = new System.Windows.Forms.TextBox(); + this.PasswordTextBox = new System.Windows.Forms.TextBox(); + this.LabelFIO = new System.Windows.Forms.Label(); + this.LabelPassword = new System.Windows.Forms.Label(); + this.QualificationNumericUpDown = new System.Windows.Forms.NumericUpDown(); + this.WorkExpNumericUpDown = new System.Windows.Forms.NumericUpDown(); + this.LabelWorkExperience = new System.Windows.Forms.Label(); + this.LabelQualification = new System.Windows.Forms.Label(); + this.ButtonCancel = new System.Windows.Forms.Button(); + this.ButtonSave = new System.Windows.Forms.Button(); + ((System.ComponentModel.ISupportInitialize)(this.QualificationNumericUpDown)).BeginInit(); + ((System.ComponentModel.ISupportInitialize)(this.WorkExpNumericUpDown)).BeginInit(); + this.SuspendLayout(); + // + // FIOTextBox + // + this.FIOTextBox.Location = new System.Drawing.Point(112, 12); + this.FIOTextBox.Name = "FIOTextBox"; + this.FIOTextBox.Size = new System.Drawing.Size(170, 23); + this.FIOTextBox.TabIndex = 0; + // + // PasswordTextBox + // + this.PasswordTextBox.Location = new System.Drawing.Point(112, 49); + this.PasswordTextBox.Name = "PasswordTextBox"; + this.PasswordTextBox.Size = new System.Drawing.Size(170, 23); + this.PasswordTextBox.TabIndex = 1; + // + // LabelFIO + // + this.LabelFIO.AutoSize = true; + this.LabelFIO.Location = new System.Drawing.Point(12, 15); + this.LabelFIO.Name = "LabelFIO"; + this.LabelFIO.Size = new System.Drawing.Size(40, 15); + this.LabelFIO.TabIndex = 2; + this.LabelFIO.Text = "ФИО: "; + // + // LabelPassword + // + this.LabelPassword.AutoSize = true; + this.LabelPassword.Location = new System.Drawing.Point(12, 52); + this.LabelPassword.Name = "LabelPassword"; + this.LabelPassword.Size = new System.Drawing.Size(55, 15); + this.LabelPassword.TabIndex = 3; + this.LabelPassword.Text = "Пароль: "; + // + // QualificationNumericUpDown + // + this.QualificationNumericUpDown.Location = new System.Drawing.Point(112, 131); + this.QualificationNumericUpDown.Name = "QualificationNumericUpDown"; + this.QualificationNumericUpDown.Size = new System.Drawing.Size(170, 23); + this.QualificationNumericUpDown.TabIndex = 4; + // + // WorkExpNumericUpDown + // + this.WorkExpNumericUpDown.Location = new System.Drawing.Point(112, 90); + this.WorkExpNumericUpDown.Name = "WorkExpNumericUpDown"; + this.WorkExpNumericUpDown.Size = new System.Drawing.Size(170, 23); + this.WorkExpNumericUpDown.TabIndex = 5; + // + // LabelWorkExperience + // + this.LabelWorkExperience.AutoSize = true; + this.LabelWorkExperience.Location = new System.Drawing.Point(12, 92); + this.LabelWorkExperience.Name = "LabelWorkExperience"; + this.LabelWorkExperience.Size = new System.Drawing.Size(87, 15); + this.LabelWorkExperience.TabIndex = 6; + this.LabelWorkExperience.Text = "Опыт работы: "; + // + // LabelQualification + // + this.LabelQualification.AutoSize = true; + this.LabelQualification.Location = new System.Drawing.Point(12, 133); + this.LabelQualification.Name = "LabelQualification"; + this.LabelQualification.Size = new System.Drawing.Size(94, 15); + this.LabelQualification.TabIndex = 7; + this.LabelQualification.Text = "Квалификация: "; + // + // ButtonCancel + // + this.ButtonCancel.Location = new System.Drawing.Point(185, 169); + this.ButtonCancel.Name = "ButtonCancel"; + this.ButtonCancel.Size = new System.Drawing.Size(97, 29); + this.ButtonCancel.TabIndex = 8; + this.ButtonCancel.Text = "Отмена"; + this.ButtonCancel.UseVisualStyleBackColor = true; + this.ButtonCancel.Click += new System.EventHandler(this.ButtonCancel_Click); + // + // ButtonSave + // + this.ButtonSave.Location = new System.Drawing.Point(82, 169); + this.ButtonSave.Name = "ButtonSave"; + this.ButtonSave.Size = new System.Drawing.Size(97, 29); + this.ButtonSave.TabIndex = 9; + this.ButtonSave.Text = "Сохранить"; + this.ButtonSave.UseVisualStyleBackColor = true; + this.ButtonSave.Click += new System.EventHandler(this.ButtonSave_Click); + // + // FormImplementer + // + this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(306, 214); + this.Controls.Add(this.ButtonSave); + this.Controls.Add(this.ButtonCancel); + this.Controls.Add(this.LabelQualification); + this.Controls.Add(this.LabelWorkExperience); + this.Controls.Add(this.WorkExpNumericUpDown); + this.Controls.Add(this.QualificationNumericUpDown); + this.Controls.Add(this.LabelPassword); + this.Controls.Add(this.LabelFIO); + this.Controls.Add(this.PasswordTextBox); + this.Controls.Add(this.FIOTextBox); + this.Name = "FormImplementer"; + this.Text = "Исполнитель"; + this.Load += new System.EventHandler(this.FormImplementer_Load); + ((System.ComponentModel.ISupportInitialize)(this.QualificationNumericUpDown)).EndInit(); + ((System.ComponentModel.ISupportInitialize)(this.WorkExpNumericUpDown)).EndInit(); + this.ResumeLayout(false); + this.PerformLayout(); + + } + + #endregion + + private TextBox FIOTextBox; + private TextBox PasswordTextBox; + private Label LabelFIO; + private Label LabelPassword; + private NumericUpDown QualificationNumericUpDown; + private NumericUpDown WorkExpNumericUpDown; + private Label LabelWorkExperience; + private Label LabelQualification; + private Button ButtonCancel; + private Button ButtonSave; + } +} \ No newline at end of file diff --git a/JewelryStore/FormImplementer.cs b/JewelryStore/FormImplementer.cs new file mode 100644 index 0000000..241fcfa --- /dev/null +++ b/JewelryStore/FormImplementer.cs @@ -0,0 +1,107 @@ +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 FormImplementer : Form + { + private readonly ILogger _logger; + private readonly IImplementerLogic _logic; + private int? _id; + public int Id { set { _id = value; } } + + public FormImplementer(ILogger logger, IImplementerLogic logic) + { + InitializeComponent(); + _logger = logger; + _logic = logic; + } + + private void ButtonSave_Click(object sender, EventArgs e) + { + if (string.IsNullOrEmpty(PasswordTextBox.Text)) + { + MessageBox.Show("Заполните пароль", "Ошибка", + MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + if (string.IsNullOrEmpty(FIOTextBox.Text)) + { + MessageBox.Show("Заполните фио", "Ошибка", + MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + _logger.LogInformation("Сохранение исполнителя"); + try + { + var model = new ImplementerBindingModel + { + Id = _id ?? 0, + ImplementerFIO = FIOTextBox.Text, + Password = PasswordTextBox.Text, + Qualification = (int)QualificationNumericUpDown.Value, + WorkExperience = (int)WorkExpNumericUpDown.Value, + }; + 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 void FormImplementer_Load(object sender, EventArgs e) + { + if (_id.HasValue) + { + try + { + _logger.LogInformation("Получение исполнителя"); + var view = _logic.ReadElement(new ImplementerSearchModel + { + Id = _id.Value + }); + if (view != null) + { + FIOTextBox.Text = view.ImplementerFIO; + PasswordTextBox.Text = view.Password; + QualificationNumericUpDown.Value = view.Qualification; + WorkExpNumericUpDown.Value = view.WorkExperience; + } + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка получения исполнителя"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + } + } +} + diff --git a/JewelryStore/FormImplementer.resx b/JewelryStore/FormImplementer.resx new file mode 100644 index 0000000..1af7de1 --- /dev/null +++ b/JewelryStore/FormImplementer.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/FormImplementers.Designer.cs b/JewelryStore/FormImplementers.Designer.cs new file mode 100644 index 0000000..cf210bf --- /dev/null +++ b/JewelryStore/FormImplementers.Designer.cs @@ -0,0 +1,114 @@ +namespace JewelryStore +{ + partial class FormImplementers + { + /// + /// 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, 1); + this.DataGridView.Name = "DataGridView"; + this.DataGridView.RowTemplate.Height = 25; + this.DataGridView.Size = new System.Drawing.Size(632, 448); + this.DataGridView.TabIndex = 0; + // + // AddButton + // + this.AddButton.Location = new System.Drawing.Point(639, 12); + this.AddButton.Name = "AddButton"; + this.AddButton.Size = new System.Drawing.Size(98, 45); + 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(639, 63); + this.ChangeButton.Name = "ChangeButton"; + this.ChangeButton.Size = new System.Drawing.Size(98, 45); + 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(639, 114); + this.DeleteButton.Name = "DeleteButton"; + this.DeleteButton.Size = new System.Drawing.Size(98, 45); + 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(639, 165); + this.UpdateButton.Name = "UpdateButton"; + this.UpdateButton.Size = new System.Drawing.Size(98, 45); + this.UpdateButton.TabIndex = 4; + this.UpdateButton.Text = "Обновить"; + this.UpdateButton.UseVisualStyleBackColor = true; + this.UpdateButton.Click += new System.EventHandler(this.UpdateButton_Click); + // + // FormImplementers + // + this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(749, 450); + 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.Name = "FormImplementers"; + this.Text = "Исполнители"; + this.Load += new System.EventHandler(this.FormImplementers_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/FormImplementers.cs b/JewelryStore/FormImplementers.cs new file mode 100644 index 0000000..22fa746 --- /dev/null +++ b/JewelryStore/FormImplementers.cs @@ -0,0 +1,120 @@ +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 FormImplementers : Form + { + private readonly ILogger _logger; + private readonly IImplementerLogic _logic; + public FormImplementers(ILogger logger, IImplementerLogic logic) + { + InitializeComponent(); + _logger = logger; + _logic = logic; + } + + private void AddButton_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormImplementer)); + + if (service is FormImplementer 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(FormImplementer)); + if (service is FormImplementer 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 ImplementerBindingModel + { + 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 FormImplementers_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["ImplementerFIO"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; + } + + _logger.LogInformation("Загрузка исполнителей"); + } + + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка загрузки исполнителей"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + } +} diff --git a/JewelryStore/FormImplementers.resx b/JewelryStore/FormImplementers.resx new file mode 100644 index 0000000..1af7de1 --- /dev/null +++ b/JewelryStore/FormImplementers.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 index a837582..251d535 100644 --- a/JewelryStore/FormMain.Designer.cs +++ b/JewelryStore/FormMain.Designer.cs @@ -39,6 +39,7 @@ this.компонентыToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.изделияToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.клиентыToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.исполнителиToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.отчетыToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.списокКомпонентовToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.компонентыПоИзделиямToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); @@ -50,11 +51,11 @@ // // buttonReady // - this.buttonReady.Location = new System.Drawing.Point(1273, 225); + this.buttonReady.Location = new System.Drawing.Point(1273, 298); this.buttonReady.Name = "buttonReady"; this.buttonReady.Size = new System.Drawing.Size(215, 34); this.buttonReady.TabIndex = 3; - this.buttonReady.Text = "Заказ готов"; + this.buttonReady.Text = "Заказ выдан"; this.buttonReady.UseVisualStyleBackColor = true; this.buttonReady.Click += new System.EventHandler(this.buttonReady_Click); // @@ -90,11 +91,11 @@ // // buttonPut // - this.buttonPut.Location = new System.Drawing.Point(1273, 308); + this.buttonPut.Location = new System.Drawing.Point(1273, 218); this.buttonPut.Name = "buttonPut"; this.buttonPut.Size = new System.Drawing.Size(215, 34); this.buttonPut.TabIndex = 4; - this.buttonPut.Text = "Заказ выдан"; + this.buttonPut.Text = "Заказ готов"; this.buttonPut.UseVisualStyleBackColor = true; this.buttonPut.Click += new System.EventHandler(this.buttonPut_Click); // @@ -126,7 +127,8 @@ this.справочникиToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] { this.компонентыToolStripMenuItem, this.изделияToolStripMenuItem, - this.клиентыToolStripMenuItem}); + this.клиентыToolStripMenuItem, + this.исполнителиToolStripMenuItem}); this.справочникиToolStripMenuItem.Name = "справочникиToolStripMenuItem"; this.справочникиToolStripMenuItem.Size = new System.Drawing.Size(139, 29); this.справочникиToolStripMenuItem.Text = "Справочники"; @@ -152,6 +154,13 @@ 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); + // // отчетыToolStripMenuItem // this.отчетыToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] { @@ -232,5 +241,6 @@ private ToolStripMenuItem списокЗаказзовToolStripMenuItem; private ToolStripMenuItem клиентыToolStripMenuItem; private ToolStripMenuItem запускРаботToolStripMenuItem; + private ToolStripMenuItem исполнителиToolStripMenuItem; } } \ No newline at end of file diff --git a/JewelryStore/FormMain.cs b/JewelryStore/FormMain.cs index c8a6e2b..1917875 100644 --- a/JewelryStore/FormMain.cs +++ b/JewelryStore/FormMain.cs @@ -48,7 +48,7 @@ namespace JewelryStore dataGridView.DataSource = list; dataGridView.Columns["JewelId"].Visible = false; dataGridView.Columns["ClientId"].Visible = false; - + dataGridView.Columns["ImplementerId"].Visible = false; } _logger.LogInformation("Загрузка заказов"); @@ -100,14 +100,14 @@ namespace JewelryStore var operationResult = _orderLogic.TakeOrderInWork(new OrderBindingModel { Id = id, - JewelId = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["JewelId"].Value), - ClientId = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["ClientId"].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()), + //JewelId = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["JewelId"].Value), + //ClientId = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["ClientId"].Value), + //ImplementerId = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["ImplementerId"].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) { @@ -136,13 +136,14 @@ namespace JewelryStore var operationResult = _orderLogic.FinishOrder(new OrderBindingModel { Id = id, - JewelId = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["JewelId"].Value), - ClientId = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["ClientId"].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()), + //JewelId = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["JewelId"].Value), + //ClientId = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["ClientId"].Value), + //ImplementerId = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["ImplementerId"].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) { @@ -171,13 +172,14 @@ namespace JewelryStore OrderBindingModel { Id = id, - JewelId = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["JewelId"].Value), - ClientId = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["ClientId"].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()), + //JewelId = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["JewelId"].Value), + //ClientId = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["ClientId"].Value), + //ImplementerId = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["ImplementerId"].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) { @@ -250,5 +252,15 @@ namespace JewelryStore MessageBoxButtons.OK, MessageBoxIcon.Information); } } + + private void исполнителиToolStripMenuItem_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormImplementers)); + + if (service is FormImplementers form) + { + form.ShowDialog(); + } + } } } diff --git a/JewelryStore/Program.cs b/JewelryStore/Program.cs index 1f9567f..50bf9fa 100644 --- a/JewelryStore/Program.cs +++ b/JewelryStore/Program.cs @@ -42,8 +42,11 @@ namespace JewelryStore services.AddTransient(); services.AddTransient(); services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); services.AddTransient(); services.AddTransient(); @@ -65,7 +68,8 @@ namespace JewelryStore services.AddTransient(); services.AddTransient(); services.AddTransient(); - + services.AddTransient(); + services.AddTransient(); } } diff --git a/JewelryStore/nlog.config b/JewelryStore/nlog.config new file mode 100644 index 0000000..609afe6 --- /dev/null +++ b/JewelryStore/nlog.config @@ -0,0 +1,15 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/JewelryStoreBusinessLogic/BusinessLogics/OrderLogic.cs b/JewelryStoreBusinessLogic/BusinessLogics/OrderLogic.cs index 6bcfa52..7010a87 100644 --- a/JewelryStoreBusinessLogic/BusinessLogics/OrderLogic.cs +++ b/JewelryStoreBusinessLogic/BusinessLogics/OrderLogic.cs @@ -15,13 +15,9 @@ namespace JewelryStoreBusinessLogic.BusinessLogics { public class OrderLogic : IOrderLogic //TODO реализовать интерфейс { - // Класс с логикой для заказов будет отвечать за получение списка заказов, - //создания заказа и смены его статусов.Следует учитывать, что у заказа можно - //менять статус на новый, если его текущий статус предшествует новому - //(например, в статус «Готов» можно переводить, если заказ находится в статусе - //«Выполняется»). private readonly ILogger _logger; private readonly IOrderStorage _orderStorage; + public OrderLogic(ILogger logger, IOrderStorage orderStorage) { _logger = logger; @@ -31,100 +27,140 @@ namespace JewelryStoreBusinessLogic.BusinessLogics public bool CreateOrder(OrderBindingModel model) { CheckModel(model); - if (model.Status != OrderStatus.Неизвестен) return false; + + if (model.Status != OrderStatus.Неизвестен) + { + _logger.LogWarning("Insert operation failed. Order status incorrect."); + return false; + } + model.Status = OrderStatus.Принят; + if (_orderStorage.Insert(model) == null) { + model.Status = OrderStatus.Неизвестен; _logger.LogWarning("Insert operation failed"); return false; } + return true; } + public bool StatusUpdate(OrderBindingModel model, OrderStatus newStatus) + { + var vmodel = _orderStorage.GetElement(new() { Id = model.Id }); + + if (vmodel == null) + { + throw new ArgumentNullException(nameof(model)); + } + + if ((int)vmodel.Status + 1 != (int)newStatus) + { + throw new InvalidOperationException($"Попытка перевести заказ не в следующий статус: " + + $"Текущий статус: {vmodel.Status} \n" + + $"Планируемый статус: {newStatus} \n" + + $"Доступный статус: {(OrderStatus)((int)vmodel.Status + 1)}"); + } + + model.Status = newStatus; + model.DateCreate = vmodel.DateCreate; + + if (model.DateImplement == null) + model.DateImplement = vmodel.DateImplement; + + if (vmodel.ImplementerId.HasValue) + model.ImplementerId = vmodel.ImplementerId; + + model.JewelId = vmodel.JewelId; + model.Sum = vmodel.Sum; + model.Count = vmodel.Count; + + if (_orderStorage.Update(model) == null) + { + _logger.LogWarning("Update operation failed"); + + return false; + } + + return true; + } + + public bool TakeOrderInWork(OrderBindingModel model) + { + return StatusUpdate(model, OrderStatus.Выполняется); + } + 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; + return StatusUpdate(model, OrderStatus.Готов); } 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; + return StatusUpdate(model, OrderStatus.Выдан); } public List? ReadList(OrderSearchModel? model) { - _logger.LogInformation("ReadList. OrderId:{Id}", model?.Id); + _logger.LogInformation("Order. 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) + private bool CheckModel(OrderBindingModel model) { - CheckModel(model); - if (model.Status != OrderStatus.Принят) return false; - model.Status = OrderStatus.Выполняется; - if (_orderStorage.Update(model) == null) + if (model == null) { - _logger.LogWarning("Update operation failed"); - return false; + throw new ArgumentNullException(nameof(model)); } + if (model.Count <= 0) + { + throw new ArgumentException("Количество изделий в заказе должно быть больше 0", nameof(model.Count)); + } + if (model.Sum <= 0) + { + throw new ArgumentException("Суммарная стоимость заказа должна быть больше 0", nameof(model.Sum)); + } + if (model.DateCreate > model.DateImplement) + { + throw new ArgumentException("Время создания заказа не может быть больше времени его выполнения", nameof(model.DateImplement)); + } + return true; } - private void CheckModel(OrderBindingModel model, bool withParams = true) + public OrderViewModel? ReadElement(OrderSearchModel model) { if (model == null) { throw new ArgumentNullException(nameof(model)); } - if (!withParams) + _logger.LogInformation("ReadElement. Id:{ Id}", model.Id); + + var element = _orderStorage.GetElement(model); + + if (element == null) { - return; + _logger.LogWarning("ReadElement element not found"); + + return null; } - if (model.JewelId < 0) - { - throw new ArgumentNullException("Некорректный идентификатор драгоценности", nameof(model.JewelId)); - } + _logger.LogInformation("ReadElement find. Id:{Id}", element.Id); - 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); + return element; } - } } diff --git a/JewelryStoreBusinessLogic/BusinessLogics/WorkModeling.cs b/JewelryStoreBusinessLogic/BusinessLogics/WorkModeling.cs index e969286..433fe50 100644 --- a/JewelryStoreBusinessLogic/BusinessLogics/WorkModeling.cs +++ b/JewelryStoreBusinessLogic/BusinessLogics/WorkModeling.cs @@ -2,6 +2,7 @@ using JewelryStoreContracts.BusinessLogicsContracts; using JewelryStoreContracts.SearchModels; using JewelryStoreContracts.ViewModels; +using JewelryStoreDataModels.Enums; using Microsoft.Extensions.Logging; using System; using System.Collections.Generic; @@ -34,31 +35,29 @@ namespace JewelryStoreBusinessLogic.BusinessLogics _logger.LogWarning("DoWork. Implementers is null"); return; } - var orders = _orderLogic.ReadList(new OrderSearchModel { /*Status = OrderStatus.Принят*/ }); + + var orders = _orderLogic.ReadList(new OrderSearchModel { Statuses = new() { OrderStatus.Принят, OrderStatus.Выполняется } }); if (orders == null || orders.Count == 0) { _logger.LogWarning("DoWork. Orders is null or empty"); return; } + _logger.LogDebug("DoWork for {Count} orders", orders.Count); + foreach (var implementer in implementers) { Task.Run(() => WorkerWorkAsync(implementer, orders)); } } - /// - /// Иммитация работы исполнителя - /// - /// - /// private async Task WorkerWorkAsync(ImplementerViewModel implementer, List orders) { if (_orderLogic == null || implementer == null) { return; } - await RunOrderInWork(implementer); + await RunOrderInWork(implementer, orders); await Task.Run(() => { @@ -67,77 +66,69 @@ namespace JewelryStoreBusinessLogic.BusinessLogics try { _logger.LogDebug("DoWork. Worker {Id} try get order {Order}", implementer.Id, order.Id); - // пытаемся назначить заказ на исполнителя + _orderLogic.TakeOrderInWork(new OrderBindingModel { Id = order.Id, - // ImplementerId = implementer.Id + ImplementerId = implementer.Id }); - // делаем работу + Thread.Sleep(implementer.WorkExperience * _rnd.Next(100, 1000) * order.Count); _logger.LogDebug("DoWork. Worker {Id} finish order {Order}", implementer.Id, order.Id); - _orderLogic.FinishOrder(new OrderBindingModel + + _orderLogic.DeliveryOrder(new OrderBindingModel { Id = order.Id }); + + Thread.Sleep(implementer.Qualification * _rnd.Next(10, 100)); } - // кто-то мог уже перехватить заказ, игнорируем ошибку + catch (InvalidOperationException ex) { _logger.LogWarning(ex, "Error try get work"); } - // заканчиваем выполнение имитации в случае иной ошибки + catch (Exception ex) { _logger.LogError(ex, "Error while do work"); throw; } - // отдыхаем - Thread.Sleep(implementer.Qualification * _rnd.Next(10, 100)); } }); } - /// - /// Ищем заказ, которые уже в работе (вдруг исполнителя прервали) - /// - /// - /// - private async Task RunOrderInWork(ImplementerViewModel implementer) + private async Task RunOrderInWork(ImplementerViewModel implementer, List allOrders) { - if (_orderLogic == null || implementer == null) + if (_orderLogic == null || implementer == null || allOrders == null || allOrders.Count == 0) { return; } try { - var runOrder = await Task.Run(() => _orderLogic.ReadElement(new OrderSearchModel - { - // ImplementerId = implementer.Id, - // Status = OrderStatus.Выполняется - })); + var runOrder = await Task.Run(() => allOrders.FirstOrDefault(x => x.ImplementerId == implementer.Id && x.Status == OrderStatus.Выполняется)); if (runOrder == null) { return; } _logger.LogDebug("DoWork. Worker {Id} back to order {Order}", implementer.Id, runOrder.Id); - // доделываем работу + Thread.Sleep(implementer.WorkExperience * _rnd.Next(100, 300) * runOrder.Count); _logger.LogDebug("DoWork. Worker {Id} finish order {Order}", implementer.Id, runOrder.Id); - _orderLogic.FinishOrder(new OrderBindingModel + _orderLogic.DeliveryOrder(new OrderBindingModel { Id = runOrder.Id }); - // отдыхаем + Thread.Sleep(implementer.Qualification * _rnd.Next(10, 100)); } - // заказа может не быть, просто игнорируем ошибку + catch (InvalidOperationException ex) { _logger.LogWarning(ex, "Error try get work"); } - // а может возникнуть иная ошибка, тогда просто заканчиваем выполнение имитации + catch (Exception ex) { _logger.LogError(ex, "Error while do work"); diff --git a/JewelryStoreContracts/BusinessLogicsContracts/IOrderLogic.cs b/JewelryStoreContracts/BusinessLogicsContracts/IOrderLogic.cs index a403f30..5a905c5 100644 --- a/JewelryStoreContracts/BusinessLogicsContracts/IOrderLogic.cs +++ b/JewelryStoreContracts/BusinessLogicsContracts/IOrderLogic.cs @@ -12,6 +12,8 @@ namespace JewelryStoreContracts.BusinessLogicsContracts public interface IOrderLogic { List? ReadList(OrderSearchModel? model); + OrderViewModel? ReadElement(OrderSearchModel model); + bool CreateOrder(OrderBindingModel model); bool TakeOrderInWork(OrderBindingModel model); bool FinishOrder(OrderBindingModel model); diff --git a/JewelryStoreContracts/ViewModels/OrderViewModel.cs b/JewelryStoreContracts/ViewModels/OrderViewModel.cs index 0335141..4a61b37 100644 --- a/JewelryStoreContracts/ViewModels/OrderViewModel.cs +++ b/JewelryStoreContracts/ViewModels/OrderViewModel.cs @@ -35,7 +35,7 @@ namespace JewelryStoreContracts.ViewModels public DateTime? DateImplement { get; set; } public int? ImplementerId { get; set; } [DisplayName("ФИО исполнителя")] - public string ImplementerFIO { get; set; } = string.Empty; + public string ImplementerFIO { get; set; } = string.Empty; } } diff --git a/JewelryStoreDataModels/Models/IOrderModel.cs b/JewelryStoreDataModels/Models/IOrderModel.cs index 62b66af..dafe1e6 100644 --- a/JewelryStoreDataModels/Models/IOrderModel.cs +++ b/JewelryStoreDataModels/Models/IOrderModel.cs @@ -12,8 +12,8 @@ namespace JewelryStoreDataModels.Models { int JewelId { get; } string JewelName { get; } - - int ClientId { get; } + int? ImplementerId { get; } + int ClientId { get; } int Count { get; } double Sum { get; } OrderStatus Status { get; } diff --git a/JewelryStoreDatabaseImplement/Migrations/20230403133347_InitialCreate.Designer.cs b/JewelryStoreDatabaseImplement/Migrations/20230417191656_InitialCreate.Designer.cs similarity index 82% rename from JewelryStoreDatabaseImplement/Migrations/20230403133347_InitialCreate.Designer.cs rename to JewelryStoreDatabaseImplement/Migrations/20230417191656_InitialCreate.Designer.cs index c279e65..e696826 100644 --- a/JewelryStoreDatabaseImplement/Migrations/20230403133347_InitialCreate.Designer.cs +++ b/JewelryStoreDatabaseImplement/Migrations/20230417191656_InitialCreate.Designer.cs @@ -12,7 +12,7 @@ using Microsoft.EntityFrameworkCore.Storage.ValueConversion; namespace JewelryStoreDatabaseImplement.Migrations { [DbContext(typeof(JewelryStoreDataBase))] - [Migration("20230403133347_InitialCreate")] + [Migration("20230417191656_InitialCreate")] partial class InitialCreate { /// @@ -70,6 +70,33 @@ namespace JewelryStoreDatabaseImplement.Migrations b.ToTable("Components"); }); + modelBuilder.Entity("JewelryStoreDatabaseImplement.Models.Implementer", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("ImplementerFIO") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Password") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Qualification") + .HasColumnType("int"); + + b.Property("WorkExperience") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.ToTable("Implementers"); + }); + modelBuilder.Entity("JewelryStoreDatabaseImplement.Models.Jewel", b => { b.Property("Id") @@ -136,6 +163,9 @@ namespace JewelryStoreDatabaseImplement.Migrations b.Property("DateImplement") .HasColumnType("datetime2"); + b.Property("ImplementerId") + .HasColumnType("int"); + b.Property("JewelId") .HasColumnType("int"); @@ -153,6 +183,8 @@ namespace JewelryStoreDatabaseImplement.Migrations b.HasIndex("ClientId"); + b.HasIndex("ImplementerId"); + b.HasIndex("JewelId"); b.ToTable("Orders"); @@ -185,6 +217,10 @@ namespace JewelryStoreDatabaseImplement.Migrations .OnDelete(DeleteBehavior.Cascade) .IsRequired(); + b.HasOne("JewelryStoreDatabaseImplement.Models.Implementer", "Implementer") + .WithMany("Orders") + .HasForeignKey("ImplementerId"); + b.HasOne("JewelryStoreDatabaseImplement.Models.Jewel", "Jewel") .WithMany("Orders") .HasForeignKey("JewelId") @@ -193,6 +229,8 @@ namespace JewelryStoreDatabaseImplement.Migrations b.Navigation("Client"); + b.Navigation("Implementer"); + b.Navigation("Jewel"); }); @@ -206,6 +244,11 @@ namespace JewelryStoreDatabaseImplement.Migrations b.Navigation("JewelComponents"); }); + modelBuilder.Entity("JewelryStoreDatabaseImplement.Models.Implementer", b => + { + b.Navigation("Orders"); + }); + modelBuilder.Entity("JewelryStoreDatabaseImplement.Models.Jewel", b => { b.Navigation("Components"); diff --git a/JewelryStoreDatabaseImplement/Migrations/20230403133347_InitialCreate.cs b/JewelryStoreDatabaseImplement/Migrations/20230417191656_InitialCreate.cs similarity index 82% rename from JewelryStoreDatabaseImplement/Migrations/20230403133347_InitialCreate.cs rename to JewelryStoreDatabaseImplement/Migrations/20230417191656_InitialCreate.cs index 6702f40..3435bf1 100644 --- a/JewelryStoreDatabaseImplement/Migrations/20230403133347_InitialCreate.cs +++ b/JewelryStoreDatabaseImplement/Migrations/20230417191656_InitialCreate.cs @@ -40,6 +40,22 @@ namespace JewelryStoreDatabaseImplement.Migrations table.PrimaryKey("PK_Components", x => x.Id); }); + migrationBuilder.CreateTable( + name: "Implementers", + columns: table => new + { + Id = table.Column(type: "int", nullable: false) + .Annotation("SqlServer:Identity", "1, 1"), + ImplementerFIO = table.Column(type: "nvarchar(max)", nullable: false), + Password = table.Column(type: "nvarchar(max)", nullable: false), + WorkExperience = table.Column(type: "int", nullable: false), + Qualification = table.Column(type: "int", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_Implementers", x => x.Id); + }); + migrationBuilder.CreateTable( name: "Jewels", columns: table => new @@ -89,6 +105,7 @@ namespace JewelryStoreDatabaseImplement.Migrations .Annotation("SqlServer:Identity", "1, 1"), JewelId = table.Column(type: "int", nullable: false), ClientId = table.Column(type: "int", nullable: false), + ImplementerId = table.Column(type: "int", nullable: true), JewelName = table.Column(type: "nvarchar(max)", nullable: false), Count = table.Column(type: "int", nullable: false), Sum = table.Column(type: "float", nullable: false), @@ -105,6 +122,11 @@ namespace JewelryStoreDatabaseImplement.Migrations principalTable: "Clients", principalColumn: "Id", onDelete: ReferentialAction.Cascade); + table.ForeignKey( + name: "FK_Orders_Implementers_ImplementerId", + column: x => x.ImplementerId, + principalTable: "Implementers", + principalColumn: "Id"); table.ForeignKey( name: "FK_Orders_Jewels_JewelId", column: x => x.JewelId, @@ -128,6 +150,11 @@ namespace JewelryStoreDatabaseImplement.Migrations table: "Orders", column: "ClientId"); + migrationBuilder.CreateIndex( + name: "IX_Orders_ImplementerId", + table: "Orders", + column: "ImplementerId"); + migrationBuilder.CreateIndex( name: "IX_Orders_JewelId", table: "Orders", @@ -149,6 +176,9 @@ namespace JewelryStoreDatabaseImplement.Migrations migrationBuilder.DropTable( name: "Clients"); + migrationBuilder.DropTable( + name: "Implementers"); + migrationBuilder.DropTable( name: "Jewels"); } diff --git a/JewelryStoreDatabaseImplement/Migrations/JewelryStoreDataBaseModelSnapshot.cs b/JewelryStoreDatabaseImplement/Migrations/JewelryStoreDataBaseModelSnapshot.cs index ec2bacf..599816d 100644 --- a/JewelryStoreDatabaseImplement/Migrations/JewelryStoreDataBaseModelSnapshot.cs +++ b/JewelryStoreDatabaseImplement/Migrations/JewelryStoreDataBaseModelSnapshot.cs @@ -67,6 +67,33 @@ namespace JewelryStoreDatabaseImplement.Migrations b.ToTable("Components"); }); + modelBuilder.Entity("JewelryStoreDatabaseImplement.Models.Implementer", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("ImplementerFIO") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Password") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Qualification") + .HasColumnType("int"); + + b.Property("WorkExperience") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.ToTable("Implementers"); + }); + modelBuilder.Entity("JewelryStoreDatabaseImplement.Models.Jewel", b => { b.Property("Id") @@ -133,6 +160,9 @@ namespace JewelryStoreDatabaseImplement.Migrations b.Property("DateImplement") .HasColumnType("datetime2"); + b.Property("ImplementerId") + .HasColumnType("int"); + b.Property("JewelId") .HasColumnType("int"); @@ -150,6 +180,8 @@ namespace JewelryStoreDatabaseImplement.Migrations b.HasIndex("ClientId"); + b.HasIndex("ImplementerId"); + b.HasIndex("JewelId"); b.ToTable("Orders"); @@ -182,6 +214,10 @@ namespace JewelryStoreDatabaseImplement.Migrations .OnDelete(DeleteBehavior.Cascade) .IsRequired(); + b.HasOne("JewelryStoreDatabaseImplement.Models.Implementer", "Implementer") + .WithMany("Orders") + .HasForeignKey("ImplementerId"); + b.HasOne("JewelryStoreDatabaseImplement.Models.Jewel", "Jewel") .WithMany("Orders") .HasForeignKey("JewelId") @@ -190,6 +226,8 @@ namespace JewelryStoreDatabaseImplement.Migrations b.Navigation("Client"); + b.Navigation("Implementer"); + b.Navigation("Jewel"); }); @@ -203,6 +241,11 @@ namespace JewelryStoreDatabaseImplement.Migrations b.Navigation("JewelComponents"); }); + modelBuilder.Entity("JewelryStoreDatabaseImplement.Models.Implementer", b => + { + b.Navigation("Orders"); + }); + modelBuilder.Entity("JewelryStoreDatabaseImplement.Models.Jewel", b => { b.Navigation("Components"); diff --git a/JewelryStoreDatabaseImplement/Models/Order.cs b/JewelryStoreDatabaseImplement/Models/Order.cs index 3bfbd59..97d4cfe 100644 --- a/JewelryStoreDatabaseImplement/Models/Order.cs +++ b/JewelryStoreDatabaseImplement/Models/Order.cs @@ -78,6 +78,8 @@ namespace JewelryStoreDatabaseImplement.Models Status = model.Status; DateCreate = model.DateCreate; DateImplement = model.DateImplement; + ImplementerId = model.ImplementerId; + } public OrderViewModel GetViewModel diff --git a/JewelryStoreFileImplement/Models/Order.cs b/JewelryStoreFileImplement/Models/Order.cs index 627c3d0..23bcf7c 100644 --- a/JewelryStoreFileImplement/Models/Order.cs +++ b/JewelryStoreFileImplement/Models/Order.cs @@ -18,6 +18,7 @@ namespace JewelryStoreFileImplement.Models public int ClientId { get; private set; } public string JewelName { get; private set; } = string.Empty; + public int? ImplementerId { get; private set; } public int Count { get; private set; } diff --git a/JewelryStoreListImplement/Implements/ImplementerStorage.cs b/JewelryStoreListImplement/Implements/ImplementerStorage.cs index 6737fd4..42077eb 100644 --- a/JewelryStoreListImplement/Implements/ImplementerStorage.cs +++ b/JewelryStoreListImplement/Implements/ImplementerStorage.cs @@ -128,4 +128,4 @@ namespace JewelryStoreListImplement.Implements } } } -} + diff --git a/JewelryStoreListImplement/Models/Order.cs b/JewelryStoreListImplement/Models/Order.cs index 23c1fbb..18c0bbf 100644 --- a/JewelryStoreListImplement/Models/Order.cs +++ b/JewelryStoreListImplement/Models/Order.cs @@ -15,6 +15,8 @@ namespace JewelryStoreListImplement.Models public int JewelId { get; private set; } public string JewelName { get; private set; } public int ClientId { get; private set; } + public int? ImplementerId { get; private set; } + public int Count { get; private set; } public double Sum { get; private set; } @@ -71,5 +73,6 @@ namespace JewelryStoreListImplement.Models DateCreate = DateCreate, DateImplement = DateImplement }; + } } diff --git a/JewelryStoreRestApi/Controllers/ImplementerController.cs b/JewelryStoreRestApi/Controllers/ImplementerController.cs index 9a318f4..82ae8e5 100644 --- a/JewelryStoreRestApi/Controllers/ImplementerController.cs +++ b/JewelryStoreRestApi/Controllers/ImplementerController.cs @@ -65,7 +65,7 @@ namespace JewelryStoreRestApi.Controllers { return _order.ReadElement(new OrderSearchModel { - //ImplementerId = implementerId + ImplementerId = implementerId }); } catch (Exception ex)