using com.sun.tools.doclets.formats.html;
using Comal.Classes;
using InABox.Clients;
using InABox.Core;
using InABox.DynamicGrid;
using InABox.Reports;
using InABox.Reports.Common;
using InABox.Scripting;
using InABox.WPF;
using PRSDesktop.Configuration;
using PRSDesktop.Forms;
using PRSDesktop.WidgetGroups;
using Syncfusion.UI.Xaml.Grid;
using Syncfusion.UI.Xaml.Grid.Converter;
using Syncfusion.Windows.Shared;
using Syncfusion.XlsIO;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Data;
using System.Diagnostics;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
using System.Linq.Expressions;
using System.Reflection;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using SelectionChangedEventArgs = System.Windows.Controls.SelectionChangedEventArgs;
namespace PRSDesktop
{
public enum DateFilterType
{
Today,
Yesterday,
Week,
SevenDays,
Month,
ThirtyDays,
Year,
TwelveMonths,
Custom
}
public class DFFilter : BaseObject
{
[EditorSequence(1)]
[TextBoxEditor]
public string Name { get; set; }
[EditorSequence(2)]
[FilterEditor]
public string Filter { get; set; }
protected override void Init()
{
base.Init();
Name = "";
Filter = "";
}
}
public class DigitalFormsDashboardProperties : IDashboardProperties
{
public bool ShowJobFilter { get; set; } = false;
public bool ShowDateFilter { get; set; } = true;
public string? Category { get; set; }
public Guid SelectedForm { get; set; }
public Guid JobID { get; set; }
public DateFilterType DateFilterType { get; set; } = DateFilterType.Today;
public DateTime FromDate { get; set; }
public DateTime ToDate { get; set; }
public Dictionary> Filters { get; set; } = new();
}
public class DigitalFormsDashboardElement : DashboardElement { }
///
/// Interaction logic for DigitalFormsDashboard.xaml
///
public partial class DigitalFormsDashboard : UserControl,
IDashboardWidget,
IRequiresSecurity,
IHeaderDashboard, IActionsDashboard
{
public DigitalFormsDashboardProperties Properties { get; set; }
private List DigitalForms;
private List Jobs;
private Dictionary Categories;
public DashboardHeader Header { get; set; } = new();
private bool IsQAForm = false;
private List Questions = new();
private bool IsSetup = false;
public DigitalFormsDashboard()
{
InitializeComponent();
}
public void Setup()
{
var results = Client.QueryMultiple(
new KeyedQueryDef(new Filter(x => x.Active).IsEqualTo(true)),
new KeyedQueryDef(
LookupFactory.DefineFilter(),
new Columns(x => x.ID)
.Add(x => x.JobNumber)
.Add(x => x.Name)));
DigitalForms = results.Get().ToList();
var categories = new DigitalFormCategoryLookups(null);
categories.OnAfterGenerateLookups += (sender, entries) => { entries.Insert(0, new LookupEntry("", "Select Category")); };
Categories = categories.AsTable("AppliesTo")
.ToDictionary("AppliesTo", "Display")
.Cast>()
.ToDictionary(x => (x.Key as string)!, x => x.Value);
Jobs = results.Get().ToList();
Jobs.Insert(0, new Job { ID = Guid.Empty, JobNumber = "ALL", Name = "All Jobs" });
SetupHeader();
SetupFilters();
IsSetup = true;
}
#region Header
private ComboBox CategoryBox;
private ComboBox FormBox;
private ComboBox JobBox;
private ComboBox DateTypeBox;
private Label FromLabel;
private DatePicker FromPicker;
private Label ToLabel;
private DatePicker ToPicker;
private Button Print;
private Button FilterBtn;
private static Dictionary FilterTypes = new()
{
{ DateFilterType.Today, "Today" },
{ DateFilterType.Yesterday, "Yesterday" },
{ DateFilterType.Week, "Week to Date" },
{ DateFilterType.SevenDays, "Last 7 Days" },
{ DateFilterType.Month, "Month to Date" },
{ DateFilterType.ThirtyDays, "Last 30 Days" },
{ DateFilterType.Year, "Year to Date" },
{ DateFilterType.TwelveMonths, "Last 12 Months" },
{ DateFilterType.Custom, "Custom" }
};
public void SetupHeader()
{
CategoryBox = new ComboBox {
Width = 150,
VerticalContentAlignment = VerticalAlignment.Center,
Margin = new Thickness(0, 0, 5, 0)
};
CategoryBox.ItemsSource = Categories;
CategoryBox.SelectedValue = Properties.Category;
CategoryBox.SelectedValuePath = "Key";
CategoryBox.DisplayMemberPath = "Value";
CategoryBox.SelectionChanged += Category_SelectionChanged;
FormBox = new ComboBox
{
Width = 250,
VerticalContentAlignment = VerticalAlignment.Center,
Margin = new Thickness(0, 0, 5, 0),
IsEnabled = false
};
FormBox.SelectionChanged += FormBox_SelectionChanged;
FormBox.ItemsSource = new Dictionary { };
JobBox = new ComboBox
{
Width = 250,
Margin = new Thickness(0, 0, 5, 0),
VerticalContentAlignment = VerticalAlignment.Center
};
JobBox.ItemsSource = Jobs.ToDictionary(x => x.ID, x => $"{x.JobNumber} : {x.Name}");
JobBox.SelectedIndex = 0;
JobBox.SelectedValuePath = "Key";
JobBox.DisplayMemberPath = "Value";
JobBox.SelectionChanged += JobBox_SelectionChanged;
DateTypeBox = new ComboBox
{
Width = 120,
VerticalContentAlignment = VerticalAlignment.Center
};
DateTypeBox.ItemsSource = FilterTypes;
DateTypeBox.SelectedValuePath = "Key";
DateTypeBox.DisplayMemberPath = "Value";
DateTypeBox.SelectedValue = Properties.DateFilterType;
DateTypeBox.SelectionChanged += DateTypeBox_SelectionChanged;
FromLabel = new Label { Content = "From", VerticalContentAlignment = VerticalAlignment.Center, Margin = new Thickness(0, 0, 5, 0) };
FromPicker = new DatePicker {
Width = 100,
Background = new SolidColorBrush(Colors.LightYellow),
VerticalContentAlignment = VerticalAlignment.Center,
FirstDayOfWeek = DayOfWeek.Monday,
Margin = new Thickness(0, 0, 5, 0)
};
FromPicker.SelectedDateChanged += FromPicker_SelectedDateChanged;
ToLabel = new Label { Content = "To", VerticalContentAlignment = VerticalAlignment.Center, Margin = new Thickness(0, 0, 5, 0) };
ToPicker = new DatePicker
{
Width = 100,
Background = new SolidColorBrush(Colors.LightYellow),
VerticalContentAlignment = VerticalAlignment.Center,
FirstDayOfWeek = DayOfWeek.Monday,
Margin = new Thickness(0, 0, 5, 0)
};
ToPicker.SelectedDateChanged += ToPicker_SelectedDateChanged;
Print = new Button
{
Width = 25,
Height = 25,
Content = new Image { Source = PRSDesktop.Resources.printer.AsBitmapImage() }
};
Print.Click += Print_Click;
FilterBtn = new Button
{
Width = 25,
Height = 25,
Content = new Image { Source = InABox.DynamicGrid.Properties.Resources.filter.AsBitmapImage() },
Margin = new Thickness(0, 0, 5, 0)
};
FilterBtn.Click += Filter_Click;
Header.BeginUpdate()
.Clear()
.Add(CategoryBox)
.Add(FormBox)
.Add(JobBox)
.Add(DateTypeBox)
.Add(FromLabel)
.Add(FromPicker)
.Add(ToLabel)
.Add(ToPicker)
.AddRight(FilterBtn)
.AddRight(Print);
Header.EndUpdate();
UpdateCategory(Properties.Category);
}
private void Filter_Click(object sender, RoutedEventArgs e)
{
var menu = new ContextMenu();
menu.AddCheckItem