private void CriaObjAlter()
        {
            try
            {
                List<belinfCte> objList = new List<belinfCte>();


                for (int i = 0; i < this.objObjetos.objLinfCte.Count; i++)
                {
                    belinfCte objbelinfCte = new belinfCte();
                    belinfCte obj = this.objObjetos.objLinfCte[i];

                    #region Identificacao
                    objbelinfCte.id = obj.id;
                    objbelinfCte.ide = new belide();

                    objbelinfCte.ide.cUF = obj.ide.cUF;
                    objbelinfCte.ide.cCT = obj.ide.cCT;
                    objbelinfCte.ide.CFOP = obj.ide.CFOP;
                    objbelinfCte.ide.natOp = obj.ide.natOp;
                    objbelinfCte.ide.forPag = obj.ide.forPag;
                    objbelinfCte.ide.mod = obj.ide.mod;
                    objbelinfCte.ide.serie = obj.ide.serie;
                    objbelinfCte.ide.nCT = obj.ide.nCT;
                    objbelinfCte.ide.tpImp = obj.ide.tpImp;
                    objbelinfCte.ide.tpEmis = belStatic.bModoContingencia == true ? "2" : "1";
                    objbelinfCte.ide.cDV = obj.ide.cDV;
                    objbelinfCte.ide.tpAmb = obj.ide.tpAmb;
                    objbelinfCte.ide.tpCTe = obj.ide.tpCTe;
                    objbelinfCte.ide.procEmi = obj.ide.procEmi;
                    objbelinfCte.ide.verProc = obj.ide.verProc;
                    objbelinfCte.ide.cMunEnv = obj.ide.cMunEnv;
                    objbelinfCte.ide.xMunEnv = obj.ide.xMunEnv;
                    objbelinfCte.ide.UFEnv = obj.ide.UFEnv;
                    objbelinfCte.ide.modal = obj.ide.modal;
                    objbelinfCte.ide.tpServ = obj.ide.tpServ;
                    objbelinfCte.ide.cMunIni = obj.ide.cMunIni;
                    objbelinfCte.ide.xMunIni = obj.ide.xMunIni;
                    objbelinfCte.ide.UFIni = obj.ide.UFIni;
                    objbelinfCte.ide.cMunFim = obj.ide.cMunFim;
                    objbelinfCte.ide.xMunFim = obj.ide.xMunFim;
                    objbelinfCte.ide.UFFim = obj.ide.UFFim;
                    objbelinfCte.ide.retira = obj.ide.retira;
                    objbelinfCte.ide.xDetRetira = obj.ide.xDetRetira;

                    #endregion

                    #region compl
                    if (obj.compl != null)
                    {
                        objbelinfCte.compl = new belcompl();
                        objbelinfCte.compl.ObsCont.Xcampo = obj.compl.ObsCont.Xcampo;
                        objbelinfCte.compl.ObsCont.Xtexto = obj.compl.ObsCont.Xtexto;                        
                    }
                    #endregion

                    #region Tomador
                    if (obj.ide.toma03 != null)
                    {
                        objbelinfCte.ide.toma03 = new beltoma03();
                        objbelinfCte.ide.toma03.toma = obj.ide.toma03.toma;
                    }
                    else if (obj.ide.toma04 != null)
                    {
                        objbelinfCte.ide.toma04 = new beltoma04();
                        objbelinfCte.ide.toma04.toma = obj.ide.toma04.toma;
                        objbelinfCte.ide.toma04.CNPJ = obj.ide.toma04.CNPJ;
                        objbelinfCte.ide.toma04.CPF = obj.ide.toma04.CPF;
                        objbelinfCte.ide.toma04.IE = obj.ide.toma04.IE;
                        objbelinfCte.ide.toma04.xNome = obj.ide.toma04.xNome;
                        objbelinfCte.ide.toma04.xFant = obj.ide.toma04.xFant;
                        objbelinfCte.ide.toma04.fone = obj.ide.toma04.fone;

                        objbelinfCte.ide.toma04.enderToma = new belenderToma();
                        objbelinfCte.ide.toma04.enderToma.xLgr = obj.ide.toma04.enderToma.xLgr;
                        objbelinfCte.ide.toma04.enderToma.nro = obj.ide.toma04.enderToma.nro;
                        objbelinfCte.ide.toma04.enderToma.xCpl = obj.ide.toma04.enderToma.xCpl;
                        objbelinfCte.ide.toma04.enderToma.xBairro = obj.ide.toma04.enderToma.xBairro;
                        objbelinfCte.ide.toma04.enderToma.cMun = obj.ide.toma04.enderToma.cMun;
                        objbelinfCte.ide.toma04.enderToma.xMun = obj.ide.toma04.enderToma.xMun;
                        objbelinfCte.ide.toma04.enderToma.CEP = obj.ide.toma04.enderToma.CEP;
                        objbelinfCte.ide.toma04.enderToma.UF = obj.ide.toma04.enderToma.UF;
                        objbelinfCte.ide.toma04.enderToma.cPais = obj.ide.toma04.enderToma.cPais;
                        objbelinfCte.ide.toma04.enderToma.xPais = obj.ide.toma04.enderToma.xPais;

                    }

                    #endregion

                    #region Emitente
                    objbelinfCte.emit = new belemit();

                    objbelinfCte.emit.CNPJ = obj.emit.CNPJ;
                    objbelinfCte.emit.IE = obj.emit.IE;
                    objbelinfCte.emit.xNome = obj.emit.xNome;
                    objbelinfCte.emit.xFant = obj.emit.xFant;

                    objbelinfCte.emit.enderEmit = new belenderEmit();

                    objbelinfCte.emit.enderEmit.xLgr = obj.emit.enderEmit.xLgr;
                    objbelinfCte.emit.enderEmit.nro = obj.emit.enderEmit.nro;
                    objbelinfCte.emit.enderEmit.xCpl = obj.emit.enderEmit.xCpl;
                    objbelinfCte.emit.enderEmit.xBairro = obj.emit.enderEmit.xBairro;
                    objbelinfCte.emit.enderEmit.cMun = obj.emit.enderEmit.cMun;
                    objbelinfCte.emit.enderEmit.xMun = obj.emit.enderEmit.xMun;
                    objbelinfCte.emit.enderEmit.CEP = obj.emit.enderEmit.CEP;
                    objbelinfCte.emit.enderEmit.UF = obj.emit.enderEmit.UF;
                    objbelinfCte.emit.enderEmit.fone = obj.emit.enderEmit.fone;

                    #endregion

                    #region Remetente
                    objbelinfCte.rem = new belrem();

                    objbelinfCte.rem.CNPJ = obj.rem.CNPJ;
                    objbelinfCte.rem.CPF = obj.rem.CPF;
                    objbelinfCte.rem.IE = obj.rem.IE;
                    objbelinfCte.rem.xNome = obj.rem.xNome;
                    objbelinfCte.rem.xFant = obj.rem.xFant;
                    objbelinfCte.rem.fone = obj.rem.fone;

                    objbelinfCte.rem.enderReme = new belenderReme();

                    objbelinfCte.rem.enderReme.xLgr = obj.rem.enderReme.xLgr;
                    objbelinfCte.rem.enderReme.nro = obj.rem.enderReme.nro;
                    objbelinfCte.rem.enderReme.xCpl = obj.rem.enderReme.xCpl;
                    objbelinfCte.rem.enderReme.xBairro = obj.rem.enderReme.xBairro;
                    objbelinfCte.rem.enderReme.cMun = obj.rem.enderReme.cMun;
                    objbelinfCte.rem.enderReme.xMun = obj.rem.enderReme.xMun;
                    objbelinfCte.rem.enderReme.CEP = obj.rem.enderReme.CEP;
                    objbelinfCte.rem.enderReme.UF = obj.rem.enderReme.UF;
                    objbelinfCte.rem.enderReme.xPais = obj.rem.enderReme.xPais;
                    objbelinfCte.rem.enderReme.cPais = obj.rem.enderReme.cPais;

                    #endregion

                    #region Destinatario

                    objbelinfCte.dest = new beldest();

                    objbelinfCte.dest.CNPJ = obj.dest.CNPJ;
                    objbelinfCte.dest.CPF = obj.dest.CPF;
                    objbelinfCte.dest.IE = obj.dest.IE;
                    objbelinfCte.dest.xNome = obj.dest.xNome;
                    objbelinfCte.dest.fone = obj.dest.fone;
                    objbelinfCte.dest.ISUF = obj.dest.ISUF;

                    objbelinfCte.dest.enderDest = new belenderDest();

                    objbelinfCte.dest.enderDest.xLgr = obj.dest.enderDest.xLgr;
                    objbelinfCte.dest.enderDest.nro = obj.dest.enderDest.nro;
                    objbelinfCte.dest.enderDest.xCpl = obj.dest.enderDest.xCpl;
                    objbelinfCte.dest.enderDest.xBairro = obj.dest.enderDest.xBairro;
                    objbelinfCte.dest.enderDest.cMun = obj.dest.enderDest.cMun;
                    objbelinfCte.dest.enderDest.xMun = obj.dest.enderDest.xMun;
                    objbelinfCte.dest.enderDest.CEP = obj.dest.enderDest.CEP;
                    objbelinfCte.dest.enderDest.UF = obj.dest.enderDest.UF;
                    objbelinfCte.dest.enderDest.xPais = obj.dest.enderDest.xPais;
                    objbelinfCte.dest.enderDest.cPais = obj.dest.enderDest.cPais;

                    #endregion

                    #region Expedidor
                    if (obj.exped != null)
                    {
                        objbelinfCte.exped = new belexped();

                        objbelinfCte.exped.CNPJ = obj.exped.CNPJ;
                        objbelinfCte.exped.CPF = obj.exped.CPF;
                        objbelinfCte.exped.IE = obj.exped.IE;
                        objbelinfCte.exped.xNome = obj.exped.xNome;
                        objbelinfCte.exped.fone = obj.exped.fone;

                        objbelinfCte.exped.enderExped = new belenderExped();

                        objbelinfCte.exped.enderExped.xLgr = obj.exped.enderExped.xLgr;
                        objbelinfCte.exped.enderExped.nro = obj.exped.enderExped.nro;
                        objbelinfCte.exped.enderExped.xCpl = obj.exped.enderExped.xCpl;
                        objbelinfCte.exped.enderExped.xBairro = obj.exped.enderExped.xBairro;
                        objbelinfCte.exped.enderExped.cMun = obj.exped.enderExped.cMun;
                        objbelinfCte.exped.enderExped.xMun = obj.exped.enderExped.xMun;
                        objbelinfCte.exped.enderExped.CEP = obj.exped.enderExped.CEP;
                        objbelinfCte.exped.enderExped.UF = obj.exped.enderExped.UF;
                        objbelinfCte.exped.enderExped.xPais = obj.exped.enderExped.xPais;
                        objbelinfCte.exped.enderExped.cPais = obj.exped.enderExped.cPais;


                    }


                    #endregion

                    #region Recebedor
                    if (obj.receb != null)
                    {
                        objbelinfCte.receb = new belreceb();

                        objbelinfCte.receb.CNPJ = obj.receb.CNPJ;
                        objbelinfCte.receb.CPF = obj.receb.CPF;
                        objbelinfCte.receb.IE = obj.receb.IE;
                        objbelinfCte.receb.xNome = obj.receb.xNome;
                        objbelinfCte.receb.fone = obj.receb.fone;

                        objbelinfCte.receb.enderReceb = new belenderReceb();

                        objbelinfCte.receb.enderReceb.xLgr = obj.receb.enderReceb.xLgr;
                        objbelinfCte.receb.enderReceb.nro = obj.receb.enderReceb.nro;
                        objbelinfCte.receb.enderReceb.xCpl = obj.receb.enderReceb.xCpl;
                        objbelinfCte.receb.enderReceb.xBairro = obj.receb.enderReceb.xBairro;
                        objbelinfCte.receb.enderReceb.cMun = obj.receb.enderReceb.cMun;
                        objbelinfCte.receb.enderReceb.xMun = obj.receb.enderReceb.xMun;
                        objbelinfCte.receb.enderReceb.CEP = obj.receb.enderReceb.CEP;
                        objbelinfCte.receb.enderReceb.UF = obj.receb.enderReceb.UF;
                        objbelinfCte.receb.enderReceb.xPais = obj.receb.enderReceb.xPais;
                        objbelinfCte.receb.enderReceb.cPais = obj.receb.enderReceb.cPais;


                    }


                    #endregion

                    #region Informacoes da NF

                    objbelinfCte.rem.infNF = new List<belinfNF>();
                    for (int j = 0; j < obj.rem.infNF.Count; j++)
                    {
                        belinfNF nf = new belinfNF();
                        nf.mod = obj.rem.infNF[j].mod;
                        nf.nDoc = obj.rem.infNF[j].nDoc;
                        nf.serie = obj.rem.infNF[j].serie;
                        nf.dEmi = obj.rem.infNF[j].dEmi;
                        nf.vBC = obj.rem.infNF[j].vBC;
                        nf.vICMS = obj.rem.infNF[j].vICMS;
                        nf.vBCST = obj.rem.infNF[j].vBCST;
                        nf.vST = obj.rem.infNF[j].vST;
                        nf.vProd = obj.rem.infNF[j].vProd;
                        nf.vNF = obj.rem.infNF[j].vNF;
                        nf.nCFOP = Convert.ToInt32(obj.rem.infNF[j].nCFOP).ToString();

                        objbelinfCte.rem.infNF.Add(nf);
                    }


                    objbelinfCte.rem.infNFe = new List<belinfNFe>();
                    for (int n = 0; n < obj.rem.infNFe.Count; n++)
                    {
                        belinfNFe nfe = new belinfNFe();
                        nfe.chave = obj.rem.infNFe[n].chave;

                        objbelinfCte.rem.infNFe.Add(nfe);
                    }

                    #endregion

                    #region Outros Documentos
                    objbelinfCte.rem.infOutros = new List<belinfOutros>();
                    for (int j = 0; j < obj.rem.infOutros.Count; j++)
                    {
                        belinfOutros infOutros = new belinfOutros();
                        infOutros.tpDoc = obj.rem.infOutros[j].tpDoc;
                        infOutros.descOutros = obj.rem.infOutros[j].descOutros;
                        infOutros.nDoc = obj.rem.infOutros[j].nDoc;
                        infOutros.dEmi = obj.rem.infOutros[j].dEmi;
                        infOutros.vDocFisc = obj.rem.infOutros[j].vDocFisc;

                        objbelinfCte.rem.infOutros.Add(infOutros);
                    }


                    #endregion

                    #region Valores

                    objbelinfCte.vPrest = new belvPrest();
                    objbelinfCte.vPrest.vTPrest = obj.vPrest.vTPrest;
                    objbelinfCte.vPrest.vRec = obj.vPrest.vRec;

                    objbelinfCte.vPrest.Comp = obj.vPrest.Comp;



                    objbelinfCte.imp = new belimp();
                    objbelinfCte.imp.ICMS = new belICMS();

                    if (obj.imp.ICMS.ICMS00 != null)
                    {
                        objbelinfCte.imp.ICMS.ICMS00 = new belICMS00();
                        objbelinfCte.imp.ICMS.ICMS00.CST = obj.imp.ICMS.ICMS00.CST;
                        objbelinfCte.imp.ICMS.ICMS00.vBC = obj.imp.ICMS.ICMS00.vBC;
                        objbelinfCte.imp.ICMS.ICMS00.pICMS = obj.imp.ICMS.ICMS00.pICMS;
                        objbelinfCte.imp.ICMS.ICMS00.vICMS = obj.imp.ICMS.ICMS00.vICMS;
                    }
                    else if (obj.imp.ICMS.ICMS20 != null)
                    {
                        objbelinfCte.imp.ICMS.ICMS20 = new belICMS20();
                        objbelinfCte.imp.ICMS.ICMS20.CST = obj.imp.ICMS.ICMS20.CST;
                        objbelinfCte.imp.ICMS.ICMS20.pRedBC = obj.imp.ICMS.ICMS20.pRedBC;
                        objbelinfCte.imp.ICMS.ICMS20.vBC = obj.imp.ICMS.ICMS20.vBC;
                        objbelinfCte.imp.ICMS.ICMS20.pICMS = obj.imp.ICMS.ICMS20.pICMS;
                        objbelinfCte.imp.ICMS.ICMS20.vICMS = obj.imp.ICMS.ICMS20.vICMS;
                    }
                    else if (obj.imp.ICMS.ICMS45 != null)
                    {
                        objbelinfCte.imp.ICMS.ICMS45 = new belICMS45();
                        objbelinfCte.imp.ICMS.ICMS45.CST = obj.imp.ICMS.ICMS45.CST;
                    }
                    else if (obj.imp.ICMS.ICMS60 != null)
                    {
                        objbelinfCte.imp.ICMS.ICMS60 = new belICMS60();
                        objbelinfCte.imp.ICMS.ICMS60.CST = obj.imp.ICMS.ICMS60.CST;
                        objbelinfCte.imp.ICMS.ICMS60.vBCSTRet = obj.imp.ICMS.ICMS60.vBCSTRet;
                        objbelinfCte.imp.ICMS.ICMS60.vICMSSTRet = obj.imp.ICMS.ICMS60.vICMSSTRet;
                        objbelinfCte.imp.ICMS.ICMS60.pICMSSTRet = obj.imp.ICMS.ICMS60.pICMSSTRet;
                        objbelinfCte.imp.ICMS.ICMS60.vCred = obj.imp.ICMS.ICMS60.vCred;
                    }
                    else if (obj.imp.ICMS.ICMS90 != null)
                    {
                        objbelinfCte.imp.ICMS.ICMS90 = new belICMS90();
                        objbelinfCte.imp.ICMS.ICMS90.CST = obj.imp.ICMS.ICMS90.CST;
                        objbelinfCte.imp.ICMS.ICMS90.pRedBC = obj.imp.ICMS.ICMS90.pRedBC;
                        objbelinfCte.imp.ICMS.ICMS90.vBC = obj.imp.ICMS.ICMS90.vBC;
                        objbelinfCte.imp.ICMS.ICMS90.pICMS = obj.imp.ICMS.ICMS90.pICMS;
                        objbelinfCte.imp.ICMS.ICMS90.vICMS = obj.imp.ICMS.ICMS90.vICMS;
                        objbelinfCte.imp.ICMS.ICMS90.vCred = obj.imp.ICMS.ICMS90.vCred;
                    }
                    else if (obj.imp.ICMS.ICMSOutraUF != null)
                    {
                        objbelinfCte.imp.ICMS.ICMSOutraUF = new belICMSOutraUF();
                        objbelinfCte.imp.ICMS.ICMSOutraUF.CST = obj.imp.ICMS.ICMSOutraUF.CST;
                        objbelinfCte.imp.ICMS.ICMSOutraUF.pRedBCOutraUF = obj.imp.ICMS.ICMSOutraUF.pRedBCOutraUF;
                        objbelinfCte.imp.ICMS.ICMSOutraUF.vBCOutraUF = obj.imp.ICMS.ICMSOutraUF.vBCOutraUF;
                        objbelinfCte.imp.ICMS.ICMSOutraUF.pICMSOutraUF = obj.imp.ICMS.ICMSOutraUF.pICMSOutraUF;
                        objbelinfCte.imp.ICMS.ICMSOutraUF.vICMSOutraUF = obj.imp.ICMS.ICMSOutraUF.vICMSOutraUF;
                    }


                    #endregion

                    #region InformacoesCarga
                    objbelinfCte.infCTeNorm = new belinfCTeNorm();
                    objbelinfCte.infCTeNorm.infCarga = new belinfCarga();

                    objbelinfCte.infCTeNorm.infCarga.vCarga = obj.infCTeNorm.infCarga.vCarga;
                    objbelinfCte.infCTeNorm.infCarga.proPred = obj.infCTeNorm.infCarga.proPred;
                    objbelinfCte.infCTeNorm.infCarga.xOutCat = obj.infCTeNorm.infCarga.xOutCat;

                    objbelinfCte.infCTeNorm.infCarga.infQ = new List<belinfQ>();
                    for (int j = 0; j < obj.infCTeNorm.infCarga.infQ.Count; j++)
                    {
                        belinfQ objInfQ = new belinfQ();
                        objInfQ.cUnid = obj.infCTeNorm.infCarga.infQ[j].cUnid;
                        objInfQ.tpMed = obj.infCTeNorm.infCarga.infQ[j].tpMed;
                        objInfQ.qCarga = obj.infCTeNorm.infCarga.infQ[j].qCarga;

                        objbelinfCte.infCTeNorm.infCarga.infQ.Add(objInfQ);
                    }

                    #endregion

                    #region Rodoviario
                    objbelinfCte.infCTeNorm.seg = new belseg();
                    objbelinfCte.infCTeNorm.rodo = new belrodo();

                    objbelinfCte.infCTeNorm.seg.respSeg = obj.infCTeNorm.seg.respSeg;
                    objbelinfCte.infCTeNorm.seg.nApol = obj.infCTeNorm.seg.nApol;
                    objbelinfCte.infCTeNorm.rodo.RNTRC = obj.infCTeNorm.rodo.RNTRC;
                    objbelinfCte.infCTeNorm.rodo.dPrev = obj.infCTeNorm.rodo.dPrev;
                    objbelinfCte.infCTeNorm.rodo.lota = obj.infCTeNorm.rodo.lota;

                    #endregion

                    #region Veiculo

                    objbelinfCte.infCTeNorm.rodo.veic = new List<belveic>();
                    for (int v = 0; v < obj.infCTeNorm.rodo.veic.Count; v++)
                    {
                        belveic veic = new belveic();

                        veic.RENAVAM = obj.infCTeNorm.rodo.veic[v].RENAVAM;
                        veic.placa = obj.infCTeNorm.rodo.veic[v].placa;
                        veic.tara = obj.infCTeNorm.rodo.veic[v].tara;
                        veic.capKG = obj.infCTeNorm.rodo.veic[v].capKG;
                        veic.capM3 = obj.infCTeNorm.rodo.veic[v].capM3;
                        veic.tpProp = obj.infCTeNorm.rodo.veic[v].tpProp;
                        veic.tpVeic = obj.infCTeNorm.rodo.veic[v].tpVeic;
                        veic.tpRod = obj.infCTeNorm.rodo.veic[v].tpRod;
                        veic.tpCar = obj.infCTeNorm.rodo.veic[v].tpCar;
                        veic.UF = obj.infCTeNorm.rodo.veic[v].UF;

                        if (obj.infCTeNorm.rodo.veic[v].prop != null)
                        {
                            veic.prop = new belprop();

                            veic.prop.CPFCNPJ = obj.infCTeNorm.rodo.veic[v].prop.CPFCNPJ;
                            veic.prop.RNTRC = obj.infCTeNorm.rodo.veic[v].prop.RNTRC;
                            veic.prop.xNome = obj.infCTeNorm.rodo.veic[v].prop.xNome;
                            veic.prop.IE = obj.infCTeNorm.rodo.veic[v].prop.IE;
                            veic.prop.UF = obj.infCTeNorm.rodo.veic[v].prop.UF;
                            veic.prop.tpProp = obj.infCTeNorm.rodo.veic[v].prop.tpProp;
                        }

                        objbelinfCte.infCTeNorm.rodo.veic.Add(veic);
                    }
                    if (obj.infCTeNorm.rodo.moto != null)
                    {
                        objbelinfCte.infCTeNorm.rodo.moto = new belmoto();
                        objbelinfCte.infCTeNorm.rodo.moto.xNome = obj.infCTeNorm.rodo.moto.xNome;
                        objbelinfCte.infCTeNorm.rodo.moto.CPF = obj.infCTeNorm.rodo.moto.CPF;
                    }
                    #endregion

                    objList.Add(objbelinfCte);

                }
                this.objObjetosAlter = new belPopulaObjetos(objObjetos.sEmp, objObjetos.objlConhec, objObjetos.cUf, objObjetos.cert);
                this.objObjetosAlter.objLinfCte = objList;
                this.objObjetosAlter.sFormEmiss = objObjetos.sFormEmiss;
                this.objObjetosAlter.sNomeArq = objObjetos.sNomeArq;
                this.objObjetosAlter.sPath = objObjetos.sPath;

            }
            catch (Exception ex)
            {
                KryptonMessageBox.Show(null, _sMessageException + (ex.InnerException != null ? ex.InnerException.Message : ex.Message).ToString(), "CT-e - AVISO", MessageBoxButtons.OK, MessageBoxIcon.Information); ;
            }
        }
Exemple #2
0
        public void PopulaNf(belinfCte objbelinfCte, FbConnection conn, string sCte)
        {
            try
            {
                StringBuilder sQuery = new StringBuilder();
                sQuery.Append("Select ");
                sQuery.Append("coalesce(nfconhec.st_tiponf,'')Tipo, ");
                sQuery.Append("coalesce(nfconhec.cd_mod,'01')mod, ");
                sQuery.Append("coalesce(nfconhec.cd_chave,'')chave, ");
                sQuery.Append("coalesce(nfconhec.desc_outros,'')descOutros, ");
                sQuery.Append("coalesce(nfconhec.cd_serie,'')serie, ");
                sQuery.Append("coalesce(nfconhec.cd_nf,'')nDoc, ");
                sQuery.Append("coalesce(nfconhec.dt_emi,'')dEmi, ");
                sQuery.Append("coalesce(nfconhec.vl_basecalc,'')vBC, ");
                sQuery.Append("coalesce(nfconhec.vl_totalicms,'')vICMS, ");
                sQuery.Append("coalesce(nfconhec.vl_basecalcst,'')vBCST, ");
                sQuery.Append("coalesce(nfconhec.vl_totalicmsst,'')vST, ");
                sQuery.Append("coalesce(nfconhec.vl_nf,'')vProd, ");
                sQuery.Append("coalesce(nfconhec.cd_cfop,'')nCFOP ");
                sQuery.Append("from nfconhec ");
                sQuery.Append("join empresa on nfconhec.cd_empresa = empresa.cd_empresa ");
                sQuery.Append("where nfconhec.nr_lancconhecim ='" + sCte + "'");
                sQuery.Append("and empresa.cd_empresa ='" + belStatic.CodEmpresaCte + "'");




                FbCommand fbConn = new FbCommand(sQuery.ToString(), conn);
                fbConn.ExecuteNonQuery();
                FbDataReader dr = fbConn.ExecuteReader();


                objbelinfCte.rem.infNF = new List<belinfNF>();
                objbelinfCte.rem.infNFe = new List<belinfNFe>();
                objbelinfCte.rem.infOutros = new List<belinfOutros>();
                while (dr.Read())
                {
                    switch (dr["Tipo"].ToString())
                    {
                        case "N":
                            belinfNF infNf = new belinfNF();
                            infNf.mod = dr["mod"].ToString();
                            infNf.serie = dr["serie"].ToString();
                            infNf.nDoc = dr["nDoc"].ToString();
                            infNf.dEmi = dr["dEmi"].ToString() != "" ? (Convert.ToDateTime(dr["dEmi"].ToString())).ToString("dd/MM/yyyy") : "";
                            infNf.vBC = dr["vBC"].ToString() != "" ? dr["vBC"].ToString().Replace(",", ".") : "0.00";
                            infNf.vICMS = dr["vICMS"].ToString() != "" ? dr["vICMS"].ToString().Replace(",", ".") : "0.00";
                            infNf.vBCST = dr["vBCST"].ToString() != "" ? dr["vBCST"].ToString().Replace(",", ".") : "0.00";
                            infNf.vST = dr["vST"].ToString() != "" ? dr["vST"].ToString().Replace(",", ".") : "0.00";
                            infNf.vProd = dr["vProd"].ToString() != "" ? dr["vProd"].ToString().Replace(",", ".") : "0.00";
                            infNf.vNF = dr["vProd"].ToString() != "" ? dr["vProd"].ToString().Replace(",", ".") : "0.00";
                            infNf.nCFOP = dr["nCFOP"].ToString() != "" ? Convert.ToInt32(dr["nCFOP"]).ToString() : "0";

                            objbelinfCte.rem.infNF.Add(infNf);
                            break;

                        case "E":
                            belinfNFe infNfe = new belinfNFe();
                            infNfe.chave = dr["chave"].ToString();
                            infNfe.nDoc = dr["nDoc"].ToString();
                            objbelinfCte.rem.infNFe.Add(infNfe);
                            break;

                        case "00":
                            belinfOutros infDeclaracao = new belinfOutros();
                            infDeclaracao.tpDoc = "00";
                            infDeclaracao.nDoc = dr["nDoc"].ToString();
                            infDeclaracao.dEmi = dr["dEmi"].ToString() != "" ? (Convert.ToDateTime(dr["dEmi"].ToString())).ToString("dd/MM/yyyy") : "";
                            infDeclaracao.vDocFisc = dr["vProd"].ToString() != "" ? dr["vProd"].ToString().Replace(",", ".") : "0.00";

                            objbelinfCte.rem.infOutros.Add(infDeclaracao);
                            break;

                        case "10":
                            belinfOutros infDutoviario = new belinfOutros();
                            infDutoviario.tpDoc = "00";
                            infDutoviario.nDoc = dr["nDoc"].ToString();
                            infDutoviario.dEmi = dr["dEmi"].ToString() != "" ? (Convert.ToDateTime(dr["dEmi"].ToString())).ToString("dd/MM/yyyy") : "";
                            infDutoviario.vDocFisc = dr["vProd"].ToString() != "" ? dr["vProd"].ToString().Replace(",", ".") : "0.00";

                            objbelinfCte.rem.infOutros.Add(infDutoviario);
                            break;

                        case "99":
                            belinfOutros infOutros = new belinfOutros();
                            infOutros.tpDoc = "99";
                            infOutros.descOutros = dr["descOutros"].ToString();
                            infOutros.nDoc = dr["nDoc"].ToString();
                            infOutros.dEmi = dr["dEmi"].ToString() != "" ? (Convert.ToDateTime(dr["dEmi"].ToString())).ToString("dd/MM/yyyy") : "";
                            infOutros.vDocFisc = dr["vProd"].ToString() != "" ? dr["vProd"].ToString().Replace(",", ".") : "0.00";

                            objbelinfCte.rem.infOutros.Add(infOutros);
                            break;

                        default:
                            throw new Exception("A nota " + dr["nDoc"].ToString() + " do Conhecimento " + objbelinfCte.ide.nCT + " não tem Tipo selecionado(NF, NF-e, Declaração, Dutoviário, Outros)");

                    }


                }
            }
            catch (Exception ex)
            {
                throw ex;
            }


        }
        private void SalvarAlteracao(int index)
        {
            try
            {
                belinfCte objInfCte = this.objObjetosAlter.objLinfCte[index];

                #region Identificacao
                objInfCte.ide.cUF = txtcUF.Text;
                objInfCte.ide.cCT = txtcCT.Text;
                objInfCte.ide.CFOP = txtCFOP.Text;
                objInfCte.ide.natOp = txtnatOp.Text;
                objInfCte.ide.forPag = cboforPag.SelectedIndex;
                objInfCte.ide.mod = txtmod.Text;
                objInfCte.ide.serie = txtserie.Text;
                objInfCte.ide.nCT = txtnCT.Text;
                switch (cbotpEmis.SelectedIndex)
                {
                    case 0: objInfCte.ide.tpEmis = "1";
                        break;
                    case 1: objInfCte.ide.tpEmis = "5";
                        break;

                    case 2: objInfCte.ide.tpEmis = "7";
                        break;

                    case 3: objInfCte.ide.tpEmis = "8";
                        break;

                    default: objInfCte.ide.tpEmis = "";
                        break;
                }

                objInfCte.ide.cDV = txtcDV.Text;
                objInfCte.ide.tpCTe = cbotpCTe.SelectedIndex;
                objInfCte.ide.verProc = txtverProc.Text;
                objInfCte.ide.cMunEnv = txtcMunEmi.Text;
                objInfCte.ide.xMunEnv = txtxMunEmi.Text;
                objInfCte.ide.UFEnv = txtUFEmi.Text;
                objInfCte.ide.modal = "0" + (cbomodal.SelectedIndex + 1).ToString();
                objInfCte.ide.tpServ = cbotpServ.SelectedIndex;
                objInfCte.ide.cMunIni = txtcMunIni.Text;
                objInfCte.ide.xMunIni = txtxMunIni.Text;
                objInfCte.ide.UFIni = txtUFIni.Text;
                objInfCte.ide.cMunFim = txtcMunFim.Text;
                objInfCte.ide.xMunFim = txtxMunFim.Text;
                objInfCte.ide.UFFim = txtUFFim.Text;
                objInfCte.ide.retira = cboretira.SelectedIndex;


                #endregion

                #region Compl
                if (txtObs.Text != "")
                {
                    belcompl objcompl = new belcompl();
                    objcompl.ObsCont.Xtexto = txtObs.Text;
                    objcompl.ObsCont.Xcampo = "OBSERVACAO";
                    objInfCte.compl = objcompl;
                }

                #endregion

                #region Tomador
                objInfCte.ide.toma03 = null;

                objInfCte.ide.toma04 = null;

                if (cbotoma.SelectedIndex != -1)
                {
                    if (cbotoma.SelectedIndex != 4)
                    {
                        objInfCte.ide.toma03 = new beltoma03();
                        objInfCte.ide.toma03.toma = cbotoma.SelectedIndex.ToString();
                    }
                    else
                    {
                        objInfCte.ide.toma04 = new beltoma04();
                        objInfCte.ide.toma04.enderToma = new belenderToma();
                        objInfCte.ide.toma04.toma = cbotoma.SelectedIndex.ToString();

                        string sCnpj = txtCNPJtoma.Text;
                        if (sCnpj != "")
                        {
                            if (txtCNPJtoma.Text.Length == 14)
                            {
                                objInfCte.ide.toma04.CNPJ = sCnpj;
                            }
                            else if (txtCNPJtoma.Text.Length == 11)
                            {
                                objInfCte.ide.toma04.CPF = sCnpj;
                            }
                        }
                        objInfCte.ide.toma04.IE = txtIEToma.Text;
                        objInfCte.ide.toma04.xNome = txtxNomeToma.Text;
                        objInfCte.ide.toma04.xFant = txtxFantToma.Text;
                        if (txtfoneToma.Text != "")
                        {
                            objInfCte.ide.toma04.fone = txtfoneToma.Text;
                        }
                        objInfCte.ide.toma04.enderToma.xLgr = txtxLgrToma.Text;
                        objInfCte.ide.toma04.enderToma.nro = txtnroToma.Text;
                        objInfCte.ide.toma04.enderToma.xCpl = txtxCplToma.Text;
                        objInfCte.ide.toma04.enderToma.xBairro = txtxBairroToma.Text;
                        if (txtcMunToma.Text != "")
                        {
                            objInfCte.ide.toma04.enderToma.cMun = txtcMunToma.Text;
                        }
                        objInfCte.ide.toma04.enderToma.xMun = txtxMunToma.Text;

                        string sCep = mskCEPToma.Text.Replace(" ", "").Replace("-", "");
                        objInfCte.ide.toma04.enderToma.CEP = sCep;

                        objInfCte.ide.toma04.enderToma.UF = txtUFToma.Text;
                        if (txtcPaisToma.Text != "")
                        {
                            objInfCte.ide.toma04.enderToma.cPais = txtcPaisToma.Text;
                        }
                        objInfCte.ide.toma04.enderToma.xPais = txtxPaisToma.Text;

                    }
                }
                #endregion

                #region Emitente

                objInfCte.emit.CNPJ = txtCNPJEmit.Text.Replace(" ", "").Replace("-", "").Replace("/", "").Replace(".", ""); ;
                objInfCte.emit.IE = txtIEEmit.Text;
                objInfCte.emit.xNome = txtxNomeEmit.Text;
                objInfCte.emit.xFant = txtxFantEmit.Text;

                objInfCte.emit.enderEmit.xLgr = txtxLgrEmit.Text;
                objInfCte.emit.enderEmit.nro = txtnroEmit.Text;
                objInfCte.emit.enderEmit.xCpl = txtxCplEmit.Text;
                objInfCte.emit.enderEmit.xBairro = txtxBairroEmit.Text;
                if (txtcMunEmit.Text != "")
                {
                    objInfCte.emit.enderEmit.cMun = txtcMunEmit.Text;
                }
                objInfCte.emit.enderEmit.xMun = txtxMunEmit.Text;

                string sCepemit = mskCEPEmit.Text.Replace(" ", "").Replace("-", "");
                if (sCepemit != "")
                {
                    objInfCte.emit.enderEmit.CEP = sCepemit;
                }
                objInfCte.emit.enderEmit.UF = txtUFEmit.Text;
                if (txtfoneEmit.Text != "")
                {
                    objInfCte.emit.enderEmit.fone = txtfoneEmit.Text;
                }

                #endregion

                #region Remetente
                objInfCte.rem = new belrem();
                objInfCte.rem.enderReme = new belenderReme();

                if (objInfCte.rem.CNPJ != "")
                {
                    if (txtCNPJrem.Text.Length == 14)
                    {
                        objInfCte.rem.CNPJ = txtCNPJrem.Text;
                    }
                }
                else if (objInfCte.rem.CPF != "")
                {
                    if (txtCNPJrem.Text.Length == 11)
                    {
                        objInfCte.rem.CPF = txtCNPJrem.Text;
                    }
                }
                else
                {
                    if (txtCNPJrem.Text.Length == 14)
                    {
                        objInfCte.rem.CNPJ = txtCNPJrem.Text;
                    }
                    else if (txtCNPJrem.Text.Length == 11)
                    {
                        objInfCte.rem.CPF = txtCNPJrem.Text;
                    }
                }
                objInfCte.rem.IE = txtIErem.Text;
                objInfCte.rem.xNome = txtxNomerem.Text;
                objInfCte.rem.xFant = txtxFantrem.Text;
                objInfCte.rem.fone = txtfonerem.Text;


                objInfCte.rem.enderReme.xLgr = txtxLgrrem.Text;
                objInfCte.rem.enderReme.nro = txtnrorem.Text;
                objInfCte.rem.enderReme.xCpl = txtxCplrem.Text;
                objInfCte.rem.enderReme.xBairro = txtxBairrorem.Text;
                objInfCte.rem.enderReme.cMun = txtcMunrem.Text;
                objInfCte.rem.enderReme.xMun = txtxMunrem.Text;
                objInfCte.rem.enderReme.CEP = mskCEPrem.Text;
                objInfCte.rem.enderReme.UF = txtUFrem.Text;
                objInfCte.rem.enderReme.xPais = xPaisrem.Text;
                objInfCte.rem.enderReme.cPais = txtcPaisrem.Text;

                #endregion

                #region Destinatario

                objInfCte.dest = new beldest();
                objInfCte.dest.enderDest = new belenderDest();

                if (objInfCte.dest.CNPJ != "")
                {
                    if (txtCNPJdest.Text.Length == 14)
                    {
                        objInfCte.dest.CNPJ = txtCNPJdest.Text;
                    }
                }
                else if (objInfCte.dest.CPF != "")
                {
                    if (txtCNPJdest.Text.Length == 11)
                    {
                        objInfCte.dest.CPF = txtCNPJdest.Text;
                    }
                }
                else
                {
                    if (txtCNPJdest.Text.Length == 14)
                    {
                        objInfCte.dest.CNPJ = txtCNPJdest.Text;
                    }
                    else if (txtCNPJdest.Text.Length == 11)
                    {
                        objInfCte.dest.CPF = txtCNPJdest.Text;
                    }
                }

                objInfCte.dest.IE = txtIEdest.Text;
                objInfCte.dest.xNome = txtxNomedest.Text;
                objInfCte.dest.fone = txtfonedest.Text;
                objInfCte.dest.ISUF = txtISUFdest.Text;


                objInfCte.dest.enderDest.xLgr = txtxLgrdest.Text;
                objInfCte.dest.enderDest.nro = txtnrodest.Text;
                objInfCte.dest.enderDest.xCpl = txtxCpldest.Text;
                objInfCte.dest.enderDest.xBairro = txtxBairrodest.Text;
                objInfCte.dest.enderDest.cMun = txtcMundest.Text;
                objInfCte.dest.enderDest.xMun = txtxMundest.Text;
                objInfCte.dest.enderDest.CEP = mskCEPdest.Text;
                objInfCte.dest.enderDest.UF = txtUFdest.Text;
                objInfCte.dest.enderDest.xPais = txtxPaisdest.Text;
                objInfCte.dest.enderDest.cPais = txtcPaisdest.Text;

                #endregion

                #region Expedidor
                if (objInfCte.exped != null)
                {
                    if (objInfCte.exped.CNPJ != "")
                    {
                        if (txtCNPJexped.Text.Length == 14)
                        {
                            objInfCte.exped.CNPJ = txtCNPJexped.Text;
                        }
                    }
                    else if (objInfCte.exped.CPF != "")
                    {
                        if (txtCNPJexped.Text.Length == 11)
                        {
                            objInfCte.exped.CPF = txtCNPJexped.Text;
                        }
                    }
                    else
                    {
                        if (txtCNPJexped.Text.Length == 14)
                        {
                            objInfCte.exped.CNPJ = txtCNPJexped.Text;
                        }
                        else if (txtCNPJexped.Text.Length == 11)
                        {
                            objInfCte.exped.CPF = txtCNPJexped.Text;
                        }
                    }

                    objInfCte.exped.IE = txtIEexped.Text;
                    objInfCte.exped.xNome = txtxNomeexped.Text;
                    objInfCte.exped.fone = txtfoneexped.Text;


                    objInfCte.exped.enderExped.xLgr = txtxLgrexped.Text;
                    objInfCte.exped.enderExped.nro = txtnroexped.Text;
                    objInfCte.exped.enderExped.xBairro = txtxBairroexped.Text;
                    objInfCte.exped.enderExped.xCpl = txtxCplexped.Text;
                    objInfCte.exped.enderExped.cMun = txtcMunexped.Text;
                    objInfCte.exped.enderExped.xMun = txtxMunexped.Text;
                    objInfCte.exped.enderExped.CEP = mskCEPexped.Text;
                    objInfCte.exped.enderExped.UF = txtUFexped.Text;
                    objInfCte.exped.enderExped.xPais = txtxPaisexped.Text;
                    objInfCte.exped.enderExped.cPais = txtcPaisexped.Text;

                }


                #endregion

                #region Recebedor
                if (objInfCte.receb != null)
                {
                    if (objInfCte.receb.CNPJ != "")
                    {
                        if (txtCpfCnpfreceb.Text.Length == 14)
                        {
                            objInfCte.receb.CNPJ = txtCpfCnpfreceb.Text;
                        }
                    }
                    else if (objInfCte.receb.CPF != "")
                    {
                        if (txtCpfCnpfreceb.Text.Length == 11)
                        {
                            objInfCte.receb.CPF = txtCpfCnpfreceb.Text;
                        }
                    }
                    else
                    {
                        if (txtCpfCnpfreceb.Text.Length == 14)
                        {
                            objInfCte.receb.CNPJ = txtCpfCnpfreceb.Text;
                        }
                        else if (txtCpfCnpfreceb.Text.Length == 11)
                        {
                            objInfCte.receb.CPF = txtCpfCnpfreceb.Text;
                        }
                    }

                    objInfCte.receb.IE = txtIEreceb.Text;
                    objInfCte.receb.xNome = txtxNomereceb.Text;
                    objInfCte.receb.fone = txtfonereceb.Text;

                    objInfCte.receb.enderReceb.xLgr = txtxLgrreceb.Text;
                    objInfCte.receb.enderReceb.nro = txtnroreceb.Text;
                    objInfCte.receb.enderReceb.xBairro = txtxBairroreceb.Text;
                    objInfCte.receb.enderReceb.xCpl = txtxCplreceb.Text;
                    objInfCte.receb.enderReceb.cMun = txtcMunreceb.Text;
                    objInfCte.receb.enderReceb.xMun = txtxMunreceb.Text;
                    objInfCte.receb.enderReceb.CEP = mskCEPreceb.Text;
                    objInfCte.receb.enderReceb.UF = txtUFreceb.Text;
                    objInfCte.receb.enderReceb.xPais = txtxPaisreceb.Text;
                    objInfCte.receb.enderReceb.cPais = txtcPaisreceb.Text;

                }


                #endregion

                #region Informacoes da NF

                objInfCte.rem.infNF = new List<belinfNF>();
                for (int j = 0; j < gridNfNormal.RowCount; j++)
                {
                    belinfNF nf = new belinfNF();

                    switch (gridNfNormal.Rows[j].Cells["mod"].Value.ToString())
                    {
                        case "01 - NF Modelo 01/1A e Avulsa": nf.mod = "01";
                            break;
                        case "04 - NF de Produtor": nf.mod = "04";
                            break;
                    }
                    nf.nDoc = gridNfNormal.Rows[j].Cells["nDoc"].Value == null ? "" : gridNfNormal.Rows[j].Cells["nDoc"].Value.ToString();
                    nf.serie = gridNfNormal.Rows[j].Cells["serie"].Value == null ? "" : gridNfNormal.Rows[j].Cells["serie"].Value.ToString();
                    nf.dEmi = gridNfNormal.Rows[j].Cells["dEmi"].Value == null ? "" : gridNfNormal.Rows[j].Cells["dEmi"].Value.ToString();
                    nf.vBC = gridNfNormal.Rows[j].Cells["vBC"].Value == null ? "" : gridNfNormal.Rows[j].Cells["vBC"].Value.ToString().Replace(",", ".");
                    nf.vICMS = gridNfNormal.Rows[j].Cells["vICMS"].Value == null ? "" : gridNfNormal.Rows[j].Cells["vICMS"].Value.ToString().Replace(",", ".");
                    nf.vBCST = gridNfNormal.Rows[j].Cells["vBCST"].Value == null ? "" : gridNfNormal.Rows[j].Cells["vBCST"].Value.ToString().Replace(",", ".");
                    nf.vST = gridNfNormal.Rows[j].Cells["vST"].Value == null ? "" : gridNfNormal.Rows[j].Cells["vST"].Value.ToString().Replace(",", ".");
                    nf.vProd = gridNfNormal.Rows[j].Cells["vProd"].Value == null ? "" : gridNfNormal.Rows[j].Cells["vProd"].Value.ToString().Replace(",", ".");
                    nf.vNF = gridNfNormal.Rows[j].Cells["vNF"].Value == null ? "" : gridNfNormal.Rows[j].Cells["vNF"].Value.ToString().Replace(",", ".");
                    nf.nCFOP = gridNfNormal.Rows[j].Cells["nCFOP"].Value == null ? "" : gridNfNormal.Rows[j].Cells["nCFOP"].Value.ToString();

                    objInfCte.rem.infNF.Add(nf);
                }

                objInfCte.rem.infNFe = new List<belinfNFe>();
                for (int n = 0; n < gridNfe.RowCount; n++)
                {
                    belinfNFe nfe = new belinfNFe();
                    nfe.chave = gridNfe.Rows[n].Cells[0].Value == null ? "" : gridNfe.Rows[n].Cells[0].Value.ToString();

                    objInfCte.rem.infNFe.Add(nfe);
                }



                #endregion

                #region Outros Documentos

                objInfCte.rem.infOutros = new List<belinfOutros>();
                for (int j = 0; j < gridDocumentos.RowCount; j++)
                {
                    belinfOutros infOutros = new belinfOutros();
                    switch (gridDocumentos.Rows[j].Cells["tpDoc"].Value.ToString())
                    {
                        case "00 - Declaração":
                            infOutros.tpDoc = "00";
                            break;
                        case "10 - Dutoviário":
                            infOutros.tpDoc = "10";
                            break;
                        case "99 - Outros":
                            infOutros.tpDoc = "99";
                            break;
                    }
                    infOutros.descOutros = gridDocumentos.Rows[j].Cells["descOutros"].Value == null ? "" : gridDocumentos.Rows[j].Cells["descOutros"].Value.ToString();
                    infOutros.nDoc = gridDocumentos.Rows[j].Cells["nDoc_"].Value == null ? "" : gridDocumentos.Rows[j].Cells["nDoc_"].Value.ToString();
                    infOutros.dEmi = gridDocumentos.Rows[j].Cells["dEmi_"].Value == null ? "" : gridDocumentos.Rows[j].Cells["dEmi_"].Value.ToString();
                    infOutros.vDocFisc = gridDocumentos.Rows[j].Cells["vDocFisc"].Value == null ? "" : gridDocumentos.Rows[j].Cells["vDocFisc"].Value.ToString().Replace(",", ".");

                    objInfCte.rem.infOutros.Add(infOutros);
                }

                #endregion

                #region Valores

                objInfCte.vPrest.vTPrest = nudvTPrest.Value.ToString().Replace(",", ".");
                objInfCte.vPrest.vRec = nudvRec.Value.ToString().Replace(",", ".");

                objInfCte.vPrest.Comp = new List<belComp>();
                belComp Comp = new belComp();

                #region Componentes
                if (nudvFrete.Value > 0)
                {
                    Comp.xNome = "FRETE VALOR";
                    Comp.vComp = nudvFrete.Text.Replace(",", ".");
                    objInfCte.vPrest.Comp.Add(Comp);
                }
                if (nudFreteCubagem.Value > 0)
                {
                    Comp = new belComp();
                    Comp.xNome = "FRETE CUBAGEM";
                    Comp.vComp = nudFreteCubagem.Text.Replace(",", ".");
                    objInfCte.vPrest.Comp.Add(Comp);
                }

                if (nudFretePeso.Value > 0)
                {
                    Comp = new belComp();
                    Comp.xNome = "FRETE PESO";
                    Comp.vComp = nudFretePeso.Text.Replace(",", ".");
                    objInfCte.vPrest.Comp.Add(Comp);
                }

                if (nudCat.Value > 0)
                {
                    Comp = new belComp();
                    Comp.xNome = "CAT";
                    Comp.vComp = nudCat.Text.Replace(",", ".");
                    objInfCte.vPrest.Comp.Add(Comp);
                }

                if (nudDespacho.Value > 0)
                {
                    Comp = new belComp();
                    Comp.xNome = "DESPACHO";
                    Comp.vComp = nudDespacho.Text.Replace(",", ".");
                    objInfCte.vPrest.Comp.Add(Comp);
                }

                if (nudPedagio.Value > 0)
                {
                    Comp = new belComp();
                    Comp.xNome = "PEDAGIO";
                    Comp.vComp = nudPedagio.Text.Replace(",", ".");
                    objInfCte.vPrest.Comp.Add(Comp);
                }

                if (nudOutros.Value > 0)
                {
                    Comp = new belComp();
                    Comp.xNome = "OUTROS";
                    Comp.vComp = nudOutros.Text.Replace(",", ".");
                    objInfCte.vPrest.Comp.Add(Comp);
                }

                if (nudAdme.Value > 0)
                {
                    Comp = new belComp();
                    Comp.xNome = "ADME";
                    Comp.vComp = nudAdme.Text.Replace(",", ".");
                    objInfCte.vPrest.Comp.Add(Comp);
                }

                if (nudEntrega.Value > 0)
                {
                    Comp = new belComp();
                    Comp.xNome = "ENTREGA";
                    Comp.vComp = nudEntrega.Text.Replace(",", ".");
                    objInfCte.vPrest.Comp.Add(Comp);
                }
                #endregion




                objInfCte.imp.ICMS = new belICMS();
                if (cboCST.SelectedIndex == 0)
                {
                    objInfCte.imp.ICMS.ICMS00 = new belICMS00();
                    objInfCte.imp.ICMS.ICMS00.CST = "00";
                    objInfCte.imp.ICMS.ICMS00.vBC = nudvBC.Value.ToString().Replace(",", ".");
                    objInfCte.imp.ICMS.ICMS00.pICMS = nudpICMS.Value.ToString().Replace(",", ".");
                    objInfCte.imp.ICMS.ICMS00.vICMS = nudvICMS.Value.ToString().Replace(",", ".");
                }
                else if (cboCST.SelectedIndex == 1)
                {
                    objInfCte.imp.ICMS.ICMS20 = new belICMS20();
                    objInfCte.imp.ICMS.ICMS20.CST = "20";
                    objInfCte.imp.ICMS.ICMS20.pRedBC = nudpRedBC.Value.ToString().Replace(",", ".");
                    objInfCte.imp.ICMS.ICMS20.vBC = nudvBC.Value.ToString().Replace(",", ".");
                    objInfCte.imp.ICMS.ICMS20.pICMS = nudpICMS.Value.ToString().Replace(",", ".");
                    objInfCte.imp.ICMS.ICMS20.vICMS = nudvICMS.Value.ToString().Replace(",", ".");
                }
                else if (cboCST.SelectedIndex == 2 || cboCST.SelectedIndex == 3 || cboCST.SelectedIndex == 4)
                {
                    objInfCte.imp.ICMS.ICMS45 = new belICMS45();
                    switch (cboCST.SelectedIndex)
                    {
                        case 2: objInfCte.imp.ICMS.ICMS45.CST = "40";
                            break;
                        case 3: objInfCte.imp.ICMS.ICMS45.CST = "41";
                            break;
                        case 4: objInfCte.imp.ICMS.ICMS45.CST = "51";
                            break;
                    }
                }
                else if (cboCST.SelectedIndex == 5)
                {
                    objInfCte.imp.ICMS.ICMS60 = new belICMS60();
                    objInfCte.imp.ICMS.ICMS60.CST = "60";
                    objInfCte.imp.ICMS.ICMS60.vBCSTRet = nudvBC.Value.ToString().Replace(",", ".");
                    objInfCte.imp.ICMS.ICMS60.vICMSSTRet = nudvICMS.Value.ToString().Replace(",", ".");
                    objInfCte.imp.ICMS.ICMS60.pICMSSTRet = nudpICMS.Value.ToString().Replace(",", ".");
                }
                else if (cboCST.SelectedIndex == 6)
                {
                    objInfCte.imp.ICMS.ICMS90 = new belICMS90();
                    objInfCte.imp.ICMS.ICMS90.CST = "90";
                    objInfCte.imp.ICMS.ICMS90.pRedBC = nudpRedBC.Value.ToString().Replace(",", ".");
                    objInfCte.imp.ICMS.ICMS90.vBC = nudvBC.Value.ToString().Replace(",", ".");
                    objInfCte.imp.ICMS.ICMS90.pICMS = nudpICMS.Value.ToString().Replace(",", ".");
                    objInfCte.imp.ICMS.ICMS90.vICMS = nudvICMS.Value.ToString().Replace(",", ".");
                }
                else if (cboCST.SelectedIndex == 7)
                {
                    objInfCte.imp.ICMS.ICMSOutraUF = new belICMSOutraUF();
                    objInfCte.imp.ICMS.ICMSOutraUF.CST = "90";
                    objInfCte.imp.ICMS.ICMSOutraUF.pRedBCOutraUF = nudpRedBC.Value.ToString().Replace(",", ".");
                    objInfCte.imp.ICMS.ICMSOutraUF.vBCOutraUF = nudvBC.Value.ToString().Replace(",", ".");
                    objInfCte.imp.ICMS.ICMSOutraUF.pICMSOutraUF = nudpICMS.Value.ToString().Replace(",", ".");
                    objInfCte.imp.ICMS.ICMSOutraUF.vICMSOutraUF = nudvICMS.Value.ToString().Replace(",", ".");
                }



                #endregion

                #region InformacoesCarga

                objInfCte.infCTeNorm.infCarga.vCarga = nudvMerc.Value;
                objInfCte.infCTeNorm.infCarga.proPred = txtproPred.Text;
                objInfCte.infCTeNorm.infCarga.xOutCat = txtxOutCat.Text;


                objInfCte.infCTeNorm.infCarga.infQ = new List<belinfQ>();
                for (int j = 0; j < gridinfQ.RowCount; j++)
                {
                    belinfQ obj = new belinfQ();
                    if (gridinfQ.Rows[j].Cells[0].Value == null)
                    {
                        obj.cUnid = "";
                    }
                    else
                    {
                        switch (gridinfQ.Rows[j].Cells[0].Value.ToString())
                        {
                            case "00-M3": obj.cUnid = "00";
                                break;
                            case "01-KG": obj.cUnid = "01";
                                break;
                            case "02-Ton": obj.cUnid = "02";
                                break;
                            case "03-Unidade": obj.cUnid = "03";
                                break;
                            case "04-Litros": obj.cUnid = "04";
                                break;
                        }
                    }
                    if (gridinfQ.Rows[j].Cells[1].Value == null)
                    {
                        obj.tpMed = "";
                    }
                    else
                    {
                        obj.tpMed = gridinfQ.Rows[j].Cells[1].Value.ToString();
                    }
                    if (gridinfQ.Rows[j].Cells[2].Value == null)
                    {
                        obj.qCarga = 0;
                    }
                    else
                    {
                        obj.qCarga = Convert.ToDecimal(gridinfQ.Rows[j].Cells[2].Value.ToString());
                    }

                    objInfCte.infCTeNorm.infCarga.infQ.Add(obj);
                }

                #endregion

                #region Rodoviario

                objInfCte.infCTeNorm.seg.respSeg = cborespSeg.SelectedIndex != -1 ? cborespSeg.SelectedIndex.ToString() : "";
                objInfCte.infCTeNorm.rodo.dPrev = mskdPrev.Text.Replace(" ", "").Replace("/", "") != "" ? Convert.ToDateTime(mskdPrev.Text).ToShortDateString() : "";
                objInfCte.infCTeNorm.seg.nApol = txtnApol.Text;
                objInfCte.infCTeNorm.rodo.RNTRC = txtRNTRC.Text;
                objInfCte.infCTeNorm.rodo.lota = cbolota.SelectedIndex != -1 ? cbolota.SelectedIndex.ToString() : "";

                #endregion

                #region Veiculo

                if (objInfCte.infCTeNorm.rodo.veic.Count() > 0)
                {
                    if (VerificaCamposVeiculo() || objInfCte.infCTeNorm.rodo.lota == "1")
                    {
                        belveic veic = (belveic)bsVeiculos.Current;

                        veic.RENAVAM = txtRENAVAM.Text;
                        veic.placa = txtplaca.Text;
                        veic.tara = nudtara.Value.ToString();
                        veic.capKG = nudcapKG.Value.ToString();
                        veic.capM3 = nudcapM3.Value.ToString();
                        switch (cbotpProp.SelectedIndex)
                        {
                            case 0:
                                veic.tpProp = "P";
                                break;
                            case 1:
                                veic.tpProp = "T";
                                break;
                            default:
                                veic.tpProp = "";
                                break;
                        }
                        veic.tpVeic = cbotpVeic.SelectedIndex != -1 ? cbotpVeic.SelectedIndex.ToString() : "";
                        veic.tpRod = cbotpRod.SelectedIndex != -1 ? "0" + cbotpRod.SelectedIndex.ToString() : "";
                        veic.tpCar = cbotpCar.SelectedIndex != -1 ? "0" + cbotpCar.SelectedIndex.ToString() : "";
                        veic.UF = txtUF.Text;

                        if (veic.tpProp == "T")
                        {
                            veic.prop = new belprop();
                            veic.prop.CPFCNPJ = txtCPFprop.Text;
                            veic.prop.RNTRC = txtRNTRCprop.Text;
                            veic.prop.xNome = txtxNomeprop.Text;
                            veic.prop.IE = txtIEprop.Text;
                            veic.prop.UF = txtUFprop.Text;
                            veic.prop.tpProp = cbotpPropprop.SelectedIndex != -1 ? cbotpCar.SelectedIndex.ToString() : "";
                        }
                        else
                        {
                            veic.prop = null;
                        }
                    }
                }

                if (VerificaCamposProprietarioVeiculo() || objInfCte.infCTeNorm.rodo.lota == "1")
                {
                    objInfCte.infCTeNorm.rodo.moto = new belmoto();
                    objInfCte.infCTeNorm.rodo.moto.xNome = txtxNomemoto.Text;
                    objInfCte.infCTeNorm.rodo.moto.CPF = txtCPFmoto.Text;
                }
                else
                {
                    objInfCte.infCTeNorm.rodo.moto = null;
                }

                #endregion


                VerificaCte();

            }
            catch (Exception ex)
            {
                KryptonMessageBox.Show(null, _sMessageException + (ex.InnerException != null ? ex.InnerException.Message : ex.Message).ToString(), "CT-e - AVISO", MessageBoxButtons.OK, MessageBoxIcon.Information); ;
            }
        }