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


using System.Data; 
 
 
using MyShop.DALFactory; 
using MyShop.IDAL; 
using MyShop.Model; 
 
namespace MyShop.BLL 
{ 
    public class ProductKinds 
    { 
        private IProductKinds dal = DataAccess.CreateProductKinds(); 
        private int _id; 
        public ProductKinds() 
        { 
        } 
 
        public ProductKinds(int id) 
        { 
            this._id = id; 
 
        } 
 
        #region ICategory member 
 
       public int Add(ProductKindsInfo 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 DataSet GetDataSet(int ProductKindId) 
        { 
            if (ProductKindId <= 0) 
                return null; 
            string filter = " ProductKindId=" + ProductKindId; 
            return GetDataSet(filter); 
        } 
 
 
        public DataSet GetDataSetEnabledOrderByOrderId() 
        { 
            string filter = " [IsDisabled] = 0   Order by  OrderId  "; 
            return GetDataSet(filter); 
        } 
 
        public ProductKindsInfo 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); 
        } 
 
        protected int Update(ProductKindsInfo 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(ProductKindsInfo model, out string msg) 
        { 
            msg = ""; 
            if (model == null) 
            { 
                msg = msg + "
  • 数据不能为空
  • "; return 0; } bool isErr = false; if (string.IsNullOrEmpty(model.ProductKindName.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 ProductKindId) { if (string.IsNullOrEmpty(ProductKindId.ToString())) return 0; string filer; filer = " ProductKindId =" + ProductKindId; return Delete(filer); } public int Update(ProductKindsInfo model) { if (model == null) { return 0; } string filter; filter = " ProductKindId=" + model.ProductKindId; return Update(model, filter); } public ProductKindsInfo GetModel(int ProductKindId) { DataSet dataset = new DataSet(); dataset = GetDataSet(" ProductKindId=" + ProductKindId); if (dataset != null && dataset.Tables[0].Rows.Count > 0) return GetModel(dataset.Tables[0].Rows[0]); return null; } #endregion #region 以下过程要用ProductKinds product = new ProductKinds(id)实例化后才能进行调用 #region property /// /// 获取当前项目ID /// public int ID { get { return this._id; } } /// /// 获取调查项目的实体 /// public ProductKindsInfo Model { get { return GetModel(this._id); } set { Update(value); } } /// /// 获取当前对象是否存在(数据库中有没有这条记录) /// public bool isExist { get { return Model == null ? false : true; } } #endregion #endregion #region 后台管理 public DataSet GetDataSetOrderByOrderId() { return GetDataSet(" productKindId > 0 Order by OrderId "); } /// /// 检查名称是否存在 /// /// /// public bool IsExist(string productKindName) { productKindName = Utils.ReplaceBadSQL(productKindName.Trim()); if (string.IsNullOrEmpty(productKindName)) return false; string filter = " productKindName='" + productKindName + "'"; return Exist(filter); } #endregion } }