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 DevExpress.Web;
public partial class Transactions_TA_UI_Transaction_Encashment : Base.BasePage
{
    ResourceManager rm;
    CultureInfo ci;
    LeaveApplicationEventData objLeaveApplicationEventData = new LeaveApplicationEventData();
    cls_Common objClassCommon = new cls_Common();
    DataSet dsEmployeeGroup = new DataSet();
    protected override void Page_Load(object sender, EventArgs e)
    {
        // session checking
        base.Page_Load(sender, e);
        grv_EncashmentApplication.Styles.CssFilePath = Convert.ToString(Session["GridCSS"]);
        //get the culture info to set the language
        if (!Page.IsPostBack)
        {
            base.CheckPages(0);
            objClassCommon.menu("LeaveTransaction", "76");
        }
        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);
        string strSetAlert = "";
        strSetAlert = strSetAlert + "<script language='javascript'>";
        strSetAlert = strSetAlert + "MaxLengthh('" + rm.GetString("Alert_MaximumLengthis", 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);
        Hidden1.Value = Convert.ToString(Session["IDateFormat"]);
        if (!Page.IsPostBack)
        {
            dsEmployeeGroup = objLeaveApplicationEventData.GetEmployeeGroupName(Convert.ToInt32(Session["EmpAutoId"]));
            if (dsEmployeeGroup.Tables[0].Rows.Count > 0)
            {
                if (dsEmployeeGroup.Tables[0].Rows[0]["GroupName"].ToString() == "SuperAdmin" || Convert.ToString(Session["HasSpecialRights"]) == "True")
                {
                    grv_EncashmentApplication.DataSourceID = "";
                    grv_EncashmentApplication.DataSourceID = ObjectDataSource2.ID;
                    ViewState["GroupName"] = "SuperAdmin";
                }
                else
                {
                    // grv_EncashmentApplication.Columns[2].Visible = false;
                    //grv_EncashmentApplication.Columns[3].Visible = false;
                }
            }
            else
            {
                //grv_EncashmentApplication.Columns[2].Visible = false;
                //grv_EncashmentApplication.Columns[3].Visible = false;
            }
        }
    }
    private void LoadStrings(CultureInfo ci)
    {
        lbl_Header.Text = rm.GetString("UserGroups_Encashment", ci);
        lbl_EmployeeName.Text = rm.GetString("email_EmployeeName", ci);
        lbl_EmployeeId.Text = rm.GetString("email_EmployeeId", ci);
        lblTimePeriod.Text = rm.GetString("ShiftExchange_DateRange", ci);
        lblEncashmentStartDate.Text = rm.GetString("email_FromDate", ci);
        lblEncashmentEndDate.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_EncashmentApplication.Columns[1].Caption = rm.GetString("email_EmployeeId", ci);
        grv_EncashmentApplication.Columns[2].Caption = rm.GetString("LeaveApplication_LeaveApplicationDate", ci);
        grv_EncashmentApplication.Columns[3].Caption = rm.GetString("email_EmployeeName", ci);
        grv_EncashmentApplication.Columns[4].Caption = rm.GetString("LevelDetails_LevelName", ci);
        grv_EncashmentApplication.Columns[5].Caption = rm.GetString("lbl_leavetype", ci);
        grv_EncashmentApplication.Columns[6].Caption = rm.GetString("LeaveSanction_NumberOfDays", ci);
        grv_EncashmentApplication.Columns[7].Caption = rm.GetString("email_Reason", ci);
        lblEmpSwipe.Text = rm.GetString("TerminalDataType_Card_No", ci);
        lblFilter.Text = rm.GetString("lblFilter", ci);

    }
    protected void btn_Add_Click(object sender, EventArgs e)
    {
        Response.Redirect("TA_UI_Transaction_EncashmentAdd.aspx");
    }
    protected void btn_Clear_Click(object sender, EventArgs e)
    {
        grid_RestoreDefault();
        lbl_Error.Text = string.Empty;
    }
    private void grid_RestoreDefault()
    {
        //Restores the Default view of the grid
        txt_EmpName.Text = string.Empty;
        txtEmployeeId.Text = string.Empty;
        txtEncashmentStartDate.Text = string.Empty;
        txtEncashmentEndDate.Text = string.Empty;
        txtSwipeCard.Text = string.Empty;
        grv_EncashmentApplication.PageIndex = 0;
        grv_EncashmentApplication.DataSourceID = ObjectDataSource2.ID;
    }
    protected void btn_Search_Click(object sender, EventArgs e)
    {
        //fill gridview based on search details given in textbox
        FillGrid_Search();
    }
    private void FillGrid_Search()
    {
        string empName = txt_EmpName.Text.Trim();
        txt_EmpName.Text = empName;
        string empId = txtEmployeeId.Text.Trim();
        txtEmployeeId.Text = empId;
        string strStartDate = txtEncashmentStartDate.Text;
        string strEndDate = txtEncashmentEndDate.Text;
        bool boolErrorStatus = true;
        string gstrDateFormat = Convert.ToString(Session["MDateFormat"]);
        strStartDate = objClassCommon.DateConvertion(gstrDateFormat, strStartDate);
        strEndDate = objClassCommon.DateConvertion(gstrDateFormat, strEndDate);
        string strSwipeCard = "";
        strSwipeCard = txtSwipeCard.Text.ToString().Trim().Replace("'", "''");
        if (empName == string.Empty && empId == string.Empty && strStartDate == string.Empty && strEndDate == string.Empty && strSwipeCard == string.Empty)
        {
            base.Message(rm.GetString("Alert_FillDetails", ci));
            grv_EncashmentApplication.DataSourceID = "";
            txt_EmpName.Focus();
            boolErrorStatus = true;
            return;
        }
        else
        {
            //Checks weather both the start and end order date are available or not available
            if (strStartDate == string.Empty && strEndDate == string.Empty)
            {
                //Both date not given
                boolErrorStatus = false;
            }
            else if (strStartDate != string.Empty && strEndDate != string.Empty)
            {
                //Both date Given
                if (Convert.ToDateTime(strEndDate).Date < Convert.ToDateTime(strStartDate).Date)
                {
                    base.Message(rm.GetString("Alert_FromDateLessThanToDate", ci));
                    grv_EncashmentApplication.DataSourceID = "";
                    return;
                    boolErrorStatus = true;
                }
                else
                {
                    boolErrorStatus = false;
                }
            }
            else
            {
                //Any one date is given
                base.Message(rm.GetString("Alert_FillFromToDate", ci));
                grv_EncashmentApplication.DataSourceID = "";
                return;
                boolErrorStatus = true;
            }
        }
        if (boolErrorStatus == true)
        {
            grid_RestoreDefault();
        }
        else
        {
            if (ViewState["GroupName"].ToString() == "SuperAdmin")
            {
                lbl_Error.Text = string.Empty;
                grv_EncashmentApplication.PageIndex = 0;
                grv_EncashmentApplication.DataSourceID = ObjectDataSource2.ID;
            }
        }
    }
    public void GetEmptyText(object sender, EventArgs e)
    {
        Label lblNoRecords = (Label)sender;
        lblNoRecords.Text = rm.GetString("Alert_Norecordsfound", ci);
    }
    protected void grv_EncashmentApplication_HtmlRowCreated(object sender, DevExpress.Web.ASPxGridViewTableRowEventArgs e)
    {
        //if (e.RowType == GridViewRowType.Data)
        //{
        //    Label lbl = (Label)grv_EncashmentApplication.FindRowCellTemplateControl(e.VisibleIndex, null, "AppDate1");
        //    if (lbl.Text != "")
        //    {
        //        lbl.Text = (Convert.ToDateTime(lbl.Text.ToString())).ToString(Session["MDateFormat"].ToString());
        //        e.Row.Cells[1].Text = lbl.Text;
        //    }
        //}
    }
}
