using System;
using System.Data;
using System.Drawing;
using System.Globalization;
using System.IO;
using System.Resources;
using System.Threading;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using DevExpress.XtraCharts;
/*
 * Modified By      :   Manjula.P
 * Modified Date    :   19-Jul-2
 * Descriptions     :   Adding this line for Session["YearSettingsId"] = Convert.ToInt32(ds_Year.Tables[0].Rows[0]["YearSettings_Id"]);
 * */
public partial class Landing : Base.BasePage
{
    #region Variable Declaration
    ResourceManager rm;
    cls_Common objCommon = new cls_Common();
    EmployeeEventData ObjEmployeeEventData = new EmployeeEventData();
    DataSet dstAttendance = new DataSet();
    CultureInfo ci;
    GetReports rptEmp = new GetReports();
    Rpt_Common rptcommon = new Rpt_Common();
    #endregion
    #region PageLoad
    protected override void Page_Load(object sender, EventArgs e)
    {
        // session checking
        base.Page_Load(sender, e);
        if (!Page.IsPostBack)
        {
            objCommon.menu("Dashboard", "179");
            //base.CheckPages(50);
        }
        if (Session["Session_ActiveLanguage"] == null)
        {
            Response.Redirect("Index.aspx");
        }
        //get the culture info to set the language
        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;
        // LoadStrings(ci);
        string strSetAlert = "";
        strSetAlert = strSetAlert + "<script language='javascript'>";
        strSetAlert = strSetAlert + "MaxLengthh('" + rm.GetString("Alert_MaximumLengthis", ci) + "');";
        strSetAlert = strSetAlert + "SetAlertMessages('" + rm.GetString("Alert_EnterDate", ci) + "','" + rm.GetString("Alert_EnterToDate", ci) + "');";
        strSetAlert = strSetAlert + "SetAlertCheckDate('" + rm.GetString("Alert_Validmonthdatefourdigit", ci) + "','" + rm.GetString("Alert_Validdatemonthfourdigit", ci) + "','" + rm.GetString("Alert_Invalidyearentry", ci) + "','" + rm.GetString("Alert_Invalidmonthentry", ci) + "','" + rm.GetString("Alert_Invaliddateentry", ci) + "','" + rm.GetString("Alert_IncorrectdateformatDDMONYYYY", ci) + "','" + rm.GetString("Alert_Entertime", ci) + "','" + rm.GetString("Alert_Invalidvalueforhours", ci) + "','" + rm.GetString("Alert_Invalidvalueforminites", ci) + "','" + rm.GetString("Alert_Invalidtimeformat1", ci) + "','" + rm.GetString("Alert_PleaseentervalidDateandTime", ci) + "','" + rm.GetString("Alert_ValiddatemonthMMDDYYHHMM", ci) + "','" + rm.GetString("Alert_ValiddatemonthMMDDYYHHMMTT", ci) + "','" + rm.GetString("Alert_PleaseentervalidDateandTime", ci) + "','" + rm.GetString("Alert_Invalidvalueforhours", ci) + "','" + rm.GetString("Alert_Invalidvalueforminites", ci) + "');";
        strSetAlert = strSetAlert + "</script>";
        Page.RegisterStartupScript("SetAlertMessages", strSetAlert);
        // checking license expiry date 
        CheckDemoVersion();
        GenerateMenu();
        //  string source_Language = string.Empty;
        if (Session["Session_ActiveLanguage"] != null)
        {
            source_Language = Convert.ToString(Session["Session_ActiveLanguage"]);
            rm = new ResourceManager(source_Language, System.Reflection.Assembly.Load("App_GlobalResources"));
            ci = Thread.CurrentThread.CurrentCulture;
            //form1.Attributes.CssStyle.Add("Direction", rm.GetString("Direction", ci));
            userRightsEventData objClass = new userRightsEventData();
            DataSet ds = new DataSet();
            ds = objClass.SelectLevelRights(Convert.ToInt32(Session["userGroup_Id"]));
            Session["LevelRights"] = "0";
            if (ds != null)
            {
                if (ds.Tables.Count > 0)
                {
                    if (ds.Tables[0].Rows.Count > 0)
                    {
                        if (ds.Tables[0].Rows[0]["LevelId"] != DBNull.Value)
                        {
                            string strLevelID = Convert.ToString(ds.Tables[0].Rows[0]["LevelId"]);
                            Session["LevelRights"] = strLevelID;
                        }
                    }
                }
            }
            CheckMandatoryPage();
        }
        Hidden1.Value = Convert.ToString(Session["IDateFormat"]);
        if (source_Language == "Resources.Resource_AR")
        {
            //menuStyle.Href = "css/fancydropdown_Arabic.css";
        }
        else
        {
            //menuStyle.Href = "css/fancydropdown.css";
        }
        if (!IsPostBack)
        {
            //TestChartload();
            cls_master_levels class1 = new cls_master_levels();
            DataSet ds = new DataSet();
            if (Session["UserGroupName"] != null)
            {
                ds = class1.getOrgLevelUpdated(0, Convert.ToString(Session["LevelRights"]), 0, Convert.ToString(Session["UserGroupName"]));
            }
            Session["OrgLevels"] = ds;
            if (Session["parentLevelId"] != null || Convert.ToInt32(Session["parentLevelId"]) != 0)
            {
                Session["parentLevelId"] = null;
            }
        }
        if (Session["SanctionUrl"] != null)
        {
            Response.Redirect(Session["SanctionUrl"].ToString());
        }
    }
    #endregion
    #region UserDefinedFunctions
    protected void CheckMandatoryPage()
    {
        cls_Common objClass = new cls_Common();
        DataSet ds = new DataSet();
        ds = objClass.GetCheckMandatory();
        if (ds != null && ds.Tables[0].Rows.Count > 0)
        {
            if (ds.Tables[0].Rows[0]["MandatoryChecking"] != DBNull.Value && Convert.ToInt16(ds.Tables[0].Rows[0]["MandatoryChecking"]) == 0)
                Session["CheckMandatoryPage"] = "Not Required";
            else
                Session["CheckMandatoryPage"] = "Required";
        }
        else
            Session["CheckMandatoryPage"] = "Required";
    }
    protected void CheckDemoVersion()
    {
        string[] fileArr = Directory.GetFiles(Server.MapPath("LicenseFile"), "*.lic");
        int arrCount = fileArr.Length;
        if (arrCount > 0)
        {
            // continue with license file
            lblDemo.Visible = false;
            lblDemo.Text = "Welcome" + "<br />" + Session["user"].ToString();
            int expiryDays = Convert.ToInt32(Session["sExpiryDays"]);
            string expiryDate = Convert.ToString(Session["sExpiryDate"]);
            if ((expiryDays <= 5) && (expiryDays >= 0))
            {
                if (expiryDays == 0)
                {
                    string licenseUptScript = "<script language='javascript' type='text/javascript'>";
                    licenseUptScript += "alert('Your Software License will be expired Today, Please update license On/Before " + expiryDate + "');";
                    licenseUptScript += " </script>";
                    this.RegisterStartupScript("licenseUptScript", licenseUptScript);
                }
                else
                {
                    string licenseUptScript = "<script language='javascript' type='text/javascript'>";
                    licenseUptScript += "alert('Your Software License will be expired within " + expiryDays.ToString() + " day(s) , Please update license On/Before " + expiryDate + "');";
                    licenseUptScript += " </script>";
                    this.RegisterStartupScript("licenseUptScript", licenseUptScript);
                }
            }
        }
        else
        {
            lblDemo.Visible = false;
            lblDemo.Text = "Demo Version";
        }
    }
    protected void GenerateMenu()
    {
        //Get Year Setting Details for Menu constructing and Year Setting Display
        cls_Common objClassCommon = new cls_Common();
        DataSet ds_Year = new DataSet();
        string strYearData = string.Empty;
        string StartYear = string.Empty, EndYear = string.Empty, StartMonth = string.Empty, EndMonth = string.Empty;
        ds_Year = objClassCommon.GetYearsetting();
        if (ds_Year.Tables[0].Rows.Count > 0)
        {
            Session["YearSettingsId"] = Convert.ToInt32(ds_Year.Tables[0].Rows[0]["YearSettings_Id"]);
            Session["YearSettingFromDate"] = Convert.ToString(ds_Year.Tables[0].Rows[0]["YearSettingFromDate"]);
            Session["YearSettingToDate"] = Convert.ToString(ds_Year.Tables[0].Rows[0]["YearSettingToDate"]);
            StartYear = ds_Year.Tables[0].Rows[0]["StartYear"].ToString();
            StartMonth = ds_Year.Tables[0].Rows[0]["StartMonth"].ToString();
            EndYear = ds_Year.Tables[0].Rows[0]["EndYear"].ToString();
            EndMonth = ds_Year.Tables[0].Rows[0]["EndMonth"].ToString();
            Session["SearchFromDate"] = Convert.ToDateTime(ds_Year.Tables[0].Rows[0]["FromDate"]);
            strYearData = StartMonth + " " + StartYear + " - " + EndMonth + " " + EndYear;
            string sYearValue = Convert.ToString(Cache["ActiveYearSetting"]);
            if (sYearValue == null || sYearValue == String.Empty)
            {
                TimeSpan SessTimeOut = new TimeSpan(0, 0, HttpContext.Current.Session.Timeout, 0, 0);
                HttpContext.Current.Cache.Insert("ActiveYearSetting", strYearData, null, DateTime.MaxValue, SessTimeOut, System.Web.Caching.CacheItemPriority.NotRemovable, null); // cache handling
            }
            else if (strYearData != sYearValue)
            {
                TimeSpan SessTimeOut = new TimeSpan(0, 0, HttpContext.Current.Session.Timeout, 0, 0);
                HttpContext.Current.Cache.Remove("ActiveYearSetting");
                HttpContext.Current.Cache.Insert("ActiveYearSetting", strYearData, null, DateTime.MaxValue, SessTimeOut, System.Web.Caching.CacheItemPriority.NotRemovable, null); // cache handling
            }
        }
        else
        {
            TimeSpan SessTimeOut = new TimeSpan(0, 0, HttpContext.Current.Session.Timeout, 0, 0);
            HttpContext.Current.Cache.Remove("ActiveYearSetting");
            HttpContext.Current.Cache.Insert("ActiveYearSetting", "", null, DateTime.MaxValue, SessTimeOut, System.Web.Caching.CacheItemPriority.NotRemovable, null); // cache handling
            Session["SearchFromDate"] = (Convert.ToDateTime(System.DateTime.Now.ToShortDateString())).ToString(Session["MDateFormat"].ToString());
        }
    }
    #endregion
}
