public frmAssignedSurvy_SingleForm(UDT.AssignedSurvey AssignedSurvey, CourseRecord Course, TeacherRecord Teacher, string CaseName)
 {
     InitializeComponent();
     this.AssignedSurvey = AssignedSurvey;
     this.Course = Course;
     this.Teacher = Teacher;
     this.CaseName = CaseName;
     Access = new AccessHelper();
     this.ErrorProvider = new ErrorProvider();
     this.Load += new EventHandler(frmAssignedSurvy_SingleForm_Load);
 }
        private void btnSet_Click(object sender, EventArgs e)
        {
            if (!this.Is_Validated())
            {
                MessageBox.Show("請修正錯誤再儲存。");
                return;
            }
            this.btnSet.Enabled = false;
            List<UDT.AssignedSurvey> AssignedSurveys = new List<UDT.AssignedSurvey>();
            foreach (DataGridViewRow row in this.dgvData.Rows)
            {
                if (row.IsNewRow)
                    continue;

                //if (row.Cells[5].Tag == null)
                //    continue;

                string SurveyID = row.Cells[5].Value + "";
                int course_id = int.Parse(row.Cells[0].Tag + "");
                int teacher_id = int.Parse(row.Cells[1].Tag + "");

                UDT.AssignedSurvey AssignedSurvey = row.Tag as UDT.AssignedSurvey;
                if (AssignedSurvey == null)
                    AssignedSurvey = new UDT.AssignedSurvey();

                if (string.IsNullOrEmpty(SurveyID))
                    AssignedSurvey.Deleted = true;
                else
                {
                    AssignedSurvey.CourseID = course_id;
                    AssignedSurvey.TeacherID = teacher_id;
                    AssignedSurvey.SurveyID = int.Parse(SurveyID);
                    AssignedSurvey.OpeningTime = DateTime.Parse((row.Cells[3].Value + "").Trim());
                    AssignedSurvey.EndTime = DateTime.Parse((row.Cells[4].Value + "").Trim());
                    AssignedSurvey.Description = (row.Cells[6].Value + "").Trim();
                }

                AssignedSurveys.Add(AssignedSurvey);
            }
            AssignedSurveys.SaveAll();
            //  問卷組態
            AssignedSurveys = Access.Select<UDT.AssignedSurvey>();
            this.dicAssignedSurveys.Clear();
            foreach (UDT.AssignedSurvey AssegnedSurvey in AssignedSurveys)
            {
                if (!this.dicAssignedSurveys.ContainsKey(AssegnedSurvey.CourseID + "-" + AssegnedSurvey.TeacherID))
                    this.dicAssignedSurveys.Add(AssegnedSurvey.CourseID + "-" + AssegnedSurvey.TeacherID, AssegnedSurvey);
            }
            this.btnSet.Enabled = true;
            MsgBox.Show("儲存成功。");

            if (this.cboCourse.SelectedIndex == -1)
                return;

            ComboItem item = this.cboCourse.Items[this.cboCourse.SelectedIndex] as ComboItem;
            this.DGV_DataBinding(item);
        }
        private void Save_Click(object sender, EventArgs e)
        {
            this.DialogResult = System.Windows.Forms.DialogResult.OK;
            if (!this.Validated())
            {
                MessageBox.Show("請修正錯誤再儲存。");
                this.DialogResult = System.Windows.Forms.DialogResult.None;
                return;
            }
            if (this.AssignedSurvey == null)
                this.AssignedSurvey = new UDT.AssignedSurvey();

            List<UDT.AssignedSurvey> AssignedSurveys = Access.Select<UDT.AssignedSurvey>();

            this.AssignedSurvey.CourseID = int.Parse((this.txtCourseName.Tag as CourseRecord).ID);
            this.AssignedSurvey.TeacherID = int.Parse((this.txtTeacherName.Tag as TeacherRecord).ID);

            ComboItem item = (ComboItem)this.cboSurvey.SelectedItem;
            string SurveyID = ((UDT.Survey)item.Tag).UID;
            this.AssignedSurvey.SurveyID = int.Parse(SurveyID);

            this.AssignedSurvey.OpeningTime = DateTime.Parse(this.txtBeginTime.Text.Trim());
            this.AssignedSurvey.EndTime = DateTime.Parse(this.txtEndTime.Text.Trim());
            this.AssignedSurvey.Description = this.txtTeachingEvaluationDescription.Text.Trim();

            this.AssignedSurvey.Save();
            this.Close();
        }