Пример #1
0
    protected void btnExportToExcel_Click(object sender, EventArgs e)
    {
        sDataSource = System.Configuration.ConfigurationManager.ConnectionStrings[Request.Cookies["Company"].Value].ToString();

        int    empNO         = 0;
        int    managerID     = 0;
        string empName       = string.Empty;
        string managerName   = string.Empty;
        string sWeekID       = string.Empty;
        string dTSEDateRange = string.Empty;
        string sApproved     = string.Empty;

        if (ddlEmployee.Text.Trim() != string.Empty)
        {
            empNO = Convert.ToInt32(ddlEmployee.Text.Trim());
            lblEmployeeNumber.Text = empNO.ToString();
        }

        if (ddlApprover.Text.Trim() != string.Empty)
        {
            managerID = Convert.ToInt32(ddlApprover.Text.Trim());
        }

        if (txtDateRange.Text.Trim() != string.Empty)
        {
            dTSEDateRange        = txtDateRange.Text.Trim();
            sWeekID              = DateTimeExtension.CurrentWeekwithYear(Convert.ToDateTime(txtDateRange.Text));
            lblSelectedWeek.Text = DateTimeExtension.GetFormatWeekForGivenWeekID(sWeekID);
        }

        if (drpsApproved.Text.Trim() != string.Empty)
        {
            sApproved = drpsApproved.Text.Trim();
            lblApprovedStatus.Text = sApproved.ToString();
        }

        BusinessLogic bl = new BusinessLogic(sDataSource);

        bl.GetEmployeeMangerName(empNO, out empName, managerID, out managerName);
        lblEmployeeName.Text = empName;
        lblArroverName.Text  = managerName;

        if (bl.IsManagerForThisEmployee(empNO, managerID))
        {
            DataSet ds = bl.generateTSEReportDSNew(sWeekID, empNO, managerID, sApproved, sDataSource);
            gvTSE.DataSource = ds;
            gvTSE.DataBind();

            ExportToExcel();
        }
        else
        {
            ScriptManager.RegisterStartupScript(Page, Page.GetType(), Guid.NewGuid().ToString(), "alert('Selected Employee is not reporting to this Approver. Report cannot be generated.');", true);
        }
    }
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            if (Request.Cookies["Company"] != null)
            {
                sDataSource = System.Configuration.ConfigurationManager.ConnectionStrings[Request.Cookies["Company"].Value].ToString();
            }
            else
            {
                Response.Redirect("~/Login.aspx");
            }

            int    empNO       = 0;
            int    managerID   = 0;
            string empName     = string.Empty;
            string managerName = string.Empty;
            string sWeekID     = string.Empty;
            string sApproved   = string.Empty;

            BusinessLogic bl = new BusinessLogic(sDataSource);


            if (Request.QueryString["sWeekID"] != null)
            {
                sWeekID = Request.QueryString["sWeekID"].ToString();

                lblSelectedWeek.Text = DateTimeExtension.GetFormatWeekForGivenWeekID(sWeekID);
            }
            if (Request.QueryString["empNO"] != null)
            {
                empNO = Convert.ToInt32(Request.QueryString["empNO"].ToString());

                lblEmployeeNumber.Text = empNO.ToString();
            }
            if (Request.QueryString["smanagerID"] != null)
            {
                managerID = Convert.ToInt32(Request.QueryString["smanagerID"].ToString());
            }
            if (Request.QueryString["sApproved"] != null)
            {
                sApproved = Request.QueryString["sApproved"].ToString();

                lblApprovedStatus.Text = sApproved.ToString();
            }
            bl.GetEmployeeMangerName(empNO, out empName, managerID, out managerName);
            lblEmployeeName.Text = empName;
            lblArroverName.Text  = managerName;

            DataSet ds = bl.generateTSEReportDSNew(sWeekID, empNO, managerID, sApproved, sDataSource);
            gvTSE.DataSource = ds;
            gvTSE.DataBind();
        }
    }