123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129 |
- 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<DigitalForm>
- {
- 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<DigitalForm, string>(c => c.AppliesTo);
- var formid = arg.Get<DigitalForm, Guid>(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<IDigitalFormInstance, String>(x => x.Form.Description, "."), DataType = typeof(String) });
- form.Columns.Add(new CoreColumn() { ColumnName = CoreUtils.GetFullPropertyName<IDigitalFormInstance, String>(x => x.FormCompletedBy.UserID, "."), DataType = typeof(String) });
- form.Columns.Add(new CoreColumn() { ColumnName = CoreUtils.GetFullPropertyName<IDigitalFormInstance, DateTime>(x => x.FormCompleted, "."), DataType = typeof(String) });
- form.Columns.Add(new CoreColumn() { ColumnName = CoreUtils.GetFullPropertyName<IDigitalFormInstance, String>(x => x.Location.Address, "."), DataType = typeof(String) });
- form.Columns.Add(new CoreColumn() { ColumnName = CoreUtils.GetFullPropertyName<IDigitalFormInstance, double>(x => x.Location.Latitude, "."), DataType = typeof(String) });
- form.Columns.Add(new CoreColumn() { ColumnName = CoreUtils.GetFullPropertyName<IDigitalFormInstance, double>(x => x.Location.Longitude, "."), DataType = typeof(String) });
-
- var variables = new Client<DigitalFormVariable>().Query(new Filter<DigitalFormVariable>(x => x.Form.ID).IsEqualTo(formid));
- foreach (var row in variables.Rows)
- {
- form.Columns.Add(
- new CoreColumn()
- {
- ColumnName = row.Get<DigitalFormVariable, String>(c => c.Code),
- DataType = DigitalFormVariable.DataType(row.Get<DigitalFormVariable, DigitalFormVariableType>(c => c.VariableType))
- }
- );
- }*
- // Create DataModel
- //DigitalFormReportDataModel model = new DigitalFormReportDataModel(form,entity,typename);
- AutoDataModel<DigitalForm> model = new AutoDataModel<DigitalForm>(new Filter<DigitalForm>(x => x.ID).IsEqualTo(formid));
- // Load Template
- var template = new Client<ReportTemplate>()
- .Load(new Filter<ReportTemplate>(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<ReportTemplate>().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<DigitalForm> criteria, Columns<DigitalForm> columns, ref SortOrder<DigitalForm> sort,
- Action<CoreTable, Exception> action)
- {
- if (!_showall)
- criteria.Add(new Filter<DigitalForm>(x => x.Active).IsEqualTo(true));
- base.Reload(criteria, columns, ref sort, action);
- }
- public override bool EditItems(DigitalForm[] items, Func<Type, CoreTable> 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<string> errors)
- {
- base.DoValidate(items, errors);
- if (items.Any(x => string.IsNullOrWhiteSpace(x.AppliesTo)))
- errors.Add("[Applies To] must not be blank!");
- }
- }
- }
|