protected void btnApprove_Click(object sender, EventArgs e) { bool CheckTrue = false; try { for (int r = 0; r < gvRequest.Rows.Count; r++) //find checkbox checked or not { CheckBox chkResult = (CheckBox)gvRequest.Rows[r].Cells[0].FindControl("chkResult1"); if (chkResult.Checked == true) { CheckTrue = true; } } if (CheckTrue != true) { string script = "alert('At least one check box need to selected to delete process.');"; ClientScript.RegisterStartupScript(this.GetType(), "test", script, true); } else { DepartmentBLL deptbll = new DepartmentBLL(); //int empid = 1004;// to update empid int empid = Convert.ToInt32(Session["loginUser"]); Department depart = deptbll.getDeptCodebyEmpID(empid); //need to update session value of employee id DepartmentRequBLL deptreqBll = new DepartmentRequBLL(); DateTime processdate = DateTime.Now; int dep_reqid = deptreqBll.insertHeaderRecord(processdate, "current", depart.Department_Code); //create header record first if (dep_reqid > 0) { for (int r = 0; r < gvRequest.Rows.Count; r++) //find checkbox checked or not { CheckBox chkResult = (CheckBox)gvRequest.Rows[r].Cells[0].FindControl("chkResult1"); if (chkResult.Checked == true) { string emp_reqID = gvRequest.DataKeys[r].Values["Emp_ReqID"].ToString(); deptreqBll.insertDetailRecord(dep_reqid, Convert.ToInt32(emp_reqID), processdate);//insert detail records updateStatustoEmpReq(Convert.ToInt32(emp_reqID), "Approved");//update request status String body = "Your registration have been approved! \n" + txtRejectInfo.Text + "\n Thanks \nBest Regards,\n"; String subject = "Approved your Stationery Request "; String employeeid = gvRequest.DataKeys[r].Values["EmployeeID"].ToString(); SendNotification(Convert.ToInt32(employeeid), body, subject); } } } } gvRequest_DataBind(); } catch (Exception ex) { lblMessage.Text = ex.Message; } }
void SendNotification(int empid, string body, string subject) { DepartmentRequBLL deptreqBll = new DepartmentRequBLL(); int currentuserid = Convert.ToInt32(Session["loginUser"]); //int currentuserid = Convert.ToInt32(System.Web.HttpContext.Current.User.Identity.Name.ToString()); //int currentuserid = 1004; //to update empid EmployeeBLL empbll = new EmployeeBLL(); Employee employeeinfo = new Employee(); Employee currentuserinfo = new Employee(); employeeinfo = empbll.getEmployeebyempid(empid); currentuserinfo = empbll.getEmployeebyempid(currentuserid); //to update employee type string body1 = body + currentuserinfo.EmployeeName; deptreqBll.sendNotificationToEmployee(employeeinfo.Email, currentuserinfo.Email, body1, subject); }