Exemple #1
0
 private void updateToolStripMenuItem_Click(object sender, EventArgs e)
 {
     try {
         Newdata add = new Newdata();
         add.ShowDialog();
         if (add.ok)
         {
             int ChiScore, EngScore, MathScore, total;
             if (Person.Exists(x => x.Id == add.Tb_id.Text))
             {
                 ChiScore  = Convert.ToInt32(add.Tb_chi.Text);
                 EngScore  = Convert.ToInt32(add.Tb_eng.Text);
                 MathScore = Convert.ToInt32(add.Tb_math.Text);
                 total     = ChiScore + EngScore + MathScore;
                 Person.First(x => x.Id == add.Tb_id.Text).Name  = add.Tb_name.Text;
                 Person.First(x => x.Id == add.Tb_id.Text).Chi   = add.Tb_chi.Text;
                 Person.First(x => x.Id == add.Tb_id.Text).Eng   = add.Tb_eng.Text;
                 Person.First(x => x.Id == add.Tb_id.Text).Math  = add.Tb_math.Text;
                 Person.First(x => x.Id == add.Tb_id.Text).Total = total.ToString();
                 MessageBox.Show("修改成功!");
             }
         }
         else
         {
             MessageBox.Show("取消修改!");
         }
     }
     catch (Exception err) {
         MessageBox.Show(err.Message);
     }
 }
Exemple #2
0
 private void addToolStripMenuItem_Click(object sender, EventArgs e)
 {
     try {
         Newdata add = new Newdata();
         add.ShowDialog();
         if (add.ok)
         {
             int ChiScore, EngScore, MathScore, total;
             if (Person.Exists(x => x.Id == add.Tb_id.Text))
             {
                 MessageBox.Show("學號重複!");
             }
             else
             {
                 ChiScore  = Convert.ToInt32(add.Tb_chi.Text);
                 EngScore  = Convert.ToInt32(add.Tb_eng.Text);
                 MathScore = Convert.ToInt32(add.Tb_math.Text);
                 total     = ChiScore + EngScore + MathScore;
                 Person.Add(new Student()
                 {
                     Id    = add.Tb_id.Text,
                     Name  = add.Tb_name.Text,
                     Chi   = add.Tb_chi.Text,
                     Eng   = add.Tb_eng.Text,
                     Math  = add.Tb_math.Text,
                     Total = total.ToString()
                 });
                 searchToolStripMenuItem.Enabled = true;
                 updateToolStripMenuItem.Enabled = true;
                 queryToolStripMenuItem.Enabled  = true;
                 deleteToolStripMenuItem.Enabled = true;
                 MessageBox.Show("資料新增成功!");
             }
         }
         else
         {
             MessageBox.Show("取消新增!");
         }
     }
     catch (Exception err) {
         MessageBox.Show(err.Message);
     }
 }