Skip to content

Instantly share code, notes, and snippets.

@hasokeric
Last active February 19, 2020 18:12
Show Gist options
  • Save hasokeric/fbf42d627508a911652f76acb54c730e to your computer and use it in GitHub Desktop.
Save hasokeric/fbf42d627508a911652f76acb54c730e to your computer and use it in GitHub Desktop.
Epicor Example TryGetValue
/// <summary>
/// Helper to check if Part Number Generator Module is Enabled
/// </summary>
public bool GetIsPNGEnabled()
{
MessageBox.Show(Convert.ToString(GetCompanyValue<bool>("XaSyst", "PNGEnabled_c")));
MessageBox.Show(GetCompanyValue<string>("XaSyst", "DefaultPlant"));
string sValue;
if (TryGetCompanyValue<string>("XaSyst", "DefaultPlant", out sValue))
{
MessageBox.Show(sValue);
}
else {
MessageBox.Show("Couldnt Find Value");
}
return GetCompanyValue<bool>("XaSyst", "PNGEnabled_c");
}
/// <summary>
/// Helper to Get a Value from the Company Tables
/// </summary>
public T GetCompanyValue<T>(string sTable, string sColumn)
{
using (BOReaderImpl bor = WCFServiceSupport.CreateImpl<BOReaderImpl>((Ice.Core.Session)oTrans.Session, Epicor.ServiceModel.Channels.ImplBase<Ice.Contracts.BOReaderSvcContract>.UriPath))
{
DataSet ds = bor.GetRows("Erp:BO:Company", string.Format("Company = '{0}'", ((Ice.Core.Session)oTrans.Session).CompanyID), "Company, " + sColumn);
if (ds != null && ds.Tables.Contains(sTable))
{
DataTable table = ds.Tables[sTable];
if (table.Rows.Count > 0 && table.Columns.Contains(sColumn))
{
return (T)table.Rows[0][sColumn];
}
}
}
return (T)(object)null;
}
public bool TryGetCompanyValue<T>(string sTable, string sColumn, out T item)
{
try
{
using (BOReaderImpl bor = WCFServiceSupport.CreateImpl<BOReaderImpl>((Ice.Core.Session)oTrans.Session, Epicor.ServiceModel.Channels.ImplBase<Ice.Contracts.BOReaderSvcContract>.UriPath))
{
DataSet ds = bor.GetRows("Erp:BO:Company", string.Format("Company = '{0}'", ((Ice.Core.Session)oTrans.Session).CompanyID), "Company, " + sColumn);
if (ds != null && ds.Tables.Contains(sTable))
{
DataTable table = ds.Tables[sTable];
if (table.Rows.Count > 0 && table.Columns.Contains(sColumn))
{
item = (T)table.Rows[0][sColumn];
return true;
}
}
}
}
catch { }
item = default(T);
return false;
}
/// <summary>
/// Helper to check if Part Number Generator Module is Enabled
/// </summary>
public bool GetIsPNGEnabled()
{
bool result;
TryGetCompanyValue<bool>("XaSyst", "PNGEnabled_c", out result);
return result;
}
/// <summary>
/// Helper to Get a Value from the Company Tables
/// </summary>
public bool TryGetCompanyValue<T>(string sTable, string sColumn, out T item)
{
try
{
using (BOReaderImpl bor = WCFServiceSupport.CreateImpl<BOReaderImpl>((Ice.Core.Session)oTrans.Session, Epicor.ServiceModel.Channels.ImplBase<Ice.Contracts.BOReaderSvcContract>.UriPath))
{
DataSet ds = bor.GetRows("Erp:BO:Company", string.Format("Company = '{0}'", ((Ice.Core.Session)oTrans.Session).CompanyID), "Company, " + sColumn);
if (ds != null && ds.Tables.Contains(sTable))
{
// DataTable table = ds.Tables[sTable];
if (ds.Tables[sTable].Rows.Count > 0 && ds.Tables[sTable].Columns.Contains(sColumn))
{
item = (T)ds.Tables[sTable].Rows[0][sColumn];
return true;
}
}
}
}
catch { }
item = default(T);
return false;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment