using BusinessLayer;
using DTO;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Telerik.Web.UI;

namespace NikaiDSR.Executive
{
    public partial class DSRReport : PageBase
    {
        #region declare
        ReportManager rm = new ReportManager();
        #endregion

        protected void Page_Load(object sender, EventArgs e)
        {
            Grid.GridExporting += new OnGridExportingEventHandler(RadGrid1_GridExporting);

            if (!Page.IsPostBack)
            {
                PageTitle = "NIKAI- DSR REPORT";
                lblDate.Text = DateTime.Now.ToShortDateString();

                fillActualsTargetsData();
               
                if (LanguageId == 27)
                {
                    Grid.MasterTableView.GetColumn("Customer_Name_BL").Display = true;
                    Grid.MasterTableView.GetColumn("Contact_Name_BL").Display = true;
                    Grid.MasterTableView.GetColumn("Department_BL").Display = true;
                }
                else
                {
                    Grid.MasterTableView.GetColumn("Customer_Name").Display = true;
                    Grid.MasterTableView.GetColumn("Contact_Name").Display = true;
                    Grid.MasterTableView.GetColumn("Department").Display = true;
                }
            }
        }

        private void fillActualsTargetsData()
        {
            ExecutiveTargetsActualsDTO ExecutiveTargetsActuals = rm.GetExecutiveTargetsActuals(DateTime.Now, UserID);
            if (ExecutiveTargetsActuals != null)
            {
                lblCollection_Actual.Text = ExecutiveTargetsActuals.Collection_Actual.ToString();
                lblCollecion_Target.Text = ExecutiveTargetsActuals.Collection_Target.ToString();
                lblLPO_Actual.Text = ExecutiveTargetsActuals.Lpo_Actual.ToString();
                lblLPO_Target.Text = ExecutiveTargetsActuals.Lpo_Target.ToString();
                lblSecondary_Sales_Actual.Text = ExecutiveTargetsActuals.Secondary_Sales_Actual.ToString();
                lblSecondary_Sales_Target.Text = ExecutiveTargetsActuals.Secondary_Sales_Target.ToString();
            }
        }
        protected void Grid_ItemDataBound(object sender, Telerik.Web.UI.GridItemEventArgs e)
        {
            if (e.Item is GridDataItem)
            {
                GridDataItem item = (GridDataItem)e.Item;
            }
        }

        protected void Grid_NeedDataSource(object sender, Telerik.Web.UI.GridNeedDataSourceEventArgs e)
        {
            Grid.DataSource = rm.GetExecutiveReport(Convert.ToDateTime(lblDate.Text), UserID);
        }

        #region Export Report

        protected void Radgrid1_ItemCommand(object sender, GridCommandEventArgs e)
        {
            if (e.CommandName == RadGrid.ExportToExcelCommandName)
            {
                
                Grid.ExportSettings.FileName = "Daily_Sales_Report";
            }
        }

        protected void RadGrid1_GridExporting(object source, GridExportingArgs e)
        {
            if (e.ExportType == ExportType.Excel)
            {
                Grid.ExportSettings.FileName = "asdasds";
                string customText = (string)GetGlobalResourceObject("Res", "Daily_Sales_Report");
                ExcelHeader(e, customText);
            }
        }

        #endregion

    }
}