This commit is contained in:
Danil Markov 2023-04-21 14:19:31 +04:00
parent 4a88074155
commit 2e62277509
14 changed files with 47 additions and 44 deletions

View File

@ -52,7 +52,7 @@ namespace LawFirmBusinessLogic.BusinessLogics
{
model.DateImplement = viewModel.DateImplement;
}
CheckModel(model);
CheckModel(model, false);
if (_orderStorage.Update(model) == null)
{
model.Status--;

View File

@ -50,8 +50,7 @@ namespace LawFirmBusinessLogic.BusinessLogics
if (document.DocumentBlanks.ContainsKey(blank.Id))
{
record.Blanks.Add(new Tuple<string, int>(blank.BlankName, document.DocumentBlanks[blank.Id].Item2));
record.TotalCount +=
document.DocumentBlanks[blank.Id].Item2;
record.TotalCount += document.DocumentBlanks[blank.Id].Item2;
}
}
list.Add(record);

View File

@ -23,10 +23,10 @@ namespace LawFirmBusinessLogic.OfficePackage
= "Normal",
ParagraphAlignment = PdfParagraphAlignmentType.Center
});
CreateTable(new List<string> { "2cm", "3cm", "6cm", "3cm" });
CreateTable(new List<string> { "2cm", "3cm", "6cm", "3cm", "3cm" });
CreateRow(new PdfRowParameters
{
Texts = new List<string> { "Номер", "Дата заказа", "Изделие", "Сумма" },
Texts = new List<string> { "Номер", "Дата заказа", "Изделие", "Статус", "Сумма" },
Style = "NormalTitle",
ParagraphAlignment = PdfParagraphAlignmentType.Center
});
@ -34,7 +34,7 @@ namespace LawFirmBusinessLogic.OfficePackage
{
CreateRow(new PdfRowParameters
{
Texts = new List<string> { order.Id.ToString(), order.DateCreate.ToShortDateString(), order.DocumentName, order.Sum.ToString() },
Texts = new List<string> { order.Id.ToString(), order.DateCreate.ToShortDateString(), order.DocumentName, order.OrderStatus, order.Sum.ToString() },
Style = "Normal",
ParagraphAlignment = PdfParagraphAlignmentType.Left
});

View File

@ -70,17 +70,17 @@ namespace LawFirmDatabaseImplement.Implements
using var transaction = context.Database.BeginTransaction();
try
{
var product = context.Documents.FirstOrDefault(rec =>
var document = context.Documents.FirstOrDefault(rec =>
rec.Id == model.Id);
if (product == null)
if (document == null)
{
return null;
}
product.Update(model);
document.Update(model);
context.SaveChanges();
product.UpdateBlanks(context, model);
document.UpdateBlanks(context, model);
transaction.Commit();
return product.GetViewModel;
return document.GetViewModel;
}
catch
{

View File

@ -13,19 +13,19 @@ namespace LawFirmDatabaseImplement.Models
public string DocumentName { get; set; } = string.Empty;
[Required]
public double Price { get; set; }
private Dictionary<int, (IBlankModel, int)>? _productBlanks = null;
private Dictionary<int, (IBlankModel, int)>? _documentBlanks = null;
[NotMapped]
public Dictionary<int, (IBlankModel, int)> DocumentBlanks
{
get
{
if (_productBlanks == null)
if (_documentBlanks == null)
{
_productBlanks = Blanks
_documentBlanks = Blanks
.ToDictionary(recPC => recPC.BlankId, recPC =>
(recPC.Blank as IBlankModel, recPC.Count));
}
return _productBlanks;
return _documentBlanks;
}
}
[ForeignKey("DocumentId")]
@ -61,15 +61,15 @@ namespace LawFirmDatabaseImplement.Models
public void UpdateBlanks(LawFirmDatabase context,
DocumentBindingModel model)
{
var productBlanks = context.DocumentBlanks.Where(rec =>
var documentBlanks = context.DocumentBlanks.Where(rec =>
rec.DocumentId == model.Id).ToList();
if (productBlanks != null && productBlanks.Count > 0)
if (documentBlanks != null && documentBlanks.Count > 0)
{ // удалили те, которых нет в модели
context.DocumentBlanks.RemoveRange(productBlanks.Where(rec
context.DocumentBlanks.RemoveRange(documentBlanks.Where(rec
=> !model.DocumentBlanks.ContainsKey(rec.BlankId)));
context.SaveChanges();
// обновили количество у существующих записей
foreach (var updateBlank in productBlanks)
foreach (var updateBlank in documentBlanks)
{
updateBlank.Count =
model.DocumentBlanks[updateBlank.BlankId].Item2;
@ -77,18 +77,18 @@ namespace LawFirmDatabaseImplement.Models
}
context.SaveChanges();
}
var product = context.Documents.First(x => x.Id == Id);
var document = context.Documents.First(x => x.Id == Id);
foreach (var pc in model.DocumentBlanks)
{
context.DocumentBlanks.Add(new DocumentBlank
{
Document = product,
Document = document,
Blank = context.Blanks.First(x => x.Id == pc.Key),
Count = pc.Value.Item2
});
context.SaveChanges();
}
_productBlanks = null;
_documentBlanks = null;
}
}

View File

@ -27,8 +27,8 @@ namespace LawFirmFileImplement
{
Blanks = LoadData(BlankFileName, "Blank", x => Blank.Create(x)!)!;
Documents = LoadData(DocumentFileName, "Document", x => Document.Create(x)!)!;
Orders = new List<Order>();
}
Orders = LoadData(OrderFileName, "Order", x => Order.Create(x)!)!;
}
private static List<T>? LoadData<T>(string filename, string xmlNodeName,
Func<XElement, T> selectFunction)
{

View File

@ -50,14 +50,14 @@ namespace LawFirmFileImplement.Implements
}
public DocumentViewModel? Update(DocumentBindingModel model)
{
var ship = source.Documents.FirstOrDefault(x => x.Id == model.Id);
if (ship == null)
var document = source.Documents.FirstOrDefault(x => x.Id == model.Id);
if (document == null)
{
return null;
}
ship.Update(model);
document.Update(model);
source.SaveDocuments();
return ship.GetViewModel;
return document.GetViewModel;
}
public DocumentViewModel? Delete(DocumentBindingModel model)
{

View File

@ -38,10 +38,10 @@ namespace LawFirmFileImplement.Implements
private OrderViewModel GetViewModel(Order order)
{
var viewModel = order.GetViewModel;
var ship = source.Documents.FirstOrDefault(x => x.Id == order.DocumentId);
if (ship != null)
var document = source.Documents.FirstOrDefault(x => x.Id == order.DocumentId);
if (document != null)
{
viewModel.DocumentName = ship.DocumentName;
viewModel.DocumentName = document.DocumentName;
}
return viewModel;
}

View File

@ -11,20 +11,20 @@ namespace LawFirmFileImplement.Models
public string DocumentName { get; private set; } = string.Empty;
public double Price { get; private set; }
public Dictionary<int, int> Blanks { get; private set; } = new();
private Dictionary<int, (IBlankModel, int)>? _productBlanks =
private Dictionary<int, (IBlankModel, int)>? _documentBlanks =
null;
public Dictionary<int, (IBlankModel, int)> DocumentBlanks
{
get
{
if (_productBlanks == null)
if (_documentBlanks == null)
{
var source = DataFileSingleton.GetInstance();
_productBlanks = Blanks.ToDictionary(x => x.Key, y =>
_documentBlanks = Blanks.ToDictionary(x => x.Key, y =>
((source.Blanks.FirstOrDefault(z => z.Id == y.Key) as IBlankModel)!,
y.Value));
}
return _productBlanks;
return _documentBlanks;
}
}
public static Document? Create(DocumentBindingModel model)
@ -70,7 +70,7 @@ namespace LawFirmFileImplement.Models
Price = model.Price;
Blanks = model.DocumentBlanks.ToDictionary(x => x.Key, x =>
x.Value.Item2);
_productBlanks = null;
_documentBlanks = null;
}
public DocumentViewModel GetViewModel => new()
{

View File

@ -45,12 +45,12 @@ namespace LawFirmView
try
{
int id = Convert.ToInt32(comboBoxDocument.SelectedValue);
var product = _logicD.ReadElement(new DocumentSearchModel
var document = _logicD.ReadElement(new DocumentSearchModel
{
Id = id
});
int count = Convert.ToInt32(textBoxCount.Text);
textBoxSum.Text = Math.Round(count * (product?.Price ?? 0), 2).ToString();
textBoxSum.Text = Math.Round(count * (document?.Price ?? 0), 2).ToString();
_logger.LogInformation("Расчет суммы заказа");
}
catch (Exception ex)

View File

@ -95,7 +95,7 @@
this.списокКомпонентовToolStripMenuItem.Name = "списокКомпонентовToolStripMenuItem";
this.списокКомпонентовToolStripMenuItem.Size = new System.Drawing.Size(218, 22);
this.списокКомпонентовToolStripMenuItem.Text = "Список компонентов";
this.списокКомпонентовToolStripMenuItem.Click += new System.EventHandler(this.BlanksReportToolStripMenuItem_Click);
this.списокКомпонентовToolStripMenuItem.Click += new System.EventHandler(this.DocumentsReportToolStripMenuItem_Click);
//
// компонентыПоИзделиямToolStripMenuItem
//

View File

@ -167,7 +167,7 @@ namespace LawFirmView
}
}
private void BlanksReportToolStripMenuItem_Click(object sender, EventArgs
private void DocumentsReportToolStripMenuItem_Click(object sender, EventArgs
e)
{
using var dialog = new SaveFileDialog { Filter = "docx|*.docx" };

View File

@ -31,11 +31,9 @@ namespace LawFirmView
dataGridView.Rows.Add(new object[] { elem.DocumentName, "", "" });
foreach (var listElem in elem.Blanks)
{
dataGridView.Rows.Add(new object[] { "",
listElem.Item1, listElem.Item2 });
dataGridView.Rows.Add(new object[] { "", listElem.Item1, listElem.Item2 });
}
dataGridView.Rows.Add(new object[] { "Итого", "",
elem.TotalCount });
dataGridView.Rows.Add(new object[] { "Итого", "", elem.TotalCount });
dataGridView.Rows.Add(Array.Empty<object>());
}
}

View File

@ -27,4 +27,10 @@
<ProjectReference Include="..\LawFirmListImplement\LawFirmListImplement.csproj" />
</ItemGroup>
<ItemGroup>
<None Update="ReportOrders.rdlc">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
</ItemGroup>
</Project>