Skip to content

Commit

Permalink
Preview of calculation added
Browse files Browse the repository at this point in the history
  • Loading branch information
rappen committed Dec 13, 2020
1 parent 6208f1f commit 54d0084
Show file tree
Hide file tree
Showing 3 changed files with 145 additions and 89 deletions.
66 changes: 37 additions & 29 deletions BulkDataUpdater/BDU.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

59 changes: 52 additions & 7 deletions BulkDataUpdater/BDU.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Drawing;
using System.Linq;
using System.Reflection;
using System.Windows.Forms;
Expand Down Expand Up @@ -169,12 +170,7 @@ private void GetFromEditor()

private void GetFromFXB()
{
var messageBusEventArgs = new MessageBusEventArgs("FetchXML Builder")
{
//SourcePlugin = "Bulk Data Updater"
};
messageBusEventArgs.TargetArgument = fetchXml;
OnOutgoingMessage(this, messageBusEventArgs);
OnOutgoingMessage(this, new MessageBusEventArgs("FetchXML Builder") { TargetArgument = fetchXml });
}

private void GetRecords(string tag)
Expand Down Expand Up @@ -679,6 +675,7 @@ private void cmbAttribute_SelectedIndexChanged(object sender, EventArgs e)
private void crmGridView1_SelectionChanged(object sender, EventArgs e)
{
UpdateIncludeCount();
PreviewCalc();
}

private void DataUpdater_ConnectionUpdated(object sender, ConnectionUpdatedEventArgs e)
Expand Down Expand Up @@ -892,6 +889,8 @@ private void btnCalcHelp_Click(object sender, EventArgs e)
Process.Start("https://jonasr.app/bdu/#calc");
}

#region Implementation of ILogger

public void EndSection()
{
LogInfo("<----");
Expand All @@ -912,6 +911,8 @@ public void StartSection(string name = null)
LogInfo($"----> {name}");
}

#endregion Implementation of ILogger

private void btnCalcPreview_Click(object sender, EventArgs e)
{
var record = crmGridView1.SelectedCellRecords.FirstOrDefault();
Expand All @@ -920,8 +921,52 @@ private void btnCalcPreview_Click(object sender, EventArgs e)
MessageBox.Show("Please select a record to the left to see preview of calculation.", "Calculation Preview", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
return;
}
var preview = record.Populate(bag, txtValueCalc.Text);
var preview = record.Substitute(bag, txtValueCalc.Text);
MessageBox.Show($"Preview of calculation:\n{preview}", "Calculation Preview", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
}

private void txtValueCalc_TextChanged(object sender, EventArgs e)
{
AwaitCalc();
EnableControls(true);
}

private void AwaitCalc()
{
txtCalcPreview.ForeColor = SystemColors.GrayText;
tmCalc.Stop();
tmCalc.Start();
}

private void PreviewCalc()
{
tmCalc.Enabled = false;
if (tabControl1.SelectedTab == tabUpdate &&
rbCalculate.Checked &&
bag?.Service != null &&
crmGridView1.SelectedCellRecords.FirstOrDefault() is Entity record)
{
try
{
var preview = record.Substitute(bag, txtValueCalc.Text, null, true);
preview = XrmSubstituter.InjectSequence(preview, crmGridView1.SelectedRows.Count);
txtCalcPreview.Text = preview;
}
catch (Exception ex)
{
txtCalcPreview.Text = $"Error: {ex.Message}";
}
txtCalcPreview.ForeColor = SystemColors.WindowText;
}
else if (!string.IsNullOrEmpty(txtCalcPreview.Text))
{
txtCalcPreview.Text = string.Empty;
}
}

private void tmCalc_Tick(object sender, EventArgs e)
{
PreviewCalc();
}
}
}
Loading

0 comments on commit 54d0084

Please sign in to comment.