using System; using System.Collections.Generic; using System.Linq; using System.Windows.Controls; using Comal.Classes; using InABox.Clients; using InABox.Core; using InABox.DynamicGrid; using RichTextEditor = InABox.Core.RichTextEditor; namespace PRSDesktop { /// /// Interaction logic for QuoteProposalSummary.xaml /// public partial class QuoteProposalDetails : UserControl { private QuoteProposal _proposal; private Guid _proposalid; private Guid _quoteid; public QuoteProposalDetails() { InitializeComponent(); } public Guid QuoteID { get => CostSheets.QuoteID; set => CostSheets.QuoteID = value; } public Guid ProposalID { get => _proposalid; set { _proposalid = value; Refresh(false, true); } } public void Refresh(bool columns, bool data) { if (columns) { Preamble.EditorDefinition = new RichTextEditor(); Preamble.ColumnName = "Preamble"; Preamble.Configure(); Preamble.OnEditorValueChanged += Preamble_OnEditorValueChanged; Preamble.Loaded = true; Summary.EditorDefinition = new RichTextEditor(); Summary.ColumnName = "Summary"; Summary.Configure(); Summary.OnEditorValueChanged += Summary_OnEditorValueChanged; Summary.Loaded = true; ExTax.EditorDefinition = new DoubleEditor(); ExTax.ColumnName = "ExTax"; ExTax.Configure(); ExTax.OnEditorValueChanged += ExTax_OnEditorValueChanged; ExTax.Loaded = true; ExTax.EditorDefinition = new DoubleEditor(); ExTax.ColumnName = "Tax"; ExTax.Configure(); ExTax.Loaded = true; IncTax.EditorDefinition = new DoubleEditor(); IncTax.ColumnName = "IncTax"; IncTax.Configure(); IncTax.OnEditorValueChanged += IncTax_OnEditorValueChanged; IncTax.Loaded = true; CostSheets.Refresh(true, false); } if (data) { new Client().Query( new Filter(x => x.ID).IsEqualTo(_proposalid), new Columns(x => x.ID, x => x.Preamble, x => x.Summary, x => x.ExTax, x => x.TaxCode.ID, x => x.IncTax), null, (table, error) => { _proposal = table != null && table.Rows.Any() ? table.Rows.First().ToObject() : null; Dispatcher.Invoke(() => { Preamble.Value = _proposal != null ? _proposal.Preamble : ""; ExTax.Value = _proposal != null ? _proposal.ExTax : 0.0F; TaxCode.Value = _proposal != null ? _proposal.TaxCode.ID : Guid.Empty; IncTax.Value = _proposal != null ? _proposal.IncTax : 0.0F; Summary.Value = _proposal != null ? _proposal.Summary : ""; }); } ); CostSheets.ProposalID = _proposalid; } } private void Preamble_OnEditorValueChanged(IDynamicEditorControl sender, Dictionary values) { if (_proposal != null && _proposal.Preamble != Preamble.Value) { _proposal.Preamble = Preamble.Value; new Client().Save(_proposal, "", (p, e) => { }); } } private void ExTax_OnEditorValueChanged(IDynamicEditorControl sender, Dictionary values) { } private void IncTax_OnEditorValueChanged(IDynamicEditorControl sender, Dictionary values) { } private void Summary_OnEditorValueChanged(IDynamicEditorControl sender, Dictionary values) { if (_proposal != null && _proposal.Summary != Summary.Value) { _proposal.Summary = Summary.Value; new Client().Save(_proposal, "", (p, e) => { }); } } } }