protected void grdProductos_RowUpdating(object sender, GridViewUpdateEventArgs e) { string s_codigoProducto = ((Label)grdProductos.Rows[e.RowIndex].FindControl("lbl_eit_Codigo")).Text; string s_nombreProducto = ((TextBox)grdProductos.Rows[e.RowIndex].FindControl("txt_eit_nombre")).Text; string s_DescripcionProducto = ((TextBox)grdProductos.Rows[e.RowIndex].FindControl("txt_eit_descripcion")).Text; string s_MarcaProducto = ((DropDownList)grdProductos.Rows[e.RowIndex].FindControl("ddl_eit_marca")).SelectedValue; string s_CategoriaProducto = ((DropDownList)grdProductos.Rows[e.RowIndex].FindControl("ddl_eit_categoria")).SelectedValue; string s_GeneroProducto = ((DropDownList)grdProductos.Rows[e.RowIndex].FindControl("ddl_eit_genero")).SelectedValue; string s_FechaPublicacion = ((TextBox)grdProductos.Rows[e.RowIndex].FindControl("txt_eit_FPublicacion")).Text; string s_CodigoPlataforma = ((DropDownList)grdProductos.Rows[e.RowIndex].FindControl("ddl_eit_plataforma")).SelectedValue; string s_Stock = ((TextBox)grdProductos.Rows[e.RowIndex].FindControl("txt_eit_Stock")).Text; string s_PU = ((TextBox)grdProductos.Rows[e.RowIndex].FindControl("txt_eit_PrecioUnitario")).Text; string s_img = ((TextBox)grdProductos.Rows[e.RowIndex].FindControl("txt_eit_Imagen")).Text; ENTIDAD.Producto p = new ENTIDAD.Producto(); PlataformaXProducto PxP = new PlataformaXProducto(); p.setCodigoProducto(s_codigoProducto); p.setNombreProducto(s_nombreProducto); p.setDescripcion(s_DescripcionProducto); p.setIdCodigoMarca(s_MarcaProducto); p.setIdCodigoCategoria(s_CategoriaProducto); p.setIdCodigoGenero(s_GeneroProducto); p.setFechaPublicacion(DateTime.Parse(s_FechaPublicacion)); PxP.setIdProducto(s_codigoProducto); PxP.setIdPlataforma(s_CodigoPlataforma); PxP.setStock(Int32.Parse(s_Stock)); PxP.setPrecioUnitario(decimal.Parse(s_PU)); PxP.setimgURL(s_img); N_Producto n_Producto = new N_Producto(); n_Producto.ActualizarProducto(p); N_PlataformaXProducto n_PxP = new N_PlataformaXProducto(); n_PxP.ActualizarPlataformaxProducto(PxP); grdProductos.EditIndex = -1; cargarGridview(); }
protected void btnAgregar_Click(object sender, EventArgs e) { try { ENTIDAD.Producto producto = new ENTIDAD.Producto(); PlataformaXProducto PxP = new PlataformaXProducto(); String s_categoria = ddlCategoria.SelectedValue.ToString(); String s_genero = ddlGeneros.SelectedValue.ToString(); String s_marca = ddlMarcas.SelectedValue.ToString(); String s_plat = ddlPlataformas.SelectedValue.ToString(); String nom = txtNombreProducto.Text; String desc = txtDescripcion.Text; String fecha = txtAnioFabricacion.Text; String img = txtimgURL.Text; String pu = txtPrecio.Text; String stock = txtStock.Text; if (solonumeros(Int32.Parse(pu)) == false) { Response.Write("<script>alert('Solo se aceptan numeros con decimal');</script>"); } N_Producto n_Producto = new N_Producto(); if (s_categoria != "" && s_genero != "" && s_marca != "" && s_plat != "" && nom != "" && desc != "" && fecha != "" && img != "" && pu != "" && stock != "") { int n = n_Producto.getConsultaUltimoProducto() + 1; string cod = "A" + n.ToString(); producto.setCodigoProducto(cod); producto.setNombreProducto(nom); producto.setIdCodigoCategoria(s_categoria); producto.setIdCodigoGenero(s_genero); producto.setIdCodigoMarca(s_marca); producto.setDescripcion(desc); producto.setFechaPublicacion(DateTime.Parse(fecha)); producto.setEstado(true); PxP.setIdPlataforma(s_plat); PxP.setimgURL(img); PxP.setPrecioUnitario(decimal.Parse(pu)); PxP.setStock(Int16.Parse(stock)); PxP.setIdProducto(cod); N_PlataformaXProducto n_PXP = new N_PlataformaXProducto(); if (n_Producto.AltaProducto(producto) == true && n_PXP.AltaPlataformaxProducto(PxP) == true) { Response.Write("<script>alert('Marca agregada con exito');</script>"); Response.Redirect("AdminProductos.aspx"); } } else { Response.Write("<script>alert('Debe completar todos los campos');</script>"); } } catch (Exception ex) { throw; } }
protected void btnComprar_Click(object sender, EventArgs e) { int filasventa = 0; int filasdet = 0; Venta venta = new Venta(); Usuario usr = new Usuario(); TipoDePago tp = new TipoDePago(); TipoUsuario tu = new TipoUsuario(); N_Usuario negu = new N_Usuario(); N_Venta negv = new N_Venta(); N_Producto negp = new N_Producto(); N_Plataforma negpl = new N_Plataforma(); string codUsuario = negu.getIDporUsername(this.Session["username"].ToString().Trim()); string tipoUsuario = this.Session["usertype"].ToString(); string tipoPago = ddlTipoPago.SelectedValue.ToString(); tu.setCodigoTipoUsuario(tipoUsuario); usr.setCodigoUsuario(codUsuario); usr.setIdTipoUsuario(tu); venta.setIdCodigoUsuario(usr); venta.setFechaVenta(DateTime.Now); tp.setcodigoTipo(tipoPago); venta.setIdTipoPago(tp); filasventa = negv.GuardarVenta(venta); DataTable dt = (DataTable)Session["carrito"]; int stockTotal = 0; ///COMPROBAR QUE TODOS LOS PRODUCTOS TENGAN STOCK for (int c = 0; c < dt.Rows.Count; c++) { N_PlataformaXProducto negPXP = new N_PlataformaXProducto(); string codProd = negp.getCodigoProductoConNombre(dt.Rows[c]["Nombre"].ToString()); string stockProd = negPXP.getStockProducto(codProd); int stockFinal = Convert.ToInt32(stockProd) - Convert.ToInt32(dt.Rows[c]["Cantidad"].ToString()); if (stockFinal >= 0) { stockTotal++; } } if (stockTotal == dt.Rows.Count) { for (int i = 0; i < dt.Rows.Count; i++) { N_DetalleVenta negd = new N_DetalleVenta(); N_PlataformaXProducto pxp = new N_PlataformaXProducto(); DetalleVenta detalle = new DetalleVenta(); Venta v = new Venta(); ENTIDAD.Producto p = new ENTIDAD.Producto(); ENTIDAD.Plataforma pl = new Plataforma(); string codProd = negp.getCodigoProductoConNombre(dt.Rows[i]["Nombre"].ToString()); string codPlat = negpl.getCodigoPlataformaConNombre(dt.Rows[i]["Plataforma"].ToString()); int cant = Convert.ToInt32(dt.Rows[i]["Cantidad"].ToString()); float preciototal = float.Parse(dt.Rows[i]["PrecioUnitario"].ToString()); string stockProd = pxp.getStockProducto(codProd); int nuevostock = Convert.ToInt32(stockProd) - Convert.ToInt32(dt.Rows[i]["Cantidad"].ToString()); int codVenta = negv.getCodVenta(); v.setCodigoVenta(codVenta); detalle.setIdCodigoVenta(v); p.setCodigoProducto(codProd); detalle.setIdCodigoProducto(p); pl.setCodigoPlataforma(codPlat); detalle.setIdCodigoPlataforma(pl); detalle.setCantidadVendida(cant); detalle.setPrecioUnitario(preciototal / cant); filasdet = negd.GuardarDetalleVenta(detalle); pxp.modificarStockProducto(codProd, nuevostock.ToString()); } if (filasventa > 0 && filasdet > 0) { this.Session["carrito"] = null; Response.Redirect("CarritoCheckout.aspx"); } else { this.Session["carrito"] = null; Response.Redirect("CarritoError.aspx"); } } else { this.Session["carrito"] = null; Response.Redirect("CarritoStock.aspx"); } }