fix forms, restruct entities
This commit is contained in:
parent
1fc85814dc
commit
1da0a7d90c
@ -18,7 +18,11 @@ public class Contract
|
|||||||
|
|
||||||
public int PaymentAmount { get; private set; }
|
public int PaymentAmount { get; private set; }
|
||||||
|
|
||||||
public static Contract CreateEntity(int id, int customerID, int executorID, ContractCategory category, DateTime deadline, int paymentAmount)
|
public IEnumerable<Service> Services { get; private set; } = [];
|
||||||
|
|
||||||
|
public static Contract CreateEntity(int id, int customerID, int executorID,
|
||||||
|
ContractCategory category, DateTime deadline,
|
||||||
|
int paymentAmount, IEnumerable<Service> services)
|
||||||
{
|
{
|
||||||
return new Contract
|
return new Contract
|
||||||
{
|
{
|
||||||
@ -28,7 +32,8 @@ public class Contract
|
|||||||
Category = category,
|
Category = category,
|
||||||
ConclusionDate = DateTime.Now,
|
ConclusionDate = DateTime.Now,
|
||||||
Deadline = deadline,
|
Deadline = deadline,
|
||||||
PaymentAmount = paymentAmount
|
PaymentAmount = paymentAmount,
|
||||||
|
Services = services
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -32,7 +32,6 @@
|
|||||||
справочникиToolStripMenuItem = new ToolStripMenuItem();
|
справочникиToolStripMenuItem = new ToolStripMenuItem();
|
||||||
CustomersToolStripMenuItem = new ToolStripMenuItem();
|
CustomersToolStripMenuItem = new ToolStripMenuItem();
|
||||||
ExecutorsToolStripMenuItem = new ToolStripMenuItem();
|
ExecutorsToolStripMenuItem = new ToolStripMenuItem();
|
||||||
ServicesToolStripMenuItem = new ToolStripMenuItem();
|
|
||||||
операцииToolStripMenuItem = new ToolStripMenuItem();
|
операцииToolStripMenuItem = new ToolStripMenuItem();
|
||||||
CustomerContractReviewsToolStripMenuItem = new ToolStripMenuItem();
|
CustomerContractReviewsToolStripMenuItem = new ToolStripMenuItem();
|
||||||
контрактыToolStripMenuItem = new ToolStripMenuItem();
|
контрактыToolStripMenuItem = new ToolStripMenuItem();
|
||||||
@ -51,7 +50,7 @@
|
|||||||
//
|
//
|
||||||
// справочникиToolStripMenuItem
|
// справочникиToolStripMenuItem
|
||||||
//
|
//
|
||||||
справочникиToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { CustomersToolStripMenuItem, ExecutorsToolStripMenuItem, ServicesToolStripMenuItem });
|
справочникиToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { CustomersToolStripMenuItem, ExecutorsToolStripMenuItem });
|
||||||
справочникиToolStripMenuItem.Name = "справочникиToolStripMenuItem";
|
справочникиToolStripMenuItem.Name = "справочникиToolStripMenuItem";
|
||||||
справочникиToolStripMenuItem.Size = new Size(94, 20);
|
справочникиToolStripMenuItem.Size = new Size(94, 20);
|
||||||
справочникиToolStripMenuItem.Text = "Справочники";
|
справочникиToolStripMenuItem.Text = "Справочники";
|
||||||
@ -70,13 +69,6 @@
|
|||||||
ExecutorsToolStripMenuItem.Text = "Исполнители";
|
ExecutorsToolStripMenuItem.Text = "Исполнители";
|
||||||
ExecutorsToolStripMenuItem.Click += ExecutorsToolStripMenuItem_Click;
|
ExecutorsToolStripMenuItem.Click += ExecutorsToolStripMenuItem_Click;
|
||||||
//
|
//
|
||||||
// ServicesToolStripMenuItem
|
|
||||||
//
|
|
||||||
ServicesToolStripMenuItem.Name = "ServicesToolStripMenuItem";
|
|
||||||
ServicesToolStripMenuItem.Size = new Size(180, 22);
|
|
||||||
ServicesToolStripMenuItem.Text = "Услуги";
|
|
||||||
ServicesToolStripMenuItem.Click += ServicesToolStripMenuItem_Click;
|
|
||||||
//
|
|
||||||
// операцииToolStripMenuItem
|
// операцииToolStripMenuItem
|
||||||
//
|
//
|
||||||
операцииToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { CustomerContractReviewsToolStripMenuItem, контрактыToolStripMenuItem });
|
операцииToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { CustomerContractReviewsToolStripMenuItem, контрактыToolStripMenuItem });
|
||||||
@ -128,7 +120,6 @@
|
|||||||
private ToolStripMenuItem справочникиToolStripMenuItem;
|
private ToolStripMenuItem справочникиToolStripMenuItem;
|
||||||
private ToolStripMenuItem CustomersToolStripMenuItem;
|
private ToolStripMenuItem CustomersToolStripMenuItem;
|
||||||
private ToolStripMenuItem ExecutorsToolStripMenuItem;
|
private ToolStripMenuItem ExecutorsToolStripMenuItem;
|
||||||
private ToolStripMenuItem ServicesToolStripMenuItem;
|
|
||||||
private ToolStripMenuItem операцииToolStripMenuItem;
|
private ToolStripMenuItem операцииToolStripMenuItem;
|
||||||
private ToolStripMenuItem отчетыToolStripMenuItem;
|
private ToolStripMenuItem отчетыToolStripMenuItem;
|
||||||
private ToolStripMenuItem CustomerContractReviewsToolStripMenuItem;
|
private ToolStripMenuItem CustomerContractReviewsToolStripMenuItem;
|
||||||
|
@ -37,18 +37,6 @@ namespace PIbd_23_Gutorov_I.A._IT_Company
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void ServicesToolStripMenuItem_Click(object sender, EventArgs e)
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
_container.Resolve<FormServices>().ShowDialog();
|
|
||||||
}
|
|
||||||
catch (Exception ex)
|
|
||||||
{
|
|
||||||
MessageBox.Show(ex.Message, "Îøèáêà ïðè çàãðóçêå", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void ContractsToolStripMenuItem_Click(object sender, EventArgs e)
|
private void ContractsToolStripMenuItem_Click(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
|
@ -42,7 +42,7 @@
|
|||||||
labelContractPaymentAmount = new Label();
|
labelContractPaymentAmount = new Label();
|
||||||
dataGridViewServices = new DataGridView();
|
dataGridViewServices = new DataGridView();
|
||||||
groupBox = new GroupBox();
|
groupBox = new GroupBox();
|
||||||
ColumnServiceDescription = new DataGridViewComboBoxColumn();
|
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();
|
||||||
@ -185,10 +185,10 @@
|
|||||||
//
|
//
|
||||||
// ColumnServiceDescription
|
// ColumnServiceDescription
|
||||||
//
|
//
|
||||||
|
ColumnServiceDescription.AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
|
||||||
ColumnServiceDescription.HeaderText = "Услуга";
|
ColumnServiceDescription.HeaderText = "Услуга";
|
||||||
ColumnServiceDescription.Name = "ColumnServiceDescription";
|
ColumnServiceDescription.Name = "ColumnServiceDescription";
|
||||||
ColumnServiceDescription.Resizable = DataGridViewTriState.True;
|
ColumnServiceDescription.Resizable = DataGridViewTriState.True;
|
||||||
ColumnServiceDescription.SortMode = DataGridViewColumnSortMode.Automatic;
|
|
||||||
//
|
//
|
||||||
// FormContract
|
// FormContract
|
||||||
//
|
//
|
||||||
@ -234,6 +234,6 @@
|
|||||||
private Label labelContractPaymentAmount;
|
private Label labelContractPaymentAmount;
|
||||||
private DataGridView dataGridViewServices;
|
private DataGridView dataGridViewServices;
|
||||||
private GroupBox groupBox;
|
private GroupBox groupBox;
|
||||||
private DataGridViewComboBoxColumn ColumnServiceDescription;
|
private DataGridViewTextBoxColumn 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, IServiceRepository serviceRepository)
|
IExecutorRepository executorRepository)
|
||||||
{
|
{
|
||||||
InitializeComponent();
|
InitializeComponent();
|
||||||
_contractRepository = contractRepository ?? throw new ArgumentNullException(nameof(contractRepository));
|
_contractRepository = contractRepository ?? throw new ArgumentNullException(nameof(contractRepository));
|
||||||
@ -22,10 +22,6 @@ namespace PIbd_23_Gutorov_I.A._IT_Company.Forms
|
|||||||
comboBoxContractExecutorId.DisplayMember = "Name";
|
comboBoxContractExecutorId.DisplayMember = "Name";
|
||||||
comboBoxContractExecutorId.DisplayMember = "Id";
|
comboBoxContractExecutorId.DisplayMember = "Id";
|
||||||
|
|
||||||
ColumnServiceDescription.DataSource = serviceRepository.ReadServices();
|
|
||||||
ColumnServiceDescription.DisplayMember = "Description";
|
|
||||||
comboBoxContractExecutorId.DisplayMember = "Id";
|
|
||||||
|
|
||||||
foreach (var elem in Enum.GetValues(typeof(ContractCategory)))
|
foreach (var elem in Enum.GetValues(typeof(ContractCategory)))
|
||||||
{
|
{
|
||||||
checkedListBoxContractCategory.Items.Add(elem);
|
checkedListBoxContractCategory.Items.Add(elem);
|
||||||
@ -63,8 +59,22 @@ namespace PIbd_23_Gutorov_I.A._IT_Company.Forms
|
|||||||
contractCategory |= (ContractCategory)elem;
|
contractCategory |= (ContractCategory)elem;
|
||||||
}
|
}
|
||||||
|
|
||||||
return Contract.CreateEntity(id, (int)comboBoxContractCustomerId.SelectedValue!, (int)comboBoxContractExecutorId.SelectedValue!,
|
return Contract.CreateEntity(id, (int)comboBoxContractCustomerId.SelectedValue!,
|
||||||
contractCategory, dateTimePickerContractDeadline.Value, Convert.ToInt32(numericUpDownContractPaymentAmount.Value));
|
(int)comboBoxContractExecutorId.SelectedValue!, contractCategory,
|
||||||
}
|
dateTimePickerContractDeadline.Value, Convert.ToInt32(numericUpDownContractPaymentAmount.Value),
|
||||||
|
CreateServicesFromDataGrid());
|
||||||
|
}
|
||||||
|
|
||||||
|
private List<Service> CreateServicesFromDataGrid()
|
||||||
|
{
|
||||||
|
var list = new List<Service>();
|
||||||
|
|
||||||
|
foreach (DataGridViewRow row in dataGridViewServices.Rows)
|
||||||
|
if (!row.IsNewRow)
|
||||||
|
list.Add(Service.CreateEntity(0, Convert.ToString(row.Cells["Description"].Value)!, 0));
|
||||||
|
|
||||||
|
return list;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -49,7 +49,7 @@ namespace PIbd_23_Gutorov_I.A._IT_Company.Forms
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (_customerId.HasValue) _customerRepository.UpdateCustomer(CreateCustomer(_customerId.Value));
|
if (_customerId.HasValue) _customerRepository.UpdateCustomer(CreateCustomer(_customerId.Value));
|
||||||
else _customerRepository.UpdateCustomer(CreateCustomer(0));
|
else _customerRepository.CreateCustomer(CreateCustomer(0));
|
||||||
|
|
||||||
Close();
|
Close();
|
||||||
}
|
}
|
||||||
|
@ -50,7 +50,7 @@ namespace PIbd_23_Gutorov_I.A._IT_Company.Forms
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (_executorId.HasValue) _executorRepository.UpdateExecutor(CreateExecutor(_executorId.Value));
|
if (_executorId.HasValue) _executorRepository.UpdateExecutor(CreateExecutor(_executorId.Value));
|
||||||
else _executorRepository.UpdateExecutor(CreateExecutor(0));
|
else _executorRepository.CreateExecutor(CreateExecutor(0));
|
||||||
|
|
||||||
Close();
|
Close();
|
||||||
}
|
}
|
||||||
|
@ -1,121 +0,0 @@
|
|||||||
namespace PIbd_23_Gutorov_I.A._IT_Company.Forms
|
|
||||||
{
|
|
||||||
partial class FormService
|
|
||||||
{
|
|
||||||
/// <summary>
|
|
||||||
/// Required designer variable.
|
|
||||||
/// </summary>
|
|
||||||
private System.ComponentModel.IContainer components = null;
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Clean up any resources being used.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
|
|
||||||
protected override void Dispose(bool disposing)
|
|
||||||
{
|
|
||||||
if (disposing && (components != null))
|
|
||||||
{
|
|
||||||
components.Dispose();
|
|
||||||
}
|
|
||||||
base.Dispose(disposing);
|
|
||||||
}
|
|
||||||
|
|
||||||
#region Windows Form Designer generated code
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Required method for Designer support - do not modify
|
|
||||||
/// the contents of this method with the code editor.
|
|
||||||
/// </summary>
|
|
||||||
private void InitializeComponent()
|
|
||||||
{
|
|
||||||
comboBoxServiceContractId = new ComboBox();
|
|
||||||
labelServiceContractId = new Label();
|
|
||||||
labelServiceDescription = new Label();
|
|
||||||
richTextBoxServiceDescription = new RichTextBox();
|
|
||||||
buttonCancel = new Button();
|
|
||||||
buttonSave = new Button();
|
|
||||||
SuspendLayout();
|
|
||||||
//
|
|
||||||
// comboBoxServiceContractId
|
|
||||||
//
|
|
||||||
comboBoxServiceContractId.DropDownStyle = ComboBoxStyle.DropDownList;
|
|
||||||
comboBoxServiceContractId.FormattingEnabled = true;
|
|
||||||
comboBoxServiceContractId.Location = new Point(169, 6);
|
|
||||||
comboBoxServiceContractId.Name = "comboBoxServiceContractId";
|
|
||||||
comboBoxServiceContractId.Size = new Size(202, 23);
|
|
||||||
comboBoxServiceContractId.TabIndex = 15;
|
|
||||||
//
|
|
||||||
// labelServiceContractId
|
|
||||||
//
|
|
||||||
labelServiceContractId.AutoSize = true;
|
|
||||||
labelServiceContractId.Location = new Point(12, 9);
|
|
||||||
labelServiceContractId.Name = "labelServiceContractId";
|
|
||||||
labelServiceContractId.Size = new Size(60, 15);
|
|
||||||
labelServiceContractId.TabIndex = 14;
|
|
||||||
labelServiceContractId.Text = "Контракт:";
|
|
||||||
//
|
|
||||||
// labelServiceDescription
|
|
||||||
//
|
|
||||||
labelServiceDescription.AutoSize = true;
|
|
||||||
labelServiceDescription.Location = new Point(12, 38);
|
|
||||||
labelServiceDescription.Name = "labelServiceDescription";
|
|
||||||
labelServiceDescription.Size = new Size(65, 15);
|
|
||||||
labelServiceDescription.TabIndex = 30;
|
|
||||||
labelServiceDescription.Text = "Описание:";
|
|
||||||
//
|
|
||||||
// richTextBoxServiceDescription
|
|
||||||
//
|
|
||||||
richTextBoxServiceDescription.Location = new Point(169, 35);
|
|
||||||
richTextBoxServiceDescription.Name = "richTextBoxServiceDescription";
|
|
||||||
richTextBoxServiceDescription.Size = new Size(202, 96);
|
|
||||||
richTextBoxServiceDescription.TabIndex = 29;
|
|
||||||
richTextBoxServiceDescription.Text = "";
|
|
||||||
//
|
|
||||||
// buttonCancel
|
|
||||||
//
|
|
||||||
buttonCancel.Location = new Point(12, 166);
|
|
||||||
buttonCancel.Name = "buttonCancel";
|
|
||||||
buttonCancel.Size = new Size(359, 23);
|
|
||||||
buttonCancel.TabIndex = 32;
|
|
||||||
buttonCancel.Text = "Отмена";
|
|
||||||
buttonCancel.UseVisualStyleBackColor = true;
|
|
||||||
buttonCancel.Click += ButtonCancel_Click;
|
|
||||||
//
|
|
||||||
// buttonSave
|
|
||||||
//
|
|
||||||
buttonSave.Location = new Point(12, 137);
|
|
||||||
buttonSave.Name = "buttonSave";
|
|
||||||
buttonSave.Size = new Size(359, 23);
|
|
||||||
buttonSave.TabIndex = 31;
|
|
||||||
buttonSave.Text = "Сохранить";
|
|
||||||
buttonSave.UseVisualStyleBackColor = true;
|
|
||||||
buttonSave.Click += ButtonSave_Click;
|
|
||||||
//
|
|
||||||
// FormService
|
|
||||||
//
|
|
||||||
AutoScaleDimensions = new SizeF(7F, 15F);
|
|
||||||
AutoScaleMode = AutoScaleMode.Font;
|
|
||||||
ClientSize = new Size(387, 208);
|
|
||||||
Controls.Add(buttonCancel);
|
|
||||||
Controls.Add(buttonSave);
|
|
||||||
Controls.Add(labelServiceDescription);
|
|
||||||
Controls.Add(richTextBoxServiceDescription);
|
|
||||||
Controls.Add(comboBoxServiceContractId);
|
|
||||||
Controls.Add(labelServiceContractId);
|
|
||||||
Name = "FormService";
|
|
||||||
StartPosition = FormStartPosition.CenterParent;
|
|
||||||
Text = "Услуга";
|
|
||||||
ResumeLayout(false);
|
|
||||||
PerformLayout();
|
|
||||||
}
|
|
||||||
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
private ComboBox comboBoxServiceContractId;
|
|
||||||
private Label labelServiceContractId;
|
|
||||||
private Label labelServiceDescription;
|
|
||||||
private RichTextBox richTextBoxServiceDescription;
|
|
||||||
private Button buttonCancel;
|
|
||||||
private Button buttonSave;
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,64 +0,0 @@
|
|||||||
using PIbd_23_Gutorov_I.A._IT_Company.Entities;
|
|
||||||
using PIbd_23_Gutorov_I.A._IT_Company.Repositories;
|
|
||||||
|
|
||||||
namespace PIbd_23_Gutorov_I.A._IT_Company.Forms
|
|
||||||
{
|
|
||||||
public partial class FormService : Form
|
|
||||||
{
|
|
||||||
private readonly IServiceRepository _serviceRepository;
|
|
||||||
|
|
||||||
private int? _serviceId;
|
|
||||||
|
|
||||||
public int Id
|
|
||||||
{
|
|
||||||
set
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
var contract = _serviceRepository.ReadServiceById(value);
|
|
||||||
if (contract == null) throw new InvalidDataException(nameof(contract));
|
|
||||||
|
|
||||||
richTextBoxServiceDescription.Text = contract.Description;
|
|
||||||
_serviceId = value;
|
|
||||||
}
|
|
||||||
catch (Exception ex)
|
|
||||||
{
|
|
||||||
MessageBox.Show(ex.Message, "Ошибка при получении данных", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public FormService(IServiceRepository serviceRepository, IContractRepository contractRepository)
|
|
||||||
{
|
|
||||||
InitializeComponent();
|
|
||||||
_serviceRepository = serviceRepository ?? throw new ArgumentNullException(nameof(serviceRepository));
|
|
||||||
|
|
||||||
comboBoxServiceContractId.DataSource = contractRepository.ReadContracts();
|
|
||||||
comboBoxServiceContractId.DisplayMember = "Id";
|
|
||||||
}
|
|
||||||
|
|
||||||
private void ButtonSave_Click(object sender, EventArgs e)
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
if (comboBoxServiceContractId.SelectedIndex < 0 ||
|
|
||||||
string.IsNullOrEmpty(richTextBoxServiceDescription.Text))
|
|
||||||
{
|
|
||||||
throw new Exception("Имеются незаполненные поля");
|
|
||||||
}
|
|
||||||
|
|
||||||
_serviceRepository.CreateService(Service.CreateEntity(0,
|
|
||||||
richTextBoxServiceDescription.Text, (int)comboBoxServiceContractId.SelectedValue!));
|
|
||||||
|
|
||||||
Close();
|
|
||||||
}
|
|
||||||
catch (Exception ex)
|
|
||||||
{
|
|
||||||
MessageBox.Show(ex.Message, "Ошибка при сохранении", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void ButtonCancel_Click(object sender, EventArgs e) => Close();
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,120 +0,0 @@
|
|||||||
<?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>
|
|
@ -1,126 +0,0 @@
|
|||||||
namespace PIbd_23_Gutorov_I.A._IT_Company.Forms
|
|
||||||
{
|
|
||||||
partial class FormServices
|
|
||||||
{
|
|
||||||
/// <summary>
|
|
||||||
/// Required designer variable.
|
|
||||||
/// </summary>
|
|
||||||
private System.ComponentModel.IContainer components = null;
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Clean up any resources being used.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
|
|
||||||
protected override void Dispose(bool disposing)
|
|
||||||
{
|
|
||||||
if (disposing && (components != null))
|
|
||||||
{
|
|
||||||
components.Dispose();
|
|
||||||
}
|
|
||||||
base.Dispose(disposing);
|
|
||||||
}
|
|
||||||
|
|
||||||
#region Windows Form Designer generated code
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Required method for Designer support - do not modify
|
|
||||||
/// the contents of this method with the code editor.
|
|
||||||
/// </summary>
|
|
||||||
private void InitializeComponent()
|
|
||||||
{
|
|
||||||
dataGridViewData = new DataGridView();
|
|
||||||
panel = new Panel();
|
|
||||||
buttonDel = new Button();
|
|
||||||
buttonUpd = new Button();
|
|
||||||
buttonAdd = new Button();
|
|
||||||
((System.ComponentModel.ISupportInitialize)dataGridViewData).BeginInit();
|
|
||||||
panel.SuspendLayout();
|
|
||||||
SuspendLayout();
|
|
||||||
//
|
|
||||||
// dataGridViewData
|
|
||||||
//
|
|
||||||
dataGridViewData.AllowUserToAddRows = false;
|
|
||||||
dataGridViewData.AllowUserToDeleteRows = false;
|
|
||||||
dataGridViewData.AllowUserToResizeColumns = false;
|
|
||||||
dataGridViewData.AllowUserToResizeRows = false;
|
|
||||||
dataGridViewData.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill;
|
|
||||||
dataGridViewData.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize;
|
|
||||||
dataGridViewData.Dock = DockStyle.Fill;
|
|
||||||
dataGridViewData.Location = new Point(0, 0);
|
|
||||||
dataGridViewData.MultiSelect = false;
|
|
||||||
dataGridViewData.Name = "dataGridViewData";
|
|
||||||
dataGridViewData.ReadOnly = true;
|
|
||||||
dataGridViewData.RowHeadersVisible = false;
|
|
||||||
dataGridViewData.SelectionMode = DataGridViewSelectionMode.FullRowSelect;
|
|
||||||
dataGridViewData.Size = new Size(677, 450);
|
|
||||||
dataGridViewData.TabIndex = 5;
|
|
||||||
//
|
|
||||||
// panel
|
|
||||||
//
|
|
||||||
panel.Controls.Add(buttonDel);
|
|
||||||
panel.Controls.Add(buttonUpd);
|
|
||||||
panel.Controls.Add(buttonAdd);
|
|
||||||
panel.Dock = DockStyle.Right;
|
|
||||||
panel.Location = new Point(677, 0);
|
|
||||||
panel.Name = "panel";
|
|
||||||
panel.Size = new Size(123, 450);
|
|
||||||
panel.TabIndex = 4;
|
|
||||||
//
|
|
||||||
// buttonDel
|
|
||||||
//
|
|
||||||
buttonDel.BackgroundImage = Properties.Resources.icon_remove_button;
|
|
||||||
buttonDel.BackgroundImageLayout = ImageLayout.Stretch;
|
|
||||||
buttonDel.Location = new Point(16, 204);
|
|
||||||
buttonDel.Name = "buttonDel";
|
|
||||||
buttonDel.Size = new Size(90, 90);
|
|
||||||
buttonDel.TabIndex = 2;
|
|
||||||
buttonDel.UseVisualStyleBackColor = true;
|
|
||||||
buttonDel.Click += ButtonDel_Click;
|
|
||||||
//
|
|
||||||
// buttonUpd
|
|
||||||
//
|
|
||||||
buttonUpd.BackgroundImage = Properties.Resources.icon_edit_button;
|
|
||||||
buttonUpd.BackgroundImageLayout = ImageLayout.Stretch;
|
|
||||||
buttonUpd.Location = new Point(16, 108);
|
|
||||||
buttonUpd.Name = "buttonUpd";
|
|
||||||
buttonUpd.Size = new Size(90, 90);
|
|
||||||
buttonUpd.TabIndex = 1;
|
|
||||||
buttonUpd.UseVisualStyleBackColor = true;
|
|
||||||
buttonUpd.Click += ButtonUpd_Click;
|
|
||||||
//
|
|
||||||
// buttonAdd
|
|
||||||
//
|
|
||||||
buttonAdd.BackgroundImage = Properties.Resources.icon_add_button;
|
|
||||||
buttonAdd.BackgroundImageLayout = ImageLayout.Stretch;
|
|
||||||
buttonAdd.Location = new Point(16, 12);
|
|
||||||
buttonAdd.Name = "buttonAdd";
|
|
||||||
buttonAdd.Size = new Size(90, 90);
|
|
||||||
buttonAdd.TabIndex = 0;
|
|
||||||
buttonAdd.UseVisualStyleBackColor = true;
|
|
||||||
buttonAdd.Click += ButtonAdd_Click;
|
|
||||||
//
|
|
||||||
// FormServices
|
|
||||||
//
|
|
||||||
AutoScaleDimensions = new SizeF(7F, 15F);
|
|
||||||
AutoScaleMode = AutoScaleMode.Font;
|
|
||||||
ClientSize = new Size(800, 450);
|
|
||||||
Controls.Add(dataGridViewData);
|
|
||||||
Controls.Add(panel);
|
|
||||||
Name = "FormServices";
|
|
||||||
StartPosition = FormStartPosition.CenterParent;
|
|
||||||
Text = "Услуги";
|
|
||||||
Load += FormServices_Load;
|
|
||||||
((System.ComponentModel.ISupportInitialize)dataGridViewData).EndInit();
|
|
||||||
panel.ResumeLayout(false);
|
|
||||||
ResumeLayout(false);
|
|
||||||
}
|
|
||||||
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
private DataGridView dataGridViewData;
|
|
||||||
private Panel panel;
|
|
||||||
private Button buttonDel;
|
|
||||||
private Button buttonUpd;
|
|
||||||
private Button buttonAdd;
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,96 +0,0 @@
|
|||||||
using PIbd_23_Gutorov_I.A._IT_Company.Repositories;
|
|
||||||
using Unity;
|
|
||||||
|
|
||||||
namespace PIbd_23_Gutorov_I.A._IT_Company.Forms
|
|
||||||
{
|
|
||||||
public partial class FormServices : Form
|
|
||||||
{
|
|
||||||
private readonly IUnityContainer _container;
|
|
||||||
|
|
||||||
private readonly IServiceRepository _serviceRepository;
|
|
||||||
|
|
||||||
public FormServices(IUnityContainer container, IServiceRepository serviceRepository)
|
|
||||||
{
|
|
||||||
InitializeComponent();
|
|
||||||
_container = container ?? throw new ArgumentException(nameof(container));
|
|
||||||
_serviceRepository = serviceRepository ?? throw new ArgumentException(nameof(serviceRepository));
|
|
||||||
}
|
|
||||||
|
|
||||||
private void FormServices_Load(object sender, EventArgs e)
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
LoadList();
|
|
||||||
}
|
|
||||||
catch (Exception ex)
|
|
||||||
{
|
|
||||||
MessageBox.Show(ex.Message, "Ошибка при загрузке", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void ButtonAdd_Click(object sender, EventArgs e)
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
_container.Resolve<FormService>().ShowDialog();
|
|
||||||
LoadList();
|
|
||||||
}
|
|
||||||
catch (Exception ex)
|
|
||||||
{
|
|
||||||
MessageBox.Show(ex.Message, "Ошибка при добавлении", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void ButtonUpd_Click(object sender, EventArgs e)
|
|
||||||
{
|
|
||||||
if (!TryGetIdentifierFromSelectedRow(out var findId))
|
|
||||||
return;
|
|
||||||
|
|
||||||
try
|
|
||||||
{
|
|
||||||
var form = _container.Resolve<FormService>();
|
|
||||||
form.Id = findId;
|
|
||||||
form.ShowDialog();
|
|
||||||
LoadList();
|
|
||||||
}
|
|
||||||
catch (Exception ex)
|
|
||||||
{
|
|
||||||
MessageBox.Show(ex.Message, "Ошибка при изменении", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void ButtonDel_Click(object sender, EventArgs e)
|
|
||||||
{
|
|
||||||
if (!TryGetIdentifierFromSelectedRow(out var findId))
|
|
||||||
return;
|
|
||||||
|
|
||||||
if (MessageBox.Show("Удалить запись?", "Удаление", MessageBoxButtons.YesNo) != DialogResult.Yes)
|
|
||||||
return;
|
|
||||||
|
|
||||||
try
|
|
||||||
{
|
|
||||||
_serviceRepository.DeleteService(findId);
|
|
||||||
LoadList();
|
|
||||||
}
|
|
||||||
catch (Exception ex)
|
|
||||||
{
|
|
||||||
MessageBox.Show(ex.Message, "Ошибка при удалении", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void LoadList() => dataGridViewData.DataSource = _serviceRepository.ReadServices();
|
|
||||||
|
|
||||||
private bool TryGetIdentifierFromSelectedRow(out int id)
|
|
||||||
{
|
|
||||||
id = 0;
|
|
||||||
if (dataGridViewData.SelectedRows.Count < 1)
|
|
||||||
{
|
|
||||||
MessageBox.Show("Нет выбранной записи", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
id = Convert.ToInt32(dataGridViewData.SelectedRows[0].Cells["Id"].Value);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,120 +0,0 @@
|
|||||||
<?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,7 +32,6 @@ 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>();
|
||||||
|
|
||||||
|
@ -1,16 +0,0 @@
|
|||||||
using PIbd_23_Gutorov_I.A._IT_Company.Entities;
|
|
||||||
|
|
||||||
namespace PIbd_23_Gutorov_I.A._IT_Company.Repositories;
|
|
||||||
|
|
||||||
public interface IServiceRepository
|
|
||||||
{
|
|
||||||
IEnumerable<Service> ReadServices(int? contractId = null);
|
|
||||||
|
|
||||||
Service ReadServiceById(int id);
|
|
||||||
|
|
||||||
void CreateService(Service service);
|
|
||||||
|
|
||||||
void UpdateService(Service service);
|
|
||||||
|
|
||||||
void DeleteService(int id);
|
|
||||||
}
|
|
@ -1,125 +0,0 @@
|
|||||||
using Dapper;
|
|
||||||
using Microsoft.Extensions.Logging;
|
|
||||||
using Newtonsoft.Json;
|
|
||||||
using Npgsql;
|
|
||||||
using PIbd_23_Gutorov_I.A._IT_Company.Entities;
|
|
||||||
|
|
||||||
namespace PIbd_23_Gutorov_I.A._IT_Company.Repositories.Implementations;
|
|
||||||
|
|
||||||
internal class ServiceRepository : IServiceRepository
|
|
||||||
{
|
|
||||||
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, ContractId)
|
|
||||||
VALUES (@Description, @ContractId);
|
|
||||||
";
|
|
||||||
connection.Execute(queryInsert, service);
|
|
||||||
}
|
|
||||||
catch (Exception ex)
|
|
||||||
{
|
|
||||||
_logger.LogError(ex, "Ошибка при добавлении объекта");
|
|
||||||
throw;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
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)
|
|
||||||
{
|
|
||||||
_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(int? contractId = null)
|
|
||||||
{
|
|
||||||
_logger.LogInformation("Получение всех объектов");
|
|
||||||
|
|
||||||
try
|
|
||||||
{
|
|
||||||
using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
|
|
||||||
var queryInsert = @"
|
|
||||||
SELECT * FROM Services;
|
|
||||||
";
|
|
||||||
var services = connection.Query<Service>(queryInsert);
|
|
||||||
_logger.LogDebug("Полученные объекты: {json}", JsonConvert.SerializeObject(services));
|
|
||||||
return services;
|
|
||||||
}
|
|
||||||
catch (Exception ex)
|
|
||||||
{
|
|
||||||
_logger.LogError(ex, "Ошибка при чтении объектов");
|
|
||||||
throw;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
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, ContractId = @ContractId
|
|
||||||
WHERE Id = @Id;
|
|
||||||
";
|
|
||||||
connection.Execute(queryUpdate, service);
|
|
||||||
}
|
|
||||||
catch (Exception ex)
|
|
||||||
{
|
|
||||||
_logger.LogError(ex, "Ошибка при редактировании объекта");
|
|
||||||
throw;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
Loading…
x
Reference in New Issue
Block a user