private string geraChaveCanc(string sEmp, string sSeq)
        {
            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("')");

            belGerarXML BuscaConexao = new belGerarXML();

            FbConnection Conn = BuscaConexao.Conn;

            Conn.Open();

            FbCommand sqlConsulta = new FbCommand(sSql.ToString(), Conn);
            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 = objgeraxmlexp.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;

            Conn.Close();


            return sChave;
        }
示例#2
0
        public void populaTagInfNFe(dsDanfe dsdanfe, XmlDocument xml, string CodinfNfeId, int ihoraImpDanfe, int iDataImpDanfe)
        {
            XmlNodeList xNinfNFe = xml.GetElementsByTagName("infNFe");

            drInfNFe = dsdanfe.infNFe.NewinfNFeRow();

           HLP.bel.GeraXMLExp objbelGeraExp = new GeraXMLExp();


            if (xNinfNFe.Count > 0)
            {
                for (int i = 0; i < xNinfNFe.Count; i++)
                {
                    string InfNFeId = CodinfNfeId; //Codigo
                    // qtde de nodes 
                    for (int j = 0; j < xNinfNFe[i].Attributes.Count; j++)
                    {
                        populaDadosInfNFe(xNinfNFe[i].Attributes[j].LocalName, xNinfNFe[i].Attributes[j].Value, InfNFeId.ToString());
                    }

                    string sCodDadosNfe = objbelGeraExp.GeraChaveDadosNfe(i, xml);
                    dsdanfe.infNFe.AddinfNFeRow(drInfNFe);
                    drInfNFe = dsdanfe.infNFe.NewinfNFeRow();

                    // Diego - O.S 24205 - 02/03/2010 
                    if (dsdanfe.infNFe[Convert.ToInt16(CodinfNfeId) - 1].Id != "") // Diego - OS_24302 - 01/04/2010
                    {
                        XmlNodeList xDet = xml.GetElementsByTagName("det"); //Para Verificar a Qtde de Pag.
                        drCodigoBarras = dsdanfe.codigo_barras.Newcodigo_barrasRow();
                        drCodigoBarras.codId = Convert.ToInt32(InfNFeId);
                        drCodigoBarras.InfNFeId = InfNFeId.ToString();

                        // DIEGO - 05/05/2010
                        drCodigoBarras.horaImpDanfe = ihoraImpDanfe;
                        drCodigoBarras.dataImpDanfe = iDataImpDanfe;
                        // DIEGO - 05/05/2010 - FIM                       

                        Byte[] bimagem = SalvaCodBarras(dsdanfe.infNFe[Convert.ToInt16(CodinfNfeId) - 1].Id);
                        Byte[] bImagemDadosNfe = SalvaCodBarras(sCodDadosNfe);
                        drCodigoBarras.cod_Barras = bimagem;
                        drCodigoBarras.cod_BarrasContingenciaDadosNfe = bImagemDadosNfe;
                        drCodigoBarras.cod_DadosNfe = sCodDadosNfe;
                        // Diego - OS_24302 - 01/04/2010
                        if (xDet.Count < 19)
                        {
                            drCodigoBarras.qtdePagRetrato = "1";
                        }
                        else
                        {
                            double dx = (xDet.Count - 19) / 44.0;
                            int ix = (xDet.Count - 19) / 44;

                            if (dx == Convert.ToDouble(ix))
                            {
                                drCodigoBarras.qtdePagRetrato = ix.ToString();
                            }
                            else
                            {
                                drCodigoBarras.qtdePagRetrato = (ix + 2).ToString();
                            }                            
                        }
                        // Diego - OS_24302 - 01/04/2010 - fim
                        dsdanfe.codigo_barras.Addcodigo_barrasRow(drCodigoBarras);
                        drCodigoBarras = dsdanfe.codigo_barras.Newcodigo_barrasRow();
                    }
                    // Diego - O.S 24205 - 02/03/2010  - FIM
                }
            }
        }
示例#3
0
        private string CadastraCliFor(string psDoc)
        {
            string scdClifor = string.Empty;

            try
            {
                scdClifor = BuscaValorChavePrimaria("CLIFOR", 7, "cd_clifor", "Clifor", "");

                string sPEssoaj = (PessoaJuridica() == true ? "S" : "N");
                StringBuilder sInsert = new StringBuilder();
                sInsert.Append("Insert into ");
                sInsert.Append("Clifor (");
                sInsert.Append("cd_clifor, ");
                sInsert.Append("cd_alter, ");
                sInsert.Append("nm_clifor, ");
                sInsert.Append("nm_guerra, ");
                sInsert.Append("ds_endnor, ");
                sInsert.Append("nr_endnor, ");
                sInsert.Append("nm_bairronor, ");
                sInsert.Append("nm_cidnor, ");
                sInsert.Append("cd_ufnor, ");
                sInsert.Append("cd_cepnor, ");
                sInsert.Append("cd_fonenor, ");
                sInsert.Append("cd_catego, ");
                sInsert.Append("st_pessoaj, ");

                if (sPEssoaj == "S")
                {
                    sInsert.Append("cd_cgc, ");
                }
                else
                {
                    sInsert.Append("cd_cpf, ");
                }

                sInsert.Append("cd_insest, ");
                sInsert.Append("st_zfmalc ");
                sInsert.Append(") ");
                sInsert.Append("Values ('");
                sInsert.Append(scdClifor);
                sInsert.Append("', '");
                GeraXMLExp objGerarXMLExp = new GeraXMLExp(1);
                sInsert.Append(objGerarXMLExp.TiraSimbolo(psDoc, ""));
                sInsert.Append("', '");
                sInsert.Append(objInfNFe.BelDest.Xnome.ToString());
                sInsert.Append("', '");
                sInsert.Append(objInfNFe.BelDest.Xnome.ToString().Substring(0, 15));
                sInsert.Append("', '");
                sInsert.Append(objInfNFe.BelDest.Xlgr.ToString());
                sInsert.Append("', '");
                sInsert.Append(objInfNFe.BelDest.Nro.ToString());
                sInsert.Append("', '");
                if (objInfNFe.BelDest.Xbairro.ToString().Length > 20)
                {
                    objInfNFe.BelDest.Xbairro = objInfNFe.BelDest.Xbairro.ToString().Substring(0, 20);
                }
                sInsert.Append(objInfNFe.BelDest.Xbairro.ToString());
                sInsert.Append("', '");
                sInsert.Append(objInfNFe.BelDest.Xmun.ToString());
                sInsert.Append("', '");
                sInsert.Append(objInfNFe.BelDest.Uf.ToString());
                sInsert.Append("', '");
                sInsert.Append(objInfNFe.BelDest.Cep.ToString());
                sInsert.Append("', '");
                sInsert.Append((objInfNFe.BelDest.Fone != null ? objInfNFe.BelDest.Fone.ToString() : ""));
                sInsert.Append("', '");
                sInsert.Append(BuscaCategoria());
                sInsert.Append("', '");
                sInsert.Append(sPEssoaj);
                sInsert.Append("', '");
                sInsert.Append(psDoc);
                sInsert.Append("', '");
                sInsert.Append(objInfNFe.BelDest.Ie.ToString() != null ? objInfNFe.BelDest.Ie.ToString() : "Null");
                sInsert.Append("', '");
                sInsert.Append(objInfNFe.BelDest.Isuf != null ? "S" : "N");
                sInsert.Append("') ");

                using (FbCommand cmd = new FbCommand(sInsert.ToString(), Conexao))
                {
                    if (Conexao.State != ConnectionState.Open)
                    {
                        Conexao.Open();
                    }

                    cmd.ExecuteNonQuery();

                }

            }
            catch (Exception ex)
            {
                throw new Exception(string.Format("Não foi Possível incluir o Cliente/Fornecedor, CNPJ {0}, Erro.:{1}",
                                                  psDoc,
                                                  ex.Message));
            }
            finally
            {
                if (Conexao.State == ConnectionState.Open)
                {
                    Conexao.Close();
                }
            }
            return scdClifor;
        }
示例#4
0
        public string TipoLancamento()
        {
            try
            {
                string sTipoLancamento = string.Empty;
                string sCNPJempresa = "";
                using (FbCommand cmd = new FbCommand("select cd_cgc from empresa where cd_empresa ='" + objInfNFe.Empresa + "'", Conexao))
                {
                    if (Conexao.State != ConnectionState.Open)
                    {
                        Conexao.Open();
                    }
                    GeraXMLExp objGerarXMLExp = new GeraXMLExp();
                    sCNPJempresa = objGerarXMLExp.TiraSimbolo(cmd.ExecuteScalar().ToString(), "");
                    Conexao.Close();
                }

                //--->  0-Entrada / 1-Saída


                if (objInfNFe.BelIde.Tpnf == "0")
                {
                    sTipoLancamento = "E";
                    if (objInfNFe.BelEmit.Cnpj != null)
                    {
                        if (objInfNFe.BelEmit.Cnpj.ToString() == sCNPJempresa)
                        {
                            bProdutorRural = true;
                        }
                    }
                    else
                    {
                        string sInstrucao = string.Empty;
                        sInstrucao = "select cd_cpf from empresa where cd_empresa ='" + objInfNFe.Empresa + "'";
                        using (FbCommand cmd = new FbCommand(sInstrucao, Conexao))
                        {
                            if (Conexao.State != ConnectionState.Open)
                            {
                                Conexao.Open();
                            }
                            GeraXMLExp objGerarXMLExp = new GeraXMLExp();

                            string sCPF = objGerarXMLExp.TiraSimbolo(cmd.ExecuteScalar().ToString(), "");

                            if (sCPF == objInfNFe.BelEmit.Cpf.ToString())
                            {
                                sCPF = objInfNFe.BelEmit.Cpf;
                                bProdutorRural = true;
                            }
                        }
                    }
                }
                else
                {

                    if (objInfNFe.BelEmit.Cnpj != null)
                    {
                        if (objInfNFe.BelEmit.Cnpj.ToString() == sCNPJempresa)
                        {
                            sTipoLancamento = "S";
                        }
                    }
                    if (objInfNFe.BelDest.Cnpj != null)
                    {
                        if (objInfNFe.BelDest.Cnpj.ToString() == sCNPJempresa)
                        {
                            sTipoLancamento = "E";
                        }
                    }
                }
                return sTipoLancamento;
            }
            catch (Exception ex)
            {
                throw new Exception(string.Format("Não foi possivel definir o Tipo de Lançamento, Erro.: {0}",
                                                   ex.Message));
            }

            #region Codigo Comentado
            // string sTipoLancamento = string.Empty;

            // if (objInfNFe.BelIde.Tpnf == "0")
            // {
            //     sTipoLancamento = "S";
            // }
            // else
            // {
            //     sTipoLancamento = "E";
            // }



            //try
            //{
            //    if (sTipoLancamento == "E")
            //    {
            //        if (objInfNFe.BelEmit.Cnpj != null)
            //        {
            //            using (FbCommand cmd = new FbCommand("select cd_cgc from empresa where cd_empresa ='" + objInfNFe.Empresa + "'", Conexao))
            //            {
            //                if (Conexao.State != ConnectionState.Open)
            //                {
            //                    Conexao.Open();
            //                }
            //                GeraXMLExp objGerarXMLExp = new GeraXMLExp();

            //                string sCNPJ = objGerarXMLExp.TiraSimbolo(cmd.ExecuteScalar().ToString(), "");

            //                if (objInfNFe.BelEmit.Cnpj.ToString() == sCNPJ)
            //                {
            //                    bProdutorRural = true;
            //                }
            //            }
            //        }
            //        else
            //        {
            //            string sInstrucao = string.Empty;
            //            sInstrucao = "select cd_cpf from empresa where cd_empresa ='" + objInfNFe.Empresa + "'";
            //            using (FbCommand cmd = new FbCommand(sInstrucao, Conexao))
            //            {
            //                if (Conexao.State != ConnectionState.Open)
            //                {
            //                    Conexao.Open();
            //                }
            //                GeraXMLExp objGerarXMLExp = new GeraXMLExp();

            //                string sCPF = objGerarXMLExp.TiraSimbolo(cmd.ExecuteScalar().ToString(), "");

            //                if (sCPF == objInfNFe.BelEmit.Cpf.ToString())
            //                {
            //                    sCPF = objInfNFe.BelEmit.Cpf;
            //                    bProdutorRural = true;
            //                }
            //            }
            //        }                    
            //    }


            //    return sTipoLancamento;

            //}
            //catch (Exception ex)
            //{
            //    throw new Exception(string.Format("Não foi possivel definir o Tipo de Lançamento, Erro.: {0}",
            //                                       ex.Message));
            //}            
            #endregion
        }
示例#5
0
        private bool NotaSaida()
        {
            bool bSaida = false;
            try
            {
                StringBuilder sSql = new StringBuilder();
                string sDoc = string.Empty;

                sSql.Append("Select ");
                if (objInfNFe.BelDest.Cnpj != null)
                {
                    sSql.Append("cd_cgc ");
                }
                else
                {
                    sSql.Append("cd_CPF ");
                }
                sSql.Append("from Empresa ");
                sSql.Append("where cd_empresa = '");
                sSql.Append(objInfNFe.Empresa);
                sSql.Append("'");

                using (FbCommand cmd = new FbCommand(sSql.ToString(), Conexao))
                {
                    if (Conexao.State != ConnectionState.Open)
                    {
                        Conexao.Open();
                    }
                    GeraXMLExp objGerarXMLExp = new GeraXMLExp(1);

                    sDoc = objGerarXMLExp.TiraSimbolo(cmd.ExecuteScalar().ToString(), "");
                }

                if (objInfNFe.BelDest.Cnpj != null)
                {
                    if (sDoc == objInfNFe.BelDest.Cnpj)
                    {
                        bSaida = false;
                    }
                    else
                    {
                        bSaida = true;
                    }
                }
                else
                {
                    if (sDoc == objInfNFe.BelDest.Cpf)
                    {
                        bSaida = false;
                    }
                    else
                    {
                        bSaida = true;
                    }
                }

            }
            catch (Exception ex)
            {

                throw new Exception(string.Format("Não foi possivel definir se à Nota é de entrada ou saída. Erro {0}",
                                                   ex.Message));
            }
            finally
            {
                if (Conexao.State == ConnectionState.Open)
                {
                    Conexao.Close();
                }
            }
            return bSaida;
        }