protected void gvViajes_RowUpdating(object sender, GridViewUpdateEventArgs e) { String path = Server.MapPath("img\\"); path = path + DateTime.Now.ToString("HHmm"); try { EntViaje ent = new EntViaje(); ent.fotoLugar = gvViajes.DataKeys[e.RowIndex].Values["fotoLugar"].ToString(); ent.fotoHotel = gvViajes.DataKeys[e.RowIndex].Values["fotoHotel"].ToString(); FileUpload fuFotoLug = (FileUpload)gvViajes.Rows[e.RowIndex].FindControl("fuFotoLugarEIT"); FileUpload fuFotoHot = (FileUpload)gvViajes.Rows[e.RowIndex].FindControl("fuFotoHotelEIT"); if (fuFotoLug.HasFile) { string fileName = fuFotoLug.FileName; ent.fotoLugar = path + fileName; fuFotoLug.SaveAs(ent.fotoLugar); ent.fotoLugar = "img/" + DateTime.Now.ToString("HHmm") + fileName; } if (fuFotoHot.HasFile) { string fileName = fuFotoHot.FileName; ent.fotoHotel = path + fileName; fuFotoHot.SaveAs(ent.fotoHotel); ent.fotoHotel = "img" + DateTime.Now.ToString("HHmm") + fileName; } ent.id = Convert.ToInt32(gvViajes.DataKeys[e.RowIndex].Values["Id"]); ent.nombre = ((TextBox)gvViajes.Rows[e.RowIndex].FindControl("txtNombreEIT")).Text; ent.fechaLlegada = Convert.ToDateTime(((TextBox)gvViajes.Rows[e.RowIndex].FindControl("txtLlegadaEIT")).Text); ent.categoriaId = Convert.ToInt32(((DropDownList)gvViajes.Rows[e.RowIndex].FindControl("ddlCategoriaEIT")).SelectedItem.Value); ent.destinoId = Convert.ToInt32(((DropDownList)gvViajes.Rows[e.RowIndex].FindControl("ddlDestinoEIT")).SelectedItem.Value); ent.descripcion = ((TextBox)gvViajes.Rows[e.RowIndex].FindControl("txtDescrEIT")).Text; ent.video = ((TextBox)gvViajes.Rows[e.RowIndex].FindControl("txtVideoEIT")).Text; ent.estatus = ((CheckBox)gvViajes.Rows[e.RowIndex].FindControl("ckbEstatusEIT")).Checked; new BusViaje().Actualizar(ent); Response.Redirect("Default.aspx"); } catch (Exception ex) { Title = ex.Message; } }
public void Actualizar(EntViaje ent) { try { int filas = new DatViaje().Actualizar(ent.id, ent.nombre, ent.fechaLlegada.ToString("MM/dd/yyyy"), ent.destinoId, ent.categoriaId, ent.fechaAlta.ToString("MM/dd/yyyy"), ent.estatus, ent.descripcion, ent.video, ent.fotoLugar, ent.fotoHotel, ent.costo); if (filas != 1) throw new ApplicationException("Error al actualizar"); { } } catch (Exception ex) { throw new ApplicationException(ex.Message); } }
public List<EntViaje> Obtener() { DataTable dt = new DatViaje().Obtener(); List<EntViaje> lst = new List<EntViaje>(); foreach (DataRow dr in dt.Rows) { EntViaje ent = new EntViaje(); ent.id = Convert.ToInt32(dr["VIAJ_Id"]); ent.nombre = dr["VIAJ_NOMB"].ToString(); ent.fechaLlegada = Convert.ToDateTime(dr["VIAJ_FECH_LLEG"]); ent.categoriaId = Convert.ToInt32(dr["VIAJ_CATE_ID"]); ent.destinoId = Convert.ToInt32(dr["VIAJ_DEST_ID"]); ent.fechaAlta = Convert.ToDateTime(dr["VIAJ_FECH_ALTA"]); ent.estatus = Convert.ToBoolean(dr["VIAJ_ESTA"]); ent.descripcion =dr["VIAJ_DESC"].ToString(); ent.video = dr["VIAJ_VIDE"].ToString(); ent.fotoLugar = dr["VIAJ_FOTO_LUG"].ToString(); ent.fotoHotel = dr["VIAJ_FOTO_HOTE"].ToString(); ent.costo = Convert.ToDouble(dr["VIAJ_COST"]); lst.Add(ent); } return lst; }
protected void lnbAgregar_Click(object sender, EventArgs e) { string path = Server.MapPath("img\\"); path = path + DateTime.Now.ToString("HHmm"); try { EntViaje entViaje = new EntViaje(); entViaje.fotoLugar = ((TextBox)gvViajes.FooterRow.FindControl("fuFotoLugarFT")).Text; entViaje.fotoHotel = ((TextBox)gvViajes.FooterRow.FindControl("fuFotoHotelFT")).Text; FileUpload fuFotoLugr = (FileUpload)gvViajes.FooterRow.FindControl("fuFotoLugarFT"); FileUpload fuFotoHolet = (FileUpload)gvViajes.FooterRow.FindControl("fuFotoHotelFT"); if (fuFotoLugr.HasFile) { string fileName = fuFotoLugr.FileName; entViaje.fotoLugar = path + fileName; fuFotoLugr.SaveAs(entViaje.fotoLugar); entViaje.fotoLugar = "img/" + DateTime.Now.ToString("HHmm") + fileName; } else { string alerta = "Error: falta agregar una image del deltino turístco"; ScriptManager.RegisterStartupScript(this, GetType(), "", alerta, true); } if (fuFotoHolet.HasFile) { string fileName = fuFotoHolet.FileName; entViaje.fotoHotel = path + fileName; fuFotoHolet.SaveAs(entViaje.fotoHotel); entViaje.fotoHotel = "img/" + DateTime.Now.ToString("HHmm") + fileName; } else { string alerta = "Errot: falta agregar la foto del hotel"; ScriptManager.RegisterStartupScript(this, GetType(), "", alerta, true); } entViaje.nombre = ((TextBox)gvViajes.FooterRow.FindControl("txtNombreFT")).Text; entViaje.fechaLlegada = Convert.ToDateTime(((TextBox)gvViajes.FooterRow.FindControl("txtLlegadaEIT")).Text); entViaje.categoriaId = Convert.ToInt32(((DropDownList)gvViajes.FooterRow.FindControl("ddlCategoriaFT")).SelectedValue); entViaje.destinoId = Convert.ToInt32(((DropDownList)gvViajes.FooterRow.FindControl("ddlDestinoFT")).SelectedValue); entViaje.descripcion = ((TextBox)gvViajes.FooterRow.FindControl("txtDescrFT")).Text; entViaje.descripcion = ((TextBox)gvViajes.FooterRow.FindControl("txtVideoFT")).Text; entViaje.estatus = ((CheckBox)gvViajes.FooterRow.FindControl("chbEstatusFT")).Checked; entViaje.fechaAlta = Convert.ToDateTime(DateTime.Now.ToString("MM/dd/yyyy")); new BusViaje().Insertar(entViaje); Response.Redirect("Default.aspx"); } catch (Exception ex) { Title = "Error: " + ex.Message; } }
public EntViaje Obtener(int id) { try { DataTable dt = new DatViaje().Obtener(); EntViaje ent = new EntViaje(); ent.id = Convert.ToInt32(dt.Rows[0]["VIAJ_Id"]); ent.nombre = dt.Rows[0]["VIAJ_NOMB"].ToString(); ent.fechaLlegada = Convert.ToDateTime(dt.Rows[0]["VIAJ_FECH_LLEG"]); ent.categoriaId = Convert.ToInt32(dt.Rows[0]["VIAJ_CATE_ID"]); ent.destinoId = Convert.ToInt32(dt.Rows[0]["VIAJ_DEST_ID"]); ent.fechaAlta = Convert.ToDateTime(dt.Rows[0]["VIAJ_FECH_ALTA"]); ent.estatus = Convert.ToBoolean(dt.Rows[0]["VIAJ_ESTA"]); ent.descripcion = dt.Rows[0]["VIAJ_DESC"].ToString(); ent.video = dt.Rows[0]["VIAJ_VIDE"].ToString(); ent.fotoLugar = dt.Rows[0]["VIAJ_FOTO_LUG"].ToString(); ent.fotoHotel = dt.Rows[0]["VIAJ_FOTO_HOTE"].ToString(); ent.costo = Convert.ToDouble(dt.Rows[0]["VIAJ_DESC"]); return ent; } catch (Exception ex) { throw new ApplicationException(ex.Message); } }
public void Insertar(EntViaje ent) { int filas = new DatViaje().spInsertar(ent.nombre, ent.fechaLlegada.ToString("MM/dd/yyyy"), ent.categoriaId, ent.destinoId, ent.fechaAlta.ToString("MM/dd/yyyy"), ent.estatus, ent.descripcion, ent.video, ent.fotoLugar, ent.fotoHotel, ent.costo); if (filas != 1) throw new ApplicationException("Error al insertar"); }