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
|
namespace WPFControls
{
/// <summary>
/// Interaction logic for JobTreatment.xaml
/// </summary>
public partial class JobList : System.Windows.Controls.UserControl
{
private ObservableCollection<Job> _ocJobs = new ObservableCollection<Job>();
PictureBox pictureBoxLoading;
public ObservableCollection<Job> OcJobs
{
get { return _ocJobs; }
set { _ocJobs = value; }
}
private int iJobInstanceID = 0;
//Constructor
public JobList()
{
InitializeComponent();
dgJob.ItemsSource = _ocJobs;
}
/// <summary>
/// Add a new Jod to the Datagrid
/// </summary>
/// <param name="target">Inform the user of the target of this job</param>
/// <param name="description">Description of the process running</param>
/// <returns></returns>
public Job AddJob(string target, string description)
{
//Use the dispatcher cause this function may be called from a thread, therefore it has to be executed in the Main UI thread
//If no dispatcher = exception
Dispatcher.Invoke(System.Windows.Threading.DispatcherPriority.Normal,
new Action(
delegate()
{
iJobInstanceID += 1;
_ocJobs.Add(new Job(iJobInstanceID, target, description));
}
));
return _ocJobs.Last();
}
/// <summary>
/// Add a new job to the datagrid
/// </summary>
/// <param name="Target"></param>
/// <param name="Description"></param>
/// <param name="jobStatus"></param>
public virtual void UpdateJob(string Target, string Description, Job.JobStatusValue jobStatus)
{
this.Dispatcher.Invoke(System.Windows.Threading.DispatcherPriority.Normal,
new Action(
delegate()
{
Job jobToUpdate = (Job)_ocJobs.First(job => job.Target == Target);
jobToUpdate.Description = Description;
jobToUpdate.Status = jobStatus;
_ocJobs.Remove(jobToUpdate);
_ocJobs.Add(jobToUpdate);
dgJob.Items.Refresh();
//Check if there is no more job running. If Yes, enable close button
int iJobNotDone = _ocJobs.Count(job => job.Status == Job.JobStatusValue.Running);
if (iJobNotDone == 0) btClose.IsEnabled = true;
}
));
//}
}
/// <summary>
/// Button closed (enabled once all job are not anymore in Running status)
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void btClose_Click(object sender, RoutedEventArgs e)
{
this.Content = null;
_ocJobs = null;
dgJob = null;
Window parentwin = Window.GetWindow(this.Parent);
//Dispatcher.InvokeShutdown();
parentwin.Close();
}
}
/// <summary>
/// The datagrid contains Job Objects (binding via XAML)
/// </summary>
public partial class Job
{
// declares the dufferent job status values
public enum JobStatusValue
{
NotStarted,
Running,
DoneSuccessfully,
DoneWarning,
DoneError,
}
int _ID;
JobStatusValue _status;
string _description;
BitmapImage _sImagePath;
public JobStatusValue Status
{
get { return _status; }
set { _status = value; UpdateJobImage(); }
}
public int ID
{
get { return _ID; }
set { _ID = value; }
}
string _target;
public string Target
{
get { return _target; }
set { _target = value; }
}
public string Description
{
get { return _description; }
set { _description = value; }
}
public BitmapImage ImagePath
{
get { return _sImagePath; }
set { _sImagePath = value; }
}
public Job(int IDJob, string target, string description)
{
_ID = IDJob;
_status = JobStatusValue.Running;
_target = target;
_description = description;
_sImagePath = null;
}
private void UpdateJobImage()
{
if (_status == JobStatusValue.DoneSuccessfully)
{
Uri uri = new Uri("pack://application:,,,/WPFControls;component/Resources/Actions-dialog-ok-apply-icon.png");
BitmapImage img = new BitmapImage(uri);
_sImagePath = img;
}
else if (_status == JobStatusValue.DoneWarning)
{
Uri uri = new Uri("pack://application:,,,/WPFControls;component/Resources/Actions-messagebox-warning-icon.png");
BitmapImage img = new BitmapImage(uri);
_sImagePath = img;
}
else if (_status == JobStatusValue.DoneError)
{
Uri uri = new Uri("pack://application:,,,/WPFControls;component/Resources/Actions-window-error-icon.png");
BitmapImage img = new BitmapImage(uri);
_sImagePath = img;
}
}
}
} |