Пример #1
0
 private void btnShow_Click(object sender, EventArgs e)
 {
     // 按鈕:顯示儲存內容 (輸出 strGrade 的資料到 lblGrade)
     try
     {
         // 測試 strGrade 是否有存入的資料,因已設定所有欄位都有資料才能存入,所以測試一個欄位就好,不用測試四個欄位。
         if (strGrade.Name != null)
         {
             string FmtCN   = String.Format("{0,3}", strGrade.CN.ToString());
             string FmtEN   = String.Format("{0,3}", strGrade.EN.ToString());
             string FmtMath = String.Format("{0,3}", strGrade.Math.ToString());
             lblGrade.Text = $"姓名:{strGrade.Name}\n" +
                             $"國文:{FmtCN} 分\n" +
                             $"英文:{FmtEN} 分\n" +
                             $"數學:{FmtMath} 分";
         }
         else
         {
             MessageBox.Show("請先存入資料", "Error", MessageBoxButtons.OK, MessageBoxIcon.Warning);
         }
     }
     catch (Exception ex)
     {
         Form00.msgError(ex);
     }
 }
Пример #2
0
        private void btnHi_Click(object sender, EventArgs e)
        {
            // 點擊按鈕:Say Hi!
            string Cname    = txtCname.Text;
            string Ename    = txtEname.Text;
            string Sex      = txtSex.Text;
            string StarSign = txtStarSign.Text;

            try
            {
                DialogResult Result = MessageBox.Show("Hi,我是 " + Cname + ",\r\n"
                                                      + "英文名字是 " + Ename + ",\r\n"
                                                      + "性別是 " + Sex + ",\r\n"
                                                      + "星座是 " + StarSign + ",\r\n"
                                                      + "很高興認識你。 ,\r\n\r\n"
                                                      + "繼續請按確定,離開請按取消。",
                                                      "Say Hi!",
                                                      MessageBoxButtons.YesNo,
                                                      MessageBoxIcon.Information
                                                      );
                if (Result == DialogResult.No)
                {
                    this.Close();
                }
            }
            catch (Exception ex)
            {
                Form00.msgError(ex);
            }
        }
Пример #3
0
 private void btnRngX_Click(object sender, EventArgs e)
 {
     // 按鈕:隨機加入20筆
     try
     {
         btnTotal.Enabled = true;
         int x = ID;
         while (ID < x + 20)
         {
             strGrade[ID].Name = "Student" + string.Format("{0:000}", ID + 1);
             strGrade[ID].CN   = R.Next(0, 101);                   // R.Next(0,100) 不會產生 100
             strGrade[ID].EN   = R.Next(0, 101);
             strGrade[ID].Math = R.Next(0, 101);
             strGrade[ID].Sum  = strGrade[ID].CN + strGrade[ID].EN + strGrade[ID].Math;
             strGrade[ID].Avg  = strGrade[ID].Sum / 3.0;
             MaxAndMin();
             lblGrade.Text += string.Format("{0,2}{1,6}{2,6}{3,6}{4,6}{5,8:f1}{6,8}{7,8}\n",
                                            strGrade[ID].Name, strGrade[ID].CN, strGrade[ID].EN, strGrade[ID].Math, strGrade[ID].Sum, strGrade[ID].Avg, strGrade[ID].MajorMin, strGrade[ID].MajorMax);
             ID++;
             txtCurrent.Text = ID.ToString();
             txtLeft.Text    = (100 - ID).ToString();
         }
         if (ID == 100)
         {
             MessageBox.Show("記憶空間已滿,請先刪除舊有資料。", "警告!", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
             btnAdd.Enabled = false;
         }
         btnReset.Enabled = true;
     }
     catch (Exception ex)
     {
         Form00.msgError(ex);
     }
 }
Пример #4
0
        private void btnRngX2_Click(object sender, EventArgs e)
        {
            //按鈕:隨機加入20筆(2)_偷吃步 直接觸發20次隨機單筆的按鈕
            try
            {
                int x = ID;
                if (x + 20 > 100)
                {
                    MessageBox.Show("新增20筆後會超過上限100筆,請先清除資料。");
                    return;
                }

                for (int i = 0; i < 20; i++)
                {
                    btnRng_Click(null, null);
                    //btnRng.PerformClick(); //另一個寫法
                }

                if (ID == 100)
                {
                    MessageBox.Show("記憶空間已滿,請先刪除舊有資料。", "警告!", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                    btnAdd.Enabled = false;
                }
                btnReset.Enabled = true;
            }
            catch (Exception ex)
            {
                Form00.msgError(ex);
            }
        }
Пример #5
0
 private void btnTotal_Click(object sender, EventArgs e)
 {
     // 按扭:各科統計
     try
     {
         for (int i = 0; i < ID; i++)
         {
             strSta.TCN   += strGrade[i].CN;
             strSta.TEN   += strGrade[i].EN;
             strSta.TMath += strGrade[i].Math;
         }
         strSta.AvgCN   = strSta.TCN / (double)ID;
         strSta.AvgEN   = strSta.TEN / (double)ID;
         strSta.AvgMath = strSta.TMath / (double)ID;
         strSta.MinCN   = 999;
         strSta.MinEN   = 999;
         strSta.MinMath = 999;
         for (int j = 0; j < ID; j++)
         {
             if (strGrade[j].CN > strSta.MaxCN)
             {
                 strSta.MaxCN = strGrade[j].CN;
             }
             if (strGrade[j].EN > strSta.MaxEN)
             {
                 strSta.MaxEN = strGrade[j].EN;
             }
             if (strGrade[j].Math > strSta.MaxMath)
             {
                 strSta.MaxMath = strGrade[j].Math;
             }
             if (strGrade[j].CN < strSta.MinCN)
             {
                 strSta.MinCN = strGrade[j].CN;
             }
             if (strGrade[j].EN < strSta.MinEN)
             {
                 strSta.MinEN = strGrade[j].EN;
             }
             if (strGrade[j].Math < strSta.MinMath)
             {
                 strSta.MinMath = strGrade[j].Math;
             }
         }
         lblCaculate.Text = string.Format("總分{0,8} {1,6}{2,6}\n", strSta.TCN, strSta.TEN, strSta.TMath) + string.Format("平均{0,10:f1} {1,6:f1}{2,6:f1}\n", strSta.AvgCN, strSta.AvgEN, strSta.AvgMath) + string.Format("最高分{0,6}{1,7}{2,6}\n", strSta.MaxCN, strSta.MaxEN, strSta.MaxMath) + string.Format("最低分{0,6}{1,7}{2,6}", strSta.MinCN, strSta.MinEN, strSta.MinMath);
         btnTotal.Enabled = false;
         btnAdd.Enabled   = false;
         btnRng.Enabled   = false;
         btnReset.Enabled = true;
         btnRngX.Enabled  = false;
     }
     catch (Exception ex)
     {
         Form00.msgError(ex);
     }
 }
Пример #6
0
        int MonthPay; // 月付額

        private double Handmade(double A, double P, double R)
        {
            // 方法:月付款公式 = a * r * (1 + r) ^ p / [(1 + r) ^ p - 1] * p  (a:本金, r:利率, p:期數)
            try
            {
                MonthPay = Convert.ToInt32(A * R * Math.Pow((1 + R), P) / (Math.Pow((1 + R), P) - 1));
                return(MonthPay);
            }
            catch (Exception ex)
            {
                Form00.msgError(ex);
                return(0);
            }
        }
Пример #7
0
 private void btnTotal_Click(object sender, EventArgs e)
 {
     // 點擊按鈕:總付款(PMT) (使用 PMT 函數)
     try
     {
         A        = Convert.ToDouble(txtAmount.Text) - Convert.ToDouble(txtDownPayment.Text);
         P        = Convert.ToDouble(txtYear.Text) * 12;
         R        = Convert.ToDouble(txtRate.Text) / 1200;
         MonthPay = Convert.ToInt32(Financial.Pmt(R, P, A)) * -1; // using Microsoft.VisualBasic;
         MessageBox.Show("總付款:" + (double)MonthPay * P + "元");
     }
     catch (Exception ex)
     {
         Form00.msgError(ex);
     }
 }
Пример #8
0
 private void btnCredit_Click(object sender, EventArgs e)
 {
     // 按鈕:信用卡
     try
     {
         if (Total < 1)                 // 如果總金額 < 1
         {
             MessageBox.Show("尚未點餐!", "確認付款", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
             return;
         }
         MessageBox.Show($"總金額:NT$  {Total} \n折扣後金額:NT$ {(double)Total * 0.9}", "確認付款", MessageBoxButtons.OKCancel);
     }
     catch (Exception ex)
     {
         Form00.msgError(ex);
     }
 }
Пример #9
0
        private void btnMonthPay_Click(object sender, EventArgs e)
        {
            // 點擊按鈕:月付款(公式)
            // 月付款公式:月付款 = a * r * (1 + r) ^ p / [(1 + r) ^ p - 1]   (a:本金, r:利率, p:期數)
            try
            {
                A        = Convert.ToDouble(txtAmount.Text) - Convert.ToDouble(txtDownPayment.Text);
                P        = Convert.ToDouble(txtYear.Text) * 12;
                R        = Convert.ToDouble(txtRate.Text) / 1200;
                MonthPay = Convert.ToInt32(Handmade(A, P, R));

                MessageBox.Show("月付額 = " + MonthPay);
            }
            catch (Exception ex)
            {
                Form00.msgError(ex);
            }
        }
Пример #10
0
        private void btnTotal2_Click(object sender, EventArgs e)
        {
            // 點擊按鈕:總付款(公式) (使用公式)
            // 總付款公式:總付款 = 月付款 * 期數
            try
            {
                A        = Convert.ToDouble(txtAmount.Text) - Convert.ToDouble(txtDownPayment.Text);
                P        = Convert.ToDouble(txtYear.Text) * 12;
                R        = Convert.ToDouble(txtRate.Text) / 1200;
                MonthPay = Convert.ToInt32(Handmade(A, P, R));

                MessageBox.Show("總付款:" + MonthPay * P + "元");
            }
            catch (Exception ex)
            {
                Form00.msgError(ex);
            }
        }
Пример #11
0
        private void btnAdd_Click(object sender, EventArgs e)
        {
            // 按鈕:加入學生資料
            try
            {
                // 測試資料是否為空
                if (txtName.Text == string.Empty || txtCN.Text == string.Empty || txtEng.Text == string.Empty || txtMath.Text == string.Empty)
                {
                    MessageBox.Show("姓名或成績不可為空!!", "警告!", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                    return;
                }

                btnTotal.Enabled = true;
                // 指派資料給 strGrade
                strGrade[ID].Name = txtName.Text;
                strGrade[ID].CN   = int.Parse(txtCN.Text);
                strGrade[ID].EN   = int.Parse(txtEng.Text);
                strGrade[ID].Math = int.Parse(txtMath.Text);
                strGrade[ID].Sum  = strGrade[ID].CN + strGrade[ID].EN + strGrade[ID].Math;
                strGrade[ID].Avg  = strGrade[ID].Sum / 3;
                // 計算最高最低分科目
                MaxAndMin();

                //lblGrade.Text = lblGrade.Text + string.Format("{0,-10}", strGrade[ID].Name) + string.Format("{0,6}", strGrade[ID].CN) + string.Format("{0,6}", strGrade[ID].EN) + string.Format("{0,6}", strGrade[ID].Math) +
                //    string.Format("{0,6}", strGrade[ID].Sum) + string.Format("{0,8:f1}", strGrade[ID].Avg) + string.Format("{0,8}", strGrade[ID].MajorMin) + string.Format("{0,8}\n", strGrade[ID].MajorMax);
                lblGrade.Text += string.Format("{0,-10}{1,6}{2,6}{3,6}{4,6}{5,8:f1}{6,8}{7,8}\n",
                                               strGrade[ID].Name, strGrade[ID].CN, strGrade[ID].EN, strGrade[ID].Math, strGrade[ID].Sum, strGrade[ID].Avg, strGrade[ID].MajorMin, strGrade[ID].MajorMax);

                ID++;
                txtCurrent.Text = ID.ToString();
                txtLeft.Text    = (100 - ID).ToString();
                if (ID == 100)
                {
                    MessageBox.Show("記憶空間已滿,請先刪除舊有資料。", "警告!", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                    btnRng.Enabled = false;
                }

                btnReset.Enabled = true;
            }
            catch (Exception ex)
            {
                Form00.msgError(ex);
            }
        }
Пример #12
0
 private void btnMultiply_Click(object sender, EventArgs e)
 {
     try
     {
         if (double.TryParse(txtNum1.Text, out number1) && double.TryParse(txtNum2.Text, out number2))
         {
             txtAnswer.Text   = $" {Multiply(number1, number2)}";
             lblEquation.Text = $" {number1} - {number2} = {Multiply(number1, number2)}";
         }
         else
         {
             msg();
         }
     }
     catch (Exception ex)
     {
         Form00.msgError(ex);
     }
 }
Пример #13
0
        private void btnMenuD_Click(object sender, EventArgs e)
        {
            // 按鈕:D 菜單
            try
            {
                DA++;                           // 數量 + 1
                Total        += 320;            // 累加總金額
                lblTotal.Text = "NT$ " + Total; // 秀出總金額

                // 設定品項數量金額清單
                DL = String.Format("{0,8}", "海景第一排 x ") + String.Format("{0,3}", DA) + ",共NT$ " + String.Format("{0,5}", DPrize * DA) + " 元\n";

                lblList.Text = AL + BL + CL + DL;                 // 加總所有品項清單並秀出
            }
            catch (Exception ex)
            {
                Form00.msgError(ex);
            }
        }
Пример #14
0
        private void btnMenuC_Click(object sender, EventArgs e)
        {
            // 按鈕:C 菜單
            try
            {
                CA++;                           // 數量 + 1
                Total        += 350;            // 累加總金額
                lblTotal.Text = "NT$ " + Total; // 秀出總金額

                // 設定品項數量金額清單
                CL = String.Format("{0,10}", "中部粽 x ") + String.Format("{0,3}", CA) + ",共NT$ " + String.Format("{0,5}", CPrize * CA) + " 元\n";

                lblList.Text = AL + BL + CL + DL;                 // 加總所有品項清單並秀出
            }
            catch (Exception ex)
            {
                Form00.msgError(ex);
            }
        }
Пример #15
0
        private int Total = 0;     // 總金額

        private void btnMenuA_Click(object sender, EventArgs e)
        {
            // 按鈕:A 菜單
            try
            {
                AA++;                           // 數量 + 1
                Total        += 120;            // 累加總金額
                lblTotal.Text = "NT$ " + Total; // 秀出總金額

                // 設定品項數量金額清單
                AL = String.Format("{0,11}", "3D油飯 x ") + String.Format("{0,3}", AA) + ",共NT$ " + String.Format("{0,5}", APrize * AA) + " 元\n";

                lblList.Text = AL + BL + CL + DL;                 // 加總所有品項清單並秀出
            }
            catch (Exception ex)
            {
                Form00.msgError(ex);
            }
        }
Пример #16
0
 private void btnCash_Click(object sender, EventArgs e)
 {
     // 按鈕:現金
     try
     {
         if (Total < 1)                 // 如果總金額 < 1
         {
             MessageBox.Show("尚未點餐!", "確認付款", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
         }
         else
         {
             MessageBox.Show($"總金額:NT$  {Total} ", "確認付款", MessageBoxButtons.OKCancel);
         }
     }
     catch (Exception ex)
     {
         Form00.msgError(ex);
     }
 }
Пример #17
0
        private void btnRemove_Click(object sender, EventArgs e) // 按鈕:移除資料
        {
            try
            {
                if (GradeList.Count == 0)
                {
                    MessageBox.Show("沒東西了,你再刪我要叫了。");
                    return;
                }

                GradeList.RemoveAt(0);
                MaxAndMin();
                ShowGrade();
            }
            catch (Exception ex)
            {
                Form00.msgError(ex);
            }
        }
Пример #18
0
 private void btnSearch_Click(object sender, EventArgs e)  // 按鈕:Search
 {
     try
     {
         int num  = int.Parse(textBox1.Text);
         int num2 = int.Parse(textBox2.Text);
         lblGrade.Text = string.Empty;
         for (int i = 0; i < GradeList.Count; i++)
         {
             if (num <= GradeList[i].CN && num2 >= GradeList[i].CN)
             {
                 Label gradeShowLabel = lblGrade;
                 gradeShowLabel.Text = gradeShowLabel.Text + string.Format("{0,-6}{1,6}{2,6}", GradeList[i].Name, GradeList[i].CN, GradeList[i].EN) + string.Format("{0,6}{1,6}{2,6:N1}", GradeList[i].Math, GradeList[i].Sum, GradeList[i].Avg) + string.Format("{0,6}{1,6}\n", GradeList[i].MajorMin, GradeList[i].MajorMax);
             }
         }
     }
     catch (Exception ex)
     {
         Form00.msgError(ex);
     }
 }
Пример #19
0
 private void btnClear_Click(object sender, EventArgs e)
 {
     // 按鈕:清除清單
     try
     {
         lblList.Text  = "尚未點餐";
         Total         = 0;      // 總金額歸 0
         lblTotal.Text = "NT$ " + Total;
         AA            = 0;      // 品項數量歸 0
         BA            = 0;
         CA            = 0;
         DA            = 0;
         AL            = string.Empty;      // 清空品項數量金額清單
         BL            = string.Empty;
         CL            = string.Empty;
         DL            = string.Empty;
     }
     catch (Exception ex)
     {
         Form00.msgError(ex);
     }
 }
Пример #20
0
 private void btnReset_Click(object sender, EventArgs e)
 {
     // 按鈕:各科統計
     try
     {
         for (int i = 0; i < ID; i++)
         {
             strGrade[i].CN   = 0;
             strGrade[i].EN   = 0;
             strGrade[i].Math = 0;
             strGrade[i].Sum  = 0.0;
             strGrade[i].Avg  = 0.0;
             strSta.AvgCN     = 0.0;
             strSta.AvgEN     = 0.0;
             strSta.AvgMath   = 0.0;
             strSta.TCN       = 0.0;
             strSta.TEN       = 0.0;
             strSta.TMath     = 0.0;
             strSta.MaxCN     = 0;
             strSta.MaxEN     = 0;
             strSta.MaxMath   = 0;
             strSta.MinCN     = 0;
             strSta.MinEN     = 0;
             strSta.MinMath   = 0;
         }
         ID               = 0;
         lblGrade.Text    = string.Empty;
         lblCaculate.Text = string.Empty;
         btnAdd.Enabled   = true;
         btnRng.Enabled   = true;
         btnRngX.Enabled  = true;
         btnReset.Enabled = false;
     }
     catch (Exception ex)
     {
         Form00.msgError(ex);
     }
 }
Пример #21
0
 private void btnReport_Click(object sender, EventArgs e)
 {
     // 點擊按鈕:Report)
     try
     {
         Form02_Loan_Report flr = new Form02_Loan_Report();
         // 不同 form取控件值需要修改權限
         flr.txtRAmount.Text = txtAmount.Text;
         flr.txtRYear.Text   = txtYear.Text;
         flr.txtRRate.Text   = txtRate.Text;
         A        = Convert.ToDouble(txtAmount.Text) - Convert.ToDouble(txtDownPayment.Text);
         P        = Convert.ToDouble(txtYear.Text) * 12;
         R        = Convert.ToDouble(txtRate.Text) / 1200;
         MonthPay = Convert.ToInt32(Financial.Pmt(R, P, A)) * -1;
         flr.txtRMonthPay.Text = $"{MonthPay}";
         flr.txtRTotal.Text    = $"{MonthPay * P}";
         flr.Show();
     }
     catch (Exception ex)
     {
         Form00.msgError(ex);
     }
 }
Пример #22
0
        private void btnMail_Click(object sender, EventArgs e)
        {
            if (txtEmail.Text == "")
            {
                DialogResult result = MessageBox.Show("Email 不可為空!!\r\n繼續請按 Yes,離開請按 No。", "Error", MessageBoxButtons.YesNo, MessageBoxIcon.Warning);
                if (result == DialogResult.No)
                {
                    this.Close();
                }
            }
            else
            {
                try
                {
                    string Body = $"{lblAmonut.Text} : {txtRAmount.Text} \r\n " +
                                  $"{lblYear.Text} : {txtRYear.Text} \r\n " +
                                  $"{lblRate.Text} : {txtRRate.Text} \r\n " +
                                  $"{lblMonthPay.Text} : {txtRMonthPay.Text} \r\n" +
                                  $" {lblTotal.Text} : {txtRTotal.Text}";
                    System.Net.Mail.SmtpClient MySmtp = new System.Net.Mail.SmtpClient("smtp.gmail.com", 587);
                    MySmtp.Credentials = new System.Net.NetworkCredential("*****@*****.**", "wbiesolnfcrgmjfn");
                    MySmtp.EnableSsl   = true;
                    MySmtp.Send("測試主機端<*****@*****.**>", txtEmail.Text, "貸款報告書", Body);
                    MySmtp.Dispose();

                    DialogResult result = MessageBox.Show("已發送報告\r\n繼續請按 Yes,離開請按 No。", "mail", MessageBoxButtons.YesNo, MessageBoxIcon.Information);
                    if (result == DialogResult.No)
                    {
                        this.Close();
                    }
                }
                catch (Exception ex)
                {
                    Form00.msgError(ex);
                }
            }
        }
Пример #23
0
 private void btnSave_Click(object sender, EventArgs e)
 {
     // 按鈕:儲存 (儲存資料到 strGarde)
     try
     {
         // 測試姓名是否輸入且分數是否介於 0 - 100
         if (txtName.Text != "" & Int32.Parse(txtCN.Text) < 101 & Int32.Parse(txtCN.Text) > -1 & Int32.Parse(txtEN.Text) < 101 & Int32.Parse(txtEN.Text) > -1 & Int32.Parse(txtMath.Text) < 101 & Int32.Parse(txtMath.Text) > -1)
         {
             // 指派資料到 strGrade
             strGrade.Name = txtName.Text;
             strGrade.CN   = int.Parse(txtCN.Text);
             strGrade.EN   = int.Parse(txtEN.Text);
             strGrade.Math = int.Parse(txtMath.Text);
         }
         else
         {
             MessageBox.Show("請輸入姓名\r分數必需介於 0 - 100。", "Error", MessageBoxButtons.OK, MessageBoxIcon.Warning);
         }
     }
     catch (Exception ex)
     {
         Form00.msgError(ex);
     }
 }
Пример #24
0
        private void btnMaxMin_Click(object sender, EventArgs e)
        {
            // 按鈕:最高分/最低分科目 (輸出最高最低分科目到 lblMinMax)
            try
            {
                // 測試 lblGrade 有沒有資料
                if (lblGrade.Text != "")
                {
                    // 計算最高分
                    if (strGrade.CN > strGrade.EN)                     // 測試國文 > 英文
                    {
                        if (strGrade.CN > strGrade.Math)               // 測試國文 > 數學
                        {
                            strGrade.MajorMax = "國文 " + String.Format("{0,3}", Convert.ToString(strGrade.CN));
                        }
                        else
                        {
                            strGrade.MajorMax = "數學 " + String.Format("{0,3}", Convert.ToString(strGrade.Math));
                        }
                    }
                    else if (strGrade.EN > strGrade.Math)                     // 測試英文 > 數學
                    {
                        if (strGrade.EN > strGrade.CN)                        // 測試英文 > 國文
                        {
                            strGrade.MajorMax = "英文 " + String.Format("{0,3}", Convert.ToString(strGrade.EN));
                        }
                        else
                        {
                            strGrade.MajorMax = "國文 " + String.Format("{0,3}", Convert.ToString(strGrade.CN));
                        }
                    }
                    else
                    {
                        strGrade.MajorMax = "數學 " + String.Format("{0,3}", Convert.ToString(strGrade.Math));
                    }

                    //計算最低分
                    if (strGrade.CN < strGrade.EN)                     // 測試國文 < 英文
                    {
                        if (strGrade.CN < strGrade.Math)               // 測試國文 < 數學
                        {
                            strGrade.MajorMin = "國文 " + String.Format("{0,3}", Convert.ToString(strGrade.CN));
                        }
                        else
                        {
                            strGrade.MajorMin = "數學 " + String.Format("{0,3}", Convert.ToString(strGrade.Math));
                        }
                    }
                    else if (strGrade.EN < strGrade.Math)                     // 測試英文 < 數學
                    {
                        if (strGrade.EN < strGrade.CN)                        // 測試英文 < 國文
                        {
                            strGrade.MajorMin = "英文 " + String.Format("{0,3}", Convert.ToString(strGrade.EN));
                        }
                        else
                        {
                            strGrade.MajorMin = "國文 " + String.Format("{0,3}", Convert.ToString(strGrade.CN));
                        }
                    }
                    else
                    {
                        strGrade.MajorMin = "數學 " + String.Format("{0,3}", Convert.ToString(strGrade.Math));
                    }
                    // 輸出到 lblMaxMin
                    lblMaxMin.Text = "最高科目成績為:" + strGrade.MajorMax + " 分\n最低科目成績為:" + strGrade.MajorMin + " 分";
                }
                else
                {
                    MessageBox.Show("請先秀出資料", "Error", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                }
            }
            catch (Exception ex)
            {
                Form00.msgError(ex);
            }
        }
Пример #25
0
        private void btnMinMax3_Click(object sender, EventArgs e)
        {
            // 按鈕:最高分/最低分科目 (3) (輸出最高最低分科目到 lblMinMax 可測試同分)
            try
            {
                int    max      = -1;           // 最高分
                string maxMajor = string.Empty; // 最高分科目
                int    min      = 101;          // 最低分
                string minMajor = string.Empty; // 最低分科目

                // 測試 lblGrade 有沒有資料
                if (lblGrade.Text != "")
                {
                    if (!(strGrade.CN == strGrade.EN & strGrade.EN == strGrade.Math))                       // 如果(國文 = 英文 且 英文 = 數學)不成立
                    {
                        // 計算最高分
                        if (strGrade.CN > max)                         // 測試國文
                        {
                            max      = strGrade.CN;
                            maxMajor = "國文";
                        }

                        if (strGrade.EN > max)                         // 測試英文
                        {
                            max      = strGrade.EN;
                            maxMajor = "英文";
                        }
                        else if (strGrade.EN == max)
                        {
                            maxMajor += "英文";
                        }

                        if (strGrade.Math > max)                         // 測試數學
                        {
                            max      = strGrade.Math;
                            maxMajor = "數學";
                        }
                        else if (strGrade.Math == max)
                        {
                            maxMajor += "數學";
                        }

                        // 計算最低分
                        if (strGrade.CN < min)                         // 測試國文
                        {
                            min      = strGrade.CN;
                            minMajor = "國文";
                        }

                        if (strGrade.EN < min)                         // 測試英文
                        {
                            min      = strGrade.EN;
                            minMajor = "英文";
                        }
                        else if (strGrade.EN == min)
                        {
                            minMajor += "英文";
                        }

                        if (strGrade.Math < min)                         // 測試數學
                        {
                            min      = strGrade.Math;
                            minMajor = "數學";
                        }
                        else if (strGrade.Math == min)
                        {
                            minMajor += "數學";
                        }

                        // 輸出到 lblMaxMin
                        string strMax = String.Format("{0,3}", max);
                        string strMin = String.Format("{0,3}", min);
                        //string strMax = max.ToString().PadLeft(3, ' ');
                        //string strMin = min.ToString().PadLeft(3, ' ');
                        lblMaxMin.Text = $"使用最高/最低分(3)\n附加測試同分\n\n最高科目成績為:{maxMajor} {strMax} 分\n最低科目成績為:{minMajor} {strMin} 分";
                    }
                    else
                    {
                        lblMaxMin.Text = $"使用最高 / 最低分(3)\n附加測試同分\n\n國文英文數學三科同分 { strGrade.CN} 分";
                    }
                }
                else
                {
                    MessageBox.Show("請先秀出資料", "Error", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                }
            }
            catch (Exception ex)
            {
                Form00.msgError(ex);
            }
        }