ИСЭбд-21.Васильева.С.В. 4 лабораторная работа #4

Closed
SVETLANA_8 wants to merge 7 commits from LabWork_4 into LabWork_3
8 changed files with 45 additions and 23 deletions
Showing only changes of commit 894c3a3485 - Show all commits

View File

@ -17,11 +17,11 @@ public class MaterialReplenishment
[DisplayName("Дата пополнения")] [DisplayName("Дата пополнения")]
public DateTime DataTime { get; private set; } public DateTime DataTime { get; private set; }
[DisplayName("Название")] [DisplayName("Ткань")]
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
{ {
@ -29,7 +29,7 @@ public class MaterialReplenishment
Count = count, Count = count,
DataTime = dataTime, DataTime = dataTime,
IDMaterial = idmaterial Name = name
}; };
} }

View File

@ -36,6 +36,8 @@
label1 = new Label(); label1 = new Label();
dateTimePicker = new DateTimePicker(); dateTimePicker = new DateTimePicker();
label3 = new Label(); label3 = new Label();
label4 = new Label();
textBoxName = new TextBox();
((System.ComponentModel.ISupportInitialize)numericUpDownCount).BeginInit(); ((System.ComponentModel.ISupportInitialize)numericUpDownCount).BeginInit();
SuspendLayout(); SuspendLayout();
// //
@ -80,7 +82,7 @@
// comboBoxMaterial // comboBoxMaterial
// //
comboBoxMaterial.FormattingEnabled = true; comboBoxMaterial.FormattingEnabled = true;
comboBoxMaterial.Location = new Point(211, 125); comboBoxMaterial.Location = new Point(210, 153);
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,7 +90,7 @@
// label1 // label1
// //
label1.AutoSize = true; label1.AutoSize = true;
label1.Location = new Point(28, 125); label1.Location = new Point(28, 156);
label1.Name = "label1"; label1.Name = "label1";
label1.Size = new Size(78, 20); label1.Size = new Size(78, 20);
label1.TabIndex = 7; label1.TabIndex = 7;
@ -110,11 +112,29 @@
label3.TabIndex = 9; label3.TabIndex = 9;
label3.Text = "Дата"; label3.Text = "Дата";
// //
// label4
//
label4.AutoSize = true;
label4.Location = new Point(28, 106);
label4.Name = "label4";
label4.Size = new Size(77, 20);
label4.TabIndex = 10;
label4.Text = "Название";
//
// textBoxName
//
textBoxName.Location = new Point(212, 94);
textBoxName.Name = "textBoxName";
textBoxName.Size = new Size(150, 27);
textBoxName.TabIndex = 11;
//
// FormMaterialReplenishment // FormMaterialReplenishment
// //
AutoScaleDimensions = new SizeF(8F, 20F); AutoScaleDimensions = new SizeF(8F, 20F);
AutoScaleMode = AutoScaleMode.Font; AutoScaleMode = AutoScaleMode.Font;
ClientSize = new Size(490, 404); ClientSize = new Size(490, 404);
Controls.Add(textBoxName);
Controls.Add(label4);
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 Label label4;
private TextBox textBoxName;
} }
} }

View File

@ -30,9 +30,9 @@ namespace ProjectAtelier.Forms
{ {
throw new InvalidDataException(nameof(materialReplenishment)); throw new InvalidDataException(nameof(materialReplenishment));
} }
textBoxName.Text = materialReplenishment.Name;
numericUpDownCount.Value = materialReplenishment.Count; numericUpDownCount.Value = materialReplenishment.Count;
comboBoxMaterial.SelectedValue = materialReplenishment.IDMaterial; // Устанавливаем выбранный материал //comboBoxMaterial.SelectedValue = materialReplenishment.Name; // Устанавливаем выбранный материал
dateTimePicker.Value = materialReplenishment.DataTime; // Устанавливаем выбранную дату и время dateTimePicker.Value = materialReplenishment.DataTime; // Устанавливаем выбранную дату и время
_materialReplenishmentId = value; _materialReplenishmentId = value;
} }
@ -58,9 +58,9 @@ 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);
} }

View File

@ -9,7 +9,7 @@ namespace ProjectAtelier.REPOSITORY;
public interface IMaterialReplenishmentRepository public interface IMaterialReplenishmentRepository
{ {
IEnumerable<MaterialReplenishment> ReadMaterialsSpent(DateTime? dateForm = null, DateTime? dateTo = null, int? idmaterial = null); IEnumerable<MaterialReplenishment> ReadMaterialsSpent(DateTime? dateForm = null, DateTime? dateTo = null, string? materialName = null);
MaterialReplenishment ReadMaterialSpentById(int id); MaterialReplenishment ReadMaterialSpentById(int id);
void CreateMaterialSpent(MaterialReplenishment material); void CreateMaterialSpent(MaterialReplenishment material);
void UpdateMaterialSpent(MaterialReplenishment material); void UpdateMaterialSpent(MaterialReplenishment material);

View File

@ -30,8 +30,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)
@ -64,7 +64,7 @@ public class MaterialReplenishmentRepository : IMaterialReplenishmentRepository
throw; throw;
} }
} }
public IEnumerable<MaterialReplenishment> ReadMaterialsSpent(DateTime? dateForm = null, DateTime? dateTo = null, int? idmaterial = null) public IEnumerable<MaterialReplenishment> ReadMaterialsSpent(DateTime? dateForm = null, DateTime? dateTo = null, string? materialName = null)
{ {
var builder = new QueryBuilder(); var builder = new QueryBuilder();
if (dateForm.HasValue) if (dateForm.HasValue)
@ -75,9 +75,9 @@ public class MaterialReplenishmentRepository : IMaterialReplenishmentRepository
{ {
builder.AddCondition("DataTime <= @dateTo"); builder.AddCondition("DataTime <= @dateTo");
} }
if (idmaterial != null) if ( materialName != null)
{ {
builder.AddCondition("IDMaterial = @idmaterial"); builder.AddCondition("Name = @materialName");
} }
_logger.LogInformation("Получение всех объектов"); _logger.LogInformation("Получение всех объектов");
@ -87,7 +87,7 @@ public class MaterialReplenishmentRepository : IMaterialReplenishmentRepository
var querySelect = @$" var querySelect = @$"
SELECT * FROM MaterialReplenishment SELECT * FROM MaterialReplenishment
{builder.Build()}"; {builder.Build()}";
var materials = connection.Query<MaterialReplenishment>(querySelect, new { dateForm, dateTo, idmaterial }); var materials = connection.Query<MaterialReplenishment>(querySelect, new { dateForm, dateTo, materialName });
_logger.LogDebug("Полученные объекты: {json}", JsonConvert.SerializeObject(materials)); _logger.LogDebug("Полученные объекты: {json}", JsonConvert.SerializeObject(materials));
return materials; return materials;
} }
@ -110,7 +110,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

@ -34,7 +34,7 @@ class ChartReport
{ {
return _materialReplenishmentRepository return _materialReplenishmentRepository
.ReadMaterialsSpent(dateForm: dateTime.Date, dateTo: dateTime.Date.AddDays(1)) .ReadMaterialsSpent(dateForm: dateTime.Date, dateTo: dateTime.Date.AddDays(1))
.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

@ -47,7 +47,7 @@ internal class TableReport
private List<string[]> GetData(int materialId, DateTime startDate, DateTime endDate) private List<string[]> GetData(int materialId, DateTime startDate, DateTime endDate)
{ {
var data = _materialReplenishmentRepository var data = _materialReplenishmentRepository
.ReadMaterialsSpent(dateForm: startDate, dateTo: endDate, idmaterial: _materialRepository.ReadMaterialById(materialId).Id) .ReadMaterialsSpent(dateForm: startDate, dateTo: endDate, materialName: _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

View File

@ -16,7 +16,7 @@ public class OrderMaterialsRepository : IOrderMaterialsRepository
_connectionString = connectionString; _connectionString = connectionString;
_logger = logger; _logger = logger;
} }
//orders.datatime AS DataOrder,
public IEnumerable<TempOrder> ReadOrders(DateTime? dateForm = null, DateTime? dateTo = null, int? matid = null) public IEnumerable<TempOrder> ReadOrders(DateTime? dateForm = null, DateTime? dateTo = null, int? matid = null)
{ {
var builder = new QueryBuilder(); var builder = new QueryBuilder();
@ -30,12 +30,12 @@ public class OrderMaterialsRepository : IOrderMaterialsRepository
} }
if (matid.HasValue) if (matid.HasValue)
{ {
builder.AddCondition("materialid = @matid"); builder.AddCondition("materialid = @matid");
} }
using var connection = new NpgsqlConnection(_connectionString.ConnectionString); using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
var querySelect = @$" var querySelect = @$"
SELECT SELECT
orders.datatime AS DataOrder,
orders.*, orders.*,
materials.id AS materialid, materials.id AS materialid,
pm.count*op.count AS count pm.count*op.count AS count