Лаба 2 готовая.
This commit is contained in:
parent
699bc69f48
commit
48e06960a8
@ -10,7 +10,7 @@ public class Contract
|
||||
{
|
||||
public int ContractID { get; private set; }
|
||||
|
||||
public DateTime SaleTime { get; private set; }
|
||||
public DateTime SaleDate { get; private set; }
|
||||
|
||||
public int PurchasingCompanyID { get; private set; }
|
||||
|
||||
@ -23,7 +23,7 @@ public class Contract
|
||||
return new Contract
|
||||
{
|
||||
ContractID = contractID,
|
||||
SaleTime = DateTime.Now,
|
||||
SaleDate = DateTime.Now,
|
||||
PurchasingCompanyID = purchasingCompanyID,
|
||||
AgentsID = agentsID,
|
||||
ProductSales = productSales
|
||||
|
@ -8,7 +8,8 @@ namespace TradeAndProcurementEnterprice.Entities.Enums;
|
||||
|
||||
public enum Unit
|
||||
{
|
||||
Kilogram = 0,
|
||||
Piece = 1,
|
||||
Liter = 2
|
||||
None = 0,
|
||||
Kilogram = 1,
|
||||
Piece = 2,
|
||||
Liter = 3
|
||||
}
|
||||
|
@ -11,7 +11,7 @@ public class Product
|
||||
{
|
||||
public int Article { get; private set; }
|
||||
|
||||
public string Nomenclature { get; private set; } = string.Empty;
|
||||
public string Name { get; private set; } = string.Empty;
|
||||
|
||||
public decimal SellingPrice { get; private set; }
|
||||
|
||||
@ -21,13 +21,13 @@ public class Product
|
||||
|
||||
public int InventoryQuantity { get; private set; }
|
||||
|
||||
public static Product CreateEntity(int article, string nomenclature, decimal sellingPrice, Unit unit,
|
||||
public static Product CreateEntity(int article, string name, decimal sellingPrice, Unit unit,
|
||||
Category category, int inventoryQuantity)
|
||||
{
|
||||
return new Product
|
||||
{
|
||||
Article = article,
|
||||
Nomenclature = nomenclature ?? string.Empty,
|
||||
Name = name ?? string.Empty,
|
||||
SellingPrice = sellingPrice,
|
||||
Unit = unit,
|
||||
Category = category,
|
||||
|
@ -43,20 +43,18 @@
|
||||
panel1.Controls.Add(buttonEdit);
|
||||
panel1.Controls.Add(buttonAdd);
|
||||
panel1.Dock = DockStyle.Right;
|
||||
panel1.Location = new Point(1196, 0);
|
||||
panel1.Margin = new Padding(6, 6, 6, 6);
|
||||
panel1.Location = new Point(644, 0);
|
||||
panel1.Name = "panel1";
|
||||
panel1.Size = new Size(178, 929);
|
||||
panel1.Size = new Size(96, 435);
|
||||
panel1.TabIndex = 0;
|
||||
//
|
||||
// buttonDel
|
||||
//
|
||||
buttonDel.BackgroundImage = Properties.Resources.remove;
|
||||
buttonDel.BackgroundImageLayout = ImageLayout.Stretch;
|
||||
buttonDel.Location = new Point(32, 390);
|
||||
buttonDel.Margin = new Padding(6, 6, 6, 6);
|
||||
buttonDel.Location = new Point(17, 183);
|
||||
buttonDel.Name = "buttonDel";
|
||||
buttonDel.Size = new Size(121, 139);
|
||||
buttonDel.Size = new Size(65, 65);
|
||||
buttonDel.TabIndex = 3;
|
||||
buttonDel.UseVisualStyleBackColor = true;
|
||||
buttonDel.Click += ButtonDel_Click;
|
||||
@ -65,10 +63,9 @@
|
||||
//
|
||||
buttonEdit.BackgroundImage = Properties.Resources.edit;
|
||||
buttonEdit.BackgroundImageLayout = ImageLayout.Stretch;
|
||||
buttonEdit.Location = new Point(32, 203);
|
||||
buttonEdit.Margin = new Padding(6, 6, 6, 6);
|
||||
buttonEdit.Location = new Point(17, 95);
|
||||
buttonEdit.Name = "buttonEdit";
|
||||
buttonEdit.Size = new Size(121, 139);
|
||||
buttonEdit.Size = new Size(65, 65);
|
||||
buttonEdit.TabIndex = 2;
|
||||
buttonEdit.UseVisualStyleBackColor = true;
|
||||
buttonEdit.Click += ButtonEdit_Click;
|
||||
@ -77,10 +74,9 @@
|
||||
//
|
||||
buttonAdd.BackgroundImage = Properties.Resources.add;
|
||||
buttonAdd.BackgroundImageLayout = ImageLayout.Stretch;
|
||||
buttonAdd.Location = new Point(32, 26);
|
||||
buttonAdd.Margin = new Padding(6, 6, 6, 6);
|
||||
buttonAdd.Location = new Point(17, 12);
|
||||
buttonAdd.Name = "buttonAdd";
|
||||
buttonAdd.Size = new Size(121, 139);
|
||||
buttonAdd.Size = new Size(65, 65);
|
||||
buttonAdd.TabIndex = 1;
|
||||
buttonAdd.UseVisualStyleBackColor = true;
|
||||
buttonAdd.Click += ButtonAdd_Click;
|
||||
@ -95,25 +91,24 @@
|
||||
dataGridViewData.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize;
|
||||
dataGridViewData.Dock = DockStyle.Fill;
|
||||
dataGridViewData.Location = new Point(0, 0);
|
||||
dataGridViewData.Margin = new Padding(6, 6, 6, 6);
|
||||
dataGridViewData.MultiSelect = false;
|
||||
dataGridViewData.Name = "dataGridViewData";
|
||||
dataGridViewData.ReadOnly = true;
|
||||
dataGridViewData.RowHeadersVisible = false;
|
||||
dataGridViewData.RowHeadersWidth = 82;
|
||||
dataGridViewData.RowTemplate.Height = 25;
|
||||
dataGridViewData.Size = new Size(1196, 929);
|
||||
dataGridViewData.SelectionMode = DataGridViewSelectionMode.FullRowSelect;
|
||||
dataGridViewData.Size = new Size(644, 435);
|
||||
dataGridViewData.TabIndex = 1;
|
||||
//
|
||||
// FormAgents
|
||||
//
|
||||
AutoScaleDimensions = new SizeF(13F, 32F);
|
||||
AutoScaleDimensions = new SizeF(7F, 15F);
|
||||
AutoScaleMode = AutoScaleMode.Font;
|
||||
ClientSize = new Size(1374, 929);
|
||||
ClientSize = new Size(740, 435);
|
||||
Controls.Add(dataGridViewData);
|
||||
Controls.Add(panel1);
|
||||
Margin = new Padding(6, 6, 6, 6);
|
||||
MinimumSize = new Size(1000, 630);
|
||||
MinimumSize = new Size(546, 316);
|
||||
Name = "FormAgents";
|
||||
StartPosition = FormStartPosition.CenterParent;
|
||||
Text = "Агенты-реализаторы";
|
||||
|
@ -45,10 +45,9 @@
|
||||
// buttonCancel
|
||||
//
|
||||
buttonCancel.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
|
||||
buttonCancel.Location = new Point(292, 653);
|
||||
buttonCancel.Margin = new Padding(6);
|
||||
buttonCancel.Location = new Point(293, 306);
|
||||
buttonCancel.Name = "buttonCancel";
|
||||
buttonCancel.Size = new Size(156, 49);
|
||||
buttonCancel.Size = new Size(84, 23);
|
||||
buttonCancel.TabIndex = 32;
|
||||
buttonCancel.Text = "Отмена";
|
||||
buttonCancel.UseVisualStyleBackColor = true;
|
||||
@ -57,10 +56,9 @@
|
||||
// buttonSave
|
||||
//
|
||||
buttonSave.Anchor = AnchorStyles.Bottom | AnchorStyles.Left;
|
||||
buttonSave.Location = new Point(50, 653);
|
||||
buttonSave.Margin = new Padding(6);
|
||||
buttonSave.Location = new Point(27, 306);
|
||||
buttonSave.Name = "buttonSave";
|
||||
buttonSave.Size = new Size(156, 49);
|
||||
buttonSave.Size = new Size(84, 23);
|
||||
buttonSave.TabIndex = 33;
|
||||
buttonSave.Text = "Сохранить";
|
||||
buttonSave.UseVisualStyleBackColor = true;
|
||||
@ -71,10 +69,9 @@
|
||||
comboBoxPurchasingCompany.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
|
||||
comboBoxPurchasingCompany.DropDownStyle = ComboBoxStyle.DropDownList;
|
||||
comboBoxPurchasingCompany.FormattingEnabled = true;
|
||||
comboBoxPurchasingCompany.Location = new Point(221, 34);
|
||||
comboBoxPurchasingCompany.Margin = new Padding(6);
|
||||
comboBoxPurchasingCompany.Location = new Point(119, 16);
|
||||
comboBoxPurchasingCompany.Name = "comboBoxPurchasingCompany";
|
||||
comboBoxPurchasingCompany.Size = new Size(241, 40);
|
||||
comboBoxPurchasingCompany.Size = new Size(268, 23);
|
||||
comboBoxPurchasingCompany.TabIndex = 29;
|
||||
//
|
||||
// comboBoxAgent
|
||||
@ -82,27 +79,24 @@
|
||||
comboBoxAgent.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
|
||||
comboBoxAgent.DropDownStyle = ComboBoxStyle.DropDownList;
|
||||
comboBoxAgent.FormattingEnabled = true;
|
||||
comboBoxAgent.Location = new Point(221, 126);
|
||||
comboBoxAgent.Margin = new Padding(6);
|
||||
comboBoxAgent.Location = new Point(119, 59);
|
||||
comboBoxAgent.Name = "comboBoxAgent";
|
||||
comboBoxAgent.Size = new Size(241, 40);
|
||||
comboBoxAgent.Size = new Size(268, 23);
|
||||
comboBoxAgent.TabIndex = 30;
|
||||
//
|
||||
// labelAgent
|
||||
//
|
||||
labelAgent.Location = new Point(39, 111);
|
||||
labelAgent.Margin = new Padding(6, 0, 6, 0);
|
||||
labelAgent.Location = new Point(21, 52);
|
||||
labelAgent.Name = "labelAgent";
|
||||
labelAgent.Size = new Size(167, 77);
|
||||
labelAgent.Size = new Size(90, 36);
|
||||
labelAgent.TabIndex = 27;
|
||||
labelAgent.Text = "Агент-\r\nреализатор";
|
||||
//
|
||||
// labelPurchatingCompany
|
||||
//
|
||||
labelPurchatingCompany.Location = new Point(43, 23);
|
||||
labelPurchatingCompany.Margin = new Padding(6, 0, 6, 0);
|
||||
labelPurchatingCompany.Location = new Point(23, 11);
|
||||
labelPurchatingCompany.Name = "labelPurchatingCompany";
|
||||
labelPurchatingCompany.Size = new Size(163, 68);
|
||||
labelPurchatingCompany.Size = new Size(88, 32);
|
||||
labelPurchatingCompany.TabIndex = 28;
|
||||
labelPurchatingCompany.Text = "Компания закупщик";
|
||||
//
|
||||
@ -110,11 +104,9 @@
|
||||
//
|
||||
groupBox1.Anchor = AnchorStyles.Top | AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right;
|
||||
groupBox1.Controls.Add(dataGridViewProduct);
|
||||
groupBox1.Location = new Point(43, 218);
|
||||
groupBox1.Margin = new Padding(6);
|
||||
groupBox1.Location = new Point(23, 102);
|
||||
groupBox1.Name = "groupBox1";
|
||||
groupBox1.Padding = new Padding(6);
|
||||
groupBox1.Size = new Size(422, 422);
|
||||
groupBox1.Size = new Size(363, 198);
|
||||
groupBox1.TabIndex = 34;
|
||||
groupBox1.TabStop = false;
|
||||
groupBox1.Text = "Продукт";
|
||||
@ -126,15 +118,14 @@
|
||||
dataGridViewProduct.Anchor = AnchorStyles.Top | AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right;
|
||||
dataGridViewProduct.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize;
|
||||
dataGridViewProduct.Columns.AddRange(new DataGridViewColumn[] { ColumnProduct, ColumnQuantity });
|
||||
dataGridViewProduct.Location = new Point(6, 41);
|
||||
dataGridViewProduct.Margin = new Padding(6);
|
||||
dataGridViewProduct.Location = new Point(3, 19);
|
||||
dataGridViewProduct.MultiSelect = false;
|
||||
dataGridViewProduct.Name = "dataGridViewProduct";
|
||||
dataGridViewProduct.RowHeadersVisible = false;
|
||||
dataGridViewProduct.RowHeadersWidth = 82;
|
||||
dataGridViewProduct.RowTemplate.Height = 25;
|
||||
dataGridViewProduct.SelectionMode = DataGridViewSelectionMode.FullRowSelect;
|
||||
dataGridViewProduct.Size = new Size(404, 375);
|
||||
dataGridViewProduct.Size = new Size(354, 176);
|
||||
dataGridViewProduct.TabIndex = 0;
|
||||
//
|
||||
// ColumnProduct
|
||||
@ -153,9 +144,9 @@
|
||||
//
|
||||
// FormContract
|
||||
//
|
||||
AutoScaleDimensions = new SizeF(13F, 32F);
|
||||
AutoScaleDimensions = new SizeF(7F, 15F);
|
||||
AutoScaleMode = AutoScaleMode.Font;
|
||||
ClientSize = new Size(497, 727);
|
||||
ClientSize = new Size(404, 341);
|
||||
Controls.Add(groupBox1);
|
||||
Controls.Add(buttonCancel);
|
||||
Controls.Add(buttonSave);
|
||||
@ -163,8 +154,7 @@
|
||||
Controls.Add(comboBoxAgent);
|
||||
Controls.Add(labelAgent);
|
||||
Controls.Add(labelPurchatingCompany);
|
||||
Margin = new Padding(6);
|
||||
MinimumSize = new Size(480, 730);
|
||||
MinimumSize = new Size(266, 363);
|
||||
Name = "FormContract";
|
||||
StartPosition = FormStartPosition.CenterParent;
|
||||
Text = "Контракт";
|
||||
|
@ -33,7 +33,7 @@ namespace TradeAndProcurementEnterprice.Forms
|
||||
comboBoxAgent.ValueMember = "Id";
|
||||
|
||||
ColumnProduct.DataSource = productRepository.ReadProducts();
|
||||
ColumnProduct.DisplayMember = "Nomenclature";
|
||||
ColumnProduct.DisplayMember = "Name";
|
||||
ColumnProduct.ValueMember = "Article";
|
||||
}
|
||||
|
||||
@ -48,6 +48,7 @@ namespace TradeAndProcurementEnterprice.Forms
|
||||
|
||||
_contractRepository.CreateContract(Contract.CreateOperation(0,
|
||||
(int)comboBoxPurchasingCompany.SelectedValue!, (int)comboBoxAgent.SelectedValue!, CreateListProductSalesFromDataGrid()));
|
||||
Close();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
@ -67,7 +68,7 @@ namespace TradeAndProcurementEnterprice.Forms
|
||||
continue;
|
||||
}
|
||||
|
||||
list.Add(ProductSales.CreateElement(0, Convert.ToInt32(row.Cells["ColumnProduct"]), Convert.ToInt32(row.Cells["ColumnQuantity"])));
|
||||
list.Add(ProductSales.CreateElement(0, Convert.ToInt32(row.Cells["ColumnProduct"].Value), Convert.ToInt32(row.Cells["ColumnQuantity"].Value)));
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
@ -39,20 +39,18 @@
|
||||
//
|
||||
panel1.Controls.Add(buttonAdd);
|
||||
panel1.Dock = DockStyle.Right;
|
||||
panel1.Location = new Point(1196, 0);
|
||||
panel1.Margin = new Padding(6, 6, 6, 6);
|
||||
panel1.Location = new Point(644, 0);
|
||||
panel1.Name = "panel1";
|
||||
panel1.Size = new Size(178, 929);
|
||||
panel1.Size = new Size(96, 435);
|
||||
panel1.TabIndex = 0;
|
||||
//
|
||||
// buttonAdd
|
||||
//
|
||||
buttonAdd.BackgroundImage = Properties.Resources.add;
|
||||
buttonAdd.BackgroundImageLayout = ImageLayout.Stretch;
|
||||
buttonAdd.Location = new Point(32, 26);
|
||||
buttonAdd.Margin = new Padding(6, 6, 6, 6);
|
||||
buttonAdd.Location = new Point(17, 12);
|
||||
buttonAdd.Name = "buttonAdd";
|
||||
buttonAdd.Size = new Size(121, 139);
|
||||
buttonAdd.Size = new Size(65, 65);
|
||||
buttonAdd.TabIndex = 1;
|
||||
buttonAdd.UseVisualStyleBackColor = true;
|
||||
buttonAdd.Click += ButtonAdd_Click;
|
||||
@ -67,25 +65,24 @@
|
||||
dataGridViewData.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize;
|
||||
dataGridViewData.Dock = DockStyle.Fill;
|
||||
dataGridViewData.Location = new Point(0, 0);
|
||||
dataGridViewData.Margin = new Padding(6, 6, 6, 6);
|
||||
dataGridViewData.MultiSelect = false;
|
||||
dataGridViewData.Name = "dataGridViewData";
|
||||
dataGridViewData.ReadOnly = true;
|
||||
dataGridViewData.RowHeadersVisible = false;
|
||||
dataGridViewData.RowHeadersWidth = 82;
|
||||
dataGridViewData.RowTemplate.Height = 25;
|
||||
dataGridViewData.Size = new Size(1196, 929);
|
||||
dataGridViewData.SelectionMode = DataGridViewSelectionMode.FullRowSelect;
|
||||
dataGridViewData.Size = new Size(644, 435);
|
||||
dataGridViewData.TabIndex = 1;
|
||||
//
|
||||
// FormContracts
|
||||
//
|
||||
AutoScaleDimensions = new SizeF(13F, 32F);
|
||||
AutoScaleDimensions = new SizeF(7F, 15F);
|
||||
AutoScaleMode = AutoScaleMode.Font;
|
||||
ClientSize = new Size(1374, 929);
|
||||
ClientSize = new Size(740, 435);
|
||||
Controls.Add(dataGridViewData);
|
||||
Controls.Add(panel1);
|
||||
Margin = new Padding(6, 6, 6, 6);
|
||||
MinimumSize = new Size(1000, 630);
|
||||
MinimumSize = new Size(546, 316);
|
||||
Name = "FormContracts";
|
||||
StartPosition = FormStartPosition.CenterParent;
|
||||
Text = "Продажи";
|
||||
|
@ -24,7 +24,7 @@ namespace TradeAndProcurementEnterprice.Forms
|
||||
throw new ArgumentNullException(nameof(delegateToAgentRepository));
|
||||
|
||||
comboBoxProduct.DataSource = productRepository.ReadProducts();
|
||||
comboBoxProduct.DisplayMember = "Nomenclature";
|
||||
comboBoxProduct.DisplayMember = "Name";
|
||||
comboBoxProduct.ValueMember = "Article";
|
||||
|
||||
comboBoxAgent.DataSource = agentsRepository.ReadAgents();
|
||||
@ -44,6 +44,7 @@ namespace TradeAndProcurementEnterprice.Forms
|
||||
_delegateToAgentRepository.CreateDelegatesToAgent(DelegateToAgents.CreateOperation(0,
|
||||
(int)comboBoxProduct.SelectedValue!, Convert.ToInt32(numericUpDownQuantity.Value),
|
||||
(int)comboBoxAgent.SelectedValue!));
|
||||
Close();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
|
@ -39,20 +39,18 @@
|
||||
//
|
||||
panel1.Controls.Add(buttonAdd);
|
||||
panel1.Dock = DockStyle.Right;
|
||||
panel1.Location = new Point(1196, 0);
|
||||
panel1.Margin = new Padding(6, 6, 6, 6);
|
||||
panel1.Location = new Point(644, 0);
|
||||
panel1.Name = "panel1";
|
||||
panel1.Size = new Size(178, 929);
|
||||
panel1.Size = new Size(96, 435);
|
||||
panel1.TabIndex = 0;
|
||||
//
|
||||
// buttonAdd
|
||||
//
|
||||
buttonAdd.BackgroundImage = Properties.Resources.add;
|
||||
buttonAdd.BackgroundImageLayout = ImageLayout.Stretch;
|
||||
buttonAdd.Location = new Point(32, 26);
|
||||
buttonAdd.Margin = new Padding(6, 6, 6, 6);
|
||||
buttonAdd.Location = new Point(17, 12);
|
||||
buttonAdd.Name = "buttonAdd";
|
||||
buttonAdd.Size = new Size(121, 139);
|
||||
buttonAdd.Size = new Size(65, 65);
|
||||
buttonAdd.TabIndex = 1;
|
||||
buttonAdd.UseVisualStyleBackColor = true;
|
||||
buttonAdd.Click += ButtonAdd_Click;
|
||||
@ -67,25 +65,24 @@
|
||||
dataGridViewData.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize;
|
||||
dataGridViewData.Dock = DockStyle.Fill;
|
||||
dataGridViewData.Location = new Point(0, 0);
|
||||
dataGridViewData.Margin = new Padding(6, 6, 6, 6);
|
||||
dataGridViewData.MultiSelect = false;
|
||||
dataGridViewData.Name = "dataGridViewData";
|
||||
dataGridViewData.ReadOnly = true;
|
||||
dataGridViewData.RowHeadersVisible = false;
|
||||
dataGridViewData.RowHeadersWidth = 82;
|
||||
dataGridViewData.RowTemplate.Height = 25;
|
||||
dataGridViewData.Size = new Size(1196, 929);
|
||||
dataGridViewData.SelectionMode = DataGridViewSelectionMode.FullRowSelect;
|
||||
dataGridViewData.Size = new Size(644, 435);
|
||||
dataGridViewData.TabIndex = 1;
|
||||
//
|
||||
// FormDelegatesToAgents
|
||||
//
|
||||
AutoScaleDimensions = new SizeF(13F, 32F);
|
||||
AutoScaleDimensions = new SizeF(7F, 15F);
|
||||
AutoScaleMode = AutoScaleMode.Font;
|
||||
ClientSize = new Size(1374, 929);
|
||||
ClientSize = new Size(740, 435);
|
||||
Controls.Add(dataGridViewData);
|
||||
Controls.Add(panel1);
|
||||
Margin = new Padding(6, 6, 6, 6);
|
||||
MinimumSize = new Size(1000, 630);
|
||||
MinimumSize = new Size(546, 316);
|
||||
Name = "FormDelegatesToAgents";
|
||||
StartPosition = FormStartPosition.CenterParent;
|
||||
Text = "Передача товара агентам-реализаторам";
|
||||
|
@ -28,12 +28,12 @@
|
||||
/// </summary>
|
||||
private void InitializeComponent()
|
||||
{
|
||||
labelNomenclature = new Label();
|
||||
labelName = new Label();
|
||||
labelPrice = new Label();
|
||||
labelUnit = new Label();
|
||||
labelCategory = new Label();
|
||||
labelInventoryQuantity = new Label();
|
||||
textBoxNomenclature = new TextBox();
|
||||
textBoxName = new TextBox();
|
||||
numericUpDownPrice = new NumericUpDown();
|
||||
comboBoxUnit = new ComboBox();
|
||||
numericUpDownQuantity = new NumericUpDown();
|
||||
@ -44,14 +44,14 @@
|
||||
((System.ComponentModel.ISupportInitialize)numericUpDownQuantity).BeginInit();
|
||||
SuspendLayout();
|
||||
//
|
||||
// labelNomenclature
|
||||
// labelName
|
||||
//
|
||||
labelNomenclature.AutoSize = true;
|
||||
labelNomenclature.Location = new Point(26, 27);
|
||||
labelNomenclature.Name = "labelNomenclature";
|
||||
labelNomenclature.Size = new Size(180, 33);
|
||||
labelNomenclature.TabIndex = 0;
|
||||
labelNomenclature.Text = "Номенклатура";
|
||||
labelName.AutoSize = true;
|
||||
labelName.Location = new Point(26, 27);
|
||||
labelName.Name = "labelName";
|
||||
labelName.Size = new Size(180, 33);
|
||||
labelName.TabIndex = 0;
|
||||
labelName.Text = "Номенклатура";
|
||||
//
|
||||
// labelPrice
|
||||
//
|
||||
@ -86,19 +86,20 @@
|
||||
labelInventoryQuantity.TabIndex = 0;
|
||||
labelInventoryQuantity.Text = "Количество на складе";
|
||||
//
|
||||
// textBoxNomenclature
|
||||
// textBoxName
|
||||
//
|
||||
textBoxNomenclature.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
|
||||
textBoxNomenclature.Location = new Point(248, 24);
|
||||
textBoxNomenclature.Name = "textBoxNomenclature";
|
||||
textBoxNomenclature.Size = new Size(237, 41);
|
||||
textBoxNomenclature.TabIndex = 1;
|
||||
textBoxName.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
|
||||
textBoxName.Location = new Point(248, 24);
|
||||
textBoxName.Name = "textBoxName";
|
||||
textBoxName.Size = new Size(237, 41);
|
||||
textBoxName.TabIndex = 1;
|
||||
//
|
||||
// numericUpDownPrice
|
||||
//
|
||||
numericUpDownPrice.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
|
||||
numericUpDownPrice.DecimalPlaces = 2;
|
||||
numericUpDownPrice.Location = new Point(248, 100);
|
||||
numericUpDownPrice.Maximum = new decimal(new int[] { 1000000, 0, 0, 0 });
|
||||
numericUpDownPrice.Name = "numericUpDownPrice";
|
||||
numericUpDownPrice.Size = new Size(237, 41);
|
||||
numericUpDownPrice.TabIndex = 2;
|
||||
@ -165,12 +166,12 @@
|
||||
Controls.Add(numericUpDownQuantity);
|
||||
Controls.Add(comboBoxUnit);
|
||||
Controls.Add(numericUpDownPrice);
|
||||
Controls.Add(textBoxNomenclature);
|
||||
Controls.Add(textBoxName);
|
||||
Controls.Add(labelInventoryQuantity);
|
||||
Controls.Add(labelCategory);
|
||||
Controls.Add(labelUnit);
|
||||
Controls.Add(labelPrice);
|
||||
Controls.Add(labelNomenclature);
|
||||
Controls.Add(labelName);
|
||||
Font = new Font("Comic Sans MS", 9F, FontStyle.Regular, GraphicsUnit.Point);
|
||||
MinimumSize = new Size(585, 585);
|
||||
Name = "FormProduct";
|
||||
@ -184,12 +185,12 @@
|
||||
|
||||
#endregion
|
||||
|
||||
private Label labelNomenclature;
|
||||
private Label labelName;
|
||||
private Label labelPrice;
|
||||
private Label labelUnit;
|
||||
private Label labelCategory;
|
||||
private Label labelInventoryQuantity;
|
||||
private TextBox textBoxNomenclature;
|
||||
private TextBox textBoxName;
|
||||
private NumericUpDown numericUpDownPrice;
|
||||
private ComboBox comboBoxUnit;
|
||||
private NumericUpDown numericUpDownQuantity;
|
||||
|
@ -31,7 +31,7 @@ namespace TradeAndProcurementEnterprice.Forms
|
||||
throw new InvalidDataException(nameof(product));
|
||||
}
|
||||
|
||||
textBoxNomenclature.Text = product.Nomenclature;
|
||||
textBoxName.Text = product.Name;
|
||||
numericUpDownPrice.Value = product.SellingPrice;
|
||||
comboBoxUnit.SelectedItem = product.Unit;
|
||||
comboBoxCategory.SelectedItem = product.Category;
|
||||
@ -60,7 +60,7 @@ namespace TradeAndProcurementEnterprice.Forms
|
||||
{
|
||||
try
|
||||
{
|
||||
if (string.IsNullOrEmpty(textBoxNomenclature.Text) || comboBoxUnit.SelectedIndex < 1
|
||||
if (string.IsNullOrEmpty(textBoxName.Text) || comboBoxUnit.SelectedIndex < 1
|
||||
|| comboBoxCategory.SelectedIndex < 1)
|
||||
{
|
||||
throw new Exception("Имеются незаполненные поля!");
|
||||
@ -85,7 +85,7 @@ namespace TradeAndProcurementEnterprice.Forms
|
||||
|
||||
private void ButtonCancel_Click(object sender, EventArgs e) => Close();
|
||||
|
||||
private Product CreateProduct(int article) => Product.CreateEntity(article, textBoxNomenclature.Text,
|
||||
private Product CreateProduct(int article) => Product.CreateEntity(article, textBoxName.Text,
|
||||
numericUpDownPrice.Value, (Unit)comboBoxUnit.SelectedItem, (Category)comboBoxCategory.SelectedItem,
|
||||
Convert.ToInt32(numericUpDownQuantity.Value));
|
||||
}
|
||||
|
@ -43,20 +43,18 @@
|
||||
panel1.Controls.Add(buttonEdit);
|
||||
panel1.Controls.Add(buttonAdd);
|
||||
panel1.Dock = DockStyle.Right;
|
||||
panel1.Location = new Point(1196, 0);
|
||||
panel1.Margin = new Padding(6, 6, 6, 6);
|
||||
panel1.Location = new Point(644, 0);
|
||||
panel1.Name = "panel1";
|
||||
panel1.Size = new Size(178, 929);
|
||||
panel1.Size = new Size(96, 435);
|
||||
panel1.TabIndex = 0;
|
||||
//
|
||||
// buttonDel
|
||||
//
|
||||
buttonDel.BackgroundImage = Properties.Resources.remove;
|
||||
buttonDel.BackgroundImageLayout = ImageLayout.Stretch;
|
||||
buttonDel.Location = new Point(32, 390);
|
||||
buttonDel.Margin = new Padding(6, 6, 6, 6);
|
||||
buttonDel.Location = new Point(17, 183);
|
||||
buttonDel.Name = "buttonDel";
|
||||
buttonDel.Size = new Size(121, 139);
|
||||
buttonDel.Size = new Size(65, 65);
|
||||
buttonDel.TabIndex = 3;
|
||||
buttonDel.UseVisualStyleBackColor = true;
|
||||
buttonDel.Click += ButtonDel_Click;
|
||||
@ -65,10 +63,9 @@
|
||||
//
|
||||
buttonEdit.BackgroundImage = Properties.Resources.edit;
|
||||
buttonEdit.BackgroundImageLayout = ImageLayout.Stretch;
|
||||
buttonEdit.Location = new Point(32, 203);
|
||||
buttonEdit.Margin = new Padding(6, 6, 6, 6);
|
||||
buttonEdit.Location = new Point(17, 95);
|
||||
buttonEdit.Name = "buttonEdit";
|
||||
buttonEdit.Size = new Size(121, 139);
|
||||
buttonEdit.Size = new Size(65, 65);
|
||||
buttonEdit.TabIndex = 2;
|
||||
buttonEdit.UseVisualStyleBackColor = true;
|
||||
buttonEdit.Click += ButtonEdit_Click;
|
||||
@ -77,10 +74,9 @@
|
||||
//
|
||||
buttonAdd.BackgroundImage = Properties.Resources.add;
|
||||
buttonAdd.BackgroundImageLayout = ImageLayout.Stretch;
|
||||
buttonAdd.Location = new Point(32, 26);
|
||||
buttonAdd.Margin = new Padding(6, 6, 6, 6);
|
||||
buttonAdd.Location = new Point(17, 12);
|
||||
buttonAdd.Name = "buttonAdd";
|
||||
buttonAdd.Size = new Size(121, 139);
|
||||
buttonAdd.Size = new Size(65, 65);
|
||||
buttonAdd.TabIndex = 1;
|
||||
buttonAdd.UseVisualStyleBackColor = true;
|
||||
buttonAdd.Click += ButtonAdd_Click;
|
||||
@ -95,25 +91,24 @@
|
||||
dataGridViewData.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize;
|
||||
dataGridViewData.Dock = DockStyle.Fill;
|
||||
dataGridViewData.Location = new Point(0, 0);
|
||||
dataGridViewData.Margin = new Padding(6, 6, 6, 6);
|
||||
dataGridViewData.MultiSelect = false;
|
||||
dataGridViewData.Name = "dataGridViewData";
|
||||
dataGridViewData.ReadOnly = true;
|
||||
dataGridViewData.RowHeadersVisible = false;
|
||||
dataGridViewData.RowHeadersWidth = 82;
|
||||
dataGridViewData.RowTemplate.Height = 25;
|
||||
dataGridViewData.Size = new Size(1196, 929);
|
||||
dataGridViewData.SelectionMode = DataGridViewSelectionMode.FullRowSelect;
|
||||
dataGridViewData.Size = new Size(644, 435);
|
||||
dataGridViewData.TabIndex = 1;
|
||||
//
|
||||
// FormProducts
|
||||
//
|
||||
AutoScaleDimensions = new SizeF(13F, 32F);
|
||||
AutoScaleDimensions = new SizeF(7F, 15F);
|
||||
AutoScaleMode = AutoScaleMode.Font;
|
||||
ClientSize = new Size(1374, 929);
|
||||
ClientSize = new Size(740, 435);
|
||||
Controls.Add(dataGridViewData);
|
||||
Controls.Add(panel1);
|
||||
Margin = new Padding(6, 6, 6, 6);
|
||||
MinimumSize = new Size(1000, 630);
|
||||
MinimumSize = new Size(546, 316);
|
||||
Name = "FormProducts";
|
||||
StartPosition = FormStartPosition.CenterParent;
|
||||
Text = "Номенклатура";
|
||||
|
@ -43,20 +43,18 @@
|
||||
panel1.Controls.Add(buttonEdit);
|
||||
panel1.Controls.Add(buttonAdd);
|
||||
panel1.Dock = DockStyle.Right;
|
||||
panel1.Location = new Point(1196, 0);
|
||||
panel1.Margin = new Padding(6, 6, 6, 6);
|
||||
panel1.Location = new Point(644, 0);
|
||||
panel1.Name = "panel1";
|
||||
panel1.Size = new Size(178, 929);
|
||||
panel1.Size = new Size(96, 435);
|
||||
panel1.TabIndex = 0;
|
||||
//
|
||||
// buttonDel
|
||||
//
|
||||
buttonDel.BackgroundImage = Properties.Resources.remove;
|
||||
buttonDel.BackgroundImageLayout = ImageLayout.Stretch;
|
||||
buttonDel.Location = new Point(32, 390);
|
||||
buttonDel.Margin = new Padding(6, 6, 6, 6);
|
||||
buttonDel.Location = new Point(17, 183);
|
||||
buttonDel.Name = "buttonDel";
|
||||
buttonDel.Size = new Size(121, 139);
|
||||
buttonDel.Size = new Size(65, 65);
|
||||
buttonDel.TabIndex = 3;
|
||||
buttonDel.UseVisualStyleBackColor = true;
|
||||
buttonDel.Click += ButtonDel_Click;
|
||||
@ -65,10 +63,9 @@
|
||||
//
|
||||
buttonEdit.BackgroundImage = Properties.Resources.edit;
|
||||
buttonEdit.BackgroundImageLayout = ImageLayout.Stretch;
|
||||
buttonEdit.Location = new Point(32, 203);
|
||||
buttonEdit.Margin = new Padding(6, 6, 6, 6);
|
||||
buttonEdit.Location = new Point(17, 95);
|
||||
buttonEdit.Name = "buttonEdit";
|
||||
buttonEdit.Size = new Size(121, 139);
|
||||
buttonEdit.Size = new Size(65, 65);
|
||||
buttonEdit.TabIndex = 2;
|
||||
buttonEdit.UseVisualStyleBackColor = true;
|
||||
buttonEdit.Click += ButtonEdit_Click;
|
||||
@ -77,10 +74,9 @@
|
||||
//
|
||||
buttonAdd.BackgroundImage = Properties.Resources.add;
|
||||
buttonAdd.BackgroundImageLayout = ImageLayout.Stretch;
|
||||
buttonAdd.Location = new Point(32, 26);
|
||||
buttonAdd.Margin = new Padding(6, 6, 6, 6);
|
||||
buttonAdd.Location = new Point(17, 12);
|
||||
buttonAdd.Name = "buttonAdd";
|
||||
buttonAdd.Size = new Size(121, 139);
|
||||
buttonAdd.Size = new Size(65, 65);
|
||||
buttonAdd.TabIndex = 1;
|
||||
buttonAdd.UseVisualStyleBackColor = true;
|
||||
buttonAdd.Click += ButtonAdd_Click;
|
||||
@ -95,25 +91,24 @@
|
||||
dataGridViewData.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize;
|
||||
dataGridViewData.Dock = DockStyle.Fill;
|
||||
dataGridViewData.Location = new Point(0, 0);
|
||||
dataGridViewData.Margin = new Padding(6, 6, 6, 6);
|
||||
dataGridViewData.MultiSelect = false;
|
||||
dataGridViewData.Name = "dataGridViewData";
|
||||
dataGridViewData.ReadOnly = true;
|
||||
dataGridViewData.RowHeadersVisible = false;
|
||||
dataGridViewData.RowHeadersWidth = 82;
|
||||
dataGridViewData.RowTemplate.Height = 25;
|
||||
dataGridViewData.Size = new Size(1196, 929);
|
||||
dataGridViewData.SelectionMode = DataGridViewSelectionMode.FullRowSelect;
|
||||
dataGridViewData.Size = new Size(644, 435);
|
||||
dataGridViewData.TabIndex = 1;
|
||||
//
|
||||
// FormPurchasingCompanies
|
||||
//
|
||||
AutoScaleDimensions = new SizeF(13F, 32F);
|
||||
AutoScaleDimensions = new SizeF(7F, 15F);
|
||||
AutoScaleMode = AutoScaleMode.Font;
|
||||
ClientSize = new Size(1374, 929);
|
||||
ClientSize = new Size(740, 435);
|
||||
Controls.Add(dataGridViewData);
|
||||
Controls.Add(panel1);
|
||||
Margin = new Padding(6, 6, 6, 6);
|
||||
MinimumSize = new Size(1000, 630);
|
||||
MinimumSize = new Size(546, 316);
|
||||
Name = "FormPurchasingCompanies";
|
||||
StartPosition = FormStartPosition.CenterParent;
|
||||
Text = "Компании закупщики";
|
||||
|
@ -1,7 +1,11 @@
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Serilog;
|
||||
using TradeAndProcurementEnterprice.Repositories;
|
||||
using TradeAndProcurementEnterprice.Repositories.Implementations;
|
||||
using Unity;
|
||||
using Unity.Lifetime;
|
||||
using Unity.Microsoft.Logging;
|
||||
|
||||
namespace TradeAndProcurementEnterprice
|
||||
{
|
||||
@ -23,13 +27,29 @@ namespace TradeAndProcurementEnterprice
|
||||
{
|
||||
var container = new UnityContainer();
|
||||
|
||||
container.AddExtension(new LoggingExtension(CreateLoggerFactory()));
|
||||
|
||||
container.RegisterType<IAgentsRepository, AgentsRepository>(new TransientLifetimeManager());
|
||||
container.RegisterType<IContractRepository, ContractRepository>(new TransientLifetimeManager());
|
||||
container.RegisterType<IProductRepository, ProductRepository>(new TransientLifetimeManager());
|
||||
container.RegisterType<IPurchasingCompanyRepository, PurchasingCompanyRepository>(new TransientLifetimeManager());
|
||||
container.RegisterType<IDelegateToAgentRepository, DelegateToAgentRepository>(new TransientLifetimeManager());
|
||||
|
||||
container.RegisterType<IConnectionString, ConnectionString>(new SingletonLifetimeManager());
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,12 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace TradeAndProcurementEnterprice.Repositories;
|
||||
|
||||
public interface IConnectionString
|
||||
{
|
||||
public string ConnectionString { get; }
|
||||
}
|
@ -13,9 +13,9 @@ public interface IPurchasingCompanyRepository
|
||||
|
||||
PurchasingCompany ReadCompaniesByID(int id);
|
||||
|
||||
void CreateCompany(PurchasingCompany agent);
|
||||
void CreateCompany(PurchasingCompany company);
|
||||
|
||||
void UpdateCompanies(PurchasingCompany agent);
|
||||
void UpdateCompanies(PurchasingCompany company);
|
||||
|
||||
void DeleteCompany(int id);
|
||||
}
|
||||
|
@ -1,5 +1,10 @@
|
||||
using System;
|
||||
using Dapper;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Newtonsoft.Json;
|
||||
using Npgsql;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Data.SqlClient;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
@ -7,27 +12,122 @@ using TradeAndProcurementEnterprice.Entities;
|
||||
|
||||
namespace TradeAndProcurementEnterprice.Repositories.Implementations;
|
||||
|
||||
public class AgentsRepository : IAgentsRepository
|
||||
internal class AgentsRepository : IAgentsRepository
|
||||
{
|
||||
private readonly IConnectionString _connectionString;
|
||||
|
||||
private readonly ILogger<AgentsRepository> _logger;
|
||||
|
||||
public AgentsRepository(IConnectionString connectionString, ILogger<AgentsRepository> logger)
|
||||
{
|
||||
_connectionString = connectionString;
|
||||
_logger = logger;
|
||||
}
|
||||
|
||||
public void CreateAgent(Agent agent)
|
||||
{
|
||||
_logger.LogInformation("Добавление объекта.");
|
||||
_logger.LogDebug("Объект: {json}", JsonConvert.SerializeObject(agent));
|
||||
|
||||
try
|
||||
{
|
||||
using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
|
||||
|
||||
var queryInsert = @"
|
||||
INSERT INTO Agents (Name, Qualification, Category)
|
||||
VALUES (@Name, @Qualification, @Category)";
|
||||
connection.Execute(queryInsert, agent);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка при добавлении объекта!");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
public void DeleteAgent(int id)
|
||||
{
|
||||
_logger.LogInformation("Удаление объекта.");
|
||||
_logger.LogDebug("Объект: {id}", id);
|
||||
try
|
||||
{
|
||||
using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
|
||||
|
||||
var queryDelete = @"
|
||||
DELETE FROM Agents
|
||||
WHERE Id=@id";
|
||||
connection.Execute(queryDelete, new { id });
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка при удалении объекта!");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
public Agent ReadAgentByID(int id)
|
||||
{
|
||||
return Agent.CreateEntity(0, string.Empty, Entities.Enums.Qualification.Junior, Entities.Enums.Category.Other);
|
||||
_logger.LogInformation("Получение объекта по идентификатору.");
|
||||
_logger.LogDebug("Объект: {id}", id);
|
||||
try
|
||||
{
|
||||
using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
|
||||
var querySelect = @"
|
||||
SELECT * FROM Agents
|
||||
WHERE Id=@id";
|
||||
var agent = connection.QueryFirst<Agent>(querySelect, new { id });
|
||||
_logger.LogDebug("Найденный объект: {json}", JsonConvert.SerializeObject(agent));
|
||||
return agent;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка при поиске объекта!");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
public IEnumerable<Agent> ReadAgents()
|
||||
{
|
||||
return [];
|
||||
_logger.LogInformation("Получение всех объектов.");
|
||||
try
|
||||
{
|
||||
using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
|
||||
var querySelect = "SELECT * FROM Agents";
|
||||
var agents = connection.Query<Agent>(querySelect);
|
||||
_logger.LogDebug("Полученные объекты: {json}", JsonConvert.SerializeObject(agents));
|
||||
|
||||
return agents;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка при чтении объектов!");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
public void UpdateAgent(Agent agent)
|
||||
{
|
||||
_logger.LogInformation("Редактирование объекта.");
|
||||
_logger.LogDebug("Объект: {json}", JsonConvert.SerializeObject(agent));
|
||||
|
||||
try
|
||||
{
|
||||
using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
|
||||
|
||||
var queryUpdate = @"
|
||||
UPDATE Agents
|
||||
SET
|
||||
Name=@Name,
|
||||
Qualification=@Qualification,
|
||||
Category=@Category
|
||||
WHERE Id=@Id";
|
||||
connection.Execute(queryUpdate, agent);
|
||||
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка при редактировании объекта!");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,12 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace TradeAndProcurementEnterprice.Repositories.Implementations;
|
||||
|
||||
public class ConnectionString : IConnectionString
|
||||
{
|
||||
string IConnectionString.ConnectionString => "Server=localhost, 5432;Database=enterprice;Username=postgres;Password=maria;";
|
||||
}
|
@ -1,5 +1,10 @@
|
||||
using System;
|
||||
using Dapper;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Newtonsoft.Json;
|
||||
using Npgsql;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Data.SqlClient;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
@ -7,14 +12,66 @@ using TradeAndProcurementEnterprice.Entities;
|
||||
|
||||
namespace TradeAndProcurementEnterprice.Repositories.Implementations;
|
||||
|
||||
public class ContractRepository : IContractRepository
|
||||
internal class ContractRepository : IContractRepository
|
||||
{
|
||||
private readonly IConnectionString _connectionString;
|
||||
|
||||
private readonly ILogger<ContractRepository> _logger;
|
||||
|
||||
public ContractRepository(IConnectionString connectionString, ILogger<ContractRepository> logger)
|
||||
{
|
||||
_connectionString = connectionString;
|
||||
_logger = logger;
|
||||
}
|
||||
|
||||
public void CreateContract(Contract contract)
|
||||
{
|
||||
_logger.LogInformation("Добавление объекта.");
|
||||
_logger.LogDebug("Объект: {json}", JsonConvert.SerializeObject(contract));
|
||||
try
|
||||
{
|
||||
using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
|
||||
connection.Open();
|
||||
using var transaction = connection.BeginTransaction();
|
||||
var queryInsert = @"
|
||||
INSERT INTO Contracts (SaleDate, PurchasingCompanyID, AgentsID)
|
||||
VALUES (@SaleDate, @PurchasingCompanyID, @AgentsID);
|
||||
SELECT MAX(contractid) FROM Contracts";
|
||||
var contractId = connection.QueryFirst<int>(queryInsert, contract, transaction);
|
||||
|
||||
var querySubInsert = @"
|
||||
INSERT INTO ProductSales (ContractId, ProductArticle, ProductQuantity)
|
||||
VALUES (@ContractId, @ProductArticle, @ProductQuantity)";
|
||||
|
||||
foreach (var elem in contract.ProductSales)
|
||||
{
|
||||
connection.Execute(querySubInsert, new { contractId, elem.ProductArticle, elem.ProductQuantity }, transaction);
|
||||
}
|
||||
|
||||
transaction.Commit();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка при добавлении объекта!");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
public IEnumerable<Contract> ReadContracts(DateTime? dateFrom = null, DateTime? dateTo = null, int? productArticle = null, int? agentID = null, int? purchasingCompaniID = null)
|
||||
{
|
||||
return [];
|
||||
_logger.LogInformation("Получение всех объектов.");
|
||||
try
|
||||
{
|
||||
using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
|
||||
var querySelect = "SELECT * FROM Contracts";
|
||||
var contracts = connection.Query<Contract>(querySelect);
|
||||
_logger.LogDebug("Полученные объекты: {json}", JsonConvert.SerializeObject(contracts));
|
||||
return contracts;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка при чтении объектов!");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,5 +1,10 @@
|
||||
using System;
|
||||
using Dapper;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Newtonsoft.Json;
|
||||
using Npgsql;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Data.SqlClient;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
@ -7,14 +12,52 @@ using TradeAndProcurementEnterprice.Entities;
|
||||
|
||||
namespace TradeAndProcurementEnterprice.Repositories.Implementations;
|
||||
|
||||
public class DelegateToAgentRepository : IDelegateToAgentRepository
|
||||
internal class DelegateToAgentRepository : IDelegateToAgentRepository
|
||||
{
|
||||
private readonly IConnectionString _connectionString;
|
||||
|
||||
private readonly ILogger<DelegateToAgentRepository> _logger;
|
||||
|
||||
public DelegateToAgentRepository(IConnectionString connectionString, ILogger<DelegateToAgentRepository> logger)
|
||||
{
|
||||
_connectionString = connectionString;
|
||||
_logger = logger;
|
||||
}
|
||||
|
||||
public void CreateDelegatesToAgent(DelegateToAgents delegateToAgents)
|
||||
{
|
||||
_logger.LogInformation("Добавление объекта.");
|
||||
_logger.LogDebug("Объект: {json}", JsonConvert.SerializeObject(delegateToAgents));
|
||||
try
|
||||
{
|
||||
using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
|
||||
var queryInsert = @"
|
||||
INSERT INTO DelegateToAgents (ProductArticle, AgentsID, Quantity, Date)
|
||||
VALUES (@ProductArticle, @AgentsID, @Quantity, @Date)";
|
||||
connection.Execute(queryInsert, delegateToAgents);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка при добавлении объекта!");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
public IEnumerable<DelegateToAgents> ReadDelegatesToAgent(DateTime? dateFrom = null, DateTime? dateTo = null, int? productArticle = null, int? agentID = null)
|
||||
{
|
||||
return [];
|
||||
_logger.LogInformation("Получение всех объектов.");
|
||||
try
|
||||
{
|
||||
using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
|
||||
var querySelect = "SELECT * FROM DelegateToAgents";
|
||||
var delegatesToAgents = connection.Query<DelegateToAgents>(querySelect);
|
||||
_logger.LogDebug("Полученные объекты: {json}", JsonConvert.SerializeObject(delegatesToAgents));
|
||||
return delegatesToAgents;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка при чтении объектов!");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,5 +1,10 @@
|
||||
using System;
|
||||
using Dapper;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Newtonsoft.Json;
|
||||
using Npgsql;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Data.SqlClient;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
@ -7,27 +12,125 @@ using TradeAndProcurementEnterprice.Entities;
|
||||
|
||||
namespace TradeAndProcurementEnterprice.Repositories.Implementations;
|
||||
|
||||
public class ProductRepository : IProductRepository
|
||||
internal class ProductRepository : IProductRepository
|
||||
{
|
||||
private readonly IConnectionString _connectionString;
|
||||
|
||||
private readonly ILogger<ProductRepository> _logger;
|
||||
|
||||
public ProductRepository(IConnectionString connectionString, ILogger<ProductRepository> logger)
|
||||
{
|
||||
_connectionString = connectionString;
|
||||
_logger = logger;
|
||||
}
|
||||
|
||||
public void CreateProduct(Product product)
|
||||
{
|
||||
}
|
||||
_logger.LogInformation("Добавление объекта.");
|
||||
_logger.LogDebug("Объект: {json}", JsonConvert.SerializeObject(product));
|
||||
|
||||
public void DeleteProduct(int article)
|
||||
{
|
||||
}
|
||||
try
|
||||
{
|
||||
using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
|
||||
|
||||
public Product ReadProductByArticle(int article)
|
||||
{
|
||||
return Product.CreateEntity(0, string.Empty, 0, Entities.Enums.Unit.Piece, Entities.Enums.Category.Other, 0);
|
||||
}
|
||||
var queryInsert = @"
|
||||
INSERT INTO Products (Name, SellingPrice, Unit, Category, InventoryQuantity)
|
||||
VALUES (@Name, @SellingPrice, @Unit, @Category, @InventoryQuantity)";
|
||||
|
||||
public IEnumerable<Product> ReadProducts()
|
||||
{
|
||||
return [];
|
||||
connection.Execute(queryInsert, product);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка при добавлении объекта!");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
public void UpdateProduct(Product product)
|
||||
{
|
||||
_logger.LogInformation("Редактирование объекта.");
|
||||
_logger.LogDebug("Объект: {json}", JsonConvert.SerializeObject(product));
|
||||
|
||||
try
|
||||
{
|
||||
using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
|
||||
|
||||
var queryUpdate = @"
|
||||
UPDATE Products
|
||||
SET
|
||||
Name=@Name,
|
||||
SellingPrice=@SellingPrice,
|
||||
Unit=@Unit,
|
||||
Category=@Category,
|
||||
InventoryQuantity=@InventoryQuantity
|
||||
WHERE Article=@article";
|
||||
connection.Execute(queryUpdate, product);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка при редактировании объекта!");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
public void DeleteProduct(int article)
|
||||
{
|
||||
_logger.LogInformation("Удаление объекта.");
|
||||
_logger.LogDebug("Объект: {article}", article);
|
||||
|
||||
try
|
||||
{
|
||||
using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
|
||||
var queryDelete = @"
|
||||
DELETE FROM Products
|
||||
WHERE Article=@article";
|
||||
connection.Execute(queryDelete, new { article });
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка при удалении объекта!");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
public Product ReadProductByArticle(int article)
|
||||
{
|
||||
_logger.LogInformation("Получение объекта по идентификатору.");
|
||||
_logger.LogDebug("Объект: {article}", article);
|
||||
try
|
||||
{
|
||||
using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
|
||||
|
||||
var querySelect = @"
|
||||
SELECT * FROM Products
|
||||
WHERE Article=@article";
|
||||
var product = connection.QueryFirst<Product>(querySelect, new { article });
|
||||
_logger.LogDebug("Найденный объект: {json}", JsonConvert.SerializeObject(product));
|
||||
return product;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка при поиске объекта!");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
public IEnumerable<Product> ReadProducts()
|
||||
{
|
||||
_logger.LogInformation("Получение всех объектов.");
|
||||
try
|
||||
{
|
||||
using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
|
||||
|
||||
var querySelect = "SELECT * FROM Products";
|
||||
var products = connection.Query<Product>(querySelect);
|
||||
_logger.LogDebug("Полученные объекты: {json}", JsonConvert.SerializeObject(products));
|
||||
return products;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка при чтении объектов!");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,5 +1,10 @@
|
||||
using System;
|
||||
using Dapper;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Newtonsoft.Json;
|
||||
using Npgsql;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Data.SqlClient;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
@ -7,27 +12,114 @@ using TradeAndProcurementEnterprice.Entities;
|
||||
|
||||
namespace TradeAndProcurementEnterprice.Repositories.Implementations;
|
||||
|
||||
public class PurchasingCompanyRepository : IPurchasingCompanyRepository
|
||||
internal class PurchasingCompanyRepository : IPurchasingCompanyRepository
|
||||
{
|
||||
public void CreateCompany(PurchasingCompany agent)
|
||||
private readonly IConnectionString _connectionString;
|
||||
|
||||
private readonly ILogger<PurchasingCompanyRepository> _logger;
|
||||
|
||||
public PurchasingCompanyRepository(IConnectionString connectionString, ILogger<PurchasingCompanyRepository> logger)
|
||||
{
|
||||
_connectionString = connectionString;
|
||||
_logger = logger;
|
||||
}
|
||||
|
||||
public void CreateCompany(PurchasingCompany company)
|
||||
{
|
||||
_logger.LogInformation("Добавление объекта.");
|
||||
_logger.LogDebug("Объект: {json}", JsonConvert.SerializeObject(company));
|
||||
|
||||
try
|
||||
{
|
||||
using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
|
||||
var queryInsert = @"
|
||||
INSERT INTO PurchasingCompanies (Name)
|
||||
VALUES (@Name)";
|
||||
connection.Execute(queryInsert, company);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка при добавлении объекта!");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
public void DeleteCompany(int id)
|
||||
{
|
||||
_logger.LogInformation("Удаление объекта.");
|
||||
_logger.LogDebug("Объект: {id}", id);
|
||||
try
|
||||
{
|
||||
using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
|
||||
var queryDelete = @"
|
||||
DELETE FROM purchasingCompanies
|
||||
WHERE Id=@id";
|
||||
connection.Execute(queryDelete, new { id });
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка при удалении объекта!");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
public IEnumerable<PurchasingCompany> ReadCompanies()
|
||||
{
|
||||
return [];
|
||||
_logger.LogInformation("Получение всех объектов.");
|
||||
try
|
||||
{
|
||||
using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
|
||||
var querySelect = "SELECT * FROM purchasingCompanies";
|
||||
var companies = connection.Query<PurchasingCompany>(querySelect);
|
||||
_logger.LogDebug("Полученные объекты: {json}", JsonConvert.SerializeObject(companies));
|
||||
return companies;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка при чтении объектов!");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
public PurchasingCompany ReadCompaniesByID(int id)
|
||||
{
|
||||
return PurchasingCompany.CreateEntity(0, string.Empty);
|
||||
_logger.LogInformation("Получение объекта по идентификатору.");
|
||||
_logger.LogDebug("Объект: {id}", id);
|
||||
try
|
||||
{
|
||||
using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
|
||||
var querySelect = @"
|
||||
SELECT * FROM PurchasingCompanies
|
||||
WHERE Id=@id";
|
||||
var company = connection.QueryFirst<PurchasingCompany>(querySelect, new { id });
|
||||
_logger.LogDebug("Найденный объект: {json}", JsonConvert.SerializeObject(company));
|
||||
return company;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка при поиске объекта!");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
public void UpdateCompanies(PurchasingCompany agent)
|
||||
public void UpdateCompanies(PurchasingCompany company)
|
||||
{
|
||||
_logger.LogInformation("Редактирование объекта.");
|
||||
_logger.LogDebug("Объект: {json}", JsonConvert.SerializeObject(company));
|
||||
try
|
||||
{
|
||||
using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
|
||||
var queryUpdate = @"
|
||||
UPDATE PurchasingCompanies
|
||||
SET
|
||||
Name=@Name
|
||||
WHERE Id=@Id";
|
||||
connection.Execute(queryUpdate, company);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка при редактировании объекта!");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -10,7 +10,19 @@
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Dapper" Version="2.1.35" />
|
||||
<PackageReference Include="Microsoft.Extensions.Configuration" Version="8.0.0" />
|
||||
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="8.0.1" />
|
||||
<PackageReference Include="Microsoft.Extensions.Logging" Version="8.0.1" />
|
||||
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
|
||||
<PackageReference Include="Npgsql" Version="9.0.2" />
|
||||
<PackageReference Include="Serilog" Version="4.0.2" />
|
||||
<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="System.Data.SqlClient" Version="4.9.0" />
|
||||
<PackageReference Include="Unity" Version="5.11.10" />
|
||||
<PackageReference Include="Unity.Microsoft.Logging" Version="5.11.1" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
@ -28,4 +40,10 @@
|
||||
</EmbeddedResource>
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<None Update="appsettings.json">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</None>
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
@ -0,0 +1,15 @@
|
||||
{
|
||||
"Serilog": {
|
||||
"Using": [ "Serilog.Sinks.File" ],
|
||||
"MinimumLevel": "Debug",
|
||||
"WriteTo": [
|
||||
{
|
||||
"Name": "File",
|
||||
"Args": {
|
||||
"path": "Logs/enterprice_log.txt",
|
||||
"rollingInterval": "Day"
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user