private void GenerateDataWithOutNoOfLeaves() { try { int employeeid = Convert.ToInt32(Session["currentpayslipemployeeid"]); lblDeductionForLeaves.Text = ""; lblNetSalary.Text = ""; if (txtNoOfLeaves.Text.Length <= 0) { txtNoOfLeaves.Text = "0"; } int noofleaves = Convert.ToInt32(txtNoOfLeaves.Text); if (noofleaves >= 0 && noofleaves <= 31) { DataTable dt1 = BusinessAccessLayer.Query("select * from employees e,levels l where e.levelid=l.levelid and employeeid=" + employeeid); decimal basicsalary = Convert.ToDecimal(dt1.Rows[0]["basicsalary"]); int daysinmonth = DateTime.DaysInMonth(Convert.ToInt32(dropYear.SelectedItem.Text), dropMonth.SelectedIndex + 1); decimal salaryperday = basicsalary / daysinmonth; decimal deductionforleaves = noofleaves * salaryperday; decimal netsalary = basicsalary - deductionforleaves; lblSalaryPerDay.Text = Math.Round(salaryperday, 2).ToString(); lblDeductionForLeaves.Text = Math.Round(deductionforleaves, 2).ToString(); lblNetSalary.Text = Math.Round(netsalary, 2).ToString(); } txtNoOfLeaves.Focus(); } catch (Exception ex) { lblError.Text = "Error: " + ex.Message; } }
private void Show() { try { lnkGeneratePayslip.Visible = false; gridPayslips.DataSource = null; gridPayslips.DataBind(); lblMessage.Text = ""; if (dropEmployee.SelectedIndex > 0) { lnkGeneratePayslip.Visible = true; string employeename = dropEmployee.SelectedItem.Text; int employeeid = Convert.ToInt32(BusinessAccessLayer.Query("select employeeid from employees where name='" + employeename + "'").Rows[0]["employeeid"]); DataTable dt = BusinessAccessLayer.Query("select payslipid,monthname + ' ' + convert(varchar,year) 'MonthAndYear',generatedon,basicsalary,noofleaves,salaryperday,deductionforleaves,netsalary from payslips ps where employeeid=" + employeeid + " order by year desc,ps.month desc"); if (dt.Rows.Count > 0) { gridPayslips.DataSource = dt; gridPayslips.DataBind(); } else { lblMessage.Text = "No payslips found."; } } dropEmployee.Focus(); } catch (Exception ex) { lblError.Text = "Error: " + ex.Message; } }
protected void Page_Load(object sender, EventArgs e) { try { if (Page.IsPostBack == false) { for (int i = DateTime.Now.Year; i >= 1950; i--) { dropYear.Items.Add(i.ToString()); } int employeeid = Convert.ToInt32(Session["currentpayslipemployeeid"]); DataTable dt = BusinessAccessLayer.Query("select * from employees e,levels l where e.levelid=l.levelid and employeeid=" + employeeid); if (dt.Rows.Count > 0) { lblEmployee.Text = Convert.ToString(dt.Rows[0]["name"]); lblBasicSalary.Text = Convert.ToString(dt.Rows[0]["basicsalary"]); DateTime date = DateTime.Now.AddMonths(-1); dropMonth.SelectedIndex = date.Month - 1; dropYear.SelectedIndex = dropYear.Items.IndexOf(new ListItem(date.Year.ToString())); GenerateData(); txtNoOfLeaves.Focus(); } else { Response.Redirect("payslips.aspx", false); } } } catch (Exception ex) { lblError.Text = "Error: " + ex.Message; } }
protected void Page_Load(object sender, EventArgs e) { try { if (Convert.ToString(Session["currentusertype"]) != "Administrator") { Response.Redirect("welcome.aspx"); } if (Page.IsPostBack == false) { dropLevel.Items.Clear(); DataTable dt = BusinessAccessLayer.Query("select * from levels order by levelid"); if (dt.Rows.Count > 0) { for (int i = 0; i < dt.Rows.Count; i++) { dropLevel.Items.Add(Convert.ToString(dt.Rows[i]["levelid"])); } dropLevel.SelectedIndex = 0; } else { Response.Redirect("welcome.aspx", false); } int newemployeeid = BusinessAccessLayer.GetNextID("employees", "employeeid"); lblEmployeeID.Text = Convert.ToString(newemployeeid); txtName.Focus(); } } catch (Exception ex) { lblError.Text = "Error: " + ex.Message; } }
protected void Page_Load(object sender, EventArgs e) { try { //if (Convert.ToString(Session["currentusertype"]) != "Manager") // Response.Redirect("welcome.aspx"); DataTable dt = BusinessAccessLayer.Query("select * from employees order by employeeid"); gridEmployees.DataSource = dt; gridEmployees.DataBind(); } catch (Exception ex) { lblError.Text = "Error: " + ex.Message; } }
protected void Page_Load(object sender, EventArgs e) { try { if (Convert.ToString(Session["currentusertype"]) != "Manager") { Response.Redirect("welcome.aspx"); } if (Page.IsPostBack == false) { dropTo.Focus(); dropTo.Items.Clear(); dropTo.Items.Add("---Select---"); DataTable dt = BusinessAccessLayer.Query("select * from employees order by levelid"); if (dt.Rows.Count > 0) { for (int i = 0; i < dt.Rows.Count; i++) { dropTo.Items.Add(Convert.ToString(dt.Rows[i]["name"])); } dropTo.SelectedIndex = 0; if (Session["replyemployeename"] != null && Convert.ToString(Session["replyemployeename"]) != "") { int n = 0; for (int i = 0; i < dropTo.Items.Count; i++) { if (Convert.ToString(Session["replyemployeename"]) == dropTo.Items[i].Text) { n = i; } } Session["replyemployeename"] = null; dropTo.SelectedIndex = n; txtMessage.Focus(); } } else { Response.Redirect("welcome.aspx", false); } } } catch (Exception ex) { lblError.Text = "Error: " + ex.Message; } }
protected void lnkGeneratePayslip_Click(object sender, EventArgs e) { try { if (dropEmployee.SelectedIndex > 0) { string employeename = dropEmployee.SelectedItem.Text; int employeeid = Convert.ToInt32(BusinessAccessLayer.Query("select employeeid from employees where name='" + employeename + "'").Rows[0]["employeeid"]); Session["currentpayslipemployeeid"] = employeeid; Response.Redirect("generatepayslip.aspx", false); } } catch (Exception ex) { lblError.Text = "Error: " + ex.Message; } }
private void Show() { gridMessages.DataSource = null; gridMessages.DataBind(); lblMessage.Text = ""; DataTable dt = BusinessAccessLayer.Query("select * from messages where messagefrom='" + from + "' order by date desc"); if (dt.Rows.Count > 0) { gridMessages.DataSource = dt; gridMessages.DataBind(); } else { lblMessage.Text = "No Messages."; } }
private void Show() { gridMessages.DataSource = null; gridMessages.DataBind(); lblMessage.Text = ""; int to = Convert.ToInt32(Session["currentemployeeid"]); DataTable dt = BusinessAccessLayer.Query("select * from messages where messagefrom='Manager' and employeeid=" + to + " and active=1 order by date desc"); if (dt.Rows.Count > 0) { gridMessages.DataSource = dt; gridMessages.DataBind(); } else { lblMessage.Text = "No Messages."; } }
protected void Page_Load(object sender, EventArgs e) { try { if (Convert.ToString(Session["currentusertype"]) != "Manager") { Response.Redirect("welcome.aspx"); } if (Page.IsPostBack == false) { dropEmployee.Focus(); dropEmployee.Items.Clear(); dropEmployee.Items.Add("---Select---"); DataTable dt = BusinessAccessLayer.Query("select * from employees order by name"); if (dt.Rows.Count > 0) { for (int i = 0; i < dt.Rows.Count; i++) { dropEmployee.Items.Add(Convert.ToString(dt.Rows[i]["name"])); } dropEmployee.SelectedIndex = 0; if (Session["currentpayslipemployeeid"] != null && Convert.ToString(Session["currentpayslipemployeeid"]) != "") { int employeeid = Convert.ToInt32(Session["currentpayslipemployeeid"]); string empname = Convert.ToString(BusinessAccessLayer.Query("select name from employees where employeeid=" + employeeid).Rows[0]["name"]); dropEmployee.SelectedIndex = dropEmployee.Items.IndexOf(new ListItem(empname)); Session["currentpayslipemployeeid"] = null; Show(); } } else { Response.Redirect("welcome.aspx", false); } } } catch (Exception ex) { lblError.Text = "Error: " + ex.Message; } }
protected void gridPayslips_RowCommand(object sender, GridViewCommandEventArgs e) { if (e.CommandName == "Print") { int rowindex = Convert.ToInt32(e.CommandArgument); string monthandyear = gridPayslips.Rows[rowindex].Cells[1].Text; int payslipid = Convert.ToInt32(gridPayslips.Rows[rowindex].Cells[0].Text); DataTable dt1 = BusinessAccessLayer.Query("select * from payslips where payslipid=" + payslipid); if (dt1.Rows.Count > 0) { DataTable dt2 = BusinessAccessLayer.Query("select * from employees where employeeid=" + dt1.Rows[0]["employeeid"]); string htmlcode = ""; htmlcode += "<h1 align=center class='mylabel' style='font-family:Monotype Corsiva;font-size:30px;color:white;background-color:black;'>" + ConfigurationManager.AppSettings["CompanyName"] + "</h1>"; htmlcode += "<h2 align=center class='mylabel' style='font-family:Tahoma;font-size:16px;'>" + ConfigurationManager.AppSettings["City"] + "</h2>"; htmlcode += "<h2 align=center class='mylabel' style='font-family:Comic Sans MS;font-size:15px;'>Payslip for the Month of " + monthandyear + "</h2>"; htmlcode += "<table width=97% class='mylabel' cellpadding=10 align=center>"; htmlcode += "<tr><td colspan=2><hr></tr>"; htmlcode += "<tr><td align=right>Employee ID:</td><td>" + dt1.Rows[0]["employeeid"] + "</td></tr>"; htmlcode += "<tr><td align=right>Employee Name:</td><td>" + dt2.Rows[0]["name"] + "</td></tr>"; htmlcode += "<tr><td align=right>Phone:</td><td>" + dt2.Rows[0]["phone"] + "</td></tr>"; htmlcode += "<tr><td align=right>E-Mail:</td><td>" + dt2.Rows[0]["email"] + "</td></tr>"; htmlcode += "<tr><td align=right>Designation:</td><td>" + dt2.Rows[0]["designation"] + "</td></tr>"; htmlcode += "<tr><td align=right>Level:</td><td>" + dt2.Rows[0]["levelid"] + "</td></tr>"; htmlcode += "<tr><td align=right>Generated On:</td><td>" + dt1.Rows[0]["generatedon"] + "</td></tr>"; htmlcode += "<tr><td align=right>Basic Salary:</td><td>" + dt1.Rows[0]["basicsalary"] + "</td></tr>"; htmlcode += "<tr><td align=right>No. of Leaves:</td><td>" + dt1.Rows[0]["noofleaves"] + "</td></tr>"; htmlcode += "<tr><td align=right>Deduction for Leaves:</td><td>" + dt1.Rows[0]["deductionforleaves"] + "</td></tr>"; htmlcode += "<tr><td align=right style='font-weight:bold;border-top-style:solid;border-bottom-style:solid;border-top-color:black;border-bottom-color:black;'>Net Salary</td><td style='font-weight:bold;border-top-style:solid;border-bottom-style:solid;border-top-color:black;border-bottom-color:black;'>" + dt1.Rows[0]["netsalary"] + "</td></tr>"; htmlcode += "<tr><td align=right></td><td> </td></tr>"; htmlcode += "<tr><td align=right></td><td align=center style='font-weight:bold'>Signature of the<br>Payroll Manager</td>"; htmlcode += "</table>"; Session["htmlcodetoprint"] = htmlcode; Response.Write("<script language='javascript'>window.open('print.aspx','prn','toolbar=no,menubar=no,scrollbars=yes,location=no');</script>"); } } else if (e.CommandName == "Open") { } }
protected void btnSubmit_Click(object sender, EventArgs e) { try { if (Page.IsValid) { int employeeid, month, year, noofleaves; string monthname; DateTime generatedon; decimal basicsalary, salaryperday, deductionperleaves, netsalary; employeeid = Convert.ToInt32(Session["currentpayslipemployeeid"]); month = dropMonth.SelectedIndex + 1; monthname = dropMonth.SelectedItem.Text; year = Convert.ToInt32(dropYear.SelectedItem.Text); generatedon = DateTime.Now; basicsalary = Convert.ToDecimal(lblBasicSalary.Text); noofleaves = Convert.ToInt32(txtNoOfLeaves.Text); salaryperday = Convert.ToDecimal(lblSalaryPerDay.Text); deductionperleaves = Convert.ToDecimal(lblDeductionForLeaves.Text); netsalary = Convert.ToDecimal(lblNetSalary.Text); DataTable dt = BusinessAccessLayer.Query("select * from payslips where employeeid=" + employeeid + " and month=" + month + " and year=" + year); string sqlstr; if (dt.Rows.Count == 0) { sqlstr = "insert into payslips values(" + employeeid + "," + month + ",'" + monthname + "'," + year + ",'" + generatedon.ToString("yyyy-MM-ddTHH:mm:ss.fff") + "'," + basicsalary + "," + noofleaves + "," + salaryperday + "," + deductionperleaves + "," + netsalary + ")"; } else { sqlstr = "update payslips set generatedon='" + generatedon.ToString() + "',basicsalary=" + basicsalary + ",noofleaves=" + noofleaves + ",salaryperday=" + salaryperday + ",deductionforleaves=" + deductionperleaves + ",netsalary=" + netsalary + " where employeeid=" + employeeid + " and month=" + month + " and year=" + year; } BusinessAccessLayer.NonQuery(sqlstr); Response.Redirect("payslips.aspx"); } } catch (Exception ex) { lblError.Text = "Error: " + ex.Message; } }
protected void btnSubmit_Click(object sender, EventArgs e) { try { string date, messagefrom, messageto, message; int employeeid; date = DateTime.Now.ToString(); messagefrom = from; messageto = dropTo.SelectedItem.Text; message = txtMessage.Text; DataTable dt = BusinessAccessLayer.Query("select employeeid from employees where name='" + messageto + "'"); if (dt.Rows.Count > 0) { employeeid = Convert.ToInt32(dt.Rows[0]["employeeid"]); string sqlstr = "insert into messages values('" + date + "','" + messagefrom + "','" + messageto + "','" + message + "'," + employeeid + ",1)"; BusinessAccessLayer.NonQuery(sqlstr); } Response.Redirect("managermessageoutbox.aspx", false); } catch (Exception ex) { lblError.Text = "Error: " + ex.Message; } }
protected void btnSubmit_Click(object sender, EventArgs e) { try { lblError.Text = ""; string username = txtUserName.Text; string password = txtPassword.Text; if (username == "admin" && password == "payroll123") { Session["currentusertype"] = "Administrator"; Response.Redirect("welcome.aspx", false); } else if (username == "manager" && password == "payroll123") { Session["currentusertype"] = "Manager"; Response.Redirect("welcome.aspx", false); } else { DataTable dt = BusinessAccessLayer.Query("select * from employees where username='******' and password='******'"); if (dt.Rows.Count >= 1) { Session["currentusertype"] = "Employee"; Session["currentusername"] = username; Session["currentuserpassword"] = password; Session["currentemployeeid"] = Convert.ToInt32(dt.Rows[0]["employeeid"]); Session["currentemployeename"] = Convert.ToString(dt.Rows[0]["name"]); Response.Redirect("welcome.aspx", false); } } } catch (Exception ex) { lblError.Text = "Error: " + ex.Message; } }
private void Show() { try { gridPayslips.DataSource = null; gridPayslips.DataBind(); lblMessage.Text = ""; int employeeid = Convert.ToInt32(Session["currentemployeeid"]); DataTable dt = BusinessAccessLayer.Query("select payslipid,monthname + ' ' + convert(varchar,year) 'MonthAndYear',generatedon,basicsalary,noofleaves,salaryperday,deductionforleaves,netsalary from payslips ps where employeeid=" + employeeid + " order by year desc,ps.month desc"); if (dt.Rows.Count > 0) { gridPayslips.DataSource = dt; gridPayslips.DataBind(); } else { lblMessage.Text = "No payslips found."; } } catch (Exception ex) { lblError.Text = "Error: " + ex.Message; } }