示例#1
0
        protected void Page_Load(object sender, EventArgs e)
        {
            this.payrollRunId = Common.GetEncryptedQueryStringValue("PayrollRunId", 0);

            PanelError.Visible = false;

            Page.Form.DefaultFocus  = TextBoxDeduction.ClientID;
            Page.Form.DefaultButton = ButtonSaveList.UniqueID;

            if (!IsPostBack)
            {
                TextBoxDeduction.Focus();
                if (ViewState["PayrollRunId"] != null)
                {
                    this.payrollRunId = Convert.ToInt32(ViewState["PayrollRunId"]);
                }

                if (this.payrollRunId > 0)
                {
                    PayrollRun payrollRun = PayrollRun.GetPayrollRunByPayrollRunId(this.payrollRunId);
                    Employee   employee   = Employee.GetEmployeeByEmployeeId(payrollRun.EmployeeId);

                    LabelPageTitle.Text = String.Format("{0} {1} - Payroll Run Detail", employee.FirstName, employee.LastName);

                    BindPayrollRun();
                }
            }
        }
示例#2
0
        private void BindPayrollRun()
        {
            PayrollRun payrollRun = PayrollRun.GetPayrollRunByPayrollRunId(this.payrollRunId);

            TextBoxDeduction.Text = payrollRun.Deduction.ToString();
            TextBoxComment.Text   = payrollRun.Comment;

            GridViewResult.DataSource = PayrollRun.GetPayrollRunDetailListByEmployeeId(payrollRun.EmployeeId);
            GridViewResult.DataBind();
        }
        private void BindPayrollMonthList()
        {
            DropDownListPayrollMonth.DataSource     = PayrollRun.GetPayrollMonthList();
            DropDownListPayrollMonth.DataTextField  = "FormattedPayrollMonth";
            DropDownListPayrollMonth.DataValueField = "FormattedPayrollMonth";
            DropDownListPayrollMonth.DataBind();

            if (DropDownListPayrollMonth.Items.Count > 1)
            {
                DropDownListPayrollMonth.Items.Insert(0, new ListItem("Please select", "0"));
            }
        }
        protected void ButtonSave_Click(object sender, EventArgs e)
        {
            try
            {
                foreach (GridViewRow gridViewRow in GridViewResult.Rows)
                {
                    CheckBox    checkBoxRepStoreLink    = (CheckBox)gridViewRow.Cells[3].FindControl("CheckBoxLink");
                    HiddenField hiddenFieldPayrollRunId = (HiddenField)gridViewRow.Cells[5].FindControl("HiddenFieldPayrollRunId");
                    HiddenField hiddenFieldEmployeeId   = (HiddenField)gridViewRow.Cells[6].FindControl("HiddenFieldEmployeeId");

                    if (checkBoxRepStoreLink.Checked)
                    {
                        if (hiddenFieldPayrollRunId.Value == "0")
                        {
                            PayrollRun payrollRun = new PayrollRun();

                            int year  = Convert.ToInt32(DropDownListPayrollMonth.SelectedValue.ToString().Substring(0, 4));
                            int month = Convert.ToInt32(DropDownListPayrollMonth.SelectedValue.ToString().Substring(5, 2));

                            payrollRun.PayrollRunId = 0;
                            payrollRun.PayrollMonth = new DateTime(year, month, 01);
                            payrollRun.EmployeeId   = Convert.ToInt32(hiddenFieldEmployeeId.Value);
                            payrollRun.Deduction    = 0;
                            payrollRun.Run          = 1; //Status = Execute/Run
                            payrollRun.Comment      = "";
                            payrollRun.ModifiedUser = this.Master.LoggedOnAccount;

                            payrollRun.Save();
                        }
                    }
                    else
                    {
                        if (hiddenFieldPayrollRunId.Value != "0")
                        {
                            PayrollRun.DeletePayrollRunByPayrollRunId(Convert.ToInt32(hiddenFieldPayrollRunId.Value));
                        }
                    }
                }

                GridViewResult.DataSource = PayrollRun.GetPayrollRunList(Convert.ToInt32(DropDownListLocation.SelectedValue), DropDownListPayrollMonth.SelectedValue);
                GridViewResult.DataBind();
            }
            catch (System.Data.SqlClient.SqlException sqlEx)
            {
                LabelError.Text = "";
                for (int i = 0; i < sqlEx.Errors.Count; i++)
                {
                    LabelError.Text += (sqlEx.Errors[i].Message + "<br />");
                }
                PanelError.Visible = true;
            }
        }
        protected void GridViewResult_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            GridViewRow currentRow = e.Row;

            if (currentRow.RowType == DataControlRowType.DataRow)
            {
                PayrollRun payrollRun = (PayrollRun)currentRow.DataItem;

                if (payrollRun.PayrollRunId == 0)
                {
                    currentRow.Cells[4].ForeColor = System.Drawing.Color.White;
                    currentRow.Cells[4].Text      = "-";
                    currentRow.Cells[4].Enabled   = false;
                }
            }
        }
        protected void ButtonSearchByFilter_Click(object sender, EventArgs e)
        {
            LabelError.Text    = "";
            PanelError.Visible = false;

            GridViewResult.DataSource = PayrollRun.GetPayrollRunList(Convert.ToInt32(DropDownListLocation.SelectedValue), DropDownListPayrollMonth.SelectedValue);
            GridViewResult.DataBind();

            if (GridViewResult.Rows.Count == 0)
            {
                LabelError.Text    = "No rows returned.";
                PanelError.Visible = true;
            }
            else
            {
                ButtonSave.Visible           = true;
                ButtonGenerateReport.Visible = true;
            }
        }
        protected void ButtonGenerateReport_Click(object sender, EventArgs e)
        {
            int    index     = 1;
            string sFileName = System.IO.Path.GetRandomFileName().Substring(0, 8);
            string sGenName  = String.Format("ReportPayrollRun{0}.csv", DropDownListPayrollMonth.SelectedValue.ToString().Replace("/", ""));

            using (System.IO.StreamWriter SW = new System.IO.StreamWriter(Server.MapPath("Upload/" + sFileName + ".csv")))
            {
                SW.WriteLine(String.Format("LOCATION - {0}", DropDownListLocation.SelectedItem.Text));
                SW.WriteLine(String.Format("Month - {0}", DropDownListPayrollMonth.SelectedValue.ToString()));
                SW.WriteLine("");
                SW.WriteLine("ID NUMBER, EMPLOYEE NUMBER, FIRST NAME, LAST NAME, DEDUCTION, COMMENT, RUN");
                string row = "";
                SW.WriteLine(row);
                List <PayrollRun> cs = PayrollRun.GetReportPayrollRun(Convert.ToInt32(DropDownListLocation.SelectedValue), DropDownListPayrollMonth.SelectedItem.Text);
                if (cs.Count > 0)
                {
                    foreach (PayrollRun payrollRun in cs)
                    {
                        row = String.Format("{0},{1},{2},{3},{4},{5},{6}", payrollRun.IDNumber, payrollRun.EmployeeNumber, payrollRun.FirstName, payrollRun.LastName, payrollRun.Deduction, payrollRun.Comment, payrollRun.FormattedRun);
                        SW.WriteLine(row);
                        index++;
                    }

                    SW.Close();
                }
                else
                {
                    LabelError.Text    = "No rows returned.";
                    PanelError.Visible = true;
                }
            }

            System.IO.FileStream fs = null;
            fs = System.IO.File.Open(Server.MapPath("Upload/" + sFileName + ".csv"), System.IO.FileMode.Open);
            byte[] btFile = new byte[fs.Length];
            fs.Read(btFile, 0, Convert.ToInt32(fs.Length));
            fs.Close();
            Response.AddHeader("Content-disposition", "attachment; filename=" + sGenName);
            Response.ContentType = "application/octet-stream";
            Response.BinaryWrite(btFile);
            Response.End();
        }
示例#8
0
        protected void ButtonSave_Click(object sender, EventArgs e)
        {
            if (Page.IsValid)
            {
                LabelError.Text         = "";
                PanelErrorSpace.Visible = false;

                try
                {
                    PayrollRun payrollRun = new PayrollRun();
                    payrollRun.PayrollRunId = this.payrollRunId;
                    payrollRun.Deduction    = Convert.ToDecimal(TextBoxDeduction.Text);
                    payrollRun.Comment      = TextBoxComment.Text;
                    payrollRun.ModifiedUser = this.Master.LoggedOnAccount;

                    payrollRun.Save();

                    Button clickedButton = (Button)sender;
                    switch (clickedButton.ID)
                    {
                    case "ButtonSaveList":
                        Response.Redirect("PayrollRunList.aspx");
                        break;
                    }
                }
                catch (System.Data.SqlClient.SqlException sqlEx)
                {
                    LabelError.Text = "";
                    for (int i = 0; i < sqlEx.Errors.Count; i++)
                    {
                        LabelError.Text += (sqlEx.Errors[i].Message + "<br />");
                    }
                    PanelError.Visible      = true;
                    PanelErrorSpace.Visible = true;
                }
            }
        }