ComponentOne Scheduler for WPF and Silverlight
Scheduler for WPF Tutorials / Creating a Multi-User Schedule / Step 3 of 4: Adding the Code to your Application
In This Topic
    Step 3 of 4: Adding the Code to your Application
    In This Topic

    In this step you will add the code for your application.

    1. Right-click your application and select View Code from the list.
    2. Import the following namespaces:

      Visual Basic
      Copy Code
      Imports C1.WPF.Schedule
      Imports C1.C1Schedule
      Imports System.ComponentModel
      Imports System.Collections.Specialized
      

       

      C#
      Copy Code
      using C1.WPF.Schedule;
      using System.Collections.Specialized;
      using C1.C1Schedule;
      

       

    3. Above the public MainWindow() method, insert the following region:

      Visual Basic
      Copy Code
      #Region "** fields"
       Private appointmentsTableAdapter As MultiUser.NwindDataSetTableAdapters.AppointmentsTableAdapter = New NwindDataSetTableAdapters.AppointmentsTableAdapter()
       Private employeesTableAdapter As MultiUser.NwindDataSetTableAdapters.EmployeesTableAdapter = New NwindDataSetTableAdapters.EmployeesTableAdapter()
       Private customersTableAdapter As MultiUser.NwindDataSetTableAdapters.CustomersTableAdapter = New NwindDataSetTableAdapters.CustomersTableAdapter()
       Private dataSet As New NwindDataSet()
      #End Region
      

       

      C#
      Copy Code
      #region ** fields
       private MultiUserCS2.NwindDataSetTableAdapters.AppointmentsTableAdapter appointmentsTableAdapter = new NwindDataSetTableAdapters.AppointmentsTableAdapter();
       private MultiUserCS2.NwindDataSetTableAdapters.EmployeesTableAdapter employeesTableAdapter = new NwindDataSetTableAdapters.EmployeesTableAdapter();
       private MultiUserCS2.NwindDataSetTableAdapters.CustomersTableAdapter customersTableAdapter = new NwindDataSetTableAdapters.CustomersTableAdapter();
       private NwindDataSet dataSet = new NwindDataSet();
      #endregion
      

       

    4. Directly below the InitializeComponent() method, insert the following handlers and call to get data from the database:

      Visual Basic
      Copy Code
      AddHandler Scheduler.ReminderFire, AddressOf scheduler_ReminderFire
                     AddHandler Scheduler.GroupItems.CollectionChanged, AddressOf GroupItems_CollectionChanged
                     ' get data from the data base
                     Me.employeesTableAdapter.Fill(dataSet.Employees)
                     Me.customersTableAdapter.Fill(dataSet.Customers)
                     Me.appointmentsTableAdapter.Fill(dataSet.Appointments)
      

       

      C#
      Copy Code
      Scheduler.ReminderFire += new EventHandler<ReminderActionEventArgs>(scheduler_ReminderFire);
                  Scheduler.GroupItems.CollectionChanged += new NotifyCollectionChangedEventHandler(GroupItems_CollectionChanged);
                  // get data from the data base
                  this.employeesTableAdapter.Fill(dataSet.Employees);
                  this.customersTableAdapter.Fill(dataSet.Customers);
                 this.appointmentsTableAdapter.Fill(dataSet.Appointments);
      

       

    5. Set the mappings and DataSource for the AppointmentStorage:

      Visual Basic
      Copy Code
      Dim storage As AppointmentStorage = Scheduler.DataStorage.AppointmentStorage
                     storage.Mappings.AppointmentProperties.MappingName = "Properties"
                     storage.Mappings.Body.MappingName = "Description"
                     storage.Mappings.End.MappingName = "End"
                     storage.Mappings.IdMapping.MappingName = "AppointmentId"
                     storage.Mappings.Location.MappingName = "Location"
                     storage.Mappings.Start.MappingName = "Start"
                     storage.Mappings.Subject.MappingName = "Subject"
                     storage.Mappings.OwnerIndexMapping.MappingName = "Owner"
                     storage.DataSource = dataSet.Appointments
      

       

      C#
      Copy Code
      AppointmentStorage storage = Scheduler.DataStorage.AppointmentStorage;
                  storage.Mappings.AppointmentProperties.MappingName = "Properties";
                  storage.Mappings.Body.MappingName = "Description";
                  storage.Mappings.End.MappingName = "End";
                  storage.Mappings.IdMapping.MappingName = "AppointmentId";
                  storage.Mappings.Location.MappingName = "Location";
                  storage.Mappings.Start.MappingName = "Start";
                  storage.Mappings.Subject.MappingName = "Subject";
                  storage.Mappings.OwnerIndexMapping.MappingName = "Owner";
                  storage.DataSource = dataSet.Appointments;
      

       

    6. Set the mappings and DataSOurce for the OwnerStorage:

      Visual Basic
      Copy Code
      Dim ownerStorage As ContactStorage = Scheduler.DataStorage.OwnerStorage
                     AddHandler(CType(ownerStorage.Contacts, INotifyCollectionChanged)).CollectionChanged, AddressOf Owners_CollectionChanged
                     ownerStorage.Mappings.IndexMapping.MappingName = "EmployeeId"
                     ownerStorage.Mappings.TextMapping.MappingName = "FirstName"
                     ownerStorage.DataSource = dataSet.Employees
      

       

      C#
      Copy Code
      ContactStorage ownerStorage = Scheduler.DataStorage.OwnerStorage;            ((INotifyCollectionChanged)ownerStorage.Contacts).CollectionChanged += new NotifyCollectionChangedEventHandler(Owners_CollectionChanged);
                  ownerStorage.Mappings.IndexMapping.MappingName = "EmployeeId";
                  ownerStorage.Mappings.TextMapping.MappingName = "FirstName";
                  ownerStorage.DataSource = dataSet.Employees;
      

       

    7. Set the mappings and DataSource for the ContactStorage:

      Visual Basic
      Copy Code
      Dim cntStorage As ContactStorage = Scheduler.DataStorage.ContactStorage
                     AddHandler(CType(cntStorage.Contacts, INotifyCollectionChanged)).CollectionChanged, AddressOf Contacts_CollectionChanged
                     cntStorage.Mappings.IdMapping.MappingName = "CustomerId"
                     cntStorage.Mappings.TextMapping.MappingName = "CompanyName"
                     cntStorage.DataSource = dataSet.Customers
                     btnDay.IsChecked = True
                     AddHandler Scheduler.StyleChanged, AddressOf Scheduler_StyleChanged
      

       

      C#
      Copy Code
      // set mappings and DataSource for the ContactStorage
                  ContactStorage cntStorage = Scheduler.DataStorage.ContactStorage;
      ((INotifyCollectionChanged)cntStorage.Contacts).CollectionChanged += new NotifyCollectionChangedEventHandler(Contacts_CollectionChanged);
                  cntStorage.Mappings.IdMapping.MappingName = "CustomerId";
                  cntStorage.Mappings.TextMapping.MappingName = "CompanyName";
                  cntStorage.DataSource = dataSet.Customers;
                  btnDay.IsChecked = true;
                  Scheduler.StyleChanged += new System.EventHandler<RoutedEventArgs>(Scheduler_StyleChanged);