private void btnSave_Click(object sender, EventArgs e)
        {
            btnSave.Enabled    = false;
            GraduateClassItems = new List <ClassItem>();
            UpgradeClassItems  = new List <ClassItem>();
            checkClassItems    = new List <ClassItem>();

            bool checkSaveGrauate = true;
            bool checkSaveUpgrade = true;

            // 調整後班級
            ClearDGRowCellErrorText(dgClassUpgrade.Rows, 4);

            if (checkNewClassName() == true)
            {
                return;
            }

            foreach (DataGridViewRow dgv in dgClassUpgrade.Rows)
            {
                if (dgv.Cells[4].Value != null)
                {
                    ClassItem ciClassItem = dgv.Cells[7].Value as ClassItem;
                    ciClassItem.newGradeYear = dgv.Cells[3].Value.ToString();
                    ciClassItem.newClassName = dgv.Cells[4].Value.ToString();

                    if (dgv.Cells[5].Value.ToString() == "畢業")
                    {
                        GraduateClassItems.Add(ciClassItem);
                    }

                    if (dgv.Cells[5].Value.ToString() == "升級")
                    {
                        UpgradeClassItems.Add(ciClassItem);
                    }
                }
            }



            checkClassItems = UpgradeClassDAL.checkUpdateClassName(GraduateClassItems);
            if (checkClassItems.Count > 0)
            {
                checkSaveGrauate = false;
                foreach (ClassItem ci in checkClassItems)
                {
                    foreach (DataGridViewRow drv in dgClassUpgrade.Rows)
                    {
                        if (drv.Cells[0].Value.ToString() == ci.ClassID)
                        {
                            drv.Cells[4].ErrorText = "畢業班級名稱與系統內有重覆!";
                            break;
                        }
                    }
                }
            }

            checkClassItems.Clear();
            checkClassItems = UpgradeClassDAL.checkUpdateClassName(UpgradeClassItems);
            if (checkClassItems.Count > 0)
            {
                List <string> classname = new List <string>();
                foreach (ClassItem ci in GraduateClassItems)
                {
                    classname.Add(ci.ClassName);
                }
                foreach (ClassItem ci in UpgradeClassItems)
                {
                    classname.Add(ci.ClassName);
                }

                List <ClassItem> rmClassItems = new List <ClassItem>();

                foreach (ClassItem cic in checkClassItems)
                {
                    if (classname.Contains(cic.newClassName))
                    {
                        rmClassItems.Add(cic);
                    }
                }
                foreach (ClassItem ci in rmClassItems)
                {
                    checkClassItems.Remove(ci);
                }
            }

            if (checkClassItems.Count > 0)
            {
                checkSaveUpgrade = false;
                foreach (ClassItem ci in checkClassItems)
                {
                    foreach (DataGridViewRow drv in dgClassUpgrade.Rows)
                    {
                        if (drv.Cells[0].Value.ToString() == ci.ClassID)
                        {
                            drv.Cells[4].ErrorText = "調整後班級名稱與系統內有重覆!";
                            break;
                        }
                    }
                }
            }



            if (GraduateClassItems.Count == 0 && UpgradeClassItems.Count == 0)
            {
                MessageBox.Show("請先設定升級或畢業");
                btnSave.Enabled = true;
                return;
            }


            if (checkSaveGrauate == true && checkSaveUpgrade == true)
            {
                // 使用 bk

                bkWorkUpgrd                     = new BackgroundWorker();
                bkWorkUpgrd.DoWork             += new DoWorkEventHandler(bkWorkUpgrd_DoWork);
                bkWorkUpgrd.RunWorkerCompleted += new RunWorkerCompletedEventHandler(bkWorkUpgrd_RunWorkerCompleted);
                bkWorkUpgrd.RunWorkerAsync();
            }
            else
            {
                btnSave.Enabled = true;
            }
        }
 // 字串比較
 public static int ClassItemmStrCpmparer(ClassItem x, ClassItem y)
 {
     return(y.newGradeYear.CompareTo(x.newGradeYear));
 }