SimpleScheduleDataProvider dataProvider = new SimpleScheduleDataProvider();
dataProvider.MasterList = SimpleScheduleDataProvider.InitializeRandomData();
scheduleControl1.DataSource = dataProvider;
public class SimpleScheduleDataProvider : ScheduleDataProvider
{
DataSet dset = new DataSet();
static DataTable dt = new DataTable();
/// <summary>
/// Default constructor.
/// </summary>
public SimpleScheduleDataProvider()
: base()
{
dset.ReadXml(@"..\..\default.xml");
dt = dset.Tables["MasterList"];
}
private SimpleScheduleAppointmentList masterList;
/// <summary>
/// Get or sets an IScheduleAppointmentList collection that holds the IScheduleAppointments.
/// </summary>
public SimpleScheduleAppointmentList MasterList
{
get{return masterList;}
set{masterList = value;}
}
#region random data
public static SimpleScheduleAppointmentList InitializeRandomData()
{
Random r = new Random(tc);
// set the number of sample items you want in this list.
int count = dt.Rows.Count;
SimpleScheduleAppointmentList masterList = new SimpleScheduleAppointmentList();
for (int i = 0; i < count; ++i)
{
ScheduleAppointment item = masterList.NewScheduleAppointment() as ScheduleAppointment;
int dayOffSet = 30 - r.Next(60);
int hourOffSet = 24 - r.Next(48);
int len = 30 * (r.Next(4) + 1);
item.StartTime = DateTime.Now.AddDays(i);
item.EndTime = DateTime.Now.AddDays(i); item.Subject = dt.Rows[i]["Subject"].ToString();
item.Content = dt.Rows[i]["Content"].ToString();
item.LabelValue = Convert.ToInt16(dt.Rows[i]["LabelValue"]);
item.LocationValue = dt.Rows[i]["LocationValue"].ToString();
item.MarkerValue = (Convert.ToInt16(dt.Rows[i]["MarkerValue"]));
item.UniqueId = i;
item.Dirty = false;
masterList.Add(item);
}
masterList.SortStartTime();
return masterList;
}
} |
this.scheduleControl1.ItemChanged += ScheduleControl1_ItemChanged;
private void ScheduleControl1_ItemChanged(object sender, ScheduleAppointmentEventArgs e)
{
if (e.Action == ItemAction.Edit)
{
int id = e.CurrentItem.UniqueID;
var dr = SimpleScheduleDataProvider.dt.Rows.Cast<DataRow>().First(x => x[10].Equals(e.CurrentItem.UniqueID.ToString()));
int index = SimpleScheduleDataProvider.dt.Rows.IndexOf(dr as DataRow);
if (index > -1)
{
dr[0] = e.CurrentItem.StartTime;
dr[1] = e.CurrentItem.EndTime;
dr[2] = e.CurrentItem.Subject;
dr[3] = e.CurrentItem.AllDay;
dr[4] = e.CurrentItem.Content;
dr[5] = e.CurrentItem.LabelValue;
dr[6] = e.CurrentItem.MarkerValue;
dr[7] = e.CurrentItem.Reminder;
dr[8] = e.CurrentItem.ReminderValue;
dr[9] = e.CurrentItem.LocationValue;
dr[10] = e.CurrentItem.UniqueID;
}
}
} |
//In SimpleScheduleDataProvider class
public override void AddItem(IScheduleAppointment item)
{
DataRow dr = dt.NewRow();
dr[0] = item.StartTime;
dr[1] = item.EndTime;
dr[2] = item.Subject;
dr[3] = item.AllDay;
dr[4] = item.Content;
dr[5] = item.LabelValue;
dr[6] = item.MarkerValue;
dr[7] = item.Reminder;
dr[8] = item.ReminderValue;
dr[9] = item.LocationValue;
dr[10] = item.UniqueID;
dt.Rows.Add(dr);
this.MasterList.Add(item);
} |
//In SimpleScheduleDataProvider class
public override void RemoveItem(IScheduleAppointment item)
{
var row = dt.Rows.Cast<DataRow>().First(x => x[10].Equals(item.UniqueID.ToString()));
int index = dt.Rows.IndexOf(row as DataRow);
if (index>-1)
{
dt.Rows.RemoveAt(index);
}
this.MasterList.Remove(item);
} |