-
Notifications
You must be signed in to change notification settings - Fork 124
/
Copy pathHighlightingTasksViewModel.cs
246 lines (218 loc) · 7.56 KB
/
HighlightingTasksViewModel.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
#region Copyright Syncfusion® Inc. 2001-2025.
// Copyright Syncfusion® Inc. 2001-2025. All rights reserved.
// Use of this code is subject to the terms of our license.
// A copy of the current license can be obtained at any time by e-mailing
// licensing@syncfusion.com. Any infringement will be prosecuted under
// applicable laws.
#endregion
using syncfusion.demoscommon.wpf;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
namespace syncfusion.ganttdemos.wpf
{
public class HighlightingTasksViewModel : TaskRepository
{
/// <summary>
/// Initializes a new instance of the <see cref="ViewModel"/> class.
/// </summary>
public HighlightingTasksViewModel()
{
_highlightTaskBetween = new DelegateCommand<object>(OnHighlightTaskBetweenClicked, CanExcute);
_highlightCriticalTask = new DelegateCommand<object>(OnHighlightCriticalTaskClicked, CanExcute);
_highlightingBrush = Brushes.Red;
}
private List<HighlightingTasksModel> _highlightTaskItems;
/// <summary>
/// Gets or sets the highlight task items.
/// </summary>
/// <value>The highlight task items.</value>
public List<HighlightingTasksModel> HighlightTaskItems
{
get
{
return _highlightTaskItems;
}
set
{
_highlightTaskItems = value;
RaisePropertyChanged("HighlightTaskItems");
}
}
private DateTime _startTime =new DateTime(2012,2,16);
/// <summary>
/// Gets or sets the start time.
/// </summary>
/// <value>The start time.</value>
public DateTime StartTime
{
get
{
return _startTime;
}
set
{
if (value <= _endTime || this._endTime.Equals(DateTime.MinValue))
{
_startTime = value;
}
RaisePropertyChanged("StartTime");
}
}
private DateTime _endTime=new DateTime(2012,8,1);
/// <summary>
/// Gets or sets the end time.
/// </summary>
/// <value>The end time.</value>
public DateTime EndTime
{
get
{
return _endTime;
}
set
{
_endTime = value;
RaisePropertyChanged("EndTime");
}
}
private Brush _highlightingBrush;
/// <summary>
/// Gets or sets the highlighting brush.
/// </summary>
/// <value>The highlighting brush.</value>
public Brush HighlightingBrush
{
get
{
return _highlightingBrush;
}
set
{
_highlightingBrush = value;
RaisePropertyChanged("HighlightingBrush");
}
}
#region Delegate Commands
private DelegateCommand<object> _highlightTaskBetween;
/// <summary>
/// Gets the highlight task between.
/// </summary>
/// <value>The highlight task between.</value>
public DelegateCommand<object> HighlightTaskBetween
{
get
{
return _highlightTaskBetween;
}
}
private DelegateCommand<object> _highlightCriticalTask;
/// <summary>
/// Gets the highlight critical task.
/// </summary>
/// <value>The highlight critical task.</value>
public DelegateCommand<object> HighlightCriticalTask
{
get
{
return _highlightCriticalTask;
}
}
#endregion
#region Delegate Command Methods
/// <summary>
/// Called when [highlight task between clicked].
/// </summary>
/// <param name="parms">The parms.</param>
private void OnHighlightTaskBetweenClicked(object parms)
{
this.HighlightTaskItems = this.GetTasksBetween(this.StartTime, this.EndTime);
}
/// <summary>
/// Called when [highlight critical task clicked].
/// </summary>
/// <param name="parms">The parms.</param>
private void OnHighlightCriticalTaskClicked(object parms)
{
this.HighlightTaskItems = this.GetCriticalTasks();
}
/// <summary>
/// Determines whether this instance can excute the specified parms.
/// </summary>
/// <param name="parms">The parms.</param>
/// <returns>
/// <c>true</c> if this instance can excute the specified parms; otherwise, <c>false</c>.
/// </returns>
private bool CanExcute(object parms)
{
return true;
}
#endregion
/// <summary>
/// Gets the tasks between.
/// </summary>
/// <param name="Start">The start.</param>
/// <param name="End">The end.</param>
/// <returns></returns>
internal List<HighlightingTasksModel> GetTasksBetween(DateTime Start, DateTime End)
{
if (DateTime.MaxValue.Equals(Start) || DateTime.MaxValue.Equals(End) || DateTime.MinValue.Equals(Start) || DateTime.MinValue.Equals(End))
return null;
List<HighlightingTasksModel> tasks = new List<HighlightingTasksModel>();
this.GetTasksBetween(Start, End, this.TaskCollections, tasks);
return tasks;
}
/// <summary>
/// Gets the tasks between.
/// </summary>
/// <param name="start">The start.</param>
/// <param name="end">The end.</param>
/// <param name="source">The source.</param>
/// <param name="taskList">The task list.</param>
private void GetTasksBetween(DateTime start, DateTime end, ObservableCollection<HighlightingTasksModel> source, List<HighlightingTasksModel> taskList)
{
foreach (HighlightingTasksModel task in source)
{
if (task.StDate >= start && task.EndDate <= end)
taskList.Add(task);
if (task.ChildTask != null && task.ChildTask.Count > 0)
GetTasksBetween(start, end, task.ChildTask, taskList);
}
}
/// <summary>
/// Gets the critical tasks.
/// </summary>
/// <returns></returns>
internal List<HighlightingTasksModel> GetCriticalTasks()
{
List<HighlightingTasksModel> criticalTasks = new List<HighlightingTasksModel>();
criticalTasks.AddRange(this.TaskCollections[0].ChildTask[0].ChildTask[2].ChildTask);
criticalTasks.AddRange(this.TaskCollections[0].ChildTask[1].ChildTask);
criticalTasks.AddRange(this.TaskCollections[0].ChildTask[2].ChildTask);
return criticalTasks;
}
internal void Dispose()
{
if (HighlightTaskItems != null)
{
foreach (var highlightingTaskItem in HighlightTaskItems)
{
highlightingTaskItem.Dispose();
}
}
}
}
}