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 ReportViewerWithC1Report
{
    public partial class MainPage : UserControl
    {
        public MainPage()
        {
            InitializeComponent();

            // populate combo with report list
            var svc = new C1ReportServiceReference.C1ReportServiceClient();
            svc.GetReportListAsync();
            svc.GetReportListCompleted += (s, e) =>
                {
                    _cmbReports.ItemsSource = e.Result;
                };
        }

        private void _cmbReports_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            // get report as PDF stream
            var svc = new C1ReportServiceReference.C1ReportServiceClient();
            svc.GetReportAsync((string)_cmbReports.SelectedValue);
            svc.GetReportCompleted += (s, re) =>
                {
                    // pass PDF stream to the viewer
                    var ms = new System.IO.MemoryStream(re.Result);
                    _c1rv.LoadDocument(ms);
                };
        }
    }
}
