private async void btnCalculate_Click(object sender, EventArgs e)
        {
            CalcInterests calcInterests = new CalcInterests();

            Interest = calcInterests.CalculateSimpleInterest(tbPrincipal.Text.Trim().ToString(), tbYear.Text.Trim().ToString(), tbMonth.Text.Trim().ToString(), tbRate.Text.Trim().ToString());
            Converter converter = new Converter();

            Principal = converter.ToDouble(tbPrincipal.Text.Trim().ToString());
            Interestdata interestdata = new Interestdata
            {
                Interest   = Interest,
                Total      = Interest + Principal,
                Principal  = Principal,
                Rate       = converter.ToDouble(tbRate.Text.Trim().ToString()),
                Time_Month = (converter.ToDouble(tbYear.Text.Trim().ToString()) * 12) + converter.ToDouble(tbMonth.Text.Trim().ToString()),
            };

            if (interestDatalist == null)
            {
                List <Interestdata> list = new List <Interestdata>();
                interestDatalist = list;
            }
            interestDatalist.Add(interestdata);
            Label lb = new Label();

            lb.Location = new Point(251, 70);
            lb.Text     = Interest.ToString();
            dataGridView1.DataSource = null;
            dataGridView1.DataSource = interestDatalist;
            // Adding this label in the form
            this.Controls.Add(lb);
            //richTextBox1.Document.Blocks.Add(new Paragraph(new Run("Text")));
        }
        private void btnCalculate_Click(object sender, EventArgs e)
        {
            Converter converter = new Converter();

            try
            {
                CalcInterests calcInterests = new CalcInterests();
                Interest  = calcInterests.CalculateCompoundInterest(tbPrincipal.Text.Trim().ToString(), tbYear.Text.Trim().ToString(), tbMonth.Text.Trim().ToString(), tbRate.Text.Trim().ToString(), tbNoOfTimes.Text.Trim().ToString());
                Principal = converter.ToDouble(tbPrincipal.Text.Trim().ToString());
                Rate      = converter.ToDouble(tbRate.Text.Trim().ToString());
                Time      = converter.ToDouble(tbYear.Text.Trim().ToString()) * 12 + converter.ToDouble(tbMonth.Text.Trim().ToString());
                Interest  = Interest - Principal;
                Interestdata interestdata2 = new Interestdata();
                interestdata           = interestdata2;
                interestdata.Interest  = Interest;
                interestdata.Total     = Interest + Principal;
                interestdata.Principal = Principal;
                interestdata.Rate      = Rate;

                interestdata.Time_Month = Time;;
                if (interestDatalist == null)
                {
                    List <Interestdata> list = new List <Interestdata>();
                    interestDatalist = list;
                }
                interestDatalist.Add(interestdata);
                dataGridView1.DataSource = null;
                dataGridView1.DataSource = interestDatalist;
                Label lb = new Label();
                lb.Location = new Point(251, 70);
                lb.Text     = Interest.ToString();

                // Adding this label in the form
                this.Controls.Add(lb);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
        public double CalculateCompoundInterest(double p = 0, double i = 0, double timesInYear = 0)
        {
            Converter converter = new Converter();

            try
            {
                if (p == 0)
                {
                    Principal = converter.ToDouble(tbPrincipal.Text.Trim().ToString());
                }
                else
                {
                    Principal = p;
                }
                CalcInterests calcInterests = new CalcInterests();
                if (i == 0)
                {
                    Interest = calcInterests.CalculateCompoundInterest(Principal.ToString(), tbYear.Text.Trim().ToString(), tbMonth.Text.Trim().ToString(), tbRate.Text.Trim().ToString(), tbNoOfTimes.Text.Trim().ToString());
                }
                else
                {
                    Interest = i;
                }

                Rate     = converter.ToDouble(tbRate.Text.Trim().ToString());
                Time     = converter.ToDouble(tbYear.Text.Trim().ToString()) * 12 + converter.ToDouble(tbMonth.Text.Trim().ToString());
                Interest = Interest - Principal;
                Interestdata interestdata2 = new Interestdata();
                interestdata           = interestdata2;
                interestdata.Interest  = Interest;
                interestdata.SN        = Serial;
                interestdata.Total     = Interest + Principal;
                interestdata.Principal = Principal;
                interestdata.Rate      = Rate;
                if (timesInYear == 0)
                {
                    interestdata.Time_Month = Time;;
                }
                else
                {
                    interestdata.Time_Month = timesInYear;
                }
                if (interestDatalist == null)
                {
                    List <Interestdata> list = new List <Interestdata>();
                    interestDatalist = list;
                }
                interestDatalist.Add(interestdata);
                dataGridView1.DataSource = null;
                dataGridView1.DataSource = interestDatalist;
                Label lb = new Label();
                lb.Location = new Point(251, 70);
                lb.Text     = Interest.ToString();

                // Adding this label in the form
                this.Controls.Add(lb);
                return(interestdata.Total);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
            return(interestdata.Total);
        }