123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151 |
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Linq;
- using System.Windows;
- using System.Windows.Controls;
- using System.Windows.Threading;
- using Comal.Classes;
- using InABox.Clients;
- using InABox.Configuration;
- using InABox.Core;
- using InABox.DynamicGrid;
- namespace PRSDesktop
- {
-
- public class CustomerPanelSettings : IUserConfigurationSettings
- {
- public CustomerPanelSettings()
- {
- AnchorWidth = 500F;
- View = DynamicSplitPanelView.Combined;
- }
-
- public DynamicSplitPanelView View { get; set; }
- public double AnchorWidth { get; set; }
- }
-
- public partial class CustomerPanel : UserControl, IPanel<Customer>
- {
-
- private CustomerPanelSettings settings;
- private Customer _customer;
- private enum PageIndex
- {
- Contacts,
- Spreadsheets
- }
- public CustomerPanel()
- {
- InitializeComponent();
- }
- public bool IsReady { get; set; }
- public event DataModelUpdateEvent? OnUpdateDataModel;
- public Dictionary<string, object[]> Selected()
- {
- return new Dictionary<string, object[]> { { typeof(Customer).EntityName(), Customers.SelectedRows } };
- }
- public void Setup()
- {
- settings = new UserConfiguration<CustomerPanelSettings>().Load();
- SplitPanel.View = settings.View;
- SplitPanel.AnchorWidth = settings.AnchorWidth;
- Customers.ColumnsTag = settings.View == DynamicSplitPanelView.Master ? settings.View.ToString() : "";
- Customers.Refresh(true, false);
- CustomerContacts.Refresh(true, false);
- CustomerSpreadsheets.Refresh(true,false);
- CustomerActivities.Refresh(true,false);
- CustomerProducts.Refresh(true,false);
- }
- public void Shutdown(CancelEventArgs? cancel)
- {
- }
- public void CreateToolbarButtons(IPanelHost host)
- {
- AccountsSetupActions.Standard(host);
- host.CreateSetupSeparator();
- AccountsSetupActions.CustomerSpreadsheetTemplates(host);
- //host.CreateToolbarButton(new PanelAction() { Caption = "Select Columns", OnExecute = DoSelectColumns, Image = PRSDesktop.Resources.shared });
- }
- public void Refresh()
- {
- Customers.Refresh(true, true);
- }
- public string SectionName => "Customers";
- public DataModel DataModel(Selection selection)
- {
- var ids = Customers.ExtractValues(x => x.ID, selection).ToArray();
- return new BaseDataModel<Customer>(new Filter<Customer>(x => x.ID).InList(ids));
- }
- public void Heartbeat(TimeSpan time)
- {
- }
- public Type DataType()
- {
- return typeof(Customer);
- }
-
- private void RefreshSubPage(ICustomerGrid grid)
- {
- if (grid == null)
- return;
- Logger.Send(LogType.Information, ClientFactory.UserID, string.Format("CustomerPanel: RefreshSubPage({0})", grid.GetType().EntityName()));
- grid.Customer = _customer;
-
- var timer = new DispatcherTimer { Interval = TimeSpan.FromMilliseconds(100) };
- timer.Tick += (o, e) =>
- {
- timer.Stop();
- grid.Refresh(!grid.IsReady, true);
- };
- timer.Start();
- }
-
- private void SplitPanel_OnChanged(object sender, DynamicSplitPanelSettings e)
- {
- settings.View = SplitPanel.View;
- settings.AnchorWidth = SplitPanel.AnchorWidth;
-
- new UserConfiguration<CustomerPanelSettings>().Save(settings);
- var newTag = settings.View == DynamicSplitPanelView.Master ? settings.View.ToString() : "";
- if (Customers.ColumnsTag != newTag)
- {
- Customers.ColumnsTag = newTag;
- Customers.Refresh(true, true);
- }
- }
-
- private void CustomerDetails_SelectionChanged(object sender, SelectionChangedEventArgs e)
- {
- if (e.AddedItems.Count > 0)
- {
- var t = e.AddedItems[0] as TabItem;
- if (t != null && t.Visibility == Visibility.Visible)
- RefreshSubPage(t.Content as ICustomerGrid);
- }
- }
-
- private void Customers_OnOnSelectItem(object sender, DynamicGridSelectionEventArgs e)
- {
- var row = e.Rows?.FirstOrDefault();
- _customer = row?.ToObject<Customer>() ?? new Customer();
- Dispatcher.Invoke(() => { RefreshSubPage(CustomerDetails.SelectedContent as ICustomerGrid); });
- }
- }
- }
|