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


using System; 
using System.Collections; 
using System.Data; 
 
 
using MyShop.DALFactory; 
using MyShop.IDAL; 
using MyShop.Model; 
 
namespace MyShop.BLL 
{ 
    public class PaymentType 
    { 
        private IPaymentType dal = DataAccess.CreatePaymentType(); 
 
        public PaymentType() { } 
 
        #region IPaymentType 
 
        public int Add(PaymentTypeInfo 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 PaymentTypeInfo 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(PaymentTypeInfo 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(PaymentTypeInfo model, out string msg) 
        { 
            msg = ""; 
            if (model == null) 
            { 
                msg = msg + "
  • 数据不能为空
  • "; return 0; } bool isErr = false; if (string.IsNullOrEmpty(model.typeName.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 typeId) { if ( string.IsNullOrEmpty( typeId.ToString()) ) return 0; string filer; filer = " typeId =" + typeId; return Delete(filer); } public int Update(PaymentTypeInfo model) { if (model == null) { return 0; } string filter; filter = " typeId=" + model.typeId; return Update(model, filter); } public PaymentTypeInfo GetModel(int typeId) { DataSet dataset = new DataSet(); dataset = GetDataSet(" typeId=" + typeId); if (dataset != null && dataset.Tables[0].Rows.Count > 0) return GetModel(dataset.Tables[0].Rows[0]); return null; } public PaymentTypeInfo GetModel(string typeName) { if (string.IsNullOrEmpty(typeName)) return null; DataSet dataset = new DataSet(); dataset = GetDataSet(" typeName='" + typeName + "'"); if (dataset != null && dataset.Tables[0].Rows.Count > 0) return GetModel(dataset.Tables[0].Rows[0]); return null; } #endregion #region 后台管理 public DataSet GetDataSetOrderByOrderId() { return GetDataSet(" typeId > 0 Order by OrderId "); } /// /// 把为typeId的记录改为默认,同时将其它记录改为不是默认 /// /// /// public int MakeDefault(int typeId) { string filter = " [Isdefault] = 1 "; DataSet dataset = new DataSet(); PaymentTypeInfo model = new PaymentTypeInfo(); dataset = GetDataSet(filter); //把其它的改为不是默认 if (dataset.Tables[0].Rows.Count > 0) { for (int i = 0; i < dataset.Tables[0].Rows.Count; i++) { model = GetModel(dataset.Tables[0].Rows[i]); model.isDefault = 0; Update(model); } } model = GetModel(typeId); model.isDefault = 1; return Update(model); } /// /// 检查付款方式名称是否存在 /// /// /// public bool IsExist(string typeName) { typeName = Utils.ReplaceBadSQL(typeName.Trim()); if (string.IsNullOrEmpty(typeName)) return false; string filter = " typeName='" + typeName + "'"; return Exist(filter); } #endregion } }