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_ShiftExchangeList : Base.BasePage
{
    #region Variable Declaration
    ResourceManager rm;
    CultureInfo ci;
    ShiftExchangeEventData obj = new ShiftExchangeEventData();
    cls_Common objClassCommon = new cls_Common();
    DataView dv;
    #endregion
    #region Page Load Event
    protected override void Page_Load(object sender, EventArgs e)
    {
        base.Page_Load(sender, e);
        grvShiftExchange.Styles.CssFilePath = Convert.ToString(Session["GridCSS"]);
        if (!Page.IsPostBack)
        {
            base.CheckPages(0);
            objClassCommon.menu("ShiftTransaction", "60");
        }
        Hidden1.Value = Convert.ToString(Session["IDateFormat"]);
        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 + "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);
        if (!IsPostBack)
        {
        }
        ShiftExchangeEmployeeDetails();
    }
    #endregion
    #region User Defined Functions
    private void LoadStrings(CultureInfo ci)
    {
        lbl_Header.Text = rm.GetString("UserGroups_ShiftExchange", ci);
        //lbl_EmployeeName.Text = rm.GetString("email_EmployeeName", ci);
        //lbl_EmployeeId.Text = rm.GetString("email_EmployeeId", ci);
        lblTimePeriod.Text = rm.GetString("ShiftExchange_DateRange", ci);
        lblStartDate.Text = rm.GetString("email_FromDate", ci);
        lblEndDate.Text = rm.GetString("email_ToDate", ci);
        grvShiftExchange.Columns[1].Caption = rm.GetString("Reports_Date", ci);
        grvShiftExchange.Columns[2].Caption = rm.GetString("ShiftExchange_Employee1", ci);
        grvShiftExchange.Columns[3].Caption = rm.GetString("ShiftTiming_ShiftName", ci);
        grvShiftExchange.Columns[4].Caption = rm.GetString("ShiftExchange_Employee2", ci);
        grvShiftExchange.Columns[5].Caption = rm.GetString("ShiftTiming_ShiftName", ci);
        grvShiftExchange.Columns[0].Caption = rm.GetString("EntranceMaster_Company", 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);
        lblFilter.Text = rm.GetString("lblFilter", ci);

    }
    protected void ShiftExchangeEmployeeDetails()
    {
        DataSet dsShiftDetails = new DataSet();
        string date1 = string.Empty;
        string date2 = string.Empty;
        YearSettingsEventData objYearSettingsEventData = new YearSettingsEventData();
        DataSet dsYearSetting = new DataSet();
        string startDate = string.Empty;
        string endDate = string.Empty;
        dsYearSetting = objYearSettingsEventData.GetActiveYearSettings();
        if (dsYearSetting.Tables[0].Rows.Count <= 0)
        {
            return;
        }
        else
        {
            startDate = dsYearSetting.Tables[0].Rows[0]["FromDate"].ToString();
            endDate = dsYearSetting.Tables[0].Rows[0]["ToDate"].ToString();
        }
        dsShiftDetails = obj.SelectShiftExchangeDetails(Convert.ToInt32(Session["EmpAutoID"]), "A", startDate, endDate, Convert.ToString(Session["UserGroupName"]), Convert.ToString(Session["GradeLevel"]), Convert.ToString(Session["LevelRights"]), Convert.ToInt32(Session["parentLevelId"]));
        Session["ShiftExchange"] = dsShiftDetails;
        if (dsShiftDetails.Tables[0].Rows.Count > 0)
        {
            grvShiftExchange.DataSource = dsShiftDetails;
            grvShiftExchange.DataBind();
        }
        else
        {
            grvShiftExchange.DataSource = dsShiftDetails;
            grvShiftExchange.DataBind();
        }
    }
    public void ShiftExchangeSorting_bind()
    {
        DataSet dsSort = new DataSet();
        dsSort = (DataSet)Session["ShiftExchange"];
        if (ViewState["sort"] != null)
        {
            dv = new DataView(dsSort.Tables[0]);
            dv.Sort = ViewState["sort"].ToString() + " " + ViewState["sort_direction"].ToString();
        }
        else
        {
            dv = dsSort.Tables[0].DefaultView;
        }
        grvShiftExchange.DataSource = dv; ;
        grvShiftExchange.DataBind();
    }
    private void grid_RestoreDefault()
    {
        DataSet dsRestore = new DataSet();
        dsRestore = (DataSet)Session["ShiftExchange"];
        //Restores the Default view of the grid
        txtStartDate.Text = string.Empty;
        txtEndDate.Text = string.Empty;
        grvShiftExchange.PageIndex = 0;
        grvShiftExchange.DataSource = dsRestore;
        grvShiftExchange.DataBind();
    }
    private void FillGridSearchDetails()
    {
        string strFromDate = txtStartDate.Text;
        string strToDate = txtEndDate.Text;
        bool boolErrorStatus = true;
        string gstrDateFormat = Convert.ToString(Session["MDateFormat"]);
        strFromDate = objClassCommon.DateConvertion(gstrDateFormat, strFromDate);
        strToDate = objClassCommon.DateConvertion(gstrDateFormat, strToDate);
        if (strFromDate == string.Empty && strToDate == string.Empty)
        {
            //lbl_Error.Text = "Please Enter From Date and To Date";
            base.Message(rm.GetString("Msg_PleaseEnterFromDateandToDate", ci));
            txtStartDate.Focus();
            boolErrorStatus = true;
        }
        else if (strFromDate != string.Empty && strToDate != string.Empty)
        {
            if (Convert.ToDateTime(strToDate).Date < Convert.ToDateTime(strFromDate).Date)
            {
                //Checks weather the start date is less than end date
                //lbl_Error.Text = "From date should be less than to Todate";
                base.Message(rm.GetString("Alert_FromdateshouldbelessthantoTodate", ci));
                boolErrorStatus = true;
            }
            else
            {
                boolErrorStatus = false;
            }
        }
        else
        {
            //Any one date is given
            //lbl_Error.Text = "Please enter both the From and To date";
            base.Message(rm.GetString("Alert_FillFromToDate", ci));
            boolErrorStatus = true;
        }
        if (boolErrorStatus == true)
        {
            //DataSet dsempty = new DataSet();
            //grid_RestoreDefault();
            grvShiftExchange.DataSourceID = "";
            grvShiftExchange.DataBind();
        }
        else
        {
            //strFromDate = "02/01/2009";
            //strToDate = "02/10/2010";
            lbl_Error.Text = string.Empty;
            grvShiftExchange.PageIndex = 0;
            grvShiftExchange.DataSource = obj.SelectShiftExchangeDetails(Convert.ToInt32(Session["EmpAutoID"]), "S", strFromDate, strToDate, Convert.ToString(Session["UserGroupName"]), Convert.ToString(Session["GradeLevel"]), Convert.ToString(Session["LevelRights"]), Convert.ToInt32(Session["parentLevelId"]));
            grvShiftExchange.DataBind();
        }
    }
    public void GetEmptyText(object sender, EventArgs e)
    {
        Label lblNoRecords = (Label)sender;
        lblNoRecords.Text = rm.GetString("Alert_Norecordsfound", ci);
    }
    #endregion
    #region Grid Events
    protected void grvShiftExchange_HtmlRowCreated(object sender, DevExpress.Web.ASPxGridViewTableRowEventArgs e)
    {
        //if (e.RowType == GridViewRowType.Data)
        //{
        //    Label lbl = (Label)grvShiftExchange.FindRowCellTemplateControl(e.VisibleIndex, null, "lblShiftExchangeDate");
        //    if (lbl.Text != "")
        //    {
        //        lbl.Text = (Convert.ToDateTime(lbl.Text.ToString())).ToString(Session["MDateFormat"].ToString());
        //        e.Row.Cells[1].Text = lbl.Text;
        //    }
        //}
    }
    #endregion
    #region Button Events
    protected void btn_Add_Click(object sender, EventArgs e)
    {
        Response.Redirect("TA_UI_Transaction_ShiftExchange.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)
    {
        FillGridSearchDetails();
    }
    #endregion
    #region Not Used
    //protected void grvShiftExchange_RowDataBound(object sender, GridViewRowEventArgs e)
    //{
    //    if (e.Row.RowType == DataControlRowType.DataRow)
    //    {
    //        Label lblCompany = (Label)e.Row.Cells[0].FindControl("lblCompany");
    //         org_levelsEventData getOrg = new org_levelsEventData();
    //         getOrg.GetOrgParentLevels_FromID(Convert.ToInt32(lblCompany.Text));
    //            DataSet ds_getOrg = new DataSet();
    //            ds_getOrg = getOrg.GetOrgParentLevels();
    //            if (ds_getOrg != null)
    //            {
    //                if (ds_getOrg.Tables[0].Rows.Count > 0)
    //                {
    //                    lblCompany.Text  = ds_getOrg.Tables[0].Rows[0]["LevelName"].ToString();
    //                }
    //            }
    //    }
    //}
    #endregion
}
