Altering a Built In Epicor Text Box Value on Field Change


I’m working on setting up a customization that basically executes an external BAQ what a Quantity is reported.

The goal is look at the quantity reported, and if that quantity is higher than the count that the BAQ returns, it should display a message box, and then clear the Current/Total values.

Here is a bit of the code:

 private void ReportQty_AfterFieldChange(object sender, DataColumnChangeEventArgs args)
 		// ** Argument Properties and Uses **
 		// args.Row["FieldName"]
 		// args.Column, args.ProposedValue, args.Row
 		// Add Event Handler Code
 				Control txtResc = csm.GetNativeControlReference("fcda044e-f261-47b3-be39-49e88db77b2e");
 				Control nbrCurrent = csm.GetNativeControlReference("94e152f3-dbc7-4180-a2c5-ea03f8d12aa2");
 				Control nbrTotal = csm.GetNativeControlReference("c87c566a-db0d-4fe1-aa8d-0947764f2eb5");
 				string currentQty = nbrCurrent.Text;
 				if (currentQty != "0.00000000")
 				string RescID = txtResc.Text;				
 				DynamicQueryAdapter dqa = new DynamicQueryAdapter(oTrans);
 				QueryExecutionDataSet qeds = dqa.GetQueryExecutionParametersByID("SHRINK1COUNT");
 				qeds.ExecutionParameter.AddExecutionParameterRow("MchParam", RescID, "nvarchar", false, Guid.NewGuid(),"A");
 				tbMDCQty.Text = dqa.QueryResults.Tables[0].Rows[0][0].ToString();
 				string MDCrtn = tbMDCQty.Text;
 				decimal mQty = decimal.Parse(MDCrtn);
 				decimal cQty = decimal.Parse(currentQty);
 			if (cQty  mQty)
 int cQty2 = decimal.ToInt32(cQty);
 MessageBox.Show(String.Format("You reported a quantity of {0}, which is higher than the database returned {1}",cQty2,mQty));
 nbrCurrent.Text = "0.00000000";
 nbrTotal.Text = "0.00000000";
 tbMDCQty.Text = "";

(That is not all of the code, but the portion I’m working with.)

It seems if I run this bit on an EpiButton click it clears:

nbrCurrent.Text = “0.00000000”;
nbrTotal.Text = “0.00000000”;

I also noticed that it seems to run twice, once it updates the Current it displays the messagebox, as well is when it updates the Total.

Are there any suggestions as to what I may be doing wrong to have the value changed back to 0 after the MessageBox?

Are your number boxes text? or Numeric editors? I think (and I could be wrong, I am not real experienced in coding) that you will need nbrCurrent.Text to be nbrCurrent.Value , because a text editor doesn’t use text.

Also does this part need a comparator?

if (cQty  mQty)

It looks the Current uses a Value, so I’ll have to see how to reference it as a NumericEditor.

Yes, the comparator was “>”

Must not have shown when pasting the code!

Also, is there are reason you converting the current value to a string? I would think you would want to keep those decimals.

string currentQty = nbrCurrent.Text;

It was picked up from some code I messed with months back when I was initially looking at referencing native controls in e10.

Trying to use this:

Control nbrCurrent = (EpiNumericEditor)csm.GetNativeControlReference(“94e152f3-dbc7-4180-a2c5-ea03f8d12aa2”);

Ends up with this:

(335) - ‘System.Windows.Forms.Control’ does not contain a definition for ‘Value’ and no extension method ‘Value’ accepting a first argument of type ‘System.Windows.Forms.Control’ could be found (are you missing a using directive or an assembly reference?)

So the field type you can find when you click on the control and look in the properties, it should tell you what type of editor it is, that should tell you what you need to put into your control to get a hold of it. See what those boxes are there, and you’ll know how to set them up.

Also I’m just wondering if the use of the generic “Control” is messing you up. Generally I set up the variable first.

EpiNumericEditor YourNameHere;

Then link the control like this

YourNameHere = (EpiNumericEditor)csm.GetNativeControlReference("GUID");

So if you keep with that convention, replace “control” with “EpiNumericEditor”, it would make more sense to me.

EpiNumericEditor nbrCurrent = (EpiNumericEditor)csm.GetNativeControlReference(“94e152f3-dbc7-4180-a2c5-ea03f8d12aa2”);

Like I said before though, I’m fairly inexperienced, so if anyone in here reading this wants to correct me, please do!

I’m planning to clean it all up once I get it working, but I’m already referencing theIce.Lib.Framework


As well as using this:

With the same error as above

If that was the case your error shouldn’t say “control” it should say EpiNumericEditor. You must have something duplicated.

(335) - ‘System.Windows.Forms.Control’

I think that was it! All is working now, minus the duplicate text box!

I think I need to spend some time cleaning up this code before I go any further.



1 Like