Best way to calculate a value for display on Part Entry and Part Tracker

I have two UD fields that define temperature limits in deg F, and are entered in Part Entry in deg F. I also want the values to show in degC. I had created a TextChanged event that puts the calculated value in the appropriate text field, but since the degC field isn’t actually saved in the database it displays as zero the next time the form is loaded in part entry or in part tracker. I tried other form events to do the same, but none seemed to do anything. Can anyone point me to the correct even to use for something like this? It doesn’t seem like it should be necessary to store the converted value in another field in the database.

image

try an EpiViewNotification instead of text change. use initialize to get when it loads. I think you might have to do another command to catch the change. but try it and see, it may work for a change too.

I must be doing something wrong here. I added an EpiViewNotification through the form event wizard to a PartTracker customization, but it doesn’t appear to be firing. I added Message Boxes to test but nothing happens after loading a part or multiple parts into the form.

public void InitializeCustomCode()
{
	// ** Wizard Insert Location - Do not delete 'Begin/End Wizard Added Variable Initialization' lines **
	// Begin Wizard Added Variable Initialization

	this.edvPart = ((EpiDataView)(this.oTrans.EpiDataViews["Part"]));
	this.edvPart.EpiViewNotification += new EpiViewNotification(this.edvPart_EpiViewNotification);
	// End Wizard Added Variable Initialization

	// Begin Wizard Added Custom Method Calls

	// End Wizard Added Custom Method Calls
}

private void edvPart_EpiViewNotification(EpiDataView view, EpiNotifyArgs args)
{
	// ** Argument Properties and Uses **
	// view.dataView[args.Row]["FieldName"]
	// args.Row, args.Column, args.Sender, args.NotifyType
	// NotifyType.Initialize, NotifyType.AddRow, NotifyType.DeleteRow, NotifyType.InitLastView, NotifyType.InitAndResetTreeNodes
	if ((args.NotifyType == EpiTransaction.NotifyType.AddRow))
	{ MessageBox.Show("View addrow");
		if ((args.Row > -1))
		{ MessageBox.Show("View args > -1");
		}
	}
}

you need to change this

if ((args.NotifyType == EpiTransaction.NotifyType.AddRow))

to

if ((args.NotifyType == EpiTransaction.NotifyType.Initialize))

Add row will only fire if you add a new row to the dataset.

1 Like

That worked to get it firing. Now it shows both Message Boxes and then throws an error. This is without any custom code inside of the if ((args.Row > -1)){} statement

Application Error

Exception caught in: >App.PartTracker.PartTrackerForm.EP.QTRCO.Customization.PartTrackerQ.CustomCode.1

Error Detail

Message: Specified cast is not valid.
Program: App.PartTracker.PartTrackerForm.EP.QTRCO.Customization.PartTrackerQ.CustomCode.1.dll
Method: edvPart_EpiViewNotification

Client Stack Trace

at Script.edvPart_EpiViewNotification(EpiDataView view, EpiNotifyArgs args)
at Ice.Lib.Framework.EpiViewNotification.Invoke(EpiDataView view, EpiNotifyArgs args)
at Ice.Lib.Framework.EpiDataView.OnEpiViewNotification(EpiNotifyArgs e)
at Ice.Lib.Framework.EpiDataView.Notify(EpiNotifyArgs args)
at Erp.UI.App.PartTracker.Transaction.GetByID(String partNum)

image

I take that back. I had used a block comment inside the if ((args.Row > -1)){} to comment out the code, but the block comment was ignored. The EpiDataViewNotification is working without error, just have to adjust a data type somewhere in the custom code. Thanks.

1 Like

Almost there. The conversion fires and fills the new fields, but the fields to be converted are always treated as zero (see below, -20F should convert to -29C, 0F is -18C). Is there a way to have the EpiViewNotification fire later after the data is read?

image

is this just when you open up the screen? Or after you are inputting the data? What you mean my “read”?

It might be helpful at this point to post what you have so far.

I think he means when data is fetched from the DB. Like after entering an order number, and all the order lines are “read” into the dataview

Calvin is correct. When I open part tracker I expect the fields to have zero value, but when I search for and select a part all of the data loads which populates those fields. My code is still treating the fields as though they have zero value, however. Below is the full code:

// **************************************************
// Custom code for PartTrackerForm
// Created: 08-Feb-2019 15:16:11
// **************************************************

extern alias Erp_Contracts_BO_NonConf;
extern alias Erp_Contracts_BO_SerialNo;

using System;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Windows.Forms;
using Erp.Adapters;
using Erp.UI;
using Ice.Lib;
using Ice.Adapters;
using Ice.Lib.Customization;
using Ice.Lib.ExtendedProps;
using Ice.Lib.Framework;
using Ice.Lib.Searches;
using Ice.UI.FormFunctions;

public class Script
{
	// ** Wizard Insert Location - Do Not Remove 'Begin/End Wizard Added Module Level Variables' Comments! **
	// Begin Wizard Added Module Level Variables **

	private EpiDataView edvPart;
	// End Wizard Added Module Level Variables **

	// Add Custom Module Level Variables Here **

	public void InitializeCustomCode()
	{
		// ** Wizard Insert Location - Do not delete 'Begin/End Wizard Added Variable Initialization' lines **
		// Begin Wizard Added Variable Initialization

		this.edvPart = ((EpiDataView)(this.oTrans.EpiDataViews["Part"]));
		this.edvPart.EpiViewNotification += new EpiViewNotification(this.edvPart_EpiViewNotification);
		// End Wizard Added Variable Initialization

		// Begin Wizard Added Custom Method Calls

		// End Wizard Added Custom Method Calls
	}

	public void DestroyCustomCode()
	{
		// ** Wizard Insert Location - Do not delete 'Begin/End Wizard Added Object Disposal' lines **
		// Begin Wizard Added Object Disposal

		this.edvPart.EpiViewNotification -= new EpiViewNotification(this.edvPart_EpiViewNotification);
		this.edvPart = null;
		// End Wizard Added Object Disposal

		// Begin Custom Code Disposal

		// End Custom Code Disposal
	}

	private void edvPart_EpiViewNotification(EpiDataView view, EpiNotifyArgs args)
	{
		// ** Argument Properties and Uses **
		// view.dataView[args.Row]["FieldName"]
		// args.Row, args.Column, args.Sender, args.NotifyType
		// NotifyType.Initialize, NotifyType.AddRow, NotifyType.DeleteRow, NotifyType.InitLastView, NotifyType.InitAndResetTreeNodes
		if ((args.NotifyType == EpiTransaction.NotifyType.Initialize))
		{ MessageBox.Show("View addrow");
			if ((args.Row > -1))
			{ 
				if (MaxTf.Text != ""){
					MessageBox.Show(Convert.ToString(MaxTc.Value));
					MaxTc.Value = (int)(Math.Round((Convert.ToDouble(MaxTf.Value) - 32) * 5 / 9));
					MessageBox.Show(Convert.ToString(MaxTc.Value));
				}
	
				if (MinTf.Text != ""){
					MessageBox.Show(Convert.ToString(MinTc.Value));
					MinTc.Value = (int)(Math.Round((Convert.ToDouble(MinTf.Value) - 32) * 5 / 9));
					MessageBox.Show(Convert.ToString(MinTc.Value));
				}
	
				if (MAWPp.Text != ""){
					MessageBox.Show(Convert.ToString(MAWPb.Value));
					double MAWPpTemp = Convert.ToDouble(MAWPp.Value);
					double MAWPbTemp = Math.Abs(0.06894757 * MAWPpTemp);
			        if(MAWPbTemp < 10){
			                  MAWPb.Value = (int)Math.Round(MAWPbTemp, 2);
			        }else if(MAWPbTemp < 100){
			                	MAWPb.Value = Math.Round(MAWPbTemp, 1);
			        }else if(MAWPbTemp >= 100){
			                	MAWPb.Value = Math.Round(MAWPbTemp, 0);
						}
			 	} MessageBox.Show(Convert.ToString(MAWPb.Value));
			}
		}
	}

}

Is the MessageBox.Show("View addrow"); call happening?

Also, the numeric value text boxes aren’t nullable (I don’t think) so your test for !="" may not be a valid test.

1 Like

And why test them at all. Worst case, you’re actually “correcting” an incorrect value in one of the metric controls.

All of the message boxes are firing, it just isn’t pulling the correct value from the MAWPp, MinTf, and MaxTf fields.

The test for null was for when I was evaluating at a text changed event, deleting the value would throw an error before the box reset itself to the default zero. You’re probably right that I don’t need those checks with this method.

so the fields are wrong even in the message boxes right?

Correct, the message boxes also just showed 0 (or values converted from 0). I replaced my field.value statements with epiDataView statements and everything started working. Not sure why exactly, but referencing the current value of a form field doesn’t work as I think it should. I suppose calling the epiDataView is likely a better practice anyway.

image

Here’s the cleaned up and working code FFR:

private void edvPart_EpiViewNotification(EpiDataView view, EpiNotifyArgs args)
	{
		// ** Argument Properties and Uses **
		// view.dataView[args.Row]["FieldName"]
		// args.Row, args.Column, args.Sender, args.NotifyType
		// NotifyType.Initialize, NotifyType.AddRow, NotifyType.DeleteRow, NotifyType.InitLastView, NotifyType.InitAndResetTreeNodes
		if ((args.NotifyType == EpiTransaction.NotifyType.Initialize))
		{
			if ((args.Row > -1))
			{ 
					int tMaxTF = Convert.ToInt32(edvPart.dataView[edvPart.Row]["TagMaxT_c"]);
					int tMinTF = Convert.ToInt32(edvPart.dataView[edvPart.Row]["TagMinT_c"]);
					int tMAWPp = Convert.ToInt32(edvPart.dataView[edvPart.Row]["TagMAWP_c"]);
					MaxTc.Value = (int)(Math.Round((double)((tMaxTF - 32) * 5 / 9)));
					MinTc.Value = (int)(Math.Round((double)((tMinTF - 32) * 5 / 9)));
					double tMAWPb = Math.Abs(0.06894757 * tMAWPp);
			        if(tMAWPb < 10){
			                  MAWPb.Value = Math.Round(tMAWPb, 2);
			        }else if(tMAWPb < 100){
			                	MAWPb.Value = Math.Round(tMAWPb, 1);
			        }else if(tMAWPb >= 100){
			                	MAWPb.Value = Math.Round(tMAWPb, 0);
						}
			}
		}
	}
3 Likes

My wild ass guess is, the data view is updating, then it’s triggering your event, then it’s updating the UI. So you were probably getting in the middle of it. Glad you figured it out!