using System;
using System.Data;
using System.Globalization;
using System.IO;
using System.Resources;
using System.Threading;
using CrystalDecisions.CrystalReports.Engine;
using CrystalDecisions.ReportSource;
using CrystalDecisions.Shared;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class Reports_TA_UI_Report_Graphical_View : System.Web.UI.Page
{
    #region Variable Declaration
    ResourceManager rm;
    CultureInfo ci;
    cls_Common objCommon = new cls_Common();
    ReportDocument rptDoc = new ReportDocument();
    GetReports rptEmp = new GetReports();
    HeaderInformation hdrTable = new HeaderInformation();
    Rpt_Common rptcommon = new Rpt_Common();
    EmailConfiguration objEmailConfiguration = new EmailConfiguration();
    int shft = 0, absentType = 0, EmployeeCategory = 0, EmployeeType = 0, NoOfDays, Designation, AllSwipesReportType, RawDataDashboard, ProcessType = 0;
    string rptFileName, Level = string.Empty, employeeName = string.Empty, empName = string.Empty, empId = string.Empty;
    int ParentLevelid = 0;
    string dtFrom, dtTo, UserGroupName, GradeLevel, ReportName, Normal, Status, LeaveType, MinWorkHours, EmpStatus, TableDescription, Operation, MonthClosureId, YearSettingsId;
    string strSwipOpt = "", strSwipeCard = "", strMaxDeviationHrs = string.Empty, strPunchType = string.Empty;
    string Gender = string.Empty, ReportType = string.Empty, TotalDays = string.Empty, OverTimeReportType = string.Empty, LeaveReportType = string.Empty, SanctionType = string.Empty, SummaryOrDetail = string.Empty; string strReportType = string.Empty; string dtIntime, dtOutTime;
    string strEmpAutoId = "0", MinExceptHours;
    string ReportHeaderName = string.Empty;
    int chkunplan = 0;
    int MonthlydataLoading = 0;
    string punchTypeValue = "All";
    Boolean blnCheckDataExits = true;
    int Shift = 0;
    #endregion
    #region PageLoad
    protected void Page_Load(object sender, EventArgs e)
    {
        Level = Request.QueryString["Level"];
        employeeName = Request.QueryString["EmpName"];
        employeeName = employeeName.Replace("%", " ");
        employeeName = employeeName.Replace("''", "'");
        empId = Request.QueryString["empid"];
        dtFrom = Request.QueryString["dtFrom"];
        dtTo = Request.QueryString["dtTo"];
        EmployeeCategory = Convert.ToInt32(Request.QueryString["EmpCategory"]);
        EmployeeType = Convert.ToInt32(Request.QueryString["EmpType"]);
        string str = Convert.ToString(Request.QueryString["ParentLevelId"]);
        if (str == "" || str == string.Empty)
        {
            ParentLevelid = 0;
        }
        else
        {
            ParentLevelid = Convert.ToInt16(str);
        }
        UserGroupName = Request.QueryString["UserGroupName"];
        GradeLevel = Request.QueryString["GradeLevel"];
        ReportName = Request.QueryString["ReportName"];
        TotalDays = Request.QueryString["TotalDays"];
        strMaxDeviationHrs = Convert.ToString(Request.QueryString["MaxDeviationHrs"]);
        strPunchType = Convert.ToString(Request.QueryString["PunchType"]);
        if (Request.QueryString["absentType"] != null)
        {
            absentType = Convert.ToInt16(Request.QueryString["absentType"]);
        }
        if (Session["ReportsBasedOn"] != null)
        {
            if (Convert.ToString(Session["ReportsBasedOn"]) == "False")
            {
                strEmpAutoId = "0";
            }
            else
            {
                strEmpAutoId = Convert.ToString(Session["EmpAutoID"]);
            }
        }
        if (Request.QueryString["ProcessType"] != null)
        {
            ProcessType = Convert.ToInt16(Request.QueryString["ProcessType"]);
        }
        if (Request.QueryString["Planned"] != null)
        {
            chkunplan = Convert.ToInt32(Request.QueryString["Planned"]);
        }
        if (Request.QueryString["SanctionType"] != null)
        {
            SanctionType = Convert.ToString(Request.QueryString["SanctionType"]);
        }
        if (Request.QueryString["ReportType"] != null)
        {
            ReportType = Convert.ToString(Request.QueryString["ReportType"]);
        }
        if (Request.QueryString["AllSwipesReportType"] != null)
        {
            AllSwipesReportType = Convert.ToInt32(Request.QueryString["AllSwipesReportType"]);
        }
        if (Request.QueryString["OverTimeReportType"] != null)
        {
            OverTimeReportType = Convert.ToString(Request.QueryString["OverTimeReportType"]);
        }
        if (Request.QueryString["LeaveReportType"] != null)
        {
            LeaveReportType = Convert.ToString(Request.QueryString["LeaveReportType"]);
        }
        if (Request.QueryString["OutTime"] != null)
        {
            dtOutTime = Request.QueryString["OutTime"];
        }
        if (Request.QueryString["InTime"] != null)
        {
            dtIntime = Request.QueryString["InTime"];
        }
        if (Request.QueryString["MinExceptHours"] != null)
        {
            MinExceptHours = Request.QueryString["MinExceptHours"];
        }
        Gender = Request.QueryString["Gender"];
        Designation = Convert.ToInt32(Request.QueryString["Designation"]);
        if (Request.QueryString["SwipOpt"] != null)
        {
            strSwipOpt = Convert.ToString(Request.QueryString["SwipOpt"]);
        }
        if (Request.QueryString["SwipeCard"] != null)
        {
            strSwipeCard = Convert.ToString(Request.QueryString["SwipeCard"]);
        }
        if (Request.QueryString["MonthlydataLoadingVer"] != null)
        {
            MonthlydataLoading = Convert.ToInt32(Request.QueryString["MonthlydataLoadingVer"]);
        }
        if (Request.QueryString["punchTypeValue"] != null)
        {
            punchTypeValue = Convert.ToString(Request.QueryString["punchTypeValue"]);
        }
        if (Request.QueryString["RawDataDashboard"] != null)
        {
            RawDataDashboard = Convert.ToInt16(Request.QueryString["RawDataDashboard"]);
        }
        if (Request.QueryString["ReportHeaderName"] != null)
        {
            ReportHeaderName = Convert.ToString(Request.QueryString["ReportHeaderName"]);
        }
        if (!IsPostBack)
        {
            if (ReportName != string.Empty)
            {
                if (ReportName == "Absentees")
                {
                    ListItem lstItem1 = new ListItem();
                    lstItem1.Value = "0";
                    lstItem1.Text = "Spline Chart";
                    ddlReportType.Items.Insert(0, lstItem1);
                    ListItem lstItem2 = new ListItem();
                    lstItem2.Value = "2";
                    lstItem2.Text = "Pie Chart";
                    ddlReportType.Items.Insert(1, lstItem2);
                    ListItem lstItem3 = new ListItem();
                    lstItem3.Value = "3";
                    lstItem3.Text = "Doughnut Chart";
                    ddlReportType.Items.Insert(2, lstItem3);
                    //SplineChart.Attributes.Add("display", "black");

                }
                else if (ReportName == "Punctuality")
                {
                    ListItem lstItem1 = new ListItem();
                    lstItem1.Value = "0";
                    lstItem1.Text = "Spline Chart";
                    ddlReportType.Items.Insert(0, lstItem1);
                    ListItem lstItem2 = new ListItem();
                    lstItem2.Value = "1";
                    lstItem2.Text = "Spline Area Chart";
                    ddlReportType.Items.Insert(1, lstItem2);
                }
                else if (ReportName == "SummaryReport")
                {
                    ListItem lstItem1 = new ListItem();
                    lstItem1.Value = "0";
                    lstItem1.Text = "Cloumn Chart";
                    ddlReportType.Items.Insert(0, lstItem1);
                    ListItem lstItem2 = new ListItem();
                    lstItem2.Value = "1";
                    lstItem2.Text = "Spline Chart";
                    ddlReportType.Items.Insert(1, lstItem2);
                }
                else if (ReportName == "Discrepancy")
                {
                    ListItem lstItem1 = new ListItem();
                    lstItem1.Value = "0";
                    lstItem1.Text = "Spline Area Chart";
                    ddlReportType.Items.Insert(0, lstItem1);
                    ListItem lstItem2 = new ListItem();
                    lstItem2.Value = "1";
                    lstItem2.Text = "Cloumn Chart";
                    ddlReportType.Items.Insert(1, lstItem2);
                }
                else
                {
                    ListItem lstItem1 = new ListItem();
                    lstItem1.Value = "0";
                    lstItem1.Text = "Spline Chart";
                    ddlReportType.Items.Insert(0, lstItem1);
                    ListItem lstItem2 = new ListItem();
                    lstItem2.Value = "1";
                    lstItem2.Text = "Cloumn Chart";
                    ddlReportType.Items.Insert(1, lstItem2);
                }

            }
        }
        Level = rptcommon.getNodes(Convert.ToInt16(ParentLevelid), Convert.ToString(Session["LevelRights"]));
        string strMsg;
        loadcss();
        strMsg = "<script language='javascript'>";
        strMsg = strMsg + "ajaxGetGraphicalReport('" + ReportName + "','" + dtFrom + "','" + dtTo + "','" + empName + "','" + empId + "','" + Level + "'," + EmployeeCategory + "," + EmployeeType + "," + ParentLevelid + ",'" + UserGroupName + "'," + GradeLevel + ",'" + strSwipeCard + "'," + Designation + ",'" + Gender + "'," + Shift + ",'" + ReportType + "'," + GradeLevel + "," + absentType + ",'" + ReportHeaderName + "','" + MinExceptHours + "'); ";

        strMsg = strMsg + "</script>";
        Page.RegisterStartupScript("Re", strMsg);
    }
    #endregion
    #region ButtonEvents
    protected void ddlReportType_SelectedIndexChanged(object sender, EventArgs e)
    {
        if (ddlReportType.SelectedValue == "0")
        {
            SplineChart.Attributes.Add("display", "block");
            PieChart.Attributes.Add("display", "none");
            DoughnutChart.Attributes.Add("display", "none");
            CloumnChart.Attributes.Add("display", "none");
        }
        else if (ddlReportType.SelectedValue == "1")
        {
            SplineChart.Attributes.Add("display", "none");
            PieChart.Attributes.Add("display", "none");
            DoughnutChart.Attributes.Add("display", "none");
            CloumnChart.Attributes.Add("display", "block");
        }
        else if (ddlReportType.SelectedValue == "2")
        {
            SplineChart.Attributes.Add("display", "none");
            PieChart.Attributes.Add("display", "block");
            DoughnutChart.Attributes.Add("display", "none");
            CloumnChart.Attributes.Add("display", "none");
        }
        else if (ddlReportType.SelectedValue == "3")
        {
            SplineChart.Attributes.Add("display", "none");
            PieChart.Attributes.Add("display", "none");
            DoughnutChart.Attributes.Add("display", "block");
            CloumnChart.Attributes.Add("display", "none");
        }

    }
    protected void btnback_Click(object sender, EventArgs e)
    {

        if (ReportName != string.Empty)
        {
            if (ReportName == "Absentees")
            {
                Response.Redirect("TA_UI_Report_Absentes.aspx");
            }
            else if (ReportName == "Punctuality")
            {
                Response.Redirect("TA_UI_Report_Punctuality.aspx");
            }
            else if (ReportName == "SummaryReport")
            {
                Response.Redirect("TA_UI_Report_Summary.aspx");
            }
            else if (ReportName == "Discrepancy")
            {
                Response.Redirect("TA_UI_Report_Discrepancy.aspx");
            }
            else
            {
                Response.Redirect("TA_UI_Report_LateInstance.aspx");
            }

        }
    }
    #endregion
    #region UserDefinedFunctions
    private void loadcss()
    {
        CultureInfo ci;
        string source_Language;
        source_Language = Convert.ToString(Session["Session_ActiveLanguage"]);
        rm = new ResourceManager(source_Language, System.Reflection.Assembly.Load("App_GlobalResources"));
        ci = Thread.CurrentThread.CurrentCulture;
        //if Standard Demo
        //htmlGraphical.Attributes.Add("dir", rm.GetString("Direction", ci));
        if (source_Language == "Resources.Resource_AR")
        {
            stylebootstrap.Href = "../bootstrap/css/bootstrap-rtl.min.css";
            stylefontawesome.Href = "../bootstrap/font-awesome/css/font-awesome-rtl.css";
            styleAdminLTE.Href = "../dist/css/AdminLTE.min-rtl.css";
            stylecustom.Href = "../dist/css/custom-rtl.css";
            stylefonts.Href = "../dist/css/fonts.css";
            //stylebootstrap.Href = "../bootstrap/css/bootstrap.min.css";
            //stylefontawesome.Href = "../bootstrap/font-awesome/css/font-awesome.css";
            //styleAdminLTE.Href = "../dist/css/AdminLTE.min.css";
            //stylecustom.Href = "../dist/css/custom.css";
            //stylefonts.Href = "../dist/css/fonts.css";
        }
        else
        {
            //htmlGraphical.Attributes.Add("dir", "rtl");
            //stylebootstrap.Href = "../bootstrap/css/bootstrap-rtl.min.css";
            //stylefontawesome.Href = "../bootstrap/font-awesome/css/font-awesome-rtl.css";
            //styleAdminLTE.Href = "../dist/css/AdminLTE.min-rtl.css";
            //stylecustom.Href = "../dist/css/custom-rtl.css";
            //stylefonts.Href = "../dist/css/fonts.css";
            stylebootstrap.Href = "../bootstrap/css/bootstrap.min.css";
            stylefontawesome.Href = "../bootstrap/font-awesome/css/font-awesome.css";
            styleAdminLTE.Href = "../dist/css/AdminLTE.min.css";
            stylecustom.Href = "../dist/css/custom.css";
            stylefonts.Href = "../dist/css/fonts.css";
        }
    }
    #endregion
}