Wannabe-coder, lost in views and Scripting syntax, looking for help with correct code for AfterFieldChange
This customization adds a few columns from a BAQ to the Standard Data view for Sales Order > Build Order from history. I am now trying to add a new input field (NumPacks) such that they can change that value, and it will do the math and fill in the standard Epicor Value (NewQty). I started by adding a field to my BAQ that returns a Zero, and making it ReadOnly False, seems fine.
My goal, is that IF someone changes that field, it will do the math multiplying NumPacks * Part_Number05 and replace the proposed value for NewQty.
At the very bottom of the script below you will see my ham-handed attempt to stuff an integer into NewQty, so Iâm clearly out of my depth. Can anyone provide the code to replace that line commented with âI WANT TO SETâŚâ
// **************************************************
// Custom code for OrderHistoryForm
// Created: 11/19/2019 2:00:26 PM
// **************************************************
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 System.Linq;
public class Script
{
// ** Wizard Insert Location - Do Not Remove âBegin/End Wizard Added Module Level Variablesâ Comments! **
// Begin Wizard Added Module Level Variables **
// End Wizard Added Module Level Variables **
// Add Custom Module Level Variables Here **
DataTable searchDt; //Holds my search paramters (order numb, customer num)
EpiDataView edvSearch; //EpiDataView for the above table.
BAQDataView bdvSalesHistory; //BAQDAtaView for pulling in the history records
private OrderHistAdapter oTrans_adapter;
private EpiUltraGrid orderHistGrid;
public void InitializeCustomCode()
{
// ** Wizard Insert Location - Do not delete 'Begin/End Wizard Added Variable Initialization' lines **
// Begin Wizard Added Variable Initialization
this.OrderHist_Column.ColumnChanged += new DataColumnChangeEventHandler(this.OrderHist_AfterFieldChange);
// End Wizard Added Variable Initialization
// Begin Wizard Added Custom Method Calls
// End Wizard Added Custom Method Calls
this.oTrans_adapter = ((OrderHistAdapter)(this.csm.TransAdaptersHT["oTrans_adapter"]));
CreateSearchDataView();
orderHistGrid = csm.GetNativeControlReference("7908565c-cc3c-43d1-b85b-9921ad88fb89") as EpiUltraGrid;
orderHistGrid.InitializeRow += new Infragistics.Win.UltraWinGrid.InitializeRowEventHandler(this.orderHist_InitializedRow);
SetExtendedProperties();
}
public void DestroyCustomCode()
{
// ** Wizard Insert Location - Do not delete 'Begin/End Wizard Added Object Disposal' lines **
// Begin Wizard Added Object Disposal
this.OrderHist_Column.ColumnChanged -= new DataColumnChangeEventHandler(this.OrderHist_AfterFieldChange);
// End Wizard Added Object Disposal
// Begin Custom Code Disposal
// End Custom Code Disposal
orderHistGrid.InitializeRow -= new Infragistics.Win.UltraWinGrid.InitializeRowEventHandler(this.orderHist_InitializedRow);
}
private void CreateSearchDataView()
{
searchDt = new DataTable();
searchDt.Columns.Add(new DataColumn("OrderNum", typeof(int)));
searchDt.Columns.Add(new DataColumn("CustNum", typeof(int)));
searchDt.Columns.Add(new DataColumn("SysRowID", typeof(Guid)){DefaultValue = Guid.NewGuid()});
searchDt.TableName="SearchDv";
//Add any new columns in the BAQ here
oTrans_adapter.OrderHistData.OrderHist.Columns.Add(new DataColumn("OrderDtl_XPartNum",typeof(String)));
oTrans_adapter.OrderHistData.OrderHist.Columns.Add(new DataColumn("Part_Number05",typeof(decimal)));
oTrans_adapter.OrderHistData.OrderHist.Columns.Add(new DataColumn("Part_ShortChar01",typeof(String)));
oTrans_adapter.OrderHistData.OrderHist.Columns.Add(new DataColumn("Part_Number03",typeof(decimal)));
oTrans_adapter.OrderHistData.OrderHist.Columns.Add(new DataColumn("Part_PartOnHold",typeof(bool)));
oTrans_adapter.OrderHistData.OrderHist.Columns.Add(new DataColumn("Part_ShortChar03",typeof(String))); //Rick add 25-Nov-2019
oTrans_adapter.OrderHistData.OrderHist.Columns.Add(new DataColumn("Part_Number01",typeof(decimal))); //Rick add 25-Nov-2019
oTrans_adapter.OrderHistData.OrderHist.Columns.Add(new DataColumn("Part_Number02",typeof(decimal))); //Rick add 25-Nov-2019
oTrans_adapter.OrderHistData.OrderHist.Columns.Add(new DataColumn("NumPacks",typeof(int))); //Rick add 29-Sept-2020
//Getting a hold of launch form options to extract customer number and order number
var lfo = OrderHistoryForm.LaunchFormOptions;
CompoundKeyBinding ckb = lfo.ValueIn as CompoundKeyBinding;
int orderNum=0;
int custNum =0;
if (ckb != null)
{
var iEnum = ckb.CompoundKeys.GetEnumerator();
custNum = int.Parse(ckb.CompoundKeys[0]);
orderNum = int.Parse(ckb.CompoundKeys[1]);
var row = searchDt.NewRow();
row["OrderNum"]=orderNum;
row["CustNum"]=custNum;
searchDt.Rows.Add(row);
}
edvSearch = new EpiDataView();
edvSearch.dataView = searchDt.DefaultView;
oTrans.Add("SearchDv",edvSearch);
//BAQ DataView being added to the current form for BAQID: BuildOrderFromHistory
bdvSalesHistory = new BAQDataView("BuildOrderFromHistory");
oTrans.Add("CustomerHistory", bdvSalesHistory);
var customerNumBinding = "SearchDv.CustNum";
oTrans.PublishColumnChange(customerNumBinding, Guid.NewGuid().ToString());
var customerNumPub = oTrans.GetPublisher(customerNumBinding);
bdvSalesHistory.SubscribeToPublisher(customerNumPub.PublishName, "OrderDtl_CustNum");
customerNumPub.PublishInitialValue(custNum.ToString(),true);
}
private void orderHist_InitializedRow(object sender, Infragistics.Win.UltraWinGrid.InitializeRowEventArgs args)
{
var row = bdvSalesHistory.dataView.Table.Select(string.Format("OrderDtl_OrderNum = {0} and OrderDtl_OrderLine = {1}",args.Row.Cells["OrderNum"].Value,args.Row.Cells["OrderLine"].Value)).FirstOrDefault();
if(row!=null)
{
//Add any new columns in the BAQ here
//Left Side is my custom column = Right Side is BAQ Column Name
args.Row.Cells["OrderDtl_XPartNum"].Value = row["OrderDtl_XPartNum"];
args.Row.Cells["Part_Number05"].Value = row["Part_Number05"];
args.Row.Cells["Part_ShortChar01"].Value = row["Part_ShortChar01"];
args.Row.Cells["Part_Number03"].Value = row["Part_Number03"];
args.Row.Cells["Part_PartOnHold"].Value = row["Part_OnHold"];
args.Row.Cells["Part_ShortChar03"].Value = row["Part_ShortChar03"]; //Rick add 25-Nov-2019
args.Row.Cells["Part_Number01"].Value = row["Part_Number01"]; //Rick add 25-Nov-2019
args.Row.Cells["Part_Number02"].Value = row["Part_Number02"]; //Rick add 25-Nov-2019
args.Row.Cells["NumPacks"].Value = row["# of Packs"]; //Rick add 29-Sept-2020
}
}
private void SetExtendedProperties()
{
// Begin Wizard Added EpiDataView Initialization
EpiDataView edvorderHist = ((EpiDataView)(this.oTrans.EpiDataViews["orderHist"]));
// End Wizard Added EpiDataView Initialization
// Begin Wizard Added Conditional Block
if (edvorderHist.dataView.Table.Columns.Contains("Part_Number03"))
{
// Begin Wizard Added ExtendedProperty Settings: edvorderHist-Part_Number03
//Add any new columns in the BAQ here
edvorderHist.dataView.Table.Columns["Part_Number03"].ExtendedProperties["ReadOnly"] = true;
edvorderHist.dataView.Table.Columns["Part_Number05"].ExtendedProperties["ReadOnly"] = true;
edvorderHist.dataView.Table.Columns["Part_ShortChar01"].ExtendedProperties["ReadOnly"] = true;
edvorderHist.dataView.Table.Columns["Part_PartOnHold"].ExtendedProperties["ReadOnly"] = true;
edvorderHist.dataView.Table.Columns["OrderDtl_XPartNum"].ExtendedProperties["ReadOnly"] = true;
edvorderHist.dataView.Table.Columns["Part_ShortChar03"].ExtendedProperties["ReadOnly"] = true; //Rick add 25-Nov-2019
edvorderHist.dataView.Table.Columns["Part_Number01"].ExtendedProperties["ReadOnly"] = true; //Rick add 25-Nov-2019
edvorderHist.dataView.Table.Columns["Part_Number02"].ExtendedProperties["ReadOnly"] = true; //Rick add 25-Nov-2019
edvorderHist.dataView.Table.Columns["NumPacks"].ExtendedProperties["ReadOnly"] = false; //Rick add 29-Sept-2020
// End Wizard Added ExtendedProperty Settings: edvorderHist-Part_Number03
}
// End Wizard Added Conditional Block
}
private void OrderHist_AfterFieldChange(object sender, DataColumnChangeEventArgs args)//Rick add 29-Sept-2020
{
// ** Argument Properties and Uses **
// args.Row["FieldName"]
// args.Column, args.ProposedValue, args.Row
// Add Event Handler Code
switch (args.Column.ColumnName)
{
case "NumPacks":
// args.ProposedValue.NewQty = 789; - //I WANT TO SET 'NewQty' which is a native field in Epicor, to 'NumPacks * Part_Number05'
break;
}
}
}