diff --git a/TradeAndProcurementEnterprice/TradeAndProcurementEnterprice/Entities/Contract.cs b/TradeAndProcurementEnterprice/TradeAndProcurementEnterprice/Entities/Contract.cs index e6d4c35..c4178d9 100644 --- a/TradeAndProcurementEnterprice/TradeAndProcurementEnterprice/Entities/Contract.cs +++ b/TradeAndProcurementEnterprice/TradeAndProcurementEnterprice/Entities/Contract.cs @@ -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 diff --git a/TradeAndProcurementEnterprice/TradeAndProcurementEnterprice/Entities/Enums/Unit.cs b/TradeAndProcurementEnterprice/TradeAndProcurementEnterprice/Entities/Enums/Unit.cs index ca16b6b..1827b8f 100644 --- a/TradeAndProcurementEnterprice/TradeAndProcurementEnterprice/Entities/Enums/Unit.cs +++ b/TradeAndProcurementEnterprice/TradeAndProcurementEnterprice/Entities/Enums/Unit.cs @@ -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 } diff --git a/TradeAndProcurementEnterprice/TradeAndProcurementEnterprice/Entities/Product.cs b/TradeAndProcurementEnterprice/TradeAndProcurementEnterprice/Entities/Product.cs index 95a080f..d57c6d6 100644 --- a/TradeAndProcurementEnterprice/TradeAndProcurementEnterprice/Entities/Product.cs +++ b/TradeAndProcurementEnterprice/TradeAndProcurementEnterprice/Entities/Product.cs @@ -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, diff --git a/TradeAndProcurementEnterprice/TradeAndProcurementEnterprice/Forms/FormAgents.Designer.cs b/TradeAndProcurementEnterprice/TradeAndProcurementEnterprice/Forms/FormAgents.Designer.cs index 2cc2a35..b568e1c 100644 --- a/TradeAndProcurementEnterprice/TradeAndProcurementEnterprice/Forms/FormAgents.Designer.cs +++ b/TradeAndProcurementEnterprice/TradeAndProcurementEnterprice/Forms/FormAgents.Designer.cs @@ -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 = "Агенты-реализаторы"; diff --git a/TradeAndProcurementEnterprice/TradeAndProcurementEnterprice/Forms/FormContract.Designer.cs b/TradeAndProcurementEnterprice/TradeAndProcurementEnterprice/Forms/FormContract.Designer.cs index 2daca3b..55da1b5 100644 --- a/TradeAndProcurementEnterprice/TradeAndProcurementEnterprice/Forms/FormContract.Designer.cs +++ b/TradeAndProcurementEnterprice/TradeAndProcurementEnterprice/Forms/FormContract.Designer.cs @@ -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 = "Контракт"; diff --git a/TradeAndProcurementEnterprice/TradeAndProcurementEnterprice/Forms/FormContract.cs b/TradeAndProcurementEnterprice/TradeAndProcurementEnterprice/Forms/FormContract.cs index ad41ba6..460b49c 100644 --- a/TradeAndProcurementEnterprice/TradeAndProcurementEnterprice/Forms/FormContract.cs +++ b/TradeAndProcurementEnterprice/TradeAndProcurementEnterprice/Forms/FormContract.cs @@ -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; } diff --git a/TradeAndProcurementEnterprice/TradeAndProcurementEnterprice/Forms/FormContracts.Designer.cs b/TradeAndProcurementEnterprice/TradeAndProcurementEnterprice/Forms/FormContracts.Designer.cs index 6a4a595..fc33721 100644 --- a/TradeAndProcurementEnterprice/TradeAndProcurementEnterprice/Forms/FormContracts.Designer.cs +++ b/TradeAndProcurementEnterprice/TradeAndProcurementEnterprice/Forms/FormContracts.Designer.cs @@ -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 = "Продажи"; diff --git a/TradeAndProcurementEnterprice/TradeAndProcurementEnterprice/Forms/FormDelegateToAgent.cs b/TradeAndProcurementEnterprice/TradeAndProcurementEnterprice/Forms/FormDelegateToAgent.cs index 52b110b..71c8421 100644 --- a/TradeAndProcurementEnterprice/TradeAndProcurementEnterprice/Forms/FormDelegateToAgent.cs +++ b/TradeAndProcurementEnterprice/TradeAndProcurementEnterprice/Forms/FormDelegateToAgent.cs @@ -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) { diff --git a/TradeAndProcurementEnterprice/TradeAndProcurementEnterprice/Forms/FormDelegatesToAgents.Designer.cs b/TradeAndProcurementEnterprice/TradeAndProcurementEnterprice/Forms/FormDelegatesToAgents.Designer.cs index 119fddf..b533b8f 100644 --- a/TradeAndProcurementEnterprice/TradeAndProcurementEnterprice/Forms/FormDelegatesToAgents.Designer.cs +++ b/TradeAndProcurementEnterprice/TradeAndProcurementEnterprice/Forms/FormDelegatesToAgents.Designer.cs @@ -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 = "Передача товара агентам-реализаторам"; diff --git a/TradeAndProcurementEnterprice/TradeAndProcurementEnterprice/Forms/FormProduct.Designer.cs b/TradeAndProcurementEnterprice/TradeAndProcurementEnterprice/Forms/FormProduct.Designer.cs index d3e8586..b7cc616 100644 --- a/TradeAndProcurementEnterprice/TradeAndProcurementEnterprice/Forms/FormProduct.Designer.cs +++ b/TradeAndProcurementEnterprice/TradeAndProcurementEnterprice/Forms/FormProduct.Designer.cs @@ -28,12 +28,12 @@ /// 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; diff --git a/TradeAndProcurementEnterprice/TradeAndProcurementEnterprice/Forms/FormProduct.cs b/TradeAndProcurementEnterprice/TradeAndProcurementEnterprice/Forms/FormProduct.cs index b32d5ed..75b97f1 100644 --- a/TradeAndProcurementEnterprice/TradeAndProcurementEnterprice/Forms/FormProduct.cs +++ b/TradeAndProcurementEnterprice/TradeAndProcurementEnterprice/Forms/FormProduct.cs @@ -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)); } diff --git a/TradeAndProcurementEnterprice/TradeAndProcurementEnterprice/Forms/FormProducts.Designer.cs b/TradeAndProcurementEnterprice/TradeAndProcurementEnterprice/Forms/FormProducts.Designer.cs index 22a2a1a..9bc1838 100644 --- a/TradeAndProcurementEnterprice/TradeAndProcurementEnterprice/Forms/FormProducts.Designer.cs +++ b/TradeAndProcurementEnterprice/TradeAndProcurementEnterprice/Forms/FormProducts.Designer.cs @@ -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 = "Номенклатура"; diff --git a/TradeAndProcurementEnterprice/TradeAndProcurementEnterprice/Forms/FormPurchasingCompanies.Designer.cs b/TradeAndProcurementEnterprice/TradeAndProcurementEnterprice/Forms/FormPurchasingCompanies.Designer.cs index a0184c4..9ef3d6a 100644 --- a/TradeAndProcurementEnterprice/TradeAndProcurementEnterprice/Forms/FormPurchasingCompanies.Designer.cs +++ b/TradeAndProcurementEnterprice/TradeAndProcurementEnterprice/Forms/FormPurchasingCompanies.Designer.cs @@ -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 = "Компании закупщики"; diff --git a/TradeAndProcurementEnterprice/TradeAndProcurementEnterprice/Program.cs b/TradeAndProcurementEnterprice/TradeAndProcurementEnterprice/Program.cs index e0feeeb..b0d6347 100644 --- a/TradeAndProcurementEnterprice/TradeAndProcurementEnterprice/Program.cs +++ b/TradeAndProcurementEnterprice/TradeAndProcurementEnterprice/Program.cs @@ -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(new TransientLifetimeManager()); container.RegisterType(new TransientLifetimeManager()); container.RegisterType(new TransientLifetimeManager()); container.RegisterType(new TransientLifetimeManager()); container.RegisterType(new TransientLifetimeManager()); + container.RegisterType(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; + } } } \ No newline at end of file diff --git a/TradeAndProcurementEnterprice/TradeAndProcurementEnterprice/Repositories/IConnectionString.cs b/TradeAndProcurementEnterprice/TradeAndProcurementEnterprice/Repositories/IConnectionString.cs new file mode 100644 index 0000000..3353be2 --- /dev/null +++ b/TradeAndProcurementEnterprice/TradeAndProcurementEnterprice/Repositories/IConnectionString.cs @@ -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; } +} diff --git a/TradeAndProcurementEnterprice/TradeAndProcurementEnterprice/Repositories/IPurchasingCompanyRepository.cs b/TradeAndProcurementEnterprice/TradeAndProcurementEnterprice/Repositories/IPurchasingCompanyRepository.cs index 9c92ef4..de81bb7 100644 --- a/TradeAndProcurementEnterprice/TradeAndProcurementEnterprice/Repositories/IPurchasingCompanyRepository.cs +++ b/TradeAndProcurementEnterprice/TradeAndProcurementEnterprice/Repositories/IPurchasingCompanyRepository.cs @@ -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); } diff --git a/TradeAndProcurementEnterprice/TradeAndProcurementEnterprice/Repositories/Implementations/AgentsRepository.cs b/TradeAndProcurementEnterprice/TradeAndProcurementEnterprice/Repositories/Implementations/AgentsRepository.cs index 188c681..c78da09 100644 --- a/TradeAndProcurementEnterprice/TradeAndProcurementEnterprice/Repositories/Implementations/AgentsRepository.cs +++ b/TradeAndProcurementEnterprice/TradeAndProcurementEnterprice/Repositories/Implementations/AgentsRepository.cs @@ -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 _logger; + + public AgentsRepository(IConnectionString connectionString, ILogger 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(querySelect, new { id }); + _logger.LogDebug("Найденный объект: {json}", JsonConvert.SerializeObject(agent)); + return agent; + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка при поиске объекта!"); + throw; + } } public IEnumerable ReadAgents() { - return []; + _logger.LogInformation("Получение всех объектов."); + try + { + using var connection = new NpgsqlConnection(_connectionString.ConnectionString); + var querySelect = "SELECT * FROM Agents"; + var agents = connection.Query(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; + } } } diff --git a/TradeAndProcurementEnterprice/TradeAndProcurementEnterprice/Repositories/Implementations/ConnectionString.cs b/TradeAndProcurementEnterprice/TradeAndProcurementEnterprice/Repositories/Implementations/ConnectionString.cs new file mode 100644 index 0000000..47bef1f --- /dev/null +++ b/TradeAndProcurementEnterprice/TradeAndProcurementEnterprice/Repositories/Implementations/ConnectionString.cs @@ -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;"; +} diff --git a/TradeAndProcurementEnterprice/TradeAndProcurementEnterprice/Repositories/Implementations/ContractRepository.cs b/TradeAndProcurementEnterprice/TradeAndProcurementEnterprice/Repositories/Implementations/ContractRepository.cs index f261b2b..97b9a81 100644 --- a/TradeAndProcurementEnterprice/TradeAndProcurementEnterprice/Repositories/Implementations/ContractRepository.cs +++ b/TradeAndProcurementEnterprice/TradeAndProcurementEnterprice/Repositories/Implementations/ContractRepository.cs @@ -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 _logger; + + public ContractRepository(IConnectionString connectionString, ILogger 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(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 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(querySelect); + _logger.LogDebug("Полученные объекты: {json}", JsonConvert.SerializeObject(contracts)); + return contracts; + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка при чтении объектов!"); + throw; + } } } diff --git a/TradeAndProcurementEnterprice/TradeAndProcurementEnterprice/Repositories/Implementations/DelegateToAgentRepository.cs b/TradeAndProcurementEnterprice/TradeAndProcurementEnterprice/Repositories/Implementations/DelegateToAgentRepository.cs index 49625ca..0e76969 100644 --- a/TradeAndProcurementEnterprice/TradeAndProcurementEnterprice/Repositories/Implementations/DelegateToAgentRepository.cs +++ b/TradeAndProcurementEnterprice/TradeAndProcurementEnterprice/Repositories/Implementations/DelegateToAgentRepository.cs @@ -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 _logger; + + public DelegateToAgentRepository(IConnectionString connectionString, ILogger 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 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(querySelect); + _logger.LogDebug("Полученные объекты: {json}", JsonConvert.SerializeObject(delegatesToAgents)); + return delegatesToAgents; + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка при чтении объектов!"); + throw; + } } } diff --git a/TradeAndProcurementEnterprice/TradeAndProcurementEnterprice/Repositories/Implementations/ProductRepository.cs b/TradeAndProcurementEnterprice/TradeAndProcurementEnterprice/Repositories/Implementations/ProductRepository.cs index a34f1ab..dd3af83 100644 --- a/TradeAndProcurementEnterprice/TradeAndProcurementEnterprice/Repositories/Implementations/ProductRepository.cs +++ b/TradeAndProcurementEnterprice/TradeAndProcurementEnterprice/Repositories/Implementations/ProductRepository.cs @@ -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 _logger; + + public ProductRepository(IConnectionString connectionString, ILogger 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 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(querySelect, new { article }); + _logger.LogDebug("Найденный объект: {json}", JsonConvert.SerializeObject(product)); + return product; + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка при поиске объекта!"); + throw; + } + } + + public IEnumerable ReadProducts() + { + _logger.LogInformation("Получение всех объектов."); + try + { + using var connection = new NpgsqlConnection(_connectionString.ConnectionString); + + var querySelect = "SELECT * FROM Products"; + var products = connection.Query(querySelect); + _logger.LogDebug("Полученные объекты: {json}", JsonConvert.SerializeObject(products)); + return products; + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка при чтении объектов!"); + throw; + } } } diff --git a/TradeAndProcurementEnterprice/TradeAndProcurementEnterprice/Repositories/Implementations/PurchasingCompanyRepository.cs b/TradeAndProcurementEnterprice/TradeAndProcurementEnterprice/Repositories/Implementations/PurchasingCompanyRepository.cs index ed5b353..83a0ef8 100644 --- a/TradeAndProcurementEnterprice/TradeAndProcurementEnterprice/Repositories/Implementations/PurchasingCompanyRepository.cs +++ b/TradeAndProcurementEnterprice/TradeAndProcurementEnterprice/Repositories/Implementations/PurchasingCompanyRepository.cs @@ -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 _logger; + + public PurchasingCompanyRepository(IConnectionString connectionString, ILogger 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 ReadCompanies() { - return []; + _logger.LogInformation("Получение всех объектов."); + try + { + using var connection = new NpgsqlConnection(_connectionString.ConnectionString); + var querySelect = "SELECT * FROM purchasingCompanies"; + var companies = connection.Query(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(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; + } } } diff --git a/TradeAndProcurementEnterprice/TradeAndProcurementEnterprice/TradeAndProcurementEnterprice.csproj b/TradeAndProcurementEnterprice/TradeAndProcurementEnterprice/TradeAndProcurementEnterprice.csproj index 0f76343..a82cacf 100644 --- a/TradeAndProcurementEnterprice/TradeAndProcurementEnterprice/TradeAndProcurementEnterprice.csproj +++ b/TradeAndProcurementEnterprice/TradeAndProcurementEnterprice/TradeAndProcurementEnterprice.csproj @@ -10,7 +10,19 @@ + + + + + + + + + + + + @@ -28,4 +40,10 @@ + + + PreserveNewest + + + \ No newline at end of file diff --git a/TradeAndProcurementEnterprice/TradeAndProcurementEnterprice/appsettings.json b/TradeAndProcurementEnterprice/TradeAndProcurementEnterprice/appsettings.json new file mode 100644 index 0000000..9c45c34 --- /dev/null +++ b/TradeAndProcurementEnterprice/TradeAndProcurementEnterprice/appsettings.json @@ -0,0 +1,15 @@ +{ + "Serilog": { + "Using": [ "Serilog.Sinks.File" ], + "MinimumLevel": "Debug", + "WriteTo": [ + { + "Name": "File", + "Args": { + "path": "Logs/enterprice_log.txt", + "rollingInterval": "Day" + } + } + ] + } +} \ No newline at end of file