namespace StraightlineDepreciationCalculator
{
public partial class frmStraightlinedDepreciationCalculator : Form
{
public frmStraightlinedDepreciationCalculator()
{
InitializeComponent();
}
private void btnClear_Click(object sender, EventArgs e)
{
// Clears text boxes and selects first tab in form
txtPresentValue.Text = "";
txtSalvageValue.Text = "";
txtYearsOfDepreciation.Text = "";
txtDisplay.Text = "";
txtPresentValue.SelectAll();
txtPresentValue.Select();
}
private void btnExit_Click(object sender, EventArgs e)
{
// This function confirms and exits the application
DialogResult dlgresult;
dlgresult = MessageBox.Show("Do you want to exit the application?", "Close the form", MessageBoxButtons.YesNo);
if (dlgresult == DialogResult.Yes)
{
//Closes the application
System.Environment.Exit(1);
}
else
{
txtPresentValue.Select();
}
}
private void btnCalculate_Click(object sender, EventArgs e)
{
// Validates user inputted data and calculates the value at the end of each year
// displayed in multiline textbox
double dblPresentValue = 0;
double dblSalvageValue = 0;
int intYearsOfDepreciation = 0;
int intCounter = 0;
string strDisplay = "";
// Clear any text already in display
txtDisplay.Text = "";
// Get values from text boxes
dblPresentValue = Convert.ToDouble(txtPresentValue.Text);
dblSalvageValue = Convert.ToDouble(txtSalvageValue.Text);
intYearsOfDepreciation = Convert.ToInt32(txtYearsOfDepreciation.Text);
// Validate user entry
if (dblPresentValue < 1 | dblPresentValue > 1000000)
{
MessageBox.Show("Present value must be between $1 and $1,000,000");
txtPresentValue.Select(); //selects defective input text box
txtPresentValue.SelectAll();
}
else if (dblSalvageValue > dblPresentValue)
{
MessageBox.Show("Salvage value cannot be greater than Present Value");
txtSalvageValue.Select(); //selects defective input text box
txtSalvageValue.SelectAll();
}
else if (intYearsOfDepreciation < 0 | intYearsOfDepreciation > 25)
{
MessageBox.Show("Years of Depreciation must be in 1 - 25 range");
txtYearsOfDepreciation.Select(); //selects defective input text box
txtYearsOfDepreciation.SelectAll();
}
else
{
// set up column headers in text display
strDisplay = "Year Asset Value/r/n------- ---------------";
}
}
}
}