QuoteContracts.xaml.cs 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Linq;
  5. using System.Windows.Controls;
  6. using Comal.Classes;
  7. using InABox.Configuration;
  8. using InABox.Core;
  9. using InABox.DynamicGrid;
  10. using InABox.Wpf;
  11. namespace PRSDesktop
  12. {
  13. public class QuoteContractsSettings : BaseObject, IGlobalConfigurationSettings
  14. {
  15. public bool EnableCustomProposalValues { get; set; }
  16. }
  17. /// <summary>
  18. /// Interaction logic for QuoteContracts.xaml
  19. /// </summary>
  20. public partial class QuoteContracts : UserControl, IMasterDetailControl<Quote>, IPanel<Quote>
  21. {
  22. public Quote? Master
  23. {
  24. get => Contracts.Master;
  25. set => Contracts.Master = value;
  26. }
  27. private readonly QuoteContractsSettings _settings;
  28. public QuoteContracts()
  29. {
  30. InitializeComponent();
  31. _settings = new GlobalConfiguration<QuoteContractsSettings>().Load();
  32. }
  33. public bool IsReady { get; set; }
  34. public event DataModelUpdateEvent? OnUpdateDataModel;
  35. public void CreateToolbarButtons(IPanelHost host)
  36. {
  37. host.CreatePanelAction(new PanelAction("Create Job", PRSDesktop.Resources.tick, CreateJob));
  38. host.CreateSetupAction(new PanelAction()
  39. {
  40. Caption = "Contracts Settings",
  41. Image = PRSDesktop.Resources.specifications,
  42. OnExecute = action =>
  43. {
  44. var grid = new DynamicItemsListGrid<ProjectsSettings>();
  45. if (grid.EditItems(new QuoteContractsSettings[] { _settings }))
  46. {
  47. new GlobalConfiguration<QuoteContractsSettings>().Save(_settings);
  48. // reload grids?
  49. }
  50. }
  51. });
  52. }
  53. private void CreateJob(PanelAction action)
  54. {
  55. // Scan through
  56. }
  57. public string SectionName => "Quote Contracts";
  58. public DataModel DataModel(Selection selection)
  59. {
  60. var ids = Contracts.ExtractValues(x => x.ID, selection).ToArray();
  61. return new BaseDataModel<QuoteContract>(new Filter<QuoteContract>(x => x.ID).InList(ids));
  62. }
  63. public void Heartbeat(TimeSpan time)
  64. {
  65. }
  66. public void Refresh()
  67. {
  68. Contracts.Refresh(false, true);
  69. }
  70. public Dictionary<string, object[]> Selected()
  71. {
  72. return new Dictionary<string, object[]>();
  73. }
  74. public void Setup()
  75. {
  76. Contracts.Refresh(true, false);
  77. Proposals.Refresh(true, false);
  78. Contracts.OnSelectItem += Contracts_OnSelectItem;
  79. }
  80. public void Shutdown(CancelEventArgs? cancel)
  81. {
  82. }
  83. public Dictionary<Type, CoreTable> DataEnvironment()
  84. {
  85. return new Dictionary<Type, CoreTable>();
  86. }
  87. private void Contracts_OnSelectItem(object sender, DynamicGridSelectionEventArgs e)
  88. {
  89. var row = e.Rows?.FirstOrDefault();
  90. Proposals.Master = row?.ToObject<QuoteContract>() ;
  91. Proposals.Refresh(false,true);
  92. }
  93. }
  94. }