123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706 |
- 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 window = new MultiSelectDialog<Job>(
- LookupFactory.DefineFilter<Job>(entityType, CoreUtils.One(entity)),
- 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 window = new MultiSelectDialog<JobScope>(
- new Filters<JobScope>()
- .Add(LookupFactory.DefineFilter<JobScope>(entityType, CoreUtils.One(entity)))
- .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();
- }
- }
- }
- }
|