rendered paste bodyusing System;
using System.Collections;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
public partial class CpfCalc : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
List<ListItem> ageList;
CpfCalculator cpfCalculator;
List<CpfRate> cpfRatesList;
TableRow row;
TableCell cell;
if (IsPostBack == false)
{
ageList = new List<ListItem>();
ageList.Add(new ListItem("35 & Below", "35"));
ageList.Add(new ListItem("Above 35 - 45", "35"));
ageList.Add(new ListItem("Above 45 - 50", "45"));
ageList.Add(new ListItem("Above 50 - 55", "50"));
ageList.Add(new ListItem("Above 55 - 60", "55"));
ageList.Add(new ListItem("Above 60 - 65", "60"));
ageList.Add(new ListItem("Above 65", "66"));
foreach (ListItem age in ageList)
{
DropDownListAge.Items.Add(age);
}
row = new TableRow();
cell = new TableCell();
cell.Text = "Employee Age (Years)";
row.Cells.Add(cell);
cell = new TableCell();
cell.Text = "Employer Contribution (% of Wage)";
row.Cells.Add(cell);
cell = new TableCell();
cell.Text = "Employee Contribution (% of Wage)";
row.Cells.Add(cell);
cell = new TableCell();
cell.Text = "Total Contribution (% of Wage)";
row.Cells.Add(cell);
cell = new TableCell();
cell.Text = "Ordinary Account (Ration Of Contribution)";
row.Cells.Add(cell);
cell = new TableCell();
cell.Text = "Special Account (Ration Of Contribution)";
row.Cells.Add(cell);
cell = new TableCell();
cell.Text = "Medisave Account (Ration Of Contribution)";
row.Cells.Add(cell);
TableRates.Rows.Add(row);//end of table header
cpfCalculator = new CpfCalculator();
cpfRatesList = cpfCalculator.GetRates();
for (int i = 0; i < ageList.Count; i++)
{
row = new TableRow();
cell = new TableCell();
cell.Text = ageList[i].Text;
row.Cells.Add(cell);
cell = new TableCell();
cell.Text = cpfRatesList[i].Employer.ToString();
row.Cells.Add(cell);
cell = new TableCell();
cell.Text = cpfRatesList[i].Employee.ToString();
row.Cells.Add(cell);
cell = new TableCell();
cell.Text = (cpfRatesList[i].Employer + cpfRatesList[i].Employee).ToString();
row.Cells.Add(cell);
cell = new TableCell();
cell.Text = cpfRatesList[i].Ordinary.ToString();
row.Cells.Add(cell);
cell = new TableCell();
cell.Text = cpfRatesList[i].Special.ToString();
row.Cells.Add(cell);
cell = new TableCell();
cell.Text = cpfRatesList[i].Medisave.ToString();
row.Cells.Add(cell);
TableRates.Rows.Add(row);
}
}
}
protected void ButtonCalculate_Click(object sender, EventArgs e)
{
CpfCalculator calculator;
CpfContribution contribution;
int userAge;
double userWage;
try
{
userAge = Convert.ToInt32(DropDownListAge.SelectedValue);
userWage = Convert.ToDouble(TextBoxWage.Text);
calculator = new CpfCalculator();
if (RadioButtonListWageCap.SelectedValue == "Yes")
{
contribution = calculator.calculate(userAge, userWage, 4500);
}
else
{
contribution = calculator.calculate(userAge, userWage);
}
LabelEmployeeContribution.Text = contribution.Employee.ToString();
LabelEmployerContribution.Text = contribution.Employer.ToString();
LabelTotalContribution.Text = contribution.TotalContribution.ToString();
LabelNetPay.Text = contribution.NetPay.ToString();
LabelOrdinary.Text = contribution.Ordinary.ToString();
LabelSpecial.Text = contribution.Special.ToString();
LabelMedisave.Text = contribution.Medisave.ToString();
}
catch (Exception ex)
{
LabelErrorMessage.Text = ex.Message;
}
}
}