private void btnSave_Click(object sender, EventArgs e)
        {
            try
            {
                if (string.IsNullOrWhiteSpace(txtName.Text))
                {
                    FISCA.Presentation.Controls.MsgBox.Show("名稱不可空白!");
                    return;
                }

                btnSave.Enabled = false;

                if (_editMode == EditMode.Edit)
                {
                    // 先刪除原有
                    if (_SelectDeptDefList.Count > 0)
                        UDTTransfer.UDTCdselectDelete(_SelectDeptDefList);
                }
                else
                { 
                    // 新增資料
                    string newName = txtName.Text;
                    bool checkSameName = false;
                    foreach (UDTCourseTimetableDef da in UDTTransfer.UDTCourseTimetableSelectAll())
                    {
                        if (da.Name == newName)
                        {
                            checkSameName = true;
                            break;
                        }
                    }

                    if (checkSameName)
                    {
                        FISCA.Presentation.Controls.MsgBox.Show("已有相同課表名稱無法新增,請修改課表名稱.");
                        return;
                    }
                    else
                    { 
                       // 新增一筆課表
                        List<UDTCourseTimetableDef> insertDataList = new List<UDTCourseTimetableDef>();
                        UDTCourseTimetableDef newIData = new UDTCourseTimetableDef();
                        newIData.Name = newName;
                        insertDataList.Add(newIData);
                        UDTTransfer.UDTCourseTimetableInsert(insertDataList);
                    
                        // 將目前可表設成新增
                        foreach (UDTCourseTimetableDef da in UDTTransfer.UDTCourseTimetableSelectAll())
                        {
                            if (da.Name == newName)
                            {
                                _CurrentCourseTimetable = da;
                                break;
                            }
                        }
                    }
                }                

                //新增勾選
                List<UDTCdselectDef> insertDeptDataList = new List<UDTCdselectDef>();
                foreach (ListViewItem lvi in lvwDept.CheckedItems)
                {
                    UDTCdselectDef newData = new UDTCdselectDef();
                    newData.RefCourseTimetableID = int.Parse(_CurrentCourseTimetable.UID);
                    newData.DeptName = lvi.Text;
                    insertDeptDataList.Add(newData);
                }
                if (insertDeptDataList.Count > 0)
                    UDTTransfer.UDTCdselectInsert(insertDeptDataList);

                FISCA.Presentation.Controls.MsgBox.Show("儲存成功");
                this.DialogResult = System.Windows.Forms.DialogResult.Yes;
                this.Close();
            }
            catch (Exception ex)
            {
                FISCA.Presentation.Controls.MsgBox.Show("儲存失敗," + ex.Message);                
            }
            btnSave.Enabled = true;
        }
 public SubAddEditCourseTimetableForm(EditMode editMode, UDTCourseTimetableDef data)
 {
     InitializeComponent();            
     _CurrentCourseTimetable = data;
     _editMode = editMode;
 }