Исправление ошибок

This commit is contained in:
Валерия Никифорова 2023-02-19 01:38:22 +04:00
parent 0aa3494da6
commit 36bb460f12
17 changed files with 86 additions and 99 deletions

View File

@ -31,7 +31,7 @@
this.labelComponentName = new System.Windows.Forms.Label();
this.labelComponentPrice = new System.Windows.Forms.Label();
this.textBoxComponentName = new System.Windows.Forms.TextBox();
this.textBoxComponentPrice = new System.Windows.Forms.TextBox();
this.textBoxComponentCost = new System.Windows.Forms.TextBox();
this.buttonSave = new System.Windows.Forms.Button();
this.buttonCancel = new System.Windows.Forms.Button();
this.SuspendLayout();
@ -61,12 +61,12 @@
this.textBoxComponentName.Size = new System.Drawing.Size(283, 27);
this.textBoxComponentName.TabIndex = 2;
//
// textBoxComponentPrice
// textBoxComponentCost
//
this.textBoxComponentPrice.Location = new System.Drawing.Point(121, 52);
this.textBoxComponentPrice.Name = "textBoxComponentPrice";
this.textBoxComponentPrice.Size = new System.Drawing.Size(144, 27);
this.textBoxComponentPrice.TabIndex = 3;
this.textBoxComponentCost.Location = new System.Drawing.Point(121, 52);
this.textBoxComponentCost.Name = "textBoxComponentCost";
this.textBoxComponentCost.Size = new System.Drawing.Size(144, 27);
this.textBoxComponentCost.TabIndex = 3;
//
// buttonSave
//
@ -95,7 +95,7 @@
this.ClientSize = new System.Drawing.Size(429, 145);
this.Controls.Add(this.buttonCancel);
this.Controls.Add(this.buttonSave);
this.Controls.Add(this.textBoxComponentPrice);
this.Controls.Add(this.textBoxComponentCost);
this.Controls.Add(this.textBoxComponentName);
this.Controls.Add(this.labelComponentPrice);
this.Controls.Add(this.labelComponentName);
@ -112,7 +112,7 @@
private Label labelComponentName;
private Label labelComponentPrice;
private TextBox textBoxComponentName;
private TextBox textBoxComponentPrice;
private TextBox textBoxComponentCost;
private Button buttonSave;
private Button buttonCancel;
}

View File

@ -42,7 +42,7 @@ namespace AircraftPlantView
if (view != null)
{
textBoxComponentName.Text = view.ComponentName;
textBoxComponentPrice.Text = view.Cost.ToString();
textBoxComponentCost.Text = view.Cost.ToString();
}
}
catch (Exception ex)
@ -61,6 +61,11 @@ namespace AircraftPlantView
MessageBox.Show("Заполните название", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
if (string.IsNullOrEmpty(textBoxComponentCost.Text))
{
MessageBox.Show("Заполните стоимость", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
_logger.LogInformation("Сохранение комплектующего");
try
{
@ -68,7 +73,7 @@ namespace AircraftPlantView
{
Id = _id ?? 0,
ComponentName = textBoxComponentName.Text,
Cost = Convert.ToDouble(textBoxComponentPrice.Text)
Cost = Convert.ToDouble(textBoxComponentCost.Text)
};
var operationResult = _id.HasValue ? _logic.Update(model) : _logic.Create(model);
if (!operationResult)

View File

@ -80,6 +80,7 @@
this.textBoxCount.Name = "textBoxCount";
this.textBoxCount.Size = new System.Drawing.Size(297, 27);
this.textBoxCount.TabIndex = 4;
this.textBoxCount.TextChanged += new System.EventHandler(this.TextBoxCount_TextChanged);
//
// textBoxSum
//
@ -87,7 +88,6 @@
this.textBoxSum.Name = "textBoxSum";
this.textBoxSum.Size = new System.Drawing.Size(297, 27);
this.textBoxSum.TabIndex = 5;
this.textBoxSum.TextChanged += new System.EventHandler(this.TextBoxSum_TextChanged);
//
// buttonSave
//

View File

@ -73,7 +73,7 @@ namespace AircraftPlantView
}
}
private void TextBoxSum_TextChanged(object sender, EventArgs e)
private void TextBoxCount_TextChanged(object sender, EventArgs e)
{
CalcSum();
}
@ -87,7 +87,7 @@ namespace AircraftPlantView
{
if (string.IsNullOrEmpty(textBoxCount.Text))
{
MessageBox.Show("Заполните поле Количество", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
MessageBox.Show("Заполните поле количество", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
if (comboBoxPlane.SelectedValue == null)
@ -101,7 +101,6 @@ namespace AircraftPlantView
var operationResult = _logicO.CreateOrder(new OrderBindingModel
{
PlaneId = Convert.ToInt32(comboBoxPlane.SelectedValue),
PlaneName = comboBoxPlane.Text,
Count = Convert.ToInt32(textBoxCount.Text),
Sum = Convert.ToDouble(textBoxSum.Text)
});

View File

@ -49,7 +49,7 @@
this.справочникиToolStripMenuItem});
this.menuStrip.Location = new System.Drawing.Point(0, 0);
this.menuStrip.Name = "menuStrip";
this.menuStrip.Size = new System.Drawing.Size(1078, 28);
this.menuStrip.Size = new System.Drawing.Size(1180, 28);
this.menuStrip.TabIndex = 0;
this.menuStrip.Text = "menuStrip1";
//
@ -65,14 +65,14 @@
// комплектующиеToolStripMenuItem
//
this.комплектующиеToolStripMenuItem.Name = омплектующиеToolStripMenuItem";
this.комплектующиеToolStripMenuItem.Size = new System.Drawing.Size(224, 26);
this.комплектующиеToolStripMenuItem.Size = new System.Drawing.Size(207, 26);
this.комплектующиеToolStripMenuItem.Text = "Комплектующие";
this.комплектующиеToolStripMenuItem.Click += new System.EventHandler(this.комплектующиеToolStripMenuItem_Click);
//
// самолетыToolStripMenuItem
//
this.самолетыToolStripMenuItem.Name = "самолетыToolStripMenuItem";
this.самолетыToolStripMenuItem.Size = new System.Drawing.Size(224, 26);
this.самолетыToolStripMenuItem.Size = new System.Drawing.Size(207, 26);
this.самолетыToolStripMenuItem.Text = "Самолеты";
this.самолетыToolStripMenuItem.Click += new System.EventHandler(this.самолетыToolStripMenuItem_Click);
//
@ -83,12 +83,12 @@
this.dataGridView.Name = "dataGridView";
this.dataGridView.RowHeadersWidth = 51;
this.dataGridView.RowTemplate.Height = 29;
this.dataGridView.Size = new System.Drawing.Size(836, 341);
this.dataGridView.Size = new System.Drawing.Size(929, 341);
this.dataGridView.TabIndex = 1;
//
// buttonCreateOrder
//
this.buttonCreateOrder.Location = new System.Drawing.Point(863, 65);
this.buttonCreateOrder.Location = new System.Drawing.Point(961, 63);
this.buttonCreateOrder.Name = "buttonCreateOrder";
this.buttonCreateOrder.Size = new System.Drawing.Size(189, 29);
this.buttonCreateOrder.TabIndex = 2;
@ -98,7 +98,7 @@
//
// buttonSetToWork
//
this.buttonSetToWork.Location = new System.Drawing.Point(863, 126);
this.buttonSetToWork.Location = new System.Drawing.Point(961, 125);
this.buttonSetToWork.Name = "buttonSetToWork";
this.buttonSetToWork.Size = new System.Drawing.Size(189, 29);
this.buttonSetToWork.TabIndex = 3;
@ -108,7 +108,7 @@
//
// buttonSetToDone
//
this.buttonSetToDone.Location = new System.Drawing.Point(863, 186);
this.buttonSetToDone.Location = new System.Drawing.Point(961, 185);
this.buttonSetToDone.Name = "buttonSetToDone";
this.buttonSetToDone.Size = new System.Drawing.Size(189, 29);
this.buttonSetToDone.TabIndex = 4;
@ -118,7 +118,7 @@
//
// buttonSetToFinish
//
this.buttonSetToFinish.Location = new System.Drawing.Point(863, 249);
this.buttonSetToFinish.Location = new System.Drawing.Point(961, 246);
this.buttonSetToFinish.Name = "buttonSetToFinish";
this.buttonSetToFinish.Size = new System.Drawing.Size(189, 29);
this.buttonSetToFinish.TabIndex = 5;
@ -128,7 +128,7 @@
//
// buttonUpdate
//
this.buttonUpdate.Location = new System.Drawing.Point(863, 309);
this.buttonUpdate.Location = new System.Drawing.Point(961, 306);
this.buttonUpdate.Name = "buttonUpdate";
this.buttonUpdate.Size = new System.Drawing.Size(189, 29);
this.buttonUpdate.TabIndex = 6;
@ -140,7 +140,7 @@
//
this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(1078, 371);
this.ClientSize = new System.Drawing.Size(1180, 371);
this.Controls.Add(this.buttonUpdate);
this.Controls.Add(this.buttonSetToFinish);
this.Controls.Add(this.buttonSetToDone);

View File

@ -89,18 +89,12 @@ namespace AircraftPlantView
try
{
var operationResult = _orderLogic.TakeOrderInWork(new OrderBindingModel
{ //id,name,count,sum,status,start,end
Id = id,
PlaneId = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["PlaneId"].Value),
PlaneName = dataGridView.SelectedRows[0].Cells["PlaneName"].Value.ToString(),
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()),
{
Id = id
});
if (!operationResult)
{
throw new Exception("Ошибка при сохранении. Дополнительная информация в логах.");
throw new Exception("Заказ уже в статусе 'Выполняется'");
}
LoadData();
}
@ -123,17 +117,11 @@ namespace AircraftPlantView
{
var operationResult = _orderLogic.DeliveryOrder(new OrderBindingModel
{
Id = id,
PlaneId = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["PlaneId"].Value),
PlaneName = dataGridView.SelectedRows[0].Cells["PlaneName"].Value.ToString(),
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()),
Id = id
});
if (!operationResult)
{
throw new Exception("Ошибка при сохранении. Дополнительная информация в логах.");
throw new Exception("Заказ не в статусе 'Выполняется'");
}
LoadData();
}
@ -155,17 +143,11 @@ namespace AircraftPlantView
{
var operationResult = _orderLogic.FinishOrder(new OrderBindingModel
{
Id = id,
PlaneId = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["PlaneId"].Value),
PlaneName = dataGridView.SelectedRows[0].Cells["PlaneName"].Value.ToString(),
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()),
Id = id
});
if (!operationResult)
{
throw new Exception("Ошибка при сохранении. Дополнительная информация в логах.");
throw new Exception("Заказ не в статусе 'Готов'");
}
_logger.LogInformation("Заказ №{id} выдан", id);
LoadData();

View File

@ -38,11 +38,11 @@
this.buttonEdit = new System.Windows.Forms.Button();
this.buttonAdd = new System.Windows.Forms.Button();
this.dataGridView = new System.Windows.Forms.DataGridView();
this.buttonSave = new System.Windows.Forms.Button();
this.buttonCancel = new System.Windows.Forms.Button();
this.ID = new System.Windows.Forms.DataGridViewTextBoxColumn();
this.ColumnComponentName = new System.Windows.Forms.DataGridViewTextBoxColumn();
this.ColumnCount = new System.Windows.Forms.DataGridViewTextBoxColumn();
this.buttonSave = new System.Windows.Forms.Button();
this.buttonCancel = new System.Windows.Forms.Button();
this.groupBoxComponents.SuspendLayout();
((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit();
this.SuspendLayout();
@ -148,26 +148,6 @@
this.dataGridView.TabIndex = 0;
this.dataGridView.CellContentClick += new System.Windows.Forms.DataGridViewCellEventHandler(this.dataGridView_CellContentClick);
//
// buttonSave
//
this.buttonSave.Location = new System.Drawing.Point(460, 460);
this.buttonSave.Name = "buttonSave";
this.buttonSave.Size = new System.Drawing.Size(94, 29);
this.buttonSave.TabIndex = 5;
this.buttonSave.Text = "Сохранить";
this.buttonSave.UseVisualStyleBackColor = true;
this.buttonSave.Click += new System.EventHandler(this.ButtonSave_Click);
//
// buttonCancel
//
this.buttonCancel.Location = new System.Drawing.Point(570, 460);
this.buttonCancel.Name = "buttonCancel";
this.buttonCancel.Size = new System.Drawing.Size(94, 29);
this.buttonCancel.TabIndex = 6;
this.buttonCancel.Text = "Отмена";
this.buttonCancel.UseVisualStyleBackColor = true;
this.buttonCancel.Click += new System.EventHandler(this.ButtonCancel_Click);
//
// ID
//
this.ID.HeaderText = "ID";
@ -192,6 +172,26 @@
this.ColumnCount.Name = "ColumnCount";
this.ColumnCount.Width = 125;
//
// buttonSave
//
this.buttonSave.Location = new System.Drawing.Point(460, 460);
this.buttonSave.Name = "buttonSave";
this.buttonSave.Size = new System.Drawing.Size(94, 29);
this.buttonSave.TabIndex = 5;
this.buttonSave.Text = "Сохранить";
this.buttonSave.UseVisualStyleBackColor = true;
this.buttonSave.Click += new System.EventHandler(this.ButtonSave_Click);
//
// buttonCancel
//
this.buttonCancel.Location = new System.Drawing.Point(570, 460);
this.buttonCancel.Name = "buttonCancel";
this.buttonCancel.Size = new System.Drawing.Size(94, 29);
this.buttonCancel.TabIndex = 6;
this.buttonCancel.Text = "Отмена";
this.buttonCancel.UseVisualStyleBackColor = true;
this.buttonCancel.Click += new System.EventHandler(this.ButtonCancel_Click);
//
// FormPlane
//
this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F);

View File

@ -108,7 +108,7 @@ namespace AircraftPlantView
{
return;
}
_logger.LogInformation("Добавление нового комплектующего:{ ComponentName}- { Count}", form.ComponentModel.ComponentName, form.Count);
_logger.LogInformation("Добавление нового комплектующего:{ ComponentName} - { Count}", form.ComponentModel.ComponentName, form.Count);
if (_planeComponents.ContainsKey(form.Id))
{
_planeComponents[form.Id] = (form.ComponentModel, form.Count);
@ -138,7 +138,7 @@ namespace AircraftPlantView
{
return;
}
_logger.LogInformation("Изменение комплектующего:{ ComponentName}- { Count}", form.ComponentModel.ComponentName, form.Count);
_logger.LogInformation("Изменение комплектующего:{ ComponentName} - { Count}", form.ComponentModel.ComponentName, form.Count);
_planeComponents[form.Id] = (form.ComponentModel, form.Count);
LoadData();
}
@ -154,7 +154,7 @@ namespace AircraftPlantView
{
try
{
_logger.LogInformation("Удаление комплектующего:{ ComponentName}- { Count}", dataGridView.SelectedRows[0].Cells[1].Value);
_logger.LogInformation("Удаление комплектующего:{ ComponentName} - { Count}", dataGridView.SelectedRows[0].Cells[1].Value);
_planeComponents?.Remove(Convert.ToInt32(dataGridView.SelectedRows[0].Cells[0].Value));
}
catch (Exception ex)

View File

@ -44,23 +44,42 @@ namespace AircraftPlantBusinessLogic.BusinessLogics
public bool StatusUpdate(OrderBindingModel model, OrderStatus newStatus)
{
CheckModel(model);
if (model.Status + 1 != newStatus)
var viewModel = _orderStorage.GetElement(new OrderSearchModel
{
_logger.LogWarning("Status update to " + newStatus.ToString() + " operation failed. Order status incorrect.");
Id = model.Id
});
if (viewModel == null)
{
throw new ArgumentNullException(nameof(model));
}
if (viewModel.Status + 1 != newStatus)
{
_logger.LogWarning("Change status operation failed");
return false;
}
model.Status = newStatus;
if (model.Status == OrderStatus.Выдан) model.DateImplement = DateTime.Now;
if (model.Status == OrderStatus.Выдан)
{
model.DateImplement = DateTime.Now;
}
else
{
model.DateImplement = viewModel.DateImplement;
}
CheckModel(model, false);
if (_orderStorage.Update(model) == null)
{
model.Status--;
_logger.LogWarning("Update operation failed");
_logger.LogWarning("Change status operation failed");
return false;
}
return true;
}
public bool TakeOrderInWork(OrderBindingModel model)
{
return StatusUpdate(model, OrderStatus.Выполняется);
}
public bool DeliveryOrder(OrderBindingModel model)
{
return StatusUpdate(model, OrderStatus.Готов);
@ -84,11 +103,6 @@ namespace AircraftPlantBusinessLogic.BusinessLogics
return list;
}
public bool TakeOrderInWork(OrderBindingModel model)
{
return StatusUpdate(model, OrderStatus.Выполняется);
}
private void CheckModel(OrderBindingModel model, bool withParams = true)
{
if (model == null)

View File

@ -105,7 +105,7 @@ namespace AircraftPlantBusinessLogic.BusinessLogics
{
throw new ArgumentNullException("Стоимость самолета должна быть больше 0", nameof(model.Price));
}
_logger.LogInformation("Plane. PlaneName:{PlaneName}.Price:{ Price}. Id: { Id}", model.PlaneName, model.Price, model.Id);
_logger.LogInformation("Plane. PlaneName:{PlaneName}.Price:{ Cost}. Id: { Id}", model.PlaneName, model.Price, model.Id);
var element = _planeStorage.GetElement(new PlaneSearchModel
{
PlaneName = model.PlaneName

View File

@ -12,8 +12,6 @@ namespace AircraftPlantContracts.BindingModels
{
public int PlaneId { get; set; }
public string PlaneName { get; set; } = string.Empty;
public int Count { get; set; }
public double Sum { get; set; }

View File

@ -10,7 +10,6 @@ namespace AircraftPlantDataModels.Models
public interface IOrderModel : IId
{
int PlaneId { get; }
string PlaneName { get; }
int Count { get; }
double Sum { get; }
OrderStatus Status { get; }

View File

@ -15,8 +15,6 @@ namespace AircraftPlantListImplement.Models
{
public int PlaneId { get; private set; }
public string PlaneName { get; private set; } = string.Empty;
public int Count { get; private set; }
public double Sum { get; private set; }
@ -38,7 +36,6 @@ namespace AircraftPlantListImplement.Models
return new Order
{
PlaneId = model.PlaneId,
PlaneName = model.PlaneName,
Count = model.Count,
Sum = model.Sum,
Status = model.Status,
@ -54,20 +51,13 @@ namespace AircraftPlantListImplement.Models
{
return;
}
PlaneId = model.PlaneId;
PlaneName = model.PlaneName;
Count = model.Count;
Sum = model.Sum;
Status = model.Status;
DateCreate = model.DateCreate;
DateImplement = model.DateImplement;
Id = model.Id;
}
public OrderViewModel GetViewModel => new()
{
PlaneId = PlaneId,
PlaneName = PlaneName,
Count = Count,
Sum = Sum,
DateCreate = DateCreate,