сдал
This commit is contained in:
parent
09557899c2
commit
95d2100685
@ -23,15 +23,17 @@ public class Order
|
|||||||
public IEnumerable<ServicesOrder> ServicesOrders { get; private set; } = [];
|
public IEnumerable<ServicesOrder> ServicesOrders { get; private set; } = [];
|
||||||
|
|
||||||
|
|
||||||
public static Order CreateElement(int id, string name, string coment, int masterId)
|
public static Order CreateElement(int id, string name,DateTime date, string coment, int masterId, IEnumerable<AccessoiresOrder> accessoiresOrders, IEnumerable<ServicesOrder> servicesOrder)
|
||||||
{
|
{
|
||||||
return new Order()
|
return new Order()
|
||||||
{
|
{
|
||||||
Id = id,
|
Id = id,
|
||||||
Name = name,
|
Name = name,
|
||||||
Coment = coment,
|
Coment = coment,
|
||||||
Date = DateTime.Now,
|
Date = date,
|
||||||
MasterID = masterId
|
MasterID = masterId,
|
||||||
|
AccessoiresOrders = accessoiresOrders,
|
||||||
|
ServicesOrders = servicesOrder
|
||||||
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
@ -70,7 +70,7 @@ public partial class FormOrder : Form
|
|||||||
{
|
{
|
||||||
throw new Exception("Имеются незаполненые поля");
|
throw new Exception("Имеются незаполненые поля");
|
||||||
}
|
}
|
||||||
_orderRepository.CreateOrder(Order.CreateElement(0, textBoxName.Text, textBoxComent.Text, (int)comboBoxMaster.SelectedValue!));
|
_orderRepository.CreateOrder(Order.CreateElement(0, textBoxName.Text,dateTimePicker.Value, textBoxComent.Text, (int)comboBoxMaster.SelectedValue!, CreateListAccessoiresOrderFromDataGrid(), CreateListServicesOrderFromDataGrid()));
|
||||||
Close();
|
Close();
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
@ -87,13 +87,13 @@ public partial class FormOrder : Form
|
|||||||
var list = new List<AccessoiresOrder>();
|
var list = new List<AccessoiresOrder>();
|
||||||
foreach (DataGridViewRow row in dataGridViewAccessories.Rows)
|
foreach (DataGridViewRow row in dataGridViewAccessories.Rows)
|
||||||
{
|
{
|
||||||
if (row.Cells["ColumnAccessoires"].Value == null ||
|
if (row.Cells["ColumnAccessories"].Value == null ||
|
||||||
row.Cells["ColumnCount"].Value == null)
|
row.Cells["ColumnCount"].Value == null)
|
||||||
{
|
{
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
list.Add(AccessoiresOrder.CreateElement(0,
|
list.Add(AccessoiresOrder.CreateElement(0,
|
||||||
Convert.ToInt32(row.Cells["ColumnAccessoires"].Value),
|
Convert.ToInt32(row.Cells["ColumnAccessories"].Value),
|
||||||
Convert.ToInt32(row.Cells["ColumnCount"].Value)));
|
Convert.ToInt32(row.Cells["ColumnCount"].Value)));
|
||||||
}
|
}
|
||||||
return list;
|
return list;
|
||||||
@ -102,16 +102,16 @@ public partial class FormOrder : Form
|
|||||||
private List<ServicesOrder> CreateListServicesOrderFromDataGrid()
|
private List<ServicesOrder> CreateListServicesOrderFromDataGrid()
|
||||||
{
|
{
|
||||||
var list = new List<ServicesOrder>();
|
var list = new List<ServicesOrder>();
|
||||||
foreach (DataGridViewRow row in dataGridViewAccessories.Rows)
|
foreach (DataGridViewRow row in dataGridViewServices.Rows)
|
||||||
{
|
{
|
||||||
if (row.Cells["ColumnServices"].Value == null ||
|
if (row.Cells["ColumnService"].Value == null ||
|
||||||
row.Cells["ColumnCountServices"].Value == null)
|
row.Cells["ColumnCountServ"].Value == null)
|
||||||
{
|
{
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
list.Add(ServicesOrder.CreateElement(0,
|
list.Add(ServicesOrder.CreateElement(0,
|
||||||
Convert.ToInt32(row.Cells["ColumnAccessoires"].Value),
|
Convert.ToInt32(row.Cells["ColumnService"].Value),
|
||||||
Convert.ToInt32(row.Cells["ColumnCount"].Value)));
|
Convert.ToInt32(row.Cells["ColumnCountServ"].Value)));
|
||||||
}
|
}
|
||||||
return list;
|
return list;
|
||||||
}
|
}
|
||||||
|
@ -123,18 +123,6 @@
|
|||||||
<metadata name="ColumnCount.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
|
<metadata name="ColumnCount.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
|
||||||
<value>True</value>
|
<value>True</value>
|
||||||
</metadata>
|
</metadata>
|
||||||
<metadata name="ColumnAccessories.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
|
|
||||||
<value>True</value>
|
|
||||||
</metadata>
|
|
||||||
<metadata name="ColumnCount.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
|
|
||||||
<value>True</value>
|
|
||||||
</metadata>
|
|
||||||
<metadata name="ColumnService.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
|
|
||||||
<value>True</value>
|
|
||||||
</metadata>
|
|
||||||
<metadata name="ColumnCountServ.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
|
|
||||||
<value>True</value>
|
|
||||||
</metadata>
|
|
||||||
<metadata name="ColumnService.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
|
<metadata name="ColumnService.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
|
||||||
<value>True</value>
|
<value>True</value>
|
||||||
</metadata>
|
</metadata>
|
||||||
|
@ -29,7 +29,6 @@
|
|||||||
private void InitializeComponent()
|
private void InitializeComponent()
|
||||||
{
|
{
|
||||||
buttonDel = new Button();
|
buttonDel = new Button();
|
||||||
buttonChange = new Button();
|
|
||||||
buttonCreate = new Button();
|
buttonCreate = new Button();
|
||||||
dataGridView = new DataGridView();
|
dataGridView = new DataGridView();
|
||||||
panelButtons = new Panel();
|
panelButtons = new Panel();
|
||||||
@ -41,24 +40,13 @@
|
|||||||
//
|
//
|
||||||
buttonDel.BackgroundImage = Properties.Resources.pngwing_com__7_;
|
buttonDel.BackgroundImage = Properties.Resources.pngwing_com__7_;
|
||||||
buttonDel.BackgroundImageLayout = ImageLayout.Stretch;
|
buttonDel.BackgroundImageLayout = ImageLayout.Stretch;
|
||||||
buttonDel.Location = new Point(40, 255);
|
buttonDel.Location = new Point(40, 173);
|
||||||
buttonDel.Name = "buttonDel";
|
buttonDel.Name = "buttonDel";
|
||||||
buttonDel.Size = new Size(94, 91);
|
buttonDel.Size = new Size(94, 91);
|
||||||
buttonDel.TabIndex = 2;
|
buttonDel.TabIndex = 2;
|
||||||
buttonDel.UseVisualStyleBackColor = true;
|
buttonDel.UseVisualStyleBackColor = true;
|
||||||
buttonDel.Click += ButtonDel_Click;
|
buttonDel.Click += ButtonDel_Click;
|
||||||
//
|
//
|
||||||
// buttonChange
|
|
||||||
//
|
|
||||||
buttonChange.BackgroundImage = Properties.Resources.pngwing_com__8_;
|
|
||||||
buttonChange.BackgroundImageLayout = ImageLayout.Stretch;
|
|
||||||
buttonChange.Location = new Point(40, 149);
|
|
||||||
buttonChange.Name = "buttonChange";
|
|
||||||
buttonChange.Size = new Size(94, 89);
|
|
||||||
buttonChange.TabIndex = 1;
|
|
||||||
buttonChange.UseVisualStyleBackColor = true;
|
|
||||||
buttonChange.Click += ButtonChange_Click;
|
|
||||||
//
|
|
||||||
// buttonCreate
|
// buttonCreate
|
||||||
//
|
//
|
||||||
buttonCreate.BackgroundImage = Properties.Resources.pngwing_com__6_;
|
buttonCreate.BackgroundImage = Properties.Resources.pngwing_com__6_;
|
||||||
@ -83,7 +71,6 @@
|
|||||||
// panelButtons
|
// panelButtons
|
||||||
//
|
//
|
||||||
panelButtons.Controls.Add(buttonDel);
|
panelButtons.Controls.Add(buttonDel);
|
||||||
panelButtons.Controls.Add(buttonChange);
|
|
||||||
panelButtons.Controls.Add(buttonCreate);
|
panelButtons.Controls.Add(buttonCreate);
|
||||||
panelButtons.Dock = DockStyle.Right;
|
panelButtons.Dock = DockStyle.Right;
|
||||||
panelButtons.Location = new Point(545, 0);
|
panelButtons.Location = new Point(545, 0);
|
||||||
@ -109,7 +96,6 @@
|
|||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
private Button buttonDel;
|
private Button buttonDel;
|
||||||
private Button buttonChange;
|
|
||||||
private Button buttonCreate;
|
private Button buttonCreate;
|
||||||
private DataGridView dataGridView;
|
private DataGridView dataGridView;
|
||||||
private Panel panelButtons;
|
private Panel panelButtons;
|
||||||
|
@ -41,6 +41,7 @@ namespace ProjectCompRepair.Forms
|
|||||||
}
|
}
|
||||||
|
|
||||||
_service = value;
|
_service = value;
|
||||||
|
numericUpDownPrice.Value = (int)service.Price;
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
|
@ -17,8 +17,6 @@ public interface IOrderRepository
|
|||||||
|
|
||||||
void CreateOrder(Order order);
|
void CreateOrder(Order order);
|
||||||
|
|
||||||
void UpdateOrder(Order order);
|
|
||||||
|
|
||||||
void DeleteOrder(int id);
|
void DeleteOrder(int id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,26 +0,0 @@
|
|||||||
using ProjectCompRepair.Entities;
|
|
||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Text;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
|
|
||||||
namespace ProjectCompRepair.Repositories.Implemantations;
|
|
||||||
|
|
||||||
public class AccessoriesOrderRepository : IAccessoriesOrder
|
|
||||||
{
|
|
||||||
public void CreateAccessoriesOrder(AccessoiresOrder accessoriesOrder)
|
|
||||||
{
|
|
||||||
throw new NotImplementedException();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void DeleteAccessoriesOrder(int id)
|
|
||||||
{
|
|
||||||
throw new NotImplementedException();
|
|
||||||
}
|
|
||||||
|
|
||||||
public IEnumerable<AccessoiresOrder> ReadAccessoiresOrder(int? Id = 0, int? orderId = 0, int? count = 0)
|
|
||||||
{
|
|
||||||
throw new NotImplementedException();
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,27 +1,27 @@
|
|||||||
using Dapper;
|
using Dapper;
|
||||||
using Microsoft.Extensions.Logging;
|
using Microsoft.Extensions.Logging;
|
||||||
using Newtonsoft.Json;
|
using Newtonsoft.Json;
|
||||||
using Npgsql;
|
using Npgsql;
|
||||||
using ProjectCompRepair.Entities;
|
using ProjectCompRepair.Entities;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
namespace ProjectCompRepair.Repositories.Implemantations;
|
namespace ProjectCompRepair.Repositories.Implemantations;
|
||||||
|
|
||||||
public class OrderRepository : IOrderRepository
|
public class OrderRepository : IOrderRepository
|
||||||
{
|
|
||||||
private readonly IConnectionString _connectionString;
|
|
||||||
|
|
||||||
private readonly ILogger<AccessoriesRepository> _logger;
|
|
||||||
|
|
||||||
public OrderRepository(IConnectionString connectionString, ILogger<AccessoriesRepository> logger)
|
|
||||||
{
|
{
|
||||||
_connectionString = connectionString;
|
private readonly IConnectionString _connectionString;
|
||||||
_logger = logger;
|
|
||||||
}
|
private readonly ILogger<AccessoriesRepository> _logger;
|
||||||
|
|
||||||
|
public OrderRepository(IConnectionString connectionString, ILogger<AccessoriesRepository> logger)
|
||||||
|
{
|
||||||
|
_connectionString = connectionString;
|
||||||
|
_logger = logger;
|
||||||
|
}
|
||||||
public void CreateOrder(Order order)
|
public void CreateOrder(Order order)
|
||||||
{
|
{
|
||||||
_logger.LogInformation("Добавление объекта");
|
_logger.LogInformation("Добавление объекта");
|
||||||
@ -30,11 +30,43 @@ public class OrderRepository : IOrderRepository
|
|||||||
{
|
{
|
||||||
using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
|
using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
|
||||||
connection.Open();
|
connection.Open();
|
||||||
|
using var transaction = connection.BeginTransaction();
|
||||||
|
|
||||||
var queryInsert = @"
|
var queryInsert = @"
|
||||||
INSERT INTO Order (Name, Coment, Date, MasterId, AccessoiresOrders, ServicesOrders)
|
INSERT INTO Orderl (Name, Coment, Date, MasterId)
|
||||||
VALUES (@Name, @Coment, @Date, @MasterId, @AccessoiresOrders, @ServicesOrders)";
|
VALUES (@Name, @Coment, @Date, @MasterId);
|
||||||
connection.Execute(queryInsert, order);
|
SELECT MAX(ID) FROM Orderl";
|
||||||
|
|
||||||
|
|
||||||
|
var orderId = connection.QueryFirst<int>(queryInsert, order, transaction);
|
||||||
|
|
||||||
|
var querySubInsertAccessories = @"
|
||||||
|
INSERT INTO AccessoriesOrder (OrderId, Count)
|
||||||
|
VALUES (@OrderId, @Count)";
|
||||||
|
|
||||||
|
foreach (var elem in order.AccessoiresOrders)
|
||||||
|
{
|
||||||
|
connection.Execute(querySubInsertAccessories, new
|
||||||
|
{
|
||||||
|
OrderId = orderId,
|
||||||
|
elem.Count
|
||||||
|
}, transaction);
|
||||||
|
}
|
||||||
|
|
||||||
|
var querySubInsertServices = @"
|
||||||
|
INSERT INTO ServicesOrder (OrderId, Count)
|
||||||
|
VALUES (@OrderId, @Count)";
|
||||||
|
|
||||||
|
foreach (var elem in order.ServicesOrders)
|
||||||
|
{
|
||||||
|
connection.Execute(querySubInsertServices, new
|
||||||
|
{
|
||||||
|
OrderId = orderId,
|
||||||
|
elem.Count
|
||||||
|
}, transaction);
|
||||||
|
}
|
||||||
|
|
||||||
|
transaction.Commit();
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
@ -42,102 +74,75 @@ VALUES (@Name, @Coment, @Date, @MasterId, @AccessoiresOrders, @ServicesOrders)";
|
|||||||
throw;
|
throw;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
public void UpdateOrder(Order order)
|
|
||||||
{
|
|
||||||
_logger.LogInformation("Редактирование объекта");
|
|
||||||
_logger.LogDebug("Объект : {json}", JsonConvert.SerializeObject(order));
|
|
||||||
try
|
|
||||||
{
|
|
||||||
using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
|
|
||||||
connection.Open();
|
|
||||||
|
|
||||||
var queryUpdate = @"UPDATE Order
|
public void DeleteOrder(int id)
|
||||||
SET
|
|
||||||
Name = @Name,
|
|
||||||
Coment = @Coment,
|
|
||||||
Price = @Price,
|
|
||||||
Date = @Date,
|
|
||||||
MasterId = @MasterId,
|
|
||||||
AccessoiresOrders = @AccessoiresOrders,
|
|
||||||
ServicesOrders = @ServicesOrders
|
|
||||||
WHERE ID = @Id;";
|
|
||||||
connection.Execute(queryUpdate, order);
|
|
||||||
}
|
|
||||||
catch (Exception ex)
|
|
||||||
{
|
{
|
||||||
_logger.LogError(ex, "Ошибка при редактировании объекта");
|
_logger.LogInformation("Удаление объекта");
|
||||||
throw;
|
_logger.LogDebug("Объект : {id}", id);
|
||||||
|
try
|
||||||
|
{
|
||||||
|
using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
|
||||||
|
connection.Open();
|
||||||
|
|
||||||
|
var queryDelete = @"
|
||||||
|
DELETE FROM Orderl
|
||||||
|
WHERE ID = @id
|
||||||
|
"
|
||||||
|
;
|
||||||
|
connection.Execute(queryDelete, new { id });
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "Ошибка при удалении объекта");
|
||||||
|
throw;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
public Order ReadOrderById(int id)
|
||||||
|
{
|
||||||
|
_logger.LogInformation("Получение объекта по идентификатору");
|
||||||
|
_logger.LogDebug("Объект : {id}", id);
|
||||||
|
try
|
||||||
|
{
|
||||||
|
using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
|
||||||
|
connection.Open();
|
||||||
|
|
||||||
|
var querySelect = @"
|
||||||
|
SELECT * FROM Orderl
|
||||||
|
WHERE ID = @id
|
||||||
|
";
|
||||||
|
var order = connection.QueryFirst<Order>(querySelect, new { id });
|
||||||
|
_logger.LogDebug("Найденный объект {json}", JsonConvert.SerializeObject(order));
|
||||||
|
return order;
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "Ошибка при поиске объекта");
|
||||||
|
throw;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public IEnumerable<Order> ReadOrder()
|
||||||
|
{
|
||||||
|
_logger.LogInformation("Получение всех объектов");
|
||||||
|
try
|
||||||
|
{
|
||||||
|
using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
|
||||||
|
connection.Open();
|
||||||
|
|
||||||
|
var querySelect = @"SELECT * FROM Orderl";
|
||||||
|
var order = connection.Query<Order>(querySelect);
|
||||||
|
_logger.LogDebug("Полученные объекты : {json}", JsonConvert.SerializeObject(order));
|
||||||
|
return order;
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "Ошибка при чтении объектов");
|
||||||
|
throw;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
public void DeleteOrder(int id)
|
|
||||||
{
|
|
||||||
_logger.LogInformation("Удаление объекта");
|
|
||||||
_logger.LogDebug("Объект : {id}", id);
|
|
||||||
try
|
|
||||||
{
|
|
||||||
using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
|
|
||||||
connection.Open();
|
|
||||||
|
|
||||||
var queryDelete = @"
|
|
||||||
DELETE FROM Order
|
|
||||||
WHERE ID = @id
|
|
||||||
"
|
|
||||||
;
|
|
||||||
connection.Execute(queryDelete, new { id });
|
|
||||||
}
|
|
||||||
catch (Exception ex)
|
|
||||||
{
|
|
||||||
_logger.LogError(ex, "Ошибка при удалении объекта");
|
|
||||||
throw;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
public Order ReadOrderById(int id)
|
|
||||||
{
|
|
||||||
_logger.LogInformation("Получение объекта по идентификатору");
|
|
||||||
_logger.LogDebug("Объект : {id}", id);
|
|
||||||
try
|
|
||||||
{
|
|
||||||
using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
|
|
||||||
connection.Open();
|
|
||||||
|
|
||||||
var querySelect = @"
|
|
||||||
SELECT * FROM Order
|
|
||||||
WHERE ID = @id
|
|
||||||
";
|
|
||||||
var order = connection.QueryFirst<Order>(querySelect, new { id });
|
|
||||||
_logger.LogDebug("Найденный объект {json}", JsonConvert.SerializeObject(order));
|
|
||||||
return order;
|
|
||||||
}
|
|
||||||
catch (Exception ex)
|
|
||||||
{
|
|
||||||
_logger.LogError(ex, "Ошибка при поиске объекта");
|
|
||||||
throw;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public IEnumerable<Order> ReadOrder()
|
|
||||||
{
|
|
||||||
_logger.LogInformation("Получение всех объектов");
|
|
||||||
try
|
|
||||||
{
|
|
||||||
using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
|
|
||||||
connection.Open();
|
|
||||||
|
|
||||||
var querySelect = @"SELECT * FROM Order";
|
|
||||||
var order = connection.Query<Order>(querySelect);
|
|
||||||
_logger.LogDebug("Полученные объекты : {json}", JsonConvert.SerializeObject(order));
|
|
||||||
return order;
|
|
||||||
}
|
|
||||||
catch (Exception ex)
|
|
||||||
{
|
|
||||||
_logger.LogError(ex, "Ошибка при чтении объектов");
|
|
||||||
throw;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
|
Loading…
Reference in New Issue
Block a user