Example #1
0
        private string NomeArqCte()
        {
            belConnection cx = new belConnection();
            try
            {
                string sNomeArq = "";
                FbCommand cmd = new FbCommand();
                cmd.Connection = cx.get_Conexao();
                cx.Open_Conexao();
                cmd.CommandText = "SP_CHAVEPRI";
                cmd.CommandType = CommandType.StoredProcedure;
                cmd.Parameters.Clear();

                cmd.Parameters.Add("@SNOMEGENERATOR", FbDbType.VarChar, 31).Value = "GEN_NOMEARQXML";

                sNomeArq = cmd.ExecuteScalar().ToString();

                return "Cte_" + sEmp + sNomeArq.PadLeft(15, '0') + ".xml";
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally { cx.Close_Conexao(); }
        }
Example #2
0
        public void AlteraDuplicataLorenzon(List<belNumeroNF> objNumeroNfs, int i)
        {
            belConnection cx = new belConnection();
            try
            {

                StringBuilder sQuery = new StringBuilder();
                sQuery.Append("UPDATE dupnotar SET dupnotar.cd_notafis = '" + objNumeroNfs[i].Cdnotafis + "' ");
                sQuery.Append("where dupnotar.cd_empresa = '" + Static.belStatic.codEmpresaNFe + "' ");
                sQuery.Append("and dupnotar.cd_nfseq = '" + objNumeroNfs[i].Nfseq + "'");
                FbCommand cmdLorenzon = new FbCommand(sQuery.ToString(), cx.get_Conexao());
                cx.Open_Conexao();
                cmdLorenzon.ExecuteNonQuery();

            }
            catch (Exception)
            {
                throw;
            }
            finally { cx.Close_Conexao(); }
          
        }
Example #3
0
        private void PopulaDadosNf(string sNumNf)
        {
            belConnection cx = new belConnection();

            try
            {
                StringBuilder sQuery = new StringBuilder();
                sQuery.Append("Select ");
                sQuery.Append("coalesce(nfconhec.cd_cgc,'')cnpj, ");
                sQuery.Append("coalesce(nfconhec.cd_cpf,'')cpf, ");
                sQuery.Append("coalesce(nfconhec.cd_serie,'')serie ");
                sQuery.Append("from nfconhec ");
                sQuery.Append("join empresa on nfconhec.cd_empresa ='" + belStatic.CodEmpresaCte + "' ");
                sQuery.Append("where nfconhec.cd_nf ='" + sNumNf + "' ");
                sQuery.Append("and empresa.cd_empresa ='" + belStatic.CodEmpresaCte + "'");



                FbCommand fbConn = new FbCommand(sQuery.ToString(), cx.get_Conexao());
                cx.Open_Conexao();
                FbDataReader dr = fbConn.ExecuteReader();
                dr.Read();

                if (dr["cnpj"].ToString() != "")
                {
                    dsInfNF.CPFCNPJ = dr["cnpj"].ToString();
                }
                else if (dr["cpf"].ToString() != "")
                {
                    dsInfNF.CPFCNPJ = dr["cpf"].ToString();
                }
                //dsInfNF.serie = dr["serie"].ToString();

            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                cx.Close_Conexao();
            }
        }
Example #4
0
        private string BuscaNumNotas(string scd_nrlanc)
        {
            belConnection cx = new belConnection();
            DataTable dt = new DataTable();
            scd_nrlanc = Convert.ToInt32(scd_nrlanc).ToString().PadLeft(7, '0');

            string sQuery = string.Format("select cd_nf from nfconhec where   cd_empresa = '{0}' and nr_lancconhecim = '{1}'", belStatic.CodEmpresaCte, scd_nrlanc);

            FbDataAdapter da = new FbDataAdapter(sQuery, cx.get_Conexao());
            dt.Clear();
            cx.Open_Conexao();
            da.Fill(dt);
            da.Dispose();

            string sretorno = "";

            foreach (DataRow item in dt.Rows)
            {
                sretorno += "- Nota nÂș" + item["cd_nf"].ToString();
            }
            return sretorno;
        }
Example #5
0
        public tcIdentificacaoRps BuscatcIdentificacaoRps(string sNotaFis)
        {
            belConnection cx = new belConnection();
            Globais objGlobais = new Globais();
            try
            {
                StringBuilder sQuery = new StringBuilder();
                sQuery.Append("select nf.cd_nfseq, nf.cd_notafis, coalesce(nf.cd_serie,'00001')cd_serie from nf ");
                sQuery.Append("where nf.cd_notafis = '" + sNotaFis + "' and ");
                sQuery.Append("nf.cd_empresa = '" + belStatic.codEmpresaNFe + "'");
                sQuery.Append(" and coalesce(nf.st_nf_prod,'S') = 'N'");
                sQuery.Append(" and nf.cd_gruponf = '" + objGlobais.LeRegConfig("GrupoServico") + "'");

                FbCommand Comand = new FbCommand(sQuery.ToString(), cx.get_Conexao());
                cx.Open_Conexao();
                Comand.ExecuteNonQuery();
                FbDataReader dr = Comand.ExecuteReader();
                dr.Read();

                tcIdentificacaoRps objtcIdentificacaoRps = new tcIdentificacaoRps();
                objtcIdentificacaoRps.Nfseq = dr["cd_nfseq"].ToString();
                objtcIdentificacaoRps.Numero = dr["cd_notafis"].ToString();
                objtcIdentificacaoRps.Serie = dr["cd_serie"].ToString();

                return objtcIdentificacaoRps;

            }
            catch (Exception)
            {
                throw new Exception("O Grupo de faturamento da nota " + sNotaFis + " deve ser igual ao Grupo de faturamento parametrizado no Config.");
            }
            finally { cx.Close_Conexao(); }
        }
Example #6
0
        private void AlteraDuplicataNumNFse(tcIdentificacaoRps objIdentRps, string sNotaFis)
        {
            Globais objGlobais = new Globais();
            belConnection cx = new belConnection();

            try
            {
                StringBuilder sQuery = new StringBuilder();
                sQuery.Append("UPDATE dupnotar SET dupnotar.cd_notafis = '" + sNotaFis + "' ");
                sQuery.Append("where dupnotar.cd_empresa = '" + belStatic.codEmpresaNFe + "' ");
                sQuery.Append("and dupnotar.cd_nfseq = '" + objIdentRps.Nfseq + "' ");
                sQuery.Append("and dupnotar.cd_gruponf = '" + objGlobais.LeRegConfig("GrupoServico") + "'");

                FbCommand cmd = new FbCommand(sQuery.ToString(), cx.get_Conexao());
                cx.Open_Conexao();
                cmd.ExecuteNonQuery();

            }
            catch (Exception)
            {
                throw;
            }
            finally
            { cx.Close_Conexao(); }
        }
Example #7
0
        private string retEmailDestinatario(string sNumCte)
        {
            belConnection cx = new belConnection();
            StringBuilder sQuery = new StringBuilder();

            string email = "";

            try
            {
                sQuery.Append("Select ");
                sQuery.Append("coalesce(remetent.cd_email,'')email ");
                sQuery.Append("from remetent ");
                sQuery.Append("join conhecim on remetent.cd_remetent = conhecim.cd_remetent ");
                sQuery.Append("where conhecim.cd_conheci  ='" + sNumCte + "'");


                FbCommand fbConn = new FbCommand(sQuery.ToString(), cx.get_Conexao());
                cx.Open_Conexao();
                fbConn.ExecuteNonQuery();
                FbDataReader dr = fbConn.ExecuteReader();
                dr.Read();
                email = dr["email"].ToString();

            }
            catch (Exception x)
            {
                throw new Exception(x.Message);
            }
            finally
            {
                cx.Close_Conexao();
            }

            return email;
        }
Example #8
0
        public static void CarregaConfiguracoesIniciais()
        {
            try
            {
                string sRetorno = string.Empty;
                Globais g = new Globais();
                string sEmpresa = g.LeRegConfig("Empresa");

                belConnection cx = new belConnection();
                using (FbCommand cmd = new FbCommand("select control.cd_conteud from control where control.cd_nivel = '0016'", cx.get_Conexao()))
                {
                    cx.Open_Conexao();
                    belStatic.sNomeEmpresa = Convert.ToString(cmd.ExecuteScalar()).Trim();
                    cx.Close_Conexao();
                }

                belStatic.psNM_Banco = g.LeRegConfig("BancoDados");

                belStatic.sTipoIndustrializacao = g.LeRegConfig("Industrializacao");

                string[] sRamo = belStatic.psNM_Banco.Split('\\');
                if (sRamo[sRamo.Count() - 1].ToUpper().Contains("TRANSPOR"))
                {
                    belStatic.RAMO = "TRANSPORTE";
                }
                else if (sRamo[sRamo.Count() - 1].ToUpper().Contains("INDUSTRI"))
                {
                    belStatic.RAMO = "INDUSTRIA";
                }
                else if (sRamo[sRamo.Count() - 1].ToUpper().Contains("COMERCIO"))
                {
                    belStatic.RAMO = "COMERCIO";
                }
                else if (sRamo[sRamo.Count() - 1].ToUpper().Contains("CERAMICA"))
                {
                    belStatic.RAMO = "CERAMICA";
                }

                StringBuilder sSql = new StringBuilder();
                if (belStatic.RAMO != "TRANSPORTE" && belStatic.RAMO != "")
                {
                    sSql.Append("Select ");
                    sSql.Append("empresa.nm_empresa, ");
                    sSql.Append("coalesce(empresa.st_ambiente_nfse,'2')st_ambiente_nfse, ");
                    sSql.Append("UF.nr_ufnfe, ");
                    sSql.Append("empresa.cd_cgc, ");
                    sSql.Append("coalesce(empresa.st_ambiente, '2') tpAmb ");
                    sSql.Append("from empresa ");
                    sSql.Append("left join uf on (uf.cd_uf = empresa.cd_ufnor) ");
                    sSql.Append("where ");
                    sSql.Append("cd_empresa ='");
                    sSql.Append(sEmpresa);
                    sSql.Append("'");
                }
                else
                {
                    sSql.Append("Select ");
                    sSql.Append("empresa.nm_empresa, ");
                    sSql.Append("empresa.cd_cgc, ");
                    sSql.Append("empresa.cd_ufnor, ");
                    sSql.Append("coalesce(empresa.st_ambiente, '2') tpAmb ");
                    sSql.Append("from empresa ");
                    sSql.Append("where ");
                    sSql.Append("cd_empresa ='");
                    sSql.Append(sEmpresa);
                    sSql.Append("'");
                }

                using (FbCommand cmd = new FbCommand(sSql.ToString(), cx.get_Conexao()))
                {
                    cx.Open_Conexao();
                    cmd.ExecuteNonQuery();
                    FbDataReader dr = cmd.ExecuteReader();
                    dr.Read();
                    cx.Close_Conexao();
                    belStatic.codEmpresaNFe = sEmpresa;
                    belStatic.TpAmb = Convert.ToInt16(dr["tpAmb"].ToString());
                    belStatic.sNomeEmpresaCompleto = dr["nm_empresa"].ToString();
                    belStatic.CNPJ_Empresa = dr["cd_cgc"].ToString();
                    if (belStatic.RAMO != "TRANSPORTE" && belStatic.RAMO != "")
                    {
                        belStatic.cUF = Convert.ToInt32(dr["nr_ufnfe"].ToString());
                        belStatic.tpAmbNFse = Convert.ToInt16(dr["st_ambiente_nfse"].ToString());
                    }
                    else
                    {
                        belUF objUf = new belUF();
                        objUf.SiglaUF = dr["cd_ufnor"].ToString();
                        belStatic.cUF = Convert.ToInt32(objUf.CUF);
                        belStatic.CodEmpresaCte = sEmpresa;
                    }
                }
            }
            catch (Exception ex)
            {
                throw;
            }
           
        }
Example #9
0
        public string GeraChave(string sEmp, string sNF)
        {
            belConnection ctx = new belConnection();
            try
            {
                StringBuilder sSql = new StringBuilder();
                sSql.Append("Select ");
                sSql.Append("uf.nr_ufnfe, ");
                sSql.Append("coalesce(nf.cd_serie, 1) serie, ");
                sSql.Append("nf.cd_notafis nNF, ");
                sSql.Append("nf.dt_emi dEmi, ");
                sSql.Append("empresa.cd_cgc CNPJ, ");
                sSql.Append("nf.cd_nfseq cNF ");
                sSql.Append(" From ");
                sSql.Append("NF ");
                sSql.Append("inner join empresa on (empresa.cd_empresa = nf.cd_empresa) ");
                sSql.Append("left join uf on (uf.cd_uf = empresa.cd_ufnor) ");
                sSql.Append("where ");
                sSql.Append("(nf.cd_empresa ='");
                sSql.Append(sEmp);
                sSql.Append("')");
                sSql.Append(" and ");
                sSql.Append("(nf.cd_nfseq = '");
                sSql.Append(sNF);
                sSql.Append("')");

                FbCommand sqlConsulta = new FbCommand(sSql.ToString(), ctx.get_Conexao());
                ctx.Open_Conexao();
                sqlConsulta.ExecuteNonQuery();
                FbDataReader drChave = sqlConsulta.ExecuteReader();
                drChave.Read();

                string scUF, sAAmM, sCNPJ, sMod, sSerie, snNF, tpemis, scNF;
                scUF = drChave["nr_ufnfe"].ToString().PadLeft(2, '0');
                sAAmM = drChave["demi"].ToString().Replace("/", "").Substring(6, 2).ToString() +
                        drChave["demi"].ToString().Replace("/", "").Substring(2, 2).ToString();
                sCNPJ = belUtil.TiraSimbolo(drChave["cnpj"].ToString(), "");
                sCNPJ = sCNPJ.PadLeft(14, '0');
                sMod = "55";
                tpemis = this.sFormaEmiNFe;

                Globais objGlobais = new Globais();

                if (Convert.ToBoolean(objGlobais.LeRegConfig("AtivaModuloScan")))
                {
                    sSerie = objGlobais.LeRegConfig("SerieScan");
                }
                else if (IsNumeric(drChave["serie"].ToString()))
                {
                    sSerie = drChave["serie"].ToString().PadLeft(3, '0');
                }
                else
                {
                    sSerie = "001";
                }
                snNF = drChave["nNF"].ToString().PadLeft(9, '0');
                scNF = drChave["cNF"].ToString().PadLeft(8, '0');

                string sChaveantDig = "";
                string sChave = "";
                string sDig = "";

                sChaveantDig = scUF.Trim() + sAAmM.Trim() + sCNPJ.Trim() + sMod.Trim() + sSerie.Trim() + snNF.Trim() + iStatusAtualSistema + scNF.Trim();//+ tpemis + scNF.Trim();
                sDig = CalculaDig11(sChaveantDig).ToString();

                sChave = sChaveantDig + sDig;

                return sChave;
            }
            catch (Exception)
            {
                throw;
            }
            finally { ctx.Close_Conexao(); }
        }