Пример #1
0
        public belEscrituracao(belInfNFe pInfNFe, FbConnection pfbConexao)
        {
            bProdutorRural = false;
            objInfNFe = pInfNFe;
            string scdClifor = string.Empty;

            Conexao = pfbConexao;//MontaConexaoEscritor();


            if (objInfNFe.Empresa != null)
            {
                string sTipoLanc = TipoLancamento();
                string sDoc = string.Empty;

                #region Clientes/Fornecedores
                if (objInfNFe.BelDest.Cnpj != null)
                {
                    sDoc = FormataString(objInfNFe.BelDest.Cnpj.ToString(), "CNPJ");
                }
                else
                {
                    sDoc = FormataString(objInfNFe.BelDest.Cpf.ToString(), "CPF");
                }


                if (!RegistroExiste("CLIFOR", (objInfNFe.BelDest.Cnpj != null ? "CD_CGC = '" : "CD_CPF ='") + sDoc + "'", "CD_CLIFOR"))
                {

                    scdClifor = CadastraCliFor(sDoc);
                }
                else
                {
                    scdClifor = BuscaCodigoClifor(sDoc);
                }

                //OS_28165
                String sQuery = string.Format("UPDATE CLIFOR SET CD_MUNIC = '{0}' WHERE CD_CLIFOR = '{1}'", objInfNFe.BelDest.Cmun, scdClifor);
                using (FbCommand cmd = new FbCommand(sQuery, Conexao))
                {
                    if (Conexao.State != ConnectionState.Open)
                    {
                        Conexao.Open();
                    }
                    cmd.ExecuteNonQuery();
                }

                objInfNFe.Cdclifor = scdClifor;
                #endregion

                bool bSaida = true; //  NotaSaida();
                if (sTipoLanc == "E")
                {
                    bSaida = false;
                }
                Escritura(bSaida);



            }
        }
Пример #2
0
        public belInfNFe xmlBuscaInfNFe()
        {
            belInfNFe objInfNFe = new belInfNFe();

            return objInfNFe;

        }
Пример #3
0
        public belEscrituracao(belInfNFe pInfNFe, FbConnection pfbConexao)
        {
            bProdutorRural = false;
            objInfNFe = pInfNFe;
            string scdClifor = string.Empty;

            Conexao = pfbConexao;//MontaConexaoEscritor();


            if (objInfNFe.Empresa != null)
            {
                string sTipoLanc = TipoLancamento();
                string sDoc = string.Empty;

                #region Clientes/Fornecedores
                if (objInfNFe.BelDest.Cnpj != null)
                {
                    sDoc = FormataString(objInfNFe.BelDest.Cnpj.ToString(), "CNPJ");
                }
                else
                {
                    sDoc = FormataString(objInfNFe.BelDest.Cpf.ToString(), "CPF");
                }


                if (!RegistroExiste("CLIFOR", (objInfNFe.BelDest.Cnpj != null ? "CD_CGC = '" : "CD_CPF ='") + sDoc + "'", "CD_CLIFOR"))
                {

                    scdClifor = CadastraCliFor(sDoc);
                }
                else
                {
                    scdClifor = BuscaCodigoClifor(sDoc);
                }

                objInfNFe.Cdclifor = scdClifor;
                #endregion

                bool bSaida = true; //  NotaSaida();
                if (sTipoLanc == "E")
                {
                    bSaida = false;
                }
                Escritura(bSaida);



            }
        }
Пример #4
0
        public string BuscaCodigoClifor(string sDoc, belInfNFe objbelinf, bool bSaida)
        {
            string scdClifor = "";
            try
            {
                StringBuilder sCodigoCliente = new StringBuilder();
                sCodigoCliente.Append("Select ");
                sCodigoCliente.Append("cd_clifor ");
                sCodigoCliente.Append("from Clifor ");
                sCodigoCliente.Append("where ");
                if (!bSaida)
                {
                    sCodigoCliente.Append((objbelinf.BelEmit.Cnpj != null ? "cd_cgc" : "cd_cpf"));
                }
                else
                {
                    sCodigoCliente.Append((objbelinf.BelDest.Cnpj != null ? "cd_cgc" : "cd_cpf"));
                }
                sCodigoCliente.Append(" ='");
                sCodigoCliente.Append(sDoc);
                sCodigoCliente.Append("'");

                using (FbCommand cmd = new FbCommand(sCodigoCliente.ToString(), Conexao))
                {
                    if (Conexao.State != ConnectionState.Open)
                    {
                        Conexao.Open();
                    }
                    scdClifor = cmd.ExecuteScalar().ToString();
                }
            }
            catch (Exception)
            {
                return scdClifor;
            }
            finally
            {
                if (Conexao.State == ConnectionState.Open)
                {
                    Conexao.Close();
                }
            }
            return scdClifor;
        }
Пример #5
0
        public belInfNFe MontaInfNFe()
        {
            belInfNFe objInfNFe = null;
            if (xmlAnalizado())
            {
                objInfNFe = new belInfNFe();
                objInfNFe.Id = xmlBuscaId();
                objInfNFe.BelIde = xmlBuscaIde();
                objInfNFe.BelEmit = xmlBuscaEmit();
                objInfNFe.BelDest = xmlBuscaDest();
                objInfNFe.BelDet = xmlBuscaDet();
                objInfNFe.BelTotal = xmlBuscaTotal();
                objInfNFe.BelTransp = xmlBuscaTransp();
                objInfNFe.BelCobr = xmlBuscaCobr();
                objInfNFe.BelinfAdic = xmlBuscaInfAdic();
                objInfNFe.BelExporta = xmlBuscaExporta();
                objInfNFe.BelCompra = xmlBuscaCompra();
                objInfNFe.BelProtNFe = xmlBuscaProNFe();

            }
            //else
            //{
            //    throw new Exception("XML não pode ser Analisado");
            //} // Diego - tratar lista não validada
            return objInfNFe;
        }
Пример #6
0
        private void frmImportaEscritor_Load(object sender, EventArgs e)
        {


            belInfNFe objInfNFe = new belInfNFe();
            belConnection cx = new belConnection();
            fbConexao = cx.get_Conexao();

            belEscrituracao objEscrituracao = new belEscrituracao(objInfNFe, fbConexao);

            cbxEmpresas.DisplayMember = "Descricao";
            cbxEmpresas.ValueMember = "Codigo";

            cbxEmpresas.DataSource = objEscrituracao.RetornaEmpresa();

        }
Пример #7
0
        public string TipoLancamento(belInfNFe objInfNFe)
        {
            try
            {
                string sTipoLancamento = string.Empty;
                string sCNPJempresa = "";
                bool bProdutorRural = false;
                using (FbCommand cmd = new FbCommand("select cd_cgc from empresa where cd_empresa ='" + cbxEmpresas.SelectedValue.ToString() + "'", fbConexao))
                {
                    if (fbConexao.State != ConnectionState.Open)
                    {
                        fbConexao.Open();
                    }
                    GeraXMLExp objGerarXMLExp = new GeraXMLExp();
                    sCNPJempresa = belUtil.TiraSimbolo(cmd.ExecuteScalar().ToString(), "");
                    fbConexao.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, fbConexao))
                        {
                            if (fbConexao.State != ConnectionState.Open)
                            {
                                fbConexao.Open();
                            }
                            GeraXMLExp objGerarXMLExp = new GeraXMLExp();

                            string sCPF = belUtil.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));
            }
        }