using System;
using System.Data;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Globalization;
using System.Threading;
using System.Resources;
public partial class Transactions_TA_UI_Transaction_Transfer : Base.BasePage
{
    #region "Variable Declaration"
    ResourceManager rm;
    CultureInfo ci;
    GetReports ObjEmpFilters = new GetReports();
    GetReports ObjDelete = new GetReports();
    Cls_CheckUser objCheckUser = new Cls_CheckUser();
    Cls_CheckUser ObjEmpFilter = new Cls_CheckUser();
    DataSet ds_Checkuser = new DataSet();
    LeaveApplicationEventData objLeaveHolidays = new LeaveApplicationEventData();
    cls_Common objClassCommon = new cls_Common();
    DataSet dsLeaveHolidays = new DataSet();
    DataSet ds_Year = new DataSet();
    LeaveApplicationEventData objLeaveApplicationEventData = new LeaveApplicationEventData();
    PermissionEventData objPermissionEventData = new PermissionEventData();
    DataSet dsEmailIdOfSanctionAuthority = new DataSet();
    DataSet ds_EmailIdOfReportingTo = new DataSet();
    DataSet ds_EmployeeDetails = new DataSet();
    int StartYear, EndYear; string source_Language;
    int iLeaveApplication_Id, iEmployeeID, YearSettingID;
    string strReason = string.Empty, strEmailIdReportingTo, gstrDateFormat, gstrTimeFormat, strlevelName, strStatusType;
    Boolean blnCheckEmail;
    DataSet dsEmployeeGroup = new DataSet();
    int payrollConfig = 0;
    #endregion
    protected override void Page_Load(object sender, EventArgs e)
    {
        base.Page_Load(sender, e);
        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"]);

        if (!Page.IsPostBack)
        {
            grvEmpTransfer.Styles.CssFilePath = Convert.ToString(Session["GridCSS"]);
            base.CheckPages(0);
            objClassCommon.menu("ManualTransaction", "313");
            UserRights();
            LoadStrings(ci);
            btn_Add.Focus();
            BindTransferApplications();
            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);
            ds_Year = objClassCommon.GetYearsetting();
            if (ds_Year.Tables[0].Rows.Count <= 0)
            {
                string strScript = string.Empty;
                strScript = strScript + "<script language='javascript'>";
                strScript = strScript + "alert('" + rm.GetString("Msg_DefineYearSettinginOrganizationSettings", ci) + "');location.replace('../Organization Settings/Organization_YearSetting.aspx')";
                strScript = strScript + "</script>";
                Page.RegisterStartupScript("AlertLeavePolicyYear", strScript);
            }
            else
            {
                StartYear = Convert.ToInt32(ds_Year.Tables[0].Rows[0]["StartYear"]);
                EndYear = Convert.ToInt32(ds_Year.Tables[0].Rows[0]["EndYear"]);
                ViewState["YearSettings_Id"] = Convert.ToString(ds_Year.Tables[0].Rows[0]["YearSettings_Id"]);
                ds_Year.Dispose();
            }
            Hidden1.Value = Convert.ToString(Session["IDateFormat"]);
            Hidden2.Value = Convert.ToString(Session["ITimeFormat"]);
        }
        GetGrid();
    }
    protected void btn_Add_Click(object sender, EventArgs e)
    {
        Response.Redirect("TA_UI_Transaction_TransferAdd.aspx");
    }
    protected void btnImport_Click(object sender, EventArgs e)
    {
        Response.Redirect("TA_UI_Transactions_LeaveImport.aspx");
    }
    protected void lnktbnexcel_Click(object sender, EventArgs e)
    {
        LinkButton lnkbtn = (LinkButton)sender;  //Called From  Grid Report Icon click / both excel and pdf
        DisableControls();
        ASPxGridViewExporter1.Landscape = true;
        ASPxGridViewExporter1.LeftMargin = 10;
        ASPxGridViewExporter1.RightMargin = 10;
        ASPxGridViewExporter1.ExportedRowType = DevExpress.Web.GridViewExportedRowType.All;
        ASPxGridViewExporter1.MaxColumnWidth = 400;
        string saveAsFileName = string.Format("ListofTransferApplications - {0:d}", DateTime.Now).Replace("/", "-").Replace(" ", "");
        ASPxGridViewExporter1.FileName = saveAsFileName;
        ASPxGridViewExporter1.PaperKind = System.Drawing.Printing.PaperKind.A3;
        switch (lnkbtn.CommandName)
        {
            case "excel":
                ASPxGridViewExporter1.WriteXlsxToResponse();
                break;
            case "pdf":
                ASPxGridViewExporter1.WritePdfToResponse();
                break;
            case "csv":
                ASPxGridViewExporter1.WriteCsvToResponse();
                break;
        }
    }
    protected void grvEmpTransfer_HtmlRowCreated(object sender, DevExpress.Web.ASPxGridViewTableRowEventArgs e)
    {
    }
    private void UserRights()
    {
        ds_Checkuser = objCheckUser.checkRights(22, 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;
                //btnImport.Visible = true;
            }
            else
            {
                this.btn_Add.Visible = false;
                //btnImport.Visible = false;
            }
            if (ds_Checkuser.Tables[0].Rows[0]["viewPrv"] != DBNull.Value && Convert.ToInt32(ds_Checkuser.Tables[0].Rows[0]["viewPrv"]) == 1)
            {
                //this.grvEmpTransfer.Columns[10].Visible = true;
            }
            else
            {
                this.grvEmpTransfer.Columns[10].Visible = false;
            }
            if (ds_Checkuser.Tables[0].Rows[0]["deletePrv"] != DBNull.Value && Convert.ToInt32(ds_Checkuser.Tables[0].Rows[0]["deletePrv"]) == 1)
            {
                this.grvEmpTransfer.Columns[10].Visible = true;
            }
            else
            {
                this.grvEmpTransfer.Columns[10].Visible = false;
            }
            if (ds_Checkuser.Tables[0].Rows[0]["addPrv"] != DBNull.Value && Convert.ToInt32(ds_Checkuser.Tables[0].Rows[0]["addPrv"]) == 0 &&
                ds_Checkuser.Tables[0].Rows[0]["deletePrv"] != DBNull.Value && Convert.ToInt32(ds_Checkuser.Tables[0].Rows[0]["deletePrv"]) == 0 &&
                ds_Checkuser.Tables[0].Rows[0]["viewPrv"] != DBNull.Value && Convert.ToInt32(ds_Checkuser.Tables[0].Rows[0]["viewPrv"]) == 0)
            {
                //Response.Redirect("TransactionLandingPage.aspx");
            }
        }
        else
        {
            //Response.Redirect("TransactionLandingPage.aspx");
        }
        if (Convert.ToString(Session["UserGroupName"]) == "SuperAdmin" || Convert.ToString(Session["HasSpecialRights"]) == "True")
        {
            //lnktbnexcel.Visible = true;
            //lnkbtnpdf.Visible = true;
        }
    }
    private void LoadStrings(CultureInfo ci)
    {
        lbl_Header.Text = "Transfer";
        lbl_EmployeeName.Text = rm.GetString("email_EmployeeName", ci);
        lbl_EmployeeId.Text = rm.GetString("email_EmployeeId", ci);
        lblTransferStartDate.Text = "Transferred From";
        lblTransferEndDate.Text = "Transferred To";
        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);
        grvEmpTransfer.Columns[1].Caption = "Employee ID";
        grvEmpTransfer.Columns[2].Caption = "Employee Code";
        grvEmpTransfer.Columns[3].Caption = rm.GetString("email_EmployeeName", ci);
        grvEmpTransfer.Columns[4].Caption = "Organization Levels";
        grvEmpTransfer.Columns[5].Caption = "Raised On"; 
        grvEmpTransfer.Columns[6].Caption = "New Organization Levels"; 
        grvEmpTransfer.Columns[7].Caption = "Raised To"; 
        grvEmpTransfer.Columns[8].Caption = "New Designation";
        grvEmpTransfer.Columns[9].Caption = "Reason";
        //grvEmpTransfer.Columns[10].Caption = "Remarks";
        //grvEmpTransfer.Columns[11].Caption = "EtyDteTme";
        //lblFilter.Text = rm.GetString("lblFilter", ci);
        //lblDataView.Text = rm.GetString("lblDataView", ci);
        //btnImport.Text = rm.GetString("btnImport", ci);
    }
    private void DisableControls()
    {

    }
    private void BindTransferApplications()
    {

    }

    protected void btn_Clear_Click(object sender, EventArgs e)
    {
        txt_EmpName.Text = "";
        txtEmployeeId.Text = "";
        txtTransferStartDate.Text = "";
        txtTransferEndDate.Text = "";


    }

    protected void btn_Search_Click(object sender, EventArgs e)
    {

        DataSet DA = new DataSet();
        DA = ObjEmpFilters.EmployeeDetailFetch(txtEmployeeId.Text, txt_EmpName.Text, txtTransferStartDate.Text,
            txtTransferEndDate.Text, "1");
        if (DA.Tables[0].Rows.Count >= 0)
        {

            grvEmpTransfer.DataSource = DA;
            grvEmpTransfer.DataBind();
        }
    }

    private void GetGrid()
    {
        DataSet DA = new DataSet();
        DateTime Date = DateTime.Today.AddYears(100);
        DA = ObjEmpFilters.EmployeeDetailFetch(" "," ","1990-01-01"," ", "1");
        if (DA.Tables[0].Rows.Count >= 0)
        {

            grvEmpTransfer.DataSource = DA;
            grvEmpTransfer.DataBind();
        }

    }

    protected void btnDelete_Click(object sender, EventArgs e)
    {
        LinkButton btn = sender as LinkButton;
        int TriggerID = Convert.ToInt32(btn.CommandName);
        ObjDelete.EmployeeTransferDelete(TriggerID);

    }
}