using System;
using System.Collections.Generic;
using System.Windows;
using System.Windows.Controls;
using BeWo.Core;
using BeWo.ServiceProxy;

using BS.Shared.DataContracts;
using BS.Shared.Extensions;

namespace BeWo.View.Report.Finance
{
    public partial class FinanceOverviewView : BeWoView
    {
		public FinanceOverviewView()
        {
            this.InitializeComponent();

			datePickerStartDate.DateTime = DateTime.MinValue;
			datePickerEndDate.DateTime = DateTime.MinValue;
			datePickerStartDate.DateTime = new DateTime(DateTime.Now.Year, DateTime.Now.Month, 1);
			datePickerEndDate.DateTime = new DateTime(DateTime.Now.Year, DateTime.Now.Month, 1).AddMonths(1).AddDays(-1);
        }


        private void buttonRefresh_Click(object sender, RoutedEventArgs e)
        {

			string url = String.Format("{0}/ReportView.aspx?type={1}&start={2:ddMMyyyy}&end={3:ddMMyyyy}", BeWoApp.SiteOfOrigin, ReportTypes.FinanceReport, datePickerStartDate.DateTime, datePickerEndDate.DateTime);

			var tempToken = string.Empty;
			ServiceFacade.DoDownloadServiceSync(s => tempToken = s.CreateTemporaryToken(url, true));
			string addChar = (url.Contains("?")) ? "&" : "?";
			url = url + addChar + "token=" + tempToken;

			url = BeWoWpfUtils.GetHTMLEncodedURL(url);

			BeWoUtils.NavigateToReportUri(url, "Finanzauswertung", docPrevControl);
        }

    }
}