| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301 |
- 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
- {
- /// <summary>
- /// Interaction logic for JobPanel.xaml
- /// </summary>
- public partial class QuotePanel : UserControl, IPanel<Quote>
- {
- private int CurrentPage = -1;
- private DateTime lastselection = DateTime.MaxValue;
- private IDataModelSource modelsource;
- private QuoteContracts QuoteContracts;
- private QuoteCostSheets QuoteCostSheets;
- private QuoteDesigns QuoteDesigns;
- //ComboBox QuoteStatus = null;
- //Quotes Quotes = null;
- //TabControl QuotePages = null;
- private QuoteDetails QuoteDetails;
- private QuoteDiagrams QuoteDiagrams;
- private QuoteDocuments QuoteDocuments;
- private QuoteProposals QuoteProposals;
- private QuoteTakeoffs QuoteTakeoffs;
- private QuoteScreenSettings settings;
- private readonly DispatcherTimer timer = new();
- public QuotePanel()
- {
- InitializeComponent();
- Quotes.OnDoubleClick += OpenQuote;
- }
- public bool IsReady { get; set; }
- public event DataModelUpdateEvent OnUpdateDataModel;
- public Dictionary<string, object[]> Selected()
- {
- var result = new Dictionary<string, object[]> { { typeof(Job).EntityName(), Quotes.SelectedRows } };
- if (QuotePages.SelectedIndex == (int)PageIndex.Details)
- return QuoteDetails.Selected();
- if (QuotePages.SelectedIndex == (int)PageIndex.Documents)
- result[typeof(QuoteDocument).EntityName()] = QuoteDocuments.SelectedRows;
- else if (QuotePages.SelectedIndex == (int)PageIndex.Diagrams)
- return QuoteDiagrams.Selected();
- else if (QuotePages.SelectedIndex == (int)PageIndex.Takeoffs)
- result[typeof(QuoteTakeoff).EntityName()] = QuoteTakeoffs.SelectedRows;
- else if (QuotePages.SelectedIndex == (int)PageIndex.Designs)
- return QuoteDesigns.Selected();
- else if (QuotePages.SelectedIndex == (int)PageIndex.CostSheets)
- return QuoteCostSheets.Selected();
- else if (QuotePages.SelectedIndex == (int)PageIndex.Proposals)
- return QuoteProposals.Selected();
- else if (QuotePages.SelectedIndex == (int)PageIndex.Contract)
- return QuoteContracts.Selected();
- return result;
- }
- public void Setup()
- {
- QuoteDiagramSymbolCache.Refresh();
- settings = new UserConfiguration<QuoteScreenSettings>().Load();
- SplitPanel.View = settings.ViewType == ScreenViewType.Register
- ? DynamicSplitPanelView.Master
- : settings.ViewType == ScreenViewType.Details
- ? DynamicSplitPanelView.Detail
- : DynamicSplitPanelView.Combined;
- SplitPanel.MasterWidth = settings.QuoteColumnWidth;
- Diagrams.Visibility = ClientFactory.IsSupported<QuoteDiagram>() ? Visibility.Visible : Visibility.Collapsed;
- var sc = new Dictionary<Guid, string> { { Guid.Empty, "All Quotes" } };
- var statuses = new Client<QuoteStatus>().Query();
- foreach (var row in statuses.Rows)
- sc[row.Get<QuoteStatus, Guid>(x => x.ID)] = row.Get<QuoteStatus, string>(x => x.Description);
- QuoteStatus.ItemsSource = sc;
- if (sc.ContainsKey(settings.QuoteStatus))
- QuoteStatus.SelectedValue = settings.QuoteStatus;
- else
- QuoteStatus.SelectedValue = sc.Keys.First();
- Quotes.OnSelectItem += Quotes_OnSelectItem;
- Quotes.ColumnsTag = settings.ViewType == ScreenViewType.Register ? settings.ViewType.ToString() : "";
- Quotes.Refresh(true, false);
- }
- public void Shutdown()
- {
- }
- public void Refresh()
- {
- if (!timer.IsEnabled)
- {
- timer.Interval = new TimeSpan(0, 0, 0, 0, 100);
- timer.Tick += Timer_Tick;
- timer.IsEnabled = true;
- }
- Quotes.Refresh(false, true);
- lastselection = DateTime.MinValue;
- }
- public void CreateToolbarButtons(IPanelHost host)
- {
- }
- public string SectionName => "Quotes";
- public DataModel DataModel(Selection selected)
- {
- //Guid[] ids = Quotes.ExtractValues<Guid>(x => x.ID, selected).ToArray();
- //return new QuoteDataModel(new Filter<Quote>(x => x.ID).InList(ids));
- if (modelsource == null)
- {
- var row = Quotes.SelectedRows.FirstOrDefault();
- var quoteid = row != null ? row.Get<Quote, Guid>(x => x.ID) : CoreUtils.FullGuid;
- return new QuoteDataModel(new Filter<Quote>(x => x.ID).IsEqualTo(quoteid));
- }
- return modelsource.DataModel(selected);
- }
- public void Heartbeat(TimeSpan time)
- {
- }
- private void OpenQuote(object sender, HandledEventArgs args)
- {
- if (SplitPanel.View != DynamicSplitPanelView.Detail)
- {
- SplitPanel.View = DynamicSplitPanelView.Detail;
- settings.ViewType = SplitPanel.View == DynamicSplitPanelView.Master
- ? ScreenViewType.Register
- : SplitPanel.View == DynamicSplitPanelView.Combined
- ? ScreenViewType.Combined
- : ScreenViewType.Details;
- new UserConfiguration<QuoteScreenSettings>().Save(settings);
- }
- args.Handled = true;
- }
- private void Timer_Tick(object sender, EventArgs e)
- {
- if (lastselection < DateTime.Now.AddMilliseconds(-500))
- {
- lastselection = DateTime.MaxValue;
- var row = Quotes.SelectedRows.FirstOrDefault();
- var quoteid = row != null ? row.Get<Quote, Guid>(x => x.ID) : CoreUtils.FullGuid;
- if (QuotePages.SelectedIndex == (int)PageIndex.Details)
- RefreshPanel(Details, ref QuoteDetails, quoteid, row != null);
- else if (QuotePages.SelectedIndex == (int)PageIndex.Documents)
- RefreshGrid(Documents, ref QuoteDocuments, quoteid, row != null);
- else if (QuotePages.SelectedIndex == (int)PageIndex.Diagrams)
- RefreshPanel(Diagrams, ref QuoteDiagrams, quoteid, row != null);
- else if (QuotePages.SelectedIndex == (int)PageIndex.Takeoffs)
- RefreshGrid(Takeoffs, ref QuoteTakeoffs, quoteid, row != null);
- else if (QuotePages.SelectedIndex == (int)PageIndex.Designs)
- RefreshPanel(Designs, ref QuoteDesigns, quoteid, row != null);
- else if (QuotePages.SelectedIndex == (int)PageIndex.CostSheets)
- RefreshPanel(CostSheets, ref QuoteCostSheets, quoteid, row != null);
- else if (QuotePages.SelectedIndex == (int)PageIndex.Proposals)
- RefreshPanel(Proposals, ref QuoteProposals, quoteid, row != null);
- else if (QuotePages.SelectedIndex == (int)PageIndex.Contract)
- RefreshPanel(Contract, ref QuoteContracts, quoteid, row != null);
- }
- }
- private void RefreshPanel<T>(TabItem container, ref T panel, Guid quoteid, bool data) where T : IBasePanel, IQuotePage, new()
- {
- if (panel == null)
- {
- panel = new T();
- panel.IsReady = false;
- panel.QuoteID = CoreUtils.FullGuid;
- panel.Setup();
- panel.IsReady = true;
- container.Content = panel;
- }
- if (QuotePages.SelectedIndex != CurrentPage)
- {
- modelsource = panel;
- OnUpdateDataModel?.Invoke(panel.SectionName, panel.DataModel(Selection.None));
- CurrentPage = QuotePages.SelectedIndex;
- }
- panel.QuoteID = quoteid;
- panel.Refresh();
- }
- private void RefreshGrid<T>(TabItem container, ref T grid, Guid quoteid, bool data)
- where T : IDynamicGrid, IQuotePage, IDataModelSource, new()
- {
- var bInitialised = false;
- if (grid == null)
- {
- grid = new T();
- container.Content = grid;
- }
- else
- {
- bInitialised = true;
- }
- if (QuotePages.SelectedIndex != CurrentPage)
- {
- modelsource = grid;
- OnUpdateDataModel?.Invoke(grid.SectionName, grid.DataModel(Selection.None));
- CurrentPage = QuotePages.SelectedIndex;
- }
- grid.QuoteID = quoteid;
- grid.Refresh(!bInitialised, data);
- }
- private void Quotes_OnSelectItem(object sender, DynamicGridSelectionEventArgs e)
- {
- if (SplitPanel.View != DynamicSplitPanelView.Master)
- lastselection = DateTime.Now;
- }
- public Dictionary<Type, CoreTable> DataEnvironment()
- {
- var env = new Dictionary<Type, CoreTable>();
- env[typeof(Job)] = Quotes.Data;
- return env;
- }
- private void QuotePages_SelectionChanged(object sender, SelectionChangedEventArgs e)
- {
- if (e.Source == QuotePages)
- lastselection = DateTime.MinValue;
- }
- private void QuoteStatus_SelectionChanged(object sender, SelectionChangedEventArgs e)
- {
- if (IsReady)
- {
- settings.QuoteStatus = (Guid)QuoteStatus.SelectedValue;
- new UserConfiguration<QuoteScreenSettings>().Save(settings);
- Quotes.StatusID = (Guid)QuoteStatus.SelectedValue;
- }
- }
- private void SplitPanel_OnChanged(object sender, DynamicSplitPanelChangedArgs e)
- {
- settings.ViewType = SplitPanel.View == DynamicSplitPanelView.Master ? ScreenViewType.Register :
- SplitPanel.View == DynamicSplitPanelView.Detail ? ScreenViewType.Details : ScreenViewType.Combined;
- settings.QuoteColumnWidth = SplitPanel.MasterWidth;
- var newTag = settings.ViewType == ScreenViewType.Register ? settings.ViewType.ToString() : "";
- if (Quotes.ColumnsTag != newTag)
- {
- Quotes.ColumnsTag = newTag;
- Quotes.Refresh(true, true);
- }
- new UserConfiguration<QuoteScreenSettings>().Save(settings);
- if (settings.ViewType == ScreenViewType.Details)
- lastselection = DateTime.Now;
- }
- private enum PageIndex
- {
- Details = 00,
- Documents,
- Diagrams,
- Takeoffs,
- Designs,
- CostSheets,
- Proposals,
- Contract
- }
- }
- }
|