доделать операции с заказом
This commit is contained in:
parent
3a88d14c31
commit
5f50a44a69
@ -3,7 +3,7 @@ Microsoft Visual Studio Solution File, Format Version 12.00
|
|||||||
# Visual Studio Version 17
|
# Visual Studio Version 17
|
||||||
VisualStudioVersion = 17.7.34221.43
|
VisualStudioVersion = 17.7.34221.43
|
||||||
MinimumVisualStudioVersion = 10.0.40219.1
|
MinimumVisualStudioVersion = 10.0.40219.1
|
||||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "FishFactory", "FishFactory.csproj", "{D820588F-CBC7-418A-8473-1224A24A8327}"
|
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "FishFactoryView", "FishFactoryView.csproj", "{D820588F-CBC7-418A-8473-1224A24A8327}"
|
||||||
EndProject
|
EndProject
|
||||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "FishFactoryBusinessLogic", "..\FishFactoryBusinessLogic\FishFactoryBusinessLogic.csproj", "{B2815667-7698-4714-8A4A-49E2D2D12897}"
|
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "FishFactoryBusinessLogic", "..\FishFactoryBusinessLogic\FishFactoryBusinessLogic.csproj", "{B2815667-7698-4714-8A4A-49E2D2D12897}"
|
||||||
EndProject
|
EndProject
|
||||||
|
@ -10,10 +10,13 @@
|
|||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Include="Microsoft.Extensions.Logging" Version="8.0.0" />
|
<PackageReference Include="Microsoft.Extensions.Logging" Version="8.0.0" />
|
||||||
|
<PackageReference Include="NLog.Extensions.Logging" Version="5.3.8" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
<ProjectReference Include="..\FishFactoryBusinessLogic\FishFactoryBusinessLogic.csproj" />
|
||||||
<ProjectReference Include="..\FishFactoryContracts\FishFactoryContracts.csproj" />
|
<ProjectReference Include="..\FishFactoryContracts\FishFactoryContracts.csproj" />
|
||||||
|
<ProjectReference Include="..\FishFactoryListImplement\FishFactoryListImplement.csproj" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
</Project>
|
</Project>
|
298
FishFactory/FormCanned.Designer.cs
generated
298
FishFactory/FormCanned.Designer.cs
generated
@ -28,163 +28,217 @@
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
private void InitializeComponent()
|
private void InitializeComponent()
|
||||||
{
|
{
|
||||||
this.label1 = new System.Windows.Forms.Label();
|
label1 = new Label();
|
||||||
this.label2 = new System.Windows.Forms.Label();
|
label2 = new Label();
|
||||||
this.button1 = new System.Windows.Forms.Button();
|
buttonAdd = new Button();
|
||||||
this.button2 = new System.Windows.Forms.Button();
|
buttonUpd = new Button();
|
||||||
this.button3 = new System.Windows.Forms.Button();
|
buttonDel = new Button();
|
||||||
this.button4 = new System.Windows.Forms.Button();
|
buttonRef = new Button();
|
||||||
this.dataGridView1 = new System.Windows.Forms.DataGridView();
|
dataGridView = new DataGridView();
|
||||||
this.Component = new System.Windows.Forms.DataGridViewTextBoxColumn();
|
Number = new DataGridViewTextBoxColumn();
|
||||||
this.Count = new System.Windows.Forms.DataGridViewTextBoxColumn();
|
Component = new DataGridViewTextBoxColumn();
|
||||||
this.textBox1 = new System.Windows.Forms.TextBox();
|
Count = new DataGridViewTextBoxColumn();
|
||||||
this.textBox2 = new System.Windows.Forms.TextBox();
|
textBoxName = new TextBox();
|
||||||
this.groupBox1 = new System.Windows.Forms.GroupBox();
|
textBoxPrice = new TextBox();
|
||||||
((System.ComponentModel.ISupportInitialize)(this.dataGridView1)).BeginInit();
|
groupBox1 = new GroupBox();
|
||||||
this.groupBox1.SuspendLayout();
|
buttonSave = new Button();
|
||||||
this.SuspendLayout();
|
buttonCancel = new Button();
|
||||||
|
((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit();
|
||||||
|
groupBox1.SuspendLayout();
|
||||||
|
SuspendLayout();
|
||||||
//
|
//
|
||||||
// label1
|
// label1
|
||||||
//
|
//
|
||||||
this.label1.AutoSize = true;
|
label1.AutoSize = true;
|
||||||
this.label1.Location = new System.Drawing.Point(18, 16);
|
label1.Location = new Point(18, 20);
|
||||||
this.label1.Name = "label1";
|
label1.Name = "label1";
|
||||||
this.label1.Size = new System.Drawing.Size(76, 16);
|
label1.Size = new Size(80, 20);
|
||||||
this.label1.TabIndex = 0;
|
label1.TabIndex = 0;
|
||||||
this.label1.Text = "Название:";
|
label1.Text = "Название:";
|
||||||
//
|
//
|
||||||
// label2
|
// label2
|
||||||
//
|
//
|
||||||
this.label2.AutoSize = true;
|
label2.AutoSize = true;
|
||||||
this.label2.Location = new System.Drawing.Point(18, 44);
|
label2.Location = new Point(18, 55);
|
||||||
this.label2.Name = "label2";
|
label2.Name = "label2";
|
||||||
this.label2.Size = new System.Drawing.Size(80, 16);
|
label2.Size = new Size(86, 20);
|
||||||
this.label2.TabIndex = 1;
|
label2.TabIndex = 1;
|
||||||
this.label2.Text = "Стоимость:";
|
label2.Text = "Стоимость:";
|
||||||
//
|
//
|
||||||
// button1
|
// buttonAdd
|
||||||
//
|
//
|
||||||
this.button1.Location = new System.Drawing.Point(661, 47);
|
buttonAdd.Location = new Point(656, 59);
|
||||||
this.button1.Name = "button1";
|
buttonAdd.Margin = new Padding(3, 4, 3, 4);
|
||||||
this.button1.Size = new System.Drawing.Size(97, 30);
|
buttonAdd.Name = "buttonAdd";
|
||||||
this.button1.TabIndex = 0;
|
buttonAdd.Size = new Size(111, 38);
|
||||||
this.button1.Text = "Добавить";
|
buttonAdd.TabIndex = 0;
|
||||||
this.button1.UseVisualStyleBackColor = true;
|
buttonAdd.Text = "Добавить";
|
||||||
|
buttonAdd.UseVisualStyleBackColor = true;
|
||||||
|
buttonAdd.Click += buttonAdd_Click;
|
||||||
//
|
//
|
||||||
// button2
|
// buttonUpd
|
||||||
//
|
//
|
||||||
this.button2.Location = new System.Drawing.Point(661, 96);
|
buttonUpd.Location = new Point(656, 120);
|
||||||
this.button2.Name = "button2";
|
buttonUpd.Margin = new Padding(3, 4, 3, 4);
|
||||||
this.button2.Size = new System.Drawing.Size(97, 30);
|
buttonUpd.Name = "buttonUpd";
|
||||||
this.button2.TabIndex = 1;
|
buttonUpd.Size = new Size(111, 38);
|
||||||
this.button2.Text = "Изменить";
|
buttonUpd.TabIndex = 1;
|
||||||
this.button2.UseVisualStyleBackColor = true;
|
buttonUpd.Text = "Изменить";
|
||||||
|
buttonUpd.UseVisualStyleBackColor = true;
|
||||||
|
buttonUpd.Click += buttonUpd_Click;
|
||||||
//
|
//
|
||||||
// button3
|
// buttonDel
|
||||||
//
|
//
|
||||||
this.button3.Location = new System.Drawing.Point(661, 142);
|
buttonDel.Location = new Point(656, 178);
|
||||||
this.button3.Name = "button3";
|
buttonDel.Margin = new Padding(3, 4, 3, 4);
|
||||||
this.button3.Size = new System.Drawing.Size(97, 30);
|
buttonDel.Name = "buttonDel";
|
||||||
this.button3.TabIndex = 2;
|
buttonDel.Size = new Size(111, 38);
|
||||||
this.button3.Text = "Удалить";
|
buttonDel.TabIndex = 2;
|
||||||
this.button3.UseVisualStyleBackColor = true;
|
buttonDel.Text = "Удалить";
|
||||||
|
buttonDel.UseVisualStyleBackColor = true;
|
||||||
|
buttonDel.Click += buttonDel_Click;
|
||||||
//
|
//
|
||||||
// button4
|
// buttonRef
|
||||||
//
|
//
|
||||||
this.button4.Location = new System.Drawing.Point(661, 185);
|
buttonRef.Location = new Point(656, 231);
|
||||||
this.button4.Name = "button4";
|
buttonRef.Margin = new Padding(3, 4, 3, 4);
|
||||||
this.button4.Size = new System.Drawing.Size(97, 30);
|
buttonRef.Name = "buttonRef";
|
||||||
this.button4.TabIndex = 3;
|
buttonRef.Size = new Size(111, 38);
|
||||||
this.button4.Text = "Обновить";
|
buttonRef.TabIndex = 3;
|
||||||
this.button4.UseVisualStyleBackColor = true;
|
buttonRef.Text = "Обновить";
|
||||||
|
buttonRef.UseVisualStyleBackColor = true;
|
||||||
|
buttonRef.Click += buttonRef_Click;
|
||||||
//
|
//
|
||||||
// dataGridView1
|
// dataGridView
|
||||||
//
|
//
|
||||||
this.dataGridView1.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
|
dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize;
|
||||||
this.dataGridView1.Columns.AddRange(new System.Windows.Forms.DataGridViewColumn[] {
|
dataGridView.Columns.AddRange(new DataGridViewColumn[] { Number, Component, Count });
|
||||||
this.Component,
|
dataGridView.Location = new Point(0, 26);
|
||||||
this.Count});
|
dataGridView.Margin = new Padding(3, 4, 3, 4);
|
||||||
this.dataGridView1.Location = new System.Drawing.Point(0, 21);
|
dataGridView.Name = "dataGridView";
|
||||||
this.dataGridView1.Name = "dataGridView1";
|
dataGridView.ReadOnly = true;
|
||||||
this.dataGridView1.RowHeadersWidth = 51;
|
dataGridView.RowHeadersWidth = 51;
|
||||||
this.dataGridView1.RowTemplate.Height = 24;
|
dataGridView.RowTemplate.Height = 24;
|
||||||
this.dataGridView1.Size = new System.Drawing.Size(627, 443);
|
dataGridView.SelectionMode = DataGridViewSelectionMode.FullRowSelect;
|
||||||
this.dataGridView1.TabIndex = 4;
|
dataGridView.ShowEditingIcon = false;
|
||||||
|
dataGridView.Size = new Size(627, 443);
|
||||||
|
dataGridView.TabIndex = 4;
|
||||||
|
//
|
||||||
|
// Number
|
||||||
|
//
|
||||||
|
Number.HeaderText = "Номер";
|
||||||
|
Number.MinimumWidth = 6;
|
||||||
|
Number.Name = "Number";
|
||||||
|
Number.Width = 60;
|
||||||
//
|
//
|
||||||
// Component
|
// Component
|
||||||
//
|
//
|
||||||
this.Component.HeaderText = "Компонент";
|
Component.HeaderText = "Компонент";
|
||||||
this.Component.MinimumWidth = 6;
|
Component.MinimumWidth = 6;
|
||||||
this.Component.Name = "Component";
|
Component.Name = "Component";
|
||||||
this.Component.Width = 125;
|
Component.Width = 125;
|
||||||
//
|
//
|
||||||
// Count
|
// Count
|
||||||
//
|
//
|
||||||
this.Count.HeaderText = "Количество";
|
Count.AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
|
||||||
this.Count.MinimumWidth = 6;
|
Count.HeaderText = "Количество";
|
||||||
this.Count.Name = "Count";
|
Count.MinimumWidth = 6;
|
||||||
this.Count.Width = 125;
|
Count.Name = "Count";
|
||||||
//
|
//
|
||||||
// textBox1
|
// textBoxName
|
||||||
//
|
//
|
||||||
this.textBox1.Location = new System.Drawing.Point(107, 14);
|
textBoxName.Location = new Point(107, 18);
|
||||||
this.textBox1.Name = "textBox1";
|
textBoxName.Margin = new Padding(3, 4, 3, 4);
|
||||||
this.textBox1.Size = new System.Drawing.Size(281, 22);
|
textBoxName.Name = "textBoxName";
|
||||||
this.textBox1.TabIndex = 3;
|
textBoxName.Size = new Size(281, 27);
|
||||||
|
textBoxName.TabIndex = 3;
|
||||||
//
|
//
|
||||||
// textBox2
|
// textBoxPrice
|
||||||
//
|
//
|
||||||
this.textBox2.Location = new System.Drawing.Point(107, 42);
|
textBoxPrice.Location = new Point(107, 52);
|
||||||
this.textBox2.Name = "textBox2";
|
textBoxPrice.Margin = new Padding(3, 4, 3, 4);
|
||||||
this.textBox2.Size = new System.Drawing.Size(97, 22);
|
textBoxPrice.Name = "textBoxPrice";
|
||||||
this.textBox2.TabIndex = 4;
|
textBoxPrice.ReadOnly = true;
|
||||||
|
textBoxPrice.Size = new Size(97, 27);
|
||||||
|
textBoxPrice.TabIndex = 4;
|
||||||
|
textBoxPrice.TabStop = false;
|
||||||
//
|
//
|
||||||
// groupBox1
|
// groupBox1
|
||||||
//
|
//
|
||||||
this.groupBox1.Controls.Add(this.button4);
|
groupBox1.Controls.Add(buttonRef);
|
||||||
this.groupBox1.Controls.Add(this.button3);
|
groupBox1.Controls.Add(buttonDel);
|
||||||
this.groupBox1.Controls.Add(this.dataGridView1);
|
groupBox1.Controls.Add(dataGridView);
|
||||||
this.groupBox1.Controls.Add(this.button2);
|
groupBox1.Controls.Add(buttonUpd);
|
||||||
this.groupBox1.Controls.Add(this.button1);
|
groupBox1.Controls.Add(buttonAdd);
|
||||||
this.groupBox1.Location = new System.Drawing.Point(16, 76);
|
groupBox1.Location = new Point(16, 95);
|
||||||
this.groupBox1.Name = "groupBox1";
|
groupBox1.Margin = new Padding(3, 4, 3, 4);
|
||||||
this.groupBox1.Size = new System.Drawing.Size(787, 464);
|
groupBox1.Name = "groupBox1";
|
||||||
this.groupBox1.TabIndex = 5;
|
groupBox1.Padding = new Padding(3, 4, 3, 4);
|
||||||
this.groupBox1.TabStop = false;
|
groupBox1.Size = new Size(787, 489);
|
||||||
this.groupBox1.Text = "Компоненты";
|
groupBox1.TabIndex = 5;
|
||||||
|
groupBox1.TabStop = false;
|
||||||
|
groupBox1.Text = "Компоненты";
|
||||||
|
//
|
||||||
|
// buttonSave
|
||||||
|
//
|
||||||
|
buttonSave.Location = new Point(454, 605);
|
||||||
|
buttonSave.Margin = new Padding(3, 4, 3, 4);
|
||||||
|
buttonSave.Name = "buttonSave";
|
||||||
|
buttonSave.Size = new Size(130, 38);
|
||||||
|
buttonSave.TabIndex = 0;
|
||||||
|
buttonSave.Text = "Сохранить";
|
||||||
|
buttonSave.UseVisualStyleBackColor = true;
|
||||||
|
buttonSave.Click += buttonSave_Click;
|
||||||
|
//
|
||||||
|
// buttonCancel
|
||||||
|
//
|
||||||
|
buttonCancel.Location = new Point(609, 605);
|
||||||
|
buttonCancel.Margin = new Padding(3, 4, 3, 4);
|
||||||
|
buttonCancel.Name = "buttonCancel";
|
||||||
|
buttonCancel.Size = new Size(130, 38);
|
||||||
|
buttonCancel.TabIndex = 0;
|
||||||
|
buttonCancel.Text = "Отмена";
|
||||||
|
buttonCancel.UseVisualStyleBackColor = true;
|
||||||
|
buttonCancel.Click += buttonCancel_Click;
|
||||||
//
|
//
|
||||||
// FormCanned
|
// FormCanned
|
||||||
//
|
//
|
||||||
this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 16F);
|
AutoScaleDimensions = new SizeF(8F, 20F);
|
||||||
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
AutoScaleMode = AutoScaleMode.Font;
|
||||||
this.ClientSize = new System.Drawing.Size(813, 558);
|
ClientSize = new Size(813, 663);
|
||||||
this.Controls.Add(this.groupBox1);
|
Controls.Add(groupBox1);
|
||||||
this.Controls.Add(this.textBox2);
|
Controls.Add(textBoxPrice);
|
||||||
this.Controls.Add(this.textBox1);
|
Controls.Add(textBoxName);
|
||||||
this.Controls.Add(this.label2);
|
Controls.Add(label2);
|
||||||
this.Controls.Add(this.label1);
|
Controls.Add(buttonCancel);
|
||||||
this.Name = "FormCanned";
|
Controls.Add(buttonSave);
|
||||||
this.Text = "FormCanned";
|
Controls.Add(label1);
|
||||||
((System.ComponentModel.ISupportInitialize)(this.dataGridView1)).EndInit();
|
Margin = new Padding(3, 4, 3, 4);
|
||||||
this.groupBox1.ResumeLayout(false);
|
Name = "FormCanned";
|
||||||
this.ResumeLayout(false);
|
Text = "Консерва";
|
||||||
this.PerformLayout();
|
Load += FormCanned_Load;
|
||||||
|
((System.ComponentModel.ISupportInitialize)dataGridView).EndInit();
|
||||||
|
groupBox1.ResumeLayout(false);
|
||||||
|
ResumeLayout(false);
|
||||||
|
PerformLayout();
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
private System.Windows.Forms.Label label1;
|
private Label label1;
|
||||||
private System.Windows.Forms.Label label2;
|
private Label label2;
|
||||||
private System.Windows.Forms.Button button4;
|
private Button buttonRef;
|
||||||
private System.Windows.Forms.Button button3;
|
private Button buttonDel;
|
||||||
private System.Windows.Forms.Button button2;
|
private Button buttonUpd;
|
||||||
private System.Windows.Forms.Button button1;
|
private Button buttonAdd;
|
||||||
private System.Windows.Forms.DataGridView dataGridView1;
|
private DataGridView dataGridView;
|
||||||
private System.Windows.Forms.DataGridViewTextBoxColumn Component;
|
private TextBox textBoxName;
|
||||||
private System.Windows.Forms.DataGridViewTextBoxColumn Count;
|
private TextBox textBoxPrice;
|
||||||
private System.Windows.Forms.TextBox textBox1;
|
private GroupBox groupBox1;
|
||||||
private System.Windows.Forms.TextBox textBox2;
|
private DataGridViewTextBoxColumn Number;
|
||||||
private System.Windows.Forms.GroupBox groupBox1;
|
private DataGridViewTextBoxColumn Component;
|
||||||
|
private DataGridViewTextBoxColumn Count;
|
||||||
|
private Button buttonSave;
|
||||||
|
private Button buttonCancel;
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -1,4 +1,6 @@
|
|||||||
using System;
|
using FishFactoryDataModel.Models;
|
||||||
|
using Microsoft.Extensions.Logging;
|
||||||
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.ComponentModel;
|
using System.ComponentModel;
|
||||||
using System.Data;
|
using System.Data;
|
||||||
@ -7,14 +9,197 @@ using System.Linq;
|
|||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using System.Windows.Forms;
|
using System.Windows.Forms;
|
||||||
|
using FishFactoryContracts.BusinessLogicsContracts;
|
||||||
|
using FishFactoryContracts.SearchModels;
|
||||||
|
using FishFactoryContracts.BindingModels;
|
||||||
|
|
||||||
namespace FishFactory.Forms
|
namespace FishFactory.Forms
|
||||||
{
|
{
|
||||||
public partial class FormCanned : Form
|
public partial class FormCanned : Form
|
||||||
{
|
{
|
||||||
public FormCanned()
|
private readonly ILogger _logger;
|
||||||
|
private readonly ICannedLogic _logic;
|
||||||
|
private int? _id;
|
||||||
|
private Dictionary<int, (IComponentModel, int)> _productComponents;
|
||||||
|
public int Id { set { _id = value; } }
|
||||||
|
public FormCanned(ILogger<FormCanned> logger, ICannedLogic logic)
|
||||||
{
|
{
|
||||||
InitializeComponent();
|
InitializeComponent();
|
||||||
|
_logger = logger;
|
||||||
|
_logic = logic;
|
||||||
|
_productComponents = new Dictionary<int, (IComponentModel, int)>();
|
||||||
|
}
|
||||||
|
private void FormCanned_Load(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
if (_id.HasValue)
|
||||||
|
{
|
||||||
|
_logger.LogInformation("Загрузка изделия");
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var view = _logic.ReadElement(new CannedSearchModel
|
||||||
|
{
|
||||||
|
Id = _id.Value
|
||||||
|
});
|
||||||
|
if (view != null)
|
||||||
|
{
|
||||||
|
textBoxName.Text = view.CannedName;
|
||||||
|
textBoxPrice.Text = view.Price.ToString();
|
||||||
|
_productComponents = view.CannedComponents ?? new Dictionary<int, (IComponentModel, int)>();
|
||||||
|
LoadData();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "Ошибка загрузки изделия");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
private void LoadData()
|
||||||
|
{
|
||||||
|
_logger.LogInformation("Загрузка компонент изделия");
|
||||||
|
try
|
||||||
|
{
|
||||||
|
if (_productComponents != null)
|
||||||
|
{
|
||||||
|
dataGridView.Rows.Clear();
|
||||||
|
foreach (var pc in _productComponents)
|
||||||
|
{
|
||||||
|
dataGridView.Rows.Add(new object[] { pc.Key, pc.Value.Item1.ComponentName, pc.Value.Item2 });
|
||||||
|
}
|
||||||
|
textBoxPrice.Text = CalcPrice().ToString();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "Ошибка загрузки компонент изделия");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
private void buttonAdd_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
var service = Program.ServiceProvider?.GetService(typeof(FormCannedComponent));
|
||||||
|
if (service is FormCannedComponent form)
|
||||||
|
{
|
||||||
|
if (form.ShowDialog() == DialogResult.OK)
|
||||||
|
{
|
||||||
|
if (form.ComponentModel == null)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
_logger.LogInformation("Добавление нового компонента: { ComponentName} - { Count} ", form.ComponentModel.ComponentName, form.Count);
|
||||||
|
if (_productComponents.ContainsKey(form.Id))
|
||||||
|
{
|
||||||
|
_productComponents[form.Id] = (form.ComponentModel, form.Count);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
_productComponents.Add(form.Id, (form.ComponentModel, form.Count));
|
||||||
|
}
|
||||||
|
LoadData();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
private void buttonUpd_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
if (dataGridView.SelectedRows.Count == 1)
|
||||||
|
{
|
||||||
|
var service = Program.ServiceProvider?.GetService(typeof(FormCannedComponent));
|
||||||
|
if (service is FormCannedComponent form)
|
||||||
|
{
|
||||||
|
int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells[0].Value);
|
||||||
|
form.Id = id;
|
||||||
|
form.Count = _productComponents[id].Item2;
|
||||||
|
if (form.ShowDialog() == DialogResult.OK)
|
||||||
|
{
|
||||||
|
if (form.ComponentModel == null)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
_logger.LogInformation("Изменение компонента: { ComponentName} - { Count}", form.ComponentModel.ComponentName, form.Count);
|
||||||
|
_productComponents[form.Id] = (form.ComponentModel, form.Count);
|
||||||
|
LoadData();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
private void buttonDel_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
if (dataGridView.SelectedRows.Count == 1)
|
||||||
|
{
|
||||||
|
if (MessageBox.Show("Удалить запись?", "Вопрос", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
_logger.LogInformation("Удаление компонента: { ComponentName} - { Count}", dataGridView.SelectedRows[0].Cells[1].Value);
|
||||||
|
_productComponents?.Remove(Convert.ToInt32(dataGridView.SelectedRows[0].Cells[0].Value));
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||||
|
}
|
||||||
|
LoadData();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
private void buttonRef_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
LoadData();
|
||||||
|
}
|
||||||
|
private void buttonSave_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
if (string.IsNullOrEmpty(textBoxName.Text))
|
||||||
|
{
|
||||||
|
MessageBox.Show("Заполните название", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (string.IsNullOrEmpty(textBoxPrice.Text))
|
||||||
|
{
|
||||||
|
MessageBox.Show("Заполните цену", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (_productComponents == null || _productComponents.Count == 0)
|
||||||
|
{
|
||||||
|
MessageBox.Show("Заполните компоненты", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
_logger.LogInformation("Сохранение изделия");
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var model = new CannedBindingModel
|
||||||
|
{
|
||||||
|
Id = _id ?? 0,
|
||||||
|
CannedName = textBoxName.Text,
|
||||||
|
Price = Convert.ToDouble(textBoxPrice.Text),
|
||||||
|
CannedComponents = _productComponents
|
||||||
|
};
|
||||||
|
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();
|
||||||
|
}
|
||||||
|
|
||||||
|
private double CalcPrice()
|
||||||
|
{
|
||||||
|
double price = 0;
|
||||||
|
foreach (var elem in _productComponents)
|
||||||
|
{
|
||||||
|
price += ((elem.Value.Item1?.Cost ?? 0) * elem.Value.Item2);
|
||||||
|
}
|
||||||
|
return Math.Round(price * 1.1, 2);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -117,10 +117,7 @@
|
|||||||
<resheader name="writer">
|
<resheader name="writer">
|
||||||
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||||
</resheader>
|
</resheader>
|
||||||
<metadata name="Component.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
|
<metadata name="Number.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
|
||||||
<value>True</value>
|
|
||||||
</metadata>
|
|
||||||
<metadata name="Count.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
|
|
||||||
<value>True</value>
|
<value>True</value>
|
||||||
</metadata>
|
</metadata>
|
||||||
<metadata name="Component.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
|
<metadata name="Component.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
|
||||||
|
134
FishFactory/FormCannedComponent.Designer.cs
generated
134
FishFactory/FormCannedComponent.Designer.cs
generated
@ -28,90 +28,96 @@
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
private void InitializeComponent()
|
private void InitializeComponent()
|
||||||
{
|
{
|
||||||
this.button1 = new System.Windows.Forms.Button();
|
buttonSave = new Button();
|
||||||
this.button2 = new System.Windows.Forms.Button();
|
buttonCancel = new Button();
|
||||||
this.label1 = new System.Windows.Forms.Label();
|
label1 = new Label();
|
||||||
this.label2 = new System.Windows.Forms.Label();
|
label2 = new Label();
|
||||||
this.comboBox1 = new System.Windows.Forms.ComboBox();
|
comboBoxComponent = new ComboBox();
|
||||||
this.textBox1 = new System.Windows.Forms.TextBox();
|
textBoxCount = new TextBox();
|
||||||
this.SuspendLayout();
|
SuspendLayout();
|
||||||
//
|
//
|
||||||
// button1
|
// buttonSave
|
||||||
//
|
//
|
||||||
this.button1.Location = new System.Drawing.Point(220, 80);
|
buttonSave.Location = new Point(199, 100);
|
||||||
this.button1.Name = "button1";
|
buttonSave.Margin = new Padding(3, 4, 3, 4);
|
||||||
this.button1.Size = new System.Drawing.Size(86, 29);
|
buttonSave.Name = "buttonSave";
|
||||||
this.button1.TabIndex = 0;
|
buttonSave.Size = new Size(98, 36);
|
||||||
this.button1.Text = "button1";
|
buttonSave.TabIndex = 0;
|
||||||
this.button1.UseVisualStyleBackColor = true;
|
buttonSave.Text = "Сохранить";
|
||||||
|
buttonSave.UseVisualStyleBackColor = true;
|
||||||
|
buttonSave.Click += buttonSave_Click;
|
||||||
//
|
//
|
||||||
// button2
|
// buttonCancel
|
||||||
//
|
//
|
||||||
this.button2.Location = new System.Drawing.Point(316, 80);
|
buttonCancel.Location = new Point(308, 100);
|
||||||
this.button2.Name = "button2";
|
buttonCancel.Margin = new Padding(3, 4, 3, 4);
|
||||||
this.button2.Size = new System.Drawing.Size(86, 29);
|
buttonCancel.Name = "buttonCancel";
|
||||||
this.button2.TabIndex = 1;
|
buttonCancel.Size = new Size(98, 36);
|
||||||
this.button2.Text = "button2";
|
buttonCancel.TabIndex = 1;
|
||||||
this.button2.UseVisualStyleBackColor = true;
|
buttonCancel.Text = "Отмена";
|
||||||
|
buttonCancel.UseVisualStyleBackColor = true;
|
||||||
|
buttonCancel.Click += buttonCancel_Click;
|
||||||
//
|
//
|
||||||
// label1
|
// label1
|
||||||
//
|
//
|
||||||
this.label1.AutoSize = true;
|
label1.AutoSize = true;
|
||||||
this.label1.Location = new System.Drawing.Point(14, 14);
|
label1.Location = new Point(14, 18);
|
||||||
this.label1.Name = "label1";
|
label1.Name = "label1";
|
||||||
this.label1.Size = new System.Drawing.Size(82, 16);
|
label1.Size = new Size(91, 20);
|
||||||
this.label1.TabIndex = 2;
|
label1.TabIndex = 2;
|
||||||
this.label1.Text = "Компонент:";
|
label1.Text = "Компонент:";
|
||||||
//
|
//
|
||||||
// label2
|
// label2
|
||||||
//
|
//
|
||||||
this.label2.AutoSize = true;
|
label2.AutoSize = true;
|
||||||
this.label2.Location = new System.Drawing.Point(14, 46);
|
label2.Location = new Point(14, 58);
|
||||||
this.label2.Name = "label2";
|
label2.Name = "label2";
|
||||||
this.label2.Size = new System.Drawing.Size(88, 16);
|
label2.Size = new Size(93, 20);
|
||||||
this.label2.TabIndex = 3;
|
label2.TabIndex = 3;
|
||||||
this.label2.Text = "Количество:";
|
label2.Text = "Количество:";
|
||||||
//
|
//
|
||||||
// comboBox1
|
// comboBoxComponent
|
||||||
//
|
//
|
||||||
this.comboBox1.FormattingEnabled = true;
|
comboBoxComponent.FormattingEnabled = true;
|
||||||
this.comboBox1.Location = new System.Drawing.Point(121, 10);
|
comboBoxComponent.Location = new Point(121, 12);
|
||||||
this.comboBox1.Name = "comboBox1";
|
comboBoxComponent.Margin = new Padding(3, 4, 3, 4);
|
||||||
this.comboBox1.Size = new System.Drawing.Size(285, 24);
|
comboBoxComponent.Name = "comboBoxComponent";
|
||||||
this.comboBox1.TabIndex = 4;
|
comboBoxComponent.Size = new Size(285, 28);
|
||||||
|
comboBoxComponent.TabIndex = 4;
|
||||||
//
|
//
|
||||||
// textBox1
|
// textBoxCount
|
||||||
//
|
//
|
||||||
this.textBox1.Location = new System.Drawing.Point(121, 46);
|
textBoxCount.Location = new Point(121, 58);
|
||||||
this.textBox1.Name = "textBox1";
|
textBoxCount.Margin = new Padding(3, 4, 3, 4);
|
||||||
this.textBox1.Size = new System.Drawing.Size(285, 22);
|
textBoxCount.Name = "textBoxCount";
|
||||||
this.textBox1.TabIndex = 5;
|
textBoxCount.Size = new Size(285, 27);
|
||||||
|
textBoxCount.TabIndex = 5;
|
||||||
//
|
//
|
||||||
// FormCannedComponent
|
// FormCannedComponent
|
||||||
//
|
//
|
||||||
this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 16F);
|
AutoScaleDimensions = new SizeF(8F, 20F);
|
||||||
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
AutoScaleMode = AutoScaleMode.Font;
|
||||||
this.ClientSize = new System.Drawing.Size(426, 120);
|
ClientSize = new Size(426, 150);
|
||||||
this.Controls.Add(this.textBox1);
|
Controls.Add(textBoxCount);
|
||||||
this.Controls.Add(this.comboBox1);
|
Controls.Add(comboBoxComponent);
|
||||||
this.Controls.Add(this.label2);
|
Controls.Add(label2);
|
||||||
this.Controls.Add(this.label1);
|
Controls.Add(label1);
|
||||||
this.Controls.Add(this.button2);
|
Controls.Add(buttonCancel);
|
||||||
this.Controls.Add(this.button1);
|
Controls.Add(buttonSave);
|
||||||
this.Name = "FormCannedComponent";
|
Margin = new Padding(3, 4, 3, 4);
|
||||||
this.Text = "FormCannedComponent";
|
Name = "FormCannedComponent";
|
||||||
this.ResumeLayout(false);
|
Text = "Компонент консервы";
|
||||||
this.PerformLayout();
|
ResumeLayout(false);
|
||||||
|
PerformLayout();
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
private System.Windows.Forms.Button button1;
|
private Button buttonSave;
|
||||||
private System.Windows.Forms.Button button2;
|
private Button buttonCancel;
|
||||||
private System.Windows.Forms.Label label1;
|
private Label label1;
|
||||||
private System.Windows.Forms.Label label2;
|
private Label label2;
|
||||||
private System.Windows.Forms.ComboBox comboBox1;
|
private ComboBox comboBoxComponent;
|
||||||
private System.Windows.Forms.TextBox textBox1;
|
private TextBox textBoxCount;
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -1,4 +1,7 @@
|
|||||||
using System;
|
using FishFactoryContracts.BusinessLogicsContracts;
|
||||||
|
using FishFactoryContracts.ViewModels;
|
||||||
|
using FishFactoryDataModel.Models;
|
||||||
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.ComponentModel;
|
using System.ComponentModel;
|
||||||
using System.Data;
|
using System.Data;
|
||||||
@ -12,9 +15,75 @@ namespace FishFactory.Forms
|
|||||||
{
|
{
|
||||||
public partial class FormCannedComponent : Form
|
public partial class FormCannedComponent : Form
|
||||||
{
|
{
|
||||||
public FormCannedComponent()
|
private readonly List<ComponentViewModel>? _list;
|
||||||
|
public int Id
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
return Convert.ToInt32(comboBoxComponent.SelectedValue);
|
||||||
|
}
|
||||||
|
set
|
||||||
|
{
|
||||||
|
comboBoxComponent.SelectedValue = value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
public IComponentModel? ComponentModel
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
if (_list == null)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
foreach (var elem in _list)
|
||||||
|
{
|
||||||
|
if (elem.Id == Id)
|
||||||
|
{
|
||||||
|
return elem;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
public int Count
|
||||||
|
{
|
||||||
|
get { return Convert.ToInt32(textBoxCount.Text); }
|
||||||
|
set { textBoxCount.Text = value.ToString(); }
|
||||||
|
}
|
||||||
|
|
||||||
|
public FormCannedComponent(IComponentLogic logic)
|
||||||
{
|
{
|
||||||
InitializeComponent();
|
InitializeComponent();
|
||||||
|
|
||||||
|
_list = logic.ReadList(null);
|
||||||
|
if (_list != null)
|
||||||
|
{
|
||||||
|
comboBoxComponent.DisplayMember = "ComponentName";
|
||||||
|
comboBoxComponent.ValueMember = "Id";
|
||||||
|
comboBoxComponent.DataSource = _list;
|
||||||
|
comboBoxComponent.SelectedItem = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void buttonSave_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
if (string.IsNullOrEmpty(textBoxCount.Text))
|
||||||
|
{
|
||||||
|
MessageBox.Show("Заполните поле Количество", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (comboBoxComponent.SelectedValue == null)
|
||||||
|
{
|
||||||
|
MessageBox.Show("Выберите компонент", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
DialogResult = DialogResult.OK;
|
||||||
|
Close();
|
||||||
|
}
|
||||||
|
private void buttonCancel_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
DialogResult = DialogResult.Cancel;
|
||||||
|
Close();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
120
FishFactory/FormCanneds.Designer.cs
generated
Normal file
120
FishFactory/FormCanneds.Designer.cs
generated
Normal file
@ -0,0 +1,120 @@
|
|||||||
|
namespace FishFactory.Forms
|
||||||
|
{
|
||||||
|
partial class FormCanneds
|
||||||
|
{
|
||||||
|
/// <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()
|
||||||
|
{
|
||||||
|
buttonRef = new Button();
|
||||||
|
buttonDel = new Button();
|
||||||
|
buttonUpd = new Button();
|
||||||
|
buttonAdd = new Button();
|
||||||
|
dataGridView = new DataGridView();
|
||||||
|
((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit();
|
||||||
|
SuspendLayout();
|
||||||
|
//
|
||||||
|
// buttonRef
|
||||||
|
//
|
||||||
|
buttonRef.Location = new Point(740, 180);
|
||||||
|
buttonRef.Margin = new Padding(3, 4, 3, 4);
|
||||||
|
buttonRef.Name = "buttonRef";
|
||||||
|
buttonRef.Size = new Size(128, 35);
|
||||||
|
buttonRef.TabIndex = 9;
|
||||||
|
buttonRef.Text = "Обновить";
|
||||||
|
buttonRef.UseVisualStyleBackColor = true;
|
||||||
|
buttonRef.Click += buttonRef_Click;
|
||||||
|
//
|
||||||
|
// buttonDel
|
||||||
|
//
|
||||||
|
buttonDel.Location = new Point(740, 129);
|
||||||
|
buttonDel.Margin = new Padding(3, 4, 3, 4);
|
||||||
|
buttonDel.Name = "buttonDel";
|
||||||
|
buttonDel.Size = new Size(128, 35);
|
||||||
|
buttonDel.TabIndex = 8;
|
||||||
|
buttonDel.Text = "Удалить";
|
||||||
|
buttonDel.UseVisualStyleBackColor = true;
|
||||||
|
buttonDel.Click += buttonDel_Click;
|
||||||
|
//
|
||||||
|
// buttonUpd
|
||||||
|
//
|
||||||
|
buttonUpd.Location = new Point(740, 77);
|
||||||
|
buttonUpd.Margin = new Padding(3, 4, 3, 4);
|
||||||
|
buttonUpd.Name = "buttonUpd";
|
||||||
|
buttonUpd.Size = new Size(128, 35);
|
||||||
|
buttonUpd.TabIndex = 7;
|
||||||
|
buttonUpd.Text = "Изменить";
|
||||||
|
buttonUpd.UseVisualStyleBackColor = true;
|
||||||
|
buttonUpd.Click += buttonUpd_Click;
|
||||||
|
//
|
||||||
|
// buttonAdd
|
||||||
|
//
|
||||||
|
buttonAdd.Location = new Point(740, 27);
|
||||||
|
buttonAdd.Margin = new Padding(3, 4, 3, 4);
|
||||||
|
buttonAdd.Name = "buttonAdd";
|
||||||
|
buttonAdd.Size = new Size(128, 35);
|
||||||
|
buttonAdd.TabIndex = 6;
|
||||||
|
buttonAdd.Text = "Добавить";
|
||||||
|
buttonAdd.UseVisualStyleBackColor = true;
|
||||||
|
buttonAdd.Click += buttonAdd_Click;
|
||||||
|
//
|
||||||
|
// dataGridView
|
||||||
|
//
|
||||||
|
dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize;
|
||||||
|
dataGridView.Location = new Point(-1, 0);
|
||||||
|
dataGridView.Margin = new Padding(3, 4, 3, 4);
|
||||||
|
dataGridView.Name = "dataGridView";
|
||||||
|
dataGridView.ReadOnly = true;
|
||||||
|
dataGridView.RowHeadersWidth = 51;
|
||||||
|
dataGridView.RowTemplate.Height = 24;
|
||||||
|
dataGridView.Size = new Size(709, 568);
|
||||||
|
dataGridView.TabIndex = 5;
|
||||||
|
//
|
||||||
|
// FormCanneds
|
||||||
|
//
|
||||||
|
AutoScaleDimensions = new SizeF(8F, 20F);
|
||||||
|
AutoScaleMode = AutoScaleMode.Font;
|
||||||
|
ClientSize = new Size(895, 570);
|
||||||
|
Controls.Add(buttonRef);
|
||||||
|
Controls.Add(buttonDel);
|
||||||
|
Controls.Add(buttonUpd);
|
||||||
|
Controls.Add(buttonAdd);
|
||||||
|
Controls.Add(dataGridView);
|
||||||
|
Name = "FormCanneds";
|
||||||
|
Text = "Список консерв";
|
||||||
|
Load += FormCanneds_Load;
|
||||||
|
((System.ComponentModel.ISupportInitialize)dataGridView).EndInit();
|
||||||
|
ResumeLayout(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
private Button buttonRef;
|
||||||
|
private Button buttonDel;
|
||||||
|
private Button buttonUpd;
|
||||||
|
private Button buttonAdd;
|
||||||
|
private DataGridView dataGridView;
|
||||||
|
}
|
||||||
|
}
|
115
FishFactory/FormCanneds.cs
Normal file
115
FishFactory/FormCanneds.cs
Normal file
@ -0,0 +1,115 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.ComponentModel;
|
||||||
|
using System.Data;
|
||||||
|
using System.Drawing;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using System.Windows.Forms;
|
||||||
|
using FishFactory;
|
||||||
|
using FishFactoryContracts.BindingModels;
|
||||||
|
using FishFactoryContracts.BusinessLogicsContracts;
|
||||||
|
using Microsoft.Extensions.Logging;
|
||||||
|
|
||||||
|
namespace FishFactory.Forms
|
||||||
|
{
|
||||||
|
public partial class FormCanneds : Form
|
||||||
|
{
|
||||||
|
private readonly ILogger _logger;
|
||||||
|
private readonly ICannedLogic _logic;
|
||||||
|
public FormCanneds(ILogger<FormCanneds> logger, ICannedLogic logic)
|
||||||
|
{
|
||||||
|
InitializeComponent();
|
||||||
|
_logger = logger;
|
||||||
|
_logic = logic;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void FormCanneds_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["CannedComponents"].Visible = false;
|
||||||
|
dataGridView.Columns["CannedName"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
|
||||||
|
}
|
||||||
|
_logger.LogInformation("Загрузка консерв");
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "Ошибка загрузки компонентов");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void buttonAdd_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
var service = Program.ServiceProvider?.GetService(typeof(FormCanned));
|
||||||
|
if (service is FormCanned 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(FormCanned));
|
||||||
|
if (service is FormCanned 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 CannedBindingModel
|
||||||
|
{
|
||||||
|
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();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
120
FishFactory/FormCanneds.resx
Normal file
120
FishFactory/FormCanneds.resx
Normal file
@ -0,0 +1,120 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<root>
|
||||||
|
<!--
|
||||||
|
Microsoft ResX Schema
|
||||||
|
|
||||||
|
Version 2.0
|
||||||
|
|
||||||
|
The primary goals of this format is to allow a simple XML format
|
||||||
|
that is mostly human readable. The generation and parsing of the
|
||||||
|
various data types are done through the TypeConverter classes
|
||||||
|
associated with the data types.
|
||||||
|
|
||||||
|
Example:
|
||||||
|
|
||||||
|
... ado.net/XML headers & schema ...
|
||||||
|
<resheader name="resmimetype">text/microsoft-resx</resheader>
|
||||||
|
<resheader name="version">2.0</resheader>
|
||||||
|
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
|
||||||
|
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
|
||||||
|
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
|
||||||
|
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
|
||||||
|
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
|
||||||
|
<value>[base64 mime encoded serialized .NET Framework object]</value>
|
||||||
|
</data>
|
||||||
|
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
|
||||||
|
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
|
||||||
|
<comment>This is a comment</comment>
|
||||||
|
</data>
|
||||||
|
|
||||||
|
There are any number of "resheader" rows that contain simple
|
||||||
|
name/value pairs.
|
||||||
|
|
||||||
|
Each data row contains a name, and value. The row also contains a
|
||||||
|
type or mimetype. Type corresponds to a .NET class that support
|
||||||
|
text/value conversion through the TypeConverter architecture.
|
||||||
|
Classes that don't support this are serialized and stored with the
|
||||||
|
mimetype set.
|
||||||
|
|
||||||
|
The mimetype is used for serialized objects, and tells the
|
||||||
|
ResXResourceReader how to depersist the object. This is currently not
|
||||||
|
extensible. For a given mimetype the value must be set accordingly:
|
||||||
|
|
||||||
|
Note - application/x-microsoft.net.object.binary.base64 is the format
|
||||||
|
that the ResXResourceWriter will generate, however the reader can
|
||||||
|
read any of the formats listed below.
|
||||||
|
|
||||||
|
mimetype: application/x-microsoft.net.object.binary.base64
|
||||||
|
value : The object must be serialized with
|
||||||
|
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
|
||||||
|
: and then encoded with base64 encoding.
|
||||||
|
|
||||||
|
mimetype: application/x-microsoft.net.object.soap.base64
|
||||||
|
value : The object must be serialized with
|
||||||
|
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
|
||||||
|
: and then encoded with base64 encoding.
|
||||||
|
|
||||||
|
mimetype: application/x-microsoft.net.object.bytearray.base64
|
||||||
|
value : The object must be serialized into a byte array
|
||||||
|
: using a System.ComponentModel.TypeConverter
|
||||||
|
: and then encoded with base64 encoding.
|
||||||
|
-->
|
||||||
|
<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>
|
126
FishFactory/FormComponent.Designer.cs
generated
126
FishFactory/FormComponent.Designer.cs
generated
@ -28,91 +28,95 @@
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
private void InitializeComponent()
|
private void InitializeComponent()
|
||||||
{
|
{
|
||||||
this.buttonSave = new System.Windows.Forms.Button();
|
buttonSave = new Button();
|
||||||
this.buttonCancel = new System.Windows.Forms.Button();
|
buttonCancel = new Button();
|
||||||
this.label1 = new System.Windows.Forms.Label();
|
label1 = new Label();
|
||||||
this.label2 = new System.Windows.Forms.Label();
|
label2 = new Label();
|
||||||
this.textBoxName = new System.Windows.Forms.TextBox();
|
textBoxName = new TextBox();
|
||||||
this.textBoxCost = new System.Windows.Forms.TextBox();
|
textBoxCost = new TextBox();
|
||||||
this.SuspendLayout();
|
SuspendLayout();
|
||||||
//
|
//
|
||||||
// buttonSave
|
// buttonSave
|
||||||
//
|
//
|
||||||
this.buttonSave.Location = new System.Drawing.Point(217, 95);
|
buttonSave.Location = new Point(217, 119);
|
||||||
this.buttonSave.Name = "buttonSave";
|
buttonSave.Margin = new Padding(3, 4, 3, 4);
|
||||||
this.buttonSave.Size = new System.Drawing.Size(98, 27);
|
buttonSave.Name = "buttonSave";
|
||||||
this.buttonSave.TabIndex = 0;
|
buttonSave.Size = new Size(98, 34);
|
||||||
this.buttonSave.Text = "Сохранить";
|
buttonSave.TabIndex = 0;
|
||||||
this.buttonSave.UseVisualStyleBackColor = true;
|
buttonSave.Text = "Сохранить";
|
||||||
this.buttonSave.Click += new System.EventHandler(this.buttonSave_Click);
|
buttonSave.UseVisualStyleBackColor = true;
|
||||||
|
buttonSave.Click += buttonSave_Click;
|
||||||
//
|
//
|
||||||
// buttonCancel
|
// buttonCancel
|
||||||
//
|
//
|
||||||
this.buttonCancel.Location = new System.Drawing.Point(325, 95);
|
buttonCancel.Location = new Point(325, 119);
|
||||||
this.buttonCancel.Name = "buttonCancel";
|
buttonCancel.Margin = new Padding(3, 4, 3, 4);
|
||||||
this.buttonCancel.Size = new System.Drawing.Size(98, 27);
|
buttonCancel.Name = "buttonCancel";
|
||||||
this.buttonCancel.TabIndex = 1;
|
buttonCancel.Size = new Size(98, 34);
|
||||||
this.buttonCancel.Text = "Отмена";
|
buttonCancel.TabIndex = 1;
|
||||||
this.buttonCancel.UseVisualStyleBackColor = true;
|
buttonCancel.Text = "Отмена";
|
||||||
this.buttonCancel.Click += new System.EventHandler(this.buttonCancel_Click);
|
buttonCancel.UseVisualStyleBackColor = true;
|
||||||
|
buttonCancel.Click += buttonCancel_Click;
|
||||||
//
|
//
|
||||||
// label1
|
// label1
|
||||||
//
|
//
|
||||||
this.label1.AutoSize = true;
|
label1.AutoSize = true;
|
||||||
this.label1.Location = new System.Drawing.Point(24, 24);
|
label1.Location = new Point(24, 30);
|
||||||
this.label1.Name = "label1";
|
label1.Name = "label1";
|
||||||
this.label1.Size = new System.Drawing.Size(76, 16);
|
label1.Size = new Size(80, 20);
|
||||||
this.label1.TabIndex = 2;
|
label1.TabIndex = 2;
|
||||||
this.label1.Text = "Название:";
|
label1.Text = "Название:";
|
||||||
//
|
//
|
||||||
// label2
|
// label2
|
||||||
//
|
//
|
||||||
this.label2.AutoSize = true;
|
label2.AutoSize = true;
|
||||||
this.label2.Location = new System.Drawing.Point(24, 55);
|
label2.Location = new Point(24, 69);
|
||||||
this.label2.Name = "label2";
|
label2.Name = "label2";
|
||||||
this.label2.Size = new System.Drawing.Size(43, 16);
|
label2.Size = new Size(48, 20);
|
||||||
this.label2.TabIndex = 3;
|
label2.TabIndex = 3;
|
||||||
this.label2.Text = "Цена:";
|
label2.Text = "Цена:";
|
||||||
//
|
//
|
||||||
// textBoxName
|
// textBoxName
|
||||||
//
|
//
|
||||||
this.textBoxName.Location = new System.Drawing.Point(118, 21);
|
textBoxName.Location = new Point(118, 26);
|
||||||
this.textBoxName.Name = "textBoxName";
|
textBoxName.Margin = new Padding(3, 4, 3, 4);
|
||||||
this.textBoxName.Size = new System.Drawing.Size(305, 22);
|
textBoxName.Name = "textBoxName";
|
||||||
this.textBoxName.TabIndex = 4;
|
textBoxName.Size = new Size(305, 27);
|
||||||
|
textBoxName.TabIndex = 4;
|
||||||
//
|
//
|
||||||
// textBoxCost
|
// textBoxCost
|
||||||
//
|
//
|
||||||
this.textBoxCost.Location = new System.Drawing.Point(118, 52);
|
textBoxCost.Location = new Point(118, 65);
|
||||||
this.textBoxCost.Name = "textBoxCost";
|
textBoxCost.Margin = new Padding(3, 4, 3, 4);
|
||||||
this.textBoxCost.Size = new System.Drawing.Size(186, 22);
|
textBoxCost.Name = "textBoxCost";
|
||||||
this.textBoxCost.TabIndex = 5;
|
textBoxCost.Size = new Size(186, 27);
|
||||||
|
textBoxCost.TabIndex = 5;
|
||||||
//
|
//
|
||||||
// FormComponent
|
// FormComponent
|
||||||
//
|
//
|
||||||
this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 16F);
|
AutoScaleDimensions = new SizeF(8F, 20F);
|
||||||
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
AutoScaleMode = AutoScaleMode.Font;
|
||||||
this.ClientSize = new System.Drawing.Size(462, 139);
|
ClientSize = new Size(462, 174);
|
||||||
this.Controls.Add(this.textBoxCost);
|
Controls.Add(textBoxCost);
|
||||||
this.Controls.Add(this.textBoxName);
|
Controls.Add(textBoxName);
|
||||||
this.Controls.Add(this.label2);
|
Controls.Add(label2);
|
||||||
this.Controls.Add(this.label1);
|
Controls.Add(label1);
|
||||||
this.Controls.Add(this.buttonCancel);
|
Controls.Add(buttonCancel);
|
||||||
this.Controls.Add(this.buttonSave);
|
Controls.Add(buttonSave);
|
||||||
this.Name = "FormComponent";
|
Margin = new Padding(3, 4, 3, 4);
|
||||||
this.Text = "FormComponent";
|
Name = "FormComponent";
|
||||||
this.ResumeLayout(false);
|
Text = "Компонент";
|
||||||
this.PerformLayout();
|
ResumeLayout(false);
|
||||||
|
PerformLayout();
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
private System.Windows.Forms.Button buttonSave;
|
private Button buttonSave;
|
||||||
private System.Windows.Forms.Button buttonCancel;
|
private Button buttonCancel;
|
||||||
private System.Windows.Forms.Label label1;
|
private Label label1;
|
||||||
private System.Windows.Forms.Label label2;
|
private Label label2;
|
||||||
private System.Windows.Forms.TextBox textBoxName;
|
private TextBox textBoxName;
|
||||||
private System.Windows.Forms.TextBox textBoxCost;
|
private TextBox textBoxCost;
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -8,7 +8,10 @@ using System.Text;
|
|||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using System.Windows.Forms;
|
using System.Windows.Forms;
|
||||||
using Microsoft.Extensions.Logging;
|
using Microsoft.Extensions.Logging;
|
||||||
using FishFactoryBusinessLogic.BusinessLogic;
|
using FishFactoryContracts.BusinessLogicsContracts;
|
||||||
|
using Microsoft.VisualBasic.Logging;
|
||||||
|
using FishFactoryContracts.SearchModels;
|
||||||
|
using FishFactoryContracts.BindingModels;
|
||||||
|
|
||||||
namespace FishFactory.Forms
|
namespace FishFactory.Forms
|
||||||
{
|
{
|
||||||
@ -18,19 +21,75 @@ namespace FishFactory.Forms
|
|||||||
private readonly IComponentLogic _logic;
|
private readonly IComponentLogic _logic;
|
||||||
private int? _id;
|
private int? _id;
|
||||||
public int Id { set { _id = value; } }
|
public int Id { set { _id = value; } }
|
||||||
public FormComponent((ILogger<FormComponent> logger, IComponentLogic logic)
|
public FormComponent(ILogger<FormComponent> logger, IComponentLogic logic)
|
||||||
{
|
{
|
||||||
InitializeComponent();
|
InitializeComponent();
|
||||||
|
_logger = logger;
|
||||||
|
_logic = logic;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void FormComponent_Load(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
if (_id.HasValue)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
_logger.LogInformation("Получение компонента");
|
||||||
|
var view = _logic.ReadElement(new ComponentSearchModel
|
||||||
|
{
|
||||||
|
Id = _id.Value
|
||||||
|
});
|
||||||
|
if (view != null)
|
||||||
|
{
|
||||||
|
textBoxName.Text = view.ComponentName;
|
||||||
|
textBoxCost.Text = view.Cost.ToString();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "Ошибка получения компонента");
|
||||||
|
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK,
|
||||||
|
MessageBoxIcon.Error);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void buttonSave_Click(object sender, EventArgs e)
|
private void buttonSave_Click(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
|
if (string.IsNullOrEmpty(textBoxName.Text))
|
||||||
|
{
|
||||||
|
MessageBox.Show("Заполните название", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
_logger.LogInformation("Сохранение компонента");
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var model = new ComponentBindingModel
|
||||||
|
{
|
||||||
|
Id = _id ?? 0,
|
||||||
|
ComponentName = textBoxName.Text,
|
||||||
|
Cost = Convert.ToDouble(textBoxCost.Text)
|
||||||
|
};
|
||||||
|
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)
|
private void buttonCancel_Click(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
|
DialogResult = DialogResult.Cancel;
|
||||||
|
Close();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
133
FishFactory/FormComponents.Designer.cs
generated
133
FishFactory/FormComponents.Designer.cs
generated
@ -28,83 +28,94 @@
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
private void InitializeComponent()
|
private void InitializeComponent()
|
||||||
{
|
{
|
||||||
this.dataGridView1 = new System.Windows.Forms.DataGridView();
|
dataGridView = new DataGridView();
|
||||||
this.button1 = new System.Windows.Forms.Button();
|
buttonAdd = new Button();
|
||||||
this.button2 = new System.Windows.Forms.Button();
|
buttonUpd = new Button();
|
||||||
this.button3 = new System.Windows.Forms.Button();
|
buttonDel = new Button();
|
||||||
this.button4 = new System.Windows.Forms.Button();
|
buttonRef = new Button();
|
||||||
((System.ComponentModel.ISupportInitialize)(this.dataGridView1)).BeginInit();
|
((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit();
|
||||||
this.SuspendLayout();
|
SuspendLayout();
|
||||||
//
|
//
|
||||||
// dataGridView1
|
// dataGridView
|
||||||
//
|
//
|
||||||
this.dataGridView1.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
|
dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize;
|
||||||
this.dataGridView1.Location = new System.Drawing.Point(-1, -2);
|
dataGridView.Location = new Point(-1, -2);
|
||||||
this.dataGridView1.Name = "dataGridView1";
|
dataGridView.Margin = new Padding(3, 4, 3, 4);
|
||||||
this.dataGridView1.RowHeadersWidth = 51;
|
dataGridView.Name = "dataGridView";
|
||||||
this.dataGridView1.RowTemplate.Height = 24;
|
dataGridView.ReadOnly = true;
|
||||||
this.dataGridView1.Size = new System.Drawing.Size(499, 454);
|
dataGridView.RowHeadersWidth = 51;
|
||||||
this.dataGridView1.TabIndex = 0;
|
dataGridView.RowTemplate.Height = 24;
|
||||||
|
dataGridView.Size = new Size(499, 568);
|
||||||
|
dataGridView.TabIndex = 0;
|
||||||
//
|
//
|
||||||
// button1
|
// buttonAdd
|
||||||
//
|
//
|
||||||
this.button1.Location = new System.Drawing.Point(525, 38);
|
buttonAdd.Location = new Point(525, 48);
|
||||||
this.button1.Name = "button1";
|
buttonAdd.Margin = new Padding(3, 4, 3, 4);
|
||||||
this.button1.Size = new System.Drawing.Size(111, 28);
|
buttonAdd.Name = "buttonAdd";
|
||||||
this.button1.TabIndex = 1;
|
buttonAdd.Size = new Size(125, 35);
|
||||||
this.button1.Text = "button1";
|
buttonAdd.TabIndex = 1;
|
||||||
this.button1.UseVisualStyleBackColor = true;
|
buttonAdd.Text = "Добавить";
|
||||||
|
buttonAdd.UseVisualStyleBackColor = true;
|
||||||
|
buttonAdd.Click += buttonAdd_Click;
|
||||||
//
|
//
|
||||||
// button2
|
// buttonUpd
|
||||||
//
|
//
|
||||||
this.button2.Location = new System.Drawing.Point(525, 78);
|
buttonUpd.Location = new Point(525, 98);
|
||||||
this.button2.Name = "button2";
|
buttonUpd.Margin = new Padding(3, 4, 3, 4);
|
||||||
this.button2.Size = new System.Drawing.Size(111, 28);
|
buttonUpd.Name = "buttonUpd";
|
||||||
this.button2.TabIndex = 2;
|
buttonUpd.Size = new Size(125, 35);
|
||||||
this.button2.Text = "button2";
|
buttonUpd.TabIndex = 2;
|
||||||
this.button2.UseVisualStyleBackColor = true;
|
buttonUpd.Text = "Изменить";
|
||||||
|
buttonUpd.UseVisualStyleBackColor = true;
|
||||||
|
buttonUpd.Click += buttonUpd_Click;
|
||||||
//
|
//
|
||||||
// button3
|
// buttonDel
|
||||||
//
|
//
|
||||||
this.button3.Location = new System.Drawing.Point(525, 120);
|
buttonDel.Location = new Point(525, 150);
|
||||||
this.button3.Name = "button3";
|
buttonDel.Margin = new Padding(3, 4, 3, 4);
|
||||||
this.button3.Size = new System.Drawing.Size(111, 28);
|
buttonDel.Name = "buttonDel";
|
||||||
this.button3.TabIndex = 3;
|
buttonDel.Size = new Size(125, 35);
|
||||||
this.button3.Text = "button3";
|
buttonDel.TabIndex = 3;
|
||||||
this.button3.UseVisualStyleBackColor = true;
|
buttonDel.Text = "Удалить";
|
||||||
|
buttonDel.UseVisualStyleBackColor = true;
|
||||||
|
buttonDel.Click += buttonDel_Click;
|
||||||
//
|
//
|
||||||
// button4
|
// buttonRef
|
||||||
//
|
//
|
||||||
this.button4.Location = new System.Drawing.Point(525, 161);
|
buttonRef.Location = new Point(525, 201);
|
||||||
this.button4.Name = "button4";
|
buttonRef.Margin = new Padding(3, 4, 3, 4);
|
||||||
this.button4.Size = new System.Drawing.Size(111, 28);
|
buttonRef.Name = "buttonRef";
|
||||||
this.button4.TabIndex = 4;
|
buttonRef.Size = new Size(125, 35);
|
||||||
this.button4.Text = "button4";
|
buttonRef.TabIndex = 4;
|
||||||
this.button4.UseVisualStyleBackColor = true;
|
buttonRef.Text = "Обновить";
|
||||||
|
buttonRef.UseVisualStyleBackColor = true;
|
||||||
|
buttonRef.Click += buttonRef_Click;
|
||||||
//
|
//
|
||||||
// FormComponents
|
// FormComponents
|
||||||
//
|
//
|
||||||
this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 16F);
|
AutoScaleDimensions = new SizeF(8F, 20F);
|
||||||
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
AutoScaleMode = AutoScaleMode.Font;
|
||||||
this.ClientSize = new System.Drawing.Size(662, 450);
|
ClientSize = new Size(676, 562);
|
||||||
this.Controls.Add(this.button4);
|
Controls.Add(buttonRef);
|
||||||
this.Controls.Add(this.button3);
|
Controls.Add(buttonDel);
|
||||||
this.Controls.Add(this.button2);
|
Controls.Add(buttonUpd);
|
||||||
this.Controls.Add(this.button1);
|
Controls.Add(buttonAdd);
|
||||||
this.Controls.Add(this.dataGridView1);
|
Controls.Add(dataGridView);
|
||||||
this.Name = "FormComponents";
|
Margin = new Padding(3, 4, 3, 4);
|
||||||
this.Text = "FormComponents";
|
Name = "FormComponents";
|
||||||
((System.ComponentModel.ISupportInitialize)(this.dataGridView1)).EndInit();
|
Text = "Список компонентов";
|
||||||
this.ResumeLayout(false);
|
Load += FormComponents_Load;
|
||||||
|
((System.ComponentModel.ISupportInitialize)dataGridView).EndInit();
|
||||||
|
ResumeLayout(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
private System.Windows.Forms.DataGridView dataGridView1;
|
private DataGridView dataGridView;
|
||||||
private System.Windows.Forms.Button button1;
|
private Button buttonAdd;
|
||||||
private System.Windows.Forms.Button button2;
|
private Button buttonUpd;
|
||||||
private System.Windows.Forms.Button button3;
|
private Button buttonDel;
|
||||||
private System.Windows.Forms.Button button4;
|
private Button buttonRef;
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -1,4 +1,7 @@
|
|||||||
using System;
|
using FishFactoryContracts.BindingModels;
|
||||||
|
using FishFactoryContracts.BusinessLogicsContracts;
|
||||||
|
using Microsoft.Extensions.Logging;
|
||||||
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.ComponentModel;
|
using System.ComponentModel;
|
||||||
using System.Data;
|
using System.Data;
|
||||||
@ -12,9 +15,99 @@ namespace FishFactory.Forms
|
|||||||
{
|
{
|
||||||
public partial class FormComponents : Form
|
public partial class FormComponents : Form
|
||||||
{
|
{
|
||||||
public FormComponents()
|
private readonly ILogger _logger;
|
||||||
|
private readonly IComponentLogic _logic;
|
||||||
|
public FormComponents(ILogger<FormComponents> logger, IComponentLogic logic)
|
||||||
{
|
{
|
||||||
InitializeComponent();
|
InitializeComponent();
|
||||||
|
_logger = logger;
|
||||||
|
_logic = logic;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void FormComponents_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["ComponentName"].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(FormComponent));
|
||||||
|
if (service is FormComponent 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(FormComponent));
|
||||||
|
if (service is FormComponent 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 ComponentBindingModel
|
||||||
|
{
|
||||||
|
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();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
163
FishFactory/FormCreateOrder.Designer.cs
generated
163
FishFactory/FormCreateOrder.Designer.cs
generated
@ -28,112 +28,123 @@
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
private void InitializeComponent()
|
private void InitializeComponent()
|
||||||
{
|
{
|
||||||
this.label1 = new System.Windows.Forms.Label();
|
label1 = new Label();
|
||||||
this.label2 = new System.Windows.Forms.Label();
|
label2 = new Label();
|
||||||
this.label3 = new System.Windows.Forms.Label();
|
label3 = new Label();
|
||||||
this.textBoxCount = new System.Windows.Forms.TextBox();
|
textBoxCount = new TextBox();
|
||||||
this.comboBoxCanned = new System.Windows.Forms.ComboBox();
|
comboBoxCanned = new ComboBox();
|
||||||
this.textBoxSum = new System.Windows.Forms.TextBox();
|
textBoxSum = new TextBox();
|
||||||
this.buttonSave = new System.Windows.Forms.Button();
|
buttonSave = new Button();
|
||||||
this.buttonCancel = new System.Windows.Forms.Button();
|
buttonCancel = new Button();
|
||||||
this.SuspendLayout();
|
SuspendLayout();
|
||||||
//
|
//
|
||||||
// label1
|
// label1
|
||||||
//
|
//
|
||||||
this.label1.AutoSize = true;
|
label1.AutoSize = true;
|
||||||
this.label1.Location = new System.Drawing.Point(22, 13);
|
label1.Location = new Point(22, 16);
|
||||||
this.label1.Name = "label1";
|
label1.Name = "label1";
|
||||||
this.label1.Size = new System.Drawing.Size(68, 16);
|
label1.Size = new Size(71, 20);
|
||||||
this.label1.TabIndex = 0;
|
label1.TabIndex = 0;
|
||||||
this.label1.Text = "Изделие:";
|
label1.Text = "Изделие:";
|
||||||
//
|
//
|
||||||
// label2
|
// label2
|
||||||
//
|
//
|
||||||
this.label2.AutoSize = true;
|
label2.AutoSize = true;
|
||||||
this.label2.Location = new System.Drawing.Point(22, 46);
|
label2.Location = new Point(22, 58);
|
||||||
this.label2.Name = "label2";
|
label2.Name = "label2";
|
||||||
this.label2.Size = new System.Drawing.Size(88, 16);
|
label2.Size = new Size(93, 20);
|
||||||
this.label2.TabIndex = 1;
|
label2.TabIndex = 1;
|
||||||
this.label2.Text = "Количество:";
|
label2.Text = "Количество:";
|
||||||
//
|
//
|
||||||
// label3
|
// label3
|
||||||
//
|
//
|
||||||
this.label3.AutoSize = true;
|
label3.AutoSize = true;
|
||||||
this.label3.Location = new System.Drawing.Point(22, 75);
|
label3.Location = new Point(22, 94);
|
||||||
this.label3.Name = "label3";
|
label3.Name = "label3";
|
||||||
this.label3.Size = new System.Drawing.Size(53, 16);
|
label3.Size = new Size(58, 20);
|
||||||
this.label3.TabIndex = 2;
|
label3.TabIndex = 2;
|
||||||
this.label3.Text = "Сумма:";
|
label3.Text = "Сумма:";
|
||||||
//
|
//
|
||||||
// textBoxCount
|
// textBoxCount
|
||||||
//
|
//
|
||||||
this.textBoxCount.Location = new System.Drawing.Point(118, 43);
|
textBoxCount.Location = new Point(118, 55);
|
||||||
this.textBoxCount.Name = "textBoxCount";
|
textBoxCount.Margin = new Padding(3, 4, 3, 4);
|
||||||
this.textBoxCount.Size = new System.Drawing.Size(280, 22);
|
textBoxCount.Name = "textBoxCount";
|
||||||
this.textBoxCount.TabIndex = 3;
|
textBoxCount.Size = new Size(280, 27);
|
||||||
|
textBoxCount.TabIndex = 3;
|
||||||
|
textBoxCount.TextChanged += textBoxCount_TextChanged;
|
||||||
//
|
//
|
||||||
// comboBoxCanned
|
// comboBoxCanned
|
||||||
//
|
//
|
||||||
this.comboBoxCanned.FormattingEnabled = true;
|
comboBoxCanned.FormattingEnabled = true;
|
||||||
this.comboBoxCanned.Location = new System.Drawing.Point(118, 11);
|
comboBoxCanned.Location = new Point(118, 14);
|
||||||
this.comboBoxCanned.Name = "comboBoxCanned";
|
comboBoxCanned.Margin = new Padding(3, 4, 3, 4);
|
||||||
this.comboBoxCanned.Size = new System.Drawing.Size(280, 24);
|
comboBoxCanned.Name = "comboBoxCanned";
|
||||||
this.comboBoxCanned.TabIndex = 4;
|
comboBoxCanned.Size = new Size(280, 28);
|
||||||
|
comboBoxCanned.TabIndex = 4;
|
||||||
|
comboBoxCanned.SelectedIndexChanged += ComboBoxCanned_SelectedIndexChanged;
|
||||||
//
|
//
|
||||||
// textBoxSum
|
// textBoxSum
|
||||||
//
|
//
|
||||||
this.textBoxSum.Location = new System.Drawing.Point(118, 75);
|
textBoxSum.Location = new Point(118, 94);
|
||||||
this.textBoxSum.Name = "textBoxSum";
|
textBoxSum.Margin = new Padding(3, 4, 3, 4);
|
||||||
this.textBoxSum.Size = new System.Drawing.Size(280, 22);
|
textBoxSum.Name = "textBoxSum";
|
||||||
this.textBoxSum.TabIndex = 5;
|
textBoxSum.ReadOnly = true;
|
||||||
|
textBoxSum.Size = new Size(280, 27);
|
||||||
|
textBoxSum.TabIndex = 5;
|
||||||
//
|
//
|
||||||
// buttonSave
|
// buttonSave
|
||||||
//
|
//
|
||||||
this.buttonSave.Location = new System.Drawing.Point(215, 108);
|
buttonSave.Location = new Point(172, 135);
|
||||||
this.buttonSave.Name = "buttonSave";
|
buttonSave.Margin = new Padding(3, 4, 3, 4);
|
||||||
this.buttonSave.Size = new System.Drawing.Size(88, 28);
|
buttonSave.Name = "buttonSave";
|
||||||
this.buttonSave.TabIndex = 6;
|
buttonSave.Size = new Size(107, 35);
|
||||||
this.buttonSave.Text = "Сохранить";
|
buttonSave.TabIndex = 6;
|
||||||
this.buttonSave.UseVisualStyleBackColor = true;
|
buttonSave.Text = "Сохранить";
|
||||||
|
buttonSave.UseVisualStyleBackColor = true;
|
||||||
|
buttonSave.Click += buttonSave_Click;
|
||||||
//
|
//
|
||||||
// buttonCancel
|
// buttonCancel
|
||||||
//
|
//
|
||||||
this.buttonCancel.Location = new System.Drawing.Point(310, 108);
|
buttonCancel.Location = new Point(285, 135);
|
||||||
this.buttonCancel.Name = "buttonCancel";
|
buttonCancel.Margin = new Padding(3, 4, 3, 4);
|
||||||
this.buttonCancel.Size = new System.Drawing.Size(88, 28);
|
buttonCancel.Name = "buttonCancel";
|
||||||
this.buttonCancel.TabIndex = 7;
|
buttonCancel.Size = new Size(107, 35);
|
||||||
this.buttonCancel.Text = "Отмена";
|
buttonCancel.TabIndex = 7;
|
||||||
this.buttonCancel.UseVisualStyleBackColor = true;
|
buttonCancel.Text = "Отмена";
|
||||||
|
buttonCancel.UseVisualStyleBackColor = true;
|
||||||
|
buttonCancel.Click += buttonCancel_Click;
|
||||||
//
|
//
|
||||||
// FormCreateOrder
|
// FormCreateOrder
|
||||||
//
|
//
|
||||||
this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 16F);
|
AutoScaleDimensions = new SizeF(8F, 20F);
|
||||||
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
AutoScaleMode = AutoScaleMode.Font;
|
||||||
this.ClientSize = new System.Drawing.Size(428, 146);
|
ClientSize = new Size(428, 182);
|
||||||
this.Controls.Add(this.buttonCancel);
|
Controls.Add(buttonCancel);
|
||||||
this.Controls.Add(this.buttonSave);
|
Controls.Add(buttonSave);
|
||||||
this.Controls.Add(this.textBoxSum);
|
Controls.Add(textBoxSum);
|
||||||
this.Controls.Add(this.comboBoxCanned);
|
Controls.Add(comboBoxCanned);
|
||||||
this.Controls.Add(this.textBoxCount);
|
Controls.Add(textBoxCount);
|
||||||
this.Controls.Add(this.label3);
|
Controls.Add(label3);
|
||||||
this.Controls.Add(this.label2);
|
Controls.Add(label2);
|
||||||
this.Controls.Add(this.label1);
|
Controls.Add(label1);
|
||||||
this.Name = "FormCreateOrder";
|
Margin = new Padding(3, 4, 3, 4);
|
||||||
this.Text = "Заказ";
|
Name = "FormCreateOrder";
|
||||||
this.ResumeLayout(false);
|
Text = "Заказ";
|
||||||
this.PerformLayout();
|
Load += new System.EventHandler(this.FormCreateOrder_Load);
|
||||||
|
ResumeLayout(false);
|
||||||
|
PerformLayout();
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
private System.Windows.Forms.Label label1;
|
private Label label1;
|
||||||
private System.Windows.Forms.Label label2;
|
private Label label2;
|
||||||
private System.Windows.Forms.Label label3;
|
private Label label3;
|
||||||
private System.Windows.Forms.TextBox textBoxCount;
|
private TextBox textBoxCount;
|
||||||
private System.Windows.Forms.ComboBox comboBoxCanned;
|
private ComboBox comboBoxCanned;
|
||||||
private System.Windows.Forms.TextBox textBoxSum;
|
private TextBox textBoxSum;
|
||||||
private System.Windows.Forms.Button buttonSave;
|
private Button buttonSave;
|
||||||
private System.Windows.Forms.Button buttonCancel;
|
private Button buttonCancel;
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -1,4 +1,8 @@
|
|||||||
using System;
|
using FishFactoryContracts.BindingModels;
|
||||||
|
using FishFactoryContracts.BusinessLogicsContracts;
|
||||||
|
using FishFactoryContracts.SearchModels;
|
||||||
|
using Microsoft.Extensions.Logging;
|
||||||
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.ComponentModel;
|
using System.ComponentModel;
|
||||||
using System.Data;
|
using System.Data;
|
||||||
@ -12,9 +16,108 @@ namespace FishFactory.Forms
|
|||||||
{
|
{
|
||||||
public partial class FormCreateOrder : Form
|
public partial class FormCreateOrder : Form
|
||||||
{
|
{
|
||||||
public FormCreateOrder()
|
private readonly ILogger _logger;
|
||||||
|
private readonly ICannedLogic _logicP;
|
||||||
|
private readonly IOrderLogic _logicO;
|
||||||
|
public FormCreateOrder(ILogger<FormCreateOrder> logger, ICannedLogic logicP, IOrderLogic logicO)
|
||||||
{
|
{
|
||||||
InitializeComponent();
|
InitializeComponent();
|
||||||
|
_logger = logger;
|
||||||
|
_logicP = logicP;
|
||||||
|
_logicO = logicO;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void FormCreateOrder_Load(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var list = _logicP.ReadList(null);
|
||||||
|
if (list != null)
|
||||||
|
{
|
||||||
|
comboBoxCanned.DisplayMember = "CannedName";
|
||||||
|
comboBoxCanned.ValueMember = "Id";
|
||||||
|
comboBoxCanned.DataSource = list;
|
||||||
|
comboBoxCanned.SelectedItem = null;
|
||||||
|
_logger.LogInformation("Загрузка изделий для заказа");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "Ошибка загрузки списка изделий");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
private void CalcSum()
|
||||||
|
{
|
||||||
|
if (comboBoxCanned.SelectedValue != null && !string.IsNullOrEmpty(textBoxCount.Text))
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
int id = Convert.ToInt32(comboBoxCanned.SelectedValue);
|
||||||
|
var canned = _logicP.ReadElement(new CannedSearchModel
|
||||||
|
{
|
||||||
|
Id = id
|
||||||
|
});
|
||||||
|
int count = Convert.ToInt32(textBoxCount.Text);
|
||||||
|
textBoxSum.Text = Math.Round(count * (canned?.Price ?? 0), 2).ToString();
|
||||||
|
_logger.LogInformation("Расчет суммы заказа");
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "Ошибка расчета суммы заказа");
|
||||||
|
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
private void textBoxCount_TextChanged(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
CalcSum();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void ComboBoxCanned_SelectedIndexChanged(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
CalcSum();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void buttonSave_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
if (string.IsNullOrEmpty(textBoxCount.Text))
|
||||||
|
{
|
||||||
|
MessageBox.Show("Заполните поле Количество", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (comboBoxCanned.SelectedValue == null)
|
||||||
|
{
|
||||||
|
MessageBox.Show("Выберите изделие", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
_logger.LogInformation("Создание заказа");
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var operationResult = _logicO.CreateOrder(new OrderBindingModel
|
||||||
|
{
|
||||||
|
CannedId = Convert.ToInt32(comboBoxCanned.SelectedValue),
|
||||||
|
Count = Convert.ToInt32(textBoxCount.Text),
|
||||||
|
Sum = Convert.ToDouble(textBoxSum.Text)
|
||||||
|
});
|
||||||
|
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();
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
251
FishFactory/FormMain.Designer.cs
generated
251
FishFactory/FormMain.Designer.cs
generated
@ -29,143 +29,156 @@
|
|||||||
private void InitializeComponent()
|
private void InitializeComponent()
|
||||||
{
|
{
|
||||||
System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(FormMain));
|
System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(FormMain));
|
||||||
this.toolStrip1 = new System.Windows.Forms.ToolStrip();
|
toolStrip1 = new ToolStrip();
|
||||||
this.buttonCreateOrder = new System.Windows.Forms.Button();
|
toolStripDropDownButton1 = new ToolStripDropDownButton();
|
||||||
this.buttonTakeOrderInWork = new System.Windows.Forms.Button();
|
компонентыToolStripMenuItem = new ToolStripMenuItem();
|
||||||
this.buttonOrderReady = new System.Windows.Forms.Button();
|
консервыToolStripMenuItem = new ToolStripMenuItem();
|
||||||
this.buttonIssuedOrder = new System.Windows.Forms.Button();
|
buttonCreateOrder = new Button();
|
||||||
this.buttonRef = new System.Windows.Forms.Button();
|
buttonTakeOrderInWork = new Button();
|
||||||
this.dataGridView1 = new System.Windows.Forms.DataGridView();
|
buttonOrderReady = new Button();
|
||||||
this.toolStripDropDownButton1 = new System.Windows.Forms.ToolStripDropDownButton();
|
buttonIssuedOrder = new Button();
|
||||||
this.компонентыToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
|
buttonRef = new Button();
|
||||||
this.консервыToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
|
dataGridView = new DataGridView();
|
||||||
this.toolStrip1.SuspendLayout();
|
toolStrip1.SuspendLayout();
|
||||||
((System.ComponentModel.ISupportInitialize)(this.dataGridView1)).BeginInit();
|
((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit();
|
||||||
this.SuspendLayout();
|
SuspendLayout();
|
||||||
//
|
//
|
||||||
// toolStrip1
|
// toolStrip1
|
||||||
//
|
//
|
||||||
this.toolStrip1.ImageScalingSize = new System.Drawing.Size(20, 20);
|
toolStrip1.ImageScalingSize = new Size(20, 20);
|
||||||
this.toolStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
|
toolStrip1.Items.AddRange(new ToolStripItem[] { toolStripDropDownButton1 });
|
||||||
this.toolStripDropDownButton1});
|
toolStrip1.Location = new Point(0, 0);
|
||||||
this.toolStrip1.Location = new System.Drawing.Point(0, 0);
|
toolStrip1.Name = "toolStrip1";
|
||||||
this.toolStrip1.Name = "toolStrip1";
|
toolStrip1.Size = new Size(1107, 27);
|
||||||
this.toolStrip1.Size = new System.Drawing.Size(865, 27);
|
toolStrip1.TabIndex = 0;
|
||||||
this.toolStrip1.TabIndex = 0;
|
toolStrip1.Text = "toolStrip1";
|
||||||
this.toolStrip1.Text = "toolStrip1";
|
|
||||||
//
|
|
||||||
// buttonCreateOrder
|
|
||||||
//
|
|
||||||
this.buttonCreateOrder.Location = new System.Drawing.Point(655, 43);
|
|
||||||
this.buttonCreateOrder.Name = "buttonCreateOrder";
|
|
||||||
this.buttonCreateOrder.Size = new System.Drawing.Size(175, 26);
|
|
||||||
this.buttonCreateOrder.TabIndex = 1;
|
|
||||||
this.buttonCreateOrder.Text = "Создать заказ";
|
|
||||||
this.buttonCreateOrder.UseVisualStyleBackColor = true;
|
|
||||||
//
|
|
||||||
// buttonTakeOrderInWork
|
|
||||||
//
|
|
||||||
this.buttonTakeOrderInWork.Location = new System.Drawing.Point(655, 90);
|
|
||||||
this.buttonTakeOrderInWork.Name = "buttonTakeOrderInWork";
|
|
||||||
this.buttonTakeOrderInWork.Size = new System.Drawing.Size(175, 26);
|
|
||||||
this.buttonTakeOrderInWork.TabIndex = 2;
|
|
||||||
this.buttonTakeOrderInWork.Text = "Отдать на выполнение";
|
|
||||||
this.buttonTakeOrderInWork.UseVisualStyleBackColor = true;
|
|
||||||
//
|
|
||||||
// buttonOrderReady
|
|
||||||
//
|
|
||||||
this.buttonOrderReady.Location = new System.Drawing.Point(655, 135);
|
|
||||||
this.buttonOrderReady.Name = "buttonOrderReady";
|
|
||||||
this.buttonOrderReady.Size = new System.Drawing.Size(175, 26);
|
|
||||||
this.buttonOrderReady.TabIndex = 3;
|
|
||||||
this.buttonOrderReady.Text = "Заказ готов";
|
|
||||||
this.buttonOrderReady.UseVisualStyleBackColor = true;
|
|
||||||
//
|
|
||||||
// buttonIssuedOrder
|
|
||||||
//
|
|
||||||
this.buttonIssuedOrder.Location = new System.Drawing.Point(655, 176);
|
|
||||||
this.buttonIssuedOrder.Name = "buttonIssuedOrder";
|
|
||||||
this.buttonIssuedOrder.Size = new System.Drawing.Size(175, 26);
|
|
||||||
this.buttonIssuedOrder.TabIndex = 4;
|
|
||||||
this.buttonIssuedOrder.Text = "Заказ выдан";
|
|
||||||
this.buttonIssuedOrder.UseVisualStyleBackColor = true;
|
|
||||||
//
|
|
||||||
// buttonRef
|
|
||||||
//
|
|
||||||
this.buttonRef.Location = new System.Drawing.Point(655, 220);
|
|
||||||
this.buttonRef.Name = "buttonRef";
|
|
||||||
this.buttonRef.Size = new System.Drawing.Size(175, 26);
|
|
||||||
this.buttonRef.TabIndex = 5;
|
|
||||||
this.buttonRef.Text = "Обновить список";
|
|
||||||
this.buttonRef.UseVisualStyleBackColor = true;
|
|
||||||
//
|
|
||||||
// dataGridView1
|
|
||||||
//
|
|
||||||
this.dataGridView1.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
|
|
||||||
this.dataGridView1.Location = new System.Drawing.Point(0, 28);
|
|
||||||
this.dataGridView1.Name = "dataGridView1";
|
|
||||||
this.dataGridView1.RowHeadersWidth = 51;
|
|
||||||
this.dataGridView1.RowTemplate.Height = 24;
|
|
||||||
this.dataGridView1.Size = new System.Drawing.Size(630, 464);
|
|
||||||
this.dataGridView1.TabIndex = 6;
|
|
||||||
//
|
//
|
||||||
// toolStripDropDownButton1
|
// toolStripDropDownButton1
|
||||||
//
|
//
|
||||||
this.toolStripDropDownButton1.DisplayStyle = System.Windows.Forms.ToolStripItemDisplayStyle.Text;
|
toolStripDropDownButton1.DisplayStyle = ToolStripItemDisplayStyle.Text;
|
||||||
this.toolStripDropDownButton1.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] {
|
toolStripDropDownButton1.DropDownItems.AddRange(new ToolStripItem[] { компонентыToolStripMenuItem, консервыToolStripMenuItem });
|
||||||
this.компонентыToolStripMenuItem,
|
toolStripDropDownButton1.Image = (Image)resources.GetObject("toolStripDropDownButton1.Image");
|
||||||
this.консервыToolStripMenuItem});
|
toolStripDropDownButton1.ImageTransparentColor = Color.Magenta;
|
||||||
this.toolStripDropDownButton1.Image = ((System.Drawing.Image)(resources.GetObject("toolStripDropDownButton1.Image")));
|
toolStripDropDownButton1.Name = "toolStripDropDownButton1";
|
||||||
this.toolStripDropDownButton1.ImageTransparentColor = System.Drawing.Color.Magenta;
|
toolStripDropDownButton1.Size = new Size(108, 24);
|
||||||
this.toolStripDropDownButton1.Name = "toolStripDropDownButton1";
|
toolStripDropDownButton1.Text = "Справочник";
|
||||||
this.toolStripDropDownButton1.Size = new System.Drawing.Size(108, 24);
|
|
||||||
this.toolStripDropDownButton1.Text = "Справочник";
|
|
||||||
//
|
//
|
||||||
// компонентыToolStripMenuItem
|
// компонентыToolStripMenuItem
|
||||||
//
|
//
|
||||||
this.компонентыToolStripMenuItem.Name = "компонентыToolStripMenuItem";
|
компонентыToolStripMenuItem.Name = "компонентыToolStripMenuItem";
|
||||||
this.компонентыToolStripMenuItem.Size = new System.Drawing.Size(224, 26);
|
компонентыToolStripMenuItem.Size = new Size(182, 26);
|
||||||
this.компонентыToolStripMenuItem.Text = "Компоненты";
|
компонентыToolStripMenuItem.Text = "Компоненты";
|
||||||
|
компонентыToolStripMenuItem.Click += компонентыToolStripMenuItem_Click;
|
||||||
//
|
//
|
||||||
// консервыToolStripMenuItem
|
// консервыToolStripMenuItem
|
||||||
//
|
//
|
||||||
this.консервыToolStripMenuItem.Name = "консервыToolStripMenuItem";
|
консервыToolStripMenuItem.Name = "консервыToolStripMenuItem";
|
||||||
this.консервыToolStripMenuItem.Size = new System.Drawing.Size(224, 26);
|
консервыToolStripMenuItem.Size = new Size(182, 26);
|
||||||
this.консервыToolStripMenuItem.Text = "Консервы";
|
консервыToolStripMenuItem.Text = "Консервы";
|
||||||
|
консервыToolStripMenuItem.Click += консервыToolStripMenuItem_Click;
|
||||||
|
//
|
||||||
|
// buttonCreateOrder
|
||||||
|
//
|
||||||
|
buttonCreateOrder.Location = new Point(914, 75);
|
||||||
|
buttonCreateOrder.Margin = new Padding(3, 4, 3, 4);
|
||||||
|
buttonCreateOrder.Name = "buttonCreateOrder";
|
||||||
|
buttonCreateOrder.Size = new Size(161, 32);
|
||||||
|
buttonCreateOrder.TabIndex = 1;
|
||||||
|
buttonCreateOrder.Text = "Создать заказ";
|
||||||
|
buttonCreateOrder.UseVisualStyleBackColor = true;
|
||||||
|
buttonCreateOrder.Click += buttonCreateOrder_Click;
|
||||||
|
//
|
||||||
|
// buttonTakeOrderInWork
|
||||||
|
//
|
||||||
|
buttonTakeOrderInWork.Location = new Point(914, 133);
|
||||||
|
buttonTakeOrderInWork.Margin = new Padding(3, 4, 3, 4);
|
||||||
|
buttonTakeOrderInWork.Name = "buttonTakeOrderInWork";
|
||||||
|
buttonTakeOrderInWork.Size = new Size(161, 32);
|
||||||
|
buttonTakeOrderInWork.TabIndex = 2;
|
||||||
|
buttonTakeOrderInWork.Text = "Отдать на выполнение";
|
||||||
|
buttonTakeOrderInWork.UseVisualStyleBackColor = true;
|
||||||
|
buttonTakeOrderInWork.Click += buttonTakeOrderInWork_Click;
|
||||||
|
//
|
||||||
|
// buttonOrderReady
|
||||||
|
//
|
||||||
|
buttonOrderReady.Location = new Point(914, 190);
|
||||||
|
buttonOrderReady.Margin = new Padding(3, 4, 3, 4);
|
||||||
|
buttonOrderReady.Name = "buttonOrderReady";
|
||||||
|
buttonOrderReady.Size = new Size(161, 32);
|
||||||
|
buttonOrderReady.TabIndex = 3;
|
||||||
|
buttonOrderReady.Text = "Заказ готов";
|
||||||
|
buttonOrderReady.UseVisualStyleBackColor = true;
|
||||||
|
buttonOrderReady.Click += buttonOrderReady_Click;
|
||||||
|
//
|
||||||
|
// buttonIssuedOrder
|
||||||
|
//
|
||||||
|
buttonIssuedOrder.Location = new Point(914, 241);
|
||||||
|
buttonIssuedOrder.Margin = new Padding(3, 4, 3, 4);
|
||||||
|
buttonIssuedOrder.Name = "buttonIssuedOrder";
|
||||||
|
buttonIssuedOrder.Size = new Size(161, 32);
|
||||||
|
buttonIssuedOrder.TabIndex = 4;
|
||||||
|
buttonIssuedOrder.Text = "Заказ выдан";
|
||||||
|
buttonIssuedOrder.UseVisualStyleBackColor = true;
|
||||||
|
buttonIssuedOrder.Click += buttonIssuedOrder_Click;
|
||||||
|
//
|
||||||
|
// buttonRef
|
||||||
|
//
|
||||||
|
buttonRef.Location = new Point(914, 296);
|
||||||
|
buttonRef.Margin = new Padding(3, 4, 3, 4);
|
||||||
|
buttonRef.Name = "buttonRef";
|
||||||
|
buttonRef.Size = new Size(161, 32);
|
||||||
|
buttonRef.TabIndex = 5;
|
||||||
|
buttonRef.Text = "Обновить список";
|
||||||
|
buttonRef.UseVisualStyleBackColor = true;
|
||||||
|
buttonRef.Click += buttonRef_Click;
|
||||||
|
//
|
||||||
|
// dataGridView
|
||||||
|
//
|
||||||
|
dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize;
|
||||||
|
dataGridView.Location = new Point(0, 35);
|
||||||
|
dataGridView.Margin = new Padding(3, 4, 3, 4);
|
||||||
|
dataGridView.Name = "dataGridView";
|
||||||
|
dataGridView.ReadOnly = true;
|
||||||
|
dataGridView.RowHeadersWidth = 51;
|
||||||
|
dataGridView.RowTemplate.Height = 24;
|
||||||
|
dataGridView.SelectionMode = DataGridViewSelectionMode.FullRowSelect;
|
||||||
|
dataGridView.Size = new Size(872, 580);
|
||||||
|
dataGridView.TabIndex = 6;
|
||||||
//
|
//
|
||||||
// FormMain
|
// FormMain
|
||||||
//
|
//
|
||||||
this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 16F);
|
AutoScaleDimensions = new SizeF(8F, 20F);
|
||||||
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
AutoScaleMode = AutoScaleMode.Font;
|
||||||
this.ClientSize = new System.Drawing.Size(865, 494);
|
ClientSize = new Size(1107, 615);
|
||||||
this.Controls.Add(this.dataGridView1);
|
Controls.Add(dataGridView);
|
||||||
this.Controls.Add(this.buttonRef);
|
Controls.Add(buttonRef);
|
||||||
this.Controls.Add(this.buttonIssuedOrder);
|
Controls.Add(buttonIssuedOrder);
|
||||||
this.Controls.Add(this.buttonOrderReady);
|
Controls.Add(buttonOrderReady);
|
||||||
this.Controls.Add(this.buttonTakeOrderInWork);
|
Controls.Add(buttonTakeOrderInWork);
|
||||||
this.Controls.Add(this.buttonCreateOrder);
|
Controls.Add(buttonCreateOrder);
|
||||||
this.Controls.Add(this.toolStrip1);
|
Controls.Add(toolStrip1);
|
||||||
this.Name = "FormMain";
|
Margin = new Padding(3, 4, 3, 4);
|
||||||
this.Text = "Рыбный завод";
|
Name = "FormMain";
|
||||||
this.toolStrip1.ResumeLayout(false);
|
Text = "Рыбный завод";
|
||||||
this.toolStrip1.PerformLayout();
|
Load += FormMain_Load;
|
||||||
((System.ComponentModel.ISupportInitialize)(this.dataGridView1)).EndInit();
|
toolStrip1.ResumeLayout(false);
|
||||||
this.ResumeLayout(false);
|
toolStrip1.PerformLayout();
|
||||||
this.PerformLayout();
|
((System.ComponentModel.ISupportInitialize)dataGridView).EndInit();
|
||||||
|
ResumeLayout(false);
|
||||||
|
PerformLayout();
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
private System.Windows.Forms.ToolStrip toolStrip1;
|
private ToolStrip toolStrip1;
|
||||||
private System.Windows.Forms.Button buttonCreateOrder;
|
private Button buttonCreateOrder;
|
||||||
private System.Windows.Forms.Button buttonTakeOrderInWork;
|
private Button buttonTakeOrderInWork;
|
||||||
private System.Windows.Forms.Button buttonOrderReady;
|
private Button buttonOrderReady;
|
||||||
private System.Windows.Forms.Button buttonIssuedOrder;
|
private Button buttonIssuedOrder;
|
||||||
private System.Windows.Forms.Button buttonRef;
|
private Button buttonRef;
|
||||||
private System.Windows.Forms.DataGridView dataGridView1;
|
private DataGridView dataGridView;
|
||||||
private System.Windows.Forms.ToolStripDropDownButton toolStripDropDownButton1;
|
private ToolStripDropDownButton toolStripDropDownButton1;
|
||||||
private System.Windows.Forms.ToolStripMenuItem компонентыToolStripMenuItem;
|
private ToolStripMenuItem компонентыToolStripMenuItem;
|
||||||
private System.Windows.Forms.ToolStripMenuItem консервыToolStripMenuItem;
|
private ToolStripMenuItem консервыToolStripMenuItem;
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -1,4 +1,7 @@
|
|||||||
using System;
|
using FishFactoryContracts.BindingModels;
|
||||||
|
using FishFactoryContracts.BusinessLogicsContracts;
|
||||||
|
using Microsoft.Extensions.Logging;
|
||||||
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.ComponentModel;
|
using System.ComponentModel;
|
||||||
using System.Data;
|
using System.Data;
|
||||||
@ -12,10 +15,140 @@ namespace FishFactory.Forms
|
|||||||
{
|
{
|
||||||
public partial class FormMain : Form
|
public partial class FormMain : Form
|
||||||
{
|
{
|
||||||
public FormMain()
|
private readonly ILogger _logger;
|
||||||
|
private readonly IOrderLogic _orderLogic;
|
||||||
|
public FormMain(ILogger<FormMain> logger, IOrderLogic orderLogic)
|
||||||
{
|
{
|
||||||
InitializeComponent();
|
InitializeComponent();
|
||||||
|
_logger = logger;
|
||||||
|
_orderLogic = orderLogic;
|
||||||
|
}
|
||||||
|
private void FormMain_Load(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
LoadData();
|
||||||
|
}
|
||||||
|
private void LoadData()
|
||||||
|
{
|
||||||
|
_logger.LogInformation("Загрузка заказов");
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var list = _orderLogic.ReadList(null);
|
||||||
|
|
||||||
|
if (list != null)
|
||||||
|
{
|
||||||
|
dataGridView.DataSource = list;
|
||||||
|
dataGridView.Columns["CannedId"].Visible = false;
|
||||||
|
dataGridView.Columns["CannedName"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
|
||||||
|
}
|
||||||
|
|
||||||
|
_logger.LogInformation("Загрузка заказов");
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "Ошибка загрузки заказов");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
private void компонентыToolStripMenuItem_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
var service = Program.ServiceProvider?.GetService(typeof(FormComponents));
|
||||||
|
if (service is FormComponents form)
|
||||||
|
{
|
||||||
|
form.ShowDialog();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
private void консервыToolStripMenuItem_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
var service = Program.ServiceProvider?.GetService(typeof(FormCanneds));
|
||||||
|
|
||||||
|
if (service is FormCanneds form)
|
||||||
|
{
|
||||||
|
form.ShowDialog();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void buttonCreateOrder_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
var service = Program.ServiceProvider?.GetService(typeof(FormCreateOrder));
|
||||||
|
if (service is FormCreateOrder form)
|
||||||
|
{
|
||||||
|
form.ShowDialog();
|
||||||
|
LoadData();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
private void buttonTakeOrderInWork_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
if (dataGridView.SelectedRows.Count == 1)
|
||||||
|
{
|
||||||
|
int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value);
|
||||||
|
_logger.LogInformation("Заказ №{id}. Меняется статус на 'В работе'", id);
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var operationResult = _orderLogic.TakeOrderInWork(new OrderBindingModel
|
||||||
|
{ Id = id });
|
||||||
|
if (!operationResult)
|
||||||
|
{
|
||||||
|
throw new Exception("Ошибка при сохранении. Дополнительная информация в логах.");
|
||||||
|
}
|
||||||
|
LoadData();
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "Ошибка передачи заказа в работу");
|
||||||
|
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
private void buttonOrderReady_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
if (dataGridView.SelectedRows.Count == 1)
|
||||||
|
{
|
||||||
|
int id =
|
||||||
|
Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value);
|
||||||
|
_logger.LogInformation("Заказ №{id}. Меняется статус на 'Готов'", id);
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var operationResult = _orderLogic.FinishOrder(new OrderBindingModel { Id = id });
|
||||||
|
if (!operationResult)
|
||||||
|
{
|
||||||
|
throw new Exception("Ошибка при сохранении. Дополнительная информация в логах.");
|
||||||
|
}
|
||||||
|
LoadData();
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "Ошибка отметки о готовности заказа");
|
||||||
|
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
private void buttonIssuedOrder_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
if (dataGridView.SelectedRows.Count == 1)
|
||||||
|
{
|
||||||
|
int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value);
|
||||||
|
_logger.LogInformation("Заказ №{id}. Меняется статус на 'Выдан'", id);
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var operationResult = _orderLogic.DeliveryOrder(new OrderBindingModel
|
||||||
|
{
|
||||||
|
Id = id
|
||||||
|
});
|
||||||
|
if (!operationResult)
|
||||||
|
{
|
||||||
|
throw new Exception("Ошибка при сохранении. Дополнительная информация в логах.");
|
||||||
|
}
|
||||||
|
_logger.LogInformation("Заказ №{id} выдан", id);
|
||||||
|
LoadData();
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "Ошибка отметки о выдачи заказа"); MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
private void buttonRef_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
LoadData();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -136,4 +136,7 @@
|
|||||||
TgDQASA1MVpwzwAAAABJRU5ErkJggg==
|
TgDQASA1MVpwzwAAAABJRU5ErkJggg==
|
||||||
</value>
|
</value>
|
||||||
</data>
|
</data>
|
||||||
|
<metadata name="$this.TrayHeight" type="System.Int32, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
|
||||||
|
<value>56</value>
|
||||||
|
</metadata>
|
||||||
</root>
|
</root>
|
@ -1,7 +1,18 @@
|
|||||||
|
using FishFactory.Forms;
|
||||||
|
using FishFactoryContracts.BusinessLogicsContracts;
|
||||||
|
using FishFactoryBusinessLogic.BusinessLogic;
|
||||||
|
using FishFactoryContracts.StoragesContracts;
|
||||||
|
using FishFactoryListImplement.Implements;
|
||||||
|
using Microsoft.Extensions.DependencyInjection;
|
||||||
|
using Microsoft.Extensions.Logging;
|
||||||
|
using NLog.Extensions.Logging;
|
||||||
|
|
||||||
namespace FishFactory
|
namespace FishFactory
|
||||||
{
|
{
|
||||||
internal static class Program
|
internal static class Program
|
||||||
{
|
{
|
||||||
|
private static ServiceProvider? _serviceProvider;
|
||||||
|
public static ServiceProvider? ServiceProvider => _serviceProvider;
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The main entry point for the application.
|
/// The main entry point for the application.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@ -11,7 +22,32 @@ namespace FishFactory
|
|||||||
// To customize application configuration such as set high DPI settings or default font,
|
// To customize application configuration such as set high DPI settings or default font,
|
||||||
// see https://aka.ms/applicationconfiguration.
|
// see https://aka.ms/applicationconfiguration.
|
||||||
ApplicationConfiguration.Initialize();
|
ApplicationConfiguration.Initialize();
|
||||||
Application.Run(new FormComponents());
|
var services = new ServiceCollection();
|
||||||
|
ConfigureServices(services);
|
||||||
|
_serviceProvider = services.BuildServiceProvider();
|
||||||
|
|
||||||
|
Application.Run(_serviceProvider.GetRequiredService<FormMain>());
|
||||||
|
}
|
||||||
|
private static void ConfigureServices(ServiceCollection services)
|
||||||
|
{
|
||||||
|
services.AddLogging(option =>
|
||||||
|
{
|
||||||
|
option.SetMinimumLevel(LogLevel.Information);
|
||||||
|
option.AddNLog("nlog.config");
|
||||||
|
});
|
||||||
|
services.AddTransient<IComponentStorage, ComponentStorage>();
|
||||||
|
services.AddTransient<IOrderStorage, OrderStorage>();
|
||||||
|
services.AddTransient<ICannedStorage, CannedStorage>();
|
||||||
|
services.AddTransient<IComponentLogic, ComponentLogic>();
|
||||||
|
services.AddTransient<IOrderLogic, OrderLogic>();
|
||||||
|
services.AddTransient<ICannedLogic, CannedLogic>();
|
||||||
|
services.AddTransient<FormMain>();
|
||||||
|
services.AddTransient<FormComponent>();
|
||||||
|
services.AddTransient<FormComponents>();
|
||||||
|
services.AddTransient<FormCreateOrder>();
|
||||||
|
services.AddTransient<FormCanned>();
|
||||||
|
services.AddTransient<FormCannedComponent>();
|
||||||
|
services.AddTransient<FormCanneds>();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
15
FishFactory/nlog.config
Normal file
15
FishFactory/nlog.config
Normal 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="${basedir}/Logs/log-${shortdate}.log" />
|
||||||
|
</targets>
|
||||||
|
|
||||||
|
<rules>
|
||||||
|
<logger name="*" minlevel="Debug" writeTo="tofile" />
|
||||||
|
</rules>
|
||||||
|
</nlog>
|
||||||
|
</configuration>
|
@ -1,4 +1,5 @@
|
|||||||
using FishFactoryContracts.BindingModels;
|
using FishFactoryContracts.BindingModels;
|
||||||
|
using FishFactoryContracts.BusinessLogicsContracts;
|
||||||
using FishFactoryContracts.SearchModels;
|
using FishFactoryContracts.SearchModels;
|
||||||
using FishFactoryContracts.StoragesContracts;
|
using FishFactoryContracts.StoragesContracts;
|
||||||
using FishFactoryContracts.ViewModels;
|
using FishFactoryContracts.ViewModels;
|
||||||
@ -11,7 +12,7 @@ using System.Threading.Tasks;
|
|||||||
|
|
||||||
namespace FishFactoryBusinessLogic.BusinessLogic
|
namespace FishFactoryBusinessLogic.BusinessLogic
|
||||||
{
|
{
|
||||||
internal class CannedLogic
|
public class CannedLogic : ICannedLogic
|
||||||
{
|
{
|
||||||
private readonly ILogger _logger;
|
private readonly ILogger _logger;
|
||||||
private readonly ICannedStorage _cannedStorage;
|
private readonly ICannedStorage _cannedStorage;
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
using FishFactoryContracts.BindingModels;
|
using FishFactoryContracts.BindingModels;
|
||||||
|
using FishFactoryContracts.BusinessLogicsContracts;
|
||||||
using FishFactoryContracts.SearchModels;
|
using FishFactoryContracts.SearchModels;
|
||||||
using FishFactoryContracts.StoragesContracts;
|
using FishFactoryContracts.StoragesContracts;
|
||||||
using FishFactoryContracts.ViewModels;
|
using FishFactoryContracts.ViewModels;
|
||||||
@ -12,7 +13,7 @@ using System.Threading.Tasks;
|
|||||||
|
|
||||||
namespace FishFactoryBusinessLogic.BusinessLogic
|
namespace FishFactoryBusinessLogic.BusinessLogic
|
||||||
{
|
{
|
||||||
internal class OrderLogic
|
public class OrderLogic : IOrderLogic
|
||||||
{
|
{
|
||||||
//Класс с логикой для заказов будет отвечать за получение списка заказов,
|
//Класс с логикой для заказов будет отвечать за получение списка заказов,
|
||||||
//создания заказа и смены его статусов. Следует учитывать, что у заказа можно
|
//создания заказа и смены его статусов. Следует учитывать, что у заказа можно
|
||||||
@ -29,7 +30,7 @@ namespace FishFactoryBusinessLogic.BusinessLogic
|
|||||||
|
|
||||||
public List<OrderViewModel>? ReadList(OrderSearchModel? model)
|
public List<OrderViewModel>? ReadList(OrderSearchModel? model)
|
||||||
{
|
{
|
||||||
_logger.LogInformation("ReadList. Id:{Id}", model?.Id);
|
_logger.LogInformation("ReadList. OrderId:{Id}", model?.Id);
|
||||||
var list = model == null ? _orderStorage.GetFullList() : _orderStorage.GetFilteredList(model);
|
var list = model == null ? _orderStorage.GetFullList() : _orderStorage.GetFilteredList(model);
|
||||||
if (list == null)
|
if (list == null)
|
||||||
{
|
{
|
||||||
@ -40,27 +41,12 @@ namespace FishFactoryBusinessLogic.BusinessLogic
|
|||||||
return list;
|
return list;
|
||||||
}
|
}
|
||||||
|
|
||||||
//public OrderViewModel? ReadElement(OrderSearchModel model)
|
public bool CreateOrder(OrderBindingModel model)
|
||||||
//{
|
|
||||||
// if (model == null)
|
|
||||||
// {
|
|
||||||
// throw new ArgumentNullException(nameof(model));
|
|
||||||
// }
|
|
||||||
// _logger.LogInformation("ReadElement. OrderName:{OrderName}.Id:{Id}", model.OrderName, model.Id);
|
|
||||||
// var element = _orderStorage.GetElement(model);
|
|
||||||
// if (element == null)
|
|
||||||
// {
|
|
||||||
// _logger.LogWarning("ReadElement element not found");
|
|
||||||
// return null;
|
|
||||||
// }
|
|
||||||
// _logger.LogInformation("ReadElement find. Id:{Id}", element.Id);
|
|
||||||
// return element;
|
|
||||||
//}
|
|
||||||
|
|
||||||
public bool Create(OrderBindingModel model)
|
|
||||||
{
|
{
|
||||||
CheckModel(model);
|
CheckModel(model);
|
||||||
|
|
||||||
|
if (model.Status != OrderStatus.Неизвестен)
|
||||||
|
return false;
|
||||||
model.Status = OrderStatus.Принят;
|
model.Status = OrderStatus.Принят;
|
||||||
|
|
||||||
if (_orderStorage.Insert(model) == null)
|
if (_orderStorage.Insert(model) == null)
|
||||||
@ -72,9 +58,40 @@ namespace FishFactoryBusinessLogic.BusinessLogic
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public bool TakeOrderInWork(OrderBindingModel model)
|
||||||
|
{
|
||||||
|
return ToNextStatus(model, OrderStatus.Выполняется);
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool FinishOrder(OrderBindingModel model)
|
||||||
|
{
|
||||||
|
return ToNextStatus(model, OrderStatus.Готов);
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool DeliveryOrder(OrderBindingModel model)
|
||||||
|
{
|
||||||
|
return ToNextStatus(model, OrderStatus.Выдан);
|
||||||
|
}
|
||||||
|
|
||||||
public bool ToNextStatus(OrderBindingModel model, OrderStatus orderStatus)
|
public bool ToNextStatus(OrderBindingModel model, OrderStatus orderStatus)
|
||||||
{
|
{
|
||||||
CheckModel(model);
|
CheckModel(model);
|
||||||
|
var element = _orderStorage.GetElement(new OrderSearchModel()
|
||||||
|
{
|
||||||
|
Id = model.Id
|
||||||
|
});
|
||||||
|
if (element == null)
|
||||||
|
{
|
||||||
|
throw new ArgumentNullException(nameof(element));
|
||||||
|
}
|
||||||
|
|
||||||
|
model.CannedId = element.CannedId;
|
||||||
|
model.DateCreate = element.DateCreate;
|
||||||
|
model.DateImplement = element.DateImplement;
|
||||||
|
model.Status = element.Status;
|
||||||
|
model.Count = element.Count;
|
||||||
|
model.Sum = element.Sum;
|
||||||
|
|
||||||
if (model.Status != orderStatus - 1)
|
if (model.Status != orderStatus - 1)
|
||||||
{
|
{
|
||||||
_logger.LogWarning("Status update to " + orderStatus + " operation failed");
|
_logger.LogWarning("Status update to " + orderStatus + " operation failed");
|
||||||
@ -90,19 +107,7 @@ namespace FishFactoryBusinessLogic.BusinessLogic
|
|||||||
if (_orderStorage.Update(model) == null)
|
if (_orderStorage.Update(model) == null)
|
||||||
{
|
{
|
||||||
model.Status--;
|
model.Status--;
|
||||||
_logger.LogWarning("Update operation failed");
|
_logger.LogWarning("Changing status operation faled");
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
public bool Update(OrderBindingModel model)
|
|
||||||
{
|
|
||||||
CheckModel(model);
|
|
||||||
if (_orderStorage.Update(model) == null)
|
|
||||||
{
|
|
||||||
_logger.LogWarning("Update operation failed");
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
@ -126,7 +131,7 @@ namespace FishFactoryBusinessLogic.BusinessLogic
|
|||||||
{
|
{
|
||||||
throw new ArgumentNullException("Цена заказа должна быть больше 0", nameof(model.Sum));
|
throw new ArgumentNullException("Цена заказа должна быть больше 0", nameof(model.Sum));
|
||||||
}
|
}
|
||||||
_logger.LogInformation("Order. OrderName: {Count}.Price: {Sum}. Id: {Id}", model.Count, model.Sum, model.Id);
|
_logger.LogInformation("Canned. CannedId:{CannedId}.Count:{Count}.Sum:{Sum}Id:{Id}", model.CannedId, model.Count, model.Sum, model.Id);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -12,8 +12,4 @@
|
|||||||
<ProjectReference Include="..\FishFactoryDataModels\FishFactoryDataModel.csproj" />
|
<ProjectReference Include="..\FishFactoryDataModels\FishFactoryDataModel.csproj" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
|
||||||
<Folder Include="Implements\" />
|
|
||||||
</ItemGroup>
|
|
||||||
|
|
||||||
</Project>
|
</Project>
|
||||||
|
112
FishFactoryListImplement/Implements/CannedStorage.cs
Normal file
112
FishFactoryListImplement/Implements/CannedStorage.cs
Normal file
@ -0,0 +1,112 @@
|
|||||||
|
using FishFactoryContracts.BindingModels;
|
||||||
|
using FishFactoryContracts.SearchModels;
|
||||||
|
using FishFactoryContracts.StoragesContracts;
|
||||||
|
using FishFactoryContracts.ViewModels;
|
||||||
|
using FishFactoryListImplement.Models;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace FishFactoryListImplement.Implements
|
||||||
|
{
|
||||||
|
public class CannedStorage : ICannedStorage
|
||||||
|
{
|
||||||
|
private readonly DataListSingleton _source;
|
||||||
|
public CannedStorage()
|
||||||
|
{
|
||||||
|
_source = DataListSingleton.GetInstance();
|
||||||
|
}
|
||||||
|
|
||||||
|
public CannedViewModel? Delete(CannedBindingModel model)
|
||||||
|
{
|
||||||
|
for (int i = 0; i < _source.Canneds.Count; ++i)
|
||||||
|
{
|
||||||
|
if (_source.Canneds[i].Id == model.Id)
|
||||||
|
{
|
||||||
|
var element = _source.Canneds[i];
|
||||||
|
_source.Canneds.RemoveAt(i);
|
||||||
|
return element.GetViewModel;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public CannedViewModel? GetElement(CannedSearchModel model)
|
||||||
|
{
|
||||||
|
if (string.IsNullOrEmpty(model.CannedName) && !model.Id.HasValue)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
foreach (var canned in _source.Canneds)
|
||||||
|
{
|
||||||
|
if ((!string.IsNullOrEmpty(model.CannedName) && canned.CannedName == model.CannedName) ||
|
||||||
|
(model.Id.HasValue && canned.Id == model.Id))
|
||||||
|
{
|
||||||
|
return canned.GetViewModel;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<CannedViewModel> GetFilteredList(CannedSearchModel model)
|
||||||
|
{
|
||||||
|
var result = new List<CannedViewModel>();
|
||||||
|
if (string.IsNullOrEmpty(model.CannedName))
|
||||||
|
{
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
foreach (var canned in _source.Canneds)
|
||||||
|
{
|
||||||
|
if (canned.CannedName.Contains(model.CannedName))
|
||||||
|
{
|
||||||
|
result.Add(canned.GetViewModel);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<CannedViewModel> GetFullList()
|
||||||
|
{
|
||||||
|
var result = new List<CannedViewModel>();
|
||||||
|
foreach (var canned in _source.Canneds)
|
||||||
|
{
|
||||||
|
result.Add(canned.GetViewModel);
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
public CannedViewModel? Insert(CannedBindingModel model)
|
||||||
|
{
|
||||||
|
model.Id = 1;
|
||||||
|
foreach (var canned in _source.Canneds)
|
||||||
|
{
|
||||||
|
if (model.Id <= canned.Id)
|
||||||
|
{
|
||||||
|
model.Id = canned.Id + 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
var newCanned = Canned.Create(model);
|
||||||
|
if (newCanned == null)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
_source.Canneds.Add(newCanned);
|
||||||
|
return newCanned.GetViewModel;
|
||||||
|
}
|
||||||
|
|
||||||
|
public CannedViewModel? Update(CannedBindingModel model)
|
||||||
|
{
|
||||||
|
foreach (var canned in _source.Canneds)
|
||||||
|
{
|
||||||
|
if (canned.Id == model.Id)
|
||||||
|
{
|
||||||
|
canned.Update(model);
|
||||||
|
return canned.GetViewModel;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
106
FishFactoryListImplement/Implements/ComponentStorage.cs
Normal file
106
FishFactoryListImplement/Implements/ComponentStorage.cs
Normal file
@ -0,0 +1,106 @@
|
|||||||
|
using FishFactoryContracts.StoragesContracts;
|
||||||
|
using FishFactoryContracts.BindingModels;
|
||||||
|
using FishFactoryContracts.SearchModels;
|
||||||
|
using FishFactoryContracts.ViewModels;
|
||||||
|
using FishFactoryListImplement.Models;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace FishFactoryListImplement.Implements
|
||||||
|
{
|
||||||
|
public class ComponentStorage : IComponentStorage
|
||||||
|
{
|
||||||
|
private readonly DataListSingleton _source;
|
||||||
|
public ComponentStorage()
|
||||||
|
{
|
||||||
|
_source = DataListSingleton.GetInstance();
|
||||||
|
}
|
||||||
|
public List<ComponentViewModel> GetFullList()
|
||||||
|
{
|
||||||
|
var result = new List<ComponentViewModel>();
|
||||||
|
foreach (var component in _source.Components)
|
||||||
|
{
|
||||||
|
result.Add(component.GetViewModel);
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
public List<ComponentViewModel> GetFilteredList(ComponentSearchModel model)
|
||||||
|
{
|
||||||
|
var result = new List<ComponentViewModel>();
|
||||||
|
if (string.IsNullOrEmpty(model.ComponentName))
|
||||||
|
{
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
foreach (var component in _source.Components)
|
||||||
|
{
|
||||||
|
if (component.ComponentName.Contains(model.ComponentName))
|
||||||
|
{
|
||||||
|
result.Add(component.GetViewModel);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
public ComponentViewModel? GetElement(ComponentSearchModel model)
|
||||||
|
{
|
||||||
|
if (string.IsNullOrEmpty(model.ComponentName) && !model.Id.HasValue)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
foreach (var component in _source.Components)
|
||||||
|
{
|
||||||
|
if ((!string.IsNullOrEmpty(model.ComponentName) && component.ComponentName == model.ComponentName) ||
|
||||||
|
(model.Id.HasValue && component.Id == model.Id))
|
||||||
|
{
|
||||||
|
return component.GetViewModel;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
public ComponentViewModel? Insert(ComponentBindingModel model)
|
||||||
|
{
|
||||||
|
model.Id = 1;
|
||||||
|
foreach (var component in _source.Components)
|
||||||
|
{
|
||||||
|
if (model.Id <= component.Id)
|
||||||
|
{
|
||||||
|
model.Id = component.Id + 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
var newComponent = Component.Create(model);
|
||||||
|
if (newComponent == null)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
_source.Components.Add(newComponent);
|
||||||
|
return newComponent.GetViewModel;
|
||||||
|
}
|
||||||
|
public ComponentViewModel? Update(ComponentBindingModel model)
|
||||||
|
{
|
||||||
|
foreach (var component in _source.Components)
|
||||||
|
{
|
||||||
|
if (component.Id == model.Id)
|
||||||
|
{
|
||||||
|
component.Update(model);
|
||||||
|
return component.GetViewModel;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
public ComponentViewModel? Delete(ComponentBindingModel model)
|
||||||
|
{
|
||||||
|
for (int i = 0; i < _source.Components.Count; ++i)
|
||||||
|
{
|
||||||
|
if (_source.Components[i].Id == model.Id)
|
||||||
|
{
|
||||||
|
var element = _source.Components[i];
|
||||||
|
_source.Components.RemoveAt(i);
|
||||||
|
return element.GetViewModel;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
125
FishFactoryListImplement/Implements/OrderStorage.cs
Normal file
125
FishFactoryListImplement/Implements/OrderStorage.cs
Normal file
@ -0,0 +1,125 @@
|
|||||||
|
using FishFactoryContracts.BindingModels;
|
||||||
|
using FishFactoryContracts.SearchModels;
|
||||||
|
using FishFactoryContracts.StoragesContracts;
|
||||||
|
using FishFactoryContracts.ViewModels;
|
||||||
|
using FishFactoryListImplement.Models;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace FishFactoryListImplement.Implements
|
||||||
|
{
|
||||||
|
public class OrderStorage : IOrderStorage
|
||||||
|
{
|
||||||
|
private readonly DataListSingleton _source;
|
||||||
|
|
||||||
|
public OrderStorage()
|
||||||
|
{
|
||||||
|
_source = DataListSingleton.GetInstance();
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<OrderViewModel> GetFullList()
|
||||||
|
{
|
||||||
|
var result = new List<OrderViewModel>();
|
||||||
|
foreach (var order in _source.Orders)
|
||||||
|
{
|
||||||
|
result.Add(AttachCannedName(order.GetViewModel));
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<OrderViewModel> GetFilteredList(OrderSearchModel model)
|
||||||
|
{
|
||||||
|
var result = new List<OrderViewModel>();
|
||||||
|
if (model == null || !model.Id.HasValue)
|
||||||
|
{
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
foreach (var order in _source.Orders)
|
||||||
|
{
|
||||||
|
if (order.Id == model.Id)
|
||||||
|
{
|
||||||
|
result.Add(AttachCannedName(order.GetViewModel));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
public OrderViewModel? GetElement(OrderSearchModel model)
|
||||||
|
{
|
||||||
|
if (!model.Id.HasValue)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
foreach (var order in _source.Orders)
|
||||||
|
{
|
||||||
|
if (model.Id.HasValue && order.Id == model.Id)
|
||||||
|
{
|
||||||
|
return AttachCannedName(order.GetViewModel);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public OrderViewModel? Insert(OrderBindingModel model)
|
||||||
|
{
|
||||||
|
model.Id = 1;
|
||||||
|
foreach (var order in _source.Orders)
|
||||||
|
{
|
||||||
|
if (model.Id <= order.Id)
|
||||||
|
{
|
||||||
|
model.Id = order.Id + 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
var newOrder = Order.Create(model);
|
||||||
|
if (newOrder == null)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
_source.Orders.Add(newOrder);
|
||||||
|
return AttachCannedName(newOrder.GetViewModel);
|
||||||
|
}
|
||||||
|
|
||||||
|
public OrderViewModel? Update(OrderBindingModel model)
|
||||||
|
{
|
||||||
|
foreach (var order in _source.Orders)
|
||||||
|
{
|
||||||
|
if (order.Id == model.Id)
|
||||||
|
{
|
||||||
|
order.Update(model);
|
||||||
|
return AttachCannedName(order.GetViewModel);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public OrderViewModel? Delete(OrderBindingModel model)
|
||||||
|
{
|
||||||
|
for (int i = 0; i < _source.Orders.Count; ++i)
|
||||||
|
{
|
||||||
|
if (_source.Orders[i].Id == model.Id)
|
||||||
|
{
|
||||||
|
var element = _source.Orders[i];
|
||||||
|
_source.Orders.RemoveAt(i);
|
||||||
|
return AttachCannedName(element.GetViewModel);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
private OrderViewModel AttachCannedName(OrderViewModel model)
|
||||||
|
{
|
||||||
|
foreach (var canned in _source.Canneds)
|
||||||
|
{
|
||||||
|
if (canned.Id == model.CannedId)
|
||||||
|
{
|
||||||
|
model.CannedName = canned.CannedName;
|
||||||
|
return model;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return model;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -26,11 +26,11 @@ namespace FishFactoryListImplement.Models
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
return new Canned()
|
return new Canned()
|
||||||
{
|
{
|
||||||
Id = model.Id,
|
Id = model.Id,
|
||||||
CannedName = model.CannedName,
|
CannedName = model.CannedName,
|
||||||
Price = model.Price,
|
Price = model.Price,
|
||||||
CannedComponents = model.CannedComponents
|
CannedComponents = model.CannedComponents
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
public void Update(CannedBindingModel? model)
|
public void Update(CannedBindingModel? model)
|
||||||
|
11
FishFactoryView/FishFactoryView.csproj
Normal file
11
FishFactoryView/FishFactoryView.csproj
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
<Project Sdk="Microsoft.NET.Sdk">
|
||||||
|
|
||||||
|
<PropertyGroup>
|
||||||
|
<OutputType>WinExe</OutputType>
|
||||||
|
<TargetFramework>net6.0-windows</TargetFramework>
|
||||||
|
<Nullable>enable</Nullable>
|
||||||
|
<UseWindowsForms>true</UseWindowsForms>
|
||||||
|
<ImplicitUsings>enable</ImplicitUsings>
|
||||||
|
</PropertyGroup>
|
||||||
|
|
||||||
|
</Project>
|
39
FishFactoryView/Form1.Designer.cs
generated
Normal file
39
FishFactoryView/Form1.Designer.cs
generated
Normal file
@ -0,0 +1,39 @@
|
|||||||
|
namespace FishFactoryView
|
||||||
|
{
|
||||||
|
partial class Form1
|
||||||
|
{
|
||||||
|
/// <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.components = new System.ComponentModel.Container();
|
||||||
|
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
||||||
|
this.ClientSize = new System.Drawing.Size(800, 450);
|
||||||
|
this.Text = "Form1";
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
}
|
||||||
|
}
|
10
FishFactoryView/Form1.cs
Normal file
10
FishFactoryView/Form1.cs
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
namespace FishFactoryView
|
||||||
|
{
|
||||||
|
public partial class Form1 : Form
|
||||||
|
{
|
||||||
|
public Form1()
|
||||||
|
{
|
||||||
|
InitializeComponent();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
120
FishFactoryView/Form1.resx
Normal file
120
FishFactoryView/Form1.resx
Normal file
@ -0,0 +1,120 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<root>
|
||||||
|
<!--
|
||||||
|
Microsoft ResX Schema
|
||||||
|
|
||||||
|
Version 2.0
|
||||||
|
|
||||||
|
The primary goals of this format is to allow a simple XML format
|
||||||
|
that is mostly human readable. The generation and parsing of the
|
||||||
|
various data types are done through the TypeConverter classes
|
||||||
|
associated with the data types.
|
||||||
|
|
||||||
|
Example:
|
||||||
|
|
||||||
|
... ado.net/XML headers & schema ...
|
||||||
|
<resheader name="resmimetype">text/microsoft-resx</resheader>
|
||||||
|
<resheader name="version">2.0</resheader>
|
||||||
|
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
|
||||||
|
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
|
||||||
|
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
|
||||||
|
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
|
||||||
|
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
|
||||||
|
<value>[base64 mime encoded serialized .NET Framework object]</value>
|
||||||
|
</data>
|
||||||
|
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
|
||||||
|
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
|
||||||
|
<comment>This is a comment</comment>
|
||||||
|
</data>
|
||||||
|
|
||||||
|
There are any number of "resheader" rows that contain simple
|
||||||
|
name/value pairs.
|
||||||
|
|
||||||
|
Each data row contains a name, and value. The row also contains a
|
||||||
|
type or mimetype. Type corresponds to a .NET class that support
|
||||||
|
text/value conversion through the TypeConverter architecture.
|
||||||
|
Classes that don't support this are serialized and stored with the
|
||||||
|
mimetype set.
|
||||||
|
|
||||||
|
The mimetype is used for serialized objects, and tells the
|
||||||
|
ResXResourceReader how to depersist the object. This is currently not
|
||||||
|
extensible. For a given mimetype the value must be set accordingly:
|
||||||
|
|
||||||
|
Note - application/x-microsoft.net.object.binary.base64 is the format
|
||||||
|
that the ResXResourceWriter will generate, however the reader can
|
||||||
|
read any of the formats listed below.
|
||||||
|
|
||||||
|
mimetype: application/x-microsoft.net.object.binary.base64
|
||||||
|
value : The object must be serialized with
|
||||||
|
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
|
||||||
|
: and then encoded with base64 encoding.
|
||||||
|
|
||||||
|
mimetype: application/x-microsoft.net.object.soap.base64
|
||||||
|
value : The object must be serialized with
|
||||||
|
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
|
||||||
|
: and then encoded with base64 encoding.
|
||||||
|
|
||||||
|
mimetype: application/x-microsoft.net.object.bytearray.base64
|
||||||
|
value : The object must be serialized into a byte array
|
||||||
|
: using a System.ComponentModel.TypeConverter
|
||||||
|
: and then encoded with base64 encoding.
|
||||||
|
-->
|
||||||
|
<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>
|
17
FishFactoryView/Program.cs
Normal file
17
FishFactoryView/Program.cs
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
namespace FishFactoryView
|
||||||
|
{
|
||||||
|
internal static class Program
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// The main entry point for the application.
|
||||||
|
/// </summary>
|
||||||
|
[STAThread]
|
||||||
|
static void Main()
|
||||||
|
{
|
||||||
|
// To customize application configuration such as set high DPI settings or default font,
|
||||||
|
// see https://aka.ms/applicationconfiguration.
|
||||||
|
ApplicationConfiguration.Initialize();
|
||||||
|
Application.Run(new Form1());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user