EpiCurrencyConvert and calculated field customization

Hi,
I’m trying to add 5 customized fields to QuoteHed and bind to EpiCurrencyConver control.
I created 5 UD fields for each 1 customized field because 5 fields are needed to one EpiCurrencyConver.
Example: Equipment1_c, DocEQuipment1_c, Rpt1Equipment1_c, Rpt2Equipment1_c, Rpt3Equipment_3.

I also want to do a simple math calculation DocTargetPriceTotal=DocEquipment1 + DocEquipment2 + DocEquipment3 + DocEquipment4.

I tried to use EpiViewNotificaon and AfterFieldChange, however, it does not turn out the results I wanted.

Here’s my codes in Script Editor, could any guide me?

Summary

// **************************************************
// Custom code for QuoteForm
// Created:
// **************************************************

extern alias Erp_Contracts_BO_QuoteDtlSearch;
extern alias Erp_Contracts_BO_Quote;
extern alias Erp_Contracts_BO_Customer;
extern alias Erp_Contracts_BO_AlternatePart;
extern alias Erp_Contracts_BO_Part;
extern alias Erp_Contracts_BO_Vendor;
extern alias Erp_Contracts_BO_VendorPPSearch;
extern alias Erp_Contracts_BO_ShipTo;

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;
using Ice.BO;

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 edvQuoteHed;
private EpiCurrencyConver DocEquipment1;
private EpiCurrencyConver DocEquipment2;
private EpiCurrencyConver DocEquipment3;
private EpiCurrencyConver DocEquipment4;
private EpiCurrencyConver DocTargetPriceTotal;

// 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.DocEquipment1=(EpiCurrencyConver)csm.GetNativeControlReference("09db2557-a67f-427e-b261-7e75aa86bcb2");
	this.DocEquipment2=(EpiCurrencyConver)csm.GetNativeControlReference("7339e514-5aad-4371-95ff-8a1ec15f8906");
	this.DocEquipment3=(EpiCurrencyConver)csm.GetNativeControlReference("119a0283-0c90-4d32-8b5d-e3d4262da649");
	this.DocEquipment1=(EpiCurrencyConver)csm.GetNativeControlReference("db4028a0-9fcc-44f4-9044-e890f677bcee");
	this.DocTargetPriceTotal=(EpiCurrencyConver)csm.GetNativeControlReference("76e54963-335f-424a-a19f-56dc34b4c949");
	
	DocEquipment1.EpiBindingDocument="QuoteHed.Doc Equipment1_c";
	DocEquipment2.EpiBindingDocument="QuoteHed.Doc Equipment2_c ";	
	DocEquipment3.EpiBindingDocument="QuoteHed.Doc Equipment3_c ";	
	DocEquipment4.EpiBindingDocument=" QuoteHed.Doc Equipment4_c ";	
	DocTargetPriceTotal.EpiBindingDocument="QuoteHed.DocTargetPriceTotal_c";	

	this.edvQuoteHed = ((EpiDataView)(this.oTrans.EpiDataViews["QuoteHed"]));
	this.edvQuoteHed.EpiViewNotification += new EpiViewNotification(this.edvQuoteHed_EpiViewNotification);
	this.QuoteHed_Column.ColumnChanged += new DataColumnChangeEventHandler(this.QuoteHed_AfterFieldChange);
	// 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.edvQuoteHed.EpiViewNotification -= new EpiViewNotification(this.edvQuoteHed_EpiViewNotification);
	this.edvQuoteHed = null;


	this.QuoteHed_Column.ColumnChanged -= new DataColumnChangeEventHandler(this.QuoteHed_AfterFieldChange);
	// End Wizard Added Object Disposal

	// Begin Custom Code Disposal

	// End Custom Code Disposal
}






private void edvQuoteHed_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))
	{
		if ((args.Row > -1))
		{

EpiDataView edvQuoteHed=(EpiDataView)oTrans.EpiDataViews[“QuoteHed”];

edvQuoteHed.dataView[edvQuoteHed.Row].BeginEdit();

decimal DocEuipment1=Convert.ToDecimal(edvQuoteHed.dataView[edvQuoteHed.Row][" DocEuipment1_c"]);
decimal DocEuipment2=Convert.ToDecimal(edvQuoteHed.dataView[edvQuoteHed.Row][" DocEuipment2_c"]);
decimal DocEuipment3=Convert.ToDecimal(edvQuoteHed.dataView[edvQuoteHed.Row][" DocEuipment3_c"]);
decimal DocEuipment4=Convert.ToDecimal(edvQuoteHed.dataView[edvQuoteHed.Row][" DocEuipment4_c"]);
decimal DocTargetPriceTotal= DocEuipment1+ DocEuipment2+ DocEuipment3+ DocEuipment4;

edvQuoteHed.dataView[edvQuoteHed.Row]["DocTargetPriceTotal_c"]=DocTargetPriceTotal;


				
edvQuoteHed.dataView[edvQuoteHed.Row][" Euipment1_c"]=Math.Truncate(DocEuipment1*Convert.ToDecimal(edvQuoteHed.dataView[edvQuoteHed.Row]["ExchangeRate"]));
edvQuoteHed.dataView[edvQuoteHed.Row][" Euipment2_c "]=Math.Truncate(DocEuipment2*Convert.ToDecimal(edvQuoteHed.dataView[edvQuoteHed.Row]["ExchangeRate"]));
edvQuoteHed.dataView[edvQuoteHed.Row][" Euipment3_c"]=Math.Truncate(DocEuipment3*Convert.ToDecimal(edvQuoteHed.dataView[edvQuoteHed.Row]["ExchangeRate"]));
edvQuoteHed.dataView[edvQuoteHed.Row][" Euipment4_c"]=Math.Truncate(DocEuipment4*Convert.ToDecimal(edvQuoteHed.dataView[edvQuoteHed.Row]["ExchangeRate"]));
				edvQuoteHed.dataView[edvQuoteHed.Row]["DocTargetPriceTotal_c"]=Math.Truncate(DocTargetPriceTotal*Convert.ToDecimal(edvQuoteHed.dataView[edvQuoteHed.Row]["ExchangeRate"]));

edvQuoteHed.dataView[edvQuoteHed.Row].EndEdit();

		}
	}
}







private void QuoteHed_AfterFieldChange(object sender, DataColumnChangeEventArgs args)
{
	// ** Argument Properties and Uses **
	// args.Row["FieldName"]
	// args.Column, args.ProposedValue, args.Row
	// Add Event Handler Code
				
				EpiDataView edvQuoteHed=(EpiDataView)oTrans.EpiDataViews["QuoteHed"];

				decimal DocVendorAncillaries=Convert.ToDecimal(edvQuoteHed.dataView[edvQuoteHed.Row]["DocVendorAncillaries_c"]);
				decimal DocValueAddedAncillaries=Convert.ToDecimal(edvQuoteHed.dataView[edvQuoteHed.Row]["DocValueAddedAncillaries_c"]);
				decimal DocSolexAncillaries=Convert.ToDecimal(edvQuoteHed.dataView[edvQuoteHed.Row]["DocSolexAncillaries_c"]);
				decimal DocHeatExchanger=Convert.ToDecimal(edvQuoteHed.dataView[edvQuoteHed.Row]["DocHeatExchanger_c"]);
				decimal DocTargetPriceTotal=DocVendorAncillaries+DocValueAddedAncillaries+DocSolexAncillaries+DocHeatExchanger;


	switch (args.Column.ColumnName)
	{


		

		case "DocTargetPriceTotal_c":

		EpiDataView edvQuoteHed=(EpiDataView)oTrans.EpiDataViews["QuoteHed"];

		decimal DocEquipment1=Convert.ToDecimal(edvQuoteHed.dataView[edvQuoteHed.Row][" DocEquipment1_c"]);
		decimal DocEquipment2=Convert.ToDecimal(edvQuoteHed.dataView[edvQuoteHed.Row][" DocEquipment2_c"]);
		decimal DocEquipment3=Convert.ToDecimal(edvQuoteHed.dataView[edvQuoteHed.Row][" DocEquipment3_c"]);
		decimal DocEquipment4=Convert.ToDecimal(edvQuoteHed.dataView[edvQuoteHed.Row][" DocEquipment4_c"]);
		decimal DocTargetPriceTotal= DocEquipment1+ DocEquipment2+ DocEquipment3+ DocEquipment4;



				
		edvQuoteHed.dataView[edvQuoteHed.Row].BeginEdit();
		edvQuoteHed.dataView[edvQuoteHed.Row]["DocTargetPriceTotal_c"]=DocTargetPriceTotal;
		edvQuoteHed.dataView[edvQuoteHed.Row].EndEdit();

				
				edvQuoteHed.dataView[edvQuoteHed.Row]["Equipment1_c"]=Math.Truncate(DocEquipment1*Convert.ToDecimal(edvQuoteHed.dataView[edvQuoteHed.Row]["ExchangeRate"]));
				edvQuoteHed.dataView[edvQuoteHed.Row][" Equipment2_c"]=Math.Truncate(DocEquipment2*Convert.ToDecimal(edvQuoteHed.dataView[edvQuoteHed.Row]["ExchangeRate"]));
				edvQuoteHed.dataView[edvQuoteHed.Row][" Equipment3_c"]=Math.Truncate(DocEquipment3*Convert.ToDecimal(edvQuoteHed.dataView[edvQuoteHed.Row]["ExchangeRate"]));
				edvQuoteHed.dataView[edvQuoteHed.Row][" Equipment4_c"]=Math.Truncate(DocEquipment4*Convert.ToDecimal(edvQuoteHed.dataView[edvQuoteHed.Row]["ExchangeRate"]));
				edvQuoteHed.dataView[edvQuoteHed.Row]["DocTargetPriceTotal_c"]=Math.Truncate(DocTargetPriceTotal*Convert.ToDecimal(edvQuoteHed.dataView[edvQuoteHed.Row]["ExchangeRate"]));

			break;






	}
}

}

I usually start out with a couple simple things
Adding messageboxes to show when your code is executed and if your variables are actually being populated?
I might place the custom update code within a try/catch too?