почему то выполняется только одним

This commit is contained in:
Inohara 2023-04-09 14:49:06 +04:00
parent feb99e7238
commit 1d31c88b76
13 changed files with 718 additions and 62 deletions

View File

@ -95,11 +95,11 @@ namespace IceCreamBusinessLogic.BusinessLogics
_logger.LogInformation("Order. OrderID:{Id}.Sum:{ Sum}. DocumentId: { DocumentId}", model.Id, model.Sum, model.IceCreamId); _logger.LogInformation("Order. OrderID:{Id}.Sum:{ Sum}. DocumentId: { DocumentId}", model.Id, model.Sum, model.IceCreamId);
} }
public bool SetNewStatus(OrderBindingModel orderModel, OrderStatus newStatus) public bool SetNewStatus(OrderBindingModel rawModel, OrderStatus newStatus)
{ {
var viewModel = _orderStorage.GetElement(new OrderSearchModel var viewModel = _orderStorage.GetElement(new OrderSearchModel
{ {
Id = orderModel.Id Id = rawModel.Id
}); });
if (viewModel == null) if (viewModel == null)
@ -118,6 +118,11 @@ namespace IceCreamBusinessLogic.BusinessLogics
Count = viewModel.Count, Count = viewModel.Count,
Sum = viewModel.Sum Sum = viewModel.Sum
}; };
if (rawModel.ImplementerId.HasValue)
{
model.ImplementerId = rawModel.ImplementerId;
}
CheckModel(model); CheckModel(model);
if (model.Status + 1 != newStatus) if (model.Status + 1 != newStatus)
{ {
@ -126,7 +131,7 @@ namespace IceCreamBusinessLogic.BusinessLogics
} }
model.Status = newStatus; model.Status = newStatus;
if (model.Status == OrderStatus.Выдан) model.DateImplement = DateTime.Now; if (model.Status == OrderStatus.Выдан) model.DateImplement = DateTime.Now;
if (_orderStorage.Update(model) == null) if (_orderStorage. (model) == null)
{ {
model.Status--; model.Status--;
_logger.LogWarning("Update operation failed"); _logger.LogWarning("Update operation failed");
@ -135,6 +140,7 @@ namespace IceCreamBusinessLogic.BusinessLogics
return true; return true;
} }
public OrderViewModel? ReadElement(OrderSearchModel model) public OrderViewModel? ReadElement(OrderSearchModel model)
{ {
if (model == null) if (model == null)

View File

@ -74,9 +74,10 @@ namespace IceCreamBusinessLogic.BusinessLogic
// делаем работу // делаем работу
Thread.Sleep(implementer.WorkExperience * _rnd.Next(100, 1000) * order.Count); Thread.Sleep(implementer.WorkExperience * _rnd.Next(100, 1000) * order.Count);
_logger.LogDebug("DoWork. Worker {Id} finish order {Order}", implementer.Id, order.Id); _logger.LogDebug("DoWork. Worker {Id} finish order {Order}", implementer.Id, order.Id);
_orderLogic.FinishOrder(new OrderBindingModel _orderLogic.DeliveryOrder(new OrderBindingModel
{ {
Id = order.Id Id = order.Id,
ImplementerId = implementer.Id
}); });
// отдыхаем // отдыхаем
Thread.Sleep(implementer.Qualification * _rnd.Next(10, 100)); Thread.Sleep(implementer.Qualification * _rnd.Next(10, 100));

View File

@ -0,0 +1,184 @@
namespace IceCreamShopView
{
partial class FormImplementer
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.buttonSave = new System.Windows.Forms.Button();
this.buttonCancel = new System.Windows.Forms.Button();
this.numericUpDownQualification = new System.Windows.Forms.NumericUpDown();
this.numericUpDownWorkExperience = new System.Windows.Forms.NumericUpDown();
this.textBoxPassword = new System.Windows.Forms.TextBox();
this.textBoxFio = new System.Windows.Forms.TextBox();
this.label4 = new System.Windows.Forms.Label();
this.label3 = new System.Windows.Forms.Label();
this.label2 = new System.Windows.Forms.Label();
this.label1 = new System.Windows.Forms.Label();
((System.ComponentModel.ISupportInitialize)(this.numericUpDownQualification)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.numericUpDownWorkExperience)).BeginInit();
this.SuspendLayout();
//
// buttonSave
//
this.buttonSave.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
this.buttonSave.Location = new System.Drawing.Point(172, 148);
this.buttonSave.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
this.buttonSave.Name = "buttonSave";
this.buttonSave.Size = new System.Drawing.Size(102, 44);
this.buttonSave.TabIndex = 19;
this.buttonSave.Text = "Сохранить";
this.buttonSave.UseVisualStyleBackColor = true;
this.buttonSave.Click += new System.EventHandler(this.ButtonSave_Click);
//
// buttonCancel
//
this.buttonCancel.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
this.buttonCancel.Location = new System.Drawing.Point(291, 148);
this.buttonCancel.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
this.buttonCancel.Name = "buttonCancel";
this.buttonCancel.Size = new System.Drawing.Size(102, 44);
this.buttonCancel.TabIndex = 18;
this.buttonCancel.Text = "Отмена";
this.buttonCancel.UseVisualStyleBackColor = true;
this.buttonCancel.Click += new System.EventHandler(this.ButtonCancel_Click);
//
// numericUpDownQualification
//
this.numericUpDownQualification.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this.numericUpDownQualification.Location = new System.Drawing.Point(303, 94);
this.numericUpDownQualification.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
this.numericUpDownQualification.Name = "numericUpDownQualification";
this.numericUpDownQualification.Size = new System.Drawing.Size(90, 27);
this.numericUpDownQualification.TabIndex = 17;
//
// numericUpDownWorkExperience
//
this.numericUpDownWorkExperience.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this.numericUpDownWorkExperience.Location = new System.Drawing.Point(83, 92);
this.numericUpDownWorkExperience.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
this.numericUpDownWorkExperience.Name = "numericUpDownWorkExperience";
this.numericUpDownWorkExperience.Size = new System.Drawing.Size(94, 27);
this.numericUpDownWorkExperience.TabIndex = 16;
//
// textBoxPassword
//
this.textBoxPassword.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this.textBoxPassword.Location = new System.Drawing.Point(83, 51);
this.textBoxPassword.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
this.textBoxPassword.Name = "textBoxPassword";
this.textBoxPassword.PasswordChar = '*';
this.textBoxPassword.Size = new System.Drawing.Size(310, 27);
this.textBoxPassword.TabIndex = 15;
//
// textBoxFio
//
this.textBoxFio.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this.textBoxFio.Location = new System.Drawing.Point(58, 6);
this.textBoxFio.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
this.textBoxFio.Name = "textBoxFio";
this.textBoxFio.Size = new System.Drawing.Size(335, 27);
this.textBoxFio.TabIndex = 14;
//
// label4
//
this.label4.AutoSize = true;
this.label4.Location = new System.Drawing.Point(183, 94);
this.label4.Name = "label4";
this.label4.Size = new System.Drawing.Size(114, 20);
this.label4.TabIndex = 13;
this.label4.Text = "Квалификация:";
//
// label3
//
this.label3.AutoSize = true;
this.label3.Location = new System.Drawing.Point(12, 90);
this.label3.Name = "label3";
this.label3.Size = new System.Drawing.Size(46, 20);
this.label3.TabIndex = 12;
this.label3.Text = "Стаж:";
//
// label2
//
this.label2.AutoSize = true;
this.label2.Location = new System.Drawing.Point(12, 51);
this.label2.Name = "label2";
this.label2.Size = new System.Drawing.Size(65, 20);
this.label2.TabIndex = 11;
this.label2.Text = "Пароль:";
//
// label1
//
this.label1.AutoSize = true;
this.label1.Location = new System.Drawing.Point(12, 9);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(45, 20);
this.label1.TabIndex = 10;
this.label1.Text = "ФИО:";
//
// FormImplementer
//
this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(405, 205);
this.Controls.Add(this.buttonSave);
this.Controls.Add(this.buttonCancel);
this.Controls.Add(this.numericUpDownQualification);
this.Controls.Add(this.numericUpDownWorkExperience);
this.Controls.Add(this.textBoxPassword);
this.Controls.Add(this.textBoxFio);
this.Controls.Add(this.label4);
this.Controls.Add(this.label3);
this.Controls.Add(this.label2);
this.Controls.Add(this.label1);
this.Name = "FormImplementer";
this.Text = "Исполнитель";
this.Load += new System.EventHandler(this.FormImplementer_Load);
((System.ComponentModel.ISupportInitialize)(this.numericUpDownQualification)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.numericUpDownWorkExperience)).EndInit();
this.ResumeLayout(false);
this.PerformLayout();
}
#endregion
private Button buttonSave;
private Button buttonCancel;
private NumericUpDown numericUpDownQualification;
private NumericUpDown numericUpDownWorkExperience;
private TextBox textBoxPassword;
private TextBox textBoxFio;
private Label label4;
private Label label3;
private Label label2;
private Label label1;
}
}

View File

@ -0,0 +1,99 @@
using IceCreamShopContracts.BindingModels;
using IceCreamShopContracts.BusinessLogicsContracts;
using IceCreamShopContracts.SearchModels;
using Microsoft.Extensions.Logging;
namespace IceCreamShopView
{
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<FormImplementer> logger, IImplementerLogic logic)
{
InitializeComponent();
_logger = logger;
_logic = logic;
}
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)
{
textBoxFio.Text = view.ImplementerFIO;
textBoxPassword.Text = view.Password;
numericUpDownQualification.Value = view.Qualification;
numericUpDownWorkExperience.Value = view.WorkExperience;
}
}
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(textBoxPassword.Text))
{
MessageBox.Show("Заполните пароль", "Ошибка",
MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
if (string.IsNullOrEmpty(textBoxFio.Text))
{
MessageBox.Show("Заполните фио", "Ошибка",
MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
_logger.LogInformation("Сохранение исполнителя");
try
{
var model = new ImplementerBindingModel
{
Id = _id ?? 0,
ImplementerFIO = textBoxFio.Text,
Password = textBoxPassword.Text,
Qualification = (int)numericUpDownQualification.Value,
WorkExperience = (int)numericUpDownWorkExperience.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();
}
}
}

View File

@ -0,0 +1,60 @@
<root>
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="metadata">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="name" use="required" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="assembly">
<xsd:complexType>
<xsd:attribute name="alias" type="xsd:string" />
<xsd:attribute name="name" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="data">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
</root>

View File

@ -0,0 +1,127 @@
namespace IceCreamShopView
{
partial class FormImplementers
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.buttonRef = new System.Windows.Forms.Button();
this.buttonDel = new System.Windows.Forms.Button();
this.buttonUpd = new System.Windows.Forms.Button();
this.buttonAdd = new System.Windows.Forms.Button();
this.dataGridView = new System.Windows.Forms.DataGridView();
((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit();
this.SuspendLayout();
//
// buttonRef
//
this.buttonRef.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
this.buttonRef.Location = new System.Drawing.Point(688, 182);
this.buttonRef.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
this.buttonRef.Name = "buttonRef";
this.buttonRef.Size = new System.Drawing.Size(103, 49);
this.buttonRef.TabIndex = 14;
this.buttonRef.Text = "Обновить";
this.buttonRef.UseVisualStyleBackColor = true;
this.buttonRef.Click += new System.EventHandler(this.ButtonRef_Click);
//
// buttonDel
//
this.buttonDel.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
this.buttonDel.Location = new System.Drawing.Point(688, 130);
this.buttonDel.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
this.buttonDel.Name = "buttonDel";
this.buttonDel.Size = new System.Drawing.Size(103, 44);
this.buttonDel.TabIndex = 13;
this.buttonDel.Text = "Удалить";
this.buttonDel.UseVisualStyleBackColor = true;
this.buttonDel.Click += new System.EventHandler(this.ButtonDel_Click);
//
// buttonUpd
//
this.buttonUpd.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
this.buttonUpd.Location = new System.Drawing.Point(688, 77);
this.buttonUpd.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
this.buttonUpd.Name = "buttonUpd";
this.buttonUpd.Size = new System.Drawing.Size(103, 45);
this.buttonUpd.TabIndex = 12;
this.buttonUpd.Text = "Изменить";
this.buttonUpd.UseVisualStyleBackColor = true;
this.buttonUpd.Click += new System.EventHandler(this.ButtonUpd_Click);
//
// buttonAdd
//
this.buttonAdd.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
this.buttonAdd.Location = new System.Drawing.Point(688, 29);
this.buttonAdd.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
this.buttonAdd.Name = "buttonAdd";
this.buttonAdd.Size = new System.Drawing.Size(103, 40);
this.buttonAdd.TabIndex = 11;
this.buttonAdd.Text = "Добавить";
this.buttonAdd.UseVisualStyleBackColor = true;
this.buttonAdd.Click += new System.EventHandler(this.ButtonAdd_Click);
//
// dataGridView
//
this.dataGridView.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
| System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this.dataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
this.dataGridView.Location = new System.Drawing.Point(12, 13);
this.dataGridView.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
this.dataGridView.Name = "dataGridView";
this.dataGridView.RowHeadersWidth = 51;
this.dataGridView.RowTemplate.Height = 25;
this.dataGridView.Size = new System.Drawing.Size(670, 425);
this.dataGridView.TabIndex = 10;
//
// FormImplementers
//
this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(803, 451);
this.Controls.Add(this.buttonRef);
this.Controls.Add(this.buttonDel);
this.Controls.Add(this.buttonUpd);
this.Controls.Add(this.buttonAdd);
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 Button buttonRef;
private Button buttonDel;
private Button buttonUpd;
private Button buttonAdd;
private DataGridView dataGridView;
}
}

View File

@ -0,0 +1,109 @@
using IceCreamShop;
using IceCreamShopContracts.BindingModels;
using IceCreamShopContracts.BusinessLogicsContracts;
using Microsoft.Extensions.Logging;
namespace IceCreamShopView
{
public partial class FormImplementers : Form
{
private readonly ILogger _logger;
private readonly IImplementerLogic _logic;
public FormImplementers(ILogger<FormImplementers> logger, IImplementerLogic logic)
{
InitializeComponent();
_logger = logger;
_logic = logic;
}
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);
}
}
private void ButtonAdd_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 ButtonUpd_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 ButtonDel_Click(object sender, EventArgs e)
{
if (dataGridView.SelectedRows.Count == 1)
{
if (MessageBox.Show("Удалить запись?", "Вопрос",
MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
{
int id =
Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value);
_logger.LogInformation("Удаление исполнителя");
try
{
if (!_logic.Delete(new ImplementerBindingModel
{
Id = id
}))
{
throw new Exception("Ошибка при удалении. Дополнительная информация в логах.");
}
LoadData();
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка удаления исполнителя");
MessageBox.Show(ex.Message, "Ошибка",
MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
}
}
private void ButtonRef_Click(object sender, EventArgs e)
{
LoadData();
}
}
}

View File

@ -0,0 +1,60 @@
<root>
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="metadata">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="name" use="required" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="assembly">
<xsd:complexType>
<xsd:attribute name="alias" type="xsd:string" />
<xsd:attribute name="name" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="data">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
</root>

View File

@ -30,26 +30,26 @@
{ {
this.buttonUpdate = new System.Windows.Forms.Button(); this.buttonUpdate = new System.Windows.Forms.Button();
this.buttonSetToFinish = new System.Windows.Forms.Button(); this.buttonSetToFinish = new System.Windows.Forms.Button();
this.buttonSetToDone = new System.Windows.Forms.Button();
this.buttonSetToWork = new System.Windows.Forms.Button();
this.buttonCreateOrder = new System.Windows.Forms.Button(); this.buttonCreateOrder = new System.Windows.Forms.Button();
this.dataGridView = new System.Windows.Forms.DataGridView(); this.dataGridView = new System.Windows.Forms.DataGridView();
this.menuStrip = new System.Windows.Forms.MenuStrip(); 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(); 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.ImplementersToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.отчетыToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.отчетыToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.iceCreamComponentsToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.iceCreamComponentsToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.iceCreamToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.iceCreamToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.ordersToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.ordersToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.клиентыToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.DoWorkToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit(); ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit();
this.menuStrip.SuspendLayout(); this.menuStrip.SuspendLayout();
this.SuspendLayout(); this.SuspendLayout();
// //
// buttonUpdate // buttonUpdate
// //
this.buttonUpdate.Location = new System.Drawing.Point(1067, 390); this.buttonUpdate.Location = new System.Drawing.Point(1235, 149);
this.buttonUpdate.Name = "buttonUpdate"; this.buttonUpdate.Name = "buttonUpdate";
this.buttonUpdate.Size = new System.Drawing.Size(194, 49); this.buttonUpdate.Size = new System.Drawing.Size(194, 49);
this.buttonUpdate.TabIndex = 13; this.buttonUpdate.TabIndex = 13;
@ -59,7 +59,7 @@
// //
// buttonSetToFinish // buttonSetToFinish
// //
this.buttonSetToFinish.Location = new System.Drawing.Point(1067, 298); this.buttonSetToFinish.Location = new System.Drawing.Point(1235, 94);
this.buttonSetToFinish.Name = "buttonSetToFinish"; this.buttonSetToFinish.Name = "buttonSetToFinish";
this.buttonSetToFinish.Size = new System.Drawing.Size(194, 49); this.buttonSetToFinish.Size = new System.Drawing.Size(194, 49);
this.buttonSetToFinish.TabIndex = 12; this.buttonSetToFinish.TabIndex = 12;
@ -67,29 +67,9 @@
this.buttonSetToFinish.UseVisualStyleBackColor = true; this.buttonSetToFinish.UseVisualStyleBackColor = true;
this.buttonSetToFinish.Click += new System.EventHandler(this.buttonSetToFinish_Click); this.buttonSetToFinish.Click += new System.EventHandler(this.buttonSetToFinish_Click);
// //
// buttonSetToDone
//
this.buttonSetToDone.Location = new System.Drawing.Point(1067, 211);
this.buttonSetToDone.Name = "buttonSetToDone";
this.buttonSetToDone.Size = new System.Drawing.Size(194, 49);
this.buttonSetToDone.TabIndex = 11;
this.buttonSetToDone.Text = "Заказ готов";
this.buttonSetToDone.UseVisualStyleBackColor = true;
this.buttonSetToDone.Click += new System.EventHandler(this.buttonSetToDone_Click);
//
// buttonSetToWork
//
this.buttonSetToWork.Location = new System.Drawing.Point(1067, 122);
this.buttonSetToWork.Name = "buttonSetToWork";
this.buttonSetToWork.Size = new System.Drawing.Size(194, 49);
this.buttonSetToWork.TabIndex = 10;
this.buttonSetToWork.Text = "Отдать на выполнение";
this.buttonSetToWork.UseVisualStyleBackColor = true;
this.buttonSetToWork.Click += new System.EventHandler(this.buttonSetToWork_Click);
//
// buttonCreateOrder // buttonCreateOrder
// //
this.buttonCreateOrder.Location = new System.Drawing.Point(1067, 33); this.buttonCreateOrder.Location = new System.Drawing.Point(1235, 39);
this.buttonCreateOrder.Name = "buttonCreateOrder"; this.buttonCreateOrder.Name = "buttonCreateOrder";
this.buttonCreateOrder.Size = new System.Drawing.Size(194, 49); this.buttonCreateOrder.Size = new System.Drawing.Size(194, 49);
this.buttonCreateOrder.TabIndex = 9; this.buttonCreateOrder.TabIndex = 9;
@ -104,7 +84,7 @@
this.dataGridView.Name = "dataGridView"; this.dataGridView.Name = "dataGridView";
this.dataGridView.RowHeadersWidth = 51; this.dataGridView.RowHeadersWidth = 51;
this.dataGridView.RowTemplate.Height = 29; this.dataGridView.RowTemplate.Height = 29;
this.dataGridView.Size = new System.Drawing.Size(1047, 407); this.dataGridView.Size = new System.Drawing.Size(1215, 407);
this.dataGridView.TabIndex = 8; this.dataGridView.TabIndex = 8;
// //
// menuStrip // menuStrip
@ -112,11 +92,12 @@
this.menuStrip.ImageScalingSize = new System.Drawing.Size(20, 20); this.menuStrip.ImageScalingSize = new System.Drawing.Size(20, 20);
this.menuStrip.Items.AddRange(new System.Windows.Forms.ToolStripItem[] { this.menuStrip.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
this.справочникиToolStripMenuItem, this.справочникиToolStripMenuItem,
this.отчетыToolStripMenuItem}); this.отчетыToolStripMenuItem,
this.DoWorkToolStripMenuItem});
this.menuStrip.Location = new System.Drawing.Point(0, 0); this.menuStrip.Location = new System.Drawing.Point(0, 0);
this.menuStrip.Name = "menuStrip"; this.menuStrip.Name = "menuStrip";
this.menuStrip.Padding = new System.Windows.Forms.Padding(6, 3, 0, 3); this.menuStrip.Padding = new System.Windows.Forms.Padding(6, 3, 0, 3);
this.menuStrip.Size = new System.Drawing.Size(1273, 30); this.menuStrip.Size = new System.Drawing.Size(1441, 30);
this.menuStrip.TabIndex = 7; this.menuStrip.TabIndex = 7;
this.menuStrip.Text = "Справочники"; this.menuStrip.Text = "Справочники";
// //
@ -125,7 +106,8 @@
this.справочникиToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] { this.справочникиToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] {
this.компонентыToolStripMenuItem, this.компонентыToolStripMenuItem,
this.мороженоеToolStripMenuItem, this.мороженоеToolStripMenuItem,
this.клиентыToolStripMenuItem}); this.клиентыToolStripMenuItem,
this.ImplementersToolStripMenuItem});
this.справочникиToolStripMenuItem.Name = "справочникиToolStripMenuItem"; this.справочникиToolStripMenuItem.Name = "справочникиToolStripMenuItem";
this.справочникиToolStripMenuItem.Size = new System.Drawing.Size(117, 24); this.справочникиToolStripMenuItem.Size = new System.Drawing.Size(117, 24);
this.справочникиToolStripMenuItem.Text = "Справочники"; this.справочникиToolStripMenuItem.Text = "Справочники";
@ -133,17 +115,31 @@
// компонентыToolStripMenuItem // компонентыToolStripMenuItem
// //
this.компонентыToolStripMenuItem.Name = омпонентыToolStripMenuItem"; this.компонентыToolStripMenuItem.Name = омпонентыToolStripMenuItem";
this.компонентыToolStripMenuItem.Size = new System.Drawing.Size(224, 26); this.компонентыToolStripMenuItem.Size = new System.Drawing.Size(185, 26);
this.компонентыToolStripMenuItem.Text = "Компоненты"; this.компонентыToolStripMenuItem.Text = "Компоненты";
this.компонентыToolStripMenuItem.Click += new System.EventHandler(this.компонентыToolStripMenuItem_Click); this.компонентыToolStripMenuItem.Click += new System.EventHandler(this.компонентыToolStripMenuItem_Click);
// //
// мороженоеToolStripMenuItem // мороженоеToolStripMenuItem
// //
this.мороженоеToolStripMenuItem.Name = ороженоеToolStripMenuItem"; this.мороженоеToolStripMenuItem.Name = ороженоеToolStripMenuItem";
this.мороженоеToolStripMenuItem.Size = new System.Drawing.Size(224, 26); this.мороженоеToolStripMenuItem.Size = new System.Drawing.Size(185, 26);
this.мороженоеToolStripMenuItem.Text = "Мороженое"; this.мороженоеToolStripMenuItem.Text = "Мороженое";
this.мороженоеToolStripMenuItem.Click += new System.EventHandler(this.мороженоеToolStripMenuItem_Click); this.мороженоеToolStripMenuItem.Click += new System.EventHandler(this.мороженоеToolStripMenuItem_Click);
// //
// клиентыToolStripMenuItem
//
this.клиентыToolStripMenuItem.Name = "клиентыToolStripMenuItem";
this.клиентыToolStripMenuItem.Size = new System.Drawing.Size(185, 26);
this.клиентыToolStripMenuItem.Text = "Клиенты";
this.клиентыToolStripMenuItem.Click += new System.EventHandler(this.клиентыToolStripMenuItem_Click);
//
// ImplementersToolStripMenuItem
//
this.ImplementersToolStripMenuItem.Name = "ImplementersToolStripMenuItem";
this.ImplementersToolStripMenuItem.Size = new System.Drawing.Size(185, 26);
this.ImplementersToolStripMenuItem.Text = "Исполнители";
this.ImplementersToolStripMenuItem.Click += new System.EventHandler(this.ImplementersToolStripMenuItem_Click);
//
// отчетыToolStripMenuItem // отчетыToolStripMenuItem
// //
this.отчетыToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] { this.отчетыToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] {
@ -175,22 +171,20 @@
this.ordersToolStripMenuItem.Text = "Список заказов"; this.ordersToolStripMenuItem.Text = "Список заказов";
this.ordersToolStripMenuItem.Click += new System.EventHandler(this.OrdersToolStripMenuItem_Click); this.ordersToolStripMenuItem.Click += new System.EventHandler(this.OrdersToolStripMenuItem_Click);
// //
// клиентыToolStripMenuItem // DoWorkToolStripMenuItem
// //
this.клиентыToolStripMenuItem.Name = "клиентыToolStripMenuItem"; this.DoWorkToolStripMenuItem.Name = "DoWorkToolStripMenuItem";
this.клиентыToolStripMenuItem.Size = new System.Drawing.Size(224, 26); this.DoWorkToolStripMenuItem.Size = new System.Drawing.Size(114, 24);
this.клиентыToolStripMenuItem.Text = "Клиенты"; this.DoWorkToolStripMenuItem.Text = "Запуск работ";
this.клиентыToolStripMenuItem.Click += new System.EventHandler(this.клиентыToolStripMenuItem_Click); this.DoWorkToolStripMenuItem.Click += new System.EventHandler(this.DoWorkToolStripMenuItem_Click);
// //
// FormMain // FormMain
// //
this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F); this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(1273, 463); this.ClientSize = new System.Drawing.Size(1441, 463);
this.Controls.Add(this.buttonUpdate); this.Controls.Add(this.buttonUpdate);
this.Controls.Add(this.buttonSetToFinish); this.Controls.Add(this.buttonSetToFinish);
this.Controls.Add(this.buttonSetToDone);
this.Controls.Add(this.buttonSetToWork);
this.Controls.Add(this.buttonCreateOrder); this.Controls.Add(this.buttonCreateOrder);
this.Controls.Add(this.dataGridView); this.Controls.Add(this.dataGridView);
this.Controls.Add(this.menuStrip); this.Controls.Add(this.menuStrip);
@ -210,8 +204,6 @@
private Button buttonUpdate; private Button buttonUpdate;
private Button buttonSetToFinish; private Button buttonSetToFinish;
private Button buttonSetToDone;
private Button buttonSetToWork;
private Button buttonCreateOrder; private Button buttonCreateOrder;
private DataGridView dataGridView; private DataGridView dataGridView;
private MenuStrip menuStrip; private MenuStrip menuStrip;
@ -223,5 +215,7 @@
private ToolStripMenuItem iceCreamToolStripMenuItem; private ToolStripMenuItem iceCreamToolStripMenuItem;
private ToolStripMenuItem ordersToolStripMenuItem; private ToolStripMenuItem ordersToolStripMenuItem;
private ToolStripMenuItem клиентыToolStripMenuItem; private ToolStripMenuItem клиентыToolStripMenuItem;
private ToolStripMenuItem ImplementersToolStripMenuItem;
private ToolStripMenuItem DoWorkToolStripMenuItem;
} }
} }

View File

@ -21,12 +21,14 @@ namespace IceCreamShopView
private readonly ILogger _logger; private readonly ILogger _logger;
private readonly IOrderLogic _orderLogic; private readonly IOrderLogic _orderLogic;
private readonly IReportLogic _reportLogic; private readonly IReportLogic _reportLogic;
public FormMain(ILogger<FormMain> logger, IOrderLogic orderLogic, IReportLogic reportLogic) private readonly IWorkProcess _workProcess;
public FormMain(ILogger<FormMain> logger, IOrderLogic orderLogic, IReportLogic reportLogic, IWorkProcess workProcess)
{ {
InitializeComponent(); InitializeComponent();
_logger = logger; _logger = logger;
_orderLogic = orderLogic; _orderLogic = orderLogic;
_reportLogic = reportLogic; _reportLogic = reportLogic;
_workProcess = workProcess;
} }
private void FormMain_Load(object sender, EventArgs e) private void FormMain_Load(object sender, EventArgs e)
@ -45,6 +47,7 @@ namespace IceCreamShopView
dataGridView.DataSource = list; dataGridView.DataSource = list;
dataGridView.Columns["IceCreamId"].Visible = false; dataGridView.Columns["IceCreamId"].Visible = false;
dataGridView.Columns["ClientId"].Visible = false; dataGridView.Columns["ClientId"].Visible = false;
dataGridView.Columns["ImplementerId"].Visible = false;
} }
_logger.LogInformation("Загрузка заказов"); _logger.LogInformation("Загрузка заказов");
} }
@ -204,5 +207,22 @@ namespace IceCreamShopView
form.ShowDialog(); form.ShowDialog();
} }
} }
private void ImplementersToolStripMenuItem_Click(object sender, EventArgs e)
{
var service = Program.ServiceProvider?.GetService(typeof(FormImplementers));
if (service is FormImplementers form)
{
form.ShowDialog();
}
}
private void DoWorkToolStripMenuItem_Click(object sender, EventArgs e)
{
_workProcess.DoWork((
Program.ServiceProvider?.GetService(typeof(IImplementerLogic)) as IImplementerLogic)!,_orderLogic);
MessageBox.Show("Процесс обработки запущен", "Сообщение",
MessageBoxButtons.OK, MessageBoxIcon.Information);
}
} }
} }

View File

@ -58,6 +58,8 @@ namespace IceCreamShop
services.AddTransient<AbstractSaveToPdf, SaveToPdf>(); services.AddTransient<AbstractSaveToPdf, SaveToPdf>();
services.AddTransient<FormMain>(); services.AddTransient<FormMain>();
services.AddTransient<FormImplementer>();
services.AddTransient<FormImplementers>();
services.AddTransient<FormClients>(); services.AddTransient<FormClients>();
services.AddTransient<FormComponent>(); services.AddTransient<FormComponent>();
services.AddTransient<FormComponents>(); services.AddTransient<FormComponents>();

View File

@ -107,21 +107,14 @@ namespace IceCreamShopDatabaseImplement.Implements
public OrderViewModel? Update(OrderBindingModel model) public OrderViewModel? Update(OrderBindingModel model)
{ {
using var context = new IceCreamShopDatabase(); using var context = new IceCreamShopDatabase();
var order = context.Orders.FirstOrDefault(x => x.Id == model.Id);
var order = context.Orders
.Include(x => x.Client)
.Include(x => x.Implementer)
.FirstOrDefault(x => x.Id == model.Id);
if (order == null) if (order == null)
{ {
return null; return null;
} }
order.Update(model); order.Update(model);
context.SaveChanges(); context.SaveChanges();
return context.Orders.Include(x => x.IceCream).Include(x => x.Implementer).FirstOrDefault(x => x.Id == model.Id)?.GetViewModel;
return order.GetViewModel;
} }
} }
} }

View File

@ -26,8 +26,8 @@ namespace IceCreamShopDatabaseImplement.Models
public DateTime? DateImplement { get; set; } public DateTime? DateImplement { get; set; }
public int Id { get; set; } public int Id { get; set; }
public virtual IceCream IceCream{ get; set; } public virtual IceCream IceCream{ get; private set; }
public virtual Client Client { get; set; } public virtual Client Client { get; private set; }
public Implementer? Implementer { get; private set; } public Implementer? Implementer { get; private set; }
public static Order? Create(OrderBindingModel? model) public static Order? Create(OrderBindingModel? model)
{ {
@ -56,6 +56,7 @@ namespace IceCreamShopDatabaseImplement.Models
return; return;
} }
Status = model.Status; Status = model.Status;
ImplementerId = model.ImplementerId;
DateImplement = model.DateImplement; DateImplement = model.DateImplement;
} }
@ -76,7 +77,7 @@ namespace IceCreamShopDatabaseImplement.Models
DateImplement = DateImplement, DateImplement = DateImplement,
Id = Id, Id = Id,
IceCreamName = context.IceCreams.FirstOrDefault(x => x.Id == IceCreamId)?.IceCreamName ?? string.Empty, IceCreamName = context.IceCreams.FirstOrDefault(x => x.Id == IceCreamId)?.IceCreamName ?? string.Empty,
ImplementerFIO = Implementer?.ImplementerFIO ?? string.Empty, ImplementerFIO = context.Implementers.FirstOrDefault(x => x.Id == ImplementerId)?.ImplementerFIO ?? string.Empty,
ClientFIO = Client?.ClientFIO ?? string.Empty, ClientFIO = Client?.ClientFIO ?? string.Empty,
}; };
} }