|
@@ -1,33 +1,62 @@
|
|
|
using System;
|
|
|
using System.Collections.Generic;
|
|
|
using System.Collections.ObjectModel;
|
|
|
+using System.Diagnostics;
|
|
|
using System.Linq;
|
|
|
using System.Windows;
|
|
|
using System.Windows.Controls;
|
|
|
+using System.Windows.Input;
|
|
|
using System.Windows.Media.Imaging;
|
|
|
using Comal.Classes;
|
|
|
using InABox.Clients;
|
|
|
+using InABox.Configuration;
|
|
|
using InABox.Core;
|
|
|
+using InABox.DynamicGrid;
|
|
|
using InABox.WPF;
|
|
|
|
|
|
namespace PRSDesktop
|
|
|
{
|
|
|
+
|
|
|
+
|
|
|
+ public class EquipmentPanelSettings : BaseObject, IGlobalConfigurationSettings
|
|
|
+ {
|
|
|
+ public bool CustomerFilterEnabled { get; set; }
|
|
|
+
|
|
|
+ public EquipmentPanelSettings()
|
|
|
+ {
|
|
|
+ CustomerFilterEnabled = false;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
/// <summary>
|
|
|
/// Interaction logic for EquipmentPanel.xaml
|
|
|
/// </summary>
|
|
|
public partial class EquipmentPanel : UserControl, IPanel<Equipment>
|
|
|
{
|
|
|
- public EquipmentGrid _Equipment;
|
|
|
+
|
|
|
+ private EquipmentPanelSettings _settings = null;
|
|
|
+
|
|
|
+ private String _searchfilter = "";
|
|
|
+
|
|
|
+ public ObservableCollection<Tuple<string, Guid, BitmapImage>> GroupList { get; private set; }
|
|
|
+
|
|
|
+ public bool IsReady { get; set; }
|
|
|
+
|
|
|
+ private String _customercode = "";
|
|
|
+ private List<Tuple<Guid, String, String>> _customers;
|
|
|
|
|
|
public EquipmentPanel()
|
|
|
{
|
|
|
+ GroupList = new ObservableCollection<Tuple<string, Guid, BitmapImage>>();
|
|
|
+
|
|
|
InitializeComponent();
|
|
|
}
|
|
|
+
|
|
|
+ public Type DataType()
|
|
|
+ {
|
|
|
+ return typeof(Equipment);
|
|
|
+ }
|
|
|
|
|
|
- public string CurrentGroup { get; set; }
|
|
|
- public ObservableCollection<Tuple<string, string, BitmapImage>> GroupList { get; private set; }
|
|
|
-
|
|
|
- public bool IsReady { get; set; }
|
|
|
|
|
|
public event DataModelUpdateEvent OnUpdateDataModel;
|
|
|
|
|
@@ -38,64 +67,46 @@ namespace PRSDesktop
|
|
|
|
|
|
public void Setup()
|
|
|
{
|
|
|
- _Equipment = new EquipmentGrid
|
|
|
- {
|
|
|
- HorizontalAlignment = HorizontalAlignment.Stretch,
|
|
|
- VerticalAlignment = VerticalAlignment.Stretch
|
|
|
- };
|
|
|
- _Equipment.HiddenColumns.Add(x => x.GroupLink.Code);
|
|
|
- _Equipment.SetValue(Grid.RowProperty, 0);
|
|
|
- _Equipment.SetValue(Grid.ColumnProperty, 1);
|
|
|
- _Equipment.OnFilterRecord += _Equipment_OnFilterRecord;
|
|
|
- Grid.Children.Add(_Equipment);
|
|
|
+
|
|
|
+ _Equipment.CustomerID = Guid.Empty;
|
|
|
+ _Equipment.GroupID = CoreUtils.FullGuid;
|
|
|
+
|
|
|
+ _settings = new GlobalConfiguration<EquipmentPanelSettings>().Load();
|
|
|
+ ReconfigurePanel();
|
|
|
+
|
|
|
_Equipment.Refresh(true, false);
|
|
|
-
|
|
|
- CurrentGroup = null;
|
|
|
- GroupList = new ObservableCollection<Tuple<string, string, BitmapImage>>();
|
|
|
- GroupList.Add(new Tuple<string, string, BitmapImage>("All Items", null, PRSDesktop.Resources.edit.AsBitmapImage()));
|
|
|
- var groups = new Client<EquipmentGroup>().Load(
|
|
|
+
|
|
|
+ GroupList.Add(new Tuple<string, Guid, BitmapImage>("All Items", CoreUtils.FullGuid, PRSDesktop.Resources.edit.AsBitmapImage()));
|
|
|
+ var groups = new Client<EquipmentGroup>().Query(
|
|
|
null,
|
|
|
+ new Columns<EquipmentGroup>(x=>x.ID)
|
|
|
+ .Add(x=>x.Description)
|
|
|
+ .Add(x=>x.Thumbnail.ID),
|
|
|
new SortOrder<EquipmentGroup>(x => x.Code)
|
|
|
);
|
|
|
-
|
|
|
- Filter<Document> imageFilter = null;
|
|
|
- if (groups.Length == 0)
|
|
|
- {
|
|
|
- imageFilter = new Filter<Document>().None();
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- foreach (var group in groups)
|
|
|
- if (group.Thumbnail.IsValid())
|
|
|
- {
|
|
|
- var newfilter = new Filter<Document>(x => x.ID).IsEqualTo(group.Thumbnail.ID);
|
|
|
- if (imageFilter == null)
|
|
|
- imageFilter = newfilter;
|
|
|
- else
|
|
|
- imageFilter.Ors.Add(newfilter);
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- var Images = new Client<Document>().Load(imageFilter);
|
|
|
-
|
|
|
- foreach (var group in groups)
|
|
|
+
|
|
|
+ var ids = groups.ExtractValues<EquipmentGroup, Guid>(c => c.Thumbnail.ID).Distinct().Where(x => x != Guid.Empty).ToArray();
|
|
|
+ var Images = ids.Any()
|
|
|
+ ? new Client<Document>().Load(new Filter<Document>(x=>x.ID).InList(ids))
|
|
|
+ : new Document[] { };
|
|
|
+
|
|
|
+ foreach (var row in groups.Rows)
|
|
|
{
|
|
|
- var image = Images.FirstOrDefault(x => x.ID.Equals(group.Thumbnail.ID));
|
|
|
- //byte[] data = image != null ? image.Data : null;
|
|
|
- BitmapImage img = null;
|
|
|
- if (image != null && image.Data != null && image.Data.Length > 0)
|
|
|
- {
|
|
|
- img = new BitmapImage();
|
|
|
- img.LoadImage(image.Data);
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- img = PRSDesktop.Resources.edit.AsBitmapImage();
|
|
|
- }
|
|
|
+ var image = Images.FirstOrDefault(x => x.ID.Equals(row.Get<EquipmentGroup,Guid>(c=>c.Thumbnail.ID)));
|
|
|
+ BitmapImage img = (image != null && image.Data != null && image.Data.Length > 0)
|
|
|
+ ? ImageUtils.LoadImage(image.Data)
|
|
|
+ : PRSDesktop.Resources.specifications.AsBitmapImage();
|
|
|
|
|
|
- GroupList.Add(new Tuple<string, string, BitmapImage>(group.Description, group.Code, img));
|
|
|
+ GroupList.Add(
|
|
|
+ new Tuple<string, Guid, BitmapImage>(
|
|
|
+ row.Get<EquipmentGroup,String>(c=>c.Description),
|
|
|
+ row.Get<EquipmentGroup,Guid>(c=>c.ID),
|
|
|
+ img
|
|
|
+ )
|
|
|
+ );
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
+ Groups.Visibility = groups.Rows.Any() ? Visibility.Visible : Visibility.Collapsed;
|
|
|
Groups.ItemsSource = GroupList;
|
|
|
Groups.SelectedIndex = 0;
|
|
|
}
|
|
@@ -106,6 +117,54 @@ namespace PRSDesktop
|
|
|
|
|
|
public void CreateToolbarButtons(IPanelHost host)
|
|
|
{
|
|
|
+ host.CreateSetupAction(new PanelAction() { Caption = "Equipment Settings", Image = PRSDesktop.Resources.specifications, OnExecute = EquipmentSettingsClick });
|
|
|
+ }
|
|
|
+
|
|
|
+ private void EquipmentSettingsClick(PanelAction obj)
|
|
|
+ {
|
|
|
+ var pages = new DynamicEditorPages();
|
|
|
+ var buttons = new DynamicEditorButtons();
|
|
|
+ buttons.Add(
|
|
|
+ "",
|
|
|
+ PRSDesktop.Resources.help.AsBitmapImage(),
|
|
|
+ _settings,
|
|
|
+ (f, i) =>
|
|
|
+ {
|
|
|
+ Process.Start(new ProcessStartInfo("https://prsdigital.com.au/wiki/index.php/" + typeof(Equipment).Name.SplitCamelCase().Replace(" ", "_"))
|
|
|
+ { UseShellExecute = true });
|
|
|
+ }
|
|
|
+ );
|
|
|
+ var propertyEditor = new DynamicEditorForm(typeof(EquipmentPanelSettings), pages, buttons);
|
|
|
+
|
|
|
+ propertyEditor.Items = new BaseObject[] { _settings };
|
|
|
+
|
|
|
+ if (propertyEditor.ShowDialog() == true)
|
|
|
+ {
|
|
|
+ new GlobalConfiguration<EquipmentPanelSettings>().Save(_settings);
|
|
|
+ ReconfigurePanel();
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ private void ReconfigurePanel()
|
|
|
+ {
|
|
|
+ CustomerLabel.Visibility = _settings.CustomerFilterEnabled ? Visibility.Visible : Visibility.Collapsed;
|
|
|
+ Customer.Visibility = _settings.CustomerFilterEnabled ? Visibility.Visible : Visibility.Collapsed;
|
|
|
+ CustomerSearch.Visibility = _settings.CustomerFilterEnabled ? Visibility.Visible : Visibility.Collapsed;
|
|
|
+ CustomerName.Visibility = _settings.CustomerFilterEnabled ? Visibility.Visible : Visibility.Collapsed;
|
|
|
+
|
|
|
+ if (!_settings.CustomerFilterEnabled)
|
|
|
+ {
|
|
|
+ _Equipment.CustomerID = CoreUtils.FullGuid;
|
|
|
+ _customercode = "";
|
|
|
+ Customer.Text = "";
|
|
|
+ CustomerName.Text = "";
|
|
|
+ }
|
|
|
+ else if (_Equipment.CustomerID == CoreUtils.FullGuid)
|
|
|
+ _Equipment.CustomerID = Guid.Empty;
|
|
|
+
|
|
|
+ if (IsReady)
|
|
|
+ _Equipment.Refresh(false,true);
|
|
|
}
|
|
|
|
|
|
|
|
@@ -125,38 +184,135 @@ namespace PRSDesktop
|
|
|
public void Heartbeat(TimeSpan time)
|
|
|
{
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
+
|
|
|
private bool _Equipment_OnFilterRecord(CoreRow row)
|
|
|
{
|
|
|
- if (CurrentGroup == null)
|
|
|
- return true;
|
|
|
+ if (!String.IsNullOrWhiteSpace(_searchfilter))
|
|
|
+ {
|
|
|
+ for (int i=0; i<row.Table.Columns.Count; i++)
|
|
|
+ {
|
|
|
+ if ((row.Table.Columns[i].DataType == typeof(String)))
|
|
|
+ {
|
|
|
+ string value = row.Values[i] as string;
|
|
|
+ if (!String.IsNullOrEmpty(value) && value.ToUpper().Contains(_searchfilter.ToUpper()))
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
+ return true;
|
|
|
|
|
|
- object group = row.Get<Equipment, string>(x => x.GroupLink.Code);
|
|
|
- if (group == null)
|
|
|
- group = "";
|
|
|
- return CurrentGroup.Equals(group);
|
|
|
}
|
|
|
|
|
|
private void Groups_SelectionChanged(object sender, SelectionChangedEventArgs e)
|
|
|
{
|
|
|
- var sCur = CurrentGroup;
|
|
|
+ var sCur = _Equipment.GroupID;
|
|
|
if (e.AddedItems.Count == 0 || Groups.SelectedIndex == 0)
|
|
|
{
|
|
|
- CurrentGroup = null;
|
|
|
+ _Equipment.GroupID = CoreUtils.FullGuid;
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
- var selected = (Tuple<string, string, BitmapImage>)e.AddedItems[0];
|
|
|
- CurrentGroup = selected.Item2;
|
|
|
+ var selected = (Tuple<string, Guid, BitmapImage>)e.AddedItems[0];
|
|
|
+ _Equipment.GroupID = selected.Item2;
|
|
|
}
|
|
|
|
|
|
- if (sCur != CurrentGroup)
|
|
|
+ if (sCur != _Equipment.GroupID)
|
|
|
_Equipment.Refresh(false, true);
|
|
|
}
|
|
|
+
|
|
|
+ private void Search_OnTextChanged(object sender, TextChangedEventArgs e)
|
|
|
+ {
|
|
|
+ if (String.IsNullOrEmpty(Search.Text) && !String.Equals(Search.Text, _searchfilter))
|
|
|
+ {
|
|
|
+ _searchfilter = "";
|
|
|
+ _Equipment.Refresh(false, false);
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
- public Type DataType()
|
|
|
+ private void Search_OnKeyUp(object sender, KeyEventArgs e)
|
|
|
{
|
|
|
- return typeof(Equipment);
|
|
|
+ if (new Key[] { Key.Enter, Key.Return }.Contains(e.Key) && !String.Equals(Search.Text, _searchfilter))
|
|
|
+ {
|
|
|
+ _searchfilter = Search.Text;
|
|
|
+ _Equipment.Refresh(false, false);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private void CheckCustomerCache()
|
|
|
+ {
|
|
|
+ if (_customers == null)
|
|
|
+ {
|
|
|
+ _customers = new Client<Customer>().Query(
|
|
|
+ null,
|
|
|
+ new Columns<Customer>(x => x.ID).Add(x => x.Code).Add(x => x.Name),
|
|
|
+ new SortOrder<Customer>(x => x.Name)
|
|
|
+ ).ToTuples<Customer,Guid,String,String>(x =>x.ID,x=>x.Code,x=>x.Name).ToList();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private void DoSearchCustomers()
|
|
|
+ {
|
|
|
+ var dlg = new MultiSelectDialog<Customer>(null, new Columns<Customer>(x => x.ID).Add(x => x.Code).Add(x => x.Name), false);
|
|
|
+ if (dlg.ShowDialog("Code",Customer.Text))
|
|
|
+ {
|
|
|
+ var customer = dlg.Items().First();
|
|
|
+ _customercode = customer.Code;
|
|
|
+ Customer.Text = customer.Code;
|
|
|
+ CustomerName.Text = customer.Name;
|
|
|
+ _Equipment.CustomerID = customer.ID;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ _customercode = "";
|
|
|
+ Customer.Text = "";
|
|
|
+ CustomerName.Text = "";
|
|
|
+ _Equipment.CustomerID = Guid.Empty;
|
|
|
+ }
|
|
|
+
|
|
|
+ _Equipment.Refresh(false, true);
|
|
|
+ }
|
|
|
+
|
|
|
+ private void CustomerSearch_OnClick(object sender, RoutedEventArgs e)
|
|
|
+ {
|
|
|
+ DoSearchCustomers();
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ private void Customer_OnKeyUp(object sender, KeyEventArgs e)
|
|
|
+ {
|
|
|
+ if (new Key[] { Key.Enter, Key.Return }.Contains(e.Key))
|
|
|
+ {
|
|
|
+
|
|
|
+ if (!String.Equals(Customer.Text, _customercode))
|
|
|
+ {
|
|
|
+ CheckCustomerCache();
|
|
|
+ var lookup = _customers.FirstOrDefault(x => String.Equals(x.Item2, Customer.Text));
|
|
|
+ if (lookup != null)
|
|
|
+ {
|
|
|
+ _customercode = lookup.Item2;
|
|
|
+ CustomerName.Text = lookup.Item3;
|
|
|
+ _Equipment.CustomerID = lookup.Item1;
|
|
|
+ _Equipment.Refresh(false, true);
|
|
|
+ }
|
|
|
+ else
|
|
|
+ DoSearchCustomers();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private void Customer_OnTextChanged(object sender, TextChangedEventArgs e)
|
|
|
+ {
|
|
|
+ if (String.IsNullOrEmpty(Customer.Text) && !String.Equals(Customer.Text, _customercode))
|
|
|
+ {
|
|
|
+ _Equipment.CustomerID = Guid.Empty;
|
|
|
+ _customercode = "";
|
|
|
+ CustomerName.Text = "";
|
|
|
+ _Equipment.Refresh(false, true);
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
}
|