private void EventoModificarProducto()
        {
            EventoLlenarLista();
            EventoLlenarListaProveedores();

            int linProCodigo;
            linProCodigo = (int)LeerVariableSesion("proCodigo");

            DataRow drArticulo;
            CArticulo objArticulo = new CArticulo();
            drArticulo = objArticulo.fnDatosArticulo(linProCodigo);

            Articulos oArticulo = new Articulos();
            clsArticulos lstArticulos = new clsArticulos();

            oArticulo = lstArticulos.GetArticulo(linProCodigo);
            this.AgregarVariableSession("oArticulo", oArticulo);

            if (drArticulo != null)
            {
                txtCodigo.Text = drArticulo["artCod"].ToString();
                txtDescripcion.Text = drArticulo["artDescripcion"].ToString();

                //grabamos el stock del producto
                decimal ldeStockProducto = 0;
                if (drArticulo["artStock"] != null)
                    ldeStockProducto = Convert.ToDecimal( drArticulo["artStock"]);

                txtStock.Text = ldeStockProducto.ToString();
                this.AgregarVariableSession("stockProducto", ldeStockProducto);

                //txtStockMax.Text = drArticulo["artStockMax"].ToString();
                //txtStockMin.Text = drArticulo["artStockMin"].ToString();
                txtFecVencimiento.Text = drArticulo["artFecVen"].ToString();
                txtCostoPromedio.Text = drArticulo["artCostoProm"].ToString();
                txtPeso.Text = drArticulo["artPeso"].ToString();
                chkestado.Checked = Convert.ToBoolean( drArticulo["artEstado"]);

                ListItem liElegido;
                //si DropDownList está visible
                if (ddlUnidadMedida.Items.Count > 0)
                {
                    liElegido = ddlUnidadMedida.Items.FindByValue(drArticulo["UniCod"].ToString());
                    ddlUnidadMedida.SelectedIndex = ddlUnidadMedida.Items.IndexOf(liElegido);
                }

                ListItem liElegidoProveedor;
                //si DropDownList está visible
                if (ddlProveedor.Items.Count > 0)
                {
                    liElegidoProveedor = ddlProveedor.Items.FindByValue(drArticulo["PrvCod"].ToString());
                    ddlProveedor.SelectedIndex = ddlProveedor.Items.IndexOf(liElegidoProveedor);
                }

                //CONSULTAR PRECIOS Y LOTES DEL PRODUCTO
                MostrarPreciosLotes(linProCodigo);

                //MODIFICAR , se guarda en variable cache
                AgregarVariableSession("operacion", 2);
                pnlBusqueda.Visible = false;
                pnlProductos.Visible = false;
                pnlEditProductos.Visible = true;
                pnlListaPrecios.Visible = true;
                pnlDetallePrecio.Visible = false;
                lblMensajes.Visible = false;

                btnNuevoPrecio.Visible = true;
            }
        }
        protected void lsbArticulos_SelectedIndexChanged(object sender, EventArgs e)
        {
            nTasIGV = double.Parse(lblTasIGV.Value);
            int ArtCod = 0;
            int PrvCod = 0;
            int LotNro = 0;
            double LprPrecio = 0.0;
            double LprDscto = 0.0;
            double nPrecio = 0.0;
            ArtCod = int.Parse(lsbArticulos.SelectedValue);
            PrvCod = int.Parse(ddlLaboratorios.SelectedValue);

            txtLotVenci.Text = "";
            txtLotNro.Text = "";
            txtLotStock.Text = "0";

            clsArticulos lstArticulos = new clsArticulos();
            clsListaPrecios lstPrecios = new clsListaPrecios();
            clsLotesArt lstLotesArt = new clsLotesArt();
            Articulos oArticulo = new Articulos();
            ListaPrecios oPrecio = new ListaPrecios();
            LotesArt oLoteArt = new LotesArt();

            txtLotNro.Enabled = false;
            txtLotVenci.Enabled = false;
            txtLotStock.Enabled = false;
            txtArtDescuento.Enabled = true;

            oPrecio = lstPrecios.GetArticuloPrecio(ArtCod);
            oLoteArt = lstLotesArt.GetLoteArt(ArtCod);

            //oLoteArt.ListaPrecios.Articulos

            oArticulo = lstArticulos.GetArticulo(ArtCod);
            if (oArticulo != null)
            {
                txtArtCod.Text = oArticulo.ArtCod.ToString();
                txtArtUniMed.Text = oArticulo.Unidades.UniDescripcion;
                txtStockFact.Text = oArticulo.ArtStockFac.ToString();
                txtStockFis.Text = oArticulo.ArtStock.ToString();
                hideStockLote.Value = lstLotesArt.GetLoteArtStock(ArtCod).ToString();

                if (oLoteArt != null)
                {
                    txtLotNro.Text = oLoteArt.LotNro.ToString();
                    txtLotStock.Text = oLoteArt.LotStock.ToString();
                    if (oLoteArt.LotFecVenci != null)
                        txtLotVenci.Text = ((DateTime)oLoteArt.LotFecVenci).ToString("yyyy-MM-dd");
                }

                if (oArticulo.ArtStock <= 0)
                    txtStockFis.ForeColor = System.Drawing.Color.Red;
                else
                    txtStockFis.ForeColor = System.Drawing.Color.Gray;

                txtArtPreUnitario.Text = lstPrecios.GetCostoPromedio(ArtCod, nTasIGV).ToString();

                //if (oPrecio == null)
                //    txtArtPreUnitario.Text = "0.0";
                //else
                //{
                //    nPrecio = (double)oPrecio.LprPrecio;
                //    var nDcto = Math.Round((nPrecio * (double)oPrecio.LprDscto / 100), 2);
                //    nPrecio -= nDcto;
                //    var nFlete = Math.Round(nPrecio / 100, 2);
                //    nPrecio += nFlete;
                //    var nIgv = Math.Round(nPrecio * nTasIGV, 2);
                //    nPrecio += nIgv;
                //    if (oArticulo.Proveedores.PrvGanancia != 0)
                //        nPrecio = Math.Round((nPrecio * (double)oArticulo.Proveedores.PrvGanancia), 2);
                //    txtArtPreUnitario.Text = nPrecio.ToString();
                //}

                if (BuscarArticulo(oArticulo.ArtCod, ref LotNro, ref LprPrecio, ref LprDscto))
                {
                    txtArtDescuento.Enabled = false;
                    txtArtDescuento.Text = LprDscto.ToString();
                }
                else
                {
                    txtArtDescuento.Enabled = true;
                    txtArtDescuento.Text = "0";
                }
                txtArtCant.Text = "1";
            }
            else
                txtArtCant.Text = "0";

            txtImpTotal.Text = "0.0";

            lstArticulos = null;
            oArticulo = null;
            lstPrecios = null;
            oPrecio = null;

            CalcularTotalArticulo();
            lsbArticulos.Focus();
        }
        protected void lsbArticulos_SelectedIndexChanged(object sender, EventArgs e)
        {
            int ArtCod = 0;
            int LotNro = 0;
            double LprPrecio = 0.0;
            double LprDscto = 0.0;

            if (lsbArticulos.SelectedValue != "")
                ArtCod = int.Parse(lsbArticulos.SelectedValue);

            clsArticulos lstArticulos = new clsArticulos();
            clsListaPrecios lstPrecios = new clsListaPrecios();
            clsLotesArt lstLotesArt = new clsLotesArt();
            Articulos oArticulo = new Articulos();
            ListaPrecios oPrecio = new ListaPrecios();

            oPrecio = lstPrecios.GetArticuloPrecio(ArtCod);
            oArticulo = lstArticulos.GetArticulo(ArtCod);

            if (oArticulo != null) {
                txtArtCod.Text = oArticulo.ArtCod.ToString();
                txtArtUniMed.Text = oArticulo.Unidades.UniDescripcion;
                txtStockFact.Text = oArticulo.ArtStockFac.ToString();
                txtStockFis.Text = oArticulo.ArtStock.ToString();
                txtArtDescuento.Text = (oArticulo.Proveedores.PrvDscto).ToString();
                ddlTipDcto.SelectedValue = "%";
                txtLotVenci.Text = DateTime.Now.AddDays(30).ToString("yyyy-MM-dd");
                ddlLaboratorios.SelectedValue = oArticulo.PrvCod.ToString();
                hideStockLote.Value = lstLotesArt.GetLoteArtStock(ArtCod).ToString();

                if (oArticulo.ArtStock <= 0)
                {
                    txtStockFis.ForeColor = System.Drawing.Color.Red;
                }
                else
                {
                    txtStockFis.ForeColor = System.Drawing.Color.Gray;
                }

                if (oPrecio == null)
                {
                    txtArtPreUnitario.Text = "0.0";
                }
                else
                {
                    txtArtPreUnitario.Text = oPrecio.LprPrecio.ToString();
                }

                if (BuscarArticulo(oArticulo.ArtCod, ref LotNro, ref LprPrecio, ref LprDscto))
                {
                    if (lblEstadoVenArticulo.Value == "NORMAL")
                        txtArtPreUnitario.Enabled = false;
                    else
                        txtArtPreUnitario.Enabled = true;
                    txtLotNro.Enabled = false;
                    txtLotNro.Text = LotNro.ToString();
                    txtArtPreUnitario.Text = LprPrecio.ToString();
                }
                else
                {
                    txtArtPreUnitario.Enabled = true;
                    txtLotNro.Enabled = true;
                    LotNro = lstLotesArt.MaxLotNro(ArtCod);
                    txtLotNro.Text = (LotNro + 1).ToString();
                }
                if (lblEstadoVenArticulo.Value == "NORMAL")
                    txtArtCant.Text = "1";
            }
            else
                LimpiarCamposArticulos();

            txtImpTotal.Text = "0.0";

            lstArticulos = null;
            oArticulo = null;
            lstPrecios = null;
            oPrecio = null;
            lstLotesArt = null;

            CalcularTotalArticulo();
            lsbArticulos.Focus();
        }
        protected void btnAgregarArticulo_Click(object sender, EventArgs e)
        {
            DataTable dtDetalleCompra;
            DataRow NewRow;
            bool bExiste = false;
            double nPrecio = 0.0;
            double nCantidad = 0.0;
            double nDescuento = 0.0;
            double nTotal = 0.0;
            string cMensaje = "";

            clsListaPrecios lstPrecios = new clsListaPrecios();
            clsArticulos colArticulos = new clsArticulos();
            ListaPrecios oPrecio = new ListaPrecios();

            try
            {
                if (ValidarDatos("ART",ref cMensaje))
                {
                    //AGREGAMOS ARTICULO A LISTA DE ARTICULOS
                    dtDetalleCompra = g_dtDetOperacion;

                    if (dtDetalleCompra.Rows.Count > 0)
                    {
                        for (int i = 0; i < dtDetalleCompra.Rows.Count; i++)
                        {
                            if (dtDetalleCompra.Rows[i]["ArtCod"].ToString() == txtArtCod.Text)
                            {
                                nPrecio = Double.Parse(dtDetalleCompra.Rows[i]["dtpPrecioVen"].ToString());
                                nCantidad = Double.Parse(dtDetalleCompra.Rows[i]["dtpCantidad"].ToString()) + double.Parse(txtArtCant.Text);
                                nTotal = Double.Parse(dtDetalleCompra.Rows[i]["dtpSubTotal"].ToString());
                                nTotal += Double.Parse(txtImpTotal.Text);
                                nDescuento = 100 - ((100 * nTotal) / (nPrecio * nCantidad));

                                dtDetalleCompra.Rows[i]["dtpCantidad"] = nCantidad.ToString();
                                dtDetalleCompra.Rows[i]["dtpDscto"] = nDescuento;
                                dtDetalleCompra.Rows[i]["dtpSubTotal"] = nTotal.ToString();
                                i = dtDetalleCompra.Rows.Count + 10;
                                bExiste = true;
                            }
                        }
                    }

                    if (!bExiste)
                    {
                        NewRow = dtDetalleCompra.NewRow();
                        NewRow["ArtCod"] = txtArtCod.Text;
                        NewRow["ArtPeso"] = colArticulos.GetArticulo(int.Parse(txtArtCod.Text)).ArtPeso;
                        NewRow["LotNro"] = txtLotNro.Text;
                        NewRow["ArtDescripcion"] = lsbArticulos.SelectedItem.Text;
                        NewRow["UniAbrev"] = txtArtUniMed.Text;
                        NewRow["dtpCantidad"] = txtArtCant.Text;
                        NewRow["dtpPrecioVen"] = txtArtPreUnitario.Text;
                        if (ddlTipDcto.SelectedValue == "%")
                            NewRow["dtpDscto"] = txtArtDescuento.Text;
                        else
                            NewRow["dtpDscto"] = (double.Parse(txtArtDescuento.Text) * 100) / (double.Parse(txtArtPreUnitario.Text) * double.Parse(txtArtCant.Text));
                        NewRow["dtpSubTotal"] = txtImpTotal.Text;
                        dtDetalleCompra.Rows.Add(NewRow);
                    }

                    CalcularPago(dtDetalleCompra);
                    g_dtDetOperacion = dtDetalleCompra;
                    RellenarGrilla(ref dgvDetalleVenta, dtDetalleCompra, this.nNroDetPed);
                }
                else
                {
                    ModalPopupAgregar.Show();
                    MessageBox(cMensaje);
                }

            }
            catch (Exception ex)
            {
                MessageBox(ex.Message);
            }
            lstPrecios = null;
            oPrecio = null;
        }
        protected void lsbArticulos_SelectedIndexChanged(object sender, EventArgs e)
        {
            nTasIGV = double.Parse(lblTasIGV.Value);
            int ArtCod = 0;
            int PrvCod = 0;
            int LotNro = 0;
            double LprPrecio = 0.0;
            double LprDscto = 0.0;
            double nTipCam = g_nTipoCambio;

            //VARIABLES PARA TOMAR PRECIO SIN CALCULAR FLETE  E  IGV
            DateTime dLotFecRegis = DateTime.Today;
            int nLotNro;
            double nLprPrecio = 0.0;

            ArtCod = int.Parse(lsbArticulos.SelectedValue);
            PrvCod = int.Parse(ddlLaboratorios.SelectedValue);

            txtLotVenci.Text = "";
            txtLotNro.Text = "";
            txtLotStock.Text = "0";

            clsArticulos lstArticulos = new clsArticulos();
            clsLotesArt lstLotesArt = new clsLotesArt();
            Articulos oArticulo = new Articulos();
            LotesArt oLoteArt = new LotesArt();

            txtLotNro.Enabled = false;
            txtLotVenci.Enabled = false;
            txtLotStock.Enabled = false;
            txtArtDescuento.Enabled = true;

            oLoteArt = lstLotesArt.GetLoteArt(ArtCod);

            if (oLoteArt != null)
            {
                nLotNro = oLoteArt.LotNro;
                if (oLoteArt.LotFecModi.HasValue)
                    dLotFecRegis = oLoteArt.LotFecRegis.Value;

                if (oLoteArt.LotPrecioVen.HasValue)
                    nLprPrecio = (double)oLoteArt.LotPrecioVen;
            }
            else
                nLotNro = 0;

            oArticulo = lstArticulos.GetArticulo(ArtCod);
            nLprPrecio = (double)oArticulo.ArtCostoProm;

            if (oArticulo != null)
            {
                txtArtCod.Text = oArticulo.ArtCod.ToString();
                txtArtUniMed.Text = oArticulo.Unidades.UniDescripcion;
                txtStockFact.Text = oArticulo.ArtStockFac.ToString();
                txtStockFis.Text = oArticulo.ArtStock.ToString();
                hideStockLote.Value = lstLotesArt.GetLoteArtStock(ArtCod).ToString();

                if (oLoteArt != null)
                {
                    txtLotNro.Text = oLoteArt.LotNro.ToString();
                    txtLotStock.Text = oLoteArt.LotStock.ToString();
                    if (oLoteArt.LotFecVenci != null)
                        txtLotVenci.Text = ((DateTime)oLoteArt.LotFecVenci).ToString("yyyy-MM-dd");
                    else
                        txtLotVenci.Text = DateTime.Today.ToString("yyyy-MM-dd");

                }

                if (oArticulo.ArtStock <= 0)
                    txtStockFis.ForeColor = System.Drawing.Color.Red;
                else
                    txtStockFis.ForeColor = System.Drawing.Color.Gray;

                //if (nLotNro == 1 && DateTime.Compare(dLotFecRegis, DateTime.Parse("2013-04-09")) == 0)
                //    txtArtPreUnitario.Text = Math.Round(((nLprPrecio * (double)oArticulo.Proveedores.PrvGanancia) / nTipCam), 2).ToString();
                //else
                //    txtArtPreUnitario.Text = Math.Round((lstPrecios.GetCostoPromedio(ArtCod, nTasIGV) / nTipCam), 2).ToString();

                /////Cambio hecho 06-06-2013 se desea q se muestre elprecio venta q se ve en  el modulo almacen -articulos///
                //////////silvia////////////////////////////////////////////////////////////////////////////////////////////
                txtArtPreUnitario.Text = Math.Round(((nLprPrecio) / nTipCam), 2).ToString("0.00");
                ////////////////////////////////////////////////////////////////////////////////////////////////////////////

                //txtArtPreUnitario.Text = Math.Round((lstPrecios.GetCostoPromedio(ArtCod, nTasIGV) / nTipCam), 2).ToString();

                if (BuscarArticulo(oArticulo.ArtCod, ref LotNro, ref LprPrecio, ref LprDscto))
                {
                    txtArtDescuento.Enabled = false;
                    txtArtDescuento.Text = LprDscto.ToString();
                }
                else
                {
                    txtArtDescuento.Enabled = true;
                    txtArtDescuento.Text = "0";
                }
                txtArtCant.Text = "1";
            }
            else
                txtArtCant.Text = "0";

            txtImpTotal.Text = "0.0";

            lstArticulos = null;
            oArticulo = null;

            CalcularTotalArticulo();
            lsbArticulos.Focus();
        }