/// <summary> /// 处理Repeater操作 /// </summary> /// <param name="source"></param> /// <param name="e"></param> protected void repList_ItemCommand(object source, RepeaterCommandEventArgs e) { int id = int.Parse(e.CommandArgument.ToString()); if (e.CommandName.Equals("Del")) { try { if (tagKeyInfoBLL.Delete(new int[] { id })) { MessageBox.ShowAndRedirect(this, "删除成功", "Keyword.aspx"); } } catch (Exception) { MessageBox.Show(this, "删除失败"); } } else if (e.CommandName.Equals("Edit")) { btnAdd.CommandName = "Edit"; tagKeyInfoModel = tagKeyInfoBLL.GetModel(id, EyouSoft.Model.NewsStructure.ItemCategory.KeyWord); txtKeyword.Text = tagKeyInfoModel.ItemName; txtUrl.Text = tagKeyInfoModel.ItemUrl; hfID.Value = id.ToString(); } }
/// <summary> /// 根据编号获取关键字/tag对象 /// </summary> /// <param name="id">编号</param> /// <param name="cate">类别</param> /// <returns></returns> public EyouSoft.Model.NewsStructure.TagKeyInfo GetModel(int id, EyouSoft.Model.NewsStructure.ItemCategory cate) { DbCommand comm = this._db.GetSqlStringCommand(SQL_TagKeyInfo_Select); this._db.AddInParameter(comm, "@id", DbType.Int32, id); this._db.AddInParameter(comm, "@cate", DbType.Int32, (int)cate); using (IDataReader dr = DbHelper.ExecuteReader(comm, this._db)) { if (dr.Read()) { EyouSoft.Model.NewsStructure.TagKeyInfo model = new EyouSoft.Model.NewsStructure.TagKeyInfo(); model.Id = dr.GetInt32(dr.GetOrdinal("Id")); model.Category = (EyouSoft.Model.NewsStructure.ItemCategory) int.Parse(dr[dr.GetOrdinal("Category")].ToString()); model.ItemName = dr.IsDBNull(dr.GetOrdinal("ItemName")) ? string.Empty : dr[dr.GetOrdinal("ItemName")].ToString(); model.ItemUrl = dr.IsDBNull(dr.GetOrdinal("ItemUrl")) ? string.Empty : dr[dr.GetOrdinal("ItemUrl")].ToString(); model.OperatorId = dr.GetInt32(dr.GetOrdinal("OperatorId")); model.IssueTime = dr.GetDateTime(dr.GetOrdinal("IssueTime")); return(model); } } return(null); }
/// <summary> /// 添加/编辑关键字组 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void btnAdd_Click(object sender, EventArgs e) { string key = txtKeyword.Text.Replace(" ", ""); if (IsHasCHZN(txtUrl.Text.Trim())) { MessageBox.Show(this, "URL链接不能有中文字符."); return; } tagKeyInfoModel = new EyouSoft.Model.NewsStructure.TagKeyInfo() { Category = EyouSoft.Model.NewsStructure.ItemCategory.KeyWord, ItemName = EyouSoft.Common.Function.StringValidate.Encode(key), ItemUrl = txtUrl.Text.Trim(), OperatorId = base.MasterUserInfo.ID }; bool result = false; try { if (btnAdd.CommandName.Equals("Add")) //添加关键字 { if (tagKeyInfoBLL.KeyWordExists(key, 0)) //如果该关键字已经存在 { MessageBox.Show(this, "关键字已经存在,请重新输入!!!"); return; } result = tagKeyInfoBLL.Add(tagKeyInfoModel); } else if (btnAdd.CommandName.Equals("Edit")) //编辑关键字 { int ID; result = int.TryParse(hfID.Value, out ID); if (result) { if (tagKeyInfoBLL.KeyWordExists(key, ID)) //如果该关键字已经存在 { MessageBox.Show(this, "关键字已经存在,请重新输入!!!"); return; } tagKeyInfoModel.Id = ID; result = tagKeyInfoBLL.Update(tagKeyInfoModel); } } if (result) { hfID.Value = string.Empty; MessageBox.ShowAndRedirect(this, "关键字组操作成功", "Keyword.aspx"); } else { MessageBox.Show(this, "操作失败"); } } catch (Exception) { MessageBox.Show(this, "操作失败"); } }
/// <summary> /// 修改 /// </summary> /// <param name="model"></param> /// <returns>true:成功 false:失败</returns> public bool Update(EyouSoft.Model.NewsStructure.TagKeyInfo model) { if (model == null) { return(false); } return(dal.Update(model)); }
/// <summary> /// 修改 /// </summary> /// <param name="model"></param> /// <returns>true:成功 false:失败</returns> public bool Update(EyouSoft.Model.NewsStructure.TagKeyInfo model) { DbCommand dc = this._db.GetSqlStringCommand(SQL_TagKeyInfo_Update); this._db.AddInParameter(dc, "Id", DbType.Int32, model.Id); this._db.AddInParameter(dc, "ItemName", DbType.String, model.ItemName); this._db.AddInParameter(dc, "ItemUrl", DbType.String, model.ItemUrl); this._db.AddInParameter(dc, "OperatorId", DbType.Int32, model.OperatorId); return(DbHelper.ExecuteSql(dc, this._db) > 0 ? true : false); }
/// <summary> /// 添加/修改 Tag标签 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void btnAdd_Click(object sender, EventArgs e) { string tag = txtTag.Text.Replace(" ", ""); tagKeyInfoModel = new EyouSoft.Model.NewsStructure.TagKeyInfo() { Category = EyouSoft.Model.NewsStructure.ItemCategory.Tag, ItemName = EyouSoft.Common.Function.StringValidate.Encode(tag), OperatorId = base.MasterUserInfo.ID }; bool result = false; try { if (btnAdd.CommandName.Equals("Add")) { if (tagKeyInfoBLL.TagExists(tag, 0)) //检测tag是否存在 { MessageBox.Show(this, "该tag已经存在,请重新输入!!!"); return; } result = tagKeyInfoBLL.Add(tagKeyInfoModel); } else if (btnAdd.CommandName.Equals("Edit")) { int ID; result = int.TryParse(hfid.Value, out ID); if (result) { if (tagKeyInfoBLL.TagExists(tag, ID)) //检测tag是否存在 { MessageBox.Show(this, "该tag已经存在,请重新输入!!!"); return; } tagKeyInfoModel.Id = ID; result = tagKeyInfoBLL.Update(tagKeyInfoModel); } } if (result) { hfid.Value = string.Empty; MessageBox.ShowAndRedirect(this, "Tag标签操作成功", "Tag.aspx"); } else { MessageBox.Show(this, "操作失败"); } } catch (Exception) { MessageBox.Show(this, "操作失败"); } }
/// <summary> /// 分页获取标签与关键字列表信息 /// </summary> /// <param name="pageSize">每页显示条数</param> /// <param name="pageIndex">当前页码</param> /// <param name="recordCount">总记录数</param> /// <param name="ItemName">项名称</param> /// <param name="ItemUrl">项链接</param> /// <param name="Category">类别 =null返回所有</param> /// <returns></returns> public IList <EyouSoft.Model.NewsStructure.TagKeyInfo> GetList(int pageSize, int pageIndex, ref int recordCount, string ItemName, string ItemUrl, EyouSoft.Model.NewsStructure.ItemCategory?Category) { IList <EyouSoft.Model.NewsStructure.TagKeyInfo> list = new List <EyouSoft.Model.NewsStructure.TagKeyInfo>(); string tableName = "tbl_TagKeyList"; string primaryKey = "Id"; string fields = "Id,Category,ItemName,ItemUrl,OperatorId,IssueTime"; string orderByStr = " IssueTime desc"; StringBuilder strQuery = new StringBuilder(" 1=1 "); if (!string.IsNullOrEmpty(ItemName)) { strQuery.AppendFormat(" and ItemName like'%{0}%' ", ItemName); } if (Category.HasValue) { strQuery.AppendFormat(" and Category={0} ", (int)Category.Value); if (Category.Value == EyouSoft.Model.NewsStructure.ItemCategory.KeyWord && !string.IsNullOrEmpty(ItemUrl)) { strQuery.AppendFormat(" and ItemUrl='{0}' ", ItemUrl); } } using (IDataReader dr = DbHelper.ExecuteReader(this._db, pageSize, pageIndex, ref recordCount, tableName, primaryKey, fields, strQuery.ToString(), orderByStr)) { while (dr.Read()) { EyouSoft.Model.NewsStructure.TagKeyInfo model = new EyouSoft.Model.NewsStructure.TagKeyInfo(); model.Id = dr.GetInt32(dr.GetOrdinal("Id")); model.Category = (EyouSoft.Model.NewsStructure.ItemCategory) int.Parse(dr[dr.GetOrdinal("Category")].ToString()); model.ItemName = dr.IsDBNull(dr.GetOrdinal("ItemName")) ? string.Empty : dr[dr.GetOrdinal("ItemName")].ToString(); model.ItemUrl = dr.IsDBNull(dr.GetOrdinal("ItemUrl")) ? string.Empty : dr[dr.GetOrdinal("ItemUrl")].ToString(); model.OperatorId = dr.GetInt32(dr.GetOrdinal("OperatorId")); model.IssueTime = dr.GetDateTime(dr.GetOrdinal("IssueTime")); list.Add(model); model = null; } } return(list); }
private void EditKeywordAjax() { string id = Utils.GetFormValue("tid"); string key = Utils.GetFormValue("k").Replace(" ", ""); string url = Utils.GetFormValue("u").Replace(" ", "");; string msg = string.Empty; if (tagKeyInfoBLL.KeyWordExists(key, int.Parse(id))) { msg = "false"; } else { EyouSoft.Model.NewsStructure.TagKeyInfo tagKeyInfoModel = new EyouSoft.Model.NewsStructure.TagKeyInfo() { Category = EyouSoft.Model.NewsStructure.ItemCategory.KeyWord, Id = int.Parse(id), ItemName = key, ItemUrl = url, OperatorId = base.MasterUserInfo.ID }; bool result = tagKeyInfoBLL.Update(tagKeyInfoModel); if (result) { msg = "true"; } else { msg = "ftrue"; } } Response.Clear(); Response.Write("{\"msg\":\"" + msg + "\"}"); Response.End(); }
/// <summary> /// 初始化资讯列表 /// </summary> private void InitNewsList(int typeId) { lsNews = new List <EyouSoft.Model.NewsStructure.NewsModel>(); //如果是关键字列表 if (Request["TagId"] != null) { string tagName = string.Empty; EyouSoft.BLL.NewsStructure.TagKeyInfo tagBll = new EyouSoft.BLL.NewsStructure.TagKeyInfo(); EyouSoft.Model.NewsStructure.TagKeyInfo tagModel = tagBll.GetModel(int.Parse(Request["TagId"].ToString()), EyouSoft.Model.NewsStructure.ItemCategory.Tag); if (tagModel != null) { tagName = tagModel.ItemName; } this.Page.Title = string.Format(EyouSoft.Common.PageTitle.Information_List_Title, tagName + "-相关内容"); //cateName = tagName == "" ? "行业资讯":tagName; cateName = "行业资讯"; EyouSoft.Model.NewsStructure.SearchOrderInfo queryModel = new EyouSoft.Model.NewsStructure.SearchOrderInfo(); queryModel.Tag = typeId; lsNews = bll.GetList(pageSize, pageIndex, ref recordCount, queryModel); } else { //type<0表示是大类 if (typeId < 0) { queryModel = new EyouSoft.Model.NewsStructure.SearchOrderInfo(); queryModel.Category = (EyouSoft.Model.NewsStructure.NewsCategory)(-typeId); lsNews = bll.GetList(pageSize, pageIndex, ref recordCount, queryModel); cateName = queryModel.Category.ToString(); this.Page.Title = string.Format(EyouSoft.Common.PageTitle.Information_List_Title, cateName); } else { cateName = newTypeBll.GetCategoryById(typeId) == null ? "" : ((EyouSoft.Model.NewsStructure.NewsCategory)newTypeBll.GetCategoryById(typeId)).ToString(); this.Page.Title = cateName; className = newTypeBll.GetNewsTypeName(typeId).ToString(); this.Page.Title = string.Format(EyouSoft.Common.PageTitle.Information_List_Title, className); queryModel = new EyouSoft.Model.NewsStructure.SearchOrderInfo(); queryModel.Type = typeId; lsNews = bll.GetList(pageSize, pageIndex, ref recordCount, queryModel); } } AddMetaTag("keywords", string.Format(EyouSoft.Common.PageTitle.Information_List_Keywords, cateName == "" ? className : cateName)); AddMetaTag("description", string.Format(EyouSoft.Common.PageTitle.Information_List_Des, cateName == "" ? className : cateName)); //如果有数据 if (lsNews != null && lsNews.Count > 0) { rptNewsList.DataSource = lsNews; rptNewsList.DataBind(); BindPage(); BindUpPage(); } }