Stephen from DotNetIT sent me his boilerplate to connect to the Data Model and demo how to make use of Client Side BO’s in LinqPad for easier BPM Writing.
Thought id share his boilerplate. Once you open a .linq file just hit F4 and fix your References and then restart LINQPad. F4 to fix references - http://screencast.com/t/d4CbEfTiFq
Stephen from DotNetIT sent me his boilerplate to connect to the Data Model and demo how to make use of Client Side BO’s in LinqPad for easier BPM Writing.
Thought id share his boilerplate. Once you open a .linq file just hit F4 and fix your References and then restart LINQPad. F4 to fix references - http://screencast.com/t/d4CbEfTiFq
Additional Namespaces Tab Erp Ice Ice.ExtendedData Ice.Extensibility Ice.Security.Token System.Configuration System.ServiceModel
void Main()
{
// Change query references to point to the correct Ice.Data.Model.dll and Erp.Data.910100.dll from your server directories (Press F4 or Edit the .linq file).
// Change this to point to your server web.config file
//Server Side
var webConfigFile = @"C:\inetpub\wwwroot\ERP101400\Server\web.config";
InitialiseConfiguration(webConfigFile);
var Db = new ErpContext();
//Client Side
using (var session = new Ice.Core.Session("manager","manager",Ice.Core.Session.LicenseType.EnterpriseProcessing,@"C:\Epicor\ERP10\LocalClients\ERP101400\Config\ERP101400.sysconfig"))
using (var partBO = WCFServiceSupport.CreateImpl<Erp.Proxy.BO.PartImpl>(session, Erp.Proxy.BO.PartImpl.UriPath))
using (var qtyAdjBO = WCFServiceSupport.CreateImpl<Erp.Proxy.BO.InventoryQtyAdjImpl>(session, Erp.Proxy.BO.InventoryQtyAdjImpl.UriPath))
using (var soBO = WCFServiceSupport.CreateImpl<Erp.Proxy.BO.SalesOrderImpl>(session, Erp.Proxy.BO.SalesOrderImpl.UriPath))
using (var oaBO = WCFServiceSupport.CreateImpl<Erp.Proxy.BO.OrderAllocImpl>(session, Erp.Proxy.BO.OrderAllocImpl.UriPath))
{
var testNumber = 1;
var testPart = "Alloc" + testNumber.ToString();
var ds = new Erp.BO.PartDataSet();
if(!partBO.PartExists(testPart))
{
partBO.GetNewPart(ds);
ds.Part[0].PartNum = testPart;
ds.Part[0].PartDescription = testPart;
ds.Part[0].TrackLots = true;
partBO.ChangePartNum(testPart,ds);
partBO.Update(ds);
}
else
ds = partBO.GetByID(testPart);
Debug.Assert(ds.Part.Count> 0 &&
ds.Part[0].TrackLots,"Part Not Setup Correctly");
//Add in some lots
var lots = new List<StockLot>();
lots.Add(new StockLot { LotNum="Roll1", Quantity = 10});
lots.Add(new StockLot { LotNum="Roll2", Quantity = 10});
lots.Add(new StockLot { LotNum="Roll3", Quantity = 10});
foreach(var lot in lots)
{
var qds = qtyAdjBO.GetInventoryQtyAdj(testPart,ds.Part[0].IUM);
qds.InventoryQtyAdj[0].WareHseCode = "CHI";
qds.InventoryQtyAdj[0].BinNum = "00-00-00";
qds.InventoryQtyAdj[0].ReasonCode = "ADD";
qds.InventoryQtyAdj[0].AdjustQuantity = lot.Quantity;
qds.InventoryQtyAdj[0].LotNum = lot.LotNum;
var partTranPKs = "";
qtyAdjBO.SetInventoryQtyAdj(qds,out partTranPKs);
}
Debug.Assert(Db.PartLot.Where(l=>l.PartNum == testPart).Count() == 3,"Part Lots Not Setup Correctly");
//Add Items to a SalesOrder
var soDS = new Erp.BO.SalesOrderDataSet();
soBO.GetNewOrderHed(soDS);
soDS.OrderHed[0].CustomerCustID = "ADDISON";
soBO.ChangeSoldToID(soDS);
soBO.Update(soDS);
soBO.GetNewOrderDtl(soDS,soDS.OrderHed[0].OrderNum);
soDS.OrderDtl[soDS.OrderDtl.Count -1].PartNum = testPart;
soBO.ChangePartNum(soDS,false,"EA");
var vWarn = "";
soBO.ChangeSellingQuantity(soDS,false,21,out vWarn);
soBO.Update(soDS);
var orderNum = soDS.OrderHed[0].OrderNum
orderNum.Dump("Created Order Num");
//Allocate Sales Order
var morePages = false;
va oaListDS = oaBO.GetListOfOrders("",String.Format("OrderNum = {0}",orderNum),"","","","NoFilter,NoFilter,NoFilter,NoFilter","","","","","","",0,0,out morePages,"");
var oaDS = oaBO.OrderAllocationGetRows(oaListDS);
oaDS.OrderAlloc[0].SelectedForAction = true;
oaBO.GetLotBinOnHand(oaDS);
oaDS.PartAllocLot[0].AllocatedQty = 10M;
var msgout = "";
var released = false;
oaBO.AllocateByLotBin(oaDS,"CHI","",out msgout,out released);
oaBO.OrderRelUpdate(oaDS);
}
}
// Define other methods and classes here
public class StockLot
{
public String LotNum;
public Decimal Quantity;
}
private void InitialiseConfiguration(string webConfigPath)
{
// Resetting is based on http://stackoverflow.com/questions/6150644/change-default-app-config-at-runtime
AppDomain.CurrentDomain.SetData("APP_CONFIG_FILE", webConfigPath);
typeof(ConfigurationManager)
.GetField("s_initState", BindingFlags.NonPublic |
BindingFlags.Static)
.SetValue(null, 0);
typeof(ConfigurationManager)
.GetField("s_configSystem", BindingFlags.NonPublic |
BindingFlags.Static)
.SetValue(null, null);
typeof(ConfigurationManager)
.Assembly.GetTypes()
.Where(x => x.FullName ==
"System.Configuration.ClientConfigPaths")
.First()
.GetField("s_current", BindingFlags.NonPublic |
BindingFlags.Static)
.SetValue(null, null);
//ConfigurationManager.ConnectionStrings.Dump();
}
void Main()
{
// Change query references to point to the correct Ice.Data.Model.dll and Erp.Data.910100.dll from your server directories (Press F4 or Edit the .linq file).
// Change this to point to your server web.config file
var webConfigFile = @"\\THINKSERVER\E10_Code\Server\web.config";
InitialiseConfiguration(webConfigFile);
var Db = new ErpContext();
Db.Part.Where(p=>p.Company == "DIEN" && p.TrackLots == true).Dump();
}
private void InitialiseConfiguration(string webConfigPath)
{
// Resetting is based on http://stackoverflow.com/questions/6150644/change-default-app-config-at-runtime
AppDomain.CurrentDomain.SetData("APP_CONFIG_FILE", webConfigPath);
typeof(ConfigurationManager)
.GetField("s_initState", BindingFlags.NonPublic |
BindingFlags.Static)
.SetValue(null, 0);
typeof(ConfigurationManager)
.GetField("s_configSystem", BindingFlags.NonPublic |
BindingFlags.Static)
.SetValue(null, null);
typeof(ConfigurationManager)
.Assembly.GetTypes()
.Where(x => x.FullName ==
"System.Configuration.ClientConfigPaths")
.First()
.GetField("s_current", BindingFlags.NonPublic |
BindingFlags.Static)
.SetValue(null, null);
//ConfigurationManager.ConnectionStrings.Dump();
}
if your web.config points to (local)\SQLINSTANCE you might have issues, you might need to modify your web.config to SERVERNAME\INSTANCE in all of its Connection Strings.
Additional Namespaces Tab in LINQPad
Erp
Ice
Ice.ExtendedData
Ice.Extensibility
Ice.Security.Token
System.Configuration
System.ServiceModel