code.club

 找回密碼
 立即註冊
搜索
查看: 3100|回復: 0

用元件設計的計算多年通膨每年費用之表格後端的程式碼

[複製鏈接]
發表於 2021-12-1 07:59:16 | 顯示全部樓層 |閱讀模式
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Threading.Tasks;
  9. using System.Windows.Forms;

  10. namespace WindowsFormsApp48
  11. {
  12.     public partial class Form1 : Form
  13.     {
  14.         double yearSpend;
  15.         
  16.         double allYears;
  17.         double flatRate;
  18.         double sum = 0;
  19.         public Form1()
  20.         {
  21.             InitializeComponent();
  22.         }


  23.         private void button1_Click(object sender, EventArgs e)
  24.         {
  25.             if (textBox1.Text == "" || textBox2.Text == "" || textBox3.Text == "")
  26.                 MessageBox.Show("要輸入必要數字才能計算");
  27.             else if (textBox1.Text.Any(c => c < 46 || c > 57||c==47)|| textBox2.Text.Any(c => c < 46 || c > 57 || c == 47) || textBox3.Text.Any(c => c < 46 || c > 57 || c == 47))//若填入的是數字或小數點以外,則顯示錯誤
  28.                 MessageBox.Show("只能輸入數字");
  29.             else
  30.             {
  31.                 sum = 0;
  32.             yearSpend = 0;
  33.             flatRate = 0;
  34.             yearSpend = double.Parse(textBox1.Text);
  35.             
  36.                 flatRate = double.Parse(textBox2.Text);
  37.                 allYears = (int)double.Parse(textBox3.Text);
  38.                 for (double i = 1; i <= allYears; i++)
  39.                 {
  40.                     sum += yearSpend;
  41.                     yearSpend *= (1 + flatRate / 100);

  42.                 }
  43.                 label9.Text = sum.ToString("0.00");
  44.                 label10.Text = allYears.ToString();
  45.             }
  46.         }

  47.         private void button2_Click(object sender, EventArgs e)
  48.         {
  49.             yearSpend = 0;
  50.             flatRate = 0;
  51.             allYears = 0;
  52.             sum = 0;
  53.             textBox1.Text = "";
  54.             textBox2.Text = "";
  55.             textBox3.Text = "";
  56.             label9.Text = "";
  57.             label10.Text = "";

  58.         }

  59.         private void button3_Click(object sender, EventArgs e)
  60.         {
  61.             yearSpend = 0;
  62.             textBox1.Text = "";
  63.             sum = 0;
  64.         }

  65.         private void button4_Click(object sender, EventArgs e)
  66.         {
  67.             
  68.             flatRate = 0;
  69.             textBox2.Text = "";
  70.             sum = 0;
  71.         }

  72.         private void button5_Click(object sender, EventArgs e)
  73.         {
  74.            
  75.             allYears = 0;
  76.             textBox3.Text = "";
  77.             sum = 0;
  78.         }
  79.     }
  80. }
複製代碼
回復

使用道具 舉報

您需要登錄後才可以回帖 登錄 | 立即註冊

本版積分規則

小黑屋|手機版|Archiver|code.club  

GMT+8, 2024-4-19 04:00 , Processed in 0.070537 second(s), 20 queries .

Powered by Discuz! X3.2

© 2001-2013 Comsenz Inc.

快速回復 返回頂部 返回列表