почти

This commit is contained in:
Макс Бондаренко 2023-02-13 22:11:33 +04:00
parent af8f468fe3
commit 6d0b5f9438
9 changed files with 62 additions and 45 deletions

View File

@ -24,7 +24,7 @@ namespace OrdersShopListImplement.Implements
var result = new List<OrderViewModel>();
foreach (var Order in _source.Orders)
{
result.Add(Order.GetViewModel);
result.Add(GetViewModel(Order));
}
return result;
}
@ -39,7 +39,7 @@ namespace OrdersShopListImplement.Implements
{
if (Order.Id == model.Id)
{
result.Add(Order.GetViewModel);
result.Add(GetViewModel(Order));
}
}
return result;
@ -54,7 +54,7 @@ namespace OrdersShopListImplement.Implements
{
if (model.Id.HasValue && Order.Id == model.Id)
{
return Order.GetViewModel;
return GetViewModel(Order);
}
}
return null;
@ -75,7 +75,7 @@ namespace OrdersShopListImplement.Implements
return null;
}
_source.Orders.Add(newOrder);
return newOrder.GetViewModel;
return GetViewModel(newOrder);
}
public OrderViewModel? Update(OrderBindingModel model)
{
@ -84,7 +84,7 @@ namespace OrdersShopListImplement.Implements
if (Order.Id == model.Id)
{
Order.Update(model);
return Order.GetViewModel;
return GetViewModel(Order);
}
}
return null;
@ -97,10 +97,24 @@ namespace OrdersShopListImplement.Implements
{
var element = _source.Orders[i];
_source.Orders.RemoveAt(i);
return element.GetViewModel;
return GetViewModel(element);
}
}
return null;
}
private OrderViewModel GetViewModel(Order order)
{
var viewModel = order.GetViewModel;
foreach (var comp in _source.Computers)
{
if (comp.Id == order.ComputerId)
{
viewModel.ComputerName = comp.ComputerName;
break;
}
}
return viewModel;
}
}
}

View File

@ -101,6 +101,7 @@
this.Controls.Add(this.label1);
this.Name = "FormComponent";
this.Text = "FormComponent";
this.Load += new System.EventHandler(this.FormComponent_Load);
this.ResumeLayout(false);
this.PerformLayout();

View File

@ -37,8 +37,7 @@ namespace ComputersShopView
_logger.LogInformation("Получение компонента");
var view = _logic.ReadElement(new ComponentSearchModel
{
Id =
_id.Value
Id = _id.Value
});
if (view != null)
{
@ -59,8 +58,7 @@ namespace ComputersShopView
{
if (string.IsNullOrEmpty(textBoxName.Text))
{
MessageBox.Show("Заполните название", "Ошибка",
MessageBoxButtons.OK, MessageBoxIcon.Error);
MessageBox.Show("Заполните название", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
_logger.LogInformation("Сохранение компонента");
@ -72,8 +70,7 @@ namespace ComputersShopView
ComponentName = textBoxName.Text,
Cost = Convert.ToDouble(textBoxCost.Text)
};
var operationResult = _id.HasValue ? _logic.Update(model) :
_logic.Create(model);
var operationResult = _id.HasValue ? _logic.Update(model) : _logic.Create(model);
if (!operationResult)
{
throw new Exception("Ошибка при сохранении. Дополнительная информация в логах.");

View File

@ -97,6 +97,7 @@
this.Controls.Add(this.dataGridView);
this.Name = "FormComponents";
this.Text = "Компоненты";
this.Load += new System.EventHandler(this.FormComponents_Load);
((System.ComponentModel.ISupportInitialize)(this.dataGridView)).EndInit();
this.ResumeLayout(false);

View File

@ -38,11 +38,11 @@
this.buttonUpd = 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.ColumnId = new System.Windows.Forms.DataGridViewTextBoxColumn();
this.ComponentColumn = new System.Windows.Forms.DataGridViewTextBoxColumn();
this.CountColumn = new System.Windows.Forms.DataGridViewTextBoxColumn();
this.buttonSave = new System.Windows.Forms.Button();
this.buttonCancel = new System.Windows.Forms.Button();
this.groupBox1.SuspendLayout();
((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit();
this.SuspendLayout();
@ -149,26 +149,6 @@
this.dataGridView.Size = new System.Drawing.Size(417, 307);
this.dataGridView.TabIndex = 0;
//
// buttonSave
//
this.buttonSave.Location = new System.Drawing.Point(449, 408);
this.buttonSave.Name = "buttonSave";
this.buttonSave.Size = new System.Drawing.Size(75, 23);
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(530, 408);
this.buttonCancel.Name = "buttonCancel";
this.buttonCancel.Size = new System.Drawing.Size(75, 23);
this.buttonCancel.TabIndex = 6;
this.buttonCancel.Text = "Отмена";
this.buttonCancel.UseVisualStyleBackColor = true;
this.buttonCancel.Click += new System.EventHandler(this.ButtonCancel_Click);
//
// ColumnId
//
this.ColumnId.HeaderText = "Column1";
@ -190,6 +170,26 @@
this.CountColumn.Name = "CountColumn";
this.CountColumn.ReadOnly = true;
//
// buttonSave
//
this.buttonSave.Location = new System.Drawing.Point(449, 408);
this.buttonSave.Name = "buttonSave";
this.buttonSave.Size = new System.Drawing.Size(75, 23);
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(530, 408);
this.buttonCancel.Name = "buttonCancel";
this.buttonCancel.Size = new System.Drawing.Size(75, 23);
this.buttonCancel.TabIndex = 6;
this.buttonCancel.Text = "Отмена";
this.buttonCancel.UseVisualStyleBackColor = true;
this.buttonCancel.Click += new System.EventHandler(this.ButtonCancel_Click);
//
// FormComputer
//
this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F);
@ -204,6 +204,7 @@
this.Controls.Add(this.label1);
this.Name = "FormComputer";
this.Text = "Компьютер";
this.Load += new System.EventHandler(this.FormComputer_Load);
this.groupBox1.ResumeLayout(false);
((System.ComponentModel.ISupportInitialize)(this.dataGridView)).EndInit();
this.ResumeLayout(false);

View File

@ -97,6 +97,7 @@
this.Controls.Add(this.dataGridView);
this.Name = "FormComputers";
this.Text = "Компьютеры";
this.Load += new System.EventHandler(this.FormComputers_Load);
((System.ComponentModel.ISupportInitialize)(this.dataGridView)).EndInit();
this.ResumeLayout(false);

View File

@ -124,6 +124,7 @@
this.Controls.Add(this.label1);
this.Name = "FormCreateOrder";
this.Text = "Заказ";
this.Load += new System.EventHandler(this.FormCreateOrder_Load);
this.ResumeLayout(false);
this.PerformLayout();

View File

@ -50,6 +50,7 @@ namespace ComputersShopView
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
private void CalcSum()
{
if (comboBoxComputer.SelectedValue != null && !string.IsNullOrEmpty(textBoxCount.Text))
@ -85,14 +86,12 @@ namespace ComputersShopView
{
if (string.IsNullOrEmpty(textBoxCount.Text))
{
MessageBox.Show("Заполните поле Количество", "Ошибка",
MessageBoxButtons.OK, MessageBoxIcon.Error);
MessageBox.Show("Заполните поле Количество", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
if (comboBoxComputer.SelectedValue == null)
{
MessageBox.Show("Выберите компьютер", "Ошибка",
MessageBoxButtons.OK, MessageBoxIcon.Error);
MessageBox.Show("Выберите компьютер", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
_logger.LogInformation("Создание заказа");

View File

@ -45,9 +45,7 @@
// menuStrip
//
this.menuStrip.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
this.справочникToolStripMenuItem,
this.computerToolStripMenuItem,
this.componentsToolStripMenuItem});
this.справочникToolStripMenuItem});
this.menuStrip.Location = new System.Drawing.Point(0, 0);
this.menuStrip.Name = "menuStrip";
this.menuStrip.Size = new System.Drawing.Size(1047, 24);
@ -56,6 +54,9 @@
//
// справочникToolStripMenuItem
//
this.справочникToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] {
this.computerToolStripMenuItem,
this.componentsToolStripMenuItem});
this.справочникToolStripMenuItem.Name = "справочникToolStripMenuItem";
this.справочникToolStripMenuItem.Size = new System.Drawing.Size(92, 20);
this.справочникToolStripMenuItem.Text = "справочники";
@ -63,14 +64,14 @@
// computerToolStripMenuItem
//
this.computerToolStripMenuItem.Name = "computerToolStripMenuItem";
this.computerToolStripMenuItem.Size = new System.Drawing.Size(91, 20);
this.computerToolStripMenuItem.Size = new System.Drawing.Size(180, 22);
this.computerToolStripMenuItem.Text = "компьютеры";
this.computerToolStripMenuItem.Click += new System.EventHandler(this.ComputersToolStripMenuItem_Click);
//
// componentsToolStripMenuItem
//
this.componentsToolStripMenuItem.Name = "componentsToolStripMenuItem";
this.componentsToolStripMenuItem.Size = new System.Drawing.Size(89, 20);
this.componentsToolStripMenuItem.Size = new System.Drawing.Size(180, 22);
this.componentsToolStripMenuItem.Text = "компоненты";
this.componentsToolStripMenuItem.Click += new System.EventHandler(this.ComponentsToolStripMenuItem_Click);
//
@ -148,6 +149,7 @@
this.MainMenuStrip = this.menuStrip;
this.Name = "FormMain";
this.Text = "Магазин электроники";
this.Load += new System.EventHandler(this.FormMain_Load);
this.menuStrip.ResumeLayout(false);
this.menuStrip.PerformLayout();
((System.ComponentModel.ISupportInitialize)(this.dataGridView)).EndInit();
@ -160,13 +162,13 @@
private MenuStrip menuStrip;
private ToolStripMenuItem справочникToolStripMenuItem;
private ToolStripMenuItem computerToolStripMenuItem;
private ToolStripMenuItem componentsToolStripMenuItem;
private DataGridView dataGridView;
private Button buttonCreateOrder;
private Button buttonTakeOrderInWork;
private Button buttonOrderReady;
private Button buttonIssuedOrder;
private Button buttonRef;
private ToolStripMenuItem computerToolStripMenuItem;
private ToolStripMenuItem componentsToolStripMenuItem;
}
}