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;

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

            // create olap page control, add it to the page
            var c1OlapPage = new C1.Silverlight.Olap.C1OlapPage();
            LayoutRoot.Children.Add(c1OlapPage);

            // load Invoices 
            var ctx = new RiaOlap.Web.DomainService1();
            var query = ctx.GetInvoicesQuery();     
            var loadOp = ctx.Load(query);

            // when data is loaded, assign it to the c1OlapPage
            loadOp.Completed += (s, e) =>
                {
                    if (loadOp.Error == null)
                    {
                        c1OlapPage.DataSource = loadOp.Entities;
                    }
                    else
                    {
                        MessageBox.Show("Error loading data: " + loadOp.Error.Message);
                    }
                };
        }
    }
}
