using System; using System.Collections.Generic; using System.Linq; using System.Text; using CY.IDAL; using System.Data.SqlClient; using System.Data; using CY.Infrastructure.DESEncrypt; using CY.Infrastructure.Common; using CY.Infrastructure.Query; using CY.Model; namespace CY.SQLDAL { public class Pay_CreditLineLevelRuleDAL : IPay_CreditLineLevelRuleDAL { private Database _dataBase = null; #region 常量 /// /// 查询目标 /// const string SELECTTARGET = " t.* "; /// /// 查询来源 /// const string FROMSOUCEBEFORE = " (select a.Keyid,a.LevelName,a.LevelIcon,a.MaxScore,a.NextLevelRule,a.Credit,a.RebateProportion,a.LastUpdateTime,a.Operator,a.Remark,b.LevelName as LastName from [Pay_CreditLineLevelRule] a left join [Pay_CreditLineLevelRule] b on a.NextLevelRule=b.Keyid Where 0=0 "; const string FROMSOUCEEND = ") as t "; /// /// 分页默认排序字段 /// const string ORDERBY = " Keyid "; #endregion public Pay_CreditLineLevelRuleDAL() { _dataBase = new Database(); } /// /// 新增 /// /// /// public bool InserModel(Infrastructure.Domain.IAggregateRoot model) { Model.Pay_CreditLineLevelRule trueModel = model as Model.Pay_CreditLineLevelRule; if (trueModel == null) { return false; } IList sqlParms = new List() { new SqlParameter("@LevelName",trueModel.LevelName), new SqlParameter("@LevelIcon",trueModel.LevelIcon), new SqlParameter("@MaxScore",trueModel.MaxScore), new SqlParameter("@NextLevelRule",trueModel.NextLevelRule), new SqlParameter("@Credit",trueModel.Credit), new SqlParameter("@RebateProportion",trueModel.RebateProportion), new SqlParameter("@LastUpdateTime",trueModel.LastUpdateTime), new SqlParameter("@Operator",trueModel.Operator), new SqlParameter("@Remark",trueModel.Remark) }; try { _dataBase.Query("sp_Pay_CreditLineLevelRule_Insert", CommandType.StoredProcedure, sqlParms.ToArray()); } catch (Exception ex) { throw ex; } return true; } /// /// 修改 /// /// /// public bool UpdateModel(Infrastructure.Domain.IAggregateRoot model) { Model.Pay_CreditLineLevelRule trueModel = model as Model.Pay_CreditLineLevelRule; if (trueModel == null) { return false; } IList sqlParms = new List() {new SqlParameter("@Keyid",trueModel.Keyid), new SqlParameter("@LevelName",trueModel.LevelName), new SqlParameter("@LevelIcon",trueModel.LevelIcon), new SqlParameter("@MaxScore",trueModel.MaxScore), new SqlParameter("@NextLevelRule",trueModel.NextLevelRule), new SqlParameter("@Credit",trueModel.Credit), new SqlParameter("@RebateProportion",trueModel.RebateProportion), new SqlParameter("@LastUpdateTime",trueModel.LastUpdateTime), new SqlParameter("@Operator",trueModel.Operator), new SqlParameter("@Remark",trueModel.Remark) }; try { _dataBase.Query("sp_Pay_CreditLineLevelRule_Update", CommandType.StoredProcedure, sqlParms.ToArray()); } catch (Exception ex) { throw ex; } return true; } /// /// 删除 /// /// /// public bool DeleteModel(Infrastructure.Domain.IAggregateRoot model) { Model.Pay_CreditLineLevelRule trueModel = model as Model.Pay_CreditLineLevelRule; if (trueModel == null) { return false; } IList sqlParms = new List() { new SqlParameter("@Keyid",trueModel.Keyid) }; try { _dataBase.Query("sp_Pay_CreditLineLevelRule_DeleteRow", CommandType.StoredProcedure, sqlParms.ToArray()); } catch (Exception ex) { throw ex; } return true; } /// /// 分页查询 /// /// /// /// public IEnumerable SelectModelPage(Infrastructure.Query.Query query, Infrastructure.Query.Pagination pagination) { if (null == pagination || null == query || null == query.Criteria || 1 > query.Criteria.Count) return null; //query.Criteria 首个元素必须是排序字段,其值为结果排序字段 int maxParamIndex = query.Criteria.Count - 1;//最大索引 string[] orderbys = new string[] { ORDERBY }; string resultOrderBy = "";//结果集排序方式 if ("@orderBy".Equals(query.Criteria[maxParamIndex].PropertyName)) { orderbys = string.Format("{0}", query.Criteria[maxParamIndex].Value).Split(','); resultOrderBy = 1 == orderbys.Length ? resultOrderBy : orderbys[1]; } string fromSouce = string.Format("{0}{1}{2}", FROMSOUCEBEFORE, query.Criteria[0].Value, FROMSOUCEEND);//拼装条件 return _dataBase.SelectModelPage(pagination, SELECTTARGET, fromSouce, orderbys[0], resultOrderBy); } /// /// 全部查询 /// /// /// public IEnumerable SelectAllModel(Infrastructure.Query.Query query) { return _dataBase.SelectModel(" * ", " Pay_CreditLineLevelRule ") as IList;//执行查询 } /// /// 单个查询 /// /// 编号 /// public Model.Pay_CreditLineLevelRule SelectModelByKeyid(int? Keyid) { if (Keyid == null || Keyid <= 0) return null;//错误数据返会空 IList result = _dataBase.SelectModel("*", "Pay_CreditLineLevelRule", string.Format(" Keyid={0}", Keyid)) as IList;//执行查询 return (null == result || result.Count ==0) ? null : result[0];//返回结果 } } }