private string BuildConditionsByFilter(SqlQuery query, AdminDoingFilter filter, IEnumerable <Guid> excludeRoleIDs, bool startWithWhere) { StringBuffer sqlConditions = new StringBuffer(); if (filter.UserID != null && filter.UserID > 0) { sqlConditions += " AND UserID = @UserID"; query.CreateParameter <int?>("@UserID", filter.UserID, SqlDbType.Int); } if (!string.IsNullOrEmpty(filter.Username)) { sqlConditions += " AND UserID IN (SELECT UserID FROM bx_Users WHERE Username = @Username)"; query.CreateParameter <string>("@Username", filter.Username, SqlDbType.NVarChar, 50); } if (!string.IsNullOrEmpty(filter.Content)) { sqlConditions += " AND Content LIKE '%'+@Content+'%'"; query.CreateParameter <string>("@Content", filter.Content, SqlDbType.NVarChar, 200); } if (!string.IsNullOrEmpty(filter.IP)) { sqlConditions += " AND CreateIP LIKE '%'+@IP+'%'"; query.CreateParameter <string>("@IP", filter.IP, SqlDbType.VarChar, 50); } if (filter.BeginDate != null) { sqlConditions += " AND CreateDate >= @BeginDate"; query.CreateParameter <DateTime?>("@BeginDate", filter.BeginDate, SqlDbType.DateTime); } if (filter.EndDate != null) { sqlConditions += " AND CreateDate <= @EndDate"; query.CreateParameter <DateTime?>("@EndDate", filter.EndDate, SqlDbType.DateTime); } string excludeRoleSQL = DaoUtil.GetExcludeRoleSQL("[UserID]", excludeRoleIDs, query); if (string.IsNullOrEmpty(excludeRoleSQL) == false) { sqlConditions += " AND " + excludeRoleSQL; } if (sqlConditions.Length > 0) { sqlConditions.Remove(0, 5); if (startWithWhere) { sqlConditions.InnerBuilder.Insert(0, " WHERE "); } } return(sqlConditions.ToString()); }
public override bool StepExecute(int operatorUserID, string param, ref long offset, ref int totalCount, ref int finishedCount, out string title, out bool isLastStep) { StringList paramData = StringList.Parse(param); AdminDoingFilter filter = AdminDoingFilter.Parse(paramData[0]); int stepCount; if (DoingBO.Instance.DeleteDoingsForAdmin(operatorUserID, filter, paramData[1] == "1", stepDeleteCount, out stepCount)) // .DeleteDoingsBySearch(filter, 200); { finishedCount += stepCount; isLastStep = stepCount < stepDeleteCount; title = "正在删除记录,总数 " + totalCount + ",已删 " + finishedCount; return(true); } else { isLastStep = true; title = string.Empty; } return(true); }
/// <summary> /// 获取记录用于管理 /// </summary> /// <param name="operatorID">操作者ID</param> /// <param name="filter">文章搜索条件</param> /// <param name="pageNumber">数据分页页码</param> /// <returns></returns> public DoingCollection GetDoingsForAdmin(int operatorID, AdminDoingFilter filter, int pageNumber) { if (ValidateDoingAdminPermission(operatorID) == false) { return(null); } Guid[] excludeRoleIDs = ManagePermission.GetNoPermissionTargetRoleIds(operatorID, PermissionTargetType.Content); DoingCollection doings = DoingDao.Instance.GetDoingsBySearch(excludeRoleIDs, filter, pageNumber); ProcessKeyword(doings, ProcessKeywordMode.FillOriginalText); return(doings); }
public override DeleteResult DeleteDoingsBySearch(AdminDoingFilter filter, IEnumerable <Guid> excludeRoleIDs, int deleteTopCount, out int deletedCount) { deletedCount = 0; using (SqlQuery query = new SqlQuery()) { string conditions = BuildConditionsByFilter(query, filter, excludeRoleIDs, true); StringBuffer sql = new StringBuffer(); sql += @" DECLARE @DeleteData table (UserID int, DoingID int); INSERT INTO @DeleteData SELECT TOP (@TopCount) [UserID],[DoingID] FROM [bx_Doings] " + conditions + @"; DELETE [bx_Doings] WHERE DoingID IN (SELECT [DoingID] FROM @DeleteData); SELECT @@ROWCOUNT; SELECT [UserID],COUNT(*) AS [Count] FROM @DeleteData GROUP BY [UserID];"; query.CreateTopParameter("@TopCount", deleteTopCount); query.CommandText = sql.ToString(); using (XSqlDataReader reader = query.ExecuteReader()) { DeleteResult deleteResult = new DeleteResult(); if (reader.Read()) { deletedCount = reader.Get <int>(0); } if (reader.NextResult()) { while (reader.Read()) { deleteResult.Add(reader.Get <int>("UserID"), reader.Get <int>("Count")); } } return(deleteResult); } } }
/// <summary> /// 删除搜索结果 /// </summary> /// <param name="filter"></param> /// <returns></returns> public bool DeleteDoingsForAdmin(int operatorID, AdminDoingFilter filter, bool isUpdatePoint, int deleteTopCount, out int deletedCount) { if (filter == null) { throw new ArgumentNullException("filter"); } deletedCount = 0; int deleteCountTemp = 0; bool succeed = ProcessDeleteDoings(operatorID, isUpdatePoint, delegate(Guid[] excludeRoleIDs) { return(DoingDao.Instance.DeleteDoingsBySearch(filter, excludeRoleIDs, deleteTopCount, out deleteCountTemp)); }); deletedCount = deleteCountTemp; return(succeed); }
public override DoingCollection GetDoingsBySearch(Guid[] excludeRoleIDs, AdminDoingFilter filter, int pageNumber) { using (SqlQuery query = new SqlQuery()) { string conditions = BuildConditionsByFilter(query, filter, excludeRoleIDs, false); query.Pager.TableName = "[bx_Doings]"; query.Pager.SortField = filter.Order.ToString(); if (filter.Order != AdminDoingFilter.OrderBy.DoingID) { query.Pager.PrimaryKey = "DoingID"; } query.Pager.IsDesc = filter.IsDesc; query.Pager.PageNumber = pageNumber; query.Pager.PageSize = filter.PageSize; query.Pager.SelectCount = true; query.Pager.Condition = conditions.ToString(); using (XSqlDataReader reader = query.ExecuteReader()) { DoingCollection doings = new DoingCollection(reader); if (reader.NextResult()) { if (reader.Read()) { doings.TotalRecords = reader.Get <int>(0); } } return(doings); } } }
public override bool BeforeExecute(int operatorUserID, string param, ref long offset, ref int totalCount, out string title) { StringList paramData = StringList.Parse(param); AdminDoingFilter filter = AdminDoingFilter.Parse(paramData[0]); //只取一条数据测试下就可以 filter.PageSize = 1; DoingCollection doings = DoingBO.Instance.GetDoingsForAdmin(operatorUserID, filter, 1); if (doings == null || doings.Count == 0) { title = "没有数据可以删除"; return(false); } totalCount = doings.TotalRecords; title = "将删除 " + totalCount + " 篇日志"; return(true); }
public override void AfterExecute(int operatorUserID, string param, bool success, int totalCount, int finishedCount, out string title) { if (success) { title = "删除记录成功,共删除 " + finishedCount + " 篇记录"; StringList paramData = StringList.Parse(param); AdminDoingFilter filter = AdminDoingFilter.Parse(paramData[0]); if (success) { User operatorUser = UserBO.Instance.GetUser(operatorUserID, GetUserOption.WithAll); Logs.LogManager.LogOperation( new Doing_DeleteDoingBySearch(operatorUserID, operatorUser.Name, IPUtil.GetCurrentIP(), filter, finishedCount) ); } } else { title = "删除记录失败"; } }
/// <summary> /// 搜集过滤器数据并应用,此时会立即发生页面跳转 /// </summary> private void Search() { AdminDoingFilter filter = AdminDoingFilter.GetFromForm(); filter.Apply("filter", "page"); }
public abstract DoingCollection GetDoingsBySearch(Guid[] excludeRoleIDs, AdminDoingFilter filter, int pageNumber);
/// <summary> /// 删除搜索结果 /// </summary> /// <param name="filter">搜索条件</param> /// <param name="excludeRoleIDs">操作者没有权限管理的用户组ID</param> /// <param name="topCount">删除搜索结果的前几条</param> /// <param name="deletedCount">真实删除的条数</param> /// <returns></returns> public abstract DeleteResult DeleteDoingsBySearch(AdminDoingFilter filter, IEnumerable <Guid> excludeRoleIDs, int deleteTopCount, out int deletedCount);
private string BuildConditionsByFilter(SqlQuery query, AdminDoingFilter filter, IEnumerable<Guid> excludeRoleIDs, bool startWithWhere) { StringBuffer sqlConditions = new StringBuffer(); if (filter.UserID != null && filter.UserID > 0) { sqlConditions += " AND UserID = @UserID"; query.CreateParameter<int?>("@UserID", filter.UserID, SqlDbType.Int); } if (!string.IsNullOrEmpty(filter.Username)) { sqlConditions += " AND UserID IN (SELECT UserID FROM bx_Users WHERE Username = @Username)"; query.CreateParameter<string>("@Username", filter.Username, SqlDbType.NVarChar, 50); } if (!string.IsNullOrEmpty(filter.Content)) { sqlConditions += " AND Content LIKE '%'+@Content+'%'"; query.CreateParameter<string>("@Content", filter.Content, SqlDbType.NVarChar, 200); } if (!string.IsNullOrEmpty(filter.IP)) { sqlConditions += " AND CreateIP LIKE '%'+@IP+'%'"; query.CreateParameter<string>("@IP", filter.IP, SqlDbType.VarChar, 50); } if (filter.BeginDate != null) { sqlConditions += " AND CreateDate >= @BeginDate"; query.CreateParameter<DateTime?>("@BeginDate", filter.BeginDate, SqlDbType.DateTime); } if (filter.EndDate != null) { sqlConditions += " AND CreateDate <= @EndDate"; query.CreateParameter<DateTime?>("@EndDate", filter.EndDate, SqlDbType.DateTime); } string excludeRoleSQL = DaoUtil.GetExcludeRoleSQL("[UserID]", excludeRoleIDs, query); if (string.IsNullOrEmpty(excludeRoleSQL) == false) { sqlConditions += " AND " + excludeRoleSQL; } if (sqlConditions.Length > 0) { sqlConditions.Remove(0, 5); if (startWithWhere) sqlConditions.InnerBuilder.Insert(0, " WHERE "); } return sqlConditions.ToString(); }
public override DeleteResult DeleteDoingsBySearch(AdminDoingFilter filter, IEnumerable<Guid> excludeRoleIDs, int deleteTopCount, out int deletedCount) { deletedCount = 0; using (SqlQuery query = new SqlQuery()) { string conditions = BuildConditionsByFilter(query, filter, excludeRoleIDs, true); StringBuffer sql = new StringBuffer(); sql += @" DECLARE @DeleteData table (UserID int, DoingID int); INSERT INTO @DeleteData SELECT TOP (@TopCount) [UserID],[DoingID] FROM [bx_Doings] " + conditions + @"; DELETE [bx_Doings] WHERE DoingID IN (SELECT [DoingID] FROM @DeleteData); SELECT @@ROWCOUNT; SELECT [UserID],COUNT(*) AS [Count] FROM @DeleteData GROUP BY [UserID];"; query.CreateTopParameter("@TopCount", deleteTopCount); query.CommandText = sql.ToString(); using (XSqlDataReader reader = query.ExecuteReader()) { DeleteResult deleteResult = new DeleteResult(); if (reader.Read()) deletedCount = reader.Get<int>(0); if (reader.NextResult()) { while (reader.Read()) { deleteResult.Add(reader.Get<int>("UserID"), reader.Get<int>("Count")); } } return deleteResult; } } }
public override DoingCollection GetDoingsBySearch(Guid[] excludeRoleIDs, AdminDoingFilter filter, int pageNumber) { using (SqlQuery query = new SqlQuery()) { string conditions = BuildConditionsByFilter(query, filter, excludeRoleIDs, false); query.Pager.TableName = "[bx_Doings]"; query.Pager.SortField = filter.Order.ToString(); if (filter.Order != AdminDoingFilter.OrderBy.DoingID) { query.Pager.PrimaryKey = "DoingID"; } query.Pager.IsDesc = filter.IsDesc; query.Pager.PageNumber = pageNumber; query.Pager.PageSize = filter.PageSize; query.Pager.SelectCount = true; query.Pager.Condition = conditions.ToString(); using (XSqlDataReader reader = query.ExecuteReader()) { DoingCollection doings = new DoingCollection(reader); if (reader.NextResult()) { if (reader.Read()) { doings.TotalRecords = reader.Get<int>(0); } } return doings; } } }