using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Telerik.Pivot.Core;
using Telerik.Windows.Controls;

namespace PivotDataTableLocalDataSourceProviderSDK
{
    public class ViewModel : ViewModelBase
    {
        private DataTable _ItemsSource;

        /// <summary>
        /// Gets or sets ItemsSource and notifies for changes
        /// </summary>
        public DataTable ItemsSource
        {
            get
            {
                return this._ItemsSource;
            }

            set
            {
                if (this._ItemsSource != value)
                {
                    this._ItemsSource = value;
                    this.OnPropertyChanged(() => this.ItemsSource);
                }
            }
        }
        public ViewModel()
        {
            this.ItemsSource = this.GenerateDataTable();
        }

        private DataTable GenerateDataTable()
        {
            var table = new DataTable();

            table.Columns.Add("Name", typeof(string));
            table.Columns.Add("Title", typeof(string));
            table.Columns.Add("Age", typeof(int));

            table.Columns[0].Caption = "Changed from code";

            var newRow = table.NewRow();
            newRow["Name"] = "Bob";
            newRow["Age"] = 1;
            newRow["Title"] = "Manager";
            table.Rows.Add(newRow);

            newRow = table.NewRow();
            newRow["Name"] = "Mike";
            newRow["Age"] = 10;
            newRow["Title"] = "Administrator";
            table.Rows.Add(newRow);

            newRow = table.NewRow();
            newRow["Name"] = "Brad";
            newRow["Age"] = 50;
            newRow["Title"] = "Manager";
            table.Rows.Add(newRow);

            newRow = table.NewRow();
            newRow["Name"] = "Gincho";
            newRow["Age"] = 60;
            newRow["Title"] = "Manager";
            table.Rows.Add(newRow);

            newRow = table.NewRow();
            newRow["Name"] = DBNull.Value;
            newRow["Age"] = 10;
            newRow["Title"] = "Administrator";
            table.Rows.Add(newRow);

            newRow = table.NewRow();
            newRow["Name"] = "Tinky";
            newRow["Age"] = DBNull.Value;
            newRow["Title"] = "Manager";
            table.Rows.Add(newRow);

            newRow = table.NewRow();
            newRow["Name"] = "Gupi";
            newRow["Age"] = 23;
            newRow["Title"] = DBNull.Value;
            table.Rows.Add(newRow);

            return table;
        }
    }
}
