There have been several requests for info on this so I figured I’d share how I do it. Note, this may not be the right\best way but it works very well for my use of writing and testing custom code for E10.
First I do all of this in a type of implementation called a Singleton. This just means that one and only one instance can exist. I did this so I could have one living connection \ oTrans for my entire app. It’s not necessary, especially for smaller scope testing. This method requires no special permission\access to the server just in case your company doesn’t trust you - like mine does me.
In my object I make vars for the session, all of my adapters (so I am not constantly creating\destroying them), etc. Here are a few:
public static ILauncher oTrans = null;
public static UD38Adapter a = null;
public static InvTransferAdapter invAdapter = null;
public static LotSelectUpdateAdapter lotAdapter = null;
public static WhseBinAdapter binAdapter = null;
public static Ice.Core.Session epiSession;
public static bool Connected = false;
I had to create an ILauncher to use:
public class MyILaunch : ILaunch
{
public object Session { get; set; }
public string WhoAmI { get; set; }
}
Then for connecting you can do something like this:
public static bool Connect(string username, string password)
{
try
{
epiSession = new Ice.Core.Session(username, password, Ice.Core.Session.LicenseType.GlobalUser, @"C:\Epicor\ERP10.1Client\Client\config\E10LiveDB2.sysconfig");
oTrans = new ILauncher(epiSession);
a = new UD38Adapter(oTrans);
a.BOConnect();
invAdapter = new InvTransferAdapter(oTrans);
invAdapter.BOConnect();
lotAdapter = new LotSelectUpdateAdapter(oTrans);
lotAdapter.BOConnect();
binAdapter = new WhseBinAdapter(oTrans);
binAdapter.BOConnect();
Connected = true;
currentUser = ((Session)oTrans.Session).UserID;
}
catch (System.UnauthorizedAccessException e)
{
MessageBox.Show("Login failed - Check your username\\password");
return false;
}
return true;
}
Once the framework is in place you can test your adapter stuff (for example)
public static bool baseCreateRecord(string pn, string bin, string lot, decimal count)
{
if(!Connected)
{
throw new Exception("You are not connected. Cancelled.");
}
a.ClearData(); //clear the serial record
if (a.GetaNewUD38())
{
a.UD38Data.Tables[0].Rows[0]["Key1"] = pn.ToUpper();
a.UD38Data.Tables[0].Rows[0]["Key2"] = bin.ToUpper();
a.UD38Data.Tables[0].Rows[0]["Key3"] = lot.ToUpper();
a.UD38Data.Tables[0].Rows[0][GetField("User1")] = currentUser.ToUpper();
a.UD38Data.Tables[0].Rows[0][GetField("Date1")] = DateTime.Now ;
a.UD38Data.Tables[0].Rows[0][GetField("Count1")] = count;
a.Update();
}
else
{
MessageBox.Show("Failed to create record");
return false;
}
GetUD38(); //refresh the grid
return true;
}
Very important - You will have to add references to all of the DLL’s needed (for your needs) this includes adapter and contract dlls as well as the core stuff like:
If anybody has a better way - I’d love for you to share it!