I am still in need of help on this. From my research across the web, I think I am close in the CallPartBinSearchAdapterGetPartBinByLotMethod()
, but I don’t understand how to call my method.
In the code below, I began adding Form Events and just inserting a MessageBox per method and running back through the Customer Shipment form to see when each event’s method would be called.
Here are the steps I took:
- Create New Pack
- Enter Order Number
- Select Lines tab
- Select Actions>Mass Shipment (only one line to ship)
- The form populates with the part number from the SO, and it’s at this point that I want to understand and build from.
The goal is to grab the populated part number and use that in the PartBin search to find OnHandQty. The only method that fired at this point was the EpiViewNotification, although it fired numerous times throughout the process, so I’m still trying to learn about this.
I guess my main question at this point is, what form event (if any) should I use to trigger my method once the ShipDtl.PartNum field populates but before any other data changes?
// **************************************************
// Custom code for CustShipForm
// Created: 2/27/2024 12:31:08 PM
// **************************************************
extern alias Erp_Contracts_BO_CustShip;
extern alias Erp_Contracts_BO_PackOutSearch;
extern alias Erp_Contracts_BO_PickedOrders;
extern alias Erp_Contracts_BO_MaterialQueue;
extern alias Erp_Contracts_BO_Company;
extern alias Erp_Contracts_BO_Warehse;
extern alias Erp_Contracts_BO_Part;
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 EpiBaseAdapter oTrans_partBinSearchAdapter;
private EpiDataView edvShipDtl;
// 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.ShipDtl_Column.ColumnChanged += new DataColumnChangeEventHandler(this.ShipDtl_AfterFieldChange);
this.ShipDtl_Row.EpiRowChanged += new EpiRowChanged(this.ShipDtl_AfterRowChange);
this.ShipDtl_Column.ColumnChanging += new DataColumnChangeEventHandler(this.ShipDtl_BeforeFieldChange);
this.oTrans_partBinSearchAdapter = ((EpiBaseAdapter)(this.csm.TransAdaptersHT["oTrans_partBinSearchAdapter"]));
this.oTrans_partBinSearchAdapter.AfterAdapterMethod += new AfterAdapterMethod(this.oTrans_partBinSearchAdapter_AfterAdapterMethod);
this.oTrans_partBinSearchAdapter.BeforeAdapterMethod += new BeforeAdapterMethod(this.oTrans_partBinSearchAdapter_BeforeAdapterMethod);
this.edvShipDtl = ((EpiDataView)(this.oTrans.EpiDataViews["ShipDtl"]));
this.edvShipDtl.EpiViewNotification += new EpiViewNotification(this.edvShipDtl_EpiViewNotification);
// End Wizard Added Variable Initialization
// Begin Wizard Added Custom Method Calls
MessageBox.Show("InitializeCustomCode");
// 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.ShipDtl_Column.ColumnChanged -= new DataColumnChangeEventHandler(this.ShipDtl_AfterFieldChange);
this.ShipDtl_Row.EpiRowChanged -= new EpiRowChanged(this.ShipDtl_AfterRowChange);
this.ShipDtl_Column.ColumnChanging -= new DataColumnChangeEventHandler(this.ShipDtl_BeforeFieldChange);
this.oTrans_partBinSearchAdapter.AfterAdapterMethod -= new AfterAdapterMethod(this.oTrans_partBinSearchAdapter_AfterAdapterMethod);
this.oTrans_partBinSearchAdapter = null;
this.oTrans_partBinSearchAdapter.BeforeAdapterMethod -= new BeforeAdapterMethod(this.oTrans_partBinSearchAdapter_BeforeAdapterMethod);
this.edvShipDtl.EpiViewNotification -= new EpiViewNotification(this.edvShipDtl_EpiViewNotification);
this.edvShipDtl = null;
// End Wizard Added Object Disposal
// Begin Custom Code Disposal
// End Custom Code Disposal
}
private void CallPartBinSearchAdapterGetPartBinByLotMethod()
{
MessageBox.Show("CallPartBinSearchAdapterGetPartBinByLotMethod");
try
{
// Declare and Initialize EpiDataView Variables
EpiDataView edvShipDtl = ((EpiDataView)(this.oTrans.EpiDataViews["ShipDtl"]));
// Check if valid EpiDataView Row(s) are selected
if ((edvShipDtl.Row < 0))
{
return;
}
// Declare and create an instance of the Adapter.
PartBinSearchAdapter adapterPartBinSearch = new PartBinSearchAdapter(this.oTrans);
adapterPartBinSearch.BOConnect();
// Declare and Initialize Variables
// TODO: You may need to replace the default initialization with valid values as required for the BL method call.
string partNum = ((string)(edvShipDtl.dataView[edvShipDtl.Row]["PartNum"]));
string lotNum = ((string)(edvShipDtl.dataView[edvShipDtl.Row]["LotNum"]));
int attributeSetID = ((int)(edvShipDtl.dataView[edvShipDtl.Row]["AttributeSetID"]));
// Call Adapter method
Erp.BO.PartBinSearchDataSet dsPartBinSearch = adapterPartBinSearch.GetPartBinByLot(partNum, lotNum, attributeSetID);
//DataTable dt = dsPartBinSearch.Tables["PartBinSearch"];
string qtyOnHand = dsPartBinSearch.Tables["PartBinSearch"].Rows[0]["QtyOnHand"].ToString();
// Debugging help
MessageBox.Show("qtyOnHand= " + qtyOnHand);
// Cleanup Adapter Reference
adapterPartBinSearch.Dispose();
} catch (System.Exception ex)
{
ExceptionBox.Show(ex);
}
}
private void ShipDtl_AfterFieldChange(object sender, DataColumnChangeEventArgs args)
{
// ** Argument Properties and Uses **
// args.Row["FieldName"]
// args.Column, args.ProposedValue, args.Row
// Add Event Handler Code
MessageBox.Show("AfterFieldChange");
switch (args.Column.ColumnName)
{
case "PartNum":
CallPartBinSearchAdapterGetPartBinByLotMethod();
break;
}
}
private void ShipDtl_AfterRowChange(EpiRowChangedArgs args)
{
// ** Argument Properties and Uses **
// args.CurrentView.dataView[args.CurrentRow]["FieldName"]
// args.LastRow, args.CurrentRow, args.CurrentView
// Add Event Handler Code
MessageBox.Show("AfterRowChange");
}
private void ShipDtl_BeforeFieldChange(object sender, DataColumnChangeEventArgs args)
{
// ** Argument Properties and Uses **
// args.Row["FieldName"]
// args.Column, args.ProposedValue, args.Row
// Add Event Handler Code
MessageBox.Show("BeforeFIeldChange");
switch (args.Column.ColumnName)
{
case "PartNum":
break;
}
}
private void oTrans_partBinSearchAdapter_AfterAdapterMethod(object sender, AfterAdapterMethodArgs args)
{
// ** Argument Properties and Uses **
// ** args.MethodName **
// ** Add Event Handler Code **
// ** Use MessageBox to find adapter method name
// EpiMessageBox.Show(args.MethodName)
MessageBox.Show("Afteradaptermethod");
switch (args.MethodName)
{
case "Update":
break;
}
}
private void oTrans_partBinSearchAdapter_BeforeAdapterMethod(object sender, BeforeAdapterMethodArgs args)
{
// ** Argument Properties and Uses **
// ** args.MethodName **
// ** Add Event Handler Code **
// ** Use MessageBox to find adapter method name
// EpiMessageBox.Show(args.MethodName)
MessageBox.Show("BeforeadapterMethod");
switch (args.MethodName)
{
case "Update":
// DialogResult dialogResult = EpiMessageBox.Show("Cancel Update?", "Cancel", MessageBoxButtons.YesNo);
// if ((dialogResult == DialogResult.Yes))
// {
// args.Cancel = true;
// } else
// {
// DoSomethingElse();
// }
break;
}
}
private void edvShipDtl_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
MessageBox.Show("EpiViewNotification");
if ((args.NotifyType == EpiTransaction.NotifyType.AddRow))
{
if ((args.Row > 0))
{
CallPartBinSearchAdapterGetPartBinByLotMethod();
}
}
}
}