static void Main(string[] args) { Axapta Ax = new Axapta(); Ax.Logon(null, null, null, null); string className = "ZFS_TestXML"; string methodName = "getResultTable"; string paramList = null; AxaptaObject axObj = Ax.CreateAxaptaObject(className); AxaptaRecord ret = null; if (paramList != null) { ret = (AxaptaRecord)axObj.Call(methodName, paramList); } else { ret = (AxaptaRecord)axObj.Call(methodName); } while (ret.Found) { ret.get_Field(2); } axObj.Dispose(); }
private bool DeletedAxComination(tbl_AccessoryAttributesDetails detailsToUpdate, int userIserial) { var axapta = new Axapta(); //Ready To be Dependent from Ax; var credential = new NetworkCredential("bcproxy", "around1"); //Ready To be Dependent from Ax bool result = false; 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); try { var importNew = axapta.CreateAxaptaObject("CreateProductionJournals"); result = (bool)importNew.Call("DeleteInventDimCombination", detailsToUpdate.tbl_AccessoryAttributesHeader.Code, detailsToUpdate.Configuration, detailsToUpdate.Size); } catch (Exception) { } axapta.Logoff(); return(result); }
//public AxConnectorServer(System.Security.Principal.IIdentity curUserIdentity) //{ // userIdentity = curUserIdentity; //} //public AxConnectorServer() //{ //} //Metodo che legge lo schema restituito ad AX /// <summary> /// Queries Ax /// </summary> /// <param name="className">Class name</param> /// <param name="methodName">Method name</param> /// <param name="paramList">Parameter list</param> /// <returns></returns> public Byte[] GetAxData(string className, string methodName, params object[] paramList) { XmlDocument xmlDoc = new XmlDocument(); try { //this.AxLogin(); this.AxLoginAs(); AxaptaObject axObj = Ax.CreateAxaptaObject(className); string ret = (string)this.callMethod(className, methodName, paramList); Byte[] buf = Encoding.UTF8.GetBytes(ret); MemoryStream ms = new MemoryStream(); System.IO.Compression.GZipStream zip = new System.IO.Compression.GZipStream(ms, System.IO.Compression.CompressionMode.Compress); zip.Write(buf, 0, buf.Length); zip.Close(); ms.Close(); axObj.Dispose(); return(ms.GetBuffer()); } catch (Microsoft.Dynamics.AxaptaException ex) { this.WriteErrorToEventLog(ex); SoapException se = new SoapException(ex.Message, SoapException.ServerFaultCode, ex.InnerException); throw se; } catch (Exception ex) { this.WriteErrorToEventLog(ex); SoapException se = new SoapException(ex.Message, SoapException.ClientFaultCode, ex.InnerException); throw se; } finally { this.AxLogoff(); } }
public decimal PurchaseFabricLinesToAx(TblPurchaseOrderHeaderRequest headerObjToPost, TblPurchaseReceiveDetail item, string purchaseOrder, int userIserial, Axapta axapta) { try { var importNew = axapta.CreateAxaptaObject("CreateProductionJournals"); var lineNum = importNew.Call("CreatePurchaseLinesSize", purchaseOrder, item.TblPurchaseOrderDetailRequest1.ItemId, item.Qty, item.BatchNo ?? "", item.TblPurchaseOrderDetailRequest1.TblColor.Code, headerObjToPost.TblWarehouse1.Code, item.TblPurchaseOrderDetailRequest1.Price, headerObjToPost.TblWarehouse1.Code, headerObjToPost.TblWarehouse1.TblSite1.Code, item.TblPurchaseOrderDetailRequest1.Size ?? ""); return(Convert.ToDecimal(lineNum)); } catch (Exception ex) { throw new Exception(ex.Message); } }
public void DeleteReservationOrder(Tbl_ReservationHeader reservationHeader, int userIserial) { var axapta = new Axapta();//Ready To be Dependent from Ax if (SharedOperation.UseAx()) { 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); } using (var entities = new WorkFlowManagerDBEntities()) { var headerRow = entities.Tbl_ReservationHeader.SingleOrDefault(x => x.Iserial == reservationHeader.Iserial); var rows = entities.Tbl_ReservationMainDetails.Include("Tbl_ReservationDetails").Include("Tbl_ReservationHeader1").Where(x => x.Tbl_ReservationHeader == reservationHeader.Iserial); foreach (var mainRow in rows) { foreach (var detailsRow in mainRow.Tbl_ReservationDetails.ToList()) { entities.DeleteObject(detailsRow); if (SharedOperation.UseAx()) { var importNew = axapta.CreateAxaptaObject("CreateProductionJournals"); if (detailsRow.AxPicklingListJournal != null) { importNew.Call("deletejournal", 0, detailsRow.AxPicklingListJournal, 0); } } } entities.DeleteObject(mainRow); } entities.DeleteObject(headerRow); entities.SaveChanges(); } if (SharedOperation.UseAx()) { axapta.Logoff(); } }
private void DeleteAXroute(RouteCardHeader header) { var deleteOrReverse = 0; if (header.IsPosted == true) { deleteOrReverse = 1; } using (var axapta = new Axapta()) { var credential = new NetworkCredential("bcproxy", "around1"); axapta.LogonAs("osama.gamal", "ccasual.loc", credential, "ccm", null, null, null); var import = axapta.CreateAxaptaObject("CreateProductionJournals"); string journal = null; switch (header.RouteType) { case 3: journal = header.AxReportAsAFinishedJournalId; break; case 5: journal = header.AxRouteCardJournalId; break; case 0: journal = header.AxRouteCardFabricsJournalId; break; } if (journal != null) { import.Call("deletejournal", header.RouteType, journal, deleteOrReverse); } if (header.AxRouteCardFabricsJournalId != null) { import.Call("deletejournal", 0, header.AxRouteCardFabricsJournalId, deleteOrReverse); } axapta.Logoff(); } }
private void CreatePackingSlip(string packingSlipId, string purchId, string transactionGuid, int userIserial) { 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); } if (userToLogin != null) { axapta.LogonAs(userToLogin.User_Win_Login, userToLogin.User_Domain, credential, "Ccm", null, null, null); } var importNew = axapta.CreateAxaptaObject("CreateProductionJournals"); importNew.Call("PostPurchFormLetter", packingSlipId, purchId, transactionGuid); axapta.Logoff(); }
static void Main(string[] args) { Axapta Ax = new Axapta(); Ax.Logon(null, null, null, null); string className = "ZFS_TestXML"; string methodName = "getResultTable"; string paramList = null; AxaptaObject axObj = Ax.CreateAxaptaObject(className); AxaptaRecord ret = null; if (paramList != null) ret = (AxaptaRecord)axObj.Call(methodName, paramList); else ret = (AxaptaRecord)axObj.Call(methodName); while (ret.Found) { ret.get_Field(2); } axObj.Dispose(); }
private void UpdateAccDetailsInAX(List <tbl_AccessoryAttributesDetails> detailsToUpdate, int userIserial) { var axapta = new Axapta();//Ready To be Dependent from Ax 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); foreach (var item in detailsToUpdate.Select(x => x.Configuration).Distinct()) { try { var importNew = axapta.CreateAxaptaObject("CreateProductionJournals"); importNew.Call("CreateConfig", detailsToUpdate.Select(x => x.Code).FirstOrDefault(), item); } catch (Exception) { } } foreach (var item in detailsToUpdate.Select(x => x.Size).Distinct()) { try { var importNew = axapta.CreateAxaptaObject("CreateProductionJournals"); importNew.Call("CreateSize", detailsToUpdate.Select(x => x.Code).FirstOrDefault(), item); } catch (Exception) { } //--------------------------------------------// //--------------------------------------------// //--------------------------------------------//C:\Users\GDE\Desktop\CCWFM\CCWFM.Web\Service\Operations\AccessoriesOperations.cs } foreach (var item in detailsToUpdate) { try { const string tableName = "InventDimCombination"; var axaptaRecord = axapta.CreateAxaptaRecord(tableName); axaptaRecord.Clear(); axaptaRecord.InitValue(); axaptaRecord.set_Field("ItemId", item.Code); axaptaRecord.set_Field("InventSizeID", item.Size); axaptaRecord.set_Field("ConfigId", item.Configuration); //Commit the record to the database. axaptaRecord.Insert(); } catch (Exception) { } } axapta.Logoff(); }
private void InsertAllNewAccessoryToAx(IEnumerable <tbl_AccessoryAttributesDetails> listObjToPost , tbl_AccessoryAttributesHeader objToPost, bool isSizeInCode, int userIserial) { try { using (var context = new WorkFlowManagerDBEntities()) { var axapta = new Axapta();//Ready To be Dependent from Ax; 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 itemId = objToPost.Code.Trim(); var tableName = "InventTable"; var axaptaRecord = axapta.CreateAxaptaRecord(tableName); axaptaRecord.Clear(); axaptaRecord.InitValue(); var tblLkpItemGroupType = context.tbl_lkp_ItemGroupType.FirstOrDefault(x => x.Iserial == context.tbl_lkp_AccessoryGroup .FirstOrDefault( g => g.Iserial == objToPost.AccGroup) .tbl_lkp_ItemGroupType); if (tblLkpItemGroupType != null) { var itmGroup = tblLkpItemGroupType.Code; axaptaRecord.set_Field("ItemGroupId", itmGroup); } else { axaptaRecord.set_Field("ItemGroupId", "ACCESSORIES"); } axaptaRecord.set_Field("ItemId", itemId); axaptaRecord.set_Field("ItemName", objToPost.Descreption ?? itemId); axaptaRecord.set_Field("ModelGroupID", "STD"); axaptaRecord.set_Field("ItemType", 0); axaptaRecord.set_Field("DimGroupId", "ACC"); //Commit the record to the database. axaptaRecord.Insert(); tableName = "InventTableModule"; axaptaRecord = axapta.CreateAxaptaRecord(tableName); axaptaRecord.Clear(); axaptaRecord.InitValue(); axaptaRecord.set_Field("ItemId", itemId); axaptaRecord.set_Field("ModuleType", 0); if (objToPost.UoMID != null) { axaptaRecord.set_Field ("UnitId", context.tbl_lkp_UoM .Where(x => x.Iserial == objToPost.UoMID) .Select(x => x.Ename) .SingleOrDefault() ); } // axaptaRecord.Insert(); axaptaRecord = axapta.CreateAxaptaRecord(tableName); axaptaRecord.Clear(); axaptaRecord.InitValue(); axaptaRecord.set_Field("ItemId", itemId); axaptaRecord.set_Field("ModuleType", 1); // axaptaRecord.Insert(); axaptaRecord = axapta.CreateAxaptaRecord(tableName); axaptaRecord.Clear(); axaptaRecord.InitValue(); axaptaRecord.set_Field("ItemId", itemId); axaptaRecord.set_Field("ModuleType", 2); // axaptaRecord.Insert(); tableName = "InventItemLocation"; axaptaRecord = axapta.CreateAxaptaRecord(tableName); axaptaRecord.Clear(); axaptaRecord.InitValue(); axaptaRecord.set_Field("ItemId", itemId); axaptaRecord.set_Field("InventDIMID", "AllBlank"); // Commit the record to the database. axaptaRecord.Insert(); foreach (var item in listObjToPost) { try { var importNew = axapta.CreateAxaptaObject("CreateProductionJournals"); importNew.Call("CreateConfig", listObjToPost.Select(x => x.Code).FirstOrDefault(), item); } catch (Exception) { } // if (!isSizeInCode) // { try { var importNew = axapta.CreateAxaptaObject("CreateProductionJournals"); importNew.Call("CreateSize", listObjToPost.Select(x => x.Code).FirstOrDefault(), item); } catch (Exception) { } //--------------------------------------------// //--------------------------------------------// //--------------------------------------------// try { tableName = "InventDimCombination"; axaptaRecord = axapta.CreateAxaptaRecord(tableName); axaptaRecord.Clear(); axaptaRecord.InitValue(); axaptaRecord.set_Field("ItemId", itemId); axaptaRecord.set_Field("InventSizeID", item.Size); axaptaRecord.set_Field("ConfigId", item.Configuration); //Commit the record to the database. axaptaRecord.Insert(); } catch (Exception) { } //--------------------------------------------// //--------------------------------------------// //--------------------------------------------// // } } axapta.Logoff(); } } catch (Exception ex) { throw ex; } }
public void PurchaseRouteServicesToAx(RouteCardHeader headerObjToPost, int postPostOrNo) { using (var context = new WorkFlowManagerDBEntities()) { var detailsObjToPost = context.RouteCardFabrics.Where(x => x.RouteCardHeaderIserial == headerObjToPost.Iserial); using (var axapta = new Axapta()) { var credential = new NetworkCredential("bcproxy", "around1"); axapta.LogonAs("osama.gamal", "ccasual.loc", credential, "ccm", null, null, null); var inventTable = axapta.CreateAxaptaRecord("InventDim"); try { var purchId = "Rc_ " + headerObjToPost.Iserial.ToString(); var tableName = "PurchTable"; var purchTableRecord = axapta.CreateAxaptaRecord(tableName); purchTableRecord.Clear(); purchTableRecord.InitValue(); purchTableRecord.set_Field("PurchId", purchId); purchTableRecord.set_Field("DeliveryDate", headerObjToPost.DeliveryDate); // axaptaRecord.set_Field("PurchId", _PurchID); var header = axapta.CallStaticRecordMethod("VendTable", "find", headerObjToPost.Vendor) as AxaptaRecord; purchTableRecord.Call("initFromVendTable", header); purchTableRecord.Insert(); tableName = "PurchLine"; foreach (var item in detailsObjToPost) { var axaptaRecord = axapta.CreateAxaptaRecord(tableName); axaptaRecord.Clear(); axaptaRecord.InitValue(); inventTable.Clear(); inventTable.set_Field("InventLocationId", item.Warehouse); if (item.FabricColor != null) { inventTable.set_Field("InventColorId", item.FabricColor); } if (item.Size != null) { inventTable.set_Field("InventSizeId", item.Size); } var importNew = axapta.CreateAxaptaObject("CreateProductionJournals"); var producationOrder = importNew.Call("GetProdIdFromSalesorderAndColor", item.Style, item.StyleColor, item.SalesOrder); if (producationOrder == null || (string)producationOrder == "") { producationOrder = "Free"; } var config = importNew.Call("CreateConfig", item.ItemId, "Free"); var batch = importNew.Call("CreateBatch", item.ItemId, producationOrder); inventTable.set_Field("configId", "Free"); inventTable.set_Field("inventBatchId", producationOrder); inventTable = axapta.CallStaticRecordMethod("InventDim", "findOrCreate", inventTable) as AxaptaRecord; if (inventTable != null) { var tempx = inventTable.get_Field("inventDimId").ToString(); axaptaRecord.set_Field("InventDimId", tempx); } axaptaRecord.set_Field("ItemId", item.ItemId); axaptaRecord.set_Field("ItemId", item.ItemId); axaptaRecord.set_Field("purchId", purchId); axaptaRecord.set_Field("QtyOrdered", Convert.ToDecimal(item.Qty.ToString())); // axaptaRecord.set_Field("PurchPrice", item.Qty); axaptaRecord.set_Field("PurchQty", Convert.ToDecimal(item.Qty.ToString())); axaptaRecord.set_Field("LineAmount", Convert.ToDecimal(item.Qty.ToString())); axaptaRecord.Call("createLine", true, true, true, true, true, true); } //No errors occured, Commit! //Axapta.TTSCommit(); if (postPostOrNo == 1) { var importNew = axapta.CreateAxaptaObject("CreateProductionJournals"); importNew.Call("PostPurchaseOrder", purchId, headerObjToPost.DocDate); } } catch (Exception ex) { //There was some errors, Abort transaction and Raise error! //Axapta.TTSAbort(); throw new Exception(ex.Message); } finally { //Finally logoff the Axapta Session axapta.Logoff(); } } } }
private void PickingList(int routeCardHeaderIserial, int postPostOrNo) { using (var entities = new WorkFlowManagerDBEntities()) { var routeHeaderRow = entities .RouteCardHeaders.SingleOrDefault(x => x.Iserial == routeCardHeaderIserial); var pickingList = entities.RouteCardFabrics.Where(x => x.RouteCardHeaderIserial == routeHeaderRow.Iserial).ToList(); try { if (pickingList.Count() != 0) { var axapta = new Axapta(); var credential = new NetworkCredential("bcproxy", "around1"); axapta.LogonAs("osama.gamal", "ccasual.loc", credential, "ccm", null, null, null); const string tableName = "AutoPICKING"; foreach (var item in pickingList) { var site = entities.GetLocations.Where(x => x.INVENTLOCATIONID == item.Warehouse).Select(x => x.INVENTSITEID).FirstOrDefault(); var axaptaRecord = axapta.CreateAxaptaRecord(tableName); axaptaRecord.Clear(); axaptaRecord.InitValue(); axaptaRecord.set_Field("DATAAREAID", "CCM"); if (item != null) { if (item.SalesOrder != null) { axaptaRecord.set_Field("SALESORDER", item.SalesOrder); } if (item.ItemId != null) { axaptaRecord.set_Field("FABRICID", item.ItemId); } if (item.FabricColor != null) { axaptaRecord.set_Field("FABRIC_COLOR", item.FabricColor); } if (item.Style != null) { axaptaRecord.set_Field("STYLEID", item.Style); } if (item.StyleColor != null) { axaptaRecord.set_Field("STYLECOLOR", item.StyleColor); } if (site != null) { axaptaRecord.set_Field("FABRICSITEID", site); } if (item.Warehouse != null) { axaptaRecord.set_Field("FABRICLOCATION", item.Warehouse); axaptaRecord.set_Field("FABRICWAREHOUSES", item.Warehouse); } if (item.Barcode != null) { axaptaRecord.set_Field("FABRICBATCHNUMBER", item.Barcode.ToString()); } axaptaRecord.set_Field("TRANSDATE", routeHeaderRow.DocDate); axaptaRecord.set_Field("QTY", item.Qty); } axaptaRecord.set_Field("VENDOR", routeHeaderRow.Vendor); axaptaRecord.set_Field("WORKFLOWJOURID", routeHeaderRow.Iserial); axaptaRecord.Insert(); } var importNew = axapta.CreateAxaptaObject("CreateProductionJournals"); var retval = importNew.Call("CreatePicking", routeHeaderRow.Iserial, 0, postPostOrNo); routeHeaderRow.AxRouteCardFabricsJournalId = retval.ToString(); ClearAxTable(tableName, axapta); entities.SaveChanges(); axapta.Logoff(); } } catch (Exception) { throw; } } }
public void PurchaseDyeingServicesToAxAcc(TblDyeingOrdersHeaderAcc objToPost, TblDyeingOrdersMainDetailsACC headerObjToPost, int postPostOrNo, int userIserial, string transactionGuid) { using (var context = new WorkFlowManagerDBEntities()) { using (var axapta = new Axapta()) { var credential = new NetworkCredential("bcproxy", "around1"); TblAuthUser userToLogin; userToLogin = context.TblAuthUsers.SingleOrDefault(x => x.Iserial == userIserial); axapta.LogonAs(userToLogin.User_Win_Login, userToLogin.User_Domain, credential, "Ccm", null, null, null); var inventTable = axapta.CreateAxaptaRecord("InventDim"); try { var vendorWmsLocation = context.GetWmsLocations.SingleOrDefault(x => x.VENDID == objToPost.Vendor); var vendorLoc = context.GetLocations.SingleOrDefault(x => x.INVENTLOCATIONID == vendorWmsLocation.INVENTLOCATIONID); var purchId = "Rc_ " + headerObjToPost.DyeingProductionOrder.ToString() + headerObjToPost.TransId.ToString() + headerObjToPost.TransactionType; var tableName = "PurchTable"; var purchTableRecord = axapta.CreateAxaptaRecord(tableName); purchTableRecord.Clear(); purchTableRecord.InitValue(); purchTableRecord.set_Field("PurchId", purchId); purchTableRecord.set_Field("DeliveryDate", headerObjToPost.TblDyeingOrdersDetailsAccs.OrderByDescending(x => x.EstimatedDeliveryDate).FirstOrDefault().EstimatedDeliveryDate ?? DateTime.Now); var headerax = axapta.CallStaticRecordMethod("VendTable", "find", objToPost.Vendor) as AxaptaRecord; purchTableRecord.Call("initFromVendTable", headerax); purchTableRecord.Insert(); foreach (var item in headerObjToPost.TblDyeingOrdersDetailsAccs) { tableName = "PurchLine"; foreach (var servicerow in item.DyeingOrderDetailsServicesAccs) { var axaptaRecord = axapta.CreateAxaptaRecord(tableName); axaptaRecord.Clear(); axaptaRecord.InitValue(); inventTable.Clear(); inventTable.set_Field("InventLocationId", vendorLoc.INVENTLOCATIONID); if (item.Color != null) { inventTable.set_Field("InventColorId", item.Color); } var importNew = axapta.CreateAxaptaObject("CreateProductionJournals"); var producationOrder = "Free"; using (var model = new ax2009_ccEntities()) { // var batch = item.BatchNo.ToString(); var firstOrDefault = model.PRODCONNECTIONs.FirstOrDefault( x => x.DYEDITEM == item.DyedFabric && x.TRANSID == item.DyeingProductionOrder && x.FROMCONFIG == item.Color && // x.FROMBATCH == batch && x.JOURNALLINKID == item.TransId); if (firstOrDefault != null) { producationOrder = firstOrDefault.PRODID; } } if (producationOrder == null || producationOrder == "") { producationOrder = "Free"; } importNew.Call("CreateConfig", servicerow.ServiceCode, item.Color); importNew.Call("CreateBatch", servicerow.ServiceCode, producationOrder); inventTable.set_Field("configId", item.Color); inventTable.set_Field("inventBatchId", producationOrder); inventTable = axapta.CallStaticRecordMethod("InventDim", "findOrCreate", inventTable) as AxaptaRecord; if (inventTable != null) { var tempx = inventTable.get_Field("inventDimId").ToString(); axaptaRecord.set_Field("InventDimId", tempx); } axaptaRecord.set_Field("ItemId", servicerow.ServiceCode); axaptaRecord.set_Field("purchId", purchId); axaptaRecord.set_Field("QtyOrdered", Convert.ToDecimal(item.CalculatedTotalQty.ToString())); decimal price = 1; //context.TblTradeAgreementDetails.Where(x => x.ItemCode == servicerow.ServiceCode && x.TblTradeAgreementHeader1.Vendor == objToPost.Vendor); axaptaRecord.set_Field("PurchPrice", Convert.ToDecimal(price)); axaptaRecord.set_Field("PurchQty", Convert.ToDecimal(item.CalculatedTotalQty.ToString())); axaptaRecord.set_Field("LineAmount", Convert.ToDecimal(item.CalculatedTotalQty.ToString()) * price); axaptaRecord.Call("createLine", true, true, true, true, true, false); } //No errors occured, Commit! //Axapta.TTSCommit(); if (postPostOrNo == 1) { var importNew = axapta.CreateAxaptaObject("CreateProductionJournals"); importNew.Call("PostPurchaseOrder", purchId, objToPost.TransactionDate ?? DateTime.Now); PickingListForAxServicesAcc(objToPost, headerObjToPost, postPostOrNo, userIserial, transactionGuid); } } } catch (Exception ex) { //There was some errors, Abort transaction and Raise error! //Axapta.TTSAbort(); throw new Exception(ex.Message); } finally { //Finally logoff the Axapta Session 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(); } } }
public void PurchaseDyeingServicesToAx(TblDyeingOrdersHeader objToPost, TblDyeingOrdersMainDetail headerObjToPost, int postPostOrNo, int userIserial, string transactionGuid) { using (var context = new WorkFlowManagerDBEntities()) { using (var axapta = new Axapta()) { var credential = new NetworkCredential("bcproxy", "around1"); TblAuthUser userToLogin = context.TblAuthUsers.SingleOrDefault(x => x.Iserial == userIserial); axapta.LogonAs(userToLogin.User_Win_Login, userToLogin.User_Domain, credential, "Ccm", null, null, null); var inventTable = axapta.CreateAxaptaRecord("InventDim"); try { var vendorWmsLocation = context.GetWmsLocations.FirstOrDefault(x => x.VENDID == objToPost.Vendor); var vendorLoc = context.GetLocations.FirstOrDefault(x => x.INVENTLOCATIONID == vendorWmsLocation.INVENTLOCATIONID); var purchId = "Rc_ " + objToPost.DocPlan.ToString() + objToPost.DyeingProductionOrder + headerObjToPost.TransId.ToString() + headerObjToPost.TransactionType; var tableName = "PurchTable"; purchId = GenerateNewPurchase(purchId); var purchTableRecord = axapta.CreateAxaptaRecord(tableName); purchTableRecord.Clear(); purchTableRecord.InitValue(); purchTableRecord.set_Field("PurchId", purchId); purchTableRecord.set_Field("DeliveryDate", headerObjToPost.TblDyeingOrdersDetails.OrderByDescending(x => x.EstimatedDeliveryDate).FirstOrDefault().EstimatedDeliveryDate ?? DateTime.Now); var headerax = axapta.CallStaticRecordMethod("VendTable", "find", objToPost.Vendor) as AxaptaRecord; purchTableRecord.Call("initFromVendTable", headerax); purchTableRecord.Insert(); foreach (var item in headerObjToPost.TblDyeingOrdersDetails) { tableName = "PurchLine"; foreach (var servicerow in item.DyeingOrderDetailsServices) { var axaptaRecord = axapta.CreateAxaptaRecord(tableName); axaptaRecord.Clear(); axaptaRecord.InitValue(); inventTable.Clear(); inventTable.set_Field("InventLocationId", vendorLoc.INVENTLOCATIONID); inventTable.set_Field("wMSLocationId", vendorWmsLocation.WMSLOCATIONID); if (item.Color != null) { inventTable.set_Field("InventColorId", item.Color); } var importNew = axapta.CreateAxaptaObject("CreateProductionJournals"); var producationOrder = "Free"; using (var model = new ax2009_ccEntities()) { var firstOrDefault = model.PRODCONNECTIONs.FirstOrDefault( x => x.DYEDITEM == item.DyedFabric && x.TRANSID == item.DyeingProductionOrder && x.TOCONFIG == item.Color && x.PRODID != ""); if (firstOrDefault != null) { producationOrder = firstOrDefault.PRODID; } } if (producationOrder == null || (string)producationOrder == "") { producationOrder = "Free"; } importNew.Call("CreateConfig", servicerow.ServiceCode, item.Color); importNew.Call("CreateBatch", servicerow.ServiceCode, producationOrder); inventTable.set_Field("configId", item.Color); inventTable.set_Field("inventBatchId", producationOrder); inventTable.set_Field("INVENTSITEID", vendorLoc.INVENTSITEID); inventTable = axapta.CallStaticRecordMethod("InventDim", "findOrCreate", inventTable) as AxaptaRecord; if (inventTable != null) { var tempx = inventTable.get_Field("inventDimId").ToString(); axaptaRecord.set_Field("InventDimId", tempx); } axaptaRecord.set_Field("PurchUnit", "Kg"); axaptaRecord.set_Field("ItemId", servicerow.ServiceCode); axaptaRecord.set_Field("purchId", purchId); axaptaRecord.set_Field("QtyOrdered", Convert.ToDecimal(item.CalculatedTotalQty.ToString())); decimal price = 1; price = (decimal)servicerow.Qty; axaptaRecord.set_Field("PurchPrice", Convert.ToDecimal(price)); axaptaRecord.set_Field("PurchQty", Convert.ToDecimal(item.CalculatedTotalQty.ToString())); axaptaRecord.set_Field("LineAmount", Convert.ToDecimal(price * (decimal)item.CalculatedTotalQty)); axaptaRecord.Call("createLine", true, true, false, true, true, false); } } if (postPostOrNo == 1) { var importNew = axapta.CreateAxaptaObject("CreateProductionJournals"); importNew.Call("PostPurchaseOrder", purchId, objToPost.TransactionDate ?? DateTime.Now); PickingListForAxServices(objToPost, headerObjToPost, postPostOrNo, userIserial, transactionGuid); } } catch (Exception ex) { throw new Exception(ex.Message); } finally { axapta.Logoff(); } } } }
public void PostRoutCardToAx(int routeCardHeaderIserial, int postPostOrNo) // posted=1 { using (var context = new WorkFlowManagerDBEntities()) { //int _TransID, string _WorkStationID, string _OperationID, int JournalType var routeHeaderRow = context .RouteCardHeaders.SingleOrDefault(x => x.Iserial == routeCardHeaderIserial); var operation = context.WF_RouteGroup.Where(x => x.iSerial == routeHeaderRow.RoutGroupID).Select(x => x.Code).SingleOrDefault(); var workStation = context.WF_Route.Where(x => x.iSerial == routeHeaderRow.RoutID).Select(x => x.Code).SingleOrDefault(); var detailsObjToPost = context .RealRoutCards .Where(x => x.TransID == routeHeaderRow.TransID && x.Operation == operation && x.WorkStation == workStation).ToList(); var axapta = new Axapta(); var credential = new NetworkCredential("bcproxy", "around1"); axapta.LogonAs("osama.gamal", "ccasual.loc", credential, "ccm", null, null, null); AxaptaRecord salesRecord = axapta.CreateAxaptaRecord("SalesLine"), invent = axapta.CreateAxaptaRecord("InventDim"); const string tableName = "AutoRoute"; //List<string> _TempinventDimIDList = new List<string>(); //_TempinventDimIDList.Add("00008851_086"); //_TempinventDimIDList.Add("00012748_086"); //_TempinventDimIDList.Add("00008851_086"); bool posted = false; try { if (detailsObjToPost.Count > 0) { foreach (var item in detailsObjToPost) { axapta.ExecuteStmt("select * from %1 " + "JOIN %2" + " where %1.InventDimId == %2.InventDimId" + " && %2.ConfigID =='" + item.Color + "'" + " && %1.SalesId == '" + item.SalesOrder + "'", salesRecord, invent); var inventDim = salesRecord.get_Field("InventDimID").ToString(); var axaptaRecord = axapta.CreateAxaptaRecord(tableName); axaptaRecord.Clear(); axaptaRecord.InitValue(); axaptaRecord.set_Field("TransId", routeCardHeaderIserial); if (item.StyleHeader != null) { axaptaRecord.set_Field("ItemID", item.StyleHeader); } if (item.SalesOrder != null) { axaptaRecord.set_Field("SalesId", item.SalesOrder); } if (item.Color != null) { axaptaRecord.set_Field("Colour", item.Color); } if (item.WorkStation != null) { axaptaRecord.set_Field("Machine", item.WorkStation); } if (item.Qty != null) { axaptaRecord.set_Field("Qty", Convert.ToDecimal(item.Qty.ToString())); } if (item.Operation != null) { axaptaRecord.set_Field("Operation", item.Operation); } if (item.DocDate != null) { axaptaRecord.set_Field("DocDate", item.DocDate); } axaptaRecord.set_Field("WhareHouse", ""); axaptaRecord.set_Field("Site", ""); if (inventDim != null) { axaptaRecord.set_Field("InventDimID", inventDim); } axaptaRecord.set_Field("JournalType", 5); if ((routeHeaderRow.RouteType == 5)) { axaptaRecord.set_Field("BatchId", "1"); axaptaRecord.set_Field("JournalType", 5); } axaptaRecord.Insert(); } var import = axapta.CreateAxaptaObject("CreateProductionJournals"); var retval = import.Call("CreateRouteJournal", routeCardHeaderIserial, workStation, operation, 5, postPostOrNo); if (retval.ToString() == "0") { throw new Exception("Error While Posting To AX"); } else { routeHeaderRow.AxRouteCardJournalId = retval.ToString(); if (postPostOrNo == 1) { posted = true; } routeHeaderRow.IsPosted = posted; } ClearAxTable(tableName, axapta); context.SaveChanges(); } } catch (Exception ex) { //There was some errors, Abort transaction and Raise error! //Axapta.TTSAbort(); throw new Exception(ex.Message); } finally { //Finally logoff the Axapta Session axapta.Logoff(); } if (routeHeaderRow.RouteType == 3) // Report AS a Finish { PostReportAsAFinish(routeHeaderRow.TransID, 3, routeCardHeaderIserial, postPostOrNo); } if (routeHeaderRow.Direction == 0) { PurchaseRouteServicesToAx(routeHeaderRow, postPostOrNo); } PickingList(routeCardHeaderIserial, postPostOrNo); } }
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 PostReportAsAFinish(int transId, int journalType, int routeCardHeaderIserial, int postPostOrNo) { using (var context = new WorkFlowManagerDBEntities()) { var routeCardHeaderRow = context .RouteCardHeaders.SingleOrDefault(x => x.Iserial == routeCardHeaderIserial); var chainSetupList = context.tblChainSetups.Where(x => x.sGridHeaderEName == "Route Card").ToList(); var routeCardDetailList = context.RouteCardDetails.Where(x => x.RoutGroupID == routeCardHeaderRow.RoutGroupID && x.Trans_TransactionHeader == transId && x.Direction == routeCardHeaderRow.Direction).ToList(); var axapta = new Axapta(); var credential = new NetworkCredential("bcproxy", "around1"); axapta.LogonAs("osama.gamal", "ccasual.loc", credential, "ccm", null, null, null); const string tableName = "AutoRoute"; AxaptaRecord salesRecord = axapta.CreateAxaptaRecord("SalesLine"), invent = axapta.CreateAxaptaRecord("InventDim"); int i = 0; try { if (routeCardDetailList.Count > 0) { foreach (var item in routeCardDetailList) { string warehouse = null; if (item.Degree == "1st") { warehouse = chainSetupList.SingleOrDefault(x => x.sGlobalSettingCode == "DefaultFPWarehouse1st").sSetupValue; } else if (item.Degree == "2nd") { warehouse = chainSetupList.SingleOrDefault(x => x.sGlobalSettingCode == "DefaultFPWarehouse2st").sSetupValue; } else if (item.Degree == "3rd") { warehouse = chainSetupList.SingleOrDefault(x => x.sGlobalSettingCode == "DefaultFPWarehouse3rd").sSetupValue; } var site = context.GetLocations.Where(x => x.INVENTLOCATIONID == warehouse).Select(x => x.INVENTSITEID).FirstOrDefault(); #region MyRegion axapta.ExecuteStmt("select * from %1 " + "JOIN %2" + " where %1.InventDimId == %2.InventDimId" + " && %2.ConfigID =='" + item.Color + "'" + " && %1.SalesId == '" + item.SalesOrder + "'", salesRecord, invent); var inventDim = salesRecord.get_Field("InventDimID").ToString(); #endregion MyRegion var axaptaRecord = axapta.CreateAxaptaRecord(tableName); axaptaRecord.Clear(); axaptaRecord.InitValue(); axaptaRecord.set_Field("TransId", routeCardHeaderRow.Iserial); if (item.Style != null) { axaptaRecord.set_Field("ItemID", item.Style); } if (item.SalesOrder != null) { axaptaRecord.set_Field("SalesId", item.SalesOrder); } if (item.Color != null) { axaptaRecord.set_Field("Colour", item.Color); } // AxaptaRecord.set_Field("Machine", _WorkStationID); if (item.SizeQuantity != null) { axaptaRecord.set_Field("Qty", Convert.ToDecimal(item.SizeQuantity)); } // AxaptaRecord.set_Field("Operation", _OperationID); if (routeCardHeaderRow.DocDate != null) { axaptaRecord.set_Field("DocDate", routeCardHeaderRow.DocDate); } if (warehouse != null) { axaptaRecord.set_Field("WhareHouse", warehouse); } if (warehouse != null) { axaptaRecord.set_Field("Location", warehouse); } if (site != null) { axaptaRecord.set_Field("Site", site); } axaptaRecord.set_Field("InventDimID", inventDim); axaptaRecord.set_Field("JournalType", journalType); axaptaRecord.set_Field("BatchId", "N/a"); if (item.Size != null) { axaptaRecord.set_Field("SreialId", item.Size); } if (i < 3) { i++; } axaptaRecord.Insert(); } var import = axapta.CreateAxaptaObject("CreateProductionJournals"); var retval = import.Call("CreateReportJournal", routeCardHeaderRow.Iserial, journalType, true, postPostOrNo); if (retval.ToString() == "0") { throw new Exception("Error While Posting To AX"); } else { routeCardHeaderRow.AxReportAsAFinishedJournalId = retval.ToString(); } ClearAxTable(tableName, axapta); context.SaveChanges(); } } catch (Exception ex) { //There was some errors, Abort transaction and Raise error! //Axapta.TTSAbort(); throw new Exception(ex.Message); } finally { //Finally logoff the Axapta Session axapta.Logoff(); } } }
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; } } }
private bool PostBomToAx(TblSalesOrder row, int userIserial) { var credential = new NetworkCredential("bcproxy", "around1"); var success = false; try { if (SharedOperation.UseAx()) { var ax = new Axapta();//Ready To be Dependent from Ax; TblAuthUser userToLogin; using (var model = new WorkFlowManagerDBEntities()) { userToLogin = model.TblAuthUsers.SingleOrDefault(x => x.Iserial == userIserial); } ax.LogonAs(userToLogin.User_Win_Login, userToLogin.User_Domain, credential, "Ccm", null, null, null); AxaptaObject import = ax.CreateAxaptaObject("NRunIntegration1"); var retval = import.Call("run", row.SalesOrderCode); if (retval.ToString() == "") { success = true; } ax.Logoff(); } using (var context = new WorkFlowManagerDBEntities()) { var temp = context.TblSalesOrders.Include("TblSalesOrderColors.TblSalesOrderSizeRatios").FirstOrDefault(x => x.SalesOrderCode == row.SalesOrderCode && x.SalesOrderType == 2); temp.Status = 1; foreach (var VARIABLE in temp.TblSalesOrderColors) { VARIABLE.ManualCalculationForProduction = true; VARIABLE.TotalForProduction = VARIABLE.Total; var Min = VARIABLE.TblSalesOrderSizeRatios.Where(x => x.ProductionPerSize > 0) .OrderBy(x => x.ProductionPerSize) .FirstOrDefault() .ProductionPerSize; foreach (var roww in VARIABLE.TblSalesOrderSizeRatios) { roww.ProductionPerSizeForProduction = roww.ProductionPerSize; if (VARIABLE.Total > 0 && roww.ProductionPerSize > 0) { if (roww.ProductionPerSize == Min) { roww.RatioForProduction = 1; } else { roww.RatioForProduction = (double)roww.ProductionPerSize / Min; } } else { roww.RatioForProduction = 0; } } } temp.IsPostedOnAxapta = true; context.SaveChanges(); } } catch (Exception ex) { success = false; throw ex; } return(success); }