private DataTable FillTable(BXRoleOperationCollection operationCollection, int startRowIndex, int maximumRows) { if (operationCollection == null) operationCollection = new BXRoleOperationCollection(); DataTable result = new DataTable(); result.Columns.Add("num", typeof(int)); result.Columns.Add("OperationId", typeof(int)); result.Columns.Add("OperationName", typeof(string)); result.Columns.Add("OperationType", typeof(string)); result.Columns.Add("ModuleID", typeof(string)); result.Columns.Add("ModuleName", typeof(string)); result.Columns.Add("Comment", typeof(string)); int ind = -1; foreach (BXRoleOperation t in operationCollection) { ind++; if (startRowIndex > ind) continue; DataRow r = result.NewRow(); r["num"] = ind; r["OperationId"] = t.OperationId; r["OperationName"] = t.OperationFriendlyName; r["OperationType"] = t.OperationType; r["ModuleID"] = t.ModuleId; r["ModuleName"] = t.ModuleId; if (!string.IsNullOrEmpty(t.ModuleId)) { BXModule m = BXModuleManager.GetModule(t.ModuleId); if (m != null) r["ModuleName"] = m.Name; } r["Comment"] = t.Comment; result.Rows.Add(r); if (maximumRows > 0 && ind == startRowIndex + maximumRows - 1) break; } return result; }
protected void AuthOperationsGridView_Delete(object sender, BXDeleteEventArgs e) { BXGridView grid = (BXGridView)sender; try { if (!currentUserCanModifySettings) throw new PublicException(GetMessageRaw("ExceptionText.YouDontHaveRightsToDeleteThisRecord")); BXRoleOperationCollection elements; if (e.Keys != null) //Delete one element { elements = new BXRoleOperationCollection(); elements.Add(BXRoleOperationManager.GetById((int)e.Keys["OperationId"])); } else //All elements { elements = BXRoleOperationManager.GetList(BXAdminFilter1.CurrentFilter, null); } foreach(BXRoleOperation element in elements) { if (element == null) throw new PublicException(GetMessageRaw("ExceptionText.OperationIsNotFound")); if (!BXRoleOperationManager.Delete(element.OperationId)) throw new PublicException(GetMessageRaw("ExceptionText.DeletionIsFailed")); e.DeletedCount++; } successMessage.Visible = true; } catch (PublicException ex) { errorMessage.AddErrorMessage(Encode(ex.Message)); } catch(Exception ex) { errorMessage.AddErrorMessage(GetMessage("Kernel.UnknownError")); BXLogService.LogAll(ex, 0, BXLogMessageType.Error, AppRelativeVirtualPath); } grid.MarkAsChanged(); }