Лабораторная работа №2
This commit is contained in:
parent
fb7bfe478d
commit
b68734cad1
@ -12,9 +12,9 @@ public class Components
|
||||
|
||||
public double Count { get; private set; }
|
||||
|
||||
public Type_Components TypeComponents { get; private set; }
|
||||
public Type_Components TypeComponentsId { get; private set; }
|
||||
|
||||
public static Components CreateEntity(int id, string name, decimal price, double count, Type_Components typeComponents)
|
||||
public static Components CreateEntity(int id, string name, decimal price, double count, Type_Components typeComponentsId)
|
||||
{
|
||||
return new Components
|
||||
{
|
||||
@ -22,7 +22,7 @@ public class Components
|
||||
Name = name,
|
||||
Price = price,
|
||||
Count = count,
|
||||
TypeComponents = typeComponents
|
||||
TypeComponentsId = typeComponentsId
|
||||
};
|
||||
}
|
||||
}
|
||||
|
@ -4,7 +4,7 @@ public class Components_Production
|
||||
{
|
||||
public int Id { get; set; }
|
||||
|
||||
public int ComponentsID { get; private set; }
|
||||
public int ComponentsId { get; private set; }
|
||||
|
||||
public int Count { get; private set; }
|
||||
|
||||
@ -13,7 +13,7 @@ public class Components_Production
|
||||
return new Components_Production
|
||||
{
|
||||
Id = id,
|
||||
ComponentsID = componentsID,
|
||||
ComponentsId = componentsID,
|
||||
Count = count
|
||||
};
|
||||
}
|
||||
|
@ -10,7 +10,7 @@ public class Employee
|
||||
|
||||
public string LastName { get; private set; } = string.Empty;
|
||||
|
||||
public EmployeePost EmployeePost { get; private set; }
|
||||
public EmployeePost EmployeePostId { get; private set; }
|
||||
|
||||
public static Employee CreateEntity(int id, string first, string last,
|
||||
EmployeePost employeePost)
|
||||
@ -20,7 +20,7 @@ public class Employee
|
||||
Id = id,
|
||||
FirstName = first ?? string.Empty,
|
||||
LastName = last ?? string.Empty,
|
||||
EmployeePost = employeePost
|
||||
EmployeePostId = employeePost
|
||||
};
|
||||
}
|
||||
}
|
@ -2,25 +2,25 @@
|
||||
|
||||
public enum Type_Components
|
||||
{
|
||||
Electronic = 0,
|
||||
Electronic = 1,
|
||||
|
||||
Mechanical = 1,
|
||||
Mechanical = 2,
|
||||
|
||||
Fasteners = 2,
|
||||
Fasteners = 3,
|
||||
|
||||
Plastic = 3,
|
||||
Plastic = 4,
|
||||
|
||||
Power_supply_and_cables = 4,
|
||||
Power_supply_and_cables = 5,
|
||||
|
||||
Hydraulic_and_pneumatic = 5,
|
||||
Hydraulic_and_pneumatic = 6,
|
||||
|
||||
Optical = 6,
|
||||
Optical = 7,
|
||||
|
||||
Metals = 7,
|
||||
Metals = 8,
|
||||
|
||||
Wood = 8,
|
||||
Wood = 9,
|
||||
|
||||
Glass = 9,
|
||||
Glass = 10,
|
||||
|
||||
Chemistry = 10
|
||||
Chemistry = 11
|
||||
}
|
@ -8,7 +8,7 @@ public class Inventory
|
||||
|
||||
public bool IsDefect { get; private set; }
|
||||
|
||||
public int ComponentsID { get; private set; }
|
||||
public int ComponentsId { get; private set; }
|
||||
|
||||
public static Inventory CreateEntity(int id, double quantity, bool isDefect, int ComponentsID)
|
||||
{
|
||||
@ -17,7 +17,7 @@ public class Inventory
|
||||
Id = id,
|
||||
Quantity = quantity,
|
||||
IsDefect = isDefect,
|
||||
ComponentsID = ComponentsID
|
||||
ComponentsId = ComponentsID
|
||||
};
|
||||
}
|
||||
}
|
||||
|
@ -28,13 +28,12 @@ namespace ProjectWarehouse.Forms
|
||||
textBoxLastName.Text = employee.LastName;
|
||||
foreach (EmployeePost elem in Enum.GetValues(typeof(EmployeePost)))
|
||||
{
|
||||
if ((elem & employee.EmployeePost) != 0)
|
||||
if ((elem & employee.EmployeePostId) != 0)
|
||||
{
|
||||
|
||||
checkedListBoxPost.SetItemChecked(checkedListBoxPost.Items.IndexOf(elem), true);
|
||||
}
|
||||
}
|
||||
|
||||
_employeeId = value;
|
||||
}
|
||||
catch (Exception ex)
|
||||
|
@ -128,7 +128,6 @@
|
||||
#endregion
|
||||
|
||||
private Label labelComponent;
|
||||
private Label label2;
|
||||
private Label labelCount;
|
||||
private ComboBox comboBoxComponent;
|
||||
private CheckBox checkBoxIsDefect;
|
||||
|
@ -24,7 +24,7 @@ namespace ProjectWarehouse.Forms
|
||||
throw new InvalidDataException(nameof(inventory));
|
||||
}
|
||||
|
||||
comboBoxComponent.SelectedValue = inventory.ComponentsID;
|
||||
comboBoxComponent.SelectedValue = inventory.ComponentsId;
|
||||
numericUpDownCount.Value = (decimal)inventory.Quantity;
|
||||
checkBoxIsDefect.Checked = inventory.IsDefect;
|
||||
|
||||
|
@ -38,7 +38,7 @@
|
||||
comboBoxEmployee = new ComboBox();
|
||||
groupBoxComponents = new GroupBox();
|
||||
dataGridViewComponents = new DataGridView();
|
||||
ColumnComponent = new DataGridViewComboBoxColumn();
|
||||
ColumnComponents = new DataGridViewComboBoxColumn();
|
||||
ColumnCount = new DataGridViewTextBoxColumn();
|
||||
groupBoxComponents.SuspendLayout();
|
||||
((System.ComponentModel.ISupportInitialize)dataGridViewComponents).BeginInit();
|
||||
@ -47,40 +47,43 @@
|
||||
// labelName
|
||||
//
|
||||
labelName.AutoSize = true;
|
||||
labelName.Location = new Point(38, 14);
|
||||
labelName.Location = new Point(43, 19);
|
||||
labelName.Name = "labelName";
|
||||
labelName.Size = new Size(122, 15);
|
||||
labelName.Size = new Size(157, 20);
|
||||
labelName.TabIndex = 0;
|
||||
labelName.Text = "Название продукции";
|
||||
//
|
||||
// labelDescription
|
||||
//
|
||||
labelDescription.AutoSize = true;
|
||||
labelDescription.Location = new Point(36, 58);
|
||||
labelDescription.Location = new Point(41, 77);
|
||||
labelDescription.Name = "labelDescription";
|
||||
labelDescription.Size = new Size(125, 15);
|
||||
labelDescription.Size = new Size(159, 20);
|
||||
labelDescription.TabIndex = 1;
|
||||
labelDescription.Text = "Описание продукции";
|
||||
//
|
||||
// textBoxName
|
||||
//
|
||||
textBoxName.Location = new Point(191, 14);
|
||||
textBoxName.Location = new Point(218, 19);
|
||||
textBoxName.Margin = new Padding(3, 4, 3, 4);
|
||||
textBoxName.Name = "textBoxName";
|
||||
textBoxName.Size = new Size(165, 23);
|
||||
textBoxName.Size = new Size(188, 27);
|
||||
textBoxName.TabIndex = 2;
|
||||
//
|
||||
// textBoxDescription
|
||||
//
|
||||
textBoxDescription.Location = new Point(191, 56);
|
||||
textBoxDescription.Location = new Point(218, 75);
|
||||
textBoxDescription.Margin = new Padding(3, 4, 3, 4);
|
||||
textBoxDescription.Name = "textBoxDescription";
|
||||
textBoxDescription.Size = new Size(165, 23);
|
||||
textBoxDescription.Size = new Size(188, 27);
|
||||
textBoxDescription.TabIndex = 3;
|
||||
//
|
||||
// buttonSave
|
||||
//
|
||||
buttonSave.Location = new Point(63, 380);
|
||||
buttonSave.Location = new Point(72, 507);
|
||||
buttonSave.Margin = new Padding(3, 4, 3, 4);
|
||||
buttonSave.Name = "buttonSave";
|
||||
buttonSave.Size = new Size(94, 23);
|
||||
buttonSave.Size = new Size(107, 31);
|
||||
buttonSave.TabIndex = 4;
|
||||
buttonSave.Text = "Сохранить";
|
||||
buttonSave.UseVisualStyleBackColor = true;
|
||||
@ -88,9 +91,10 @@
|
||||
//
|
||||
// buttonCancel
|
||||
//
|
||||
buttonCancel.Location = new Point(260, 380);
|
||||
buttonCancel.Location = new Point(297, 507);
|
||||
buttonCancel.Margin = new Padding(3, 4, 3, 4);
|
||||
buttonCancel.Name = "buttonCancel";
|
||||
buttonCancel.Size = new Size(75, 23);
|
||||
buttonCancel.Size = new Size(86, 31);
|
||||
buttonCancel.TabIndex = 5;
|
||||
buttonCancel.Text = "Отмена";
|
||||
buttonCancel.UseVisualStyleBackColor = true;
|
||||
@ -99,9 +103,9 @@
|
||||
// labelEmployee
|
||||
//
|
||||
labelEmployee.AutoSize = true;
|
||||
labelEmployee.Location = new Point(63, 102);
|
||||
labelEmployee.Location = new Point(72, 136);
|
||||
labelEmployee.Name = "labelEmployee";
|
||||
labelEmployee.Size = new Size(59, 15);
|
||||
labelEmployee.Size = new Size(74, 20);
|
||||
labelEmployee.TabIndex = 8;
|
||||
labelEmployee.Text = "Работник";
|
||||
//
|
||||
@ -109,21 +113,18 @@
|
||||
//
|
||||
comboBoxEmployee.DropDownStyle = ComboBoxStyle.DropDownList;
|
||||
comboBoxEmployee.FormattingEnabled = true;
|
||||
comboBoxEmployee.Location = new Point(192, 102);
|
||||
comboBoxEmployee.Margin = new Padding(3, 2, 3, 2);
|
||||
comboBoxEmployee.Location = new Point(219, 136);
|
||||
comboBoxEmployee.Name = "comboBoxEmployee";
|
||||
comboBoxEmployee.Size = new Size(164, 23);
|
||||
comboBoxEmployee.Size = new Size(187, 28);
|
||||
comboBoxEmployee.TabIndex = 7;
|
||||
//
|
||||
// groupBoxComponents
|
||||
//
|
||||
groupBoxComponents.Anchor = AnchorStyles.Top | AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right;
|
||||
groupBoxComponents.Controls.Add(dataGridViewComponents);
|
||||
groupBoxComponents.Location = new Point(23, 144);
|
||||
groupBoxComponents.Margin = new Padding(3, 2, 3, 2);
|
||||
groupBoxComponents.Location = new Point(26, 192);
|
||||
groupBoxComponents.Name = "groupBoxComponents";
|
||||
groupBoxComponents.Padding = new Padding(3, 2, 3, 2);
|
||||
groupBoxComponents.Size = new Size(349, 220);
|
||||
groupBoxComponents.Size = new Size(399, 293);
|
||||
groupBoxComponents.TabIndex = 6;
|
||||
groupBoxComponents.TabStop = false;
|
||||
groupBoxComponents.Text = "Комплектующие";
|
||||
@ -134,23 +135,22 @@
|
||||
dataGridViewComponents.AllowUserToResizeRows = false;
|
||||
dataGridViewComponents.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill;
|
||||
dataGridViewComponents.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize;
|
||||
dataGridViewComponents.Columns.AddRange(new DataGridViewColumn[] { ColumnComponent, ColumnCount });
|
||||
dataGridViewComponents.Columns.AddRange(new DataGridViewColumn[] { ColumnComponents, ColumnCount });
|
||||
dataGridViewComponents.Dock = DockStyle.Fill;
|
||||
dataGridViewComponents.Location = new Point(3, 18);
|
||||
dataGridViewComponents.Margin = new Padding(3, 2, 3, 2);
|
||||
dataGridViewComponents.Location = new Point(3, 23);
|
||||
dataGridViewComponents.MultiSelect = false;
|
||||
dataGridViewComponents.Name = "dataGridViewComponents";
|
||||
dataGridViewComponents.RowHeadersVisible = false;
|
||||
dataGridViewComponents.RowHeadersWidth = 51;
|
||||
dataGridViewComponents.SelectionMode = DataGridViewSelectionMode.FullRowSelect;
|
||||
dataGridViewComponents.Size = new Size(343, 200);
|
||||
dataGridViewComponents.Size = new Size(393, 267);
|
||||
dataGridViewComponents.TabIndex = 0;
|
||||
//
|
||||
// ColumnComponent
|
||||
// ColumnComponents
|
||||
//
|
||||
ColumnComponent.HeaderText = "Компонент";
|
||||
ColumnComponent.MinimumWidth = 6;
|
||||
ColumnComponent.Name = "ColumnComponent";
|
||||
ColumnComponents.HeaderText = "Компонент";
|
||||
ColumnComponents.MinimumWidth = 6;
|
||||
ColumnComponents.Name = "ColumnComponents";
|
||||
//
|
||||
// ColumnCount
|
||||
//
|
||||
@ -160,9 +160,9 @@
|
||||
//
|
||||
// FormProduction
|
||||
//
|
||||
AutoScaleDimensions = new SizeF(7F, 15F);
|
||||
AutoScaleDimensions = new SizeF(8F, 20F);
|
||||
AutoScaleMode = AutoScaleMode.Font;
|
||||
ClientSize = new Size(398, 415);
|
||||
ClientSize = new Size(455, 553);
|
||||
Controls.Add(labelEmployee);
|
||||
Controls.Add(comboBoxEmployee);
|
||||
Controls.Add(groupBoxComponents);
|
||||
@ -172,6 +172,7 @@
|
||||
Controls.Add(textBoxName);
|
||||
Controls.Add(labelDescription);
|
||||
Controls.Add(labelName);
|
||||
Margin = new Padding(3, 4, 3, 4);
|
||||
Name = "FormProduction";
|
||||
StartPosition = FormStartPosition.CenterParent;
|
||||
Text = "Продукция";
|
||||
@ -193,7 +194,7 @@
|
||||
private ComboBox comboBoxEmployee;
|
||||
private GroupBox groupBoxComponents;
|
||||
private DataGridView dataGridViewComponents;
|
||||
private DataGridViewComboBoxColumn ColumnComponent;
|
||||
private DataGridViewComboBoxColumn ColumnComponents;
|
||||
private DataGridViewTextBoxColumn ColumnCount;
|
||||
}
|
||||
}
|
@ -9,30 +9,6 @@ namespace ProjectWarehouse.Forms
|
||||
|
||||
private int? _productionId;
|
||||
|
||||
public int Id
|
||||
{
|
||||
set
|
||||
{
|
||||
try
|
||||
{
|
||||
var production = _productionRepository.ReadProductionByID(value);
|
||||
if (production == null)
|
||||
{
|
||||
throw new InvalidDataException(nameof(production));
|
||||
}
|
||||
|
||||
textBoxName.Text = production.Name;
|
||||
textBoxDescription.Text = production.Description;
|
||||
_productionId = value;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
MessageBox.Show(ex.Message, "Ошибка при получении данных", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public FormProduction(IProductionRepository productionRepository, IEmployeeRepository employeeRepository, IComponentsRepository componentsRepository)
|
||||
{
|
||||
InitializeComponent();
|
||||
@ -43,29 +19,22 @@ namespace ProjectWarehouse.Forms
|
||||
comboBoxEmployee.DisplayMember = "FirstName";
|
||||
comboBoxEmployee.ValueMember = "Id";
|
||||
|
||||
ColumnComponent.DataSource = componentsRepository.ReadComponents();
|
||||
ColumnComponent.DisplayMember = "Name";
|
||||
ColumnComponent.ValueMember = "Id";
|
||||
ColumnComponents.DataSource = componentsRepository.ReadComponents();
|
||||
ColumnComponents.DisplayMember = "Name";
|
||||
ColumnComponents.ValueMember = "Id";
|
||||
}
|
||||
|
||||
private void ButtonSave_Click(object sender, EventArgs e)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(textBoxName.Text) || string.IsNullOrWhiteSpace(textBoxDescription.Text) || dataGridViewComponents.RowCount < 1 || comboBoxEmployee.SelectedIndex < 0)
|
||||
if (string.IsNullOrWhiteSpace(textBoxName.Text) || dataGridViewComponents.RowCount < 1 || comboBoxEmployee.SelectedIndex < 0)
|
||||
{
|
||||
throw new Exception("Имеются незаполненные поля");
|
||||
}
|
||||
|
||||
if (_productionId.HasValue)
|
||||
{
|
||||
_productionRepository.UpdateProduction(CreateProduction(_productionId.Value));
|
||||
}
|
||||
else
|
||||
{
|
||||
_productionRepository.CreateProduction(CreateProduction(0));
|
||||
}
|
||||
|
||||
|
||||
_productionRepository.CreateProduction(Production.CreateEntity(0, textBoxName.Text, textBoxDescription.Text, (int)comboBoxEmployee.SelectedValue!, CreateListComponents_ProductionsFromDataGrid()));
|
||||
|
||||
Close();
|
||||
}
|
||||
catch (Exception ex)
|
||||
@ -92,8 +61,5 @@ namespace ProjectWarehouse.Forms
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
|
||||
private Production CreateProduction(int id) => Production.CreateEntity(id, textBoxName.Text, textBoxDescription.Text, (int)comboBoxEmployee.SelectedItem!, CreateListComponents_ProductionsFromDataGrid());
|
||||
}
|
||||
}
|
||||
|
@ -1,7 +1,7 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<root>
|
||||
<!--
|
||||
Microsoft ResX Schema
|
||||
Microsoft ResX Schema
|
||||
|
||||
Version 2.0
|
||||
|
||||
@ -48,7 +48,7 @@
|
||||
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
|
||||
@ -117,7 +117,7 @@
|
||||
<resheader name="writer">
|
||||
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
<metadata name="ColumnComponent.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
|
||||
<metadata name="ColumnComponents.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
|
||||
<value>True</value>
|
||||
</metadata>
|
||||
<metadata name="ColumnCount.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
|
||||
|
@ -30,7 +30,6 @@
|
||||
{
|
||||
panel1 = new Panel();
|
||||
ButtonDel = new Button();
|
||||
ButtonUpd = new Button();
|
||||
ButtonAdd = new Button();
|
||||
dataGridViewData = new DataGridView();
|
||||
panel1.SuspendLayout();
|
||||
@ -40,43 +39,34 @@
|
||||
// panel1
|
||||
//
|
||||
panel1.Controls.Add(ButtonDel);
|
||||
panel1.Controls.Add(ButtonUpd);
|
||||
panel1.Controls.Add(ButtonAdd);
|
||||
panel1.Dock = DockStyle.Right;
|
||||
panel1.Location = new Point(685, 0);
|
||||
panel1.Location = new Point(921, 0);
|
||||
panel1.Margin = new Padding(3, 4, 3, 4);
|
||||
panel1.Name = "panel1";
|
||||
panel1.Size = new Size(115, 450);
|
||||
panel1.Size = new Size(131, 600);
|
||||
panel1.TabIndex = 0;
|
||||
//
|
||||
// ButtonDel
|
||||
//
|
||||
ButtonDel.BackgroundImage = Properties.Resources.минус;
|
||||
ButtonDel.BackgroundImageLayout = ImageLayout.Stretch;
|
||||
ButtonDel.Location = new Point(19, 264);
|
||||
ButtonDel.Location = new Point(22, 352);
|
||||
ButtonDel.Margin = new Padding(3, 4, 3, 4);
|
||||
ButtonDel.Name = "ButtonDel";
|
||||
ButtonDel.Size = new Size(75, 74);
|
||||
ButtonDel.Size = new Size(86, 99);
|
||||
ButtonDel.TabIndex = 2;
|
||||
ButtonDel.UseVisualStyleBackColor = true;
|
||||
ButtonDel.Click += ButtonDel_Click;
|
||||
//
|
||||
// ButtonUpd
|
||||
//
|
||||
ButtonUpd.BackgroundImage = Properties.Resources.редактировать;
|
||||
ButtonUpd.BackgroundImageLayout = ImageLayout.Stretch;
|
||||
ButtonUpd.Location = new Point(19, 135);
|
||||
ButtonUpd.Name = "ButtonUpd";
|
||||
ButtonUpd.Size = new Size(75, 74);
|
||||
ButtonUpd.TabIndex = 1;
|
||||
ButtonUpd.UseVisualStyleBackColor = true;
|
||||
ButtonUpd.Click += ButtonUpd_Click;
|
||||
//
|
||||
// ButtonAdd
|
||||
//
|
||||
ButtonAdd.BackgroundImage = Properties.Resources.плюс;
|
||||
ButtonAdd.BackgroundImageLayout = ImageLayout.Stretch;
|
||||
ButtonAdd.Location = new Point(19, 24);
|
||||
ButtonAdd.Location = new Point(22, 32);
|
||||
ButtonAdd.Margin = new Padding(3, 4, 3, 4);
|
||||
ButtonAdd.Name = "ButtonAdd";
|
||||
ButtonAdd.Size = new Size(75, 74);
|
||||
ButtonAdd.Size = new Size(86, 99);
|
||||
ButtonAdd.TabIndex = 0;
|
||||
ButtonAdd.UseVisualStyleBackColor = true;
|
||||
ButtonAdd.Click += ButtonAdd_Click;
|
||||
@ -91,21 +81,24 @@
|
||||
dataGridViewData.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize;
|
||||
dataGridViewData.Dock = DockStyle.Fill;
|
||||
dataGridViewData.Location = new Point(0, 0);
|
||||
dataGridViewData.Margin = new Padding(3, 4, 3, 4);
|
||||
dataGridViewData.MultiSelect = false;
|
||||
dataGridViewData.Name = "dataGridViewData";
|
||||
dataGridViewData.ReadOnly = true;
|
||||
dataGridViewData.RowHeadersVisible = false;
|
||||
dataGridViewData.RowHeadersWidth = 51;
|
||||
dataGridViewData.SelectionMode = DataGridViewSelectionMode.FullRowSelect;
|
||||
dataGridViewData.Size = new Size(685, 450);
|
||||
dataGridViewData.Size = new Size(921, 600);
|
||||
dataGridViewData.TabIndex = 1;
|
||||
//
|
||||
// FormProductions
|
||||
//
|
||||
AutoScaleDimensions = new SizeF(7F, 15F);
|
||||
AutoScaleDimensions = new SizeF(8F, 20F);
|
||||
AutoScaleMode = AutoScaleMode.Font;
|
||||
ClientSize = new Size(800, 450);
|
||||
ClientSize = new Size(1052, 600);
|
||||
Controls.Add(dataGridViewData);
|
||||
Controls.Add(panel1);
|
||||
Margin = new Padding(3, 4, 3, 4);
|
||||
Name = "FormProductions";
|
||||
StartPosition = FormStartPosition.CenterParent;
|
||||
Text = "Продукция";
|
||||
@ -119,7 +112,6 @@
|
||||
|
||||
private Panel panel1;
|
||||
private Button ButtonDel;
|
||||
private Button ButtonUpd;
|
||||
private Button ButtonAdd;
|
||||
private DataGridView dataGridViewData;
|
||||
}
|
||||
|
@ -43,26 +43,6 @@ namespace ProjectWarehouse.Forms
|
||||
}
|
||||
}
|
||||
|
||||
private void ButtonUpd_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (!TryGetIdentifierFromSelectedRow(out var findId))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
var form = _container.Resolve<FormProduction>();
|
||||
form.Id = findId;
|
||||
form.ShowDialog();
|
||||
LoadList();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
MessageBox.Show(ex.Message, "Ошибка при изменении", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
}
|
||||
}
|
||||
|
||||
private void ButtonDel_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (!TryGetIdentifierFromSelectedRow(out var findId))
|
||||
|
@ -1,7 +1,7 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<root>
|
||||
<!--
|
||||
Microsoft ResX Schema
|
||||
Microsoft ResX Schema
|
||||
|
||||
Version 2.0
|
||||
|
||||
@ -48,7 +48,7 @@
|
||||
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
|
||||
|
@ -1,7 +1,11 @@
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using ProjectWarehouse.Repositories;
|
||||
using ProjectWarehouse.Repositories.Implementations;
|
||||
using Serilog;
|
||||
using Unity;
|
||||
using Unity.Lifetime;
|
||||
using Unity.Microsoft.Logging;
|
||||
|
||||
namespace ProjectWarehouse
|
||||
{
|
||||
@ -23,13 +27,28 @@ namespace ProjectWarehouse
|
||||
{
|
||||
var container = new UnityContainer();
|
||||
|
||||
container.AddExtension(new LoggingExtension(CreateLoggerFactory()));
|
||||
|
||||
container.RegisterType<IEmployeeRepository, EmployeeRepository>(new TransientLifetimeManager());
|
||||
container.RegisterType<IProductionRepository, ProductionRepository>(new TransientLifetimeManager());
|
||||
container.RegisterType<IComponentsRepository, ComponentsRepository>(new TransientLifetimeManager());
|
||||
container.RegisterType<IOrderRequestRepository, OrderRequestRepository>(new TransientLifetimeManager());
|
||||
container.RegisterType<IInventoryRepository, InventoryRepository>(new TransientLifetimeManager());
|
||||
container.RegisterType<IConnectionString, ConnectionString>(new TransientLifetimeManager());
|
||||
|
||||
return container;
|
||||
}
|
||||
|
||||
private static LoggerFactory CreateLoggerFactory()
|
||||
{
|
||||
var loggerFactory = new LoggerFactory();
|
||||
loggerFactory.AddSerilog(new LoggerConfiguration()
|
||||
.ReadFrom.Configuration(new ConfigurationBuilder()
|
||||
.SetBasePath(Directory.GetCurrentDirectory())
|
||||
.AddJsonFile("appsettings.json")
|
||||
.Build())
|
||||
.CreateLogger());
|
||||
return loggerFactory;
|
||||
}
|
||||
}
|
||||
}
|
@ -9,7 +9,18 @@
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Dapper" Version="2.1.35" />
|
||||
<PackageReference Include="Microsoft.Extensions.Configuration" Version="9.0.0" />
|
||||
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="9.0.0" />
|
||||
<PackageReference Include="Microsoft.Extensions.Logging" Version="9.0.0" />
|
||||
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
|
||||
<PackageReference Include="Npgsql" Version="9.0.1" />
|
||||
<PackageReference Include="Serilog" Version="4.1.0" />
|
||||
<PackageReference Include="Serilog.Extensions.Logging" Version="8.0.0" />
|
||||
<PackageReference Include="Serilog.Settings.Configuration" Version="8.0.4" />
|
||||
<PackageReference Include="Serilog.Sinks.File" Version="6.0.0" />
|
||||
<PackageReference Include="Unity" Version="5.11.10" />
|
||||
<PackageReference Include="Unity.Microsoft.Logging" Version="5.11.1" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
@ -39,4 +50,10 @@
|
||||
</EmbeddedResource>
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<None Update="appsettings.json">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</None>
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
@ -0,0 +1,6 @@
|
||||
namespace ProjectWarehouse.Repositories;
|
||||
|
||||
public interface IConnectionString
|
||||
{
|
||||
public string ConnectionString { get; }
|
||||
}
|
@ -6,11 +6,7 @@ public interface IProductionRepository
|
||||
{
|
||||
IEnumerable<Production> ReadProduction();
|
||||
|
||||
Production ReadProductionByID(int id);
|
||||
|
||||
void CreateProduction(Production production);
|
||||
|
||||
void UpdateProduction(Production production);
|
||||
|
||||
void DeleteProduction(int id);
|
||||
}
|
||||
}
|
@ -1,28 +1,120 @@
|
||||
using ProjectWarehouse.Entities;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Newtonsoft.Json;
|
||||
using ProjectWarehouse.Entities;
|
||||
using Dapper;
|
||||
|
||||
namespace ProjectWarehouse.Repositories.Implementations;
|
||||
|
||||
public class ComponentsRepository : IComponentsRepository
|
||||
{
|
||||
private readonly IConnectionString _connectionString;
|
||||
|
||||
private readonly ILogger<ComponentsRepository> _logger;
|
||||
|
||||
public ComponentsRepository(IConnectionString connectionString, ILogger<ComponentsRepository> logger)
|
||||
{
|
||||
_connectionString = connectionString;
|
||||
_logger = logger;
|
||||
}
|
||||
|
||||
public void CreateComponents(Components component)
|
||||
{
|
||||
_logger.LogInformation("Добавление объекта");
|
||||
_logger.LogDebug("Объект: {json}", JsonConvert.SerializeObject(component));
|
||||
|
||||
try
|
||||
{
|
||||
using var connection = new Npgsql.NpgsqlConnection(_connectionString.ConnectionString);
|
||||
var queryInsert = @"
|
||||
INSERT INTO Components (Name, Price, Count, TypeComponentsId)
|
||||
VALUES (@Name, @Price, @Count, @TypeComponentsId)";
|
||||
connection.Execute(queryInsert, component);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка при добавлении объекта");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
public void UpdateComponents(Components component)
|
||||
{
|
||||
_logger.LogInformation("Редактирование объекта");
|
||||
_logger.LogDebug("Объект:{json}", JsonConvert.SerializeObject(component));
|
||||
try
|
||||
{
|
||||
using var connection = new Npgsql.NpgsqlConnection(_connectionString.ConnectionString);
|
||||
var queryUpdate = @"
|
||||
UPDATE Components
|
||||
SET
|
||||
Name=@Name,
|
||||
Price=@Price,
|
||||
Count=@Count,
|
||||
TypeComponentsId=@TypeComponentsId
|
||||
WHERE Id=@id";
|
||||
connection.Execute(queryUpdate, component);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка при редактировании объекта");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
public void DeleteComponents(int id)
|
||||
{
|
||||
_logger.LogInformation("Удаление объекта");
|
||||
_logger.LogDebug("Объект:{id}", id);
|
||||
try
|
||||
{
|
||||
using var connection = new Npgsql.NpgsqlConnection(_connectionString.ConnectionString);
|
||||
var queryDelete = @"
|
||||
DELETE FROM Components
|
||||
WHERE Id=@id";
|
||||
connection.Execute(queryDelete, new { id });
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка при удалении объекта");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
public Components ReadComponentsByID(int id)
|
||||
{
|
||||
_logger.LogInformation("Получение объекта по идентификатору");
|
||||
_logger.LogDebug("Объект:{id}", id);
|
||||
try
|
||||
{
|
||||
using var connection = new Npgsql.NpgsqlConnection(_connectionString.ConnectionString);
|
||||
var querySelect = @"
|
||||
SELECT * FROM Components
|
||||
WHERE Id=@id";
|
||||
var components = connection.QueryFirst<Components>(querySelect, new { id });
|
||||
_logger.LogDebug("Найденный объект: {json}", JsonConvert.SerializeObject(components));
|
||||
return components;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка при поиске объекта");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
public IEnumerable<Components> ReadComponents()
|
||||
{
|
||||
return [];
|
||||
}
|
||||
|
||||
public Components ReadComponentsByID(int id)
|
||||
{
|
||||
return Components.CreateEntity(0, string.Empty, 0, 0, 0);
|
||||
}
|
||||
|
||||
public void UpdateComponents(Components component)
|
||||
{
|
||||
_logger.LogInformation("Получение всех объектов");
|
||||
try
|
||||
{
|
||||
using var connection = new Npgsql.NpgsqlConnection(_connectionString.ConnectionString);
|
||||
connection.Open();
|
||||
var querySelect = "SELECT * FROM Components";
|
||||
var components = connection.Query<Components>(querySelect);
|
||||
_logger.LogDebug("Полученные объекты: {json}", JsonConvert.SerializeObject(components));
|
||||
return components;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка при чтении объектов");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,6 @@
|
||||
namespace ProjectWarehouse.Repositories.Implementations;
|
||||
|
||||
public class ConnectionString : IConnectionString
|
||||
{
|
||||
string IConnectionString.ConnectionString => "Host=localhost;Port=5432;Database=warehousebd;Username=postgres;Password=postgres";
|
||||
}
|
@ -1,30 +1,121 @@
|
||||
using ProjectWarehouse.Entities.Enums;
|
||||
using ProjectWarehouse.Entities;
|
||||
using ProjectWarehouse.Entities;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Newtonsoft.Json;
|
||||
using Dapper;
|
||||
|
||||
namespace ProjectWarehouse.Repositories.Implementations;
|
||||
|
||||
public class EmployeeRepository : IEmployeeRepository
|
||||
{
|
||||
private readonly IConnectionString _connectionString;
|
||||
|
||||
private readonly ILogger<EmployeeRepository> _logger;
|
||||
|
||||
public EmployeeRepository(IConnectionString connectionString, ILogger<EmployeeRepository> logger)
|
||||
{
|
||||
_connectionString = connectionString;
|
||||
_logger = logger;
|
||||
}
|
||||
|
||||
public void CreateEmployee(Employee employee)
|
||||
{
|
||||
}
|
||||
|
||||
public void DeleteEmployee(int id)
|
||||
{
|
||||
}
|
||||
|
||||
public Employee ReadEmployeeById(int id)
|
||||
{
|
||||
return Employee.CreateEntity(0, string.Empty, string.Empty,
|
||||
EmployeePost.None);
|
||||
}
|
||||
|
||||
public IEnumerable<Employee> ReadEmployees()
|
||||
{
|
||||
return [];
|
||||
_logger.LogInformation("Добавление объекта");
|
||||
_logger.LogDebug("Объект: {json}", JsonConvert.SerializeObject(employee));
|
||||
try
|
||||
{
|
||||
using var connection = new Npgsql.NpgsqlConnection(_connectionString.ConnectionString);
|
||||
var queryInsert = @"
|
||||
INSERT INTO Employees (FirstName, LastName, EmployeePostId)
|
||||
VALUES (@FirstName, @LastName, @EmployeePostId)";
|
||||
connection.Execute(queryInsert, employee);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка при добавлении объекта");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
public void UpdateEmployee(Employee employee)
|
||||
{
|
||||
_logger.LogInformation("Редактирование объекта");
|
||||
_logger.LogDebug("Объект: {json}", JsonConvert.SerializeObject(employee));
|
||||
try
|
||||
{
|
||||
using var connection = new Npgsql.NpgsqlConnection(_connectionString.ConnectionString);
|
||||
var queryUpdate = @"
|
||||
UPDATE Employees
|
||||
SET
|
||||
FirstName=@FirstName,
|
||||
LastName=@LastName,
|
||||
EmployeePostId=@EmployeePostId
|
||||
WHERE Id=@id";
|
||||
connection.Execute(queryUpdate, employee);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка при редактировании объекта");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
public void DeleteEmployee(int id)
|
||||
{
|
||||
_logger.LogInformation("Удаление объекта");
|
||||
_logger.LogDebug("Объект: {id}", id);
|
||||
try
|
||||
{
|
||||
using var connection = new Npgsql.NpgsqlConnection(_connectionString.ConnectionString);
|
||||
var queryDelete = @"
|
||||
DELETE FROM Employees
|
||||
WHERE Id=@id";
|
||||
connection.Execute(queryDelete, new { id });
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка при удалении объекта");
|
||||
throw;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public Employee ReadEmployeeById(int id)
|
||||
{
|
||||
_logger.LogInformation("Получение объекта по идентификатору");
|
||||
_logger.LogDebug("Объект: {id}", id);
|
||||
try
|
||||
{
|
||||
using var connection = new Npgsql.NpgsqlConnection(_connectionString.ConnectionString);
|
||||
var querySelect = @"
|
||||
SELECT * FROM Employees
|
||||
WHERE Id=@id";
|
||||
var employee = connection.QueryFirst<Employee>(querySelect,
|
||||
new { id });
|
||||
_logger.LogDebug("Найденный объект: {json}", JsonConvert.SerializeObject(employee));
|
||||
return employee;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка при поиске объекта");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
public IEnumerable<Employee> ReadEmployees()
|
||||
{
|
||||
_logger.LogInformation("Получение всех объектов");
|
||||
try
|
||||
{
|
||||
using var connection = new Npgsql.NpgsqlConnection(_connectionString.ConnectionString);
|
||||
var querySelect = "SELECT * FROM Employees";
|
||||
var employees = connection.Query<Employee>(querySelect);
|
||||
_logger.LogDebug("Полученные объекты: {json}", JsonConvert.SerializeObject(employees));
|
||||
return employees;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка при чтении объектов");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,28 +1,123 @@
|
||||
using ProjectWarehouse.Entities;
|
||||
using Dapper;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Newtonsoft.Json;
|
||||
using ProjectWarehouse.Entities;
|
||||
|
||||
namespace ProjectWarehouse.Repositories.Implementations;
|
||||
|
||||
public class InventoryRepository : IInventoryRepository
|
||||
{
|
||||
private readonly IConnectionString _connectionString;
|
||||
|
||||
private readonly ILogger<InventoryRepository> _logger;
|
||||
|
||||
public InventoryRepository(IConnectionString connectionString, ILogger<InventoryRepository> logger)
|
||||
{
|
||||
_connectionString = connectionString;
|
||||
_logger = logger;
|
||||
}
|
||||
|
||||
public void CreateInventory(Inventory inventory)
|
||||
{
|
||||
_logger.LogInformation("Добавление объекта");
|
||||
_logger.LogDebug("Объект: {json}", JsonConvert.SerializeObject(inventory));
|
||||
|
||||
try
|
||||
{
|
||||
using var connection = new Npgsql.NpgsqlConnection(_connectionString.ConnectionString);
|
||||
connection.Open();
|
||||
var queryInsert = @"
|
||||
INSERT INTO Inventory (Quantity, IsDefect, ComponentsId)
|
||||
VALUES (@Quantity, @IsDefect, @ComponentsId)";
|
||||
connection.Execute(queryInsert, inventory);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка при добавлении объекта");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
public void UpdateInventory(Inventory inventory)
|
||||
{
|
||||
_logger.LogInformation("Редактирование объекта");
|
||||
_logger.LogDebug("Объект:{json}", JsonConvert.SerializeObject(inventory));
|
||||
try
|
||||
{
|
||||
using var connection = new Npgsql.NpgsqlConnection(_connectionString.ConnectionString);
|
||||
connection.Open();
|
||||
var queryUpdate = @"
|
||||
UPDATE Inventory
|
||||
SET
|
||||
Quantity=@Quantity,
|
||||
IsDefect=@IsDefect,
|
||||
ComponentsId=@ComponentsId
|
||||
WHERE Id=@Id";
|
||||
connection.Execute(queryUpdate, inventory);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка при редактировании объекта");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
public void DeleteInventory(int id)
|
||||
{
|
||||
_logger.LogInformation("Удаление объекта");
|
||||
_logger.LogDebug("Объект:{id}", id);
|
||||
try
|
||||
{
|
||||
using var connection = new Npgsql.NpgsqlConnection(_connectionString.ConnectionString);
|
||||
connection.Open();
|
||||
var queryDelete = @"
|
||||
DELETE FROM Inventory
|
||||
WHERE Id=@id";
|
||||
connection.Execute(queryDelete, new { id });
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка при удалении объекта");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
public Inventory ReadInventoryById(int id)
|
||||
{
|
||||
_logger.LogInformation("Получение объекта по идентификатору");
|
||||
_logger.LogDebug("Объект: {id}", id);
|
||||
try
|
||||
{
|
||||
using var connection = new Npgsql.NpgsqlConnection(_connectionString.ConnectionString);
|
||||
var querySelect = @"
|
||||
SELECT * FROM Inventory
|
||||
WHERE Id=@id";
|
||||
var inventory = connection.QueryFirst<Inventory>(querySelect,
|
||||
new { id });
|
||||
_logger.LogDebug("Найденный объект: {json}", JsonConvert.SerializeObject(inventory));
|
||||
return inventory;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка при поиске объекта");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
public IEnumerable<Inventory> ReadInventory()
|
||||
{
|
||||
return [];
|
||||
}
|
||||
|
||||
public Inventory ReadInventoryById(int id)
|
||||
{
|
||||
return Inventory.CreateEntity(0, 0, false, 0);
|
||||
}
|
||||
|
||||
public void UpdateInventory(Inventory inventory)
|
||||
{
|
||||
_logger.LogInformation("Получение всех объектов");
|
||||
try
|
||||
{
|
||||
using var connection = new Npgsql.NpgsqlConnection(_connectionString.ConnectionString);
|
||||
connection.Open();
|
||||
var querySelect = "SELECT * FROM Inventory";
|
||||
var inventory = connection.Query<Inventory>(querySelect);
|
||||
_logger.LogDebug("Полученные объекты: {json}", JsonConvert.SerializeObject(inventory));
|
||||
return inventory;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка при чтении объектов");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,15 +1,56 @@
|
||||
using ProjectWarehouse.Entities;
|
||||
using Dapper;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Newtonsoft.Json;
|
||||
using ProjectWarehouse.Entities;
|
||||
|
||||
namespace ProjectWarehouse.Repositories.Implementations;
|
||||
|
||||
public class OrderRequestRepository : IOrderRequestRepository
|
||||
{
|
||||
private readonly IConnectionString _connectionString;
|
||||
|
||||
private readonly ILogger<OrderRequestRepository> _logger;
|
||||
|
||||
public OrderRequestRepository(IConnectionString connectionString, ILogger<OrderRequestRepository> logger)
|
||||
{
|
||||
_connectionString = connectionString;
|
||||
_logger = logger;
|
||||
}
|
||||
|
||||
public void CreateOrderRequest(OrderRequest orderRequest)
|
||||
{
|
||||
_logger.LogInformation("Добавление объекта");
|
||||
_logger.LogDebug("Объект: {json}", JsonConvert.SerializeObject(orderRequest));
|
||||
try
|
||||
{
|
||||
using var connection = new Npgsql.NpgsqlConnection(_connectionString.ConnectionString);
|
||||
var queryInsert = @"
|
||||
INSERT INTO OrderRequest (Quantity, DateOrder, ComponentsId)
|
||||
VALUES (@Quantity, @DateOrder, @ComponentsId)";
|
||||
connection.Execute(queryInsert, orderRequest);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка при добавлении объекта");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
public IEnumerable<OrderRequest> ReadOrderRequest(DateTime? dateForm = null, DateTime? dateTo = null, double? quantity = null, int? componentsID = null)
|
||||
{
|
||||
return [];
|
||||
_logger.LogInformation("Получение всех объектов");
|
||||
try
|
||||
{
|
||||
using var connection = new Npgsql.NpgsqlConnection(_connectionString.ConnectionString);
|
||||
var querySelect = "SELECT * FROM OrderRequest";
|
||||
var orderRequest = connection.Query<OrderRequest>(querySelect);
|
||||
_logger.LogDebug("Полученные объекты: {json}", JsonConvert.SerializeObject(orderRequest));
|
||||
return orderRequest;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка при чтении объектов");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,28 +1,94 @@
|
||||
using ProjectWarehouse.Entities;
|
||||
using Dapper;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Newtonsoft.Json;
|
||||
using ProjectWarehouse.Entities;
|
||||
|
||||
namespace ProjectWarehouse.Repositories.Implementations;
|
||||
|
||||
public class ProductionRepository : IProductionRepository
|
||||
{
|
||||
private readonly IConnectionString _connectionString;
|
||||
|
||||
private readonly ILogger<ProductionRepository> _logger;
|
||||
|
||||
public ProductionRepository(IConnectionString connectionString, ILogger<ProductionRepository> logger)
|
||||
{
|
||||
_connectionString = connectionString;
|
||||
_logger = logger;
|
||||
}
|
||||
|
||||
public void CreateProduction(Production production)
|
||||
{
|
||||
_logger.LogInformation("Добавление объекта");
|
||||
_logger.LogDebug("Объект: {json}", JsonConvert.SerializeObject(production));
|
||||
try
|
||||
{
|
||||
using var connection = new Npgsql.NpgsqlConnection(_connectionString.ConnectionString);
|
||||
connection.Open();
|
||||
using var transaction = connection.BeginTransaction();
|
||||
var queryInsert = @"
|
||||
INSERT INTO Production (Name, Description, EmployeeId)
|
||||
VALUES (@Name, @Description, @EmployeeId);
|
||||
SELECT MAX(id) FROM Production";
|
||||
var productionId = connection.QueryFirst<int>(queryInsert, production, transaction);
|
||||
var querySubInsert = @"
|
||||
INSERT INTO Components_Production (ComponentsId, Count)
|
||||
VALUES (@ComponentsId, @Count)";
|
||||
foreach (var elem in production.Components_Productions)
|
||||
{
|
||||
connection.Execute(querySubInsert, new
|
||||
{
|
||||
productionId,
|
||||
elem.ComponentsId,
|
||||
elem.Count
|
||||
}, transaction);
|
||||
}
|
||||
transaction.Commit();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка при добавлении объекта");
|
||||
throw;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public void DeleteProduction(int id)
|
||||
{
|
||||
_logger.LogInformation("Удаление объекта");
|
||||
_logger.LogDebug("Объект: {id}", id);
|
||||
try
|
||||
{
|
||||
using var connection = new Npgsql.NpgsqlConnection(_connectionString.ConnectionString);
|
||||
var queryDelete = @"
|
||||
DELETE FROM Production
|
||||
WHERE Id=@id";
|
||||
connection.Execute(queryDelete, new { id });
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка при удалении объекта");
|
||||
throw;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public IEnumerable<Production> ReadProduction()
|
||||
{
|
||||
return [];
|
||||
_logger.LogInformation("Получение всех объектов");
|
||||
try
|
||||
{
|
||||
using var connection = new Npgsql.NpgsqlConnection(_connectionString.ConnectionString);
|
||||
var querySelect = @"SELECT * FROM Production";
|
||||
var production =
|
||||
connection.Query<Production>(querySelect);
|
||||
_logger.LogDebug("Полученные объекты: {json}", JsonConvert.SerializeObject(production));
|
||||
return production;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка при чтении объектов");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
public Production ReadProductionByID(int id)
|
||||
{
|
||||
return Production.CreateEntity(0, string.Empty, string.Empty, 0, []);
|
||||
}
|
||||
|
||||
public void UpdateProduction(Production production)
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
15
ProjectWarehouse/ProjectWarehouse/appsettings.json
Normal file
15
ProjectWarehouse/ProjectWarehouse/appsettings.json
Normal file
@ -0,0 +1,15 @@
|
||||
{
|
||||
"Serilog": {
|
||||
"Using": [ "Serilog.Sinks.File" ],
|
||||
"MinimumLevel": "Debug",
|
||||
"WriteTo": [
|
||||
{
|
||||
"Name": "File",
|
||||
"Args": {
|
||||
"path": "Logs/warehouse_log.txt",
|
||||
"rollingInterval": "Day"
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user