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


using System; 
using System.Collections.Generic; 
 
using System.Data; 
 
 
using MyShop.DALFactory; 
using MyShop.IDAL; 
using MyShop.Model; 
 
namespace MyShop.BLL 
{ 
    public class Producer 
    { 
        private IProducer dal = DataAccess.CreateProducer(); 
 
        #region  IProducer 
 
        public int Add(ProducerInfo 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 ProducerInfo 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(ProducerInfo 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(ProducerInfo model, out string msg) 
        { 
            msg = ""; 
            if (model == null) 
            { 
                msg = msg + "
  • 数据不能为空
  • "; return 0; } bool isErr = false; if (string.IsNullOrEmpty(model.producerName.Trim())) { msg = msg + "
  • 提供商名称不能为空
  • "; isErr = true; } if (string.IsNullOrEmpty(model.address.Trim())) { msg = msg + "
  • 地址不能为空
  • "; isErr = true; } if (isErr) return 0; int count = 0; count = Add(model); if (count == 0) msg = "
  • 系统发生错误,请重新添加!
  • "; if (count == 1) msg = "
  • 添加成功!
  • "; return count; } public int Delete(int producerId) { if (string.IsNullOrEmpty(producerId.ToString())) return 0; string filer; filer = " producerId =" + producerId; return Delete(filer); } public int Update(ProducerInfo model) { if (model == null) { return 0; } string filter; filter = " producerId=" + model.producerId; return Update(model, filter); } public ProducerInfo GetModel(int producerId) { DataSet dataset = new DataSet(); dataset = GetDataSet(" producerId=" + producerId); if (dataset != null && dataset.Tables[0].Rows.Count > 0) return GetModel(dataset.Tables[0].Rows[0]); return null; } #endregion #region 后台管理 /// /// 快速搜索 /// /// /// public DataSet QuickSearchByProducerType(int producerType) { DataSet ds = new DataSet(); string filter = " producerType=" + producerType; return GetDataSet(filter); } /// /// 高级查询 /// /// /// /// 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); } /// /// 返回所有已通过审核的厂商 /// /// public DataSet GetDataSetPassedProducerList() { return GetDataSet(" passed=1 "); } #endregion } }