using System;
using System.Data;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Globalization;
using System.Threading;
using System.Resources;
/****************************************************************************************************************************
* Project Name    : TimeCheck                         Started Date  : 12-Aug-2007
* Module          : Permission Application            Last Modified : 14-Aug-2007
* Programmer      : Prabakaran.P
* Current Storage : \\Angler56\Projects\Inprogress\SCREEN1206\code\Time_AttendanceApp
* BackUp          :
****************************************************************************************************************************/
public partial class Transactions_TA_UI_Transactions_LeavePermission : Base.BasePage
{
    #region "Variable Declaration"
    ResourceManager rm;
    CultureInfo ci;
    LeaveApplicationEventData objLeaveApplicationEventData = new LeaveApplicationEventData();
    cls_Common objClassCommon = new cls_Common();
    Cls_CheckUser objCheckUser = new Cls_CheckUser();
    DataSet ds_Checkuser = new DataSet();
    string source_Language;
    #endregion
    #region Page Load Event
    protected override void Page_Load(object sender, EventArgs e)
    {
        base.Page_Load(sender, e);
        grv_Permission.Styles.CssFilePath = Convert.ToString(Session["GridCSS"]);
        if (!Page.IsPostBack)
        {
            base.CheckPages(0);
            objClassCommon.menu("PermissionTransaction", "23");
        }
        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);
        string strSetAlert = "";
        strSetAlert = strSetAlert + "<script language='javascript'>";
        strSetAlert = strSetAlert + "MaxLengthh('" + rm.GetString("Alert_MaximumLengthis", ci) + "');";
        strSetAlert = strSetAlert + "SetAlertMessages('" + rm.GetString("Alert_FillDetails", ci) + "','" + rm.GetString("Alert_FillFromToDate", 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);
        Userrights();
        DataSet dsEmployeeGroup = new DataSet();
        dsEmployeeGroup = objLeaveApplicationEventData.GetEmployeeGroupName(Convert.ToInt32(Session["EmpAutoId"]));
        if (dsEmployeeGroup.Tables[0].Rows.Count > 0)
        {
            if (Convert.ToString(dsEmployeeGroup.Tables[0].Rows[0]["GroupName"]) == "SuperAdmin" || Convert.ToString(Session["HasSpecialRights"]) == "True")
            {
                grv_Permission.DataSourceID = "";
                grv_Permission.DataSourceID = ObjectDataSource2.ID;
                ViewState["GroupName"] = "SuperAdmin";
            }
            else
            {
                grv_Permission.DataSourceID = ObjectDataSource1.ID;
                grv_Permission.Columns[2].Visible = false;
                grv_Permission.Columns[3].Visible = false;
                grv_Permission.Columns[4].Visible = false;
                ViewState["GroupName"] = "Normal";
            }
        }
        else
        {
            grv_Permission.DataSourceID = ObjectDataSource1.ID;
            grv_Permission.Columns[2].Visible = false;
            grv_Permission.Columns[3].Visible = false;
            grv_Permission.Columns[4].Visible = false;
            ViewState["GroupName"] = "Normal";
        }
        if (!Page.IsPostBack)
        {
            Hidden1.Value = Convert.ToString(Session["IDateFormat"]);
            btn_Add.Focus();
        }
        if (ViewState["GroupName"] == "Normal")
        {
            trSwipeCardNo.Visible = false;
            trEmployeeDetails.Visible = false;
        }
    }
    #endregion
    #region User Defined Functions
    private void UserRights()
    {
        throw new Exception("The method or operation is not implemented.");
    }
    private void LoadStrings(CultureInfo ci)
    {
        lbl_Header.Text = rm.GetString("Menu_Transactions_Permission", ci);
        lbl_EmployeeName.Text = rm.GetString("email_EmployeeName", ci);
        lbl_EmployeeId.Text = rm.GetString("email_EmployeeId", ci);
        lblTimePeriod.Text = rm.GetString("ShiftExchange_DateRange", ci);
        lblPermissionStartDate.Text = rm.GetString("email_FromDate", ci);
        lblPermissionEndDate.Text = rm.GetString("email_ToDate", ci);
        btn_Search.Text = "&nbsp;&nbsp;" + rm.GetString("btn_Search", ci);
        btn_Clear.Text = "&nbsp;&nbsp;" + rm.GetString("btn_Clear", ci);
        btn_Add.Text = "&nbsp;&nbsp;" + rm.GetString("btn_Add", ci);
        grv_Permission.Columns[1].Caption = rm.GetString("LeaveApplication_LeaveApplicationDate", ci);
        grv_Permission.Columns[2].Caption = rm.GetString("email_EmployeeId", ci);
        grv_Permission.Columns[3].Caption = rm.GetString("email_EmployeeName", ci);
        grv_Permission.Columns[4].Caption = rm.GetString("LevelDetails_LevelName", ci);
        grv_Permission.Columns[5].Caption = rm.GetString("Report_Duration", ci);
        grv_Permission.Columns[6].Caption = rm.GetString("email_Status", ci);
        grv_Permission.Columns[7].Caption = rm.GetString("email_Reason", ci);
        grv_Permission.Columns[8].Caption = rm.GetString("email_Remarks", ci);
        lblEmpSwipe.Text = rm.GetString("TerminalDataType_Card_No", ci);
        lblFilter.Text = rm.GetString("lblFilter", ci);

    }
    private void grid_RestoreDefault()
    {
        txt_EmpName.Text = string.Empty;
        txtEmployeeId.Text = string.Empty;
        txtPermissionStartDate.Text = string.Empty;
        txtPermissionEndDate.Text = string.Empty;
        txtSwipeCard.Text = string.Empty;
        grv_Permission.PageIndex = 0;
        if (ViewState["GroupName"].ToString() == "SuperAdmin")
        {
            grv_Permission.DataSourceID = ObjectDataSource2.ID;
        }
        else
        {
            grv_Permission.DataSourceID = ObjectDataSource1.ID;
        }
    }
    private void Userrights()
    {
        ds_Checkuser = objCheckUser.checkRights(23, Convert.ToInt32(Session["userGroup_Id"]), "");
        if (ds_Checkuser.Tables[0].Rows.Count > 0)
        {
            if (ds_Checkuser.Tables[0].Rows[0]["addPrv"] != DBNull.Value && Convert.ToInt32(ds_Checkuser.Tables[0].Rows[0]["addPrv"]) == 1)
            {
                this.btn_Add.Visible = true;
            }
            else
            {
                this.btn_Add.Visible = false;
            }
            if (ds_Checkuser.Tables[0].Rows[0]["modifyPrv"] != DBNull.Value && Convert.ToInt32(ds_Checkuser.Tables[0].Rows[0]["modifyPrv"]) == 1)
            {
                this.grv_Permission.Columns[11].Visible = true;
            }
            else
            {
                this.grv_Permission.Columns[11].Visible = false;
            }
        }
        else
        {
            Response.Redirect("TransactionLandingPage.aspx");
        }
    }
    private void FillGrid_Search()
    {
        string empName = txt_EmpName.Text.Trim();
        txt_EmpName.Text = empName;
        string empId = txtEmployeeId.Text.Trim();
        txtEmployeeId.Text = empId;
        string strPermissionStartDate = txtPermissionStartDate.Text;
        string strPermissionEndDate = txtPermissionEndDate.Text;
        string gstrDateFormat = Convert.ToString(Session["MDateFormat"]);
        strPermissionStartDate = objClassCommon.DateConvertion(gstrDateFormat, strPermissionStartDate);
        strPermissionEndDate = objClassCommon.DateConvertion(gstrDateFormat, strPermissionEndDate);
        bool boolErrorStatus = true;
        string strSwipeCard = "";
        strSwipeCard = txtSwipeCard.Text.ToString().Trim().Replace("'", "''");
        if (empName == string.Empty && empId == string.Empty && strPermissionStartDate == string.Empty && strPermissionEndDate == string.Empty && strSwipeCard == string.Empty && ViewState["GroupName"].ToString() == "SuperAdmin")
        {
            grv_Permission.DataSourceID = "";
            return;
            txt_EmpName.Focus();
            boolErrorStatus = true;
        }
        else
        {
            if (strPermissionStartDate == string.Empty && strPermissionEndDate == string.Empty)
            {
                boolErrorStatus = false;
            }
            else if (strPermissionStartDate != string.Empty && strPermissionEndDate != string.Empty)
            {
                if (Convert.ToDateTime(strPermissionEndDate).Date < Convert.ToDateTime(strPermissionStartDate).Date)
                {
                    base.Message(rm.GetString("Alert_FromDateLessThanToDate", ci));
                    grv_Permission.DataSourceID = "";
                    return;
                    boolErrorStatus = true;
                }
                else
                {
                    boolErrorStatus = false;
                }
            }
            else
            {
                grv_Permission.DataSourceID = "";
                return;
                boolErrorStatus = true;
            }
        }
        if (boolErrorStatus == true)
        {
            grid_RestoreDefault();
        }
        else
        {
            lbl_Error.Text = string.Empty;
            grv_Permission.PageIndex = 0;
            if (ViewState["GroupName"].ToString() == "SuperAdmin")
            {
                grv_Permission.DataSourceID = ObjectDataSource2.ID;
            }
            else
            {
                grv_Permission.DataSourceID = ObjectDataSource1.ID;
            }
        }
    }
    public void GetEmptyText(object sender, EventArgs e)
    {
        Label lblNoRecords = (Label)sender;
        lblNoRecords.Text = rm.GetString("Alert_Norecordsfound", ci);
    }
    #endregion
    #region Button Click Events
    protected void btn_Add_Click(object sender, EventArgs e)
    {
        #region Eastman
        if (Convert.ToString(Session["packageID"]) != "")
            if (Convert.ToString(Session["packageID"]) == "155")
            {
                Response.Redirect("TA_UI_Transactions_PermissionAdd_Eastman.aspx");
            }
        #endregion
        Response.Redirect("TA_UI_Transactions_LeavePermissionAdd.aspx");
    }
    protected void btn_Clear_Click(object sender, EventArgs e)
    {
        grid_RestoreDefault();
        lbl_Error.Text = string.Empty;
    }
    protected void btn_Search_Click(object sender, EventArgs e)
    {
        Thread.Sleep(100);
        FillGrid_Search();
    }
    #endregion
    #region Gridview Events
    protected void grv_Permission_HtmlRowCreated(object sender, DevExpress.Web.ASPxGridViewTableRowEventArgs e)
    {
        if (e.RowType == DevExpress.Web.GridViewRowType.Data)
        {
            source_Language = Convert.ToString(Session["Session_ActiveLanguage"]);
            rm = new ResourceManager(source_Language, System.Reflection.Assembly.Load("App_GlobalResources"));
            ci = Thread.CurrentThread.CurrentCulture;
            string Lbl_EndTime = e.GetValue("Permission_ToTime").ToString();
            string Lbl_FromTime = Convert.ToString(e.GetValue("Permission_FromTime"));
            Label lbl_date = (Label)grv_Permission.FindRowCellTemplateControl(e.VisibleIndex, null, "AppDate");
            string TEndTime;
            TEndTime = DateTime.Parse(Lbl_EndTime).ToString(Session["MTimeFormat"].ToString());
            string TFromTime;
            TFromTime = DateTime.Parse(Lbl_FromTime).ToString(Session["MDateFormat"].ToString()) + "&nbsp;" + DateTime.Parse(Lbl_FromTime).ToString(Session["MTimeFormat"].ToString());
            TEndTime = TFromTime + " To " + TEndTime;
            if (Convert.ToString(Session["UserGroupName"]) == "SuperAdmin" || Convert.ToString(Session["HasSpecialRights"]) == "True")
            {
                switch (Convert.ToString(Session["IndividualUsers"]).ToUpper())
                {
                    case "TRUE":
                        e.Row.Cells[4].Text = TEndTime;
                        e.Row.Cells[4].Style.Add("color", "#5D5D5D");
                        break;
                    default:
                        e.Row.Cells[4].Text = TEndTime;
                        e.Row.Cells[4].Style.Add("color", "#5D5D5D");
                        break;
                }               
            }
            else if (Convert.ToString(Session["IndividualUsers"]) == "True")
            {
                e.Row.Cells[1].Text = TEndTime;
                e.Row.Cells[1].Style.Add("color", "#5D5D5D");
            }
            else
            {
                e.Row.Cells[1].Text = TEndTime;
                e.Row.Cells[1].Style.Add("color", "#5D5D5D");
            }
            Label lbl_Status = (Label)grv_Permission.FindRowCellTemplateControl(e.VisibleIndex, null, "lbl_Status");
            switch (Convert.ToString(lbl_Status.Text))
            {
                case "Approved":
                    lbl_Status.Text = rm.GetString("btn_Approved", ci);
                    break;
                case "Forwarded":
                    lbl_Status.Text = rm.GetString("btn_Forwarded", ci);
                    break;
                case "Pending":
                    lbl_Status.Text = rm.GetString("btn_Pending", ci);
                    break;
                case "Rejected":
                    lbl_Status.Text = rm.GetString("btn_Reject", ci);
                    break;
            }            
        }
    }
    #endregion
}
