public void PostIssueHeader(int iserial, int userIserial) { using (var entities = new WorkFlowManagerDBEntities()) { var axapta = new Axapta(); var credential = new NetworkCredential("bcproxy", "around1"); TblAuthUser userToLogin; using (var model = new WorkFlowManagerDBEntities()) { userToLogin = model.TblAuthUsers.FirstOrDefault(x => x.Iserial == userIserial); } var header = entities.TblIssueJournalHeaders.Include("TblIssueJournalDetails").FirstOrDefault(x => x.Iserial == iserial); var vendorWmsLocation = entities.GetWmsLocations.FirstOrDefault(x => x.VENDID == header.Vendor); var vendorLoc = entities.GetLocations.FirstOrDefault(x => x.INVENTLOCATIONID == vendorWmsLocation.INVENTLOCATIONID); axapta.LogonAs(userToLogin.User_Win_Login, userToLogin.User_Domain, credential, "Ccm", null, null, null); const string tableName = "PRODCONNECTION"; var transactionGuid = Guid.NewGuid().ToString(); if (header != null) { foreach (var item in header.TblIssueJournalDetails) { var locationLoc = entities.GetLocations.FirstOrDefault(x => x.INVENTLOCATIONID == item.Location); AxaptaRecord axaptaRecord = axapta.CreateAxaptaRecord(tableName); axaptaRecord.Clear(); axaptaRecord.InitValue(); //Transfer To Vendor's Location var itemcode = GetItemCode(item.ItemCode, item.ItemType); axaptaRecord.set_Field("DYEDITEM", itemcode.Code); axaptaRecord.set_Field("TRANSID", item.TblIssueJournalHeader); axaptaRecord.set_Field("RAWID", itemcode.Code); axaptaRecord.set_Field("RAWQTY", item.Qty); axaptaRecord.set_Field("DYEDQTY", item.Qty); axaptaRecord.set_Field("UNITID", itemcode.Unit); axaptaRecord.set_Field("FROMSITE", locationLoc.INVENTSITEID); axaptaRecord.set_Field("FROMLOCATION", item.Location); axaptaRecord.set_Field("FROMWAREHOUSE", item.Location); axaptaRecord.set_Field("FROMBATCH", item.BatchNo); axaptaRecord.set_Field("FROMCONFIG", item.TblColor1.Code); axaptaRecord.set_Field("TOSITE", vendorLoc.INVENTSITEID); axaptaRecord.set_Field("TOLOCATION", vendorWmsLocation.WMSLOCATIONID); axaptaRecord.set_Field("TOWAREHOUSE", vendorWmsLocation.INVENTLOCATIONID); axaptaRecord.set_Field("TOBATCH", item.BatchNo); axaptaRecord.set_Field("TOCONFIG", item.TblColor1.Code); axaptaRecord.set_Field("TRANSTYPE", Convert.ToInt64(0)); axaptaRecord.set_Field("JOURNALLINKID", item.TblIssueJournalHeader); axaptaRecord.set_Field("TransactionGuid", transactionGuid); axaptaRecord.Insert(); } } } }
private void PickingListForAxServicesAcc(TblDyeingOrdersHeaderAcc objToPost, TblDyeingOrdersMainDetailsACC headerObjToPost, int postPostOrNo, int userIserial, string transactionGuid) { using (var entities = new WorkFlowManagerDBEntities()) { var axapta = new Axapta(); AxaptaRecord AxaptaRecord; var credential = new NetworkCredential("bcproxy", "around1"); var tableName = "PRODCONNECTION"; TblAuthUser userToLogin; using (var model = new WorkFlowManagerDBEntities()) { userToLogin = model.TblAuthUsers.SingleOrDefault(x => x.Iserial == userIserial); } axapta.LogonAs(userToLogin.User_Win_Login, userToLogin.User_Domain, credential, "Ccm", null, null, null); var vendorWmsLocation = entities.GetWmsLocations.SingleOrDefault(x => x.VENDID == objToPost.Vendor); var vendorLoc = entities.GetLocations.SingleOrDefault(x => x.INVENTLOCATIONID == vendorWmsLocation.INVENTLOCATIONID); try { foreach (var item in headerObjToPost.TblDyeingOrdersDetailsAccs) { foreach (var service in item.DyeingOrderDetailsServicesAccs) { AxaptaRecord = axapta.CreateAxaptaRecord(tableName); AxaptaRecord.Clear(); AxaptaRecord.InitValue(); AxaptaRecord.set_Field("TRANSID", item.DyeingProductionOrder); AxaptaRecord.set_Field("RAWID", service.ServiceCode); AxaptaRecord.set_Field("DYEDITEM", service.ServiceCode); AxaptaRecord.set_Field("RAWQTY", item.CalculatedTotalQty); AxaptaRecord.set_Field("DYEDQTY", item.CalculatedTotalQty); //AxaptaRecord.set_Field("UNITID", item.Unit); AxaptaRecord.set_Field("FROMSITE", vendorLoc.INVENTSITEID); AxaptaRecord.set_Field("TOSITE", vendorLoc.INVENTSITEID); AxaptaRecord.set_Field("FROMLOCATION", vendorWmsLocation.WMSLOCATIONID); AxaptaRecord.set_Field("TOLOCATION", vendorWmsLocation.WMSLOCATIONID); AxaptaRecord.set_Field("TRANSTYPE", Convert.ToInt64(2)); AxaptaRecord.set_Field("FROMCONFIG", item.Color); AxaptaRecord.set_Field("TOCONFIG", item.Color); // AxaptaRecord.set_Field("FROMBATCH", item.BatchNo.ToString()); //AxaptaRecord.set_Field("TOBATCH", item.BatchNo.ToString()); AxaptaRecord.set_Field("FROMWAREHOUSE", vendorWmsLocation.INVENTLOCATIONID); AxaptaRecord.set_Field("TOWAREHOUSE", vendorWmsLocation.INVENTLOCATIONID); AxaptaRecord.set_Field("JOURNALLINKID", headerObjToPost.TransId); AxaptaRecord.set_Field("TransactionGuid", transactionGuid); AxaptaRecord.Insert(); } } //public ProdJournalId run(int transId,int journalId,int WhatToDo,str JourName,int PostorNo) var import = axapta.CreateAxaptaObject("CLEDyeProcesse"); var PickingList = import.Call("run", headerObjToPost.DyeingProductionOrder, headerObjToPost.TransId, 2, "Name", postPostOrNo); axapta.Logoff(); } catch (Exception) { axapta.Logoff(); throw; } } }
public void ProducationConnectionAcc(int dyeingProductionOrder, int transId, int transactionType, int userIserial) { using (var entities = new WorkFlowManagerDBEntities()) { var header = entities.TblDyeingOrdersHeaderAccs.SingleOrDefault(x => x.DyeingProductionOrder == dyeingProductionOrder); var mainDetail = entities.TblDyeingOrdersMainDetailsACCs.Include("TblDyeingOrdersDetailsAccs.DyeingOrderDetailsServicesAccs").SingleOrDefault(x => x.DyeingProductionOrder == dyeingProductionOrder && x.TransId == transId && x.TransactionType == transactionType); var locationLoc = entities.GetLocations.SingleOrDefault(x => x.INVENTLOCATIONID == mainDetail.WareHouse); var vendorWmsLocation = entities.GetWmsLocations.SingleOrDefault(x => x.VENDID == header.Vendor); var vendorLoc = entities.GetLocations.SingleOrDefault(x => x.INVENTLOCATIONID == vendorWmsLocation.INVENTLOCATIONID); var axapta = new Axapta(); var credential = new NetworkCredential("bcproxy", "around1"); TblAuthUser userToLogin; using (var model = new WorkFlowManagerDBEntities()) { userToLogin = model.TblAuthUsers.SingleOrDefault(x => x.Iserial == userIserial); } axapta.LogonAs(userToLogin.User_Win_Login, userToLogin.User_Domain, credential, "Ccm", null, null, null); var tableName = "PRODCONNECTION"; var transactionGuid = Guid.NewGuid().ToString(); foreach (var item in mainDetail.TblDyeingOrdersDetailsAccs) { try { AxaptaRecord AxaptaRecord; #region TransactionType0 Transfer To Vendor's Location And ProductionOrder And PickingList AxaptaRecord = axapta.CreateAxaptaRecord(tableName); AxaptaRecord.Clear(); AxaptaRecord.InitValue(); if (item.TransactionType == 0) { //Transfer To Vendor's Location AxaptaRecord.set_Field("TRANSID", item.DyeingProductionOrder); AxaptaRecord.set_Field("RAWID", item.FabricCode); AxaptaRecord.set_Field("RAWQTY", item.CalculatedTotalQty); AxaptaRecord.set_Field("UNITID", item.Unit); AxaptaRecord.set_Field("FROMSITE", locationLoc.INVENTSITEID); AxaptaRecord.set_Field("FROMLOCATION", mainDetail.WareHouse); AxaptaRecord.set_Field("FROMWAREHOUSE", mainDetail.WareHouse); AxaptaRecord.set_Field("FROMBATCH", "Free"); AxaptaRecord.set_Field("FROMCONFIG", item.Color); AxaptaRecord.set_Field("TOSITE", vendorLoc.INVENTSITEID); AxaptaRecord.set_Field("TOLOCATION", vendorWmsLocation.WMSLOCATIONID); AxaptaRecord.set_Field("TOWAREHOUSE", vendorWmsLocation.INVENTLOCATIONID); //AxaptaRecord.set_Field("TOBATCH", item.BatchNo.ToString()); AxaptaRecord.set_Field("TOCONFIG", item.Color); AxaptaRecord.set_Field("TRANSTYPE", Convert.ToInt64(0)); AxaptaRecord.set_Field("JOURNALLINKID", transId); AxaptaRecord.set_Field("TransactionGuid", transactionGuid); AxaptaRecord.Insert(); // // ProductionOrder AxaptaRecord = axapta.CreateAxaptaRecord(tableName); AxaptaRecord.Clear(); AxaptaRecord.InitValue(); AxaptaRecord.set_Field("TRANSID", item.DyeingProductionOrder); AxaptaRecord.set_Field("DYEDITEM", item.DyedFabric); AxaptaRecord.set_Field("DYEDQTY", item.CalculatedTotalQty); AxaptaRecord.set_Field("UNITID", item.Unit); AxaptaRecord.set_Field("JOURNALLINKID", transId); AxaptaRecord.set_Field("FROMSITE", vendorLoc.INVENTSITEID); AxaptaRecord.set_Field("TOSITE", vendorLoc.INVENTSITEID); AxaptaRecord.set_Field("FROMLOCATION", vendorWmsLocation.WMSLOCATIONID); AxaptaRecord.set_Field("TOLOCATION", vendorWmsLocation.WMSLOCATIONID); AxaptaRecord.set_Field("TRANSTYPE", Convert.ToInt64(1)); AxaptaRecord.set_Field("FROMCONFIG", item.Color); AxaptaRecord.set_Field("TOCONFIG", item.Color); // AxaptaRecord.set_Field("FROMBATCH", item.BatchNo.ToString()); // AxaptaRecord.set_Field("TOBATCH", item.BatchNo.ToString()); AxaptaRecord.set_Field("FROMWAREHOUSE", vendorWmsLocation.INVENTLOCATIONID); AxaptaRecord.set_Field("TOWAREHOUSE", vendorWmsLocation.INVENTLOCATIONID); AxaptaRecord.set_Field("TransactionGuid", transactionGuid); AxaptaRecord.Insert(); //// PickingList AxaptaRecord = axapta.CreateAxaptaRecord(tableName); AxaptaRecord.Clear(); AxaptaRecord.InitValue(); AxaptaRecord.set_Field("TRANSID", item.DyeingProductionOrder); AxaptaRecord.set_Field("RAWID", item.FabricCode); AxaptaRecord.set_Field("DYEDITEM", item.DyedFabric); AxaptaRecord.set_Field("RAWQTY", item.CalculatedTotalQty); AxaptaRecord.set_Field("DYEDQTY", item.CalculatedTotalQty); AxaptaRecord.set_Field("UNITID", item.Unit); AxaptaRecord.set_Field("FROMSITE", vendorLoc.INVENTSITEID); AxaptaRecord.set_Field("TOSITE", vendorLoc.INVENTSITEID); AxaptaRecord.set_Field("FROMLOCATION", vendorWmsLocation.WMSLOCATIONID); AxaptaRecord.set_Field("TOLOCATION", vendorWmsLocation.WMSLOCATIONID); AxaptaRecord.set_Field("TRANSTYPE", Convert.ToInt64(2)); AxaptaRecord.set_Field("FROMCONFIG", item.Color); AxaptaRecord.set_Field("TOCONFIG", item.Color); //AxaptaRecord.set_Field("FROMBATCH", item.BatchNo.ToString()); //AxaptaRecord.set_Field("TOBATCH", item.BatchNo.ToString()); AxaptaRecord.set_Field("FROMWAREHOUSE", vendorWmsLocation.INVENTLOCATIONID); AxaptaRecord.set_Field("TOWAREHOUSE", vendorWmsLocation.INVENTLOCATIONID); AxaptaRecord.set_Field("JOURNALLINKID", transId); AxaptaRecord.set_Field("TransactionGuid", transactionGuid); AxaptaRecord.Insert(); } #endregion TransactionType0 Transfer To Vendor's Location And ProductionOrder And PickingList #region TransactionType3 ReportAsFinished else if (item.TransactionType == 1) { AxaptaRecord = axapta.CreateAxaptaRecord(tableName); AxaptaRecord.Clear(); AxaptaRecord.InitValue(); AxaptaRecord.set_Field("TRANSID", item.DyeingProductionOrder); AxaptaRecord.set_Field("DYEDITEM", item.DyedFabric); AxaptaRecord.set_Field("DYEDQTY", item.CalculatedTotalQty); AxaptaRecord.set_Field("UNITID", item.Unit); AxaptaRecord.set_Field("FROMSITE", vendorLoc.INVENTSITEID); AxaptaRecord.set_Field("TOSITE", locationLoc.INVENTSITEID); AxaptaRecord.set_Field("FROMLOCATION", vendorWmsLocation.WMSLOCATIONID); AxaptaRecord.set_Field("TOLOCATION", mainDetail.WareHouse); AxaptaRecord.set_Field("TRANSTYPE", Convert.ToInt64(3)); AxaptaRecord.set_Field("FROMCONFIG", item.Color); AxaptaRecord.set_Field("TOCONFIG", item.Color); // AxaptaRecord.set_Field("FROMBATCH", item.BatchNo.ToString()); // AxaptaRecord.set_Field("TOBATCH", item.BatchNo.ToString()); AxaptaRecord.set_Field("JOURNALLINKID", transId); AxaptaRecord.set_Field("TOWAREHOUSE", mainDetail.WareHouse); AxaptaRecord.set_Field("FROMWAREHOUSE", vendorWmsLocation.INVENTLOCATIONID); AxaptaRecord.Insert(); } #endregion TransactionType3 ReportAsFinished } catch (Exception) { } } var import = axapta.CreateAxaptaObject("CLEDyeProcesse"); try { if (transactionType == 0) { //public ProdJournalId run(int transId,int journalId,int WhatToDo,str JourName,int PostorNo) var Production = import.Call("run", dyeingProductionOrder, transId, 1, "", 1); var Transfer = import.Call("run", dyeingProductionOrder, transId, 0, "Name", 1); var PickingList = import.Call("run", dyeingProductionOrder, transId, 2, "Name", 1); PurchaseDyeingServicesToAxAcc(header, mainDetail, 0, userIserial, transactionGuid); } else if (transactionType == 1) { var ReportAsFinished = import.Call("run", dyeingProductionOrder, transId, 3, "Name", 1); } mainDetail.Posted = true; entities.SaveChanges(); } catch (Exception) { throw; } Operations.SharedOperation.ClearAxTable("PRODCONNECTION", axapta, transactionGuid); axapta.Logoff(); } }
private void IssueJournalTransfer(TblIssueJournalHeader row, int userIserial) { using (var entities = new WorkFlowManagerDBEntities()) { if (SharedOperation.UseAx()) { var transactionGuid = Guid.NewGuid().ToString(); var vendorWmsLocation = entities.GetWmsLocations.SingleOrDefault(x => x.VENDID == row.Vendor); const string tableName = "PRODCONNECTION"; var vendorLoc = entities.GetLocations.SingleOrDefault(x => x.INVENTLOCATIONID == vendorWmsLocation.INVENTLOCATIONID); var axapta = new Axapta(); var credential = new NetworkCredential("bcproxy", "around1"); var detail = entities.TblIssueJournalDetails.Where(w => w.TblIssueJournalHeader == row.Iserial).ToList(); var userToLogin = entities.TblAuthUsers.SingleOrDefault(x => x.Iserial == userIserial); axapta.LogonAs(userToLogin.User_Win_Login, userToLogin.User_Domain, credential, "Ccm", null, null, null); axapta.CallStaticClassMethod("SysFlushAOD", "doFlush"); foreach (var item in detail) { var locationLoc = entities.GetLocations.SingleOrDefault(x => x.INVENTLOCATIONID == item.Location); AxaptaRecord AxaptaRecord = axapta.CreateAxaptaRecord(tableName); AxaptaRecord.Clear(); AxaptaRecord.InitValue(); //Transfer To Vendor's Location var fabriccode = entities.Fabric_UnitID.FirstOrDefault(w => w.Iserial == item.ItemCode); AxaptaRecord.set_Field("TRANSID", row.Iserial); AxaptaRecord.set_Field("RAWID", fabriccode.Fabric_Code); AxaptaRecord.set_Field("RAWQTY", item.Qty); AxaptaRecord.set_Field("UNITID", fabriccode.UnitID); if (locationLoc != null) { AxaptaRecord.set_Field("FROMSITE", locationLoc.INVENTSITEID); } AxaptaRecord.set_Field("FROMLOCATION", item.Location); AxaptaRecord.set_Field("FROMWAREHOUSE", item.Location); AxaptaRecord.set_Field("FROMBATCH", item.Size ?? "Free"); AxaptaRecord.set_Field("FROMCONFIG", entities.TblColors.FirstOrDefault(x => x.Iserial == item.TblColor).Code); if (vendorLoc != null) { AxaptaRecord.set_Field("TOSITE", vendorLoc.INVENTSITEID); } if (vendorWmsLocation != null) { AxaptaRecord.set_Field("TOLOCATION", vendorWmsLocation.WMSLOCATIONID); AxaptaRecord.set_Field("TOWAREHOUSE", vendorWmsLocation.INVENTLOCATIONID); } AxaptaRecord.set_Field("TOBATCH", item.Size ?? item.BatchNo ?? "Free"); AxaptaRecord.set_Field("TOCONFIG", entities.TblColors.FirstOrDefault(x => x.Iserial == item.TblColor).Code); AxaptaRecord.set_Field("TRANSTYPE", Convert.ToInt64(0)); AxaptaRecord.set_Field("JOURNALLINKID", row.Iserial); AxaptaRecord.set_Field("TransactionGuid", transactionGuid); AxaptaRecord.Insert(); } var import = axapta.CreateAxaptaObject("CLEDyeProcesse"); try { var transfer = import.Call("run", row.Iserial, row.Iserial, 0, "Name", 1, DateTime.UtcNow.ToUniversalTime()); row.AxTransaction = transfer.ToString(); row.IsPosted = true; entities.SaveChanges(); } catch (Exception) { throw; } SharedOperation.ClearAxTable("PRODCONNECTION", axapta, transactionGuid); axapta.Logoff(); } else { row.AxTransaction = "1111"; row.IsPosted = true; entities.SaveChanges(); } } }