protected void gvwPersonal_RowCommand(object sender, GridViewCommandEventArgs e)
        {
            //presiona BOTON MODIFICAR EN GRILLA
            if (e.CommandName == "SeleccionaPersonal")
            {

                int linPerCodigo;
                linPerCodigo = Convert.ToInt32(e.CommandArgument);

                AgregarVariableSession("perCod", linPerCodigo);

                Personal oPersonal = new Personal();
                clsPersonal lstPersonal = new clsPersonal();

                oPersonal = lstPersonal.GetPersonal(linPerCodigo);
                if (oPersonal != null)
                {
                    txtCodigo.Text = linPerCodigo.ToString();
                    txtNombres.Text = oPersonal.perNombres;
                    txtApellidoPat.Text = oPersonal.perApellidoPat;
                    txtApellidoMat.Text = oPersonal.perApellidoMat;
                    txtDireccion.Text = oPersonal.perDireccion;
                    txtTelefono.Text = oPersonal.perTelefono;

                    ListItem liElegido;
                    //si DropDownList está visible
                    if (ddlTipoPersonal.Items.Count > 0)
                    {
                        liElegido = ddlTipoPersonal.Items.FindByValue(oPersonal.tpecod.ToString());
                        ddlTipoPersonal.SelectedIndex = ddlTipoPersonal.Items.IndexOf(liElegido);
                    }

                    //MODIFICAR , se guarda en variable cache
                    AgregarVariableSession("operacion", 2);
                    pnlEditPersonal.Visible = true;
                    pnlPersonal.Visible = false;
                    lblMensajes.Visible = false;
                }

            }
            //presiona BOTON ELIMINAR EN GRILLA
            if (e.CommandName == "EliminaPersonal")
            {
                int linPerCodigo;

                linPerCodigo = Convert.ToInt32(e.CommandArgument);
                EventoEliminar(linPerCodigo);

            }
        }
 protected void ddlListaVendedores_SelectedIndexChanged(object sender, EventArgs e)
 {
     int nVenCod = 0;
     nVenCod  = int.Parse(ddlListaVendedores.SelectedValue);
     if (nVenCod > 0)
     {
         HabilitarBtn(btnNuevo, true);
         clsPersonal form = new clsPersonal();
         Personal obj = new Personal();
         obj = form.GetPersonal(Convert.ToInt32(ddlListaVendedores.SelectedValue));
         lblnomVen.Text = obj.perNombres + " " + obj.perApellidoPat + " " + obj.perApellidoMat;
         lblOpeCodigo.Value = ddlListaVendedores.SelectedValue;
     }
     else
     {
         HabilitarBtn(btnNuevo, false);
     }
 }
        protected void gvwPersonal_RowCommand1(object sender, GridViewCommandEventArgs e)
        {
            //presiona BOTON MODIFICAR EN GRILLA
            if (e.CommandName == "SeleccionaPersonal")
            {

                int linPerCodigo;
                linPerCodigo = Convert.ToInt32(e.CommandArgument);

                AgregarVariableSession("perCod", linPerCodigo);

                Personal oPersonal = new Personal();
                clsPersonal lstPersonal = new clsPersonal();

                oPersonal = lstPersonal.GetPersonal(linPerCodigo);
                if (oPersonal != null)
                {
                    txtCodigoPersonal.Text = linPerCodigo.ToString();
                    txtNombre.Text = oPersonal.perNombres;
                    txtApePaterno.Text = oPersonal.perApellidoPat;
                    txtApeMaterno.Text = oPersonal.perApellidoMat;

                    pnlEditUsuarios.Visible = true;
                    pnlPersonal.Visible = false;
                    pnlUsuarios.Visible = false;
                    lblMensajes.Visible = false;
                }

            }
        }
        private void EventoGuardar()
        {
            int linOperacion = (int)LeerVariableSesion("operacion");

            Personal oPersonal = new Personal();
            clsPersonal lstPersonal = new clsPersonal();

            if (linOperacion == 1)        //NUEVO
            {
                oPersonal.perCod = lstPersonal.MaxpnPerCod() + 1;
                oPersonal.perNombres = txtNombres.Text.ToUpper();
                oPersonal.perApellidoPat = txtApellidoPat.Text.ToUpper();
                oPersonal.perApellidoMat = txtApellidoMat.Text.ToUpper();
                oPersonal.perDireccion = txtDireccion.Text;
                oPersonal.perTelefono = txtTelefono.Text;
                oPersonal.tpecod = Convert.ToInt32( ddlTipoPersonal.SelectedItem.Value);

                lstPersonal.Add(oPersonal);
            }
            else                        // MODIFICAR
            {
                int linPerCodigo = (int)LeerVariableSesion("perCod");
                oPersonal = lstPersonal.GetPersonal(linPerCodigo);
                oPersonal.perNombres = txtNombres.Text.ToUpper();
                oPersonal.perApellidoPat = txtApellidoPat.Text.ToUpper();
                oPersonal.perApellidoMat = txtApellidoMat.Text.ToUpper();
                oPersonal.perDireccion = txtDireccion.Text;
                oPersonal.perTelefono = txtTelefono.Text;
                oPersonal.tpecod = Convert.ToInt32(ddlTipoPersonal.SelectedItem.Value);

                lstPersonal.Update(oPersonal);
            }

            try
            {
                lstPersonal.SaveChanges();
                lblMensajes.Visible = true;
                lblMensajes.Text = "El registro se Grabo Satisfactoriamente.";
                pnlEditPersonal.Visible = false;
                pnlPersonal.Visible = true;
                this.MessageBox("El registro se Grabo Satisfactoriamente.");
                EventoActualizaGrilla();
            }
            catch (Exception ex)
            {

                lblMensajes.Visible = true;
                lblMensajes.Text = ex.Message;
                this.MessageBox(ex.Message);
            }
        }
        protected void ddlClientes_SelectedIndexChanged(object sender, EventArgs e)
        {
            int nCliCod = 0;
            nCliCod = int.Parse(ddlClientes.SelectedValue);

            if (nCliCod == 999)
            {
                txtCliente.Text = "";
                ModalPopupNuevoCli.Show();
                IniciarCamposCliente();
                btnNuevoCliente_Click(sender, e);
            }
            else if (nCliCod == 0)
            {
                txtDocCli.Text = "";
                txtDireccion.Text = "";
                txtTelefono.Text = "";
            }
            else
            {
                if (lblTipoDoc.Value == "7")
                {
                    clsPersonal lstPersonal = new clsPersonal();
                    Personal oVendedor = lstPersonal.GetPersonal(nCliCod);

                    txtCliente.Text = oVendedor.perNombres + " " + oVendedor.perApellidoPat + " " + oVendedor.perApellidoMat;
                    txtDocCli.Text = "";
                    txtDireccion.Text = oVendedor.perDireccion == null? "" : oVendedor.perDireccion.ToString();
                    txtTelefono.Text = oVendedor.perTelefono == null ? "" : oVendedor.perTelefono.ToString();

                    lstPersonal = null;
                    oVendedor = null;
                }
                else
                {
                    clsClientes lstClientes = new clsClientes();
                    Clientes Cliente = new Clientes();

                    Cliente = lstClientes.GetCliente(nCliCod);

                    txtCliente.Text = Cliente.CliNombre.ToString();
                    txtDocCli.Text = Cliente.CliNumDoc.ToString();
                    txtDireccion.Text = Cliente.CliDireccion.ToString();
                    txtTelefono.Text = Cliente.CliTelefono.ToString();

                    lstClientes = null;
                    Cliente = null;
                    ////////////////////silvia/////////////////
                    clsListNotas lstNota = new clsListNotas();
                    nota_list nota_lista = new nota_list();
                    DataTable dtOpeNotas;
                    dtOpeNotas= lstNota.GetLista("1212111","0", "N",
                        "PEN",nCliCod  , Convert.ToDateTime("1990-01-01"),
                        Convert.ToDateTime("1990-01-01") ,"V",0);
                    dgvNotas.DataSource = dtOpeNotas;
                    dgvNotas.DataBind();
                    pnNotas.Visible = true;

                    ///////////////////////////////////////////
                }
            }
        }