правки по 3

This commit is contained in:
SVETLANA_8 2024-12-19 21:53:46 +03:00
parent cccd753680
commit 3153d5bffc
7 changed files with 46 additions and 25 deletions

View File

@ -12,9 +12,9 @@ public class MaterialReplenishment
public int Count { get; private set; } public int Count { get; private set; }
public DateTime DataTime { get; private set; } public DateTime DataTime { get; private set; }
public int IDMaterial { get; private set; } public string Name { get; private set; } = string.Empty;
public static MaterialReplenishment CreateOperation(int id, int count, DateTime dataTime, int idmaterial) public static MaterialReplenishment CreateOperation(int id, int count, DateTime dataTime, string name)
{ {
return new MaterialReplenishment return new MaterialReplenishment
{ {
@ -22,7 +22,7 @@ public class MaterialReplenishment
Count = count, Count = count,
DataTime = dataTime, DataTime = dataTime,
IDMaterial = idmaterial Name = name
}; };
} }

View File

@ -36,13 +36,15 @@
label1 = new Label(); label1 = new Label();
dateTimePicker = new DateTimePicker(); dateTimePicker = new DateTimePicker();
label3 = new Label(); label3 = new Label();
textBoxName = new TextBox();
label4 = new Label();
((System.ComponentModel.ISupportInitialize)numericUpDownCount).BeginInit(); ((System.ComponentModel.ISupportInitialize)numericUpDownCount).BeginInit();
SuspendLayout(); SuspendLayout();
// //
// label2 // label2
// //
label2.AutoSize = true; label2.AutoSize = true;
label2.Location = new Point(77, 130); label2.Location = new Point(73, 186);
label2.Name = "label2"; label2.Name = "label2";
label2.Size = new Size(90, 20); label2.Size = new Size(90, 20);
label2.TabIndex = 1; label2.TabIndex = 1;
@ -50,14 +52,14 @@
// //
// numericUpDownCount // numericUpDownCount
// //
numericUpDownCount.Location = new Point(212, 123); numericUpDownCount.Location = new Point(212, 184);
numericUpDownCount.Name = "numericUpDownCount"; numericUpDownCount.Name = "numericUpDownCount";
numericUpDownCount.Size = new Size(150, 27); numericUpDownCount.Size = new Size(150, 27);
numericUpDownCount.TabIndex = 3; numericUpDownCount.TabIndex = 3;
// //
// buttonAdd // buttonAdd
// //
buttonAdd.Location = new Point(77, 197); buttonAdd.Location = new Point(73, 255);
buttonAdd.Margin = new Padding(3, 4, 3, 4); buttonAdd.Margin = new Padding(3, 4, 3, 4);
buttonAdd.Name = "buttonAdd"; buttonAdd.Name = "buttonAdd";
buttonAdd.Size = new Size(107, 53); buttonAdd.Size = new Size(107, 53);
@ -68,7 +70,7 @@
// //
// buttonCancel // buttonCancel
// //
buttonCancel.Location = new Point(231, 197); buttonCancel.Location = new Point(228, 255);
buttonCancel.Margin = new Padding(3, 4, 3, 4); buttonCancel.Margin = new Padding(3, 4, 3, 4);
buttonCancel.Name = "buttonCancel"; buttonCancel.Name = "buttonCancel";
buttonCancel.Size = new Size(117, 53); buttonCancel.Size = new Size(117, 53);
@ -80,7 +82,7 @@
// comboBoxMaterial // comboBoxMaterial
// //
comboBoxMaterial.FormattingEnabled = true; comboBoxMaterial.FormattingEnabled = true;
comboBoxMaterial.Location = new Point(210, 76); comboBoxMaterial.Location = new Point(211, 127);
comboBoxMaterial.Name = "comboBoxMaterial"; comboBoxMaterial.Name = "comboBoxMaterial";
comboBoxMaterial.Size = new Size(151, 28); comboBoxMaterial.Size = new Size(151, 28);
comboBoxMaterial.TabIndex = 6; comboBoxMaterial.TabIndex = 6;
@ -88,11 +90,11 @@
// label1 // label1
// //
label1.AutoSize = true; label1.AutoSize = true;
label1.Location = new Point(77, 76); label1.Location = new Point(73, 135);
label1.Name = "label1"; label1.Name = "label1";
label1.Size = new Size(103, 20); label1.Size = new Size(78, 20);
label1.TabIndex = 7; label1.TabIndex = 7;
label1.Text = "ID материала"; label1.Text = "Mатериал";
// //
// dateTimePicker // dateTimePicker
// //
@ -110,11 +112,29 @@
label3.TabIndex = 9; label3.TabIndex = 9;
label3.Text = "Дата"; label3.Text = "Дата";
// //
// textBoxName
//
textBoxName.Location = new Point(210, 78);
textBoxName.Name = "textBoxName";
textBoxName.Size = new Size(152, 27);
textBoxName.TabIndex = 10;
//
// label4
//
label4.AutoSize = true;
label4.Location = new Point(77, 85);
label4.Name = "label4";
label4.Size = new Size(156, 20);
label4.TabIndex = 11;
label4.Text = "Название материала";
//
// FormMaterialReplenishment // FormMaterialReplenishment
// //
AutoScaleDimensions = new SizeF(8F, 20F); AutoScaleDimensions = new SizeF(8F, 20F);
AutoScaleMode = AutoScaleMode.Font; AutoScaleMode = AutoScaleMode.Font;
ClientSize = new Size(411, 273); ClientSize = new Size(502, 363);
Controls.Add(label4);
Controls.Add(textBoxName);
Controls.Add(label3); Controls.Add(label3);
Controls.Add(dateTimePicker); Controls.Add(dateTimePicker);
Controls.Add(label1); Controls.Add(label1);
@ -144,5 +164,7 @@
private Label label1; private Label label1;
private DateTimePicker dateTimePicker; private DateTimePicker dateTimePicker;
private Label label3; private Label label3;
private TextBox textBoxName;
private Label label4;
} }
} }

View File

@ -30,10 +30,10 @@ namespace ProjectAtelier.Forms
{ {
throw new InvalidDataException(nameof(materialReplenishment)); throw new InvalidDataException(nameof(materialReplenishment));
} }
textBoxName.Text = materialReplenishment.Name;
comboBoxMaterial.Text = materialReplenishment.Name;
numericUpDownCount.Value = materialReplenishment.Count; numericUpDownCount.Value = materialReplenishment.Count;
comboBoxMaterial.SelectedValue = materialReplenishment.IDMaterial; // Устанавливаем выбранный материал
dateTimePicker.Value = materialReplenishment.DataTime; // Устанавливаем выбранную дату и время
_materialReplenishmentId = value; _materialReplenishmentId = value;
} }
catch (Exception ex) catch (Exception ex)
@ -58,9 +58,8 @@ namespace ProjectAtelier.Forms
private MaterialReplenishment CreateMaterialReplenishment(int id) private MaterialReplenishment CreateMaterialReplenishment(int id)
{ {
int selectedMaterialId = (int)comboBoxMaterial.SelectedValue;
DateTime selectedDateTime = dateTimePicker.Value; DateTime selectedDateTime = dateTimePicker.Value;
return MaterialReplenishment.CreateOperation(id, Convert.ToInt32(numericUpDownCount.Value), selectedDateTime, selectedMaterialId); return MaterialReplenishment.CreateOperation(id, Convert.ToInt32(numericUpDownCount.Value), selectedDateTime, textBoxName.Text);
} }
private void ButtonAdd_Click_1(object sender, EventArgs e) private void ButtonAdd_Click_1(object sender, EventArgs e)

View File

@ -29,8 +29,8 @@ public class MaterialReplenishmentRepository : IMaterialReplenishmentRepository
{ {
using var connection = new NpgsqlConnection(_connectionString.ConnectionString); using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
var queryInsert = @" var queryInsert = @"
INSERT INTO MaterialReplenishment (Count, DataTime, IDMaterial) INSERT INTO MaterialReplenishment (Count, DataTime, Name)
VALUES (@Count, @DataTime, @IDMaterial)"; VALUES (@Count, @DataTime, @Name)";
connection.Execute(queryInsert, material); connection.Execute(queryInsert, material);
} }
catch (Exception ex) catch (Exception ex)
@ -93,7 +93,7 @@ public class MaterialReplenishmentRepository : IMaterialReplenishmentRepository
SET SET
Count=@Count, Count=@Count,
DataTime=@DataTime, DataTime=@DataTime,
IDMaterial=@IDMaterial Name=@Name
WHERE Id=@Id"; WHERE Id=@Id";
connection.Execute(queryUpdate, material); connection.Execute(queryUpdate, material);
} }

View File

@ -35,7 +35,7 @@ class ChartReport
return _materialReplenishmentRepository return _materialReplenishmentRepository
.ReadMaterialsSpent() .ReadMaterialsSpent()
.Where(x => x.DataTime.Date == dateTime.Date) .Where(x => x.DataTime.Date == dateTime.Date)
.GroupBy(x => x.IDMaterial, (key, group) => new { Id = key, Count = group.Sum(x => x.Count) }) .GroupBy(x => x.Name, (key, group) => new { Id = key, Count = group.Sum(x => x.Count) })
.Select(x => (x.Id.ToString(), (double)x.Count)) .Select(x => (x.Id.ToString(), (double)x.Count))
.ToList(); .ToList();
} }

View File

@ -48,7 +48,7 @@ internal class TableReport
{ {
var data = _materialReplenishmentRepository var data = _materialReplenishmentRepository
.ReadMaterialsSpent() .ReadMaterialsSpent()
.Where(x => x.DataTime >= startDate && x.DataTime <= endDate && x.IDMaterial == materialId) .Where(x => x.DataTime >= startDate && x.DataTime <= endDate && x.Name == _materialRepository.ReadMaterialById(materialId).Name)
.Select(x => new { Date = x.DataTime, CountIn = (int?)x.Count, CountOut = (int?)null }) .Select(x => new { Date = x.DataTime, CountIn = (int?)x.Count, CountOut = (int?)null })
.Union( .Union(
_orderMaterialsRepository _orderMaterialsRepository
@ -65,5 +65,3 @@ internal class TableReport
.ToList(); .ToList();
} }
} }
//.Where(x => x.DataTime >= startDate && x.DataTime <= endDate && x.Name == _materialRepository.ReadMaterialById(materialId).Name)
// .Select(x => new { Date = x.DateReplenishment, CountIn = (int?)x.Count , CountOut = (int?)null })

View File

@ -21,7 +21,9 @@ public class OrderMaterialsRepository : IOrderMaterialsRepository
{ {
using var connection = new NpgsqlConnection(_connectionString.ConnectionString); using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
var querySelect = @" var querySelect = @"
SELECT orders.*, materials.id AS materialid, pm.count*op.count AS count SELECT
orders.datatime AS DataOrder,
orders.*, materials.id AS materialid, pm.count*op.count AS count
FROM orders FROM orders
INNER JOIN order_products AS op ON orders.id = op.orderid INNER JOIN order_products AS op ON orders.id = op.orderid
INNER JOIN products ON op.productid = products.id INNER JOIN products ON op.productid = products.id