Fix RepairName

This commit is contained in:
ShabOl 2024-03-19 20:56:40 +04:00
parent b2bfe09ae5
commit 0a09ce4051
15 changed files with 135 additions and 142 deletions

View File

@ -40,6 +40,7 @@
//
// RepairComboBox
//
RepairComboBox.DropDownStyle = ComboBoxStyle.DropDownList;
RepairComboBox.FormattingEnabled = true;
RepairComboBox.Location = new Point(103, 12);
RepairComboBox.Name = "RepairComboBox";
@ -62,7 +63,6 @@
SumTextBox.ReadOnly = true;
SumTextBox.Size = new Size(232, 23);
SumTextBox.TabIndex = 2;
SumTextBox.TextChanged += SumTextBox_TextChanged;
//
// SaveButton
//

View File

@ -8,38 +8,38 @@ namespace AutoWorkshopView.Forms
public partial class FormCreateOrder : Form
{
private readonly ILogger _logger;
private readonly IRepairLogic _logicI;
private readonly IOrderLogic _logicO;
private readonly IRepairLogic _repairLogic;
private readonly IOrderLogic _orderLogic;
public FormCreateOrder(ILogger<FormCreateOrder> Logger, IRepairLogic LogicI, IOrderLogic LogicO)
public FormCreateOrder(ILogger<FormCreateOrder> Logger, IRepairLogic RepairLogic, IOrderLogic OrderLogic)
{
InitializeComponent();
_logger = Logger;
_logicI = LogicI;
_logicO = LogicO;
_repairLogic = RepairLogic;
_orderLogic = OrderLogic;
}
private void FormCreateOrder_Load(object sender, EventArgs e)
{
_logger.LogInformation("Загрузка ремонта для заказа");
_logger.LogInformation("Загрузка ремонтов для заказа");
try
{
var list = _logicI.ReadList(null);
if (list != null)
var List = _repairLogic.ReadList(null);
if (List != null)
{
RepairComboBox.DisplayMember = "RepairName";
RepairComboBox.ValueMember = "Id";
RepairComboBox.DataSource = list;
RepairComboBox.DataSource = List;
RepairComboBox.SelectedItem = null;
}
_logger.LogInformation("Ремонт загружен");
_logger.LogInformation("Ремонты загружены");
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка загрузки ремонта");
_logger.LogError(ex, "Ошибка загрузки ремонтов");
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
@ -51,13 +51,13 @@ namespace AutoWorkshopView.Forms
try
{
int id = Convert.ToInt32(RepairComboBox.SelectedValue);
var Repair = _logicI.ReadElement(new RepairSearchModel
var Repair = _repairLogic.ReadElement(new RepairSearchModel
{
Id = id
});
int count = Convert.ToInt32(CountTextBox.Text);
int Count = Convert.ToInt32(CountTextBox.Text);
SumTextBox.Text = Math.Round(count * (Repair?.Price ?? 0), 2).ToString();
SumTextBox.Text = Math.Round(Count * (Repair?.Price ?? 0), 2).ToString();
_logger.LogInformation("Расчет суммы заказа");
}
@ -74,11 +74,6 @@ namespace AutoWorkshopView.Forms
CalcSum();
}
private void SumTextBox_TextChanged(object sender, EventArgs e)
{
CalcSum();
}
private void SaveButton_Click(object sender, EventArgs e)
{
if (string.IsNullOrEmpty(CountTextBox.Text))
@ -97,7 +92,7 @@ namespace AutoWorkshopView.Forms
try
{
var OperationResult = _logicO.CreateOrder(new OrderBindingModel
var OperationResult = _orderLogic.CreateOrder(new OrderBindingModel
{
RepairId = Convert.ToInt32(RepairComboBox.SelectedValue),
Count = Convert.ToInt32(CountTextBox.Text),

View File

@ -97,13 +97,11 @@ namespace AutoWorkshopView.Forms
if (_repairComponents.ContainsKey(Form.Id))
{
_repairComponents[Form.Id] = (Form.ComponentModel,
Form.Count);
_repairComponents[Form.Id] = (Form.ComponentModel, Form.Count);
}
else
{
_repairComponents.Add(Form.Id, (Form.ComponentModel,
Form.Count));
_repairComponents.Add(Form.Id, (Form.ComponentModel, Form.Count));
}
LoadData();
@ -146,7 +144,8 @@ namespace AutoWorkshopView.Forms
{
try
{
_logger.LogInformation("Удаление компонента: {ComponentName} - {Count}", DataGridView.SelectedRows[0].Cells[1].Value);
_logger.LogInformation("Удаление компонента: {ComponentName} - {Count}", DataGridView.SelectedRows[0].Cells[1].Value,
DataGridView.SelectedRows[0].Cells[2].Value);
_repairComponents?.Remove(Convert.ToInt32(DataGridView.SelectedRows[0].Cells[0].Value));
}

View File

@ -63,6 +63,7 @@
//
// ComboBox
//
ComboBox.DropDownStyle = ComboBoxStyle.DropDownList;
ComboBox.FormattingEnabled = true;
ComboBox.Location = new Point(95, 12);
ComboBox.Name = "ComboBox";

View File

@ -96,7 +96,7 @@
Controls.Add(AddButton);
Controls.Add(DataGridView);
Name = "FormRepairs";
Text = "FormRepairs";
Text = "Ремонты";
Load += FormRepairs_Load;
((System.ComponentModel.ISupportInitialize)DataGridView).EndInit();
ResumeLayout(false);

View File

@ -65,14 +65,14 @@
ComponentsStripMenuItem.Name = "ComponentsStripMenuItem";
ComponentsStripMenuItem.Size = new Size(180, 22);
ComponentsStripMenuItem.Text = "Компоненты";
ComponentsStripMenuItem.Click += КомпонентыStripMenuItem_Click;
ComponentsStripMenuItem.Click += ComponentsStripMenuItem_Click;
//
// RepairStripMenuItem
//
RepairStripMenuItem.Name = "RepairStripMenuItem";
RepairStripMenuItem.Size = new Size(180, 22);
RepairStripMenuItem.Text = "Ремонты";
RepairStripMenuItem.Click += МороженноеStripMenuItem_Click;
RepairStripMenuItem.Click += RepairsStripMenuItem_Click;
//
// DataGridView
//
@ -104,7 +104,7 @@
TakeInWorkButton.TabIndex = 3;
TakeInWorkButton.Text = "Отдать заказ в работу";
TakeInWorkButton.UseVisualStyleBackColor = true;
TakeInWorkButton.Click += TakeInWorkButton_Click;
TakeInWorkButton.Click += TakeOrderInWorkButton_Click;
//
// ReadyButton
//
@ -115,7 +115,7 @@
ReadyButton.TabIndex = 4;
ReadyButton.Text = "Заказ готов";
ReadyButton.UseVisualStyleBackColor = true;
ReadyButton.Click += ReadyButton_Click;
ReadyButton.Click += OrderReadyButton_Click;
//
// IssuedButton
//
@ -126,7 +126,7 @@
IssuedButton.TabIndex = 5;
IssuedButton.Text = "Заказ выдан";
IssuedButton.UseVisualStyleBackColor = true;
IssuedButton.Click += IssuedButton_Click;
IssuedButton.Click += OrderDeliveredButton_Click;
//
// RefreshButton
//

View File

@ -18,16 +18,6 @@ namespace AutoWorkshopView
_orderLogic = OrderLogic;
}
private void КомпонентыStripMenuItem_Click(object sender, EventArgs e)
{
var Service = Program.ServiceProvider?.GetService(typeof(FormComponents));
if (Service is FormComponents Form)
{
Form.ShowDialog();
}
}
private void MainForm_Load(object sender, EventArgs e)
{
LoadData();
@ -36,11 +26,11 @@ namespace AutoWorkshopView
private void LoadData()
{
_logger.LogInformation("Загрузка заказов");
try
{
var List = _orderLogic.ReadList(null);
if (List != null)
{
DataGridView.DataSource = List;
@ -57,10 +47,20 @@ namespace AutoWorkshopView
}
}
private void МороженноеStripMenuItem_Click(object sender, EventArgs e)
private void ComponentsStripMenuItem_Click(object sender, EventArgs e)
{
var Service = Program.ServiceProvider?.GetService(typeof(FormComponents));
if (Service is FormComponents Form)
{
Form.ShowDialog();
}
}
private void RepairsStripMenuItem_Click(object sender, EventArgs e)
{
var Service = Program.ServiceProvider?.GetService(typeof(FormRepairs));
if (Service is FormRepairs Form)
{
Form.ShowDialog();
@ -78,20 +78,7 @@ namespace AutoWorkshopView
}
}
private OrderBindingModel CreateBindingModel(int id, bool isDone = false)
{
return new OrderBindingModel
{
Id = id,
RepairId = Convert.ToInt32(DataGridView.SelectedRows[0].Cells["RepairId"].Value),
Status = Enum.Parse<OrderStatus>(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()),
};
}
private void TakeInWorkButton_Click(object sender, EventArgs e)
private void TakeOrderInWorkButton_Click(object sender, EventArgs e)
{
if (DataGridView.SelectedRows.Count == 1)
{
@ -101,7 +88,7 @@ namespace AutoWorkshopView
try
{
var OperationResult = _orderLogic.TakeOrderInWork(CreateBindingModel(id));
var OperationResult = _orderLogic.TakeOrderInWork(new OrderBindingModel { Id = id });
if (!OperationResult)
{
@ -119,7 +106,7 @@ namespace AutoWorkshopView
}
private void ReadyButton_Click(object sender, EventArgs e)
private void OrderReadyButton_Click(object sender, EventArgs e)
{
if (DataGridView.SelectedRows.Count == 1)
{
@ -129,7 +116,7 @@ namespace AutoWorkshopView
try
{
var OperationResult = _orderLogic.FinishOrder(CreateBindingModel(id));
var OperationResult = _orderLogic.FinishOrder(new OrderBindingModel { Id = id });
if (!OperationResult)
{
@ -146,7 +133,7 @@ namespace AutoWorkshopView
}
}
private void IssuedButton_Click(object sender, EventArgs e)
private void OrderDeliveredButton_Click(object sender, EventArgs e)
{
if (DataGridView.SelectedRows.Count == 1)
{
@ -156,7 +143,7 @@ namespace AutoWorkshopView
try
{
var OperationResult = _orderLogic.DeliveryOrder(CreateBindingModel(id));
var OperationResult = _orderLogic.DeliveryOrder(new OrderBindingModel { Id = id });
if (!OperationResult)
{

15
AutoWorkshop/nlog.config Normal file
View File

@ -0,0 +1,15 @@
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<nlog xmlns="http://www.nlog-project.org/schemas/NLog.xsd"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
autoReload="true" internalLogLevel="Info">
<targets>
<target xsi:type="File" name="tofile" fileName="log-${shortdate}.log" />
</targets>
<rules>
<logger name="*" minlevel="Debug" writeTo="tofile" />
</rules>
</nlog>
</configuration>

View File

@ -84,7 +84,7 @@ namespace AutoWorkshopBusinessLogic.BusinessLogics
public bool Delete(ComponentBindingModel Model)
{
CheckModel(Model);
CheckModel(Model, false);
_logger.LogInformation("Delete. Id:{Id}", Model.Id);
if (_componentStorage.Delete(Model) is null)

View File

@ -31,7 +31,7 @@ namespace AutoWorkshopBusinessLogic.BusinessLogics
return null;
}
_logger.LogInformation("ReadList. Count:{Count}", List.Count);
_logger.LogInformation("ReadList. Count: {Count}", List.Count);
return List;
}
@ -39,6 +39,14 @@ namespace AutoWorkshopBusinessLogic.BusinessLogics
{
CheckModel(Model);
if (Model.Status != OrderStatus.Undefined)
{
_logger.LogWarning("Invalid order status");
return false;
}
Model.Status = OrderStatus.Accepted;
if (_orderStorage.Insert(Model) is null)
{
_logger.LogWarning("Insert operation failed");
@ -48,81 +56,58 @@ namespace AutoWorkshopBusinessLogic.BusinessLogics
return true;
}
public bool TakeOrderInWork(OrderBindingModel Model)
private bool ChangeOrderStatus(OrderBindingModel Model, OrderStatus NewStatus)
{
CheckModel(Model);
CheckModel(Model, false);
var Element = _orderStorage.GetElement(new OrderSearchModel
{
Id = Model.Id
});
if (Element is null)
throw new InvalidOperationException("Заказ с таким идентификатором не существует");
Element.Status = OrderStatus.Accepted;
if (_orderStorage.Update(Model) is null)
var Order = _orderStorage.GetElement(new OrderSearchModel { Id = Model.Id });
if (Order == null)
{
_logger.LogWarning("Update operation failed");
_logger.LogWarning("Change status operation failed. Order not found");
return false;
}
if (Order.Status + 1 != NewStatus)
{
_logger.LogWarning("Change status operation failed. Incorrect new status: {NewStatus}. Current status: {currStatus}",
NewStatus, Order.Status);
return false;
}
Model.RepairId = Order.RepairId;
Model.Count = Order.Count;
Model.Sum = Order.Sum;
Model.DateCreate = Order.DateCreate;
Model.Status = NewStatus;
if (Model.Status == OrderStatus.Ready)
Model.DateImplement = DateTime.Now;
else
Model.DateImplement = Order.DateImplement;
if (_orderStorage.Update(Model) == null)
{
_logger.LogWarning("Change status operation failed");
return false;
}
return true;
}
public bool TakeOrderInWork(OrderBindingModel Model)
{
return ChangeOrderStatus(Model, OrderStatus.BeingProcessed);
}
public bool FinishOrder(OrderBindingModel Model)
{
CheckModel(Model);
var Element = _orderStorage.GetElement(new OrderSearchModel
{
Id = Model.Id
});
if (Element is null)
throw new InvalidOperationException("Заказ с таким идентификатором не существует");
if (Element.Status != OrderStatus.BeingProcessed)
{
_logger.LogWarning("FinishOrder. Invalid status");
return false;
}
if (_orderStorage.Update(Model) is null)
{
_logger.LogWarning("Update operation failed");
return false;
}
return true;
return ChangeOrderStatus(Model, OrderStatus.Ready);
}
public bool DeliveryOrder(OrderBindingModel Model)
{
CheckModel(Model);
var Element = _orderStorage.GetElement(new OrderSearchModel
{
Id = Model.Id
});
if (Element is null)
throw new InvalidOperationException("Заказ с таким идентификатором не существует");
if (Element.Status != OrderStatus.Ready)
{
_logger.LogWarning("DeliveryOrder. Invalid status");
return false;
}
if (_orderStorage.Update(Model) is null)
{
_logger.LogWarning("Update operation failed");
return false;
}
return true;
return ChangeOrderStatus(Model, OrderStatus.Delivered);
}
private void CheckModel(OrderBindingModel Model, bool WithParams = true)

View File

@ -6,11 +6,11 @@ namespace AutoWorkshopContracts.ViewModels
public class ComponentViewModel : IComponentModel
{
public int Id { get; set; }
[DisplayName("Название компонента")]
[DisplayName("Название компонента")]
public string ComponentName { get; set; } = string.Empty;
[DisplayName("Цена")]
[DisplayName("Цена")]
public double Cost { get; set; }
}
}

View File

@ -11,7 +11,7 @@ namespace AutoWorkshopContracts.ViewModels
public int RepairId { get; set; }
[DisplayName("Ремонт")]
[DisplayName("Ремонт")]
public string RepairName { get; set; } = string.Empty;
[DisplayName("Количество")]

View File

@ -6,11 +6,11 @@ namespace AutoWorkshopContracts.ViewModels
public class RepairViewModel : IRepairModel
{
public int Id { get; set; }
[DisplayName("Название изделия")]
[DisplayName("Название ремонта")]
public string RepairName { get; set; } = string.Empty;
[DisplayName("Цена")]
[DisplayName("Цена")]
public double Price { get; set; }
public Dictionary<int, (IComponentModel, int)> RepairComponents

View File

@ -3,6 +3,7 @@ using AutoWorkshopContracts.SearchModels;
using AutoWorkshopContracts.StoragesContracts;
using AutoWorkshopContracts.ViewModels;
using AutoWorkshopListImplement.Models;
using System.Reflection;
namespace AutoWorkshopListImplement.Implements
{
@ -21,7 +22,7 @@ namespace AutoWorkshopListImplement.Implements
foreach (var Order in _source.Orders)
{
Result.Add(Order.GetViewModel);
Result.Add(JoinRepairName(Order.GetViewModel));
}
return Result;
@ -38,7 +39,7 @@ namespace AutoWorkshopListImplement.Implements
{
if (Order.Id == Model.Id)
{
Result.Add(Order.GetViewModel);
Result.Add(JoinRepairName(Order.GetViewModel));
break;
}
}
@ -55,7 +56,7 @@ namespace AutoWorkshopListImplement.Implements
{
if (Order.Id == Model.Id)
{
return Order.GetViewModel;
return JoinRepairName(Order.GetViewModel);
}
}
@ -79,7 +80,7 @@ namespace AutoWorkshopListImplement.Implements
return null;
_source.Orders.Add(NewOrder);
return NewOrder.GetViewModel;
return JoinRepairName(NewOrder.GetViewModel);
}
public OrderViewModel? Update(OrderBindingModel Model)
@ -89,7 +90,7 @@ namespace AutoWorkshopListImplement.Implements
if (Order.Id == Model.Id)
{
Order.Update(Model);
return Order.GetViewModel;
return JoinRepairName(Order.GetViewModel);
}
}
@ -105,12 +106,22 @@ namespace AutoWorkshopListImplement.Implements
var Element = _source.Orders[i];
_source.Orders.RemoveAt(i);
return Element.GetViewModel;
return JoinRepairName(Element.GetViewModel);
}
}
return null;
}
private OrderViewModel JoinRepairName(OrderViewModel Model)
{
var SelectedRepair = _source.Repairs.Find(reinforced => reinforced.Id == Model.RepairId);
if (SelectedRepair != null)
{
Model.RepairName = SelectedRepair.RepairName;
}
return Model;
}
}
}