/// <summary> /// 根据标识符获取实例 /// </summary> /// <param name="pID">标识符的值</param> public OptionsDefinedEntity GetByOptionName(object pOptionName, string ClientID) { //参数检查 if (pOptionName == null) { return(null); } string OptionName = pOptionName.ToString(); string Where = ""; if (!string.IsNullOrEmpty(ClientID) && ClientID != "0") { Where = " and ( ClientID='" + ClientID + "'" + " or ClientID='0')"; } //组织SQL StringBuilder sql = new StringBuilder(); sql.AppendFormat("select * from [OptionsDefined] where OptionName='{0}' and IsDelete=0 {1}", OptionName, Where); //读取数据 OptionsDefinedEntity m = null; using (SqlDataReader rdr = this.SQLHelper.ExecuteReader(sql.ToString())) { while (rdr.Read()) { this.Load(rdr, out m); break; } } //返回 return(m); }
public int OptionsDefinedEdit(OptionsDefinedEntity optionsDefinedEntity, OptionsEntity[] optionEntity) { int result = 1; int type = 0; if (optionsDefinedEntity.DefinedID > 0) { new OptionsDefinedBLL(CurrentUserInfo).Update(optionsDefinedEntity); type = 2; } else { optionsDefinedEntity.ClientID = CurrentUserInfo.ClientID; if (new OptionsDefinedBLL(CurrentUserInfo).GetByOptionName(optionsDefinedEntity.OptionName, CurrentUserInfo.UserID) == null) { new OptionsDefinedBLL(CurrentUserInfo).Create(optionsDefinedEntity); } else { return(2); } type = 1; } if (optionsDefinedEntity.DefinedID > 0) { //传递参数至BLL parameterentity optionentity new OptionsBLL(CurrentUserInfo).Edit(optionEntity, optionsDefinedEntity, type); } return(result); }
public string GetListByOptionType(NameValueCollection rParams, int OptionType) { OptionsDefinedEntity entity = rParams["form"].DeserializeJSONTo <OptionsDefinedEntity>(); if (entity == null) { entity = new OptionsDefinedEntity(); } int pageSize = rParams["limit"].ToInt(); int pageIndex = rParams["page"].ToInt(); IWhereCondition[] pWhereConditions = new IWhereCondition[3]; if (entity != null) { if (entity.Title != null && entity.Title != "") { LikeCondition like = new LikeCondition(); like.FieldName = "Title"; like.HasLeftFuzzMatching = true; like.HasRightFuzzMathing = true; like.Value = entity.Title; pWhereConditions[0] = like; } } EqualsCondition equalCondition = new EqualsCondition(); equalCondition.FieldName = "OptionType"; equalCondition.Value = OptionType; pWhereConditions[1] = equalCondition; EqualsCondition equalCondition2 = new EqualsCondition(); equalCondition2.FieldName = "ClientID"; equalCondition2.Value = CurrentUserInfo.ClientID; pWhereConditions[2] = equalCondition2; OrderBy[] pOrderBys = new OrderBy[1]; OrderBy order = new OrderBy(); order.Direction = OrderByDirections.Asc; order.FieldName = "CreateTime"; pOrderBys[0] = order; PagedQueryResult <OptionsDefinedEntity> entitys = new OptionsDefinedBLL(CurrentUserInfo).PagedQuery(pWhereConditions, pOrderBys, pageSize, pageIndex); return(string.Format("{{\"totalCount\":{1},\"topics\":{0}}}", entitys.Entities.ToJSON(), entitys.RowCount)); }
/// <summary> /// 选项编辑 /// </summary> /// <param name="pEntityList"></param> /// <param name="entity">optionName,clientID必传</param> /// <param name="type">编辑类型 1新增 2修改</param> /// <returns>1name已经存在 2成功</returns> public int Edit(OptionsEntity[] pEntityList, OptionsDefinedEntity definedEntity, int type) { int res = 0; if (type == 1) { foreach (OptionsEntity oEntity in pEntityList) { oEntity.OptionName = definedEntity.OptionName; oEntity.ClientID = definedEntity.ClientID; oEntity.DefinedID = definedEntity.DefinedID; new OptionsBLL(this.CurrentUserInfo).Create(oEntity); } } else { //修改 OptionsEntity entity = new OptionsEntity(); entity.OptionName = definedEntity.OptionName; entity.ClientID = definedEntity.ClientID; entity.DefinedID = definedEntity.DefinedID; List <OptionsEntity> oldList = this.GetOptionByName(entity).ToList(); //添加、修改、删除 foreach (OptionsEntity oEntity in pEntityList) { oEntity.OptionName = definedEntity.OptionName; oEntity.ClientID = definedEntity.ClientID; oEntity.DefinedID = definedEntity.DefinedID; if (oEntity.OptionsID == null || oEntity.OptionsID == 0) { this.Create(oEntity); } if (oldList.ToArray().Where(i => i.OptionsID == oEntity.OptionsID).ToArray().Length > 0) { this.Update(oEntity); oldList.Remove(oldList.ToArray().Where(m => m.OptionsID == oEntity.OptionsID).ToArray()[0]); } } if (oldList.ToArray().Length > 0) { this.Delete(oldList.ToArray()); } } return(res); }
/// <summary> /// 编辑 /// </summary> /// <param name="rParams"></param> /// <param name="type">1新增 2修改</param> /// <returns></returns> private string Edit(NameValueCollection rParams) { string res = "{success:false,msg:'保存失败'}"; OptionsDefinedEntity optionsDefinedEntity = new OptionsDefinedEntity(); if (!string.IsNullOrEmpty(rParams["definedID"])) { optionsDefinedEntity = new OptionsDefinedBLL(CurrentUserInfo).GetByID(rParams["definedID"].ToString()); } optionsDefinedEntity = DataLoader.LoadFrom <OptionsDefinedEntity>(rParams, optionsDefinedEntity); OptionsEntity[] optionEntity = rParams["options"].DeserializeJSONTo <OptionsEntity[]>(); int result = new OptionsBLL(CurrentUserInfo).OptionsDefinedEdit(optionsDefinedEntity, optionEntity); if (result == 1) { res = "{success:true,msg:'保存成功'}"; } else if (result == 2) { res = "{success:false,msg:'名称已经存在,请换一个名称'}"; } return(res); }
/// <summary> /// 更新 /// </summary> /// <param name="pEntity">实体实例</param> public void Update(OptionsDefinedEntity pEntity) { _currentDAO.Update(pEntity); }
/// <summary> /// 更新 /// </summary> /// <param name="pEntity">实体实例</param> /// <param name="pTran">事务实例,可为null,如果为null,则不使用事务来更新</param> public void Update(OptionsDefinedEntity pEntity, IDbTransaction pTran) { _currentDAO.Update(pEntity, pTran); }
/// <summary> /// 创建一个新实例 /// </summary> /// <param name="pEntity">实体实例</param> public void Create(OptionsDefinedEntity pEntity) { _currentDAO.Create(pEntity); }
/// <summary> /// 分页根据实体条件查询实体 /// </summary> /// <param name="pQueryEntity">以实体形式传入的参数</param> /// <param name="pOrderBys">排序组合</param> /// <returns>符合条件的实体集</returns> public PagedQueryResult <OptionsDefinedEntity> PagedQueryByEntity(OptionsDefinedEntity 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 OptionsDefinedEntity[] QueryByEntity(OptionsDefinedEntity pQueryEntity, OrderBy[] pOrderBys) { return(_currentDAO.QueryByEntity(pQueryEntity, pOrderBys)); }
/// <summary> /// 删除 /// </summary> /// <param name="pEntity"></param> public void Delete(OptionsDefinedEntity pEntity) { _currentDAO.Delete(pEntity); }