Tuesday, November 2, 2010

Visual C# projects no 2...

Simple Interest Calculation

snapshot:
Add caption


code:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace WindowsFormsApplication2
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        double p, n, r, intr, tot;
        private void btn_calint_Click(object sender, EventArgs e)
        {
            int I = Controls.Count;
            for (int i = 0; i < I; i++)
            {
                if ((String)(Controls[i].Tag) == "S" && Controls[i].Text == "")
                {
                    MessageBox.Show("you have not entered values in " + Controls[i].Name, "error", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    Controls[i].Focus();
                    return;
                }
            }

            p=double.Parse(txt_dep.Text);
            r = double.Parse(txt_int.Text);
            n = double.Parse(txt_per.Text);
            intr = (p * n * r) / 100;
            tot = p + intr;

            if (sender == btn_calint)
            {
                txt_calint.Text = intr.ToString();
            }
        }

        private void btn_cancel_Click(object sender, EventArgs e)
        {
            txt_dep.Text = "";
            txt_int.Text = "";
            txt_per.Text = "";
            txt_calint.Text = "";
            txt_totamt.Text = "";
        }

        private void btn_exit_Click(object sender, EventArgs e)
        {
            Application.Exit();
        }

        private void txt_dep_TextChanged(object sender, EventArgs e)
        {
            try
            {
                p = Double.Parse(txt_dep.Text);
            }
            catch
            {
                SendKeys.Send("{BACKSPACE}");
            }
        }

        private void txt_int_TextChanged(object sender, EventArgs e)
        {
            try
            {
                r = Double.Parse(txt_int.Text);
            }
            catch
            {
                SendKeys.Send("{BACKSPACE}");
            }
        }

        private void txt_per_TextChanged(object sender, EventArgs e)
        {
            try
            {
                n = Double.Parse(txt_per.Text);
            }
            catch
            {
                SendKeys.Send("{BACKSPACE}");
            }
        }

        private void txt_dep_Validating(object sender, CancelEventArgs e)
        {
            if (txt_dep.Text == "")
                e.Cancel = true;
        }

        private void txt_int_Validating(object sender, CancelEventArgs e)
        {
            if (txt_int.Text == "")
                e.Cancel = true;
        }

        private void txt_per_Validating(object sender, CancelEventArgs e)
        {
            if (txt_per.Text == "")
                e.Cancel = true;
        }

        private void btn_totamt_Click(object sender, EventArgs e)
        {
            if (sender == btn_totamt)
            {
                txt_totamt.Text = tot.ToString();
            }
        }
    }
}

No comments:

Post a Comment