|
@@ -1,710 +0,0 @@
|
|
|
-using System;
|
|
|
-using System.Collections.Generic;
|
|
|
-using System.Linq;
|
|
|
-using System.Windows;
|
|
|
-using System.Windows.Controls;
|
|
|
-using System.Windows.Media;
|
|
|
-using System.Windows.Media.Imaging;
|
|
|
-using System.Windows.Threading;
|
|
|
-using Comal.Classes;
|
|
|
-using InABox.Clients;
|
|
|
-using InABox.Core;
|
|
|
-using InABox.DynamicGrid;
|
|
|
-using InABox.Reports;
|
|
|
-using InABox.Core.Reports;
|
|
|
-using InABox.Scripting;
|
|
|
-using InABox.Wpf.Reports;
|
|
|
-using InABox.WPF;
|
|
|
-using PRSDesktop.Configuration;
|
|
|
-using System.Diagnostics;
|
|
|
-using System.Threading.Tasks;
|
|
|
-
|
|
|
-namespace PRSDesktop
|
|
|
-{
|
|
|
-
|
|
|
- public class DigitalFormDockModel : BaseObject
|
|
|
- {
|
|
|
- [NullEditor]
|
|
|
- public Guid ID { get; set; }
|
|
|
-
|
|
|
- [NullEditor]
|
|
|
- public Guid FormID { get; set; }
|
|
|
-
|
|
|
- [CodeEditor(Visible = Visible.Default, Width=80)]
|
|
|
- [EditorSequence(1)]
|
|
|
- public string Number { get; set; }
|
|
|
-
|
|
|
- [TextBoxEditor(Visible = Visible.Default)]
|
|
|
- [EditorSequence(2)]
|
|
|
- public string FormName { get; set; }
|
|
|
-
|
|
|
- [DateTimeEditor(Visible=Visible.Default, Width=100, Format = "dd MMM yy HH:mm")]
|
|
|
- [EditorSequence(3)]
|
|
|
- public DateTime Completed { get; set; }
|
|
|
-
|
|
|
- [TextBoxEditor(Visible=Visible.Default, Width=80, Alignment = Alignment.MiddleCenter)]
|
|
|
- [EditorSequence(4)]
|
|
|
- public string CompletedBy { get; set; }
|
|
|
-
|
|
|
- [NullEditor]
|
|
|
- public Type FormType { get; set; }
|
|
|
-
|
|
|
- [NullEditor]
|
|
|
- public DateTime Processed { get; set; }
|
|
|
-
|
|
|
- [NullEditor]
|
|
|
- public Guid ParentID { get; set; }
|
|
|
- }
|
|
|
-
|
|
|
- public class DigitalFormDockGrid : DynamicGrid<DigitalFormDockModel>
|
|
|
- {
|
|
|
- private CoreFieldMap<IDigitalFormInstance, DigitalFormDockModel> _mappings;
|
|
|
- private IEnumerable<Type> _types;
|
|
|
- private MultiQuery _query;
|
|
|
- private CoreTable _data;
|
|
|
-
|
|
|
- public Dictionary<Type, System.Drawing.Bitmap> Images { get; private set; }
|
|
|
- public List<Type> ExcludedTypes { get; private set; }
|
|
|
- public DateTime StartDate { get; set; }
|
|
|
-
|
|
|
- public DigitalFormDockGrid() : base()
|
|
|
- {
|
|
|
-
|
|
|
- StartDate = DateTime.Today;
|
|
|
- ExcludedTypes = new List<Type>();
|
|
|
-
|
|
|
- Images = new Dictionary<Type, System.Drawing.Bitmap>()
|
|
|
- {
|
|
|
- { typeof(AssignmentForm), PRSDesktop.Resources.assignments },
|
|
|
- { typeof(KanbanForm), PRSDesktop.Resources.kanban },
|
|
|
- { typeof(JobForm), PRSDesktop.Resources.project },
|
|
|
- { typeof(JobITPForm), PRSDesktop.Resources.checklist },
|
|
|
- { typeof(EmployeeForm), PRSDesktop.Resources.employees },
|
|
|
- { typeof(LeaveRequestForm), PRSDesktop.Resources.leave },
|
|
|
- { typeof(ManufacturingPacketStage), PRSDesktop.Resources.factory },
|
|
|
- { typeof(TimeSheetForm), PRSDesktop.Resources.time },
|
|
|
- { typeof(PurchaseOrderItemForm), PRSDesktop.Resources.purchase }
|
|
|
- };
|
|
|
-
|
|
|
- ActionColumns.Add(new DynamicImageColumn(TypeImage)
|
|
|
- {
|
|
|
- Position = DynamicActionColumnPosition.Start,
|
|
|
- Filters = Images.Keys.Select(x=>x.EntityName().Split('.').Last().SplitCamelCase()).ToArray(),
|
|
|
- FilterRecord = TypeFilter
|
|
|
- });
|
|
|
-
|
|
|
- ActionColumns.Add(new DynamicMenuColumn(MenuBuild, MenuStatus) { Position = DynamicActionColumnPosition.End });
|
|
|
-
|
|
|
- _mappings = new CoreFieldMap<IDigitalFormInstance, DigitalFormDockModel>()
|
|
|
- .Add(x => x.ID, x => x.ID)
|
|
|
- .Add(x => x.Form.ID, x => x.FormID)
|
|
|
- .Add(x => x.Number, x => x.Number)
|
|
|
- .Add(x => x.Form.Description, x => x.FormName)
|
|
|
- .Add(x => x.FormCompleted, x => x.Completed)
|
|
|
- .Add(x => x.FormCompletedBy.UserID, x => x.CompletedBy)
|
|
|
- .Add(x => x.FormProcessed, x => x.Processed)
|
|
|
- .Add(x => x.Parent.ID, x => x.ParentID);
|
|
|
-
|
|
|
- _query = new MultiQuery();
|
|
|
-
|
|
|
- _types = CoreUtils.TypeList(e =>
|
|
|
- e.IsSubclassOf(typeof(Entity))
|
|
|
- && e.GetInterfaces().Contains(typeof(IRemotable))
|
|
|
- && e.GetInterfaces().Contains(typeof(IPersistent))
|
|
|
- && e.GetInterfaces().Contains(typeof(IDigitalFormInstance))
|
|
|
- );
|
|
|
-
|
|
|
- _data = new CoreTable();
|
|
|
- _data.LoadColumns(typeof(DigitalFormDockModel));
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
- protected override void Init()
|
|
|
- {
|
|
|
- }
|
|
|
-
|
|
|
- protected override void DoReconfigure(FluentList<DynamicGridOption> options)
|
|
|
- {
|
|
|
- options.BeginUpdate();
|
|
|
- options.Clear();
|
|
|
- options.Add(DynamicGridOption.FilterRows);
|
|
|
- options.EndUpdate();
|
|
|
- }
|
|
|
-
|
|
|
- protected override DynamicGridStyle GetRowStyle(CoreRow row, DynamicGridStyle style)
|
|
|
- {
|
|
|
- var result = base.GetRowStyle(row, style);
|
|
|
- if (!row.Get<DigitalFormDockModel, DateTime>(x => x.Processed).IsEmpty())
|
|
|
- result = new DynamicGridRowStyle(result)
|
|
|
- {
|
|
|
- Background = new SolidColorBrush(Colors.LightGray),
|
|
|
- };
|
|
|
- return result;
|
|
|
- }
|
|
|
-
|
|
|
- private bool TypeFilter(CoreRow row, string[] filter)
|
|
|
- {
|
|
|
- string typename = row.Get<DigitalFormDockModel, Type>(x => x.FormType).EntityName().Split('.').Last().SplitCamelCase();
|
|
|
- return filter.Contains(typename);
|
|
|
- }
|
|
|
-
|
|
|
- private BitmapImage? TypeImage(CoreRow? arg)
|
|
|
- {
|
|
|
- if (arg == null)
|
|
|
- return null;
|
|
|
- var type = arg.Get<DigitalFormDockModel, Type>(x => x.FormType);
|
|
|
- return Images.GetValueOrDefault(type)?.AsBitmapImage();
|
|
|
- }
|
|
|
-
|
|
|
- private void MenuBuild(DynamicMenuColumn column, CoreRow? row)
|
|
|
- {
|
|
|
- if (row == null) return;
|
|
|
-
|
|
|
- var instanceID = row.Get<DigitalFormDockModel, Guid>(x => x.ID);
|
|
|
- var formID = row.Get<DigitalFormDockModel, Guid>(x => x.FormID);
|
|
|
- var formType = row.Get<DigitalFormDockModel, Type>(x => x.FormType);
|
|
|
- var filter = Filter.Create<IDigitalFormInstance>(formType, x => x.ID).IsEqualTo(instanceID);
|
|
|
- var model = (Activator.CreateInstance(typeof(DigitalFormReportDataModel<>).MakeGenericType(formType), filter, formID) as DataModel)!;
|
|
|
-
|
|
|
- var modules = new Client<CustomModule>().Query(
|
|
|
- new Filter<CustomModule>(x => x.DataModel).IsEqualTo(model.Name)
|
|
|
- .And(x => x.Section).IsEqualTo(formID.ToString())
|
|
|
- .And(x => x.Visible).IsEqualTo(true)
|
|
|
- ).Rows.Select(x => x.ToObject<CustomModule>());
|
|
|
- foreach(var module in modules)
|
|
|
- {
|
|
|
- column.AddItem(
|
|
|
- module.Name,
|
|
|
- PRSDesktop.Resources.edit,
|
|
|
- row =>
|
|
|
- {
|
|
|
- try
|
|
|
- {
|
|
|
- if(ScriptDocument.RunCustomModule(model, new Dictionary<string, object[]>(), module.Script))
|
|
|
- {
|
|
|
- Refresh(false, true);
|
|
|
- }
|
|
|
- }
|
|
|
- catch(CompileException c)
|
|
|
- {
|
|
|
- MessageBox.Show(c.Message);
|
|
|
- }
|
|
|
- catch(Exception e)
|
|
|
- {
|
|
|
- MessageBox.Show(CoreUtils.FormatException(e));
|
|
|
- }
|
|
|
- },
|
|
|
- null,
|
|
|
- row.Get<DigitalFormDockModel, DateTime>(x => x.Processed).IsEmpty()
|
|
|
- );
|
|
|
- }
|
|
|
-
|
|
|
- if (modules.Any())
|
|
|
- column.AddSeparator();
|
|
|
-
|
|
|
- if (row.Get<DigitalFormDockModel, DateTime>(x => x.Processed).IsEmpty())
|
|
|
- {
|
|
|
- column.AddItem(
|
|
|
- "Mark As Processed",
|
|
|
- PRSDesktop.Resources.lock_sml,
|
|
|
- (row) =>
|
|
|
- {
|
|
|
- var form = (Activator.CreateInstance(formType) as IDigitalFormInstance)!;
|
|
|
- form.ID = row!.Get<DigitalFormDockModel, Guid>(x => x.ID);
|
|
|
- form.FormProcessed = row.Get<DigitalFormDockModel, DateTime>(x => x.Processed);
|
|
|
- form.CommitChanges();
|
|
|
- form.FormProcessed = DateTime.Now;
|
|
|
- using (new WaitCursor())
|
|
|
- {
|
|
|
- ClientFactory.CreateClient(formType).Save(form, "Marked As Processed");
|
|
|
- Refresh(false, true);
|
|
|
- }
|
|
|
- }
|
|
|
- );
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- column.AddItem(
|
|
|
- "Clear Processed Flag",
|
|
|
- PRSDesktop.Resources.lock_sml,
|
|
|
- (row) =>
|
|
|
- {
|
|
|
- var form = (Activator.CreateInstance(formType) as IDigitalFormInstance)!;
|
|
|
- form.ID = row!.Get<DigitalFormDockModel, Guid>(x => x.ID);
|
|
|
- form.FormProcessed = row.Get<DigitalFormDockModel, DateTime>(x => x.Processed);
|
|
|
- form.CommitChanges();
|
|
|
- form.FormProcessed = DateTime.MinValue;
|
|
|
- using (new WaitCursor())
|
|
|
- {
|
|
|
- ClientFactory.CreateClient(formType).Save(form, "Processed Flag Cleared");
|
|
|
- Refresh(false, true);
|
|
|
- }
|
|
|
- }
|
|
|
- );
|
|
|
- }
|
|
|
-
|
|
|
- var entityType = DFUtils.FormEntityType(formType);
|
|
|
- if(entityType.HasInterface<IJobScopedItem>())
|
|
|
- {
|
|
|
- var entityID = row.Get<DigitalFormDockModel, Guid>(x => x.ParentID);
|
|
|
- column.AddSeparator();
|
|
|
- column.AddItem("Set Job", PRSDesktop.Resources.project, (row) =>
|
|
|
- {
|
|
|
- var entity = (Client.Create(entityType)
|
|
|
- .Query(
|
|
|
- Filter.Create<Entity>(entityType, x => x.ID).IsEqualTo(entityID),
|
|
|
- LookupFactory.DefineFilterColumns(typeof(Job), entityType)
|
|
|
- .Add<Entity>(x => x.ID)
|
|
|
- .Add<IJobScopedItem>(x => x.JobLink.ID)
|
|
|
- .Add<IJobScopedItem>(x => x.JobLink.JobNumber))
|
|
|
- .ToObjects(entityType).First() as Entity)!;
|
|
|
- var item = (entity as IJobScopedItem)!;
|
|
|
-
|
|
|
- var arr = Array.CreateInstance(entityType, 1);
|
|
|
- arr.SetValue(entity, 0);
|
|
|
- var window = new MultiSelectDialog<Job>(
|
|
|
- LookupFactory.DefineFilter<Job>(entityType, arr),
|
|
|
- new Columns<Job>(x => x.DefaultScope.ID).Add(x => x.JobNumber),
|
|
|
- multiselect: false);
|
|
|
- if (!window.ShowDialog(nameof(Job.JobNumber), item.JobLink.JobNumber, Syncfusion.Data.FilterType.Equals))
|
|
|
- {
|
|
|
- return;
|
|
|
- }
|
|
|
- var job = window.Data().ToObjects<Job>().First();
|
|
|
- item.JobLink.ID = job.ID;
|
|
|
- item.JobLink.Synchronise(job);
|
|
|
-
|
|
|
- Client.Create(entityType).Save(entity, "Linked job set by user from Digital forms dock.");
|
|
|
- MessageBox.Show($"{entityType.Name} has been assigned to job {job.JobNumber}.");
|
|
|
- });
|
|
|
- column.AddItem("Set Job Scope", PRSDesktop.Resources.project, (row) =>
|
|
|
- {
|
|
|
- var entity = (Client.Create(entityType)
|
|
|
- .Query(
|
|
|
- Filter.Create<Entity>(entityType, x => x.ID).IsEqualTo(entityID),
|
|
|
- LookupFactory.DefineFilterColumns(typeof(JobScope), entityType)
|
|
|
- .Add<Entity>(x => x.ID)
|
|
|
- .Add<IJobScopedItem>(x => x.JobLink.ID)
|
|
|
- .Add<IJobScopedItem>(x => x.JobScope.ID)
|
|
|
- .Add<IJobScopedItem>(x => x.JobScope.Number))
|
|
|
- .ToObjects(entityType).First() as Entity)!;
|
|
|
- var item = (entity as IJobScopedItem)!;
|
|
|
- if(item.JobLink.ID == Guid.Empty)
|
|
|
- {
|
|
|
- MessageBox.Show($"{entityType.Name} is not linked to a job. Please select a job first.");
|
|
|
- return;
|
|
|
- }
|
|
|
-
|
|
|
- var arr = Array.CreateInstance(entityType, 1);
|
|
|
- arr.SetValue(entity, 0);
|
|
|
- var window = new MultiSelectDialog<JobScope>(
|
|
|
- new Filters<JobScope>()
|
|
|
- .Add(LookupFactory.DefineFilter<JobScope>(entityType, arr))
|
|
|
- .Add(new Filter<JobScope>(x => x.Job.ID).IsEqualTo(item.JobLink.ID))
|
|
|
- .Combine(),
|
|
|
- new Columns<JobScope>(x => x.ID).Add(x => x.Number),
|
|
|
- multiselect: false);
|
|
|
- if (!window.ShowDialog(nameof(JobScope.Number), item.JobScope.Number, Syncfusion.Data.FilterType.Equals))
|
|
|
- {
|
|
|
- return;
|
|
|
- }
|
|
|
- var scope = window.Data().ToObjects<JobScope>().First();
|
|
|
- item.JobScope.ID = scope.ID;
|
|
|
-
|
|
|
- Client.Create(entityType).Save(entity, "Linked scope set by user from Digital forms dock.");
|
|
|
- MessageBox.Show($"{entityType.Name} has been assigned to scope {scope.Number}.");
|
|
|
- });
|
|
|
- }
|
|
|
- else if(entityType == typeof(Job) && formType == typeof(JobForm))
|
|
|
- {
|
|
|
- column.AddSeparator();
|
|
|
- column.AddItem("Set Job Scope", PRSDesktop.Resources.project, (row) =>
|
|
|
- {
|
|
|
- var instance = Client.Query(
|
|
|
- new Filter<JobForm>(x => x.ID).IsEqualTo(instanceID),
|
|
|
- LookupFactory.DefineFilterColumns<JobForm, JobScope>()
|
|
|
- .Add(x => x.ID)
|
|
|
- .Add(x => x.Parent.ID))
|
|
|
- .ToObjects<JobForm>().First();
|
|
|
- var job = Client.Query(
|
|
|
- new Filter<Job>(x => x.ID).IsEqualTo(instance.Parent.ID),
|
|
|
- LookupFactory.DefineFilterColumns<Job, JobScope>()).ToObjects<Job>().First();
|
|
|
-
|
|
|
- var window = new MultiSelectDialog<JobScope>(
|
|
|
- new Filters<JobScope>()
|
|
|
- .Add(LookupFactory.DefineFilter<Job, JobScope>(new Job[] { job }))
|
|
|
- .Add(new Filter<JobScope>(x => x.Job.ID).IsEqualTo(instance.Parent.ID))
|
|
|
- .Combine(),
|
|
|
- new Columns<JobScope>(x => x.ID).Add(x => x.Number), multiselect: false);
|
|
|
- if (!window.ShowDialog())
|
|
|
- {
|
|
|
- return;
|
|
|
- }
|
|
|
- var scope = window.Data().ToObjects<JobScope>().First();
|
|
|
- instance.JobScope.ID = scope.ID;
|
|
|
-
|
|
|
- Client.Save(instance, "Linked scope set by user from Digital forms dock.");
|
|
|
- MessageBox.Show($"Form has been assigned to scope {scope.Number}.");
|
|
|
- });
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- if (Security.IsAllowed<CanCustomiseModules>())
|
|
|
- {
|
|
|
- column.AddSeparator();
|
|
|
- column.AddItem("Customise Modules", PRSDesktop.Resources.script, row =>
|
|
|
- {
|
|
|
- var manager = new CustomModuleManager
|
|
|
- {
|
|
|
- Section = formID.ToString(),
|
|
|
- DataModel = model
|
|
|
- };
|
|
|
- manager.ShowDialog();
|
|
|
- });
|
|
|
- }
|
|
|
-
|
|
|
- if (Security.IsAllowed<CanPrintReports>())
|
|
|
- {
|
|
|
- column.AddSeparator();
|
|
|
- var printItem = column.AddItem("Print", PRSDesktop.Resources.printer, null);
|
|
|
-
|
|
|
- ReportUtils.PopulateMenu(printItem, formID.ToString(), model, Security.IsAllowed<CanDesignReports>(), true);
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- /*private void AttachToScope(CoreRow row, Type formType, DataModel model)
|
|
|
- {
|
|
|
- var instance = Client.Create(formType)
|
|
|
- .Query(
|
|
|
- Filter.Create<IDigitalFormInstance>(formType, x => x.ID).IsEqualTo(row.Get<DigitalFormDockModel, Guid>(x => x.ID)),
|
|
|
- Columns.Create<IDigitalFormInstance>(formType)
|
|
|
- .Add<IDigitalFormInstance>(x => x.ID)
|
|
|
- .Add<IDigitalFormInstance>(x => x.Number))
|
|
|
- .Rows.FirstOrDefault()
|
|
|
- ?.ToObject(formType) as IDigitalFormInstance;
|
|
|
- if (instance is null)
|
|
|
- {
|
|
|
- MessageBox.Show("Form does not exist!");
|
|
|
- return;
|
|
|
- }
|
|
|
- var formID = row.Get<DigitalFormDockModel, Guid>(x => x.FormID);
|
|
|
-
|
|
|
- var entityColumns = JobScopeForms.GetEntityColumns(formType)?.Add<Entity>(x => x.ID);
|
|
|
- var entityObj = Client.Create(instance.ParentType())
|
|
|
- .Query(
|
|
|
- Filter.Create<Entity>(instance.ParentType(), x => x.ID).IsEqualTo(row.Get<DigitalFormDockModel, Guid>(x => x.ParentID)),
|
|
|
- entityColumns).ToObjects(instance.ParentType()).FirstOrDefault();
|
|
|
- if (entityObj is not Entity entity)
|
|
|
- {
|
|
|
- MessageBox.Show($"Attached {instance.ParentType().Name} does not exist!");
|
|
|
- return;
|
|
|
- }
|
|
|
-
|
|
|
- #region Selecting Scope
|
|
|
-
|
|
|
- // JobScopes obviously can't have an empty ID, so it's fine that I turn null into Guid.Empty here.
|
|
|
- var scopeID = JobScopeForms.GetJobScopeID(formType, instance, entity) ?? Guid.Empty;
|
|
|
- if(scopeID == Guid.Empty)
|
|
|
- {
|
|
|
- // JobScopes can't have an empty job, so it's fine that I turn null into Guid.Empty here.
|
|
|
- var jobID = JobScopeForms.GetJobID(formType, instance, entity) ?? Guid.Empty;
|
|
|
- if(jobID == Guid.Empty)
|
|
|
- {
|
|
|
- var jobs = new MultiSelectDialog<Job>(null, null, multiselect: false);
|
|
|
- if(!jobs.ShowDialog("Select a job"))
|
|
|
- {
|
|
|
- MessageBox.Show("No job selected; process cancelled.");
|
|
|
- return;
|
|
|
- }
|
|
|
- jobID = jobs.IDs().First();
|
|
|
- }
|
|
|
-
|
|
|
- var scopes = new MultiSelectDialog<JobScope>(new Filter<JobScope>(x => x.Job.ID).IsEqualTo(jobID), null, multiselect: false);
|
|
|
- if (!scopes.ShowDialog("Select a scope"))
|
|
|
- {
|
|
|
- MessageBox.Show("Process cancelled.");
|
|
|
- return;
|
|
|
- }
|
|
|
- scopeID = scopes.IDs().First();
|
|
|
- }
|
|
|
-
|
|
|
- var scopeTask = Task.Run(() => Client.QueryMultiple(
|
|
|
- new KeyedQueryDef<JobScope>(
|
|
|
- new Filter<JobScope>(x => x.ID).IsEqualTo(scopeID),
|
|
|
- new Columns<JobScope>(x => x.ID).Add(x => x.Number)),
|
|
|
- new KeyedQueryDef<Job>(
|
|
|
- new Filter<Job>(x => x.ID).InQuery(new Filter<JobScope>(x => x.ID).IsEqualTo(scopeID), x => x.Job.ID),
|
|
|
- new Columns<Job>(x => x.JobNumber))));
|
|
|
-
|
|
|
- #endregion
|
|
|
-
|
|
|
- #region Selecting Report
|
|
|
-
|
|
|
- var reports = new List<ReportTemplate>();
|
|
|
- Progress.ShowModal("Loading Document", (progress) =>
|
|
|
- {
|
|
|
- reports = ReportUtils.LoadReports(formID.ToString(), model).ToList();
|
|
|
- });
|
|
|
-
|
|
|
- ReportTemplate report;
|
|
|
- if (reports.Count == 0)
|
|
|
- {
|
|
|
- ReportTemplate reportTemplate = null!;
|
|
|
- Progress.ShowModal("Loading form layout", (progress) =>
|
|
|
- {
|
|
|
- progress.Report("Loading form layout");
|
|
|
- var layouts = Client.Query(
|
|
|
- new Filter<DigitalFormLayout>(x => x.Form.ID).IsEqualTo(formID),
|
|
|
- new Columns<DigitalFormLayout>(x => x.Layout)
|
|
|
- .Add(x => x.Code)
|
|
|
- .Add(x => x.Type)
|
|
|
- .Add(x => x.Description))
|
|
|
- .ToObjects<DigitalFormLayout>().ToArray();
|
|
|
- var layout = layouts.FirstOrDefault(x => x.Type == DFLayoutType.Desktop) ?? layouts.FirstOrDefault();
|
|
|
- if (layout is null)
|
|
|
- {
|
|
|
- MessageBox.Show("This form has no report or layout, so it cannot be attached to a job scope!");
|
|
|
- return;
|
|
|
- }
|
|
|
-
|
|
|
- progress.Report("Generating report");
|
|
|
-
|
|
|
- report = new ReportTemplate
|
|
|
- {
|
|
|
- DataModel = model.Name,
|
|
|
- Name = layout.Description.NotWhiteSpaceOr(layout.Code),
|
|
|
- RDL = DigitalFormUtils.GenerateReport(layout, model)?.SaveToString()
|
|
|
- };
|
|
|
- });
|
|
|
- report = reportTemplate;
|
|
|
- }
|
|
|
- else if (reports.Count == 1)
|
|
|
- {
|
|
|
- report = reports[0];
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- var selectedReports = new MultiSelectDialog<ReportTemplate>(
|
|
|
- ReportUtils.GetReportFilter(formID.ToString(), model),
|
|
|
- null,
|
|
|
- multiselect: false);
|
|
|
- if (!selectedReports.ShowDialog())
|
|
|
- {
|
|
|
- return;
|
|
|
- }
|
|
|
- report = selectedReports.Items().First();
|
|
|
- }
|
|
|
-
|
|
|
- #endregion
|
|
|
-
|
|
|
- Document document = null!;
|
|
|
-
|
|
|
- Progress.ShowModal("Loading Document", (progress) =>
|
|
|
- {
|
|
|
- progress.Report("Generating Document");
|
|
|
-
|
|
|
- var data = ReportUtils.ReportToPDF(report, model, true);
|
|
|
-
|
|
|
- progress.Report("Saving Document");
|
|
|
-
|
|
|
- document = new Document
|
|
|
- {
|
|
|
- FileName = $"{instance.Number}: {report.Name}.pdf",
|
|
|
- Data = data,
|
|
|
- CRC = CoreUtils.CalculateCRC(data)
|
|
|
- };
|
|
|
- Client.Save(document, "");
|
|
|
-
|
|
|
- progress.Report("Creating Job Scope Document");
|
|
|
-
|
|
|
- var jobScopeDocument = new JobScopeDocument();
|
|
|
- jobScopeDocument.DocumentLink.ID = document.ID;
|
|
|
- jobScopeDocument.EntityLink.ID = scopeID;
|
|
|
- Client.Save(jobScopeDocument, $"Generated from form: {instance.Number}");
|
|
|
- });
|
|
|
-
|
|
|
- scopeTask.Wait();
|
|
|
- var scopeResults = scopeTask.Result;
|
|
|
- var scope = scopeResults.GetObjects<JobScope>().First();
|
|
|
- var job = scopeResults.GetObjects<Job>().First();
|
|
|
-
|
|
|
- MessageBox.Show($"Attached as '{document.FileName}' to job scope {scope.Number} for job {job.JobNumber}");
|
|
|
- }*/
|
|
|
-
|
|
|
- private DynamicMenuStatus MenuStatus(CoreRow row)
|
|
|
- {
|
|
|
- if (row == null) return DynamicMenuStatus.Hidden;
|
|
|
- return DynamicMenuStatus.Enabled;
|
|
|
- }
|
|
|
-
|
|
|
- protected override void Reload(Filters<DigitalFormDockModel> criteria, Columns<DigitalFormDockModel> columns, ref SortOrder<DigitalFormDockModel>? sort, Action<CoreTable, Exception?> action)
|
|
|
- {
|
|
|
-
|
|
|
- _query.Clear();
|
|
|
- foreach (var type in _types.Where(x => !ExcludedTypes.Contains(x)))
|
|
|
- {
|
|
|
-
|
|
|
- var filter = Filter.Create<IDigitalFormInstance>(type, x => x.FormCompleted).IsGreaterThanOrEqualTo(StartDate)
|
|
|
- .And<IDigitalFormInstance>(x=>x.FormCancelled).IsEqualTo(DateTime.MinValue);
|
|
|
-
|
|
|
- var cols = Columns.Create<IDigitalFormInstance>(type)
|
|
|
- .Add<IDigitalFormInstance>(c => c.ID)
|
|
|
- .Add<IDigitalFormInstance>(c => c.Parent.ID)
|
|
|
- .Add<IDigitalFormInstance>(c => c.Form.ID)
|
|
|
- .Add<IDigitalFormInstance>(c => c.Number)
|
|
|
- .Add<IDigitalFormInstance>(c => c.Form.Description)
|
|
|
- .Add<IDigitalFormInstance>(c => c.FormCompleted)
|
|
|
- .Add<IDigitalFormInstance>(c => c.FormCompletedBy.UserID)
|
|
|
- .Add<IDigitalFormInstance>(c => c.FormProcessed);
|
|
|
-
|
|
|
- var sorts = SortOrder.Create<IDigitalFormInstance>(type, x => x.FormCompleted, SortDirection.Descending);
|
|
|
-
|
|
|
- _query.Add(
|
|
|
- new QueryDef(type)
|
|
|
- {
|
|
|
- Filter = filter,
|
|
|
- Columns = cols,
|
|
|
- SortOrder = sorts
|
|
|
- },
|
|
|
- type
|
|
|
- );
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
- _query.Query((q) =>
|
|
|
- {
|
|
|
- _data.Rows.Clear();
|
|
|
- foreach (var type in _types.Where(x=>!ExcludedTypes.Contains(x)))
|
|
|
- _data.LoadFrom(
|
|
|
- _query.Get(type),
|
|
|
- _mappings,
|
|
|
- (r) => r.Set<DigitalFormDockModel,Type>(x=>x.FormType,type)
|
|
|
- );
|
|
|
- action.Invoke(_data, null);
|
|
|
- });
|
|
|
- }
|
|
|
-
|
|
|
- protected override DigitalFormDockModel LoadItem(CoreRow row)
|
|
|
- {
|
|
|
- return row.ToObject<DigitalFormDockModel>();
|
|
|
- }
|
|
|
-
|
|
|
- public override void SaveItem(DigitalFormDockModel item)
|
|
|
- {
|
|
|
- //throw new NotImplementedException();
|
|
|
- }
|
|
|
-
|
|
|
- protected override void DeleteItems(params CoreRow[] rows)
|
|
|
- {
|
|
|
- //throw new NotImplementedException();
|
|
|
- }
|
|
|
-
|
|
|
- protected override void DoDoubleClick(object sender)
|
|
|
- {
|
|
|
- base.DoDoubleClick(sender);
|
|
|
-
|
|
|
- var row = SelectedRows.FirstOrDefault();
|
|
|
- if (row is null)
|
|
|
- return;
|
|
|
-
|
|
|
- var instanceID = row.Get<DigitalFormDockModel, Guid>(x => x.ID);
|
|
|
- var formID = row.Get<DigitalFormDockModel, Guid>(x => x.FormID);
|
|
|
- var formType = row.Get<DigitalFormDockModel, Type>(x => x.FormType);
|
|
|
-
|
|
|
- var formInstance = Client.Create(formType)
|
|
|
- .Query(
|
|
|
- Filter.Create<IDigitalFormInstance>(formType, x => x.ID).IsEqualTo(instanceID),
|
|
|
- DynamicFormEditWindow.FormColumns(formType))
|
|
|
- .Rows.FirstOrDefault()
|
|
|
- ?.ToObject(formType) as IDigitalFormInstance;
|
|
|
-
|
|
|
- if(formInstance is null)
|
|
|
- {
|
|
|
- return;
|
|
|
- }
|
|
|
- if (formID == Guid.Empty)
|
|
|
- {
|
|
|
- var window = new DeletedFormWindow();
|
|
|
- window.FormData = formInstance?.FormData ?? "";
|
|
|
- window.ShowDialog();
|
|
|
- return;
|
|
|
- }
|
|
|
- if (DynamicFormEditWindow.EditDigitalForm(formInstance, out var model))
|
|
|
- {
|
|
|
- model.Update(null);
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
- public partial class DigitalFormsDock : UserControl, IDockPanel
|
|
|
- {
|
|
|
-
|
|
|
- private static SolidColorBrush EnabledBrush = new SolidColorBrush(Colors.LightYellow);
|
|
|
- private static SolidColorBrush DisabledBrush = new SolidColorBrush(Colors.LightGray);
|
|
|
-
|
|
|
- public DigitalFormsDock()
|
|
|
- {
|
|
|
- InitializeComponent();
|
|
|
- RefreshButton.Content = new Image() { Source = PRSDesktop.Resources.refresh.AsBitmapImage() };
|
|
|
- foreach (var type in Items.Images.Keys)
|
|
|
- {
|
|
|
- Button button = new Button();
|
|
|
- button.Background = EnabledBrush;
|
|
|
- button.Content = new Image() { Source = Items.Images[type].AsBitmapImage() };
|
|
|
- button.BorderBrush = new SolidColorBrush(Colors.Gray);
|
|
|
- button.BorderThickness = new Thickness(0.75);
|
|
|
- button.Margin = new Thickness(2, 0, 0, 0);
|
|
|
- button.Width = 25D;
|
|
|
- button.Padding = new Thickness(2);
|
|
|
- button.ToolTip = type.EntityName().Split('.').Last().SplitCamelCase();
|
|
|
- button.Click += TypeFilterClick;
|
|
|
- button.Tag = type;
|
|
|
- TypeStack.Children.Add(button);
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- private void TypeFilterClick(object sender, RoutedEventArgs e)
|
|
|
- {
|
|
|
- var button = (sender as Button)!;
|
|
|
- var type = (button.Tag as Type)!;
|
|
|
- if (Items.ExcludedTypes.Contains(type))
|
|
|
- Items.ExcludedTypes.Remove(type);
|
|
|
- else
|
|
|
- Items.ExcludedTypes.Add(type);
|
|
|
- button.Background = Items.ExcludedTypes.Contains(type)
|
|
|
- ? DisabledBrush
|
|
|
- : EnabledBrush;
|
|
|
- Refresh();
|
|
|
- }
|
|
|
-
|
|
|
- private void RefreshButton_OnClick(object sender, RoutedEventArgs e)
|
|
|
- {
|
|
|
- Refresh();
|
|
|
- }
|
|
|
-
|
|
|
- public void Setup()
|
|
|
- {
|
|
|
- Items.Refresh(true, false);
|
|
|
- }
|
|
|
-
|
|
|
- public void Refresh()
|
|
|
- {
|
|
|
- Items.Refresh(false, true);
|
|
|
- }
|
|
|
-
|
|
|
- private void AgeCombo_OnSelectionChanged(object sender, SelectionChangedEventArgs e)
|
|
|
- {
|
|
|
- var startdate = AgeCombo.SelectedIndex == 2
|
|
|
- ? DateTime.Today.AddDays(-30)
|
|
|
- : AgeCombo.SelectedIndex == 1
|
|
|
- ? DateTime.Today.AddDays(-7)
|
|
|
- : DateTime.Today;
|
|
|
- if ((Items != null) && (startdate != Items.StartDate))
|
|
|
- {
|
|
|
- Items.StartDate = startdate;
|
|
|
- Refresh();
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
-}
|