QuoteProposalDetails.xaml.cs 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Windows.Controls;
  5. using Comal.Classes;
  6. using InABox.Clients;
  7. using InABox.Core;
  8. using InABox.DynamicGrid;
  9. using RichTextEditor = InABox.Core.RichTextEditor;
  10. namespace PRSDesktop
  11. {
  12. /// <summary>
  13. /// Interaction logic for QuoteProposalSummary.xaml
  14. /// </summary>
  15. public partial class QuoteProposalDetails : UserControl
  16. {
  17. private QuoteProposal _proposal;
  18. private Guid _proposalid;
  19. private Guid _quoteid;
  20. public QuoteProposalDetails()
  21. {
  22. InitializeComponent();
  23. }
  24. public Guid QuoteID
  25. {
  26. get => CostSheets.QuoteID;
  27. set => CostSheets.QuoteID = value;
  28. }
  29. public Guid ProposalID
  30. {
  31. get => _proposalid;
  32. set
  33. {
  34. _proposalid = value;
  35. Refresh(false, true);
  36. }
  37. }
  38. public void Refresh(bool columns, bool data)
  39. {
  40. if (columns)
  41. {
  42. Preamble.EditorDefinition = new RichTextEditor();
  43. Preamble.ColumnName = "Preamble";
  44. Preamble.Configure();
  45. Preamble.OnEditorValueChanged += Preamble_OnEditorValueChanged;
  46. Preamble.Loaded = true;
  47. Summary.EditorDefinition = new RichTextEditor();
  48. Summary.ColumnName = "Summary";
  49. Summary.Configure();
  50. Summary.OnEditorValueChanged += Summary_OnEditorValueChanged;
  51. Summary.Loaded = true;
  52. ExTax.EditorDefinition = new DoubleEditor();
  53. ExTax.ColumnName = "ExTax";
  54. ExTax.Configure();
  55. ExTax.OnEditorValueChanged += ExTax_OnEditorValueChanged;
  56. ExTax.Loaded = true;
  57. ExTax.EditorDefinition = new DoubleEditor();
  58. ExTax.ColumnName = "Tax";
  59. ExTax.Configure();
  60. ExTax.Loaded = true;
  61. IncTax.EditorDefinition = new DoubleEditor();
  62. IncTax.ColumnName = "IncTax";
  63. IncTax.Configure();
  64. IncTax.OnEditorValueChanged += IncTax_OnEditorValueChanged;
  65. IncTax.Loaded = true;
  66. CostSheets.Refresh(true, false);
  67. }
  68. if (data)
  69. {
  70. new Client<QuoteProposal>().Query(
  71. new Filter<QuoteProposal>(x => x.ID).IsEqualTo(_proposalid),
  72. new Columns<QuoteProposal>(x => x.ID, x => x.Preamble, x => x.Summary, x => x.ExTax, x => x.TaxCode.ID, x => x.IncTax),
  73. null,
  74. (table, error) =>
  75. {
  76. _proposal = table != null && table.Rows.Any() ? table.Rows.First().ToObject<QuoteProposal>() : null;
  77. Dispatcher.Invoke(() =>
  78. {
  79. Preamble.Value = _proposal != null ? _proposal.Preamble : "";
  80. ExTax.Value = _proposal != null ? _proposal.ExTax : 0.0F;
  81. TaxCode.Value = _proposal != null ? _proposal.TaxCode.ID : Guid.Empty;
  82. IncTax.Value = _proposal != null ? _proposal.IncTax : 0.0F;
  83. Summary.Value = _proposal != null ? _proposal.Summary : "";
  84. });
  85. }
  86. );
  87. CostSheets.ProposalID = _proposalid;
  88. }
  89. }
  90. private void Preamble_OnEditorValueChanged(IDynamicEditorControl sender, Dictionary<string, object> values)
  91. {
  92. if (_proposal != null && _proposal.Preamble != Preamble.Value)
  93. {
  94. _proposal.Preamble = Preamble.Value;
  95. new Client<QuoteProposal>().Save(_proposal, "", (p, e) => { });
  96. }
  97. }
  98. private void ExTax_OnEditorValueChanged(IDynamicEditorControl sender, Dictionary<string, object> values)
  99. {
  100. }
  101. private void IncTax_OnEditorValueChanged(IDynamicEditorControl sender, Dictionary<string, object> values)
  102. {
  103. }
  104. private void Summary_OnEditorValueChanged(IDynamicEditorControl sender, Dictionary<string, object> values)
  105. {
  106. if (_proposal != null && _proposal.Summary != Summary.Value)
  107. {
  108. _proposal.Summary = Summary.Value;
  109. new Client<QuoteProposal>().Save(_proposal, "", (p, e) => { });
  110. }
  111. }
  112. }
  113. }