protected void gvAdmProd_RowDeleting(object sender, GridViewDeleteEventArgs e) { TableCell cell = gvAdmProd.Rows[e.RowIndex].Cells[0]; int id = Convert.ToInt32(cell.Text); ProductoServicio productoServicio = new ProductoServicio(); productoServicio.eliminar(id); lblMessage.Text = "El producto ah sido eliminado correctamente"; }
protected void create_Click(object sender, EventArgs e) { ProductoServicio productoServicio = new ProductoServicio(); Producto producto = new Producto(); Tienda tiendaLog = new Tienda(); tiendaLog = (Tienda)Session["TiendaOnline"]; producto.idTienda = tiendaLog.Id; producto.Nombre = txtbxNombre.Text; producto.Descripcion = txtbxDescripcion.Text; producto.Precio = Convert.ToInt32(txtbxPrecio.Text); producto.Stock = Convert.ToInt32(txtbxStock.Text); String pathImagen = ""; if (fuTiendaImg.HasFile) { if ( (fuTiendaImg.PostedFile.ContentType == "image/jpeg") || (fuTiendaImg.PostedFile.ContentType == "image/pjpeg") || (fuTiendaImg.PostedFile.ContentType == "image/x-png") || (fuTiendaImg.PostedFile.ContentType == "image/bmp") || (fuTiendaImg.PostedFile.ContentType == "image/jpg") || (fuTiendaImg.PostedFile.ContentType == "image/gif") ) { if (Convert.ToInt64(fuTiendaImg.PostedFile.ContentLength) < 100000000) { // Esto debería cambiarse porque tiene el dir de mi PC. String photoFolder = Path.Combine(@"C:\Users\maxi\Desktop\Fork\VisualStudio\VS\photos", tiendaLog.Email); if (!Directory.Exists(photoFolder)) { Directory.CreateDirectory(photoFolder); String extension = Path.GetExtension(fuTiendaImg.FileName); String uniqueFileName = Path.ChangeExtension(fuTiendaImg.FileName, DateTime.Now.Ticks.ToString()); fuTiendaImg.SaveAs(Path.Combine(photoFolder, uniqueFileName + extension)); pathImagen = photoFolder + fuTiendaImg.FileName; } else { String extension = Path.GetExtension(fuTiendaImg.FileName); String uniqueFileName = Path.ChangeExtension(fuTiendaImg.FileName, DateTime.Now.Ticks.ToString()); fuTiendaImg.SaveAs(Path.Combine(photoFolder, uniqueFileName + extension)); pathImagen = photoFolder + fuTiendaImg.FileName; } } else lblStatus.Text = "El archivo debe ser menor a 10MB."; } else lblStatus.Text = "El archivo debe ser una imagen."; } else lblStatus.Text = "No se seleccionó ningún archivo."; producto.Imagen = pathImagen; producto.IdCategoria = Convert.ToInt32(ucElegirCategoria.SelectedValue); productoServicio.insertar(producto); // Una vez que se guarda habria que vaciar los datos y mostrar un cartelito de OK!!. //Producto producto = new Producto(); //producto.Nombre= txtbxNombre.Text; //producto.Descripcion= txtbxDescripcion.Text; //producto.Precio= Convert.ToInt32(txtbxPrecio.Text); //producto.Stock = Convert.ToInt32(txtbxStock.Text); //Int32 tamaño = System.Convert.ToInt32(fileUploadTiendaImg.FileBytes.Length); //string nombre = fileUploadTiendaImg.FileName.ToString(); //byte[] contenido = new byte[tamaño + 1]; //fileUploadTiendaImg.PostedFile.InputStream.Read(contenido, 0, tamaño); // Get the name of the file to upload. string fileName = Server.HtmlEncode(FileUpload1.FileName); // Get the extension of the uploaded file. string extension = System.IO.Path.GetExtension(fileName); //productoServicio.insertar(producto); }
protected void gvAdmProd_RowUpdating(object sender, GridViewUpdateEventArgs e) { TextBox t1 = new TextBox(); TextBox t2 = new TextBox(); TextBox t3 = new TextBox(); TextBox t4 = new TextBox(); TextBox t5 = new TextBox(); TextBox t6 = new TextBox(); //Convert.ToInt16(HiddenField1.Value) t1 = (TextBox)gvAdmProd.Rows[Convert.ToInt16(HiddenField1.Value)].Cells[0].Controls[0]; t2 = (TextBox)gvAdmProd.Rows[Convert.ToInt16(HiddenField1.Value)].Cells[1].Controls[0]; t3 = (TextBox)gvAdmProd.Rows[Convert.ToInt16(HiddenField1.Value)].Cells[2].Controls[0]; t4 = (TextBox)gvAdmProd.Rows[Convert.ToInt16(HiddenField1.Value)].Cells[3].Controls[0]; t5 = (TextBox)gvAdmProd.Rows[Convert.ToInt16(HiddenField1.Value)].Cells[4].Controls[0]; t6 = (TextBox)gvAdmProd.Rows[Convert.ToInt16(HiddenField1.Value)].Cells[5].Controls[0]; string id = t1.Text; string nombre = t2.Text; string descripcion = t3.Text; string stock = t4.Text; string precio = t5.Text; string categoria = t6.Text; Producto producto = new Producto(); producto.ID = Convert.ToInt32(id); producto.Nombre = nombre; producto.Descripcion = descripcion; producto.Stock = Convert.ToInt32(stock); producto.Precio = (float)System.Convert.ToSingle(precio); CategoriaServicio categoriaServicio = new CategoriaServicio(); int idCategoria = categoriaServicio.obtenerIdDeCategoria(categoria); producto.IdCategoria = idCategoria; ProductoServicio productoServicio = new ProductoServicio(); productoServicio.editar(producto); //DSTable.Rows[e.RowIndex]["Id"] = id; DSTable.Rows[e.RowIndex]["Nombre"] = nombre; DSTable.Rows[e.RowIndex]["Descripcion"] = descripcion; DSTable.Rows[e.RowIndex]["Stock"] = stock; DSTable.Rows[e.RowIndex]["Precio"] = precio; DSTable.Rows[e.RowIndex]["Categoria"] = categoria; gvAdmProd.EditIndex = -1; gvAdmProd.DataSource = DSTable; gvAdmProd.DataBind(); }
protected void Page_Load(object sender, EventArgs e) { if (Session["TiendaOnline"] != null) { Master.FindControl("noLog").Visible = false; Master.FindControl("loge").Visible = true; Master.FindControl("menu").Visible = true; } else Response.Redirect("default.aspx"); if (!IsPostBack) { ProductoServicio service = new ProductoServicio(); Tienda tienda = new Tienda(); tienda = (Tienda)Session["TiendaOnline"]; int idTienda = tienda.Id; DSTable = service.obtenerProductos(idTienda); gvAdmProd.DataSource = service.obtenerProductos(idTienda); gvAdmProd.DataBind(); } }