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

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,8 +41,9 @@ namespace ConfectioneryBusinessLogic
}
public List<OrderViewModel>? ReadList(OrderSearchModel? model)
{
_logger.LogInformation("ReadList. OrderId:{Id}", model?.Id);
var list = model == null ? _orderStorage.GetFullList() : _orderStorage.GetFilteredList(model);
_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)
{
_logger.LogWarning("ReadList return null list");
@ -120,23 +121,30 @@ namespace ConfectioneryBusinessLogic
model.DateCreate = element.DateCreate;
model.PastryId = element.PastryId;
model.DateImplement = element.DateImplement;
model.Status = element.Status;
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.Выдан)
model.DateImplement = DateTime.Now;
if (_orderStorage.Update(model) == null)
{
_logger.LogWarning("Update operation failed");
return false;
}
return true;
}
_logger.LogWarning("Changing status operation faled: Current-{Status}:required-{requiredStatus}.", model.Status, requiredStatus);
throw new ArgumentException($"Невозможно присвоить статус {requiredStatus} заказу с текущим статусом {model.Status}");
if (requiredStatus - model.Status == 1)
{
model.Status = requiredStatus;
if (model.Status == OrderStatus.Готов)
{
model.DateImplement = DateTime.Now;
}
if (_orderStorage.Update(model) == null)
{
_logger.LogWarning("Update operation failed");
return false;
}
return true;
}
_logger.LogWarning("Changing status operation faled: Current-{Status}:required-{requiredStatus}.", model.Status, requiredStatus);
throw new ArgumentException($"Невозможно присвоить статус {requiredStatus} заказу с текущим статусом {model.Status}");
}
}
}

View File

@ -17,7 +17,10 @@ namespace ConfectioneryContracts.ViewModels
[DisplayName("ФИО клиента")]
public string ClientFIO { get; set; } = string.Empty;
public int PastryId { get; set; }
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;
[DisplayName("Количество")]

View File

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

View File

@ -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,7 +203,9 @@ namespace ConfectioneryDatabaseImplement.Migrations
b.Navigation("Client");
b.Navigation("Pastry");
b.Navigation("Implementer");
b.Navigation("Pastry");
});
modelBuilder.Entity("ConfectioneryDatabaseImplement.Models.PastryComponent", b =>

View File

@ -23,8 +23,10 @@ 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]
[Required]
public int Count { get; private set; }
[Required]
@ -47,7 +49,9 @@ namespace ConfectioneryDatabaseImplement.Models
Client = context.Clients.First(x => x.Id == model.ClientId),
PastryId = model.PastryId,
Pastry = context.Pastrys.First(x => x.Id == model.PastryId),
Count = model.Count,
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,
DateCreate = model.DateCreate,
@ -55,7 +59,7 @@ namespace ConfectioneryDatabaseImplement.Models
};
}
public void Update(OrderBindingModel? model)
public void Update(ConfectioneryDatabase context, OrderBindingModel? model)
{
if (model == null)
{
@ -63,7 +67,9 @@ 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,7 +78,9 @@ namespace ConfectioneryDatabaseImplement.Models
ClientFIO = Client.ClientFIO,
PastryId = PastryId,
PastryName = Pastry.PastryName,
Count = Count,
ImplementerId = ImplementerId,
ImplementerFIO = Implementer != null ? Implementer.ImplementerFIO : null,
Count = Count,
Sum = Sum,
Status = Status,
DateCreate = DateCreate,

View File

@ -17,32 +17,35 @@ 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)
{
return context.Orders.Include(x => x.Pastry).Where(x => x.DateCreate >= model.DateFrom && x.DateCreate <= model.DateTo).Select(x => x.GetViewModel).ToList();
}
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();
}
using var context = new ConfectioneryDatabase();
if ((!model.DateFrom.HasValue || !model.DateTo.HasValue) && !model.ClientId.HasValue && !model.Status.HasValue)
{
return new();
}
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)
{
return new();
}
using var context = new ConfectioneryDatabase();
return context.Orders.Include(x => x.Pastry).FirstOrDefault(x => x.Id == model.Id)?.GetViewModel;
}
if (!model.Id.HasValue && (!model.ImplementerId.HasValue || !model.Status.HasValue))
{
return new();
}
using var context = new ConfectioneryDatabase();
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;
}

View File

@ -10,7 +10,8 @@ namespace ConfectioneryFileImplement.Models
{
public int Id { get; private set; }
public int ClientId { get; private set; }
public int PastryId { 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; }
public OrderStatus Status { get; private set; } = OrderStatus.Неизвестен;
@ -27,12 +28,14 @@ namespace ConfectioneryFileImplement.Models
{
Id = model.Id,
PastryId = model.PastryId,
Count = model.Count,
Sum = model.Sum,
Status = model.Status,
DateCreate = model.DateCreate,
DateImplement = model.DateImplement,
};
ClientId = model.ClientId,
ImplementerId = model.ImplementerId,
Count = model.Count,
Sum = model.Sum,
Status = model.Status,
DateCreate = model.DateCreate,
DateImplement = model.DateImplement,
};
}
public static Order? Create(XElement element)
@ -46,12 +49,14 @@ namespace ConfectioneryFileImplement.Models
{
Id = Convert.ToInt32(element.Attribute("Id")!.Value),
PastryId = Convert.ToInt32(element.Element("PastryId")!.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)),
DateCreate = Convert.ToDateTime(element.Element("DateCreate")!.Value),
DateImplement = (dateImplement == "" || dateImplement is null) ? Convert.ToDateTime(null) : Convert.ToDateTime(dateImplement)
};
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)),
DateCreate = Convert.ToDateTime(element.Element("DateCreate")!.Value),
DateImplement = (dateImplement == "" || dateImplement is null) ? Convert.ToDateTime(null) : Convert.ToDateTime(dateImplement)
};
}
public void Update(OrderBindingModel? model)
@ -68,20 +73,24 @@ namespace ConfectioneryFileImplement.Models
{
Id = Id,
PastryId = PastryId,
Count = Count,
Sum = Sum,
Status = Status,
DateCreate = DateCreate,
DateImplement = DateImplement,
};
ClientId = ClientId,
ImplementerId = ImplementerId,
Count = Count,
Sum = Sum,
Status = Status,
DateCreate = DateCreate,
DateImplement = DateImplement,
};
public XElement GetXElement => new("Order",
new XAttribute("Id", Id),
new XElement("PastryId", PastryId.ToString()),
new XElement("Count", Count.ToString()),
new XElement("Sum", Sum.ToString()),
new XElement("Status", Status.ToString()),
new XElement("DateCreate", DateCreate.ToString()),
new XElement("DateImplement", DateImplement.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()),
new XElement("DateCreate", DateCreate.ToString()),
new XElement("DateImplement", DateImplement.ToString()));
}
}

View File

@ -24,21 +24,59 @@ namespace ConfectioneryFileImplement.Implements
public List<OrderViewModel> GetFilteredList(OrderSearchModel model)
{
if (!model.Id.HasValue)
{
return new();
}
return source.Orders.Where(x => x.Id == model.Id).Select(x => AttachPastryName(x.GetViewModel)).ToList();
}
if (model.DateFrom.HasValue)
{
return source.Orders.Where(x => x.DateCreate >= model.DateFrom && x.DateCreate <= model.DateTo)
.Select(x => GetViewModel(x)).ToList();
}
public OrderViewModel? GetElement(OrderSearchModel model)
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();
}
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.Id.HasValue)
{
return new();
}
return AttachPastryName(source.Orders.FirstOrDefault(x => x.Id == model.Id)?.GetViewModel);
}
if (model.ImplementerId.HasValue)
{
return source.Orders.FirstOrDefault(x => x.ImplementerId == model.ImplementerId)?.GetViewModel;
}
if (!model.Id.HasValue)
{
return new();
}
return AttachPastryName(source.Orders.FirstOrDefault(x => x.Id == model.Id)?.GetViewModel);
}
public OrderViewModel? Insert(OrderBindingModel model)
{

View File

@ -15,7 +15,8 @@ namespace ConfectioneryListImplement.Models
public int Id { get; private set; }
public int PastryId { get; private set; }
public int ClientId { get; private set; }
public int Count { 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.Неизвестен;
public DateTime DateCreate { get; private set; } = DateTime.Now;
@ -31,12 +32,14 @@ namespace ConfectioneryListImplement.Models
{
Id = model.Id,
PastryId = model.PastryId,
Count = model.Count,
Sum = model.Sum,
Status = model.Status,
DateCreate = model.DateCreate,
DateImplement = model.DateImplement,
};
ClientId = model.ClientId,
ImplementerId = model.ImplementerId,
Count = model.Count,
Sum = model.Sum,
Status = model.Status,
DateCreate = model.DateCreate,
DateImplement = model.DateImplement,
};
}
public void Update(OrderBindingModel? model)
@ -53,11 +56,13 @@ namespace ConfectioneryListImplement.Models
{
Id = Id,
PastryId = PastryId,
Count = Count,
Sum = Sum,
Status = Status,
DateCreate = DateCreate,
DateImplement = DateImplement,
};
ClientId = ClientId,
ImplementerId = ImplementerId,
Count = Count,
Sum = Sum,
Status = Status,
DateCreate = DateCreate,
DateImplement = DateImplement,
};
}
}

View File

@ -32,36 +32,90 @@ namespace ConfectioneryListImplement
public List<OrderViewModel> GetFilteredList(OrderSearchModel model)
{
var result = new List<OrderViewModel>();
if (model == null || !model.Id.HasValue)
{
return result;
}
foreach (var order in _source.Orders)
{
if (order.Id == model.Id)
{
result.Add(AttachPastryName(order.GetViewModel));
}
}
return result;
}
var result = new List<OrderViewModel>();
if (model.DateFrom.HasValue)
{
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(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)
public OrderViewModel? GetElement(OrderSearchModel model)
{
if (!model.Id.HasValue)
{
return null;
}
foreach (var order in _source.Orders)
{
if (model.Id.HasValue && order.Id == model.Id)
{
return AttachPastryName(order.GetViewModel);
}
}
return null;
}
if (!model.Id.HasValue)
{
return null;
}
foreach (var order in _source.Orders)
{
if (model.Id.HasValue && order.Id == model.Id)
{
return AttachPastryName(order.GetViewModel);
}
else if (model.ImplementerId.HasValue && model.ImplementerId == order.ImplementerId)
{
return GetViewModel(order);
}
}
return null;
}
public OrderViewModel? Insert(OrderBindingModel model)
{

View File

@ -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);

View File

@ -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;
}