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.Resources;
using System.IO;
using DevExpress.Web;
public partial class Transactions_TA_UI_Transactions_ManualEntryExport : Base.BasePage
{
    #region Variable Declaration
    ResourceManager rm;
    CultureInfo ci;
    ShiftEvenData getShift = new ShiftEvenData();
    GetReports rptEmp = new GetReports();
    cls_Common objCommon = new cls_Common();
    string strFromdate, gstrDateFormat, strTodate;
    DataSet dsEmp = new DataSet();
    Rpt_Common rptcommon = new Rpt_Common();
    Cls_CheckUser objCheckUser = new Cls_CheckUser();
    DataSet ds_Checkuser = new DataSet();
    #endregion
    #region Page Load Event
    protected override void Page_Load(object sender, EventArgs e)
    {
        try
        {
            base.Page_Load(sender, e);
            if (!Page.IsPostBack)
            {
                base.CheckPages(221);
                objCommon.menu("ManualTransaction", "221");
            }
            string 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);
            Hidden1.Value = Convert.ToString(Session["IDateFormat"]);
            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);
        }
        catch (Exception ex)
        {
            base.Message(ex.Message);
        }
    }
    #endregion
    #region User Defined Functions
    private void LoadStrings(CultureInfo ci)
    {
        lbl_Header.Text = rm.GetString("Transaction_ManualTimeEntryExport", ci);
        lblStatus.Text = rm.GetString("email_Status", ci);
        btnExport.Text = "&nbsp;&nbsp;" + rm.GetString("btn_Export", ci);
        btn_Cancel.Text = "&nbsp;&nbsp;" + rm.GetString("btn_Back", ci);
        lblTimePeriod.Text = rm.GetString("ShiftExchange_DateRange", ci);
        lblStartDate.Text = rm.GetString("email_FromDate", ci);
        lblEndDate.Text = rm.GetString("email_ToDate", ci);
        lbl_EmployeeName.Text = rm.GetString("email_EmployeeName", ci);
        lbl_EmployeeId.Text = rm.GetString("email_EmployeeId", ci);
        lblFilter.Text = rm.GetString("lblFilter", ci);
        lblMandatoryFields.Text = rm.GetString("IndicatesMandatoryFields", ci);
        lbl_ExportMode.Text= rm.GetString("lbl_ExportMode", ci);
    }
    public void ExportManualEntry()
    {
        string Level = string.Empty;
        string employeeName = string.Empty;
        string empId = string.Empty;
        gstrDateFormat = Convert.ToString(Session["MDateFormat"]);
        string dtFrom = "", dtTo = "";
        if (txtStartDate.Text != "")
        {
            strFromdate = txtStartDate.Text;
            strFromdate = objCommon.DateConvertion(gstrDateFormat, strFromdate);
            dtFrom = strFromdate;
        }
        if (txtEndDate.Text != "")
        {
            strTodate = txtEndDate.Text;
            strTodate = objCommon.DateConvertion(gstrDateFormat, strTodate);
            dtTo = strTodate;
        }
        string strStatus = "All";
        if (ddlManualEntryStatus.SelectedValue == "Approved")
        {
            strStatus = "Approved";
        }
        else if (ddlManualEntryStatus.SelectedValue == "Forwarded")
        {
            strStatus = "Forwarded";
        }
        else if (ddlManualEntryStatus.SelectedValue == "Pending")
        {
            strStatus = "Pending";
        }
        else if (ddlManualEntryStatus.SelectedValue == "Rejected")
        {
            strStatus = "Rejected";
        }
        else if (ddlManualEntryStatus.SelectedValue == "Deleted")
        {
            strStatus = "Deleted";
        }
        else
        {
            strStatus = "All";
        }
        empId = txtEmployeeId.Text.Trim().ToString();
        employeeName = this.txt_EmpName.Text.Replace("'", "''");
        Level = rptcommon.getNodes(Convert.ToInt16(Session["parentLevelId"]), Convert.ToString(Session["LevelRights"]));
        DataTable dtManualEntry = new DataTable();
        dsEmp = rptEmp.SelectManualTimeEntryExport(Convert.ToInt32(Session["EmpAutoID"]), employeeName, empId, dtFrom, dtTo, Level, 0, 0, Convert.ToString(Session["UserGroupName"]), "0", strStatus, "", Convert.ToInt16(Session["parentLevelId"]), Convert.ToInt32(0), "Both");
        if (dsEmp.Tables["Table"].Rows.Count == 0)
        {
            string strMsg;
            strMsg = "<script language='javascript'>";
            strMsg = strMsg + "alert('" + rm.GetString("Alert_Thereisnorecord", ci) + "');";
            strMsg = strMsg + "</script>";
            Page.RegisterStartupScript("Display Message", strMsg);
            return;
        }
        else
        {
            dsEmp.Tables["Table"].Columns.Add("Si_No");
            int i = 0;
            foreach (DataRow dr in dsEmp.Tables[0].Rows)
            {
                dsEmp.Tables[0].Rows[i][15] = i + 1;
                i = i + 1;
            }
            gvManualEntryExport.DataSource = dsEmp.Tables[0];
            gvManualEntryExport.DataBind();
            Export_SetCookie objSetCookie = new Export_SetCookie();
            objSetCookie.SetCookie(Convert.ToString(Session["EmpAutoID"]), "ManualEntryExport");
            if (gvManualEntryExport.VisibleRowCount > 0)
            {
                expShiftExport.Landscape = true;
                expShiftExport.LeftMargin = 30;
                expShiftExport.RightMargin = 30;
                expShiftExport.ExportedRowType = DevExpress.Web.GridViewExportedRowType.All;
                expShiftExport.MaxColumnWidth = 200;
                switch (ddlExport.SelectedValue.ToString())
                {
                    case "xls": expShiftExport.WriteXlsToResponse("ManualEntryExport");
                        break;
                    case "csv": expShiftExport.WriteCsvToResponse("ManualEntryExport");
                        break;
                    default:
                        break;
                }
            }
            else
            {
                base.Message("No data to be exported.");
            }
        }
    }
    private void UserRights()
    {
        ds_Checkuser = objCheckUser.checkRights(221, Convert.ToInt32(Session["userGroup_Id"]), "addPrv");
        if (ds_Checkuser.Tables[0].Rows.Count == 0)
        {
            Response.Redirect("TransactionLandingPage.aspx");
        }
    }
    #endregion
    #region Button Click Events
    protected void btn_Cancel_Click(object sender, EventArgs e)
    {
        try
        {
            Response.Redirect("TA_UI_Transactions_ManualTimeEntryList.aspx");
        }
        catch (Exception Ex)
        {
            base.Message(Ex.Message);
        }
    }
    protected void btnExport_Click(object sender, EventArgs e)
    {
        try
        {
            ExportManualEntry();
        }
        catch (Exception ex)
        {
            base.Message(ex.Message);
        }
    }
    #endregion
}
