|
@@ -12,10 +12,10 @@ namespace PRSDesktop
|
|
|
/// <summary>
|
|
|
/// Interaction logic for QuoteDetails.xaml
|
|
|
/// </summary>
|
|
|
- public partial class QuoteDetails : UserControl, IPanel<Quote>, IQuotePage
|
|
|
+ public partial class QuoteDetails : UserControl, IPanel<Quote>, IQuotePage, IDynamicEditorHost
|
|
|
{
|
|
|
- private CoreTable Data;
|
|
|
-
|
|
|
+ private CoreRow[] _rows;
|
|
|
+
|
|
|
public QuoteDetails()
|
|
|
{
|
|
|
InitializeComponent();
|
|
@@ -69,8 +69,7 @@ namespace PRSDesktop
|
|
|
|
|
|
public Dictionary<string, object[]> Selected()
|
|
|
{
|
|
|
- var rows = Data != null ? Data.Rows.ToArray() : new CoreRow[] { };
|
|
|
- return new Dictionary<string, object[]> { { typeof(Quote).EntityName(), rows } };
|
|
|
+ return new Dictionary<String, object[]>() { { typeof(Quote).EntityName(), _rows } };
|
|
|
}
|
|
|
|
|
|
public void Setup()
|
|
@@ -99,6 +98,7 @@ namespace PRSDesktop
|
|
|
Customer.OtherColumns["Account.ID"] = "Account.ID";
|
|
|
Customer.OtherColumns["Account.Code"] = "Account.Code";
|
|
|
Customer.OtherColumns["Account.Name"] = "Account.Name";
|
|
|
+ Customer.Host = this;
|
|
|
Customer.Configure();
|
|
|
Customer.OnEditorValueChanged += Customer_OnEditorValueChanged;
|
|
|
Customer.Loaded = true;
|
|
@@ -108,6 +108,7 @@ namespace PRSDesktop
|
|
|
Account.CodeColumn = "Code";
|
|
|
Account.OtherColumns["Code"] = "Account.Code";
|
|
|
Account.OtherColumns["Name"] = "Account.Name";
|
|
|
+ Account.Host = this;
|
|
|
Account.Configure();
|
|
|
Account.OnEditorValueChanged += Account_OnEditorValueChanged;
|
|
|
Account.Loaded = true;
|
|
@@ -126,28 +127,24 @@ namespace PRSDesktop
|
|
|
|
|
|
private void UpdateScreen(CoreTable o, Exception e)
|
|
|
{
|
|
|
- Data = o;
|
|
|
+ _rows = o?.Rows.ToArray() ?? new CoreRow[] { };
|
|
|
Dispatcher.Invoke(() =>
|
|
|
{
|
|
|
var bIsReady = IsReady;
|
|
|
IsReady = false;
|
|
|
|
|
|
- Title.Value = o != null && o.Rows.Any() ? o.Rows.First().Get<Quote, string>(col => col.Title) : "";
|
|
|
- Customer.Value = o != null && o.Rows.Any() ? o.Rows.First().Get<Quote, Guid>(col => col.Customer.ID) : Guid.Empty;
|
|
|
- //CustomerCode.Text = (o != null) && o.Rows.Any() ? o.Rows.First().Get<Quote, String>(col => col.Customer.Code) : "";
|
|
|
- //CustomerName.Text = (o != null) && o.Rows.Any() ? o.Rows.First().Get<Quote, String>(col => col.Customer.Name) : "";
|
|
|
- Address.Text = o != null && o.Rows.Any() ? o.Rows.First().Get<Quote, string>(col => col.SiteAddress.Street) : "";
|
|
|
- City.Text = o != null && o.Rows.Any() ? o.Rows.First().Get<Quote, string>(col => col.SiteAddress.City) : "";
|
|
|
- State.Text = o != null && o.Rows.Any() ? o.Rows.First().Get<Quote, string>(col => col.SiteAddress.State) : "";
|
|
|
- PostCode.Text = o != null && o.Rows.Any() ? o.Rows.First().Get<Quote, string>(col => col.SiteAddress.PostCode) : "";
|
|
|
- Account.Value = o != null && o.Rows.Any() ? o.Rows.First().Get<Quote, Guid>(col => col.Account.ID) : Guid.Empty;
|
|
|
- //AccountCode.Text = (o != null) && o.Rows.Any() ? o.Rows.First().Get<Quote, String>(col => col.Account.Code) : "";
|
|
|
- //AccountName.Text = (o != null) && o.Rows.Any() ? o.Rows.First().Get<Quote, String>(col => col.Account.Name) : "";
|
|
|
-
|
|
|
- var notes = o != null && o.Rows.Any() ? o.Rows.First().Get<Quote, string[]>(col => col.Notes) : null;
|
|
|
+ Title.Value = o?.Rows.FirstOrDefault()?.Get<Quote, string>(col => col.Title) ?? "";
|
|
|
+ Customer.Value = o?.Rows.FirstOrDefault()?.Get<Quote, Guid>(col => col.Customer.ID) ?? Guid.Empty;
|
|
|
+ Address.Text = o?.Rows.FirstOrDefault()?.Get<Quote, string>(col => col.SiteAddress.Street) ?? "";
|
|
|
+ City.Text = o?.Rows.FirstOrDefault()?.Get<Quote, string>(col => col.SiteAddress.City) ?? "";
|
|
|
+ State.Text = o?.Rows.FirstOrDefault()?.Get<Quote, string>(col => col.SiteAddress.State) ?? "";
|
|
|
+ PostCode.Text = o?.Rows.FirstOrDefault()?.Get<Quote, string>(col => col.SiteAddress.PostCode) ?? "";
|
|
|
+ Account.Value = o?.Rows.FirstOrDefault()?.Get<Quote, Guid>(col => col.Account.ID) ?? Guid.Empty;
|
|
|
+
|
|
|
+ var notes = o?.Rows.FirstOrDefault()?.Get<Quote, string[]>(col => col.Notes) ?? null;
|
|
|
Notes.Text = notes != null ? string.Join("\n\n", notes).Replace("\r\n\r\n", "\r\n").Replace("\n\n", "\n") : "";
|
|
|
|
|
|
- Status.SelectedValue = o != null && o.Rows.Any() ? o.Rows.First().Get<Quote, Guid>(col => col.Status.ID) : Guid.Empty;
|
|
|
+ Status.SelectedValue = o?.Rows.FirstOrDefault()?.Get<Quote, Guid>(col => col.Status.ID) ?? Guid.Empty;
|
|
|
|
|
|
QuoteValue.Text = o != null && o.Rows.Any() ? string.Format("${0:F2}", o.Rows.First().Get<Quote, double>(col => col.ExTax)) : "";
|
|
|
|
|
@@ -160,7 +157,7 @@ namespace PRSDesktop
|
|
|
if (IsReady)
|
|
|
{
|
|
|
var quote = new Quote { ID = ParentID };
|
|
|
- quote.Number = Data != null && Data.Rows.Any() ? Data.Rows.First().Get<Quote, string>(col => col.Number) : "";
|
|
|
+ quote.Number = _rows?.FirstOrDefault()?.Get<Quote, string>(col => col.Number) ?? "";
|
|
|
quote.Title = Title.Value;
|
|
|
new Client<Quote>().Save(quote, "Updated Title", (j, err) => { });
|
|
|
}
|
|
@@ -172,7 +169,7 @@ namespace PRSDesktop
|
|
|
if (IsReady)
|
|
|
{
|
|
|
var quote = new Quote { ID = ParentID };
|
|
|
- quote.Number = Data != null && Data.Rows.Any() ? Data.Rows.First().Get<Quote, string>(col => col.Number) : "";
|
|
|
+ quote.Number = _rows.FirstOrDefault()?.Get<Quote, string>(col => col.Number) ?? "";
|
|
|
quote.Customer.ID = (Guid)values["Customer.ID"];
|
|
|
quote.Account.ID = (Guid)values["Account.ID"];
|
|
|
new Client<Quote>().Save(quote, "Updated Customer ID", (j, err) => { });
|
|
@@ -184,7 +181,7 @@ namespace PRSDesktop
|
|
|
if (IsReady)
|
|
|
{
|
|
|
var quote = new Quote { ID = ParentID };
|
|
|
- quote.Number = Data != null && Data.Rows.Any() ? Data.Rows.First().Get<Quote, string>(col => col.Number) : "";
|
|
|
+ quote.Number = _rows?.FirstOrDefault()?.Get<Quote, string>(col => col.Number) ?? "";
|
|
|
quote.Account.ID = (Guid)values["Account.ID"];
|
|
|
new Client<Quote>().Save(quote, "Updated Account ID", (j, err) => { });
|
|
|
}
|
|
@@ -195,10 +192,65 @@ namespace PRSDesktop
|
|
|
if (IsReady)
|
|
|
{
|
|
|
var quote = new Quote { ID = ParentID };
|
|
|
- quote.Number = Data != null && Data.Rows.Any() ? Data.Rows.First().Get<Quote, string>(col => col.Number) : "";
|
|
|
+ quote.Number = _rows?.FirstOrDefault()?.Get<Quote, string>(col => col.Number) ?? "";
|
|
|
quote.Status.ID = Status.SelectedValue != null ? (Guid)Status.SelectedValue : Guid.Empty;
|
|
|
new Client<Quote>().Save(quote, "Updated Quote Status", (j, err) => { });
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+ #region IDynamicEditorHost
|
|
|
+
|
|
|
+ public IEnumerable<DynamicGridColumn> Columns { get; } = InitialiseColumns();
|
|
|
+
|
|
|
+ private static DynamicGridColumns InitialiseColumns()
|
|
|
+ {
|
|
|
+ var columns = new DynamicGridColumns();
|
|
|
+ columns.ExtractColumns(typeof(Quote));
|
|
|
+ return columns;
|
|
|
+ }
|
|
|
+
|
|
|
+ public void LoadColumns(string column, Dictionary<string, string> columns)
|
|
|
+ {
|
|
|
+ columns.Clear();
|
|
|
+ var comps = column.Split('.').ToList();
|
|
|
+ comps.RemoveAt(comps.Count - 1);
|
|
|
+ var prefix = string.Format("{0}.", string.Join(".", comps));
|
|
|
+ var cols = Columns.Where(x => !x.ColumnName.Equals(column) && x.ColumnName.StartsWith(prefix));
|
|
|
+ foreach (var col in cols)
|
|
|
+ columns[col.ColumnName.Replace(prefix, "")] = col.ColumnName;
|
|
|
+ }
|
|
|
+
|
|
|
+ public IFilter? DefineFilter(Type type) => LookupFactory.DefineFilter<Quote>(new Quote[] { new Quote() }, type);
|
|
|
+
|
|
|
+ public void LoadLookups(ILookupEditorControl editor)
|
|
|
+ {
|
|
|
+ //if (editor == Activity) Activity_OnDefineLookups(editor);
|
|
|
+ //else if (editor == Kanban) Task_OnDefineLookups(editor);
|
|
|
+ //else if (editor == ITP) ITP_OnDefineLookups(editor);
|
|
|
+ }
|
|
|
+
|
|
|
+ public Document? FindDocument(string filename)
|
|
|
+ {
|
|
|
+ return new Client<Document>().Load(new Filter<Document>(x => x.FileName).IsEqualTo(filename)).FirstOrDefault();
|
|
|
+ }
|
|
|
+
|
|
|
+ public Document? GetDocument(Guid id)
|
|
|
+ {
|
|
|
+ Document? doc = null;
|
|
|
+ if (id != Guid.Empty)
|
|
|
+ doc = new Client<Document>().Load(new Filter<Document>(x => x.ID).IsEqualTo(id)).FirstOrDefault();
|
|
|
+ return doc;
|
|
|
+ }
|
|
|
+
|
|
|
+ public void SaveDocument(Document document)
|
|
|
+ {
|
|
|
+ new Client<Document>().Save(document, "");
|
|
|
+ }
|
|
|
+
|
|
|
+ object?[] IDynamicEditorHost.GetItems() => new object?[] { new Quote() };
|
|
|
+
|
|
|
+ public BaseEditor? GetEditor(DynamicGridColumn column) => column.Editor.CloneEditor();
|
|
|
+
|
|
|
+ #endregion
|
|
|
}
|
|
|
}
|