Я вроде +- починила всё
This commit is contained in:
parent
9e943ce4d4
commit
d3d8d0e340
@ -41,7 +41,8 @@ namespace ConfectioneryBusinessLogic
|
||||
}
|
||||
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);
|
||||
if (list == null)
|
||||
{
|
||||
@ -120,14 +121,21 @@ namespace ConfectioneryBusinessLogic
|
||||
model.DateCreate = element.DateCreate;
|
||||
model.PastryId = element.PastryId;
|
||||
model.DateImplement = element.DateImplement;
|
||||
model.ClientId = element.ClientId;
|
||||
if (!model.ImplementerId.HasValue)
|
||||
{
|
||||
model.ImplementerId = element.ImplementerId;
|
||||
}
|
||||
model.Status = element.Status;
|
||||
model.Count = element.Count;
|
||||
model.Sum = element.Sum;
|
||||
if (requiredStatus - model.Status == 1)
|
||||
{
|
||||
model.Status = requiredStatus;
|
||||
if (model.Status == OrderStatus.Выдан)
|
||||
if (model.Status == OrderStatus.Готов)
|
||||
{
|
||||
model.DateImplement = DateTime.Now;
|
||||
}
|
||||
if (_orderStorage.Update(model) == null)
|
||||
{
|
||||
_logger.LogWarning("Update operation failed");
|
||||
|
@ -17,6 +17,9 @@ namespace ConfectioneryContracts.ViewModels
|
||||
|
||||
[DisplayName("ФИО клиента")]
|
||||
public string ClientFIO { get; set; } = string.Empty;
|
||||
public int? ImplementerId { get; set; }
|
||||
[DisplayName("Исполнитель")]
|
||||
public string? ImplementerFIO { get; set; } = null;
|
||||
public int PastryId { get; set; }
|
||||
[DisplayName("Изделие")]
|
||||
public string PastryName { get; set; } = string.Empty;
|
||||
|
@ -11,6 +11,7 @@ namespace ConfectioneryDataModels.Models
|
||||
{
|
||||
int PastryId { get; }
|
||||
int ClientId { get; }
|
||||
int? ImplementerId { get; }
|
||||
int Count { get; }
|
||||
double Sum { get; }
|
||||
OrderStatus Status { get; }
|
||||
|
@ -191,7 +191,7 @@ namespace ConfectioneryDatabaseImplement.Migrations
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.HasOne("ConfectioneryDatabaseImplement.Models.Implementer", null)
|
||||
b.HasOne("ConfectioneryDatabaseImplement.Models.Implementer", "Implementer")
|
||||
.WithMany("Order")
|
||||
.HasForeignKey("ImplementerId");
|
||||
|
||||
@ -203,6 +203,8 @@ namespace ConfectioneryDatabaseImplement.Migrations
|
||||
|
||||
b.Navigation("Client");
|
||||
|
||||
b.Navigation("Implementer");
|
||||
|
||||
b.Navigation("Pastry");
|
||||
});
|
||||
|
||||
|
@ -23,6 +23,8 @@ namespace ConfectioneryDatabaseImplement.Models
|
||||
public int PastryId { get; private set; }
|
||||
|
||||
public virtual Pastry Pastry { get; set; } = new();
|
||||
public int? ImplementerId { get; private set; }
|
||||
public virtual Implementer? Implementer { get; set; } = new();
|
||||
|
||||
[Required]
|
||||
public int Count { get; private set; }
|
||||
@ -47,6 +49,8 @@ namespace ConfectioneryDatabaseImplement.Models
|
||||
Client = context.Clients.First(x => x.Id == model.ClientId),
|
||||
PastryId = 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,
|
||||
Sum = model.Sum,
|
||||
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)
|
||||
{
|
||||
@ -63,6 +67,8 @@ namespace ConfectioneryDatabaseImplement.Models
|
||||
}
|
||||
Status = model.Status;
|
||||
DateImplement = model.DateImplement;
|
||||
ImplementerId = model.ImplementerId;
|
||||
Implementer = model.ImplementerId.HasValue ? context.Implementers.First(x => x.Id == model.ImplementerId) : null;
|
||||
}
|
||||
|
||||
public OrderViewModel GetViewModel => new()
|
||||
@ -72,6 +78,8 @@ namespace ConfectioneryDatabaseImplement.Models
|
||||
ClientFIO = Client.ClientFIO,
|
||||
PastryId = PastryId,
|
||||
PastryName = Pastry.PastryName,
|
||||
ImplementerId = ImplementerId,
|
||||
ImplementerFIO = Implementer != null ? Implementer.ImplementerFIO : null,
|
||||
Count = Count,
|
||||
Sum = Sum,
|
||||
Status = Status,
|
||||
|
@ -17,31 +17,34 @@ namespace ConfectioneryDatabaseImplement.Implements
|
||||
public List<OrderViewModel> GetFullList()
|
||||
{
|
||||
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)
|
||||
{
|
||||
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).Where(x => x.ClientId == model.ClientId).Select(x => x.GetViewModel).ToList();
|
||||
}
|
||||
return context.Orders.Include(x => x.Pastry).Where(x => x.Id == model.Id).Select(x => x.GetViewModel).ToList();
|
||||
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) ||
|
||||
(model.ClientId.HasValue && x.ClientId == model.ClientId) ||
|
||||
(model.Status.HasValue && x.Status == model.Status))
|
||||
.Select(x => x.GetViewModel).ToList();
|
||||
}
|
||||
|
||||
public OrderViewModel? GetElement(OrderSearchModel model)
|
||||
{
|
||||
if (!model.Id.HasValue)
|
||||
if (!model.Id.HasValue && (!model.ImplementerId.HasValue || !model.Status.HasValue))
|
||||
{
|
||||
return new();
|
||||
}
|
||||
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)
|
||||
@ -67,7 +70,7 @@ namespace ConfectioneryDatabaseImplement.Implements
|
||||
{
|
||||
return null;
|
||||
}
|
||||
order.Update(model);
|
||||
order.Update(context, model);
|
||||
context.SaveChanges();
|
||||
return order.GetViewModel;
|
||||
}
|
||||
|
@ -10,6 +10,7 @@ namespace ConfectioneryFileImplement.Models
|
||||
{
|
||||
public int Id { get; private set; }
|
||||
public int ClientId { get; private set; }
|
||||
public int? ImplementerId { get; set; }
|
||||
public int PastryId { get; private set; }
|
||||
public int Count { get; private set; }
|
||||
public double Sum { get; private set; }
|
||||
@ -27,6 +28,8 @@ namespace ConfectioneryFileImplement.Models
|
||||
{
|
||||
Id = model.Id,
|
||||
PastryId = model.PastryId,
|
||||
ClientId = model.ClientId,
|
||||
ImplementerId = model.ImplementerId,
|
||||
Count = model.Count,
|
||||
Sum = model.Sum,
|
||||
Status = model.Status,
|
||||
@ -46,6 +49,8 @@ namespace ConfectioneryFileImplement.Models
|
||||
{
|
||||
Id = Convert.ToInt32(element.Attribute("Id")!.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),
|
||||
Sum = Convert.ToDouble(element.Element("Sum")!.Value),
|
||||
Status = (OrderStatus)(Enum.Parse(typeof(OrderStatus), element.Element("Status")!.Value)),
|
||||
@ -68,6 +73,8 @@ namespace ConfectioneryFileImplement.Models
|
||||
{
|
||||
Id = Id,
|
||||
PastryId = PastryId,
|
||||
ClientId = ClientId,
|
||||
ImplementerId = ImplementerId,
|
||||
Count = Count,
|
||||
Sum = Sum,
|
||||
Status = Status,
|
||||
@ -78,6 +85,8 @@ namespace ConfectioneryFileImplement.Models
|
||||
public XElement GetXElement => new("Order",
|
||||
new XAttribute("Id", Id),
|
||||
new XElement("PastryId", PastryId.ToString()),
|
||||
new XElement("ClientId", ClientId.ToString()),
|
||||
new XElement("ImplementerId", ImplementerId),
|
||||
new XElement("Count", Count.ToString()),
|
||||
new XElement("Sum", Sum.ToString()),
|
||||
new XElement("Status", Status.ToString()),
|
||||
|
@ -24,15 +24,53 @@ namespace ConfectioneryFileImplement.Implements
|
||||
|
||||
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 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)
|
||||
{
|
||||
if (model.ImplementerId.HasValue)
|
||||
{
|
||||
return source.Orders.FirstOrDefault(x => x.ImplementerId == model.ImplementerId)?.GetViewModel;
|
||||
}
|
||||
if (!model.Id.HasValue)
|
||||
{
|
||||
return new();
|
||||
|
@ -15,6 +15,7 @@ namespace ConfectioneryListImplement.Models
|
||||
public int Id { get; private set; }
|
||||
public int PastryId { get; private set; }
|
||||
public int ClientId { get; private set; }
|
||||
public int? ImplementerId { get; private set; }
|
||||
public int Count { get; private set; }
|
||||
public double Sum { get; private set; }
|
||||
public OrderStatus Status { get; private set; } = OrderStatus.Неизвестен;
|
||||
@ -31,6 +32,8 @@ namespace ConfectioneryListImplement.Models
|
||||
{
|
||||
Id = model.Id,
|
||||
PastryId = model.PastryId,
|
||||
ClientId = model.ClientId,
|
||||
ImplementerId = model.ImplementerId,
|
||||
Count = model.Count,
|
||||
Sum = model.Sum,
|
||||
Status = model.Status,
|
||||
@ -53,6 +56,8 @@ namespace ConfectioneryListImplement.Models
|
||||
{
|
||||
Id = Id,
|
||||
PastryId = PastryId,
|
||||
ClientId = ClientId,
|
||||
ImplementerId = ImplementerId,
|
||||
Count = Count,
|
||||
Sum = Sum,
|
||||
Status = Status,
|
||||
|
@ -33,19 +33,69 @@ namespace ConfectioneryListImplement
|
||||
public List<OrderViewModel> GetFilteredList(OrderSearchModel model)
|
||||
{
|
||||
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)
|
||||
{
|
||||
if (order.Id == model.Id)
|
||||
{
|
||||
result.Add(AttachPastryName(order.GetViewModel));
|
||||
result.Add(GetViewModel(order));
|
||||
}
|
||||
}
|
||||
}
|
||||
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)
|
||||
{
|
||||
@ -59,6 +109,10 @@ namespace ConfectioneryListImplement
|
||||
{
|
||||
return AttachPastryName(order.GetViewModel);
|
||||
}
|
||||
else if (model.ImplementerId.HasValue && model.ImplementerId == order.ImplementerId)
|
||||
{
|
||||
return GetViewModel(order);
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
16
Confectionery/ConfectioneryView/FormMain.Designer.cs
generated
16
Confectionery/ConfectioneryView/FormMain.Designer.cs
generated
@ -56,7 +56,7 @@
|
||||
dataGridView.Location = new Point(12, 60);
|
||||
dataGridView.Name = "dataGridView";
|
||||
dataGridView.RowHeadersWidth = 62;
|
||||
dataGridView.Size = new Size(1374, 549);
|
||||
dataGridView.Size = new Size(1614, 549);
|
||||
dataGridView.TabIndex = 0;
|
||||
//
|
||||
// menuStrip
|
||||
@ -65,7 +65,7 @@
|
||||
menuStrip.Items.AddRange(new ToolStripItem[] { toolStripMenuItem, отчетыToolStripMenuItem, startWorkToolStripMenuItem });
|
||||
menuStrip.Location = new Point(0, 0);
|
||||
menuStrip.Name = "menuStrip";
|
||||
menuStrip.Size = new Size(1666, 33);
|
||||
menuStrip.Size = new Size(1921, 33);
|
||||
menuStrip.TabIndex = 1;
|
||||
menuStrip.Text = "menuStrip1";
|
||||
//
|
||||
@ -142,7 +142,7 @@
|
||||
// buttonCreateOrder
|
||||
//
|
||||
buttonCreateOrder.Anchor = AnchorStyles.Top | AnchorStyles.Right;
|
||||
buttonCreateOrder.Location = new Point(1402, 83);
|
||||
buttonCreateOrder.Location = new Point(1657, 83);
|
||||
buttonCreateOrder.Name = "buttonCreateOrder";
|
||||
buttonCreateOrder.Size = new Size(232, 34);
|
||||
buttonCreateOrder.TabIndex = 2;
|
||||
@ -153,7 +153,7 @@
|
||||
// buttonTakeOrderInWork
|
||||
//
|
||||
buttonTakeOrderInWork.Anchor = AnchorStyles.Top | AnchorStyles.Right;
|
||||
buttonTakeOrderInWork.Location = new Point(1402, 143);
|
||||
buttonTakeOrderInWork.Location = new Point(1657, 143);
|
||||
buttonTakeOrderInWork.Name = "buttonTakeOrderInWork";
|
||||
buttonTakeOrderInWork.Size = new Size(232, 34);
|
||||
buttonTakeOrderInWork.TabIndex = 3;
|
||||
@ -164,7 +164,7 @@
|
||||
// buttonOrderReady
|
||||
//
|
||||
buttonOrderReady.Anchor = AnchorStyles.Top | AnchorStyles.Right;
|
||||
buttonOrderReady.Location = new Point(1402, 203);
|
||||
buttonOrderReady.Location = new Point(1657, 203);
|
||||
buttonOrderReady.Name = "buttonOrderReady";
|
||||
buttonOrderReady.Size = new Size(232, 34);
|
||||
buttonOrderReady.TabIndex = 4;
|
||||
@ -175,7 +175,7 @@
|
||||
// buttonIssuedOrder
|
||||
//
|
||||
buttonIssuedOrder.Anchor = AnchorStyles.Top | AnchorStyles.Right;
|
||||
buttonIssuedOrder.Location = new Point(1402, 266);
|
||||
buttonIssuedOrder.Location = new Point(1657, 266);
|
||||
buttonIssuedOrder.Name = "buttonIssuedOrder";
|
||||
buttonIssuedOrder.Size = new Size(232, 34);
|
||||
buttonIssuedOrder.TabIndex = 5;
|
||||
@ -186,7 +186,7 @@
|
||||
// buttonRef
|
||||
//
|
||||
buttonRef.Anchor = AnchorStyles.Top | AnchorStyles.Right;
|
||||
buttonRef.Location = new Point(1402, 329);
|
||||
buttonRef.Location = new Point(1657, 329);
|
||||
buttonRef.Name = "buttonRef";
|
||||
buttonRef.Size = new Size(232, 34);
|
||||
buttonRef.TabIndex = 6;
|
||||
@ -198,7 +198,7 @@
|
||||
//
|
||||
AutoScaleDimensions = new SizeF(10F, 25F);
|
||||
AutoScaleMode = AutoScaleMode.Font;
|
||||
ClientSize = new Size(1666, 621);
|
||||
ClientSize = new Size(1921, 621);
|
||||
Controls.Add(buttonRef);
|
||||
Controls.Add(buttonIssuedOrder);
|
||||
Controls.Add(buttonOrderReady);
|
||||
|
@ -43,6 +43,7 @@ namespace ConfectioneryView
|
||||
dataGridView.DataSource = list;
|
||||
dataGridView.Columns["PastryId"].Visible = false;
|
||||
dataGridView.Columns["ClientId"].Visible = false;
|
||||
dataGridView.Columns["ImplementerId"].Visible = false;
|
||||
dataGridView.Columns["PastryName"].AutoSizeMode =
|
||||
DataGridViewAutoSizeColumnMode.Fill;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user