/// <summary> /// 批量删除 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void btnDel_Click(object sender, EventArgs e) { string ids = selInfo(); int num = 0; if (ids.Length == 0) { Jscript.Alert("请选择要删除的记录!", this.Page); return; } string[] arr = ids.TrimEnd(',').Split(','); int newsId = 0; for (int i = 0; i < arr.Length; i++) { int id = Convert.ToInt32(arr[i]); newsId = TopNewsService.GetModel(id).newsId; if (TopNewsService.Delete(id) > 0) { NewsService.UpdateTop(newsId, 0); num++; } } ScriptManager.RegisterStartupScript(this.UpdatePanel1, this.GetType(), "", "alert('成功删除" + num + "条记录!');", true); sp.InitBindData(Repeater1, pager1, "TopNews", "id", sear()); }
/// <summary> /// 获取对象 /// </summary> private void LoadModelInfo() { TopNews item = TopNewsService.GetModel(id); if (item != null) { txtTitle.Text = item.remark; txtZhaiYao.Text = item.baseInfo; ViewState["newsImg1"] = item.imgURL; } }
/// <summary> /// 发布资讯 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void btnRelease_Click(object sender, EventArgs e) { if (Session["loginUser"] == null) { Jscript.AlertAndRedirect("请登录", "/admin/login.aspx"); return; } if (newsId != 0) { TopNews item = new TopNews(); item.newsId = newsId; item.newsType = CRequest.GetInt("newsType", 0); item.imgURL = ""; if (ViewState["newsImg1"] != null) { item.imgURL = ViewState["newsImg1"].ToString(); } else { item.imgURL = ""; } item.baseInfo = txtZhaiYao.Text.Trim(); item.orderNum = 0; item.status = 0; item.remark = txtTitle.Text.Trim(); item.addtime = DateTime.Now; item.adduser = (Session["loginUser"] as AdminUser).id; item.infoType = 0; if (item.imgURL == "" || item.baseInfo == "") { this.lblError.Text = "请填写信息内容并上传图片"; return; } if (item.baseInfo.Length > 500) { this.lblError.Text = "信息内容不能超过500字"; return; } int num = TopNewsService.Add(item); if (num > 0) { NewsService.UpdateTop(item.newsId, 1); Response.Redirect("infoList.aspx"); } else { lblError.Text = "设置置顶失败"; } } if (id != 0) { TopNews item = TopNewsService.GetModel(id); if (item != null) { item.imgURL = ""; if (ViewState["newsImg1"] != null) { item.imgURL = ViewState["newsImg1"].ToString(); } else { item.imgURL = ""; } item.remark = txtTitle.Text.Trim(); item.baseInfo = txtZhaiYao.Text.Trim(); int num = TopNewsService.Update(item); if (num > 0) { Response.Redirect("topInfoList.aspx"); } else { lblError.Text = "修改失败"; } } } }