final (yeeeaaah)
This commit is contained in:
parent
ca303c678b
commit
7d57c72997
@ -29,31 +29,32 @@
|
|||||||
private void InitializeComponent()
|
private void InitializeComponent()
|
||||||
{
|
{
|
||||||
menuStrip = new MenuStrip();
|
menuStrip = new MenuStrip();
|
||||||
справочникиToolStripMenuItem = new ToolStripMenuItem();
|
EntitiesToolStripMenuItem = new ToolStripMenuItem();
|
||||||
CustomersToolStripMenuItem = new ToolStripMenuItem();
|
CustomersToolStripMenuItem = new ToolStripMenuItem();
|
||||||
ExecutorsToolStripMenuItem = new ToolStripMenuItem();
|
ExecutorsToolStripMenuItem = new ToolStripMenuItem();
|
||||||
операцииToolStripMenuItem = new ToolStripMenuItem();
|
ServicesToolStripMenuItem = new ToolStripMenuItem();
|
||||||
|
OperationsToolStripMenuItem = new ToolStripMenuItem();
|
||||||
CustomerContractReviewsToolStripMenuItem = new ToolStripMenuItem();
|
CustomerContractReviewsToolStripMenuItem = new ToolStripMenuItem();
|
||||||
контрактыToolStripMenuItem = new ToolStripMenuItem();
|
ContractsToolStripMenuItem = new ToolStripMenuItem();
|
||||||
отчетыToolStripMenuItem = new ToolStripMenuItem();
|
ReportsToolStripMenuItem = new ToolStripMenuItem();
|
||||||
menuStrip.SuspendLayout();
|
menuStrip.SuspendLayout();
|
||||||
SuspendLayout();
|
SuspendLayout();
|
||||||
//
|
//
|
||||||
// menuStrip
|
// menuStrip
|
||||||
//
|
//
|
||||||
menuStrip.Items.AddRange(new ToolStripItem[] { справочникиToolStripMenuItem, операцииToolStripMenuItem, отчетыToolStripMenuItem });
|
menuStrip.Items.AddRange(new ToolStripItem[] { EntitiesToolStripMenuItem, OperationsToolStripMenuItem, ReportsToolStripMenuItem });
|
||||||
menuStrip.Location = new Point(0, 0);
|
menuStrip.Location = new Point(0, 0);
|
||||||
menuStrip.Name = "menuStrip";
|
menuStrip.Name = "menuStrip";
|
||||||
menuStrip.Size = new Size(734, 24);
|
menuStrip.Size = new Size(734, 24);
|
||||||
menuStrip.TabIndex = 0;
|
menuStrip.TabIndex = 0;
|
||||||
menuStrip.Text = "menuStrip1";
|
menuStrip.Text = "menuStrip1";
|
||||||
//
|
//
|
||||||
// справочникиToolStripMenuItem
|
// EntitiesToolStripMenuItem
|
||||||
//
|
//
|
||||||
справочникиToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { CustomersToolStripMenuItem, ExecutorsToolStripMenuItem });
|
EntitiesToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { CustomersToolStripMenuItem, ExecutorsToolStripMenuItem, ServicesToolStripMenuItem });
|
||||||
справочникиToolStripMenuItem.Name = "справочникиToolStripMenuItem";
|
EntitiesToolStripMenuItem.Name = "EntitiesToolStripMenuItem";
|
||||||
справочникиToolStripMenuItem.Size = new Size(94, 20);
|
EntitiesToolStripMenuItem.Size = new Size(94, 20);
|
||||||
справочникиToolStripMenuItem.Text = "Справочники";
|
EntitiesToolStripMenuItem.Text = "Справочники";
|
||||||
//
|
//
|
||||||
// CustomersToolStripMenuItem
|
// CustomersToolStripMenuItem
|
||||||
//
|
//
|
||||||
@ -69,12 +70,19 @@
|
|||||||
ExecutorsToolStripMenuItem.Text = "Исполнители";
|
ExecutorsToolStripMenuItem.Text = "Исполнители";
|
||||||
ExecutorsToolStripMenuItem.Click += ExecutorsToolStripMenuItem_Click;
|
ExecutorsToolStripMenuItem.Click += ExecutorsToolStripMenuItem_Click;
|
||||||
//
|
//
|
||||||
// операцииToolStripMenuItem
|
// ServicesToolStripMenuItem
|
||||||
//
|
//
|
||||||
операцииToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { CustomerContractReviewsToolStripMenuItem, контрактыToolStripMenuItem });
|
ServicesToolStripMenuItem.Name = "ServicesToolStripMenuItem";
|
||||||
операцииToolStripMenuItem.Name = "операцииToolStripMenuItem";
|
ServicesToolStripMenuItem.Size = new Size(180, 22);
|
||||||
операцииToolStripMenuItem.Size = new Size(75, 20);
|
ServicesToolStripMenuItem.Text = "Услуги";
|
||||||
операцииToolStripMenuItem.Text = "Операции";
|
ServicesToolStripMenuItem.Click += ServicesToolStripMenuItem_Click;
|
||||||
|
//
|
||||||
|
// OperationsToolStripMenuItem
|
||||||
|
//
|
||||||
|
OperationsToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { CustomerContractReviewsToolStripMenuItem, ContractsToolStripMenuItem });
|
||||||
|
OperationsToolStripMenuItem.Name = "OperationsToolStripMenuItem";
|
||||||
|
OperationsToolStripMenuItem.Size = new Size(75, 20);
|
||||||
|
OperationsToolStripMenuItem.Text = "Операции";
|
||||||
//
|
//
|
||||||
// CustomerContractReviewsToolStripMenuItem
|
// CustomerContractReviewsToolStripMenuItem
|
||||||
//
|
//
|
||||||
@ -83,18 +91,18 @@
|
|||||||
CustomerContractReviewsToolStripMenuItem.Text = "Отзывы заказчиков";
|
CustomerContractReviewsToolStripMenuItem.Text = "Отзывы заказчиков";
|
||||||
CustomerContractReviewsToolStripMenuItem.Click += CustomerContractReviewsToolStripMenuItem_Click;
|
CustomerContractReviewsToolStripMenuItem.Click += CustomerContractReviewsToolStripMenuItem_Click;
|
||||||
//
|
//
|
||||||
// контрактыToolStripMenuItem
|
// ContractsToolStripMenuItem
|
||||||
//
|
//
|
||||||
контрактыToolStripMenuItem.Name = "контрактыToolStripMenuItem";
|
ContractsToolStripMenuItem.Name = "ContractsToolStripMenuItem";
|
||||||
контрактыToolStripMenuItem.Size = new Size(181, 22);
|
ContractsToolStripMenuItem.Size = new Size(181, 22);
|
||||||
контрактыToolStripMenuItem.Text = "Контракты";
|
ContractsToolStripMenuItem.Text = "Контракты";
|
||||||
контрактыToolStripMenuItem.Click += ContractsToolStripMenuItem_Click;
|
ContractsToolStripMenuItem.Click += ContractsToolStripMenuItem_Click;
|
||||||
//
|
//
|
||||||
// отчетыToolStripMenuItem
|
// ReportsToolStripMenuItem
|
||||||
//
|
//
|
||||||
отчетыToolStripMenuItem.Name = "отчетыToolStripMenuItem";
|
ReportsToolStripMenuItem.Name = "ReportsToolStripMenuItem";
|
||||||
отчетыToolStripMenuItem.Size = new Size(60, 20);
|
ReportsToolStripMenuItem.Size = new Size(60, 20);
|
||||||
отчетыToolStripMenuItem.Text = "Отчеты";
|
ReportsToolStripMenuItem.Text = "Отчеты";
|
||||||
//
|
//
|
||||||
// FormItCompany
|
// FormItCompany
|
||||||
//
|
//
|
||||||
@ -117,13 +125,13 @@
|
|||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
private MenuStrip menuStrip;
|
private MenuStrip menuStrip;
|
||||||
private ToolStripMenuItem справочникиToolStripMenuItem;
|
private ToolStripMenuItem EntitiesToolStripMenuItem;
|
||||||
private ToolStripMenuItem CustomersToolStripMenuItem;
|
private ToolStripMenuItem CustomersToolStripMenuItem;
|
||||||
private ToolStripMenuItem ExecutorsToolStripMenuItem;
|
private ToolStripMenuItem ExecutorsToolStripMenuItem;
|
||||||
private ToolStripMenuItem операцииToolStripMenuItem;
|
private ToolStripMenuItem OperationsToolStripMenuItem;
|
||||||
private ToolStripMenuItem отчетыToolStripMenuItem;
|
private ToolStripMenuItem ReportsToolStripMenuItem;
|
||||||
private ToolStripMenuItem CustomerContractReviewsToolStripMenuItem;
|
private ToolStripMenuItem CustomerContractReviewsToolStripMenuItem;
|
||||||
private ToolStripMenuItem контрактыToolStripMenuItem;
|
private ToolStripMenuItem ContractsToolStripMenuItem;
|
||||||
private ToolStripMenuItem ServicesToolStripMenuItem;
|
private ToolStripMenuItem ServicesToolStripMenuItem;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -41,8 +41,8 @@
|
|||||||
labelContractDeadline = new Label();
|
labelContractDeadline = new Label();
|
||||||
labelContractPaymentAmount = new Label();
|
labelContractPaymentAmount = new Label();
|
||||||
dataGridViewServices = new DataGridView();
|
dataGridViewServices = new DataGridView();
|
||||||
|
ColumnServiceDescription = new DataGridViewComboBoxColumn();
|
||||||
groupBox = new GroupBox();
|
groupBox = new GroupBox();
|
||||||
ColumnServiceDescription = new DataGridViewTextBoxColumn();
|
|
||||||
((System.ComponentModel.ISupportInitialize)numericUpDownContractPaymentAmount).BeginInit();
|
((System.ComponentModel.ISupportInitialize)numericUpDownContractPaymentAmount).BeginInit();
|
||||||
((System.ComponentModel.ISupportInitialize)dataGridViewServices).BeginInit();
|
((System.ComponentModel.ISupportInitialize)dataGridViewServices).BeginInit();
|
||||||
groupBox.SuspendLayout();
|
groupBox.SuspendLayout();
|
||||||
@ -172,6 +172,14 @@
|
|||||||
dataGridViewServices.Size = new Size(352, 244);
|
dataGridViewServices.Size = new Size(352, 244);
|
||||||
dataGridViewServices.TabIndex = 17;
|
dataGridViewServices.TabIndex = 17;
|
||||||
//
|
//
|
||||||
|
// ColumnServiceDescription
|
||||||
|
//
|
||||||
|
ColumnServiceDescription.AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
|
||||||
|
ColumnServiceDescription.HeaderText = "Услуга";
|
||||||
|
ColumnServiceDescription.Name = "ColumnServiceDescription";
|
||||||
|
ColumnServiceDescription.Resizable = DataGridViewTriState.True;
|
||||||
|
ColumnServiceDescription.SortMode = DataGridViewColumnSortMode.Automatic;
|
||||||
|
//
|
||||||
// groupBox
|
// groupBox
|
||||||
//
|
//
|
||||||
groupBox.Anchor = AnchorStyles.Top | AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right;
|
groupBox.Anchor = AnchorStyles.Top | AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right;
|
||||||
@ -183,13 +191,6 @@
|
|||||||
groupBox.TabStop = false;
|
groupBox.TabStop = false;
|
||||||
groupBox.Text = "Услуги:";
|
groupBox.Text = "Услуги:";
|
||||||
//
|
//
|
||||||
// ColumnServiceDescription
|
|
||||||
//
|
|
||||||
ColumnServiceDescription.AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
|
|
||||||
ColumnServiceDescription.HeaderText = "Услуга";
|
|
||||||
ColumnServiceDescription.Name = "ColumnServiceDescription";
|
|
||||||
ColumnServiceDescription.Resizable = DataGridViewTriState.True;
|
|
||||||
//
|
|
||||||
// FormContract
|
// FormContract
|
||||||
//
|
//
|
||||||
AutoScaleDimensions = new SizeF(7F, 15F);
|
AutoScaleDimensions = new SizeF(7F, 15F);
|
||||||
@ -234,6 +235,6 @@
|
|||||||
private Label labelContractPaymentAmount;
|
private Label labelContractPaymentAmount;
|
||||||
private DataGridView dataGridViewServices;
|
private DataGridView dataGridViewServices;
|
||||||
private GroupBox groupBox;
|
private GroupBox groupBox;
|
||||||
private DataGridViewTextBoxColumn ColumnServiceDescription;
|
private DataGridViewComboBoxColumn ColumnServiceDescription;
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -9,7 +9,7 @@ namespace PIbd_23_Gutorov_I.A._IT_Company.Forms
|
|||||||
private readonly IContractRepository _contractRepository;
|
private readonly IContractRepository _contractRepository;
|
||||||
|
|
||||||
public FormContract(IContractRepository contractRepository, ICustomerRepository customerRepository,
|
public FormContract(IContractRepository contractRepository, ICustomerRepository customerRepository,
|
||||||
IExecutorRepository executorRepository)
|
IExecutorRepository executorRepository, IServiceRepository serviceRepository)
|
||||||
{
|
{
|
||||||
InitializeComponent();
|
InitializeComponent();
|
||||||
_contractRepository = contractRepository ?? throw new ArgumentNullException(nameof(contractRepository));
|
_contractRepository = contractRepository ?? throw new ArgumentNullException(nameof(contractRepository));
|
||||||
|
@ -42,8 +42,8 @@ namespace PIbd_23_Gutorov_I.A._IT_Company.Forms
|
|||||||
if (string.IsNullOrEmpty(richTextBoxServiceDescription.Text))
|
if (string.IsNullOrEmpty(richTextBoxServiceDescription.Text))
|
||||||
throw new Exception("Имеются незаполненные поля");
|
throw new Exception("Имеются незаполненные поля");
|
||||||
|
|
||||||
_serviceRepository.CreateService(Service.CreateEntity(0,
|
if (_serviceId.HasValue) _serviceRepository.UpdateService(Service.CreateEntity(_serviceId.Value, richTextBoxServiceDescription.Text));
|
||||||
richTextBoxServiceDescription.Text));
|
else _serviceRepository.CreateService(Service.CreateEntity(0, richTextBoxServiceDescription.Text));
|
||||||
|
|
||||||
Close();
|
Close();
|
||||||
}
|
}
|
||||||
|
120
PIbd-23_Gutorov_I.A._IT-Company/Forms/FormService.resx
Normal file
120
PIbd-23_Gutorov_I.A._IT-Company/Forms/FormService.resx
Normal file
@ -0,0 +1,120 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<root>
|
||||||
|
<!--
|
||||||
|
Microsoft ResX Schema
|
||||||
|
|
||||||
|
Version 2.0
|
||||||
|
|
||||||
|
The primary goals of this format is to allow a simple XML format
|
||||||
|
that is mostly human readable. The generation and parsing of the
|
||||||
|
various data types are done through the TypeConverter classes
|
||||||
|
associated with the data types.
|
||||||
|
|
||||||
|
Example:
|
||||||
|
|
||||||
|
... ado.net/XML headers & schema ...
|
||||||
|
<resheader name="resmimetype">text/microsoft-resx</resheader>
|
||||||
|
<resheader name="version">2.0</resheader>
|
||||||
|
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
|
||||||
|
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
|
||||||
|
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
|
||||||
|
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
|
||||||
|
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
|
||||||
|
<value>[base64 mime encoded serialized .NET Framework object]</value>
|
||||||
|
</data>
|
||||||
|
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
|
||||||
|
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
|
||||||
|
<comment>This is a comment</comment>
|
||||||
|
</data>
|
||||||
|
|
||||||
|
There are any number of "resheader" rows that contain simple
|
||||||
|
name/value pairs.
|
||||||
|
|
||||||
|
Each data row contains a name, and value. The row also contains a
|
||||||
|
type or mimetype. Type corresponds to a .NET class that support
|
||||||
|
text/value conversion through the TypeConverter architecture.
|
||||||
|
Classes that don't support this are serialized and stored with the
|
||||||
|
mimetype set.
|
||||||
|
|
||||||
|
The mimetype is used for serialized objects, and tells the
|
||||||
|
ResXResourceReader how to depersist the object. This is currently not
|
||||||
|
extensible. For a given mimetype the value must be set accordingly:
|
||||||
|
|
||||||
|
Note - application/x-microsoft.net.object.binary.base64 is the format
|
||||||
|
that the ResXResourceWriter will generate, however the reader can
|
||||||
|
read any of the formats listed below.
|
||||||
|
|
||||||
|
mimetype: application/x-microsoft.net.object.binary.base64
|
||||||
|
value : The object must be serialized with
|
||||||
|
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
|
||||||
|
: and then encoded with base64 encoding.
|
||||||
|
|
||||||
|
mimetype: application/x-microsoft.net.object.soap.base64
|
||||||
|
value : The object must be serialized with
|
||||||
|
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
|
||||||
|
: and then encoded with base64 encoding.
|
||||||
|
|
||||||
|
mimetype: application/x-microsoft.net.object.bytearray.base64
|
||||||
|
value : The object must be serialized into a byte array
|
||||||
|
: using a System.ComponentModel.TypeConverter
|
||||||
|
: and then encoded with base64 encoding.
|
||||||
|
-->
|
||||||
|
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
|
||||||
|
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
|
||||||
|
<xsd:element name="root" msdata:IsDataSet="true">
|
||||||
|
<xsd:complexType>
|
||||||
|
<xsd:choice maxOccurs="unbounded">
|
||||||
|
<xsd:element name="metadata">
|
||||||
|
<xsd:complexType>
|
||||||
|
<xsd:sequence>
|
||||||
|
<xsd:element name="value" type="xsd:string" minOccurs="0" />
|
||||||
|
</xsd:sequence>
|
||||||
|
<xsd:attribute name="name" use="required" type="xsd:string" />
|
||||||
|
<xsd:attribute name="type" type="xsd:string" />
|
||||||
|
<xsd:attribute name="mimetype" type="xsd:string" />
|
||||||
|
<xsd:attribute ref="xml:space" />
|
||||||
|
</xsd:complexType>
|
||||||
|
</xsd:element>
|
||||||
|
<xsd:element name="assembly">
|
||||||
|
<xsd:complexType>
|
||||||
|
<xsd:attribute name="alias" type="xsd:string" />
|
||||||
|
<xsd:attribute name="name" type="xsd:string" />
|
||||||
|
</xsd:complexType>
|
||||||
|
</xsd:element>
|
||||||
|
<xsd:element name="data">
|
||||||
|
<xsd:complexType>
|
||||||
|
<xsd:sequence>
|
||||||
|
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||||
|
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
|
||||||
|
</xsd:sequence>
|
||||||
|
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
|
||||||
|
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
|
||||||
|
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
|
||||||
|
<xsd:attribute ref="xml:space" />
|
||||||
|
</xsd:complexType>
|
||||||
|
</xsd:element>
|
||||||
|
<xsd:element name="resheader">
|
||||||
|
<xsd:complexType>
|
||||||
|
<xsd:sequence>
|
||||||
|
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||||
|
</xsd:sequence>
|
||||||
|
<xsd:attribute name="name" type="xsd:string" use="required" />
|
||||||
|
</xsd:complexType>
|
||||||
|
</xsd:element>
|
||||||
|
</xsd:choice>
|
||||||
|
</xsd:complexType>
|
||||||
|
</xsd:element>
|
||||||
|
</xsd:schema>
|
||||||
|
<resheader name="resmimetype">
|
||||||
|
<value>text/microsoft-resx</value>
|
||||||
|
</resheader>
|
||||||
|
<resheader name="version">
|
||||||
|
<value>2.0</value>
|
||||||
|
</resheader>
|
||||||
|
<resheader name="reader">
|
||||||
|
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||||
|
</resheader>
|
||||||
|
<resheader name="writer">
|
||||||
|
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||||
|
</resheader>
|
||||||
|
</root>
|
@ -32,6 +32,7 @@ namespace PIbd_23_Gutorov_I.A._IT_Company
|
|||||||
container.RegisterType<ICustomerExecutorReviewRepository, CustomerExecutorReviewRepository>();
|
container.RegisterType<ICustomerExecutorReviewRepository, CustomerExecutorReviewRepository>();
|
||||||
container.RegisterType<ICustomerRepository, CustomerRepository>();
|
container.RegisterType<ICustomerRepository, CustomerRepository>();
|
||||||
container.RegisterType<IExecutorRepository, ExecutorRepository>();
|
container.RegisterType<IExecutorRepository, ExecutorRepository>();
|
||||||
|
container.RegisterType<IServiceRepository, ServiceRepository>();
|
||||||
|
|
||||||
container.RegisterType<IConnectionString, ConnectionString>();
|
container.RegisterType<IConnectionString, ConnectionString>();
|
||||||
|
|
||||||
|
@ -8,9 +8,9 @@ public interface IServiceRepository
|
|||||||
|
|
||||||
Service ReadServiceById(int id);
|
Service ReadServiceById(int id);
|
||||||
|
|
||||||
void CreateService(Service Service);
|
void CreateService(Service service);
|
||||||
|
|
||||||
void UpdateService(Service Service);
|
void UpdateService(Service service);
|
||||||
|
|
||||||
void DeleteService(int id);
|
void DeleteService(int id);
|
||||||
}
|
}
|
@ -37,11 +37,15 @@ public class ContractRepository : IContractRepository
|
|||||||
var contractId = connection.QueryFirst<int>(queryInsert, contract, transaction);
|
var contractId = connection.QueryFirst<int>(queryInsert, contract, transaction);
|
||||||
|
|
||||||
var querySubInsert = @"
|
var querySubInsert = @"
|
||||||
INSERT INTO Services (Description, ContractId)
|
INSERT INTO ServiceContract (ServiceId, ContractId)
|
||||||
VALUES (@Description, @ContractId);
|
VALUES (@ServiceId, @ContractId);
|
||||||
";
|
";
|
||||||
foreach (var elem in contract.Services)
|
foreach (var elem in contract.Services)
|
||||||
connection.Execute(querySubInsert, new { elem.Description, contractId }, transaction);
|
{
|
||||||
|
var serviceId = elem.Id;
|
||||||
|
connection.Execute(querySubInsert, new { serviceId, contractId }, transaction);
|
||||||
|
}
|
||||||
|
|
||||||
transaction.Commit();
|
transaction.Commit();
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
|
@ -1,28 +1,127 @@
|
|||||||
using PIbd_23_Gutorov_I.A._IT_Company.Entities;
|
using Dapper;
|
||||||
|
using Microsoft.Extensions.Logging;
|
||||||
|
using Newtonsoft.Json;
|
||||||
|
using Npgsql;
|
||||||
|
using PIbd_23_Gutorov_I.A._IT_Company.Entities;
|
||||||
|
using System.CodeDom.Compiler;
|
||||||
|
|
||||||
namespace PIbd_23_Gutorov_I.A._IT_Company.Repositories.Implementations;
|
namespace PIbd_23_Gutorov_I.A._IT_Company.Repositories.Implementations;
|
||||||
|
|
||||||
internal class ServiceRepository : IServiceRepository
|
public class ServiceRepository : IServiceRepository
|
||||||
{
|
{
|
||||||
public void CreateService(Service Service)
|
private readonly IConnectionString _connectionString;
|
||||||
|
private readonly ILogger<ServiceRepository> _logger;
|
||||||
|
|
||||||
|
public ServiceRepository(IConnectionString connectionString, ILogger<ServiceRepository> logger)
|
||||||
{
|
{
|
||||||
|
_connectionString = connectionString;
|
||||||
|
_logger = logger;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public void CreateService(Service service)
|
||||||
|
{
|
||||||
|
_logger.LogInformation("Добавление объекта");
|
||||||
|
_logger.LogDebug("Объект: {json}", JsonConvert.SerializeObject(service));
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
|
||||||
|
var queryInsert = @"
|
||||||
|
INSERT INTO Services (Description)
|
||||||
|
VALUES (@Description);
|
||||||
|
";
|
||||||
|
connection.Execute(queryInsert, service);
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "Ошибка при добавлении объекта");
|
||||||
|
throw;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void DeleteService(int id)
|
public void DeleteService(int id)
|
||||||
{
|
{
|
||||||
|
_logger.LogInformation("Удаление объекта");
|
||||||
|
_logger.LogDebug("Объект: {id}", id);
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
|
||||||
|
var queryDelete = @"
|
||||||
|
DELETE FROM Services WHERE Id = @Id;
|
||||||
|
";
|
||||||
|
connection.Execute(queryDelete, new { id });
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "Ошибка при удалении объекта");
|
||||||
|
throw;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public Service ReadServiceById(int id)
|
public Service ReadServiceById(int id)
|
||||||
{
|
{
|
||||||
return Service.CreateEntity(0, string.Empty);
|
_logger.LogInformation("Получение объекта по идентификатору");
|
||||||
|
_logger.LogDebug("Объект: {id}", id);
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
|
||||||
|
var querySelect = @"
|
||||||
|
SELECT * FROM Services WHERE Id = @Id;
|
||||||
|
";
|
||||||
|
var service = connection.QueryFirst<Service>(querySelect, new { id });
|
||||||
|
_logger.LogDebug("Найденный объект: {json}", JsonConvert.SerializeObject(service));
|
||||||
|
return service;
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "Ошибка при поиске объекта");
|
||||||
|
throw;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public IEnumerable<Service> ReadServices()
|
public IEnumerable<Service> ReadServices()
|
||||||
{
|
{
|
||||||
return [];
|
_logger.LogInformation("Получение всех объектов");
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
|
||||||
|
var querySelect = @"
|
||||||
|
SELECT * FROM Services;
|
||||||
|
";
|
||||||
|
var services = connection.Query<Service>(querySelect);
|
||||||
|
_logger.LogDebug("Полученные объекты: {json}", JsonConvert.SerializeObject(services));
|
||||||
|
return services;
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "Ошибка при чтении объектов");
|
||||||
|
throw;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void UpdateService(Service Service)
|
public void UpdateService(Service service)
|
||||||
{
|
{
|
||||||
|
_logger.LogInformation("Редактирование объекта");
|
||||||
|
_logger.LogDebug("Объект: {json}", JsonConvert.SerializeObject(service));
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
|
||||||
|
var queryUpdate = @"
|
||||||
|
UPDATE Services
|
||||||
|
SET Description = @Description
|
||||||
|
WHERE Id = @Id;
|
||||||
|
";
|
||||||
|
connection.Execute(queryUpdate, service);
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "Ошибка при редактировании объекта");
|
||||||
|
throw;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
x
Reference in New Issue
Block a user