private void Noticia_Cargar(int idNoticia) { NoticiasWCFClient objNoticiaWCF = new NoticiasWCFClient(); NoticiaFoto_ListarResult[] lstFotos = null; Noticia_BuscarResult objNoticia; try { objNoticia = objNoticiaWCF.Noticia_Buscar(idNoticia, ref lstFotos); txtTexto.Text = objNoticia.texto; txtTitulo.Text = objNoticia.titulo; dpFechaPublicacion.SelectedDate = objNoticia.fechaPublicacion; dpFechaVencimiento.SelectedDate = objNoticia.fechaVencimiento; cboEmpresa.SelectedValue = objNoticia.idEmpresa.ToString(); ckbActivo.Checked = objNoticia.activo; grdImagenes.Visible = true; grdImagenes.DataSource = lstFotos; grdImagenes.DataBind(); ViewState["lstFotos"] = JsonHelper.JsonSerializer(lstFotos); rauArchivo.MaxFileInputsCount = 5 - lstFotos.Count(); } catch (Exception ex) { throw ex; } }
protected void btnGuardar_Click(object sender, EventArgs e) { if (Session["Usuario"] == null) { ScriptManager.RegisterStartupScript(Page, this.GetType(), "mykey", "CancelEdit();", true); } NoticiasWCFClient objNoticiasWCF = new NoticiasWCFClient(); int idNoticia = 0; List <NoticiaFoto_ListarResult> lstFotos = JsonHelper.JsonDeserialize <List <NoticiaFoto_ListarResult> >((string)ViewState["lstFotos"]); try { if (string.IsNullOrEmpty(txtTexto.Text)) { throw new ArgumentException("Se debe ingresar un texto valido."); } if (string.IsNullOrEmpty(txtTitulo.Text)) { throw new ArgumentException("Se debe ingresar un título para la noticia"); } if (DateTime.Compare(dpFechaPublicacion.SelectedDate.Value, dpFechaVencimiento.SelectedDate.Value) > 0) { throw new ArgumentException("La fecha de publicación no puede ser despues de la fecha de vencimiento."); } if (Request.QueryString["idNoticia"] != "") { idNoticia = int.Parse(Request.QueryString["idNoticia"]); foreach (GridDataItem row in grdImagenes.Items) { NoticiaFoto_ListarResult foto = lstFotos.Find(x => x.idNoticiaFoto.ToString() == row["idNoticiaFoto"].Text); foto.activo = ((RadButton)row.FindControl("btnSeleccionar")).Checked; lstFotos.RemoveAll(x => x.idNoticiaFoto.ToString() == row["idNoticiaFoto"].Text); lstFotos.Add(foto); } } if (lstFotos.FindAll(x => !x.elimino).Count <= 0) { throw new ArgumentException("Se debe guardar por lo menos un archivo valido."); } objNoticiasWCF.Noticia_Registrar(idNoticia, txtTitulo.Text, txtTexto.Text, dpFechaPublicacion.SelectedDate.Value, dpFechaVencimiento.SelectedDate.Value, int.Parse(cboEmpresa.SelectedValue), ((Usuario_LoginResult)Session["Usuario"]).idUsuario, ckbActivo.Checked, lstFotos.ToArray()); ScriptManager.RegisterStartupScript(Page, this.GetType(), "mykey", "CloseAndRebind(" + cboEmpresa.SelectedValue + ");", true); } catch (Exception ex) { lblMensaje.Text = "ERROR: " + ex.Message; lblMensaje.CssClass = "mensajeError"; } }
private void Noticias_Cargar(int idEmpresa, string descripcion) { NoticiasWCFClient objNoticiasWCF = new NoticiasWCFClient(); try { List <Noticia_ListarResult> lstNoticias = objNoticiasWCF.Noticia_Listar(idEmpresa, descripcion, DateTime.Now).ToList(); grdNoticias.DataSource = lstNoticias; grdNoticias.DataBind(); ViewState["lstNoticias"] = JsonHelper.JsonSerializer(lstNoticias); ViewState["idEmpresa"] = idEmpresa; ViewState["descripcion"] = descripcion; } catch (Exception ex) { throw ex; } }
protected void grdNoticias_DeleteCommand(object sender, Telerik.Web.UI.GridCommandEventArgs e) { if (Session["Usuario"] == null) { ScriptManager.RegisterStartupScript(Page, this.GetType(), "mykey", "CancelEdit();", true); } try { NoticiasWCFClient objNoticiasWCF = new NoticiasWCFClient(); objNoticiasWCF.Noticia_Eliminar(Convert.ToInt32(((GridDataItem)e.Item).GetDataKeyValue("idNoticia")), ((Usuario_LoginResult)Session["Usuario"]).idUsuario); Noticias_Cargar(int.Parse(cboEmpresa.SelectedValue), txtBuscar.Text); lblMensaje.Text = "La noticia se eliminó con éxito"; lblMensaje.CssClass = "mensajeExito"; } catch (Exception ex) { lblMensaje.Text = "ERROR: " + ex.Message; lblMensaje.CssClass = "mensajeError"; } }