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;

namespace CustomViews
{
    public partial class MainPage : UserControl, IDisposable
    {
        public MainPage()
        {
            InitializeComponent();
            sched1.ChangeStyle(sched1.WeekStyle);
        }
        private void btnToday_Click(object sender, C1.Silverlight.SourcedEventArgs e)
        {
            sched1.VisibleDates.BeginUpdate();
            sched1.VisibleDates.Clear();
            sched1.VisibleDates.Add(DateTime.Today);
            sched1.VisibleDates.EndUpdate();
        }

        // Change view from Month View mode to 2 Week mode if selection 
        // contains 2 full weeks.
        void sched1_BeforeViewChange(object sender, BeforeViewChangeEventArgs e)
        {
            if (e.Dates.Length == 14 && e.Style == sched1.MonthStyle)
            {
                Style s = (Style)this.Resources["TwoWeekStyle"];
                if (s != null)
                {
                    e.Style = s;
                }
            }
        }

        private void btnDay_Click(object sender, C1.Silverlight.SourcedEventArgs e)
        {
            sched1.ChangeStyle(sched1.OneDayStyle);
        }

        private void btnWorkWeek_Click(object sender, C1.Silverlight.SourcedEventArgs e)
        {
            sched1.ChangeStyle(sched1.WorkingWeekStyle);
        }

        private void btnWeek_Click(object sender, C1.Silverlight.SourcedEventArgs e)
        {
            sched1.ChangeStyle(sched1.WeekStyle);
        }
        
        private void btn2Week_Click(object sender, C1.Silverlight.SourcedEventArgs e)
        {
            sched1.ChangeStyle(Resources["TwoWeekStyle"]);
        }

        private void btnMonth_Click(object sender, C1.Silverlight.SourcedEventArgs e)
        {
            sched1.ChangeStyle(sched1.MonthStyle);
        }
        
        private void btnTimeLine_Click(object sender, C1.Silverlight.SourcedEventArgs e)
        {
            sched1.ChangeStyle(sched1.TimeLineStyle);
        }

        private void btnImport_Click(object sender, C1.Silverlight.SourcedEventArgs e)
        {
            C1Scheduler.ImportCommand.Execute(null, sched1);
        }

        private void btnExport_Click(object sender, C1.Silverlight.SourcedEventArgs e)
        {
            C1Scheduler.ExportCommand.Execute(null, sched1);
        }
        
        #region IDisposable Members

        public void Dispose()
        {
            menu.Close();
            sched1.Dispose();
        }

        #endregion

    }
}
