コード例 #1
0
	private DataTable FillTable(BXRoleTaskCollection taskCollection, int startRowIndex, int maximumRows)
	{
		if (taskCollection == null)
			taskCollection = new BXRoleTaskCollection();

		DataTable result = new DataTable();

		result.Columns.Add("num", typeof(int));
		result.Columns.Add("TaskId", typeof(int));
		result.Columns.Add("TaskName", typeof(string));
		result.Columns.Add("Comment", typeof(string));
		result.Columns.Add("TasksCount", typeof(int));
		result.Columns.Add("OperationsCount", typeof(int));

		int ind = -1;
		foreach (BXRoleTask t in taskCollection)
		{
			ind++;
			if (startRowIndex > ind)
				continue;

			DataRow r = result.NewRow();
			r["num"] = ind;
			r["TaskId"] = t.TaskId;
			r["TaskName"] = t.Title;
			r["Comment"] = t.Comment;
			r["TasksCount"] = t.TasksCount;
			r["OperationsCount"] = t.OperationsCount;
			result.Rows.Add(r);

			if (maximumRows > 0 && ind == startRowIndex + maximumRows - 1)
				break;
		}

		return result;
	}
コード例 #2
0
	protected void TasksGridView_Delete(object sender, Bitrix.UI.BXDeleteEventArgs e)
	{
		BXGridView grid = (BXGridView)sender;
		try
		{
			if (!currentUserCanModifySettings)
				throw new PublicException(GetMessageRaw("ExceptionText.YouDontHaveRightsToDeleteThisRecord"));

			BXRoleTaskCollection elements;
			if (e.Keys != null) //Delete one element
			{
				elements = new BXRoleTaskCollection();
				elements.Add(BXRoleTaskManager.GetById((int)e.Keys["TaskId"]));
			}
			else //All elements
			{
				elements = BXRoleTaskManager.GetList(BXAdminFilter1.CurrentFilter, null);
			}

			foreach (BXRoleTask element in elements)
			{
				if (element == null)
					throw new PublicException(GetMessageRaw("ExceptionText.TaskIsNotFound"));
				if (!BXRoleTaskManager.Delete(element.TaskId))
					throw new PublicException(GetMessageRaw("ExceptionText.DeletionOfTaskIsFailed"));
				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();
	}