Пример #1
0
 /// <summary>
 /// 添加一个标签
 /// </summary>
 /// <param name="value">标签数据</param>
 /// <returns>返回新增的标签的ID</returns>
 public int InsertTag(TagItem value)
 {
     int id = 0;
     _DbParameter[] pars ={
                              new _DbParameter().Set("@Key", DbType.String, value.Key),
                              new _DbParameter().Set("@PC", DbType.Int32, value.PostCount)
                          };
     conn.ExecuteNonQuery("INSERT INTO [Tag] ([Key], [PostCount]) VALUES (@Key, @PC)", pars);
     id = Convert.ToInt32(conn.ExecuteNewField("[Tag]", null, null));
     return id;
 }
Пример #2
0
 /// <summary>
 /// 把一个标签列插入到数据库里(存在的标签则更新,否则新增)
 /// </summary>
 /// <param name="list">标签列表</param>
 /// <returns>返回成功插入的数量</returns>
 public int InsertTagList(string list)
 {
     int count = 0;
     if (!string.IsNullOrEmpty(list))
     {
         string[] arrList = list.Split(',', ' ');
         for (int i = 0; i < arrList.Length; i++)
         {
             if (!string.IsNullOrEmpty(arrList[i])) { arrList[i] = arrList[i].Trim(); }
             if (ExistsKey(arrList[i], 0)) { CountTagPost(arrList[i]); }
             else
             {
                 TagItem val = new TagItem();
                 val.Key = arrList[i];
                 val.PostCount = 1;
                 InsertTag(val);
             }
             count++;
         }
     }
     return count;
 }
Пример #3
0
 /// <summary>
 /// 修改一个标签
 /// </summary>
 /// <param name="value">标签数据</param>
 /// <returns>返回被修改的标签的ID</returns>
 public int UpdateTag(TagItem value)
 {
     int id = 0;
     _DbParameter[] pars ={
                              new _DbParameter().Set("@Key", DbType.String, value.Key),
                              new _DbParameter().Set("@ID", DbType.Int32, value.ID)
                          };
     conn.ExecuteNonQuery("UPDATE [Tag] SET [Key] = @Key WHERE [ID] = @ID", pars);
     id = value.ID;
     return id;
 }
Пример #4
0
 /// <summary>
 /// 筛选标签
 /// </summary>
 /// <param name="intCurPage">当前页码</param>
 /// <param name="btePerPage">分页大小</param>
 /// <param name="orderField">排序字段</param>
 /// <param name="orderMode">排序模式,ASC, DESC</param>
 /// <returns>返回标签数据列表</returns>
 public TagList SelectTag(int intCurPage, int btePerPage, string orderField, string orderMode)
 {
     if (string.IsNullOrEmpty(orderField)) { orderField = "[Key]"; }
     if (string.IsNullOrEmpty(orderMode)) { orderMode = "ASC"; }
     TagList list = new TagList();
     int rows = 0;
     using (IDataReader reader = conn.ExecutePager("[Tag]", "[ID], [Key], [PostCount]", null, orderField, orderMode, intCurPage, btePerPage, ref rows))
     {
         while (reader.Read())
         {
             TagItem item = new TagItem();
             item.ID = reader.GetInt32(0);
             item.Key = reader.GetString(1);
             item.PostCount = reader.GetInt32(2);
             list.Add(item);
         }
     }
     list.Number = rows;
     return list;
 }
Пример #5
0
 /// <summary>
 /// 系统标签操作
 /// </summary>
 /// <returns>标签列表及操作表单</returns>
 public string List()
 {
     StringBuilder sr = new StringBuilder();
     TagData tData = new TagData(conn);
     if (SiteFun.IsPost)
     {
         //取值
         TagItem postVal = new TagItem();
         postVal.ID = SiteFun.ToInt(SiteFun.Post("id"));
         postVal.Key = SiteFun.Post("key");
         //处理
         if (string.IsNullOrEmpty(postVal.Key)) { sr.Append(AdminUI.ErrorBox(SiteDat.GetLan("MsgNoKey"))); }
         else
         {
             if (tData.ExistsKey(postVal.Key, postVal.ID)) { sr.Append(AdminUI.ErrorBox(SiteDat.GetLan("MsgTagExists"))); }
             else
             {
                 if (postVal.ID == 0) { tData.InsertTag(postVal); sr.Append(AdminUI.SuccessBox(SiteDat.GetLan("MsgInsertDat"))); }
                 else
                 {
                     if (SiteFun.ToInt(SiteFun.Post("del")) == 0) { tData.UpdateTag(postVal); sr.Append(AdminUI.SuccessBox(SiteDat.GetLan("MsgUpdateDat"))); }
                     else { tData.DeleteTag(postVal.ID); sr.Append(AdminUI.SuccessBox(SiteDat.GetLan("MsgDelDat"))); }
                 }
             }
         }
         ClearCache();
     }
     sr.Append(AdminUI.AdminBoxStart(true));
     sr.Append(HtmlUI.TableStart());
     sr.Append(HtmlUI.TrStart());
     sr.Append(HtmlUI.CreateTh(SiteDat.GetLan("Key")));
     sr.Append(HtmlUI.CreateTh(SiteDat.GetLan("Article")));
     sr.Append(HtmlUI.CreateTh(SiteDat.GetLan("Delete")));
     sr.Append(HtmlUI.CreateTh(SiteDat.GetLan("Operate")));
     sr.Append(HtmlUI.TrFinal());
     //下面三行是分页设置
     int page = SiteFun.ToInt(SiteFun.Query("page"));
     if (page < 1) { page = 1; }
     int pageSize = 20;
     TagList list = new TagData(conn).SelectTag(page, pageSize);
     int i = 1;
     foreach (TagItem vItem in list)
     {
         i++;
         sr.Append(HtmlUI.FormStart());
         sr.Append(HtmlUI.TrStart(i % 2 == 0 ? " cRow" : null));
         sr.Append(HtmlUI.CreateTd(HtmlUI.HiddenInput("id", vItem.ID) + HtmlUI.Input("key", 20, null, SiteFun.HtmlEncode(vItem.Key))));
         sr.Append(HtmlUI.CreateTd(vItem.PostCount));
         sr.Append(HtmlUI.CreateTd(HtmlUI.CheckBoxInput("del", 1, false)));
         sr.Append(HtmlUI.CreateTd(HtmlUI.SubmitButton(SiteDat.GetLan("BtnSave"))));
         sr.Append(HtmlUI.TrFinal());
         sr.Append(HtmlUI.FormFinal());
     }
     sr.Append(HtmlUI.FormStart());
     sr.Append(HtmlUI.TrStart());
     sr.Append(HtmlUI.CreateTd(HtmlUI.Input("key", 20, null, null)));
     sr.Append(HtmlUI.CreateTd(0));
     sr.Append(HtmlUI.CreateTd());
     sr.Append(HtmlUI.CreateTd(HtmlUI.SubmitButton(SiteDat.GetLan("BtnInsert"))));
     sr.Append(HtmlUI.TrFinal());
     sr.Append(HtmlUI.FormFinal());
     sr.Append(HtmlUI.TrStart());
     sr.Append(HtmlUI.CreateTd(new SitePages().Make(list.Number, page, pageSize, "?act=tag&amp;mode=list&amp;page={0}"), 4, null));
     sr.Append(HtmlUI.TrFinal());
     sr.Append(HtmlUI.TableFinal());
     sr.Append(AdminUI.AdminBoxFinal());
     return sr.ToString();
 }
Пример #6
0
 /// <summary>
 /// 向列表里增加标签对象
 /// </summary>
 /// <param name="list">列表字符串,以半角逗号区分</param>
 /// <returns>返回零</returns>
 public int AddString(string list)
 {
     if (!string.IsNullOrEmpty(list))
     {
         string[] strArray = list.Split(new char[] { ',', ' ' });
         for (int i = 0; i < strArray.Length; i++)
         {
             if (!string.IsNullOrEmpty(strArray[i]))
             {
                 TagItem item = new TagItem();
                 item.Key = strArray[i].Trim();
                 base.List.Add(item);
             }
         }
     }
     return 0;
 }
Пример #7
0
 /// <summary>
 /// 向当前列表增加标签对象
 /// </summary>
 /// <param name="value"></param>
 /// <returns></returns>
 public int Add(TagItem value)
 {
     return base.List.Add(value);
 }