public SingleChoice()
        {
            InitializeComponent();

            DataListener = new Campus.Windows.ChangeListen();
            DataListener.Add(new TextBoxSource(this.txtTitle));
            DataListener.Add(new DataGridViewSource(this.dgvData));
            DataListener.Add(new NumericUpDownSource(this.nudDisplayOrder));
            DataListener.Add(new CheckBoxXSource(this.chkRequired));
            DataListener.Add(new CheckBoxXSource(this.chkCase));
            DataListener.Add(new CheckBoxXSource(this.chkSelfAssessment));
            DataListener.Add(new CheckBoxXSource(this.chkNoneCalculated));
            DataListener.Add(new ComboBoxSource(this.cboHierarchy, ComboBoxSource.ListenAttribute.Text));
            DataListener.StatusChanged += new EventHandler<ChangeEventArgs>(Listener_StatusChanged);
            DataListener.ResumeListen();

            this.dgvData.DataError += new DataGridViewDataErrorEventHandler(dgvData_DataError);
            this.dgvData.CurrentCellDirtyStateChanged += new EventHandler(dgvData_CurrentCellDirtyStateChanged);
            this.dgvData.CellEnter += new DataGridViewCellEventHandler(dgvData_CellEnter);
            this.dgvData.ColumnHeaderMouseClick += new System.Windows.Forms.DataGridViewCellMouseEventHandler(this.dgvData_ColumnHeaderMouseClick);
            this.dgvData.RowHeaderMouseClick += new System.Windows.Forms.DataGridViewCellMouseEventHandler(this.dgvData_RowHeaderMouseClick);
            this.dgvData.MouseClick += new System.Windows.Forms.MouseEventHandler(this.dgvData_MouseClick);

            this.RecordDetails = new List<UDT.QuestionOption>();
            Access = new FISCA.UDT.AccessHelper();

            this.Group = Guid.NewGuid().ToString();
            this.Type = "單選題";
            this.Caption = this.Type;

            this.Load += new System.EventHandler(this.SingleChoice_Load);
        }
        public ExportMakeUpReportSettingForm(string targetBatchID, string printMode)
        {
            InitializeComponent();

            _targetBatchID = targetBatchID;

            _worker                       = new BackgroundWorker();
            _worker.DoWork               += new DoWorkEventHandler(Worker_DoWork);
            _worker.RunWorkerCompleted   += new RunWorkerCompletedEventHandler(Worker_RunWorkerCompleted);
            _worker.ProgressChanged      += new ProgressChangedEventHandler(Worker_ProgressChanged);
            _worker.WorkerReportsProgress = true;

            _printMode = printMode;

            // 依照選擇的模式(依群組、依學生) 修改標題
            this.Text = "產生補考公告" + "(" + _printMode + ")";

            labelMemo.Text = "本功能將選擇梯次內所有補考資料," + _printMode + "分類列印報表。";

            FISCA.UDT.AccessHelper _AccessHelper = new FISCA.UDT.AccessHelper();

            // 一開始就先 select 假如沒有的話, 傳預設樣板上去
            _configuresList = _AccessHelper.Select <UDT_ReportTemplate>();

            if (_configuresList.Count == 0)
            {
                UDT_ReportTemplate configure1 = new UDT_ReportTemplate();

                configure1.Template = new Aspose.Words.Document(new MemoryStream(Properties.Resources.補考公告樣板_依群組_));

                configure1.PrintMode = "依群組";

                configure1.Encode();
                configure1.Save();

                UDT_ReportTemplate configure2 = new UDT_ReportTemplate();

                configure2.Template = new Aspose.Words.Document(new MemoryStream(Properties.Resources.補考公告樣板_依學生_));

                configure2.PrintMode = "依學生";

                configure2.Encode();
                configure2.Save();
            }


            string qry = "PrintMode = '" + _printMode + "'";

            _configuresList = _AccessHelper.Select <UDT_ReportTemplate>(qry);

            if (_configuresList.Count > 0)
            {
                _configure = _configuresList[0];

                _configure.Decode();
            }

            GetMakeUpBatch();
        }
 private void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e)
 {
     FISCA.UDT.AccessHelper ah = new FISCA.UDT.AccessHelper();
     string query = string.Format("ref_student_id={0} and ref_template_id ='{1}'", this.PrimaryKey, this.currentTemplate.UID);
     List<DAO.UDT_ABCardDataDef> records = ah.Select<DAO.UDT_ABCardDataDef>(query);
     if (records.Count > 0)
     {
         this.card_data = records[0];
     }
     else
     {
         this.card_data = null;
     }
 }
        private void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e)
        {
            FISCA.UDT.AccessHelper ah = new FISCA.UDT.AccessHelper();
            string query = string.Format("ref_student_id={0} and ref_template_id ='{1}'", this.PrimaryKey, this.currentTemplate.UID);
            List <DAO.UDT_ABCardDataDef> records = ah.Select <DAO.UDT_ABCardDataDef>(query);

            if (records.Count > 0)
            {
                this.card_data = records[0];
            }
            else
            {
                this.card_data = null;
            }
        }
        private void backgroundWorker2_DoWork(object sender, DoWorkEventArgs e)
        {
            FISCA.UDT.AccessHelper ah = new FISCA.UDT.AccessHelper();

            List <FISCA.UDT.ActiveRecord> objs = new List <FISCA.UDT.ActiveRecord>();

            objs.Add(this.card_data);

            if (string.IsNullOrEmpty(this.card_data.UID))
            {
                ah.InsertValues(objs);
            }
            else
            {
                ah.UpdateValues(objs);
            }
        }
Exemple #6
0
        /// <summary>
        /// 取得設定值
        /// </summary>
        /// <returns></returns>
        private Configure GetUDTConfig()
        {
            Configure conf;

            FISCA.UDT.AccessHelper accHelper = new FISCA.UDT.AccessHelper();
            List <Configure>       confList  = accHelper.Select <Configure>();

            if (confList.Count == 1)
            {
                conf = confList[0];
            }
            else
            {
                conf          = new Configure();
                conf.Template = new Document(new MemoryStream(Properties.Resources.領域補考通知單範本));
            }
            return(conf);
        }
Exemple #7
0
        public static void Main()
        {
            K12.Presentation.NLDPanels.Student.RibbonBarItems["DearDiary"]["addTestData"].Click += delegate
            {
                //取得選取學生
                var stuList = K12.Data.Student.SelectByIDs(K12.Presentation.NLDPanels.Student.SelectedSource);
                //多次儲存
                foreach (var stuRec in stuList)
                {
                    var newRec = new DiaryRecord()
                    {
                        RefStudentID = int.Parse(stuRec.ID),
                        Content      = "TEST"
                    };
                    newRec.Save();
                }
                return;

                //批次儲存
                List <DiaryRecord> list = new List <DiaryRecord>();
                foreach (var stuRec in stuList)
                {
                    list.Add(new DiaryRecord()
                    {
                        RefStudentID = int.Parse(stuRec.ID),
                        Content      = "TEST"
                    });
                }
                list.SaveAll();
            };
            K12.Presentation.NLDPanels.Student.RibbonBarItems["DearDiary"]["showDiaryCount"].Click += delegate
            {
                var stuList = K12.Data.Student.SelectByIDs(K12.Presentation.NLDPanels.Student.SelectedSource);
                var message = "";
                foreach (var stuRec in stuList)
                {
                    FISCA.UDT.AccessHelper accessHelper = new FISCA.UDT.AccessHelper();
                    message += string.Format("{0}:{1}\n", stuRec.Name, accessHelper.Select <DiaryRecord>("ref_student_id=" + stuRec.ID).Count);
                }
                System.Windows.Forms.MessageBox.Show(message.TrimEnd());
            };
        }
        private void loadTemplate()
        {
            FISCA.UDT.AccessHelper ah = new FISCA.UDT.AccessHelper();
            this.template = ah.Select <UDT_ABCardTemplateDefinitionDef>();
            this.template.Sort(delegate(UDT_ABCardTemplateDefinitionDef t1, UDT_ABCardTemplateDefinitionDef t2)
            {
                return(t1.ToString().CompareTo(t2.ToString()));
            }
                               );
            //MessageBox.Show(this.template.Count.ToString());
            this.comboBoxEx1.Items.Clear();
            this.comboBoxEx1.Items.AddRange(this.template.ToArray());

            if (this.comboBoxEx1.Items.Count > 0)
            {
                this.comboBoxEx1.SelectedIndex = 0;
            }

            //initUI();
        }
        public Essay()
        {
            InitializeComponent();

            DataListener = new Campus.Windows.ChangeListen();
            DataListener.Add(new TextBoxSource(this.txtTitle));
            DataListener.Add(new NumericUpDownSource(this.nudDisplayOrder));
            DataListener.Add(new CheckBoxXSource(this.chkRequired));
            DataListener.Add(new CheckBoxXSource(this.chkCase));
            DataListener.Add(new CheckBoxXSource(this.chkSelfAssessment));
            DataListener.Add(new CheckBoxXSource(this.chkNoneCalculated));
            DataListener.Add(new ComboBoxSource(this.cboHierarchy, ComboBoxSource.ListenAttribute.Text));
            DataListener.StatusChanged += new EventHandler<ChangeEventArgs>(Listener_StatusChanged);
            DataListener.ResumeListen();

            this.RecordDetails = new List<UDT.QuestionOption>();
            Access = new FISCA.UDT.AccessHelper();

            this.Group = Guid.NewGuid().ToString();
            this.Type = "問答題";
            this.Caption = this.Type;

            this.Load += new System.EventHandler(this.Form_Load);
        }
        void BGW_DoWork(object sender, DoWorkEventArgs e)
        {
            List <string> StudentIDList = K12.Presentation.NLDPanels.Student.SelectedSource;

            _doc = new Document();
            _doc.Sections.Clear(); //清空此Document

            //取得設定檔
            Campus.Report.ReportConfiguration ConfigurationInCadre = new Campus.Report.ReportConfiguration(CadreConfig);
            if (ConfigurationInCadre.Template == null)
            {
                //如果範本為空,則建立一個預設範本
                Campus.Report.ReportConfiguration ConfigurationInCadre_1 = new Campus.Report.ReportConfiguration(CadreConfig);
                ConfigurationInCadre_1.Template = new Campus.Report.ReportTemplate(Properties.Resources.社團幹部證明單, Campus.Report.TemplateType.Word);
                //ConfigurationInCadre_1.Template = new Campus.Report.ReportTemplate(Properties.Resources.社團點名表_合併欄位總表, Campus.Report.TemplateType.Word);
                _template = ConfigurationInCadre_1.Template.ToDocument();
            }
            else
            {
                //如果已有範本,則取得樣板
                _template = ConfigurationInCadre.Template.ToDocument();
            }

            List <StudentRecord> StudList = Student.SelectByIDs(StudentIDList);

            //取得學生的 社團學期成績 , 內包含社長副社長,與其它資料
            //$K12.ResultScore.Shinmin
            //結算後,相關記錄會放在學生的社團學期成績

            #region 社團學期成績

            _StudentResultDic.Clear();
            FISCA.UDT.AccessHelper   _A         = new FISCA.UDT.AccessHelper();
            List <ResultScoreRecord> ResultList = _A.Select <ResultScoreRecord>(string.Format("ref_student_id in ('{0}')", string.Join("','", StudentIDList)));
            List <string>            CLUBIDList = new List <string>();

            List <string> StudentOkList = new List <string>();

            foreach (ResultScoreRecord each in ResultList)
            {
                if (string.IsNullOrEmpty(each.CadreName))
                {
                    continue;
                }

                if (!CLUBIDList.Contains(each.RefClubID))
                {
                    if (each.RefClubID != "")
                    {
                        CLUBIDList.Add(each.RefClubID);
                    }
                }

                //當勾選畫面是社長/副社長時
                if (cbPrintByPresident.Checked)
                {
                    if (each.CadreName == "社長" || each.CadreName == "副社長")
                    {
                        if (!_StudentResultDic.ContainsKey(each.RefStudentID))
                        {
                            _StudentResultDic.Add(each.RefStudentID, new List <ResultScoreRecord>());
                        }

                        _StudentResultDic[each.RefStudentID].Add(each);

                        if (!StudentOkList.Contains(each.RefStudentID))
                        {
                            StudentOkList.Add(each.RefStudentID);
                        }
                    }
                }
                else
                {
                    if (!_StudentResultDic.ContainsKey(each.RefStudentID))
                    {
                        _StudentResultDic.Add(each.RefStudentID, new List <ResultScoreRecord>());
                    }

                    _StudentResultDic[each.RefStudentID].Add(each);

                    if (!StudentOkList.Contains(each.RefStudentID))
                    {
                        StudentOkList.Add(each.RefStudentID);
                    }
                }
            }

            #endregion

            if (StudentOkList.Count != 0)
            {
                // 入學照片
                _PhotoPDict.Clear();
                _PhotoPDict = K12.Data.Photo.SelectFreshmanPhoto(StudentOkList);

                // 畢業照片
                _PhotoGDict.Clear();
                _PhotoGDict = K12.Data.Photo.SelectGraduatePhoto(StudentOkList);
            }

            foreach (StudentRecord student in StudList)
            {
                List <string> name  = new List <string>();
                List <object> value = new List <object>();

                if (_StudentResultDic.ContainsKey(student.ID))
                {
                    bool check = true;
                    foreach (ResultScoreRecord each in _StudentResultDic[student.ID])
                    {
                        if (!string.IsNullOrEmpty(each.CadreName))
                        {
                            check = false;
                            break;
                        }
                    }

                    if (check)
                    {
                        continue;
                    }
                }
                else
                {
                    continue;
                }

                name.Add("資料");
                if (_StudentResultDic.ContainsKey(student.ID))
                {
                    value.Add(_StudentResultDic[student.ID]); //重點欄位
                }
                else
                {
                    value.Add(new List <ResultScoreRecord>());
                }

                #region MailMerge

                name.Add("學校名稱");
                value.Add(School.ChineseName);

                if (student.Class != null)
                {
                    name.Add("班級");
                    value.Add(student.Class.Name);
                }
                else
                {
                    name.Add("班級");
                    value.Add("");
                }

                name.Add("座號");
                value.Add(student.SeatNo.HasValue ? student.SeatNo.Value.ToString() : "");

                name.Add("姓名");
                value.Add(student.Name);

                name.Add("學號");
                value.Add(student.StudentNumber);

                name.Add("校長");
                if (K12.Data.School.Configuration["學校資訊"].PreviousData != null)
                {
                    if (K12.Data.School.Configuration["學校資訊"].PreviousData.SelectSingleNode("ChancellorChineseName") != null)
                    {
                        value.Add(K12.Data.School.Configuration["學校資訊"].PreviousData.SelectSingleNode("ChancellorChineseName").InnerText);
                    }
                    else
                    {
                        value.Add("");
                    }
                }
                else
                {
                    value.Add("");
                }

                if (_PhotoPDict.ContainsKey(student.ID))
                {
                    name.Add("新生照片1");
                    value.Add(_PhotoPDict[student.ID]);

                    name.Add("新生照片2");
                    value.Add(_PhotoPDict[student.ID]);
                }

                if (_PhotoGDict.ContainsKey(student.ID))
                {
                    name.Add("畢業照片1");
                    value.Add(_PhotoGDict[student.ID]);

                    name.Add("畢業照片2");
                    value.Add(_PhotoGDict[student.ID]);
                }

                #endregion

                //取得範本樣式
                Document PageOne = (Document)_template.Clone(true);

                PageOne.MailMerge.MergeField += new Aspose.Words.Reporting.MergeFieldEventHandler(MailMerge_MergeField);
                PageOne.MailMerge.Execute(name.ToArray(), value.ToArray());

                _doc.Sections.Add(_doc.ImportNode(PageOne.FirstSection, true));
            }

            e.Result = _doc;
        }
 private void PupopDetailPane_Load(object sender, EventArgs e)
 {
     this.detailPane1.panProgress.Height = 0;
     detailPane1.btnPreview.Click += new EventHandler(btnPreview_Click);
     Access = new FISCA.UDT.AccessHelper();
     Query = new FISCA.Data.QueryHelper();
     this.lstSurvey.DisplayMember = "Name";
     this.lstSurvey.ValueMember = "UID";
     this.Init();
 }
        public StudentMoralProcessor(DocumentBuilder builder, SemesterMap map)
        {
            _builder = builder;

            _map = map;
            _types = new Dictionary<string, List<string>>();

            _run = WordHelper.CreateRun(_builder);

            #region 取得假別設定
            ConfigData cd = K12.Data.School.Configuration["學籍表"];
            if (cd.Contains("假別設定"))
            {
                XmlElement config = Framework.XmlHelper.LoadXml(cd["假別設定"]);

                foreach (XmlElement type in config.SelectNodes("Type"))
                {
                    string typeName = type.GetAttribute("Text");
                    if (!_types.ContainsKey(typeName))
                        _types.Add(typeName, new List<string>());

                    foreach (XmlElement absence in type.SelectNodes("Absence"))
                    {
                        string absenceName = absence.GetAttribute("Text");
                        if (!_types[typeName].Contains(absenceName))
                            _types[typeName].Add(absenceName);
                    }
                }
            }
            #endregion

            #region 取得社團成績
            _assnScoreCache = new Dictionary<string, List<AssnScore>>();

            FISCA.UDT.AccessHelper ah = new FISCA.UDT.AccessHelper();
//            string condition = string.Format("SchoolYear='{0}' and Semester='{1}'", options.SchoolYear, options.Semester);
//            List<AssnCode> list = ah.Select<AssnCode>(condition);

            if (AssociationUDTCache == null)
                AssociationUDTCache = ah.Select<AssnCode>();

            List<AssnCode> list = AssociationUDTCache;
            foreach (AssnCode record in list)
            {
                //if (!_assnScoreCache.ContainsKey(record.StudentID))
                //{
                    XmlElement scores = K12.Data.XmlHelper.LoadXml(record.Scores);
                    XmlElement itemElement = (XmlElement)scores.SelectSingleNode("Item");
                    if (itemElement != null)
                    {
                        AssnScore assnScore = new AssnScore()
                        {
                            Score = itemElement.GetAttribute("Score"),
                            Effort = itemElement.GetAttribute("Effort"),
                            Text = itemElement.GetAttribute("Text"),
                            SchoolYear = record.SchoolYear,
                            Semester = record.Semester
                        };
                        if (_assnScoreCache.ContainsKey(record.StudentID))
                            _assnScoreCache[record.StudentID].Add(assnScore);
                        else
                        {
                            List<AssnScore> lis = new List<AssnScore>();
                            lis.Add(assnScore);
                            _assnScoreCache.Add(record.StudentID, lis);
                        }
                    }
                //}
            }

            //<Content>
            //<Item AssociationName="籃球社" Score="" Effort="" Text=""></Item>
            //</Content>
            #endregion
        }
Exemple #13
0
        public StudentMoralProcessor(DocumentBuilder builder, SemesterMap map)
        {
            _builder = builder;

            _map   = map;
            _types = new Dictionary <string, List <string> >();

            _run = WordHelper.CreateRun(_builder);

            #region 取得假別設定
            ConfigData cd = K12.Data.School.Configuration["學籍表"];
            if (cd.Contains("假別設定"))
            {
                XmlElement config = Framework.XmlHelper.LoadXml(cd["假別設定"]);

                foreach (XmlElement type in config.SelectNodes("Type"))
                {
                    string typeName = type.GetAttribute("Text");
                    if (!_types.ContainsKey(typeName))
                    {
                        _types.Add(typeName, new List <string>());
                    }

                    foreach (XmlElement absence in type.SelectNodes("Absence"))
                    {
                        string absenceName = absence.GetAttribute("Text");
                        if (!_types[typeName].Contains(absenceName))
                        {
                            _types[typeName].Add(absenceName);
                        }
                    }
                }
            }
            #endregion

            #region 取得社團成績
            _assnScoreCache = new Dictionary <string, List <AssnScore> >();

            FISCA.UDT.AccessHelper ah = new FISCA.UDT.AccessHelper();
//            string condition = string.Format("SchoolYear='{0}' and Semester='{1}'", options.SchoolYear, options.Semester);
//            List<AssnCode> list = ah.Select<AssnCode>(condition);

            if (AssociationUDTCache == null)
            {
                AssociationUDTCache = ah.Select <AssnCode>();
            }

            List <AssnCode> list = AssociationUDTCache;
            foreach (AssnCode record in list)
            {
                //if (!_assnScoreCache.ContainsKey(record.StudentID))
                //{
                XmlElement scores      = K12.Data.XmlHelper.LoadXml(record.Scores);
                XmlElement itemElement = (XmlElement)scores.SelectSingleNode("Item");
                if (itemElement != null)
                {
                    AssnScore assnScore = new AssnScore()
                    {
                        Score      = itemElement.GetAttribute("Score"),
                        Effort     = itemElement.GetAttribute("Effort"),
                        Text       = itemElement.GetAttribute("Text"),
                        SchoolYear = record.SchoolYear,
                        Semester   = record.Semester
                    };
                    if (_assnScoreCache.ContainsKey(record.StudentID))
                    {
                        _assnScoreCache[record.StudentID].Add(assnScore);
                    }
                    else
                    {
                        List <AssnScore> lis = new List <AssnScore>();
                        lis.Add(assnScore);
                        _assnScoreCache.Add(record.StudentID, lis);
                    }
                }
                //}
            }

            //<Content>
            //<Item AssociationName="籃球社" Score="" Effort="" Text=""></Item>
            //</Content>
            #endregion
        }
Exemple #14
0
        public static void Main()
        {
            //FISCA.Permission.Catalog cat = FISCA.Permission.RoleAclSource.Instance["教務作業"]["功能按鈕"];
            //cat.Add(new FISCA.Permission.RibbonFeature("SHSchool.SHStaticRank2.Data", "計算固定排名(測試版)"));

            var button = FISCA.Presentation.MotherForm.RibbonBarItems["教務作業", "批次作業/檢視"]["成績作業"]["計算固定排名"]["計算多學期成績固定排名(104學年度技職繁星)"];

            button.Enable = FISCA.Permission.UserAcl.Current["SHSchool.SHStaticRank2.Data"].Executable;
            button.Click += delegate
            {
                var conf = new StarTechnical();
                conf.ShowDialog();
                if (conf.DialogResult == System.Windows.Forms.DialogResult.OK)
                {
                    CalcMutilSemeSubjectRank.OneClassCompleted += delegate
                    {
                        #region delegate
                        if (string.IsNullOrWhiteSpace(conf.Configure.Rank1Tag))
                        {
                            return;
                        }
                        #region 取得設定值 , MapRecord
                        string rank1tag     = conf.Configure.Rank1Tag.Replace("[", "").Replace("]", "");
                        int    subjectLimit = Math.Max(conf.Configure.useSubjectPrintList.Count, conf.Configure.SubjectLimit);
                        string path         = Path.Combine(System.Windows.Forms.Application.StartupPath + "\\Reports",
                                                           CalcMutilSemeSubjectRank.FolderName);
                        string path_prefix = "E_群別";
                        string path_suffix = "報名表.xls";

                        FISCA.UDT.AccessHelper         _AccessHelper = new FISCA.UDT.AccessHelper();
                        Dictionary <string, MapRecord> dmr;
                        try
                        {
                            dmr = _AccessHelper.Select <MapRecord>()
                                  .FindAll(delegate(MapRecord mr) { return(!string.IsNullOrWhiteSpace(mr.student_tag)); })
                                  .ToDictionary(x => x.student_tag, x => x);
                        }
                        catch (Exception)
                        {
                            return;
                        }

                        int seq;
                        Dictionary <string, Aspose.Cells.Workbook> wbs     = new Dictionary <string, Aspose.Cells.Workbook>();
                        Dictionary <string, Aspose.Cells.Workbook> wbCheck = new Dictionary <string, Aspose.Cells.Workbook>();
                        Aspose.Cells.Workbook  wb;
                        Aspose.Cells.Worksheet ws;
                        string fulltag;
                        string group_code;
                        string full_doc_path;
                        #endregion
                        foreach (DataRow student in CalcMutilSemeSubjectRank._table.Rows)
                        {
                            fulltag = student.Table.Columns.Contains("類別一分類") ? rank1tag + ":" + student["類別一分類"] : "";
                            //只處理有設定群別的類別
                            if (dmr.ContainsKey(fulltag))
                            {
                                #region 處理上傳表
                                group_code    = dmr[fulltag].code1;
                                full_doc_path = Path.Combine(path, path_prefix + group_code + path_suffix);
                                try
                                {
                                    #region 開啟xls檔案加入Dictionary,或新增
                                    if (wbs.ContainsKey(group_code))
                                    {
                                        wb = wbs[group_code];
                                    }
                                    else if (File.Exists(full_doc_path))
                                    {
                                        wb = new Aspose.Cells.Workbook();
                                        wb.Open(full_doc_path);
                                        wbs.Add(group_code, wb);
                                    }
                                    else
                                    {
                                        wb = new Aspose.Cells.Workbook();
                                        ws = wb.Worksheets[0];
                                        #region 報表header初始化
                                        ws.Cells[0, 0].PutValue("序號");
                                        ws.Cells[0, 1].PutValue("學號");
                                        ws.Cells[0, 2].PutValue("學生姓名");
                                        ws.Cells[0, 3].PutValue("群別代碼");
                                        ws.Cells[0, 4].PutValue("學制代碼");
                                        ws.Cells[0, 5].PutValue("科(組)、學程名稱");
                                        ws.Cells[0, 6].PutValue("班級名稱");
                                        ws.Cells[0, 7].PutValue("學業平均成績科(組)、學程名次");
                                        ws.Cells[0, 8].PutValue("學業平均成績群名次");
                                        ws.Cells[0, 9].PutValue("專業及實習科目平均成績群名次");
                                        ws.Cells[0, 10].PutValue("英文平均成績群名次");
                                        ws.Cells[0, 11].PutValue("國文平均成績群名次");
                                        ws.Cells[0, 12].PutValue("數學平均成績群名次");
                                        #endregion
                                        wbs.Add(group_code, wb);
                                    }
                                    #endregion
                                    ws  = wb.Worksheets[0];
                                    seq = 1;//序號
                                    while (!string.IsNullOrWhiteSpace("" + ws.Cells[seq, 0].Value))
                                    {
                                        seq++;
                                    }
                                    #region 填入資料
                                    ws.Cells[seq, 0].PutValue("" + seq);                            //1.序號
                                    ws.Cells[seq, 1].PutValue("" + student["學號"]);                  //2.學號
                                    ws.Cells[seq, 2].PutValue("" + student["姓名"]);                  //3.學生姓名
                                    ws.Cells[seq, 3].PutValue(group_code);                          //4.群別代碼
                                    ws.Cells[seq, 4].PutValue(dmr[fulltag].code2);                  //5.學制代碼
                                    ws.Cells[seq, 5].PutValue("" + student["科別"]);                  //6.科(組),學程名稱
                                    ws.Cells[seq, 6].PutValue("" + student["班級"]);                  //7.班級名稱
                                    ws.Cells[seq, 7].PutValue("" + student["學業原始平均科排名"]);           //8.平均科排名
                                    ws.Cells[seq, 8].PutValue("" + student["學業原始平均類別一排名"]);         //9.學業平均成績群名次
                                    ws.Cells[seq, 9].PutValue("" + student["篩選科目原始成績加權平均平均類別二排名"]); //10.專業及實習平均成績群名次
                                    for (int i = 1; i <= subjectLimit; i++)
                                    {
                                        switch ("" + student["科目名稱" + i])
                                        {
                                        case "英文":
                                            ws.Cells[seq, 10].PutValue("" + student["科目平均類別一排名" + i]);    //11.英文平均成績群名次
                                            break;

                                        case "國文":
                                            ws.Cells[seq, 11].PutValue("" + student["科目平均類別一排名" + i]);    //12.國文平均成績群名次
                                            break;

                                        case "數學":
                                            ws.Cells[seq, 12].PutValue("" + student["科目平均類別一排名" + i]);    //13.數學平均群名次
                                            break;

                                        default:
                                            break;
                                        }
                                    }
                                    #endregion
                                    wb = null;
                                }
                                catch (Exception)
                                {
                                    #region save all opened excel
                                    foreach (KeyValuePair <string, Aspose.Cells.Workbook> item in wbs)
                                    {
                                        item.Value.Save(Path.Combine(path, path_prefix + item.Key + path_suffix), Aspose.Cells.FileFormatType.Excel97To2003);
                                    }
                                    #endregion
                                    throw;
                                }
                                #endregion
                                #region 處理驗算表
                                group_code    = dmr[fulltag].code1;
                                full_doc_path = Path.Combine(Path.Combine(path, path_prefix + "成績明細" + group_code + ".xls"));
                                try
                                {
                                    #region 開啟xls檔案加入Dictionary,或新增
                                    if (wbCheck.ContainsKey(group_code))
                                    {
                                        wb = wbCheck[group_code];
                                    }
                                    else if (File.Exists(full_doc_path))
                                    {
                                        wb = new Aspose.Cells.Workbook();
                                        wb.Open(full_doc_path);
                                        wbCheck.Add(group_code, wb);
                                    }
                                    else
                                    {
                                        wb = new Aspose.Cells.Workbook();
                                        ws = wb.Worksheets[0];
                                        #region 報表header初始化
                                        ws.Cells[0, 0].PutValue("序號");
                                        ws.Cells[0, 1].PutValue("學號");
                                        ws.Cells[0, 2].PutValue("學生姓名");
                                        ws.Cells[0, 3].PutValue("群別代碼");
                                        ws.Cells[0, 4].PutValue("學制代碼");
                                        ws.Cells[0, 5].PutValue("科(組)、學程名稱");
                                        ws.Cells[0, 6].PutValue("班級名稱");

                                        ws.Cells[0, 7].PutValue("類別一分類");
                                        ws.Cells[0, 8].PutValue("類別二分類");

                                        ws.Cells[0, 9].PutValue("學業原始平均成績");
                                        ws.Cells[0, 10].PutValue("學業平均成績科(組)、學程名次");
                                        ws.Cells[0, 11].PutValue("學業平均成績群名次");

                                        ws.Cells[0, 12].PutValue("專業及實習科目平均成績");
                                        ws.Cells[0, 13].PutValue("專業及實習科目平均成績群名次");

                                        ws.Cells[0, 14].PutValue("英文科平均成績");
                                        ws.Cells[0, 15].PutValue("英文平均成績群名次");
                                        ws.Cells[0, 16].PutValue("國文科平均成績");
                                        ws.Cells[0, 17].PutValue("國文平均成績群名次");
                                        ws.Cells[0, 18].PutValue("數學科平均成績");
                                        ws.Cells[0, 19].PutValue("數學平均成績群名次");
                                        #endregion
                                        wbCheck.Add(group_code, wb);
                                    }
                                    #endregion
                                    ws  = wb.Worksheets[0];
                                    seq = 1;//序號
                                    while (!string.IsNullOrWhiteSpace("" + ws.Cells[seq, 0].Value))
                                    {
                                        seq++;
                                    }
                                    #region 填入資料
                                    ws.Cells[seq, 0].PutValue("" + seq);           //1.序號
                                    ws.Cells[seq, 1].PutValue("" + student["學號"]); //2.學號
                                    ws.Cells[seq, 2].PutValue("" + student["姓名"]); //3.學生姓名
                                    ws.Cells[seq, 3].PutValue(group_code);         //4.群別代碼
                                    ws.Cells[seq, 4].PutValue(dmr[fulltag].code2); //5.學制代碼
                                    ws.Cells[seq, 5].PutValue("" + student["科別"]); //6.科(組),學程名稱
                                    ws.Cells[seq, 6].PutValue("" + student["班級"]); //7.班級名稱

                                    ws.Cells[seq, 7].PutValue("" + student["類別一分類"]);
                                    ws.Cells[seq, 8].PutValue("" + student["類別二分類"]);

                                    ws.Cells[seq, 9].PutValue("" + student["學業原始平均"]);               //學業原始平均成績
                                    ws.Cells[seq, 10].PutValue("" + student["學業原始平均科排名"]);           //8.平均科排名
                                    ws.Cells[seq, 11].PutValue("" + student["學業原始平均類別一排名"]);         //9.學業平均成績群名次

                                    ws.Cells[seq, 12].PutValue("" + student["篩選科目原始成績加權平均平均類別二"]);   //專業及實習平均成績
                                    ws.Cells[seq, 13].PutValue("" + student["篩選科目原始成績加權平均平均類別二排名"]); //10.專業及實習平均成績群名次
                                    for (int i = 1; i <= subjectLimit; i++)
                                    {
                                        switch ("" + student["科目名稱" + i])
                                        {
                                        case "英文":
                                            ws.Cells[seq, 14].PutValue("" + student["科目平均" + i]);      //英文平均成績
                                            ws.Cells[seq, 15].PutValue("" + student["科目平均類別一排名" + i]); //11.英文平均成績群名次
                                            break;

                                        case "國文":
                                            ws.Cells[seq, 16].PutValue("" + student["科目平均" + i]);      //國文平均成績
                                            ws.Cells[seq, 17].PutValue("" + student["科目平均類別一排名" + i]); //12.國文平均成績群名次
                                            break;

                                        case "數學":
                                            ws.Cells[seq, 18].PutValue("" + student["科目平均" + i]);      //數學平均成績
                                            ws.Cells[seq, 19].PutValue("" + student["科目平均類別一排名" + i]); //13.數學平均群名次
                                            break;

                                        default:
                                            break;
                                        }
                                    }
                                    #endregion
                                    wb = null;
                                }
                                catch (Exception)
                                {
                                    #region save all opened excel
                                    foreach (KeyValuePair <string, Aspose.Cells.Workbook> item in wbCheck)
                                    {
                                        item.Value.Save(Path.Combine(path, path_prefix + "成績明細" + item.Key + ".xls"), Aspose.Cells.FileFormatType.Excel97To2003);
                                    }
                                    #endregion
                                    throw;
                                }
                                #endregion
                            }
                        }
                        #region save all opened excel
                        foreach (KeyValuePair <string, Aspose.Cells.Workbook> item in wbs)
                        {
                            item.Value.Save(Path.Combine(path, path_prefix + item.Key + path_suffix), Aspose.Cells.FileFormatType.Excel97To2003);
                        }
                        #endregion
                        #region save all opened excel wbCheck
                        foreach (KeyValuePair <string, Aspose.Cells.Workbook> item in wbCheck)
                        {
                            item.Value.Save(Path.Combine(path, path_prefix + "成績明細" + item.Key + ".xls"), Aspose.Cells.FileFormatType.Excel97To2003);
                        }
                        #endregion
                        wbs = null;
                        #endregion
                    };
                    CalcMutilSemeSubjectRank.Setup(conf.Configure);
                }
            };
        }
Exemple #15
0
        public DataCache(Options options)
        {
            var student_ids = from student in options.Students select student.ID;

            #region 取得 AutoSummary
            _autoSummaryCache = new Dictionary <string, AutoSummaryRecord>();
            foreach (AutoSummaryRecord record in AutoSummary.Select(student_ids.ToList <string>(), null))
            {
                if (record.SchoolYear == options.SchoolYear &&
                    record.Semester == options.Semester)
                {
                    if (!_autoSummaryCache.ContainsKey(record.RefStudentID))
                    {
                        _autoSummaryCache.Add(record.RefStudentID, record);
                    }
                }
            }
            #endregion

            #region 取得 SemesterScore
            _semesterScoreCache = new Dictionary <string, JHSemesterScoreRecord>();
            foreach (var record in JHSemesterScore.SelectByStudentIDs(student_ids.ToList <string>()))
            {
                if (record.SchoolYear == options.SchoolYear &&
                    record.Semester == options.Semester)
                {
                    if (!_semesterScoreCache.ContainsKey(record.RefStudentID))
                    {
                        _semesterScoreCache.Add(record.RefStudentID, record);
                    }
                }
            }
            #endregion
            #region 取得 SemesterHistoryItem
            _historyItemCache = new Dictionary <string, K12.Data.SemesterHistoryItem>();
            foreach (var record in JHSemesterHistory.SelectByStudentIDs(student_ids))
            {
                foreach (var item in record.SemesterHistoryItems)
                {
                    if (item.SchoolYear == options.SchoolYear &&
                        item.Semester == options.Semester)
                    {
                        if (!_historyItemCache.ContainsKey(item.RefStudentID))
                        {
                            _historyItemCache.Add(item.RefStudentID, item);
                        }
                    }
                }
            }
            #endregion

            if (Global.Params["Mode"] == "KaoHsiung")
            {
                #region 取得社團成績
                _assnScoreCache = new Dictionary <string, AssnScore>();

                FISCA.UDT.AccessHelper ah = new FISCA.UDT.AccessHelper();
                string          condition = string.Format("SchoolYear='{0}' and Semester='{1}'", options.SchoolYear, options.Semester);
                List <AssnCode> list      = ah.Select <AssnCode>(condition);
                foreach (AssnCode record in list)
                {
                    if (!_assnScoreCache.ContainsKey(record.StudentID))
                    {
                        XmlElement scores      = K12.Data.XmlHelper.LoadXml(record.Scores);
                        XmlElement itemElement = (XmlElement)scores.SelectSingleNode("Item");
                        if (itemElement != null)
                        {
                            AssnScore assnScore = new AssnScore()
                            {
                                Score  = itemElement.GetAttribute("Score"),
                                Effort = itemElement.GetAttribute("Effort"),
                                Text   = itemElement.GetAttribute("Text")
                            };
                            _assnScoreCache.Add(record.StudentID, assnScore);
                        }
                    }
                }

                //<Content>
                //<Item AssociationName="籃球社" Score="" Effort="" Text=""></Item>
                //</Content>
                #endregion
            }
        }
Exemple #16
0
        private void Worker_DoWork(object sender, DoWorkEventArgs e)
        {
            // 處理等第
            DegreeMapper dm = new DegreeMapper();

            _worker.ReportProgress(0, "開始列印 ESL報表...");

            #region 取得課程成績單 設定樣板
            _eslCouseList = new List <K12.Data.CourseRecord>();

            _eslCouseList = K12.Data.Course.SelectByIDs(_courseIDList);

            _refAssessmentSetupIDList = new List <string>();

            foreach (K12.Data.CourseRecord courseRecord in _eslCouseList)
            {
                if (!_refAssessmentSetupIDList.Contains("'" + courseRecord.RefAssessmentSetupID + "'"))
                {
                    _refAssessmentSetupIDList.Add("'" + courseRecord.RefAssessmentSetupID + "'");
                }

                if (!_courseIDPairDict.ContainsKey(courseRecord.ID))
                {
                    _courseIDPairDict.Add(courseRecord.ID, courseRecord.RefAssessmentSetupID);
                }

                if (!_assessmentSetupIDPairDict.ContainsKey(courseRecord.RefAssessmentSetupID))
                {
                    _assessmentSetupIDPairDict.Add(courseRecord.RefAssessmentSetupID, courseRecord.ID);
                }
            }

            string assessmentSetupIDs = string.Join(",", _refAssessmentSetupIDList);


            FISCA.UDT.AccessHelper _AccessHelper = new FISCA.UDT.AccessHelper();

            _worker.ReportProgress(0, "取得課程成績單設定樣板...");


            string qry = "ref_exam_template_id IN (" + assessmentSetupIDs + ") and schoolyear='" + K12.Data.School.DefaultSchoolYear + "' and semester ='" + K12.Data.School.DefaultSemester + "' and exam ='" + _examType + "'";

            List <UDT_ReportTemplate> configures = _AccessHelper.Select <UDT_ReportTemplate>(qry);

            _documentDict = new Dictionary <string, Document>();

            foreach (UDT_ReportTemplate templateconfig in configures)
            {
                if (!_documentDict.ContainsKey(templateconfig.Ref_exam_Template_ID))
                {
                    Document _doc = new Document();

                    templateconfig.Decode(); // 將 stream 轉成 Word

                    _doc = templateconfig.Template;

                    _documentDict.Add(templateconfig.Ref_exam_Template_ID, _doc);
                }
            }
            #endregion


            #region 取得修課學生、 並做整理
            List <K12.Data.SCAttendRecord> scList = K12.Data.SCAttend.SelectByCourseIDs(_courseIDList);

            List <string> studentIDList = new List <string>();


            foreach (K12.Data.SCAttendRecord scr in scList)
            {
                studentIDList.Add(scr.Student.ID);

                // 建立成績整理 Dict ,[studentID_courseID,[scoreKey,scoreID]]
                _scoreDict.Add(scr.Student.ID + "_" + scr.Course.ID, new Dictionary <string, string>());
            }
            #endregion

            // 建立功能變數對照
            CreateFieldTemplate();

            #region 取得、整理ESL成績
            _worker.ReportProgress(20, "取得ESL課程成績");


            int     progress = 80;
            decimal per      = (decimal)(100 - progress) / scList.Count;
            int     count    = 0;

            string course_ids = string.Join("','", _courseIDList);

            string student_ids = string.Join("','", studentIDList);

            string sql = "SELECT * FROM $esl.gradebook_assessment_score WHERE ref_course_id IN ('" + course_ids + "') AND ref_student_id IN ('" + student_ids + "') ORDER BY last_update "; // 2018/6/21 通通都抓了,因為一張成績單上資訊,不只Final的

            QueryHelper qh = new QueryHelper();
            DataTable   dt = qh.Select(sql);


            foreach (DataRow row in dt.Rows)
            {
                string termWord       = "" + row["term"];
                string subjectWord    = "" + row["subject"];
                string assessmentWord = "" + row["assessment"];

                string id = "" + row["ref_student_id"] + "_" + row["ref_course_id"];

                // 有教師自訂的子項目成績就跳掉 不處理
                if ("" + row["custom_assessment"] != "")
                {
                    continue;
                }

                // 要設計一個模式 處理 三種成績

                // 項目都有,為assessment 成績
                if (termWord != "" && "" + subjectWord != "" && "" + assessmentWord != "")
                {
                    if (_scoreDict.ContainsKey(id))
                    {
                        // 指標型成績
                        if (_indicatorList.Contains("" + row["ref_course_id"] + "_" + termWord.Trim().Replace(' ', '_').Replace('"', '_') + "_" + subjectWord.Trim().Replace(' ', '_').Replace('"', '_') + "_" + assessmentWord.Trim().Replace(' ', '_').Replace('"', '_')))
                        {
                            string key = "評量" + "_" + termWord.Trim().Replace(' ', '_').Replace('"', '_') + "/" + subjectWord.Trim().Replace(' ', '_').Replace('"', '_') + "/" + assessmentWord.Trim().Replace(' ', '_').Replace('"', '_') + "_" + "指標";
                            if (_scoreDict[id].ContainsKey(key))
                            {
                                _scoreDict[id][key] = "" + row["value"]; //重覆項目,後來時間的蓋過前面
                            }
                            else
                            {
                                _scoreDict[id].Add(key, "" + row["value"]);
                            }
                        }
                        // 評語型成績
                        else if (_commentList.Contains("" + row["ref_course_id"] + "_" + termWord.Trim().Replace(' ', '_').Replace('"', '_') + "_" + subjectWord.Trim().Replace(' ', '_').Replace('"', '_') + "_" + assessmentWord.Trim().Replace(' ', '_').Replace('"', '_')))
                        {
                            string key = "評量" + "_" + termWord.Trim().Replace(' ', '_').Replace('"', '_') + "/" + subjectWord.Trim().Replace(' ', '_').Replace('"', '_') + "/" + assessmentWord.Trim().Replace(' ', '_').Replace('"', '_') + "_" + "評語";
                            if (_scoreDict[id].ContainsKey(key))
                            {
                                _scoreDict[id][key] = "" + row["value"]; //重覆項目,後來時間的蓋過前面
                            }
                            else
                            {
                                _scoreDict[id].Add(key, "" + row["value"]);
                            }
                        }
                        // 分數型成績
                        else
                        {
                            string key = "評量" + "_" + termWord.Trim().Replace(' ', '_').Replace('"', '_') + "/" + subjectWord.Trim().Replace(' ', '_').Replace('"', '_') + "/" + assessmentWord.Trim().Replace(' ', '_').Replace('"', '_') + "_" + "分數";
                            if (_scoreDict[id].ContainsKey(key))
                            {
                                _scoreDict[id][key] = "" + row["value"]; //重覆項目,後來時間的蓋過前面
                            }
                            else
                            {
                                _scoreDict[id].Add(key, "" + row["value"]);
                            }
                        }
                    }
                }

                // 沒有assessment,為subject 成績
                if (termWord != "" && "" + subjectWord != "" && "" + assessmentWord == "")
                {
                    if (_scoreDict.ContainsKey(id))
                    {
                        _scoreDict[id].Add("評量" + "_" + termWord.Trim().Replace(' ', '_').Replace('"', '_') + "/" + subjectWord.Trim().Replace(' ', '_').Replace('"', '_') + "_" + "分數", "" + row["value"]);
                    }
                }
                // 沒有assessment、subject,為term 成績
                if (termWord != "" && "" + subjectWord == "" && "" + assessmentWord == "")
                {
                    if (_scoreDict.ContainsKey(id))
                    {
                        _scoreDict[id].Add("評量" + "_" + termWord.Trim().Replace(' ', '_').Replace('"', '_') + "_" + "分數", "" + row["value"]);
                    }
                }
            }



            // 課程學期成績
            string sqlSemesterCourseScore = @"SELECT
sc_attend.ref_student_id
,sc_attend.ref_course_id
,exam_template.name
,course.domain
,course.subject
,sc_attend.score
FROM sc_attend
LEFT JOIN course ON course.id = sc_attend.ref_course_id
LEFT JOIN exam_template ON exam_template.id =course.ref_exam_template_id
WHERE course.id IN ('" + course_ids + "') " +
                                            "AND sc_attend.ref_student_id IN ('" + student_ids + "')" +
                                            "ORDER BY ref_student_id,domain,subject";

            DataTable dtSemesterCourseScore = qh.Select(sqlSemesterCourseScore);

            foreach (DataRow row in dtSemesterCourseScore.Rows)
            {
                string id = "" + row["ref_student_id"] + "_" + row["ref_course_id"];

                string templateWord = "" + row["name"];
                string domainWord   = "" + row["domain"];
                string subjectWord  = "" + row["subject"];

                string score = "" + row["score"]; // 課程學期成績


                if (_scoreDict.ContainsKey(id))
                {
                    #region 跟樣板的功能變數
                    // 理論上一學期上 一個學生 只會有一個ESL評分樣版的課程成績 , 不會有同一個ESL 評分樣版 有不同的課程成績
                    if (!_scoreDict[id].ContainsKey("課程學期成績分數"))
                    {
                        _scoreDict[id].Add("課程學期成績分數", score);
                    }
                    if (!_scoreDict[id].ContainsKey("課程學期成績等第"))
                    {
                        decimal score_d;
                        if (decimal.TryParse(score, out score_d))
                        {
                            _scoreDict[id].Add("課程學期成績等第", dm.GetDegreeByScore(score_d));
                        }
                    }

                    #endregion
                }
            }



            #endregion


            foreach (K12.Data.SCAttendRecord scar in scList)
            {
                string id = scar.RefStudentID + "_" + scar.RefCourseID;

                string assessmentSetID = _courseIDPairDict[scar.RefCourseID];

                DataTable data = _assessmentSetupDataTableDict[assessmentSetID];

                DataRow row = data.NewRow();
                row["電子報表辨識編號"] = "系統編號{" + scar.Student.ID + "}"; // 學生系統編號

                row["學年度"]    = scar.Course.SchoolYear;
                row["學期"]     = scar.Course.Semester;
                row["學號"]     = scar.Student.StudentNumber;
                row["年級"]     = scar.Student.Class != null ? "" + scar.Student.Class.GradeYear : "";
                row["英文課程名稱"] = scar.Course.Name;
                row["原班級名稱"]  = scar.Student.Class != null ? "" + scar.Student.Class.Name : "";
                row["學生英文姓名"] = scar.Student.EnglishName;
                row["學生中文姓名"] = scar.Student.Name;
                row["教師一"]    = scar.Course.Teachers.Count > 0 ? scar.Course.Teachers.Find(x => x.Sequence == 1).TeacherName : ""; // 新寫法 直接找list 內教師條件
                row["教師二"]    = scar.Course.Teachers.Count > 1 ? scar.Course.Teachers.Find(x => x.Sequence == 2).TeacherName : "";
                row["教師三"]    = scar.Course.Teachers.Count > 2 ? scar.Course.Teachers.Find(x => x.Sequence == 3).TeacherName : "";

                if (_itemDict.ContainsKey(scar.RefCourseID))
                {
                    foreach (string mergeKey in _itemDict[scar.RefCourseID].Keys)
                    {
                        if (row.Table.Columns.Contains(mergeKey))
                        {
                            row[mergeKey] = _itemDict[scar.RefCourseID][mergeKey];
                        }
                    }
                }


                if (_scoreDict.ContainsKey(id))
                {
                    foreach (string mergeKey  in _scoreDict[id].Keys)
                    {
                        if (row.Table.Columns.Contains(mergeKey))
                        {
                            row[mergeKey] = _scoreDict[id][mergeKey];
                        }
                    }
                }



                data.Rows.Add(row);

                count++;
                progress += (int)(count * per);
                _worker.ReportProgress(progress);
            }

            Document docFinal = new Document();

            foreach (string assessmentSetupID in _assessmentSetupDataTableDict.Keys)
            {
                Document doc = _documentDict[assessmentSetupID];

                DataTable data = _assessmentSetupDataTableDict[assessmentSetupID];

                doc.MailMerge.Execute(data);

                docFinal.AppendDocument(doc, ImportFormatMode.KeepSourceFormatting);
            }


            docFinal.Sections[0].Remove();// 把第一頁刪掉


            e.Result = docFinal;


            _worker.ReportProgress(100, "ESL 報表列印完成。");
        }
Exemple #17
0
        public static void Main()
        {
            FISCA.UDT.AccessHelper accessHelper = new FISCA.UDT.AccessHelper();

            // 先將UDT 選起來,如果是第一次開啟沒有話就會新增
            accessHelper.Select <UDT_MakeUpBatch>();
            accessHelper.Select <UDT_MakeUpGroup>();
            accessHelper.Select <UDT_MakeUpData>();
            accessHelper.Select <UDT_ReportTemplate>();


            MotherForm.RibbonBarItems["教務作業", "補考作業"]["補考作業"].Size = RibbonBarButton.MenuButtonSize.Large;

            MotherForm.RibbonBarItems["教務作業", "補考作業"]["補考作業"].Image = Properties.Resources.calc_64;

            {
                Catalog ribbon = RoleAclSource.Instance["教務作業"]["補考作業"];
                ribbon.Add(new RibbonFeature("BE538A8F-71BA-4979-A04A-32A8C239E716", "管理補考梯次"));

                MotherForm.RibbonBarItems["教務作業", "補考作業"]["補考作業"]["管理補考梯次"].Enable = UserAcl.Current["BE538A8F-71BA-4979-A04A-32A8C239E716"].Executable;

                MotherForm.RibbonBarItems["教務作業", "補考作業"]["補考作業"]["管理補考梯次"].Click += delegate
                {
                    Form.MakeUpBatchManagerForm mubmf = new Form.MakeUpBatchManagerForm();

                    mubmf.ShowDialog();
                };
            }

            {
                Catalog ribbon = RoleAclSource.Instance["教務作業"]["補考作業"];
                ribbon.Add(new RibbonFeature("AE783777-B1F1-47F7-814B-887FC0C2460D", "管理補考群組"));

                MotherForm.RibbonBarItems["教務作業", "補考作業"]["補考作業"]["管理補考群組"].Enable = UserAcl.Current["AE783777-B1F1-47F7-814B-887FC0C2460D"].Executable;

                MotherForm.RibbonBarItems["教務作業", "補考作業"]["補考作業"]["管理補考群組"].Click += delegate
                {
                    Form.MakeUpGroupManagerForm mugmf = new Form.MakeUpGroupManagerForm("管理補考群組");

                    mugmf.ShowDialog();
                };
            }

            {
                Catalog ribbon = RoleAclSource.Instance["教務作業"]["補考作業"];
                ribbon.Add(new RibbonFeature("5AA949A7-7535-42DD-A81C-D4E4DB2B677C", "產生補考公告"));

                MotherForm.RibbonBarItems["教務作業", "補考作業"]["補考作業"]["產生補考公告"].Enable = UserAcl.Current["5AA949A7-7535-42DD-A81C-D4E4DB2B677C"].Executable;

                MotherForm.RibbonBarItems["教務作業", "補考作業"]["補考作業"]["產生補考公告"].Click += delegate
                {
                    Form.ExportMakeUpReportForm emurf = new Form.ExportMakeUpReportForm();

                    emurf.ShowDialog();
                };
            }

            {
                Catalog ribbon = RoleAclSource.Instance["教務作業"]["補考作業"];
                ribbon.Add(new RibbonFeature("6AED85C7-F6CF-49A5-8AAC-C97CF7127AEB", "補考成績輸入狀況"));

                MotherForm.RibbonBarItems["教務作業", "補考作業"]["補考作業"]["補考成績輸入狀況"].Enable = UserAcl.Current["6AED85C7-F6CF-49A5-8AAC-C97CF7127AEB"].Executable;

                MotherForm.RibbonBarItems["教務作業", "補考作業"]["補考作業"]["補考成績輸入狀況"].Click += delegate
                {
                    Form.MakeUpScoreStatusForm myssf = new Form.MakeUpScoreStatusForm();

                    myssf.ShowDialog();
                };
            }



            // 2019/06/03 穎驊註解, 後來有了 補考成績輸入狀況 檢查, 就把 管理成績輸入 介面一併 併過了去了, 這個專門輸入成績的流程 先隱藏
            //{
            //    Catalog ribbon = RoleAclSource.Instance["教務作業"]["補考作業"];
            //    ribbon.Add(new RibbonFeature("47A870E8-0C03-4DE0-A85E-C2B4551351C8", "管理補考成績"));

            //    MotherForm.RibbonBarItems["教務作業", "補考作業"]["補考作業"]["管理補考成績"].Enable = UserAcl.Current["47A870E8-0C03-4DE0-A85E-C2B4551351C8"].Executable;

            //    MotherForm.RibbonBarItems["教務作業", "補考作業"]["補考作業"]["管理補考成績"].Click += delegate
            //    {
            //        Form.MakeUpGroupManagerForm mugmf = new Form.MakeUpGroupManagerForm("管理補考成績");

            //        mugmf.ShowDialog();
            //    };
            //}


            {
                Catalog ribbon = RoleAclSource.Instance["教務作業"]["補考作業"];
                ribbon.Add(new RibbonFeature("E3D987DC-E75C-4472-BAB8-C58EEAA844F9", "產生學期科目成績匯入檔"));

                MotherForm.RibbonBarItems["教務作業", "補考作業"]["補考作業"]["產生學期科目成績匯入檔"].Enable = UserAcl.Current["E3D987DC-E75C-4472-BAB8-C58EEAA844F9"].Executable;

                MotherForm.RibbonBarItems["教務作業", "補考作業"]["補考作業"]["產生學期科目成績匯入檔"].Click += delegate
                {
                    Form.ExportMakeUpScoreForm emusf = new Form.ExportMakeUpScoreForm();

                    emusf.ShowDialog();
                };
            }
        }
        private void Worker_DoWork(object sender, DoWorkEventArgs e)
        {
            _worker.ReportProgress(0, "開始列印 ESL報表...");

            #region 取得課程成績單 設定樣板
            _eslCouseList = new List <K12.Data.CourseRecord>();

            _eslCouseList = K12.Data.Course.SelectByIDs(_courseIDList);

            _refAssessmentSetupIDList = new List <string>();

            foreach (K12.Data.CourseRecord courseRecord in _eslCouseList)
            {
                if (!_refAssessmentSetupIDList.Contains("'" + courseRecord.RefAssessmentSetupID + "'"))
                {
                    _refAssessmentSetupIDList.Add("'" + courseRecord.RefAssessmentSetupID + "'");
                }

                if (!_courseIDPairDict.ContainsKey(courseRecord.ID))
                {
                    _courseIDPairDict.Add(courseRecord.ID, courseRecord.RefAssessmentSetupID);
                }

                if (!_assessmentSetupIDPairDict.ContainsKey(courseRecord.RefAssessmentSetupID))
                {
                    _assessmentSetupIDPairDict.Add(courseRecord.RefAssessmentSetupID, courseRecord.ID);
                }
            }

            string assessmentSetupIDs = string.Join(",", _refAssessmentSetupIDList);


            FISCA.UDT.AccessHelper _AccessHelper = new FISCA.UDT.AccessHelper();

            _worker.ReportProgress(0, "取得課程成績單設定樣板...");


            string qry = "ref_exam_template_id IN (" + assessmentSetupIDs + ") and schoolyear='" + K12.Data.School.DefaultSchoolYear + "' and semester ='" + K12.Data.School.DefaultSemester + "' and exam ='" + _examType + "'";

            List <UDT_ReportTemplate> configures = _AccessHelper.Select <UDT_ReportTemplate>(qry);

            _documentDict = new Dictionary <string, Document>();

            foreach (UDT_ReportTemplate templateconfig in configures)
            {
                if (!_documentDict.ContainsKey(templateconfig.Ref_exam_Template_ID))
                {
                    Document _doc = new Document();

                    templateconfig.Decode(); // 將 stream 轉成 Word

                    _doc = templateconfig.Template;

                    _documentDict.Add(templateconfig.Ref_exam_Template_ID, _doc);
                }
            }
            #endregion


            #region 取得修課學生、 並做整理
            List <K12.Data.SCAttendRecord> scList = K12.Data.SCAttend.SelectByCourseIDs(_courseIDList);

            List <string> studentIDList = new List <string>();


            foreach (K12.Data.SCAttendRecord scr in scList)
            {
                studentIDList.Add(scr.Student.ID);

                // 建立成績整理 Dict ,[studentID_courseID,[scoreKey,scoreID]]
                _scoreDict.Add(scr.Student.ID + "_" + scr.Course.ID, new Dictionary <string, string>());
            }
            #endregion

            // 建立功能變數對照
            CreateFieldTemplate();

            #region 取得、整理ESL成績
            _worker.ReportProgress(20, "取得ESL課程成績");


            int     progress = 80;
            decimal per      = (decimal)(100 - progress) / scList.Count;
            int     count    = 0;

            string course_ids = string.Join("','", _courseIDList);

            string student_ids = string.Join("','", studentIDList);

            string sql = "SELECT * FROM $esl.gradebook_assessment_score WHERE ref_course_id IN ('" + course_ids + "') AND ref_student_id IN ('" + student_ids + "') "; // 2018/6/21 通通都抓了,因為一張成績單上資訊,不只Final的

            QueryHelper qh = new QueryHelper();
            DataTable   dt = qh.Select(sql);


            foreach (DataRow row in dt.Rows)
            {
                string termWord       = "" + row["term"];
                string subjectWord    = "" + row["subject"];
                string assessmentWord = "" + row["assessment"];

                string id = "" + row["ref_student_id"] + "_" + row["ref_course_id"];

                // 有教師自訂的子項目成績就跳掉 不處理
                if ("" + row["custom_assessment"] != "")
                {
                    continue;
                }

                // 要設計一個模式 處理 三種成績

                // 項目都有,為assessment 成績
                if (termWord != "" && "" + subjectWord != "" && "" + assessmentWord != "")
                {
                    if (_scoreDict.ContainsKey(id))
                    {
                        // 指標型成績
                        if (_indicatorList.Contains("" + row["ref_course_id"] + "_" + "_" + termWord + "_" + subjectWord + "_" + assessmentWord))
                        {
                            _scoreDict[id].Add("評量" + "_" + termWord.Trim().Replace(' ', '_').Replace('"', '_') + "/" + subjectWord.Trim().Replace(' ', '_').Replace('"', '_') + "/" + assessmentWord.Trim().Replace(' ', '_').Replace('"', '_') + "_" + "指標", "" + row["value"]);
                        }
                        // 評語型成績
                        else if (_commentList.Contains("" + row["ref_course_id"] + "_" + "_" + termWord + "_" + subjectWord + "_" + assessmentWord))
                        {
                            _scoreDict[id].Add("評量" + "_" + termWord.Trim().Replace(' ', '_').Replace('"', '_') + "/" + subjectWord.Trim().Replace(' ', '_').Replace('"', '_') + "/" + assessmentWord.Trim().Replace(' ', '_').Replace('"', '_') + "_" + "評語", "" + row["value"]);
                        }
                        // 分數型成績
                        else
                        {
                            _scoreDict[id].Add("評量" + "_" + termWord.Trim().Replace(' ', '_').Replace('"', '_') + "/" + subjectWord.Trim().Replace(' ', '_').Replace('"', '_') + "/" + assessmentWord.Trim().Replace(' ', '_').Replace('"', '_') + "_" + "分數", "" + row["value"]);
                        }
                    }
                }

                // 沒有assessment,為subject 成績
                if (termWord != "" && "" + subjectWord != "" && "" + assessmentWord == "")
                {
                    if (_scoreDict.ContainsKey(id))
                    {
                        _scoreDict[id].Add("評量" + "_" + termWord.Trim().Replace(' ', '_').Replace('"', '_') + "/" + subjectWord.Trim().Replace(' ', '_').Replace('"', '_') + "_" + "分數", "" + row["value"]);
                    }
                }
                // 沒有assessment、subject,為term 成績
                if (termWord != "" && "" + subjectWord == "" && "" + assessmentWord == "")
                {
                    if (_scoreDict.ContainsKey(id))
                    {
                        _scoreDict[id].Add("評量" + "_" + termWord.Trim().Replace(' ', '_').Replace('"', '_') + "_" + "分數", "" + row["value"]);
                    }
                }
            }
            #endregion



            //// 配對學生 與 其功能變數關係
            //foreach (K12.Data.SCAttendRecord scar in scList)
            //{
            //    string id = scar.RefStudentID + "_" + scar.RefCourseID;

            //    string assessmentSetID = _courseIDPairDict[scar.RefCourseID];

            //    _scoreDataTableDict.Add(id, _assessmentSetupDataTableDict[assessmentSetID]);
            //}


            foreach (K12.Data.SCAttendRecord scar in scList)
            {
                string id = scar.RefStudentID + "_" + scar.RefCourseID;

                string assessmentSetID = _courseIDPairDict[scar.RefCourseID];

                DataTable data = _assessmentSetupDataTableDict[assessmentSetID];

                DataRow row = data.NewRow();
                row["電子報表辨識編號"] = "系統編號{" + scar.Student.ID + "}"; // 學生系統編號

                row["學號"]     = scar.Student.StudentNumber;
                row["年級"]     = scar.Student.Class != null ? "" + scar.Student.Class.GradeYear : "";
                row["英文課程名稱"] = scar.Course.Name;
                row["原班級名稱"]  = scar.Student.Class != null ? "" + scar.Student.Class.Name : "";
                row["學生英文姓名"] = scar.Student.EnglishName;
                row["學生中文姓名"] = scar.Student.Name;
                row["教師一"]    = scar.Course.Teachers.Count > 0 ? scar.Course.Teachers.Find(x => x.Sequence == 1).TeacherName : ""; // 新寫法 直接找list 內教師條件
                row["教師二"]    = scar.Course.Teachers.Count > 1 ? scar.Course.Teachers.Find(x => x.Sequence == 2).TeacherName : "";
                row["教師三"]    = scar.Course.Teachers.Count > 2 ? scar.Course.Teachers.Find(x => x.Sequence == 3).TeacherName : "";

                if (_itemDict.ContainsKey(scar.RefCourseID))
                {
                    foreach (KeyValuePair <string, string> p in _itemDict[scar.RefCourseID])
                    {
                        row[p.Key] = p.Value;
                    }
                }


                if (_scoreDict.ContainsKey(id))
                {
                    foreach (KeyValuePair <string, string> p in _scoreDict[id])
                    {
                        row[p.Key] = p.Value;
                    }
                }



                data.Rows.Add(row);

                count++;
                progress += (int)(count * per);
                _worker.ReportProgress(progress);
            }

            Document docFinal = new Document();

            foreach (string assessmentSetupID in _assessmentSetupDataTableDict.Keys)
            {
                Document doc = _documentDict[assessmentSetupID];

                DataTable data = _assessmentSetupDataTableDict[assessmentSetupID];

                doc.MailMerge.Execute(data);

                docFinal.AppendDocument(doc, ImportFormatMode.KeepSourceFormatting);
            }


            docFinal.Sections[0].Remove();// 把第一頁刪掉


            e.Result = docFinal;


            _worker.ReportProgress(100, "ESL 報表列印完成。");
        }
        private void backgroundWorker2_DoWork(object sender, DoWorkEventArgs e)
        {
            FISCA.UDT.AccessHelper ah = new FISCA.UDT.AccessHelper();

            List<FISCA.UDT.ActiveRecord> objs = new List<FISCA.UDT.ActiveRecord>();
            objs.Add(this.card_data);

            if (string.IsNullOrEmpty(this.card_data.UID))
            {
                ah.InsertValues(objs);
            }
            else
            {
                ah.UpdateValues(objs);
            }
        }
        public static void AddMenuButton()
        {
            var accessHelper = new FISCA.UDT.AccessHelper();
            var ribbonBarItem = K12.Presentation.NLDPanels.Course.RibbonBarItems["課程行事曆"];
            var syncButton = ribbonBarItem["同步行事曆"];

            Catalog button_syncCalendar = RoleAclSource.Instance["課程"]["功能按鈕"];
            button_syncCalendar.Add(new RibbonFeature("Sync_Course_Calendar", "同步課程行事曆"));
            bool isEnabled = UserAcl.Current["Sync_Course_Calendar"].Executable;

            syncButton.Enable = ((K12.Presentation.NLDPanels.Course.SelectedSource.Count > 0) && isEnabled);
            K12.Presentation.NLDPanels.Course.SelectedSourceChanged += delegate(object sender, EventArgs e)
            {

                syncButton.Enable = ((K12.Presentation.NLDPanels.Course.SelectedSource.Count > 0) && isEnabled);
            };
            syncButton.Click += delegate
            {
                bool hasFaild = false;
                FISCA.Presentation.MotherForm.SetStatusBarMessage("課程行事曆同步中...", 0);
                List<string> selectedSource = new List<string>(K12.Presentation.NLDPanels.Course.SelectedSource);
                BackgroundWorker bkw = new System.ComponentModel.BackgroundWorker() { WorkerReportsProgress = true };
                bkw.ProgressChanged += delegate(object sender, ProgressChangedEventArgs e)
                {
                    FISCA.Presentation.MotherForm.SetStatusBarMessage("課程行事曆同步中...", e.ProgressPercentage);
                };
                bkw.RunWorkerCompleted += delegate(object sender, RunWorkerCompletedEventArgs e)
                {
                    SectionSyncColumn.Reload();
                    FISCA.Presentation.MotherForm.SetStatusBarMessage("課程行事曆同步完成");
                    if (hasFaild)
                    {
                        FISCA.Presentation.Controls.MsgBox.Show("課程行事曆同步完成,其中部分資料同步失敗,請稍後再試。");
                    }
                };
                bkw.DoWork += delegate(object sender, DoWorkEventArgs e)
                {
                    Dictionary<string, Calendar> calendars = new Dictionary<string, Calendar>();
                    Dictionary<string, List<string>> courseAttend = new Dictionary<string, List<string>>();
                    Dictionary<string, List<Section>> publishItems = new Dictionary<string, List<Section>>();
                    Dictionary<string, string> studentLoginAccount = new Dictionary<string, string>();
                    List<string> syncCourses = new List<string>();
                    int count = 0;
                    string condition = "RefCourseID in (";
                    foreach (string key in selectedSource)
                    {
                        if (condition != "RefCourseID in (")
                            condition += ",";
                        condition += "'" + key + "'";
                    }
                    condition += ")";
                    string condition2 = "ref_course_id in (";
                    foreach (string key in selectedSource)
                    {
                        if (condition2 != "ref_course_id in (")
                            condition2 += ",";
                        condition2 += "'" + key + "'";
                    }
                    condition2 += ")";
                    bkw.ReportProgress(3);
                    foreach (Section section in accessHelper.Select<Section>(condition))
                    {
                        if (!section.IsPublished || section.Removed)
                        {
                            if (!publishItems.ContainsKey(section.RefCourseID))
                                publishItems.Add(section.RefCourseID, new List<Section>());
                            publishItems[section.RefCourseID].Add(section);
                            count++;
                        }
                    }
                    foreach (Calendar cal in accessHelper.Select<Calendar>(condition))
                    {
                        if (!calendars.ContainsKey(cal.RefCourseID))
                            calendars.Add(cal.RefCourseID, cal);
                    }
                    syncCourses.AddRange(publishItems.Keys);
                    foreach (var item in accessHelper.Select<SCAttendExt>(condition2))
                    {
                        if (!courseAttend.ContainsKey(item.CourseID.ToString()))
                            courseAttend.Add(item.CourseID.ToString(), new List<string>());
                        courseAttend[item.CourseID.ToString()].Add(item.StudentID.ToString());
                        if (!studentLoginAccount.ContainsKey(item.StudentID.ToString()))
                            studentLoginAccount.Add(item.StudentID.ToString(), "");
                        count++;
                    }
                    foreach (string key in selectedSource)
                    {
                        if (!courseAttend.ContainsKey(key))
                            courseAttend.Add(key, new List<string>());
                    }
                    foreach (var student in K12.Data.Student.SelectByIDs(studentLoginAccount.Keys))
                    {
                        if (student.SALoginName != "")
                        {
                            studentLoginAccount[student.ID] = student.SALoginName.ToLower();
                        }
                    }
                    foreach (string calid in courseAttend.Keys)
                    {
                        if (calendars.ContainsKey(calid))
                        {
                            Calendar cal = calendars[calid];
                            List<string> aclList = new List<string>(cal.ACLList.Split("%".ToCharArray(), StringSplitOptions.RemoveEmptyEntries));
                            List<string> attentAccounts = new List<string>();
                            foreach (string sid in courseAttend[calid])
                            {
                                if (studentLoginAccount[sid] != "")
                                    attentAccounts.Add(studentLoginAccount[sid]);
                            }
                            if (aclList.Count != attentAccounts.Count)
                            {
                                if (!syncCourses.Contains(calid))
                                    syncCourses.Add(calid);
                            }
                            else
                            {
                                foreach (string acc in aclList)
                                {
                                    if (!attentAccounts.Contains(acc.ToLower()))
                                    {
                                        if (!syncCourses.Contains(calid))
                                            syncCourses.Add(calid);
                                        break;
                                    }
                                }
                            }
                        }
                    }
                    bkw.ReportProgress(5);
                    CalendarService myService = new CalendarService("ischool.CourseCalendar");
                    myService.setUserCredentials(googleAcc, googlePWD);
                    bkw.ReportProgress(20);
                    List<Section> syncedSections = new List<Section>();
                    foreach (K12.Data.CourseRecord course in K12.Data.Course.SelectByIDs(syncCourses))
                    {
                        //CalendarEntry targetCalender = null;
                        Calendar targetCal = null;
                        try
                        {
                            if (!calendars.ContainsKey(course.ID))
                            {
                                #region 建立新Calender
                                string[] colorLists = new string[]{"#A32929","#B1365F","#7A367A","#5229A3","#29527A","#2952A3","#1B887A",
                            "#28754E","#0D7813","#528800","#88880E","#AB8B00","#BE6D00","#B1440E",
                            "#865A5A","#705770","#4E5D6C","#5A6986","#4A716C","#6E6E41","#8D6F47"};
                                CalendarEntry newCal = new CalendarEntry();
                                newCal.Title.Text = course.Name;
                                newCal.Summary.Text = "科目:" + course.Subject
                                    + "\n學年度:" + course.SchoolYear
                                    + "\n學期:" + course.Semester
                                    + "\n學分數:" + course.Credit;
                                newCal.TimeZone = "Asia/Taipei";
                                //targetCalender.Hidden = false;
                                newCal.Color = colorLists[new Random(DateTime.Now.Millisecond).Next(0, colorLists.Length)];
                                Uri postUri = new Uri("http://www.google.com/calendar/feeds/default/owncalendars/full");
                                newCal = (CalendarEntry)myService.Insert(postUri, newCal);
                                #endregion
                                String calendarURI = newCal.Id.Uri.ToString();
                                String calendarID = calendarURI.Substring(calendarURI.LastIndexOf("/") + 1);
                                targetCal = new Calendar() { RefCourseID = course.ID, GoogleCalanderID = calendarID };
                                targetCal.Save();
                            }
                            else
                            {
                                targetCal = calendars[course.ID];
                            }
                        }
                        catch
                        {
                            hasFaild = true;
                        }
                        if (targetCal != null)
                        {
                            try
                            {
                                #region ACL
                                if (courseAttend.ContainsKey(course.ID))
                                {
                                    List<string> aclList = new List<string>(targetCal.ACLList.Split("%".ToCharArray(), StringSplitOptions.RemoveEmptyEntries));
                                    for (int i = 0; i < aclList.Count; i++)
                                    {
                                        aclList[i] = aclList[i].ToLower();
                                    }
                                    List<string> attentAccounts = new List<string>();
                                    foreach (string sid in courseAttend[course.ID])
                                    {
                                        if (studentLoginAccount[sid] != "")
                                            attentAccounts.Add(studentLoginAccount[sid]);
                                    }
                                    foreach (string acc in attentAccounts)
                                    {
                                        if (!aclList.Contains(acc))
                                        {
                                            try
                                            {
                                                #region 新增分享
                                                AclEntry entry = new AclEntry();
                                                entry.Scope = new AclScope();
                                                entry.Scope.Type = AclScope.SCOPE_USER;
                                                entry.Scope.Value = acc;
                                                entry.Role = AclRole.ACL_CALENDAR_READ;
                                                try
                                                {
                                                    AclEntry insertedEntry = myService.Insert(new Uri("https://www.google.com/calendar/feeds/" + targetCal.GoogleCalanderID + "/acl/full"), entry);
                                                }
                                                catch (GDataRequestException gex)
                                                {
                                                    if (!gex.InnerException.Message.Contains("(409)"))
                                                        throw;
                                                }
                                                #endregion
                                                aclList.Add(acc);
                                            }
                                            catch
                                            {
                                                hasFaild = true;
                                            }
                                        }
                                    }
                                    List<string> removeList = new List<string>();
                                    if (aclList.Count != attentAccounts.Count)
                                    {
                                        #region 移除分享
                                        AtomFeed calFeed = myService.Query(new FeedQuery("https://www.google.com/calendar/feeds/" + targetCal.GoogleCalanderID + "/acl/full"));
                                        foreach (string acc in aclList)
                                        {
                                            if (!attentAccounts.Contains(acc))
                                            {
                                                try
                                                {
                                                    foreach (AtomEntry atomEntry in calFeed.Entries)
                                                    {
                                                        if (atomEntry is AtomEntry)
                                                        {
                                                            AclEntry aclEntry = (AclEntry)atomEntry;
                                                            if (aclEntry.Scope.Value.ToLower() == acc)
                                                            {
                                                                aclEntry.Delete();
                                                                break;
                                                            }
                                                        }
                                                    }
                                                    removeList.Add(acc);
                                                }
                                                catch
                                                {
                                                    hasFaild = true;
                                                }
                                            }
                                        }
                                        #endregion
                                    }
                                    foreach (string acc in removeList)
                                    {
                                        if (aclList.Contains(acc)) aclList.Remove(acc);
                                    }
                                    targetCal.ACLList = "";
                                    foreach (string acc in aclList)
                                    {
                                        targetCal.ACLList += (targetCal.ACLList == "" ? "" : "%") + acc;
                                    }
                                }
                                #endregion
                                #region Events
                                if (publishItems.ContainsKey(course.ID))
                                {
                                    EventFeed feed = myService.Query(new EventQuery("https://www.google.com/calendar/feeds/" + targetCal.GoogleCalanderID + "/private/full"));
                                    AtomFeed batchFeed = new AtomFeed(feed);
                                    foreach (Section section in publishItems[course.ID])
                                    {
                                        if (!section.Removed)
                                        {
                                            #region 新增Event
                                            Google.GData.Calendar.EventEntry eventEntry = new Google.GData.Calendar.EventEntry();

                                            eventEntry.Title.Text = course.Name;
                                            //eventEntry
                                            Where eventLocation = new Where();
                                            eventLocation.ValueString = section.Place;
                                            eventEntry.Locations.Add(eventLocation);
                                            eventEntry.Notifications = true;
                                            eventEntry.Times.Add(new When(section.StartTime, section.EndTime));
                                            eventEntry.Participants.Add(new Who()
                                            {
                                                ValueString = googleAcc,
                                                Attendee_Type = new Who.AttendeeType() { Value = Who.AttendeeType.EVENT_REQUIRED },
                                                Attendee_Status = new Who.AttendeeStatus() { Value = Who.AttendeeStatus.EVENT_ACCEPTED },
                                                Rel = Who.RelType.EVENT_ATTENDEE
                                            });
                                            eventEntry.BatchData = new GDataBatchEntryData(section.UID, GDataBatchOperationType.insert);
                                            batchFeed.Entries.Add(eventEntry);
                                            #endregion
                                        }
                                        else
                                        {
                                            #region 刪除Event

                                            EventEntry toDelete = (EventEntry)feed.Entries.FindById(new AtomId(feed.Id.AbsoluteUri + "/" + section.EventID));
                                            if (toDelete != null)
                                            {
                                                toDelete.Id = new AtomId(toDelete.EditUri.ToString());
                                                toDelete.BatchData = new GDataBatchEntryData(section.UID, GDataBatchOperationType.delete);
                                                batchFeed.Entries.Add(toDelete);
                                            }
                                            else
                                            {
                                                section.Deleted = true;
                                                syncedSections.Add(section);
                                            }
                                            #endregion
                                        }
                                        int p = syncedSections.Count * 80 / count + 20;
                                        if (p > 100) p = 100;
                                        if (p < 0) p = 0;
                                        bkw.ReportProgress(p);
                                    }
                                    EventFeed batchResultFeed = (EventFeed)myService.Batch(batchFeed, new Uri(feed.Batch));
                                    foreach (Section section in publishItems[course.ID])
                                    {
                                        if (syncedSections.Contains(section)) continue;
                                        #region 儲存Section狀態
                                        bool match = false;
                                        if (section.Removed)
                                        {
                                            foreach (EventEntry entry in batchResultFeed.Entries)
                                            {
                                                if (entry.BatchData.Status.Code == 200)
                                                {
                                                    if (section.UID == entry.BatchData.Id)
                                                    {
                                                        section.Deleted = true;
                                                        match = true;
                                                        syncedSections.Add(section);
                                                        break;
                                                    }
                                                }
                                            }
                                        }
                                        else
                                        {
                                            foreach (EventEntry entry in batchResultFeed.Entries)
                                            {
                                                if (entry.BatchData.Status.Code == 201)
                                                {
                                                    if (section.UID == entry.BatchData.Id)
                                                    {
                                                        section.IsPublished = true;
                                                        match = true;
                                                        section.EventID = entry.EventId;
                                                        syncedSections.Add(section);
                                                        break;
                                                    }
                                                }
                                            }
                                        }
                                        if (!match)
                                            hasFaild = true;
                                        #endregion
                                    }
                                }
                                #endregion
                            }
                            catch
                            {
                                hasFaild = true;
                            }
                            targetCal.Save();
                        }
                    }
                    syncedSections.SaveAll();
                };
                bkw.RunWorkerAsync();
            };
        }
Exemple #21
0
        public static void Main()
        {
            FISCA.UDT.AccessHelper accessHelper = new FISCA.UDT.AccessHelper();

            accessHelper.Select <UDT_ReportTemplate>();       // 先將UDT 選起來,如果是第一次開啟沒有話就會新增
            accessHelper.Select <UDT_WeeklyReportTemplate>(); // 先將UDT 選起來,如果是第一次開啟沒有話就會新增

            Catalog ribbon = RoleAclSource.Instance["教務作業"]["功能按鈕"];

            ribbon.Add(new RibbonFeature("ESL評分樣版設定", "ESL評分樣版設定"));

            MotherForm.RibbonBarItems["教務作業", "基本設定"]["設定"]["ESL評分樣版設定"].Enable = UserAcl.Current["ESL評分樣版設定"].Executable;

            MotherForm.RibbonBarItems["教務作業", "基本設定"]["設定"]["ESL評分樣版設定"].Click += delegate
            {
                Form.ESL_TemplateSetupManager form = new Form.ESL_TemplateSetupManager();

                form.ShowDialog();
            };

            Catalog ribbon2 = RoleAclSource.Instance["課程"]["ESL課程"];

            ribbon2.Add(new RibbonFeature("ESL評量分數計算", "評量成績結算"));

            MotherForm.RibbonBarItems["課程", "ESL課程"]["評量成績結算"].Enable = false;

            K12.Presentation.NLDPanels.Course.SelectedSourceChanged += (sender, e) =>
            {
                if (K12.Presentation.NLDPanels.Course.SelectedSource.Count > 0)
                {
                    MotherForm.RibbonBarItems["課程", "ESL課程"]["評量成績結算"].Enable = UserAcl.Current["ESL評量分數計算"].Executable;
                }
                else
                {
                    MotherForm.RibbonBarItems["課程", "ESL課程"]["評量成績結算"].Enable = false;
                }
            };

            MotherForm.RibbonBarItems["課程", "ESL課程"]["評量成績結算"].Image = Properties.Resources.calc_64;
            MotherForm.RibbonBarItems["課程", "ESL課程"]["評量成績結算"].Size  = RibbonBarButton.MenuButtonSize.Medium;

            MotherForm.RibbonBarItems["課程", "ESL課程"]["評量成績結算"].Click += delegate
            {
                Form.CheckCalculateTermForm form = new Form.CheckCalculateTermForm(K12.Presentation.NLDPanels.Course.SelectedSource);

                form.ShowDialog();
            };


            //2019/02/26 穎驊註解, 依據ESL 寒假優化項目 課程上的 ESL 報表功能 將移除,日後會統一在學生上列印

            //Catalog ribbon3 = RoleAclSource.Instance["課程"]["ESL報表"];
            //ribbon3.Add(new RibbonFeature("ESL成績單", "ESL報表"));

            //MotherForm.RibbonBarItems["課程", "資料統計"]["報表"]["ESL報表"]["ESL成績單"].Enable = UserAcl.Current["ESL成績單"].Executable && K12.Presentation.NLDPanels.Course.SelectedSource.Count > 0;

            //K12.Presentation.NLDPanels.Course.SelectedSourceChanged += delegate
            //{
            //    MotherForm.RibbonBarItems["課程", "資料統計"]["報表"]["ESL報表"]["ESL成績單"].Enable = UserAcl.Current["ESL成績單"].Executable && (K12.Presentation.NLDPanels.Course.SelectedSource.Count > 0);
            //};


            //MotherForm.RibbonBarItems["課程", "資料統計"]["報表"]["ESL報表"]["ESL成績單"].Click += delegate
            //{
            //    List<string> eslCouseList = K12.Presentation.NLDPanels.Course.SelectedSource.ToList();

            //    Form.PrintESLReportForm printform = new Form.PrintESLReportForm(eslCouseList);

            //    printform.ShowDialog();

            //};


            Catalog ribbon4 = RoleAclSource.Instance["課程"]["ESL課程"];

            ribbon4.Add(new RibbonFeature("ESL課程成績輸入狀況", "成績輸入狀況"));

            MotherForm.RibbonBarItems["課程", "ESL課程"]["成績輸入狀況"].Enable = false;

            K12.Presentation.NLDPanels.Course.SelectedSourceChanged += (sender, e) =>
            {
                if (K12.Presentation.NLDPanels.Course.SelectedSource.Count > 0)
                {
                    MotherForm.RibbonBarItems["課程", "ESL課程"]["成績輸入狀況"].Enable = UserAcl.Current["ESL課程成績輸入狀況"].Executable;
                }
                else
                {
                    MotherForm.RibbonBarItems["課程", "ESL課程"]["成績輸入狀況"].Enable = false;
                }
            };

            MotherForm.RibbonBarItems["課程", "ESL課程"]["成績輸入狀況"].Image = Properties.Resources.calc_64;
            MotherForm.RibbonBarItems["課程", "ESL課程"]["成績輸入狀況"].Size  = RibbonBarButton.MenuButtonSize.Medium;

            MotherForm.RibbonBarItems["課程", "ESL課程"]["成績輸入狀況"].Click += delegate
            {
                List <string> eslCouseList = K12.Presentation.NLDPanels.Course.SelectedSource.ToList();

                Form.ESLCourseScoreStatusForm form = new Form.ESLCourseScoreStatusForm(eslCouseList);

                form.ShowDialog();
            };


            Catalog ribbon5 = RoleAclSource.Instance["學生"]["報表"];

            ribbon5.Add(new RibbonFeature("1C389099-FBA2-4C4B-9C0C-0FD7CB18EBC3", "ESL個人成績單"));

            MotherForm.RibbonBarItems["學生", "資料統計"]["報表"]["ESL報表"]["ESL個人成績單"].Enable = UserAcl.Current["1C389099-FBA2-4C4B-9C0C-0FD7CB18EBC3"].Executable && K12.Presentation.NLDPanels.Student.SelectedSource.Count > 0;

            K12.Presentation.NLDPanels.Student.SelectedSourceChanged += delegate
            {
                MotherForm.RibbonBarItems["學生", "資料統計"]["報表"]["ESL報表"]["ESL個人成績單"].Enable = UserAcl.Current["1C389099-FBA2-4C4B-9C0C-0FD7CB18EBC3"].Executable && (K12.Presentation.NLDPanels.Student.SelectedSource.Count > 0);
            };


            MotherForm.RibbonBarItems["學生", "資料統計"]["報表"]["ESL報表"]["ESL個人成績單"].Click += delegate
            {
                Form.PrintStudentESLReportForm form = new Form.PrintStudentESLReportForm();

                form.ShowDialog();
            };


            Catalog ribbon6 = RoleAclSource.Instance["課程"]["ESL課程"];

            ribbon6.Add(new RibbonFeature("12813482-3D73-4AEF-8924-FA5189C9BDE3", "課程成績匯出"));

            MotherForm.RibbonBarItems["課程", "ESL課程"]["課程成績匯出"].Enable = false;

            K12.Presentation.NLDPanels.Course.SelectedSourceChanged += (sender, e) =>
            {
                if (K12.Presentation.NLDPanels.Course.SelectedSource.Count > 0)
                {
                    MotherForm.RibbonBarItems["課程", "ESL課程"]["課程成績匯出"].Enable = UserAcl.Current["12813482-3D73-4AEF-8924-FA5189C9BDE3"].Executable;
                }
                else
                {
                    MotherForm.RibbonBarItems["課程", "ESL課程"]["課程成績匯出"].Enable = false;
                }
            };

            MotherForm.RibbonBarItems["課程", "ESL課程"]["課程成績匯出"].Image = Properties.Resources.admissions_zoom_64;
            MotherForm.RibbonBarItems["課程", "ESL課程"]["課程成績匯出"].Size  = RibbonBarButton.MenuButtonSize.Medium;

            MotherForm.RibbonBarItems["課程", "ESL課程"]["課程成績匯出"].Click += delegate
            {
                List <string> eslCouseList = K12.Presentation.NLDPanels.Course.SelectedSource.ToList();

                // 舊課程成績匯出,其格式 為SQL 抓出來的資料Excel, 不符合使用者直觀的介面,
                // 將用新的介面功能取代(從取前N名功能改寫過來)
                ExportESLscore_New exporter = new ExportESLscore_New(eslCouseList);
                exporter.PrintReport();
            };

            //MotherForm.RibbonBarItems["課程", "ESL課程"]["匯入新竹成績(暫時)"].Click += delegate
            //{
            //    ImportHCScore import = new ImportHCScore();
            //};

            Catalog ribbon7 = RoleAclSource.Instance["課程"]["ESL報表"];

            ribbon7.Add(new RibbonFeature("EB1AF12A-F5B3-41B9-9F9A-B2ABE541F3A3", "班級前N名"));

            MotherForm.RibbonBarItems["課程", "資料統計"]["報表"]["ESL報表"]["班級前N名"].Enable = UserAcl.Current["EB1AF12A-F5B3-41B9-9F9A-B2ABE541F3A3"].Executable && K12.Presentation.NLDPanels.Course.SelectedSource.Count > 0;

            K12.Presentation.NLDPanels.Course.SelectedSourceChanged += delegate
            {
                MotherForm.RibbonBarItems["課程", "資料統計"]["報表"]["ESL報表"]["班級前N名"].Enable = UserAcl.Current["EB1AF12A-F5B3-41B9-9F9A-B2ABE541F3A3"].Executable && (K12.Presentation.NLDPanels.Course.SelectedSource.Count > 0);
            };

            MotherForm.RibbonBarItems["課程", "資料統計"]["報表"]["ESL報表"]["班級前N名"].Click += delegate
            {
                List <string> eslCouseList = K12.Presentation.NLDPanels.Course.SelectedSource.ToList();


                Form.PrintESLAwardTotalScoreReportForm printform = new Form.PrintESLAwardTotalScoreReportForm(eslCouseList);

                printform.ShowDialog();
            };


            Catalog ribbon8 = RoleAclSource.Instance["課程"]["ESL報表"];

            ribbon8.Add(new RibbonFeature("4B1318A1-1DA6-4A23-8508-2A394CFE4D9C", "進步名單"));

            MotherForm.RibbonBarItems["課程", "資料統計"]["報表"]["ESL報表"]["進步名單"].Enable = UserAcl.Current["4B1318A1-1DA6-4A23-8508-2A394CFE4D9C"].Executable && K12.Presentation.NLDPanels.Course.SelectedSource.Count > 0;

            K12.Presentation.NLDPanels.Course.SelectedSourceChanged += delegate
            {
                MotherForm.RibbonBarItems["課程", "資料統計"]["報表"]["ESL報表"]["進步名單"].Enable = UserAcl.Current["4B1318A1-1DA6-4A23-8508-2A394CFE4D9C"].Executable && (K12.Presentation.NLDPanels.Course.SelectedSource.Count > 0);
            };

            MotherForm.RibbonBarItems["課程", "資料統計"]["報表"]["ESL報表"]["進步名單"].Click += delegate
            {
                List <string> eslCouseList = K12.Presentation.NLDPanels.Course.SelectedSource.ToList();

                Form.PrintESLAwardProgressScoreReportForm printform = new Form.PrintESLAwardProgressScoreReportForm(eslCouseList);

                printform.ShowDialog();
            };


            Catalog ribbon9 = RoleAclSource.Instance["課程"]["ESL課程"];

            ribbon4.Add(new RibbonFeature("DA908268-F1E6-4514-B69D-386EC37184A9", "缺考成績處理(指定比例)"));

            MotherForm.RibbonBarItems["課程", "ESL課程"]["缺考成績處理(指定比例)"].Enable = false;

            K12.Presentation.NLDPanels.Course.SelectedSourceChanged += (sender, e) =>
            {
                // 一次只能選一個 課程 補輸入 轉班生成績
                if (K12.Presentation.NLDPanels.Course.SelectedSource.Count > 0 & K12.Presentation.NLDPanels.Course.SelectedSource.Count < 2)
                {
                    MotherForm.RibbonBarItems["課程", "ESL課程"]["缺考成績處理(指定比例)"].Enable = UserAcl.Current["DA908268-F1E6-4514-B69D-386EC37184A9"].Executable;
                }
                else
                {
                    MotherForm.RibbonBarItems["課程", "ESL課程"]["缺考成績處理(指定比例)"].Enable = false;
                }
            };

            MotherForm.RibbonBarItems["課程", "ESL課程"]["缺考成績處理(指定比例)"].Image = Properties.Resources.calc_64;
            MotherForm.RibbonBarItems["課程", "ESL課程"]["缺考成績處理(指定比例)"].Size  = RibbonBarButton.MenuButtonSize.Medium;

            MotherForm.RibbonBarItems["課程", "ESL課程"]["缺考成績處理(指定比例)"].Click += delegate
            {
                List <string> eslCouseIDList = K12.Presentation.NLDPanels.Course.SelectedSource;

                Form.ESLTransferStudentSelectForm form = new Form.ESLTransferStudentSelectForm(eslCouseIDList);

                form.ShowDialog();
            };


            //課程基本資訊 (課程難度(Level)、上課地點)
            // 此外掛方式,會讓只有 加掛 ESL 模組學校  才可以在 課程上 有 課程難度(Level)、上課地點 兩個欄位可以編輯
            K12.Presentation.NLDPanels.Course.AddDetailBulider(new FISCA.Presentation.DetailBulider <CourseExtendControls.BasicInfoItem>());


            Catalog ribbon10 = RoleAclSource.Instance["學生"]["報表"];

            ribbon10.Add(new RibbonFeature("1C26A90B-DD2E-4298-A6D8-35C7E3C8EC7D", "WeeklyReport報表"));

            MotherForm.RibbonBarItems["學生", "資料統計"]["報表"]["ESL報表"]["WeeklyReport報表"].Enable = UserAcl.Current["1C26A90B-DD2E-4298-A6D8-35C7E3C8EC7D"].Executable && K12.Presentation.NLDPanels.Student.SelectedSource.Count > 0;

            K12.Presentation.NLDPanels.Student.SelectedSourceChanged += delegate
            {
                MotherForm.RibbonBarItems["學生", "資料統計"]["報表"]["ESL報表"]["WeeklyReport報表"].Enable = UserAcl.Current["1C26A90B-DD2E-4298-A6D8-35C7E3C8EC7D"].Executable && (K12.Presentation.NLDPanels.Student.SelectedSource.Count > 0);
            };


            MotherForm.RibbonBarItems["學生", "資料統計"]["報表"]["ESL報表"]["WeeklyReport報表"].Click += delegate
            {
                Form.PrintWeeklyReportForm form = new Form.PrintWeeklyReportForm();

                form.ShowDialog();
            };
        }
Exemple #22
0
        // 列印
        private void btnPrint_Click_1(object s, EventArgs ea)
        {
            if (comboBox_ChooseSchoolYear.SelectedItem == null)
            {
                // 請使用者一定要選擇學年度,否則系統會當機
                MsgBox.Show("請先選擇學年度");
            }
            else
            {
                string schoolYear = comboBox_ChooseSchoolYear.Text;
                string returnDate = textBoxHandInDay.Text;
                string printDate  = DateTime.Today.ToShortDateString();

                BackgroundWorker BGW = new BackgroundWorker();
                BGW.WorkerReportsProgress = true;

                BGW.DoWork += delegate(object sender, DoWorkEventArgs e)
                {
                    #region DoWork
                    FISCA.UDT.AccessHelper accessHelper = new FISCA.UDT.AccessHelper();

                    Aspose.Words.Document Template;
                    Template = new Aspose.Words.Document(new MemoryStream(Properties.Resources.班級體適能確認單範本1));
                    // 取得選取班級
                    List <ClassRecord> ClassList = K12.Data.Class.SelectByIDs(K12.Presentation.NLDPanels.Class.SelectedSource);
                    Dictionary <string, StudentFitnessRecord> dicStudentFitnessRecord = new Dictionary <string, StudentFitnessRecord>();
                    var studentIDList = new List <string>();
                    foreach (ClassRecord classrecord in ClassList)
                    {
                        foreach (var studentRec in classrecord.Students)
                        {
                            studentIDList.Add(studentRec.ID);
                        }
                    }
                    BGW.ReportProgress(10);

                    var studentFitnessRecordList = accessHelper.Select <StudentFitnessRecord>(string.Format("ref_student_id in ('{0}') AND school_year = {1}", string.Join("','", studentIDList), schoolYear));

                    foreach (var fitnessRec in studentFitnessRecordList)
                    {
                        //2021/3/16 -  如果沒有新增,避免爆掉
                        //- By Dylan
                        if (!dicStudentFitnessRecord.ContainsKey(fitnessRec.StudentID))
                        {
                            dicStudentFitnessRecord.Add(fitnessRec.StudentID, fitnessRec);
                        }
                        else
                        {
                            StudentRecord stud = K12.Data.Student.SelectByID(fitnessRec.StudentID);
                            MsgBox.Show(string.Format("學生「{0}」體適能資料重複\n(一學年僅會有一筆體適能紀錄)", stud.Name));
                        }
                    }

                    BGW.ReportProgress(20);

                    //填資料部份
                    DataTable table = new DataTable();
                    table.Columns.Add("製表日期");
                    table.Columns.Add("學年");
                    table.Columns.Add("學期");
                    table.Columns.Add("班級");
                    table.Columns.Add("導師");
                    table.Columns.Add("繳回日期");


                    int classIndex = 0;
                    foreach (ClassRecord classRec in ClassList)
                    {
                        DataRow row = table.NewRow();
                        row["學年"] = schoolYear;

                        row["班級"] = classRec.Name;

                        if (classRec.Teacher != null)
                        {
                            row["導師"] = classRec.Teacher.Name;
                        }
                        //  取得視窗輸入的繳回日期
                        row["繳回日期"] = returnDate;

                        row["製表日期"] = printDate;

                        int studentCounter = 0;

                        foreach (StudentRecord studentRec in classRec.Students)
                        {
                            //2016/11/11 穎驊更正,限制抓取"一般"狀態的學生,要不然會在同一班 抓到畢業、休學、刪除的學生資料
                            if (studentRec.Status == StudentRecord.StudentStatus.一般)
                            {
                                string col = "";

                                col = string.Format("姓名{0}", studentCounter);
                                if (!table.Columns.Contains(col))
                                {
                                    table.Columns.Add(col);
                                }
                                row[col] = studentRec.Name;

                                col = string.Format("座號{0}", studentCounter);
                                if (!table.Columns.Contains(col))
                                {
                                    table.Columns.Add(col);
                                }
                                row[col] = studentRec.SeatNo;

                                if (dicStudentFitnessRecord.ContainsKey(studentRec.ID))
                                {
                                    col = string.Format("測驗日期{0}", studentCounter);
                                    if (!table.Columns.Contains(col))
                                    {
                                        table.Columns.Add(col);
                                    }
                                    row[col] = dicStudentFitnessRecord[studentRec.ID].TestDate.ToShortDateString();

                                    col = string.Format("身高{0}", studentCounter);
                                    if (!table.Columns.Contains(col))
                                    {
                                        table.Columns.Add(col);
                                    }
                                    row[col] = dicStudentFitnessRecord[studentRec.ID].Height;

                                    col = string.Format("體重{0}", studentCounter);
                                    if (!table.Columns.Contains(col))
                                    {
                                        table.Columns.Add(col);
                                    }
                                    row[col] = dicStudentFitnessRecord[studentRec.ID].Weight;

                                    col = string.Format("坐姿體前彎{0}", studentCounter);
                                    if (!table.Columns.Contains(col))
                                    {
                                        table.Columns.Add(col);
                                    }
                                    row[col] = dicStudentFitnessRecord[studentRec.ID].SitAndReach;

                                    col = string.Format("坐姿體前彎常模{0}", studentCounter);
                                    if (!table.Columns.Contains(col))
                                    {
                                        table.Columns.Add(col);
                                    }
                                    row[col] = dicStudentFitnessRecord[studentRec.ID].SitAndReachDegree;

                                    col = string.Format("立定跳遠{0}", studentCounter);
                                    if (!table.Columns.Contains(col))
                                    {
                                        table.Columns.Add(col);
                                    }
                                    row[col] = dicStudentFitnessRecord[studentRec.ID].StandingLongJump;

                                    col = string.Format("立定跳遠常模{0}", studentCounter);
                                    if (!table.Columns.Contains(col))
                                    {
                                        table.Columns.Add(col);
                                    }
                                    row[col] = dicStudentFitnessRecord[studentRec.ID].StandingLongJumpDegree;

                                    col = string.Format("仰臥起坐{0}", studentCounter);
                                    if (!table.Columns.Contains(col))
                                    {
                                        table.Columns.Add(col);
                                    }
                                    row[col] = dicStudentFitnessRecord[studentRec.ID].SitUp;

                                    col = string.Format("仰臥起坐常模{0}", studentCounter);
                                    if (!table.Columns.Contains(col))
                                    {
                                        table.Columns.Add(col);
                                    }
                                    row[col] = dicStudentFitnessRecord[studentRec.ID].SitUpDegree;

                                    col = string.Format("心肺適能{0}", studentCounter);
                                    if (!table.Columns.Contains(col))
                                    {
                                        table.Columns.Add(col);
                                    }
                                    row[col] = dicStudentFitnessRecord[studentRec.ID].Cardiorespiratory;

                                    col = string.Format("心肺適能常模{0}", studentCounter);
                                    if (!table.Columns.Contains(col))
                                    {
                                        table.Columns.Add(col);
                                    }
                                    row[col] = dicStudentFitnessRecord[studentRec.ID].CardiorespiratoryDegree;
                                }

                                studentCounter++;

                                //2016/11/11 光棍節,穎驊新增,由於目前Word樣板只支援38個學生,當班級學生數量將會有印不下的問題,
                                //因此 將第39位後的學生資料,印在第二頁、第三頁...
                                if (studentCounter >= 38)
                                {
                                    studentCounter = 0;
                                    table.Rows.Add(row);

                                    row = table.NewRow();

                                    row["學年"] = schoolYear;

                                    row["班級"] = classRec.Name;

                                    if (classRec.Teacher != null)
                                    {
                                        row["導師"] = classRec.Teacher.Name;
                                    }
                                    //  取得視窗輸入的繳回日期
                                    row["繳回日期"] = returnDate;

                                    row["製表日期"] = printDate;
                                }
                            }
                        }
                        // 一個row 一班
                        if (studentCounter != 0)
                        {
                            table.Rows.Add(row);
                        }

                        classIndex++;
                        BGW.ReportProgress(20 + classIndex * 80 / ClassList.Count);
                    }

                    #region 自動生成功變數代碼(開發用很方便,平常註解掉)

                    // 雖然已經講過了,但穎驊不得不大力推薦,這~真~的~超~級~好~用~的!!! 原本自己手動改,三個小時還不一全部改得完、正確,
                    // 用程式自動產生功能變數mailmerge名稱後,十分鐘內就完成&確認檢查完畢了


                    //Document doc = new Document();
                    //DocumentBuilder bu = new DocumentBuilder(doc);
                    //bu.MoveToDocumentStart();
                    //bu.CellFormat.Borders.LineStyle = LineStyle.Single;
                    //bu.CellFormat.VerticalAlignment = CellVerticalAlignment.Center;
                    //Table table1 = bu.StartTable();

                    //List<string> fitnessItem = new List<string>();

                    //fitnessItem.Add("座號");
                    //fitnessItem.Add("姓名");
                    //fitnessItem.Add("測驗日期");
                    //fitnessItem.Add("身高");
                    //fitnessItem.Add("體重");
                    //fitnessItem.Add("坐姿體前彎");
                    //fitnessItem.Add("坐姿體前彎常模");
                    //fitnessItem.Add("立定跳遠");
                    //fitnessItem.Add("立定跳遠常模");
                    //fitnessItem.Add("仰臥起坐");
                    //fitnessItem.Add("仰臥起坐常模");
                    //fitnessItem.Add("心肺適能");
                    //fitnessItem.Add("心肺適能常模");

                    //    foreach (String item in fitnessItem)
                    //    {
                    //        for (int fitnessCounter = 0; fitnessCounter < 40; fitnessCounter++)
                    //        {
                    //        bu.InsertCell();
                    //        bu.CellFormat.Width = 15;
                    //        bu.InsertField("MERGEFIELD " + item + fitnessCounter + @" \* MERGEFORMAT", "«»");
                    //        bu.ParagraphFormat.Alignment = ParagraphAlignment.Center;
                    //        bu.InsertCell();
                    //        bu.CellFormat.Width = 125;
                    //        bu.Write(item + fitnessCounter);
                    //        bu.ParagraphFormat.Alignment = ParagraphAlignment.Left;
                    //        bu.EndRow();

                    //    }

                    //}
                    //    table1.AllowAutoFit = false;
                    //bu.EndTable();
                    //Document PageOne = (Document)Template.Clone(true);
                    //PageOne = doc;

                    # endregion

                    Document PageOne = (Document)Template.Clone(true);
                    PageOne.MailMerge.Execute(table);
                    PageOne.MailMerge.DeleteFields();


                    e.Result = PageOne;
                    #endregion
                };

                BGW.ProgressChanged += delegate(object sender, ProgressChangedEventArgs e)
                {
                    FISCA.Presentation.MotherForm.SetStatusBarMessage("班級體適能通知單產生中...", e.ProgressPercentage);
                };

                BGW.RunWorkerCompleted += delegate(object sender, RunWorkerCompletedEventArgs e)
                {
                    #region RunWorkerCompleted
                    if (e.Cancelled)
                    {
                        MsgBox.Show("作業已被中止!!");
                    }
                    else
                    {
                        if (e.Error == null)
                        {
                            Document inResult = (Document)e.Result;

                            try
                            {
                                SaveFileDialog SaveFileDialog1 = new SaveFileDialog();

                                SaveFileDialog1.Filter   = "Word (*.docx)|*.docx|所有檔案 (*.*)|*.*";
                                SaveFileDialog1.FileName = "班級體適能通知單";

                                if (SaveFileDialog1.ShowDialog() == DialogResult.OK)
                                {
                                    inResult.Save(SaveFileDialog1.FileName);
                                    Process.Start(SaveFileDialog1.FileName);
                                }
                                else
                                {
                                    FISCA.Presentation.Controls.MsgBox.Show("檔案未儲存");
                                    return;
                                }
                            }
                            catch
                            {
                                FISCA.Presentation.Controls.MsgBox.Show("檔案儲存錯誤,請檢查檔案是否開啟中!!");
                                return;
                            }

                            FISCA.Presentation.MotherForm.SetStatusBarMessage("班級體適能通知單產生完成", 100);
                        }
                        else
                        {
                            MsgBox.Show("列印資料發生錯誤\n" + e.Error.Message);
                        }
                    }
                    #endregion
                };

                FISCA.Presentation.MotherForm.SetStatusBarMessage("班級體適能通知單產生中...", 0);

                BGW.RunWorkerAsync();
                this.Close();
            }
        public static void AddMenuButton()
        {
            var ribbonBarItem = K12.Presentation.NLDPanels.Course.RibbonBarItems["課程行事曆"];

            Catalog button_syncCalendar = RoleAclSource.Instance["課程"]["功能按鈕"];
            button_syncCalendar.Add(new RibbonFeature("Reset_Course_Calendar", "重置課程行事曆"));
            bool isEnabled = UserAcl.Current["Reset_Course_Calendar"].Executable;
            var btn = ribbonBarItem["重置課程行事曆"];
            if (isEnabled)
            {
                ribbonBarItem["重置課程行事曆"].Click += delegate
                {
                    if (System.Windows.Forms.MessageBox.Show("將會清空行事例曆中所有資料,\n以及系統內課程同步狀態。\n\nPS.不會影響輸入的上課時間資料。", "重置課程行事曆", System.Windows.Forms.MessageBoxButtons.OKCancel, System.Windows.Forms.MessageBoxIcon.Warning) == System.Windows.Forms.DialogResult.OK)
                    {
                        System.ComponentModel.BackgroundWorker bkw = new System.ComponentModel.BackgroundWorker();
                        bkw.WorkerReportsProgress = true;
                        bkw.RunWorkerCompleted += delegate
                        {
                            FISCA.Presentation.MotherForm.SetStatusBarMessage("重置課程行事曆完成。", 100);
                            System.Windows.Forms.MessageBox.Show("課程行事曆已重置,\n請上google calendar檢查,\n如有殘留資料請再執行此功能。");
                        };
                        bkw.ProgressChanged += delegate(object sender, System.ComponentModel.ProgressChangedEventArgs e)
                        {
                            FISCA.Presentation.MotherForm.SetStatusBarMessage("重置課程行事曆...", e.ProgressPercentage);
                        };
                        bkw.DoWork += delegate
                        {
                            bkw.ReportProgress(1);
                            var accessHelper = new FISCA.UDT.AccessHelper();
                            var l1 = accessHelper.Select<Section>();
                            foreach (Section section in l1)
                            {
                                section.IsPublished = false;
                            }
                            l1.SaveAll();
                            bkw.ReportProgress(5);
                            var l2 = accessHelper.Select<Calendar>();
                            foreach (Calendar cal in l2)
                            {
                                cal.Deleted = true;
                            }
                            l2.SaveAll();
                            bkw.ReportProgress(10);
                            #region 清空行事曆
                            CalendarService myService = new CalendarService("ischool.CourseCalendar");
                            myService.setUserCredentials(googleAcc, googlePWD);
                            CalendarQuery cq = new CalendarQuery();
                            cq.Uri = new Uri("http://www.google.com/calendar/feeds/default/owncalendars/full");
                            CalendarFeed resultFeed = myService.Query(cq);
                            foreach (CalendarEntry entry in resultFeed.Entries)
                            {
                                String calendarURI = entry.Id.Uri.ToString();
                                String calendarID = calendarURI.Substring(calendarURI.LastIndexOf("/") + 1);
                                clearAndDeleteCalender(calendarID);
                            }
                            bkw.ReportProgress(55);
                            deleteAllEvent("default");
                            #endregion
                            bkw.ReportProgress(100);
                        };
                        bkw.RunWorkerAsync();
                    }
                };
            }
            else
            {
                btn.Enable = false;
            }
        }
        private void buttonX1_Click(object s, EventArgs ea)
        {
            string schoolYear = comboBox_ChooseSchoolYear.Text;

            List <String> Error_List = new List <string>();

            BackgroundWorker BGW = new BackgroundWorker();

            BGW.WorkerReportsProgress = true;

            #region 資料處理

            BGW.DoWork += delegate(object sender, DoWorkEventArgs e)
            {
                BGW.ReportProgress(5);

                // 為列印Excel 先New 物件,注意下行方法只能參考新的 Aspose.Cell_201402,如果用舊的話會有錯誤
                Aspose.Cells.Workbook wb = new Aspose.Cells.Workbook(new MemoryStream(Properties.Resources.全校體適能中等以上_含中等_各項目百分比統計表));

                Cells cs0 = wb.Worksheets[0].Cells;

                FISCA.UDT.AccessHelper accessHelper = new FISCA.UDT.AccessHelper();

                //沒任何列印邏輯?? - 先註解掉(by Dylan)
                //Aspose.Words.Document Template;
                //Template = new Aspose.Words.Document(new MemoryStream(Properties.Resources.班級體適能確認單範本1));



                // 存放學生ID 與班級名稱的對照
                Dictionary <string, string> studentID_to_className = new Dictionary <string, string>();

                // 存放學生ID 與學生名稱的對照
                Dictionary <string, string> studentID_to_studentName = new Dictionary <string, string>();

                //目前體適能一共五個等級,分別為金牌、銀牌、銅牌、中等、請加強,下面字典為蒐集每班各體適能項目"請加強"的人數使用
                Dictionary <string, to_be_Improve_counter> dic_class_fitness_to_be_Improve = new Dictionary <string, to_be_Improve_counter>();

                // 計算BGW進度使用
                int progress = 0;

                //統計"全校" 體適能項目 "請加強"人數使用
                to_be_Improve_counter Total_school_to_be_Improve_counter = new to_be_Improve_counter();

                //蒐集全校正常在學有班級學生之全部ID
                var studentIDList = new List <string>();

                //蒐集全校正常在學有班級且有"體適能"資料學生之全部ID ,注意此項與studentIDList不一定永遠一樣
                var studentIDList_fitness = new List <string>();

                var studentRecordList = new List <StudentRecord>();

                #region 取得全校班級,並將全校學生做班級分類

                // 取得選取班級,(不給使用者指定選取了,直接選全校)
                //List<ClassRecord> ClassList = K12.Data.Class.SelectByIDs(K12.Presentation.NLDPanels.Class.SelectedSource);


                studentRecordList = K12.Data.Student.SelectAll();

                foreach (var stuRec in studentRecordList)
                {
                    // 0 = 一般生 ,如此一來可以避免選到畢業班,另外也必須要有班級才行
                    if (stuRec.Status == 0 && stuRec.Class != null)
                    {
                        studentIDList.Add(stuRec.ID);

                        studentID_to_className.Add(stuRec.ID, stuRec.Class.Name);

                        studentID_to_studentName.Add(stuRec.ID, stuRec.Name);

                        if (!dic_class_fitness_to_be_Improve.ContainsKey(stuRec.Class.Name))
                        {
                            dic_class_fitness_to_be_Improve.Add(stuRec.Class.Name, new to_be_Improve_counter());
                        }
                    }
                }


                // 穎驊筆記,下面的方法註解掉,原因是如果直接選取全校班級Class.SelectAll() ,會選到已經畢業的班級,就現階段來說比較麻煩處理,
                //不如像上面直接找尋全部學生再配給他們班級

                //List<ClassRecord> ClassList = K12.Data.Class.SelectAll();
                //foreach (ClassRecord classrecord in ClassList)
                //{
                //    foreach (var studentRec in classrecord.Students)
                //    {
                //        studentIDList.Add(studentRec.ID);

                //        studentID_to_className.Add(studentRec.ID, classrecord.Name);
                //    }

                //    dic_class_fitness_to_be_Improve.Add(classrecord.Name, new to_be_Improve_counter());


                //}


                #endregion

                BGW.ReportProgress(20);

                #region 取得體適能資料並分類

                //取得全學生的體適能資料
                var studentFitnessRecordList = accessHelper.Select <StudentFitnessRecord>(string.Format("ref_student_id in ('{0}') AND school_year = {1}", string.Join("','", studentIDList), schoolYear));

                // 把各學生的體適能資料和班級做集合整理
                foreach (var fitnessRec in studentFitnessRecordList)
                {
                    //蒐集全校正常在學有班級且有"體適能"資料學生之全部ID ,注意此項與studentIDList不一定永遠一樣,因為很有可能有在studentIDList的學生卻沒有體適能資料,
                    //自然在取得全學生體適能資料studentFitnessRecordList就不會出現,但我們又必須要將沒有資料的人視為"缺考"、"零分"、"待加強",所以要再出一個studentIDList_fitness
                    //之後與studentIDList內的ID做比較,找出其班級,把總人數、待加強人數加上去

                    studentIDList_fitness.Add(fitnessRec.StudentID);

                    // 計算坐姿體前彎各班待加強人數

                    if (fitnessRec.SitAndReachDegree == "請加強")
                    {
                        dic_class_fitness_to_be_Improve[studentID_to_className[fitnessRec.StudentID]].SitAndReachDegree_failed_counter++;
                        dic_class_fitness_to_be_Improve[studentID_to_className[fitnessRec.StudentID]].SitAndReachDegree_total++;
                    }
                    // 用來處理假如該學生沒有常模的狀況,此時不能將之算入不及格或是總母群內,另存錯誤提醒視窗

                    //2016/7/21 修正,因為實際拿各個學校資料測試,發現其實真實學校資料都缺蠻多的,會造成錯誤提醒視窗一大包
                    //恩正說學生沒有體適能資料、沒有體適能常模,不是我們的責任,是各個學校應該要自己負責,所以資料不齊者視為"0分"、"缺考"、"不及格"
                    else if (fitnessRec.SitAndReachDegree == "")
                    {
                        Error_List.Add("班級:" + studentID_to_className[fitnessRec.StudentID] + "," + "學生:" + studentID_to_studentName[fitnessRec.StudentID] + "沒有坐姿體前彎常模資料,將不會納入計算,請確認是否忘記常模計算");

                        //缺體適能常模資料,就當你不合格要"請加強"
                        dic_class_fitness_to_be_Improve[studentID_to_className[fitnessRec.StudentID]].SitAndReachDegree_failed_counter++;
                        dic_class_fitness_to_be_Improve[studentID_to_className[fitnessRec.StudentID]].SitAndReachDegree_total++;
                    }
                    else
                    {
                        dic_class_fitness_to_be_Improve[studentID_to_className[fitnessRec.StudentID]].SitAndReachDegree_total++;
                    }

                    // 計算立定跳遠各班待加強人數

                    if (fitnessRec.StandingLongJumpDegree == "請加強")
                    {
                        dic_class_fitness_to_be_Improve[studentID_to_className[fitnessRec.StudentID]].StandingLongJumpDegree_failed_counter++;
                        dic_class_fitness_to_be_Improve[studentID_to_className[fitnessRec.StudentID]].StandingLongJumpDegree_total++;
                    }
                    // 用來處理假如該學生沒有常模的狀況,此時不能將之算入不及格或是總母群內,另存錯誤提醒視窗

                    //2016/7/21 修正,因為實際拿各個學校資料測試,發現其實真實學校資料都缺蠻多的,會造成錯誤提醒視窗一大包
                    //恩正說學生沒有體適能資料、沒有體適能常模,不是我們的責任,是各個學校應該要自己負責,所以資料不齊者視為"0分"、"缺考"、"不及格"
                    else if (fitnessRec.StandingLongJumpDegree == "")
                    {
                        Error_List.Add("班級:" + studentID_to_className[fitnessRec.StudentID] + "," + "學生:" + studentID_to_studentName[fitnessRec.StudentID] + "沒有立定跳遠常模資料,將不會納入計算,請確認是否忘記常模計算");

                        //缺體適能常模資料,就當你不合格要"請加強"
                        dic_class_fitness_to_be_Improve[studentID_to_className[fitnessRec.StudentID]].StandingLongJumpDegree_failed_counter++;
                        dic_class_fitness_to_be_Improve[studentID_to_className[fitnessRec.StudentID]].StandingLongJumpDegree_total++;
                    }
                    else
                    {
                        dic_class_fitness_to_be_Improve[studentID_to_className[fitnessRec.StudentID]].StandingLongJumpDegree_total++;
                    }


                    // 計算坐仰臥起坐各班待加強人數

                    if (fitnessRec.SitUpDegree == "請加強")
                    {
                        dic_class_fitness_to_be_Improve[studentID_to_className[fitnessRec.StudentID]].SitUpDegree_failed_counter++;
                        dic_class_fitness_to_be_Improve[studentID_to_className[fitnessRec.StudentID]].SitUpDegree_total++;
                    }
                    // 用來處理假如該學生沒有常模的狀況,此時不能將之算入不及格或是總母群內,另存錯誤提醒視窗

                    //2016/7/21 修正,因為實際拿各個學校資料測試,發現其實真實學校資料都缺蠻多的,會造成錯誤提醒視窗一大包
                    //恩正說學生沒有體適能資料、沒有體適能常模,不是我們的責任,是各個學校應該要自己負責,所以資料不齊者視為"0分"、"缺考"、"不及格"
                    else if (fitnessRec.SitUpDegree == "")
                    {
                        Error_List.Add("班級:" + studentID_to_className[fitnessRec.StudentID] + "," + "學生:" + studentID_to_studentName[fitnessRec.StudentID] + "沒有仰臥起坐常模資料,將不會納入計算,請確認是否忘記常模計算");

                        //缺體適能常模資料,就當你不合格要"請加強"
                        dic_class_fitness_to_be_Improve[studentID_to_className[fitnessRec.StudentID]].SitUpDegree_failed_counter++;
                        dic_class_fitness_to_be_Improve[studentID_to_className[fitnessRec.StudentID]].SitUpDegree_total++;
                    }
                    else
                    {
                        dic_class_fitness_to_be_Improve[studentID_to_className[fitnessRec.StudentID]].SitUpDegree_total++;
                    }

                    // 計算心肺適能各班待加強人數

                    if (fitnessRec.CardiorespiratoryDegree == "請加強")
                    {
                        dic_class_fitness_to_be_Improve[studentID_to_className[fitnessRec.StudentID]].CardiorespiratoryDegree_failed_counter++;
                        dic_class_fitness_to_be_Improve[studentID_to_className[fitnessRec.StudentID]].CardiorespiratoryDegree_total++;
                    }
                    // 用來處理假如該學生沒有常模的狀況,此時不能將之算入不及格或是總母群內,另存錯誤提醒視窗

                    //2016/7/21 修正,因為實際拿各個學校資料測試,發現其實真實學校資料都缺蠻多的,會造成錯誤提醒視窗一大包
                    //恩正說學生沒有體適能資料、沒有體適能常模,不是我們的責任,是各個學校應該要自己負責,所以資料不齊者視為"0分"、"缺考"、"不及格"
                    else if (fitnessRec.CardiorespiratoryDegree == "")
                    {
                        Error_List.Add("班級:" + studentID_to_className[fitnessRec.StudentID] + "," + "學生:" + studentID_to_studentName[fitnessRec.StudentID] + "沒有心肺適能常模資料,將不會納入計算,請確認是否忘記常模計算");

                        //缺體適能常模資料,就當你不合格要"請加強"
                        dic_class_fitness_to_be_Improve[studentID_to_className[fitnessRec.StudentID]].CardiorespiratoryDegree_failed_counter++;
                        dic_class_fitness_to_be_Improve[studentID_to_className[fitnessRec.StudentID]].CardiorespiratoryDegree_total++;
                    }
                    else
                    {
                        dic_class_fitness_to_be_Improve[studentID_to_className[fitnessRec.StudentID]].CardiorespiratoryDegree_total++;
                    }

                    //2016/11/11 光棍節,穎驊新增計算班級四個項目(坐姿體前彎、立定跳遠、仰臥起坐、心肺適能)都通過比例(在金牌、銀牌、銅牌、中等、待加強五個評等中至少拿中等)

                    // 四大項目都必須要有常模資料,才會進行計算,否則即使只缺一項資料其他項目都通過,也會將之不算四項目都通過
                    if (fitnessRec.SitAndReachDegree != "" && fitnessRec.StandingLongJumpDegree != "" && fitnessRec.SitUpDegree != "" && fitnessRec.CardiorespiratoryDegree != "")
                    {
                        if (fitnessRec.SitAndReachDegree != "請加強" && fitnessRec.StandingLongJumpDegree != "請加強" && fitnessRec.SitUpDegree != "請加強" && fitnessRec.CardiorespiratoryDegree != "請加強")
                        {
                            dic_class_fitness_to_be_Improve[studentID_to_className[fitnessRec.StudentID]].Four_Item_All_Pass_counter++;
                            dic_class_fitness_to_be_Improve[studentID_to_className[fitnessRec.StudentID]].Four_Item_All_Pass_counter_total++;
                        }
                        else
                        {
                            dic_class_fitness_to_be_Improve[studentID_to_className[fitnessRec.StudentID]].Four_Item_All_Pass_counter_total++;
                        }
                    }
                    else
                    {
                        dic_class_fitness_to_be_Improve[studentID_to_className[fitnessRec.StudentID]].Four_Item_All_Pass_counter_total++;
                    }

                    // 2016/7/22 上一版已在昨天(7/21)早上出去了,今天再做別的東西時發現ReportProgress有點問題,必須要先轉型有浮點數的類型(decimal 、float)算完後,再轉回int
                    //否則 1 / studentFitnessRecordList.Count 一除下來的型別int 可能永遠都是零。由於此功能在實際功能其實沒甚麼影響,先把Code改好,下次等有需求再更新。

                    progress += (int)(((decimal)1 / studentFitnessRecordList.Count) * 60);

                    BGW.ReportProgress(20 + progress);
                }

                //蒐集全校正常在學有班級且有"體適能"資料學生之全部ID ,注意此項與studentIDList不一定永遠一樣,因為很有可能有在studentIDList的學生卻沒有體適能資料,
                //自然在取得全學生體適能資料studentFitnessRecordList就不會出現,但我們又必須要將沒有資料的人視為"缺考"、"零分"、"待加強",所以要再出一個studentIDList_fitness
                //之後與studentIDList內的ID做比較,找出其班級,把總人數、待加強人數加上去

                // 全校身份一般、有班級的學生
                foreach (var stuID in studentIDList)
                {
                    //卻沒有體適能資料的話,就在該班把每一個項目總人數、待加強人數給加上去
                    if (!studentIDList_fitness.Contains(stuID))

                    {
                        dic_class_fitness_to_be_Improve[studentID_to_className[stuID]].SitAndReachDegree_failed_counter++;
                        dic_class_fitness_to_be_Improve[studentID_to_className[stuID]].SitAndReachDegree_total++;

                        dic_class_fitness_to_be_Improve[studentID_to_className[stuID]].StandingLongJumpDegree_failed_counter++;
                        dic_class_fitness_to_be_Improve[studentID_to_className[stuID]].StandingLongJumpDegree_total++;

                        dic_class_fitness_to_be_Improve[studentID_to_className[stuID]].SitUpDegree_failed_counter++;
                        dic_class_fitness_to_be_Improve[studentID_to_className[stuID]].SitUpDegree_total++;


                        dic_class_fitness_to_be_Improve[studentID_to_className[stuID]].CardiorespiratoryDegree_failed_counter++;
                        dic_class_fitness_to_be_Improve[studentID_to_className[stuID]].CardiorespiratoryDegree_total++;


                        //沒有體適能資料,視為沒通過,在四項全過統計直接加分母總人數就好。
                        dic_class_fitness_to_be_Improve[studentID_to_className[stuID]].Four_Item_All_Pass_counter_total++;

                        Error_List.Add("班級:" + studentID_to_className[stuID] + "," + "學生:" + studentID_to_studentName[stuID] + "沒有體適能資料 請確認是否忘記輸入");
                    }
                }



                #endregion

                BGW.ReportProgress(80);

                #region 報表填值

                cs0[0, 0].Value = schoolYear + "學年度中等以上(含中等)各項目百分比統計表";

                int RowCounter = 3;

                int ColCounter = 0;

                int endRow = dic_class_fitness_to_be_Improve.Count + 3;

                //看看全資料有沒有錯誤,如果有錯,全校的百分比將不計算,而顯示錯誤
                //2016/7/21 因應恩正所說,我們其實不太需要為殘破的資料負責任,所以這個Bool 會暫時用不到
                bool DataBroken = false;

                Workbook template = new Workbook();

                template = new Aspose.Cells.Workbook(new MemoryStream(Properties.Resources.全校體適能中等以上_含中等_各項目百分比統計表_程式用樣版_));

                // 固定複製另一份的樣板,最後一行"全校"的那一行,這樣不論班級有多少,最後一行都會是全校
                cs0.CopyRow(template.Worksheets[0].Cells, 12, endRow);


                foreach (var item in dic_class_fitness_to_be_Improve)
                {
                    cs0.CopyRow(template.Worksheets[0].Cells, 3, RowCounter);

                    // 第一欄填班級
                    cs0[RowCounter, ColCounter].Value = item.Key;

                    // 第二欄坐姿體前彎,且分母總數不可為0
                    if (item.Value.SitAndReachDegree_total != 0)
                    {
                        cs0[RowCounter, ColCounter + 1].Value = Math.Round((100 - (item.Value.SitAndReachDegree_failed_counter / item.Value.SitAndReachDegree_total) * 100), 0, MidpointRounding.AwayFromZero) + "%";


                        Total_school_to_be_Improve_counter.SitAndReachDegree_failed_counter += item.Value.SitAndReachDegree_failed_counter;

                        Total_school_to_be_Improve_counter.SitAndReachDegree_total += item.Value.SitAndReachDegree_total;
                    }
                    else
                    {
                        Error_List.Add("班級:" + item.Key + "全班無同學有坐姿體前彎體適能紀錄常模,將造成計算百分比錯誤,請檢查是否忘記常模計算,或是該班同學都沒有體適能資料");

                        // 下行為舊的處理方式。
                        //cs0[RowCounter, ColCounter + 1].Value = "無資料";

                        //新的處理方式,全班數不到人直接0%
                        cs0[RowCounter, ColCounter + 1].Value = "0%";

                        DataBroken = true;
                    }

                    // 第三欄填立定跳遠,且分母總數不可為0
                    if (item.Value.StandingLongJumpDegree_total != 0)
                    {
                        cs0[RowCounter, ColCounter + 2].Value = Math.Round((100 - (item.Value.StandingLongJumpDegree_failed_counter / item.Value.StandingLongJumpDegree_total) * 100), 0, MidpointRounding.AwayFromZero) + "%";

                        Total_school_to_be_Improve_counter.StandingLongJumpDegree_failed_counter += item.Value.StandingLongJumpDegree_failed_counter;

                        Total_school_to_be_Improve_counter.StandingLongJumpDegree_total += item.Value.StandingLongJumpDegree_total;
                    }
                    else
                    {
                        Error_List.Add("班級:" + item.Key + "全班無同學有立定跳遠體適能紀錄常模,將造成計算百分比錯誤,請檢查是否忘記常模計算,或是該班同學都沒有體適能資料");


                        // 下行為舊的處理方式。
                        //cs0[RowCounter, ColCounter + 2].Value = "無資料";

                        //新的處理方式,全班數不到人直接0%
                        cs0[RowCounter, ColCounter + 2].Value = "0%";

                        DataBroken = true;
                    }


                    // 第四欄填仰臥起坐,且分母總數不可為0
                    if (item.Value.SitUpDegree_total != 0)
                    {
                        cs0[RowCounter, ColCounter + 3].Value = Math.Round((100 - (item.Value.SitUpDegree_failed_counter / item.Value.SitUpDegree_total) * 100), 0, MidpointRounding.AwayFromZero) + "%";


                        Total_school_to_be_Improve_counter.SitUpDegree_failed_counter += item.Value.SitUpDegree_failed_counter;

                        Total_school_to_be_Improve_counter.SitUpDegree_total += item.Value.SitUpDegree_total;
                    }
                    else
                    {
                        Error_List.Add("班級:" + item.Key + "全班無同學有仰臥起坐體適能紀錄常模,將造成計算百分比錯誤,請檢查是否忘記常模計算,或是該班同學都沒有體適能資料");


                        // 下行為舊的處理方式。
                        //cs0[RowCounter, ColCounter + 3].Value = "無資料";

                        //新的處理方式,全班數不到人直接0%
                        cs0[RowCounter, ColCounter + 3].Value = "0%";

                        DataBroken = true;
                    }


                    // 第五欄填心肺適能,且分母總數不可為0
                    if (item.Value.CardiorespiratoryDegree_total != 0)
                    {
                        cs0[RowCounter, ColCounter + 4].Value = Math.Round((100 - (item.Value.CardiorespiratoryDegree_failed_counter / item.Value.CardiorespiratoryDegree_total) * 100), 0, MidpointRounding.AwayFromZero) + "%";


                        Total_school_to_be_Improve_counter.CardiorespiratoryDegree_failed_counter += item.Value.CardiorespiratoryDegree_failed_counter;

                        Total_school_to_be_Improve_counter.CardiorespiratoryDegree_total += item.Value.CardiorespiratoryDegree_total;
                    }

                    else
                    {
                        Error_List.Add("班級:" + item.Key + "全班無同學有心肺體適能紀錄常模,將造成計算百分比錯誤,請檢查是否忘記常模計算,或是該班同學都沒有體適能資料");


                        // 下行為舊的處理方式。
                        //cs0[RowCounter, ColCounter + 4].Value = "無資料";



                        //新的處理方式,全班數不到人直接0%
                        cs0[RowCounter, ColCounter + 4].Value = "0%";



                        DataBroken = true;
                    }

                    //2016/11/11 光棍節,穎驊新增   第六欄填四項皆通過人數百分比統計,且分母總數不可為0
                    if (item.Value.Four_Item_All_Pass_counter_total != 0)
                    {
                        cs0[RowCounter, ColCounter + 5].Value = Math.Round((item.Value.Four_Item_All_Pass_counter / item.Value.Four_Item_All_Pass_counter_total) * 100, 0, MidpointRounding.AwayFromZero) + "%";


                        Total_school_to_be_Improve_counter.Four_Item_All_Pass_counter += item.Value.Four_Item_All_Pass_counter;

                        Total_school_to_be_Improve_counter.Four_Item_All_Pass_counter_total += item.Value.Four_Item_All_Pass_counter_total;
                    }


                    RowCounter++;
                }

                cs0[endRow, ColCounter + 1].Value = Math.Round((100 - (Total_school_to_be_Improve_counter.SitAndReachDegree_failed_counter / Total_school_to_be_Improve_counter.SitAndReachDegree_total) * 100), 0, MidpointRounding.AwayFromZero) + "%";

                cs0[endRow, ColCounter + 2].Value = Math.Round((100 - (Total_school_to_be_Improve_counter.StandingLongJumpDegree_failed_counter / Total_school_to_be_Improve_counter.StandingLongJumpDegree_total) * 100), 0, MidpointRounding.AwayFromZero) + "%";

                cs0[endRow, ColCounter + 3].Value = Math.Round((100 - (Total_school_to_be_Improve_counter.SitUpDegree_failed_counter / Total_school_to_be_Improve_counter.SitUpDegree_total) * 100), 0, MidpointRounding.AwayFromZero) + "%";

                cs0[endRow, ColCounter + 4].Value = Math.Round((100 - (Total_school_to_be_Improve_counter.CardiorespiratoryDegree_failed_counter / Total_school_to_be_Improve_counter.CardiorespiratoryDegree_total) * 100), 0, MidpointRounding.AwayFromZero) + "%";


                //新增全校四項通過百分比
                cs0[endRow, ColCounter + 5].Value = Math.Round((Total_school_to_be_Improve_counter.Four_Item_All_Pass_counter / Total_school_to_be_Improve_counter.Four_Item_All_Pass_counter_total * 100), 0, MidpointRounding.AwayFromZero) + "%";



                // 下行為舊的處理方式。
                //if (!DataBroken == true)
                //{
                //    cs0[endRow, ColCounter + 1].Value = Math.Round((100 - (Total_school_to_be_Improve_counter.SitAndReachDegree_failed_counter / Total_school_to_be_Improve_counter.SitAndReachDegree_total) * 100), 0, MidpointRounding.AwayFromZero) + "%";

                //    cs0[endRow, ColCounter + 2].Value = Math.Round((100 - (Total_school_to_be_Improve_counter.StandingLongJumpDegree_failed_counter / Total_school_to_be_Improve_counter.StandingLongJumpDegree_total) * 100), 0, MidpointRounding.AwayFromZero) + "%";

                //    cs0[endRow, ColCounter + 3].Value = Math.Round((100 - (Total_school_to_be_Improve_counter.SitUpDegree_failed_counter / Total_school_to_be_Improve_counter.SitUpDegree_total) * 100), 0, MidpointRounding.AwayFromZero) + "%";

                //    cs0[endRow, ColCounter + 4].Value = Math.Round((100 - (Total_school_to_be_Improve_counter.CardiorespiratoryDegree_failed_counter / Total_school_to_be_Improve_counter.CardiorespiratoryDegree_total) * 100), 0, MidpointRounding.AwayFromZero) + "%";

                //}
                //else
                //{

                //    cs0[endRow, ColCounter + 1].Value = "無法計算";

                //    cs0[endRow, ColCounter + 2].Value = "無法計算";

                //    cs0[endRow, ColCounter + 3].Value = "無法計算";

                //    cs0[endRow, ColCounter + 4].Value = "無法計算";

                //}

                #endregion
                e.Result = wb;
                BGW.ReportProgress(100);
            };
            #endregion


            #region 計算DoWork完成百分比

            BGW.ProgressChanged += delegate(object sender, ProgressChangedEventArgs e)
            {
                FISCA.Presentation.MotherForm.SetStatusBarMessage("班級體適能通知單產生中...", e.ProgressPercentage);
            };

            #endregion

            #region 列印存檔

            BGW.RunWorkerCompleted += delegate(object sender, RunWorkerCompletedEventArgs e)
            {
                //2016/7/21 不再顯示錯誤訊息

                // 顯示錯誤訊息
                //if (Error_List.Count > 0)
                //{

                //    StringBuilder sb = new StringBuilder();

                //    foreach (var errorMsg in Error_List)
                //    {
                //        sb.AppendLine(errorMsg);

                //    }

                //    MsgBox.Show(sb.ToString());

                //}

                #region RunWorkerCompleted


                Workbook workbook = e.Result as Workbook;

                if (workbook == null)
                {
                    return;
                }


                // 以後記得存Excel 都用新版的Xlsx,可以避免ㄧ些不必要的問題(EX: sheet 只能到1023張)
                SaveFileDialog save = new SaveFileDialog();
                save.Title    = "另存新檔";
                save.FileName = "全校體適能中等以上(含中等)各項目百分比統計表" + "(" + schoolYear + "學年度" + ")";
                save.Filter   = "Excel檔案 (*.Xlsx)|*.Xlsx|所有檔案 (*.*)|*.*";

                if (save.ShowDialog() == System.Windows.Forms.DialogResult.OK)
                {
                    try
                    {
                        workbook.Save(save.FileName, Aspose.Cells.SaveFormat.Xlsx);
                        System.Diagnostics.Process.Start(save.FileName);
                    }
                    catch
                    {
                        MessageBox.Show("檔案儲存失敗");
                    }
                }
                #endregion
            };

            #endregion

            BGW.RunWorkerAsync();
            this.Close();
        }
Exemple #25
0
        public static void Main()
        {
            FISCA.UDT.AccessHelper _AccessHelper = new FISCA.UDT.AccessHelper();

            _AccessHelper.Select <UDT_ReportTemplate>(); // 先將UDT 選起來,如果是第一次開啟沒有話就會新增

            Catalog ribbon = RoleAclSource.Instance["教務作業"]["功能按鈕"];

            ribbon.Add(new RibbonFeature("ESL評分樣版設定", "ESL評分樣版設定"));

            MotherForm.RibbonBarItems["教務作業", "基本設定"]["設定"]["ESL評分樣版設定"].Enable = UserAcl.Current["ESL評分樣版設定"].Executable;

            MotherForm.RibbonBarItems["教務作業", "基本設定"]["設定"]["ESL評分樣版設定"].Click += delegate
            {
                Form.ESL_TemplateSetupManager form = new Form.ESL_TemplateSetupManager();

                form.ShowDialog();
            };

            Catalog ribbon2 = RoleAclSource.Instance["課程"]["ESL課程"];

            ribbon2.Add(new RibbonFeature("ESL評量分數計算", "評量成績結算"));

            MotherForm.RibbonBarItems["課程", "ESL課程"]["評量成績結算"].Enable = false;

            K12.Presentation.NLDPanels.Course.SelectedSourceChanged += (sender, e) =>
            {
                if (K12.Presentation.NLDPanels.Course.SelectedSource.Count > 0)
                {
                    MotherForm.RibbonBarItems["課程", "ESL課程"]["評量成績結算"].Enable = UserAcl.Current["ESL評量分數計算"].Executable;
                }
                else
                {
                    MotherForm.RibbonBarItems["課程", "ESL課程"]["評量成績結算"].Enable = false;
                }
            };

            MotherForm.RibbonBarItems["課程", "ESL課程"]["評量成績結算"].Image = Properties.Resources.calc_64;
            MotherForm.RibbonBarItems["課程", "ESL課程"]["評量成績結算"].Size  = RibbonBarButton.MenuButtonSize.Medium;

            MotherForm.RibbonBarItems["課程", "ESL課程"]["評量成績結算"].Click += delegate
            {
                Form.CheckCalculateTermForm form = new Form.CheckCalculateTermForm(K12.Presentation.NLDPanels.Course.SelectedSource);

                form.ShowDialog();
            };

            Catalog ribbon3 = RoleAclSource.Instance["課程"]["ESL報表"];

            ribbon3.Add(new RibbonFeature("ESL成績單", "ESL報表"));

            MotherForm.RibbonBarItems["課程", "資料統計"]["報表"]["ESL報表"]["ESL成績單"].Enable = UserAcl.Current["ESL成績單"].Executable && K12.Presentation.NLDPanels.Course.SelectedSource.Count > 0;

            K12.Presentation.NLDPanels.Course.SelectedSourceChanged += delegate
            {
                MotherForm.RibbonBarItems["課程", "資料統計"]["報表"]["ESL報表"]["ESL成績單"].Enable = UserAcl.Current["ESL成績單"].Executable && (K12.Presentation.NLDPanels.Course.SelectedSource.Count > 0);
            };


            MotherForm.RibbonBarItems["課程", "資料統計"]["報表"]["ESL報表"]["ESL成績單"].Click += delegate
            {
                List <string> esl_couse_list = K12.Presentation.NLDPanels.Course.SelectedSource.ToList();

                Form.PrintESLReportForm printform = new Form.PrintESLReportForm(esl_couse_list);

                printform.ShowDialog();
            };
        }
        private void loadTemplate()
        {
            FISCA.UDT.AccessHelper ah = new FISCA.UDT.AccessHelper();
            this.template = ah.Select<UDT_ABCardTemplateDefinitionDef>();
            this.template.Sort(delegate(UDT_ABCardTemplateDefinitionDef t1, UDT_ABCardTemplateDefinitionDef t2)
            {
                return t1.ToString().CompareTo(t2.ToString());
            }
            );
            //MessageBox.Show(this.template.Count.ToString());
            this.comboBoxEx1.Items.Clear();
            this.comboBoxEx1.Items.AddRange(this.template.ToArray());

            if (this.comboBoxEx1.Items.Count > 0)
                this.comboBoxEx1.SelectedIndex = 0;

            //initUI();
        }