コード例 #1
0
        public belIde xmlBuscaIde()
        {
            XmlDocument xIde = new XmlDocument();
            belIde objIde = new belIde();

            try
            {
                xIde.LoadXml(xDoc.GetElementsByTagName("ide")[0].OuterXml);


                objIde.Cuf = xIde.GetElementsByTagName("cUF")[0].InnerText;
                objIde.Mod = xIde.GetElementsByTagName("mod")[0].InnerText;
                objIde.Serie = xIde.GetElementsByTagName("serie")[0].InnerText;
                objIde.Nnf = xIde.GetElementsByTagName("nNF")[0].InnerText;
                objIde.Indpag = xIde.GetElementsByTagName("indPag")[0].InnerText;
                objIde.Demi = Convert.ToDateTime(xIde.GetElementsByTagName("dEmi")[0].InnerText);
                objIde.Dsaient = (xIde.GetElementsByTagName("dSaiEnt")[0] != null ? Convert.ToDateTime(xIde.GetElementsByTagName("dSaiEnt")[0].InnerText) : Convert.ToDateTime(xIde.GetElementsByTagName("dEmi")[0].InnerText));
                objIde.Tpnf = xIde.GetElementsByTagName("tpNF")[0].InnerText;

            }
            catch (Exception ex)
            {

                throw new Exception(string.Format("Problemas lendo a Tag IDE, Erro.: {0}",
                                                  ex.Message));
            }

            return objIde;
        }
コード例 #2
0
ファイル: belGerarxml.cs プロジェクト: dramosti/GeraXml_2.0
        public belIde BuscaIde(string sEmp,
                                    string sNF,
                                    string sForDanfe,
                                    string sFormaEmissao,
                                    Version versao)
        {
            //belGerarXML BuscaConexao = new belGerarXML();
            // FbConnection Conn = BuscaConexao.Conn;
            belIde objide = new belIde();
            try
            {
                StringBuilder sSql = new StringBuilder();
                //Campos do Select
                sSql.Append("Select First 1 ");
                sSql.Append("coalesce(tpdoc.st_ref_outra_nf,'S') st_ref_outra_nf, ");
                sSql.Append("uf.nr_ufnfe cUF, ");
                sSql.Append("nf.cd_nfseq cNF, ");
                sSql.Append("nf.ds_cfop natop, ");
                sSql.Append("coalesce(PRAZOS.ST_FPAGNFE,0) indPag, ");
                sSql.Append("'55' mod, ");
                sSql.Append("coalesce(nf.cd_serie, 1) serie, ");
                sSql.Append("nf.cd_notafis nNF, ");
                sSql.Append("nf.dt_emi dEmi, ");
                sSql.Append("nf.dt_sainf dSaiEnt, ");
                sSql.Append("case when tpdoc.tp_doc = 'NS' then '1' else '0' end tpNF, ");
                sSql.Append("cidades.cd_municipio cMunFg, ");
                sSql.Append("'1' tpImp, ");
                sSql.Append("'1' tpEmis, ");
                sSql.Append("coalesce(empresa.st_ambiente, '2') tpAmb, ");
                sSql.Append("case when tpdoc.st_nfcompl = 'S' then '2' else '1' end finNFe, ");
                sSql.Append("'0' procEmi, ");
                Globais LeRegWin = new Globais();
                string versionstring = versao.Major + "." + versao.Minor + "." + versao.Build + "." + versao.Revision;
                sSql.Append("'");
                sSql.Append(versionstring);
                sSql.Append("' verProc ");
                //Tabela
                sSql.Append("From NF ");
                //Relacionamentos
                sSql.Append("left join tpdoc on (tpdoc.cd_tipodoc = nf.cd_tipodoc)");
                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("left join cidades on (cidades.nm_cidnor = empresa.nm_cidnor)");
                sSql.Append(" and ");
                sSql.Append("(cidades.cd_ufnor = empresa.cd_ufnor) ");
                sSql.Append("left join  prazos on (prazos.cd_prazo = nf.cd_prazo)");
                //Where
                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("') ");
                // Conn.Open();

                FbCommand cmdIde = new FbCommand(sSql.ToString(), Conn);
                cmdIde.ExecuteNonQuery();
                FbDataReader drIde = cmdIde.ExecuteReader();
                drIde.Read();
                string sNFe = "NFe" + GeraChave(sEmp, sNF, Conn);
                objide = new belIde();
                objide.Cuf = drIde["cUF"].ToString();
                Int32 icNF = Convert.ToInt32(drIde["cNF"].ToString());
                objide.Cnf = icNF.ToString().PadLeft(8, '0'); // NFe_2.0
                string snatop = drIde["natop"].ToString();
                if (snatop.Length > 60)
                {
                    snatop = snatop.Substring(0, 59);
                }
                objide.Natop = TiraSimbolo(snatop, "");
                objide.Indpag = drIde["indPag"].ToString();
                objide.Mod = drIde["mod"].ToString();
                objide.Serie = (bModoSCAN == false ? drIde["serie"].ToString().Replace("U", "1") : iSerieSCAN.ToString());//Diego - OS_24580
                Int32 inNF = Convert.ToInt32(drIde["nNF"].ToString()); //Claudinei - o.s. 23630
                objide.Nnf = inNF.ToString().Trim();
                objide.Demi = System.DateTime.Parse(drIde["dEmi"].ToString());
                if (drIde["dSaiEnt"].ToString() != "")
                {
                    objide.Dsaient = System.DateTime.Parse(drIde["dSaiEnt"].ToString());
                    objide.HSaiEnt = System.DateTime.Parse(drIde["dSaiEnt"].ToString());
                }
                else
                {
                    objide.Dsaient = DateTime.Now;
                    objide.HSaiEnt = DateTime.Now;
                }
                objide.Tpnf = drIde["tpNF"].ToString();
                objide.Cmunfg = TiraSimbolo(drIde["cMunFG"].ToString(), "");
                objide.Tpimp = sForDanfe;
                objide.Tpemis = sFormaEmissao;
                objide.Cdv = sNFe.Substring((sNFe.Length - 1), 1);
                objide.Tpamb = drIde["tpAmb"].ToString();
                objide.Finnfe = drIde["finNFe"].ToString();
                objide.Procemi = drIde["procEmi"].ToString();
                objide.Verproc = drIde["verProc"].ToString();
                objide.bReferenciaNF = (drIde["st_ref_outra_nf"].ToString().Equals("N") ? false : true); //25360
            }
            catch (Exception Ex)
            {
                sExecao = " - Problemas na Identificação da Nota";
                throw new Exception(Ex.Message + sExecao);
            }
            //finally
            //{
            //    Conn.Close();
            //}
            return objide;


        }
コード例 #3
0
        private void Gravar()
        {
            List<object> lObj = new List<object>();
            try
            {
                #region IDE
                objide = new belIde();

                objide.Cuf = Convert.ToString(cbxUF.SelectedValue).Trim();
                objide.Cnf = txtSeq.Text;
                objide.Natop = txtNatOp.Text;
                objide.Indpag = Convert.ToString(cbxIndPag.SelectedIndex).Trim();
                objide.Mod = txtMod.Text.Trim();
                objide.Serie = txtSerie.Text.Trim();
                objide.Nnf = txtNNF.Text.Trim();
                objide.Demi = Convert.ToDateTime(mtbDEmi.Text);
                objide.Dsaient = Convert.ToDateTime(mtbDSaiEnt.Text);
                objide.Tpnf = Convert.ToString(cbxTpNF.SelectedIndex);
                objide.Cmunfg = txtCMunFG.Text.Trim();
                objide.Tpimp = Convert.ToString((int)cbxtpImp.SelectedIndex + 1);
                objide.Tpemis = Convert.ToString((int)cbcxTpEmis.SelectedIndex + 1);
                objide.Cdv = txtCDV.Text.Trim();
                objide.Tpamb = Convert.ToString((int)cbxTpAmb.SelectedIndex + 1);
                objide.Finnfe = Convert.ToString((int)cbxFinNFe.SelectedIndex + 1);
                objide.Procemi = txtProcEmi.Text.Trim();
                objide.Verproc = txtVerProc.Text.Trim();
                if (belNFrefBindingSource.Count > 0) // 25360
                {
                    List<belNFref> lObjNFref = new List<belNFref>();

                    for (int i = 0; i < belNFrefBindingSource.Count; i++)
                    {
                        lObjNFref.Add((belNFref)belNFrefBindingSource[i]);
                        if (lObjNFref[i].cUF != null)
                        {
                            if (!HLP.Util.Util.IsNumeric(lObjNFref[i].cUF))
                            {
                                belUF objuf = new belUF();
                                lObjNFref[i].cUF = objuf.RetornaCUF((lObjNFref[i].cUF));
                                lObjNFref[i].CNPJ = (lObjNFref[i].CNPJ).Replace(",", "").Replace("/", "").Replace("-", "");
                                lObjNFref[i].nNF = (Convert.ToInt32(lObjNFref[i].nNF)).ToString();
                            }
                        }

                    }
                    objide.belNFref = lObjNFref;
                }
                objide.HSaiEnt = dtpHSaiEnt.Value; //NFe_2.0

                lObj.Add(objide);
                #endregion

                #region Emitente
                belEmit objemit = new belEmit();

                if (cbxPessoaEmit.SelectedIndex == 0)
                {
                    objemit.Cpf = mtbCpfCnpjEmit.Text;
                }
                else
                {
                    objemit.Cnpj = mtbCpfCnpjEmit.Text;
                }
                objemit.Xnome = txtXNomeEmit.Text.Trim();
                objemit.Xfant = txtXFantEmit.Text.Trim();
                if (txtIEEmit.Text != "")
                {
                    objemit.Ie = txtIEEmit.Text.Trim();
                }
                if (txtIESTEmit.Text != "")
                {
                    objemit.Iest = txtIESTEmit.Text.Trim();
                }
                if (txtIM.Text != "")
                {
                    objemit.Im = txtIM.Text.Trim();
                }
                if (txtCNAE.Text != "")
                {
                    objemit.Cnae = txtCNAE.Text;
                }

                //Endereço

                objemit.Xlgr = txtEnderEmitXlgr.Text.Trim();
                objemit.Nro = txtEnderEmitNum.Text.Trim();
                if (txtEnderEmitCompl.Text != "")
                {
                    objemit.Xcpl = txtEnderEmitCompl.Text.Trim();
                }
                objemit.Xbairro = txtEnderEmitXbairro.Text.Trim();
                objemit.Cmun = txtEnderEmitCmun.Text.Trim();
                objemit.Xmun = txtEnderEmitXmun.Text.Trim();
                objemit.Uf = txtEnderEmitUF.Text.Trim();
                objemit.Cpais = txtEnderEmitCpais.Text.Trim();
                objemit.Xpais = txtEnderEmitXpais.Text.Trim();
                objemit.Cep = mtbEnderEmitCep.Text.Trim();
                objemit.Fone = mtbEnderEmitFone.Text.Trim();

                switch (cmbCRT.SelectedIndex) // NFe_2.0
                {
                    case 0: objemit.CRT = 1;
                        break;

                    case 1: objemit.CRT = 2;
                        break;

                    case 2: objemit.CRT = 3;
                        break;
                }

                //Fim - Endereço
                lObj.Add(objemit);
                #endregion

                #region Destinatário

                belDest objdest = new belDest();

                if (mtbCpfCnpjDest.Mask.Equals("00.000.000/0000-00") || mtbCpfCnpjDest.Text.ToString().ToUpper().Equals("EXTERIOR"))
                {
                    objdest.Cnpj = mtbCpfCnpjDest.Text.Trim();
                }
                else
                {
                    objdest.Cpf = mtbCpfCnpjDest.Text.Trim();
                }

                objdest.Xnome = (belStatic.TpAmb == 2 ? "NF-E EMITIDA EM AMBIENTE DE HOMOLOGACAO - SEM VALOR FISCAL"
                    : txtXnomeDest.Text.Trim());

                objdest.Ie = txtIEDest.Text.Trim();// (belStatic.tpAmb == 2 ? "" : txtIEDest.Text.Trim());
                if (txtISUFDest.Text != "")
                {
                    objdest.Isuf = txtISUFDest.Text.Trim();
                }

                //Endereço

                objdest.Xlgr = txtEnderDestXlgr.Text.Trim();
                objdest.Nro = txtEnderDestNro.Text.Trim();
                objdest.Xcpl = txtEnderDestCpl.Text.Trim(); //OS_26347
                objdest.Xbairro = txtEnderDestXbairro.Text.Trim();
                objdest.Cmun = txtEnderDestCmun.Text.Trim();
                objdest.Xmun = txtEnderDestXmun.Text.Trim();
                objdest.Uf = txtEnderDestUF.Text.Trim();
                objdest.Cpais = txtEnderDestCpais.Text.Trim();
                objdest.Xpais = txtEnderDestXpais.Text.Trim();
                objdest.Cep = mtbEnderDestCEP.Text.Trim();
                if (mtbEnderDestFone.Text.Trim() != "")
                {
                    objdest.Fone = mtbEnderDestFone.Text.Trim();
                }
                objdest.email = txtEmaildest.Text.Trim(); // NFe_2.0

                //Fim - Endereço
                lObj.Add(objdest);
                #endregion

                #region Endereço de Entrega
                belEndEnt objendent = new belEndEnt();
                if (mtbEndEntCNPJ.Text != "")
                {
                    objendent.Cnpj = mtbEndEntCNPJ.Text.Trim();
                    objendent.Xlgr = txtEndEntXlgr.Text.Trim();
                    objendent.Nro = txtEndEntNro.Text.Trim();
                    objendent.Cmun = txtEndEntCmun.Text.Trim();
                    objendent.Xmun = txtEndEntXmun.Text.Trim();
                    objendent.Uf = txtEndEntUF.Text.Trim();
                    objendent.Xbairro = txtEndEntXbairro.Text.Trim(); //0S_25185
                    objendent.Xcpl = txtEndEntCpl.Text.Trim();//0S_25185
                }
                lObj.Add(objendent);

                #endregion

                #region Detatalhes

                List<belDet> lObjDet = new List<belDet>();

                for (int i = 0; i < dgvDet.RowCount; i++)
                {
                    belDet objDet = new belDet();

                    objDet.Nitem = i + 1;

                    #region Prod
                    belProd objprod = new belProd();

                    objprod.Cean = Convert.ToString(dgvDet["Cean", i].Value);
                    objprod.Ceantrib = Convert.ToString(dgvDet["Ceantrib", i].Value);
                    objprod.Cfop = Convert.ToString(dgvDet["Cfop", i].Value);
                    objprod.Cprod = Convert.ToString(dgvDet["Cprod", i].Value);
                    if (dgvDet["Extipi", i].Value != null)
                    {
                        objprod.Extipi = Convert.ToString(dgvDet["Extipi", i].Value);
                    }
                    if (dgvDet["Genero", i].Value != null)
                    {
                        objprod.Genero = Convert.ToString(dgvDet["Genero", i].Value);
                    }
                    if (Convert.ToString(dgvDet["NCM", i].Value) != "")
                    {
                        objprod.Ncm = Convert.ToString(dgvDet["NCM", i].Value);
                    }
                    objprod.Qcom = Convert.ToDecimal(dgvDet["Qcom", i].Value);
                    objprod.Qtrib = Convert.ToDecimal(dgvDet["Qtrib", i].Value);
                    objprod.Ucom = Convert.ToString(dgvDet["Ucom", i].Value);
                    objprod.Utrib = Convert.ToString(dgvDet["Utrib", i].Value);
                    objprod.Vdesc = Convert.ToDecimal(dgvDet["Vdesc", i].Value);
                    objprod.Vfrete = Convert.ToDecimal(dgvDet["Vfrete", i].Value);
                    objprod.Vprod = Convert.ToDecimal(dgvDet["Vprod", i].Value);
                    objprod.Vseg = Convert.ToDecimal(dgvDet["Vseg", i].Value);
                    objprod.Vuncom = Convert.ToDecimal(dgvDet["Vuncom", i].Value);
                    objprod.Vuntrib = Convert.ToDecimal(dgvDet["Vuntrib", i].Value);
                    objprod.Xprod = Convert.ToString(dgvDet["Xprod", i].Value);
                    objprod.VOutro = Convert.ToDecimal(dgvDet["vOutro", i].Value);// NFe_2.0
                    objprod.IndTot = Convert.ToInt16(dgvDet["indTot", i].Value); // NFe_2.0
                    objprod.XPed = dgvDet["xPed", i].Value.ToString();
                    objprod.NItemPed = dgvDet["nItemPed", i].Value.ToString();

                    objDet.belProd = objprod;

                    objDet.belProd.belDI = ((List<belDet>)lObjTotNotas[notAtual - 1][4])[i].belProd.belDI;
                    #endregion

                    #region Imposto

                    belImposto objimposto = new belImposto();


                    #region ICMS

                    belIcms objicms = new belIcms();

                    if (!HLP.Util.Util.VerificaNovaST(Convert.ToString(dgvDet["CstIcms", i].Value)))
                    {
                        #region cst_antigas
                        switch (Convert.ToString(dgvDet["CstIcms", i].Value))
                        {

                            case "00":
                                {
                                    belIcms00 obj00 = new belIcms00();

                                    obj00.Cst = Convert.ToString(dgvDet["CstIcms", i].Value);
                                    obj00.Modbc = Convert.ToString(dgvDet["ModbcIcms", i].Value);
                                    obj00.Orig = Convert.ToString(dgvDet["OrigIcms", i].Value);
                                    obj00.Picms = Convert.ToDecimal(dgvDet["PicmsIcms", i].Value);
                                    obj00.Vbc = Convert.ToDecimal(dgvDet["VbcIcms", i].Value);
                                    obj00.Vicms = Convert.ToDecimal(dgvDet["VicmsIcms", i].Value);
                                    objicms.belIcms00 = obj00;
                                    break;
                                }
                            case "10":
                                {
                                    belIcms10 obj10 = new belIcms10();

                                    obj10.Cst = Convert.ToString(dgvDet["CstIcms", i].Value);
                                    obj10.Modbc = Convert.ToString(dgvDet["ModbcIcms", i].Value);
                                    obj10.Modbcst = Convert.ToDecimal(dgvDet["ModbcstIcms", i].Value);
                                    obj10.Orig = Convert.ToString(dgvDet["OrigIcms", i].Value);
                                    obj10.Picms = Convert.ToDecimal(dgvDet["PicmsIcms", i].Value);
                                    obj10.Picmsst = Convert.ToDecimal(dgvDet["PicmsstIcms", i].Value);
                                    obj10.Pmvast = Convert.ToDecimal(dgvDet["PmvastIcms", i].Value);
                                    obj10.Predbcst = Convert.ToDecimal(dgvDet["PredbcstIcms", i].Value);
                                    obj10.Vbc = Convert.ToDecimal(dgvDet["VbcIcms", i].Value);
                                    obj10.Vbcst = Convert.ToDecimal(dgvDet["VbcstIcms", i].Value);
                                    obj10.Vicms = Convert.ToDecimal(dgvDet["VicmsIcms", i].Value);
                                    obj10.Vicmsst = Convert.ToDecimal(dgvDet["VicmsstIcms", i].Value);
                                    objicms.belIcms10 = obj10;
                                    break;
                                }
                            case "20":
                                {
                                    belIcms20 obj20 = new belIcms20();
                                    obj20.Cst = Convert.ToString(dgvDet["CstIcms", i].Value);
                                    obj20.Modbc = Convert.ToString(dgvDet["ModbcIcms", i].Value);
                                    obj20.Orig = Convert.ToString(dgvDet["OrigIcms", i].Value);
                                    obj20.Picms = Convert.ToDecimal(dgvDet["PicmsIcms", i].Value);
                                    obj20.Predbc = Convert.ToDecimal(dgvDet["PredbcIcms", i].Value);
                                    obj20.Vbc = Convert.ToDecimal(dgvDet["VbcIcms", i].Value);
                                    obj20.Vicms = Convert.ToDecimal(dgvDet["VicmsIcms", i].Value);
                                    objicms.belIcms20 = obj20;
                                    break;
                                }
                            case "30":
                                {
                                    belIcms30 obj30 = new belIcms30();

                                    obj30.Cst = Convert.ToString(dgvDet["CstIcms", i].Value);
                                    obj30.Modbcst = Convert.ToDecimal(dgvDet["ModbcstIcms", i].Value);
                                    obj30.Orig = Convert.ToString(dgvDet["OrigIcms", i].Value);
                                    obj30.Picmsst = Convert.ToDecimal(dgvDet["PicmsstIcms", i].Value);
                                    obj30.Pmvast = Convert.ToDecimal(dgvDet["PmvastIcms", i].Value);
                                    obj30.Predbcst = Convert.ToDecimal(dgvDet["PredbcstIcms", i].Value);
                                    obj30.Vbcst = Convert.ToDecimal(dgvDet["VbcstIcms", i].Value);
                                    obj30.Vicmsst = Convert.ToDecimal(dgvDet["VicmsIcms", i].Value);
                                    objicms.belIcms30 = obj30;

                                    break;
                                }
                            case "40":
                                {
                                    belIcms40 obj40 = new belIcms40();

                                    obj40.Cst = Convert.ToString(dgvDet["CstIcms", i].Value);
                                    obj40.Orig = Convert.ToString(dgvDet["OrigIcms", i].Value);

                                    obj40.Vicms = Convert.ToDecimal(dgvDet["VicmsIcms", i].Value); //NFe_2.0
                                    obj40.motDesICMS = Convert.ToInt16(dgvDet["motDesICMS", i].Value);//NFe_2.0

                                    objicms.belIcms40 = obj40;
                                    break;
                                }
                            case "41":
                                {
                                    belIcms40 obj40 = new belIcms40();

                                    obj40.Cst = Convert.ToString(dgvDet["CstIcms", i].Value);
                                    obj40.Orig = Convert.ToString(dgvDet["OrigIcms", i].Value);
                                    obj40.Vicms = Convert.ToDecimal(dgvDet["VicmsIcms", i].Value); //NFe_2.0
                                    obj40.motDesICMS = Convert.ToInt16(dgvDet["motDesICMS", i].Value);//NFe_2.0
                                    objicms.belIcms40 = obj40;
                                    break;
                                }
                            case "50":
                                {
                                    belIcms40 obj40 = new belIcms40();

                                    obj40.Cst = Convert.ToString(dgvDet["CstIcms", i].Value);
                                    obj40.Orig = Convert.ToString(dgvDet["OrigIcms", i].Value);
                                    obj40.Vicms = Convert.ToDecimal(dgvDet["VicmsIcms", i].Value); //NFe_2.0
                                    obj40.motDesICMS = Convert.ToInt16(dgvDet["motDesICMS", i].Value);//NFe_2.0
                                    objicms.belIcms40 = obj40;
                                    break;

                                }
                            case "51":
                                {
                                    belIcms51 obj51 = new belIcms51();

                                    obj51.Cst = Convert.ToString(dgvDet["CstIcms", i].Value);
                                    obj51.Modbc = Convert.ToString(dgvDet["ModbcIcms", i].Value);
                                    obj51.Orig = Convert.ToString(dgvDet["OrigIcms", i].Value);
                                    obj51.Picms = Convert.ToDecimal(dgvDet["PicmsIcms", i].Value);
                                    obj51.Predbc = Convert.ToDecimal(dgvDet["PredbcIcms", i].Value);
                                    obj51.Vbc = Convert.ToDecimal(dgvDet["VbcIcms", i].Value);
                                    obj51.Vicms = Convert.ToDecimal(dgvDet["VicmsIcms", i].Value);
                                    objicms.belIcms51 = obj51;
                                    break;
                                }
                            //Fim - Danner - o.s. 24189 - 26/02/2010
                            case "60":
                                {
                                    belIcms60 obj60 = new belIcms60();
                                    obj60.Cst = Convert.ToString(dgvDet["CstIcms", i].Value);
                                    obj60.Orig = Convert.ToString(dgvDet["OrigIcms", i].Value);
                                    obj60.Vbcst = Convert.ToDecimal(dgvDet["VbcstIcms", i].Value);
                                    obj60.Vicmsst = Convert.ToDecimal(dgvDet["VicmsstIcms", i].Value);
                                    objicms.belIcms60 = obj60;
                                    break;
                                }
                            case "70":
                                {
                                    belIcms70 obj70 = new belIcms70();
                                    obj70.Cst = Convert.ToString(dgvDet["CstIcms", i].Value);
                                    obj70.Modbc = Convert.ToString(dgvDet["ModbcIcms", i].Value);
                                    obj70.Modbcst = Convert.ToDecimal(dgvDet["ModbcstIcms", i].Value);
                                    obj70.Orig = Convert.ToString(dgvDet["OrigIcms", i].Value);
                                    obj70.Picms = Convert.ToDecimal(dgvDet["PicmsIcms", i].Value);
                                    obj70.Picmsst = Convert.ToDecimal(dgvDet["PicmsstIcms", i].Value);
                                    obj70.Pmvast = Convert.ToDecimal(dgvDet["PmvastIcms", i].Value);
                                    obj70.Predbc = Convert.ToDecimal(dgvDet["PredbcIcms", i].Value);
                                    obj70.Predbcst = Convert.ToDecimal(dgvDet["PredbcstIcms", i].Value);
                                    obj70.Vbc = Convert.ToDecimal(dgvDet["VbcIcms", i].Value);
                                    obj70.Vbcst = Convert.ToDecimal(dgvDet["VbcstIcms", i].Value);
                                    obj70.Vicms = Convert.ToDecimal(dgvDet["VicmsIcms", i].Value);
                                    obj70.Vicmsst = Convert.ToDecimal(dgvDet["VicmsstIcms", i].Value);
                                    objicms.belIcms70 = obj70;
                                    break;
                                }
                            case "90":
                                {
                                    belIcms90 obj90 = new belIcms90();

                                    obj90.Cst = Convert.ToString(dgvDet["CstIcms", i].Value);
                                    obj90.Modbc = Convert.ToString(dgvDet["ModbcIcms", i].Value);
                                    obj90.Modbcst = Convert.ToDecimal(dgvDet["ModbcstIcms", i].Value);
                                    obj90.Orig = Convert.ToString(dgvDet["OrigIcms", i].Value);
                                    obj90.Picms = Convert.ToDecimal(dgvDet["PicmsIcms", i].Value);
                                    obj90.Picmsst = Convert.ToDecimal(dgvDet["PicmsstIcms", i].Value);
                                    obj90.Pmvast = Convert.ToDecimal(dgvDet["PmvastIcms", i].Value);
                                    obj90.Predbc = Convert.ToDecimal(dgvDet["PredbcIcms", i].Value);
                                    obj90.Predbcst = Convert.ToDecimal(dgvDet["PredbcstIcms", i].Value);
                                    obj90.Vbc = Convert.ToDecimal(dgvDet["VbcIcms", i].Value);
                                    obj90.Vbcst = Convert.ToDecimal(dgvDet["VbcstIcms", i].Value);
                                    obj90.Vicms = Convert.ToDecimal(dgvDet["VicmsIcms", i].Value);
                                    obj90.Vicmsst = Convert.ToDecimal(dgvDet["VicmsstIcms", i].Value);

                                    objicms.belIcms90 = obj90;
                                    break;
                                }
                        }
                        #endregion
                    }
                    else
                    {
                        #region cst_novas
                        switch (HLP.Util.Util.RetornaSTnovaAserUsada(Convert.ToString(dgvDet["CstIcms", i].Value)))
                        {
                            case "101":
                                {
                                    belICMSSN101 obj101 = new belICMSSN101();

                                    obj101.CSOSN = Convert.ToString(dgvDet["CstIcms", i].Value);
                                    obj101.orig = Convert.ToString(dgvDet["OrigIcms", i].Value);
                                    obj101.pCredSN = Convert.ToDecimal(dgvDet["pCredSN", i].Value);
                                    obj101.vCredICMSSN = Convert.ToDecimal(dgvDet["vCredICMSSN", i].Value);
                                    objicms.belICMSSN101 = obj101;
                                    break;
                                }
                            case "102":
                                {
                                    belICMSSN102 obj102 = new belICMSSN102();
                                    obj102.CSOSN = Convert.ToString(dgvDet["CstIcms", i].Value);
                                    obj102.orig = Convert.ToString(dgvDet["OrigIcms", i].Value);
                                    objicms.belICMSSN102 = obj102;
                                    break;
                                }
                            case "201":
                                {
                                    belICMSSN201 obj201 = new belICMSSN201();

                                    obj201.CSOSN = Convert.ToString(dgvDet["CstIcms", i].Value);
                                    obj201.orig = Convert.ToString(dgvDet["OrigIcms", i].Value);
                                    obj201.modBCST = Convert.ToInt32(dgvDet["ModbcstIcms", i].Value);
                                    obj201.pMVAST = Convert.ToDecimal(dgvDet["PmvastIcms", i].Value);
                                    obj201.pRedBCST = Convert.ToDecimal(dgvDet["PredbcstIcms", i].Value);
                                    obj201.vBCST = Convert.ToDecimal(dgvDet["VbcstIcms", i].Value);
                                    obj201.pICMSST = Convert.ToDecimal(dgvDet["PicmsstIcms", i].Value);
                                    obj201.vICMSST = Convert.ToDecimal(dgvDet["VicmsstIcms", i].Value);

                                    if (Convert.ToString(dgvDet["CstIcms", i].Value).Equals("101"))
                                    {
                                        obj201.pCredSN = Convert.ToDecimal(dgvDet["pCredSN", i].Value);
                                        obj201.vCredICMSSN = Convert.ToDecimal(dgvDet["vCredICMSSN", i].Value);
                                    }
                                    objicms.belICMSSN201 = obj201;
                                    break;
                                }
                            case "500":
                                {
                                    belICMSSN500 obj500 = new belICMSSN500();
                                    obj500.CSOSN = Convert.ToString(dgvDet["CstIcms", i].Value);
                                    obj500.orig = Convert.ToString(dgvDet["OrigIcms", i].Value);
                                    obj500.vBCSTRet = Convert.ToDecimal(dgvDet["VbcstIcms", i].Value);
                                    obj500.vICMSSTRet = Convert.ToDecimal(dgvDet["VicmsstIcms", i].Value);
                                    objicms.belICMSSN500 = obj500;
                                    break;
                                }
                            case "900":
                                {
                                    belICMSSN900 obj900 = new belICMSSN900();
                                    obj900.CSOSN = Convert.ToString(dgvDet["CstIcms", i].Value);
                                    obj900.orig = Convert.ToString(dgvDet["OrigIcms", i].Value);
                                    //obj900.modBC = Convert.ToInt32(dgvDet["ModbcIcms", i].Value);
                                    //obj900.vBC = Convert.ToDecimal(dgvDet["VbcIcms", i].Value);
                                    //obj900.pRedBC = Convert.ToDecimal(dgvDet["VicmsstIcms", i].Value);
                                    //obj900.pICMS = Convert.ToDecimal(dgvDet["PicmsIcms", i].Value);
                                    //obj900.vICMS = Convert.ToDecimal(dgvDet["VicmsIcms", i].Value);
                                    //obj900.modBCST = Convert.ToInt32(dgvDet["ModbcstIcms", i].Value);
                                    //obj900.pMVAST = Convert.ToDecimal(dgvDet["PmvastIcms", i].Value);
                                    //obj900.pRedBCST = Convert.ToDecimal(dgvDet["PredbcstIcms", i].Value);
                                    //obj900.vBCST = Convert.ToDecimal(dgvDet["VbcstIcms", i].Value);
                                    //obj900.pICMSST = Convert.ToDecimal(dgvDet["PicmsstIcms", i].Value);
                                    //obj900.vICMSST = Convert.ToDecimal(dgvDet["VicmsstIcms", i].Value);
                                    //obj900.vBCSTRet = Convert.ToDecimal(dgvDet["VbcstIcms", i].Value);
                                    //obj900.vICMSSTRet = Convert.ToDecimal(dgvDet["VicmsstIcms", i].Value);
                                    //obj900.pCredSN = Convert.ToDecimal(dgvDet["pCredSN", i].Value);
                                    //obj900.vCredICMSSN = Convert.ToDecimal(dgvDet["vCredICMSSN", i].Value);
                                    objicms.belICMSSN900 = obj900;
                                    break;
                                }
                        }
                        #endregion
                    }


                    objimposto.belIcms = objicms;

                    #endregion

                    #region IPI

                    belIpi objipi = new belIpi();
                    objipi.Cenq = Convert.ToString(dgvDet["CenqIpi", i].Value);

                    string sCSTIPI = Convert.ToString(dgvDet["CstIpi", i].Value);


                    if (sCSTIPI == "00" || sCSTIPI == "49" || sCSTIPI == "50" || sCSTIPI == "99")
                    {
                        belIpitrib objipitrib = new belIpitrib();

                        objipitrib.Cst = sCSTIPI;
                        objipitrib.Pipi = Convert.ToDecimal(dgvDet["PipiTrib", i].Value);
                        if (Convert.ToDecimal(dgvDet["QunidIpiTrib", i].Value) != 0)
                        {
                            objipitrib.Qunid = Convert.ToString(dgvDet["QunidIpiTrib", i].Value);
                        }
                        objipitrib.Vbc = Convert.ToDecimal(dgvDet["VbcIpiTrib", i].Value);
                        objipitrib.Vipi = Convert.ToDecimal(dgvDet["VipiTrib", i].Value); //Claudinei - o.s. 24192 - 01/03/2010
                        objipitrib.Vunid = Convert.ToDecimal(dgvDet["VunidTrib", i].Value);
                        objipi.belIpitrib = objipitrib;
                    }
                    else
                    {
                        belIpint objipint = new belIpint();

                        objipint.Cst = sCSTIPI;
                        objipi.belIpint = objipint;
                    }
                    objimposto.belIpi = objipi;



                    #endregion

                    #region II



                    //if (Convert.ToDecimal(dgvDet["VbcIi", i].Value) != 0)
                    if (objdest.Uf.Equals("EX"))
                    {
                        belIi objii = new belIi();
                        objii.Vbc = Convert.ToDecimal(dgvDet["VbcIi", i].Value);
                        objii.Vdespadu = Convert.ToDecimal(dgvDet["VdespaduIi", i].Value);
                        objii.Vii = Convert.ToDecimal(dgvDet["Vii", i].Value);
                        objii.Viof = Convert.ToDecimal(dgvDet["ViofIi", i].Value);
                        objimposto.belIi = objii;
                    }
                    #endregion

                    #region PIS

                    belPis objpis = new belPis();
                    string sCstPis = Convert.ToString(dgvDet["CstPis", i].Value);

                    if (sCstPis == "01" || sCstPis == "02") // aqui
                    {
                        belPisaliq objpisaliq = new belPisaliq();

                        objpisaliq.Cst = sCstPis;
                        objpisaliq.Ppis = Convert.ToDecimal(dgvDet["Ppis", i].Value);
                        objpisaliq.Vbc = Convert.ToDecimal(dgvDet["VbcPis", i].Value);
                        objpisaliq.Vpis = Convert.ToDecimal(dgvDet["Vpis", i].Value);
                        objpis.belPisaliq = objpisaliq;
                    }
                    else if (sCstPis == "03")
                    {
                        belPisqtde objpisqtde = new belPisqtde();
                        objpisqtde.Cst = sCstPis;
                        objpisqtde.Valiqprod = Convert.ToDecimal(dgvDet["ValiqprodPis", i].Value);
                        objpisqtde.Qbcprod = Convert.ToDecimal(dgvDet["QbcprodPis", i].Value);
                        objpisqtde.Vpis = Convert.ToDecimal(dgvDet["Vpis", i].Value);
                        objpis.belPisqtde = objpisqtde;
                    }
                    else if (sCstPis == "04" || sCstPis == "06" || sCstPis == "07" || sCstPis == "08" || sCstPis == "09")
                    {
                        belPisnt objpisnt = new belPisnt();
                        objpisnt.Cst = sCstPis;
                        objpis.belPisnt = objpisnt;
                    }
                    else //if (sCstPis == "99")
                    {
                        belPisoutr objpisoutr = new belPisoutr();

                        objpisoutr.Cst = sCstPis;
                        objpisoutr.Ppis = Convert.ToDecimal(dgvDet["Ppis", i].Value);
                        objpisoutr.Vbc = Convert.ToDecimal(dgvDet["VbcPis", i].Value);
                        if (Convert.ToDecimal(dgvDet["ValiqprodPis", i].Value) != 0)
                        {
                            objpisoutr.Valiqprod = Convert.ToDecimal(dgvDet["ValiqprodPis", i].Value);
                            //Danner - o.s. 24167 - 22/01/2010
                            objpisoutr.Qbcprod = Convert.ToDecimal(dgvDet["QbcprodPis", i].Value);
                            //Fim - Danner - o.s. 24167 - 22/01/2010
                        }
                        //objpisoutr.Vbcprod = Convert.ToString(dgvDet["QbcprodPis", i].Value);//Danner - o.s. 24167 - 22/01/2010
                        objpisoutr.Vpis = Convert.ToDecimal(dgvDet["Vpis", i].Value);
                        objpis.belPisoutr = objpisoutr;

                    }

                    objimposto.belPis = objpis;



                    #endregion

                    #region COFINS

                    belCofins objcofins = new belCofins();
                    string sCstCofins = Convert.ToString(dgvDet["CstCofins", i].Value);

                    if (sCstCofins == "01" || sCstCofins == "02")
                    {
                        belCofinsaliq objconfinsaliq = new belCofinsaliq();

                        objconfinsaliq.Cst = sCstCofins;
                        objconfinsaliq.Pcofins = Convert.ToDecimal(dgvDet["Pcofins", i].Value);
                        objconfinsaliq.Vbc = Convert.ToDecimal(dgvDet["VbcCofins", i].Value);
                        objconfinsaliq.Vcofins = Convert.ToDecimal(dgvDet["Vconfins", i].Value);

                        objcofins.belCofinsaliq = objconfinsaliq;
                    }
                    else if (sCstCofins == "03")
                    {
                        belCofinsqtde objcofinsqtde = new belCofinsqtde();

                        objcofinsqtde.Cst = sCstCofins;
                        objcofinsqtde.Qbcprod = Convert.ToDecimal(dgvDet["QbcprodCofins", i].Value);
                        objcofinsqtde.Valiqprod = Convert.ToDecimal(dgvDet["ValiqprodCofins", i].Value);
                        objcofinsqtde.Vcofins = Convert.ToDecimal(dgvDet["Vconfins", i].Value);
                        objcofins.belCofinsqtde = objcofinsqtde;
                    }
                    else if (sCstCofins == "04" || sCstCofins == "06" || sCstCofins == "07" || sCstCofins == "08" || sCstCofins == "09")
                    {
                        belCofinsnt objcofinsnt = new belCofinsnt();
                        objcofinsnt.Cst = sCstCofins;
                        objcofins.belCofinsnt = objcofinsnt;
                    }
                    else //if (sCstCofins == "99")
                    {
                        belCofinsoutr objcofinsoutr = new belCofinsoutr();
                        objcofinsoutr.Cst = sCstCofins;
                        objcofinsoutr.Pcofins = Convert.ToDecimal(dgvDet["Pcofins", i].Value);
                        objcofinsoutr.Vbc = Convert.ToDecimal(dgvDet["VbcCofins", i].Value);
                        objcofinsoutr.Qbcprod = Convert.ToDecimal(dgvDet["QbcprodCofins", i].Value);
                        objcofinsoutr.Valiqprod = Convert.ToDecimal(dgvDet["ValiqprodCofins", i].Value);
                        objcofinsoutr.Vcofins = Convert.ToDecimal(dgvDet["Vconfins", i].Value);
                        objcofins.belCofinsoutr = objcofinsoutr;
                    }
                    objimposto.belCofins = objcofins;

                    #endregion

                    #region ISSQN

                    if (Convert.ToDecimal(dgvDet["VbcIss", i].Value) != 0)
                    {
                        belIss objiss = new belIss();
                        objiss.Clistserv = Convert.ToInt64(dgvDet["ClistservIss", i].Value);
                        objiss.Cmunfg = Convert.ToString(dgvDet["CmunfgIss", i].Value);
                        objiss.Valiq = Convert.ToDecimal(dgvDet["ValiqIss", i].Value);
                        objiss.Vbc = Convert.ToDecimal(dgvDet["VbcIss", i].Value);
                        objiss.Vissqn = Convert.ToDecimal(dgvDet["VissqnIss", i].Value);
                        objimposto.belIss = objiss;
                    }



                    #endregion

                    objDet.belImposto = objimposto;

                    #region InfadProd
                    belInfadprod objinfadprod = new belInfadprod();
                    if (Convert.ToString(dgvDet["Infcpl", i].Value) != "")
                    {

                        objinfadprod.Infadprid = Convert.ToString(dgvDet["Infcpl", i].Value);
                        objDet.belInfadprod = objinfadprod;
                    }

                    #endregion

                    #endregion
                    lObjDet.Add(objDet);
                }
                lObj.Add(lObjDet);
                #endregion

                #region Totais

                belTotal objtotal = new belTotal();

                //Totais
                belIcmstot objIcmsTot = new belIcmstot();

                objIcmsTot.Vbc = nudVBC.Value;
                objIcmsTot.Vicms = nudVICMS.Value;
                objIcmsTot.Vbcst = nudVBCICMSST.Value;
                objIcmsTot.Vst = nudVST.Value;
                objIcmsTot.Vprod = nudVProd.Value;
                //Danner - o.s. 24154 - 18/02/2010
                objIcmsTot.Vfrete = nudVFrete.Value;
                //Fim - Danner - o.s. 24154 - 18/02/2010
                objIcmsTot.Vseg = nudVSEG.Value;
                objIcmsTot.Vdesc = nudVDesc.Value;
                objIcmsTot.Vii = nudVII.Value;
                objIcmsTot.Vipi = nudVIPI.Value;
                objIcmsTot.Vpis = nudVPIS.Value;
                objIcmsTot.Vcofins = nudVCOFINS.Value;
                objIcmsTot.Voutro = nudVOutro.Value;
                objIcmsTot.Vnf = nudVNF.Value;
                objtotal.belIcmstot = objIcmsTot;

                //Fim - Totais

                //ISSQNtot
                if (flpISSNQ.Enabled != false)
                {
                    belIssqntot objissqnTot = new belIssqntot();

                    objissqnTot.Vserv = nudVServ.Value;
                    objissqnTot.Vbc = nudVBCISS.Value;
                    objissqnTot.Viss = nudVISS.Value;
                    objissqnTot.Vpis = nudVPISISS.Value;
                    objissqnTot.Vcofins = nudVCOFINSISS.Value;
                    objtotal.belIssqntot = objissqnTot;
                }

                //Fin - ISSQNtot;

                //retTrib
                if (flpRetTrib.Enabled != false)
                {
                    belRetTrib objRetTrib = new belRetTrib();

                    objRetTrib.Vretpis = nudVPISRet.Value;
                    objRetTrib.Vretcofins = nudVCOFINSRet.Value;
                    objRetTrib.Vretcsll = nudVCSLLRet.Value;
                    objRetTrib.Vbcretprev = nudVBCIRRFRet.Value;
                    objRetTrib.Virrf = nudVIRRFRet.Value;
                    objRetTrib.Vbcirrf = nudVBCIRRFRet.Value;
                    objRetTrib.Vbcretprev = nudVBCRetPrev.Value;
                    objRetTrib.Vretprev = nudVRetPrev.Value;
                    objtotal.belRetTrib = objRetTrib;

                }

                lObj.Add(objtotal);

                //Fim - retTrib
                #endregion

                #region Transporte

                belTransp objtransp = new belTransp();

                switch (cbxModFrete.SelectedIndex) //Nfe_2.0
                {
                    case 0: objtransp.Modfrete = "0";
                        break;

                    case 1: objtransp.Modfrete = "1";
                        break;

                    case 2: objtransp.Modfrete = "2";
                        break;

                    case 3: objtransp.Modfrete = "9";
                        break;
                }

                //objtransp.Modfrete = Convert.ToString(cbxModFrete.SelectedIndex);

                //Transportadora
                belTransportadora objtransportadora = new belTransportadora();

                if (cbxPessoaTranp.SelectedIndex == 1)
                {
                    if (mtbCPJCNPJTransp.Text.Trim() != "")
                    {
                        objtransportadora.Cnpj = mtbCPJCNPJTransp.Text.Trim();
                    }
                }
                else
                {
                    if (mtbCPJCNPJTransp.Text.Trim() != "")
                    {
                        objtransportadora.Cpf = mtbCPJCNPJTransp.Text.Trim();
                    }
                }

                if (txtXnomeTransp.Text.Trim() != "")
                {
                    objtransportadora.Xnome = txtXnomeTransp.Text.Trim();
                }
                if (txtIETransp.Text.Trim() != "")
                {
                    objtransportadora.Ie = txtIETransp.Text.Trim();
                }
                if (txtEnderTransp.Text.Trim() != "")
                {
                    objtransportadora.Xender = txtEnderTransp.Text.Trim();
                }
                if (txtUFTransp.Text.Trim() != "")
                {
                    objtransportadora.Uf = txtUFTransp.Text.Trim();
                }
                if (txtXmunTransp.Text.Trim() != "")
                {
                    objtransportadora.Xmun = txtXmunTransp.Text.Trim();
                }

                objtransp.belTransportadora = objtransportadora;

                //Fim - Transportadora

                //VeicTransp
                if (flpVeicTransp.Enabled != false)
                {
                    belVeicTransp objVeicTrasnp = new belVeicTransp();
                    objVeicTrasnp.Placa = mtbPlacaVeicTransp.Text.Trim();
                    objVeicTrasnp.Uf = txtUFVeicTransp.Text.Trim();

                    //Danner - o.s. sem - 05/03/2010
                    if (txtRNTCVeicTransp.Text.Trim() != "")
                    {
                        objVeicTrasnp.Rntc = txtRNTCVeicTransp.Text.Trim();
                    }
                    //Fim - Danner - o.s. sem - 05/03/2010
                    objtransp.belVeicTransp = objVeicTrasnp;

                }
                //Fim -  VeicTransp

                //Reboque
                if (flpReboque.Enabled != false)
                {
                    belReboque objReboque = new belReboque();
                    objReboque.Placa = mtbPlacaReboque.Text.Trim();
                    objReboque.Uf = txtUFReboque.Text.Trim();
                    objReboque.Rntc = txtRNTCReboque.Text.Trim();
                    objtransp.belReboque = objReboque;
                }
                //Fim - Reboque 

                //RetTransp
                if (flpRetICMS.Enabled != false)
                {
                    belRetTransp objRetTransp = new belRetTransp();
                    objRetTransp.Vbvret = nudVBCICMSTransp.Value;
                    objRetTransp.Vserv = nudVServTransp.Value;
                    objRetTransp.Picmsret = nudPICMSTRetTransp.Value;
                    objRetTransp.Vicmsret = nudVICMSRet.Value;
                    objRetTransp.Cmunfg = txtCmunFGTransp.Text.Trim();
                    objRetTransp.Cfop = txtCFOPTransp.Text.Trim();
                    objtransp.belRetTransp = objRetTransp;
                }
                //Fim - RetTransp

                if (flpVolumes.Enabled != false)
                {
                    belVol objVol = new belVol();
                    objVol.Esp = txtEsp.Text.Trim();
                    objVol.Marca = txtMarca.Text.Trim();
                    //Danner - o.s. 24385 - 26/04/2010
                    if (txtNVol.Text != "")
                    {
                        objVol.Nvol = txtNVol.Text;//Danner - o.s. 24432 - 04/05/2010
                    }
                    //Fim - Danner - o.s. 24385 - 26/04/2010
                    objVol.PesoB = nudPesoB.Value;
                    objVol.PesoL = nudPesoL.Value;
                    objVol.Qvol = nudQvol.Value;
                    objtransp.belVol = objVol;

                }

                lObj.Add(objtransp);
                #endregion

                #region Cobrança

                belCobr objcobr = new belCobr();

                belFat objFat = new belFat();

                objFat.Nfat = txtNFat.Text.Trim();
                objFat.Vorig = nudVOrigFat.Value;
                objFat.Vdesc = nudVDescFat.Value;
                objFat.Vliq = nudVLiqFat.Value;

                if (dgvDup.RowCount != 0)
                {
                    List<belDup> lObjDup = new List<belDup>();

                    for (int i = 0; i < dgvDup.RowCount; i++)
                    {
                        belDup objdup = new belDup();
                        objdup.Ndup = Convert.ToString(dgvDup[0, i].Value);
                        objdup.Dvenc = Convert.ToDateTime(dgvDup[1, i].Value);
                        objdup.Vdup = Convert.ToDecimal(dgvDup[2, i].Value);
                        lObjDup.Add(objdup);
                    }
                    objFat.belDup = lObjDup;

                }
                objcobr.belFat = objFat;

                lObj.Add(objcobr);
                #endregion

                #region Inf Adicionais
                belInfAdic objinfadic = new belInfAdic();
                if (txtInfAdic.Text != "")
                {


                    objinfadic.Infcpl = txtInfAdic.Text.Trim().Replace(Environment.NewLine, "");
                }
                lObj.Add(objinfadic);

                #endregion

                #region exporta
                belExporta objexporta = new belExporta();
                if (cbxUF_embarque.SelectedIndex > 0)
                {
                    objexporta.Ufembarq = cbxUF_embarque.Text.ToString();
                }
                if (txtLocalEntrega.Text != "")
                {
                    objexporta.Xlocembarq = txtLocalEntrega.Text;
                }

                lObj.Add(objexporta);

                #endregion

                lObjTotNotasFinal[notAtual - 1] = lObj;
                lObjTotNotas[notAtual - 1] = lObjTotNotasFinal[notAtual - 1];

            }

            catch (Exception ex)
            {

                KryptonMessageBox.Show(ex.Message); ;
            }

        }
コード例 #4
0
        private void btnImprimir_Click(object sender, EventArgs e)
        {
            try
            {
                List<String> sChaves = new List<string>();
                List<string> lCaminhosXml = new List<string>();
                List<string> lCaminhosXmlContingencia = new List<string>();
                List<string> lCaminhosXmlCancelados = new List<string>();
                StringBuilder sbSeq = new StringBuilder();
                string nao_autorizada = "";
                string cancelada = "";
                string arquivoInexist = "";
                int cont_1 = 0;
                int cont = 0;
                DirectoryInfo dinfo = null;
                FileInfo[] finfo = null;
                XmlDocument xml = new XmlDocument();
                List<belIde> objlbelIde = new List<belIde>(); // Lista de Notas Para envio de email

                string select = "";
                for (int i = 0; i < dgvNF.RowCount; i++)
                {
                    bool bImprime = false;

                    if (dgvNF["Imprime", i].Value == null)
                    {
                        bImprime = false;
                    }
                    else if (dgvNF["Imprime", i].Value.ToString() == "False")
                    {
                        bImprime = false;
                    }
                    else
                    {
                        bImprime = true;
                    }

                    if (((dgvNF["ST_NFE", i].Value.ToString().Equals("1")) || (dgvNF["st_contingencia", i].Value.ToString().Equals("S"))) && (bImprime == true))//&& (dgvNF["CANCELADA", i].Value.ToString().Equals("0")))
                    {

                        select = "Select cd_chavenfe from nf where cd_empresa = '"
                               + belStatic.codEmpresaNFe.Trim() + "' and CD_NFSEQ ='" + dgvNF["CD_NFSEQ", i].Value.ToString() + "'";

                        try
                        {
                            using (FbCommand cmd = new FbCommand(select, cx.get_Conexao()))
                            {
                                cx.Open_Conexao();
                                sChaves.Add(cmd.ExecuteScalar().ToString());

                                try
                                {
                                    if ((dgvNF["st_contingencia", i].Value.ToString().Equals("S"))
                                                         && (dgvNF["ST_NFE", i].Value.ToString().Equals("0"))
                                                         && (dgvNF["CD_NOTAFIS", i].Value.ToString() != ""))
                                    {
                                        #region Imprime Contingência
                                        dinfo = new DirectoryInfo(belStaticPastas.CONTINGENCIA); ;
                                        finfo = dinfo.GetFiles();
                                        foreach (FileInfo item in finfo)
                                        {
                                            if (Path.GetExtension(item.FullName).ToUpper().Equals(".XML"))
                                            {
                                                if (item.Name.ToString().Length == 26)
                                                {
                                                    xml.Load(@item.FullName);

                                                    if (xml.GetElementsByTagName("infNFe")[0].Attributes["Id"].Value.ToString().Replace("NFe", "").Equals(cmd.ExecuteScalar().ToString()))
                                                    {
                                                        lCaminhosXmlContingencia.Add(belStaticPastas.CONTINGENCIA + "\\" + (item.ToString()));
                                                    }
                                                }
                                            }
                                        }
                                        #endregion
                                    }
                                    else if (dgvNF["cd_recibocanc", i].Value.ToString() != "")
                                    {
                                        dinfo = new DirectoryInfo(belStaticPastas.CANCELADOS); ;
                                        finfo = dinfo.GetFiles();
                                        bool bAchouArquivo = false;

                                        foreach (FileInfo item in finfo)
                                        {
                                            if (Path.GetExtension(item.FullName).ToUpper().Equals(".XML"))
                                            {
                                                if (item.Name.ToString().Length == 56)
                                                {
                                                    if (item.Name.Replace("-can.xml.xml", "").Equals(cmd.ExecuteScalar().ToString()))
                                                    {
                                                        lCaminhosXmlCancelados.Add(dinfo.FullName + "\\" + (item.ToString()));
                                                        belIde objbelide = new belIde();
                                                        objbelide.Cnf = dgvNF["CD_NOTAFIS", i].Value.ToString();
                                                        objbelide.Nnf = dgvNF["CD_NFSEQ", i].Value.ToString();
                                                        objlbelIde.Add(objbelide);
                                                        bAchouArquivo = true;
                                                    }
                                                }
                                            }
                                        }
                                        if (bAchouArquivo == false)
                                        {
                                            foreach (DirectoryInfo diretorio in dinfo.GetDirectories())
                                            {
                                                foreach (FileInfo item in diretorio.GetFiles("*.xml"))
                                                {
                                                    if (item.Name.ToString().Length == 56)
                                                    {
                                                        if (item.Name.Replace("-can.xml.xml", "").Equals(cmd.ExecuteScalar().ToString()))
                                                        {
                                                            lCaminhosXmlCancelados.Add(diretorio.FullName + "\\" + (item.ToString()));
                                                            belIde objbelide = new belIde();
                                                            objbelide.Cnf = dgvNF["CD_NOTAFIS", i].Value.ToString();
                                                            objbelide.Nnf = dgvNF["CD_NFSEQ", i].Value.ToString();
                                                            objlbelIde.Add(objbelide);
                                                            break;
                                                        }
                                                    }
                                                }
                                            }
                                        }
                                    }
                                    else
                                    {
                                        string sArquivo = belStaticPastas.ENVIADOS + cmd.ExecuteScalar().ToString().Substring(2, 4) + "\\" + cmd.ExecuteScalar().ToString() + "-nfe.xml";

                                        if (File.Exists(sArquivo))
                                        {
                                            lCaminhosXml.Add(sArquivo);
                                            belIde objbelide = new belIde();
                                            objbelide.Cnf = dgvNF["CD_NOTAFIS", i].Value.ToString();
                                            objbelide.Nnf = dgvNF["CD_NFSEQ", i].Value.ToString();
                                            objlbelIde.Add(objbelide);

                                        }
                                        else
                                        {
                                            dinfo = new DirectoryInfo(belStaticPastas.ENVIADOS + "/" + cmd.ExecuteScalar().ToString().Substring(2, 4)); ;
                                            finfo = dinfo.GetFiles();

                                            foreach (FileInfo item in finfo)
                                            {
                                                if (Path.GetExtension(item.FullName).ToUpper().Equals(".XML"))
                                                {
                                                    if (item.Name.ToString().Length == 52)
                                                    {
                                                        // xml.Load(@item.FullName);
                                                        if (item.Name.Replace("-nfe.xml", "").Equals(cmd.ExecuteScalar().ToString()))
                                                        {
                                                            lCaminhosXml.Add(dinfo.FullName + "\\" + (item.ToString()));
                                                            belIde objbelide = new belIde();
                                                            objbelide.Cnf = dgvNF["CD_NOTAFIS", i].Value.ToString();
                                                            objbelide.Nnf = dgvNF["CD_NFSEQ", i].Value.ToString();
                                                            objlbelIde.Add(objbelide);
                                                            // EnviaEmail(i, item);
                                                        }
                                                    }
                                                }
                                            }
                                        }
                                    }
                                }
                                catch (Exception ex)
                                {
                                    new HLPexception("Verifique se não existe nenhum arquivo Corrompido ou que não seja de Enviados na Pasta Correspondente", ex);
                                    break;
                                }
                            }
                        }
                        catch (Exception)
                        {
                            throw;
                        }
                        finally { cx.Close_Conexao(); }
                    }
                    else if ((bImprime == true) && (dgvNF["CANCELADA", i].Value.ToString().Equals("0")))
                    {
                        if (cont > 0)
                        {
                            nao_autorizada = nao_autorizada + ", " + dgvNF["CD_NFSEQ", i].Value.ToString();
                        }
                        else
                        {
                            nao_autorizada = dgvNF["CD_NFSEQ", i].Value.ToString();
                        }
                        cont++;
                    }
                }

                // Diego - OS_23834 18/12/2009 
                if ((lCaminhosXml.Count > 0) || (lCaminhosXmlContingencia.Count > 0) || (lCaminhosXmlCancelados.Count > 0))
                {
                    if (lCaminhosXmlCancelados.Count > 0)
                    {
                        //Impressão de Danfe Normal
                        dsdanfe = new dsDanfe();
                        for (int i = 0; i < lCaminhosXmlCancelados.Count; i++)
                        {
                            InformaStatusEnvio("Gerando PDF da DANFE ", i, lCaminhosXml.Count);
                            PopulaDataSetXML(dsdanfe, lCaminhosXmlCancelados[i].ToString(), (i + 1).ToString());
                            dsDanfe dsPDF = new dsDanfe();
                            PopulaDataSetXML(dsPDF, lCaminhosXmlCancelados[i].ToString(), 1.ToString());
                            GeraPDF_Danfe(dsPDF, TipoPDF.CANCELADO, false);
                        }
                        if (LeRegWin.LeRegConfig("EmailAutomatico").ToString() == "True")
                        {
                            EnviaEmail(lCaminhosXml, objlbelIde);
                        }
                        GeraPDF_Danfe(dsdanfe, TipoPDF.CANCELADO, true);
                    }
                    if (lCaminhosXml.Count > 0)
                    {
                        //Impressão de Danfe Normal
                        dsdanfe = new dsDanfe();
                        for (int i = 0; i < lCaminhosXml.Count; i++)
                        {
                            InformaStatusEnvio("Gerando PDF da DANFE ", i, lCaminhosXml.Count);
                            statusStrip1.Refresh();
                            PopulaDataSetXML(dsdanfe, lCaminhosXml[i].ToString(), (i + 1).ToString());
                            dsDanfe dsPDF = new dsDanfe();
                            PopulaDataSetXML(dsPDF, lCaminhosXml[i].ToString(), 1.ToString());
                            GeraPDF_Danfe(dsPDF, TipoPDF.ENVIADO, false);
                        }
                        if (LeRegWin.LeRegConfig("EmailAutomatico").ToString() == "True")
                        {
                            EnviaEmail(lCaminhosXml, objlbelIde);
                        }
                        GeraPDF_Danfe(dsdanfe, TipoPDF.ENVIADO, true);
                    }

                    sslStatusEnvio.Text = "";

                    #region Contingencia
                    if ((lCaminhosXmlContingencia.Count > 0))
                    {
                        string sQueryEmpresa = "select empresa.nm_empresa from empresa " +
                                        "where empresa.cd_empresa = '" + belStatic.codEmpresaNFe + "'";
                        FbCommand fbComEmp = new FbCommand(sQueryEmpresa, cx.get_Conexao());
                        fbComEmp.ExecuteNonQuery();
                        FbDataReader drEmp = fbComEmp.ExecuteReader();
                        cx.Close_Conexao();
                        drEmp.Read();
                        frmContratoContingenciaNfe objfrmAviso = new frmContratoContingenciaNfe(drEmp["nm_empresa"].ToString());
                        objfrmAviso.ShowDialog();

                        if (objfrmAviso.bImprime)
                        {
                            //Impressão de Danfe em Contingencia
                            dsdanfe = new dsDanfe();
                            for (int i = 0; i < lCaminhosXmlContingencia.Count; i++)
                            {
                                PopulaDataSetXML(dsdanfe, lCaminhosXmlContingencia[i].ToString(), (i + 1).ToString());
                            }// OS.23999 - DIEGO - 02/02/2010                            
                            PrintReport(TipoPDF.CONTINGENCIA);
                        }
                        else
                        {
                            KryptonMessageBox.Show(null, "Impressão Cancelada!!", "IMPRESSÃO DE DANFE", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                        }
                    }
                    #endregion
                }
                else
                {
                    KryptonMessageBox.Show(null, "Nenhuma nota selecionada para Impressão!", "IMPRESSÃO DE DANFE", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                }
                if (nao_autorizada != "")
                {
                    KryptonMessageBox.Show(null, "Sequencia de Notas não autorizadas para a impressão do Danfe: " + nao_autorizada, "Alerta", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                }
                if (arquivoInexist != "")
                {
                    KryptonMessageBox.Show(null, "XML da sequencia a seguir não foi encontrada na Pasta: " + arquivoInexist, "Alerta", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                }
                if (cancelada != "")
                {
                    KryptonMessageBox.Show(null, "XML da Sequencia a seguir está Cancelado e não pode ser impresso: " + cancelada, "Alerta", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                }
                for (int i = 0; i < dgvNF.RowCount; i++)
                {
                    dgvNF["Imprime", i].Value = false;
                }
                PopulaDataGridView();
            }
            catch (DirectoryNotFoundException)
            {
                KryptonMessageBox.Show(null, "Pasta de Arquivos não encontrados", "Erro", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            catch (Exception ex)
            {
                new HLPexception(ex.Message, ex);
            }
            finally
            {
                cx.Close_Conexao();
            }

        }