www.pudn.com > MyShop.rar > Channel.cs


using System; 
using System.Collections.Generic; 
using System.Data; 
 
 
using MyShop.DALFactory; 
using MyShop.IDAL; 
using MyShop.Model; 
 
 
namespace MyShop.BLL 
{ 
    public class Channel 
    { 
        private IChannel dal = DataAccess.CreateChannel(); 
 
        #region  IChannel 
 
        public int Add(ChannelInfo model) 
        { 
            if (model == null) 
            { 
                return 0; 
            } 
            return dal.Add(model); 
        } 
 
        public int Delete(string filter) 
        { 
            if (string.IsNullOrEmpty(filter)) 
                return 0; 
            return dal.Delete(filter); 
        } 
 
        public bool Exist(string filter) 
        { 
            filter = filter.Trim(); 
            if (string.IsNullOrEmpty(filter)) 
                return false; 
            return dal.Exist(filter); 
        } 
        public DataSet GetDataSet() 
        { 
            return dal.GetDataSet(); 
        } 
 
        public DataSet GetDataSet(string filter) 
        { 
            filter = filter.Trim(); 
            if (string.IsNullOrEmpty(filter)) 
                return null; 
            return dal.GetDataSet(filter); 
        } 
 
        public ChannelInfo GetModel(DataRow dr) 
        { 
            if (dr == null) 
                return null; 
            return dal.GetModel(dr); 
        } 
 
        private DataSet Query(string sql) 
        { 
            sql = sql.Trim(); 
            if (string.IsNullOrEmpty(sql)) 
                return null; 
            return dal.Query(sql); 
        } 
 
        public int Update(ChannelInfo model, string filter) 
        { 
            if (model == null) 
                return 0; 
            filter = filter.Trim(); 
            if (string.IsNullOrEmpty(filter)) 
                return 0; 
            return dal.Update(model, filter); 
        } 
 
        #endregion 
 
        #region common 
 
        public int Add(ChannelInfo model, out string msg) 
        { 
            msg = ""; 
            if (model == null) 
            { 
                msg = msg + "
  • 数据不能为空
  • "; return 0; } bool isErr = false; if (isErr) return 0; int count = 0; count = Add(model); if (count == 0) msg = "
  • 系统发生错误,请重新添加!
  • "; if (count == 1) msg = "
  • 添加成功!
  • "; return count; } public int Delete(int channelId) { if (string.IsNullOrEmpty(channelId.ToString())) return 0; string filer; filer = " channelId =" + channelId; return Delete(filer); } public int Update(ChannelInfo model) { if (model == null) { return 0; } string filter; filter = " channelId=" + model.ChannelID; return Update(model, filter); } public ChannelInfo GetModel(int channelId) { DataSet dataset = new DataSet(); dataset = GetDataSet(" channelId=" + channelId); if (dataset != null && dataset.Tables[0].Rows.Count > 0) return GetModel(dataset.Tables[0].Rows[0]); return null; } /// /// 系统商品频道 /// /// public ChannelInfo GetShopModel() { DataSet dataset = new DataSet(); dataset = GetDataSet(" [channelID] = 2 "); if (dataset != null && dataset.Tables[0].Rows.Count > 0) return GetModel(dataset.Tables[0].Rows[0]); return null; } /// /// 系统文章频道 /// /// public ChannelInfo GetArticlepModel() { DataSet dataset = new DataSet(); dataset = GetDataSet(" [channelID] = 1 "); if (dataset != null && dataset.Tables[0].Rows.Count > 0) return GetModel(dataset.Tables[0].Rows[0]); return null; } /// /// 返回可用的频道 /// /// public DataSet GetDataSetChannelNav() { string filter = " [disabled] = 0 Order by OrderId "; return GetDataSet(filter); } #endregion #region 后台管理 public DataSet GetDataSetOrderByOrderId() { return GetDataSet(" [channelId] > 0 Order by OrderId "); } /// /// 启用或禁用 /// /// /// public int Enable(int channelId,bool action) { ChannelInfo model = new ChannelInfo(); model = GetModel(channelId); if (model == null) return 0; model.Disabled = action? 0 :1; return Update(model); } /// /// 频道是否存在 /// /// /// public bool IsExist(string channelName) { channelName = channelName.Trim(); if (Utils.ChkBadChar(channelName)) return false; if (Exist(" [channelName] = '" + Utils.ReplaceBadSQL(channelName.Trim()) + "' ")) { return true; } else return false; } #endregion } }