Пример #1
0
        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); ;
            }
        }
Пример #2
0
        public void PopulaVPrest(belinfCte objbelinfCte, FbConnection conn, string sCte)
        {
            try
            {
                StringBuilder sQuery = new StringBuilder();

                sQuery.Append("Select ");
                sQuery.Append("coalesce (conhecim.vl_total,'') vTPrest, ");
                sQuery.Append("coalesce (conhecim.vl_frcubagem,'') FRETECUBAGEM, ");
                sQuery.Append("coalesce (conhecim.vl_frpeso,'') FRETEPESO, ");
                sQuery.Append("coalesce (conhecim.vl_cat,'') CAT, ");
                sQuery.Append("coalesce (conhecim.vl_desp,'') DESPACHO, ");
                sQuery.Append("coalesce (conhecim.vl_pedagio,'') PEDAGIO, ");
                sQuery.Append("coalesce (conhecim.vl_outros,'') OUTROS, ");
                sQuery.Append("coalesce (conhecim.vl_adval,'') ADME, ");
                sQuery.Append("coalesce (conhecim.vl_entcole,'') ENTREGA, ");
                sQuery.Append("coalesce (conhecim.vl_frvalor,'') FRETEVALOR ");
                sQuery.Append("From conhecim  ");
                sQuery.Append("join  empresa on conhecim.cd_empresa = empresa.cd_empresa ");
                sQuery.Append("Where conhecim.nr_lanc = '" + sCte + "'");
                sQuery.Append("And empresa.cd_empresa = '" + belStatic.CodEmpresaCte + "'");


                FbCommand fbConn = new FbCommand(sQuery.ToString(), conn);
                fbConn.ExecuteNonQuery();
                FbDataReader dr = fbConn.ExecuteReader();
                objbelinfCte.vPrest = new belvPrest();
                objbelinfCte.vPrest.Comp = new List<belComp >();

                while (dr.Read())
                {
                    objbelinfCte.vPrest.vTPrest = dr["vTPrest"].ToString();
                    objbelinfCte.vPrest.vRec = dr["vTPrest"].ToString();

                    belComp Comp = new belComp();
                    if (dr["FRETEVALOR"].ToString() != "0.00")
                    {
                        Comp = new belComp();
                        Comp.xNome = "FRETE VALOR";
                        Comp.vComp = dr["FRETEVALOR"].ToString();
                        objbelinfCte.vPrest.Comp.Add(Comp);
                    }
                    if (dr["FRETECUBAGEM"].ToString() != "0.00")
                    {
                        Comp = new belComp();
                        Comp.xNome = "FRETE CUBAGEM";
                        Comp.vComp = dr["FRETECUBAGEM"].ToString();
                        objbelinfCte.vPrest.Comp.Add(Comp);
                    }
                    if (dr["FRETEPESO"].ToString() != "0.00")
                    {
                        Comp = new belComp();
                        Comp.xNome = "FRETE PESO";
                        Comp.vComp = dr["FRETEPESO"].ToString();
                        objbelinfCte.vPrest.Comp.Add(Comp);
                    }
                    if (dr["CAT"].ToString() != "0.00")
                    {
                        Comp = new belComp();
                        Comp.xNome = "CAT";
                        Comp.vComp = dr["CAT"].ToString();
                        objbelinfCte.vPrest.Comp.Add(Comp);
                    }
                    if (dr["DESPACHO"].ToString() != "0.00")
                    {
                        Comp = new belComp();
                        Comp.xNome = "DESPACHO";
                        Comp.vComp = dr["DESPACHO"].ToString();
                        objbelinfCte.vPrest.Comp.Add(Comp);
                    }
                    if (dr["PEDAGIO"].ToString() != "0.00")
                    {
                        Comp = new belComp();
                        Comp.xNome = "PEDAGIO";
                        Comp.vComp = dr["PEDAGIO"].ToString();
                        objbelinfCte.vPrest.Comp.Add(Comp);
                    }
                    if (dr["OUTROS"].ToString() != "0.00")
                    {
                        Comp = new belComp();
                        Comp.xNome = "OUTROS";
                        Comp.vComp = dr["OUTROS"].ToString();
                        objbelinfCte.vPrest.Comp.Add(Comp);
                    }
                    if (dr["ADME"].ToString() != "0.00")
                    {
                        Comp = new belComp();
                        Comp.xNome = "ADME";
                        Comp.vComp = dr["ADME"].ToString();
                        objbelinfCte.vPrest.Comp.Add(Comp);
                    }
                    if (dr["ENTREGA"].ToString() != "0.00")
                    {
                        Comp = new belComp();
                        Comp.xNome = "ENTREGA";
                        Comp.vComp = dr["ENTREGA"].ToString();
                        objbelinfCte.vPrest.Comp.Add(Comp);
                    }
                    

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

        }