12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667 |
- using Comal.Classes;
- using InABox.Core;
- using System.Collections.Generic;
- using System.Linq;
- using Syncfusion.Pdf.Parsing;
- using System.Drawing;
- using System.IO;
- using System.Drawing.Imaging;
- using InABox.Database;
- using System;
- namespace Comal.Stores
- {
- public class SetoutStore : BaseStore<Setout>
- {
- protected override void AfterSave(Setout entity)
- {
- if (entity.Group.ID != Guid.Empty)
- {
- var table = Provider.Query<SetoutGroup>(new Filter<SetoutGroup>(x => x.ID).IsEqualTo(entity.Group.ID)
- .And(x => x.OptimizationDocument.ID).IsNotEqualTo(Guid.Empty),
- Columns.None<SetoutGroup>().Add(x => x.OptimizationDocument.ID));
- if (!table.Rows.Any())
- return;
- var docID = table.Rows.FirstOrDefault().Get<SetoutGroup, Guid>(x => x.OptimizationDocument.ID);
- UpdateOptimisationDocument(FindSubStore<SetoutDocument>, entity, docID);
- }
- base.AfterSave(entity);
- }
- /// <summary>
- /// Update the optimisation document ID for a setout. The setout must have a non-empty <see cref="Entity.ID"/>.
- /// </summary>
- /// <param name="docStore"></param>
- /// <param name="setout">Setout with non-empty <see cref="Entity.ID"/></param>
- /// <param name="optimisationDocumentID"></param>
- public void UpdateOptimisationDocument(Func<IStore<SetoutDocument>> docStore, Setout setout, Guid optimisationDocumentID)
- {
- if (optimisationDocumentID == Guid.Empty) return;
- var ids = new List<Guid>();
- var docsTable = Provider.Query<SetoutDocument>(
- new Filter<SetoutDocument>(x => x.EntityLink.ID).IsEqualTo(setout.ID),
- Columns.None<SetoutDocument>().Add(x => x.DocumentLink.ID)
- );
- foreach (var row in docsTable.Rows)
- ids.Add(row.Get<SetoutDocument, Guid>(x => x.DocumentLink.ID));
- if (!ids.Contains(optimisationDocumentID))
- {
- var setoutdoc = new SetoutDocument();
- setoutdoc.EntityLink.ID = setout.ID;
- setoutdoc.DocumentLink.ID = optimisationDocumentID;
- docStore().Save(setoutdoc, "Added optimsation document from Group");
- }
- }
- protected override void BeforeDelete(Setout entity)
- {
- UnlinkTrackingKanban<SetoutKanban, Setout, SetoutLink>(entity);
- }
- }
- }
|