private void BuscaDados()
        {
            DataSet   ds  = new DataSet();
            daoTrocas bdt = new daoTrocas();

            if (dropSelecao.SelectedValue != "Selecione")
            {
                int tipo = Convert.ToInt32(dropSelecao.SelectedValue);

                switch (tipo)
                {
                case 1:
                    ds = bdt.pro_getDados(1, txtContratoPlaca.Text);
                    break;

                case 2:
                    ds = bdt.pro_getDados(2, txtContratoPlaca.Text);
                    break;
                }
            }
            else
            {
            }
            if (ds.Tables[0].Rows.Count > 0)
            {
                txtNome.Text              = ds.Tables[0].Rows[0]["ds_nome"].ToString();
                txtId.Text                = ds.Tables[0].Rows[0]["idpeca"].ToString();
                txtContrato.Text          = ds.Tables[0].Rows[0]["Pedido"].ToString();
                txtPlaca.Text             = ds.Tables[0].Rows[0]["ds_placa"].ToString();
                txtProduto.Text           = ds.Tables[0].Rows[0]["ds_produto"].ToString();
                txtStatusContrato.Text    = ds.Tables[0].Rows[0]["ds_statusCliente"].ToString();
                txtStatusAtendimento.Text = ds.Tables[0].Rows[0]["ds_statusAtendimento"].ToString();
                txtstatusVenda.Text       = ds.Tables[0].Rows[0]["ds_statusVenda"].ToString();
                txtCpf_Cnpj.Text          = ds.Tables[0].Rows[0]["ds_Cpf_Cnpj"].ToString();
                txtDocumento.Text         = ds.Tables[0].Rows[0]["ds_documento"].ToString();
                txtDataNascimento.Text    = ds.Tables[0].Rows[0]["dt_nascimento"].ToString();
                txtDataVenda.Text         = ds.Tables[0].Rows[0]["dt_venda"].ToString();
                txtDtConfirmacao.Text     = ds.Tables[0].Rows[0]["dt_confirmacao"].ToString();
                txtVendedor.Text          = ds.Tables[0].Rows[0]["ds_vendedor"].ToString();
                txtVeiculo.Text           = ds.Tables[0].Rows[0]["ds_modelo"].ToString();
                txtFabricante.Text        = ds.Tables[0].Rows[0]["ds_fabricante"].ToString();
                txtCategoria.Text         = ds.Tables[0].Rows[0]["ds_categoria"].ToString();
                txtAno.Text               = ds.Tables[0].Rows[0]["ds_ano"].ToString();
                txtRenavan.Text           = ds.Tables[0].Rows[0]["ds_renavan"].ToString();
                txtChassi.Text            = ds.Tables[0].Rows[0]["ds_chassi"].ToString();
                txtCombustivel.Text       = ds.Tables[0].Rows[0]["ds_combustivel"].ToString();
                txtCor.Text               = ds.Tables[0].Rows[0]["Cor"].ToString();
                divProduto.Visible        = true;
                txtCodigo.Text            = ds.Tables[0].Rows[0]["id_produto"].ToString();
                int _produto = Convert.ToInt32(ds.Tables[0].Rows[0]["id_produto"].ToString());
                getProdutos(_produto);
            }
            else
            {
                Mensagem("Contrato não atende os requisitos..");
                LimpaCampos();
            }
        }
 private void GravaTroca()
 {
     if (txtContrato.Text != "" && txtProduto.Text != "" && txtValorTroca.Text != "0,00")
     {
         int         nr_troca           = 0;
         daoTrocas   bdt                = new daoTrocas();
         AcessoLogin acessoLogin        = (AcessoLogin)Session["acessoLogin"];
         string      contrato           = txtContrato.Text;
         int         id_franquia        = acessoLogin.idFranquia;
         string      ds_produtoAnterior = txtProduto.Text.Substring(0, 6);
         string      vendedor           = acessoLogin.Nome;
         nr_troca = bdt.pro_setTroca(contrato, id_franquia, ds_produtoAnterior, vendedor);
         if (nr_troca > 0)
         {
             int     nr_itens       = 0;
             int     id_novoProduto = Convert.ToInt32(dropProdutosTrocas.SelectedValue);
             decimal vl_troca       = Convert.ToDecimal(txtValorTroca.Text);
             decimal vl_cobrado     = Convert.ToDecimal(txtValorCobrado.Text);
             nr_itens = bdt.pro_setTrocaItens(nr_troca, id_novoProduto, vl_troca, vl_cobrado);
             if (nr_itens > 0)
             {
                 int nr_pagamento = GravaPagamento(nr_troca);
                 if (nr_pagamento > 0)
                 {
                     string produto    = dropProdutosTrocas.SelectedItem.Text;
                     string ds_Usuario = acessoLogin.Nome;
                     int    alterado   = bdt.pro_setAtualizaClientes(contrato, produto, ds_Usuario);
                     if (alterado > 0)
                     {
                         Mensagem("Troca gerada com sucesso: " + nr_troca.ToString());
                         btnFinalizar.Text    = "Pedido gerado N.: " + nr_troca.ToString();
                         btnFinalizar.Enabled = false;
                         btnCancelar.Enabled  = false;
                     }
                 }
             }
         }
     }
     else
     {
         Mensagem("Favor preencher todos os dados");
     }
 }
        private int GravaPagamento(int troca)
        {
            int nr_pagamento = 0;

            if (dropForma.SelectedValue != "Selecione" && txtValor.Text != "0,00" && txtValor.Text != "" && gridPagamento.Rows.Count > 0)
            {
                foreach (GridViewRow gwp in gridPagamento.Rows)
                {
                    daoTrocas bdtp       = new daoTrocas();
                    int       pagamento  = Convert.ToInt32(dropForma.SelectedValue);
                    int       quantidade = Convert.ToInt32(txtQtdParcela.Text);
                    bdtp._dsDoc = txtCpf_Cnpj.Text;
                    decimal valorCalculado = Convert.ToDecimal(txtValor.Text) / quantidade;
                    switch (pagamento)
                    {
                    case 1:
                        bdtp._idtroca     = troca;
                        bdtp._idTipo      = Convert.ToInt32(dropForma.SelectedValue);
                        bdtp._vlPagamento = Convert.ToDecimal(txtValor.Text);
                        bdtp._dataVenc    = DateTime.Now.Date;
                        bdtp._pcParcela   = Convert.ToInt32(txtQtdParcela.Text);
                        bdtp._dsDoc       = txtCpf_Cnpj.Text;
                        bdtp._dsTitular   = txtNome.Text;
                        nr_pagamento      = bdtp.pro_setTrocaPagamento();

                        break;

                    case 2:
                        bdtp._idtroca     = troca;
                        bdtp._idTipo      = Convert.ToInt32(dropForma.SelectedValue);
                        bdtp._vlPagamento = Convert.ToDecimal(txtValor.Text);
                        bdtp._dataVenc    = DateTime.Now.Date;
                        bdtp._pcParcela   = Convert.ToInt32(txtQtdParcela.Text);
                        if (txtTitular.Text != "")
                        {
                            bdtp._dsTitular = txtTitular.Text;
                        }
                        else
                        {
                            bdtp._dsTitular = txtNome.Text;
                        }
                        nr_pagamento = bdtp.pro_setTrocaPagamento();

                        break;

                    case 3:
                        bdtp._idtroca     = troca;
                        bdtp._idTipo      = Convert.ToInt32(gwp.Cells[0].Text);
                        bdtp._vlPagamento = Convert.ToDecimal(gwp.Cells[3].Text);
                        bdtp._dataVenc    = Convert.ToDateTime(gwp.Cells[4].Text);
                        bdtp._pcParcela   = Convert.ToInt32(gwp.Cells[2].Text);
                        bdtp._dsDoc       = txtCpf_Cnpj.Text;
                        if (txtTitular.Text != "")
                        {
                            bdtp._dsTitular = gwp.Cells[5].Text;
                        }
                        else
                        {
                            bdtp._dsTitular = gwp.Cells[5].Text;
                        }
                        bdtp._nrAgencia = gwp.Cells[6].Text;
                        bdtp._nrConta   = gwp.Cells[7].Text;
                        bdtp._ccm       = Server.HtmlDecode(gwp.Cells[11].Text);
                        bdtp._nrBanco   = gwp.Cells[10].Text;
                        bdtp._nr_cheque = gwp.Cells[9].Text;
                        nr_pagamento    = bdtp.pro_setTrocaPagamento();
                        break;

                    case 4:
                        bdtp._idtroca     = troca;
                        bdtp._idTipo      = Convert.ToInt32(dropForma.SelectedValue);
                        bdtp._vlPagamento = Convert.ToDecimal(txtValor.Text);
                        bdtp._dataVenc    = DateTime.Now.Date;
                        bdtp._pcParcela   = Convert.ToInt32(txtQtdParcela.Text);
                        if (txtTitular.Text != "")
                        {
                            bdtp._dsTitular = txtTitular.Text;
                        }
                        else
                        {
                            bdtp._dsTitular = txtNome.Text;
                        }
                        nr_pagamento = bdtp.pro_setTrocaPagamento();
                        break;

                    default:
                        break;
                    }
                }
            }
            else
            {
                Mensagem("Selecione todas as informações..");
            }
            return(nr_pagamento);
        }