public void DeleteRes(int resId) { DataBaseAccess db = this._dao.New(); IWxRes res = this.GetResById(resId); object[,] data = new object[, ] { { "@resId", resId } }; if (res.Type() == 1) { db.ExecuteNonQuery( new SqlQuery("DELETE FROM wx_res WHERE id=@resId", data), new SqlQuery("DELETE FROM wx_text Where resid=@resId", data) ); } else { db.ExecuteNonQuery( new SqlQuery("DELETE FROM wx_res WHERE id=@resId", data), new SqlQuery("DELETE FROM wx_art_item Where resid=@resId", data) ); } }
public int Save(IWxRes res) { TextRes textRes = res as TextRes; if (textRes != null) { return(SaveTextRes(textRes)); } else { ArticleRes artRes = res as ArticleRes; return(this.SaveArticleRes(artRes)); } }
public IResponseMessageBase GetResponseByResKey(CustomMessageHandler handler, string resKey) { IWxRes res = IocObject.WeixinRes.GetResByKey(resKey); if (res == null) { Config.Logln("素材" + resKey + "不存在"); } TextRes trs; if ((trs = res as TextRes) != null) { var strongResponseMessage = handler.CreateResponseMessage <ResponseMessageText>(); strongResponseMessage.Content = trs.Content; Config.Logln("素材" + resKey + "/文本"); return(strongResponseMessage); } else { var rsp = handler.CreateResponseMessage <ResponseMessageNews>(); ArticleRes ares = res as ArticleRes; var items = ares.Items; string domain = WebCtx.Current.Domain; foreach (var item in items) { if (item.Enabled) { rsp.Articles.Add(new Article() { Title = item.Title, Description = item.Description ?? "", PicUrl = domain + "/" + item.Pic, Url = item.Url.StartsWith("http://")?item.Url:domain + item.Url }); } } Config.Logln("素材" + resKey + "/图文"); return(rsp); } }
public int Save(IWxRes res) { TextRes textRes = res as TextRes; if (textRes != null) { return SaveTextRes(textRes); } else { ArticleRes artRes = res as ArticleRes; return this.SaveArticleRes(artRes); } }
public IWxRes GetResByKey(string resKey) { IWxRes res = null; DataBaseAccess db = this._dao.New(); db.ExecuteReader(new SqlQuery("SELECT Id ,ResKey,TypeId,TypeName,CreateTime,UpdateTime FROM wx_res WHERE ResKey=@ResKey", new object[, ] { { "@ResKey", resKey } }), rd => { if (rd.Read()) { int typeId = rd.GetInt32(2); if (typeId == 1) { res = new TextRes { CreateTime = rd.GetDateTime(4), UpdateTime = rd.GetDateTime(5), TypeId = typeId, TypeName = rd.GetString(3), ResKey = rd.GetString(1), Id = rd.GetInt32(0) }; } else { res = new ArticleRes { CreateTime = rd.GetDateTime(4), UpdateTime = rd.GetDateTime(5), TypeId = typeId, ResKey = rd.GetString(1), TypeName = rd.GetString(3), Id = rd.GetInt32(0) }; } } }); if (res != null) { TextRes tRes; ArticleRes atRes; if ((tRes = (res as TextRes)) != null) { db.ExecuteReader("SELECT Content FROM wx_text Where resid=" + tRes.Id.ToString(), rd => { if (rd.Read()) { tRes.Content = rd.GetString(0); } }); } else { atRes = res as ArticleRes; db.ExecuteReader("SELECT * FROM wx_art_item WHERE resid=" + atRes.Id.ToString() + " ORDER BY sort,id", rd => { if (rd.HasRows) { atRes.Items = rd.ToEntityList <ArticleResItem>(); } }); if (atRes.Items != null) { foreach (var articleResItem in atRes.Items) { articleResItem.SetArticle(atRes); } } else { atRes.Items = new List <ArticleResItem>(); } } } return(res); }