public ExcelDocumentMaker(Dictionary<string, Dictionary<string, Color>> dicEvaluationBackgroundColor, Dictionary<string, Dictionary<string, Color>> dicQuestionBackgroundColor, List<UDT.QHRelation> QHRelations, List<UDT.Hierarchy> Hierarchies, UDT.TeacherStatistics Statistics, Workbook wb)
        {
            this.Access = new AccessHelper();
            this.Query = new QueryHelper();

            this.QHRelations = QHRelations;
            this.Hierarchies = Hierarchies;
            this._Statistics = Statistics;
            this._Template = wb;
            this._DataBindedSheets = new List<DataBindedSheet>();
            this._DicEvaluationBackgroundColor = dicEvaluationBackgroundColor;
            this._DicQuestionBackgroundColor = dicQuestionBackgroundColor;
            this.dicCellStyles = new Dictionary<CellObject, CellStyle>();
        }
        private void btnSet_Click(object sender, EventArgs e)
        {
            this.circularProgress.IsRunning = true;
            this.circularProgress.Visible = true;
            this.btnSet.Enabled = false;

            int school_year = int.Parse(this.nudSchoolYear.Value + "");
            int semester = int.Parse((this.cboSemester.SelectedItem as DataItems.SemesterItem).Value);

            List<dynamic> backup_lists = new List<dynamic>();
            foreach (DataGridViewRow row in this.dgvData.Rows)
            {
                if (!row.Selected)
                    continue;

                dynamic o = new ExpandoObject();
                dynamic oo = row.Tag as dynamic;

                o.CourseName = row.Cells[0].Value + "";
                o.CourseID = row.Cells[0].Tag + "";
                o.TeacherID = row.Cells[3].Tag + "";
                o.TeacherName = row.Cells[3].Value + "";
                o.SubjectCode = row.Cells[1].Value + "";
                o.NewSubjectCode = row.Cells[2].Value + "";
                o.TotalNo = row.Cells[6].Value + "";
                o.FillNo = row.Cells[7].Value + "";
                o.SubjectName = oo.SubjectName;
                o.ClassName = oo.ClassName;
                o.Status = row.Cells[8].Value + "";
                o.SubjectID = row.Cells[1].Tag + "";

                DateTime survey_date_begin = DateTime.Today;
                DateTime survey_date_end = DateTime.Today;
                List<string> survey_dates = new List<string>();

                if (DateTime.TryParse(row.Cells[4].Value + "", out survey_date_begin))
                    survey_dates.Add(survey_date_begin.ToShortDateString());
                if (DateTime.TryParse(row.Cells[5].Value + "", out survey_date_end))
                    survey_dates.Add(survey_date_end.ToShortDateString());

                survey_dates = survey_dates.Distinct().ToList();

                o.SurveyDate = string.Join("~", survey_dates);

                backup_lists.Add(o);
            }
            Task task = Task.Factory.StartNew(()=>
            {
                List<UDT.Reply> Replys = Access.Select<UDT.Reply>("status = 1");
                List<UDT.TeacherStatistics> TeacherStatistics = Access.Select<UDT.TeacherStatistics>();
                Dictionary<string, UDT.TeacherStatistics> dicTeacherStatistics = new Dictionary<string, UDT.TeacherStatistics>();
                if (TeacherStatistics.Count > 0)
                    dicTeacherStatistics = TeacherStatistics.ToDictionary(x => x.CourseID + "-" + x.TeacherID + "-" + x.SchoolYear + "-" + x.Semester);

                List<UDT.TeacherStatistics> nTeacherStatistics = new List<UDT.TeacherStatistics>();
                foreach (dynamic o in backup_lists)
                {
                    //if (o.Status == "無效")
                    //    continue;

                    BusinessLogic.TeacherStatistics cTeacherStatistics = new BusinessLogic.TeacherStatistics(o.CourseID, o.TeacherID);
                    bool can_save = false;
                    if (cTeacherStatistics.Survey == null)
                        continue;

                    cTeacherStatistics.SchoolYear = school_year.ToString();
                    cTeacherStatistics.Semester = semester.ToString();
                    cTeacherStatistics.CourseName = o.CourseName;
                    cTeacherStatistics.SubjectName = o.SubjectName;
                    cTeacherStatistics.ClassName = o.ClassName;
                    cTeacherStatistics.TeacherName = o.TeacherName;
                    cTeacherStatistics.SubjectCode = o.SubjectCode;
                    cTeacherStatistics.NewSubjectCode = o.NewSubjectCode;
                    cTeacherStatistics.FeedBackCount = o.FillNo;
                    cTeacherStatistics.CSAttendCount = o.TotalNo;
                    cTeacherStatistics.CourseID = o.CourseID;
                    cTeacherStatistics.SubjectID = o.SubjectID;
                    cTeacherStatistics.TeacherID = o.TeacherID;
                    cTeacherStatistics.SurveyDate = o.SurveyDate;

                    foreach (UDT.Reply Reply in Replys)
                    {
                        if (Reply.SurveyID.ToString() != cTeacherStatistics.Survey.uSurvey.UID || Reply.CourseID.ToString() != o.CourseID || Reply.TeacherID.ToString() != o.TeacherID)
                            continue;

                        cTeacherStatistics.SetAnswer(Reply.Answer);
                        can_save = true;
                    }

                    string Statistics_List = cTeacherStatistics.ToString();
                    string key = o.CourseID + "-" + o.TeacherID;
                    UDT.TeacherStatistics oTeacherStatistic = new UDT.TeacherStatistics();
                    if (dicTeacherStatistics.ContainsKey(key + "-" + school_year + "-" + semester))
                        oTeacherStatistic = dicTeacherStatistics[key + "-" + school_year + "-" + semester];

                    oTeacherStatistic.CourseID = int.Parse(o.CourseID);
                    oTeacherStatistic.TeacherID = int.Parse(o.TeacherID);
                    oTeacherStatistic.SchoolYear = school_year;
                    oTeacherStatistic.Semester = semester;
                    oTeacherStatistic.StatisticsList = Statistics_List;
                    oTeacherStatistic.TimeStamp = DateTime.Now;

                    if (can_save)
                        nTeacherStatistics.Add(oTeacherStatistic);
                }
                nTeacherStatistics.SaveAll();
            });

            task.ContinueWith((y) =>
            {
                if (y.Exception != null)
                {
                    MessageBox.Show(y.Exception.InnerException.Message);
                    goto TheEnd;
                }

                this.DGV_DataBinding();
                MessageBox.Show("計算完畢。");
                TheEnd:
                this.circularProgress.IsRunning = false;
                this.circularProgress.Visible = false;
                this.btnSet.Enabled = true;
            }, System.Threading.CancellationToken.None, TaskContinuationOptions.None, TaskScheduler.FromCurrentSynchronizationContext());
        }