コード例 #1
0
ファイル: WeixinResLogic.cs プロジェクト: ReinhardHsu/devfw
 public ArticleResItem GetArticleItem(int id)
 {
     ArticleResItem res = null;
     DataBaseAccess db = this._dao.New();
     db.ExecuteReader(
         "SELECT Id ,ResId,Title ,Content,Url ,Pic ,Sort,Enabled,Description FROM wx_art_item WHERE Id=" + id.ToString(),
         rd =>
         {
             if (rd.Read())
             {
                 int resId = rd.GetInt32(1);
                 res = new ArticleResItem(new ArticleRes { Id = resId });
                 res.Id = rd.GetInt32(0);
                 res.Title = rd.GetString(2);
                 res.Content = rd.GetString(3);
                 res.Url = rd.GetString(4);
                 res.Pic = rd.GetString(5);
                 res.Sort = rd.GetInt32(6);
                 res.Enabled = rd.GetBoolean(7);
                 res.Description = rd.GetString(8);
             }
         });
     return res;
 }
コード例 #2
0
ファイル: WeixinResLogic.cs プロジェクト: ReinhardHsu/devfw
        public int SaveArticleItem(int id, ArticleResItem item)
        {
            DataBaseAccess db = this._dao.New();
            var data = new object[,]
            {
                {"@ResId", id},
                {"@Description",item.Description},
                {"@Content", item.Content},
                {"@Enabled", item.Enabled},
                {"@Pic", item.Pic},
                {"@Id", item.Id},
                {"@Sort", item.Sort},
                {"@Title", item.Title},
                {"@Url", item.Url},
            };

            if (item.Id > 0)
            {
                db.ExecuteNonQuery(new SqlQuery(@"UPDATE wx_art_item SET Title = @Title ,
                    [Content]=@Content, Description=@Description,[Url] = @Url ,[Pic] = @Pic ,[Sort] = @Sort ,[Enabled] = @Enabled
                    WHERE [ResId] = @ResId AND id=@Id",
                    data));
            }
            else
            {
                int row =
                    db.ExecuteNonQuery(new SqlQuery(@"INSERT INTO wx_art_item ([ResId],[Title],Description,[Content],[Url],[Pic],[Sort],[Enabled])
                        VALUES (@ResId,@Title,@Description,@Content,@Url,@Pic,@Sort,@Enabled)", data));
                if (row == 1)
                {
                    return Convert.ToInt32(db.ExecuteScalar("SELECT MAX(id) FROM wx_art_item"));
                }
            }

            return item.Id;
        }