Skip to content

Instantly share code, notes, and snippets.

@dennis-garavsky
Last active December 28, 2016 09:03
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save dennis-garavsky/5486a70bd85356ca1ec7af2a4072ab7c to your computer and use it in GitHub Desktop.
using DevExpress.ExpressApp;
using DevExpress.ExpressApp.Actions;
using DevExpress.Persistent.Base;
using Solution62.Module.BusinessObjects;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace YourSolutionName.Module.Controllers {
public class TaskStatusController_SimpleActions : ViewController {
SimpleAction notStartedState;
SimpleAction draftState;
SimpleAction inProgressState;
SimpleAction pausedState;
SimpleAction completedState;
SimpleAction droppedState;
public TaskStatusController_SimpleActions() {
TargetObjectType = typeof(Task1);
notStartedState = new SimpleAction(this, "Not Started", PredefinedCategory.Edit);
notStartedState.SelectionDependencyType = SelectionDependencyType.RequireMultipleObjects;
notStartedState.Execute += notStartedState_Execute;
draftState = new SimpleAction(this, "Draft", PredefinedCategory.Edit);
draftState.SelectionDependencyType = SelectionDependencyType.RequireMultipleObjects;
draftState.Execute += draftState_Execute;
inProgressState = new SimpleAction(this, "In Progress", PredefinedCategory.Edit);
inProgressState.SelectionDependencyType = SelectionDependencyType.RequireMultipleObjects;
inProgressState.Execute += draftState_Execute;
pausedState = new SimpleAction(this, "Paused", PredefinedCategory.Edit);
pausedState.SelectionDependencyType = SelectionDependencyType.RequireMultipleObjects;
pausedState.Execute += draftState_Execute;
completedState = new SimpleAction(this, "Completed", PredefinedCategory.Edit);
completedState.SelectionDependencyType = SelectionDependencyType.RequireMultipleObjects;
completedState.Execute += draftState_Execute;
droppedState = new SimpleAction(this, "Dropped", PredefinedCategory.Edit);
droppedState.SelectionDependencyType = SelectionDependencyType.RequireMultipleObjects;
droppedState.Execute += draftState_Execute;
}
private void AssignStatus(TaskStatus status) {
foreach(Task1 task in View.SelectedObjects) {
task.Status = status;
}
View.ObjectSpace.CommitChanges();
}
void notStartedState_Execute(object sender, SimpleActionExecuteEventArgs e) {
AssignStatus(TaskStatus.NotStarted);
}
void draftState_Execute(object sender, SimpleActionExecuteEventArgs e) {
AssignStatus(TaskStatus.Draft);
}
void inProgressState_Execute(object sender, SimpleActionExecuteEventArgs e) {
AssignStatus(TaskStatus.InProgress);
}
void pausedState_Execute(object sender, SimpleActionExecuteEventArgs e) {
AssignStatus(TaskStatus.Paused);
}
void completedState_Execute(object sender, SimpleActionExecuteEventArgs e) {
AssignStatus(TaskStatus.Completed);
}
void droppedState_Execute(object sender, SimpleActionExecuteEventArgs e) {
AssignStatus(TaskStatus.Dropped);
}
void ObjectSpace_Reloaded(object sender, EventArgs e) {
UpdateActions();
}
void View_SelectionChanged(object sender, EventArgs e) {
UpdateActions();
}
void ObjectSpace_ObjectChanged(object sender, ObjectChangedEventArgs e) {
if(e.Object == View.CurrentObject) {
UpdateActions();
}
}
private void UpdateActions() {
notStartedState.Active[""] = false;
draftState.Active[""] = false;
inProgressState.Active[""] = false;
pausedState.Active[""] = false;
completedState.Active[""] = false;
droppedState.Active[""] = false;
if(View.SelectedObjects.Count > 0) {
Task1 task = (Task1)View.SelectedObjects[0];
if(task != null) {
if(task.Status == TaskStatus.Draft) {
notStartedState.Active[""] = true;
inProgressState.Active[""] = true;
}
else if(task.Status == TaskStatus.NotStarted) {
draftState.Active[""] = true;
inProgressState.Active[""] = true;
}
else if(task.Status == TaskStatus.Draft) {
notStartedState.Active[""] = true;
}
else if(task.Status == TaskStatus.InProgress) {
pausedState.Active[""] = true;
completedState.Active[""] = true;
droppedState.Active[""] = true;
}
else if(task.Status == TaskStatus.Paused) {
inProgressState.Active[""] = true;
}
else if(task.Status == TaskStatus.Completed) {
}
else if(task.Status == TaskStatus.Dropped) {
notStartedState.Active[""] = true;
}
}
}
}
protected override void OnActivated() {
base.OnActivated();
View.ObjectSpace.ObjectChanged += ObjectSpace_ObjectChanged;
View.ObjectSpace.Reloaded += ObjectSpace_Reloaded;
View.SelectionChanged += View_SelectionChanged;
UpdateActions();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment