protected void btnEditar_Click(object sender, EventArgs e)
        {
            lblPaso.Value="Detalle";
            cargarMoneda_new();

            pnNuevo.Visible = true;
            dgvLetReg.Columns[15].Visible = true;

            int cod_letra = int.Parse(dgvLetReg.Rows[dgvLetReg.SelectedIndex].Cells[15].Text);
            txtFecha.Text = dgvLetReg.Rows[dgvLetReg.SelectedIndex].Cells[6].Text;
            lblPersona.Text = dgvLetReg.Rows[dgvLetReg.SelectedIndex].Cells[5].Text;
            ddlMoneda_new.SelectedValue = dgvLetReg.Rows[dgvLetReg.SelectedIndex].Cells[10].Text;
            txtNumCuotas.Text = dgvLetReg.Rows[dgvLetReg.SelectedIndex].Cells[7].Text;
            lblNroDocumento.Text = dgvLetReg.Rows[dgvLetReg.SelectedIndex].Cells[3].Text;
            String cpago = dgvLetReg.Rows[dgvLetReg.SelectedIndex].Cells[16].Text;
            if (cpago == "D")
                rbtdias.Checked = true;
            else
                rbtletra.Checked = true;
            //////////////////////CARGA FACTURAS
            clsfac_x_letra formFac = new clsfac_x_letra();
            DataTable dtPendientes;

            dtPendientes = formFac.GetList(cod_letra);
            dgvListFact.DataSource = dtPendientes;
            dgvListFact.DataBind();

            //////////////////////CARGA NOTAS
            clsListNotas lstOperaciones = new clsListNotas();
            DataTable dtNotasPen;
            dtNotasPen = lstOperaciones.GetLista("1111112", "0", "N", "", 0, DateTime.Today, DateTime.Today, "V", cod_letra);
            dgvNotas.DataSource = dtNotasPen;
            dgvNotas.DataBind();
            ////////////////////CALCULOS
            Double total_acum = 0.0;
            int multiplica;

            foreach (GridViewRow row in dgvListFact.Rows)
            {
                //CheckBox chk_Publicar = (CheckBox)row.Cells[1].Controls[0];
                CheckBox check = row.FindControl("CheckBox1") as CheckBox;
                check.Checked = true;
                total_acum = total_acum + Convert.ToDouble(row.Cells[5].Text);
            }
            lbSuma.Text = total_acum.ToString();
            //////////////////////////////
            dgvNotas.Columns[3].Visible = true;
            total_acum = 0.0;
            /////////////////////////////
            foreach (GridViewRow rown in dgvNotas.Rows)
            {

                CheckBox check = rown.FindControl("grdchknota") as CheckBox;
                check.Checked = true;

                if (rown.Cells[3].Text.Substring(0, 1) == "1")
                    multiplica = 1;
                else
                    multiplica = -1;

                total_acum = total_acum + (Convert.ToDouble(rown.Cells[7].Text) * multiplica);

            }
            lbresta.Text = (Math.Round(total_acum, 2)).ToString();
            CalculartotalPago();
            ///////////////DETALLE DE LETRAS
            clsdetletra formDet = new clsdetletra();
            DataTable dtDetalle;

            dtDetalle = formDet.GetList(cod_letra);
            int valor = dtDetalle.Rows.Count;
            dgvcuotas.DataSource = dtDetalle;
            dgvcuotas.DataBind();
            int cont = 0;
            foreach (GridViewRow row in dgvcuotas.Rows)
            {
                row.Cells[0].Text = dtDetalle.Rows[cont][1].ToString();
                TextBox txtFecVen = row.FindControl("txtFecVen") as TextBox;
                txtFecVen.Enabled = false;
                txtFecVen.Text = Convert.ToDateTime(dtDetalle.Rows[cont][6]).ToString("yyyy-MM-dd");
                TextBox num_let = row.FindControl("num_let") as TextBox;
                num_let.Text = dtDetalle.Rows[cont][10].ToString();
                num_let.Enabled = false;
                TextBox cod_unic = row.FindControl("cod_unic") as TextBox;
                cod_unic.Text = dtDetalle.Rows[cont][2].ToString();
                cod_unic.Enabled = false;
                TextBox monto = row.FindControl("monto") as TextBox;
                monto.Text = dtDetalle.Rows[cont][3].ToString();
                monto.Enabled = false;
                cont++;
            }

            dgvNotas.Columns[3].Visible = false;

            HabilitarBtn(btnEditar, false);
            HabilitarBtn(btnCancelar, true);
            HabilitarBtn(btnProcesar, true);
            pnNuevo.Enabled = false;
            btgenCuotas.Visible = false;
            dgvLetReg.Columns[15].Visible = false;
        }
        protected void btnEditar_Click(object sender, EventArgs e)
        {
            btnImprimir.Visible = true;
            HabilitarBtn(btnImprimir, true);
            int nOpeCod = 0;
            try
            {
                HabilitarCampos(true);

                nOpeCod = int.Parse(dgvListOperLetras.Rows[dgvListOperLetras.SelectedIndex].Cells[2].Text);
                lblNroDocumento.Text = dgvListOperLetras.Rows[dgvListOperLetras.SelectedIndex].Cells[2].Text;
                txtFecha.Text  = dgvListOperLetras.Rows[dgvListOperLetras.SelectedIndex].Cells[4].Text;
                txtFecha.Enabled = false;
                lblProveedor.Text = dgvListOperLetras.Rows[dgvListOperLetras.SelectedIndex].Cells[6].Text;

                txtNumCuotas.Text = dgvListOperLetras.Rows[dgvListOperLetras.SelectedIndex].Cells[7].Text;
                clsCabletra lstOperaciones = new clsCabletra();
                cab_letra obj = new cab_letra();
                obj = lstOperaciones.GetCabLetra(nOpeCod);
                int icodLetra = int.Parse(obj.icodigo.ToString());
                /////////////////////carga facturas enlazadas
                clsfac_x_letra form = new clsfac_x_letra();
                DataTable dtFact;
                dtFact = form.GetList(icodLetra);
                dgvListFact.DataSource = dtFact;
                dgvListFact.DataBind();
                grdchk_CheckedChanged(sender, e);
                dgvListFact.Enabled = false;

                dgvNotas.Columns[7].Visible = false;
                dgvNotas.Columns[6].Visible = false;
                /////////////////////carga Notas enlazadas
                clsviewrel_not_fac formNot = new clsviewrel_not_fac();
                DataTable dtNot;
                dtNot = formNot.GetListNotas(icodLetra);
                if (dtNot.Rows.Count == 0)
                    pnnotasempty.Visible = true;
                else {
                    pnaddNotas.Visible = true;
                    pnnotasempty.Visible = false;
                    dgvNotas.DataSource = dtNot;
                    dgvNotas.DataBind();
                    grdchknota_CheckedChanged(sender, e);
                    dgvNotas.Enabled = false;

                }
                /////////////////////carga detalle de letras
                clsdetletra formDet = new clsdetletra();
                DataTable dtDetalle;

                dtDetalle = formDet.GetList(icodLetra);
                int valor = dtDetalle.Rows.Count;
                dgvcuotas.DataSource = dtDetalle;
                dgvcuotas.DataBind();
                int cont = 0;
                foreach (GridViewRow row in dgvcuotas.Rows)
                {
                    row.Cells[0].Text = dtDetalle.Rows[cont][1].ToString();
                    TextBox txtFecVen = row.FindControl("txtFecVen") as TextBox;
                    txtFecVen.Enabled = false;
                    txtFecVen.Text = Convert.ToDateTime(dtDetalle.Rows[cont][6]).ToString("yyyy-MM-dd");
                    TextBox num_let = row.FindControl("num_let") as TextBox;
                    num_let.Text = dtDetalle.Rows[cont][10].ToString();
                    num_let.Enabled = false;
                    TextBox cod_unic = row.FindControl("cod_unic") as TextBox;
                    cod_unic.Text = dtDetalle.Rows[cont][2].ToString();
                    cod_unic.Enabled = false;
                    TextBox monto = row.FindControl("monto") as TextBox;
                    monto.Text = dtDetalle.Rows[cont][3].ToString();
                    monto.Enabled = false;
                    cont++;
                }
                ////////////////////////////////////////////////////
                this.pnListOperaciones.Visible = false;
                this.pnDocLetra.Visible = true;
                pnCuotas.Visible = true;
                pnListOperLetras.Visible = true;
                pnCuotas.Visible = true;
                Pnokaddfactura.Visible = true;

                pnaddfactura.Visible = true;
                pnNotas.Visible = true;
                btnCancelar.Visible = true;
                HabilitarBtn(btnNuevo, false);
                HabilitarBtn(btnCancelar, true);
                HabilitarBtn(btnAnular, false);
                HabilitarBtn(btnEditar, false);
                HabilitarBtn(btnImprimir, true);
                ///////////////////////////////////////////////////

                lblPaso.Value = "Detalle";
            }
            catch (Exception ex)
            {
                MessageBox("Error Interno: " + ex.Message);
            }
        }