Лабораторная работа 2 (доработаны формы)
This commit is contained in:
parent
a5a1099be9
commit
b0e19ce372
@ -21,7 +21,7 @@ namespace ProjectConfectioneryFactory.Forms
|
|||||||
{
|
{
|
||||||
throw new InvalidDataException(nameof(order));
|
throw new InvalidDataException(nameof(order));
|
||||||
}
|
}
|
||||||
checkBoxCompleted.Enabled = order.Completed;
|
checkBoxCompleted.Checked = order.Completed;
|
||||||
_orderId = value;
|
_orderId = value;
|
||||||
}
|
}
|
||||||
catch (Exception ex) { MessageBox.Show(ex.Message, "Ошибка при получении данных", MessageBoxButtons.OK, MessageBoxIcon.Error); return; }
|
catch (Exception ex) { MessageBox.Show(ex.Message, "Ошибка при получении данных", MessageBoxButtons.OK, MessageBoxIcon.Error); return; }
|
||||||
@ -33,7 +33,7 @@ namespace ProjectConfectioneryFactory.Forms
|
|||||||
InitializeComponent();
|
InitializeComponent();
|
||||||
_orderRepository = orderRepository ?? throw new ArgumentNullException(nameof(orderRepository));
|
_orderRepository = orderRepository ?? throw new ArgumentNullException(nameof(orderRepository));
|
||||||
comboBoxClient.DataSource = clientRepository.ReadClients();
|
comboBoxClient.DataSource = clientRepository.ReadClients();
|
||||||
comboBoxClient.DisplayMember = "FirstName";
|
comboBoxClient.DisplayMember = "Phone";
|
||||||
comboBoxClient.ValueMember = "Id";
|
comboBoxClient.ValueMember = "Id";
|
||||||
|
|
||||||
ColumnProductName.DataSource = productRepository.ReadProducts();
|
ColumnProductName.DataSource = productRepository.ReadProducts();
|
||||||
@ -45,7 +45,7 @@ namespace ProjectConfectioneryFactory.Forms
|
|||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
if (dataGridViewProducts.RowCount < 1 || comboBoxClient.SelectedIndex < 0)
|
if (dataGridViewProducts.RowCount <= 1 || comboBoxClient.SelectedIndex < 0)
|
||||||
{
|
{
|
||||||
throw new Exception("Имеются незаполненные поля");
|
throw new Exception("Имеются незаполненные поля");
|
||||||
}
|
}
|
||||||
@ -74,14 +74,14 @@ namespace ProjectConfectioneryFactory.Forms
|
|||||||
var list = new List<OrderProduct>();
|
var list = new List<OrderProduct>();
|
||||||
foreach (DataGridViewRow row in dataGridViewProducts.Rows)
|
foreach (DataGridViewRow row in dataGridViewProducts.Rows)
|
||||||
{
|
{
|
||||||
if (row.Cells["ColumnComponent"].Value == null ||
|
if (row.Cells["ColumnProductName"].Value == null ||
|
||||||
row.Cells["ColumnWeight"].Value == null)
|
row.Cells["ColumnProductCount"].Value == null)
|
||||||
{
|
{
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
list.Add(OrderProduct.CreateEntity(0,
|
list.Add(OrderProduct.CreateEntity(0,
|
||||||
Convert.ToInt32(row.Cells["ColumnComponent"].Value),
|
Convert.ToInt32(row.Cells["ColumnProductName"].Value),
|
||||||
Convert.ToInt32(row.Cells["ColumnWeight"].Value)));
|
Convert.ToInt32(row.Cells["ColumnProductCount"].Value)));
|
||||||
}
|
}
|
||||||
return list;
|
return list;
|
||||||
}
|
}
|
||||||
|
@ -1,8 +1,6 @@
|
|||||||
using Microsoft.VisualBasic.FileIO;
|
using ProjectConfectioneryFactory.Entities;
|
||||||
using ProjectConfectioneryFactory.Entities;
|
|
||||||
using ProjectConfectioneryFactory.Entities.Enums;
|
using ProjectConfectioneryFactory.Entities.Enums;
|
||||||
using ProjectConfectioneryFactory.Repositories;
|
using ProjectConfectioneryFactory.Repositories;
|
||||||
using ProjectConfectioneryFactory.Repositories.Implementations;
|
|
||||||
|
|
||||||
namespace ProjectConfectioneryFactory.Forms
|
namespace ProjectConfectioneryFactory.Forms
|
||||||
{
|
{
|
||||||
@ -46,7 +44,7 @@ namespace ProjectConfectioneryFactory.Forms
|
|||||||
{
|
{
|
||||||
InitializeComponent();
|
InitializeComponent();
|
||||||
_productRepository = productRepository ?? throw new ArgumentNullException(nameof(productRepository));
|
_productRepository = productRepository ?? throw new ArgumentNullException(nameof(productRepository));
|
||||||
|
|
||||||
foreach (var elem in Enum.GetValues(typeof(ConfectioneryType)))
|
foreach (var elem in Enum.GetValues(typeof(ConfectioneryType)))
|
||||||
{
|
{
|
||||||
checkedListBoxConfectioneryType.Items.Add(elem);
|
checkedListBoxConfectioneryType.Items.Add(elem);
|
||||||
@ -61,7 +59,7 @@ namespace ProjectConfectioneryFactory.Forms
|
|||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
if (checkedListBoxConfectioneryType.CheckedItems.Count == 0 || string.IsNullOrWhiteSpace(textBoxProductName.Text) || dataGridViewComponents.RowCount < 1)
|
if (checkedListBoxConfectioneryType.CheckedItems.Count == 0 || string.IsNullOrWhiteSpace(textBoxProductName.Text) || dataGridViewComponents.RowCount <= 1)
|
||||||
{
|
{
|
||||||
throw new Exception("Имеются незаполненные поля");
|
throw new Exception("Имеются незаполненные поля");
|
||||||
}
|
}
|
||||||
|
@ -21,7 +21,7 @@ namespace ProjectConfectioneryFactory.Forms
|
|||||||
throw new InvalidDataException(nameof(supply));
|
throw new InvalidDataException(nameof(supply));
|
||||||
}
|
}
|
||||||
numericUpDownWeight.Value = (decimal)supply.Weight;
|
numericUpDownWeight.Value = (decimal)supply.Weight;
|
||||||
checkBoxCompleted.Enabled = supply.Completed;
|
checkBoxCompleted.Checked = supply.Completed;
|
||||||
_supplyId = value;
|
_supplyId = value;
|
||||||
}
|
}
|
||||||
catch (Exception ex) { MessageBox.Show(ex.Message, "Ошибка при получении данных", MessageBoxButtons.OK, MessageBoxIcon.Error); return; }
|
catch (Exception ex) { MessageBox.Show(ex.Message, "Ошибка при получении данных", MessageBoxButtons.OK, MessageBoxIcon.Error); return; }
|
||||||
@ -32,11 +32,13 @@ namespace ProjectConfectioneryFactory.Forms
|
|||||||
{
|
{
|
||||||
InitializeComponent();
|
InitializeComponent();
|
||||||
_supplyRepository = supplyRepository ?? throw new ArgumentNullException(nameof(supplyRepository));
|
_supplyRepository = supplyRepository ?? throw new ArgumentNullException(nameof(supplyRepository));
|
||||||
|
|
||||||
comboBoxSupplier.DataSource = supplierRepository.ReadSuppliers();
|
comboBoxSupplier.DataSource = supplierRepository.ReadSuppliers();
|
||||||
comboBoxSupplier.DisplayMember = "Name";
|
comboBoxSupplier.DisplayMember = "Name";
|
||||||
comboBoxSupplier.ValueMember = "Id";
|
comboBoxSupplier.ValueMember = "Id";
|
||||||
|
|
||||||
comboBoxComponent.DataSource = componentRepository.ReadComponents();
|
comboBoxComponent.DataSource = componentRepository.ReadComponents();
|
||||||
comboBoxComponent.DisplayMember = "ComponentName";
|
comboBoxComponent.DisplayMember = "Name";
|
||||||
comboBoxComponent.ValueMember = "Id";
|
comboBoxComponent.ValueMember = "Id";
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -44,7 +46,7 @@ namespace ProjectConfectioneryFactory.Forms
|
|||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
if (comboBoxSupplier.SelectedIndex < 0 || comboBoxComponent.SelectedIndex < 0 || !checkBoxCompleted.Checked)
|
if (comboBoxSupplier.SelectedIndex < 0 || comboBoxComponent.SelectedIndex < 0)
|
||||||
{
|
{
|
||||||
throw new Exception("Имеются незаполненные поля");
|
throw new Exception("Имеются незаполненные поля");
|
||||||
}
|
}
|
||||||
|
@ -64,7 +64,7 @@ public class ProductRepository : IProductRepository
|
|||||||
var queryUpdate = @"
|
var queryUpdate = @"
|
||||||
UPDATE Products
|
UPDATE Products
|
||||||
SET
|
SET
|
||||||
сonfectioneryType=@сonfectioneryType,
|
ConfectioneryType=@ConfectioneryType,
|
||||||
Name=@Name,
|
Name=@Name,
|
||||||
Price=@Price
|
Price=@Price
|
||||||
WHERE Id=@Id";
|
WHERE Id=@Id";
|
||||||
@ -117,7 +117,7 @@ public class ProductRepository : IProductRepository
|
|||||||
var querySelect = @"
|
var querySelect = @"
|
||||||
SELECT *
|
SELECT *
|
||||||
FROM Products
|
FROM Products
|
||||||
WHERE Id=@id";
|
WHERE Id=@Id";
|
||||||
var product = connection.QueryFirst<Product>(querySelect, new { id });
|
var product = connection.QueryFirst<Product>(querySelect, new { id });
|
||||||
_logger.LogDebug("Найденный объект: {json}", JsonConvert.SerializeObject(product));
|
_logger.LogDebug("Найденный объект: {json}", JsonConvert.SerializeObject(product));
|
||||||
return product;
|
return product;
|
||||||
@ -135,7 +135,7 @@ public class ProductRepository : IProductRepository
|
|||||||
try
|
try
|
||||||
{
|
{
|
||||||
using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
|
using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
|
||||||
var querySelect = "SELECT * FROM Products";
|
var querySelect = @"SELECT * FROM Products";
|
||||||
var products = connection.Query<Product>(querySelect);
|
var products = connection.Query<Product>(querySelect);
|
||||||
_logger.LogDebug("Полученные объекты: {json}", JsonConvert.SerializeObject(products));
|
_logger.LogDebug("Полученные объекты: {json}", JsonConvert.SerializeObject(products));
|
||||||
return products;
|
return products;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user