public List<EntJuguete> Obtener() { DataTable dt = new DatJuguetes().Obtener(); List<EntJuguete> lst = new List<EntJuguete>(); foreach (DataRow dr in dt.Rows) { EntJuguete ent = new EntJuguete(); ent.Id = Convert.ToInt32(dr["Jugue_Id"]); ent.Nombre = dr["Jugue_Nombre"].ToString(); ent.Marca_Id = Convert.ToInt32(dr["Jugue_Marca_Id"]); ent.Modelo_Id = Convert.ToInt32(dr["Jugue_Modelo_Id"]); ent.Categoria_Id = Convert.ToInt32(dr["Jugue_Categoria_Id"]); ent.Costo = Convert.ToDouble(dr["Jugue_Costo"]); ent.Estatus = Convert.ToBoolean(dr["Jugue_Estatus"]); ent.Existencia = Convert.ToInt32(dr["Jugue_Existencia"]); ent.Fecha = Convert.ToDateTime(dr["Jugue_Fecha_Alta"]); ent.Foto = dr["Jugue_Foto"].ToString(); ent.Precio = Convert.ToDouble(dr["Jugue_Precio"]); ent.Marca.Nombre = Convert.ToString(dr["Cata_Nombre"]); ent.Modelo.Nombre = Convert.ToString(dr["Cata_Modelo_Nombre"]); ent.Categoria.Nombre = Convert.ToString(dr["Cate_Nombre"]); lst.Add(ent); } return lst; }
protected void GvJuguetes_RowDeleting(object sender, GridViewDeleteEventArgs e) { EntJuguete ent = new EntJuguete(); ent.Id = Convert.ToInt32(GvJuguetes.DataKeys[e.RowIndex].Values["Id"].ToString()); new BusJuguete().Borrar(ent); Response.Redirect(Request.CurrentExecutionFilePath); }
protected void btnActualizar_Click(object sender, EventArgs e) { EntJuguete ent = new EntJuguete(); ent.Nombre = txtNombre.Text; ent.Existencia = Convert.ToInt32(txtExistencia.Text); ent.Fecha = Convert.ToDateTime(txtFecha.Text); ent.Costo = Convert.ToInt32(lblCosto.Text); ent.Precio = Convert.ToInt32(txtPrecio.Text); ent.Marca_Id = Convert.ToInt32(ddlMarca.SelectedValue); ent.Modelo_Id = Convert.ToInt32(ddlModelo.SelectedValue); ent.Categoria_Id = Convert.ToInt32(ddlCategoria.SelectedValue); ent.Id = Convert.ToInt32(Request.QueryString["ID"]); ent.Foto = "Img/" + fuFoto.FileName; bool guardado = GuardarFoto(fuFoto); imgFoto.ImageUrl = "Img/" + fuFoto.FileName; ent.Estatus = chkEstatus.Checked; try { BusJuguete obj = new BusJuguete(); obj.Actuaizar(ent); Response.Redirect("EdicionUrl.aspx?ID=" + ent.Id); } catch (Exception ex) { Title = ex.Message; } }
public void Borrar(EntJuguete ent) { int filas = new DatJuguetes().Borrar(ent.Id); if (filas != 1) { throw new ApplicationException(string.Format("Error al Borrar")); } }
public void Actuaizar(EntJuguete ent) { int filas = new DatJuguetes().Actualizar(ent.Nombre, ent.Existencia, ent.Marca_Id, ent.Modelo_Id, ent.Categoria_Id, ent.Fecha.ToString("MM/dd/yyyy"), ent.Precio, ent.Estatus, ent.Costo, ent.Foto, ent.Id); if (filas != 1) { throw new ApplicationException(string.Format("Error al Actualizar")); } }
public void Insertar(EntJuguete ent) { bool existe = Validar(ent.Marca_Id, ent.Modelo_Id); if (existe) { int filas = new DatJuguetes().Actualizar(ent.Marca_Id, ent.Existencia, ent.Modelo_Id); if (filas != 1) throw new ApplicationException("error al actualizar"); } else { int filas = new DatJuguetes().Insertar(ent.Nombre, ent.Existencia, ent.Marca_Id, ent.Modelo_Id, ent.Categoria_Id, ent.Fecha.ToString("MM/dd/yyyy"), ent.Precio, ent.Estatus, ent.Costo, ent.Foto); if (filas != 1) throw new ApplicationException(string.Format("Error al Insertar")); } }
protected void GvJuguetes_RowUpdating(object sender, GridViewUpdateEventArgs e) { try { EntJuguete ent = new EntJuguete(); ent.Id = Convert.ToInt32(GvJuguetes.DataKeys[e.RowIndex].Values["Id"].ToString()); ent.Existencia = Convert.ToInt32(((TextBox)GvJuguetes.Rows[e.RowIndex].FindControl("txtExistenciaEIT")).Text); if (Convert.ToInt32(ent.Existencia) > Convert.ToInt32(GvJuguetes.DataKeys[e.RowIndex].Values["Existencia"].ToString())) throw new ApplicationException("La cantidad de articulos no es suficiente en la exitencia"); ent.Existencia = Convert.ToInt32(GvJuguetes.DataKeys[e.RowIndex].Values["Existencia"].ToString()) - ent.Existencia; new BusJuguete().Actuaizar(ent.Id, ent.Existencia); Response.Redirect(Request.CurrentExecutionFilePath); } catch (Exception ex) { MostrarMensaje(ex.Message); } }
protected void lnkAgregarFT_Click1(object sender, EventArgs e) { try { EntJuguete ent = new EntJuguete(); ent.Marca_Id = Convert.ToInt32(((DropDownList)GvJuguetes.FooterRow.FindControl("ddlMarcaFT")).SelectedValue); ent.Modelo_Id = Convert.ToInt32(((DropDownList)GvJuguetes.FooterRow.FindControl("ddlModeloFT")).SelectedValue); ent.Categoria_Id = Convert.ToInt32(((DropDownList)GvJuguetes.FooterRow.FindControl("ddlCategoriaFT")).SelectedValue); ent.Nombre = ((TextBox)GvJuguetes.FooterRow.FindControl("txtNombreFT")).Text; ent.Precio = Convert.ToDouble(((TextBox)GvJuguetes.FooterRow.FindControl("txtPrecioFT")).Text); ent.Costo = ent.Precio * 2.00; ent.Existencia = Convert.ToInt32(((TextBox)GvJuguetes.FooterRow.FindControl("txtExistenciaFT")).Text); FileUpload fu = (FileUpload)GvJuguetes.FooterRow.FindControl("fuFotoFT"); bool guardado = GuardarFoto(fu); ent.Foto = "Img/" + fu.FileName; ent.Fecha = Convert.ToDateTime(((TextBox)GvJuguetes.FooterRow.FindControl("txtFechaFT")).Text); ent.Estatus = ((CheckBox)GvJuguetes.FooterRow.FindControl("chkEstatusFT")).Checked; new BusJuguete().Insertar(ent); Response.Redirect(Request.CurrentExecutionFilePath); } catch (Exception ex) { MostrarMensaje(ex.Message); } }
protected void GvJuguetes_RowUpdating(object sender, GridViewUpdateEventArgs e) { try { EntJuguete ent = new EntJuguete(); ent.Id = Convert.ToInt32(GvJuguetes.DataKeys[e.RowIndex].Values["Id"].ToString()); ent.Marca_Id = Convert.ToInt32(((DropDownList)GvJuguetes.Rows[e.RowIndex].FindControl("ddlMarcaEIT")).SelectedValue); ent.Modelo_Id = Convert.ToInt32(((DropDownList)GvJuguetes.Rows[e.RowIndex].FindControl("ddlModeloEIT")).SelectedValue); ent.Categoria_Id = Convert.ToInt32(((DropDownList)GvJuguetes.Rows[e.RowIndex].FindControl("ddlCategoriaEIT")).SelectedValue); ent.Nombre = ((TextBox)GvJuguetes.Rows[e.RowIndex].FindControl("txtNombreEIT")).Text; ent.Precio = Convert.ToDouble(((TextBox)GvJuguetes.Rows[e.RowIndex].FindControl("txtPrecioEIT")).Text); ent.Costo = Convert.ToDouble(((Label)GvJuguetes.Rows[e.RowIndex].FindControl("lblCostoEIT")).Text); ent.Existencia = Convert.ToInt32(((TextBox)GvJuguetes.Rows[e.RowIndex].FindControl("txtExistenciaEIT")).Text); FileUpload fu = (FileUpload)GvJuguetes.Rows[e.RowIndex].FindControl("fuFotoEIT"); bool guardado = GuardarFoto(fu); ent.Foto = "Img/" + fu.FileName; ent.Fecha = Convert.ToDateTime(((TextBox)GvJuguetes.Rows[e.RowIndex].FindControl("txtFechaEIT")).Text); ent.Estatus = ((CheckBox)GvJuguetes.Rows[e.RowIndex].FindControl("chkEstatusEIT")).Checked; new BusJuguete().Actuaizar(ent); Response.Redirect(Request.CurrentExecutionFilePath); } catch (Exception ex) { MostrarMensaje(ex.Message); } }
public EntJuguete Obtener(int Id) { DataRow dr = new DatJuguetes().Obtener(Id); EntJuguete ent = new EntJuguete(); ent.Id = Convert.ToInt32(dr["Jugue_Id"]); ent.Nombre = dr["Jugue_Nombre"].ToString(); ent.Marca_Id = Convert.ToInt32(dr["Jugue_Marca_Id"]); ent.Modelo_Id = Convert.ToInt32(dr["Jugue_Modelo_Id"]); ent.Categoria_Id = Convert.ToInt32(dr["Jugue_Categoria_Id"]); ent.Costo = Convert.ToDouble(dr["Jugue_Costo"]); ent.Estatus = Convert.ToBoolean(dr["Jugue_Estatus"]); ent.Existencia = Convert.ToInt32(dr["Jugue_Existencia"]); ent.Fecha = Convert.ToDateTime(dr["Jugue_Fecha_Alta"]); ent.Foto = dr["Jugue_Foto"].ToString(); ent.Precio = Convert.ToDouble(dr["Jugue_Precio"]); return ent; }