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 Telerik.Windows.Controls;
using Telerik.Windows.Data;
using System.Windows.Data;

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

            xRadTimeBar.MinSelectionRange = TimeSpan.FromHours(1);
            xRadTimeBar.MaxSelectionRange = TimeSpan.FromDays(14);
            xRadTimeBar.MinZoomRange = TimeSpan.FromHours(1);

            xRadChart.DefaultView.ChartArea.EnableAnimations = false;
            xRadChart.DefaultView.ChartArea.EnableTransitionAnimations = true;

            xRadChart.DefaultView.ChartArea.AxisX.LabelStep = 5;
            xRadChart.DefaultView.ChartArea.AxisX.IsDateTime = true;
            xRadChart.DefaultView.ChartArea.AxisX.StepLabelLevelCount = 3;

            xRadChart.DefaultView.ChartArea.ZoomScrollSettingsX.MinZoomRange = .02d;
            xRadChart.DefaultView.ChartArea.ZoomScrollSettingsX.ScrollMode = Telerik.Windows.Controls.Charting.ScrollMode.ScrollAndZoom;
        }

        private void xRadTimeBar_SelectionChanged(object sender, Telerik.Windows.RadRoutedEventArgs e)
        {
            if (xRadTimeBar == null)
                return;

            xRadGridView.FilterDescriptors.Clear();

            CompositeFilterDescriptor compositeDescriptor = new CompositeFilterDescriptor();

            compositeDescriptor.LogicalOperator = FilterCompositionLogicalOperator.And;

            compositeDescriptor.FilterDescriptors.Add(
                new FilterDescriptor("datadate", FilterOperator.IsGreaterThanOrEqualTo, 
                    xRadTimeBar.SelectionStart));

            compositeDescriptor.FilterDescriptors.Add(
                new FilterDescriptor("datadate", FilterOperator.IsLessThanOrEqualTo, 
                    xRadTimeBar.SelectionEnd));

            xRadGridView.FilterDescriptors.Add(compositeDescriptor);
        }
    }
}
