fix conflict

This commit is contained in:
Danil Markov 2023-05-02 14:13:01 +04:00
commit 10a249df2b
8 changed files with 28 additions and 30 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

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

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

@ -54,12 +54,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

@ -104,7 +104,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

@ -168,7 +168,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>());
}
}