using System;
using System.Data;
using System.Globalization;
using System.Resources;
using System.Threading;
using System.Web;
using System.Web.UI;
/****************************************************************************************************************************
* Project Name    : TimeCheck                                 Started Date  : 07-Oct-2007
* Module          : Date and Time Format                      Last Modified : 15-Oct-2007
* Programmer      : Christopher S
* Current Storage : \\Angler56\Projects\Inprogress\SCREEN1206\code\TimeCheck_Product\Time_AttendanceApp
* BackUp          :
 * 
 * Modified By      :   Manjula.P 
 * Modified On      :   04-Oct-2013
 * Descriptions     :   To viewing datetime format while importing the master mantis : 0019241 
****************************************************************************************************************************/
public partial class System_Settings_System_DateTimeFormat : Base.BasePage
{
    #region VariableDeclaration
    ResourceManager rm;
    string strDate, strTime;
    DataSet ds = new DataSet();
    ShiftExchange objshift = new ShiftExchange();
    Cls_CheckUser objCheckUser = new Cls_CheckUser();
    DataSet ds_Checkuser = new DataSet();
    EmployeeEventData ObjEmployeeEventData = new EmployeeEventData();
    cls_Common objCommon = new cls_Common();
    #endregion
    #region PageLoad
    protected override void Page_Load(object sender, EventArgs e)
    {
        // session checking
        base.Page_Load(sender, e);
        //Commented by Manjula.P on 04-Oct-2013 for : Because no need to check in Date format for default values 0019241 
        //if (!Page.IsPostBack)
        //{
        //    base.CheckPages(0);
        //}
        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;
        site.SiteMapProvider = Convert.ToString(Session["SiteMapProvider"]);
        LoadStrings(ci);
        if (!Page.IsPostBack)
        {
            objCommon.menu("Configuration", "67");
            DateandTimeFormatWhilePageLoading();
            btn_Add.OnClientClick = "return confirm('" + rm.GetString("Alert_ConfirmSave") + "');return false;";
            //objCommon.menu("Configuration", "Date & Time Format ");
        }
        //Call to a function to implement the UserRights
        UserRights();
    }
    #endregion
    #region UserDefinedFunctions
    //Getting Information from resource file and display it in label
    private void LoadStrings(CultureInfo ci)
    {
        lbl_DateFormat.Text = rm.GetString("DateandTimeFormat_DateFormat", ci);
        lbl_TimeFormat.Text = rm.GetString("DateandTimeFormat_TimeFormat", ci);
        lbl_HeaderDateandTimeFormat.Text = rm.GetString("Menu_SystemSettings_DateandTimeFormat", ci);
        btn_Add.Text = "&nbsp;&nbsp" + rm.GetString("btn_Save", ci);
    }
    private void UserRights()
    {
        ds_Checkuser = objCheckUser.checkRights(67, Convert.ToInt32(Session["userGroup_Id"]), "");
        if (ds_Checkuser.Tables[0].Rows.Count > 0)
        {
            if (ds_Checkuser.Tables[0].Rows[0]["viewPrv"] == DBNull.Value || Convert.ToInt32(ds_Checkuser.Tables[0].Rows[0]["viewPrv"]) != 1)
            {
                Response.Redirect("SystemLandingPage.aspx");
            }
            if (ds_Checkuser.Tables[0].Rows[0]["modifyPrv"] != DBNull.Value && Convert.ToInt32(ds_Checkuser.Tables[0].Rows[0]["modifyPrv"]) == 1)
            {
                this.btn_Add.Visible = true;
            }
            else
            {
                this.btn_Add.Visible = false;
            }
        }
        else
        {
            Response.Redirect("SystemLandingPage.aspx");
        }
    }
    // date and time format being set while page very first time loading
    private void DateandTimeFormatWhilePageLoading()
    {
        // get date,time format from session and show the same in UI
        strDate = Convert.ToString(Session["MDateFormat"]);
        strTime = Convert.ToString(Session["MTimeFormat"]);
        if (strDate.Equals(rbtnddmmyyyy.Text))
        {
            rbtnddmmyyyy.Checked = true;
        }
        if (strDate.Equals(rbtnmdyy.Text))
        {
            rbtnmdyy.Checked = true;
        }
        if (strDate.Equals(rbtnmmddyy.Text))
        {
            rbtnmmddyy.Checked = true;
        }
        if (strDate.Equals(rbtnmmddyyyy.Text))
        {
            rbtnmmddyyyy.Checked = true;
        }
        if (strDate.Equals(rbtnyymmdd.Text))
        {
            rbtnyymmdd.Checked = true;
        }
        if (strDate.Equals(rbtnyyyymmdd.Text))
        {
            rbtnyyyymmdd.Checked = true;
        }
        if (strDate.Equals(rbtnddmmmyy.Text))
        {
            rbtnddmmmyy.Checked = true;
        }
        if (strTime.Equals(rbtnhmmsstt.Text))
        {
            rbtnhmmsstt.Checked = true;
        }
        if (strTime.Equals(rbtnhhmmsstt.Text))
        {
            rbtnhhmmsstt.Checked = true;
        }
        if (strTime.Equals(rbtnHmmss.Text))
        {
            rbtnHmmss.Checked = true;
        }
        if (strTime.Equals(rbtnHHmmss.Text))
        {
            rbtnHHmmss.Checked = true;
        }
    }
    // inser or update could be done while saving the date and time format
    private void InsertOrUpdate(string strDate, string strTime)
    {
        // while inserting or updating a new date time format
        // the date and time format key is assigned to session's date and time format 
        // for applying the format to other pages of application
        Session["IDateFormat"] = Convert.ToString(System.Configuration.ConfigurationManager.AppSettings[strDate]);
        Session["ITimeFormat"] = Convert.ToString(System.Configuration.ConfigurationManager.AppSettings[strTime]);
        Session["MDateFormat"] = strDate;
        Session["MTimeFormat"] = strTime;
        int empId = Convert.ToInt32(Session["EmpAutoID"]);
        // inert or update the changed date and time format to database
        objshift.InsertorUpdate_DateandTimeFormat(strDate, strTime, empId, 0, "", "", "");
        //Clear All Session For Current Login user Code By A.K.T.MOORTHI(25-Dec-2013) <-- START
        if (Session["EmployeeId"] != null)
        {
            string userId = Convert.ToString(Session["EmployeeId"]);
            string sUser = Convert.ToString(Cache[Session["EmployeeId"].ToString().ToUpper()]);
            if (sUser != null && sUser != String.Empty)
            {
                ObjEmployeeEventData.InsertUpdateLastLogout(userId);
                HttpContext.Current.Cache.Remove(Convert.ToString(Session["EmployeeId"]).ToUpper());
                Session.Clear();
            }
        }
        // END -->
        string strScript = string.Empty;
        strScript = strScript + "<script language='javascript'>";
        strScript = strScript + "alert('" + rm.GetString("Alert_DateTimeFormat") + "');location.replace('../Index.aspx');";
        strScript = strScript + "</script>";
        Page.RegisterStartupScript("AlertLogOut", strScript);
    }
    #endregion
    #region ButtonEvents
    protected void btn_Add_Click(object sender, EventArgs e)
    {
        // check which date and time format is selected for updation
        // and assign the key to date and time format variables
        if (rbtnddmmyyyy.Checked)
        {
            strDate = rbtnddmmyyyy.Text;
        }
        if (rbtnmdyy.Checked)
        {
            strDate = rbtnmdyy.Text;
        }
        if (rbtnmmddyy.Checked)
        {
            strDate = rbtnmmddyy.Text;
        }
        if (rbtnmmddyyyy.Checked)
        {
            strDate = rbtnmmddyyyy.Text;
        }
        if (rbtnyymmdd.Checked)
        {
            strDate = rbtnyymmdd.Text;
        }
        if (rbtnyyyymmdd.Checked)
        {
            strDate = rbtnyyyymmdd.Text;
        }
        if (rbtnddmmmyy.Checked)
        {
            strDate = rbtnddmmmyy.Text;
        }
        if (rbtnhmmsstt.Checked)
        {
            strTime = rbtnhmmsstt.Text;
        }
        if (rbtnhhmmsstt.Checked)
        {
            strTime = rbtnhhmmsstt.Text;
        }
        if (rbtnHmmss.Checked)
        {
            strTime = rbtnHmmss.Text;
        }
        if (rbtnHHmmss.Checked)
        {
            strTime = rbtnHHmmss.Text;
        }
        // insert or update with key of date and time format
        InsertOrUpdate(strDate, strTime);
    }
    #endregion
}