/// <summary> /// 根据标识符获取实例 /// </summary> /// <param name="pID">标识符的值</param> public SMSCustomerEntity GetByID(object pID, object pSign) { //参数检查 if (pID == null && pSign == null) { return(null); } // string id = pID.ToString(); //组织SQL StringBuilder sql = new StringBuilder(); if (pID != null) { sql.AppendFormat("select * from [SMS_Customer] where SMS_CustomerID='{0}' and IsDelete=0 ", pID.ToString()); } else if (pSign != null) { sql.AppendFormat("select * from [SMS_Customer] where SMSCustomer_Sign='{0}' and IsDelete=0 ", pSign.ToString()); } //读取数据 SMSCustomerEntity m = null; using (SqlDataReader rdr = this.SQLHelper.ExecuteReader(sql.ToString())) { while (rdr.Read()) { this.Load(rdr, out m); break; } } //返回 return(m); }
/// <summary> /// 在事务内创建一个新实例 /// </summary> /// <param name="pEntity">实体实例</param> /// <param name="pTran">事务实例,可为null,如果为null,则不使用事务来更新</param> public void Create(SMSCustomerEntity pEntity, IDbTransaction pTran) { ////参数校验 //if (pEntity == null) // throw new ArgumentNullException("pEntity"); ////初始化固定字段 //pEntity.CreateTime = DateTime.Now; //pEntity.CreateBy = Convert.ToInt32(CurrentUserInfo.UserID); //pEntity.LastUpdateTime = pEntity.CreateTime; //pEntity.LastUpdateBy = Convert.ToInt32(CurrentUserInfo.UserID); //pEntity.IsDelete = 0; //StringBuilder strSql = new StringBuilder(); //strSql.Append("insert into [SMS_Customer]("); //strSql.Append("[Account],[Password],[IsDelete],[CreateTime],[CreateBy],[LastUpdateBy],[LastUpdateTime],[SMS_CustomerID])"); //strSql.Append(" values ("); //strSql.Append("@Account,@Password,@IsDelete,@CreateTime,@CreateBy,@LastUpdateBy,@LastUpdateTime,@SMSCustomerID)"); //Guid? pkGuid; //if (pEntity.SMSCustomerID == null) // pkGuid = Guid.NewGuid(); //else // pkGuid = pEntity.SMSCustomerID; //SqlParameter[] parameters = //{ // new SqlParameter("@Account",SqlDbType.NVarChar,100), // new SqlParameter("@Password",SqlDbType.NVarChar,100), // new SqlParameter("@IsDelete",SqlDbType.Int), // new SqlParameter("@CreateTime",SqlDbType.DateTime), // new SqlParameter("@CreateBy",SqlDbType.NVarChar,100), // new SqlParameter("@LastUpdateBy",SqlDbType.NVarChar,100), // new SqlParameter("@LastUpdateTime",SqlDbType.DateTime), // new SqlParameter("@SMSCustomerID",SqlDbType.NVarChar,100) //}; //parameters[0].Value = pEntity.Account; //parameters[1].Value = pEntity.Password; //parameters[2].Value = pEntity.IsDelete; //parameters[3].Value = pEntity.CreateTime; //parameters[4].Value = pEntity.CreateBy; //parameters[5].Value = pEntity.LastUpdateBy; //parameters[6].Value = pEntity.LastUpdateTime; //parameters[7].Value = pkGuid; ////执行并将结果回写 //int result; //if (pTran != null) // result = this.SQLHelper.ExecuteNonQuery((SqlTransaction)pTran, CommandType.Text, strSql.ToString(), parameters); //else // result = this.SQLHelper.ExecuteNonQuery(CommandType.Text, strSql.ToString(), parameters); //pEntity.SMS_CustomerID = pkGuid; }
/// <summary> /// 删除 /// </summary> /// <param name="pEntity">实体实例</param> /// <param name="pTran">事务实例,可为null,如果为null,则不使用事务来更新</param> public void Delete(SMSCustomerEntity pEntity, IDbTransaction pTran) { //参数校验 if (pEntity == null) { throw new ArgumentNullException("pEntity"); } if (!pEntity.SMSCustomerID.HasValue) { throw new ArgumentException("执行删除时,实体的主键属性值不能为null."); } //执行 this.Delete(pEntity.SMSCustomerID.Value, pTran); }
/// <summary> /// 装载实体 /// </summary> /// <param name="pReader">向前只读器</param> /// <param name="pInstance">实体实例</param> protected void Load(SqlDataReader pReader, out SMSCustomerEntity pInstance) { //将所有的数据从SqlDataReader中读取到Entity中 pInstance = new SMSCustomerEntity(); pInstance.PersistenceHandle = new PersistenceHandle(); pInstance.PersistenceHandle.Load(); if (pReader["SMS_CustomerID"] != DBNull.Value) { pInstance.SMSCustomerID = Convert.ToInt32(pReader["SMS_CustomerID"]); } if (pReader["Account"] != DBNull.Value) { pInstance.Account = Convert.ToString(pReader["Account"]); } if (pReader["Password"] != DBNull.Value) { pInstance.Password = Convert.ToString(pReader["Password"]); } if (pReader["IsDelete"] != DBNull.Value) { pInstance.IsDelete = Convert.ToInt32(pReader["IsDelete"]); } if (pReader["CreateTime"] != DBNull.Value) { pInstance.CreateTime = Convert.ToDateTime(pReader["CreateTime"]); } if (pReader["CreateBy"] != DBNull.Value) { pInstance.CreateBy = Convert.ToString(pReader["CreateBy"]); } if (pReader["LastUpdateBy"] != DBNull.Value) { pInstance.LastUpdateBy = Convert.ToString(pReader["LastUpdateBy"]); } if (pReader["LastUpdateTime"] != DBNull.Value) { pInstance.LastUpdateTime = Convert.ToDateTime(pReader["LastUpdateTime"]); } }
/// <summary> /// 更新 /// </summary> /// <param name="pEntity">实体实例</param> /// <param name="pTran">事务实例,可为null,如果为null,则不使用事务来更新</param> public void Update(SMSCustomerEntity pEntity, IDbTransaction pTran) { ////参数校验 //if (pEntity == null) // throw new ArgumentNullException("pEntity"); //if (!pEntity.SMSCustomerID.HasValue) //{ // throw new ArgumentException("执行更新时,实体的主键属性值不能为null."); //} ////初始化固定字段 //pEntity.LastUpdateTime = DateTime.Now; //pEntity.LastUpdateBy = Convert.ToInt32(CurrentUserInfo.UserID); ////组织参数化SQL //StringBuilder strSql = new StringBuilder(); //strSql.Append("update [SMS_Customer] set "); //strSql.Append("[Account]=@Account,[Password]=@Password,[LastUpdateBy]=@LastUpdateBy,[LastUpdateTime]=@LastUpdateTime"); //strSql.Append(" where SMS_CustomerID=@SMSCustomerID "); //SqlParameter[] parameters = //{ // new SqlParameter("@Account",SqlDbType.NVarChar,100), // new SqlParameter("@Password",SqlDbType.NVarChar,100), // new SqlParameter("@LastUpdateBy",SqlDbType.NVarChar,100), // new SqlParameter("@LastUpdateTime",SqlDbType.DateTime), // new SqlParameter("@SMSCustomerID",SqlDbType.NVarChar,100) //}; //parameters[0].Value = pEntity.Account; //parameters[1].Value = pEntity.Password; //parameters[2].Value = pEntity.LastUpdateBy; //parameters[3].Value = pEntity.LastUpdateTime; //parameters[4].Value = pEntity.SMSCustomerID; ////执行语句 //int result = 0; //if (pTran != null) // result = this.SQLHelper.ExecuteNonQuery((SqlTransaction)pTran, CommandType.Text, strSql.ToString(), parameters); //else // result = this.SQLHelper.ExecuteNonQuery(CommandType.Text, strSql.ToString(), parameters); }
/// <summary> /// 创建一个新实例 /// </summary> /// <param name="pEntity">实体实例</param> public void Create(SMSCustomerEntity pEntity) { // this.Create(pEntity, null); }
/// <summary> /// 根据实体非Null属性生成查询条件。 /// </summary> /// <returns></returns> protected IWhereCondition[] GetWhereConditionByEntity(SMSCustomerEntity pQueryEntity) { //获取非空属性数量 List <EqualsCondition> lstWhereCondition = new List <EqualsCondition>(); if (pQueryEntity.SMSCustomerID != null) { lstWhereCondition.Add(new EqualsCondition() { FieldName = "SMSCustomerID", Value = pQueryEntity.SMSCustomerID }); } if (pQueryEntity.Account != null) { lstWhereCondition.Add(new EqualsCondition() { FieldName = "Account", Value = pQueryEntity.Account }); } if (pQueryEntity.Password != null) { lstWhereCondition.Add(new EqualsCondition() { FieldName = "Password", Value = pQueryEntity.Password }); } if (pQueryEntity.IsDelete != null) { lstWhereCondition.Add(new EqualsCondition() { FieldName = "IsDelete", Value = pQueryEntity.IsDelete }); } if (pQueryEntity.CreateTime != null) { lstWhereCondition.Add(new EqualsCondition() { FieldName = "CreateTime", Value = pQueryEntity.CreateTime }); } if (pQueryEntity.CreateBy != null) { lstWhereCondition.Add(new EqualsCondition() { FieldName = "CreateBy", Value = pQueryEntity.CreateBy }); } if (pQueryEntity.LastUpdateBy != null) { lstWhereCondition.Add(new EqualsCondition() { FieldName = "LastUpdateBy", Value = pQueryEntity.LastUpdateBy }); } if (pQueryEntity.LastUpdateTime != null) { lstWhereCondition.Add(new EqualsCondition() { FieldName = "LastUpdateTime", Value = pQueryEntity.LastUpdateTime }); } return(lstWhereCondition.ToArray()); }
/// <summary> /// 分页根据实体条件查询实体 /// </summary> /// <param name="pQueryEntity">以实体形式传入的参数</param> /// <param name="pOrderBys">排序组合</param> /// <returns>符合条件的实体集</returns> public PagedQueryResult <SMSCustomerEntity> PagedQueryByEntity(SMSCustomerEntity pQueryEntity, OrderBy[] pOrderBys, int pPageSize, int pCurrentPageIndex) { IWhereCondition[] queryWhereCondition = GetWhereConditionByEntity(pQueryEntity); return(PagedQuery(queryWhereCondition, pOrderBys, pPageSize, pCurrentPageIndex)); }
/// <summary> /// 根据实体条件查询实体 /// </summary> /// <param name="pQueryEntity">以实体形式传入的参数</param> /// <param name="pOrderBys">排序组合</param> /// <returns>符合条件的实体集</returns> public SMSCustomerEntity[] QueryByEntity(SMSCustomerEntity pQueryEntity, OrderBy[] pOrderBys) { IWhereCondition[] queryWhereCondition = GetWhereConditionByEntity(pQueryEntity); return(Query(queryWhereCondition, pOrderBys)); }
/// <summary> /// 删除 /// </summary> /// <param name="pEntity"></param> public void Delete(SMSCustomerEntity pEntity) { this.Delete(pEntity, null); }
/// <summary> /// 更新 /// </summary> /// <param name="pEntity">实体实例</param> public void Update(SMSCustomerEntity pEntity) { _currentDAO.Update(pEntity); }
/// <summary> /// 在事务内创建一个新实例 /// </summary> /// <param name="pEntity">实体实例</param> /// <param name="pTran">事务实例,可为null,如果为null,则不使用事务来更新</param> public void Create(SMSCustomerEntity pEntity, IDbTransaction pTran) { _currentDAO.Create(pEntity, pTran); }
/// <summary> /// 创建一个新实例 /// </summary> /// <param name="pEntity">实体实例</param> public void Create(SMSCustomerEntity pEntity) { _currentDAO.Create(pEntity); }
/// <summary> /// 分页根据实体条件查询实体 /// </summary> /// <param name="pQueryEntity">以实体形式传入的参数</param> /// <param name="pOrderBys">排序组合</param> /// <returns>符合条件的实体集</returns> public PagedQueryResult <SMSCustomerEntity> PagedQueryByEntity(SMSCustomerEntity pQueryEntity, OrderBy[] pOrderBys, int pPageSize, int pCurrentPageIndex) { return(_currentDAO.PagedQueryByEntity(pQueryEntity, pOrderBys, pPageSize, pCurrentPageIndex)); }
/// <summary> /// 根据实体条件查询实体 /// </summary> /// <param name="pQueryEntity">以实体形式传入的参数</param> /// <param name="pOrderBys">排序组合</param> /// <returns>符合条件的实体集</returns> public SMSCustomerEntity[] QueryByEntity(SMSCustomerEntity pQueryEntity, OrderBy[] pOrderBys) { return(_currentDAO.QueryByEntity(pQueryEntity, pOrderBys)); }
/// <summary> /// 删除 /// </summary> /// <param name="pEntity"></param> public void Delete(SMSCustomerEntity pEntity) { _currentDAO.Delete(pEntity); }
/// <summary> /// 更新 /// </summary> /// <param name="pEntity">实体实例</param> public void Update(SMSCustomerEntity pEntity) { this.Update(pEntity, null); }
/// <summary> /// 获取TOP数据短信实体 /// </summary> /// <param name="topCount"></param> /// <returns></returns> public SMSSendEntity[] GetNoSend(int topCount = 100) { string sql = "select top {0} * from SMS_Send where Status=0 and isnull(Send_Count,0)<3 order by SMS_send_id desc".Fmt(topCount); List <SMSSendEntity> list = new List <SMSSendEntity> { }; JITMemoryCache jitCache = new JITMemoryCache(); System.Web.Caching.Cache objCache = HttpRuntime.Cache; using (SqlDataReader dr = this.SQLHelper.ExecuteReader(sql.ToString())) { objCache.Insert("SMSCustomerID", (Object)string.Empty); while (dr.Read()) { SMSSendEntity m; this.Load(dr, out m); // update by:wuwen 20141020 增加适用多账号 //1:账号id放入缓存 缓存不存在,则添加缓存 //2:根据短信账号id,获取账号用户名和密码 cf_jieyt kLhNMF //客户id缓存不为空,并且客户id不为空,当前的客户id缓存不等于当前的客户id,则获取客户名称和客户密码 if ((!objCache["SMSCustomerID"].Equals(string.Empty)) && (!string.IsNullOrWhiteSpace(m.SMSCustomerID)) && (objCache["SMSCustomerID"].ToString().Equals(m.SMSCustomerID))) { //获取短信账号和密码 SMSCustomerBLL SMSCustomerBLL = new SMSCustomerBLL(new BasicUserInfo()); SMSCustomerEntity SMSCustomerEntity = SMSCustomerBLL.GetByID(m.SMSCustomerID, null); m.Account = SMSCustomerEntity.Account; m.Password = SMSCustomerEntity.Password; objCache.Insert("Account", (Object)m.Account); objCache.Insert("Password", (Object)m.Password); } //用于用户领取会员卡,会员云程序中没有设置对应客户id,用sign签名关联客户表和发送消息表 else if (string.IsNullOrWhiteSpace(m.SMSCustomerID)) { //获取短信账号和密码 SMSCustomerBLL SMSCustomerBLL = new SMSCustomerBLL(new BasicUserInfo()); SMSCustomerEntity SMSCustomerEntity = SMSCustomerBLL.GetByID(null, m.Sign); m.Account = SMSCustomerEntity.Account; m.Password = SMSCustomerEntity.Password; m.SMSCustomerID = SMSCustomerEntity.SMSCustomerID.ToString(); objCache.Insert("Account", (Object)m.Account); objCache.Insert("Password", (Object)m.Password); } //客户id缓存不为空,并且客户id不为空,则获取客户名称和客户密码,第一次进入方法时操作 //else if ((objCache["SMSCustomerID"].Equals(string.Empty)) && (!string.IsNullOrWhiteSpace(m.SMSCustomerID))) else if ((!string.IsNullOrWhiteSpace(m.SMSCustomerID))) { //获取短信账号和密码 SMSCustomerBLL SMSCustomerBLL = new SMSCustomerBLL(new BasicUserInfo()); SMSCustomerEntity SMSCustomerEntity = SMSCustomerBLL.GetByID(m.SMSCustomerID, null); m.Account = SMSCustomerEntity.Account; m.Password = SMSCustomerEntity.Password; objCache.Insert("Account", (Object)m.Account); objCache.Insert("Password", (Object)m.Password); } else//获取客户账号和客户密码 { m.Account = objCache["Account"].ToString(); m.Password = objCache["Password"].ToString(); } objCache.Insert("SMSCustomerID", (Object)m.SMSCustomerID); list.Add(m); } } Loggers.Debug(new DebugLogInfo() { Message = sql }); return(list.ToArray()); }