/// <summary> /// 控件绑定事件 /// </summary> /// <param name="source"></param> /// <param name="e"></param> protected void repInfo_ItemCommand(object source, RepeaterCommandEventArgs e) { if (e.CommandName == "del") { int id = Convert.ToInt32(e.CommandArgument); int num = KeyWordInfoService.Delete(id); if (num > 0) { ScriptManager.RegisterStartupScript(this.UpdatePanel1, this.GetType(), "", "alert('删除成功!');", true); } else { ScriptManager.RegisterStartupScript(this.UpdatePanel1, this.GetType(), "", "alert('删除失败,请重试!');", true); } sp.InitBindData(Repeater1, pager1, "KeyWordInfo", "id", "1=1"); } else if (e.CommandName == "mod") { int id = Convert.ToInt32(e.CommandArgument); KeyWordInfo item = KeyWordInfoService.GetModel(id); if (item != null) { txtPageName.Text = item.pageName; txtTitle.Text = item.title; txtKeyWord.Text = item.keyword; txtDesc.Text = item.description; txtURL.Text = item.pageNameValue; ViewState["modId"] = item.id; ScriptManager.RegisterStartupScript(this.UpdatePanel1, this.GetType(), "", "overKeyWordDiv();", true); } } }
/// <summary> /// 添加信息 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void Button1_Click1(object sender, EventArgs e) { string name = this.txtPageName.Text.Trim(); string title = this.txtTitle.Text.Trim(); string keyword = this.txtKeyWord.Text.Trim(); string description = this.txtDesc.Text.Trim(); string url = this.txtURL.Text.Trim(); KeyWordInfo item = new KeyWordInfo(); item.pageName = name; item.title = title; item.keyword = keyword; item.description = description; item.pageNameValue = url; if (ViewState["modId"] != null) { item.id = Convert.ToInt32(ViewState["modId"]); int num = KeyWordInfoService.Update(item); if (num > 0) { ScriptManager.RegisterStartupScript(this.UpdatePanel1, this.GetType(), "", "alert('保存成功!');", true); txtPageName.Text = ""; txtTitle.Text = ""; txtKeyWord.Text = ""; txtDesc.Text = ""; txtURL.Text = ""; } ViewState["modId"] = null; } else { if (KeyWordInfoService.Exists(item.pageNameValue)) { ScriptManager.RegisterStartupScript(this.UpdatePanel1, this.GetType(), "", "alert('信息已存在!');", true); return; } int num = KeyWordInfoService.Add(item); if (num > 0) { ScriptManager.RegisterStartupScript(this.UpdatePanel1, this.GetType(), "", "alert('保存成功!');", true); txtPageName.Text = ""; txtTitle.Text = ""; txtKeyWord.Text = ""; txtDesc.Text = ""; txtURL.Text = ""; } } sp.InitBindData(Repeater1, pager1, "KeyWordInfo", "id", "1=1"); }
/// <summary> /// 页面标题、关键字和描述信息 /// </summary> private void KeyWordBind() { string url = Request.Url.ToString().Replace("aspx", "html"); KeyWordInfo km = KeyWordInfoService.GetModel(url); if (km != null) { ViewState["title"] = km.title; ViewState["keyword"] = km.keyword; ViewState["miaoshu"] = km.description; } else { ViewState["title"] = BaseConfigService.GetById(9); ViewState["keyword"] = BaseConfigService.GetById(23); ViewState["miaoshu"] = BaseConfigService.GetById(13); } }