private long GetLongField(string sTable, string sFieldName) { long lValue = 0; StringBuilder refValor = new StringBuilder(25); int iResult = 0; switch (sTable) { case "ClientSupplier": iResult = CompacSDK.fLeeDatoCteProv(sFieldName, refValor, refValor.Capacity); break; case "Product": iResult = CompacSDK.fLeeDatoProducto(sFieldName, refValor, refValor.Capacity); break; case "Address": iResult = CompacSDK.fLeeDatoDireccion(sFieldName, refValor, refValor.Capacity); break; case "Agent": iResult = CompacSDK.fLeeDatoAgente(sFieldName, refValor, refValor.Capacity); break; } if (iResult == 0) { string sValue = refValor.ToString(); if (sValue.Length != 0) { lValue = long.Parse(sValue); } else { lValue = -1; } } else { lValue = -2; Console.WriteLine(string.Format("#Error#-{0}", GetError(iResult)) + ". Errno: " + iResult); Console.WriteLine("Field " + sFieldName + " in table " + sTable + " is invalid"); } return(lValue); }
/// <summary> /// Method that retrieves the agent of a given client. /// </summary> /// <param name="clientCode">Code of client</param> /// <param name="agent">Ref: Agent retrieved.</param> /// <returns>0 if success.</returns> public int GetAgent(string clientCode, ref string agent) { Logger log = new Logger(); int lError = 0; try { StringBuilder dato = new StringBuilder(); //lCteProv lError = CompacSDK.fBuscaCteProv(clientCode); if (lError != 0) { log.Warn("Error buscando el cliente: " + clientCode + "." + CompacSDK.GetError(lError)); return(lError); } else { //Leer dato del cliente rfc lError = CompacSDK.fLeeDatoCteProv("CIDAGENT01", dato, 11); if (lError != 0) { //CompacSDK.GetError(lError); log.Warn("Error buscando agente por id para el cliente " + clientCode + ". Error " + CompacSDK.GetError(lError)); return(lError); } } log.Debug("id agente de venta " + dato.ToString()); if (dato.Length == 0) { // No hay agente de venta asignado return(-1); } //posteriormente con los id del agente podrás buscar sus datos de la siguiente forma: StringBuilder a = new StringBuilder(); a.Capacity = 120; int agID = Convert.ToInt32(dato.ToString()); lError = CompacSDK.fBuscaIdAgente(agID); if (lError != 0) { log.Warn(CompacSDK.GetError(lError)); return(lError); } else { lError = CompacSDK.fLeeDatoAgente("CNOMBREA01", a, 60); agent = a.ToString(); return(lError); } } catch (Exception ex) { log.Warn("Algo fallo al buscar el agente para el cliente " + clientCode + ". Error: " + ex); agent = ""; return(-1); } }