private void EventoGuardarPrecio()
        {
            int linOperacion = (int)LeerVariableSesion("operacionPrecio");

            if (linOperacion == 1)        //NUEVO
            {
                int linProCodigo = (int)LeerVariableSesion("proCodigo");

                clsListaPrecios oListaPrecioLst = new clsListaPrecios();
                clsLotesArt oLotesArtLst = new clsLotesArt();

                ListaPrecios oListaPrecio = new ListaPrecios();
                LotesArt oLotesArt = new LotesArt();

                int linLprCod = oListaPrecioLst.MaxListaPrecioCod() + 1;
                int linLotCod = oLotesArtLst.MaxLotesCod() + 1;
                int linNroLot = oLotesArtLst.MaxLotNro(linProCodigo) + 1;

                oListaPrecio.LprPrecio = Convert.ToDecimal( txtPrecio.Text);
                oListaPrecio.LprDscto = Convert.ToDecimal( txtDescuento.Text);
                oListaPrecio.LprCod = linLprCod;
                oListaPrecio.LprFecRegis = DateTime.Today;
                oListaPrecio.LprEstado = true;
                oListaPrecio.ArtCod = linProCodigo;

                oLotesArt.LotStock = Convert.ToDecimal(txtStockLote.Text);
                oLotesArt.LotFecVenci = DateTime.Parse( txtFecVenceLote.Text);
                oLotesArt.LprCod = linLprCod;
                oLotesArt.LotCod = linLotCod;
                oLotesArt.LotNro = Convert.ToInt32(txtLote.Text);
                oLotesArt.LotFecModi = DateTime.Today;
                oLotesArt.LotFecRegis = DateTime.Today;
                oLotesArt.LotEstado = true;

                try
                {
                    oListaPrecioLst.Add(oListaPrecio);
                    oListaPrecioLst.SaveChanges();

                    oLotesArtLst.Add(oLotesArt);
                    oLotesArtLst.SaveChanges();

                    RestaurarDatosProducto_sesion();

                    lblMensajes.Visible = true;
                    lblMensajes.Text = "El registro se Grabo Satisfactoriamente.";
                    this.MessageBox("El registro se Grabo Satisfactoriamente.");
                    pnlBusqueda.Visible = false;
                    //pnlTipoProductos.Visible = false;
                    pnlProductos.Visible = false;
                    pnlEditProductos.Visible = true;
                    pnlListaPrecios.Visible = true;
                    pnlDetallePrecio.Visible = false;
                }
                catch (Exception ex)
                {
                    lblMensajes.Text = "Error:" + ex.Message;
                    this.MessageBox("Error:" + ex.Message);
                }

            }
            else             // MODIFICAR
            {
                int linPrecioCodigo = (int)LeerVariableSesion("precioCodigo");

                ListaPrecios oListaPrecio = new ListaPrecios();
                clsListaPrecios oListaPrecioLst  =  new clsListaPrecios ();
                oListaPrecio =  oListaPrecioLst.GetPrecio(linPrecioCodigo);

                LotesArt oLotesArt = new LotesArt();
                clsLotesArt oLotesArtLst = new clsLotesArt();
                oLotesArt = oLotesArtLst.GetLotesPrecio(oListaPrecio.LprCod);

                oListaPrecio.LprPrecio = Convert.ToDecimal( txtPrecio.Text);
                oListaPrecio.LprDscto = Convert.ToDecimal( txtDescuento.Text);

                oLotesArt.LotStock = Convert.ToDecimal(txtStockLote.Text);
                oLotesArt.LotFecVenci = DateTime.Parse( txtFecVenceLote.Text);

                try
                {
                    oListaPrecioLst.Update(oListaPrecio);
                    oListaPrecioLst.SaveChanges();

                    oLotesArtLst.Update(oLotesArt);
                    oLotesArtLst.SaveChanges();

                    lblMensajes.Visible = true;
                    lblMensajes.Text = "El registro se Grabo Satisfactoriamente.";
                    this.MessageBox("El registro se Grabo Satisfactoriamente.");
                    pnlBusqueda.Visible = false;
                    //pnlTipoProductos.Visible = false;
                    pnlProductos.Visible = false;
                    pnlEditProductos.Visible = true;
                    pnlListaPrecios.Visible = true;
                    pnlDetallePrecio.Visible = false;

                    RestaurarDatosProducto_sesion();
                }
                catch (Exception ex)
                {
                    lblMensajes.Text = "Error:" + ex.Message;
                    this.MessageBox("Error:" + ex.Message);
                }

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

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

                AgregarVariableSession("precioCodigo", linPrecioCodigo);
                AgregarVariableSession("operacionPrecio", 2);

                clsListaPrecios oListaPrecioList = new clsListaPrecios();
                ListaPrecios oListaPrecio = new ListaPrecios();
                oListaPrecio =  oListaPrecioList.GetPrecio(linPrecioCodigo);

                clsLotesArt oLotesArtList = new clsLotesArt();
                LotesArt oLotesArt = new LotesArt();
                oLotesArt = oLotesArtList.GetLotesPrecio(linPrecioCodigo);

                if (oListaPrecio != null)
                {

                    txtCodigoPrecio.Text = oListaPrecio.LprCod.ToString();
                    txtPrecio.Text = oListaPrecio.LprPrecio.ToString();
                    txtDescuento.Text = oListaPrecio.LprDscto.ToString();
                    txtLote.Text = oLotesArt.LotNro.ToString();
                    //grabamos el stock del lote
                    decimal ldeStockLote = 0;
                    if (oLotesArt.LotStock.HasValue )
                       ldeStockLote = oLotesArt.LotStock.Value;

                    txtStockLote.Text = ldeStockLote.ToString();
                    this.AgregarVariableSession("stockLote", ldeStockLote);

                    txtFecVenceLote.Text = oLotesArt.LotFecVenci.ToString();
                    chkEstadoPrecio.Checked = oListaPrecio.LprEstado;
                    lblCodigoLote.Text = oLotesArt.LotCod.ToString();

                    pnlBusqueda.Visible = false;
                    pnlProductos.Visible = false;
                    pnlEditProductos.Visible = false ;
                    pnlListaPrecios.Visible = false;
                    pnlDetallePrecio.Visible = true;
                    lblMensajes.Visible = false;

                    GuardarDatosProducto_Sesion();
                }
            }
            //presiona BOTON ELIMINAR EN GRILLA
            if (e.CommandName == "EliminaPrecio")
            {
                int linPrecioCodigo;
                linPrecioCodigo = Convert.ToInt32(e.CommandArgument);

                clsListaPrecios oListaPrecioList = new clsListaPrecios();
                ListaPrecios oListaPrecio = new ListaPrecios();
                oListaPrecio = oListaPrecioList.GetPrecio(linPrecioCodigo);
                oListaPrecio.LprEstado = false;

                clsLotesArt oLotesArtList = new clsLotesArt();
                LotesArt oLotesArt = new LotesArt();
                oLotesArt = oLotesArtList.GetLotesPrecio(linPrecioCodigo);
                oLotesArt.LotEstado = false;

                oListaPrecioList.Update(oListaPrecio);
                oListaPrecioList.SaveChanges();

                oLotesArtList.Update(oLotesArt);
                oLotesArtList.SaveChanges();

                lblMensajes.Visible = true;
                lblMensajes.Text = "El registro se Elimino Satisfactoriamente.";
                this.MessageBox("El registro se Elimino Satisfactoriamente.");

            }
        }
        protected void gvwListaPrecios_RowCommand(object sender, GridViewCommandEventArgs e)
        {
            int linProCodigo = (int)LeerVariableSesion("proCodigo");
            //presiona BOTON MODIFICAR EN GRILLA
            if (e.CommandName == "SeleccionaPrecio")
            {

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

                AgregarVariableSession("loteCodigo", LoteCodigo);
                AgregarVariableSession("operacionPrecio", 2);

                clsLotesArt oLotesArtList = new clsLotesArt();
                LotesArt oLotesArt = new LotesArt();
                oLotesArt = oLotesArtList.GetLoteArt(linProCodigo,LoteCodigo);

                if (oLotesArt != null)
                {

                    txtCodigoPrecio.Text = oLotesArt.LotCod.ToString();
                    txtPrecio.Text = oLotesArt.LotPrecioVen.ToString();
                    txtDescuento.Text = "0.0";
                    txtLote.Text = oLotesArt.LotNro.ToString();
                    //grabamos el stock del lote
                    decimal ldeStockLote = 0;
                    if (oLotesArt.LotStock.HasValue )
                       ldeStockLote = oLotesArt.LotStock.Value;

                    txtStockLote.Text = ldeStockLote.ToString();
                    this.AgregarVariableSession("stockLote", ldeStockLote);

                    DateTime FechaVenci ;

                    FechaVenci = oLotesArt.LotFecVenci.Value;

                    txtFecVenceLote.Text = FechaVenci.ToString("yyyy-MM-dd");
                    if (oLotesArt.LotEstado == "A")
                        chkEstadoPrecio.Checked = true;
                    else
                        chkEstadoPrecio.Checked = false;

                    lblCodigoLote.Text = oLotesArt.LotCod.ToString();

                    pnlBusqueda.Visible = false;
                    pnlProductos.Visible = false;
                    pnlEditProductos.Visible = false ;
                    pnlListaPrecios.Visible = false;
                    pnlDetallePrecio.Visible = true;
                    lblMensajes.Visible = false;

                    GuardarDatosProducto_Sesion();
                }
            }
            //presiona BOTON ELIMINAR EN GRILLA
            if (e.CommandName == "EliminaPrecio")
            {
                int LoteCodigo;
                LoteCodigo = Convert.ToInt32(e.CommandArgument);

                clsLotesArt oLotesArtList = new clsLotesArt();
                LotesArt oLotesArt = new LotesArt();
                oLotesArt = oLotesArtList.GetLoteArt(linProCodigo, LoteCodigo);
                oLotesArt.LotEstado = "I";
                oLotesArt.LotStock = 0;
                oLotesArt.LotPrecioCom = 0;
                oLotesArt.LotPrecioVen = 0;

                try
                {
                    oLotesArtList.Update(oLotesArt);
                    oLotesArtList.SaveChanges();

                    RestaurarDatosProducto_sesion();

                    txtStock.Text = CalcularStock(linProCodigo).ToString();
                    EventoGuardar(false );

                    lblMensajes.Visible = true;
                    lblMensajes.Text = "El registro se Elimino Satisfactoriamente.";
                    this.MessageBox("El registro se Elimino Satisfactoriamente.");
                }
                catch (Exception ex)
                {
                    lblMensajes.Visible = true;
                    lblMensajes.Text = ex.Message;
                    this.MessageBox(ex.Message);
                }
            }
        }