Лабораторная работа №2

This commit is contained in:
Anitonchik 2024-11-15 15:23:00 +04:00
parent 46658bd340
commit 7a0c58ab6c
15 changed files with 45 additions and 37 deletions

View File

@ -19,7 +19,7 @@ public class Invoice
public int SellingPrice { get; set; }
DateTime Data { get; set; }
DateTime DateInvoice { get; set; }
public IEnumerable<InvoiceProduct> Products
{
@ -37,7 +37,7 @@ public class Invoice
AvailabilityOfPromotionalCode = availabilityOfPromotionalCode,
DiscountPercentage = discountPercentage,
SellingPrice = sellingPrice,
Data = DateTime.Now,
DateInvoice = DateTime.Now,
Products = products
};
}

View File

@ -14,8 +14,6 @@ public class InvoiceProduct
public int Count { get; private set; }
public int SellingPrice { get; private set; }
public static InvoiceProduct CreateElement(int invoiceId, int productID, int count)
{
return new InvoiceProduct

View File

@ -55,9 +55,7 @@ namespace ProjectCompanyFurniture.Forms
{
try
{
if (string.IsNullOrWhiteSpace(textBoxName.Text)
|| checkBoxOptYes.Checked == false
|| comboBoxClientType.SelectedIndex < 1)
if (string.IsNullOrWhiteSpace(textBoxName.Text) || comboBoxClientType.SelectedIndex < 1)
{
throw new Exception("Имеются незаполненные поля");
}

View File

@ -129,6 +129,7 @@
// numericUpDownDiscPercentage
//
numericUpDownDiscPercentage.Location = new Point(213, 141);
numericUpDownDiscPercentage.Maximum = new decimal(new int[] { 1000000, 0, 0, 0 });
numericUpDownDiscPercentage.Name = "numericUpDownDiscPercentage";
numericUpDownDiscPercentage.Size = new Size(150, 27);
numericUpDownDiscPercentage.TabIndex = 20;
@ -154,6 +155,7 @@
// numericUpDownSellingPrice
//
numericUpDownSellingPrice.Location = new Point(212, 194);
numericUpDownSellingPrice.Maximum = new decimal(new int[] { 10000000, 0, 0, 0 });
numericUpDownSellingPrice.Name = "numericUpDownSellingPrice";
numericUpDownSellingPrice.Size = new Size(151, 27);
numericUpDownSellingPrice.TabIndex = 23;

View File

@ -24,7 +24,7 @@ namespace ProjectCompanyFurniture.Forms
throw new ArgumentNullException(nameof(invoiceRepository));
comboBoxClient.DataSource = clientRepository.ReadClients();
comboBoxClient.DisplayMember = "FirstName";
comboBoxClient.DisplayMember = "Name";
comboBoxClient.ValueMember = "ID";
ColumnProduct.DataSource = productRepository.ReadProducts();
@ -36,7 +36,7 @@ namespace ProjectCompanyFurniture.Forms
{
try
{
if (dataGridViewProducts.RowCount < 1 || comboBoxClient.SelectedIndex < 0 || checkBoxPromYes.Checked == false)
if (dataGridViewProducts.RowCount < 1 || comboBoxClient.SelectedIndex < 0)
{
throw new Exception("Имеются незаполненные поля");
}

View File

@ -85,6 +85,7 @@
// numericUpDownStartPrice
//
numericUpDownStartPrice.Location = new Point(211, 220);
numericUpDownStartPrice.Maximum = new decimal(new int[] { 1000000, 0, 0, 0 });
numericUpDownStartPrice.Name = "numericUpDownStartPrice";
numericUpDownStartPrice.Size = new Size(125, 27);
numericUpDownStartPrice.TabIndex = 5;

View File

@ -42,7 +42,7 @@ namespace ProjectCompanyFurniture.Forms
_productRepository = productRepository ?? throw new ArgumentNullException(nameof(productRepository));
comboBoxManufacturer.DataSource = manufacturerRepository.ReadManufacturers();
comboBoxManufacturer.DisplayMember = "FirstName";
comboBoxManufacturer.DisplayMember = "Name";
comboBoxManufacturer.ValueMember = "Id";
}

View File

@ -59,7 +59,7 @@ namespace ProjectCompanyFurniture.Forms
}
try
{
var form = _container.Resolve<FormClient>();
var form = _container.Resolve<FormProduct>();
form.Id = findId;
form.ShowDialog();
LoadList();

View File

@ -18,6 +18,7 @@
<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="Sstv.Outbox.Npgsql" Version="2.0.0" />
<PackageReference Include="System.Data.SqlClient" Version="4.9.0" />
<PackageReference Include="Unity" Version="5.11.10" />
<PackageReference Include="Unity.Container" Version="5.11.11" />

View File

@ -1,6 +1,7 @@
using Dapper;
using Microsoft.Extensions.Logging;
using Newtonsoft.Json;
using Npgsql;
using ProjectCompanyFurniture.Entities;
using ProjectCompanyFurniture.Entities.Enums;
using System;
@ -29,7 +30,7 @@ public class ClientRepository : IClientRepository
_logger.LogDebug("Объект: {json}", JsonConvert.SerializeObject(client));
try
{
using var connection = new SqlConnection(_connectionString.ConnectionString);
using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
var queryInsert = @"INSERT INTO Clients (Name, ClientType, Optovik)
VALUES (@Name, @ClientType, @Optovik)";
connection.Execute(queryInsert, client);
@ -48,7 +49,7 @@ public class ClientRepository : IClientRepository
JsonConvert.SerializeObject(client));
try
{
using var connection = new SqlConnection(_connectionString.ConnectionString);
using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
var queryUpdate = @"UPDATE Clients SET
Name=@Name,
ClientType=@ClientType,
@ -69,7 +70,7 @@ public class ClientRepository : IClientRepository
_logger.LogDebug("Объект: {id}", id);
try
{
using var connection = new SqlConnection(_connectionString.ConnectionString);
using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
var queryDelete = @"DELETE FROM Clients WHERE ID=@id";
connection.Execute(queryDelete, new { id });
}
@ -86,7 +87,7 @@ public class ClientRepository : IClientRepository
_logger.LogDebug("Объект: {id}", id);
try
{
using var connection = new SqlConnection(_connectionString.ConnectionString);
using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
var querySelect = @"SELECT * FROM Clients WHERE [ID]=@id";
var client = connection.QueryFirst<Client>(querySelect, new
{
@ -108,7 +109,7 @@ public class ClientRepository : IClientRepository
_logger.LogInformation("Получение всех объектов");
try
{
using var connection = new SqlConnection(_connectionString.ConnectionString);
using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
var querySelect = "SELECT * FROM Clients";
var clients = connection.Query<Client>(querySelect);
_logger.LogDebug("Полученные объекты: {json}",

View File

@ -8,5 +8,8 @@ namespace ProjectCompanyFurniture.Repositories.Implementations;
public class ConnectionString : IConnectionString
{
string IConnectionString.ConnectionString => "Driver={PostgreSQL};Server=localhost;Port=5432;Database=furnitureotp;Uid=postgres;Pwd=postgres";
string IConnectionString.ConnectionString =>
"Server=localhost, 5432;Database=furnitureotp;Uid=postgres;Pwd=postgres;"
/*"Server=localhost;Port=5432Database=furnitureotp;"*/
/* "Host=localhost;Port=5432;Database=furnitureotp;Username=postgres;Password=postgres;"*/;
}

View File

@ -1,6 +1,7 @@
using Dapper;
using Microsoft.Extensions.Logging;
using Newtonsoft.Json;
using Npgsql;
using ProjectCompanyFurniture.Entities;
using System;
using System.Collections.Generic;
@ -28,14 +29,14 @@ public class InvoiceRepository : IInvoiceRepository
_logger.LogDebug("Объект: {json}", JsonConvert.SerializeObject(invoice));
try
{
using var connection = new SqlConnection(_connectionString.ConnectionString);
using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
connection.Open();
using var transaction = connection.BeginTransaction();
var queryInsert = @"INSERT INTO Invoices (ClientID, AvailabilityOfPromotionalCode,
DiscountPercentage, SellingPrice, Data)
DiscountPercentage, SellingPrice, DateInvoice)
VALUES (@ClientID, @AvailabilityOfPromotionalCode,
@DiscountPercentage, @SellingPrice, @Data);
SELECT MAX(Id) FROM FeedReplenishments";
@DiscountPercentage, @SellingPrice, @DateInvoice);
SELECT MAX(Id) FROM Invoices";
var invoiceID = connection.QueryFirst<int>(queryInsert, invoice, transaction);
var querySubInsert = @"INSERT INTO InvoiceProducts (InvoiceId, ProductId, Count, SellingPrice)
VALUES (@InvoiceId, @ProductId, @Count, @SellingPrice)";
@ -63,7 +64,7 @@ public class InvoiceRepository : IInvoiceRepository
_logger.LogDebug("Объект: {id}", id);
try
{
using var connection = new SqlConnection(_connectionString.ConnectionString);
using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
var queryDelete = @"DELETE FROM Invoices
WHERE ID=@id";
connection.Execute(queryDelete, new { id });
@ -80,7 +81,7 @@ public class InvoiceRepository : IInvoiceRepository
_logger.LogInformation("Получение всех объектов");
try
{
using var connection = new SqlConnection(_connectionString.ConnectionString);
using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
var querySelect = @"SELECT * FROM Invoices";
var invoices = connection.Query<Invoice>(querySelect);
_logger.LogDebug("Полученные объекты: {json}", JsonConvert.SerializeObject(invoices));

View File

@ -8,6 +8,7 @@ using System.Data.SqlClient;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Npgsql;
namespace ProjectCompanyFurniture.Repositories.Implementations;
@ -28,7 +29,7 @@ public class ManufacturerRepository : IManufacturerRepository
_logger.LogDebug("Объект: {json}", JsonConvert.SerializeObject(manufacturer));
try
{
using var connection = new SqlConnection(_connectionString.ConnectionString);
using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
var queryInsert = @"INSERT INTO Manufacturers (Name)
VALUES (@Name)";
connection.Execute(queryInsert, manufacturer);
@ -47,7 +48,7 @@ public class ManufacturerRepository : IManufacturerRepository
JsonConvert.SerializeObject(manufacturer));
try
{
using var connection = new SqlConnection(_connectionString.ConnectionString);
using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
var queryUpdate = @"UPDATE Manufacturers SET
Name=@Name
WHERE ID=@id";
@ -66,7 +67,7 @@ public class ManufacturerRepository : IManufacturerRepository
_logger.LogDebug("Объект: {id}", id);
try
{
using var connection = new SqlConnection(_connectionString.ConnectionString);
using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
var queryDelete = @"DELETE FROM Manufacturers WHERE ID=@id";
connection.Execute(queryDelete, new { id });
}
@ -83,7 +84,7 @@ public class ManufacturerRepository : IManufacturerRepository
_logger.LogDebug("Объект: {id}", id);
try
{
using var connection = new SqlConnection(_connectionString.ConnectionString);
using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
var querySelect = @"SELECT * FROM Manufacturers WHERE [ID]=@id";
var manufacturer = connection.QueryFirst<Manufacturer>(querySelect, new
{
@ -105,8 +106,8 @@ public class ManufacturerRepository : IManufacturerRepository
_logger.LogInformation("Получение всех объектов");
try
{
using var connection = new SqlConnection(_connectionString.ConnectionString);
var querySelect = "SELECT * FROM Manufacturers";
using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
var querySelect = "SELECT * FROM MANUFACTURERS";
var manufacturers = connection.Query<Manufacturer>(querySelect);
_logger.LogDebug("Полученные объекты: {json}",
JsonConvert.SerializeObject(manufacturers));

View File

@ -1,6 +1,7 @@
using Dapper;
using Microsoft.Extensions.Logging;
using Newtonsoft.Json;
using Npgsql;
using ProjectCompanyFurniture.Entities;
using ProjectCompanyFurniture.Entities.Enums;
using System;
@ -29,7 +30,7 @@ public class ProductMovementRepository : IProductMovementRepository
_logger.LogDebug("Объект: {json}", JsonConvert.SerializeObject(productMovement));
try
{
using var connection = new SqlConnection(_connectionString.ConnectionString);
using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
var queryInsert = @"INSERT INTO ProductMovements (ProductID, MovementType, Date)
VALUES (@ProductID, @MovementType, @Date)";
connection.Execute(queryInsert, productMovement);
@ -46,7 +47,7 @@ public class ProductMovementRepository : IProductMovementRepository
_logger.LogInformation("Получение всех объектов");
try
{
using var connection = new SqlConnection(_connectionString.ConnectionString);
using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
var querySelect = "SELECT * FROM ProductMovements";
var productMovements = connection.Query<ProductMovement>(querySelect);
_logger.LogDebug("Полученные объекты: {json}",

View File

@ -1,6 +1,7 @@
using Dapper;
using Microsoft.Extensions.Logging;
using Newtonsoft.Json;
using Npgsql;
using ProjectCompanyFurniture.Entities;
using System;
using System.Collections.Generic;
@ -28,7 +29,7 @@ public class ProductRepository : IProductRepository
_logger.LogDebug("Объект: {json}", JsonConvert.SerializeObject(product));
try
{
using var connection = new SqlConnection(_connectionString.ConnectionString);
using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
var queryInsert = @"INSERT INTO Products (ManufacturerID, Name, Category, StartingPrice)
VALUES (@ManufacturerID, @Name, @Category, @StartingPrice)";
connection.Execute(queryInsert, product);
@ -47,7 +48,7 @@ public class ProductRepository : IProductRepository
JsonConvert.SerializeObject(product));
try
{
using var connection = new SqlConnection(_connectionString.ConnectionString);
using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
var queryUpdate = @"UPDATE Products SET
ManufacturerID=@ManufacturerID,
Name=@Name,
@ -69,7 +70,7 @@ public class ProductRepository : IProductRepository
_logger.LogDebug("Объект: {id}", id);
try
{
using var connection = new SqlConnection(_connectionString.ConnectionString);
using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
var queryDelete = @"DELETE FROM Productss WHERE ID=@id";
connection.Execute(queryDelete, new { id });
}
@ -86,8 +87,8 @@ public class ProductRepository : IProductRepository
_logger.LogDebug("Объект: {id}", id);
try
{
using var connection = new SqlConnection(_connectionString.ConnectionString);
var querySelect = @"SELECT * FROM Products WHERE [ID]=@id";
using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
var querySelect = @"SELECT * FROM Products WHERE ID=@id";
var product = connection.QueryFirst<Product>(querySelect, new
{
id
@ -108,7 +109,7 @@ public class ProductRepository : IProductRepository
_logger.LogInformation("Получение всех объектов");
try
{
using var connection = new SqlConnection(_connectionString.ConnectionString);
using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
var querySelect = "SELECT * FROM Products";
var products = connection.Query<Product>(querySelect);
_logger.LogDebug("Полученные объекты: {json}",