using System;
using System.ComponentModel;
using System.Windows.Forms;
namespace Microsoft.Win32.TaskScheduler
{
///
/// Control that will display the run times for a provided task.
///
[System.Drawing.ToolboxBitmap(typeof(Microsoft.Win32.TaskScheduler.TaskEditDialog), "TaskControl")]
public partial class TaskRunTimesControl : UserControl, ISupportInitialize
{
private bool initializing = false;
private bool isTemp = false;
private Task task;
///
/// Initializes a new instance of the class.
///
public TaskRunTimesControl()
{
initializing = true;
InitializeComponent();
initializing = false;
}
///
/// Gets or sets the end date.
///
/// The end date.
[Category("Data")]
public DateTime EndDate
{
get { return endDatePicker.Value; }
set { endDatePicker.Value = value; }
}
///
/// Gets or sets the start date.
///
/// The start date.
[Category("Data")]
public DateTime StartDate
{
get { return startDatePicker.Value; }
set { startDatePicker.Value = value; }
}
///
/// Gets or sets the task.
///
/// The task.
[Browsable(false), DefaultValue((Task)null)]
public Task Task
{
get
{
return task;
}
set
{
task = value;
this.Text = task == null ? null : string.Format(EditorProperties.Resources.TaskRunTimesDialogTitle, value.Name);
isTemp = task == null ? false : task.Name.StartsWith(TaskPropertiesControl.runTimesTempTaskPrefix) && task.Name.Length == (TaskPropertiesControl.runTimesTempTaskPrefix.Length + Guid.NewGuid().ToString().Length);
if (!initializing)
Fetch();
}
}
///
/// Signals the object that initialization is starting.
///
public void BeginInit()
{
initializing = true;
}
///
/// Signals the object that initialization is complete.
///
public void EndInit()
{
initializing = false;
Fetch();
}
///
/// Initializes an instance of the class.
///
/// The task to display.
/// The date to begin looking for run times.
/// The date to end looking for run times.
public void Initialize(Task task = null, DateTime? startDate = null, DateTime? endDate = null)
{
BeginInit();
if (startDate.HasValue)
this.StartDate = startDate.Value;
if (endDate.HasValue)
this.EndDate = endDate.Value;
this.Task = task;
EndInit();
}
private void dateValueChanged(object sender, EventArgs e)
{
if (!initializing)
Fetch();
}
private void Fetch()
{
if (task == null)
listBox1.DataSource = null;
else
{
if (isTemp) task.Enabled = true;
listBox1.DataSource = task.GetRunTimes(this.StartDate, this.EndDate);
if (isTemp) task.Enabled = false;
}
}
internal bool ShouldSerializeEndDate()
{
return endDatePicker.ShouldSerializeValue();
}
internal bool ShouldSerializeStartDate()
{
return startDatePicker.ShouldSerializeValue();
}
private void label1_Click(object sender, EventArgs e)
{
}
}
}