using System; using System.Data; using System.Collections.Generic; namespace CallCenterApi.BLL { /// /// 文章内容 /// public partial class article { //private readonly Model.sysconfig sysConfig = new BLL.sysconfig().loadConfig();//获得系统配置信息 private readonly CallCenterApi.DAL.article dal; public article() { dal = new CallCenterApi.DAL.article(); } #region 基本方法================================ /// /// 是否存在该记录 /// public bool Exists(int channel_id, int article_id) { //string channelName = new BLL.site_channel().GetChannelName(channel_id);//查询频道名称 //if (string.IsNullOrEmpty(channelName)) //{ // return false; //} return dal.Exists(article_id); } /// /// 是否存在该记录 /// public bool Exists(string call_index) { if (string.IsNullOrEmpty(call_index)) { return false; } //string channelName = new BLL.site_channel().GetChannelName(channel_id);//查询频道名称 //if (string.IsNullOrEmpty(channelName)) //{ // return false; //} return dal.Exists(call_index); } /// /// 增加一条数据 /// public int Add(Model.article model) { return dal.Add(model); } /// /// 更新一条数据 /// public bool Update(Model.article model) { return dal.Update(model); } /// /// 删除一条数据 /// public bool Delete(int article_id) { //string channelName = new BLL.site_channel().GetChannelName(channel_id);//查询频道名称 //if (string.IsNullOrEmpty(channelName)) //{ // return false; //} string content = dal.GetContent(article_id);//获取信息内容 bool result = dal.Delete(article_id);//删除内容 //if (result && !string.IsNullOrEmpty(content)) //{ // FileHelper.DeleteContentPic(content, sysConfig.webpath + sysConfig.filepath); //删除内容图片 //} return result; } /// /// 删除一条数据 /// public bool DeleteBatch(string where) { bool result = dal.DeleteBatch(where);//删除内容 return result; } /// /// 得到一个对象实体 /// public Model.article GetModel(int article_id) { //string channelName = new BLL.site_channel().GetChannelName(channel_id);//查询频道名称 //if (string.IsNullOrEmpty(channelName)) //{ // return null; //} return dal.GetModel(article_id); } /// /// 得到一个对象实体 /// public Model.article GetModel(string call_index) { //string channelName = new BLL.site_channel().GetChannelName(channel_id);//查询频道名称 //if (string.IsNullOrEmpty(channelName)) //{ // return null; //} return dal.GetModel(call_index); } public List DataTableToList(DataTable dt) { List list = new List(); int rowsCount = dt.Rows.Count; if (rowsCount > 0) { CallCenterApi.Model.article model; for (int n = 0; n < rowsCount; n++) { model = new CallCenterApi.Model.article(); if (dt.Rows[n]["id"] != null && dt.Rows[n]["id"].ToString() != "") { model.id = int.Parse(dt.Rows[n]["id"].ToString()); } if (dt.Rows[n]["category_id"] != null && dt.Rows[n]["category_id"].ToString() != "") { model.category_id = Convert.ToInt32(dt.Rows[n]["category_id"]); } //if (dt.Rows[n]["trade_no"] != null && dt.Rows[n]["trade_no"].ToString() != "") //{ // model.trade_no = dt.Rows[n]["trade_no"].ToString(); //} if (dt.Rows[n]["title"] != DBNull.Value && dt.Rows[n]["title"].ToString() != "") { model.title = dt.Rows[n]["title"].ToString(); } if (dt.Rows[n]["img_url"] != null && dt.Rows[n]["img_url"].ToString() != "") { model.img_url = dt.Rows[n]["img_url"].ToString(); } if (dt.Rows[n]["zhaiyao"] != null && dt.Rows[n]["zhaiyao"].ToString() != "") { model.zhaiyao = dt.Rows[n]["zhaiyao"].ToString(); } if (dt.Rows[n]["content"] != null && dt.Rows[n]["content"].ToString() != "") { model.content = dt.Rows[n]["content"].ToString(); } if (dt.Rows[n]["sort_id"] != null && dt.Rows[n]["sort_id"].ToString() != "") { model.sort_id = Convert.ToInt32(dt.Rows[n]["sort_id"]); } if (dt.Rows[n]["status"] != null && dt.Rows[n]["status"].ToString() != "") { model.status = Convert.ToInt32(dt.Rows[n]["status"]); } if (dt.Rows[n]["add_time"] != null && dt.Rows[n]["add_time"].ToString() != "") { model.add_time = Convert.ToDateTime(dt.Rows[n]["add_time"]); } if (dt.Rows[n]["update_time"] != DBNull.Value && dt.Rows[n]["update_time"].ToString() != "") { model.update_time = Convert.ToDateTime(dt.Rows[n]["update_time"]); } else { model.update_time = null; } if (dt.Rows[n]["sell_price"] != DBNull.Value && dt.Rows[n]["sell_price"].ToString() != "") { model.sell_price = decimal.Parse(dt.Rows[n]["sell_price"].ToString()); } else { model.sell_price = null; } if (dt.Rows[n]["goods_no"] != null && dt.Rows[n]["goods_no"].ToString() != "") { model.goods_no = dt.Rows[n]["goods_no"].ToString(); } if (dt.Rows[n]["department"] != null && dt.Rows[n]["department"].ToString() != "") { model.department = Convert.ToInt32(dt.Rows[n]["department"]); } if (dt.Rows[n]["categorytitle"] != null && dt.Rows[n]["categorytitle"].ToString() != "") { model.categorytitle = dt.Rows[n]["categorytitle"].ToString(); } list.Add(model); } } return list; } #endregion #region 扩展方法================================ /// /// 是否存在标题 /// public bool ExistsTitle(int channel_id, string title) { return dal.ExistsTitle(title); } /// /// 是否存在标题 /// public bool ExistsTitle(int channel_id, int category_id, string title) { return dal.ExistsTitle(category_id, title); } /// /// 返回信息标题 /// public string GetTitle(int channel_id, int article_id) { return dal.GetTitle(article_id); } /// /// 返回信息内容 /// public string GetContent(string channel_name, int article_id) { return dal.GetContent(article_id); } /// /// 返回信息内容 /// public string GetContent(string channel_name, string call_index) { return dal.GetContent(call_index); } /// /// 返回信息封面图 /// public string GetImgUrl(int channel_id, int article_id) { return dal.GetImgUrl(article_id); } /// /// 获取阅读次数 /// public int GetClick(int channel_id, int article_id) { return dal.GetClick(article_id); } /// /// 返回数据总数 /// public int GetCount(int channel_id, string strWhere) { return dal.GetCount(strWhere); } /// /// 返回商品库存数量 /// public int GetStockQuantity(int channel_id, int article_id) { return dal.GetStockQuantity(article_id); } /// /// 修改一列数据 /// public bool UpdateField(int channel_id, int article_id, string strValue) { return dal.UpdateField(article_id, strValue); } /// /// 获取微信推送实体 /// public Model.article GetWXModel(int channel_id, int article_id) { DataTable dt = dal.GetList(1, "id=" + article_id, "id desc").Tables[0]; if (dt.Rows.Count == 0) { return null; } Model.article model = new Model.article(); model.id = int.Parse(dt.Rows[0]["id"].ToString()); model.title = dt.Rows[0]["title"].ToString(); model.img_url = dt.Rows[0]["img_url"].ToString(); model.zhaiyao = dt.Rows[0]["zhaiyao"].ToString(); model.content = dt.Rows[0]["content"].ToString(); return model; } #endregion } }