//原本被標為退選的,按下退選後沒有反應。
        //原本被標為加選的,按下退選後刪除該加退選紀錄。
        //原本沒有標示的,按下退選後會加入一筆退選紀錄。
        private void btnRemove_Click(object sender, EventArgs e)
        {
            if (this.dataGridViewX1.SelectedRows.Count < 1)
            {
                return;
            }

            List<ActiveRecord> addRecs = new List<ActiveRecord>();
            List<ActiveRecord> delRecs = new List<ActiveRecord>();
            this.btnRemove.Enabled = false;

            foreach (DataGridViewRow row in this.dataGridViewX1.SelectedRows)
            {
                SHCourseRecord course = (SHCourseRecord)row.Tag;
                if (row.Cells[0].Value.ToString() == "")
                {
                    UDT.AddDropCourse ad = new UDT.AddDropCourse();
                    ad.CourseID = int.Parse(course.ID);
                    ad.StudentID = int.Parse(this.PrimaryKey);
                    ad.AddOrDrop = this.dropCourse;
                    addRecs.Add(ad);
                }

                if (row.Cells[0].Value.ToString() == this.addCourse)
                {
                    UDT.AddDropCourse ad = this.dicAddDropList[course.ID];
                    delRecs.Add(ad);
                }
            }

            try
            {
                AccessHelper ah = new AccessHelper();
                if (delRecs.Count > 0) ah.DeletedValues(delRecs);
                if (addRecs.Count > 0) ah.InsertValues(addRecs);
                this.OnPrimaryKeyChanged(EventArgs.Empty);
                this.saveLogs(delRecs, addRecs);
            }
            catch (Exception ex)
            {
                Util.ShowMsg(ex.Message, "退選課程");
                this.btnRemove.Enabled = true;
            }

            //this.btnRemove.Enabled = true;
        }
        private void btnAdd_Click(object sender, EventArgs e)
        {
            if (this.dataGridViewX2.SelectedRows.Count < 1)
            {
                return;
            }

            List<ActiveRecord> addRecs = new List<ActiveRecord>();
            List<ActiveRecord> delRecs = new List<ActiveRecord>();
            this.btnAdd.Enabled = false;

            foreach (DataGridViewRow row in this.dataGridViewX2.SelectedRows)
            {
                SHCourseRecord course = (SHCourseRecord)row.Tag;
                //如果原本是被標註退選的,應該要把該退選紀錄移除
                if (this.dicAddDropList.ContainsKey(course.ID))
                {
                    if (this.dicAddDropList[course.ID].AddOrDrop.ToUpper() == this.dropCourse)
                    {
                        delRecs.Add(this.dicAddDropList[course.ID]);
                    }
                }
                else
                {
                    UDT.AddDropCourse ad = new UDT.AddDropCourse();
                    ad.StudentID = int.Parse(this.PrimaryKey);
                    ad.CourseID = int.Parse(course.ID);
                    ad.AddOrDrop = this.addCourse;
                    addRecs.Add(ad);
                }
            }
            try
            {
                AccessHelper ah = new AccessHelper();
                if (delRecs.Count > 0)  ah.DeletedValues(delRecs);
                if (addRecs.Count > 0) ah.InsertValues(addRecs);
                this.OnPrimaryKeyChanged(EventArgs.Empty);
                this.saveLogs(delRecs, addRecs);
            }
            catch (Exception ex)
            {
                Util.ShowMsg(ex.Message, "加選課程");
                this.btnAdd.Enabled = true;
            }

            //this.btnAdd.Enabled = true ;    //應該要等資料讀取完後才 enabled,  2012/5/2, kevin.
        }