protected void btnGuardar_Click(object sender, EventArgs e)
        {
            Entidad.Productos producto = null;
            try
            {
                producto                = new Entidad.Productos();
                producto.Descripcion    = txtDescripcion.Text.Trim().ToUpper();
                producto.Existencia     = int.Parse(txtExistencia.Text);
                producto.PrecioUnitario = decimal.Parse(txtPrecioUnitario.Text);
                producto.FechaProceso   = DateTime.Now;
                producto.Estado         = 1;

                if (dc.InsertaProductoNegocio(producto) > 0)
                {
                    cvMensaje.IsValid      = false;
                    cvMensaje.Text         = "EL PRODUCTO " + producto.Descripcion + " FUE GUARDADO EXITOSAMENTE";
                    cvMensaje.ErrorMessage = "EL PRODUCTO " + producto.Descripcion + " FUE GUARDADO SATISFACTORIAMENTE";
                    txtDescripcion.Text    = "";
                    txtExistencia.Text     = "";
                    txtPrecioUnitario.Text = "";
                }
            }
            catch (Exception excepcion)
            {
                cvMensaje.IsValid = false;
                cvMensaje.Text    = "ERROR AL GUARDAR EL PRODUCTO " + producto.Descripcion + ": " + excepcion.Message;
            }
        }
 protected void btnGuardar_Click(object sender, EventArgs e)
 {
     try
     {
         dc = new Negocio.ProductoNegocio();
         Entidad.Productos producto = null;
         producto                = (Entidad.Productos)Session["ObjetoProducto"];
         producto.Descripcion    = txtDescripcion.Text.Trim().ToUpper();
         producto.Existencia     = int.Parse(txtExistencia.Text.Trim());
         producto.PrecioUnitario = decimal.Parse(txtPrecioUnitario.Text.Trim());
         producto.Estado         = 1;
         producto.FechaProceso   = DateTime.Now;
         producto.UsuarioProceso = 0;
         if (dc.EditaProductoNegocio(producto) > 0)
         {
             txtDescripcion.Text    = ""; txtDescripcion.ReadOnly = true; rfvDescripcion.Enabled = false;
             txtExistencia.Text     = "";  txtExistencia.ReadOnly = true; rfvExistencia.Enabled = false;
             txtPrecioUnitario.Text = ""; txtPrecioUnitario.ReadOnly = true; rfvPrecioUnitario.Enabled = false;
             btnGuardar.Visible     = false; btnGuardar.Enabled = false; btnCancelar.Text = "Volver";
             cvMensaje.IsValid      = false;
             cvMensaje.ErrorMessage = "EL PRODUCTO " + producto.Descripcion + " FUE EDITADO CORRECTAMENTE";
         }
         else
         {
             throw new Exception("OCURRIO UN EEROR AL EDITAR EL ELEMENTO " + producto.Descripcion);
         }
     }
     catch (Exception excepcion)
     {
         cvMensaje.IsValid      = false;
         cvMensaje.ErrorMessage = "ERROR: " + excepcion.Message;
     }
 }
 public int EditaProductoNegocio(Entidad.Productos producto)
 {
     try
     {
         dc = new ProductoDatos();
         return(dc.EditaProductoDatos(producto));
     }
     catch (Exception excepcion)
     {
         throw excepcion;
     }
 }
 public int InsertaProdructoDatos(Entidad.Productos producto)
 {
     try
     {
         dc = new Entidad.BD_EvaluacionEntities();
         dc.Productos.Add(producto);
         return(dc.SaveChanges());
     }
     catch (Exception excepcion)
     {
         throw excepcion;
     }
 }
 public void CargaDatos(Entidad.Productos producto)
 {
     try
     {
         txtDescripcion.Text    = producto.Descripcion;
         txtExistencia.Text     = producto.Existencia.ToString();
         txtPrecioUnitario.Text = producto.PrecioUnitario.ToString();
     }
     catch (Exception excepcion)
     {
         cvMensaje.IsValid      = false;
         cvMensaje.ErrorMessage = "ERROR: " + excepcion.Message;
     }
 }
示例#6
0
 /*METODO ENCARGADO DE OBTENER LOS DATOS DEL PRODUCTOS*/
 public Entidad.Productos DatosProducto(int id)
 {
     Entidad.BD_EvaluacionEntities dc = null;
     Entidad.Productos             p  = new Entidad.Productos();
     try
     {
         dc = new Entidad.BD_EvaluacionEntities();
         p  = dc.Productos.Where(pro => pro.Id == id).FirstOrDefault();
     }
     catch (Exception err)
     {
         throw (err);
     }
     return(p);
 }
 /*METODO ENCARGADO DE OBTENER LOS DATOS DEL PRODUCTOS*/
 public Entidad.Productos DatosProducto(int id)
 {
     Datos.ProductosDatos dc = null;
     Entidad.Productos    p  = new Entidad.Productos();
     try
     {
         dc = new Datos.ProductosDatos();
         p  = dc.DatosProducto(id);
     }
     catch (Exception err)
     {
         throw (err);
     }
     return(p);
 }
 protected void Page_Load(object sender, EventArgs e)
 {
     if (!IsPostBack)
     {
         if (Session["sessionIDUsuario"] != null)
         {
             Entidad.Productos producto = (Entidad.Productos)Session["ObjetoProducto"];
             CargaDatos(producto);
         }
         else
         {
             Response.Redirect("wfLogin");
         }
     }
 }
 public int InsertaProductoNegocio(Entidad.Productos producto)
 {
     try
     {
         dc = new ProductoDatos();
         if (RetornaProductoNegocio(producto) == null)
         {
             return(dc.InsertaProdructoDatos(producto));
         }
         else
         {
             throw new Exception("EL PRODUCTO QUE INTENTÓ GRABAR, YA EXISTE.");
         }
     }
     catch (Exception excepcion)
     {
         throw excepcion;
     }
 }
 public int EditaProductoDatos(Entidad.Productos ProductoEditado)
 {
     try
     {
         dc = new Entidad.BD_EvaluacionEntities();
         Entidad.Productos ProductoAEditar = dc.Productos.Where(p => p.Id == ProductoEditado.Id).FirstOrDefault();
         ProductoAEditar.Id             = ProductoEditado.Id;
         ProductoAEditar.Descripcion    = ProductoEditado.Descripcion;
         ProductoAEditar.Existencia     = ProductoEditado.Existencia;
         ProductoAEditar.PrecioUnitario = ProductoEditado.PrecioUnitario;
         ProductoAEditar.FechaProceso   = DateTime.Now;
         ProductoAEditar.Estado         = ProductoEditado.Estado;
         ProductoAEditar.UsuarioProceso = 0;
         //dc.Productos.Attach(producto);
         return(dc.SaveChanges());
     }
     catch (Exception excepcion)
     {
         throw excepcion;
     }
 }
        public Entidad.Productos RetornaProductoNegocio(Entidad.Productos producto)
        {
            try
            {
                List <Entidad.Productos> listaProductos = RetornaListaProductosNegocio();

                if (listaProductos.Exists(lp => lp.Id == producto.Id))
                {
                    producto = listaProductos.Where(lp => lp.Id == producto.Id).FirstOrDefault();
                }
                else
                {
                    producto = null;
                }
            }
            catch (Exception excepcion)
            {
                throw excepcion;
            }
            return(producto);
        }
示例#12
0
        protected void gvProductos_RowCommand(object sender, GridViewCommandEventArgs e)
        {
            dc = new Negocio.ProductoNegocio();
            string identificador = e.CommandArgument.ToString();

            try
            {
                Entidad.Productos producto = new Entidad.Productos();
                producto.Id = int.Parse(identificador);
                producto    = dc.RetornaProductoNegocio(producto);

                if (e.CommandName == "ELIMINAR")
                {
                    producto.Estado = 0;
                    if (dc.EditaProductoNegocio(producto) > 0)
                    {
                        CargaProductos();
                        cvMensaje.IsValid      = false;
                        cvMensaje.ErrorMessage = "EL ELEMENTO " + producto.Descripcion + " FUE DADO DE BAJA CORRECTAMENTE";
                    }
                    else
                    {
                        throw new Exception("NO SE PUDO DAR DE BAJA EL ELEMENTO " + producto.Descripcion);
                    }
                }
                else
                {
                    /*Codigo para editar*/
                    Session["ObjetoProducto"] = producto;
                    Response.Redirect("wfEditaProductoIndividual");
                }
            }
            catch (Exception excepcion)
            {
                cvMensaje.IsValid      = false;
                cvMensaje.ErrorMessage = "ERROR: " + excepcion.Message;
            }
        }
 protected void btnAgregar_Click(object sender, EventArgs e)
 {
     try
     {
         Negocio.ProductosNegocio pn  = new Negocio.ProductosNegocio();
         Entidad.Productos        pro = new Entidad.Productos();
         /*SE OBTIENEN LOS DATOS DEL PRODUCTO PARA ASI SABER SU PRECIO Y EXISTENCIA*/
         pro = pn.DatosProducto(int.Parse(ddlProducto.SelectedValue));
         /*VERIFICAMOS SI HAY PRODUCTO EN EXISTENCIA*/
         if (int.Parse(txtCantidad.Text) > pro.Existencia)
         {
             cvDatos.IsValid      = false;
             cvDatos.CssClass     = "alert-danger";
             cvDatos.ErrorMessage = "No se puede despachar el producto " + ddlProducto.SelectedItem.ToString() + " porque no hay en existencia";
         } /*CIERRE IF EXISTENCIA*/
         else
         {
             /*SE CREO UNA CLASE DEDICADA A ALMACENAR LOS DATOS DEL GRID*/
             Negocio.Datos_Factura_Detalle        df  = new Negocio.Datos_Factura_Detalle();
             List <Negocio.Datos_Factura_Detalle> dfd = new List <Negocio.Datos_Factura_Detalle>();
             /*SI LA VARIABLE SESSION NO ESTA VACIA*/
             if (Session["s_Detalle_Factura"] != null)
             {
                 dfd = (List <Negocio.Datos_Factura_Detalle>)Session["s_Detalle_Factura"];
             }
             decimal SumaImporte = 0;
             /*SI EL PRODUCTO NO EXISTE LO AGREGAMOS AL GRID*/
             if (!ExisteProducto(int.Parse(ddlProducto.SelectedValue)))
             {
                 df.IdProducto     = int.Parse(ddlProducto.SelectedValue.ToString());
                 df.Producto       = ddlProducto.SelectedItem.ToString();
                 df.Cantidad       = int.Parse(txtCantidad.Text);
                 df.PrecioUnitario = pro.PrecioUnitario;
                 df.Importe        = (df.Cantidad * df.PrecioUnitario);
                 dfd.Add(df);
                 Session.Add("s_Detalle_Factura", dfd);
                 gvFactura.DataSource = dfd;
                 gvFactura.DataBind();
             }
             else
             {
                 cvDatos.IsValid      = false;
                 cvDatos.CssClass     = "alert-danger";
                 cvDatos.ErrorMessage = "No se puede agregar el producto " + ddlProducto.SelectedItem.ToString() + " porque ya esta en la lista.";
             }
             /*CICLO ENCARGADO DE SUMAR LOS IMPORTES DE LOS PRODUCTOS DEL GRID*/
             foreach (var item in dfd)
             {
                 SumaImporte += Convert.ToInt32(item.Importe);  //aqui recorre las celdas y las va sumando
             } /*CIERRE FOREACH*/
             txtSubTotal.Text = SumaImporte.ToString();
             decimal Impuesto = 0;
             Impuesto         = (decimal.Parse(txtSubTotal.Text) * 15) / 100;
             txtImpuesto.Text = Impuesto.ToString();
             /*CALCULAMOS EL NETO DE LA FACTURA*/
             decimal Total = 0;
             Total         = decimal.Parse(txtSubTotal.Text) + decimal.Parse(txtImpuesto.Text);
             txtTotal.Text = Total.ToString();
         } /*CIERRE DEL ELSE SI HAY EN EXISTENCIA PRODUCTO*/
     }
     catch (Exception err)
     {
         cvDatos.IsValid      = false;
         cvDatos.CssClass     = "alert-danger";
         cvDatos.ErrorMessage = err.Message;
     }
 }