sql запросы + фиксы логики
This commit is contained in:
parent
6d2c12b419
commit
c50bb9bc55
@ -48,12 +48,12 @@ namespace Workshop.Forms
|
||||
var list = new List<ChequeProduct>();
|
||||
foreach (DataGridViewRow row in dataGridViewProducts.Rows)
|
||||
{
|
||||
if (row.Cells["ColumnProductName"].Value == null || row.Cells["ColumnAmount"].Value == null)
|
||||
if (row.Cells["ColumnProductName"].Value == null || row.Cells["ProductAmount"].Value == null)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
list.Add(ChequeProduct.CreateEntity(Convert.ToInt32(row.Cells["ColumnProductName"].Value), 0,
|
||||
Convert.ToInt32(row.Cells["ColumnAmount"].Value)));
|
||||
Convert.ToInt32(row.Cells["ProductAmount"].Value)));
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
2
Workshop/Forms/FormCheques.Designer.cs
generated
2
Workshop/Forms/FormCheques.Designer.cs
generated
@ -82,7 +82,7 @@
|
||||
Controls.Add(panel);
|
||||
Name = "FormCheques";
|
||||
StartPosition = FormStartPosition.CenterParent;
|
||||
Text = "Изделия";
|
||||
Text = "Продажи";
|
||||
Load += FormCheques_Load;
|
||||
panel.ResumeLayout(false);
|
||||
((System.ComponentModel.ISupportInitialize)dataGridProductCreatings).EndInit();
|
||||
|
2
Workshop/Forms/FormMaster.Designer.cs
generated
2
Workshop/Forms/FormMaster.Designer.cs
generated
@ -154,7 +154,7 @@
|
||||
Controls.Add(labelLastName);
|
||||
Controls.Add(labelName);
|
||||
Name = "FormMaster";
|
||||
Text = "FormMaster";
|
||||
Text = "Добавление мастера";
|
||||
((System.ComponentModel.ISupportInitialize)numericUpDownAge).EndInit();
|
||||
ResumeLayout(false);
|
||||
PerformLayout();
|
||||
|
2
Workshop/Forms/FormMasters.Designer.cs
generated
2
Workshop/Forms/FormMasters.Designer.cs
generated
@ -108,7 +108,7 @@
|
||||
Controls.Add(panel);
|
||||
Name = "FormMasters";
|
||||
StartPosition = FormStartPosition.CenterParent;
|
||||
Text = "Изделия";
|
||||
Text = "Мастера";
|
||||
Load += FormMasters_Load;
|
||||
panel.ResumeLayout(false);
|
||||
((System.ComponentModel.ISupportInitialize)dataGridViewMasters).EndInit();
|
||||
|
2
Workshop/Forms/FormMaterial.Designer.cs
generated
2
Workshop/Forms/FormMaterial.Designer.cs
generated
@ -125,7 +125,7 @@
|
||||
Controls.Add(labelPrice);
|
||||
Controls.Add(labelName);
|
||||
Name = "FormMaterial";
|
||||
Text = "FormMaterial";
|
||||
Text = "Добавление материала";
|
||||
((System.ComponentModel.ISupportInitialize)numericUpDownAmount).EndInit();
|
||||
((System.ComponentModel.ISupportInitialize)numericUpDownPrice).EndInit();
|
||||
ResumeLayout(false);
|
||||
|
2
Workshop/Forms/FormMaterials.Designer.cs
generated
2
Workshop/Forms/FormMaterials.Designer.cs
generated
@ -108,7 +108,7 @@
|
||||
Controls.Add(panel);
|
||||
Name = "FormMaterials";
|
||||
StartPosition = FormStartPosition.CenterParent;
|
||||
Text = "Изделия";
|
||||
Text = "Материалы";
|
||||
Load += FormMaterials_Load;
|
||||
panel.ResumeLayout(false);
|
||||
((System.ComponentModel.ISupportInitialize)dataGridViewMaterials).EndInit();
|
||||
|
2
Workshop/Forms/FormProduct.Designer.cs
generated
2
Workshop/Forms/FormProduct.Designer.cs
generated
@ -191,7 +191,7 @@
|
||||
Controls.Add(labelName);
|
||||
Name = "FormProduct";
|
||||
StartPosition = FormStartPosition.CenterParent;
|
||||
Text = "FormProduct";
|
||||
Text = "Добавление изделия";
|
||||
((System.ComponentModel.ISupportInitialize)numericUpDownPrice).EndInit();
|
||||
((System.ComponentModel.ISupportInitialize)numericUpDownAmount).EndInit();
|
||||
groupBoxMaterials.ResumeLayout(false);
|
||||
|
@ -36,6 +36,10 @@ namespace Workshop.Forms
|
||||
checkedListBoxCategory.SetItemChecked(checkedListBoxCategory.Items.IndexOf(elem), true);
|
||||
}
|
||||
}
|
||||
//foreach (ProductMaterial item in product.Materials)
|
||||
//{
|
||||
// dataGridViewMaterials.Rows.Add(materialRepository.ReadMaterialById(item.MaterialId).Name, item.Count);
|
||||
//}
|
||||
textBoxName.Text = product.Name;
|
||||
numericUpDownPrice.Value = (decimal)product.Price;
|
||||
numericUpDownAmount.Value = product.WarehouseAmount;
|
||||
|
2
Workshop/Forms/FormProductCreate.Designer.cs
generated
2
Workshop/Forms/FormProductCreate.Designer.cs
generated
@ -125,7 +125,7 @@
|
||||
Controls.Add(label2);
|
||||
Controls.Add(label1);
|
||||
Name = "FormProductCreate";
|
||||
Text = "FormProductCreate";
|
||||
Text = "Изготовление продукта";
|
||||
ResumeLayout(false);
|
||||
PerformLayout();
|
||||
}
|
||||
|
@ -26,7 +26,7 @@ namespace Workshop.Forms
|
||||
comboBoxProduct.ValueMember = "Id";
|
||||
|
||||
comboBoxMaster.DataSource = masterRepository.ReadMasters();
|
||||
comboBoxMaster.DisplayMember = "Name";
|
||||
comboBoxMaster.DisplayMember = "LastName";
|
||||
comboBoxMaster.ValueMember = "Id";
|
||||
|
||||
}
|
||||
|
2
Workshop/Forms/FormProductCreatings.Designer.cs
generated
2
Workshop/Forms/FormProductCreatings.Designer.cs
generated
@ -95,7 +95,7 @@
|
||||
Controls.Add(panel);
|
||||
Name = "FormProductCreatings";
|
||||
StartPosition = FormStartPosition.CenterParent;
|
||||
Text = "Изделия";
|
||||
Text = "История создания изделий";
|
||||
Load += FormProductCreatings_Load;
|
||||
panel.ResumeLayout(false);
|
||||
((System.ComponentModel.ISupportInitialize)dataGridProductCreatings).EndInit();
|
||||
|
@ -10,9 +10,9 @@ namespace Workshop
|
||||
{
|
||||
internal static class Program
|
||||
{
|
||||
//TODO: 1. Как разраб понимает, что sql атрибут автоматически удаляет запись в связанной таблице?
|
||||
//TODO: 2. Перечисления в самой БД - строки?
|
||||
//TODO: 3. Update со связтю МкМ
|
||||
//TODO: 1. Update со связью МкМ.
|
||||
//TODO: Спросить про заполнение связей МкМ в FormProduct
|
||||
//TODO: Спросить про заполнение колонки materials в таблице
|
||||
/// <summary>
|
||||
/// The main entry point for the application.
|
||||
/// </summary>
|
||||
|
@ -33,13 +33,19 @@ JsonConvert.SerializeObject(cheque));
|
||||
using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
|
||||
connection.Open();
|
||||
using var transaction = connection.BeginTransaction();
|
||||
var queryInsert = @"";
|
||||
var queryInsert = @"
|
||||
INSERT INTO CHEQUE (Date, Sum)
|
||||
VALUES (@Date, @Sum);
|
||||
SELECT MAX(Id) FROM CHEQUE";
|
||||
var chequeId = connection.QueryFirst<int>(queryInsert, cheque, transaction);
|
||||
var querySubInsert = @"";
|
||||
var querySubInsert = @"
|
||||
INSERT INTO CHEQUE_PRODUCT (ProductID, ChequeID, Amount)
|
||||
VALUES (@ProductId, @ChequeID, @Amount)";
|
||||
foreach (var elem in cheque.ChequeProduct)
|
||||
{
|
||||
connection.Execute(querySubInsert, new {chequeId, elem.ProductId, elem.Amount});
|
||||
}
|
||||
transaction.Commit();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
@ -54,7 +60,7 @@ JsonConvert.SerializeObject(cheque));
|
||||
try
|
||||
{
|
||||
using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
|
||||
var querySelect = "";
|
||||
var querySelect = "SELECT * FROM CHEQUE";
|
||||
var productCreatings = connection.Query<Cheque>(querySelect);
|
||||
_logger.LogDebug("Полученные объекты: {json}", JsonConvert.SerializeObject(productCreatings));
|
||||
return productCreatings;
|
||||
|
@ -118,7 +118,7 @@ SET
|
||||
LastName=@LastName,
|
||||
Age=@Age,
|
||||
Position=@Position
|
||||
WHERE [Id]=@Id";
|
||||
WHERE Id=@Id";
|
||||
connection.Execute(queryUpdate, master);
|
||||
}
|
||||
catch (Exception ex)
|
||||
|
@ -117,7 +117,7 @@ SET
|
||||
Name=@Name,
|
||||
WarehouseAmount=@WarehouseAmount,
|
||||
Price=@Price
|
||||
WHERE [Id]=@Id";
|
||||
WHERE Id=@Id";
|
||||
connection.Execute(queryUpdate, material);
|
||||
}
|
||||
catch (Exception ex)
|
||||
|
@ -31,7 +31,9 @@ JsonConvert.SerializeObject(productCreate));
|
||||
try
|
||||
{
|
||||
using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
|
||||
var queryInsert = @"";
|
||||
var queryInsert = @"
|
||||
INSERT INTO PRODUCTCREATE (ProductID, MasterID, CreatingDate)
|
||||
VALUES (@ProductId, @MasterId, @CreatingDate)";
|
||||
connection.Execute(queryInsert, productCreate);
|
||||
}
|
||||
catch (Exception ex)
|
||||
@ -48,7 +50,9 @@ JsonConvert.SerializeObject(productCreate));
|
||||
try
|
||||
{
|
||||
using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
|
||||
var queryDelete = @"";
|
||||
var queryDelete = @"
|
||||
DELETE FROM PRODUCTCREATE
|
||||
WHERE Id=@id";
|
||||
connection.Execute(queryDelete, new { id });
|
||||
}
|
||||
catch (Exception ex)
|
||||
@ -64,7 +68,7 @@ JsonConvert.SerializeObject(productCreate));
|
||||
try
|
||||
{
|
||||
using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
|
||||
var querySelect = "";
|
||||
var querySelect = "SELECT * FROM PRODUCTCREATE";
|
||||
var productCreatings = connection.Query<ProductCreate>(querySelect);
|
||||
_logger.LogDebug("Полученные объекты: {json}", JsonConvert.SerializeObject(productCreatings));
|
||||
return productCreatings;
|
||||
|
@ -34,7 +34,7 @@ JsonConvert.SerializeObject(product));
|
||||
connection.Open();
|
||||
using var transaction = connection.BeginTransaction();
|
||||
var queryInsert = @"
|
||||
INSERT INTO PRODUCT (Name, Price, WarehouseAmount, Type)
|
||||
INSERT INTO PRODUCT (Name, Price, WarehouseAmount, Category)
|
||||
VALUES (@Name, @Price, @WarehouseAmount, @Category);
|
||||
SELECT MAX(Id) FROM PRODUCT";
|
||||
var productId = connection.QueryFirst<int>(queryInsert, product, transaction);
|
||||
@ -43,8 +43,9 @@ INSERT INTO PRODUCT_MATERIAL (ProductID, MaterialID, Count)
|
||||
VALUES (@ProductId, @MaterialId, @Count)";
|
||||
foreach (var elem in product.Materials)
|
||||
{
|
||||
connection.Execute(querySubInsert, new { productId, elem.ProductId, elem.Count });
|
||||
connection.Execute(querySubInsert, new { productId, elem.MaterialId, elem.Count });
|
||||
}
|
||||
transaction.Commit();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
@ -128,7 +129,7 @@ SET
|
||||
Price=@Price,
|
||||
WarehouseAmount=@WarehouseAmount,
|
||||
Category=@Category
|
||||
WHERE [Id]=@Id";
|
||||
WHERE Id=@Id";
|
||||
connection.Execute(queryUpdate, product);
|
||||
}
|
||||
catch (Exception ex)
|
||||
|
Loading…
x
Reference in New Issue
Block a user