Example #1
0
        public static int retonarTpamb(string sEmp)
        {

            belConnection cx = new belConnection();
            int tp_amb;
            try
            {
                StringBuilder sSql = new StringBuilder();

                sSql.Append("select ");
                sSql.Append("empresa.st_ambiente ");
                sSql.Append("uf.nr_ufnfe cd_ufnor, ");
                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(sEmp);
                sSql.Append("'");

                FbCommand cmdIde = new FbCommand(sSql.ToString(), cx.get_Conexao());
                cx.Open_Conexao();
                cmdIde.ExecuteNonQuery();
                FbDataReader dr = cmdIde.ExecuteReader();
                dr.Read();
                tp_amb = Convert.ToInt16((dr["st_ambiente"].ToString() != "" ? dr["st_ambiente"].ToString() : "2"));
            }
            catch (Exception x)
            {
                throw new Exception("Erro de " + x.Source + Environment.NewLine + x.Message);
            }
            finally { cx.Close_Conexao(); }

            return tp_amb;

        }
Example #2
0
        public List<string> BuscaCodigoEmpresas()
        {
            List<string> slCodigos = new List<string>();
            belConnection cx = new belConnection();

            try
            {
                using (FbCommand cmd = new FbCommand("Select empresa.cd_empresa from empresa order by empresa.cd_empresa", cx.get_Conexao()))
                {
                    cx.Open_Conexao();
                    cmd.ExecuteNonQuery();
                    FbDataReader dr = cmd.ExecuteReader();
                    while (dr.Read())
                    {
                        slCodigos.Add(dr["cd_empresa"].ToString());
                    }
                }
            }
            catch (Exception ex)
            {
                throw;
            }
            finally
            {
                cx.Close_Conexao();
            }

            return slCodigos;
        }
Example #3
0
        public string RetPrestadorEmail()
        {
            belConnection cx = new belConnection();

            try
            {
                string sMsgPadraoEmail = "{5}Razão Social:{1}{0}{5}E-mail: {2}{0}{5}CCM :{3}{0}{5}CNPJ:{4}{0}{0}";
                StringBuilder sQuery = new StringBuilder();
                sQuery.Append(" select empresa.cd_cgc, empresa.cd_inscrmu, empresa.cd_email, empresa.nm_empresa from empresa ");
                sQuery.Append(" where empresa.cd_empresa = '" + belStatic.codEmpresaNFe + "'");
                FbCommand Comand = new FbCommand(sQuery.ToString(), cx.get_Conexao());
                cx.Open_Conexao();
                Comand.ExecuteNonQuery();
                FbDataReader dr = Comand.ExecuteReader();
                dr.Read();
                objtcIdentificacaoPrestador = new tcIdentificacaoPrestador();

                return string.Format(sMsgPadraoEmail, "<br>",
                                            dr["nm_empresa"].ToString(),
                                            dr["cd_email"].ToString(),
                                            dr["cd_inscrmu"].ToString(),
                                            dr["cd_cgc"].ToString(), "    ");
            }
            catch (Exception ex)
            {
                throw;
            }
            finally
            {
                cx.Close_Conexao();
            }
        }
Example #4
0
        public void BuscaUFeAmb()
        {

            belConnection cx = new belConnection();
            try
            {

                StringBuilder sSql = new StringBuilder();
                sSql.Append("Select ");
                sSql.Append("empresa.nm_empresa, ");
                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(belStatic.CodEmpresaCte);
                sSql.Append("'");

                using (FbCommand cmd = new FbCommand(sSql.ToString(), cx.get_Conexao()))
                {
                    cx.Open_Conexao();
                    cmd.ExecuteNonQuery();

                    FbDataReader dr = cmd.ExecuteReader();
                    while (dr.Read())
                    {

                        belStatic.Sigla_uf = dr["cd_ufnor"].ToString();
                        belStatic.TpAmb = Convert.ToInt32(dr["tpAmb"].ToString());
                        //belStatic.sNomeEmpresa = dr["nm_empresa"].ToString();
                    }
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally { cx.Close_Conexao(); }
        }
Example #5
0
        public bool VerificaEmailContador()
        {
            belConnection cx = new belConnection();
            try
            {
                StringBuilder sQuery = new StringBuilder();
                sQuery.Append("select coalesce(empresa.cd_emailcont,'')cd_emailcont ,  empresa.nm_empresa from empresa ");
                sQuery.Append("where empresa.cd_empresa = '" + belStatic.codEmpresaNFe + "'");
                FbCommand fbCom = new FbCommand(sQuery.ToString(), cx.get_Conexao());
                cx.Open_Conexao();
                FbDataReader dr = fbCom.ExecuteReader();
                dr.Read();
                string sEmailCont = dr["cd_emailcont"].ToString();

                if (sEmailCont.Equals(""))
                {
                    return false;
                    throw new Exception("Não existe nenhum e-mail de contador cadastrado nesse empresa");
                }
                else
                {
                    belStatic.sEmailContador = sEmailCont;
                    belStatic.sNomeEmpresaCompleto = dr["nm_empresa"].ToString();
                    return true;
                }

            }
            catch (Exception ex)
            {
                return false;
                throw ex;
            }
            finally
            {
                cx.Close_Conexao();
            }

        }
        private string geraChaveCanc(string sEmp, string sSeq)
        {
            belConnection cx = 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(sSeq);
                sSql.Append("')");

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

                GeraXMLExp objgeraxmlexp = new GeraXMLExp();

                string scUF, sAAmM, sCNPJ, sMod, sSerie, snNF, 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";

                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(9, '0');

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

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

                sChave = sChaveantDig + sDig;
                return sChave;
            }
            catch (Exception)
            {
                throw;
            }
            finally
            {
                cx.Close_Conexao();
            }
        }
        public List<string> VerificaPendenciasdeEnvio()
        {
            belConnection cx = new belConnection();
            try
            {
                List<string> ListaConhecimento = new List<string>();
                StringBuilder sQuery = new StringBuilder();
                sQuery.Append("Select conhecim.nr_lanc from conhecim ");
                sQuery.Append("where conhecim.st_contingencia ='S' ");
                sQuery.Append("and (conhecim.st_cte='N' or  conhecim.st_cte is null)");

                FbCommand fbConn = new FbCommand(sQuery.ToString(), cx.get_Conexao());
                cx.Open_Conexao();
                FbDataReader dr = fbConn.ExecuteReader();
                while (dr.Read())
                {
                    ListaConhecimento.Add(dr["nr_lanc"].ToString());
                }
                return ListaConhecimento;
            }
            catch (Exception ex)
            {
                cx.Close_Conexao();
                throw ex;
            }
            finally
            {
                cx.Close_Conexao();
            }
        }
 public string BuscaNumeroConhecimento(string sSeq)
 {
     belConnection cx = new belConnection();
     try
     {
         StringBuilder sQuery = new StringBuilder();
         sQuery.Append("Select  conhecim.cd_conheci ");
         sQuery.Append("from conhecim  ");
         sQuery.Append("where conhecim.nr_lanc ='" + sSeq + "' ");
         sQuery.Append("and conhecim.cd_empresa ='" + belStatic.CodEmpresaCte + "'");
         FbCommand fbConn = new FbCommand(sQuery.ToString(), cx.get_Conexao());
         cx.Open_Conexao();
         fbConn.ExecuteNonQuery();
         FbDataReader dr = fbConn.ExecuteReader();
         dr.Read();
         return dr["cd_conheci"].ToString();
     }
     catch (Exception ex)
     {
         throw ex;
     }
     finally
     {
         cx.Close_Conexao();
     }
 }
Example #9
0
        public void CarregaDadosEmpresa()
        {
            try
            {
                cx = new belConnection();
                string sQuery = "select empresa.nm_cidnor, empresa.cd_ufnor from empresa where empresa.cd_empresa ='" + belStatic.codEmpresaNFe + "'";
                FbCommand command = new FbCommand(sQuery, cx.get_Conexao());
                cx.Open_Conexao();
                command.ExecuteNonQuery();
                FbDataReader dr = command.ExecuteReader();
                dr.Read();
                List<string> ObjListCidadesNFse = new List<string>();
                ObjListCidadesNFse.Add("itu");
                ObjListCidadesNFse.Add("jundiai");
                belStatic.sNmCidadeEmpresa = dr["nm_cidnor"].ToString().ToUpper().Trim().ToLower();
                belStatic.sUF = dr["cd_ufnor"].ToString().ToUpper().Trim().ToUpper();
                belStatic.Sigla_uf = belStatic.sUF;
                belStatic.CodEmpresaCte = belStatic.codEmpresaNFe;
            }
            catch (Exception)
            {
                throw;
            }
            finally { cx.Close_Conexao(); }

        }
Example #10
0
        public void SalvaRetornoNotaDuplicada(string sRecibo, string sSeq)
        {
            belConnection cx = new belConnection();
            StringBuilder sSql = new StringBuilder();
            try
            {
                sSql.Append("UPDATE NF ");
                sSql.Append("set cd_recibonfe = '" + sRecibo + "' ");
                sSql.Append("where ");
                sSql.Append("cd_empresa ='");
                sSql.Append(belStatic.codEmpresaNFe);
                sSql.Append("' ");
                sSql.Append("and ");
                sSql.Append("cd_nfseq ='");
                sSql.Append(sSeq);
                sSql.Append("'");
                using (FbCommand cmdUpdate = new FbCommand(sSql.ToString(), cx.get_Conexao()))
                {
                    cx.Open_Conexao();
                    cmdUpdate.ExecuteNonQuery();
                }
            }
            catch (Exception)
            {
                throw;
            }
            finally { cx.Close_Conexao(); }

        }
Example #11
0
        private void btnAtualiza_Click(object sender, EventArgs e)
        {
            try
            {
                StringBuilder sSql = new StringBuilder();
                sSql.Append("SET GENERATOR gen_nomearqxml TO ");
                sSql.Append(nudNovo_Lote.Value.ToString().Trim());
                cx = new belConnection();
                using (FbCommand cmd = new FbCommand(sSql.ToString(), cx.get_Conexao()))
                {
                    cx.Open_Conexao();
                    cmd.ExecuteNonQuery();
                }
                CarregarDados();
            }
            catch (Exception)
            {
                throw;
            }
            finally { cx.Close_Conexao(); }

        }
Example #12
0
        public tcLoteRps BuscaDadosNFes(List<string> sListaNotas)
        {
            belConnection cx = new belConnection();            
            try
            {                
                objLoteRps = new tcLoteRps();

                objLoteRps.Rps = new List<TcRps>();
                foreach (string sNota in sListaNotas)
                {
                    TcRps objTcRps = new TcRps();

                    //IdentificacaoRps - TcIdentificacaoRps
                    daotcIdentificacaoRps objdaotcIdentificacaoRps = new daotcIdentificacaoRps();
                    objTcRps.InfRps = new TcInfRps();

                    StringBuilder sQuery = new StringBuilder();
                    sQuery.Append("SELECT   coalesce (tpdoc.cd_natureza_oper_nfse,'1')cd_natureza_oper_nfse , ");
                    sQuery.Append("coalesce (empresa.st_simples,'')st_simples , ");
                    sQuery.Append("coalesce (empresa.cd_regime_trib_especial,'0')RegimeEspecialTributacao , ");
                    sQuery.Append("coalesce (empresa.st_insentivador_cultural,'N')st_insentivador_cultural from nf ");
                    sQuery.Append("inner join tpdoc on nf.cd_tipodoc = tpdoc.cd_tipodoc ");
                    sQuery.Append("inner join empresa on empresa.cd_empresa = nf.cd_empresa ");
                    sQuery.Append(" where nf.cd_nfseq = '" + sNota + "' and ");
                    sQuery.Append(" nf.cd_empresa = '" + belStatic.codEmpresaNFe + "'");

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

                    
                    objTcRps.InfRps.DataEmissao = HLP.Util.Util.GetDateServidor();
                    objTcRps.InfRps.NaturezaOperacao = Convert.ToInt16(dr["cd_natureza_oper_nfse"].ToString());

                    objTcRps.InfRps.OptanteSimplesNacional = (dr["st_simples"].ToString().Equals("S") ? 1 : 2);
                    objTcRps.InfRps.IncentivadorCultural = (dr["st_insentivador_cultural"].ToString().Equals("S")?1:2);

                    objTcRps.InfRps.Status = 1;//Normal;

                    if (objTcRps.InfRps.OptanteSimplesNacional == 1)
                    {
                        objTcRps.InfRps.RegimeEspecialTributacao = Convert.ToInt16(dr["RegimeEspecialTributacao"].ToString());
                    }
                    else
                    {
                        objTcRps.InfRps.RegimeEspecialTributacao = 0;
                    }


                    objTcRps.InfRps.IdentificacaoRps = objdaotcIdentificacaoRps.BuscatcIdentificacaoRps(cx.get_Conexao(), sNota);


                    //RpsSubstituido - TcIdentificacaoRps // Método tratado na visualização da Nota;
                    //daoRpsSubstituido objdaoRpsSubstituido = new daoRpsSubstituido();
                    //objTcRps.InfRps.RpsSubstituido = objdaoRpsSubstituido.RetornaIdentificacaoRpds(Conn, sNota);

                    //Servico - TcDadosServico
                    daoServico objdaoServico = new daoServico();
                    objTcRps.InfRps.Servico = objdaoServico.RetornaDadosServico(cx.get_Conexao(), sNota, objTcRps.InfRps.NaturezaOperacao);


                    //Prestador - tcIdentificacaoPrestador
                    daoPrestador objdaoPrestador = new daoPrestador();
                    objTcRps.InfRps.Prestador = objdaoPrestador.RettcIdentificacaoPrestador(cx.get_Conexao(), sNota);
                    objLoteRps.Cnpj = objTcRps.InfRps.Prestador.Cnpj; // Tag Pai;
                    objLoteRps.InscricaoMunicipal = objTcRps.InfRps.Prestador.InscricaoMunicipal; //Tag Pai;


                    //Tomador - TcDadosTomador
                    daoTomador objdaoTomador = new daoTomador();
                    objTcRps.InfRps.Tomador = objdaoTomador.RettcDadosTomador(cx.get_Conexao(), sNota);

                    //IntermediarioServico - tcIdentificacaoIntermediarioServico  //Tratado na visualização da Nota
                    //daoIntermediarioServico objdaoIntermediarioServico = new daoIntermediarioServico();
                    //objTcRps.InfRps.IntermediarioServico = objdaoIntermediarioServico.RettcIdentificacaoIntermediarioServico(Conn, sNota);

                    //ConstrucaoCivil - TcDadosContrucaoCivil - Tratado na Visualização da Nota
                    if (belStatic.sNomeEmpresa.Equals("AENGE"))
                    {
                        daoConstrucaoCivil objdaoConstrucaoCivil = new daoConstrucaoCivil();
                        objTcRps.InfRps.ConstrucaoCivil = objdaoConstrucaoCivil.RettcDadosConstrucaoCivil(cx.get_Conexao(), sNota);                       
                    }
                    objLoteRps.Rps.Add(objTcRps);
                }
                daoUtil objdaoUtil = new daoUtil();
                objLoteRps.NumeroLote = objdaoUtil.RetornaProximoValorGenerator("GEN_LOTE_NFES", 15);
                objLoteRps.QuantidadeRps = objLoteRps.Rps.Count;

                return objLoteRps;
            }
            catch (Exception ex)
            {              
                throw ex;
            }
            finally
            {
                cx.Close_Conexao();
            }
        }
Example #13
0
        public void LimpaCampoRecibo(string sEmp, string sSeq)
        {
            belConnection cx = new belConnection();
            StringBuilder sSql = new StringBuilder();
            try
            {
                sSql.Append("update nf ");
                sSql.Append("set cd_recibonfe = null ");
                sSql.Append("where ");
                sSql.Append("cd_empresa ='");
                sSql.Append(sEmp);
                sSql.Append("' ");
                sSql.Append("and ");
                sSql.Append("cd_nfseq ='");
                sSql.Append(sSeq);
                sSql.Append("'");

                using (FbCommand cmdUpdate = new FbCommand(sSql.ToString(), cx.get_Conexao()))
                {
                    cx.Open_Conexao();
                    cmdUpdate.ExecuteNonQuery();
                }
            }
            catch (Exception)
            {
                throw;
            }
            finally
            {
                cx.Close_Conexao();
            }
        }
        private void NfeDadosMsg()
        {
            XmlSchemaCollection myschema = new XmlSchemaCollection();
            XmlValidatingReader reader;
            Globais sPath = new Globais();
            belConnection cx = new belConnection();
            try
            {
                StringBuilder sSql = new StringBuilder();
                sSql.Append("select ");
                sSql.Append("cd_chavenferet, ");
                sSql.Append("cd_nprotnfe ");
                sSql.Append("from nf ");
                sSql.Append("where ");
                sSql.Append("(cd_empresa = '");
                sSql.Append(_emp);
                sSql.Append("') ");
                sSql.Append("and ");
                sSql.Append("(cd_nfseq = '");
                sSql.Append(_seq);
                sSql.Append("')");




                FbCommand cmdcanc = new FbCommand(sSql.ToString(), cx.get_Conexao());
                cx.Open_Conexao();
                cmdcanc.ExecuteNonQuery();



                FbDataReader drCanc = cmdcanc.ExecuteReader();
                drCanc.Read();

                _chnfe = drCanc["cd_chavenferet"].ToString();
                _nprot = drCanc["cd_nprotnfe"].ToString();
                _id = "ID" + _chnfe;

                XNamespace xname = "http://www.portalfiscal.inf.br/nfe";
                XDocument xdoc = new XDocument(new XElement(xname + "cancNFe", new XAttribute("versao", _versaodados),
                                                   new XElement(xname + "infCanc", new XAttribute("Id", _id),
                                                       new XElement(xname + "tpAmb", _tpamb),
                                                       new XElement(xname + "xServ", _xserv),
                                                       new XElement(xname + "chNFe", _chnfe),
                                                       new XElement(xname + "nProt", _nprot),
                                                       new XElement(xname + "xJust", _xjust))));
                xdoc.Save(_spath + "\\" + _seq + "_ped-can.xml");

                AssinaNFeCancXml assinaCanc = new AssinaNFeCancXml();
                assinaCanc.ConfigurarArquivo(_spath + "\\" + _seq + "_ped-can.xml", "infCanc", _cert);

                StreamReader ler;

                ler = File.OpenText(_spath + "\\" + _seq + "_ped-can.xml");



                XmlParserContext context = new XmlParserContext(null, null, "", XmlSpace.None);

                reader = new XmlValidatingReader(ler.ReadToEnd().ToString(), XmlNodeType.Element, context);

                myschema.Add("http://www.portalfiscal.inf.br/nfe", belStaticPastas.SCHEMA_NFE + "\\cancNFe_v2.00.xsd");

                reader.ValidationType = ValidationType.Schema;

                reader.Schemas.Add(myschema);

                while (reader.Read())
                { }

            }
            catch (Exception x)
            {
                throw new Exception(x.Message);
            }
            finally { cx.Close_Conexao(); }
        }
Example #15
0
        public List<belNumeroNF> GeraNumeroNF(List<string> lsNFSEq, string sProximaNF, string sEmpresa)
        {
            belConnection cx = new belConnection();
            try
            {

                StringBuilder sSql = new StringBuilder();

                sSql.Append("select ");
                sSql.Append("nf.cd_nfseq ");
                sSql.Append("From nf ");
                sSql.Append("where ");
                sSql.Append("((nf.cd_notafis is null) or (nf.cd_notafis = '')) and (");
                sSql.Append("nf.cd_empresa ='");
                sSql.Append(sEmpresa);
                sSql.Append("') and (");
                sSql.Append("nf.cd_nfseq in('");
                int iCont = 0;
                foreach (var sNfseq in lsNFSEq)
                {
                    iCont++;
                    sSql.Append(sNfseq);
                    if (lsNFSEq.Count > iCont)
                    {
                        sSql.Append("','");
                    }
                }
                sSql.Append("')) ");
                sSql.Append("Order by nf.cd_empresa, nf.cd_nfseq ");



                //Fim - Claudinei - o.s. sem - 11/03/2010
                FbCommand cmd = new FbCommand(sSql.ToString(), cx.get_Conexao());
                cx.Open_Conexao();
                cmd.ExecuteNonQuery();

                FbDataReader dr = cmd.ExecuteReader();


                Int32 iNumeroNF = Convert.ToInt32(sProximaNF);

                List<belNumeroNF> objNumeroNFs = new List<belNumeroNF>();
                //dr = AcessoDados.ExecuteReader(sSql.ToString(), CommandType.Text);                  


                while (dr.Read())
                {

                    belNumeroNF objNumeroNF = new belNumeroNF();
                    objNumeroNF._nfseq = dr["cd_nfseq"].ToString();
                    objNumeroNF.Cdnotafis = iNumeroNF.ToString().PadLeft(6, '0');
                    objNumeroNFs.Add(objNumeroNF);

                    iNumeroNF++;

                }

                return objNumeroNFs;
            }
            catch (Exception)
            {
                throw;
            }
            finally { cx.Close_Conexao(); }

        }
Example #16
0
        public static DateTime GetDateServidor()
        {
            belConnection cx = new belConnection();

            try
            {
                using (FbCommand cmd = new FbCommand("Select current_timestamp d from empresa", cx.get_Conexao()))
                {
                    cx.Open_Conexao();
                    cmd.ExecuteNonQuery();
                    FbDataReader dr = cmd.ExecuteReader();
                    string d = "";
                    while (dr.Read())
                    {
                        d = dr["d"].ToString();
                        break;
                    }
                    DateTime dtRet = Convert.ToDateTime(d);
                    return dtRet;
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally { cx.Close_Conexao(); }
        }
Example #17
0
        /// <summary>
        /// Método Responsavel por gravar os campos cd_chavenferet e cd_nprotnfe. Responsavel tambem montar o TAG procNFe no xml e
        /// grava-lo na pasta de xml enviados.
        /// </summary>
        /// <param name="sEmp"></param>
        /// <param name="sSeq"></param>
        /// <param name="sNFe"></param>
        /// <param name="sChNfe"></param>
        /// <param name="sNProt"></param>
        /// <param name="xret"></param>
        /// <param name="glob"></param>
        /// <param name="pf"></param>
        public void geraProcNFe(string sSeq, string sNFe, string sChNfe, string sNProt,
                                XmlNode xret, XNamespace pf)//Danner - o.s. 24435 - 05/05/2010
        {
            Globais glob = new Globais();
            XDocument retcab = new XDocument();
            belConnection cx = new belConnection();
            try
            {
                //String sql que dará o update no campos: cd_recibonfe, cd_chavenferet, cd_nprotnfe.
                StringBuilder sSql = new StringBuilder();

                sSql.Append("update nf set cd_chavenferet ='");
                sSql.Append(sChNfe);
                sSql.Append("', ");
                sSql.Append("cd_nprotnfe ='");
                sSql.Append(sNProt);
                sSql.Append("' ");
                sSql.Append("Where nf.cd_empresa = '");
                sSql.Append(belStatic.codEmpresaNFe);
                sSql.Append("' and ");
                sSql.Append("nf.cd_nfseq ='");
                sSql.Append(sSeq);
                sSql.Append("'");

                using (FbCommand cmdUpdate = new FbCommand(sSql.ToString(), cx.get_Conexao()))
                {
                    cx.Open_Conexao();
                    cmdUpdate.ExecuteNonQuery();
                }
                //Geração do Xml da nfe Autorizado, incluindo a TAG infProc onde consta as informaçoes de retorno da nfe.
                XContainer retproc = new XElement(pf + "nfeProc", new XAttribute("versao", "2.00"),
                                                                     new XAttribute("xmlns", "http://www.portalfiscal.inf.br/nfe"));
                XElement retxml = XElement.Parse(sNFe);
                string sCodificacao = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>";
                string sRetProc = "<nfeProc versao=\"2.00\" xmlns=\"http://www.portalfiscal.inf.br/nfe\">";
                XmlDocument xmldocteste = new XmlDocument();
                xmldocteste.LoadXml(sNFe);
                DirectoryInfo dPastaData = new DirectoryInfo(belStaticPastas.ENVIADOS + "\\" + sChNfe.Substring(2, 4));
                if (!dPastaData.Exists) { dPastaData.Create(); }


                StreamWriter sw = new StreamWriter(belStaticPastas.ENVIADOS + "\\" + sChNfe.Substring(2, 4) + "\\" + sChNfe + "-nfe.xml"); //OS_25024

                if (@xmldocteste.FirstChild.Name.Equals("xml"))
                {
                    sw.Write(@sRetProc + @xmldocteste.OuterXml.Remove(0, 38) + @xret.OuterXml.ToString() + @"</nfeProc>");
                }
                else
                {
                    sw.Write(@sCodificacao + @sRetProc + @xmldocteste.OuterXml + @xret.OuterXml.ToString() + @"</nfeProc>");
                }
                sw.Close();

                //Geração do Xml da nfe Autorizado, incluindo a TAG infProc onde consta as informaçoes de retorno da nfe.
            }
            catch (Exception x)
            {
                throw new Exception("Erro na geração do XML Protocolado, infProt - " + x.Message);
            }
            finally
            {
                cx.Close_Conexao();
            }
        }
Example #18
0
        //Fim - Danner - o.s. 23732 - 11/11/2009
        //Danner - o.s. 23732 - 13/11/2009
        public static string retornaCdfunor(string sEmp)
        {

            belConnection cx = new belConnection();

            string cd_ufnor;
            try
            {
                StringBuilder sSql = new StringBuilder();
                sSql.Append("select ");
                sSql.Append("uf.nr_ufnfe cd_ufnor, ");
                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(sEmp);
                sSql.Append("'");
                FbCommand cmdIde = new FbCommand(sSql.ToString(), cx.get_Conexao());
                cx.Open_Conexao();
                cmdIde.ExecuteNonQuery();
                FbDataReader dr = cmdIde.ExecuteReader();
                dr.Read();
                cd_ufnor = dr["cd_ufnor"].ToString();
            }
            catch (Exception x)
            {
                throw new Exception("Erro de " + x.Source + Environment.NewLine + x.Message);
            }
            finally
            {
                cx.Close_Conexao();
            }
            return cd_ufnor;

        }
Example #19
0
        private string retEmailTransportador(string sSeq, string sEmp)
        {
            StringBuilder sSql = new StringBuilder();
            string email = "";
            belConnection cx = new belConnection();
            try
            {
                sSql.Append("select ");
                sSql.Append("transpor.cd_email ");
                sSql.Append("from ");
                sSql.Append("transpor inner join nf ");
                sSql.Append("on transpor.cd_trans = nf.cd_trans ");
                sSql.Append("where ");
                sSql.Append("nf.cd_empresa = '");
                sSql.Append(sEmp);
                sSql.Append("' ");
                sSql.Append("and ");
                sSql.Append("nf.cd_nfseq = '");
                sSql.Append(sSeq);
                sSql.Append("'");


                FbCommand sqlConsulta = new FbCommand(sSql.ToString(), cx.get_Conexao());
                cx.Open_Conexao();
                sqlConsulta.ExecuteNonQuery();

                FbDataReader drDest = sqlConsulta.ExecuteReader();
                drDest.Read();

                string[] split = drDest["cd_email"].ToString().Split(';');

                foreach (var i in split)
                {
                    email = i;
                    break;
                }
            }
            catch (Exception x)
            {
                throw new Exception(x.Message);
            }
            finally { cx.Close_Conexao(); }

            return email;
        }
Example #20
0
        private void populaComboGruposFat()
        {
            try
            {
                StringBuilder sQuery = new StringBuilder();
                sQuery.Append("select hlpstatus.ds_descvalor, hlpstatus.ds_valor FROM hlpstatus ");
                sQuery.Append("where hlpstatus.ds_referencia = 'CD_GRUPONF'");

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

                List<GruposFaturamento> objLista = new List<GruposFaturamento>();
                while (dr.Read())
                {
                    objLista.Add(new GruposFaturamento
                    {
                        ds_descvalor = dr["ds_valor"].ToString() + " - " + dr["ds_descvalor"].ToString(),
                        ds_valor = dr["ds_valor"].ToString()
                    });
                }
                cbxGruposServico.DataSource = objLista;
                cbxGruposServico.SelectedIndex = -1;
            }
            catch (Exception)
            {
                throw;
            }
            finally { cx.Close_Conexao(); }
        }
Example #21
0
        public void CarregarDados()
        {
            if (File.Exists(belStatic.Pasta_xmls_Configs + spath))
            {
                if (!spath.ToUpper().Equals("ESCRITA.XML"))
                {
                    try
                    {
                        populaComboGruposFat();
                        StringBuilder sSql = new StringBuilder();
                        sSql.Append("Select ");
                        sSql.Append("gen_id(gen_nomearqxml, 0) ");
                        sSql.Append("from rdb$database");
                        cx = new belConnection();
                        using (FbCommand cmd = new FbCommand(sSql.ToString(), cx.get_Conexao()))
                        {
                            cx.Open_Conexao();
                            lblAtual.Text = cmd.ExecuteScalar().ToString();
                        }
                    }
                    catch (FbException ex)
                    {
                        KryptonMessageBox.Show(string.Format("Erro.: {0}", ex.Message), "Atenção", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        lblAtual.Text = "Generator Inexistente!";
                    }
                    finally { cx.Close_Conexao(); }
                }

                XmlTextReader reader = new XmlTextReader(belStatic.Pasta_xmls_Configs + spath);
                cbxFormDanfe.SelectedIndex = 0;
                while (reader.Read())
                {
                    if ((reader.NodeType != XmlNodeType.Element) || !(reader.Name == "nfe_configuracoes"))
                    {
                        continue;
                    }
                    #region Campos
                    while (reader.Read())
                    {
                        if (reader.NodeType == XmlNodeType.Element)
                        {
                            if (reader.Name == "PastaXmlEnvio")
                            {
                                reader.Read();
                                txtEnvioArquivo.Text = reader.Value;
                            }
                            else
                            {
                                if (reader.Name == "PastaXmlEnviado")
                                {
                                    reader.Read();
                                    txtXmlEnviados.Text = reader.Value;
                                    continue;
                                }
                                //Danner - o.s. 23851 - 17/11/2009
                                if (reader.Name == "PastaXmlCancelados")
                                {
                                    reader.Read();
                                    txtXmlCancelados.Text = reader.Value;
                                    continue;
                                }
                                if (reader.Name == "PastaProtocolos")
                                {
                                    reader.Read();
                                    txtProtocolo.Text = reader.Value;
                                    continue;
                                }
                                if (reader.Name == "PastaContingencia")
                                {
                                    reader.Read();
                                    txtContingencia.Text = reader.Value;
                                    continue;
                                }
                                if (reader.Name == "PastaCCe")
                                {
                                    reader.Read();
                                    txtCCe.Text = reader.Value;
                                    continue;
                                }
                                if (reader.Name == "CaminhoPadrao")
                                {
                                    reader.Read();
                                    txtCaminhoPadrao.Text = reader.Value;
                                    continue;
                                }
                                if (reader.Name == "UsaRelatorioEspecifico")
                                {
                                    reader.Read();
                                    chkRelatorio.Checked = Convert.ToBoolean(reader.Value);
                                    continue;
                                }
                                if (reader.Name == "UsaDanfeSimplificada")
                                {
                                    reader.Read();
                                    ckbDanfeSimplificada.Checked = Convert.ToBoolean(reader.Value);
                                    continue;
                                }
                                if (reader.Name == "CaminhoRelatorioEspecifico")
                                {
                                    reader.Read();
                                    txtCaminhoPastaRelatorio.Text = reader.Value;
                                    continue;
                                }



                                //Claudinei - o.s. 23507 - 08/06/2009
                                if (reader.Name == "BancoDados")
                                {
                                    reader.Read();
                                    txtBancoDados.Text = reader.Value;
                                    continue;
                                }

                                if (reader.Name == "Servidor")
                                {
                                    reader.Read();
                                    txtServidor.Text = reader.Value;
                                    continue;
                                }
                                if (reader.Name == "Porta")
                                {
                                    reader.Read();
                                    txtPorta.Text = reader.Value;
                                    continue;
                                }

                                if (reader.Name == "Usuario")
                                {
                                    reader.Read();
                                    txtUsuario.Text = reader.Value;
                                    continue;
                                }

                                if (reader.Name == "Senha")
                                {
                                    reader.Read();
                                    txtSenha.Text = reader.Value;
                                    continue;
                                }
                                if (reader.Name == "Empresa")
                                {
                                    reader.Read();
                                    txtEmpresa.Text = reader.Value;
                                    continue;
                                }
                                //Danner - o.s. 23851 - 19/11/2009
                                if (reader.Name == "QtdeTentativas")
                                {
                                    reader.Read();
                                    nudQtdeTentativas.Value = Convert.ToInt16(reader.Value);
                                    continue;
                                }
                                if (reader.Name == "GravaNumNFseDupl")
                                {
                                    reader.Read();
                                    chkGravaNumNFseDup.Checked = Convert.ToBoolean(reader.Value);
                                    continue;
                                }
                                if (reader.Name == "GrupoServico")
                                {
                                    reader.Read();
                                    cbxGruposServico.SelectedValue = reader.Value.ToString();
                                    continue;
                                }

                                if (reader.Name == "Fuso")
                                {
                                    reader.Read();
                                    cbxFusoHorario.SelectedItem = reader.Value.ToString();
                                    continue;
                                }
                                if (reader.Name == "TipoImpressao")
                                {
                                    reader.Read();
                                    cbxFormDanfe.Text = reader.Value.ToString();
                                    continue;
                                }
                                if (reader.Name == "HostServidor")
                                {
                                    reader.Read();
                                    txtHostServidor.Text = reader.Value;
                                    continue;
                                }
                                if (reader.Name == "PortaServidor")
                                {
                                    reader.Read();
                                    numericUpDown1.Value = Convert.ToInt16(reader.Value);
                                    continue;
                                }

                                if (reader.Name == "EmailRemetente")
                                {
                                    reader.Read();
                                    txtEmailRemetente.Text = reader.Value;
                                    continue;
                                }
                                if (reader.Name == "SenhaRemetente")
                                {
                                    reader.Read();
                                    txtSenhaEmail.Text = reader.Value;
                                    continue;
                                }
                                //Danner - o.s. 24329 - 08/04/2010
                                if (reader.Name == "RequerSSL")
                                {
                                    reader.Read();
                                    ckbRequerSSL.Checked = (reader.Value == "True" ? true : false);
                                    continue;
                                }
                                //Fim - Danner - o.s. 24329 - 08/04/2010
                                if (reader.Name == "EmailAutomatico")
                                {
                                    reader.Read();
                                    ckbEmailAutomatico.Checked = (reader.Value == "True" ? true : false);
                                    continue;
                                }

                                if (reader.Name == "DestacaImpTribMun")
                                {
                                    reader.Read();
                                    chkTribMunicipio.Checked = (reader.Value == "True" ? true : false);
                                    continue;
                                }

                                if (reader.Name == "CodBarras")
                                {
                                    reader.Read();
                                    txtCaminhoBarrasTemp.Text = reader.Value;
                                    continue;
                                }

                                //Diego - o.s. 23723 - 06/11/2009
                                if (reader.Name == "Logotipo")
                                {
                                    reader.Read();
                                    txtCaminhoLogo.Text = reader.Value;
                                    continue;
                                }
                                //Fim - o.s. 23723 - 06/11/2009

                                // Diego - OS_24178 - 25/02/2010
                                if (reader.Name == "QtdeCasasProdutos")
                                {
                                    reader.Read();
                                    nupCasasQtdeProd.Value = Convert.ToInt16(reader.Value);
                                    continue;
                                }
                                if (reader.Name == "QtdeCasasVlUnit")
                                {
                                    reader.Read();
                                    nudQtd_Vl_unitario.Value = (Convert.ToInt16(reader.Value) > 1 ? Convert.ToInt16(reader.Value) : 2);
                                    continue;
                                }
                                // Diego - OS_24178 - 25/02/2010 - Fim

                                // Diego - O.S 24344 - 05/05/2010 
                                if (reader.Name == "VisualizaHoraDanfe")
                                {
                                    reader.Read();
                                    ckbHoraSaidaDanfe.Checked = (reader.Value == "True" ? true : false);
                                    continue;
                                }
                                if (reader.Name == "VisualizaDataDanfe")
                                {
                                    reader.Read();
                                    ckbDataSaidaDanfe.Checked = (reader.Value == "True" ? true : false);
                                    continue;
                                }
                                if (reader.Name == "CodBarrasXml")
                                {
                                    reader.Read();
                                    chkCodBarras.Checked = (reader.Value == "True" ? true : false);
                                    continue;
                                }
                                if (reader.Name == "TotalizaCFOP") //OS_25021
                                {
                                    reader.Read();
                                    chkTotCfop.Checked = (reader.Value == "True" ? true : false);
                                    continue;

                                }
                                if (reader.Name == "AtivaModuloScan")
                                {
                                    reader.Read();
                                    chkModuloScan.Checked = (reader.Value == "True" ? true : false);
                                    if (chkModuloScan.Checked)
                                    {
                                        nudScan.Enabled = true;
                                    }
                                    else
                                    {
                                        nudScan.Enabled = false;
                                    }
                                    continue;
                                } if (reader.Name == "SerieScan")
                                {
                                    reader.Read();
                                    nudScan.Value = Convert.ToDecimal(reader.Value);
                                    continue;
                                } if (reader.Name == "AtivaModuloContingencia")
                                {
                                    reader.Read();
                                    chkContingencia.Checked = (reader.Value == "True" ? true : false);
                                    continue;
                                }
                                if (reader.Name == "PastaArquivosEscritor")
                                {
                                    reader.Read();
                                    txtEscrituracao.Text = reader.Value.ToString().Trim();
                                }
                                if (reader.Name == "BancoEscritor")
                                {
                                    reader.Read();
                                    txtBancoEscritor.Text = reader.Value.ToString().Trim();
                                }
                                if (reader.Name == "ServidorEscritor")
                                {
                                    reader.Read();
                                    txtServidorEscritor.Text = reader.Value.ToString().Trim();
                                }
                            }
                        }
                    }
                    #endregion
                    reader.Close();
                }
            }

            if (cbxFusoHorario.Text == "")
            {
                cbxFusoHorario.SelectedItem = "-02:00";
            }

            // Diego - OS-24566 - 18/06/2010
            cbxIndustrializacao.SelectedIndex = 1;
            // Diego - OS-24566 - 18/06/2010 - FIM
        }
Example #22
0
        private void NotaDenegada(string sNfseq)
        {
            belConnection cx = new belConnection();

            try
            {
                string sSql = string.Format("UPDATE NF SET " +
                                                    "cd_recibonfe = 'denegada', " +
                                                    "st_nfe = 'S' " +
                                                    (belUtil.CampoExisteNaTabela("ST_DENEGADA", "NF") ? " ,ST_DENEGADA = 'S' " : "") +
                                                    (belUtil.CampoExisteNaTabela("CD_STDOC", "NF") ? " ,CD_STDOC = '04' " : "") +
                                                    "WHERE CD_NFSEQ = '{0}' AND CD_EMPRESA = '{1}'",
                                sNfseq,
                                belStatic.codEmpresaNFe);
                using (FbCommand cmdUpdate = new FbCommand(sSql.ToString(), cx.get_Conexao()))
                {
                    cx.Open_Conexao();
                    cmdUpdate.ExecuteNonQuery();
                }

            }
            catch (Exception ex)
            {
                throw;
            }
            finally { cx.Close_Conexao(); }

        }