I have a need to toggle the ShipTo in the PO depending on Country. I have a company in Mexico that if a supplier is from Mexico, it defaults to the Plant address which is in Mexico. However, any supplier that ship into Mexico, I need to search for a supplier and change the address to that supplier (Laredo TX). My code seems to be working somewhat. It change the address and everything else except for the combobox for Country. If I pick another supplier, then the combobox changes to the correct country. It’s like it is not refreshing from the interface the first time it is selected? Anyone can explain how I refresh the combobox from the interface? Below is what I have.
private void POHeader_AfterFieldChange(object sender, DataColumnChangeEventArgs args)
{
// ** Argument Properties and Uses **
// args.Row["FieldName"]
// args.Column, args.ProposedValue, args.Row
// Add Event Handler Code
EpiDataView edvPOHeader = (EpiDataView)oTrans.EpiDataViews["POHeader"];
string poHeaderCompany = edvPOHeader.dataView[edvPOHeader.Row]["Company"].ToString();
string vendorCountry = edvPOHeader.dataView[edvPOHeader.Row]["VendorCountry"].ToString().ToUpper();
var edv = oTrans.Factory("POHeader");
switch (args.Column.ColumnName)
{
case "VendorVendorID":
//if company is Mexico and Supplier Country is Mexico, then default to Mexico shipto address. Otherwise, use Laredo (USA) shipTo Address.
if(!string.IsNullOrEmpty(vendorID) && (poHeaderCompany == "MEX") && (vendorCountry != "MEXICO"))
{
try
{ //Query VendorPPSearch to get ShipTo PurPoint info
Ice.Proxy.Lib.BOReaderImpl _bor = WCFServiceSupport.CreateImpl<Ice.Proxy.Lib.BOReaderImpl>((Ice.Core.Session)oTrans.Session, Epicor.ServiceModel.Channels.ImplBase<Ice.Contracts.BOReaderSvcContract>.UriPath);
DataSet ds2 = _bor.GetList("Erp:BO:VendorPPSearch", "Company = 'MEX' AND VendorNum = '170' AND PurPoint = '100'" , "");
//if dataset is not empty, populate textbox from field result
if(ds2 != null)
{
edv.dataView[edv.Row]["ShipName"] = ds2.Tables[0].Rows[0]["Name"];
edv.dataView[edv.Row]["ShipAddress1"] = ds2.Tables[0].Rows[0]["Address1"];
edv.dataView[edv.Row]["ShipAddress2"] = ds2.Tables[0].Rows[0]["Address2"];
edv.dataView[edv.Row]["ShipAddress3"] = ds2.Tables[0].Rows[0]["Address3"];
edv.dataView[edv.Row]["ShipCity"] = ds2.Tables[0].Rows[0]["City"];
edv.dataView[edv.Row]["ShipState"] = ds2.Tables[0].Rows[0]["State"];
edv.dataView[edv.Row]["ShipZip"] = ds2.Tables[0].Rows[0]["Zip"];
edv.dataView[edv.Row]["ShipCountry"] = ds2.Tables[0].Rows[0]["Country"];
edv.dataView[edv.Row]["ShipCountryNum"] = ds2.Tables[0].Rows[0]["CountryNum"];
}
}
catch(Exception e)
{
MessageBox.Show("Error: "+e.Message);
}
}
break;
}
}