public void BindEmployeeLeaveDays() { try { EmployeeLeaveDays employeeLeaveDays = EmployeeLeaveDays.GetEmployeeLeaveDaysByEmployeeLeaveDaysId(this.employeeLeaveDaysId); ViewState["employeeLeaveId"] = employeeLeaveDays.EmployeeLeaveId; DropDownListLeaveType.Items.FindByValue(employeeLeaveDays.LeaveTypeId.ToString()).Selected = true; TextBoxStartDate.Text = employeeLeaveDays.StartDate.ToString("yyyy/MM/dd"); TextBoxEndDate.Text = employeeLeaveDays.EndDate.ToString("yyyy/MM/dd"); TextBoxDays.Text = employeeLeaveDays.Days.ToString(); TextBoxComment.Text = employeeLeaveDays.Comment; } catch (System.Data.SqlClient.SqlException sqlEx) { for (int i = 0; i < sqlEx.Errors.Count; i++) { LabelError.Text += (sqlEx.Errors[i].Message + "<br />"); } PanelError.Visible = true; } catch (Exception exception) { LabelError.Text += (exception.Message + "<br />"); PanelError.Visible = true; } }
//private void BindRoleList() //{ // string[] roleList = Roles.GetAllRoles(); // foreach (string role in roleList) // { // DropDownListRole.Items.Add(new ListItem(role, role)); // } // DropDownListRole.Items.Insert(0, new ListItem("All", "0")); // DropDownListRole.Items.Remove("Administrator"); //} protected void RepeaterAlphabet_ItemCommand(object source, RepeaterCommandEventArgs e) { string searchValue = (((LinkButton)e.CommandSource).Text == "All") ? "%" : ((LinkButton)e.CommandSource).Text + "%"; if (searchValue.Length != 0) { GridViewResult.DataSource = EmployeeLeaveDays.GetEmployeeListFilterByReportsToId(searchValue, Account.GetAccountByUserName(Page.User.Identity.Name.ToString()).AccountId, Convert.ToInt32(DropDownListFinancialPeriod.SelectedValue)); GridViewResult.DataBind(); ViewState["Search"] = searchValue; } }
protected void GridViewResult_RowCommand(object sender, GridViewCommandEventArgs e) { try { switch (e.CommandName.ToLower()) { case "deleteleave": { EmployeeLeaveDays.DeleteEmployeeLeaveDaysByEmployeeLeaveDaysId(Convert.ToInt32(e.CommandArgument), this.Master.LoggedOnAccount); EmployeeLeave.UpdateEmloyeeLeaveCurrentDaysByEmployeeLeaveDaysId(Convert.ToInt32(e.CommandArgument), 2 /*Delete*/, this.Master.LoggedOnAccount); SendEmployeeLeaveDeletionNotificationList(); BindGridviewResult(); BindEmployeeLeave(); break; } case "viewattachment": { EmployeeLeaveDays employeeLeaveDays = EmployeeLeaveDays.GetEmployeeLeaveDaysByEmployeeLeaveDaysId(Convert.ToInt32(e.CommandArgument)); //Response.Redirect(String.Format("{0}",employeeLeaveDays.Attachment)); //System.IO.FileStream fs = null; //fs = System.IO.File.Open(employeeLeaveDays.Attachment, 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=" + "LeaveAttachment"); //Response.ContentType = "image/jpeg"; //Response.BinaryWrite(btFile); //Response.End(); Response.Clear(); Response.ContentType = "image/jpg"; Response.AppendHeader("Content-Disposition", "attachment; filename=LeaveAttachment.jpg"); Response.TransmitFile(employeeLeaveDays.Attachment); Response.End(); 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; } }
protected void ButtonSave_Click(object sender, EventArgs e) { if (Page.IsValid) { LabelError.Text = ""; PanelErrorSpace.Visible = false; bool hasError = false; try { if (TextBoxReportsToComment.Text.Length == 0) { LabelError.Text = "Comment is required."; PanelError.Visible = true; PanelErrorSpace.Visible = true; hasError = true; return; } EmployeeLeaveDays.UpdateEmployeeLeaveDaysReportsToCommentByEmployeeLeaveDaysId(this.employeeLeaveDaysId, TextBoxReportsToComment.Text, this.Master.LoggedOnAccount); Button clickedButton = (Button)sender; switch (clickedButton.ID) { case "ButtonSaveList": Response.Redirect("EmployeeLeaveApprovalEdit.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; } } }
protected void Page_Load(object sender, EventArgs e) { Page.Form.DefaultFocus = TextBoxSearchValue.ClientID; Page.Form.DefaultButton = ButtonSearch.UniqueID; if (!IsPostBack) { BindFinancialPeriod(); //BindRoleList(); string[] alphabet = "A;B;C;D;E;F;G;H;I;J;K;L;M;N;O;P;Q;R;S;T;U;V;W;X;Y;Z;All".Split(';'); RepeaterAlphabet.DataSource = alphabet; RepeaterAlphabet.DataBind(); string searchValue = (Request.QueryString["EmployeeNumber"] == null) ? "" : Request.QueryString["EmployeeNumber"]; if (searchValue.Length != 0) { GridViewResult.DataSource = EmployeeLeaveDays.GetEmployeeListFilterByReportsToId(searchValue, Account.GetAccountByUserName(Page.User.Identity.Name.ToString()).AccountId, Convert.ToInt32(DropDownListFinancialPeriod.SelectedValue)); GridViewResult.DataBind(); search = searchValue; } } PanelError.Visible = false; }
protected void GridViewResult_RowCommand(object sender, GridViewCommandEventArgs e) { try { switch (e.CommandName.ToLower()) { case "approve": { EmployeeLeaveDays.UpdateEmployeeLeaveDaysIsApprovalByEmployeeLeaveDaysId((Convert.ToInt32(e.CommandArgument)), 3 /*Approved*/, this.Master.LoggedOnAccount); EmployeeLeave.UpdateEmloyeeLeaveCurrentDaysByEmployeeLeaveDaysId(Convert.ToInt32(e.CommandArgument), 1 /*Approve*/, this.Master.LoggedOnAccount); SendEmployeeLeaveReportsToDecisionNotification((Convert.ToInt32(e.CommandArgument))); break; } case "decline": { EmployeeLeaveDays.UpdateEmployeeLeaveDaysIsApprovalByEmployeeLeaveDaysId((Convert.ToInt32(e.CommandArgument)), 1 /*Decline*/, this.Master.LoggedOnAccount); SendEmployeeLeaveReportsToDecisionNotification((Convert.ToInt32(e.CommandArgument))); break; } } GridViewResult.DataSource = EmployeeLeaveDays.GetEmployeeListFilterByReportsToId(ViewState["Search"].ToString(), Account.GetAccountByUserName(Page.User.Identity.Name.ToString()).AccountId, Convert.ToInt32(DropDownListFinancialPeriod.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 (Convert.ToInt32(ViewState["formLoggedInId"]) == Convert.ToInt32(ViewState["formReportsToId"])) { currentRow.Cells[7].Enabled = true; } else { currentRow.Cells[7].ForeColor = System.Drawing.Color.White; currentRow.Cells[7].Enabled = false; if (currentRow.RowType == DataControlRowType.DataRow) { EmployeeLeaveDays employeeLeaveDays = (EmployeeLeaveDays)currentRow.DataItem; if (employeeLeaveDays.IsApproved == 3) { currentRow.Cells[6].ForeColor = System.Drawing.Color.White; currentRow.Cells[6].Enabled = false; } } } //if (currentRow.RowIndex > 0) if (currentRow.RowType == DataControlRowType.DataRow) { EmployeeLeaveDays employeeLeaveDays = (EmployeeLeaveDays)currentRow.DataItem; if (employeeLeaveDays.Attachment.Length == 0) { currentRow.Cells[5].ForeColor = System.Drawing.Color.White; currentRow.Cells[5].Text = "-"; currentRow.Cells[5].Enabled = false; } } }
private void BindEmployeeLeaveDays() { TextBoxReportsToComment.Text = EmployeeLeaveDays.GetEmployeeLeaveDaysByEmployeeLeaveDaysId(this.employeeLeaveDaysId).ReportsToComment; }
protected void ButtonGenerateReport_Click(object sender, EventArgs e) { int index = 1; string sFileName = System.IO.Path.GetRandomFileName().Substring(0, 8); string sGenName = String.Format("ReportEmployeeLeave.csv"); using (System.IO.StreamWriter SW = new System.IO.StreamWriter(Server.MapPath("Upload/" + sFileName + ".csv"))) { SW.WriteLine(String.Format("FINANCIAL PERIOD - {0}", DropDownListFinancialPeriod.SelectedItem.Text)); SW.WriteLine(String.Format("LOCATION - {0}", DropDownListLocation.SelectedItem.Text)); SW.WriteLine(String.Format("LEAVE TYPE - {0}", DropDownListLeaveType.SelectedItem.Text)); SW.WriteLine(String.Format("STATUS - {0}", DropDownListIsApproved.SelectedItem.Text)); SW.WriteLine(String.Format("DATE RANGE - {0} To {1}", Convert.ToDateTime(TextBoxDateFrom.Text).ToString("yyyy/MM/dd"), Convert.ToDateTime(TextBoxDateTo.Text).ToString("yyyy/MM/dd"))); SW.WriteLine(String.Format("REPORT TYPE - {0}", (RadioButtonHeader.Checked) ? "HEADER" : "DETAIL")); SW.WriteLine(""); if (RadioButtonHeader.Checked) { if (DropDownListLeaveType.SelectedValue == "2") { SW.WriteLine("EMPLOYEE NUMBER, FIRST NAME, LAST NAME, OPENING BALANCE, ENTITLED DAYS, TOTAL DAYS, BALANCE REMAINING(ANNUAL)"); } else { SW.WriteLine("EMPLOYEE NUMBER, FIRST NAME, LAST NAME, OPENING BALANCE, ENTITLED DAYS, TOTAL DAYS"); } string row = ""; SW.WriteLine(row); List <EmployeeLeaveDays> cs = EmployeeLeaveDays.GetReportEmployeeLeaveHeader(Convert.ToInt32(DropDownListFinancialPeriod.SelectedValue), Convert.ToInt32(DropDownListLocation.SelectedValue), Convert.ToInt32(DropDownListLeaveType.SelectedValue), Convert.ToDateTime(TextBoxDateFrom.Text), Convert.ToDateTime(TextBoxDateTo.Text), Convert.ToInt32(DropDownListIsApproved.SelectedValue)); if (cs.Count > 0) { foreach (EmployeeLeaveDays employeeLeaveDays in cs) { if (DropDownListLeaveType.SelectedValue == "2") { row = String.Format("{0},{1},{2},{3},{4},{5},{6}", employeeLeaveDays.EmployeeNumber, employeeLeaveDays.FirstName, employeeLeaveDays.LastName, employeeLeaveDays.FormattedCurrentDays, employeeLeaveDays.FormattedEntitledDays, employeeLeaveDays.TotalDays, employeeLeaveDays.FormattedEmployeeLeaveProjection); } else { row = String.Format("{0},{1},{2},{3},{4},{5}", employeeLeaveDays.EmployeeNumber, employeeLeaveDays.FirstName, employeeLeaveDays.LastName, employeeLeaveDays.FormattedCurrentDays, employeeLeaveDays.FormattedEntitledDays, employeeLeaveDays.TotalDays); } SW.WriteLine(row); index++; } SW.Close(); } else { LabelError.Text = "No rows returned."; PanelError.Visible = true; } } else { if (DropDownListLeaveType.SelectedValue == "2") { SW.WriteLine("EMPLOYEE NUMBER, FIRST NAME, LAST NAME, OPENING BALANCE, ENTITLED DAYS, DAYS, TOTAL DAYS, BALANCE REMAINING(ANNUAL), LEAVE TYPE, FIRST DAY, LAST DAY, COMMENT, MANAGER COMMENT"); } else { SW.WriteLine("EMPLOYEE NUMBER, FIRST NAME, LAST NAME, OPENING BALANCE, ENTITLED DAYS, DAYS, TOTAL DAYS, LEAVE TYPE, FIRST DAY, LAST DAY, COMMENT, MANAGER COMMENT"); } string row = ""; SW.WriteLine(row); List <EmployeeLeaveDays> cs = EmployeeLeaveDays.GetReportEmployeeLeave(Convert.ToInt32(DropDownListFinancialPeriod.SelectedValue), Convert.ToInt32(DropDownListLocation.SelectedValue), Convert.ToInt32(DropDownListLeaveType.SelectedValue), Convert.ToDateTime(TextBoxDateFrom.Text), Convert.ToDateTime(TextBoxDateTo.Text), Convert.ToInt32(DropDownListIsApproved.SelectedValue)); if (cs.Count > 0) { foreach (EmployeeLeaveDays employeeLeaveDays in cs) { if (DropDownListLeaveType.SelectedValue == "2") { row = String.Format("{0},{1},{2},{3},{4},{5},{6},{7},{8},{9},{10},{11},{12}", employeeLeaveDays.EmployeeNumber, employeeLeaveDays.FirstName, employeeLeaveDays.LastName, employeeLeaveDays.FormattedCurrentDays, employeeLeaveDays.FormattedEntitledDays, employeeLeaveDays.Days, employeeLeaveDays.FormattedTotalDays, employeeLeaveDays.FormattedEmployeeLeaveProjection, employeeLeaveDays.LeaveType, employeeLeaveDays.StartDate, employeeLeaveDays.EndDate, employeeLeaveDays.Comment, employeeLeaveDays.ReportsToComment); } else { row = String.Format("{0},{1},{2},{3},{4},{5},{6},{7},{8},{9},{10},{11}", employeeLeaveDays.EmployeeNumber, employeeLeaveDays.FirstName, employeeLeaveDays.LastName, employeeLeaveDays.FormattedCurrentDays, employeeLeaveDays.FormattedEntitledDays, employeeLeaveDays.Days, employeeLeaveDays.FormattedTotalDays, employeeLeaveDays.LeaveType, employeeLeaveDays.StartDate, employeeLeaveDays.EndDate, employeeLeaveDays.Comment, employeeLeaveDays.ReportsToComment); } 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(); }
protected void ButtonSearch_Click(object sender, EventArgs e) { GridViewResult.DataSource = EmployeeLeaveDays.GetEmployeeListFilterByReportsToId("%" + TextBoxSearchValue.Text + "%", Account.GetAccountByUserName(Page.User.Identity.Name.ToString()).AccountId, Convert.ToInt32(DropDownListFinancialPeriod.SelectedValue)); GridViewResult.DataBind(); ViewState["Search"] = "%" + TextBoxSearchValue.Text + "%"; }
protected void ButtonUpdateEmployeeLeaveDays_Click(object sender, EventArgs e) { if (Page.IsValid) { int reportsToTop = EmployeeReportsTo.GetEmployeeReportsToTOPByEmployeeId(this.employeeId).ReportsToId; //EmployeeLeaveDays employeeLeaveDaysExisting = EmployeeLeaveDays.GetEmployeeLeaveDaysByEmployeeIdFinancialPeriodId(this.employeeId, Convert.ToInt32(DropDownListFinancialPeriod.SelectedValue)); if (Convert.ToDateTime(TextBoxStartDate.Text) > Convert.ToDateTime(TextBoxEndDate.Text)) { LabelError.Text = "First Day cannot be after Last Day. <br />"; PanelError.Visible = true; return; } if (Convert.ToDateTime(TextBoxStartDate.Text) < DateTime.Now.AddMonths(-1)) { int loggedInId = Account.GetAccountByUserName(Page.User.Identity.Name.ToString()).EmployeeId; int reportsToId = EmployeeReportsTo.GetEmployeeReportsToByEmployeeId(this.employeeId, loggedInId).ReportsToId; if (loggedInId != reportsToId) { LabelError.Text = "Historic leave capture is prohibited. Kindly request your line manager to action. <br />"; PanelError.Visible = true; return; } } EmployeeLeaveDays employeeLeaveDays = new EmployeeLeaveDays(); employeeLeaveDays.EmployeeLeaveDaysId = this.employeeLeaveDaysId; employeeLeaveDays.EmployeeLeaveId = Convert.ToInt32(ViewState["employeeLeaveId"].ToString()); employeeLeaveDays.StartDate = Convert.ToDateTime(TextBoxStartDate.Text); employeeLeaveDays.EndDate = Convert.ToDateTime(TextBoxEndDate.Text); employeeLeaveDays.Days = Convert.ToDecimal(TextBoxDays.Text); employeeLeaveDays.Comment = TextBoxComment.Text; employeeLeaveDays.LeaveTypeId = Convert.ToInt32(DropDownListLeaveType.SelectedValue); employeeLeaveDays.IsApproved = (reportsToTop == 0) ? 0 : 3;//0 = Pending; 3 = Approved //0; //2; //Edited-Pending. Needs re-Approval for any changes made.; employeeLeaveDays.ModifiedUser = this.Master.LoggedOnAccount; employeeLeaveDays.Attachment = UploadAttachment(); try { employeeLeaveDays.Save(); SendEmployeeLeaveApprovalNotificationList(employeeLeaveDays.Attachment); ViewState["employeeLeaveDaysId"] = employeeLeaveDays.EmployeeLeaveDaysId; BindGridviewResult(); BindEmployeeLeave(); DropDownListLeaveType.ClearSelection(); DropDownListLeaveType.Items.FindByValue("0").Selected = true; TextBoxStartDate.Text = ""; TextBoxEndDate.Text = ""; TextBoxDays.Text = ""; TextBoxComment.Text = ""; ButtonSaveEmployeeLeaveDays.Visible = true; ButtonUpdateEmployeeLeaveDays.Visible = false; } 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; } } }
private void BindGridviewResult() { GridViewResult.DataSource = EmployeeLeaveDays.GetEmployeeLeaveDaysList(this.employeeId, Convert.ToInt32(DropDownListFinancialPeriod.SelectedValue)); GridViewResult.DataBind(); }