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


using System; 
using System.Collections.Generic; 
 
using System.Data; 
 
 
using MyShop.DALFactory; 
using MyShop.IDAL; 
using MyShop.Model; 
 
namespace MyShop.BLL 
{ 
    public class GuestBook 
    { 
        private IGuestBook dal = DataAccess.CreateGuestBook(); 
 
        public GuestBook() { } 
 
        #region IGuestBook 
 
        public int Add(GuestBookInfo 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 GuestBookInfo 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(GuestBookInfo 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(GuestBookInfo 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 GuestId) { if (string.IsNullOrEmpty(GuestId.ToString())) return 0; string filer; filer = " GuestId =" + GuestId; return Delete(filer); } public int Update(GuestBookInfo model) { if (model == null) { return 0; } string filter; filter = "GuestId=" + model.GuestId; return Update(model, filter); } public GuestBookInfo GetModel(int GuestId) { DataSet dataset = new DataSet(); dataset = GetDataSet(" GuestId=" + GuestId); if (dataset.Tables[0].Rows.Count > 0) return GetModel(dataset.Tables[0].Rows[0]); return null; } #endregion /// /// 得到通过审核的列表 /// /// public DataSet GetPassedList() { return dal.GetPassedList(); } #region 后台管理 public DataSet GetDataSetOrderById() { return GetDataSet(" [GuestId] > 0 Order by [GuestId] Desc "); } /// /// 判断该留言是不是审核通过 /// /// /// 无该文章时返回false public bool Pass(int guestId) { GuestBookInfo model = new GuestBookInfo(); model = GetModel(guestId); if (model == null) return false; if (model.IsPassed == 1) return true; else return false; } /// /// 取消或设置该文章审核状态 /// /// /// true 为审核通过 false为审核未通过 /// public int Pass(int guestId, bool action) { GuestBookInfo model = new GuestBookInfo(); model = GetModel(guestId); if (model == null) return 0; if (action) { model.IsPassed = 1; } else { model.IsPassed = 0; } return Update(model); } /// /// 快速搜索 /// /// /// public DataSet QuickSearch(int searchType) { return dal.QuickSearch(searchType); } /// /// 高级查询 /// /// /// /// public DataSet KeywordsSearch(string field, string keywords) { field = Utils.ReplaceBadSQL(field.Trim().ToLower()); keywords = Utils.ReplaceBadSQL(keywords.ToLower().Trim()); if (string.IsNullOrEmpty(field) || string.IsNullOrEmpty(keywords)) return null; return dal.KeywordsSearch(field, keywords); } #endregion } }