示例#1
0
        public ScriptResponse Execute(ContextDataObject context, string query)
        {
            ErpBS bsERP = new ErpBS();

            if (!context.Parameters.ContainsKey("TipoPlataforma"))
            {
                throw new Exception("TipoPlataforma inválido");
            }

            EnumTipoPlataforma tipoPlataforma;

            if (!Enum.TryParse <EnumTipoPlataforma>((string)context.Parameters["TipoPlataforma"], out tipoPlataforma))
            {
                throw new Exception("TipoPlataforma inválido");
            }

            try
            {
                bsERP.AbreEmpresaTrabalho(tipoPlataforma, context.Company, context.Username, context.Password);
            }
            catch (Exception e)
            {
                throw new Exception("Erro a abrir a empresa no ERP: " + e.Message);
            }

            StdBELista queryResults = bsERP.Consulta(query);

            int numLinhas  = queryResults.NumLinhas();
            int numColunas = queryResults.NumColunas();

            string[] headers = new string[numColunas];
            for (short i = 0; i < numColunas; i++)
            {
                headers[i] = queryResults.Nome(i);
            }

            object[,] data = new object[numLinhas, numColunas];
            for (short i = 0; i < numLinhas; i++)
            {
                for (short j = 0; j < numColunas; j++)
                {
                    var nome = headers[j];
                    data[i, j] = queryResults.Valor(nome);
                }
                queryResults.Seguinte();
            }

            QueryResult response = new QueryResult()
            {
                Headers = headers,
                Data    = data
            };

            bsERP.FechaEmpresaTrabalho();

            return(new ScriptResponse
            {
                Object = response
            });
        }
        internal static Dictionary <String, int> CheckPendingDocuments(ERPContext oERPContext)
        {
            Dictionary <String, int>    result         = new Dictionary <string, int>();
            Dictionary <String, String> groupCompanies = CrossCompany.Platform.GetGroupCompanies(oERPContext);

            //Exit if no companies where found
            if (groupCompanies.Count == 0)
            {
                return(result);
            }

            result.Add("Purchases", 0);
            result.Add("Sales", 0);

            //Load the documents to import from all the group companies
            groupCompanies.Remove(oERPContext.BSO.Contexto.CodEmp);
            foreach (string groupCompany in groupCompanies.Keys)
            {
                ErpBS oCompany = new ErpBS();

                oCompany.AbreEmpresaTrabalho(
                    StdBE100.StdBETipos.EnumTipoPlataforma.tpEmpresarial,
                    groupCompany,
                    Properties.Settings.Default.User,
                    Properties.Settings.Default.Password);


                String strSQL = String.Format(
                    "select sum(pur) Purchases, sum(sls) Sales " +
                    "from(" +
                    "   select count(*) pur, 0 sls from cabecdoc cd inner join CabecDocStatus cds on cds.IdCabecDoc=cd.Id left join documentosvenda dv on cd.tipodoc = dv.documento " +
                    "   where dv.cdu_exportagrupo = 1 AND cd.cdu_exportado = 0  AND cds.Anulado=0 AND cd.entidade = '{0}' " +
                    "   UNION ALL " +
                    "   select 0 pur, count(*) pur from cabeccompras cc inner join CabecComprasStatus ccs on ccs.IdCabecCompras=cc.Id left join documentoscompra dc on cc.tipodoc = dc.documento " +
                    "   where dc.cdu_exportagrupo = 1 AND isnull(cc.cdu_exportado, 0) = 0 AND ccs.Anulado=0 AND cc.entidade = '{0}' " +
                    "   ) as tmp"
                    , oERPContext.BSO.Contexto.CodEmp);

                StdBELista lstPendDocs = oCompany.Consulta(strSQL);

                if (!lstPendDocs.Vazia())
                {
                    if (lstPendDocs.DaValor <int>("Purchases") > 0)
                    {
                        result["Purchases"] += lstPendDocs.DaValor <int>("Purchases");
                    }

                    if (lstPendDocs.DaValor <int>("Sales") > 0)
                    {
                        result["Sales"] += lstPendDocs.DaValor <int>("Sales");
                    }
                }
            }

            return(result);
        }
示例#3
0
        public List <Funcionario> daListaFuncionarios(string resticoes = "")
        {
            string sql = "";

            sql  = "select f.Codigo, f.Nome , f.Email, isnull(f.Telemovel,'') as Telemovel,isnull(f.Telefone,'') as Telefone, d.Descricao as Departamento from funcionarios f ";
            sql += "inner join Situacoes s on s.Situacao = f.Situacao ";
            sql += "left join Departamentos d on d.Departamento = f.CodDepartamento ";
            sql += "where s.Tipo = 0";

            if (resticoes != "")
            {
                sql += " and " + resticoes;
            }

            List <Funcionario> listFuncionario = new List <Funcionario>();


            var objLista = _erpBs.Consulta(sql);

            while (!(objLista.NoInicio() || objLista.NoFim()))
            {
                Funcionario funcionario = new Funcionario()
                {
                    codigo         = (string)objLista.Valor("Codigo"),
                    nome           = (string)objLista.Valor("Nome"),
                    departamentoId = (string)objLista.Valor("Departamento"),
                    email          = (string)objLista.Valor("Email"),
                    telemovel      = (string)objLista.Valor("Telemovel"),
                    telefone       = (string)objLista.Valor("Telefone")
                };

                listFuncionario.Add(funcionario);

                objLista.Seguinte();
            }

            return(listFuncionario);
        }
示例#4
0
        /// <summary>
        /// Check for available Data Model updates in resources and apply them, if any.
        /// </summary>
        /// <param name="companyObject"></param>
        private static void DataUpgrade(ref ErpBS companyObject)
        {
            try
            {
                StdBELista dbVersion = companyObject.Consulta("select Versao from VersaoModulo where Modulo = 'XME'");

                string currentVersion = dbVersion.Vazia() ? "0" : dbVersion.DaValor <String>("Versao");
                int    intVersion     = Convert.ToInt32(currentVersion) + 1;

                //Apply the upgrade scripts from resources
                string sqlUPG = Properties.Resources.ResourceManager.GetString(String.Format("UPG_{0}", intVersion.ToString()), CultureInfo.InvariantCulture);
                while (!String.IsNullOrEmpty(sqlUPG))
                {
                    companyObject.DSO.ExecuteSQL(sqlUPG);

                    intVersion += 1;
                    sqlUPG      = Properties.Resources.ResourceManager.GetString(String.Format("UPG_{0}", intVersion.ToString()), CultureInfo.InvariantCulture);
                }

                //Update the version
                intVersion -= 1;
                if (intVersion > Convert.ToInt32(currentVersion))
                {
                    string sqlQRY = string.Format("" +
                                                  "if exists(select * from VersaoModulo where Modulo = 'XME') " +
                                                  "   update VersaoModulo set Versao = '{0}' where Modulo = 'XME' " +
                                                  "else " +
                                                  "   insert into VersaoModulo(Modulo, Versao) values('XME', '{0}')"
                                                  , intVersion.ToString());

                    companyObject.DSO.ExecuteSQL(sqlQRY);
                }
            }
            catch
            {
                //Do nothing
            }
        }
        //Method that executes the query in the external system.
        private ScriptResponse executeQuery(ContextData context, Entity document, string query)
        {
            ErpBS bsERP = new ErpBS();

            if (context.ExternalSystems == null || context.ExternalSystems.Count == 0)
            {
                throw new Exception("External System em falta");
            }

            var externalSystem = context.ExternalSystems.FirstOrDefault().Value;

            if (!externalSystem.Parameters.ContainsKey("TipoPlataforma"))
            {
                throw new Exception("TipoPlataforma inválido");
            }

            EnumTipoPlataforma tipoPlataforma;

            if (!Enum.TryParse <EnumTipoPlataforma>((string)externalSystem.Parameters["TipoPlataforma"], out tipoPlataforma))
            {
                throw new Exception("TipoPlataforma inválido");
            }

            try
            {
                bsERP.AbreEmpresaTrabalho(tipoPlataforma, externalSystem.Code, (string)externalSystem.Parameters["Username"], (string)externalSystem.Parameters["Password"]);
            }
            catch (Exception e)
            {
                throw new Exception("Erro a abrir a empresa no ERP: " + e.Message);
            }

            StdBELista queryResults = bsERP.Consulta(query);

            int numLinhas  = queryResults.NumLinhas();
            int numColunas = queryResults.NumColunas();

            string[] headers = new string[numColunas];
            for (short i = 0; i < numColunas; i++)
            {
                headers[i] = queryResults.Nome(i);
            }

            object[,] data = new object[numLinhas, numColunas];
            for (short i = 0; i < numLinhas; i++)
            {
                for (short j = 0; j < numColunas; j++)
                {
                    var nome = headers[j];
                    data[i, j] = queryResults.Valor(nome);
                }
                queryResults.Seguinte();
            }

            QueryResult response = new QueryResult()
            {
                Headers = headers,
                Data    = data
            };

            bsERP.FechaEmpresaTrabalho();

            return(new ScriptResponse
            {
                Result = response
            });
        }
        public ScriptResponse Execute(ContextData context, Entity document, Dictionary <string, object> parameters)
        {
            /* **************************************** */
            /* **************************************** */
            /*          ADD YOUR CODE HERE              */
            ErpBS bsERP          = new ErpBS();
            var   externalSystem = context.ExternalSystems.FirstOrDefault().Value;

            try
            {
                if (!externalSystem.Parameters.ContainsKey("TipoPlataforma"))
                {
                    throw new Exception("TipoPlataforma invalido");
                }

                EnumTipoPlataforma tipoPlataforma;
                if (!Enum.TryParse <EnumTipoPlataforma>((string)externalSystem.Parameters["TipoPlataforma"], out tipoPlataforma))
                {
                    throw new Exception("TipoPlataforma invalido");
                }

                try
                {
                    bsERP.AbreEmpresaTrabalho(tipoPlataforma, externalSystem.Code, (string)externalSystem.Parameters["Username"], (string)externalSystem.Parameters["Password"]);
                }
                catch (Exception e)
                {
                    throw new Exception("Erro a abrir a empresa no ERP: " + e.Message);
                }

                string str       = externalSystem.Parameters["0"].ToString();
                int    first     = str.IndexOf("Commitments.GoodsPurchaseRequest[") + "Commitments.GoodsPurchaseRequest[".Length;
                int    last      = str.LastIndexOf("].ERPCode");
                int    commIndex = int.Parse(str.Substring(first, last - first));

                StdBELista queryResults = bsERP.Consulta($"SELECT Nome,Pais FROM Fornecedores WHERE Fornecedor='{document.Commitments.GoodsPurchaseRequest[commIndex].Attributes.ERPCode}'");

                int numLinhas  = queryResults.NumLinhas();
                int numColunas = queryResults.NumColunas();

                string[] headers = new string[numColunas];
                for (short i = 0; i < numColunas; i++)
                {
                    headers[i] = queryResults.Nome(i);
                }

                object[,] data = new object[numLinhas, numColunas];
                for (short i = 0; i < numLinhas; i++)
                {
                    for (short j = 0; j < numColunas; j++)
                    {
                        var nome = headers[j];
                        data[i, j] = queryResults.Valor(nome);
                    }
                    queryResults.Seguinte();
                }

                QueryResult response = new QueryResult()
                {
                    Headers         = headers,
                    Data            = data,
                    NumberOfRecords = numLinhas
                };

                bsERP.FechaEmpresaTrabalho();

                return(new ScriptResponse
                {
                    Result = response
                });
            }
            catch (Exception ex)
            {
                bsERP.FechaEmpresaTrabalho();

                throw ex;
            }
        }