using System; using System.Collections.Generic; using System.Linq; using System.Windows.Controls; using System.Windows.Media.Imaging; using InABox.Clients; using InABox.Core; using InABox.DynamicGrid; using InABox.Reports; using InABox.Reports.Common; using InABox.WPF; namespace PRSDesktop.Configuration { public class QAFormGrid : DynamicDataGrid { private bool _showall; public QAFormGrid() { AddButton("Show All", null, ShowAllClick); // TODO: Add back in //ActionColumns.Add(new DynamicActionColumn(ReportImage, ReportClick)); AddButton("Groups", null, EditGroupsClick); } private bool EditGroupsClick(Button arg1, CoreRow[] arg2) { new MasterList(typeof(DigitalFormGroup)).ShowDialog(); return false; } private BitmapImage ReportImage(CoreRow arg) { return arg != null ? PRSDesktop.Resources.printer.AsBitmapImage() : null; } /*private bool ReportClick(CoreRow arg) { if (arg == null) return false; var typename = arg.Get(c => c.AppliesTo); var formid = arg.Get(c => c.ID); // Get Applies To /*Type type = CoreUtils.GetEntity("Comal.Classes."+typename); CoreTable entity = new CoreTable(); entity.LoadColumns(type); // Get Form Details CoreTable form = new CoreTable(); form.Columns.Add(new CoreColumn() { ColumnName = "ID", DataType = typeof(Guid) }); form.Columns.Add(new CoreColumn() { ColumnName = "Parent.ID", DataType = typeof(Guid) }); form.Columns.Add(new CoreColumn() { ColumnName = CoreUtils.GetFullPropertyName(x => x.Form.Description, "."), DataType = typeof(String) }); form.Columns.Add(new CoreColumn() { ColumnName = CoreUtils.GetFullPropertyName(x => x.FormCompletedBy.UserID, "."), DataType = typeof(String) }); form.Columns.Add(new CoreColumn() { ColumnName = CoreUtils.GetFullPropertyName(x => x.FormCompleted, "."), DataType = typeof(String) }); form.Columns.Add(new CoreColumn() { ColumnName = CoreUtils.GetFullPropertyName(x => x.Location.Address, "."), DataType = typeof(String) }); form.Columns.Add(new CoreColumn() { ColumnName = CoreUtils.GetFullPropertyName(x => x.Location.Latitude, "."), DataType = typeof(String) }); form.Columns.Add(new CoreColumn() { ColumnName = CoreUtils.GetFullPropertyName(x => x.Location.Longitude, "."), DataType = typeof(String) }); var variables = new Client().Query(new Filter(x => x.Form.ID).IsEqualTo(formid)); foreach (var row in variables.Rows) { form.Columns.Add( new CoreColumn() { ColumnName = row.Get(c => c.Code), DataType = DigitalFormVariable.DataType(row.Get(c => c.VariableType)) } ); }* // Create DataModel //DigitalFormReportDataModel model = new DigitalFormReportDataModel(form,entity,typename); AutoDataModel model = new AutoDataModel(new Filter(x => x.ID).IsEqualTo(formid)); // Load Template var template = new Client() .Load(new Filter(x => x.Section).IsEqualTo("DigitalForms").And(x => x.Name).IsEqualTo(formid.ToString())) .FirstOrDefault(); if (template == null) { template = new ReportTemplate { Section = "DigitalForms", Name = formid.ToString(), Visible = false }; new Client().Save(template, ""); } ReportUtils.DesignReport(template, model); // Preview Report return false; }*/ private bool ShowAllClick(Button arg1, CoreRow[] arg2) { _showall = !_showall; UpdateButton(arg1, null, _showall ? "Hide Inactive" : "Show All"); return true; } protected override void Reload(Filters criteria, Columns columns, ref SortOrder sort, Action action) { if (!_showall) criteria.Add(new Filter(x => x.Active).IsEqualTo(true)); base.Reload(criteria, columns, ref sort, action); } public override bool EditItems(DigitalForm[] items, Func PageDataHandler = null, bool PreloadPages = false) { // Need to do this to make sure that the variables are available to the layouts (and vice versa?) return base.EditItems(items, PageDataHandler, true); } protected override void DoValidate(DigitalForm[] items, List errors) { base.DoValidate(items, errors); if (items.Any(x => string.IsNullOrWhiteSpace(x.AppliesTo))) errors.Add("[Applies To] must not be blank!"); } } }