123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166 |
- 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;
- using InABox.Wpf;
- namespace PRSDesktop;
- public class SupplierPanelSettings : IUserConfigurationSettings
- {
- public SupplierPanelSettings()
- {
- AnchorWidth = 800F;
- View = DynamicSplitPanelView.Combined;
- Anchor = DynamicSplitPanelAnchor.Detail;
- }
- public DynamicSplitPanelView View { get; set; }
- public DynamicSplitPanelAnchor Anchor { get; set; }
- public double AnchorWidth { get; set; }
- }
- /// <summary>
- /// Interaction logic for SupplierPanel.xaml
- /// </summary>
- public partial class SupplierPanel : UserControl, IPanel<Supplier>
- {
- private SupplierPanelSettings settings;
- private Supplier Supplier = new Supplier();
- public SupplierPanel()
- {
- InitializeComponent();
- Products.Visibility = Security.CanView<SupplierProduct>() ? Visibility.Visible : Visibility.Collapsed;
- if (Products.Visibility == Visibility.Visible)
- SupplierDetails.SelectedItem = Products;
- else
- SupplierDetails.SelectedItem = Contacts;
- }
- public event DataModelUpdateEvent? OnUpdateDataModel;
- public bool IsReady { get; set; }
- public void CreateToolbarButtons(IPanelHost host)
- {
- AccountsSetupActions.Standard(host);
-
- host.CreateSetupActionIfCanView<SupplierStatus>("Supplier Statuses", PRSDesktop.Resources.supplier,
- action =>
- {
- var list = new MasterList(typeof(SupplierStatus));
- list.ShowDialog();
- });
- host.CreateSetupActionIfCanView<SupplierCategory>("Supplier Categories", PRSDesktop.Resources.supplier, (action) =>
- {
- var list = new MasterList(typeof(SupplierCategory));
- list.ShowDialog();
- });
-
- host.CreateSetupSeparator();
- AccountsSetupActions.SupplierSpreadsheetTemplates(host);
- PostUtils.CreateToolbarButtons(
- host,
- () => (DataModel(Selection.Selected) as IDataModel<Supplier>)!,
- () => Suppliers.Refresh(false, true),
- true);
- }
- public string SectionName => "Suppliers";
- public DataModel DataModel(Selection selection)
- {
- var ids = Suppliers.ExtractValues(x => x.ID, selection).ToArray();
- return new BaseDataModel<Supplier>(new Filter<Supplier>(x => x.ID).InList(ids));
- }
- public void Heartbeat(TimeSpan time)
- {
- }
- public void Refresh()
- {
- Suppliers.Refresh(false, true);
- RefreshSubPage(SupplierDetails.SelectedContent as ISupplierGrid);
- }
- public Dictionary<string, object[]> Selected()
- {
- return new Dictionary<string, object[]> { { typeof(Supplier).EntityName(), Suppliers.SelectedRows } };
- }
- public void Setup()
- {
- settings = new UserConfiguration<SupplierPanelSettings>().Load();
- SplitPanel.View = settings.View;
- SplitPanel.Anchor = settings.Anchor;
- SplitPanel.AnchorWidth = settings.AnchorWidth;
- Suppliers.ColumnsTag = settings.View == DynamicSplitPanelView.Master ? settings.View.ToString() : "";
- Suppliers.Refresh(true, false);
- SupplierContacts.Refresh(true,false);
- SupplierProducts.Refresh(true,false);
- SupplierSpreadsheets.Refresh(true,false);
- }
- public void Shutdown(CancelEventArgs? cancel)
- {
- }
- private void RefreshSubPage(ISupplierGrid grid)
- {
- Logger.Send(LogType.Information, ClientFactory.UserID, string.Format("SupplierPanel: RefreshSubPage({0})", grid.GetType().EntityName()));
- if (grid == null)
- return;
- grid.Supplier = Supplier;
- 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<SupplierPanelSettings>().Save(settings);
- var newTag = settings.View == DynamicSplitPanelView.Master ? settings.View.ToString() : "";
- if (Suppliers.ColumnsTag != newTag)
- {
- Suppliers.ColumnsTag = newTag;
- Suppliers.Refresh(true, true);
- }
- }
- private void SupplierDetails_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 ISupplierGrid);
- }
- }
- private void Suppliers_OnSelectItem(object sender, DynamicGridSelectionEventArgs e)
- {
- var row = e.Rows?.FirstOrDefault();
- Supplier = row?.ToObject<Supplier>() ?? new Supplier();
- Dispatcher.Invoke(() => { RefreshSubPage(SupplierDetails.SelectedContent as ISupplierGrid); });
- }
- }
|