private void Instance_ItemUpdated(object sender, ItemUpdatedEventArgs e)
        {
            if (e.PrimaryKeys.Count > 0)
            {
                if (cboExistTemplates.Enabled == true && cboExistTemplates.SelectedItem is AssessmentSetupRecord)
                {
                    AssessmentSetupRecord source = cboExistTemplates.SelectedItem as AssessmentSetupRecord;
                    bool executeRequired         = false;

                    List <AEIncludeRecordEditor> aeincludeEditors = new List <AEIncludeRecordEditor>();
                    foreach (var each in source.GetAEIncludes())
                    {
                        AEIncludeRecordEditor aeincludeEditor = AEInclude.Instance.AddAEInclude();
                        aeincludeEditor.RefAssessmentSetupID = e.PrimaryKeys[0];
                        aeincludeEditor.RefExamID            = each.RefExamID;
                        aeincludeEditor.UseScore             = each.UseScore;
                        aeincludeEditor.UseText   = each.UseText;
                        aeincludeEditor.UseEffort = each.UseEffort;
                        aeincludeEditor.Weight    = each.Weight;
                        aeincludeEditor.StartTime = each.StartTime;
                        aeincludeEditor.EndTime   = each.EndTime;

                        aeincludeEditors.Add(aeincludeEditor);
                        executeRequired = true;
                    }
                    if (executeRequired)
                    {
                        aeincludeEditors.SaveAllEditors();
                    }
                }
            }
            AssessmentSetup.Instance.ItemUpdated -= new EventHandler <ItemUpdatedEventArgs>(Instance_ItemUpdated);
        }
        private void btnDelete_Click(object sender, EventArgs e)
        {
            try
            {
                if (CurrentItem == null)
                {
                    return;
                }

                string msg = "確定要刪除「" + (CurrentItem.Tag as AssessmentSetupRecord).Name + "」評量設定?\n";
                msg += "刪除後,使用此評量設定的「課程」將會自動變成未設定評量設定狀態。";

                DialogResult dr = MsgBox.Show(msg, Application.ProductName, MessageBoxButtons.YesNo);

                if (dr == DialogResult.Yes)
                {
                    AssessmentSetupRecord        record  = CurrentItem.Tag as AssessmentSetupRecord;
                    List <AEIncludeRecordEditor> editors = new List <AEIncludeRecordEditor>();
                    foreach (var item in record.GetAEIncludes())
                    {
                        AEIncludeRecordEditor editor = item.GetEditor();
                        editor.Remove = true;
                        editors.Add(editor);
                    }
                    if (editors.Count > 0)
                    {
                        editors.SaveAllEditors();
                    }

                    AssessmentSetupRecordEditor ASEditor = record.GetEditor();
                    ASEditor.Remove = true;
                    ASEditor.Save();
                }
            }
            catch (Exception ex)
            {
                MsgBox.Show(ex.Message);
                //CurrentUser.ReportError(ex);
            }
        }
        private bool SaveTemplate()
        {
            if (HasErrors())
            {
                MsgBox.Show("請修正資料後再儲存。", Application.ProductName);
                return(false);
            }

            try
            {
                //string startTime = DateToSaveFormat(CurrentItem.StartTime);
                //string endTime = DateToSaveFormat(CurrentItem.EndTime);

                //if (cboScoreSource.SelectedIndex == 0)
                //{
                //    //if (string.IsNullOrEmpty(startTime) || string.IsNullOrEmpty(endTime))
                //    //{
                //    //    MsgBox.Show("由教師提供課程成績必須指定上傳時間。", Application.ProductName);
                //    //    return false;
                //    //}
                //    //由教師提供
                //    EditTemplate.UpdateTemplate(CurrentItem.Identity, CurrentItem.TemplateName, CurrentItem.AllowUpload, startTime, endTime);
                //}
                //else //由學校計算
                //{
                //    foreach (DataGridViewRow each in dataview.Rows)
                //    {
                //        if (each.IsNewRow) continue;

                //        if ((bool)each.Cells["InputRequired"].FormattedValue)
                //        {
                //            MsgBox.Show("成績由「學校計算」時,所有「評量」必需設定成「強制繳交成績」。");
                //            return false;
                //        }
                //    }

                //    EditTemplate.UpdateTemplate(CurrentItem.Identity, CurrentItem.TemplateName, CurrentItem.AllowUpload, string.Empty, string.Empty);
                //}

                AssessmentSetupRecord record = CurrentItem.Tag as AssessmentSetupRecord;

                List <AEIncludeRecordEditor> editors = new List <AEIncludeRecordEditor>();
                foreach (var item in record.GetAEIncludes())
                {
                    AEIncludeRecordEditor editor = item.GetEditor();
                    editor.Remove = true;
                    editors.Add(editor);
                }
                if (editors.Count > 0)
                {
                    editors.SaveAllEditors();
                }

                editors = new List <AEIncludeRecordEditor>();
                foreach (DataGridViewRow each in dataview.Rows)
                {
                    if (each.IsNewRow)
                    {
                        continue;
                    }

                    AEIncludeRecordEditor editor = AEInclude.Instance.AddAEInclude();
                    editor.RefAssessmentSetupID = record.ID;
                    editor.RefExamID            = "" + each.Cells[ExamID.Index].Value;
                    editor.UseScore             = GetYesNoString(each.Cells[UseScore.Index].FormattedValue, false);
                    editor.UseText   = GetYesNoString(each.Cells[UseText.Index].FormattedValue, false);
                    editor.UseEffort = GetYesNoString(each.Cells[UseEffort.Index].FormattedValue, false);
                    int i;
                    editor.Weight    = int.TryParse("" + each.Cells[Weight.Index].Value, out i) ? i : 0;
                    editor.StartTime = DateToSaveFormat("" + each.Cells[StartTime.Index].Value);
                    editor.EndTime   = DateToSaveFormat("" + each.Cells[EndTime.Index].Value);

                    editors.Add(editor);
                }
                if (editors.Count > 0)
                {
                    editors.SaveAllEditors();
                }

                _listener.Reset();

                return(true);
            }
            catch (Exception ex)
            {
                //CurrentUser.ReportError(ex);
                MsgBox.Show(ex.Message);
                return(false);
            }
        }