using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using C1.Silverlight.Schedule;
using C1.C1Schedule;

namespace BusinessObjectsBinding
{
    public partial class MainPage : UserControl
    {
        public MainPage()
        {
            InitializeComponent();

        }

        private void UserControl_Loaded(object sender, RoutedEventArgs e)
        {
            // update toolbar buttons state
            sched1_StyleChanged(null, null);
        }
        
        private void btnToday_Click(object sender, RoutedEventArgs e)
        {
            sched1.VisibleDates.BeginUpdate();
            sched1.VisibleDates.Clear();
            sched1.VisibleDates.Add(DateTime.Today);
            sched1.VisibleDates.EndUpdate();
        }

        private void sched1_StyleChanged(object sender, RoutedEventArgs e)
        {
            // update toolbar buttons state according to the current C1Scheduler view
            if (sched1.Style == sched1.WorkingWeekStyle)
            {
                btnWorkWeek.IsChecked = true;
            }
            else if (sched1.Style == sched1.WeekStyle)
            {
                btnWeek.IsChecked = true;
            }
            else if (sched1.Style == sched1.MonthStyle)
            {
                btnMonth.IsChecked = true;
            }
            else if (sched1.Style == sched1.OneDayStyle)
            {
                btnDay.IsChecked = true;
            }
            else
            {
                btnTimeLine.IsChecked = true;
            }
        }

        private void ButtonAdd_Click(object sender, RoutedEventArgs e)
        {
            AppointmentBOList list = ((AppointmentsBO)this.Resources["_ds"]).Appointments;

            // add a new AppointmentBORow (that creates a new appointment in a C1Scheduler control)
            AppointmentBORow newObject = new AppointmentBORow();
            newObject.Subject = "The test business object " + list.Count.ToString();
            list.Add(newObject);
        }

        private void ButtonClear_Click(object sender, RoutedEventArgs e)
        {
            AppointmentBOList list = ((AppointmentsBO)this.Resources["_ds"]).Appointments;
            // clear the list of business objects (that clears all appointments from the C1Scheduler control)
            list.Clear();
        }

    }
}
