/** * EC_SeckillInfoDAL.cs * * 功 能: 特价信息数据访问实现 * 类 名: EC_SeckillInfoDAL * * Ver 变更日期 负责人 变更内容 * ─────────────────────────────────── * V0.01 2013-4-12 9:23 吴崎均 更改InsertModel以及UpdateModel以与存储相匹配 * V0.02 吴崎均 新增分页实现、获取单个实体实现 * V0.03 2013-4-18 16:00 吴崎均 新增批量删除 * V0.04 2013-5-3 10:15 吴崎均 变更字典表关联数据为DicType + MeanValue * V0.05 2013-5-14 11:53 吴崎均 改变分页方法,增加创建时间范围查询条件 * V0.06 2013-5-28 13:43 吴崎均 修改批量删除方法定义及实现 * V0.07 2013-6-2 10:42 吴崎均 增加修改状态方法 * * * * * * */ using System; using System.Collections.Generic; using System.Linq; using System.Text; using CY.IDAL; using System.Data.SqlClient; using System.Data; using CY.Model; using CY.Infrastructure.Query; namespace CY.SQLDAL { /// /// 特价信息数据访问实现 /// public class EC_SeckillInfoDAL : IEC_SeckillInfoDAL { private Database _dataBase = null; #region 常量 /// /// 查询目标 /// const string SELECTTARGET = @" s.*,p.PrintName as PrintTypeName,d_state.Name as StateName,m.Name as SellerName,acd.LevelIcon as LevelIcon"; /// /// 查询来源 /// const string FROMSOUCEBEFORE = " EC_SeckillInfo as s Inner Join EC_MemberBasic as m On(s.SellerId=m.MemberId "; const string FROMSOUCEEND = " ) " + "left join SysInquiry_PrintingType as p On(s.PrintTypeId=p.Keyid) " + "left join Integrity_IntegrityCard acd On (s.SellerId=acd.MemberId ) " + "left join Integrity_CreditLevelRule bcd on acd.RuleId = bcd.RuleId " + "Left Join Sys_Dictionary as d_state On(d_state.DicType='特价信息状态' And s.[State]=d_state.MeanValue) where bcd.RuleType ='True' " + " "; /// /// 分页默认排序字段 /// const string ORDERBY = "s.Keyid desc"; #endregion public EC_SeckillInfoDAL() { _dataBase = new Database(); } /// /// 新增 /// /// /// public bool InserModel(Infrastructure.Domain.IAggregateRoot model) { Model.EC_SeckillInfo trueModel = model as Model.EC_SeckillInfo; trueModel.State = 0; if (trueModel == null) { return false; } else { } IList sqlParms = new List() { new SqlParameter("@SellerId",trueModel.SellerId), new SqlParameter("@BusinessInfoName",trueModel.BusinessInfoName), new SqlParameter("@PrintTypeId",trueModel.PrintTypeId), new SqlParameter("@BusinessContent",trueModel.BusinessContent), new SqlParameter("@Contacts",trueModel.Contacts), new SqlParameter("@ContactPhone",trueModel.ContactPhone), new SqlParameter("@QQ",trueModel.QQ), new SqlParameter("@EndTime",trueModel.EndTime), new SqlParameter("@State",trueModel.State), new SqlParameter("@Operator",trueModel.Operator), new SqlParameter("@Remark",trueModel.Remark) }; try { _dataBase.Query("sp_EC_SeckillInfo_Insert", CommandType.StoredProcedure, sqlParms.ToArray()); } catch (Exception ex) { throw ex; } return true; } /// /// 修改 /// /// /// public bool UpdateModel(Infrastructure.Domain.IAggregateRoot model) { Model.EC_SeckillInfo trueModel = model as Model.EC_SeckillInfo; if (trueModel == null) { return false; } else { } IList sqlParms = new List() {new SqlParameter("@Keyid",trueModel.Keyid), new SqlParameter("@SellerId",trueModel.SellerId), new SqlParameter("@BusinessInfoName",trueModel.BusinessInfoName), new SqlParameter("@PrintTypeId",trueModel.PrintTypeId), new SqlParameter("@BusinessContent",trueModel.BusinessContent), new SqlParameter("@Contacts",trueModel.Contacts), new SqlParameter("@ContactPhone",trueModel.ContactPhone), new SqlParameter("@QQ",trueModel.QQ), new SqlParameter("@EndTime",trueModel.EndTime), new SqlParameter("@State",trueModel.State), new SqlParameter("@Operator",trueModel.Operator), new SqlParameter("@Remark",trueModel.Remark) }; try { _dataBase.Query("sp_EC_SeckillInfo_Update", CommandType.StoredProcedure, sqlParms.ToArray()); } catch (Exception ex) { throw ex; } return true; } /// /// 删除 /// /// /// public bool DeleteModel(Infrastructure.Domain.IAggregateRoot model) { Model.EC_SeckillInfo trueModel = model as Model.EC_SeckillInfo; if (trueModel == null) { return false; } else { } IList sqlParms = new List() { new SqlParameter("@Keyid",trueModel.Keyid) }; try { _dataBase.Query("sp_EC_SeckillInfo_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; else { } //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); } /// /// 分页查询(根据联系人和结束状态) /// /// 分页对象 /// 联系人 /// 是否结束(0为未结束 1为已结束 -1为不限) /// 创建开始时间 /// 创建结束时间 /// 查询结果 传入参数错误时结果为空 public IEnumerable SelectModelPage(Infrastructure.Query.Pagination pagination, string contacts, int isEnd, DateTime? beginCreate, DateTime? endCreate) { if (null == pagination) return null; else { } string condition = ""; if (!string.IsNullOrEmpty(contacts)) { condition += string.Format(" And s.BusinessInfoName Like '%{0}%'", contacts); } if (-1 != isEnd) { condition += isEnd == 0 ? " And s.EndTime > Getdate() And s.State=0 " : " And ( s.EndTime < Getdate() Or s.State<>0 ) "; // 0为未结束 1为已结束 -1为不限 } if (beginCreate.HasValue) { condition += string.Format(" And s.CreateTime >= '{0}' ", beginCreate.Value.ToString("yyyy-MM-dd")); } if (endCreate.HasValue) { condition += string.Format(" And s.CreateTime <= '{0}' ", endCreate.Value.ToString("yyyy-MM-dd")); } Query query = new Query(true); query.Criteria.Add(new Criterion("condition", condition)); //query.Criteria.Add(new Criterion("orderBy", "s.Keyid desc,CreateTime desc")); return SelectModelPage(query, pagination); } /// /// 分页查询(根据联系人和结束状态) /// /// 分页对象 /// 联系人 /// 是否结束(0为未结束 1为已结束 -1为不限) /// 创建开始时间 /// 创建结束时间 /// 会员编号 /// 查询结果 传入参数错误时结果为空 public IEnumerable SelectModelPage(Infrastructure.Query.Pagination pagination, string contacts, int isEnd, DateTime? beginCreate, DateTime? endCreate, Guid MemberId) { if (null == pagination) return null; else { } string condition = ""; if (!string.IsNullOrEmpty(contacts)) { condition += string.Format(" And s.BusinessInfoName Like '%{0}%'", contacts); ; } if (-1 != isEnd) { condition += isEnd == 0 ? " And s.EndTime > Getdate() And s.State=0 " : " And ( s.EndTime < Getdate() Or s.State<>0 ) "; // 0为未结束 1为已结束 -1为不限 } if (beginCreate.HasValue) { condition += string.Format(" And s.CreateTime >= '{0}' ", beginCreate.Value.ToString("yyyy-MM-dd")); } if (endCreate.HasValue) { condition += string.Format(" And s.CreateTime <= '{0}' ", endCreate.Value.ToString("yyyy-MM-dd")); } if (MemberId != Guid.Empty && MemberId != null) { condition += string.Format(" And m.MemberId = '{0}' ", MemberId); } Query query = new Query(true); query.Criteria.Add(new Criterion("condition", condition)); //query.Criteria.Add(new Criterion("orderBy", "s.Keyid desc,CreateTime desc")); return SelectModelPage(query, pagination); } /// /// 单个查询 /// /// /// public IEnumerable SelectAllModel(Infrastructure.Query.Query query) { throw new NotImplementedException(); } /// /// 根据编号获取实体信息 /// /// 主键编号 /// public EC_SeckillInfo SelectModleById(int id) { if (id < 1) return null;//错误数据返会空 else { } IList result = _dataBase.SelectModel(SELECTTARGET, string.Format("{0}{1}{2}{3}", FROMSOUCEBEFORE, " And Keyid=", id, FROMSOUCEEND)); return null == result || result.Count == 0 ? null : result[0];//返回结果 //IDataReader reader = _dataBase.QueryDataReader("sp_EC_SeckillInfo_SelectRow", CommandType.StoredProcedure, new SqlParameter() { ParameterName = "@keyid", Value = id }); //List result = Database.ReadDataToModelAndDispose(reader); //return null == result || result.Count == 0 ? null : result[0]; } /// /// 根据编号批量删除数据 /// /// 当前操作人 /// 编号集合 /// public bool DeleteDataByIds(string currentOperator, params int[] ids) { return Database.DeleteDataByIds(this, currentOperator, ids); } /// /// 改变特价信息状态 /// /// 数据编号 /// 状态 /// public bool ChangeState(int id, int state) { IList sqlParms = new List() { new SqlParameter("@Keyid",id), new SqlParameter("@State",state) }; try { _dataBase.Query("sp_EC_SeckillInfo_ChangeState", CommandType.StoredProcedure, sqlParms.ToArray()); } catch (Exception ex) { throw ex; } return true; } } }