using System;
using System.Data;
using System.Web;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Globalization;
using System.Threading;
using System.Resources;
public partial class Error_Page_TA_Page_Template_Error : System.Web.UI.MasterPage
{
    ResourceManager rm;
    cls_Common objcommon = new cls_Common();
    EmployeeEventData ObjEmployeeEventData = new EmployeeEventData();
    protected void Page_Load(object sender, EventArgs e)
    {
        Random rnd = new Random();
        HtmlLink CssLink = new HtmlLink();
        CssLink.Href = "../css/stylesheet.css?rnd=" + rnd.NextDouble();
        CssLink.Attributes.Add("Type", "text/css");
        CssLink.Attributes.Add("Rel", "StyleSheet");
        Head1.Controls.Add(CssLink);
        CultureInfo ci;
        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));
            string strSetAlert = "";
            strSetAlert = strSetAlert + "<script language='javascript'>";
            strSetAlert = strSetAlert + "SetAlertMessages_DeleteRestore('" + rm.GetString("Alert_ConfirmDelete") + "','" + rm.GetString("Alert_SelectItemsToDelete") + "','" + rm.GetString("Alert_ConfirmDeletePermanent") + "','" + rm.GetString("Alert_Areyousuretorestore") + "','" + rm.GetString("Alert_SelectItemsToRestore") + "','" + rm.GetString("Alert_SelectItemToForwarded") + "','" + rm.GetString("Alert_SelectItemToApproved") + "');";
            strSetAlert = strSetAlert + "</script>";
            Page.RegisterStartupScript("SetAlertMessages", strSetAlert);
        }
        if (source_Language == "Resources.Resource_AR")
        {
            //menuStyle.Href = "../css/fancydropdown_Arabic.css";
            //Calenderstyle.Href = "../css/Calender.css";
            //fontstyle.Href = "../css/fonts.css";
            //Progressstyle.Href = "../css/ProgressBar.css";
            //anytimestyle.Href = "../css/anytime.css";
            //anytimeProtoTypestyle.Href = "../css/anytime.prototype.css";
            //stylesheetstyle.Href = "../css/stylesheet.css";
        }
        else
        {
            //menuStyle.Href = "../css/fancydropdown.css";
            //Calenderstyle.Href = "../css/Calender.css";
            //fontstyle.Href = "../css/fonts.css";
            //Progressstyle.Href = "../css/ProgressBar.css";
            //anytimestyle.Href = "../css/anytime.css";
            //anytimeProtoTypestyle.Href = "../css/anytime.prototype.css";
            //stylesheetstyle.Href = "../css/stylesheet.css";
        }
        GenerateMenu();
        CheckMandatoryPage();
        if (!IsPostBack)
        {
            //To get the organisation levels based on the level rights of the employee.
            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;
        }
    }
    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 GenerateMenu()
    {
        CultureInfo ci;
        Session["TopMenu"] = "";
        Session["MasterLeftMenu"] = "";
        Session["OrgLeftMenu"] = "";
        Session["ReportLeftMenu"] = "";
        Session["SystemLeftMenu"] = "";
        Session["TransLeftMenu"] = "";
        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;
        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();
        string strType = string.Empty;
        if (Session["Demo"] != null)
        {
            if (Session["Demo"].ToString() == "Standard")
            {
                strType = "Standard";
            }
        }
        //Year Display 
        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());
        }
    }
    protected void lbtn_logout_Click(object sender, EventArgs e)
    {
        if (Session["EmployeeId"] != null)
        {
            string userId = Session["EmployeeId"].ToString();
            string sUser = Convert.ToString(Cache[Session["EmployeeId"].ToString().ToUpper()]);
            if (sUser != null && sUser != String.Empty)
            {
                ObjEmployeeEventData.InsertUpdateLastLogout(userId);
                HttpContext.Current.Cache.Remove(Session["EmployeeId"].ToString().ToUpper());
                Session.Clear();
            }
        }
        HttpContext.Current.Response.Redirect("../Index.aspx");
    }
}
