This commit is contained in:
nezui1 2024-11-25 14:49:17 +04:00
parent 09557899c2
commit 95d2100685
8 changed files with 129 additions and 175 deletions

View File

@ -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
}; };
} }

View File

@ -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;
} }

View File

@ -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>

View File

@ -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;

View File

@ -41,6 +41,7 @@ namespace ProjectCompRepair.Forms
} }
_service = value; _service = value;
numericUpDownPrice.Value = (int)service.Price;
} }
catch (Exception ex) catch (Exception ex)
{ {

View File

@ -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);
} }

View File

@ -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();
}
}

View File

@ -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,34 +74,7 @@ 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
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, "Ошибка при редактировании объекта");
throw;
}
}
public void DeleteOrder(int id) public void DeleteOrder(int id)
{ {
_logger.LogInformation("Удаление объекта"); _logger.LogInformation("Удаление объекта");
@ -80,7 +85,7 @@ WHERE ID = @Id;";
connection.Open(); connection.Open();
var queryDelete = @" var queryDelete = @"
DELETE FROM Order DELETE FROM Orderl
WHERE ID = @id WHERE ID = @id
" "
; ;
@ -102,7 +107,7 @@ WHERE ID = @id
connection.Open(); connection.Open();
var querySelect = @" var querySelect = @"
SELECT * FROM Order SELECT * FROM Orderl
WHERE ID = @id WHERE ID = @id
"; ";
var order = connection.QueryFirst<Order>(querySelect, new { id }); var order = connection.QueryFirst<Order>(querySelect, new { id });
@ -124,7 +129,7 @@ WHERE ID = @id
using var connection = new NpgsqlConnection(_connectionString.ConnectionString); using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
connection.Open(); connection.Open();
var querySelect = @"SELECT * FROM Order"; var querySelect = @"SELECT * FROM Orderl";
var order = connection.Query<Order>(querySelect); var order = connection.Query<Order>(querySelect);
_logger.LogDebug("Полученные объекты : {json}", JsonConvert.SerializeObject(order)); _logger.LogDebug("Полученные объекты : {json}", JsonConvert.SerializeObject(order));
return order; return order;