PIbd-22. Shabunov O.A. Lab work 06 #9

Closed
olshab wants to merge 10 commits from Lab6 into Lab5
9 changed files with 86 additions and 54 deletions
Showing only changes of commit da4f49e290 - Show all commits

View File

@ -78,7 +78,7 @@ namespace AutoWorkshopBusinessLogic.BusinessLogics
Model.RepairId = Order.RepairId;
Model.ClientId = Order.ClientId;
Model.ImplementerId = Order.ImplementerId;
if (!Model.ImplementerId.HasValue) Model.ImplementerId = Order.ImplementerId;
Model.Count = Order.Count;
Model.Sum = Order.Sum;
Model.DateCreate = Order.DateCreate;

View File

@ -35,15 +35,17 @@ namespace AutoWorkshopBusinessLogic.BusinessLogics
}
var Orders = _orderLogic.ReadList(new OrderSearchModel { Status = OrderStatus.Accepted });
if (Orders == null || Orders.Count == 0)
var BeingProcessedOrders = _orderLogic.ReadList(new OrderSearchModel { Status = OrderStatus.BeingProcessed });
// in case there are BeingProcessed orders but no Accepted orders
if (Orders == null || BeingProcessedOrders == null || (Orders.Count == 0 && BeingProcessedOrders.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));
@ -65,17 +67,25 @@ namespace AutoWorkshopBusinessLogic.BusinessLogics
{
try
{
_logger.LogDebug("DoWork. Worker {Id} try get order {Order}", Implementer.Id, Order.Id);
_logger.LogDebug("WorkerWorkAsync. Worker {Id} try get order {Order}", Implementer.Id, Order.Id);
_orderLogic.TakeOrderInWork(new OrderBindingModel
// TakeOrderInWork will fail when the worker tries to change status to BeingProcessed when the order is already BeingProcessed
// which would happen when other worker already acquired that order
bool AcquireResult = _orderLogic.TakeOrderInWork(new OrderBindingModel
{
Id = Order.Id,
ImplementerId = Implementer.Id
});
if (!AcquireResult)
{
_logger.LogDebug("WorkerWorkAsync. Worker {Id} tried to get order {Order} but it's already acquired by other worker", Implementer.Id, Order.Id);
continue;
}
Thread.Sleep(Implementer.WorkExperience * _rnd.Next(100, 1000) * Order.Count);
_logger.LogDebug("DoWork. Worker {Id} finish order {Order}", Implementer.Id, Order.Id);
_logger.LogDebug("WorkerWorkAsync. Worker {Id} finish order {Order}", Implementer.Id, Order.Id);
_orderLogic.FinishOrder(new OrderBindingModel
{
Id = Order.Id
@ -116,10 +126,10 @@ namespace AutoWorkshopBusinessLogic.BusinessLogics
return;
}
_logger.LogDebug("DoWork. Worker {Id} back to order {Order}", Implementer.Id, RunOrder.Id);
_logger.LogDebug("RunOrderInWork. 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);
_logger.LogDebug("RunOrderInWork. Worker {Id} finish order {Order}", Implementer.Id, RunOrder.Id);
_orderLogic.FinishOrder(new OrderBindingModel
{
Id = RunOrder.Id

View File

@ -40,15 +40,17 @@ namespace AutoWorkshopDatabaseImplement.Implements
.Include(x => x.Repair)
.Include(x => x.Client)
.Include (x => x.Implementer)
.Where(x => (Model.Id.HasValue && x.Id == Model.Id) || (Model.ClientId.HasValue && x.ClientId == Model.ClientId)
|| (Model.ImplementerId.HasValue && x.ImplementerId == Model.ImplementerId))
.Where(x => (Model.Id.HasValue && x.Id == Model.Id)
|| (Model.ClientId.HasValue && x.ClientId == Model.ClientId)
|| (Model.ImplementerId.HasValue && x.ImplementerId == Model.ImplementerId)
|| (Model.Status.HasValue && x.Status == Model.Status))
.Select(x => x.GetViewModel)
.ToList();
}
public OrderViewModel? GetElement(OrderSearchModel Model)
{
if (!Model.Id.HasValue)
if (!Model.Id.HasValue && !Model.ImplementerId.HasValue && !Model.Status.HasValue)
return null;
using var Context = new AutoWorkshopDatabase();
@ -57,7 +59,8 @@ namespace AutoWorkshopDatabaseImplement.Implements
.Include(x => x.Repair)
.Include(x => x.Client)
.Include(x => x.Implementer)
.FirstOrDefault(x => Model.Id.HasValue && x.Id == Model.Id)?
.FirstOrDefault(x => (Model.Id.HasValue && x.Id == Model.Id)
|| (Model.ImplementerId.HasValue && Model.Status.HasValue && x.ImplementerId == Model.ImplementerId && x.Status == Model.Status) )?
.GetViewModel;
}

View File

@ -56,15 +56,17 @@ namespace AutoWorkshopFileImplement.Implements
public OrderViewModel? GetElement(OrderSearchModel Model)
{
if (!Model.Id.HasValue)
if (!Model.Id.HasValue && !Model.ImplementerId.HasValue && !Model.Status.HasValue)
return null;
var Order = _source.Orders.FirstOrDefault(x => (Model.Id.HasValue && x.Id == Model.Id));
var Order = _source.Orders.FirstOrDefault(x =>
(Model.Id.HasValue && x.Id == Model.Id)
|| (Model.ImplementerId.HasValue && Model.Status.HasValue && x.ImplementerId == Model.ImplementerId && x.Status == Model.Status) );
if (Order == null)
return null;
return AddRepairName(Order.GetViewModel);
return AddImplementerFIO(AddClientFIO(AddRepairName(Order.GetViewModel)));
}
public OrderViewModel? Insert(OrderBindingModel Model)

View File

@ -47,12 +47,13 @@ namespace AutoWorkshopListImplement.Implements
public OrderViewModel? GetElement(OrderSearchModel Model)
{
if (!Model.Id.HasValue)
if (!Model.Id.HasValue && !Model.ImplementerId.HasValue && !Model.Status.HasValue)
return null;
foreach (var Order in _source.Orders)
{
if ((Model.Id.HasValue && Order.Id == Model.Id) || (Model.ImplementerId.HasValue && Order.ImplementerId == Model.ImplementerId))
if ((Model.Id.HasValue && Order.Id == Model.Id)
|| (Model.ImplementerId.HasValue && Model.Status.HasValue && Order.ImplementerId == Model.ImplementerId && Order.Status == Model.Status))
{
return JoinImplementerFIO(JoinClientFIO(JoinRepairName(Order.GetViewModel)));
}

View File

@ -28,4 +28,10 @@
</None>
</ItemGroup>
<ItemGroup>
<None Update="nlog.config">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
</ItemGroup>
</Project>

View File

@ -28,6 +28,8 @@
/// </summary>
private void InitializeComponent()
{
ClientLabel = new Label();
ClientComboBox = new ComboBox();
RepairComboBox = new ComboBox();
CountTextBox = new TextBox();
SumTextBox = new TextBox();
@ -38,6 +40,24 @@
SumLabel = new Label();
SuspendLayout();
//
// ClientLabel
//
ClientLabel.AutoSize = true;
ClientLabel.Location = new Point(12, 102);
ClientLabel.Name = "ClientLabel";
ClientLabel.Size = new Size(49, 15);
ClientLabel.TabIndex = 8;
ClientLabel.Text = "Клиент:";
//
// ClientComboBox
//
ClientComboBox.DropDownStyle = ComboBoxStyle.DropDownList;
ClientComboBox.FormattingEnabled = true;
ClientComboBox.Location = new Point(103, 99);
ClientComboBox.Name = "ClientComboBox";
ClientComboBox.Size = new Size(232, 23);
ClientComboBox.TabIndex = 9;
//
// RepairComboBox
//
RepairComboBox.DropDownStyle = ComboBoxStyle.DropDownList;
@ -66,7 +86,7 @@
//
// SaveButton
//
SaveButton.Location = new Point(173, 107);
SaveButton.Location = new Point(173, 139);
SaveButton.Name = "SaveButton";
SaveButton.Size = new Size(81, 23);
SaveButton.TabIndex = 3;
@ -76,7 +96,7 @@
//
// CancelButton
//
CancelButton.Location = new Point(260, 107);
CancelButton.Location = new Point(260, 139);
CancelButton.Name = "CancelButton";
CancelButton.Size = new Size(75, 23);
CancelButton.TabIndex = 4;
@ -110,33 +130,15 @@
SumLabel.Size = new Size(48, 15);
SumLabel.TabIndex = 7;
SumLabel.Text = "Сумма:";
//
// labelClient
//
labelClient.AutoSize = true;
labelClient.Location = new Point(26, 131);
labelClient.Name = "labelClient";
labelClient.Size = new Size(58, 20);
labelClient.TabIndex = 8;
labelClient.Text = "Клиент";
//
// comboBoxClient
//
comboBoxClient.DropDownStyle = ComboBoxStyle.DropDownList;
comboBoxClient.FormattingEnabled = true;
comboBoxClient.Location = new Point(131, 131);
comboBoxClient.Name = "comboBoxClient";
comboBoxClient.Size = new Size(260, 28);
comboBoxClient.TabIndex = 9;
//
// FormCreateOrder
//
AutoScaleDimensions = new SizeF(7F, 15F);
//
// FormCreateOrder
//
AutoScaleDimensions = new SizeF(7F, 15F);
AutoScaleMode = AutoScaleMode.Font;
ClientSize = new Size(348, 142);
Controls.Add(comboBoxClient);
Controls.Add(labelClient);
Controls.Add(SumLabel);
ClientSize = new Size(348, 183);
Controls.Add(ClientComboBox);
Controls.Add(ClientLabel);
Controls.Add(SumLabel);
Controls.Add(CountLabel);
Controls.Add(RepairLabel);
Controls.Add(CancelButton);
@ -161,7 +163,7 @@
private Label RepairLabel;
private Label CountLabel;
private Label SumLabel;
private Label labelClient;
private ComboBox comboBoxClient;
private Label ClientLabel;
private ComboBox ClientComboBox;
}
}

View File

@ -51,10 +51,10 @@ namespace AutoWorkshopView.Forms
var list = _clientLogic.ReadList(null);
if (list != null)
{
comboBoxClient.DisplayMember = "ClientFIO";
comboBoxClient.ValueMember = "Id";
comboBoxClient.DataSource = list;
comboBoxClient.SelectedItem = null;
ClientComboBox.DisplayMember = "ClientFIO";
ClientComboBox.ValueMember = "Id";
ClientComboBox.DataSource = list;
ClientComboBox.SelectedItem = null;
}
_logger.LogInformation("Клиенты загружены");
}
@ -110,6 +110,12 @@ namespace AutoWorkshopView.Forms
return;
}
if (ClientComboBox.SelectedValue == null)
{
MessageBox.Show("Выберите клиента", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
_logger.LogInformation("Создание заказа");
try
@ -117,6 +123,7 @@ namespace AutoWorkshopView.Forms
var OperationResult = _orderLogic.CreateOrder(new OrderBindingModel
{
RepairId = Convert.ToInt32(RepairComboBox.SelectedValue),
ClientId = Convert.ToInt32(ClientComboBox.SelectedValue),
Count = Convert.ToInt32(CountTextBox.Text),
Sum = Convert.ToDouble(SumTextBox.Text)
});

View File

@ -227,7 +227,8 @@ namespace AutoWorkshopView
private void StartWorkToolStripMenuItem_Click(object sender, EventArgs e)
{
_workProcess.DoWork((Program.ServiceProvider?.GetService(typeof(IImplementerLogic)) as IImplementerLogic)!, _orderLogic);
var ImplementerLogic = Program.ServiceProvider?.GetService(typeof(IImplementerLogic));
_workProcess.DoWork((ImplementerLogic as IImplementerLogic)!, _orderLogic);
MessageBox.Show("Процесс обработки запущен", "Сообщение", MessageBoxButtons.OK, MessageBoxIcon.Information);
}