using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Globalization;
using System.Threading;
using System.Reflection;
using System.Resources;
using System.Net;
public partial class System_Settings_SystemSettings : System.Web.UI.MasterPage
{
    ResourceManager rm;
    cls_Common objcommon = new cls_Common();
    EmployeeEventData ObjEmployeeEventData = new EmployeeEventData();
    protected void Page_Load(object sender, EventArgs e)
    {
        // not use ...
        //if (hfLogoutSS.Value == "true")
        //{
        //    if (Session["EmployeeId"] != null)
        //    {
        //        string userId = Session["EmployeeId"].ToString();
        //        string strHostName = " ", ipAddress = " ";
        //        ipAddress = Request.ServerVariables["REMOTE_ADDR"].ToString();
        //        strHostName = Dns.GetHostName();
        //        IPHostEntry ipEntry = Dns.GetHostByName(strHostName);
        //        IPAddress[] addr = ipEntry.AddressList;
        //        string sessionId = Session.SessionID.ToString();
        //        objcommon.LogoutUser(userId, ipAddress, sessionId);
        //        //update Logout time for the specified user
        //        ObjEmployeeEventData.InsertUpdateLastLogout(userId);
        //    }
        //}
        //else
        //{
        //    // no logout            
        //}
        // not use ...
        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");
        //Header.Controls.Add(CssLink);
        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)
        {
            //Included by sashma on 27-Sep-2010
            //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"]));
            }
            //stores the organization levels.
            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;
        //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 Standard Demo
        string strType = string.Empty;
        if (Session["Demo"] != null)
        {
            if (Session["Demo"].ToString() == "Standard")
            {
                strType = "Standard";
            }
        }
        //Top Menu
        //cls_Common getmenu = new cls_Common();
        //DataSet ds = new DataSet();
        //Session["TopMenu"] = "<table border='0' cellpadding=0 cellspacing=0><tr><td width'10'>&nbsp;</td>";
        //if (Convert.ToInt16(Session["userGroup_Id"]) != 0)
        //{
        //    ds = getmenu.getUserMenu(0, Convert.ToInt16(Session["userGroup_Id"]), strType);
        //    for (int iloop = 0; iloop <= ds.Tables[0].Rows.Count - 1; iloop++)
        //    {
        //        String txt = ds.Tables[0].Rows[iloop]["displayName"].ToString();
        //        //this.mnu.InnerHtml += "<td align='center'><a href='../" + ds.Tables[0].Rows[iloop]["path"] + "' title='" + ds.Tables[0].Rows[iloop]["displayName"] + " '>" + ds.Tables[0].Rows[iloop]["displayName"] + " </a></td>";
        //        Session["TopMenu"] += "<td align='center'><a href='../" + ds.Tables[0].Rows[iloop]["path"] + "' title='" + rm.GetString(txt, ci) + " '>" + rm.GetString(txt, ci) + " </a></td>";
        //        //Session["TopMenu"] += "<td width='15' align='center'><span style='color:#888888'>&nbsp;|&nbsp;</span></td>";
        //        if (iloop != ds.Tables[0].Rows.Count - 1)
        //        {
        //            Session["TopMenu"] += "<td width='15' align='center'>|</span></td>";
        //        }
        //    }
        //}
        //Session["TopMenu"] += "</tr></table>";
        //ds.Clear();
        //ds.Dispose();
        ////End of Top Menu
        ////Master Left menu
        //ds = getmenu.getUserMenu(1, Convert.ToInt16(Session["userGroup_Id"]), strType);
        //Session["MasterLeftMenu"] = "<span class='LeftMenuHeader'>&nbsp;" + rm.GetString("Menu_Masters", ci) + "</span>";
        //for (int iloop = 0; iloop <= ds.Tables[0].Rows.Count - 1; iloop++)
        //{
        //    string txt = ds.Tables[0].Rows[iloop]["displayName"].ToString();
        //    //Session["MasterLeftMenu"] += "<a class='leftMenu' href='" + ds.Tables[0].Rows[iloop]["path"] + "' title='" + rm.GetString(txt, ci) + " '>" + rm.GetString(txt, ci) + " </a>";
        //}
        //ds.Clear();
        //ds.Dispose();
        ////End of Master Left Menu
        ////Transaction left menu
        //ds = getmenu.getUserMenu(2, Convert.ToInt16(Session["userGroup_Id"]), strType);
        //Session["TransLeftMenu"] = "<span class='LeftMenuHeader'>&nbsp;" + rm.GetString("Menu_Transactions", ci) + "</span>";
        //for (int iloop = 0; iloop <= ds.Tables[0].Rows.Count - 1; iloop++)
        //{
        //    //this.mnu.InnerHtml += "<a class='leftMenu' href='" + ds.Tables[0].Rows[iloop]["path"] + "' title='" + ds.Tables[0].Rows[iloop]["displayName"] + " '>" + ds.Tables[0].Rows[iloop]["displayName"] + " </a>";
        //    string txt = ds.Tables[0].Rows[iloop]["displayName"].ToString();
        //    Session["TransLeftMenu"] += "<a class='leftMenu' href='" + ds.Tables[0].Rows[iloop]["path"] + "' title='" + rm.GetString(txt, ci) + " '>" + rm.GetString(txt, ci) + " </a>";
        //}
        //ds.Clear();
        //ds.Dispose();
        ////End of Transaction Left Menu
        ////Report left menu
        //ds = getmenu.getUserMenu(3, Convert.ToInt16(Session["userGroup_Id"]), strType);
        //Session["ReportLeftMenu"] = "<span class='LeftMenuHeader'>&nbsp;" + rm.GetString("Menu_Reports", ci) + "</span>";
        //for (int iloop = 0; iloop <= ds.Tables[0].Rows.Count - 1; iloop++)
        //{
        //    //this.mnu.InnerHtml += "<a class='leftMenu' href='" + ds.Tables[0].Rows[iloop]["path"] + "' title='" + ds.Tables[0].Rows[iloop]["displayName"] + " '>" + ds.Tables[0].Rows[iloop]["displayName"] + " </a>";
        //    string txt = ds.Tables[0].Rows[iloop]["displayName"].ToString();
        //    Session["ReportLeftMenu"] += "<a class='leftMenu' href='" + ds.Tables[0].Rows[iloop]["path"] + "' title='" + rm.GetString(txt, ci) + " '>" + rm.GetString(txt, ci) + " </a>";
        //}
        //ds.Clear();
        //ds.Dispose();
        ////End of Report Left Menu
        ////Org setting left menu
        //ds = getmenu.getUserMenu(4, Convert.ToInt16(Session["userGroup_Id"]), strType);
        //Session["OrgLeftMenu"] = "<span class='LeftMenuHeader'>" + rm.GetString("Menu_Org_Settings", ci) + "</span>";
        //for (int iloop = 0; iloop <= ds.Tables[0].Rows.Count - 1; iloop++)
        //{
        //    //this.mnu.InnerHtml += "<a class='leftMenu' href='" + ds.Tables[0].Rows[iloop]["path"] + "' title='" + ds.Tables[0].Rows[iloop]["displayName"] + " '>" + ds.Tables[0].Rows[iloop]["displayName"] + " </a>";
        //    string txt = ds.Tables[0].Rows[iloop]["displayName"].ToString();
        //    Session["OrgLeftMenu"] += "<a class='leftMenu' href='" + ds.Tables[0].Rows[iloop]["path"] + "' title='" + rm.GetString(txt, ci) + " '>" + rm.GetString(txt, ci) + " </a>";
        //}
        //ds.Clear();
        //ds.Dispose();
        ////End of Org Setting Left MEnu
        ////Sys Setting left menu            
        //ds = getmenu.getUserMenu(5, Convert.ToInt16(Session["userGroup_Id"]), strType);
        //Session["SystemLeftMenu"] = "<span class='LeftMenuHeader'>&nbsp;" + rm.GetString("Menu_System_Settings", ci) + "</span>";
        //for (int iloop = 0; iloop <= ds.Tables[0].Rows.Count - 1; iloop++)
        //{
        //    //this.mnu.InnerHtml += "<a class='leftMenu' href='" + ds.Tables[0].Rows[iloop]["path"] + "' title='" + ds.Tables[0].Rows[iloop]["displayName"] + " '>" + ds.Tables[0].Rows[iloop]["displayName"] + " </a>";
        //    string txt = ds.Tables[0].Rows[iloop]["displayName"].ToString();
        //    Session["SystemLeftMenu"] += "<a class='leftMenu' href='" + ds.Tables[0].Rows[iloop]["path"] + "' title='" + rm.GetString(txt, ci) + " '>" + rm.GetString(txt, ci) + " </a>";
        //}
        //ds.Clear();
        //ds.Dispose();
        ////End of Sys Setting Left Menu
        //Year Display 
        if (ds_Year.Tables[0].Rows.Count > 0)
        {
            //Adding by MAnjula.P on 24-Jul-2013 for getting current year settings id which was used in employee view page.
            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"]).ToString(Session["MDateFormat"].ToString());
            Session["SearchFromDate"] = Convert.ToDateTime(ds_Year.Tables[0].Rows[0]["FromDate"]);
            //lblYearData.Text = StartMonth + " " + StartYear + " - " + EndMonth + " " + EndYear;
            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());
        }
    }
}
