- Create a new VS 2010/2012
WPF Application targeting .NET Framework 4 Client
Profile.
-
Instance the dbiScheduleWPF
control in the main form.
-
Add a reference to the
dbiScheduleWPFDB.dll assembly. NOTE: By default this
would be in the Components directory of the installed
Solutions Schedule for WPF files.
-
In the dbiScheduleWPF tags in
the XAML, set the ListTitle property of the
dbiScheduleWPF instance to reflect the type of resource
being scheduled and set the SnapToDivisions property to
Absolute...
example...
<my:dbiScheduleWPF Margin="18,14,46,15"
Name="dbiScheduleWPF1" ListTitle="Meeting Rooms"
SnapToDivisions="Absolute" />
-
Add the resources to be
scheduled to the XAML inside the dbiScheduleWPF tags.
example ...
<my:dbiScheduleWPF.Items>
<my:dbiListItem>
<my:dbiListItem.Cells>
<my:dbiListCell Text="Meeting Room 1"/>
</my:dbiListItem.Cells>
</my:dbiListItem>
<my:dbiListItem>
<my:dbiListItem.Cells>
<my:dbiListCell Text="Meeting Room 2"/>
</my:dbiListItem.Cells>
</my:dbiListItem>
<my:dbiListItem>
<my:dbiListItem.Cells>
<my:dbiListCell Text="Meeting Room 3"/>
</my:dbiListItem.Cells>
</my:dbiListItem>
</my:dbiScheduleWPF.Items>
-
Add a schedule object to the
dbiScheduleWPF instance in the XAML for the current day
to run from 8:00 am to 6:00 pm showing increments of 15
minutes (RulerDivisions = 4)...
example...
<my:dbiScheduleWPF.Schedules>
<my:dbiScheduleObject Start="12/12/2012 8:00 am"
End="12/12/2012 6:00 pm" RulerAlign="Over"
TimeType="Hours" RulerDivisions="4"
DisplayTimeLines="True" />
</my:dbiScheduleWPF.Schedules>
-
Add a Date Picker Control, one
Button control (content = "Save"), and another Button
control (content = "Load") to the main form. Set the
Load button to be disabled.
-
In the code behind create a
private variable of type dbiScheduleWPFDB in the form’s
class.
example...
[VB.NET]
Private myScheduleXMLDB As
dbiScheduleWPFDB.dbiScheduleWPFDB
[C#]
private dbiScheduleWPFDB.dbiScheduleWPFDB
myScheduleXMLDB;
-
In the code behind in the
New() event, create an instance of the dbiScheduleWPFDB
class hooked to the dbiScheduleWPF instance in the
assembly.
example...
[VB.NET]
myScheduleXMLDB = New
dbiScheduleWPFDB.dbiScheduleWPFDB(Me.DbiScheduleWPF1)
[C#]
myScheduleXMLDB = new
dbiScheduleWPFDB.dbiScheduleWPFDB(dbiScheduleWPF1);
-
Add the code to Save and Load
the contents of the schedule to/from the application’s
running directory. NOTE: In the Load button code, the
Date Picker is set to the start date of the first
schedule in the schedules collection
NOTE: In the Save button code, the Load button is
enabled if the Save is successful.
In the click event of the button marked "Save"...
[VB.NET]
Dim saveError As System.Exception =
myScheduleXMLDB.SaveAll2XMLDB
If saveError Is Nothing Then
MessageBox.Show("Schedule Saved to XML in " +
myScheduleXMLDB.StorageDatabaseDirectory )
Me.buttonLoad.IsEnabled = True
Else
MessageBox.Show("Schedule Save to XML Database Failed. "
+ saveError.Message)
End If
[C#]
System.Exception saveError =
myScheduleXMLDB.SaveAll2XMLDB() ;
if (saveError == null)
{
MessageBox.Show("Schedule Saved to XML in " +
myScheduleXMLDB.StorageDatabaseDirectory);
this.buttonLoad.IsEnabled = true;
}
else
{
MessageBox.Show("Schedule Save to XML Database Failed. "
+ saveError.Message);
}
-
In the Click() event of the
button marked "Load"...
[VB.NET]
Dim loadError As System.Exception =
myScheduleXMLDB.LoadAllFromXMLDB
If loadError Is Nothing Then
Me. datePicker1.SelectedDate =
Me.DbiScheduleWPF1.Schedules(0).Start.Date
Me. datePicker1.DisplayDate =
Me.DbiScheduleWPF1.Schedules(0).Start.Date
MessageBox.Show("Schedule loaded from XML in " +
myScheduleXMLDB.StorageDatabaseDirectory)
Else
MessageBox.Show("Schedule Load from " +
myScheduleXMLDB.StorageDatabaseDirectory + " failed ...
" + vbCrLf + loadError.Message)
End If
[C#]
System.Exception loadError;
loadError = myScheduleXMLDB.LoadAllFromXMLDB();
if (loadError== null)
{
this.datePicker1.DisplayDate =
this.dbiScheduleWPF1.Schedules[0].Start.Date;
this.datePicker1.SelectedDate =
this.dbiScheduleWPF1.Schedules[0].Start.Date;
MessageBox.Show("Schedule loaded from XML in " +
myScheduleXMLDB.StorageDatabaseDirectory);
}
else
{
MessageBox.Show("Schedule Load from " +
myScheduleXMLDB.StorageDatabaseDirectory + " failed ...
" + Environment.NewLine + loadError.Message);
}
-
Add the code to sync up the
calendar control with the schedule being presented in
the dbiScheduleWPF control when the user clicks on a
date in the date picker (DatePicker
->SelectedDateChanged).
[VB.NET]
Private Sub datePicker1_SelectedDateChanged(sender As
System.Object, e As
System.Windows.Controls.SelectionChangedEventArgs)
Me.dbiScheduleWPF1.Schedules(0).Start =
Me.datePicker1.SelectedDate.Value.AddHours(8)
Me.dbiScheduleWPF1.Schedules(0).End =
Me.datePicker1.SelectedDate.Value.AddHours(18)
End Sub
[C#]
private void datePicker1_SelectedDateChanged(object
sender, SelectionChangedEventArgs e)
{
this.dbiScheduleWPF1.Schedules[0].Start =
this.datePicker1.SelectedDate.Value.AddHours(8);
this.dbiScheduleWPF1.Schedules[0].End =
this.datePicker1.SelectedDate.Value.AddHours(18);
}
-
Add the code to set the date
picker control to date of the schedule object loaded in
to the dbiScheduleWPF control when the application
starts using the dbiScheduleWPF->FirstDraw event...
[VB.NET]
Private Sub dbiScheduleWPF1_FirstDraw(sender As
System.Object, e As
Dbi.WpfControl.dbiSchedule.FirstDrawEventArgs)
Me.datePicker1.SelectedDate =
Me.dbiScheduleWPF1.Schedules(0).Start.Date
End Sub
[C#]
private void dbiScheduleWPF1_FirstDraw(object sender,
Dbi.WpfControl.dbiSchedule.FirstDrawEventArgs e)
{
this.datePicker1.SelectedDate =
this.dbiScheduleWPF1.Schedules[0].Start.Date;
}
-
Run
the application.