Я вроде +- починила всё

This commit is contained in:
malimova 2024-05-23 00:00:19 +04:00
parent 9e943ce4d4
commit d3d8d0e340
12 changed files with 266 additions and 134 deletions

View File

@ -41,7 +41,8 @@ namespace ConfectioneryBusinessLogic
} }
public List<OrderViewModel>? ReadList(OrderSearchModel? model) public List<OrderViewModel>? ReadList(OrderSearchModel? model)
{ {
_logger.LogInformation("ReadList. OrderId:{Id}", model?.Id); _logger.LogInformation("ReadList. ClientId:{ClientId}.Status:{Status}.ImplementerId:{ImplementerId}.DateFrom:{DateFrom}.DateTo:{DateTo}OrderId:{Id}",
model?.ClientId, model?.Status, model?.ImplementerId, model?.DateFrom, model?.DateTo, model?.Id);
var list = model == null ? _orderStorage.GetFullList() : _orderStorage.GetFilteredList(model); var list = model == null ? _orderStorage.GetFullList() : _orderStorage.GetFilteredList(model);
if (list == null) if (list == null)
{ {
@ -120,14 +121,21 @@ namespace ConfectioneryBusinessLogic
model.DateCreate = element.DateCreate; model.DateCreate = element.DateCreate;
model.PastryId = element.PastryId; model.PastryId = element.PastryId;
model.DateImplement = element.DateImplement; model.DateImplement = element.DateImplement;
model.ClientId = element.ClientId;
if (!model.ImplementerId.HasValue)
{
model.ImplementerId = element.ImplementerId;
}
model.Status = element.Status; model.Status = element.Status;
model.Count = element.Count; model.Count = element.Count;
model.Sum = element.Sum; model.Sum = element.Sum;
if (requiredStatus - model.Status == 1) if (requiredStatus - model.Status == 1)
{ {
model.Status = requiredStatus; model.Status = requiredStatus;
if (model.Status == OrderStatus.Выдан) if (model.Status == OrderStatus.Готов)
{
model.DateImplement = DateTime.Now; model.DateImplement = DateTime.Now;
}
if (_orderStorage.Update(model) == null) if (_orderStorage.Update(model) == null)
{ {
_logger.LogWarning("Update operation failed"); _logger.LogWarning("Update operation failed");

View File

@ -17,6 +17,9 @@ namespace ConfectioneryContracts.ViewModels
[DisplayName("ФИО клиента")] [DisplayName("ФИО клиента")]
public string ClientFIO { get; set; } = string.Empty; public string ClientFIO { get; set; } = string.Empty;
public int? ImplementerId { get; set; }
[DisplayName("Исполнитель")]
public string? ImplementerFIO { get; set; } = null;
public int PastryId { get; set; } public int PastryId { get; set; }
[DisplayName("Изделие")] [DisplayName("Изделие")]
public string PastryName { get; set; } = string.Empty; public string PastryName { get; set; } = string.Empty;

View File

@ -11,6 +11,7 @@ namespace ConfectioneryDataModels.Models
{ {
int PastryId { get; } int PastryId { get; }
int ClientId { get; } int ClientId { get; }
int? ImplementerId { get; }
int Count { get; } int Count { get; }
double Sum { get; } double Sum { get; }
OrderStatus Status { get; } OrderStatus Status { get; }

View File

@ -191,7 +191,7 @@ namespace ConfectioneryDatabaseImplement.Migrations
.OnDelete(DeleteBehavior.Cascade) .OnDelete(DeleteBehavior.Cascade)
.IsRequired(); .IsRequired();
b.HasOne("ConfectioneryDatabaseImplement.Models.Implementer", null) b.HasOne("ConfectioneryDatabaseImplement.Models.Implementer", "Implementer")
.WithMany("Order") .WithMany("Order")
.HasForeignKey("ImplementerId"); .HasForeignKey("ImplementerId");
@ -203,6 +203,8 @@ namespace ConfectioneryDatabaseImplement.Migrations
b.Navigation("Client"); b.Navigation("Client");
b.Navigation("Implementer");
b.Navigation("Pastry"); b.Navigation("Pastry");
}); });

View File

@ -23,6 +23,8 @@ namespace ConfectioneryDatabaseImplement.Models
public int PastryId { get; private set; } public int PastryId { get; private set; }
public virtual Pastry Pastry { get; set; } = new(); public virtual Pastry Pastry { get; set; } = new();
public int? ImplementerId { get; private set; }
public virtual Implementer? Implementer { get; set; } = new();
[Required] [Required]
public int Count { get; private set; } public int Count { get; private set; }
@ -47,6 +49,8 @@ namespace ConfectioneryDatabaseImplement.Models
Client = context.Clients.First(x => x.Id == model.ClientId), Client = context.Clients.First(x => x.Id == model.ClientId),
PastryId = model.PastryId, PastryId = model.PastryId,
Pastry = context.Pastrys.First(x => x.Id == model.PastryId), Pastry = context.Pastrys.First(x => x.Id == model.PastryId),
ImplementerId = model.ImplementerId,
Implementer = model.ImplementerId.HasValue ? context.Implementers.First(x => x.Id == model.ImplementerId) : null,
Count = model.Count, Count = model.Count,
Sum = model.Sum, Sum = model.Sum,
Status = model.Status, Status = model.Status,
@ -55,7 +59,7 @@ namespace ConfectioneryDatabaseImplement.Models
}; };
} }
public void Update(OrderBindingModel? model) public void Update(ConfectioneryDatabase context, OrderBindingModel? model)
{ {
if (model == null) if (model == null)
{ {
@ -63,6 +67,8 @@ namespace ConfectioneryDatabaseImplement.Models
} }
Status = model.Status; Status = model.Status;
DateImplement = model.DateImplement; DateImplement = model.DateImplement;
ImplementerId = model.ImplementerId;
Implementer = model.ImplementerId.HasValue ? context.Implementers.First(x => x.Id == model.ImplementerId) : null;
} }
public OrderViewModel GetViewModel => new() public OrderViewModel GetViewModel => new()
@ -72,6 +78,8 @@ namespace ConfectioneryDatabaseImplement.Models
ClientFIO = Client.ClientFIO, ClientFIO = Client.ClientFIO,
PastryId = PastryId, PastryId = PastryId,
PastryName = Pastry.PastryName, PastryName = Pastry.PastryName,
ImplementerId = ImplementerId,
ImplementerFIO = Implementer != null ? Implementer.ImplementerFIO : null,
Count = Count, Count = Count,
Sum = Sum, Sum = Sum,
Status = Status, Status = Status,

View File

@ -17,31 +17,34 @@ namespace ConfectioneryDatabaseImplement.Implements
public List<OrderViewModel> GetFullList() public List<OrderViewModel> GetFullList()
{ {
using var context = new ConfectioneryDatabase(); using var context = new ConfectioneryDatabase();
return context.Orders.Include(x => x.Pastry).Include(x => x.Client).Select(x => x.GetViewModel).ToList(); return context.Orders.Include(x => x.Pastry).Include(x => x.Client).Include(y => y.Implementer).Select(x => x.GetViewModel).ToList();
} }
public List<OrderViewModel> GetFilteredList(OrderSearchModel model) public List<OrderViewModel> GetFilteredList(OrderSearchModel model)
{ {
using var context = new ConfectioneryDatabase(); using var context = new ConfectioneryDatabase();
if (model.DateFrom.HasValue) if ((!model.DateFrom.HasValue || !model.DateTo.HasValue) && !model.ClientId.HasValue && !model.Status.HasValue)
{ {
return context.Orders.Include(x => x.Pastry).Where(x => x.DateCreate >= model.DateFrom && x.DateCreate <= model.DateTo).Select(x => x.GetViewModel).ToList(); return new();
} }
if (model.ClientId.HasValue) return context.Orders.Include(x => x.Pastry).Include(x => x.Client).Include(x => x.Implementer).Where(x =>
{ (model.DateFrom.HasValue && model.DateTo.HasValue && x.DateCreate >= model.DateFrom && x.DateCreate <= model.DateTo) ||
return context.Orders.Include(x => x.Pastry).Where(x => x.ClientId == model.ClientId).Select(x => x.GetViewModel).ToList(); (model.ClientId.HasValue && x.ClientId == model.ClientId) ||
} (model.Status.HasValue && x.Status == model.Status))
return context.Orders.Include(x => x.Pastry).Where(x => x.Id == model.Id).Select(x => x.GetViewModel).ToList(); .Select(x => x.GetViewModel).ToList();
} }
public OrderViewModel? GetElement(OrderSearchModel model) public OrderViewModel? GetElement(OrderSearchModel model)
{ {
if (!model.Id.HasValue) if (!model.Id.HasValue && (!model.ImplementerId.HasValue || !model.Status.HasValue))
{ {
return new(); return new();
} }
using var context = new ConfectioneryDatabase(); using var context = new ConfectioneryDatabase();
return context.Orders.Include(x => x.Pastry).FirstOrDefault(x => x.Id == model.Id)?.GetViewModel; return context.Orders.Include(x => x.Pastry).Include(x => x.Client).Include(x => x.Implementer).FirstOrDefault(x =>
(model.Id.HasValue && x.Id == model.Id) ||
(model.ImplementerId.HasValue && x.ImplementerId == model.ImplementerId && x.Status == model.Status))
?.GetViewModel;
} }
public OrderViewModel? Insert(OrderBindingModel model) public OrderViewModel? Insert(OrderBindingModel model)
@ -67,7 +70,7 @@ namespace ConfectioneryDatabaseImplement.Implements
{ {
return null; return null;
} }
order.Update(model); order.Update(context, model);
context.SaveChanges(); context.SaveChanges();
return order.GetViewModel; return order.GetViewModel;
} }

View File

@ -10,6 +10,7 @@ namespace ConfectioneryFileImplement.Models
{ {
public int Id { get; private set; } public int Id { get; private set; }
public int ClientId { get; private set; } public int ClientId { get; private set; }
public int? ImplementerId { get; set; }
public int PastryId { get; private set; } public int PastryId { get; private set; }
public int Count { get; private set; } public int Count { get; private set; }
public double Sum { get; private set; } public double Sum { get; private set; }
@ -27,6 +28,8 @@ namespace ConfectioneryFileImplement.Models
{ {
Id = model.Id, Id = model.Id,
PastryId = model.PastryId, PastryId = model.PastryId,
ClientId = model.ClientId,
ImplementerId = model.ImplementerId,
Count = model.Count, Count = model.Count,
Sum = model.Sum, Sum = model.Sum,
Status = model.Status, Status = model.Status,
@ -46,6 +49,8 @@ namespace ConfectioneryFileImplement.Models
{ {
Id = Convert.ToInt32(element.Attribute("Id")!.Value), Id = Convert.ToInt32(element.Attribute("Id")!.Value),
PastryId = Convert.ToInt32(element.Element("PastryId")!.Value), PastryId = Convert.ToInt32(element.Element("PastryId")!.Value),
ClientId = Convert.ToInt32(element.Element("ClientId")!.Value),
ImplementerId = Convert.ToInt32(element.Element("ImplementerId")!.Value),
Count = Convert.ToInt32(element.Element("Count")!.Value), Count = Convert.ToInt32(element.Element("Count")!.Value),
Sum = Convert.ToDouble(element.Element("Sum")!.Value), Sum = Convert.ToDouble(element.Element("Sum")!.Value),
Status = (OrderStatus)(Enum.Parse(typeof(OrderStatus), element.Element("Status")!.Value)), Status = (OrderStatus)(Enum.Parse(typeof(OrderStatus), element.Element("Status")!.Value)),
@ -68,6 +73,8 @@ namespace ConfectioneryFileImplement.Models
{ {
Id = Id, Id = Id,
PastryId = PastryId, PastryId = PastryId,
ClientId = ClientId,
ImplementerId = ImplementerId,
Count = Count, Count = Count,
Sum = Sum, Sum = Sum,
Status = Status, Status = Status,
@ -78,6 +85,8 @@ namespace ConfectioneryFileImplement.Models
public XElement GetXElement => new("Order", public XElement GetXElement => new("Order",
new XAttribute("Id", Id), new XAttribute("Id", Id),
new XElement("PastryId", PastryId.ToString()), new XElement("PastryId", PastryId.ToString()),
new XElement("ClientId", ClientId.ToString()),
new XElement("ImplementerId", ImplementerId),
new XElement("Count", Count.ToString()), new XElement("Count", Count.ToString()),
new XElement("Sum", Sum.ToString()), new XElement("Sum", Sum.ToString()),
new XElement("Status", Status.ToString()), new XElement("Status", Status.ToString()),

View File

@ -24,15 +24,53 @@ namespace ConfectioneryFileImplement.Implements
public List<OrderViewModel> GetFilteredList(OrderSearchModel model) public List<OrderViewModel> GetFilteredList(OrderSearchModel model)
{ {
if (!model.Id.HasValue) if (model.DateFrom.HasValue)
{ {
return source.Orders.Where(x => x.DateCreate >= model.DateFrom && x.DateCreate <= model.DateTo)
.Select(x => GetViewModel(x)).ToList();
}
if (model.ClientId.HasValue && !model.Id.HasValue)
{
return source.Orders.Where(x => x.ClientId == model.ClientId).Select(x => x.GetViewModel).ToList();
}
if (!model.ImplementerId.HasValue && !model.Id.HasValue)
{
return source.Orders.Where(x => x.ImplementerId == model.ImplementerId).Select(x => x.GetViewModel).ToList();
}
if (model.Id.HasValue)
{
return source.Orders.Where(x => x.Id.Equals(model.Id)).Select(x => GetViewModel(x)).ToList();
}
return new(); return new();
} }
return source.Orders.Where(x => x.Id == model.Id).Select(x => AttachPastryName(x.GetViewModel)).ToList(); private OrderViewModel GetViewModel(Order order)
{
var viewModel = order.GetViewModel;
var Pastry = source.Pastrys.FirstOrDefault(x => x.Id == order.PastryId);
var client = source.Clients.FirstOrDefault(x => x.Id == order.ClientId);
if (Pastry != null)
{
viewModel.PastryName = Pastry.PastryName;
}
if (client != null)
{
viewModel.ClientFIO = client.ClientFIO;
}
return viewModel;
} }
public OrderViewModel? GetElement(OrderSearchModel model) public OrderViewModel? GetElement(OrderSearchModel model)
{ {
if (model.ImplementerId.HasValue)
{
return source.Orders.FirstOrDefault(x => x.ImplementerId == model.ImplementerId)?.GetViewModel;
}
if (!model.Id.HasValue) if (!model.Id.HasValue)
{ {
return new(); return new();

View File

@ -15,6 +15,7 @@ namespace ConfectioneryListImplement.Models
public int Id { get; private set; } public int Id { get; private set; }
public int PastryId { get; private set; } public int PastryId { get; private set; }
public int ClientId { get; private set; } public int ClientId { get; private set; }
public int? ImplementerId { get; private set; }
public int Count { get; private set; } public int Count { get; private set; }
public double Sum { get; private set; } public double Sum { get; private set; }
public OrderStatus Status { get; private set; } = OrderStatus.Неизвестен; public OrderStatus Status { get; private set; } = OrderStatus.Неизвестен;
@ -31,6 +32,8 @@ namespace ConfectioneryListImplement.Models
{ {
Id = model.Id, Id = model.Id,
PastryId = model.PastryId, PastryId = model.PastryId,
ClientId = model.ClientId,
ImplementerId = model.ImplementerId,
Count = model.Count, Count = model.Count,
Sum = model.Sum, Sum = model.Sum,
Status = model.Status, Status = model.Status,
@ -53,6 +56,8 @@ namespace ConfectioneryListImplement.Models
{ {
Id = Id, Id = Id,
PastryId = PastryId, PastryId = PastryId,
ClientId = ClientId,
ImplementerId = ImplementerId,
Count = Count, Count = Count,
Sum = Sum, Sum = Sum,
Status = Status, Status = Status,

View File

@ -33,19 +33,69 @@ namespace ConfectioneryListImplement
public List<OrderViewModel> GetFilteredList(OrderSearchModel model) public List<OrderViewModel> GetFilteredList(OrderSearchModel model)
{ {
var result = new List<OrderViewModel>(); var result = new List<OrderViewModel>();
if (model == null || !model.Id.HasValue) if (model.DateFrom.HasValue)
{ {
return result; foreach (var order in _source.Orders)
{
if (order.DateCreate >= model.DateFrom && order.DateCreate <= model.DateTo)
{
result.Add(GetViewModel(order));
} }
}
}
else if (model.ClientId.HasValue && !model.Id.HasValue)
{
foreach (var order in _source.Orders)
{
if (order.ClientId == model.ClientId)
{
result.Add(GetViewModel(order));
}
}
}
else if (model.ImplementerId.HasValue && !model.Id.HasValue)
{
foreach (var order in _source.Orders)
{
if (order.ImplementerId == model.ImplementerId)
{
result.Add(GetViewModel(order));
}
}
}
else if (model.Id.HasValue)
{
foreach (var order in _source.Orders) foreach (var order in _source.Orders)
{ {
if (order.Id == model.Id) if (order.Id == model.Id)
{ {
result.Add(AttachPastryName(order.GetViewModel)); result.Add(GetViewModel(order));
}
} }
} }
return result; return result;
} }
private OrderViewModel GetViewModel(Order order)
{
var viewModel = order.GetViewModel;
foreach (var package in _source.Pastrys)
{
if (package.Id == order.PastryId)
{
viewModel.PastryName = package.PastryName;
break;
}
}
foreach (var client in _source.Clients)
{
if (client.Id == order.ClientId)
{
viewModel.ClientFIO = client.ClientFIO;
break;
}
}
return viewModel;
}
public OrderViewModel? GetElement(OrderSearchModel model) public OrderViewModel? GetElement(OrderSearchModel model)
{ {
@ -59,6 +109,10 @@ namespace ConfectioneryListImplement
{ {
return AttachPastryName(order.GetViewModel); return AttachPastryName(order.GetViewModel);
} }
else if (model.ImplementerId.HasValue && model.ImplementerId == order.ImplementerId)
{
return GetViewModel(order);
}
} }
return null; return null;
} }

View File

@ -56,7 +56,7 @@
dataGridView.Location = new Point(12, 60); dataGridView.Location = new Point(12, 60);
dataGridView.Name = "dataGridView"; dataGridView.Name = "dataGridView";
dataGridView.RowHeadersWidth = 62; dataGridView.RowHeadersWidth = 62;
dataGridView.Size = new Size(1374, 549); dataGridView.Size = new Size(1614, 549);
dataGridView.TabIndex = 0; dataGridView.TabIndex = 0;
// //
// menuStrip // menuStrip
@ -65,7 +65,7 @@
menuStrip.Items.AddRange(new ToolStripItem[] { toolStripMenuItem, отчетыToolStripMenuItem, startWorkToolStripMenuItem }); menuStrip.Items.AddRange(new ToolStripItem[] { toolStripMenuItem, отчетыToolStripMenuItem, startWorkToolStripMenuItem });
menuStrip.Location = new Point(0, 0); menuStrip.Location = new Point(0, 0);
menuStrip.Name = "menuStrip"; menuStrip.Name = "menuStrip";
menuStrip.Size = new Size(1666, 33); menuStrip.Size = new Size(1921, 33);
menuStrip.TabIndex = 1; menuStrip.TabIndex = 1;
menuStrip.Text = "menuStrip1"; menuStrip.Text = "menuStrip1";
// //
@ -142,7 +142,7 @@
// buttonCreateOrder // buttonCreateOrder
// //
buttonCreateOrder.Anchor = AnchorStyles.Top | AnchorStyles.Right; buttonCreateOrder.Anchor = AnchorStyles.Top | AnchorStyles.Right;
buttonCreateOrder.Location = new Point(1402, 83); buttonCreateOrder.Location = new Point(1657, 83);
buttonCreateOrder.Name = "buttonCreateOrder"; buttonCreateOrder.Name = "buttonCreateOrder";
buttonCreateOrder.Size = new Size(232, 34); buttonCreateOrder.Size = new Size(232, 34);
buttonCreateOrder.TabIndex = 2; buttonCreateOrder.TabIndex = 2;
@ -153,7 +153,7 @@
// buttonTakeOrderInWork // buttonTakeOrderInWork
// //
buttonTakeOrderInWork.Anchor = AnchorStyles.Top | AnchorStyles.Right; buttonTakeOrderInWork.Anchor = AnchorStyles.Top | AnchorStyles.Right;
buttonTakeOrderInWork.Location = new Point(1402, 143); buttonTakeOrderInWork.Location = new Point(1657, 143);
buttonTakeOrderInWork.Name = "buttonTakeOrderInWork"; buttonTakeOrderInWork.Name = "buttonTakeOrderInWork";
buttonTakeOrderInWork.Size = new Size(232, 34); buttonTakeOrderInWork.Size = new Size(232, 34);
buttonTakeOrderInWork.TabIndex = 3; buttonTakeOrderInWork.TabIndex = 3;
@ -164,7 +164,7 @@
// buttonOrderReady // buttonOrderReady
// //
buttonOrderReady.Anchor = AnchorStyles.Top | AnchorStyles.Right; buttonOrderReady.Anchor = AnchorStyles.Top | AnchorStyles.Right;
buttonOrderReady.Location = new Point(1402, 203); buttonOrderReady.Location = new Point(1657, 203);
buttonOrderReady.Name = "buttonOrderReady"; buttonOrderReady.Name = "buttonOrderReady";
buttonOrderReady.Size = new Size(232, 34); buttonOrderReady.Size = new Size(232, 34);
buttonOrderReady.TabIndex = 4; buttonOrderReady.TabIndex = 4;
@ -175,7 +175,7 @@
// buttonIssuedOrder // buttonIssuedOrder
// //
buttonIssuedOrder.Anchor = AnchorStyles.Top | AnchorStyles.Right; buttonIssuedOrder.Anchor = AnchorStyles.Top | AnchorStyles.Right;
buttonIssuedOrder.Location = new Point(1402, 266); buttonIssuedOrder.Location = new Point(1657, 266);
buttonIssuedOrder.Name = "buttonIssuedOrder"; buttonIssuedOrder.Name = "buttonIssuedOrder";
buttonIssuedOrder.Size = new Size(232, 34); buttonIssuedOrder.Size = new Size(232, 34);
buttonIssuedOrder.TabIndex = 5; buttonIssuedOrder.TabIndex = 5;
@ -186,7 +186,7 @@
// buttonRef // buttonRef
// //
buttonRef.Anchor = AnchorStyles.Top | AnchorStyles.Right; buttonRef.Anchor = AnchorStyles.Top | AnchorStyles.Right;
buttonRef.Location = new Point(1402, 329); buttonRef.Location = new Point(1657, 329);
buttonRef.Name = "buttonRef"; buttonRef.Name = "buttonRef";
buttonRef.Size = new Size(232, 34); buttonRef.Size = new Size(232, 34);
buttonRef.TabIndex = 6; buttonRef.TabIndex = 6;
@ -198,7 +198,7 @@
// //
AutoScaleDimensions = new SizeF(10F, 25F); AutoScaleDimensions = new SizeF(10F, 25F);
AutoScaleMode = AutoScaleMode.Font; AutoScaleMode = AutoScaleMode.Font;
ClientSize = new Size(1666, 621); ClientSize = new Size(1921, 621);
Controls.Add(buttonRef); Controls.Add(buttonRef);
Controls.Add(buttonIssuedOrder); Controls.Add(buttonIssuedOrder);
Controls.Add(buttonOrderReady); Controls.Add(buttonOrderReady);

View File

@ -43,6 +43,7 @@ namespace ConfectioneryView
dataGridView.DataSource = list; dataGridView.DataSource = list;
dataGridView.Columns["PastryId"].Visible = false; dataGridView.Columns["PastryId"].Visible = false;
dataGridView.Columns["ClientId"].Visible = false; dataGridView.Columns["ClientId"].Visible = false;
dataGridView.Columns["ImplementerId"].Visible = false;
dataGridView.Columns["PastryName"].AutoSizeMode = dataGridView.Columns["PastryName"].AutoSizeMode =
DataGridViewAutoSizeColumnMode.Fill; DataGridViewAutoSizeColumnMode.Fill;
} }