/// <summary> /// 拜访步骤选择拜访参数 /// </summary> /// <param name="stepid">拜访步骤ID</param> /// <param name="allSelectorStatus">选择状态</param> /// <param name="defaultList">默认list</param> /// <param name="includeList">选择list</param> /// <param name="excludeList">排除list</param> /// <param name="updateEntity">修改信息</param> public void EditStepParameter(Guid stepid, int allSelectorStatus, string defaultList, string includeList, string excludeList, VisitingTaskParameterMappingEntity[] updateEntity) { /* * 0默认勾选 * 添加新数据(判断是否存在) * 删除缺掉的数据 * * 1全选 * 添加, 不在excludeLists 排除id 中的数据(判断是否存在) * 删除 excludeLists 排除id * * 2全不选 * 先删除 不在includeList 包含id中的数据 * 添加 includeList 中的数据(判断是否存在) */ VisitingParameterViewEntity parameterEntity = new VisitingParameterViewEntity(); parameterEntity.VisitingTaskStepID = stepid; int rowcount = 0; IDbTransaction tran = new TransactionHelper(this.CurrentUserInfo).CreateTransaction(); using (tran.Connection) { try { List <VisitingParameterViewEntity> oldList = this.GetStepParameterList(parameterEntity, 1, 100000, out rowcount).ToList(); if (allSelectorStatus == 0)//默认,勾选 { //添加 string[] defaultLists = defaultList.Split(','); //1,2,3 string[] includeLists = includeList.Split(','); //1,2,3,4 1,2 1,2,4 StringBuilder delList = new StringBuilder(); for (int i = 0; i < includeLists.Length; i++) { if (!defaultLists.Contains(includeLists[i])) { VisitingTaskParameterMappingEntity entity = new VisitingTaskParameterMappingEntity(); entity.VisitingParameterID = Guid.Parse(includeLists[i]); entity.VisitingTaskStepID = stepid; entity.ParameterOrder = 0; entity.ClientID = CurrentUserInfo.ClientID; entity.ClientDistributorID = Convert.ToInt32(CurrentUserInfo.ClientDistributorID); new VisitingTaskParameterMappingBLL(CurrentUserInfo).Create(entity, tran); } } //删除 StringBuilder sbDelList = new StringBuilder(); for (int i = 0; i < defaultLists.Length; i++) { if (!includeLists.Contains(defaultLists[i])) { //if() //{ sbDelList.Append("'" + defaultLists[i] + "',"); //} } } if (!string.IsNullOrEmpty(sbDelList.ToString())) { this._currentDAO.DeleteStepParameterIn(stepid.ToString(), sbDelList.Remove(sbDelList.ToString().Length - 1, 1).ToString(), tran); } } else if (allSelectorStatus == 1)//全选 { //添加 string[] excludeLists = excludeList.Split(','); for (int i = 0; i < oldList.ToArray().Length; i++) { if (oldList[i].MappingID == null || string.IsNullOrEmpty(oldList[i].MappingID.ToString())) { if (!excludeLists.Contains(oldList[i].VisitingParameterID.ToString())) { VisitingTaskParameterMappingEntity entity = new VisitingTaskParameterMappingEntity(); entity.VisitingParameterID = oldList[i].VisitingParameterID; entity.VisitingTaskStepID = stepid; entity.ParameterOrder = 0; entity.ClientID = CurrentUserInfo.ClientID; entity.ClientDistributorID = Convert.ToInt32(CurrentUserInfo.ClientDistributorID); new VisitingTaskParameterMappingBLL(CurrentUserInfo).Create(entity, tran); } } } //删除 if (excludeList != "") { this._currentDAO.DeleteStepParameterIn( stepid.ToString(), "'" + excludeList.Replace(",", "','") + "'", tran); } } else if (allSelectorStatus == 2)//全不选 { //删除 if (includeList != "") { this._currentDAO.DeleteStepParameterNotIn(stepid.ToString(), "'" + includeList.Replace(",", "','") + "'" , tran); } else { this._currentDAO.DeleteStepParameterAll(stepid.ToString(), tran); } //添加 if (includeList.Trim().Length > 0) { string[] includeLists = includeList.Split(','); foreach (string pid in includeLists) { if (oldList.Where(m => m.MappingID != null && m.VisitingTaskStepID == stepid && m.VisitingParameterID == Guid.Parse(pid)).ToArray().Length == 0) { VisitingTaskParameterMappingEntity entity = new VisitingTaskParameterMappingEntity(); entity.VisitingParameterID = Guid.Parse(pid); entity.VisitingTaskStepID = stepid; entity.ParameterOrder = 0; entity.ClientID = CurrentUserInfo.ClientID; entity.ClientDistributorID = Convert.ToInt32(CurrentUserInfo.ClientDistributorID); new VisitingTaskParameterMappingBLL(CurrentUserInfo).Create(entity, tran); } } } } tran.Commit(); } catch { tran.Rollback(); throw; } } tran = new TransactionHelper(this.CurrentUserInfo).CreateTransaction(); using (tran.Connection) { try { //修改数据 List <VisitingParameterViewEntity> oldList = this.GetStepParameterList(parameterEntity, 1, 100000, out rowcount).ToList(); foreach (VisitingTaskParameterMappingEntity uEntity in updateEntity) { if (oldList.Where(m => m.VisitingParameterID == uEntity.VisitingParameterID && m.MappingID != null).ToArray().Length == 1) { VisitingParameterViewEntity entity = oldList.Where(m => m.VisitingParameterID == uEntity.VisitingParameterID && m.MappingID != null).ToArray()[0]; VisitingTaskParameterMappingEntity mEntity = new VisitingTaskParameterMappingEntity(); mEntity.MappingID = entity.MappingID; mEntity.VisitingTaskStepID = entity.VisitingTaskStepID; mEntity.VisitingParameterID = entity.VisitingParameterID; mEntity.ParameterOrder = uEntity.ParameterOrder; mEntity.ClientID = entity.ClientID; mEntity.ClientDistributorID = entity.ClientDistributorID; mEntity.CreateBy = entity.CreateBy; mEntity.CreateTime = entity.CreateTime; this.Update(mEntity, tran); } } tran.Commit(); } catch { tran.Rollback(); throw; } } }
/// <summary> /// 更新 /// </summary> /// <param name="pEntity">实体实例</param> /// <param name="pTran">事务实例,可为null,如果为null,则不使用事务来更新</param> public void Update(VisitingTaskParameterMappingEntity pEntity, IDbTransaction pTran) { _currentDAO.Update(pEntity, pTran); }
/// <summary> /// 分页根据实体条件查询实体 /// </summary> /// <param name="pQueryEntity">以实体形式传入的参数</param> /// <param name="pOrderBys">排序组合</param> /// <returns>符合条件的实体集</returns> public PagedQueryResult <VisitingTaskParameterMappingEntity> PagedQueryByEntity(VisitingTaskParameterMappingEntity pQueryEntity, OrderBy[] pOrderBys, int pPageSize, int pCurrentPageIndex) { return(_currentDAO.PagedQueryByEntity(pQueryEntity, pOrderBys, pPageSize, pCurrentPageIndex)); }
/// <summary> /// 创建一个新实例 /// </summary> /// <param name="pEntity">实体实例</param> public void Create(VisitingTaskParameterMappingEntity pEntity) { _currentDAO.Create(pEntity); }
/// <summary> /// 根据实体条件查询实体 /// </summary> /// <param name="pQueryEntity">以实体形式传入的参数</param> /// <param name="pOrderBys">排序组合</param> /// <returns>符合条件的实体集</returns> public VisitingTaskParameterMappingEntity[] QueryByEntity(VisitingTaskParameterMappingEntity pQueryEntity, OrderBy[] pOrderBys) { return(_currentDAO.QueryByEntity(pQueryEntity, pOrderBys)); }