Example #1
0
        void BGW_DoWork(object sender, DoWorkEventArgs e)
        {
            //開始列印學生清單
            #region 資料整理

            //取得需連線學校
            LoginSchoolList = tool._A.Select <LoginSchool>();

            // 取得社團老師資料 key : DSNS
            Dictionary <string, ClubTeacher> clubTeacherDic = new Dictionary <string, ClubTeacher>();

            // 2018/01/23 羿均 新增 取得學校相關資料
            SchoolClubDic = tool.SchoolClubDetail(LoginSchoolList);

            foreach (AcrossRecord Across in SchoolClubDic.Values)
            {
                foreach (OnlineClub club in Across.ClubDic.Values)
                {
                    if (!Mergerdic.ContainsKey(club.ClubName))
                    {
                        OnlineMergerClub Mclub = new OnlineMergerClub(tool.Point);
                        Mergerdic.Add(club.ClubName, Mclub);
                        Mclub.AddClub(club);
                    }
                    Mergerdic[club.ClubName].AddClub(club);
                }
            }

            //選擇了哪些社團(使用名稱進行比對)
            List <string>     ClubIDList     = K12.Club.Volunteer.ClubAdmin.Instance.SelectedSource;
            List <CLUBRecord> ClubRecordList = tool._A.Select <CLUBRecord>(ClubIDList);

            //社團名稱清單
            List <string> ClubNameList = new List <string>();
            foreach (CLUBRecord club in ClubRecordList)
            {
                ClubNameList.Add(club.ClubName);
            }

            //社團名稱 + 社團參與記錄學生
            Dictionary <string, List <OnlineSCJoin> > dic = new Dictionary <string, List <OnlineSCJoin> >();
            List <string> ClubNewNameList = new List <string>();
            foreach (LoginSchool school in LoginSchoolList)
            {
                schoolMark = school.Remark;
                Connection me = new Connection();
                me.Connect(school.School_Name, tool._contract, FISCA.Authentication.DSAServices.PassportToken);
                Dictionary <string, OnlineSCJoin> ScjList = RunService.GetSCJoinByClubName(me, ClubNameList);

                foreach (OnlineSCJoin each in ScjList.Values)
                {
                    // 2018/01/24 羿均 紀錄:主要連線學校社團老師
                    if (school.School_Name == tool.Point)
                    {
                        if (!clubTeacherDic.ContainsKey(school.School_Name))
                        {
                            ClubTeacher ct = new ClubTeacher();
                            ct.SchoolName = school.School_Name;
                            ct.Teacher1   = each.TeacherName;
                            ct.Teacher2   = each.TeacherName2;
                            ct.Teacher3   = each.TeacherName3;

                            clubTeacherDic.Add(school.School_Name, ct);
                        }
                    }

                    string name = each.ClubName;
                    if (!dic.ContainsKey(name))
                    {
                        dic.Add(name, new List <OnlineSCJoin>());
                        ClubNewNameList.Add(name);
                    }
                    // 2018/01/23 羿均 新增部別欄位
                    each.SchoolReMark = school.Remark;

                    dic[name].Add(each);
                }
            }

            ClubNewNameList.Sort();

            #endregion

            #region 報表範本整理

            Campus.Report.ReportConfiguration ConfigurationInCadre = new Campus.Report.ReportConfiguration(ConfigName);
            Aspose.Words.Document             Template;

            if (ConfigurationInCadre.Template == null)
            {
                //如果範本為空,則建立一個預設範本
                Campus.Report.ReportConfiguration ConfigurationInCadre_1 = new Campus.Report.ReportConfiguration(ConfigName);
                ConfigurationInCadre_1.Template = new Campus.Report.ReportTemplate(Properties.Resources.社團點名單_週報表樣式範本, Campus.Report.TemplateType.Word);
                Template = ConfigurationInCadre_1.Template.ToDocument();
            }
            else
            {
                //如果已有範本,則取得樣板
                Template = ConfigurationInCadre.Template.ToDocument();
            }

            #endregion

            #region 範本再修改

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

            XmlElement day = (XmlElement)e.Argument;

            if (day == null)
            {
                MsgBox.Show("第一次使用報表請先進行[日期設定]");
                return;
            }
            else
            {
                config.Clear();
                foreach (XmlElement xml in day.SelectNodes("item"))
                {
                    config.Add(xml.InnerText);
                }
            }


            SCJoinDataLoad scjoinData = new SCJoinDataLoad();

            DataTable table = new DataTable();
            table.Columns.Add("學校名稱");
            table.Columns.Add("社團名稱");
            table.Columns.Add("學年度");
            table.Columns.Add("學期");

            table.Columns.Add("上課地點");
            table.Columns.Add("社團類型");
            table.Columns.Add("社團代碼");
            //table.Columns.Add("社團老師");
            table.Columns.Add("社團老師1");
            table.Columns.Add("社團老師2");
            table.Columns.Add("社團老師3");

            table.Columns.Add("列印日期");
            table.Columns.Add("上課開始");
            table.Columns.Add("上課結束");
            table.Columns.Add("人數");

            for (int x = 1; x <= 日期多少天; x++)
            {
                table.Columns.Add(string.Format("日期_{0}", x));
            }

            for (int x = 1; x <= 學生多少個; x++)
            {
                table.Columns.Add(string.Format("社團_{0}", x));
            }

            for (int x = 1; x <= 學生多少個; x++)
            {
                table.Columns.Add(string.Format("部別名稱_{0}", x));
            }

            for (int x = 1; x <= 學生多少個; x++)
            {
                table.Columns.Add(string.Format("班級_{0}", x));
            }

            for (int x = 1; x <= 學生多少個; x++)
            {
                table.Columns.Add(string.Format("座號_{0}", x));
            }

            for (int x = 1; x <= 學生多少個; x++)
            {
                table.Columns.Add(string.Format("姓名_{0}", x));
            }

            for (int x = 1; x <= 學生多少個; x++)
            {
                table.Columns.Add(string.Format("學號_{0}", x));
            }

            for (int x = 1; x <= 學生多少個; x++)
            {
                table.Columns.Add(string.Format("性別_{0}", x));
            }

            #endregion

            foreach (string each in scjoinData.CLUBRecordDic.Keys)
            {
                //社團資料
                CLUBRecord cr = scjoinData.CLUBRecordDic[each];
            }

            foreach (string each in ClubNewNameList)
            {
                DataRow row = table.NewRow();

                row["學校名稱"] = K12.Data.School.ChineseName;
                row["學年度"]  = School.DefaultSchoolYear;
                row["學期"]   = School.DefaultSemester;

                row["列印日期"] = DateTime.Today.ToShortDateString();
                row["上課開始"] = config[0];
                row["上課結束"] = config[config.Count - 1];
                row["社團名稱"] = each;
                // 2018/01/23 羿均 新增合併欄位:
                row["上課地點"] = Mergerdic[each].Location;
                row["社團類型"] = Mergerdic[each].ClubCategory;
                row["社團代碼"] = Mergerdic[each].ClubNumber;

                row["社團老師1"] = clubTeacherDic[tool.Point].Teacher1;
                row["社團老師2"] = clubTeacherDic[tool.Point].Teacher2;
                row["社團老師3"] = clubTeacherDic[tool.Point].Teacher3;
                //特殊
                //if (dic[each].Count > 0)
                //row["社團老師"] = dic[each][0].TeacherName;

                for (int x = 1; x <= config.Count; x++)
                {
                    row[string.Format("日期_{0}", x)] = config[x - 1];
                }

                dic[each].Sort(SortStudentSCJoin);
                int y = 1;
                foreach (OnlineSCJoin scjoin in dic[each])
                {
                    if (y <= 學生多少個)
                    {
                        row[string.Format("部別名稱_{0}", y)] = scjoin.SchoolReMark;
                        row[string.Format("班級_{0}", y)]   = scjoin.ClassName;
                        row[string.Format("座號_{0}", y)]   = scjoin.SeatNo;
                        row[string.Format("姓名_{0}", y)]   = scjoin.StudentName;
                        row[string.Format("學號_{0}", y)]   = scjoin.StudentNumber;
                        row[string.Format("性別_{0}", y)]   = scjoin.Gender;
                        y++;
                    }
                }

                row["人數"] = y - 1;
                table.Rows.Add(row);
            }

            Document PageOne = (Document)Template.Clone(true);
            PageOne.MailMerge.Execute(table);
            e.Result = PageOne;
        }
Example #2
0
        void BGW_DoWork(object sender, DoWorkEventArgs e)
        {
            //開始列印學生清單


            #region 資料整理

            //取得需連線學校
            LoginSchoolList = tool._A.Select <LoginSchool>();

            //選擇了哪些社團(使用名稱進行比對)
            List <string>     ClubIDList     = K12.Club.Volunteer.ClubAdmin.Instance.SelectedSource;
            List <CLUBRecord> ClubRecordList = tool._A.Select <CLUBRecord>(ClubIDList);

            //社團名稱清單
            List <string> ClubNameList = new List <string>();
            foreach (CLUBRecord club in ClubRecordList)
            {
                ClubNameList.Add(club.ClubName);
            }

            //社團名稱 + 社團參與記錄學生
            Dictionary <string, List <OnlineSCJoin> > dic = new Dictionary <string, List <OnlineSCJoin> >();
            List <string> ClubNewNameList = new List <string>();
            foreach (LoginSchool school in LoginSchoolList)
            {
                Connection me = new Connection();
                me.Connect(school.School_Name, tool._contract, FISCA.Authentication.DSAServices.PassportToken);
                Dictionary <string, OnlineSCJoin> ScjList = RunService.GetSCJoinByClubName(me, ClubNameList);

                foreach (OnlineSCJoin each in ScjList.Values)
                {
                    string name = each.ClubName;
                    if (!dic.ContainsKey(name))
                    {
                        dic.Add(name, new List <OnlineSCJoin>());
                        ClubNewNameList.Add(name);
                    }
                    dic[name].Add(each);
                }
            }

            ClubNewNameList.Sort();

            #endregion

            #region 報表範本整理

            Campus.Report.ReportConfiguration ConfigurationInCadre = new Campus.Report.ReportConfiguration(ConfigName);
            Aspose.Words.Document             Template;

            if (ConfigurationInCadre.Template == null)
            {
                //如果範本為空,則建立一個預設範本
                Campus.Report.ReportConfiguration ConfigurationInCadre_1 = new Campus.Report.ReportConfiguration(ConfigName);
                ConfigurationInCadre_1.Template = new Campus.Report.ReportTemplate(Properties.Resources.班級點名單_週報表樣式範本, Campus.Report.TemplateType.Word);
                Template = ConfigurationInCadre_1.Template.ToDocument();
            }
            else
            {
                //如果已有範本,則取得樣板
                Template = ConfigurationInCadre.Template.ToDocument();
            }

            #endregion

            #region 範本再修改

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

            XmlElement day = (XmlElement)e.Argument;

            if (day == null)
            {
                MsgBox.Show("第一次使用報表請先進行[日期設定]");
                return;
            }
            else
            {
                config.Clear();
                foreach (XmlElement xml in day.SelectNodes("item"))
                {
                    config.Add(xml.InnerText);
                }
            }

            DataTable table = new DataTable();
            table.Columns.Add("學校名稱");
            table.Columns.Add("社團名稱");
            table.Columns.Add("學年度");
            table.Columns.Add("學期");

            table.Columns.Add("社團老師");

            table.Columns.Add("列印日期");
            table.Columns.Add("上課開始");
            table.Columns.Add("上課結束");
            table.Columns.Add("人數");

            for (int x = 1; x <= 日期多少天; x++)
            {
                table.Columns.Add(string.Format("日期_{0}", x));
            }

            for (int x = 1; x <= 學生多少個; x++)
            {
                table.Columns.Add(string.Format("社團_{0}", x));
            }

            for (int x = 1; x <= 學生多少個; x++)
            {
                table.Columns.Add(string.Format("班級_{0}", x));
            }

            for (int x = 1; x <= 學生多少個; x++)
            {
                table.Columns.Add(string.Format("座號_{0}", x));
            }

            for (int x = 1; x <= 學生多少個; x++)
            {
                table.Columns.Add(string.Format("姓名_{0}", x));
            }

            for (int x = 1; x <= 學生多少個; x++)
            {
                table.Columns.Add(string.Format("學號_{0}", x));
            }

            for (int x = 1; x <= 學生多少個; x++)
            {
                table.Columns.Add(string.Format("性別_{0}", x));
            }

            #endregion

            foreach (string each in ClubNewNameList)
            {
                DataRow row = table.NewRow();

                row["學校名稱"] = K12.Data.School.ChineseName;
                row["學年度"]  = School.DefaultSchoolYear;
                row["學期"]   = School.DefaultSemester;
                row["列印日期"] = DateTime.Today.ToShortDateString();
                row["上課開始"] = config[0];
                row["上課結束"] = config[config.Count - 1];
                row["社團名稱"] = each;

                //特殊
                if (dic[each].Count > 0)
                {
                    row["社團老師"] = dic[each][0].TeacherName;
                }

                for (int x = 1; x <= config.Count; x++)
                {
                    row[string.Format("日期_{0}", x)] = config[x - 1];
                }

                dic[each].Sort(SortStudentSCJoin);
                int y = 1;
                foreach (OnlineSCJoin scjoin in dic[each])
                {
                    if (y <= 學生多少個)
                    {
                        row[string.Format("班級_{0}", y)] = scjoin.ClassName;
                        row[string.Format("座號_{0}", y)] = scjoin.SeatNo;
                        row[string.Format("姓名_{0}", y)] = scjoin.StudentName;
                        row[string.Format("學號_{0}", y)] = scjoin.StudentNumber;
                        row[string.Format("性別_{0}", y)] = scjoin.Gender;
                        y++;
                    }
                }

                row["人數"] = y - 1;
                table.Rows.Add(row);
            }

            Document PageOne = (Document)Template.Clone(true);
            PageOne.MailMerge.Execute(table);
            e.Result = PageOne;
        }