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(); }
/// <summary> /// Creates the XML schema /// </summary> /// <param name="className">Class name</param> /// <param name="methodName">Method name</param> /// <param name="paramList">Parameters list</param> /// <returns></returns> public Byte[] GetAxDataCreateSchema(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); //converto la stringa in XML document xmlDoc.LoadXml(ret); //creo un reader di dati XML per popolare il dataset XmlNodeReader xmlReader = new XmlNodeReader(xmlDoc.DocumentElement); System.Data.DataSet ds = new System.Data.DataSet(); //carico il dataset coi dati XML (Carico lo schema) ds.ReadXml(xmlReader, System.Data.XmlReadMode.InferSchema); //comprimo il dataset compreso di schema con GZIP e restituisco un byte array MemoryStream ms = new MemoryStream(); System.IO.Compression.GZipStream zip = new System.IO.Compression.GZipStream(ms, System.IO.Compression.CompressionMode.Compress); ds.WriteXml(zip, System.Data.XmlWriteMode.WriteSchema); 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(); } }
/// <summary> /// Calls an AX method /// </summary> /// <param name="className">Class name</param> /// <param name="methodName">Method name</param> /// <param name="paramList">Parameters list</param> /// <returns></returns> private Object callMethod(string className, string methodName, params object[] paramList) { AxaptaObject axObj = Ax.CreateAxaptaObject(className); Object ret = null; if (paramList != null) { ret = axObj.Call(methodName, paramList); } else { ret = axObj.Call(methodName); } axObj.Dispose(); return(ret); }
//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(); } }
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); }