Compare commits
20 Commits
main
...
LabWork03H
Author | SHA1 | Date | |
---|---|---|---|
8e2e38e9b5 | |||
4ae6ea799f | |||
2ea3de7ef8 | |||
0e7abff08d | |||
b805fab4e0 | |||
d51f570841 | |||
1a3bab24a2 | |||
df6465ba4f | |||
831820a677 | |||
9448236d93 | |||
576c9d2a63 | |||
d0514ff3b3 | |||
987f1174b2 | |||
f7e4f386ba | |||
7914c6d4b0 | |||
ed8a8bb865 | |||
7b3c8b5b25 | |||
e9a686fc1a | |||
5554130092 | |||
75702dfc08 |
1
.gitignore
vendored
1
.gitignore
vendored
@ -398,3 +398,4 @@ FodyWeavers.xsd
|
||||
# JetBrains Rider
|
||||
*.sln.iml
|
||||
|
||||
/CarpentryWorkshop/ImplementationExtensions
|
||||
|
@ -3,7 +3,19 @@ Microsoft Visual Studio Solution File, Format Version 12.00
|
||||
# Visual Studio Version 17
|
||||
VisualStudioVersion = 17.7.34024.191
|
||||
MinimumVisualStudioVersion = 10.0.40219.1
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CarpentryWorkshop", "CarpentryWorkshop\CarpentryWorkshop.csproj", "{98E796E8-D77E-4A5D-BB64-1C4029C51360}"
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "CarpentryWorkshopView", "CarpentryWorkshop\CarpentryWorkshopView.csproj", "{98E796E8-D77E-4A5D-BB64-1C4029C51360}"
|
||||
EndProject
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "CarpentryWorkshopDataModels", "CarpentryWorkshopDataModels\CarpentryWorkshopDataModels.csproj", "{E4AD7D91-C944-486B-891A-32D402EE6AD8}"
|
||||
EndProject
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "CarpentryWorkshopContracts", "CarpentryWorkshopContracts\CarpentryWorkshopContracts.csproj", "{E1F5F636-7BA7-49CA-AF95-D36D1C55FD0E}"
|
||||
EndProject
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "CarpentryWorkshopListImplement", "CarpentryWorkshopListImplement\CarpentryWorkshopListImplement.csproj", "{8778E6ED-03D0-4073-B61E-8ED7FF2DC420}"
|
||||
EndProject
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "CarpentryWorkshopBusinessLogic", "CarpentryWorkshopBusinessLogic\CarpentryWorkshopBusinessLogic.csproj", "{4D7EFA75-B5DC-4287-A50D-73405118D4A0}"
|
||||
EndProject
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "CarpentryWorkshopFileImplement", "CarpentryWorkshopFileImplement\CarpentryWorkshopFileImplement.csproj", "{6EFF6C01-263D-4D25-806A-1DC593820AB1}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CarpentryWorkshopDatabaseImplement", "CarpentryWorkshopDatabaseImplement\CarpentryWorkshopDatabaseImplement.csproj", "{249894CF-B596-4AFD-8EB7-F167056920A1}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
@ -15,6 +27,30 @@ Global
|
||||
{98E796E8-D77E-4A5D-BB64-1C4029C51360}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{98E796E8-D77E-4A5D-BB64-1C4029C51360}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{98E796E8-D77E-4A5D-BB64-1C4029C51360}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{E4AD7D91-C944-486B-891A-32D402EE6AD8}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{E4AD7D91-C944-486B-891A-32D402EE6AD8}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{E4AD7D91-C944-486B-891A-32D402EE6AD8}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{E4AD7D91-C944-486B-891A-32D402EE6AD8}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{E1F5F636-7BA7-49CA-AF95-D36D1C55FD0E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{E1F5F636-7BA7-49CA-AF95-D36D1C55FD0E}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{E1F5F636-7BA7-49CA-AF95-D36D1C55FD0E}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{E1F5F636-7BA7-49CA-AF95-D36D1C55FD0E}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{8778E6ED-03D0-4073-B61E-8ED7FF2DC420}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{8778E6ED-03D0-4073-B61E-8ED7FF2DC420}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{8778E6ED-03D0-4073-B61E-8ED7FF2DC420}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{8778E6ED-03D0-4073-B61E-8ED7FF2DC420}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{4D7EFA75-B5DC-4287-A50D-73405118D4A0}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{4D7EFA75-B5DC-4287-A50D-73405118D4A0}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{4D7EFA75-B5DC-4287-A50D-73405118D4A0}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{4D7EFA75-B5DC-4287-A50D-73405118D4A0}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{6EFF6C01-263D-4D25-806A-1DC593820AB1}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{6EFF6C01-263D-4D25-806A-1DC593820AB1}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{6EFF6C01-263D-4D25-806A-1DC593820AB1}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{6EFF6C01-263D-4D25-806A-1DC593820AB1}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{249894CF-B596-4AFD-8EB7-F167056920A1}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{249894CF-B596-4AFD-8EB7-F167056920A1}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{249894CF-B596-4AFD-8EB7-F167056920A1}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{249894CF-B596-4AFD-8EB7-F167056920A1}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
|
@ -0,0 +1,39 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<OutputType>WinExe</OutputType>
|
||||
<TargetFramework>net6.0-windows</TargetFramework>
|
||||
<Nullable>enable</Nullable>
|
||||
<UseWindowsForms>true</UseWindowsForms>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<None Remove="nlog.config" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Content Include="nlog.config">
|
||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||
</Content>
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="7.0.17">
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
</PackageReference>
|
||||
<PackageReference Include="Microsoft.Extensions.Logging" Version="8.0.0" />
|
||||
<PackageReference Include="NLog.Extensions.Logging" Version="5.3.8" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\CarpentryWorkshopBusinessLogic\CarpentryWorkshopBusinessLogic.csproj" />
|
||||
<ProjectReference Include="..\CarpentryWorkshopContracts\CarpentryWorkshopContracts.csproj" />
|
||||
<ProjectReference Include="..\CarpentryWorkshopDatabaseImplement\CarpentryWorkshopDatabaseImplement.csproj" />
|
||||
<ProjectReference Include="..\CarpentryWorkshopDataModels\CarpentryWorkshopDataModels.csproj" />
|
||||
<ProjectReference Include="..\CarpentryWorkshopFileImplement\CarpentryWorkshopFileImplement.csproj" />
|
||||
<ProjectReference Include="..\CarpentryWorkshopListImplement\CarpentryWorkshopListImplement.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
@ -1,39 +0,0 @@
|
||||
namespace CarpentryWorkshop
|
||||
{
|
||||
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
|
||||
}
|
||||
}
|
@ -1,10 +0,0 @@
|
||||
namespace CarpentryWorkshop
|
||||
{
|
||||
public partial class Form1 : Form
|
||||
{
|
||||
public Form1()
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
}
|
||||
}
|
127
CarpentryWorkshop/CarpentryWorkshop/FormComponent.Designer.cs
generated
Normal file
127
CarpentryWorkshop/CarpentryWorkshop/FormComponent.Designer.cs
generated
Normal file
@ -0,0 +1,127 @@
|
||||
namespace CarpentryWorkshopView
|
||||
{
|
||||
partial class FormComponent
|
||||
{
|
||||
/// <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.buttonCancel = new System.Windows.Forms.Button();
|
||||
this.buttonSave = new System.Windows.Forms.Button();
|
||||
this.textBoxName = new System.Windows.Forms.TextBox();
|
||||
this.labelName = new System.Windows.Forms.Label();
|
||||
this.textBoxCost = new System.Windows.Forms.TextBox();
|
||||
this.labelCost = new System.Windows.Forms.Label();
|
||||
this.SuspendLayout();
|
||||
//
|
||||
// buttonCancel
|
||||
//
|
||||
this.buttonCancel.Location = new System.Drawing.Point(257, 71);
|
||||
this.buttonCancel.Margin = new System.Windows.Forms.Padding(4, 3, 4, 3);
|
||||
this.buttonCancel.Name = "buttonCancel";
|
||||
this.buttonCancel.Size = new System.Drawing.Size(88, 27);
|
||||
this.buttonCancel.TabIndex = 5;
|
||||
this.buttonCancel.Text = "Отмена";
|
||||
this.buttonCancel.UseVisualStyleBackColor = true;
|
||||
this.buttonCancel.Click += new System.EventHandler(this.ButtonCancel_Click);
|
||||
//
|
||||
// buttonSave
|
||||
//
|
||||
this.buttonSave.Location = new System.Drawing.Point(162, 71);
|
||||
this.buttonSave.Margin = new System.Windows.Forms.Padding(4, 3, 4, 3);
|
||||
this.buttonSave.Name = "buttonSave";
|
||||
this.buttonSave.Size = new System.Drawing.Size(88, 27);
|
||||
this.buttonSave.TabIndex = 4;
|
||||
this.buttonSave.Text = "Сохранить";
|
||||
this.buttonSave.UseVisualStyleBackColor = true;
|
||||
this.buttonSave.Click += new System.EventHandler(this.ButtonSave_Click);
|
||||
//
|
||||
// textBoxName
|
||||
//
|
||||
this.textBoxName.Location = new System.Drawing.Point(91, 7);
|
||||
this.textBoxName.Margin = new System.Windows.Forms.Padding(4, 3, 4, 3);
|
||||
this.textBoxName.Name = "textBoxName";
|
||||
this.textBoxName.Size = new System.Drawing.Size(252, 23);
|
||||
this.textBoxName.TabIndex = 1;
|
||||
//
|
||||
// labelName
|
||||
//
|
||||
this.labelName.AutoSize = true;
|
||||
this.labelName.Location = new System.Drawing.Point(14, 10);
|
||||
this.labelName.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0);
|
||||
this.labelName.Name = "labelName";
|
||||
this.labelName.Size = new System.Drawing.Size(62, 15);
|
||||
this.labelName.TabIndex = 0;
|
||||
this.labelName.Text = "Название:";
|
||||
//
|
||||
// textBoxCost
|
||||
//
|
||||
this.textBoxCost.Location = new System.Drawing.Point(91, 36);
|
||||
this.textBoxCost.Margin = new System.Windows.Forms.Padding(4, 3, 4, 3);
|
||||
this.textBoxCost.Name = "textBoxCost";
|
||||
this.textBoxCost.Size = new System.Drawing.Size(129, 23);
|
||||
this.textBoxCost.TabIndex = 3;
|
||||
//
|
||||
// labelCost
|
||||
//
|
||||
this.labelCost.AutoSize = true;
|
||||
this.labelCost.Location = new System.Drawing.Point(14, 39);
|
||||
this.labelCost.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0);
|
||||
this.labelCost.Name = "labelCost";
|
||||
this.labelCost.Size = new System.Drawing.Size(38, 15);
|
||||
this.labelCost.TabIndex = 2;
|
||||
this.labelCost.Text = "Цена:";
|
||||
//
|
||||
// FormComponent
|
||||
//
|
||||
this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F);
|
||||
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
||||
this.ClientSize = new System.Drawing.Size(360, 110);
|
||||
this.Controls.Add(this.textBoxCost);
|
||||
this.Controls.Add(this.labelCost);
|
||||
this.Controls.Add(this.buttonCancel);
|
||||
this.Controls.Add(this.buttonSave);
|
||||
this.Controls.Add(this.textBoxName);
|
||||
this.Controls.Add(this.labelName);
|
||||
this.Margin = new System.Windows.Forms.Padding(4, 3, 4, 3);
|
||||
this.Name = "FormComponent";
|
||||
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
|
||||
this.Text = "Компонент";
|
||||
this.Load += new System.EventHandler(this.FormComponent_Load);
|
||||
this.ResumeLayout(false);
|
||||
this.PerformLayout();
|
||||
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
private System.Windows.Forms.Button buttonCancel;
|
||||
private System.Windows.Forms.Button buttonSave;
|
||||
private System.Windows.Forms.TextBox textBoxName;
|
||||
private System.Windows.Forms.Label labelName;
|
||||
private TextBox textBoxCost;
|
||||
private Label labelCost;
|
||||
}
|
||||
}
|
85
CarpentryWorkshop/CarpentryWorkshop/FormComponent.cs
Normal file
85
CarpentryWorkshop/CarpentryWorkshop/FormComponent.cs
Normal file
@ -0,0 +1,85 @@
|
||||
using CarpentryWorkshopContracts.BindingModels;
|
||||
using CarpentryWorkshopContracts.BusinessLogicsContracts;
|
||||
using CarpentryWorkshopContracts.SearchModels;
|
||||
using Microsoft.Extensions.Logging;
|
||||
|
||||
namespace CarpentryWorkshopView
|
||||
{
|
||||
public partial class FormComponent : Form
|
||||
{
|
||||
private readonly ILogger _logger;
|
||||
|
||||
private readonly IComponentLogic _logic;
|
||||
|
||||
private int? _id;
|
||||
|
||||
public int Id { set { _id = value; } }
|
||||
|
||||
public FormComponent(ILogger<FormComponent> logger, IComponentLogic logic)
|
||||
{
|
||||
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)
|
||||
{
|
||||
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)
|
||||
{
|
||||
DialogResult = DialogResult.Cancel;
|
||||
Close();
|
||||
}
|
||||
}
|
||||
}
|
122
CarpentryWorkshop/CarpentryWorkshop/FormComponents.Designer.cs
generated
Normal file
122
CarpentryWorkshop/CarpentryWorkshop/FormComponents.Designer.cs
generated
Normal file
@ -0,0 +1,122 @@
|
||||
namespace CarpentryWorkshopView
|
||||
{
|
||||
partial class FormComponents
|
||||
{
|
||||
/// <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.buttonRef = new System.Windows.Forms.Button();
|
||||
this.buttonDel = new System.Windows.Forms.Button();
|
||||
this.buttonUpd = new System.Windows.Forms.Button();
|
||||
this.buttonAdd = new System.Windows.Forms.Button();
|
||||
this.dataGridView = new System.Windows.Forms.DataGridView();
|
||||
((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit();
|
||||
this.SuspendLayout();
|
||||
//
|
||||
// buttonRef
|
||||
//
|
||||
this.buttonRef.Location = new System.Drawing.Point(370, 132);
|
||||
this.buttonRef.Name = "buttonRef";
|
||||
this.buttonRef.Size = new System.Drawing.Size(75, 23);
|
||||
this.buttonRef.TabIndex = 4;
|
||||
this.buttonRef.Text = "Обновить";
|
||||
this.buttonRef.UseVisualStyleBackColor = true;
|
||||
this.buttonRef.Click += new System.EventHandler(this.buttonRef_Click);
|
||||
//
|
||||
// buttonDel
|
||||
//
|
||||
this.buttonDel.Location = new System.Drawing.Point(370, 91);
|
||||
this.buttonDel.Name = "buttonDel";
|
||||
this.buttonDel.Size = new System.Drawing.Size(75, 23);
|
||||
this.buttonDel.TabIndex = 3;
|
||||
this.buttonDel.Text = "Удалить";
|
||||
this.buttonDel.UseVisualStyleBackColor = true;
|
||||
this.buttonDel.Click += new System.EventHandler(this.buttonDel_Click);
|
||||
//
|
||||
// buttonUpd
|
||||
//
|
||||
this.buttonUpd.Location = new System.Drawing.Point(370, 50);
|
||||
this.buttonUpd.Name = "buttonUpd";
|
||||
this.buttonUpd.Size = new System.Drawing.Size(75, 23);
|
||||
this.buttonUpd.TabIndex = 2;
|
||||
this.buttonUpd.Text = "Изменить";
|
||||
this.buttonUpd.UseVisualStyleBackColor = true;
|
||||
this.buttonUpd.Click += new System.EventHandler(this.buttonUpd_Click);
|
||||
//
|
||||
// buttonAdd
|
||||
//
|
||||
this.buttonAdd.Location = new System.Drawing.Point(370, 12);
|
||||
this.buttonAdd.Name = "buttonAdd";
|
||||
this.buttonAdd.Size = new System.Drawing.Size(75, 23);
|
||||
this.buttonAdd.TabIndex = 1;
|
||||
this.buttonAdd.Text = "Добавить";
|
||||
this.buttonAdd.UseVisualStyleBackColor = true;
|
||||
this.buttonAdd.Click += new System.EventHandler(this.buttonAdd_Click);
|
||||
//
|
||||
// dataGridView
|
||||
//
|
||||
this.dataGridView.AllowUserToAddRows = false;
|
||||
this.dataGridView.AllowUserToDeleteRows = false;
|
||||
this.dataGridView.BackgroundColor = System.Drawing.SystemColors.ControlLightLight;
|
||||
this.dataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
|
||||
this.dataGridView.Dock = System.Windows.Forms.DockStyle.Left;
|
||||
this.dataGridView.Location = new System.Drawing.Point(0, 0);
|
||||
this.dataGridView.MultiSelect = false;
|
||||
this.dataGridView.Name = "dataGridView";
|
||||
this.dataGridView.ReadOnly = true;
|
||||
this.dataGridView.RowHeadersVisible = false;
|
||||
this.dataGridView.SelectionMode = System.Windows.Forms.DataGridViewSelectionMode.FullRowSelect;
|
||||
this.dataGridView.Size = new System.Drawing.Size(350, 312);
|
||||
this.dataGridView.TabIndex = 0;
|
||||
//
|
||||
// FormComponents
|
||||
//
|
||||
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
|
||||
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
||||
this.ClientSize = new System.Drawing.Size(464, 312);
|
||||
this.Controls.Add(this.buttonRef);
|
||||
this.Controls.Add(this.buttonDel);
|
||||
this.Controls.Add(this.buttonUpd);
|
||||
this.Controls.Add(this.buttonAdd);
|
||||
this.Controls.Add(this.dataGridView);
|
||||
this.Name = "FormComponents";
|
||||
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
|
||||
this.Text = "Компоненты";
|
||||
this.Load += new System.EventHandler(this.FormComponents_Load);
|
||||
((System.ComponentModel.ISupportInitialize)(this.dataGridView)).EndInit();
|
||||
this.ResumeLayout(false);
|
||||
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
private System.Windows.Forms.Button buttonRef;
|
||||
private System.Windows.Forms.Button buttonDel;
|
||||
private System.Windows.Forms.Button buttonUpd;
|
||||
private System.Windows.Forms.Button buttonAdd;
|
||||
private System.Windows.Forms.DataGridView dataGridView;
|
||||
}
|
||||
}
|
105
CarpentryWorkshop/CarpentryWorkshop/FormComponents.cs
Normal file
105
CarpentryWorkshop/CarpentryWorkshop/FormComponents.cs
Normal file
@ -0,0 +1,105 @@
|
||||
using CarpentryWorkshop;
|
||||
using CarpentryWorkshopContracts.BindingModels;
|
||||
using CarpentryWorkshopContracts.BusinessLogicsContracts;
|
||||
using Microsoft.Extensions.Logging;
|
||||
|
||||
namespace CarpentryWorkshopView
|
||||
{
|
||||
public partial class FormComponents : Form
|
||||
{
|
||||
private readonly ILogger _logger;
|
||||
|
||||
private readonly IComponentLogic _logic;
|
||||
|
||||
public FormComponents(ILogger<FormComponents> logger, IComponentLogic logic)
|
||||
{
|
||||
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();
|
||||
}
|
||||
}
|
||||
}
|
120
CarpentryWorkshop/CarpentryWorkshop/FormComponents.resx
Normal file
120
CarpentryWorkshop/CarpentryWorkshop/FormComponents.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>
|
154
CarpentryWorkshop/CarpentryWorkshop/FormCreateOrder.Designer.cs
generated
Normal file
154
CarpentryWorkshop/CarpentryWorkshop/FormCreateOrder.Designer.cs
generated
Normal file
@ -0,0 +1,154 @@
|
||||
namespace CarpentryWorkshopView
|
||||
{
|
||||
partial class FormCreateOrder
|
||||
{
|
||||
/// <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()
|
||||
{
|
||||
labelCount = new Label();
|
||||
comboBoxWood = new ComboBox();
|
||||
buttonCancel = new Button();
|
||||
buttonSave = new Button();
|
||||
textBoxCount = new TextBox();
|
||||
labelProduct = new Label();
|
||||
labelSum = new Label();
|
||||
textBoxSum = new TextBox();
|
||||
SuspendLayout();
|
||||
//
|
||||
// labelCount
|
||||
//
|
||||
labelCount.AutoSize = true;
|
||||
labelCount.Location = new Point(14, 42);
|
||||
labelCount.Margin = new Padding(4, 0, 4, 0);
|
||||
labelCount.Name = "labelCount";
|
||||
labelCount.Size = new Size(75, 15);
|
||||
labelCount.TabIndex = 2;
|
||||
labelCount.Text = "Количество:";
|
||||
//
|
||||
// comboBoxWood
|
||||
//
|
||||
comboBoxWood.DropDownStyle = ComboBoxStyle.DropDownList;
|
||||
comboBoxWood.FormattingEnabled = true;
|
||||
comboBoxWood.Location = new Point(102, 7);
|
||||
comboBoxWood.Margin = new Padding(4, 3, 4, 3);
|
||||
comboBoxWood.Name = "comboBoxWood";
|
||||
comboBoxWood.Size = new Size(252, 23);
|
||||
comboBoxWood.TabIndex = 1;
|
||||
comboBoxWood.SelectedIndexChanged += comboBoxWood_SelectedIndexChanged;
|
||||
//
|
||||
// buttonCancel
|
||||
//
|
||||
buttonCancel.Location = new Point(255, 98);
|
||||
buttonCancel.Margin = new Padding(4, 3, 4, 3);
|
||||
buttonCancel.Name = "buttonCancel";
|
||||
buttonCancel.Size = new Size(88, 27);
|
||||
buttonCancel.TabIndex = 7;
|
||||
buttonCancel.Text = "Отмена";
|
||||
buttonCancel.UseVisualStyleBackColor = true;
|
||||
buttonCancel.Click += ButtonCancel_Click;
|
||||
//
|
||||
// buttonSave
|
||||
//
|
||||
buttonSave.Location = new Point(161, 98);
|
||||
buttonSave.Margin = new Padding(4, 3, 4, 3);
|
||||
buttonSave.Name = "buttonSave";
|
||||
buttonSave.Size = new Size(88, 27);
|
||||
buttonSave.TabIndex = 6;
|
||||
buttonSave.Text = "Сохранить";
|
||||
buttonSave.UseVisualStyleBackColor = true;
|
||||
buttonSave.Click += ButtonSave_Click;
|
||||
//
|
||||
// textBoxCount
|
||||
//
|
||||
textBoxCount.Location = new Point(102, 38);
|
||||
textBoxCount.Margin = new Padding(4, 3, 4, 3);
|
||||
textBoxCount.Name = "textBoxCount";
|
||||
textBoxCount.Size = new Size(252, 23);
|
||||
textBoxCount.TabIndex = 3;
|
||||
textBoxCount.TextChanged += textBoxCount_TextChanged;
|
||||
//
|
||||
// labelProduct
|
||||
//
|
||||
labelProduct.AutoSize = true;
|
||||
labelProduct.Location = new Point(14, 10);
|
||||
labelProduct.Margin = new Padding(4, 0, 4, 0);
|
||||
labelProduct.Name = "labelProduct";
|
||||
labelProduct.Size = new Size(56, 15);
|
||||
labelProduct.TabIndex = 0;
|
||||
labelProduct.Text = "Изделие:";
|
||||
//
|
||||
// labelSum
|
||||
//
|
||||
labelSum.AutoSize = true;
|
||||
labelSum.Location = new Point(14, 72);
|
||||
labelSum.Margin = new Padding(4, 0, 4, 0);
|
||||
labelSum.Name = "labelSum";
|
||||
labelSum.Size = new Size(48, 15);
|
||||
labelSum.TabIndex = 4;
|
||||
labelSum.Text = "Сумма:";
|
||||
//
|
||||
// textBoxSum
|
||||
//
|
||||
textBoxSum.Location = new Point(102, 68);
|
||||
textBoxSum.Margin = new Padding(4, 3, 4, 3);
|
||||
textBoxSum.Name = "textBoxSum";
|
||||
textBoxSum.ReadOnly = true;
|
||||
textBoxSum.Size = new Size(252, 23);
|
||||
textBoxSum.TabIndex = 5;
|
||||
//
|
||||
// FormCreateOrder
|
||||
//
|
||||
AutoScaleDimensions = new SizeF(7F, 15F);
|
||||
AutoScaleMode = AutoScaleMode.Font;
|
||||
ClientSize = new Size(371, 136);
|
||||
Controls.Add(labelSum);
|
||||
Controls.Add(textBoxSum);
|
||||
Controls.Add(labelCount);
|
||||
Controls.Add(comboBoxWood);
|
||||
Controls.Add(buttonCancel);
|
||||
Controls.Add(buttonSave);
|
||||
Controls.Add(textBoxCount);
|
||||
Controls.Add(labelProduct);
|
||||
Margin = new Padding(4, 3, 4, 3);
|
||||
Name = "FormCreateOrder";
|
||||
StartPosition = FormStartPosition.CenterScreen;
|
||||
Text = "Заказ";
|
||||
Load += FormCreateOrder_Load;
|
||||
ResumeLayout(false);
|
||||
PerformLayout();
|
||||
}
|
||||
|
||||
#endregion
|
||||
private Label labelCount;
|
||||
private ComboBox comboBoxWood;
|
||||
private Button buttonCancel;
|
||||
private Button buttonSave;
|
||||
private TextBox textBoxCount;
|
||||
private Label labelProduct;
|
||||
private Label labelSum;
|
||||
private TextBox textBoxSum;
|
||||
}
|
||||
}
|
111
CarpentryWorkshop/CarpentryWorkshop/FormCreateOrder.cs
Normal file
111
CarpentryWorkshop/CarpentryWorkshop/FormCreateOrder.cs
Normal file
@ -0,0 +1,111 @@
|
||||
using CarpentryWorkshopContracts.BindingModels;
|
||||
using CarpentryWorkshopContracts.BusinessLogicsContracts;
|
||||
using CarpentryWorkshopContracts.SearchModels;
|
||||
using CarpentryWorkshopContracts.ViewModels;
|
||||
using Microsoft.Extensions.Logging;
|
||||
|
||||
namespace CarpentryWorkshopView
|
||||
{
|
||||
public partial class FormCreateOrder : Form
|
||||
{
|
||||
private readonly ILogger _logger;
|
||||
private readonly IWoodLogic _logicW;
|
||||
private readonly IOrderLogic _logicO;
|
||||
public FormCreateOrder(ILogger<FormCreateOrder> logger, IWoodLogic logicP, IOrderLogic logicO)
|
||||
{
|
||||
InitializeComponent();
|
||||
_logger = logger;
|
||||
_logicW = logicP;
|
||||
_logicO = logicO;
|
||||
}
|
||||
private void FormCreateOrder_Load(object sender, EventArgs e)
|
||||
{
|
||||
_logger.LogInformation("Загрузка изделий для заказа");
|
||||
try
|
||||
{
|
||||
var list = _logicW.ReadList(null);
|
||||
if (list != null)
|
||||
{
|
||||
comboBoxWood.DisplayMember = "WoodName";
|
||||
comboBoxWood.ValueMember = "Id";
|
||||
comboBoxWood.DataSource = list;
|
||||
comboBoxWood.SelectedItem = null;
|
||||
}
|
||||
_logger.LogInformation("Изделия загружены");
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка загрузки изделий");
|
||||
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK,
|
||||
MessageBoxIcon.Error);
|
||||
}
|
||||
}
|
||||
private void CalcSum()
|
||||
{
|
||||
if (comboBoxWood.SelectedValue != null && !string.IsNullOrEmpty(textBoxCount.Text))
|
||||
{
|
||||
try
|
||||
{
|
||||
int id = Convert.ToInt32(comboBoxWood.SelectedValue);
|
||||
var wood = _logicW.ReadElement(new WoodSearchModel { Id = id });
|
||||
int count = Convert.ToInt32(textBoxCount.Text);
|
||||
textBoxSum.Text = Math.Round(count * (wood?.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 comboBoxWood_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 (comboBoxWood.SelectedValue == null)
|
||||
{
|
||||
MessageBox.Show("Выберите изделие", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
return;
|
||||
}
|
||||
_logger.LogInformation("Создание заказа");
|
||||
try
|
||||
{
|
||||
var operationResult = _logicO.CreateOrder(new OrderBindingModel
|
||||
{
|
||||
WoodId = Convert.ToInt32(comboBoxWood.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();
|
||||
}
|
||||
}
|
||||
}
|
120
CarpentryWorkshop/CarpentryWorkshop/FormCreateOrder.resx
Normal file
120
CarpentryWorkshop/CarpentryWorkshop/FormCreateOrder.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>
|
206
CarpentryWorkshop/CarpentryWorkshop/FormMain.Designer.cs
generated
Normal file
206
CarpentryWorkshop/CarpentryWorkshop/FormMain.Designer.cs
generated
Normal file
@ -0,0 +1,206 @@
|
||||
namespace CarpentryWorkshopView
|
||||
{
|
||||
partial class FormMain
|
||||
{
|
||||
/// <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()
|
||||
{
|
||||
menuStrip1 = new MenuStrip();
|
||||
справочникиToolStripMenuItem = new ToolStripMenuItem();
|
||||
КомпонентыToolStripMenuItem = new ToolStripMenuItem();
|
||||
ИзделияToolStripMenuItem = new ToolStripMenuItem();
|
||||
продажиToolStripMenuItem = new ToolStripMenuItem();
|
||||
магазиныToolStripMenuItem = new ToolStripMenuItem();
|
||||
поставкиToolStripMenuItem = new ToolStripMenuItem();
|
||||
dataGridView = new DataGridView();
|
||||
ButtonCreateOrder = new Button();
|
||||
ButtonTakeOrderInWork = new Button();
|
||||
ButtonOrderReady = new Button();
|
||||
ButtonIssuedOrder = new Button();
|
||||
ButtonRef = new Button();
|
||||
menuStrip1.SuspendLayout();
|
||||
((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit();
|
||||
SuspendLayout();
|
||||
//
|
||||
// menuStrip1
|
||||
//
|
||||
menuStrip1.Items.AddRange(new ToolStripItem[] { справочникиToolStripMenuItem });
|
||||
menuStrip1.Location = new Point(0, 0);
|
||||
menuStrip1.Name = "menuStrip1";
|
||||
menuStrip1.Padding = new Padding(5, 2, 0, 2);
|
||||
menuStrip1.Size = new Size(1134, 24);
|
||||
menuStrip1.TabIndex = 0;
|
||||
menuStrip1.Text = "menuStrip1";
|
||||
//
|
||||
// справочникиToolStripMenuItem
|
||||
//
|
||||
справочникиToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { КомпонентыToolStripMenuItem, ИзделияToolStripMenuItem, магазиныToolStripMenuItem, поставкиToolStripMenuItem, продажиToolStripMenuItem });
|
||||
справочникиToolStripMenuItem.Name = "справочникиToolStripMenuItem";
|
||||
справочникиToolStripMenuItem.Size = new Size(94, 20);
|
||||
справочникиToolStripMenuItem.Text = "Справочники";
|
||||
//
|
||||
// КомпонентыToolStripMenuItem
|
||||
//
|
||||
КомпонентыToolStripMenuItem.Name = "КомпонентыToolStripMenuItem";
|
||||
КомпонентыToolStripMenuItem.Size = new Size(180, 22);
|
||||
КомпонентыToolStripMenuItem.Text = "Компоненты";
|
||||
КомпонентыToolStripMenuItem.Click += КомпонентыToolStripMenuItem_Click;
|
||||
//
|
||||
// ИзделияToolStripMenuItem
|
||||
//
|
||||
ИзделияToolStripMenuItem.Name = "ИзделияToolStripMenuItem";
|
||||
ИзделияToolStripMenuItem.Size = new Size(180, 22);
|
||||
ИзделияToolStripMenuItem.Text = "Изделия";
|
||||
ИзделияToolStripMenuItem.Click += ИзделияToolStripMenuItem_Click;
|
||||
//
|
||||
// магазиныToolStripMenuItem
|
||||
//
|
||||
магазиныToolStripMenuItem.Name = "магазиныToolStripMenuItem";
|
||||
магазиныToolStripMenuItem.Size = new Size(180, 22);
|
||||
магазиныToolStripMenuItem.Text = "Магазины";
|
||||
магазиныToolStripMenuItem.Click += магазиныToolStripMenuItem_Click;
|
||||
//
|
||||
// поставкиToolStripMenuItem
|
||||
//
|
||||
поставкиToolStripMenuItem.Name = "поставкиToolStripMenuItem";
|
||||
поставкиToolStripMenuItem.Size = new Size(180, 22);
|
||||
поставкиToolStripMenuItem.Text = "Поставки";
|
||||
поставкиToolStripMenuItem.Click += поставкиToolStripMenuItem_Click;
|
||||
//
|
||||
// продажиToolStripMenuItem
|
||||
//
|
||||
продажиToolStripMenuItem.Name = "продажиToolStripMenuItem";
|
||||
продажиToolStripMenuItem.Size = new Size(180, 22);
|
||||
продажиToolStripMenuItem.Text = "Продажи";
|
||||
продажиToolStripMenuItem.Click += продажиToolStripMenuItem_Click;
|
||||
//
|
||||
// dataGridView
|
||||
//
|
||||
dataGridView.Anchor = AnchorStyles.Top | AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right;
|
||||
dataGridView.BackgroundColor = SystemColors.ButtonHighlight;
|
||||
dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize;
|
||||
dataGridView.EnableHeadersVisualStyles = false;
|
||||
dataGridView.Location = new Point(1, 32);
|
||||
dataGridView.MultiSelect = false;
|
||||
dataGridView.Name = "dataGridView";
|
||||
dataGridView.RowTemplate.Height = 25;
|
||||
dataGridView.Size = new Size(755, 243);
|
||||
dataGridView.TabIndex = 1;
|
||||
//
|
||||
// ButtonCreateOrder
|
||||
//
|
||||
ButtonCreateOrder.Anchor = AnchorStyles.Top | AnchorStyles.Right;
|
||||
ButtonCreateOrder.Location = new Point(762, 44);
|
||||
ButtonCreateOrder.Name = "ButtonCreateOrder";
|
||||
ButtonCreateOrder.Size = new Size(122, 23);
|
||||
ButtonCreateOrder.TabIndex = 2;
|
||||
ButtonCreateOrder.Text = "Создать заказ";
|
||||
ButtonCreateOrder.UseVisualStyleBackColor = true;
|
||||
ButtonCreateOrder.Click += ButtonCreateOrder_Click;
|
||||
//
|
||||
// ButtonTakeOrderInWork
|
||||
//
|
||||
ButtonTakeOrderInWork.Anchor = AnchorStyles.Top | AnchorStyles.Right;
|
||||
ButtonTakeOrderInWork.Location = new Point(762, 73);
|
||||
ButtonTakeOrderInWork.Name = "ButtonTakeOrderInWork";
|
||||
ButtonTakeOrderInWork.Size = new Size(122, 42);
|
||||
ButtonTakeOrderInWork.TabIndex = 3;
|
||||
ButtonTakeOrderInWork.Text = "Отдать на выполнение";
|
||||
ButtonTakeOrderInWork.UseVisualStyleBackColor = true;
|
||||
ButtonTakeOrderInWork.Click += ButtonTakeOrderInWork_Click;
|
||||
//
|
||||
// ButtonOrderReady
|
||||
//
|
||||
ButtonOrderReady.Anchor = AnchorStyles.Top | AnchorStyles.Right;
|
||||
ButtonOrderReady.Location = new Point(762, 121);
|
||||
ButtonOrderReady.Name = "ButtonOrderReady";
|
||||
ButtonOrderReady.Size = new Size(122, 23);
|
||||
ButtonOrderReady.TabIndex = 4;
|
||||
ButtonOrderReady.Text = "Заказ готов";
|
||||
ButtonOrderReady.UseVisualStyleBackColor = true;
|
||||
ButtonOrderReady.Click += ButtonOrderReady_Click;
|
||||
//
|
||||
// ButtonIssuedOrder
|
||||
//
|
||||
ButtonIssuedOrder.Anchor = AnchorStyles.Top | AnchorStyles.Right;
|
||||
ButtonIssuedOrder.Location = new Point(762, 150);
|
||||
ButtonIssuedOrder.Name = "ButtonIssuedOrder";
|
||||
ButtonIssuedOrder.Size = new Size(122, 23);
|
||||
ButtonIssuedOrder.TabIndex = 5;
|
||||
ButtonIssuedOrder.Text = "Заказ выдан";
|
||||
ButtonIssuedOrder.UseVisualStyleBackColor = true;
|
||||
ButtonIssuedOrder.Click += ButtonIssuedOrder_Click;
|
||||
//
|
||||
// ButtonRef
|
||||
//
|
||||
ButtonRef.Anchor = AnchorStyles.Top | AnchorStyles.Right;
|
||||
ButtonRef.Location = new Point(762, 179);
|
||||
ButtonRef.Name = "ButtonRef";
|
||||
ButtonRef.Size = new Size(122, 23);
|
||||
ButtonRef.TabIndex = 6;
|
||||
ButtonRef.Text = "Обновить список";
|
||||
ButtonRef.UseVisualStyleBackColor = true;
|
||||
ButtonRef.Click += ButtonRef_Click;
|
||||
//
|
||||
// FormMain
|
||||
//
|
||||
AutoScaleDimensions = new SizeF(7F, 15F);
|
||||
AutoScaleMode = AutoScaleMode.Font;
|
||||
ClientSize = new Size(896, 280);
|
||||
Controls.Add(ButtonRef);
|
||||
Controls.Add(ButtonIssuedOrder);
|
||||
Controls.Add(ButtonOrderReady);
|
||||
Controls.Add(ButtonTakeOrderInWork);
|
||||
Controls.Add(ButtonCreateOrder);
|
||||
Controls.Add(dataGridView);
|
||||
Controls.Add(menuStrip1);
|
||||
MainMenuStrip = menuStrip1;
|
||||
Name = "FormMain";
|
||||
Text = "Сборка Набора";
|
||||
Load += FormMain_Load;
|
||||
menuStrip1.ResumeLayout(false);
|
||||
menuStrip1.PerformLayout();
|
||||
((System.ComponentModel.ISupportInitialize)dataGridView).EndInit();
|
||||
ResumeLayout(false);
|
||||
PerformLayout();
|
||||
}
|
||||
|
||||
#endregion
|
||||
private MenuStrip menuStrip1;
|
||||
private ToolStripMenuItem справочникиToolStripMenuItem;
|
||||
private DataGridView dataGridView;
|
||||
private Button ButtonCreateOrder;
|
||||
private Button ButtonTakeOrderInWork;
|
||||
private Button ButtonOrderReady;
|
||||
private Button ButtonIssuedOrder;
|
||||
private Button ButtonRef;
|
||||
private ToolStripMenuItem КомпонентыToolStripMenuItem;
|
||||
private ToolStripMenuItem ИзделияToolStripMenuItem;
|
||||
private ToolStripMenuItem магазиныToolStripMenuItem;
|
||||
private ToolStripMenuItem поставкиToolStripMenuItem;
|
||||
private ToolStripMenuItem продажиToolStripMenuItem;
|
||||
}
|
||||
}
|
181
CarpentryWorkshop/CarpentryWorkshop/FormMain.cs
Normal file
181
CarpentryWorkshop/CarpentryWorkshop/FormMain.cs
Normal file
@ -0,0 +1,181 @@
|
||||
using CarpentryWorkshop;
|
||||
using CarpentryWorkshopContracts.BindingModels;
|
||||
using CarpentryWorkshopContracts.BusinessLogicsContracts;
|
||||
using CarpentryWorkshopDataModels.Enums;
|
||||
using Microsoft.Extensions.Logging;
|
||||
|
||||
namespace CarpentryWorkshopView
|
||||
{
|
||||
public partial class FormMain : Form
|
||||
{
|
||||
private readonly ILogger _logger;
|
||||
private readonly IOrderLogic _orderLogic;
|
||||
public FormMain(ILogger<FormMain> logger, IOrderLogic orderLogic)
|
||||
{
|
||||
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["WoodId"].Visible = false;
|
||||
dataGridView.Columns["WoodName"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
|
||||
|
||||
}
|
||||
_logger.LogInformation("Загрузка изделий");
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка загрузки изделий");
|
||||
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
}
|
||||
}
|
||||
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(FormWoods));
|
||||
if (service is FormWoods 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 OrderBindingModel CreateBindingModel(int id, bool isDone = false)
|
||||
{
|
||||
return new OrderBindingModel
|
||||
{
|
||||
Id = id,
|
||||
WoodId = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["WoodId"].Value),
|
||||
Status = Enum.Parse<OrderStatus>(dataGridView.SelectedRows[0].Cells["Status"].Value.ToString()),
|
||||
Count = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Count"].Value),
|
||||
Sum = double.Parse(dataGridView.SelectedRows[0].Cells["Sum"].Value.ToString()),
|
||||
DateCreate = DateTime.Parse(dataGridView.SelectedRows[0].Cells["DateCreate"].Value.ToString()),
|
||||
};
|
||||
}
|
||||
|
||||
private void 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(CreateBindingModel(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(CreateBindingModel(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(CreateBindingModel(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();
|
||||
}
|
||||
|
||||
private void магазиныToolStripMenuItem_Click(object sender, EventArgs e)
|
||||
{
|
||||
var service = Program.ServiceProvider?.GetService(typeof(FormShops));
|
||||
if (service is FormShops form)
|
||||
{
|
||||
form.ShowDialog();
|
||||
}
|
||||
}
|
||||
|
||||
private void поставкиToolStripMenuItem_Click(object sender, EventArgs e)
|
||||
{
|
||||
var service = Program.ServiceProvider?.GetService(typeof(FormSupply));
|
||||
if (service is FormSupply form)
|
||||
{
|
||||
form.ShowDialog();
|
||||
}
|
||||
}
|
||||
private void продажиToolStripMenuItem_Click(object sender, EventArgs e)
|
||||
{
|
||||
var service = Program.ServiceProvider?.GetService(typeof(FormWoodSale));
|
||||
if (service is FormWoodSale form)
|
||||
{
|
||||
form.ShowDialog();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
123
CarpentryWorkshop/CarpentryWorkshop/FormMain.resx
Normal file
123
CarpentryWorkshop/CarpentryWorkshop/FormMain.resx
Normal file
@ -0,0 +1,123 @@
|
||||
<?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>
|
||||
<metadata name="menuStrip1.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
|
||||
<value>17, 17</value>
|
||||
</metadata>
|
||||
</root>
|
117
CarpentryWorkshop/CarpentryWorkshop/FormSell.Designer.cs
generated
Normal file
117
CarpentryWorkshop/CarpentryWorkshop/FormSell.Designer.cs
generated
Normal file
@ -0,0 +1,117 @@
|
||||
namespace CarpentryWorkshopView
|
||||
{
|
||||
partial class FormSell
|
||||
{
|
||||
/// <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()
|
||||
{
|
||||
WoodComboBox = new ComboBox();
|
||||
WoodLabel = new Label();
|
||||
CountLabel = new Label();
|
||||
CountTextBox = new TextBox();
|
||||
SaveButton = new Button();
|
||||
CancelButton = new Button();
|
||||
SuspendLayout();
|
||||
//
|
||||
// WoodComboBox
|
||||
//
|
||||
WoodComboBox.FormattingEnabled = true;
|
||||
WoodComboBox.Location = new Point(99, 12);
|
||||
WoodComboBox.Name = "WoodComboBox";
|
||||
WoodComboBox.Size = new Size(121, 23);
|
||||
WoodComboBox.TabIndex = 0;
|
||||
//
|
||||
// WoodLabel
|
||||
//
|
||||
WoodLabel.AutoSize = true;
|
||||
WoodLabel.Location = new Point(12, 20);
|
||||
WoodLabel.Name = "WoodLabel";
|
||||
WoodLabel.Size = new Size(81, 15);
|
||||
WoodLabel.TabIndex = 1;
|
||||
WoodLabel.Text = "Изделие";
|
||||
//
|
||||
// CountLabel
|
||||
//
|
||||
CountLabel.AutoSize = true;
|
||||
CountLabel.Location = new Point(21, 49);
|
||||
CountLabel.Name = "CountLabel";
|
||||
CountLabel.Size = new Size(72, 15);
|
||||
CountLabel.TabIndex = 2;
|
||||
CountLabel.Text = "Количество";
|
||||
//
|
||||
// CountTextBox
|
||||
//
|
||||
CountTextBox.Location = new Point(99, 41);
|
||||
CountTextBox.Name = "CountTextBox";
|
||||
CountTextBox.Size = new Size(121, 23);
|
||||
CountTextBox.TabIndex = 3;
|
||||
//
|
||||
// SaveButton
|
||||
//
|
||||
SaveButton.Location = new Point(64, 73);
|
||||
SaveButton.Name = "SaveButton";
|
||||
SaveButton.Size = new Size(75, 23);
|
||||
SaveButton.TabIndex = 4;
|
||||
SaveButton.Text = "Сохранить";
|
||||
SaveButton.UseVisualStyleBackColor = true;
|
||||
SaveButton.Click += SaveButton_Click;
|
||||
//
|
||||
// CancelButton
|
||||
//
|
||||
CancelButton.Location = new Point(145, 73);
|
||||
CancelButton.Name = "CancelButton";
|
||||
CancelButton.Size = new Size(75, 23);
|
||||
CancelButton.TabIndex = 5;
|
||||
CancelButton.Text = "Отмена";
|
||||
CancelButton.UseVisualStyleBackColor = true;
|
||||
//
|
||||
// FormSell
|
||||
//
|
||||
AutoScaleDimensions = new SizeF(7F, 15F);
|
||||
AutoScaleMode = AutoScaleMode.Font;
|
||||
ClientSize = new Size(224, 108);
|
||||
Controls.Add(CancelButton);
|
||||
Controls.Add(SaveButton);
|
||||
Controls.Add(CountTextBox);
|
||||
Controls.Add(CountLabel);
|
||||
Controls.Add(WoodLabel);
|
||||
Controls.Add(WoodComboBox);
|
||||
Name = "FormSell";
|
||||
Text = "Форма продажи";
|
||||
ResumeLayout(false);
|
||||
PerformLayout();
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
private ComboBox WoodComboBox;
|
||||
private Label WoodLabel;
|
||||
private Label CountLabel;
|
||||
private TextBox CountTextBox;
|
||||
private Button SaveButton;
|
||||
private Button CancelButton;
|
||||
}
|
||||
}
|
115
CarpentryWorkshop/CarpentryWorkshop/FormSell.cs
Normal file
115
CarpentryWorkshop/CarpentryWorkshop/FormSell.cs
Normal file
@ -0,0 +1,115 @@
|
||||
using CarpentryWorkshopContracts.BusinessLogicsContracts;
|
||||
using CarpentryWorkshopContracts.ViewModels;
|
||||
using CarpentryWorkshopDataModels.Models;
|
||||
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;
|
||||
|
||||
namespace CarpentryWorkshopView
|
||||
{
|
||||
public partial class FormSell : Form
|
||||
{
|
||||
private readonly List<WoodViewModel>? _woodList;
|
||||
IShopLogic _shopLogic;
|
||||
IWoodLogic _woodLogic;
|
||||
public FormSell(IWoodLogic woodLogic, IShopLogic shopLogic)
|
||||
{
|
||||
InitializeComponent();
|
||||
_shopLogic = shopLogic;
|
||||
_woodLogic = woodLogic;
|
||||
_woodList = woodLogic.ReadList(null);
|
||||
if (_woodList != null)
|
||||
{
|
||||
WoodComboBox.DisplayMember = "WoodName";
|
||||
WoodComboBox.ValueMember = "Id";
|
||||
WoodComboBox.DataSource = _woodList;
|
||||
WoodComboBox.SelectedItem = null;
|
||||
}
|
||||
}
|
||||
public int WoodId
|
||||
{
|
||||
get
|
||||
{
|
||||
return Convert.ToInt32(WoodComboBox.SelectedValue);
|
||||
}
|
||||
set
|
||||
{
|
||||
WoodComboBox.SelectedValue = value;
|
||||
}
|
||||
}
|
||||
|
||||
public IWoodModel? WoodModel
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_woodList == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
foreach (var elem in _woodList)
|
||||
{
|
||||
if (elem.Id == WoodId)
|
||||
{
|
||||
return elem;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public int Count
|
||||
{
|
||||
get { return Convert.ToInt32(CountTextBox.Text); }
|
||||
set
|
||||
{ CountTextBox.Text = value.ToString(); }
|
||||
}
|
||||
|
||||
private void SaveButton_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (string.IsNullOrEmpty(CountTextBox.Text))
|
||||
{
|
||||
MessageBox.Show("Заполните поле Количество", "Ошибка",
|
||||
MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
return;
|
||||
}
|
||||
if (WoodComboBox.SelectedValue == null)
|
||||
{
|
||||
MessageBox.Show("Выберите изделие", "Ошибка",
|
||||
MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
return;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
int count = Convert.ToInt32(CountTextBox.Text);
|
||||
|
||||
bool res = _shopLogic.MakeSell(
|
||||
_woodLogic.ReadElement(new() { Id = Convert.ToInt32(WoodComboBox.SelectedValue) }),
|
||||
count
|
||||
);
|
||||
|
||||
if (!res)
|
||||
{
|
||||
throw new Exception("Ошибка при продаже.");
|
||||
}
|
||||
|
||||
MessageBox.Show("Продажа прошла успешно");
|
||||
DialogResult = DialogResult.OK;
|
||||
Close();
|
||||
|
||||
}
|
||||
catch (Exception err)
|
||||
{
|
||||
MessageBox.Show("Ошибка продажи");
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
120
CarpentryWorkshop/CarpentryWorkshop/FormSell.resx
Normal file
120
CarpentryWorkshop/CarpentryWorkshop/FormSell.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>
|
221
CarpentryWorkshop/CarpentryWorkshop/FormShop.Designer.cs
generated
Normal file
221
CarpentryWorkshop/CarpentryWorkshop/FormShop.Designer.cs
generated
Normal file
@ -0,0 +1,221 @@
|
||||
namespace CarpentryWorkshopView
|
||||
{
|
||||
partial class FormShop
|
||||
{
|
||||
/// <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()
|
||||
{
|
||||
DateTimePicker = new DateTimePicker();
|
||||
NameTextBox = new TextBox();
|
||||
AddressTextBox = new TextBox();
|
||||
NameLabel = new Label();
|
||||
AdressLabel = new Label();
|
||||
DateLabel = new Label();
|
||||
SaveButton = new Button();
|
||||
CancelButton = new Button();
|
||||
DataGridView = new DataGridView();
|
||||
Column1 = new DataGridViewTextBoxColumn();
|
||||
Название = new DataGridViewTextBoxColumn();
|
||||
Цена = new DataGridViewTextBoxColumn();
|
||||
Количество = new DataGridViewTextBoxColumn();
|
||||
CapacityUpDown = new NumericUpDown();
|
||||
CapacityLabel = new Label();
|
||||
((System.ComponentModel.ISupportInitialize)DataGridView).BeginInit();
|
||||
((System.ComponentModel.ISupportInitialize)CapacityUpDown).BeginInit();
|
||||
SuspendLayout();
|
||||
//
|
||||
// DateTimePicker
|
||||
//
|
||||
DateTimePicker.Location = new Point(85, 70);
|
||||
DateTimePicker.Name = "DateTimePicker";
|
||||
DateTimePicker.Size = new Size(318, 23);
|
||||
DateTimePicker.TabIndex = 0;
|
||||
//
|
||||
// NameTextBox
|
||||
//
|
||||
NameTextBox.Location = new Point(85, 12);
|
||||
NameTextBox.Name = "NameTextBox";
|
||||
NameTextBox.Size = new Size(318, 23);
|
||||
NameTextBox.TabIndex = 1;
|
||||
//
|
||||
// AddressTextBox
|
||||
//
|
||||
AddressTextBox.Location = new Point(85, 41);
|
||||
AddressTextBox.Name = "AddressTextBox";
|
||||
AddressTextBox.Size = new Size(318, 23);
|
||||
AddressTextBox.TabIndex = 2;
|
||||
//
|
||||
// NameLabel
|
||||
//
|
||||
NameLabel.AutoSize = true;
|
||||
NameLabel.Location = new Point(12, 15);
|
||||
NameLabel.Name = "NameLabel";
|
||||
NameLabel.Size = new Size(59, 15);
|
||||
NameLabel.TabIndex = 3;
|
||||
NameLabel.Text = "Название";
|
||||
//
|
||||
// AdressLabel
|
||||
//
|
||||
AdressLabel.AutoSize = true;
|
||||
AdressLabel.Location = new Point(12, 44);
|
||||
AdressLabel.Name = "AdressLabel";
|
||||
AdressLabel.Size = new Size(40, 15);
|
||||
AdressLabel.TabIndex = 4;
|
||||
AdressLabel.Text = "Адрес";
|
||||
//
|
||||
// DateLabel
|
||||
//
|
||||
DateLabel.AutoSize = true;
|
||||
DateLabel.Location = new Point(12, 76);
|
||||
DateLabel.Name = "DateLabel";
|
||||
DateLabel.Size = new Size(32, 15);
|
||||
DateLabel.TabIndex = 5;
|
||||
DateLabel.Text = "Дата";
|
||||
//
|
||||
// SaveButton
|
||||
//
|
||||
SaveButton.Location = new Point(247, 284);
|
||||
SaveButton.Name = "SaveButton";
|
||||
SaveButton.Size = new Size(75, 23);
|
||||
SaveButton.TabIndex = 6;
|
||||
SaveButton.Text = "Сохранить";
|
||||
SaveButton.UseVisualStyleBackColor = true;
|
||||
SaveButton.Click += ButtonSave_Click;
|
||||
//
|
||||
// CancelButton
|
||||
//
|
||||
CancelButton.Location = new Point(328, 284);
|
||||
CancelButton.Name = "CancelButton";
|
||||
CancelButton.Size = new Size(75, 23);
|
||||
CancelButton.TabIndex = 7;
|
||||
CancelButton.Text = "Отмена";
|
||||
CancelButton.UseVisualStyleBackColor = true;
|
||||
CancelButton.Click += ButtonCancel_Click;
|
||||
//
|
||||
// DataGridView
|
||||
//
|
||||
DataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize;
|
||||
DataGridView.Columns.AddRange(new DataGridViewColumn[] { Column1, Название, Цена, Количество });
|
||||
DataGridView.Location = new Point(12, 128);
|
||||
DataGridView.Name = "DataGridView";
|
||||
DataGridView.RowHeadersWidth = 51;
|
||||
DataGridView.Size = new Size(391, 150);
|
||||
DataGridView.TabIndex = 8;
|
||||
//
|
||||
// Column1
|
||||
//
|
||||
Column1.HeaderText = "Column1";
|
||||
Column1.MinimumWidth = 6;
|
||||
Column1.Name = "Column1";
|
||||
Column1.Visible = false;
|
||||
Column1.Width = 125;
|
||||
//
|
||||
// Название
|
||||
//
|
||||
Название.HeaderText = "Название";
|
||||
Название.MinimumWidth = 6;
|
||||
Название.Name = "Название";
|
||||
Название.ReadOnly = true;
|
||||
Название.Width = 150;
|
||||
//
|
||||
// Цена
|
||||
//
|
||||
Цена.HeaderText = "Цена";
|
||||
Цена.MinimumWidth = 6;
|
||||
Цена.Name = "Цена";
|
||||
Цена.ReadOnly = true;
|
||||
Цена.Width = 125;
|
||||
//
|
||||
// Количество
|
||||
//
|
||||
Количество.HeaderText = "Количество";
|
||||
Количество.MinimumWidth = 6;
|
||||
Количество.Name = "Количество";
|
||||
Количество.ReadOnly = true;
|
||||
Количество.Width = 125;
|
||||
//
|
||||
// CapacityUpDown
|
||||
//
|
||||
CapacityUpDown.Location = new Point(98, 99);
|
||||
CapacityUpDown.Maximum = new decimal(new int[] { 10000, 0, 0, 0 });
|
||||
CapacityUpDown.Name = "CapacityUpDown";
|
||||
CapacityUpDown.Size = new Size(120, 23);
|
||||
CapacityUpDown.TabIndex = 9;
|
||||
//
|
||||
// CapacityLabel
|
||||
//
|
||||
CapacityLabel.AutoSize = true;
|
||||
CapacityLabel.Location = new Point(12, 107);
|
||||
CapacityLabel.Name = "CapacityLabel";
|
||||
CapacityLabel.Size = new Size(80, 15);
|
||||
CapacityLabel.TabIndex = 10;
|
||||
CapacityLabel.Text = "Вместимость";
|
||||
//
|
||||
// FormShop
|
||||
//
|
||||
AutoScaleDimensions = new SizeF(7F, 15F);
|
||||
AutoScaleMode = AutoScaleMode.Font;
|
||||
ClientSize = new Size(411, 315);
|
||||
Controls.Add(CapacityLabel);
|
||||
Controls.Add(CapacityUpDown);
|
||||
Controls.Add(DataGridView);
|
||||
Controls.Add(CancelButton);
|
||||
Controls.Add(SaveButton);
|
||||
Controls.Add(DateLabel);
|
||||
Controls.Add(AdressLabel);
|
||||
Controls.Add(NameLabel);
|
||||
Controls.Add(AddressTextBox);
|
||||
Controls.Add(NameTextBox);
|
||||
Controls.Add(DateTimePicker);
|
||||
Name = "FormShop";
|
||||
Text = "Форма магазина";
|
||||
Load += FormShop_Load;
|
||||
((System.ComponentModel.ISupportInitialize)DataGridView).EndInit();
|
||||
((System.ComponentModel.ISupportInitialize)CapacityUpDown).EndInit();
|
||||
ResumeLayout(false);
|
||||
PerformLayout();
|
||||
}
|
||||
|
||||
|
||||
#endregion
|
||||
|
||||
private DateTimePicker DateTimePicker;
|
||||
private TextBox NameTextBox;
|
||||
private TextBox AddressTextBox;
|
||||
private Label NameLabel;
|
||||
private Label AdressLabel;
|
||||
private Label DateLabel;
|
||||
private Button SaveButton;
|
||||
private Button CancelButton;
|
||||
private DataGridView DataGridView;
|
||||
private DataGridViewTextBoxColumn Column1;
|
||||
private DataGridViewTextBoxColumn Название;
|
||||
private DataGridViewTextBoxColumn Цена;
|
||||
private DataGridViewTextBoxColumn Количество;
|
||||
private NumericUpDown CapacityUpDown;
|
||||
private Label CapacityLabel;
|
||||
}
|
||||
}
|
133
CarpentryWorkshop/CarpentryWorkshop/FormShop.cs
Normal file
133
CarpentryWorkshop/CarpentryWorkshop/FormShop.cs
Normal file
@ -0,0 +1,133 @@
|
||||
using CarpentryWorkshopContracts.BindingModels;
|
||||
using CarpentryWorkshopContracts.BusinessLogicsContracts;
|
||||
using CarpentryWorkshopContracts.SearchModels;
|
||||
using CarpentryWorkshopDataModels.Models;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using System.Windows.Forms;
|
||||
|
||||
namespace CarpentryWorkshopView
|
||||
{
|
||||
public partial class FormShop : Form
|
||||
{
|
||||
private readonly ILogger _logger;
|
||||
|
||||
private readonly IShopLogic _logic;
|
||||
|
||||
private int? _id;
|
||||
|
||||
private Dictionary<int, (IWoodModel, int)> _shopWoods;
|
||||
|
||||
public int Id { set { _id = value; } }
|
||||
|
||||
public FormShop(ILogger<FormShop> logger, IShopLogic logic)
|
||||
{
|
||||
InitializeComponent();
|
||||
_logger = logger;
|
||||
_logic = logic;
|
||||
_shopWoods = new Dictionary<int, (IWoodModel, int)>();
|
||||
}
|
||||
|
||||
private void FormShop_Load(object sender, EventArgs e)
|
||||
{
|
||||
if (_id.HasValue)
|
||||
{
|
||||
_logger.LogInformation("Shop loading");
|
||||
try
|
||||
{
|
||||
var view = _logic.ReadElement(new ShopSearchModel { Id = _id.Value });
|
||||
if (view != null)
|
||||
{
|
||||
NameTextBox.Text = view.ShopName;
|
||||
AddressTextBox.Text = view.Address;
|
||||
DateTimePicker.Value = view.DateOpen;
|
||||
CapacityUpDown.Text = view.WoodMaxCount.ToString();
|
||||
_shopWoods = view.ShopWoods ?? new Dictionary<int, (IWoodModel, int)>();
|
||||
LoadData();
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Shop loading error");
|
||||
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void LoadData()
|
||||
{
|
||||
_logger.LogInformation("Shop ice creams loading");
|
||||
try
|
||||
{
|
||||
if (_shopWoods != null)
|
||||
{
|
||||
DataGridView.Rows.Clear();
|
||||
foreach (var wood in _shopWoods)
|
||||
{
|
||||
DataGridView.Rows.Add(new object[] { wood.Key, wood.Value.Item1.WoodName, wood.Value.Item1.Price,wood.Value.Item2 });
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Shop ice creams loading error");
|
||||
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
}
|
||||
}
|
||||
|
||||
private void ButtonSave_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (string.IsNullOrEmpty(NameTextBox.Text))
|
||||
{
|
||||
MessageBox.Show("Заполните название", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
return;
|
||||
}
|
||||
if (string.IsNullOrEmpty(AddressTextBox.Text))
|
||||
{
|
||||
MessageBox.Show("Заполните адрес", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
return;
|
||||
}
|
||||
if (string.IsNullOrEmpty(DateTimePicker.Text))
|
||||
{
|
||||
MessageBox.Show("Заполните дату", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
return;
|
||||
}
|
||||
if (string.IsNullOrEmpty(CapacityUpDown.Text))
|
||||
{
|
||||
MessageBox.Show("Заполните максимальное количество", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
return;
|
||||
}
|
||||
_logger.LogInformation("Shop saving");
|
||||
try
|
||||
{
|
||||
var model = new ShopBindingModel
|
||||
{
|
||||
Id = _id ?? 0,
|
||||
ShopName = NameTextBox.Text,
|
||||
Address = AddressTextBox.Text,
|
||||
DateOpen = DateTimePicker.Value,
|
||||
WoodMaxCount = Convert.ToInt32(CapacityUpDown.Text),
|
||||
ShopWoods = _shopWoods
|
||||
};
|
||||
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, "Shop saving error");
|
||||
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
}
|
||||
}
|
||||
|
||||
private void ButtonCancel_Click(object sender, EventArgs e)
|
||||
{
|
||||
DialogResult = DialogResult.Cancel;
|
||||
Close();
|
||||
}
|
||||
}
|
||||
}
|
120
CarpentryWorkshop/CarpentryWorkshop/FormShop.resx
Normal file
120
CarpentryWorkshop/CarpentryWorkshop/FormShop.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>
|
117
CarpentryWorkshop/CarpentryWorkshop/FormShops.Designer.cs
generated
Normal file
117
CarpentryWorkshop/CarpentryWorkshop/FormShops.Designer.cs
generated
Normal file
@ -0,0 +1,117 @@
|
||||
namespace CarpentryWorkshopView
|
||||
{
|
||||
partial class FormShops
|
||||
{
|
||||
/// <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()
|
||||
{
|
||||
DataGridView = new DataGridView();
|
||||
AddButton = new Button();
|
||||
UpdateButton = new Button();
|
||||
RefreshButton = new Button();
|
||||
DeleteButton = new Button();
|
||||
((System.ComponentModel.ISupportInitialize)DataGridView).BeginInit();
|
||||
SuspendLayout();
|
||||
//
|
||||
// DataGridView
|
||||
//
|
||||
DataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize;
|
||||
DataGridView.Location = new Point(12, 12);
|
||||
DataGridView.Name = "DataGridView";
|
||||
DataGridView.Size = new Size(393, 374);
|
||||
DataGridView.TabIndex = 0;
|
||||
//
|
||||
// AddButton
|
||||
//
|
||||
AddButton.Location = new Point(411, 12);
|
||||
AddButton.Name = "AddButton";
|
||||
AddButton.Size = new Size(114, 23);
|
||||
AddButton.TabIndex = 1;
|
||||
AddButton.Text = "Добавить";
|
||||
AddButton.UseVisualStyleBackColor = true;
|
||||
AddButton.Click += ButtonAdd_Click;
|
||||
//
|
||||
// UpdateButton
|
||||
//
|
||||
UpdateButton.Location = new Point(411, 41);
|
||||
UpdateButton.Name = "UpdateButton";
|
||||
UpdateButton.Size = new Size(114, 23);
|
||||
UpdateButton.TabIndex = 2;
|
||||
UpdateButton.Text = "Изменить";
|
||||
UpdateButton.UseVisualStyleBackColor = true;
|
||||
UpdateButton.Click += ButtonEdit_Click;
|
||||
//
|
||||
// RefreshButton
|
||||
//
|
||||
RefreshButton.Location = new Point(411, 70);
|
||||
RefreshButton.Name = "RefreshButton";
|
||||
RefreshButton.Size = new Size(114, 23);
|
||||
RefreshButton.TabIndex = 3;
|
||||
RefreshButton.Text = "Обновить";
|
||||
RefreshButton.UseVisualStyleBackColor = true;
|
||||
RefreshButton.Click += ButtonUpd_Click;
|
||||
//
|
||||
// DeleteButton
|
||||
//
|
||||
DeleteButton.Location = new Point(411, 99);
|
||||
DeleteButton.Name = "DeleteButton";
|
||||
DeleteButton.Size = new Size(114, 23);
|
||||
DeleteButton.TabIndex = 4;
|
||||
DeleteButton.Text = "Удалить";
|
||||
DeleteButton.UseVisualStyleBackColor = true;
|
||||
DeleteButton.Click += ButtonDel_Click;
|
||||
//
|
||||
// ShopsForm
|
||||
//
|
||||
AutoScaleDimensions = new SizeF(7F, 15F);
|
||||
AutoScaleMode = AutoScaleMode.Font;
|
||||
ClientSize = new Size(539, 403);
|
||||
Controls.Add(DeleteButton);
|
||||
Controls.Add(RefreshButton);
|
||||
Controls.Add(UpdateButton);
|
||||
Controls.Add(AddButton);
|
||||
Controls.Add(DataGridView);
|
||||
Name = "FormShops";
|
||||
Text = "FormShops";
|
||||
Load += FormShops_Load;
|
||||
((System.ComponentModel.ISupportInitialize)DataGridView).EndInit();
|
||||
ResumeLayout(false);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
private DataGridView DataGridView;
|
||||
private Button AddButton;
|
||||
private Button UpdateButton;
|
||||
private Button RefreshButton;
|
||||
private Button DeleteButton;
|
||||
private DataGridViewTextBoxColumn Column1;
|
||||
private DataGridViewTextBoxColumn Column2;
|
||||
private DataGridViewTextBoxColumn Column3;
|
||||
private DataGridViewTextBoxColumn Column4;
|
||||
private DataGridViewTextBoxColumn Column5;
|
||||
}
|
||||
}
|
106
CarpentryWorkshop/CarpentryWorkshop/FormShops.cs
Normal file
106
CarpentryWorkshop/CarpentryWorkshop/FormShops.cs
Normal file
@ -0,0 +1,106 @@
|
||||
using CarpentryWorkshop;
|
||||
using CarpentryWorkshopContracts.BindingModels;
|
||||
using CarpentryWorkshopContracts.BusinessLogicsContracts;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using System.Windows.Forms;
|
||||
|
||||
namespace CarpentryWorkshopView
|
||||
{
|
||||
public partial class FormShops : Form
|
||||
{
|
||||
private readonly ILogger _logger;
|
||||
|
||||
private readonly IShopLogic _logic;
|
||||
|
||||
public FormShops(ILogger<FormShops> logger, IShopLogic logic)
|
||||
{
|
||||
InitializeComponent();
|
||||
_logger = logger;
|
||||
_logic = logic;
|
||||
}
|
||||
|
||||
private void FormShops_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["ShopName"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
|
||||
DataGridView.Columns["ShopWoods"].Visible = false;
|
||||
}
|
||||
_logger.LogInformation("Shops loading");
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Shops loading error");
|
||||
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
}
|
||||
}
|
||||
|
||||
private void ButtonAdd_Click(object sender, EventArgs e)
|
||||
{
|
||||
var service = Program.ServiceProvider?.GetService(typeof(FormShop));
|
||||
if (service is FormShop form)
|
||||
{
|
||||
if (form.ShowDialog() == DialogResult.OK)
|
||||
{
|
||||
LoadData();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void ButtonEdit_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (DataGridView.SelectedRows.Count == 1)
|
||||
{
|
||||
var service = Program.ServiceProvider?.GetService(typeof(FormShop));
|
||||
if (service is FormShop 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("Deletion of shop");
|
||||
try
|
||||
{
|
||||
if (!_logic.Delete(new ShopBindingModel { Id = id }))
|
||||
{
|
||||
throw new Exception("Ошибка при удалении. Дополнительная информация в логах.");
|
||||
}
|
||||
LoadData();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Shop deletion error");
|
||||
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void ButtonUpd_Click(object sender, EventArgs e)
|
||||
{
|
||||
LoadData();
|
||||
}
|
||||
}
|
||||
}
|
120
CarpentryWorkshop/CarpentryWorkshop/FormShops.resx
Normal file
120
CarpentryWorkshop/CarpentryWorkshop/FormShops.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>
|
109
CarpentryWorkshop/CarpentryWorkshop/FormSupply.Designer.cs
generated
Normal file
109
CarpentryWorkshop/CarpentryWorkshop/FormSupply.Designer.cs
generated
Normal file
@ -0,0 +1,109 @@
|
||||
namespace CarpentryWorkshopView
|
||||
{
|
||||
partial class FormSupply
|
||||
{
|
||||
/// <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()
|
||||
{
|
||||
ShopComboBox = new ComboBox();
|
||||
WoodComboBox = new ComboBox();
|
||||
CountTextBox = new TextBox();
|
||||
SaveButton = new Button();
|
||||
CancelButton = new Button();
|
||||
SuspendLayout();
|
||||
//
|
||||
// ShopComboBox
|
||||
//
|
||||
ShopComboBox.FormattingEnabled = true;
|
||||
ShopComboBox.Location = new Point(12, 12);
|
||||
ShopComboBox.Name = "ShopComboBox";
|
||||
ShopComboBox.Size = new Size(331, 23);
|
||||
ShopComboBox.TabIndex = 0;
|
||||
ShopComboBox.DropDownStyle = ComboBoxStyle.DropDownList;
|
||||
ShopComboBox.FormattingEnabled = true;
|
||||
//
|
||||
// WoodComboBox
|
||||
//
|
||||
WoodComboBox.FormattingEnabled = true;
|
||||
WoodComboBox.Location = new Point(12, 41);
|
||||
WoodComboBox.Name = "WoodComboBox";
|
||||
WoodComboBox.Size = new Size(331, 23);
|
||||
WoodComboBox.TabIndex = 1;
|
||||
WoodComboBox.DropDownStyle = ComboBoxStyle.DropDownList;
|
||||
WoodComboBox.FormattingEnabled = true;
|
||||
//
|
||||
// CountTextBox
|
||||
//
|
||||
CountTextBox.Location = new Point(12, 70);
|
||||
CountTextBox.Name = "CountTextBox";
|
||||
CountTextBox.Size = new Size(331, 23);
|
||||
CountTextBox.TabIndex = 2;
|
||||
//
|
||||
// SaveButton
|
||||
//
|
||||
SaveButton.Location = new Point(187, 99);
|
||||
SaveButton.Name = "SaveButton";
|
||||
SaveButton.Size = new Size(75, 23);
|
||||
SaveButton.TabIndex = 3;
|
||||
SaveButton.Text = "Сохранить";
|
||||
SaveButton.UseVisualStyleBackColor = true;
|
||||
SaveButton.Click += SaveButton_Click;
|
||||
//
|
||||
// CancelButton
|
||||
//
|
||||
CancelButton.Location = new Point(268, 99);
|
||||
CancelButton.Name = "CancelButton";
|
||||
CancelButton.Size = new Size(75, 23);
|
||||
CancelButton.TabIndex = 4;
|
||||
CancelButton.Text = "Отмена";
|
||||
CancelButton.UseVisualStyleBackColor = true;
|
||||
CancelButton.Click += CancelButton_Click;
|
||||
//
|
||||
// FormSupply
|
||||
//
|
||||
AutoScaleDimensions = new SizeF(7F, 15F);
|
||||
AutoScaleMode = AutoScaleMode.Font;
|
||||
ClientSize = new Size(355, 136);
|
||||
Controls.Add(CancelButton);
|
||||
Controls.Add(SaveButton);
|
||||
Controls.Add(CountTextBox);
|
||||
Controls.Add(WoodComboBox);
|
||||
Controls.Add(ShopComboBox);
|
||||
Name = "FormSupply";
|
||||
Text = "SupplyForm";
|
||||
ResumeLayout(false);
|
||||
PerformLayout();
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
private ComboBox ShopComboBox;
|
||||
private ComboBox WoodComboBox;
|
||||
private TextBox CountTextBox;
|
||||
private Button SaveButton;
|
||||
private Button CancelButton;
|
||||
}
|
||||
}
|
150
CarpentryWorkshop/CarpentryWorkshop/FormSupply.cs
Normal file
150
CarpentryWorkshop/CarpentryWorkshop/FormSupply.cs
Normal file
@ -0,0 +1,150 @@
|
||||
using CarpentryWorkshopContracts.BindingModels;
|
||||
using CarpentryWorkshopContracts.BusinessLogicsContracts;
|
||||
using CarpentryWorkshopContracts.SearchModels;
|
||||
using CarpentryWorkshopContracts.ViewModels;
|
||||
using CarpentryWorkshopDataModels.Models;
|
||||
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;
|
||||
|
||||
namespace CarpentryWorkshopView
|
||||
{
|
||||
public partial class FormSupply : Form
|
||||
{
|
||||
private readonly List<WoodViewModel>? _woodList;
|
||||
private readonly List<ShopViewModel>? _shopsList;
|
||||
IShopLogic _shopLogic;
|
||||
IWoodLogic _woodLogic;
|
||||
public int ShopId
|
||||
{
|
||||
get
|
||||
{
|
||||
return Convert.ToInt32(ShopComboBox.SelectedValue);
|
||||
}
|
||||
set
|
||||
{
|
||||
ShopComboBox.SelectedValue = value;
|
||||
}
|
||||
}
|
||||
public int WoodId
|
||||
{
|
||||
get
|
||||
{
|
||||
return Convert.ToInt32(WoodComboBox.SelectedValue);
|
||||
}
|
||||
set
|
||||
{
|
||||
WoodComboBox.SelectedValue = value;
|
||||
}
|
||||
}
|
||||
|
||||
public IWoodModel? WoodModel
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_woodList == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
foreach (var elem in _woodList)
|
||||
{
|
||||
if (elem.Id == WoodId)
|
||||
{
|
||||
return elem;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public int Count
|
||||
{
|
||||
get { return Convert.ToInt32(CountTextBox.Text); }
|
||||
set
|
||||
{ CountTextBox.Text = value.ToString(); }
|
||||
}
|
||||
public FormSupply(IWoodLogic woodLogic, IShopLogic shopLogic)
|
||||
{
|
||||
InitializeComponent();
|
||||
_shopLogic = shopLogic;
|
||||
_woodLogic = woodLogic;
|
||||
_woodList = woodLogic.ReadList(null);
|
||||
_shopsList = shopLogic.ReadList(null);
|
||||
if (_woodList != null)
|
||||
{
|
||||
WoodComboBox.DisplayMember = "WoodName";
|
||||
WoodComboBox.ValueMember = "Id";
|
||||
WoodComboBox.DataSource = _woodList;
|
||||
WoodComboBox.SelectedItem = null;
|
||||
}
|
||||
if (_shopsList != null)
|
||||
{
|
||||
ShopComboBox.DisplayMember = "ShopName";
|
||||
ShopComboBox.ValueMember = "Id";
|
||||
ShopComboBox.DataSource = _shopsList;
|
||||
ShopComboBox.SelectedItem = null;
|
||||
}
|
||||
}
|
||||
|
||||
private void SaveButton_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (string.IsNullOrEmpty(CountTextBox.Text))
|
||||
{
|
||||
MessageBox.Show("Заполните поле Количество", "Ошибка",
|
||||
MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
return;
|
||||
}
|
||||
if (WoodComboBox.SelectedValue == null)
|
||||
{
|
||||
MessageBox.Show("Выберите изделие", "Ошибка",
|
||||
MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
return;
|
||||
}
|
||||
if (ShopComboBox.SelectedValue == null)
|
||||
{
|
||||
MessageBox.Show("Выберите магазин", "Ошибка",
|
||||
MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
return;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
int count = Convert.ToInt32(CountTextBox.Text);
|
||||
|
||||
bool res = _shopLogic.MakeSupply(
|
||||
new ShopSearchModel() { Id = Convert.ToInt32(ShopComboBox.SelectedValue) },
|
||||
_woodLogic.ReadElement(new() { Id = Convert.ToInt32(WoodComboBox.SelectedValue) }),
|
||||
count
|
||||
);
|
||||
|
||||
if (!res)
|
||||
{
|
||||
throw new Exception("Ошибка при пополнении. Дополнительная информация в логах");
|
||||
}
|
||||
|
||||
MessageBox.Show("Пополнение прошло успешно");
|
||||
DialogResult = DialogResult.OK;
|
||||
Close();
|
||||
|
||||
}
|
||||
catch (Exception err)
|
||||
{
|
||||
MessageBox.Show("Ошибка пополнения");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
private void CancelButton_Click(object sender, EventArgs e)
|
||||
{
|
||||
DialogResult = DialogResult.Cancel;
|
||||
Close();
|
||||
}
|
||||
}
|
||||
}
|
120
CarpentryWorkshop/CarpentryWorkshop/FormSupply.resx
Normal file
120
CarpentryWorkshop/CarpentryWorkshop/FormSupply.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>
|
225
CarpentryWorkshop/CarpentryWorkshop/FormWood.Designer.cs
generated
Normal file
225
CarpentryWorkshop/CarpentryWorkshop/FormWood.Designer.cs
generated
Normal file
@ -0,0 +1,225 @@
|
||||
namespace CarpentryWorkshopView
|
||||
{
|
||||
partial class FormWood
|
||||
{
|
||||
/// <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()
|
||||
{
|
||||
labelName = new Label();
|
||||
labelPrice = new Label();
|
||||
textBoxName = new TextBox();
|
||||
textBoxPrice = new TextBox();
|
||||
groupBox1 = new GroupBox();
|
||||
dataGridView = new DataGridView();
|
||||
ID = new DataGridViewTextBoxColumn();
|
||||
ComponentName = new DataGridViewTextBoxColumn();
|
||||
Count = new DataGridViewTextBoxColumn();
|
||||
ButtonRef = new Button();
|
||||
ButtonDel = new Button();
|
||||
ButtonUpd = new Button();
|
||||
ButtonAdd = new Button();
|
||||
ButtonSave = new Button();
|
||||
ButtonCancel = new Button();
|
||||
groupBox1.SuspendLayout();
|
||||
((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit();
|
||||
SuspendLayout();
|
||||
//
|
||||
// labelName
|
||||
//
|
||||
labelName.AutoSize = true;
|
||||
labelName.Location = new Point(12, 9);
|
||||
labelName.Name = "labelName";
|
||||
labelName.Size = new Size(62, 15);
|
||||
labelName.TabIndex = 0;
|
||||
labelName.Text = "Название:";
|
||||
//
|
||||
// labelPrice
|
||||
//
|
||||
labelPrice.AutoSize = true;
|
||||
labelPrice.Location = new Point(12, 41);
|
||||
labelPrice.Name = "labelPrice";
|
||||
labelPrice.Size = new Size(70, 15);
|
||||
labelPrice.TabIndex = 1;
|
||||
labelPrice.Text = "Стоимость:";
|
||||
//
|
||||
// textBoxName
|
||||
//
|
||||
textBoxName.Location = new Point(94, 6);
|
||||
textBoxName.Name = "textBoxName";
|
||||
textBoxName.Size = new Size(247, 23);
|
||||
textBoxName.TabIndex = 2;
|
||||
//
|
||||
// textBoxPrice
|
||||
//
|
||||
textBoxPrice.Location = new Point(94, 38);
|
||||
textBoxPrice.Name = "textBoxPrice";
|
||||
textBoxPrice.ReadOnly = true;
|
||||
textBoxPrice.Size = new Size(100, 23);
|
||||
textBoxPrice.TabIndex = 3;
|
||||
//
|
||||
// groupBox1
|
||||
//
|
||||
groupBox1.Controls.Add(dataGridView);
|
||||
groupBox1.Controls.Add(ButtonRef);
|
||||
groupBox1.Controls.Add(ButtonDel);
|
||||
groupBox1.Controls.Add(ButtonUpd);
|
||||
groupBox1.Controls.Add(ButtonAdd);
|
||||
groupBox1.Location = new Point(12, 67);
|
||||
groupBox1.Name = "groupBox1";
|
||||
groupBox1.Size = new Size(510, 338);
|
||||
groupBox1.TabIndex = 4;
|
||||
groupBox1.TabStop = false;
|
||||
groupBox1.Text = "Компонент";
|
||||
//
|
||||
// dataGridView
|
||||
//
|
||||
dataGridView.BackgroundColor = SystemColors.ButtonHighlight;
|
||||
dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize;
|
||||
dataGridView.Columns.AddRange(new DataGridViewColumn[] { ID, ComponentName, Count });
|
||||
dataGridView.Location = new Point(0, 21);
|
||||
dataGridView.Name = "dataGridView";
|
||||
dataGridView.RowTemplate.Height = 25;
|
||||
dataGridView.Size = new Size(394, 311);
|
||||
dataGridView.TabIndex = 5;
|
||||
//
|
||||
// ID
|
||||
//
|
||||
ID.HeaderText = "Id";
|
||||
ID.Name = "ID";
|
||||
ID.Visible = false;
|
||||
ID.Width = 250;
|
||||
//
|
||||
// ComponentName
|
||||
//
|
||||
ComponentName.HeaderText = "Компонент";
|
||||
ComponentName.Name = "ComponentName";
|
||||
ComponentName.Width = 250;
|
||||
//
|
||||
// Count
|
||||
//
|
||||
Count.HeaderText = "Количество";
|
||||
Count.Name = "Count";
|
||||
//
|
||||
// ButtonRef
|
||||
//
|
||||
ButtonRef.Location = new Point(400, 169);
|
||||
ButtonRef.Name = "ButtonRef";
|
||||
ButtonRef.Size = new Size(106, 28);
|
||||
ButtonRef.TabIndex = 4;
|
||||
ButtonRef.Text = "Обновить";
|
||||
ButtonRef.UseVisualStyleBackColor = true;
|
||||
ButtonRef.Click += ButtonRef_Click;
|
||||
//
|
||||
// ButtonDel
|
||||
//
|
||||
ButtonDel.Location = new Point(400, 135);
|
||||
ButtonDel.Name = "ButtonDel";
|
||||
ButtonDel.Size = new Size(106, 28);
|
||||
ButtonDel.TabIndex = 3;
|
||||
ButtonDel.Text = "Удалить";
|
||||
ButtonDel.UseVisualStyleBackColor = true;
|
||||
ButtonDel.Click += ButtonDel_Click;
|
||||
//
|
||||
// ButtonUpd
|
||||
//
|
||||
ButtonUpd.Location = new Point(400, 101);
|
||||
ButtonUpd.Name = "ButtonUpd";
|
||||
ButtonUpd.Size = new Size(106, 28);
|
||||
ButtonUpd.TabIndex = 2;
|
||||
ButtonUpd.Text = "Изменить";
|
||||
ButtonUpd.UseVisualStyleBackColor = true;
|
||||
ButtonUpd.Click += ButtonUpd_Click;
|
||||
//
|
||||
// ButtonAdd
|
||||
//
|
||||
ButtonAdd.Location = new Point(400, 67);
|
||||
ButtonAdd.Name = "ButtonAdd";
|
||||
ButtonAdd.Size = new Size(106, 28);
|
||||
ButtonAdd.TabIndex = 1;
|
||||
ButtonAdd.Text = "Добавить";
|
||||
ButtonAdd.UseVisualStyleBackColor = true;
|
||||
ButtonAdd.Click += ButtonAdd_Click;
|
||||
//
|
||||
// ButtonSave
|
||||
//
|
||||
ButtonSave.Location = new Point(354, 415);
|
||||
ButtonSave.Name = "ButtonSave";
|
||||
ButtonSave.Size = new Size(75, 23);
|
||||
ButtonSave.TabIndex = 5;
|
||||
ButtonSave.Text = "Сохранить";
|
||||
ButtonSave.UseVisualStyleBackColor = true;
|
||||
ButtonSave.Click += ButtonSave_Click;
|
||||
//
|
||||
// ButtonCancel
|
||||
//
|
||||
ButtonCancel.Location = new Point(435, 415);
|
||||
ButtonCancel.Name = "ButtonCancel";
|
||||
ButtonCancel.Size = new Size(75, 23);
|
||||
ButtonCancel.TabIndex = 6;
|
||||
ButtonCancel.Text = "Отмена";
|
||||
ButtonCancel.UseVisualStyleBackColor = true;
|
||||
ButtonCancel.Click += ButtonCancel_Click;
|
||||
//
|
||||
// FormWood
|
||||
//
|
||||
AutoScaleDimensions = new SizeF(7F, 15F);
|
||||
AutoScaleMode = AutoScaleMode.Font;
|
||||
ClientSize = new Size(536, 450);
|
||||
Controls.Add(ButtonCancel);
|
||||
Controls.Add(ButtonSave);
|
||||
Controls.Add(groupBox1);
|
||||
Controls.Add(textBoxPrice);
|
||||
Controls.Add(textBoxName);
|
||||
Controls.Add(labelPrice);
|
||||
Controls.Add(labelName);
|
||||
Name = "FormWood";
|
||||
Text = "Создание набора";
|
||||
Load += FormWood_Load;
|
||||
groupBox1.ResumeLayout(false);
|
||||
((System.ComponentModel.ISupportInitialize)dataGridView).EndInit();
|
||||
ResumeLayout(false);
|
||||
PerformLayout();
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
private Label labelName;
|
||||
private Label labelPrice;
|
||||
private TextBox textBoxName;
|
||||
private TextBox textBoxPrice;
|
||||
private GroupBox groupBox1;
|
||||
private DataGridView dataGridView;
|
||||
private Button ButtonRef;
|
||||
private Button ButtonDel;
|
||||
private Button ButtonUpd;
|
||||
private Button ButtonAdd;
|
||||
private Button ButtonSave;
|
||||
private Button ButtonCancel;
|
||||
private DataGridViewTextBoxColumn ID;
|
||||
private DataGridViewTextBoxColumn ComponentName;
|
||||
private DataGridViewTextBoxColumn Count;
|
||||
}
|
||||
}
|
193
CarpentryWorkshop/CarpentryWorkshop/FormWood.cs
Normal file
193
CarpentryWorkshop/CarpentryWorkshop/FormWood.cs
Normal file
@ -0,0 +1,193 @@
|
||||
using CarpentryWorkshop;
|
||||
using CarpentryWorkshopContracts.BindingModels;
|
||||
using CarpentryWorkshopContracts.BusinessLogicsContracts;
|
||||
using CarpentryWorkshopContracts.SearchModels;
|
||||
using CarpentryWorkshopDataModels.Models;
|
||||
using Microsoft.Extensions.Logging;
|
||||
|
||||
namespace CarpentryWorkshopView
|
||||
{
|
||||
public partial class FormWood : Form
|
||||
{
|
||||
private readonly ILogger _logger;
|
||||
private readonly IWoodLogic _logic;
|
||||
private int? _id;
|
||||
private Dictionary<int, (IComponentModel, int)> _woodComponents;
|
||||
public int Id { set { _id = value; } }
|
||||
public FormWood(ILogger<FormWood> logger, IWoodLogic logic)
|
||||
{
|
||||
InitializeComponent();
|
||||
_logger = logger;
|
||||
_logic = logic;
|
||||
_woodComponents = new Dictionary<int, (IComponentModel, int)>();
|
||||
}
|
||||
private void FormWood_Load(object sender, EventArgs e)
|
||||
{
|
||||
if (_id.HasValue)
|
||||
{
|
||||
_logger.LogInformation("Загрузка изделия");
|
||||
try
|
||||
{
|
||||
var view = _logic.ReadElement(new WoodSearchModel { Id = _id.Value });
|
||||
if (view != null)
|
||||
{
|
||||
textBoxName.Text = view.WoodName;
|
||||
textBoxPrice.Text = view.Price.ToString();
|
||||
_woodComponents = view.WoodComponents ?? new Dictionary<int, (IComponentModel, int)>();
|
||||
LoadData();
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка загрузки изделия");
|
||||
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
}
|
||||
}
|
||||
}
|
||||
private void LoadData()
|
||||
{
|
||||
_logger.LogInformation("Загрузка компонент изделия");
|
||||
try
|
||||
{
|
||||
if (_woodComponents != null)
|
||||
{
|
||||
dataGridView.Rows.Clear();
|
||||
foreach (var pc in _woodComponents)
|
||||
{
|
||||
dataGridView.Rows.Add(new object[] { pc.Key, pc.Value.Item1.ComponentName, pc.Value.Item2 });
|
||||
}
|
||||
textBoxPrice.Text = CalcPrice().ToString();
|
||||
}
|
||||
}
|
||||
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(FormWoodComponent));
|
||||
if (service is FormWoodComponent form)
|
||||
{
|
||||
if (form.ShowDialog() == DialogResult.OK)
|
||||
{
|
||||
if (form.ComponentModel == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
_logger.LogInformation("Добавление нового компонента: {ComponentName} - {Count}", form.ComponentModel.ComponentName, form.Count);
|
||||
if (_woodComponents.ContainsKey(form.Id))
|
||||
{
|
||||
_woodComponents[form.Id] = (form.ComponentModel, form.Count);
|
||||
}
|
||||
else
|
||||
{
|
||||
_woodComponents.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(FormWoodComponent));
|
||||
if (service is FormWoodComponent form)
|
||||
{
|
||||
int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells[0].Value);
|
||||
form.Id = id;
|
||||
form.Count = _woodComponents[id].Item2;
|
||||
if (form.ShowDialog() == DialogResult.OK)
|
||||
{
|
||||
if (form.ComponentModel == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
_logger.LogInformation("Изменение компонента: {ComponentName} - {Count}", form.ComponentModel.ComponentName, form.Count);
|
||||
_woodComponents[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); _woodComponents?.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 (_woodComponents == null || _woodComponents.Count == 0)
|
||||
{
|
||||
MessageBox.Show("Заполните компоненты", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
return;
|
||||
}
|
||||
_logger.LogInformation("Сохранение изделия");
|
||||
try
|
||||
{
|
||||
var model = new WoodBindingModel
|
||||
{
|
||||
Id = _id ?? 0,
|
||||
WoodName = textBoxName.Text,
|
||||
Price = Convert.ToDouble(textBoxPrice.Text),
|
||||
WoodComponents = _woodComponents
|
||||
};
|
||||
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 _woodComponents)
|
||||
{
|
||||
price += ((elem.Value.Item1?.Cost ?? 0) * elem.Value.Item2);
|
||||
}
|
||||
return Math.Round(price * 1.1, 2);
|
||||
}
|
||||
}
|
||||
}
|
120
CarpentryWorkshop/CarpentryWorkshop/FormWood.resx
Normal file
120
CarpentryWorkshop/CarpentryWorkshop/FormWood.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>
|
120
CarpentryWorkshop/CarpentryWorkshop/FormWoodComponent.Designer.cs
generated
Normal file
120
CarpentryWorkshop/CarpentryWorkshop/FormWoodComponent.Designer.cs
generated
Normal file
@ -0,0 +1,120 @@
|
||||
namespace CarpentryWorkshopView
|
||||
{
|
||||
partial class FormWoodComponent
|
||||
{
|
||||
/// <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()
|
||||
{
|
||||
labelComponent = new Label();
|
||||
labelCount = new Label();
|
||||
textBoxCount = new TextBox();
|
||||
comboBoxComponent = new ComboBox();
|
||||
buttonCancel = new Button();
|
||||
buttonSave = new Button();
|
||||
SuspendLayout();
|
||||
//
|
||||
// labelComponent
|
||||
//
|
||||
labelComponent.AutoSize = true;
|
||||
labelComponent.Location = new Point(12, 9);
|
||||
labelComponent.Name = "labelComponent";
|
||||
labelComponent.Size = new Size(72, 15);
|
||||
labelComponent.TabIndex = 0;
|
||||
labelComponent.Text = "Компонент:";
|
||||
//
|
||||
// labelCount
|
||||
//
|
||||
labelCount.AutoSize = true;
|
||||
labelCount.Location = new Point(12, 37);
|
||||
labelCount.Name = "labelCount";
|
||||
labelCount.Size = new Size(75, 15);
|
||||
labelCount.TabIndex = 1;
|
||||
labelCount.Text = "Количество:";
|
||||
//
|
||||
// textBoxCount
|
||||
//
|
||||
textBoxCount.Location = new Point(90, 34);
|
||||
textBoxCount.Name = "textBoxCount";
|
||||
textBoxCount.Size = new Size(235, 23);
|
||||
textBoxCount.TabIndex = 3;
|
||||
//
|
||||
// comboBoxComponent
|
||||
//
|
||||
comboBoxComponent.DropDownStyle = ComboBoxStyle.DropDownList;
|
||||
comboBoxComponent.BackColor = SystemColors.Window;
|
||||
comboBoxComponent.FormattingEnabled = true;
|
||||
comboBoxComponent.Location = new Point(90, 6);
|
||||
comboBoxComponent.Name = "comboBoxComponent";
|
||||
comboBoxComponent.Size = new Size(235, 23);
|
||||
comboBoxComponent.TabIndex = 4;
|
||||
//
|
||||
// buttonCancel
|
||||
//
|
||||
buttonCancel.Location = new Point(248, 63);
|
||||
buttonCancel.Name = "buttonCancel";
|
||||
buttonCancel.Size = new Size(75, 23);
|
||||
buttonCancel.TabIndex = 5;
|
||||
buttonCancel.Text = "Отмена";
|
||||
buttonCancel.UseVisualStyleBackColor = true;
|
||||
buttonCancel.Click += buttonCancel_Click;
|
||||
//
|
||||
// buttonSave
|
||||
//
|
||||
buttonSave.Location = new Point(167, 63);
|
||||
buttonSave.Name = "buttonSave";
|
||||
buttonSave.Size = new Size(75, 23);
|
||||
buttonSave.TabIndex = 6;
|
||||
buttonSave.Text = "Сохранить";
|
||||
buttonSave.UseVisualStyleBackColor = true;
|
||||
buttonSave.Click += buttonSave_Click;
|
||||
//
|
||||
// FormWoodComponent
|
||||
//
|
||||
AutoScaleDimensions = new SizeF(7F, 15F);
|
||||
AutoScaleMode = AutoScaleMode.Font;
|
||||
ClientSize = new Size(337, 97);
|
||||
Controls.Add(buttonSave);
|
||||
Controls.Add(buttonCancel);
|
||||
Controls.Add(comboBoxComponent);
|
||||
Controls.Add(textBoxCount);
|
||||
Controls.Add(labelCount);
|
||||
Controls.Add(labelComponent);
|
||||
Name = "FormWoodComponent";
|
||||
Text = "Компонент изделия";
|
||||
ResumeLayout(false);
|
||||
PerformLayout();
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
private Label labelComponent;
|
||||
private Label labelCount;
|
||||
private TextBox textBoxCount;
|
||||
private ComboBox comboBoxComponent;
|
||||
private Button buttonCancel;
|
||||
private Button buttonSave;
|
||||
}
|
||||
}
|
63
CarpentryWorkshop/CarpentryWorkshop/FormWoodComponent.cs
Normal file
63
CarpentryWorkshop/CarpentryWorkshop/FormWoodComponent.cs
Normal file
@ -0,0 +1,63 @@
|
||||
using CarpentryWorkshopContracts.BusinessLogicsContracts;
|
||||
using CarpentryWorkshopContracts.ViewModels;
|
||||
using CarpentryWorkshopDataModels.Models;
|
||||
|
||||
namespace CarpentryWorkshopView
|
||||
{
|
||||
public partial class FormWoodComponent : Form
|
||||
{
|
||||
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 FormWoodComponent(IComponentLogic logic)
|
||||
{
|
||||
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
CarpentryWorkshop/CarpentryWorkshop/FormWoodComponent.resx
Normal file
120
CarpentryWorkshop/CarpentryWorkshop/FormWoodComponent.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>
|
127
CarpentryWorkshop/CarpentryWorkshop/FormWoodSale.Designer.cs
generated
Normal file
127
CarpentryWorkshop/CarpentryWorkshop/FormWoodSale.Designer.cs
generated
Normal file
@ -0,0 +1,127 @@
|
||||
namespace CarpentryWorkshopView
|
||||
{
|
||||
partial class FormWoodSale
|
||||
{
|
||||
/// <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()
|
||||
{
|
||||
buttonCancel = new Button();
|
||||
buttonSale = new Button();
|
||||
textBoxCount = new TextBox();
|
||||
labelCount = new Label();
|
||||
comboBoxWood = new ComboBox();
|
||||
labelWood = new Label();
|
||||
SuspendLayout();
|
||||
//
|
||||
// buttonCancel
|
||||
//
|
||||
buttonCancel.Location = new Point(253, 83);
|
||||
buttonCancel.Margin = new Padding(4, 3, 4, 3);
|
||||
buttonCancel.Name = "buttonCancel";
|
||||
buttonCancel.Size = new Size(88, 27);
|
||||
buttonCancel.TabIndex = 17;
|
||||
buttonCancel.Text = "Отмена";
|
||||
buttonCancel.UseVisualStyleBackColor = true;
|
||||
buttonCancel.Click += ButtonCancel_Click;
|
||||
//
|
||||
// buttonSale
|
||||
//
|
||||
buttonSale.Location = new Point(159, 83);
|
||||
buttonSale.Margin = new Padding(4, 3, 4, 3);
|
||||
buttonSale.Name = "buttonSale";
|
||||
buttonSale.Size = new Size(88, 27);
|
||||
buttonSale.TabIndex = 16;
|
||||
buttonSale.Text = "Продать";
|
||||
buttonSale.UseVisualStyleBackColor = true;
|
||||
buttonSale.Click += ButtonSale_Click;
|
||||
//
|
||||
// textBoxCount
|
||||
//
|
||||
textBoxCount.Location = new Point(101, 51);
|
||||
textBoxCount.Margin = new Padding(4, 3, 4, 3);
|
||||
textBoxCount.Name = "textBoxCount";
|
||||
textBoxCount.Size = new Size(252, 23);
|
||||
textBoxCount.TabIndex = 15;
|
||||
//
|
||||
// labelCount
|
||||
//
|
||||
labelCount.AutoSize = true;
|
||||
labelCount.Location = new Point(13, 54);
|
||||
labelCount.Margin = new Padding(4, 0, 4, 0);
|
||||
labelCount.Name = "labelCount";
|
||||
labelCount.Size = new Size(78, 15);
|
||||
labelCount.TabIndex = 14;
|
||||
labelCount.Text = "Количество :";
|
||||
//
|
||||
// comboBoxWood
|
||||
//
|
||||
comboBoxWood.DropDownStyle = ComboBoxStyle.DropDownList;
|
||||
comboBoxWood.FormattingEnabled = true;
|
||||
comboBoxWood.Location = new Point(101, 15);
|
||||
comboBoxWood.Margin = new Padding(4, 3, 4, 3);
|
||||
comboBoxWood.Name = "comboBoxWood";
|
||||
comboBoxWood.Size = new Size(252, 23);
|
||||
comboBoxWood.TabIndex = 13;
|
||||
//
|
||||
// labelWood
|
||||
//
|
||||
labelWood.AutoSize = true;
|
||||
labelWood.Location = new Point(13, 19);
|
||||
labelWood.Margin = new Padding(4, 0, 4, 0);
|
||||
labelWood.Name = "labelWood";
|
||||
labelWood.Size = new Size(80, 15);
|
||||
labelWood.TabIndex = 12;
|
||||
labelWood.Text = "Изделие :";
|
||||
//
|
||||
// FormWoodSale
|
||||
//
|
||||
AutoScaleDimensions = new SizeF(7F, 15F);
|
||||
AutoScaleMode = AutoScaleMode.Font;
|
||||
ClientSize = new Size(373, 123);
|
||||
Controls.Add(buttonCancel);
|
||||
Controls.Add(buttonSale);
|
||||
Controls.Add(textBoxCount);
|
||||
Controls.Add(labelCount);
|
||||
Controls.Add(comboBoxWood);
|
||||
Controls.Add(labelWood);
|
||||
Name = "FormWoodSale";
|
||||
StartPosition = FormStartPosition.CenterScreen;
|
||||
Text = "Продажа изделий";
|
||||
Load += FormWoodSale_Load;
|
||||
ResumeLayout(false);
|
||||
PerformLayout();
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
private Button buttonCancel;
|
||||
private Button buttonSale;
|
||||
private TextBox textBoxCount;
|
||||
private Label labelCount;
|
||||
private ComboBox comboBoxWood;
|
||||
private Label labelWood;
|
||||
}
|
||||
}
|
96
CarpentryWorkshop/CarpentryWorkshop/FormWoodSale.cs
Normal file
96
CarpentryWorkshop/CarpentryWorkshop/FormWoodSale.cs
Normal file
@ -0,0 +1,96 @@
|
||||
using CarpentryWorkshopContracts.BindingModels;
|
||||
using CarpentryWorkshopContracts.BusinessLogicsContracts;
|
||||
using Microsoft.Extensions.Logging;
|
||||
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;
|
||||
|
||||
namespace CarpentryWorkshopView
|
||||
{
|
||||
public partial class FormWoodSale : Form
|
||||
{
|
||||
private readonly ILogger _logger;
|
||||
|
||||
private readonly IWoodLogic _logicWood;
|
||||
|
||||
private readonly IShopLogic _logicShop;
|
||||
|
||||
public FormWoodSale(ILogger<FormSupply> logger, IWoodLogic logicWood, IShopLogic logicShop)
|
||||
{
|
||||
InitializeComponent();
|
||||
_logger = logger;
|
||||
_logicWood = logicWood;
|
||||
_logicShop = logicShop;
|
||||
}
|
||||
|
||||
private void FormWoodSale_Load(object sender, EventArgs e)
|
||||
{
|
||||
_logger.LogInformation("Ice creams loading");
|
||||
try
|
||||
{
|
||||
var list = _logicWood.ReadList(null);
|
||||
if (list != null)
|
||||
{
|
||||
comboBoxWood.DisplayMember = "WoodName";
|
||||
comboBoxWood.ValueMember = "Id";
|
||||
comboBoxWood.DataSource = list;
|
||||
comboBoxWood.SelectedItem = null;
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ice creams loading error");
|
||||
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
}
|
||||
}
|
||||
|
||||
private void ButtonSale_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (comboBoxWood.SelectedValue == null)
|
||||
{
|
||||
MessageBox.Show("Выберите мороженое", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
return;
|
||||
}
|
||||
if (string.IsNullOrEmpty(textBoxCount.Text))
|
||||
{
|
||||
MessageBox.Show("Заполните поле Количество", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
return;
|
||||
}
|
||||
_logger.LogInformation("Ice cream sale");
|
||||
try
|
||||
{
|
||||
var operationResult = _logicShop.MakeSell(
|
||||
new WoodBindingModel
|
||||
{
|
||||
Id = Convert.ToInt32(comboBoxWood.SelectedValue)
|
||||
},
|
||||
Convert.ToInt32(textBoxCount.Text)
|
||||
);
|
||||
if (!operationResult)
|
||||
{
|
||||
throw new Exception("Ошибка при продаже.");
|
||||
}
|
||||
MessageBox.Show("Продажа прошла успешно", "Сообщение", MessageBoxButtons.OK, MessageBoxIcon.Information);
|
||||
DialogResult = DialogResult.OK;
|
||||
Close();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Wood sale error");
|
||||
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
}
|
||||
}
|
||||
|
||||
private void ButtonCancel_Click(object sender, EventArgs e)
|
||||
{
|
||||
DialogResult = DialogResult.Cancel;
|
||||
Close();
|
||||
}
|
||||
}
|
||||
}
|
120
CarpentryWorkshop/CarpentryWorkshop/FormWoodSale.resx
Normal file
120
CarpentryWorkshop/CarpentryWorkshop/FormWoodSale.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>
|
115
CarpentryWorkshop/CarpentryWorkshop/FormWoods.Designer.cs
generated
Normal file
115
CarpentryWorkshop/CarpentryWorkshop/FormWoods.Designer.cs
generated
Normal file
@ -0,0 +1,115 @@
|
||||
namespace CarpentryWorkshopView
|
||||
{
|
||||
partial class FormWoods
|
||||
{
|
||||
/// <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.dataGridView = new System.Windows.Forms.DataGridView();
|
||||
this.ButtonAdd = new System.Windows.Forms.Button();
|
||||
this.ButtonUpd = new System.Windows.Forms.Button();
|
||||
this.ButtonDel = new System.Windows.Forms.Button();
|
||||
this.ButtonRef = new System.Windows.Forms.Button();
|
||||
((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit();
|
||||
this.SuspendLayout();
|
||||
//
|
||||
// dataGridView
|
||||
//
|
||||
this.dataGridView.BackgroundColor = System.Drawing.SystemColors.ButtonHighlight;
|
||||
this.dataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
|
||||
this.dataGridView.Location = new System.Drawing.Point(0, 0);
|
||||
this.dataGridView.Name = "dataGridView";
|
||||
this.dataGridView.RowTemplate.Height = 25;
|
||||
this.dataGridView.Size = new System.Drawing.Size(509, 448);
|
||||
this.dataGridView.TabIndex = 0;
|
||||
//
|
||||
// ButtonAdd
|
||||
//
|
||||
this.ButtonAdd.Location = new System.Drawing.Point(526, 12);
|
||||
this.ButtonAdd.Name = "ButtonAdd";
|
||||
this.ButtonAdd.Size = new System.Drawing.Size(127, 23);
|
||||
this.ButtonAdd.TabIndex = 1;
|
||||
this.ButtonAdd.Text = "Добавить";
|
||||
this.ButtonAdd.UseVisualStyleBackColor = true;
|
||||
this.ButtonAdd.Click += new System.EventHandler(this.ButtonAdd_Click);
|
||||
//
|
||||
// ButtonUpd
|
||||
//
|
||||
this.ButtonUpd.Location = new System.Drawing.Point(526, 41);
|
||||
this.ButtonUpd.Name = "ButtonUpd";
|
||||
this.ButtonUpd.Size = new System.Drawing.Size(127, 23);
|
||||
this.ButtonUpd.TabIndex = 2;
|
||||
this.ButtonUpd.Text = "Изменить";
|
||||
this.ButtonUpd.UseVisualStyleBackColor = true;
|
||||
this.ButtonUpd.Click += new System.EventHandler(this.ButtonUpd_Click);
|
||||
//
|
||||
// ButtonDel
|
||||
//
|
||||
this.ButtonDel.Location = new System.Drawing.Point(526, 70);
|
||||
this.ButtonDel.Name = "ButtonDel";
|
||||
this.ButtonDel.Size = new System.Drawing.Size(127, 23);
|
||||
this.ButtonDel.TabIndex = 3;
|
||||
this.ButtonDel.Text = "Удалить";
|
||||
this.ButtonDel.UseVisualStyleBackColor = true;
|
||||
this.ButtonDel.Click += new System.EventHandler(this.ButtonDel_Click);
|
||||
//
|
||||
// ButtonRef
|
||||
//
|
||||
this.ButtonRef.Location = new System.Drawing.Point(526, 99);
|
||||
this.ButtonRef.Name = "ButtonRef";
|
||||
this.ButtonRef.Size = new System.Drawing.Size(127, 23);
|
||||
this.ButtonRef.TabIndex = 4;
|
||||
this.ButtonRef.Text = "Обновить";
|
||||
this.ButtonRef.UseVisualStyleBackColor = true;
|
||||
this.ButtonRef.Click += new System.EventHandler(this.ButtonRef_Click);
|
||||
//
|
||||
// FormWoods
|
||||
//
|
||||
this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F);
|
||||
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
||||
this.ClientSize = new System.Drawing.Size(668, 450);
|
||||
this.Controls.Add(this.ButtonRef);
|
||||
this.Controls.Add(this.ButtonDel);
|
||||
this.Controls.Add(this.ButtonUpd);
|
||||
this.Controls.Add(this.ButtonAdd);
|
||||
this.Controls.Add(this.dataGridView);
|
||||
this.Name = "FormWoods";
|
||||
this.Text = "Набор";
|
||||
this.Load += new System.EventHandler(this.FormWoods_Load);
|
||||
((System.ComponentModel.ISupportInitialize)(this.dataGridView)).EndInit();
|
||||
this.ResumeLayout(false);
|
||||
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
private System.Windows.Forms.DataGridView dataGridView;
|
||||
private System.Windows.Forms.Button ButtonAdd;
|
||||
private System.Windows.Forms.Button ButtonUpd;
|
||||
private System.Windows.Forms.Button ButtonDel;
|
||||
private System.Windows.Forms.Button ButtonRef;
|
||||
}
|
||||
}
|
98
CarpentryWorkshop/CarpentryWorkshop/FormWoods.cs
Normal file
98
CarpentryWorkshop/CarpentryWorkshop/FormWoods.cs
Normal file
@ -0,0 +1,98 @@
|
||||
using CarpentryWorkshop;
|
||||
using CarpentryWorkshopContracts.BindingModels;
|
||||
using CarpentryWorkshopContracts.BusinessLogicsContracts;
|
||||
using Microsoft.Extensions.Logging;
|
||||
|
||||
namespace CarpentryWorkshopView
|
||||
{
|
||||
public partial class FormWoods : Form
|
||||
{
|
||||
private readonly ILogger _logger;
|
||||
private readonly IWoodLogic _logic;
|
||||
public FormWoods(ILogger<FormWoods> logger, IWoodLogic logic)
|
||||
{
|
||||
InitializeComponent();
|
||||
_logger = logger;
|
||||
_logic = logic;
|
||||
}
|
||||
private void FormWoods_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["WoodName"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
|
||||
dataGridView.Columns[3].Visible = false;
|
||||
|
||||
}
|
||||
_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(FormWood));
|
||||
if (service is FormWood 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(FormWood));
|
||||
if (service is FormWood 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 WoodBindingModel { 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
CarpentryWorkshop/CarpentryWorkshop/FormWoods.resx
Normal file
120
CarpentryWorkshop/CarpentryWorkshop/FormWoods.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>
|
@ -1,7 +1,19 @@
|
||||
using CarpentryWorkshopBusinessLogic.BusinessLogics;
|
||||
using CarpentryWorkshopContracts.BusinessLogicsContracts;
|
||||
using CarpentryWorkshopContracts.StoragesContracts;
|
||||
using CarpentryWorkshopDatabaseImplement.Implements;
|
||||
using CarpentryWorkshopView;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using NLog.Extensions.Logging;
|
||||
|
||||
namespace CarpentryWorkshop
|
||||
{
|
||||
internal static class Program
|
||||
{
|
||||
private static ServiceProvider? _serviceProvider;
|
||||
public static ServiceProvider? ServiceProvider => _serviceProvider;
|
||||
|
||||
/// <summary>
|
||||
/// The main entry point for the application.
|
||||
/// </summary>
|
||||
@ -11,7 +23,40 @@ namespace CarpentryWorkshop
|
||||
// To customize application configuration such as set high DPI settings or default font,
|
||||
// see https://aka.ms/applicationconfiguration.
|
||||
ApplicationConfiguration.Initialize();
|
||||
Application.Run(new Form1());
|
||||
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<IWoodStorage, WoodStorage>();
|
||||
services.AddTransient<IShopStorage, ShopStorage>();
|
||||
|
||||
services.AddTransient<IComponentLogic, ComponentLogic>();
|
||||
services.AddTransient<IOrderLogic, OrderLogic>();
|
||||
services.AddTransient<IWoodLogic, WoodLogic>();
|
||||
services.AddTransient<IShopLogic, ShopLogic>();
|
||||
|
||||
services.AddTransient<FormMain>();
|
||||
services.AddTransient<FormComponent>();
|
||||
services.AddTransient<FormComponents>();
|
||||
services.AddTransient<FormCreateOrder>();
|
||||
services.AddTransient<FormWood>();
|
||||
services.AddTransient<FormWoodComponent>();
|
||||
services.AddTransient<FormWoods>();
|
||||
services.AddTransient<FormShop>();
|
||||
services.AddTransient<FormShops>();
|
||||
services.AddTransient<FormSupply>();
|
||||
services.AddTransient<FormWoodSale>();
|
||||
}
|
||||
}
|
||||
}
|
15
CarpentryWorkshop/CarpentryWorkshop/nlog.config
Normal file
15
CarpentryWorkshop/CarpentryWorkshop/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="log-${shortdate}.log" />
|
||||
</targets>
|
||||
|
||||
<rules>
|
||||
<logger name="*" minlevel="Debug" writeTo="tofile" />
|
||||
</rules>
|
||||
</nlog>
|
||||
</configuration>
|
@ -0,0 +1,107 @@
|
||||
using CarpentryWorkshopContracts.BindingModels;
|
||||
using CarpentryWorkshopContracts.BusinessLogicsContracts;
|
||||
using CarpentryWorkshopContracts.SearchModels;
|
||||
using CarpentryWorkshopContracts.StoragesContracts;
|
||||
using CarpentryWorkshopContracts.ViewModels;
|
||||
using Microsoft.Extensions.Logging;
|
||||
|
||||
namespace CarpentryWorkshopBusinessLogic.BusinessLogics
|
||||
{
|
||||
public class ComponentLogic : IComponentLogic
|
||||
{
|
||||
private readonly ILogger _logger;
|
||||
private readonly IComponentStorage _componentStorage;
|
||||
public ComponentLogic(ILogger<ComponentLogic> logger, IComponentStorage componentStorage)
|
||||
{
|
||||
_logger = logger;
|
||||
_componentStorage = componentStorage;
|
||||
}
|
||||
public List<ComponentViewModel>? ReadList(ComponentSearchModel? model)
|
||||
{
|
||||
_logger.LogInformation("ReadList. ComponentName:{ComponentName}. Id:{ Id}", model?.ComponentName, model?.Id);
|
||||
var list = model == null ? _componentStorage.GetFullList() : _componentStorage.GetFilteredList(model);
|
||||
if (list == null)
|
||||
{
|
||||
_logger.LogWarning("ReadList return null list");
|
||||
return null;
|
||||
}
|
||||
_logger.LogInformation("ReadList. Count:{Count}", list.Count);
|
||||
return list;
|
||||
}
|
||||
public ComponentViewModel? ReadElement(ComponentSearchModel model)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(model));
|
||||
}
|
||||
_logger.LogInformation("ReadElement. ComponentName:{ComponentName}. Id:{ Id}", model.ComponentName, model.Id);
|
||||
var element = _componentStorage.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(ComponentBindingModel model)
|
||||
{
|
||||
CheckModel(model);
|
||||
if (_componentStorage.Insert(model) == null)
|
||||
{
|
||||
_logger.LogWarning("Insert operation failed");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
public bool Update(ComponentBindingModel model)
|
||||
{
|
||||
CheckModel(model);
|
||||
if (_componentStorage.Update(model) == null)
|
||||
{
|
||||
_logger.LogWarning("Update operation failed");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
public bool Delete(ComponentBindingModel model)
|
||||
{
|
||||
CheckModel(model, false);
|
||||
_logger.LogInformation("Delete. Id:{Id}", model.Id);
|
||||
if (_componentStorage.Delete(model) == null)
|
||||
{
|
||||
_logger.LogWarning("Delete operation failed");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
private void CheckModel(ComponentBindingModel model, bool withParams = true)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(model));
|
||||
}
|
||||
if (!withParams)
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (string.IsNullOrEmpty(model.ComponentName))
|
||||
{
|
||||
throw new ArgumentNullException("Нет названия компонента", nameof(model.ComponentName));
|
||||
}
|
||||
if (model.Cost <= 0)
|
||||
{
|
||||
throw new ArgumentNullException("Цена компонента должна быть больше 0", nameof(model.Cost));
|
||||
}
|
||||
_logger.LogInformation("Component. ComponentName:{ComponentName}. Cost:{ Cost}. Id: { Id}", model.ComponentName, model.Cost, model.Id);
|
||||
var element = _componentStorage.GetElement(new ComponentSearchModel
|
||||
{
|
||||
ComponentName = model.ComponentName
|
||||
});
|
||||
if (element != null && element.Id != model.Id)
|
||||
{
|
||||
throw new InvalidOperationException("Компонент с таким названием уже есть");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,186 @@
|
||||
using CarpentryWorkshopContracts.BindingModels;
|
||||
using CarpentryWorkshopContracts.BusinessLogicsContracts;
|
||||
using CarpentryWorkshopContracts.SearchModels;
|
||||
using CarpentryWorkshopContracts.StoragesContracts;
|
||||
using CarpentryWorkshopContracts.ViewModels;
|
||||
using CarpentryWorkshopDataModels.Enums;
|
||||
using CarpentryWorkshopDataModels.Models;
|
||||
using Microsoft.Extensions.Logging;
|
||||
|
||||
namespace CarpentryWorkshopBusinessLogic.BusinessLogics
|
||||
{
|
||||
public class OrderLogic : IOrderLogic
|
||||
{
|
||||
private readonly ILogger _logger;
|
||||
private readonly IOrderStorage _orderStorage;
|
||||
private readonly IShopStorage _shopStorage;
|
||||
private readonly IShopLogic _shopLogic;
|
||||
private readonly IWoodStorage _woodStorage;
|
||||
|
||||
public OrderLogic(IOrderStorage orderStorage, IShopStorage shopStorage,
|
||||
IShopLogic shopLogic, IWoodStorage woodStorage, ILogger<OrderLogic> logger)
|
||||
{
|
||||
_logger = logger;
|
||||
_orderStorage = orderStorage;
|
||||
_shopStorage = shopStorage;
|
||||
_shopLogic = shopLogic;
|
||||
_woodStorage = woodStorage;
|
||||
}
|
||||
|
||||
public List<OrderViewModel>? ReadList(OrderSearchModel? model)
|
||||
{
|
||||
_logger.LogInformation("ReadList. Id:{ Id}", model?.Id);
|
||||
var list = model == null ? _orderStorage.GetFullList() :
|
||||
_orderStorage.GetFilteredList(model);
|
||||
if (list == null)
|
||||
{
|
||||
_logger.LogWarning("ReadList return null list");
|
||||
return null;
|
||||
}
|
||||
_logger.LogInformation("ReadList. Count:{Count}", list.Count);
|
||||
return list;
|
||||
}
|
||||
|
||||
public bool CreateOrder(OrderBindingModel model)
|
||||
{
|
||||
CheckModel(model);
|
||||
if (model.Status != OrderStatus.Неизвестен) return false;
|
||||
model.Status = OrderStatus.Принят;
|
||||
if (_orderStorage.Insert(model) == null)
|
||||
{
|
||||
_logger.LogWarning("Insert operation failed");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public bool ChangeStatus(OrderBindingModel model, OrderStatus status)
|
||||
{
|
||||
CheckModel(model);
|
||||
var element = _orderStorage.GetElement(new OrderSearchModel { Id = model.Id });
|
||||
if (element == null)
|
||||
{
|
||||
_logger.LogWarning("Read operation failed");
|
||||
return false;
|
||||
}
|
||||
if (element.Status != status - 1)
|
||||
{
|
||||
_logger.LogWarning("Status change operation failed");
|
||||
throw new InvalidOperationException("Текущий статус заказа не может быть переведен в выбранный");
|
||||
}
|
||||
if (element.Status == OrderStatus.Готов)
|
||||
{
|
||||
var wood = _woodStorage.GetElement(new WoodSearchModel() { Id = model.WoodId });
|
||||
if (wood == null)
|
||||
{
|
||||
_logger.LogWarning("Status update to " + status.ToString() + " operation failed. Document not found.");
|
||||
return false;
|
||||
}
|
||||
if (CheckSupply(wood, model.Count) == false)
|
||||
{
|
||||
_logger.LogWarning("Status update to " + status.ToString() + " operation failed. Shop supply error.");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
model.Status = status;
|
||||
if (model.Status == OrderStatus.Выдан) model.DateImplement = DateTime.Now;
|
||||
_orderStorage.Update(model);
|
||||
return true;
|
||||
}
|
||||
|
||||
public bool TakeOrderInWork(OrderBindingModel model)
|
||||
{
|
||||
return ChangeStatus(model, OrderStatus.Выполняется);
|
||||
}
|
||||
|
||||
public bool FinishOrder(OrderBindingModel model)
|
||||
{
|
||||
return ChangeStatus(model, OrderStatus.Готов);
|
||||
}
|
||||
|
||||
public bool DeliveryOrder(OrderBindingModel model)
|
||||
{
|
||||
return ChangeStatus(model, OrderStatus.Выдан);
|
||||
}
|
||||
|
||||
public bool CheckSupply(IWoodModel wood, int count)
|
||||
{
|
||||
if (count <= 0)
|
||||
{
|
||||
_logger.LogWarning("Check then supply operation error. Wood count < 0.");
|
||||
return false;
|
||||
}
|
||||
|
||||
int sumCapacity = 0;
|
||||
int sumCount = 0;
|
||||
sumCapacity = _shopStorage.GetFullList().Select(x => x.WoodMaxCount).Sum();
|
||||
sumCount = _shopStorage.GetFullList().Select(x => x.ShopWoods.Select(y => y.Value.Item2).Sum()).Sum();
|
||||
int freeSpace = sumCapacity - sumCount;
|
||||
|
||||
if (freeSpace - count < 0)
|
||||
{
|
||||
_logger.LogWarning("Check then supply operation error. There's no place for new Wood in shops.");
|
||||
return false;
|
||||
}
|
||||
|
||||
foreach (var shop in _shopStorage.GetFullList())
|
||||
{
|
||||
freeSpace = shop.WoodMaxCount;
|
||||
foreach (var doc in shop.ShopWoods)
|
||||
{
|
||||
freeSpace -= doc.Value.Item2;
|
||||
}
|
||||
if (freeSpace == 0)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
if (freeSpace - count >= 0)
|
||||
{
|
||||
if (_shopLogic.MakeSupply(new() { Id = shop.Id }, wood, count))
|
||||
count = 0;
|
||||
else
|
||||
{
|
||||
_logger.LogWarning("Supply error");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
if (freeSpace - count < 0)
|
||||
{
|
||||
if (_shopLogic.MakeSupply(new() { Id = shop.Id }, wood, freeSpace))
|
||||
count -= freeSpace;
|
||||
else
|
||||
{
|
||||
_logger.LogWarning("Supply error");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
if (count <= 0)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private void CheckModel(OrderBindingModel model, bool withParams = true)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(model));
|
||||
}
|
||||
if (!withParams)
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (model.Sum <= 0)
|
||||
{
|
||||
throw new ArgumentNullException("Цена заказа должна быть больше 0", nameof(model.Sum));
|
||||
}
|
||||
if (model.Count <= 0)
|
||||
{
|
||||
throw new ArgumentNullException("Количество элементов в заказе должно быть больше 0", nameof(model.Count));
|
||||
}
|
||||
_logger.LogInformation("Order. Sum:{ Cost}. Id: { Id}", model.Sum, model.Id);
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,170 @@
|
||||
using CarpentryWorkshopContracts.BindingModels;
|
||||
using CarpentryWorkshopContracts.BusinessLogicsContracts;
|
||||
using CarpentryWorkshopContracts.SearchModels;
|
||||
using CarpentryWorkshopContracts.StoragesContracts;
|
||||
using CarpentryWorkshopContracts.ViewModels;
|
||||
using CarpentryWorkshopDataModels.Models;
|
||||
using Microsoft.Extensions.Logging;
|
||||
|
||||
namespace CarpentryWorkshopBusinessLogic.BusinessLogics
|
||||
{
|
||||
public class ShopLogic : IShopLogic
|
||||
{
|
||||
private readonly ILogger _logger;
|
||||
private readonly IShopStorage _shopStorage;
|
||||
|
||||
public ShopLogic(ILogger<ShopLogic> logger, IShopStorage shopStorage)
|
||||
{
|
||||
_logger = logger;
|
||||
_shopStorage = shopStorage;
|
||||
}
|
||||
|
||||
public List<ShopViewModel> ReadList(ShopSearchModel model)
|
||||
{
|
||||
_logger.LogInformation("ReadList. ShopName:{Name}. Id:{ Id}", model?.ShopName, model?.Id);
|
||||
var list = model == null ? _shopStorage.GetFullList() : _shopStorage.GetFilteredList(model);
|
||||
if (list == null)
|
||||
{
|
||||
_logger.LogWarning("ReadList return null list");
|
||||
return null;
|
||||
}
|
||||
_logger.LogInformation("ReadList. Count:{Count}", list.Count);
|
||||
return list;
|
||||
|
||||
}
|
||||
|
||||
public bool MakeSupply(ShopSearchModel model, IWoodModel wood, int count)
|
||||
{
|
||||
|
||||
if (model == null)
|
||||
throw new ArgumentNullException(nameof(model));
|
||||
if (wood == null)
|
||||
throw new ArgumentNullException(nameof(wood));
|
||||
if (count <= 0)
|
||||
throw new ArgumentNullException("Количество должно быть положительным числом");
|
||||
|
||||
ShopViewModel curModel = _shopStorage.GetElement(model);
|
||||
if (curModel == null)
|
||||
throw new ArgumentNullException(nameof(curModel));
|
||||
var countItems = curModel.ShopWoods.Select(x => x.Value.Item2).Sum();
|
||||
if (curModel.WoodMaxCount - countItems >= count)
|
||||
{
|
||||
if (curModel.ShopWoods.TryGetValue(wood.Id, out var sameDocument))
|
||||
{
|
||||
curModel.ShopWoods[wood.Id] = (wood, sameDocument.Item2 + count);
|
||||
_logger.LogInformation("Same wood found by supply. Added {0} of {1} in {2} shop", count, wood.WoodName, curModel.ShopName);
|
||||
}
|
||||
else
|
||||
{
|
||||
curModel.ShopWoods[wood.Id] = (wood, count);
|
||||
_logger.LogInformation("New wood added by supply. Added {0} of {1} in {2} shop", count, wood.WoodName, curModel.ShopName);
|
||||
}
|
||||
_shopStorage.Update(new()
|
||||
{
|
||||
Id = curModel.Id,
|
||||
ShopName = curModel.ShopName,
|
||||
Address = curModel.Address,
|
||||
DateOpen = curModel.DateOpen,
|
||||
ShopWoods = curModel.ShopWoods,
|
||||
WoodMaxCount = curModel.WoodMaxCount
|
||||
});
|
||||
}
|
||||
else
|
||||
{
|
||||
_logger.LogWarning("Required shop is overflowed");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public bool MakeSell(IWoodModel wood, int count)
|
||||
{
|
||||
return _shopStorage.SellWoods(wood, count);
|
||||
}
|
||||
|
||||
public ShopViewModel ReadElement(ShopSearchModel model)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(model));
|
||||
}
|
||||
_logger.LogInformation("ReadElement. ShopName:{ShopName}.Id:{ Id}", model.ShopName, model.Id);
|
||||
var element = _shopStorage.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(ShopBindingModel model)
|
||||
{
|
||||
CheckModel(model);
|
||||
if (_shopStorage.Insert(model) == null)
|
||||
{
|
||||
_logger.LogWarning("Insert operation failed");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public bool Update(ShopBindingModel model)
|
||||
{
|
||||
CheckModel(model);
|
||||
if (_shopStorage.Update(model) == null)
|
||||
{
|
||||
_logger.LogWarning("Update operation failed");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
public bool Delete(ShopBindingModel model)
|
||||
{
|
||||
CheckModel(model, false);
|
||||
_logger.LogInformation("Delete. Id:{Id}", model.Id);
|
||||
if (_shopStorage.Delete(model) == null)
|
||||
{
|
||||
_logger.LogWarning("Delete operation failed");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
private void CheckModel(ShopBindingModel model, bool withParams = true)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(model));
|
||||
}
|
||||
if (!withParams)
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (string.IsNullOrEmpty(model.ShopName))
|
||||
{
|
||||
throw new ArgumentNullException("Нет названия магазина", nameof(model.ShopName));
|
||||
}
|
||||
if (string.IsNullOrEmpty(model.Address))
|
||||
{
|
||||
throw new ArgumentNullException("Нет адресса магазина", nameof(model.ShopName));
|
||||
}
|
||||
if (model.DateOpen == null)
|
||||
{
|
||||
throw new ArgumentNullException("Нет даты открытия магазина", nameof(model.ShopName));
|
||||
}
|
||||
_logger.LogInformation("Shop. ShopName:{ShopName}.Address:{Address}. DateOpen:{DateOpen}. Id: { Id}",
|
||||
model.ShopName, model.Address, model.DateOpen, model.Id);
|
||||
var element = _shopStorage.GetElement(new ShopSearchModel
|
||||
{
|
||||
ShopName = model.ShopName
|
||||
});
|
||||
if (element != null && element.Id != model.Id)
|
||||
{
|
||||
throw new InvalidOperationException("Магазин с таким названием уже есть");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
@ -0,0 +1,107 @@
|
||||
using CarpentryWorkshopContracts.BindingModels;
|
||||
using CarpentryWorkshopContracts.BusinessLogicsContracts;
|
||||
using CarpentryWorkshopContracts.SearchModels;
|
||||
using CarpentryWorkshopContracts.StoragesContracts;
|
||||
using CarpentryWorkshopContracts.ViewModels;
|
||||
using Microsoft.Extensions.Logging;
|
||||
|
||||
namespace CarpentryWorkshopBusinessLogic.BusinessLogics
|
||||
{
|
||||
public class WoodLogic : IWoodLogic
|
||||
{
|
||||
private readonly ILogger _logger;
|
||||
private readonly IWoodStorage _woodStorage;
|
||||
public WoodLogic(ILogger<WoodLogic> logger, IWoodStorage woodStorage)
|
||||
{
|
||||
_logger = logger;
|
||||
_woodStorage = woodStorage;
|
||||
}
|
||||
public List<WoodViewModel>? ReadList(WoodSearchModel? model)
|
||||
{
|
||||
_logger.LogInformation("ReadList. WoodName:{WoodName}. Id:{ Id}", model?.WoodName, model?.Id);
|
||||
var list = model == null ? _woodStorage.GetFullList() : _woodStorage.GetFilteredList(model);
|
||||
if (list == null)
|
||||
{
|
||||
_logger.LogWarning("ReadList return null list");
|
||||
return null;
|
||||
}
|
||||
_logger.LogInformation("ReadList. Count:{Count}", list.Count);
|
||||
return list;
|
||||
}
|
||||
public WoodViewModel? ReadElement(WoodSearchModel model)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(model));
|
||||
}
|
||||
_logger.LogInformation("ReadElement. WoodName:{WoodName}. Id:{ Id}", model.WoodName, model.Id);
|
||||
var element = _woodStorage.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(WoodBindingModel model)
|
||||
{
|
||||
CheckModel(model);
|
||||
if (_woodStorage.Insert(model) == null)
|
||||
{
|
||||
_logger.LogWarning("Insert operation failed");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
public bool Update(WoodBindingModel model)
|
||||
{
|
||||
CheckModel(model);
|
||||
if (_woodStorage.Update(model) == null)
|
||||
{
|
||||
_logger.LogWarning("Update operation failed");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
public bool Delete(WoodBindingModel model)
|
||||
{
|
||||
CheckModel(model, false);
|
||||
_logger.LogInformation("Delete. Id:{Id}", model.Id);
|
||||
if (_woodStorage.Delete(model) == null)
|
||||
{
|
||||
_logger.LogWarning("Delete operation failed");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
private void CheckModel(WoodBindingModel model, bool withParams = true)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(model));
|
||||
}
|
||||
if (!withParams)
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (string.IsNullOrEmpty(model.WoodName))
|
||||
{
|
||||
throw new ArgumentNullException("Нет названия компонента", nameof(model.WoodName));
|
||||
}
|
||||
if (model.Price <= 0)
|
||||
{
|
||||
throw new ArgumentNullException("Цена компонента должна быть больше 0", nameof(model.Price));
|
||||
}
|
||||
_logger.LogInformation("Wood. WoodName:{WoodName}. Cost:{ Cost}. Id: { Id}", model.WoodName, model.Price, model.Id);
|
||||
var element = _woodStorage.GetElement(new WoodSearchModel
|
||||
{
|
||||
WoodName = model.WoodName
|
||||
});
|
||||
if (element != null && element.Id != model.Id)
|
||||
{
|
||||
throw new InvalidOperationException("Компонент с таким названием уже есть");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,17 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net6.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.Extensions.Logging" Version="8.0.0" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\CarpentryWorkshopContracts\CarpentryWorkshopContracts.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
@ -0,0 +1,11 @@
|
||||
using CarpentryWorkshopDataModels.Models;
|
||||
|
||||
namespace CarpentryWorkshopContracts.BindingModels
|
||||
{
|
||||
public class ComponentBindingModel : IComponentModel
|
||||
{
|
||||
public int Id { get; set; }
|
||||
public string ComponentName { get; set; } = string.Empty;
|
||||
public double Cost { get; set; }
|
||||
}
|
||||
}
|
@ -0,0 +1,16 @@
|
||||
using CarpentryWorkshopDataModels.Enums;
|
||||
using CarpentryWorkshopDataModels.Models;
|
||||
|
||||
namespace CarpentryWorkshopContracts.BindingModels
|
||||
{
|
||||
public class OrderBindingModel : IOrderModel
|
||||
{
|
||||
public int Id { get; set; }
|
||||
public int WoodId { get; set; }
|
||||
public int Count { get; set; }
|
||||
public double Sum { get; set; }
|
||||
public OrderStatus Status { get; set; } = OrderStatus.Неизвестен;
|
||||
public DateTime DateCreate { get; set; } = DateTime.Now;
|
||||
public DateTime? DateImplement { get; set; }
|
||||
}
|
||||
}
|
@ -0,0 +1,14 @@
|
||||
using CarpentryWorkshopDataModels.Models;
|
||||
|
||||
namespace CarpentryWorkshopContracts.BindingModels
|
||||
{
|
||||
public class ShopBindingModel : IShopModel
|
||||
{
|
||||
public int Id { get; set; }
|
||||
public string ShopName { get; set; }
|
||||
public string Address { get; set; }
|
||||
public DateTime DateOpen { get; set; }
|
||||
public Dictionary<int, (IWoodModel, int)> ShopWoods { get; set; } = new();
|
||||
public int WoodMaxCount { get; set; }
|
||||
}
|
||||
}
|
@ -0,0 +1,11 @@
|
||||
using CarpentryWorkshopDataModels.Models;
|
||||
|
||||
namespace CarpentryWorkshopContracts.BindingModels
|
||||
{
|
||||
public class SupplyBindingModel : ISupplyModel
|
||||
{
|
||||
public int ShopId { get; set; }
|
||||
public int WoodId { get; set; }
|
||||
public int Count { get; set; }
|
||||
}
|
||||
}
|
@ -0,0 +1,16 @@
|
||||
using CarpentryWorkshopDataModels.Models;
|
||||
|
||||
namespace CarpentryWorkshopContracts.BindingModels
|
||||
{
|
||||
public class WoodBindingModel : IWoodModel
|
||||
{
|
||||
public int Id { get; set; }
|
||||
public string WoodName { get; set; } = string.Empty;
|
||||
public double Price { get; set; }
|
||||
public Dictionary<int, (IComponentModel, int)> WoodComponents
|
||||
{
|
||||
get;
|
||||
set;
|
||||
} = new();
|
||||
}
|
||||
}
|
@ -0,0 +1,15 @@
|
||||
using CarpentryWorkshopContracts.BindingModels;
|
||||
using CarpentryWorkshopContracts.SearchModels;
|
||||
using CarpentryWorkshopContracts.ViewModels;
|
||||
|
||||
namespace CarpentryWorkshopContracts.BusinessLogicsContracts
|
||||
{
|
||||
public interface IComponentLogic
|
||||
{
|
||||
List<ComponentViewModel>? ReadList(ComponentSearchModel? model);
|
||||
ComponentViewModel? ReadElement(ComponentSearchModel model);
|
||||
bool Create(ComponentBindingModel model);
|
||||
bool Update(ComponentBindingModel model);
|
||||
bool Delete(ComponentBindingModel model);
|
||||
}
|
||||
}
|
@ -0,0 +1,15 @@
|
||||
using CarpentryWorkshopContracts.BindingModels;
|
||||
using CarpentryWorkshopContracts.SearchModels;
|
||||
using CarpentryWorkshopContracts.ViewModels;
|
||||
|
||||
namespace CarpentryWorkshopContracts.BusinessLogicsContracts
|
||||
{
|
||||
public interface IOrderLogic
|
||||
{
|
||||
List<OrderViewModel>? ReadList(OrderSearchModel? model);
|
||||
bool CreateOrder(OrderBindingModel model);
|
||||
bool TakeOrderInWork(OrderBindingModel model);
|
||||
bool FinishOrder(OrderBindingModel model);
|
||||
bool DeliveryOrder(OrderBindingModel model);
|
||||
}
|
||||
}
|
@ -0,0 +1,18 @@
|
||||
using CarpentryWorkshopContracts.BindingModels;
|
||||
using CarpentryWorkshopContracts.SearchModels;
|
||||
using CarpentryWorkshopContracts.ViewModels;
|
||||
using CarpentryWorkshopDataModels.Models;
|
||||
|
||||
namespace CarpentryWorkshopContracts.BusinessLogicsContracts
|
||||
{
|
||||
public interface IShopLogic
|
||||
{
|
||||
List<ShopViewModel>? ReadList(ShopSearchModel? model);
|
||||
ShopViewModel? ReadElement(ShopSearchModel model);
|
||||
bool Create(ShopBindingModel model);
|
||||
bool Update(ShopBindingModel model);
|
||||
bool Delete(ShopBindingModel model);
|
||||
bool MakeSupply(ShopSearchModel model, IWoodModel wood, int count);
|
||||
bool MakeSell(IWoodModel wood, int count);
|
||||
}
|
||||
}
|
@ -0,0 +1,15 @@
|
||||
using CarpentryWorkshopContracts.BindingModels;
|
||||
using CarpentryWorkshopContracts.SearchModels;
|
||||
using CarpentryWorkshopContracts.ViewModels;
|
||||
|
||||
namespace CarpentryWorkshopContracts.BusinessLogicsContracts
|
||||
{
|
||||
public interface IWoodLogic
|
||||
{
|
||||
List<WoodViewModel>? ReadList(WoodSearchModel? model);
|
||||
WoodViewModel? ReadElement(WoodSearchModel model);
|
||||
bool Create(WoodBindingModel model);
|
||||
bool Update(WoodBindingModel model);
|
||||
bool Delete(WoodBindingModel model);
|
||||
}
|
||||
}
|
@ -0,0 +1,13 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net6.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\CarpentryWorkshopDataModels\CarpentryWorkshopDataModels.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
@ -0,0 +1,8 @@
|
||||
namespace CarpentryWorkshopContracts.SearchModels
|
||||
{
|
||||
public class ComponentSearchModel
|
||||
{
|
||||
public int? Id { get; set; }
|
||||
public string? ComponentName { get; set; }
|
||||
}
|
||||
}
|
@ -0,0 +1,7 @@
|
||||
namespace CarpentryWorkshopContracts.SearchModels
|
||||
{
|
||||
public class OrderSearchModel
|
||||
{
|
||||
public int? Id { get; set; }
|
||||
}
|
||||
}
|
@ -0,0 +1,8 @@
|
||||
namespace CarpentryWorkshopContracts.SearchModels
|
||||
{
|
||||
public class ShopSearchModel
|
||||
{
|
||||
public int? Id { get; set; }
|
||||
public string? ShopName { get; set; }
|
||||
}
|
||||
}
|
@ -0,0 +1,8 @@
|
||||
namespace CarpentryWorkshopContracts.SearchModels
|
||||
{
|
||||
public class SupplySearchModel
|
||||
{
|
||||
public int? WoodId { get; set; }
|
||||
public int? Count { get; set; }
|
||||
}
|
||||
}
|
@ -0,0 +1,8 @@
|
||||
namespace CarpentryWorkshopContracts.SearchModels
|
||||
{
|
||||
public class WoodSearchModel
|
||||
{
|
||||
public int? Id { get; set; }
|
||||
public string? WoodName { get; set; }
|
||||
}
|
||||
}
|
@ -0,0 +1,16 @@
|
||||
using CarpentryWorkshopContracts.BindingModels;
|
||||
using CarpentryWorkshopContracts.SearchModels;
|
||||
using CarpentryWorkshopContracts.ViewModels;
|
||||
|
||||
namespace CarpentryWorkshopContracts.StoragesContracts
|
||||
{
|
||||
public interface IComponentStorage
|
||||
{
|
||||
List<ComponentViewModel> GetFullList();
|
||||
List<ComponentViewModel> GetFilteredList(ComponentSearchModel model);
|
||||
ComponentViewModel? GetElement(ComponentSearchModel model);
|
||||
ComponentViewModel? Insert(ComponentBindingModel model);
|
||||
ComponentViewModel? Update(ComponentBindingModel model);
|
||||
ComponentViewModel? Delete(ComponentBindingModel model);
|
||||
}
|
||||
}
|
@ -0,0 +1,16 @@
|
||||
using CarpentryWorkshopContracts.BindingModels;
|
||||
using CarpentryWorkshopContracts.SearchModels;
|
||||
using CarpentryWorkshopContracts.ViewModels;
|
||||
|
||||
namespace CarpentryWorkshopContracts.StoragesContracts
|
||||
{
|
||||
public interface IOrderStorage
|
||||
{
|
||||
List<OrderViewModel> GetFullList();
|
||||
List<OrderViewModel> GetFilteredList(OrderSearchModel model);
|
||||
OrderViewModel? GetElement(OrderSearchModel model);
|
||||
OrderViewModel? Insert(OrderBindingModel model);
|
||||
OrderViewModel? Update(OrderBindingModel model);
|
||||
OrderViewModel? Delete(OrderBindingModel model);
|
||||
}
|
||||
}
|
@ -0,0 +1,23 @@
|
||||
using CarpentryWorkshopContracts.BindingModels;
|
||||
using CarpentryWorkshopContracts.SearchModels;
|
||||
using CarpentryWorkshopContracts.ViewModels;
|
||||
using CarpentryWorkshopDataModels.Models;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace CarpentryWorkshopContracts.StoragesContracts
|
||||
{
|
||||
public interface IShopStorage
|
||||
{
|
||||
List<ShopViewModel> GetFullList();
|
||||
List<ShopViewModel> GetFilteredList(ShopSearchModel model);
|
||||
ShopViewModel? GetElement(ShopSearchModel model);
|
||||
ShopViewModel? Insert(ShopBindingModel model);
|
||||
ShopViewModel? Update(ShopBindingModel model);
|
||||
ShopViewModel? Delete(ShopBindingModel model);
|
||||
public bool SellWoods(IWoodModel model, int count);
|
||||
}
|
||||
}
|
@ -0,0 +1,16 @@
|
||||
using CarpentryWorkshopContracts.BindingModels;
|
||||
using CarpentryWorkshopContracts.SearchModels;
|
||||
using CarpentryWorkshopContracts.ViewModels;
|
||||
|
||||
namespace CarpentryWorkshopContracts.StoragesContracts
|
||||
{
|
||||
public interface IWoodStorage
|
||||
{
|
||||
List<WoodViewModel> GetFullList();
|
||||
List<WoodViewModel> GetFilteredList(WoodSearchModel model);
|
||||
WoodViewModel? GetElement(WoodSearchModel model);
|
||||
WoodViewModel? Insert(WoodBindingModel model);
|
||||
WoodViewModel? Update(WoodBindingModel model);
|
||||
WoodViewModel? Delete(WoodBindingModel model);
|
||||
}
|
||||
}
|
@ -0,0 +1,14 @@
|
||||
using CarpentryWorkshopDataModels.Models;
|
||||
using System.ComponentModel;
|
||||
|
||||
namespace CarpentryWorkshopContracts.ViewModels
|
||||
{
|
||||
public class ComponentViewModel : IComponentModel
|
||||
{
|
||||
public int Id { get; set; }
|
||||
[DisplayName("Название компонента")]
|
||||
public string ComponentName { get; set; } = string.Empty;
|
||||
[DisplayName("Цена")]
|
||||
public double Cost { get; set; }
|
||||
}
|
||||
}
|
@ -0,0 +1,25 @@
|
||||
using CarpentryWorkshopDataModels.Enums;
|
||||
using CarpentryWorkshopDataModels.Models;
|
||||
using System.ComponentModel;
|
||||
|
||||
namespace CarpentryWorkshopContracts.ViewModels
|
||||
{
|
||||
public class OrderViewModel : IOrderModel
|
||||
{
|
||||
[DisplayName("Номер")]
|
||||
public int Id { get; set; }
|
||||
public int WoodId { get; set; }
|
||||
[DisplayName("Изделие")]
|
||||
public string WoodName { get; set; } = string.Empty;
|
||||
[DisplayName("Количество")]
|
||||
public int Count { get; set; }
|
||||
[DisplayName("Сумма")]
|
||||
public double Sum { get; set; }
|
||||
[DisplayName("Статус")]
|
||||
public OrderStatus Status { get; set; } = OrderStatus.Неизвестен;
|
||||
[DisplayName("Дата создания")]
|
||||
public DateTime DateCreate { get; set; } = DateTime.Now;
|
||||
[DisplayName("Дата выполнения")]
|
||||
public DateTime? DateImplement { get; set; }
|
||||
}
|
||||
}
|
@ -0,0 +1,19 @@
|
||||
using CarpentryWorkshopDataModels.Models;
|
||||
using System.ComponentModel;
|
||||
|
||||
namespace CarpentryWorkshopContracts.ViewModels
|
||||
{
|
||||
public class ShopViewModel : IShopModel
|
||||
{
|
||||
public int Id { get; set; }
|
||||
[DisplayName("Название магазина")]
|
||||
public string ShopName { get; set; }
|
||||
[DisplayName("Адрес магазина")]
|
||||
public string Address { get; set; }
|
||||
[DisplayName("Дата открытия")]
|
||||
public DateTime DateOpen { get; set; }
|
||||
public Dictionary<int, (IWoodModel, int)> ShopWoods { get; set; } = new();
|
||||
[DisplayName("Вместимость")]
|
||||
public int WoodMaxCount { get; set; }
|
||||
}
|
||||
}
|
@ -0,0 +1,19 @@
|
||||
using CarpentryWorkshopDataModels.Models;
|
||||
using System.ComponentModel;
|
||||
|
||||
namespace CarpentryWorkshopContracts.ViewModels
|
||||
{
|
||||
public class WoodViewModel : IWoodModel
|
||||
{
|
||||
public int Id { get; set; }
|
||||
[DisplayName("Название изделия")]
|
||||
public string WoodName { get; set; } = string.Empty;
|
||||
[DisplayName("Цена")]
|
||||
public double Price { get; set; }
|
||||
public Dictionary<int, (IComponentModel, int)> WoodComponents
|
||||
{
|
||||
get;
|
||||
set;
|
||||
} = new();
|
||||
}
|
||||
}
|
@ -0,0 +1,9 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net6.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
|
||||
</Project>
|
@ -0,0 +1,15 @@
|
||||
namespace CarpentryWorkshopDataModels.Enums
|
||||
{
|
||||
public enum OrderStatus
|
||||
{
|
||||
Неизвестен = -1,
|
||||
|
||||
Принят = 0,
|
||||
|
||||
Выполняется = 1,
|
||||
|
||||
Готов = 2,
|
||||
|
||||
Выдан = 3
|
||||
}
|
||||
}
|
7
CarpentryWorkshop/CarpentryWorkshopDataModels/IId.cs
Normal file
7
CarpentryWorkshop/CarpentryWorkshopDataModels/IId.cs
Normal file
@ -0,0 +1,7 @@
|
||||
namespace CarpentryWorkshopDataModels
|
||||
{
|
||||
public interface IId
|
||||
{
|
||||
int Id { get; }
|
||||
}
|
||||
}
|
@ -0,0 +1,9 @@
|
||||
namespace CarpentryWorkshopDataModels.Models
|
||||
{
|
||||
public interface IComponentModel : IId
|
||||
{
|
||||
string ComponentName { get; }
|
||||
|
||||
double Cost { get; }
|
||||
}
|
||||
}
|
@ -0,0 +1,19 @@
|
||||
using CarpentryWorkshopDataModels.Enums;
|
||||
|
||||
namespace CarpentryWorkshopDataModels.Models
|
||||
{
|
||||
public interface IOrderModel : IId
|
||||
{
|
||||
int WoodId { get; }
|
||||
|
||||
int Count { get; }
|
||||
|
||||
double Sum { get; }
|
||||
|
||||
OrderStatus Status { get; }
|
||||
|
||||
DateTime DateCreate { get; }
|
||||
|
||||
DateTime? DateImplement { get; }
|
||||
}
|
||||
}
|
@ -0,0 +1,11 @@
|
||||
namespace CarpentryWorkshopDataModels.Models
|
||||
{
|
||||
public interface IShopModel : IId
|
||||
{
|
||||
string ShopName { get; }
|
||||
string Address { get; }
|
||||
DateTime DateOpen { get; }
|
||||
Dictionary<int, (IWoodModel, int)> ShopWoods { get; }
|
||||
public int WoodMaxCount { get; }
|
||||
}
|
||||
}
|
@ -0,0 +1,9 @@
|
||||
namespace CarpentryWorkshopDataModels.Models
|
||||
{
|
||||
public interface ISupplyModel
|
||||
{
|
||||
int ShopId { get; }
|
||||
int WoodId { get; }
|
||||
int Count { get; }
|
||||
}
|
||||
}
|
@ -0,0 +1,9 @@
|
||||
namespace CarpentryWorkshopDataModels.Models
|
||||
{
|
||||
public interface IWoodModel : IId
|
||||
{
|
||||
string WoodName { get; }
|
||||
double Price { get; }
|
||||
Dictionary<int, (IComponentModel, int)> WoodComponents { get; }
|
||||
}
|
||||
}
|
@ -0,0 +1,23 @@
|
||||
using CarpentryWorkshopDatabaseImplement.Models;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace CarpentryWorkshopDatabaseImplement
|
||||
{
|
||||
public class CarpentryWorkshopDatabase : DbContext
|
||||
{
|
||||
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
|
||||
{
|
||||
if (optionsBuilder.IsConfigured == false)
|
||||
{
|
||||
optionsBuilder.UseSqlServer(@"Data Source=localhost\SQLEXPRESS;Initial Catalog=CarpentryWorkshopDatabaseFull;Integrated Security=True;MultipleActiveResultSets=True;TrustServerCertificate=True");
|
||||
}
|
||||
base.OnConfiguring(optionsBuilder);
|
||||
}
|
||||
public virtual DbSet<Component> Components { set; get; }
|
||||
public virtual DbSet<Wood> Woods { set; get; }
|
||||
public virtual DbSet<WoodComponent> WoodComponents { set; get; }
|
||||
public virtual DbSet<Order> Orders { set; get; }
|
||||
public virtual DbSet<Shop> Shops { get; set; }
|
||||
public virtual DbSet<ShopWood> ShopWoods { get; set; }
|
||||
}
|
||||
}
|
@ -0,0 +1,23 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net6.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="7.0.17" />
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="7.0.17" />
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="7.0.17">
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
</PackageReference>
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\CarpentryWorkshopContracts\CarpentryWorkshopContracts.csproj" />
|
||||
<ProjectReference Include="..\CarpentryWorkshopDataModels\CarpentryWorkshopDataModels.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
@ -0,0 +1,79 @@
|
||||
using CarpentryWorkshopContracts.BindingModels;
|
||||
using CarpentryWorkshopContracts.SearchModels;
|
||||
using CarpentryWorkshopContracts.StoragesContracts;
|
||||
using CarpentryWorkshopContracts.ViewModels;
|
||||
using CarpentryWorkshopDatabaseImplement.Models;
|
||||
|
||||
namespace CarpentryWorkshopDatabaseImplement.Implements
|
||||
{
|
||||
public class ComponentStorage : IComponentStorage
|
||||
{
|
||||
public List<ComponentViewModel> GetFullList()
|
||||
{
|
||||
using var context = new CarpentryWorkshopDatabase();
|
||||
return context.Components.Select(x => x.GetViewModel).ToList();
|
||||
}
|
||||
|
||||
public List<ComponentViewModel> GetFilteredList(ComponentSearchModel model)
|
||||
{
|
||||
if (string.IsNullOrEmpty(model.ComponentName))
|
||||
{
|
||||
return new();
|
||||
}
|
||||
using var context = new CarpentryWorkshopDatabase();
|
||||
return context.Components.Where(
|
||||
x => x.ComponentName.Contains(model.ComponentName)
|
||||
).Select(x => x.GetViewModel).ToList();
|
||||
}
|
||||
|
||||
public ComponentViewModel? GetElement(ComponentSearchModel model)
|
||||
{
|
||||
if (string.IsNullOrEmpty(model.ComponentName) && !model.Id.HasValue)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
using var context = new CarpentryWorkshopDatabase();
|
||||
return context.Components.FirstOrDefault(
|
||||
x => (!string.IsNullOrEmpty(model.ComponentName) && x.ComponentName == model.ComponentName) || (model.Id.HasValue && x.Id == model.Id))?.GetViewModel;
|
||||
}
|
||||
|
||||
public ComponentViewModel? Insert(ComponentBindingModel model)
|
||||
{
|
||||
var newComponent = Component.Create(model);
|
||||
if (newComponent == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
using var context = new CarpentryWorkshopDatabase();
|
||||
context.Components.Add(newComponent);
|
||||
context.SaveChanges();
|
||||
return newComponent.GetViewModel;
|
||||
}
|
||||
|
||||
public ComponentViewModel? Update(ComponentBindingModel model)
|
||||
{
|
||||
using var context = new CarpentryWorkshopDatabase();
|
||||
var component = context.Components.FirstOrDefault(x => x.Id == model.Id);
|
||||
if (component == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
component.Update(model);
|
||||
context.SaveChanges();
|
||||
return component.GetViewModel;
|
||||
}
|
||||
|
||||
public ComponentViewModel? Delete(ComponentBindingModel model)
|
||||
{
|
||||
using var context = new CarpentryWorkshopDatabase();
|
||||
var element = context.Components.FirstOrDefault(rec => rec.Id == model.Id);
|
||||
if (element != null)
|
||||
{
|
||||
context.Components.Remove(element);
|
||||
context.SaveChanges();
|
||||
return element.GetViewModel;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,80 @@
|
||||
using CarpentryWorkshopContracts.StoragesContracts;
|
||||
using CarpentryWorkshopContracts.BindingModels;
|
||||
using CarpentryWorkshopContracts.SearchModels;
|
||||
using CarpentryWorkshopContracts.ViewModels;
|
||||
using CarpentryWorkshopDatabaseImplement.Models;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace CarpentryWorkshopDatabaseImplement.Implements
|
||||
{
|
||||
public class OrderStorage : IOrderStorage
|
||||
{
|
||||
public OrderViewModel? GetElement(OrderSearchModel model)
|
||||
{
|
||||
if (!model.Id.HasValue)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
using var context = new CarpentryWorkshopDatabase();
|
||||
return context.Orders.Include(x => x.Wood).FirstOrDefault(x => (model.Id.HasValue && x.Id == model.Id))?.GetViewModel;
|
||||
}
|
||||
|
||||
public List<OrderViewModel> GetFilteredList(OrderSearchModel model)
|
||||
{
|
||||
if (!model.Id.HasValue)
|
||||
{
|
||||
return new();
|
||||
}
|
||||
using var context = new CarpentryWorkshopDatabase();
|
||||
return context.Orders
|
||||
.Where(x => x.Id == model.Id)
|
||||
.Include(x => x.Wood)
|
||||
.Select(x => x.GetViewModel)
|
||||
.ToList();
|
||||
}
|
||||
|
||||
public List<OrderViewModel> GetFullList()
|
||||
{
|
||||
using var context = new CarpentryWorkshopDatabase();
|
||||
return context.Orders.Include(x => x.Wood).Select(x => x.GetViewModel).ToList();
|
||||
}
|
||||
|
||||
public OrderViewModel? Insert(OrderBindingModel model)
|
||||
{
|
||||
var newOrder = Order.Create(model);
|
||||
if (newOrder == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
using var context = new CarpentryWorkshopDatabase();
|
||||
context.Orders.Add(newOrder);
|
||||
context.SaveChanges();
|
||||
return context.Orders.Include(x => x.Wood).FirstOrDefault(x => x.Id == newOrder.Id)?.GetViewModel;
|
||||
}
|
||||
|
||||
public OrderViewModel? Update(OrderBindingModel model)
|
||||
{
|
||||
using var context = new CarpentryWorkshopDatabase();
|
||||
var order = context.Orders.FirstOrDefault(x => x.Id == model.Id);
|
||||
if (order == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
order.Update(model);
|
||||
context.SaveChanges();
|
||||
return context.Orders.Include(x => x.Wood).FirstOrDefault(x => x.Id == model.Id)?.GetViewModel;
|
||||
}
|
||||
public OrderViewModel? Delete(OrderBindingModel model)
|
||||
{
|
||||
using var context = new CarpentryWorkshopDatabase();
|
||||
var element = context.Orders.FirstOrDefault(rec => rec.Id == model.Id);
|
||||
if (element != null)
|
||||
{
|
||||
context.Orders.Remove(element);
|
||||
context.SaveChanges();
|
||||
return element.GetViewModel;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,148 @@
|
||||
using CarpentryWorkshopContracts.BindingModels;
|
||||
using CarpentryWorkshopContracts.SearchModels;
|
||||
using CarpentryWorkshopContracts.StoragesContracts;
|
||||
using CarpentryWorkshopContracts.ViewModels;
|
||||
using CarpentryWorkshopDatabaseImplement.Models;
|
||||
using CarpentryWorkshopDataModels.Models;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace CarpentryWorkshopDatabaseImplement.Implements
|
||||
{
|
||||
public class ShopStorage : IShopStorage
|
||||
{
|
||||
public ShopViewModel? Delete(ShopBindingModel model)
|
||||
{
|
||||
using var context = new CarpentryWorkshopDatabase();
|
||||
var element = context.Shops.FirstOrDefault(x => x.Id == model.Id);
|
||||
if (element != null)
|
||||
{
|
||||
context.Shops.Remove(element);
|
||||
context.SaveChanges();
|
||||
return element.GetViewModel;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public ShopViewModel? GetElement(ShopSearchModel model)
|
||||
{
|
||||
if (string.IsNullOrEmpty(model.ShopName) && !model.Id.HasValue)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
using var context = new CarpentryWorkshopDatabase();
|
||||
return context.Shops
|
||||
.Include(x => x.Woods)
|
||||
.ThenInclude(x => x.Wood)
|
||||
.FirstOrDefault(x => model.Id.HasValue && x.Id == model.Id)
|
||||
?.GetViewModel;
|
||||
}
|
||||
|
||||
public List<ShopViewModel> GetFilteredList(ShopSearchModel model)
|
||||
{
|
||||
if (string.IsNullOrEmpty(model.ShopName))
|
||||
{
|
||||
return new();
|
||||
}
|
||||
using var context = new CarpentryWorkshopDatabase();
|
||||
return context.Shops
|
||||
.Include(x => x.Woods)
|
||||
.ThenInclude(x => x.Wood)
|
||||
.Select(x => x.GetViewModel)
|
||||
.Where(x => x.ShopName.Contains(model.ShopName ?? string.Empty))
|
||||
.ToList();
|
||||
}
|
||||
|
||||
public List<ShopViewModel> GetFullList()
|
||||
{
|
||||
using var context = new CarpentryWorkshopDatabase();
|
||||
return context.Shops
|
||||
.Include(x => x.Woods)
|
||||
.ThenInclude(x => x.Wood)
|
||||
.Select(x => x.GetViewModel)
|
||||
.ToList();
|
||||
}
|
||||
|
||||
public ShopViewModel? Insert(ShopBindingModel model)
|
||||
{
|
||||
using var context = new CarpentryWorkshopDatabase();
|
||||
try
|
||||
{
|
||||
var newShop = Shop.Create(context, model);
|
||||
if (newShop == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
if (context.Shops.Any(x => x.ShopName == newShop.ShopName))
|
||||
{
|
||||
throw new Exception("Не должно быть два магазина с одним названием");
|
||||
}
|
||||
context.Shops.Add(newShop);
|
||||
context.SaveChanges();
|
||||
return newShop.GetViewModel;
|
||||
}
|
||||
catch
|
||||
{
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
public ShopViewModel? Update(ShopBindingModel model)
|
||||
{
|
||||
using var context = new CarpentryWorkshopDatabase();
|
||||
var shop = context.Shops.FirstOrDefault(x => x.Id == model.Id);
|
||||
if (shop == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
try
|
||||
{
|
||||
if (context.Shops.Any(x => (x.ShopName == model.ShopName && x.Id != model.Id)))
|
||||
{
|
||||
throw new Exception("Не должно быть два магазина с одним названием");
|
||||
}
|
||||
shop.Update(model);
|
||||
shop.UpdateWoods(context, model);
|
||||
context.SaveChanges();
|
||||
return shop.GetViewModel;
|
||||
}
|
||||
catch
|
||||
{
|
||||
throw;
|
||||
}
|
||||
}
|
||||
public bool SellWoods(IWoodModel model, int count)
|
||||
{
|
||||
if (model == null)
|
||||
return false;
|
||||
using var context = new CarpentryWorkshopDatabase();
|
||||
using var transaction = context.Database.BeginTransaction();
|
||||
List<ShopWood> lst = new List<ShopWood>();
|
||||
foreach (var el in context.ShopWoods.Where(x => x.WoodId == model.Id))
|
||||
{
|
||||
int dif = count;
|
||||
if (el.Count < dif)
|
||||
dif = el.Count;
|
||||
el.Count -= dif;
|
||||
count -= dif;
|
||||
if (el.Count == 0)
|
||||
{
|
||||
lst.Add(el);
|
||||
}
|
||||
if (count == 0)
|
||||
break;
|
||||
}
|
||||
if (count > 0)
|
||||
{
|
||||
transaction.Rollback();
|
||||
return false;
|
||||
}
|
||||
foreach (var el in lst)
|
||||
{
|
||||
context.ShopWoods.Remove(el);
|
||||
}
|
||||
context.SaveChanges();
|
||||
transaction.Commit();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,124 @@
|
||||
using CarpentryWorkshopContracts.BindingModels;
|
||||
using CarpentryWorkshopContracts.SearchModels;
|
||||
using CarpentryWorkshopContracts.StoragesContracts;
|
||||
using CarpentryWorkshopContracts.ViewModels;
|
||||
using CarpentryWorkshopDatabaseImplement.Models;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace CarpentryWorkshopDatabaseImplement.Implements
|
||||
{
|
||||
public class WoodStorage : IWoodStorage
|
||||
{
|
||||
public List<WoodViewModel> GetFullList()
|
||||
{
|
||||
using var context = new CarpentryWorkshopDatabase();
|
||||
return context.Woods
|
||||
.Include(x => x.Components)
|
||||
.ThenInclude(x => x.Component)
|
||||
.ToList()
|
||||
.Select(x => x.GetViewModel)
|
||||
.ToList();
|
||||
}
|
||||
|
||||
public List<WoodViewModel> GetFilteredList(WoodSearchModel model)
|
||||
{
|
||||
if (string.IsNullOrEmpty(model.WoodName))
|
||||
{
|
||||
return new();
|
||||
}
|
||||
using var context = new CarpentryWorkshopDatabase();
|
||||
return context.Woods
|
||||
.Include(x => x.Components)
|
||||
.ThenInclude(x => x.Component)
|
||||
.Where(x => x.WoodName.Contains(model.WoodName))
|
||||
.ToList()
|
||||
.Select(x => x.GetViewModel)
|
||||
.ToList();
|
||||
}
|
||||
|
||||
public WoodViewModel? GetElement(WoodSearchModel model)
|
||||
{
|
||||
if (string.IsNullOrEmpty(model.WoodName) && !model.Id.HasValue)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
using var context = new CarpentryWorkshopDatabase();
|
||||
return context.Woods.Include(
|
||||
x => x.Components
|
||||
).ThenInclude(x => x.Component).FirstOrDefault(x => (
|
||||
!string.IsNullOrEmpty(model.WoodName) &&
|
||||
x.WoodName == model.WoodName) || (model.Id.HasValue && x.Id == model.Id)
|
||||
)?.GetViewModel;
|
||||
}
|
||||
|
||||
public WoodViewModel? Insert(WoodBindingModel model)
|
||||
{
|
||||
using var context = new CarpentryWorkshopDatabase();
|
||||
using var transaction = context.Database.BeginTransaction();
|
||||
{
|
||||
try
|
||||
{
|
||||
var newWood = Wood.Create(context, model);
|
||||
if (newWood == null)
|
||||
{
|
||||
transaction.Rollback();
|
||||
return null;
|
||||
}
|
||||
context.Woods.Add(newWood);
|
||||
|
||||
context.SaveChanges();
|
||||
context.Database.CommitTransaction();
|
||||
|
||||
return newWood.GetViewModel;
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
transaction.Rollback();
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public WoodViewModel? Update(WoodBindingModel model)
|
||||
{
|
||||
using var context = new CarpentryWorkshopDatabase();
|
||||
using var transaction = context.Database.BeginTransaction();
|
||||
{
|
||||
try
|
||||
{
|
||||
var wood = context.Woods.FirstOrDefault(x => x.Id == model.Id);
|
||||
if (wood == null)
|
||||
{
|
||||
transaction.Rollback();
|
||||
return null;
|
||||
}
|
||||
|
||||
wood.Update(model);
|
||||
wood.UpdateComponents(context, model);
|
||||
|
||||
context.SaveChanges();
|
||||
context.Database.CommitTransaction();
|
||||
|
||||
return wood.GetViewModel;
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
transaction.Rollback();
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
public WoodViewModel? Delete(WoodBindingModel model)
|
||||
{
|
||||
using var context = new CarpentryWorkshopDatabase();
|
||||
var element = context.Woods.FirstOrDefault(rec => rec.Id == model.Id);
|
||||
if (element != null)
|
||||
{
|
||||
context.Woods.Remove(element);
|
||||
context.SaveChanges();
|
||||
return element.GetViewModel;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
250
CarpentryWorkshop/CarpentryWorkshopDatabaseImplement/Migrations/20240522074840_InitialCreate.Designer.cs
generated
Normal file
250
CarpentryWorkshop/CarpentryWorkshopDatabaseImplement/Migrations/20240522074840_InitialCreate.Designer.cs
generated
Normal file
@ -0,0 +1,250 @@
|
||||
// <auto-generated />
|
||||
using System;
|
||||
using CarpentryWorkshopDatabaseImplement;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Infrastructure;
|
||||
using Microsoft.EntityFrameworkCore.Metadata;
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
|
||||
|
||||
#nullable disable
|
||||
|
||||
namespace CarpentryWorkshopDatabaseImplement.Migrations
|
||||
{
|
||||
[DbContext(typeof(CarpentryWorkshopDatabase))]
|
||||
[Migration("20240522074840_InitialCreate")]
|
||||
partial class InitialCreate
|
||||
{
|
||||
/// <inheritdoc />
|
||||
protected override void BuildTargetModel(ModelBuilder modelBuilder)
|
||||
{
|
||||
#pragma warning disable 612, 618
|
||||
modelBuilder
|
||||
.HasAnnotation("ProductVersion", "7.0.17")
|
||||
.HasAnnotation("Relational:MaxIdentifierLength", 128);
|
||||
|
||||
SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder);
|
||||
|
||||
modelBuilder.Entity("CarpentryWorkshopDatabaseImplement.Models.Component", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("int");
|
||||
|
||||
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
|
||||
|
||||
b.Property<string>("ComponentName")
|
||||
.IsRequired()
|
||||
.HasColumnType("nvarchar(max)");
|
||||
|
||||
b.Property<double>("Cost")
|
||||
.HasColumnType("float");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.ToTable("Components");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("CarpentryWorkshopDatabaseImplement.Models.Order", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("int");
|
||||
|
||||
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
|
||||
|
||||
b.Property<int>("Count")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.Property<DateTime>("DateCreate")
|
||||
.HasColumnType("datetime2");
|
||||
|
||||
b.Property<DateTime?>("DateImplement")
|
||||
.HasColumnType("datetime2");
|
||||
|
||||
b.Property<int>("Status")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.Property<double>("Sum")
|
||||
.HasColumnType("float");
|
||||
|
||||
b.Property<int>("WoodId")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("WoodId");
|
||||
|
||||
b.ToTable("Orders");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("CarpentryWorkshopDatabaseImplement.Models.Shop", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("int");
|
||||
|
||||
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
|
||||
|
||||
b.Property<string>("Address")
|
||||
.IsRequired()
|
||||
.HasColumnType("nvarchar(max)");
|
||||
|
||||
b.Property<DateTime>("DateOpen")
|
||||
.HasColumnType("datetime2");
|
||||
|
||||
b.Property<string>("ShopName")
|
||||
.IsRequired()
|
||||
.HasColumnType("nvarchar(max)");
|
||||
|
||||
b.Property<int>("WoodMaxCount")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.ToTable("Shops");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("CarpentryWorkshopDatabaseImplement.Models.ShopWood", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("int");
|
||||
|
||||
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
|
||||
|
||||
b.Property<int>("Count")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.Property<int>("ShopId")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.Property<int>("WoodId")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("ShopId");
|
||||
|
||||
b.HasIndex("WoodId");
|
||||
|
||||
b.ToTable("ShopWoods");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("CarpentryWorkshopDatabaseImplement.Models.Wood", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("int");
|
||||
|
||||
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
|
||||
|
||||
b.Property<double>("Price")
|
||||
.HasColumnType("float");
|
||||
|
||||
b.Property<string>("WoodName")
|
||||
.IsRequired()
|
||||
.HasColumnType("nvarchar(max)");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.ToTable("Woods");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("CarpentryWorkshopDatabaseImplement.Models.WoodComponent", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("int");
|
||||
|
||||
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
|
||||
|
||||
b.Property<int>("ComponentId")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.Property<int>("Count")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.Property<int>("WoodId")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("ComponentId");
|
||||
|
||||
b.HasIndex("WoodId");
|
||||
|
||||
b.ToTable("WoodComponents");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("CarpentryWorkshopDatabaseImplement.Models.Order", b =>
|
||||
{
|
||||
b.HasOne("CarpentryWorkshopDatabaseImplement.Models.Wood", "Wood")
|
||||
.WithMany("Orders")
|
||||
.HasForeignKey("WoodId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.Navigation("Wood");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("CarpentryWorkshopDatabaseImplement.Models.ShopWood", b =>
|
||||
{
|
||||
b.HasOne("CarpentryWorkshopDatabaseImplement.Models.Shop", "Shop")
|
||||
.WithMany("Woods")
|
||||
.HasForeignKey("ShopId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.HasOne("CarpentryWorkshopDatabaseImplement.Models.Wood", "Wood")
|
||||
.WithMany("ShopWoods")
|
||||
.HasForeignKey("WoodId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.Navigation("Shop");
|
||||
|
||||
b.Navigation("Wood");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("CarpentryWorkshopDatabaseImplement.Models.WoodComponent", b =>
|
||||
{
|
||||
b.HasOne("CarpentryWorkshopDatabaseImplement.Models.Component", "Component")
|
||||
.WithMany("WoodComponents")
|
||||
.HasForeignKey("ComponentId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.HasOne("CarpentryWorkshopDatabaseImplement.Models.Wood", "Wood")
|
||||
.WithMany("Components")
|
||||
.HasForeignKey("WoodId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.Navigation("Component");
|
||||
|
||||
b.Navigation("Wood");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("CarpentryWorkshopDatabaseImplement.Models.Component", b =>
|
||||
{
|
||||
b.Navigation("WoodComponents");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("CarpentryWorkshopDatabaseImplement.Models.Shop", b =>
|
||||
{
|
||||
b.Navigation("Woods");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("CarpentryWorkshopDatabaseImplement.Models.Wood", b =>
|
||||
{
|
||||
b.Navigation("Components");
|
||||
|
||||
b.Navigation("Orders");
|
||||
|
||||
b.Navigation("ShopWoods");
|
||||
});
|
||||
#pragma warning restore 612, 618
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,184 @@
|
||||
using System;
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
|
||||
#nullable disable
|
||||
|
||||
namespace CarpentryWorkshopDatabaseImplement.Migrations
|
||||
{
|
||||
/// <inheritdoc />
|
||||
public partial class InitialCreate : Migration
|
||||
{
|
||||
/// <inheritdoc />
|
||||
protected override void Up(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.CreateTable(
|
||||
name: "Components",
|
||||
columns: table => new
|
||||
{
|
||||
Id = table.Column<int>(type: "int", nullable: false)
|
||||
.Annotation("SqlServer:Identity", "1, 1"),
|
||||
ComponentName = table.Column<string>(type: "nvarchar(max)", nullable: false),
|
||||
Cost = table.Column<double>(type: "float", nullable: false)
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
table.PrimaryKey("PK_Components", x => x.Id);
|
||||
});
|
||||
|
||||
migrationBuilder.CreateTable(
|
||||
name: "Shops",
|
||||
columns: table => new
|
||||
{
|
||||
Id = table.Column<int>(type: "int", nullable: false)
|
||||
.Annotation("SqlServer:Identity", "1, 1"),
|
||||
ShopName = table.Column<string>(type: "nvarchar(max)", nullable: false),
|
||||
Address = table.Column<string>(type: "nvarchar(max)", nullable: false),
|
||||
DateOpen = table.Column<DateTime>(type: "datetime2", nullable: false),
|
||||
WoodMaxCount = table.Column<int>(type: "int", nullable: false)
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
table.PrimaryKey("PK_Shops", x => x.Id);
|
||||
});
|
||||
|
||||
migrationBuilder.CreateTable(
|
||||
name: "Woods",
|
||||
columns: table => new
|
||||
{
|
||||
Id = table.Column<int>(type: "int", nullable: false)
|
||||
.Annotation("SqlServer:Identity", "1, 1"),
|
||||
WoodName = table.Column<string>(type: "nvarchar(max)", nullable: false),
|
||||
Price = table.Column<double>(type: "float", nullable: false)
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
table.PrimaryKey("PK_Woods", x => x.Id);
|
||||
});
|
||||
|
||||
migrationBuilder.CreateTable(
|
||||
name: "Orders",
|
||||
columns: table => new
|
||||
{
|
||||
Id = table.Column<int>(type: "int", nullable: false)
|
||||
.Annotation("SqlServer:Identity", "1, 1"),
|
||||
WoodId = table.Column<int>(type: "int", nullable: false),
|
||||
Count = table.Column<int>(type: "int", nullable: false),
|
||||
Sum = table.Column<double>(type: "float", nullable: false),
|
||||
Status = table.Column<int>(type: "int", nullable: false),
|
||||
DateCreate = table.Column<DateTime>(type: "datetime2", nullable: false),
|
||||
DateImplement = table.Column<DateTime>(type: "datetime2", nullable: true)
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
table.PrimaryKey("PK_Orders", x => x.Id);
|
||||
table.ForeignKey(
|
||||
name: "FK_Orders_Woods_WoodId",
|
||||
column: x => x.WoodId,
|
||||
principalTable: "Woods",
|
||||
principalColumn: "Id",
|
||||
onDelete: ReferentialAction.Cascade);
|
||||
});
|
||||
|
||||
migrationBuilder.CreateTable(
|
||||
name: "ShopWoods",
|
||||
columns: table => new
|
||||
{
|
||||
Id = table.Column<int>(type: "int", nullable: false)
|
||||
.Annotation("SqlServer:Identity", "1, 1"),
|
||||
WoodId = table.Column<int>(type: "int", nullable: false),
|
||||
ShopId = table.Column<int>(type: "int", nullable: false),
|
||||
Count = table.Column<int>(type: "int", nullable: false)
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
table.PrimaryKey("PK_ShopWoods", x => x.Id);
|
||||
table.ForeignKey(
|
||||
name: "FK_ShopWoods_Shops_ShopId",
|
||||
column: x => x.ShopId,
|
||||
principalTable: "Shops",
|
||||
principalColumn: "Id",
|
||||
onDelete: ReferentialAction.Cascade);
|
||||
table.ForeignKey(
|
||||
name: "FK_ShopWoods_Woods_WoodId",
|
||||
column: x => x.WoodId,
|
||||
principalTable: "Woods",
|
||||
principalColumn: "Id",
|
||||
onDelete: ReferentialAction.Cascade);
|
||||
});
|
||||
|
||||
migrationBuilder.CreateTable(
|
||||
name: "WoodComponents",
|
||||
columns: table => new
|
||||
{
|
||||
Id = table.Column<int>(type: "int", nullable: false)
|
||||
.Annotation("SqlServer:Identity", "1, 1"),
|
||||
WoodId = table.Column<int>(type: "int", nullable: false),
|
||||
ComponentId = table.Column<int>(type: "int", nullable: false),
|
||||
Count = table.Column<int>(type: "int", nullable: false)
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
table.PrimaryKey("PK_WoodComponents", x => x.Id);
|
||||
table.ForeignKey(
|
||||
name: "FK_WoodComponents_Components_ComponentId",
|
||||
column: x => x.ComponentId,
|
||||
principalTable: "Components",
|
||||
principalColumn: "Id",
|
||||
onDelete: ReferentialAction.Cascade);
|
||||
table.ForeignKey(
|
||||
name: "FK_WoodComponents_Woods_WoodId",
|
||||
column: x => x.WoodId,
|
||||
principalTable: "Woods",
|
||||
principalColumn: "Id",
|
||||
onDelete: ReferentialAction.Cascade);
|
||||
});
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_Orders_WoodId",
|
||||
table: "Orders",
|
||||
column: "WoodId");
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_ShopWoods_ShopId",
|
||||
table: "ShopWoods",
|
||||
column: "ShopId");
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_ShopWoods_WoodId",
|
||||
table: "ShopWoods",
|
||||
column: "WoodId");
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_WoodComponents_ComponentId",
|
||||
table: "WoodComponents",
|
||||
column: "ComponentId");
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_WoodComponents_WoodId",
|
||||
table: "WoodComponents",
|
||||
column: "WoodId");
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override void Down(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.DropTable(
|
||||
name: "Orders");
|
||||
|
||||
migrationBuilder.DropTable(
|
||||
name: "ShopWoods");
|
||||
|
||||
migrationBuilder.DropTable(
|
||||
name: "WoodComponents");
|
||||
|
||||
migrationBuilder.DropTable(
|
||||
name: "Shops");
|
||||
|
||||
migrationBuilder.DropTable(
|
||||
name: "Components");
|
||||
|
||||
migrationBuilder.DropTable(
|
||||
name: "Woods");
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,247 @@
|
||||
// <auto-generated />
|
||||
using System;
|
||||
using CarpentryWorkshopDatabaseImplement;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Infrastructure;
|
||||
using Microsoft.EntityFrameworkCore.Metadata;
|
||||
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
|
||||
|
||||
#nullable disable
|
||||
|
||||
namespace CarpentryWorkshopDatabaseImplement.Migrations
|
||||
{
|
||||
[DbContext(typeof(CarpentryWorkshopDatabase))]
|
||||
partial class CarpentryWorkshopDatabaseModelSnapshot : ModelSnapshot
|
||||
{
|
||||
protected override void BuildModel(ModelBuilder modelBuilder)
|
||||
{
|
||||
#pragma warning disable 612, 618
|
||||
modelBuilder
|
||||
.HasAnnotation("ProductVersion", "7.0.17")
|
||||
.HasAnnotation("Relational:MaxIdentifierLength", 128);
|
||||
|
||||
SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder);
|
||||
|
||||
modelBuilder.Entity("CarpentryWorkshopDatabaseImplement.Models.Component", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("int");
|
||||
|
||||
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
|
||||
|
||||
b.Property<string>("ComponentName")
|
||||
.IsRequired()
|
||||
.HasColumnType("nvarchar(max)");
|
||||
|
||||
b.Property<double>("Cost")
|
||||
.HasColumnType("float");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.ToTable("Components");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("CarpentryWorkshopDatabaseImplement.Models.Order", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("int");
|
||||
|
||||
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
|
||||
|
||||
b.Property<int>("Count")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.Property<DateTime>("DateCreate")
|
||||
.HasColumnType("datetime2");
|
||||
|
||||
b.Property<DateTime?>("DateImplement")
|
||||
.HasColumnType("datetime2");
|
||||
|
||||
b.Property<int>("Status")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.Property<double>("Sum")
|
||||
.HasColumnType("float");
|
||||
|
||||
b.Property<int>("WoodId")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("WoodId");
|
||||
|
||||
b.ToTable("Orders");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("CarpentryWorkshopDatabaseImplement.Models.Shop", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("int");
|
||||
|
||||
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
|
||||
|
||||
b.Property<string>("Address")
|
||||
.IsRequired()
|
||||
.HasColumnType("nvarchar(max)");
|
||||
|
||||
b.Property<DateTime>("DateOpen")
|
||||
.HasColumnType("datetime2");
|
||||
|
||||
b.Property<string>("ShopName")
|
||||
.IsRequired()
|
||||
.HasColumnType("nvarchar(max)");
|
||||
|
||||
b.Property<int>("WoodMaxCount")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.ToTable("Shops");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("CarpentryWorkshopDatabaseImplement.Models.ShopWood", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("int");
|
||||
|
||||
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
|
||||
|
||||
b.Property<int>("Count")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.Property<int>("ShopId")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.Property<int>("WoodId")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("ShopId");
|
||||
|
||||
b.HasIndex("WoodId");
|
||||
|
||||
b.ToTable("ShopWoods");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("CarpentryWorkshopDatabaseImplement.Models.Wood", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("int");
|
||||
|
||||
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
|
||||
|
||||
b.Property<double>("Price")
|
||||
.HasColumnType("float");
|
||||
|
||||
b.Property<string>("WoodName")
|
||||
.IsRequired()
|
||||
.HasColumnType("nvarchar(max)");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.ToTable("Woods");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("CarpentryWorkshopDatabaseImplement.Models.WoodComponent", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("int");
|
||||
|
||||
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
|
||||
|
||||
b.Property<int>("ComponentId")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.Property<int>("Count")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.Property<int>("WoodId")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("ComponentId");
|
||||
|
||||
b.HasIndex("WoodId");
|
||||
|
||||
b.ToTable("WoodComponents");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("CarpentryWorkshopDatabaseImplement.Models.Order", b =>
|
||||
{
|
||||
b.HasOne("CarpentryWorkshopDatabaseImplement.Models.Wood", "Wood")
|
||||
.WithMany("Orders")
|
||||
.HasForeignKey("WoodId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.Navigation("Wood");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("CarpentryWorkshopDatabaseImplement.Models.ShopWood", b =>
|
||||
{
|
||||
b.HasOne("CarpentryWorkshopDatabaseImplement.Models.Shop", "Shop")
|
||||
.WithMany("Woods")
|
||||
.HasForeignKey("ShopId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.HasOne("CarpentryWorkshopDatabaseImplement.Models.Wood", "Wood")
|
||||
.WithMany("ShopWoods")
|
||||
.HasForeignKey("WoodId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.Navigation("Shop");
|
||||
|
||||
b.Navigation("Wood");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("CarpentryWorkshopDatabaseImplement.Models.WoodComponent", b =>
|
||||
{
|
||||
b.HasOne("CarpentryWorkshopDatabaseImplement.Models.Component", "Component")
|
||||
.WithMany("WoodComponents")
|
||||
.HasForeignKey("ComponentId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.HasOne("CarpentryWorkshopDatabaseImplement.Models.Wood", "Wood")
|
||||
.WithMany("Components")
|
||||
.HasForeignKey("WoodId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.Navigation("Component");
|
||||
|
||||
b.Navigation("Wood");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("CarpentryWorkshopDatabaseImplement.Models.Component", b =>
|
||||
{
|
||||
b.Navigation("WoodComponents");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("CarpentryWorkshopDatabaseImplement.Models.Shop", b =>
|
||||
{
|
||||
b.Navigation("Woods");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("CarpentryWorkshopDatabaseImplement.Models.Wood", b =>
|
||||
{
|
||||
b.Navigation("Components");
|
||||
|
||||
b.Navigation("Orders");
|
||||
|
||||
b.Navigation("ShopWoods");
|
||||
});
|
||||
#pragma warning restore 612, 618
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,64 @@
|
||||
using CarpentryWorkshopContracts.BindingModels;
|
||||
using CarpentryWorkshopContracts.ViewModels;
|
||||
using System.ComponentModel.DataAnnotations.Schema;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using CarpentryWorkshopDataModels.Models;
|
||||
|
||||
namespace CarpentryWorkshopDatabaseImplement.Models
|
||||
{
|
||||
public class Component : IComponentModel
|
||||
{
|
||||
public int Id { get; private set; }
|
||||
|
||||
[Required]
|
||||
public string ComponentName { get; private set; } = string.Empty;
|
||||
|
||||
[Required]
|
||||
public double Cost { get; set; }
|
||||
|
||||
[ForeignKey("ComponentId")]
|
||||
public virtual List<WoodComponent> WoodComponents { get; set; } = new();
|
||||
|
||||
public static Component? Create(ComponentBindingModel model)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
return new Component()
|
||||
{
|
||||
Id = model.Id,
|
||||
ComponentName = model.ComponentName,
|
||||
Cost = model.Cost
|
||||
};
|
||||
}
|
||||
|
||||
public static Component Create(ComponentViewModel model)
|
||||
{
|
||||
return new Component
|
||||
{
|
||||
Id = model.Id,
|
||||
ComponentName = model.ComponentName,
|
||||
Cost = model.Cost
|
||||
};
|
||||
}
|
||||
|
||||
public void Update(ComponentBindingModel model)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
ComponentName = model.ComponentName;
|
||||
Cost = model.Cost;
|
||||
}
|
||||
|
||||
public ComponentViewModel GetViewModel => new()
|
||||
{
|
||||
Id = Id,
|
||||
ComponentName = ComponentName,
|
||||
Cost = Cost
|
||||
};
|
||||
|
||||
}
|
||||
}
|
@ -0,0 +1,67 @@
|
||||
using CarpentryWorkshopContracts.BindingModels;
|
||||
using CarpentryWorkshopContracts.ViewModels;
|
||||
using CarpentryWorkshopDataModels.Enums;
|
||||
using CarpentryWorkshopDataModels.Models;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
|
||||
namespace CarpentryWorkshopDatabaseImplement.Models
|
||||
{
|
||||
public class Order : IOrderModel
|
||||
{
|
||||
public int Id { get; private set; }
|
||||
[Required]
|
||||
public int WoodId { get; private set; }
|
||||
|
||||
[Required]
|
||||
public int Count { get; private set; }
|
||||
[Required]
|
||||
public double Sum { get; private set; }
|
||||
[Required]
|
||||
public OrderStatus Status { get; private set; } = OrderStatus.Неизвестен;
|
||||
[Required]
|
||||
public DateTime DateCreate { get; private set; } = DateTime.Now;
|
||||
|
||||
public DateTime? DateImplement { get; private set; }
|
||||
public virtual Wood Wood { get; private set; }
|
||||
|
||||
public static Order? Create(OrderBindingModel? model)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
return new Order
|
||||
{
|
||||
WoodId = model.WoodId,
|
||||
Count = model.Count,
|
||||
Sum = model.Sum,
|
||||
Status = model.Status,
|
||||
DateCreate = model.DateCreate,
|
||||
DateImplement = model.DateImplement,
|
||||
Id = model.Id,
|
||||
};
|
||||
}
|
||||
|
||||
public void Update(OrderBindingModel? model)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
Status = model.Status;
|
||||
DateImplement = model.DateImplement;
|
||||
}
|
||||
|
||||
public OrderViewModel GetViewModel => new()
|
||||
{
|
||||
WoodId = WoodId,
|
||||
Count = Count,
|
||||
Sum = Sum,
|
||||
DateCreate = DateCreate,
|
||||
DateImplement = DateImplement,
|
||||
Id = Id,
|
||||
Status = Status,
|
||||
WoodName = Wood.WoodName
|
||||
};
|
||||
}
|
||||
}
|
@ -0,0 +1,118 @@
|
||||
using CarpentryWorkshopContracts.BindingModels;
|
||||
using CarpentryWorkshopContracts.ViewModels;
|
||||
using CarpentryWorkshopDataModels.Models;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.ComponentModel.DataAnnotations.Schema;
|
||||
|
||||
namespace CarpentryWorkshopDatabaseImplement.Models
|
||||
{
|
||||
public class Shop : IShopModel
|
||||
{
|
||||
public int Id { get; set; }
|
||||
|
||||
[Required]
|
||||
public string ShopName { get; set; } = string.Empty;
|
||||
|
||||
[Required]
|
||||
public string Address { get; set; } = string.Empty;
|
||||
|
||||
[Required]
|
||||
public DateTime DateOpen { get; set; }
|
||||
|
||||
[Required]
|
||||
public int WoodMaxCount { get; set; }
|
||||
|
||||
[ForeignKey("ShopId")]
|
||||
public List<ShopWood> Woods { get; set; } = new();
|
||||
|
||||
private Dictionary<int, (IWoodModel, int)>? _shopWoods = null;
|
||||
|
||||
[NotMapped]
|
||||
public Dictionary<int, (IWoodModel, int)> ShopWoods
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_shopWoods == null)
|
||||
{
|
||||
_shopWoods = Woods
|
||||
.ToDictionary(x => x.WoodId, x =>
|
||||
(x.Wood as IWoodModel, x.Count));
|
||||
}
|
||||
return _shopWoods;
|
||||
}
|
||||
}
|
||||
|
||||
public static Shop? Create(CarpentryWorkshopDatabase context, ShopBindingModel model)
|
||||
{
|
||||
if (model == null)
|
||||
return null;
|
||||
return new Shop()
|
||||
{
|
||||
Id = model.Id,
|
||||
ShopName = model.ShopName,
|
||||
Address = model.Address,
|
||||
DateOpen = model.DateOpen,
|
||||
WoodMaxCount = model.WoodMaxCount,
|
||||
Woods = model.ShopWoods.Select(x => new ShopWood
|
||||
{
|
||||
Wood = context.Woods.First(y => y.Id == x.Key),
|
||||
Count = x.Value.Item2
|
||||
}).ToList()
|
||||
};
|
||||
}
|
||||
|
||||
public void Update(ShopBindingModel? model)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
ShopName = model.ShopName;
|
||||
Address = model.Address;
|
||||
DateOpen = model.DateOpen;
|
||||
WoodMaxCount = model.WoodMaxCount;
|
||||
}
|
||||
|
||||
public ShopViewModel GetViewModel => new()
|
||||
{
|
||||
Id = Id,
|
||||
ShopName = ShopName,
|
||||
Address = Address,
|
||||
DateOpen = DateOpen,
|
||||
ShopWoods = ShopWoods,
|
||||
WoodMaxCount = WoodMaxCount
|
||||
};
|
||||
|
||||
public void UpdateWoods(CarpentryWorkshopDatabase context,
|
||||
ShopBindingModel model)
|
||||
{
|
||||
var shopWoods = context.ShopWoods.Where(rec =>
|
||||
rec.ShopId == model.Id).ToList();
|
||||
if (shopWoods != null && shopWoods.Count > 0)
|
||||
{
|
||||
context.ShopWoods.RemoveRange(shopWoods.Where(rec => !model.ShopWoods.ContainsKey(rec.WoodId)));
|
||||
|
||||
context.SaveChanges();
|
||||
foreach (var updateWood in shopWoods)
|
||||
{
|
||||
updateWood.Count =
|
||||
model.ShopWoods[updateWood.WoodId].Item2;
|
||||
model.ShopWoods.Remove(updateWood.WoodId);
|
||||
}
|
||||
context.SaveChanges();
|
||||
}
|
||||
var shop = context.Shops.First(x => x.Id == Id);
|
||||
foreach (var pc in model.ShopWoods)
|
||||
{
|
||||
context.ShopWoods.Add(new ShopWood
|
||||
{
|
||||
Shop = shop,
|
||||
Wood = context.Woods.First(x => x.Id == pc.Key),
|
||||
Count = pc.Value.Item2
|
||||
});
|
||||
context.SaveChanges();
|
||||
}
|
||||
_shopWoods = null;
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,27 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace CarpentryWorkshopDatabaseImplement.Models
|
||||
{
|
||||
public class ShopWood
|
||||
{
|
||||
public int Id { get; set; }
|
||||
|
||||
[Required]
|
||||
public int WoodId { get; set; }
|
||||
|
||||
[Required]
|
||||
public int ShopId { get; set; }
|
||||
|
||||
[Required]
|
||||
public int Count { get; set; }
|
||||
|
||||
public virtual Shop Shop { get; set; } = new();
|
||||
|
||||
public virtual Wood Wood { get; set; } = new();
|
||||
}
|
||||
}
|
@ -0,0 +1,97 @@
|
||||
using CarpentryWorkshopContracts.BindingModels;
|
||||
using CarpentryWorkshopContracts.ViewModels;
|
||||
using CarpentryWorkshopDataModels.Models;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.ComponentModel.DataAnnotations.Schema;
|
||||
|
||||
namespace CarpentryWorkshopDatabaseImplement.Models
|
||||
{
|
||||
public class Wood : IWoodModel
|
||||
{
|
||||
public int Id { get; private set; }
|
||||
[Required]
|
||||
public string WoodName { get; private set; } = string.Empty;
|
||||
[Required]
|
||||
public double Price { get; private set; }
|
||||
|
||||
private Dictionary<int, (IComponentModel, int)>? _woodComponents = null;
|
||||
|
||||
[NotMapped]
|
||||
public Dictionary<int, (IComponentModel, int)> WoodComponents
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_woodComponents == null)
|
||||
{
|
||||
_woodComponents = Components.ToDictionary(recPC => recPC.ComponentId, recPC => (recPC.Component as IComponentModel, recPC.Count));
|
||||
}
|
||||
return _woodComponents;
|
||||
}
|
||||
}
|
||||
|
||||
[ForeignKey("WoodId")]
|
||||
public virtual List<WoodComponent> Components { get; set; } = new();
|
||||
[ForeignKey("WoodId")]
|
||||
public virtual List<Order> Orders { get; set; } = new();
|
||||
[ForeignKey("WoodId")]
|
||||
public virtual List<ShopWood> ShopWoods { get; set; } = new();
|
||||
|
||||
public static Wood? Create(CarpentryWorkshopDatabase context, WoodBindingModel model)
|
||||
{
|
||||
var components = context.Components;
|
||||
return new Wood()
|
||||
{
|
||||
Id = model.Id,
|
||||
WoodName = model.WoodName,
|
||||
Price = model.Price,
|
||||
Components = model.WoodComponents.Select(x => new WoodComponent
|
||||
{
|
||||
Component = context.Components.First(y => y.Id == x.Key),
|
||||
Count = x.Value.Item2
|
||||
}).ToList()
|
||||
};
|
||||
}
|
||||
|
||||
public void Update(WoodBindingModel model)
|
||||
{
|
||||
WoodName = model.WoodName;
|
||||
Price = model.Price;
|
||||
}
|
||||
public WoodViewModel GetViewModel => new()
|
||||
{
|
||||
Id = Id,
|
||||
WoodName = WoodName,
|
||||
Price = Price,
|
||||
WoodComponents = WoodComponents
|
||||
};
|
||||
|
||||
public void UpdateComponents(CarpentryWorkshopDatabase context, WoodBindingModel model)
|
||||
{
|
||||
var woodComponents = context.WoodComponents.Where(rec => rec.WoodId == model.Id).ToList();
|
||||
if (woodComponents != null && woodComponents.Count > 0)
|
||||
{ // удалили те, которых нет в модели
|
||||
context.WoodComponents.RemoveRange(woodComponents.Where(rec => !model.WoodComponents.ContainsKey(rec.ComponentId)));
|
||||
context.SaveChanges();
|
||||
// обновили количество у существующих записей
|
||||
foreach (var updateComponent in woodComponents)
|
||||
{
|
||||
updateComponent.Count = model.WoodComponents[updateComponent.ComponentId].Item2;
|
||||
model.WoodComponents.Remove(updateComponent.ComponentId);
|
||||
}
|
||||
context.SaveChanges();
|
||||
}
|
||||
var wood = context.Woods.First(x => x.Id == Id);
|
||||
foreach (var pc in model.WoodComponents)
|
||||
{
|
||||
context.WoodComponents.Add(new WoodComponent
|
||||
{
|
||||
Wood = wood,
|
||||
Component = context.Components.First(x => x.Id == pc.Key),
|
||||
Count = pc.Value.Item2
|
||||
});
|
||||
context.SaveChanges();
|
||||
}
|
||||
_woodComponents = null;
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,17 @@
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
|
||||
namespace CarpentryWorkshopDatabaseImplement.Models
|
||||
{
|
||||
public class WoodComponent
|
||||
{
|
||||
public int Id { get; set; }
|
||||
[Required]
|
||||
public int WoodId { get; set; }
|
||||
[Required]
|
||||
public int ComponentId { get; set; }
|
||||
[Required]
|
||||
public int Count { get; set; }
|
||||
public virtual Component Component { get; set; } = new();
|
||||
public virtual Wood Wood { get; set; } = new();
|
||||
}
|
||||
}
|
@ -0,0 +1,14 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net6.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\CarpentryWorkshopContracts\CarpentryWorkshopContracts.csproj" />
|
||||
<ProjectReference Include="..\CarpentryWorkshopDataModels\CarpentryWorkshopDataModels.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
@ -0,0 +1,64 @@
|
||||
using CarpentryWorkshopFileImplement.Models;
|
||||
using System.Xml.Linq;
|
||||
|
||||
namespace CarpentryWorkshopFileImplement
|
||||
{
|
||||
internal class DataFileSingleton
|
||||
{
|
||||
private static DataFileSingleton? instance;
|
||||
private readonly string ComponentFileName = "Component.xml";
|
||||
private readonly string OrderFileName = "Order.xml";
|
||||
private readonly string WoodFileName = "Wood.xml";
|
||||
private readonly string ShopFileName = "Shop.xml";
|
||||
public List<Component> Components { get; private set; }
|
||||
public List<Order> Orders { get; private set; }
|
||||
public List<Wood> Woods { get; private set; }
|
||||
public List<Shop> Shops { get; private set; }
|
||||
public static DataFileSingleton GetInstance()
|
||||
{
|
||||
if (instance == null)
|
||||
{
|
||||
instance = new DataFileSingleton();
|
||||
}
|
||||
return instance;
|
||||
}
|
||||
public void SaveComponents() => SaveData(Components, ComponentFileName,
|
||||
"Components", x => x.GetXElement);
|
||||
public void SaveWoods() => SaveData(Woods, WoodFileName,
|
||||
"Woods", x => x.GetXElement);
|
||||
public void SaveOrders() => SaveData(Orders, OrderFileName,
|
||||
"Orders", x => x.GetXElement);
|
||||
public void SaveShops() => SaveData(Shops, ShopFileName,
|
||||
"Shops", x => x.GetXElement);
|
||||
private DataFileSingleton()
|
||||
{
|
||||
Components = LoadData(ComponentFileName, "Component", x =>
|
||||
Component.Create(x)!)!;
|
||||
Woods = LoadData(WoodFileName, "Wood", x =>
|
||||
Wood.Create(x)!)!;
|
||||
Orders = LoadData(OrderFileName, "Order", x =>
|
||||
Order.Create(x)!)!;
|
||||
Shops = LoadData(ShopFileName, "Shop", x =>
|
||||
Shop.Create(x)!)!;
|
||||
}
|
||||
private static List<T>? LoadData<T>(string filename, string xmlNodeName,
|
||||
Func<XElement, T> selectFunction)
|
||||
{
|
||||
if (File.Exists(filename))
|
||||
{
|
||||
return
|
||||
XDocument.Load(filename)?.Root?.Elements(xmlNodeName)?.Select(selectFunction)?.ToList();
|
||||
}
|
||||
return new List<T>();
|
||||
}
|
||||
private static void SaveData<T>(List<T> data, string filename, string
|
||||
xmlNodeName, Func<T, XElement> selectFunction)
|
||||
{
|
||||
if (data != null)
|
||||
{
|
||||
new XDocument(new XElement(xmlNodeName,
|
||||
data.Select(selectFunction).ToArray())).Save(filename);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,85 @@
|
||||
using CarpentryWorkshopContracts.BindingModels;
|
||||
using CarpentryWorkshopContracts.SearchModels;
|
||||
using CarpentryWorkshopContracts.StoragesContracts;
|
||||
using CarpentryWorkshopContracts.ViewModels;
|
||||
using CarpentryWorkshopFileImplement.Models;
|
||||
|
||||
namespace CarpentryWorkshopFileImplement.Implements
|
||||
{
|
||||
public class ComponentStorage : IComponentStorage
|
||||
{
|
||||
private readonly DataFileSingleton source;
|
||||
public ComponentStorage()
|
||||
{
|
||||
source = DataFileSingleton.GetInstance();
|
||||
}
|
||||
public List<ComponentViewModel> GetFullList()
|
||||
{
|
||||
return source.Components
|
||||
.Select(x => x.GetViewModel)
|
||||
.ToList();
|
||||
}
|
||||
public List<ComponentViewModel> GetFilteredList(ComponentSearchModel
|
||||
model)
|
||||
{
|
||||
if (string.IsNullOrEmpty(model.ComponentName))
|
||||
{
|
||||
return new();
|
||||
}
|
||||
return source.Components
|
||||
.Where(x => x.ComponentName.Contains(model.ComponentName))
|
||||
.Select(x => x.GetViewModel)
|
||||
.ToList();
|
||||
}
|
||||
public ComponentViewModel? GetElement(ComponentSearchModel model)
|
||||
{
|
||||
if (string.IsNullOrEmpty(model.ComponentName) && !model.Id.HasValue)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
return source.Components
|
||||
.FirstOrDefault(x =>
|
||||
(!string.IsNullOrEmpty(model.ComponentName) && x.ComponentName ==
|
||||
model.ComponentName) ||
|
||||
(model.Id.HasValue && x.Id == model.Id))
|
||||
?.GetViewModel;
|
||||
}
|
||||
public ComponentViewModel? Insert(ComponentBindingModel model)
|
||||
{
|
||||
model.Id = source.Components.Count > 0 ? source.Components.Max(x =>
|
||||
x.Id) + 1 : 1;
|
||||
var newComponent = Component.Create(model);
|
||||
if (newComponent == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
source.Components.Add(newComponent);
|
||||
source.SaveComponents();
|
||||
return newComponent.GetViewModel;
|
||||
}
|
||||
public ComponentViewModel? Update(ComponentBindingModel model)
|
||||
{
|
||||
var component = source.Components.FirstOrDefault(x => x.Id ==
|
||||
model.Id);
|
||||
if (component == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
component.Update(model);
|
||||
source.SaveComponents();
|
||||
return component.GetViewModel;
|
||||
}
|
||||
public ComponentViewModel? Delete(ComponentBindingModel model)
|
||||
{
|
||||
var element = source.Components.FirstOrDefault(x => x.Id ==
|
||||
model.Id);
|
||||
if (element != null)
|
||||
{
|
||||
source.Components.Remove(element);
|
||||
source.SaveComponents();
|
||||
return element.GetViewModel;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,88 @@
|
||||
using CarpentryWorkshopContracts.BindingModels;
|
||||
using CarpentryWorkshopContracts.SearchModels;
|
||||
using CarpentryWorkshopContracts.StoragesContracts;
|
||||
using CarpentryWorkshopContracts.ViewModels;
|
||||
using CarpentryWorkshopFileImplement.Models;
|
||||
|
||||
namespace CarpentryWorkshopFileImplement.Implements
|
||||
{
|
||||
public class OrderStorage : IOrderStorage
|
||||
{
|
||||
private readonly DataFileSingleton source;
|
||||
public OrderStorage()
|
||||
{
|
||||
source = DataFileSingleton.GetInstance();
|
||||
}
|
||||
public List<OrderViewModel> GetFullList()
|
||||
{
|
||||
return source.Orders
|
||||
.Select(x => AccessWoodStorage(x.GetViewModel))
|
||||
.ToList();
|
||||
}
|
||||
public List<OrderViewModel> GetFilteredList(OrderSearchModel model)
|
||||
{
|
||||
if (!model.Id.HasValue)
|
||||
{
|
||||
return new();
|
||||
}
|
||||
return source.Orders
|
||||
.Where(x => x.Id == model.Id)
|
||||
.Select(x => AccessWoodStorage(x.GetViewModel))
|
||||
.ToList();
|
||||
}
|
||||
public OrderViewModel? GetElement(OrderSearchModel model)
|
||||
{
|
||||
if (!model.Id.HasValue)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
return AccessWoodStorage(source.Orders
|
||||
.FirstOrDefault(x => (model.Id.HasValue && x.Id == model.Id))?.GetViewModel);
|
||||
}
|
||||
public OrderViewModel? Insert(OrderBindingModel model)
|
||||
{
|
||||
model.Id = source.Orders.Count > 0 ? source.Orders.Max(x => x.Id) + 1 : 1;
|
||||
var newOrder = Order.Create(model);
|
||||
if (newOrder == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
source.Orders.Add(newOrder);
|
||||
source.SaveOrders();
|
||||
return AccessWoodStorage(newOrder.GetViewModel);
|
||||
}
|
||||
public OrderViewModel? Update(OrderBindingModel model)
|
||||
{
|
||||
var order = source.Orders.FirstOrDefault(x => x.Id == model.Id);
|
||||
if (order == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
order.Update(model);
|
||||
source.SaveOrders();
|
||||
return AccessWoodStorage(order.GetViewModel);
|
||||
}
|
||||
public OrderViewModel? Delete(OrderBindingModel model)
|
||||
{
|
||||
var element = source.Orders.FirstOrDefault(x => x.Id ==
|
||||
model.Id);
|
||||
if (element != null)
|
||||
{
|
||||
source.Orders.Remove(element);
|
||||
source.SaveOrders();
|
||||
return AccessWoodStorage(element.GetViewModel);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
public OrderViewModel AccessWoodStorage(OrderViewModel model)
|
||||
{
|
||||
if (model == null)
|
||||
return null;
|
||||
var wood = source.Woods.FirstOrDefault(x => (x.Id == model.WoodId));
|
||||
if (wood == null)
|
||||
return model;
|
||||
model.WoodName = wood.WoodName;
|
||||
return model;
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,131 @@
|
||||
using CarpentryWorkshopContracts.BindingModels;
|
||||
using CarpentryWorkshopContracts.SearchModels;
|
||||
using CarpentryWorkshopContracts.StoragesContracts;
|
||||
using CarpentryWorkshopContracts.ViewModels;
|
||||
using CarpentryWorkshopDataModels.Models;
|
||||
using CarpentryWorkshopFileImplement.Models;
|
||||
|
||||
namespace CarpentryWorkshopFileImplement.Implements
|
||||
{
|
||||
public class ShopStorage : IShopStorage
|
||||
{
|
||||
private readonly DataFileSingleton source;
|
||||
|
||||
public ShopStorage()
|
||||
{
|
||||
source = DataFileSingleton.GetInstance();
|
||||
}
|
||||
|
||||
public List<ShopViewModel> GetFullList()
|
||||
{
|
||||
return source.Shops.Select(x => x.GetViewModel).ToList();
|
||||
}
|
||||
|
||||
public List<ShopViewModel> GetFilteredList(ShopSearchModel model)
|
||||
{
|
||||
if (string.IsNullOrEmpty(model.ShopName))
|
||||
{
|
||||
return new();
|
||||
}
|
||||
return source.Shops.Where(x => x.ShopName.Contains(model.ShopName)).Select(x => x.GetViewModel).ToList();
|
||||
}
|
||||
public ShopViewModel? GetElement(ShopSearchModel model)
|
||||
{
|
||||
if (string.IsNullOrEmpty(model.ShopName) && !model.Id.HasValue)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
return source.Shops.FirstOrDefault(x =>
|
||||
(!string.IsNullOrEmpty(model.ShopName) && x.ShopName == model.ShopName) ||
|
||||
(model.Id.HasValue && x.Id == model.Id))?.GetViewModel;
|
||||
}
|
||||
|
||||
public ShopViewModel? Insert(ShopBindingModel model)
|
||||
{
|
||||
model.Id = source.Shops.Count > 0 ? source.Shops.Max(x => x.Id) + 1 : 1;
|
||||
var newShop = Shop.Create(model);
|
||||
if (newShop == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
source.Shops.Add(newShop);
|
||||
source.SaveShops();
|
||||
return newShop.GetViewModel;
|
||||
}
|
||||
|
||||
public ShopViewModel? Update(ShopBindingModel model)
|
||||
{
|
||||
var shop = source.Shops.FirstOrDefault(x => x.Id == model.Id);
|
||||
if (shop == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
shop.Update(model);
|
||||
source.SaveShops();
|
||||
return shop.GetViewModel;
|
||||
}
|
||||
|
||||
public ShopViewModel? Delete(ShopBindingModel model)
|
||||
{
|
||||
var shop = source.Shops.FirstOrDefault(x => x.Id == model.Id);
|
||||
if (shop != null)
|
||||
{
|
||||
source.Shops.Remove(shop);
|
||||
source.SaveShops();
|
||||
return shop.GetViewModel;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public bool CheckAvailability(int woodId, int count)
|
||||
{
|
||||
int minus = source.Shops
|
||||
.SelectMany(shop => shop.ShopWoods
|
||||
.Where(wood => wood.Value.Item1.Id == woodId)
|
||||
.Select(wood => wood.Value.Item2))
|
||||
.Sum();
|
||||
count -= minus;
|
||||
return count <= 0;
|
||||
}
|
||||
|
||||
public bool SellWoods(IWoodModel model, int count)
|
||||
{
|
||||
var wood = source.Woods.FirstOrDefault(x => x.Id == model.Id);
|
||||
|
||||
if (wood == null || !CheckAvailability(wood.Id, count))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
for (int i = 0; i < source.Shops.Count; i++)
|
||||
{
|
||||
var shop = source.Shops[i];
|
||||
var woods = shop.ShopWoods;
|
||||
|
||||
foreach (var wod in woods.Where(x => x.Value.Item1.Id == wood.Id))
|
||||
{
|
||||
var min = Math.Min(wod.Value.Item2, count);
|
||||
woods[wod.Value.Item1.Id] = (wod.Value.Item1, wod.Value.Item2 - min);
|
||||
count -= min;
|
||||
|
||||
if (count <= 0)
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
shop.Update(new ShopBindingModel
|
||||
{
|
||||
Id = shop.Id,
|
||||
ShopName = shop.ShopName,
|
||||
Address = shop.Address,
|
||||
DateOpen = shop.DateOpen,
|
||||
WoodMaxCount = shop.WoodMaxCount,
|
||||
ShopWoods = woods
|
||||
});
|
||||
}
|
||||
source.SaveShops();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,84 @@
|
||||
using CarpentryWorkshopContracts.BindingModels;
|
||||
using CarpentryWorkshopContracts.SearchModels;
|
||||
using CarpentryWorkshopContracts.StoragesContracts;
|
||||
using CarpentryWorkshopContracts.ViewModels;
|
||||
using CarpentryWorkshopFileImplement.Models;
|
||||
|
||||
namespace CarpentryWorkshopFileImplement.Implements
|
||||
{
|
||||
public class WoodStorage : IWoodStorage
|
||||
{
|
||||
private readonly DataFileSingleton source;
|
||||
public WoodStorage()
|
||||
{
|
||||
source = DataFileSingleton.GetInstance();
|
||||
}
|
||||
public List<WoodViewModel> GetFullList()
|
||||
{
|
||||
return source.Woods
|
||||
.Select(x => x.GetViewModel)
|
||||
.ToList();
|
||||
}
|
||||
public List<WoodViewModel> GetFilteredList(WoodSearchModel model)
|
||||
{
|
||||
if (string.IsNullOrEmpty(model.WoodName))
|
||||
{
|
||||
return new();
|
||||
}
|
||||
return source.Woods
|
||||
.Where(x => x.WoodName.Contains(model.WoodName))
|
||||
.Select(x => x.GetViewModel)
|
||||
.ToList();
|
||||
}
|
||||
public WoodViewModel? GetElement(WoodSearchModel model)
|
||||
{
|
||||
if (string.IsNullOrEmpty(model.WoodName) && !model.Id.HasValue)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
return source.Woods
|
||||
.FirstOrDefault(x =>
|
||||
(!string.IsNullOrEmpty(model.WoodName) && x.WoodName ==
|
||||
model.WoodName) ||
|
||||
(model.Id.HasValue && x.Id == model.Id))
|
||||
?.GetViewModel;
|
||||
}
|
||||
public WoodViewModel? Insert(WoodBindingModel model)
|
||||
{
|
||||
model.Id = source.Woods.Count > 0 ? source.Woods.Max(x =>
|
||||
x.Id) + 1 : 1;
|
||||
var newWood = Wood.Create(model);
|
||||
if (newWood == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
source.Woods.Add(newWood);
|
||||
source.SaveWoods();
|
||||
return newWood.GetViewModel;
|
||||
}
|
||||
public WoodViewModel? Update(WoodBindingModel model)
|
||||
{
|
||||
var wood = source.Woods.FirstOrDefault(x => x.Id ==
|
||||
model.Id);
|
||||
if (wood == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
wood.Update(model);
|
||||
source.SaveWoods();
|
||||
return wood.GetViewModel;
|
||||
}
|
||||
public WoodViewModel? Delete(WoodBindingModel model)
|
||||
{
|
||||
var wood = source.Woods.FirstOrDefault(x => x.Id ==
|
||||
model.Id);
|
||||
if (wood != null)
|
||||
{
|
||||
source.Woods.Remove(wood);
|
||||
source.SaveWoods();
|
||||
return wood.GetViewModel;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue
Block a user