public void Constructor_AllArgumentsAreProvided_PropertiesAreSet()
        {
            var dataImport = MockRepository.GenerateMock <IDataImport>();

            var dataImportEventArgs = new DataImportEventArgs(dataImport);

            Assert.AreEqual(dataImport, dataImportEventArgs.DataImport);
        }
Esempio n. 2
0
        private void ImportSemesterEntryScore_DataImport(object sender, DataImportEventArgs e)
        {
            Dictionary <string, List <RowData> > id_Rows = new Dictionary <string, List <RowData> >();

            #region 分包裝
            foreach (RowData data in e.Items)
            {
                if (!id_Rows.ContainsKey(data.ID))
                {
                    id_Rows.Add(data.ID, new List <RowData>());
                }
                id_Rows[data.ID].Add(data);
            }
            #endregion
            List <SmartSchool.Feature.Score.AddScore.InsertInfo>  insertList = new List <SmartSchool.Feature.Score.AddScore.InsertInfo>();
            List <SmartSchool.Feature.Score.EditScore.UpdateInfo> updateList = new List <SmartSchool.Feature.Score.EditScore.UpdateInfo>();
            List <string> deleteList = new List <string>();
            XmlDocument   doc        = new XmlDocument();
            //交叉比對各學生資料
            #region 交叉比對各學生資料
            foreach (string id in id_Rows.Keys)
            {
                StudentRecord studentRec = _StudentCollection[id];
                Dictionary <int, Dictionary <int, Dictionary <string, string> > > scoreIDDictionary = (Dictionary <int, Dictionary <int, Dictionary <string, string> > >)studentRec.Fields["SemesterEntryScoreID"];
                //該學生的學期各分項成績
                Dictionary <int, Dictionary <int, Dictionary <string, SemesterEntryScoreInfo> > > semesterScoreDictionary = new Dictionary <int, Dictionary <int, Dictionary <string, SemesterEntryScoreInfo> > >();
                Dictionary <int, Dictionary <int, int> > semesterGradeYearDictionary = new Dictionary <int, Dictionary <int, int> >();
                #region 整理現有的成績資料
                foreach (SemesterEntryScoreInfo var in studentRec.SemesterEntryScoreList)
                {
                    //學期分項成績資料
                    if (!semesterScoreDictionary.ContainsKey(var.SchoolYear))
                    {
                        semesterScoreDictionary.Add(var.SchoolYear, new Dictionary <int, Dictionary <string, SemesterEntryScoreInfo> >());
                    }
                    if (!semesterScoreDictionary[var.SchoolYear].ContainsKey(var.Semester))
                    {
                        semesterScoreDictionary[var.SchoolYear].Add(var.Semester, new Dictionary <string, SemesterEntryScoreInfo>());
                    }
                    semesterScoreDictionary[var.SchoolYear][var.Semester].Add(var.Entry, var);
                    //學期成績年級資料
                    if (!semesterGradeYearDictionary.ContainsKey(var.SchoolYear))
                    {
                        semesterGradeYearDictionary.Add(var.SchoolYear, new Dictionary <int, int>());
                    }
                    if (!semesterGradeYearDictionary[var.SchoolYear].ContainsKey(var.Semester))
                    {
                        semesterGradeYearDictionary[var.SchoolYear].Add(var.Semester, var.GradeYear);
                    }
                }
                #endregion
                //匯入資訊中各學期各分項成績值
                Dictionary <int, Dictionary <int, Dictionary <string, decimal?> > > semesterImportScore = new Dictionary <int, Dictionary <int, Dictionary <string, decimal?> > >();
                #region 整理要匯入的資料
                foreach (RowData row in id_Rows[id])
                {
                    int    t;
                    string schoolYear = row["學年度"];
                    string semester   = row["學期"];
                    int    sy         = int.Parse(schoolYear);
                    int    se         = int.Parse(semester);
                    foreach (string key in row.Keys)
                    {
                        bool gyChanged = false;
                        if (e.ImportFields.Contains("成績年級") && key == "成績年級")
                        {
                            int gy = int.Parse(row["成績年級"]);
                            //學期成績年級資料
                            if (!semesterGradeYearDictionary.ContainsKey(sy))
                            {
                                semesterGradeYearDictionary.Add(sy, new Dictionary <int, int>());
                            }
                            if (!semesterGradeYearDictionary[sy].ContainsKey(se))
                            {
                                semesterGradeYearDictionary[sy].Add(se, gy);
                                gyChanged = true;
                            }
                            else
                            {
                                if (semesterGradeYearDictionary[sy][se] != gy)
                                {
                                    semesterGradeYearDictionary[sy][se] = gy;
                                    gyChanged = true;
                                }
                            }
                        }
                        if (gyChanged)//成績年級有變更就一定要改
                        {
                            if (!semesterImportScore.ContainsKey(sy))
                            {
                                semesterImportScore.Add(sy, new Dictionary <int, Dictionary <string, decimal?> >());
                            }
                            if (!semesterImportScore[sy].ContainsKey(se))
                            {
                                semesterImportScore[sy].Add(se, new Dictionary <string, decimal?>());
                            }
                        }
                        if (e.ImportFields.Contains(key) && key == "學業" ||
                            key == "體育" ||
                            key == "國防通識" ||
                            key == "健康與護理" ||
                            key == "實習科目" ||
                            key == "專業科目" ||
                            key == "學業(原始)" ||
                            key == "體育(原始)" ||
                            key == "國防通識(原始)" ||
                            key == "健康與護理(原始)" ||
                            key == "實習科目(原始)" ||
                            key == "專業科目(原始)" ||
                            key == "德行")
                        {
                            bool    import = true;
                            decimal?score  = null;
                            decimal d;
                            if (decimal.TryParse(row[key], out d))
                            {
                                score = decimal.Parse(row[key]);
                            }
                            //如果這學期有這筆分項成績
                            if (semesterScoreDictionary.ContainsKey(sy) && semesterScoreDictionary[sy].ContainsKey(se) && semesterScoreDictionary[sy][se].ContainsKey(key))
                            {
                                //成績相同
                                if (semesterScoreDictionary[sy][se][key].Score == score)
                                {
                                    import = false;
                                }
                            }
                            else
                            {
                                //原本沒有此分項成績,是匯入的也沒有成績
                                if (score == null)
                                {
                                    import = false;
                                }
                            }
                            if (import)//成績年級有變更就一定要改
                            {
                                if (!semesterImportScore.ContainsKey(sy))
                                {
                                    semesterImportScore.Add(sy, new Dictionary <int, Dictionary <string, decimal?> >());
                                }
                                if (!semesterImportScore[sy].ContainsKey(se))
                                {
                                    semesterImportScore[sy].Add(se, new Dictionary <string, decimal?>());
                                }
                                if (!semesterImportScore[sy][se].ContainsKey(key))
                                {
                                    semesterImportScore[sy][se].Add(key, score);
                                }
                            }
                        }
                    }
                }
                #endregion
                #region 整理成新增或修改清單
                foreach (int sy in semesterImportScore.Keys)
                {
                    foreach (int se in semesterImportScore[sy].Keys)
                    {
                        //抓年級
                        string gy = "" + semesterGradeYearDictionary[sy][se];
                        //匯入行為類成績
                        #region 匯入行為類成績
                        if (semesterImportScore[sy][se].ContainsKey("德行"))
                        {
                            if (semesterScoreDictionary.ContainsKey(sy) && semesterScoreDictionary[sy].ContainsKey(se) && semesterScoreDictionary[sy][se].ContainsKey("德行"))
                            {
                                //修改
                                XmlElement entryScore = doc.CreateElement("SemesterEntryScore");
                                string     scoreId    = scoreIDDictionary[sy][se]["行為"];
                                if (semesterImportScore[sy][se]["德行"] != null)
                                {
                                    XmlElement entryElement = doc.CreateElement("Entry");
                                    entryElement.SetAttribute("分項", "德行");
                                    entryElement.SetAttribute("成績", "" + semesterImportScore[sy][se]["德行"]);
                                    entryScore.AppendChild(entryElement);
                                    updateList.Add(new EditScore.UpdateInfo(scoreId, gy, entryScore));
                                }
                                else
                                {
                                    deleteList.Add(scoreId);
                                }
                            }
                            else
                            {
                                if (semesterImportScore[sy][se]["德行"] != null)
                                {
                                    //新增
                                    XmlElement entryScore   = doc.CreateElement("SemesterEntryScore");
                                    XmlElement entryElement = doc.CreateElement("Entry");
                                    entryElement.SetAttribute("分項", "德行");
                                    entryElement.SetAttribute("成績", "" + semesterImportScore[sy][se]["德行"]);
                                    entryScore.AppendChild(entryElement);
                                    insertList.Add(new AddScore.InsertInfo("" + studentRec.StudentID, "" + sy, "" + se, gy, "行為", entryScore));
                                }
                            }
                        }
                        else if (e.ImportFields.Contains("成績年級") && semesterScoreDictionary.ContainsKey(sy) && semesterScoreDictionary[sy].ContainsKey(se) && semesterScoreDictionary[sy][se].ContainsKey("德行"))
                        {
                            //修改成績年級
                            string     scoreId      = scoreIDDictionary[sy][se]["行為"];
                            XmlElement entryScore   = doc.CreateElement("SemesterEntryScore");
                            XmlElement entryElement = doc.CreateElement("Entry");
                            entryElement.SetAttribute("分項", "德行");
                            entryElement.SetAttribute("成績", "" + semesterScoreDictionary[sy][se]["德行"].Score);
                            entryScore.AppendChild(entryElement);
                            updateList.Add(new EditScore.UpdateInfo(scoreId, gy, entryScore));
                        }
                        #endregion
                        //匯入學習類成績
                        #region 匯入學習類成績
                        if (semesterImportScore[sy][se].ContainsKey("學業") ||
                            semesterImportScore[sy][se].ContainsKey("體育") ||
                            semesterImportScore[sy][se].ContainsKey("國防通識") ||
                            semesterImportScore[sy][se].ContainsKey("健康與護理") ||
                            semesterImportScore[sy][se].ContainsKey("實習科目") ||
                            semesterImportScore[sy][se].ContainsKey("專業科目") ||
                            semesterImportScore[sy][se].ContainsKey("學業(原始)") ||
                            semesterImportScore[sy][se].ContainsKey("體育(原始)") ||
                            semesterImportScore[sy][se].ContainsKey("國防通識(原始)") ||
                            semesterImportScore[sy][se].ContainsKey("健康與護理(原始)") ||
                            semesterImportScore[sy][se].ContainsKey("實習科目(原始)") ||
                            semesterImportScore[sy][se].ContainsKey("專業科目(原始)")
                            )
                        {
                            #region 匯入分項成績
                            string     scoreId    = "";
                            bool       hasEntry   = false;
                            XmlElement entryScore = doc.CreateElement("SemesterEntryScore");
                            foreach (string key in new string[] { "學業"
                                                                  , "體育"
                                                                  , "國防通識"
                                                                  , "健康與護理"
                                                                  , "實習科目"
                                                                  , "專業科目"
                                                                  , "學業(原始)"
                                                                  , "體育(原始)"
                                                                  , "國防通識(原始)"
                                                                  , "健康與護理(原始)"
                                                                  , "實習科目(原始)"
                                                                  , "專業科目(原始)" })
                            {
                                if (semesterImportScore[sy][se].ContainsKey(key) ||                                                                                              //有匯入此分項成績
                                    (semesterScoreDictionary.ContainsKey(sy) && semesterScoreDictionary[sy].ContainsKey(se) && semesterScoreDictionary[sy][se].ContainsKey(key)) //原本有此分項成績
                                    )
                                {
                                    XmlElement entryElement = doc.CreateElement("Entry");
                                    entryElement.SetAttribute("分項", key);
                                    if (semesterImportScore[sy][se].ContainsKey(key)) //有匯入
                                    {
                                        if (semesterImportScore[sy][se][key] != null) //有成績
                                        {
                                            entryElement.SetAttribute("成績", "" + semesterImportScore[sy][se][key]);
                                            entryScore.AppendChild(entryElement);
                                            hasEntry = true;
                                        }
                                    }
                                    else//保留原本就有的
                                    {
                                        entryElement.SetAttribute("成績", "" + semesterScoreDictionary[sy][se][key].Score);
                                        entryScore.AppendChild(entryElement);
                                        hasEntry = true;
                                    }
                                    //之前有學習類分項成績的話就抓ID
                                    if (scoreId == "" && semesterScoreDictionary.ContainsKey(sy) && semesterScoreDictionary[sy].ContainsKey(se) && semesterScoreDictionary[sy][se].ContainsKey(key))
                                    {
                                        scoreId = scoreIDDictionary[sy][se]["學習"];
                                    }
                                }
                            }
                            if (scoreId != "")
                            {
                                if (hasEntry)
                                {
                                    //修改
                                    updateList.Add(new EditScore.UpdateInfo(scoreId, gy, entryScore));
                                }
                                else
                                {
                                    deleteList.Add(scoreId);
                                }
                            }
                            else
                            {
                                //新增
                                insertList.Add(new AddScore.InsertInfo(studentRec.StudentID, "" + sy, "" + se, gy, "學習", entryScore));
                            }
                            #endregion
                        }//沒有匯入分項成績但有改成績年級
                        else if (e.ImportFields.Contains("成績年級") && semesterScoreDictionary.ContainsKey(sy) && semesterScoreDictionary[sy].ContainsKey(se) &&
                                 (
                                     semesterScoreDictionary[sy][se].ContainsKey("學業") ||
                                     semesterScoreDictionary[sy][se].ContainsKey("體育") ||
                                     semesterScoreDictionary[sy][se].ContainsKey("國防通識") ||
                                     semesterScoreDictionary[sy][se].ContainsKey("健康與護理") ||
                                     semesterScoreDictionary[sy][se].ContainsKey("實習科目") ||
                                     semesterScoreDictionary[sy][se].ContainsKey("專業科目") ||
                                     semesterScoreDictionary[sy][se].ContainsKey("學業(原始)") ||
                                     semesterScoreDictionary[sy][se].ContainsKey("體育(原始)") ||
                                     semesterScoreDictionary[sy][se].ContainsKey("國防通識(原始)") ||
                                     semesterScoreDictionary[sy][se].ContainsKey("健康與護理(原始)") ||
                                     semesterScoreDictionary[sy][se].ContainsKey("實習科目(原始)") ||
                                     semesterScoreDictionary[sy][se].ContainsKey("專業科目(原始)")
                                 ))
                        {
                            #region 修改成績年級
                            XmlElement entryScore = doc.CreateElement("SemesterEntryScore");
                            string     scoreId    = "";
                            foreach (string key in new string[] { "學業"
                                                                  , "體育"
                                                                  , "國防通識"
                                                                  , "健康與護理"
                                                                  , "實習科目"
                                                                  , "專業科目"
                                                                  , "學業(原始)"
                                                                  , "體育(原始)"
                                                                  , "國防通識(原始)"
                                                                  , "健康與護理(原始)"
                                                                  , "實習科目(原始)"
                                                                  , "專業科目(原始) " })
                            {
                                if (semesterScoreDictionary.ContainsKey(sy) && semesterScoreDictionary[sy].ContainsKey(se) && semesterScoreDictionary[sy][se].ContainsKey(key)) //原本有此分項成績
                                {
                                    XmlElement entryElement = doc.CreateElement("Entry");
                                    entryElement.SetAttribute("分項", key);
                                    if (semesterImportScore[sy][se].ContainsKey(key)) //有匯入
                                    {
                                        if (semesterImportScore[sy][se][key] != null) //有成績
                                        {
                                            entryElement.SetAttribute("成績", "" + semesterImportScore[sy][se][key]);
                                            entryScore.AppendChild(entryElement);
                                        }
                                    }
                                    else//保留原本就有的
                                    {
                                        entryElement.SetAttribute("成績", "" + semesterScoreDictionary[sy][se][key].Score);
                                        entryScore.AppendChild(entryElement);
                                    }
                                    scoreId = scoreIDDictionary[sy][se]["學習"];
                                }
                            }
                            updateList.Add(new EditScore.UpdateInfo(scoreId, gy, entryScore));
                            #endregion
                        }
                        #endregion
                    }
                }
                #endregion
            }
            #endregion

            if (updateList.Count > 0)
            {
                #region 分批次兩路上傳
                List <List <SmartSchool.Feature.Score.EditScore.UpdateInfo> > updatePackages  = new List <List <SmartSchool.Feature.Score.EditScore.UpdateInfo> >();
                List <List <SmartSchool.Feature.Score.EditScore.UpdateInfo> > updatePackages2 = new List <List <SmartSchool.Feature.Score.EditScore.UpdateInfo> >();
                {
                    List <SmartSchool.Feature.Score.EditScore.UpdateInfo> package = null;
                    int count = 0;
                    foreach (SmartSchool.Feature.Score.EditScore.UpdateInfo var in updateList)
                    {
                        if (count == 0)
                        {
                            package = new List <SmartSchool.Feature.Score.EditScore.UpdateInfo>(30);
                            count   = 30;
                            if ((updatePackages.Count & 1) == 0)
                            {
                                updatePackages.Add(package);
                            }
                            else
                            {
                                updatePackages2.Add(package);
                            }
                        }
                        package.Add(var);
                        count--;
                    }
                }
                Thread threadUpdateSemesterEntryScore = new Thread(new ParameterizedThreadStart(updateSemesterEntryScore));
                threadUpdateSemesterEntryScore.IsBackground = true;
                threadUpdateSemesterEntryScore.Start(updatePackages);
                Thread threadUpdateSemesterEntryScore2 = new Thread(new ParameterizedThreadStart(updateSemesterEntryScore));
                threadUpdateSemesterEntryScore2.IsBackground = true;
                threadUpdateSemesterEntryScore2.Start(updatePackages2);

                threadUpdateSemesterEntryScore.Join();
                threadUpdateSemesterEntryScore2.Join();
                #endregion
            }
            if (insertList.Count > 0)
            {
                #region 分批次兩路上傳

                List <List <SmartSchool.Feature.Score.AddScore.InsertInfo> > insertPackages  = new List <List <SmartSchool.Feature.Score.AddScore.InsertInfo> >();
                List <List <SmartSchool.Feature.Score.AddScore.InsertInfo> > insertPackages2 = new List <List <SmartSchool.Feature.Score.AddScore.InsertInfo> >();
                {
                    List <SmartSchool.Feature.Score.AddScore.InsertInfo> package = null;
                    int count = 0;
                    foreach (SmartSchool.Feature.Score.AddScore.InsertInfo var in insertList)
                    {
                        if (count == 0)
                        {
                            package = new List <SmartSchool.Feature.Score.AddScore.InsertInfo>(30);
                            count   = 30;
                            if ((insertPackages.Count & 1) == 0)
                            {
                                insertPackages.Add(package);
                            }
                            else
                            {
                                insertPackages2.Add(package);
                            }
                        }
                        package.Add(var);
                        count--;
                    }
                }
                Thread threadInsertSemesterEntryScore = new Thread(new ParameterizedThreadStart(insertSemesterEntryScore));
                threadInsertSemesterEntryScore.IsBackground = true;
                threadInsertSemesterEntryScore.Start(insertPackages);
                Thread threadInsertSemesterEntryScore2 = new Thread(new ParameterizedThreadStart(insertSemesterEntryScore));
                threadInsertSemesterEntryScore2.IsBackground = true;
                threadInsertSemesterEntryScore2.Start(insertPackages2);

                threadInsertSemesterEntryScore.Join();
                threadInsertSemesterEntryScore2.Join();
                #endregion
            }
            if (deleteList.Count > 0)
            {
                #region 分批次兩路上傳
                List <List <string> > deletePackages  = new List <List <string> >();
                List <List <string> > deletePackages2 = new List <List <string> >();
                {
                    List <string> package = null;
                    int           count   = 0;
                    foreach (string var in deleteList)
                    {
                        if (count == 0)
                        {
                            package = new List <string>(30);
                            count   = 30;
                            if ((deletePackages.Count & 1) == 0)
                            {
                                deletePackages.Add(package);
                            }
                            else
                            {
                                deletePackages2.Add(package);
                            }
                        }
                        package.Add(var);
                        count--;
                    }
                }
                Thread threadDeleteSemesterEntryScore = new Thread(new ParameterizedThreadStart(deleteSemesterEntryScore));
                threadDeleteSemesterEntryScore.IsBackground = true;
                threadDeleteSemesterEntryScore.Start(deletePackages);
                Thread threadDeleteSemesterEntryScore2 = new Thread(new ParameterizedThreadStart(deleteSemesterEntryScore));
                threadDeleteSemesterEntryScore2.IsBackground = true;
                threadDeleteSemesterEntryScore2.Start(deletePackages2);

                threadDeleteSemesterEntryScore.Join();
                threadDeleteSemesterEntryScore2.Join();
                #endregion
            }
        }
Esempio n. 3
0
        void ImportNewStudentsUpdateRecord_DataImport(object sender, DataImportEventArgs e)
        {
            Dictionary <string, string> fieldNameMapping = new Dictionary <string, string>();

            #region 建立匯入欄位名稱跟Xml內欄位對照表
            fieldNameMapping.Add("Department", "異動科別");
            fieldNameMapping.Add("GradeYear", "年級");
            fieldNameMapping.Add("StudentNumber", "異動學號");
            fieldNameMapping.Add("StudentName", "異動姓名");
            fieldNameMapping.Add("IDNumber", "身分證號");
            fieldNameMapping.Add("Gender", "性別");
            fieldNameMapping.Add("Birthdate", "生日");
            fieldNameMapping.Add("UpdateCode", "異動代碼");
            fieldNameMapping.Add("UpdateDate", "異動日期");
            fieldNameMapping.Add("UpdateDescription", "原因及事項");
            fieldNameMapping.Add("NewStudentNumber", "新學號");
            fieldNameMapping.Add("PreviousDepartment", "轉入前學生資料-科別");
            fieldNameMapping.Add("PreviousGradeYear", "轉入前學生資料-年級");
            fieldNameMapping.Add("PreviousSchool", "轉入前學生資料-學校");
            fieldNameMapping.Add("PreviousSchoolLastADDate", "轉入前學生資料-(備查日期)");
            fieldNameMapping.Add("PreviousSchoolLastADNumber", "轉入前學生資料-(備查文號)");
            fieldNameMapping.Add("PreviousStudentNumber", "轉入前學生資料-學號");
            fieldNameMapping.Add("GraduateSchool", "入學資格-畢業國中");
            fieldNameMapping.Add("GraduateSchoolLocationCode", "入學資格-畢業國中所在地代碼");
            fieldNameMapping.Add("LastUpdateCode", "最後異動代碼");
            fieldNameMapping.Add("GraduateCertificateNumber", "畢(結)業證書字號");
            fieldNameMapping.Add("LastADDate", "備查日期");
            fieldNameMapping.Add("LastADNumber", "備查文號");
            fieldNameMapping.Add("ADDate", "核准日期");
            fieldNameMapping.Add("ADNumber", "核准文號");
            fieldNameMapping.Add("Comment", "備註");

            fieldNameMapping.Add("ClassType", "班別");
            fieldNameMapping.Add("SpecialStatus", "特殊身份代碼");
            fieldNameMapping.Add("IDNumberComment", "註1");
            fieldNameMapping.Add("OldClassType", "舊班別");
            fieldNameMapping.Add("OldDepartmentCode", "舊科別代碼");
            fieldNameMapping.Add("GraduateSchoolYear", "入學資格-畢業國中年度");
            fieldNameMapping.Add("GraduateComment", "入學資格-註2");
            #endregion
            List <SHUpdateRecordRecord> InsertUpdateRecords = new List <SHUpdateRecordRecord>();
            List <SHUpdateRecordRecord> UpdateUpdateRecords = new List <SHUpdateRecordRecord>();


            bool insert = false, update = false;
            foreach (RowData row in e.Items)
            {
                if (_NewStudentUpdateRecordInfoList.ContainsKey(row.ID))
                {
                    if (_NewStudentUpdateRecordInfoList[row.ID] == null)
                    {
                        insert = true;
                        #region 新增
                        SHUpdateRecordRecord InsertUpdateRecord = new SHUpdateRecordRecord();

                        InsertUpdateRecord.StudentID = row.ID;

                        foreach (string field in fieldNameMapping.Keys)
                        {
                            string fieldname = fieldNameMapping[field];

                            PropertyInfo Property = InsertUpdateRecord.GetType().GetProperty(field, System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.Instance);

                            if (Property != null)
                            {
                                Property.SetValue(InsertUpdateRecord, row.ContainsKey(fieldname) ? row[fieldname] : string.Empty, null);
                            }
                        }

                        InsertUpdateRecords.Add(InsertUpdateRecord);
                        #endregion
                    }
                    else
                    {
                        update = true;
                        #region 修改
                        SHUpdateRecordRecord UpdateUpdateRecord = new SHUpdateRecordRecord();


                        UpdateUpdateRecord.ID        = _NewStudentUpdateRecordInfoList[row.ID].ID;
                        UpdateUpdateRecord.StudentID = row.ID;

                        foreach (string field in fieldNameMapping.Keys)
                        {
                            string fieldname = fieldNameMapping[field];

                            PropertyInfo Property = UpdateUpdateRecord.GetType().GetProperty(field, System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.Instance);

                            if (Property != null)
                            {
                                Property.SetValue(UpdateUpdateRecord, row.ContainsKey(fieldname) ? row[fieldname] : string.Empty, null);
                            }
                        }

                        UpdateUpdateRecords.Add(UpdateUpdateRecord);
                        #endregion
                    }
                }
            }
            if (insert)
            {
                try
                {
                    SHUpdateRecord.Insert(InsertUpdateRecords);
                }
                catch (Exception ve)
                {
                }
            }
            if (update)
            {
                try
                {
                    SHUpdateRecord.Update(UpdateUpdateRecords);
                }
                catch (Exception ve)
                {
                }
            }
        }
Esempio n. 4
0
        protected override void OnDataImport(DataImportEventArgs args)
        {
            Dictionary <string, List <RowData> > id_Rows = new Dictionary <string, List <RowData> >();

            #region 分包裝
            foreach (RowData data in args.Items)
            {
                if (!id_Rows.ContainsKey(data.ID))
                {
                    id_Rows.Add(data.ID, new List <RowData>());
                }
                id_Rows[data.ID].Add(data);
            }
            #endregion
            List <SmartSchool.Feature.Score.AddScore.InsertInfo>  insertList = new List <SmartSchool.Feature.Score.AddScore.InsertInfo>();
            List <SmartSchool.Feature.Score.EditScore.UpdateInfo> updateList = new List <SmartSchool.Feature.Score.EditScore.UpdateInfo>();
            //交叉比對各學生資料
            #region 交叉比對各學生資料
            foreach (string id in id_Rows.Keys)
            {
                XmlDocument   doc        = new XmlDocument();
                StudentRecord studentRec = _StudentCollection[id];
                //該學生的學期學年成績
                Dictionary <int, Dictionary <string, SchoolYearSubjectScoreInfo> > schoolYearScoreDictionary = new Dictionary <int, Dictionary <string, SchoolYearSubjectScoreInfo> >();
                Dictionary <int, string> schoolYearScoreID = new Dictionary <int, string>();
                Dictionary <int, string> scoreID           = (Dictionary <int, string>)studentRec.Fields["SchoolYearSubjectScoreID"];
                #region 整理現有的成績資料
                foreach (SchoolYearSubjectScoreInfo var in studentRec.SchoolYearSubjectScoreList)
                {
                    string key = var.Subject;
                    if (!schoolYearScoreDictionary.ContainsKey(var.SchoolYear))
                    {
                        schoolYearScoreDictionary.Add(var.SchoolYear, new Dictionary <string, SchoolYearSubjectScoreInfo>());
                    }
                    if (!schoolYearScoreDictionary[var.SchoolYear].ContainsKey(key))
                    {
                        schoolYearScoreDictionary[var.SchoolYear].Add(key, var);
                    }
                    //填入學年科目成績編號
                    if (!schoolYearScoreID.ContainsKey(var.SchoolYear))
                    {
                        schoolYearScoreID.Add(var.SchoolYear, scoreID[var.SchoolYear]);
                    }
                }
                #endregion
                //要匯入的學期學年成績
                Dictionary <int, Dictionary <string, RowData> > schoolYearImportScoreDictionary = new Dictionary <int, Dictionary <string, RowData> >();
                #region 整理要匯入的資料
                foreach (RowData row in id_Rows[id])
                {
                    int    t;
                    string subject    = row["科目"];
                    string schoolYear = row["學年度"];
                    int    sy         = int.Parse(schoolYear);
                    string key        = subject;
                    if (!schoolYearImportScoreDictionary.ContainsKey(sy))
                    {
                        schoolYearImportScoreDictionary.Add(sy, new Dictionary <string, RowData>());
                    }
                    if (!schoolYearImportScoreDictionary[sy].ContainsKey(key))
                    {
                        schoolYearImportScoreDictionary[sy].Add(key, row);
                    }
                }
                #endregion

                //學期年級重整
                Dictionary <int, int> schoolYearGradeYear = new Dictionary <int, int>();
                //要變更成績的學期
                List <int> updatedSchoolYear = new List <int>();
                //在變更學期中新增加的成績資料
                Dictionary <int, List <RowData> > updatedNewSchoolYearScore = new Dictionary <int, List <RowData> >();
                //要增加成績的學期
                Dictionary <int, List <RowData> > insertNewSchoolYearScore = new Dictionary <int, List <RowData> >();
                //開始處理ImportScore
                #region 開始處理ImportScore
                foreach (int sy in schoolYearImportScoreDictionary.Keys)
                {
                    foreach (string key in schoolYearImportScoreDictionary[sy].Keys)
                    {
                        RowData data = schoolYearImportScoreDictionary[sy][key];
                        //如果是本來沒有這筆學期的成績就加到insertNewSemesterScore
                        if (!schoolYearScoreDictionary.ContainsKey(sy))
                        {
                            if (!insertNewSchoolYearScore.ContainsKey(sy))
                            {
                                insertNewSchoolYearScore.Add(sy, new List <RowData>());
                            }
                            insertNewSchoolYearScore[sy].Add(data);
                            //加入學期年級
                            int gy = int.Parse(data["成績年級"]);
                            if (!schoolYearGradeYear.ContainsKey(sy))
                            {
                                schoolYearGradeYear.Add(sy, gy);
                            }
                            else
                            {
                                schoolYearGradeYear[sy] = gy;
                            }
                        }
                        else
                        {
                            bool hasChanged = false;
                            //修改已存在的資料
                            if (schoolYearScoreDictionary[sy].ContainsKey(key))
                            {
                                SchoolYearSubjectScoreInfo score = schoolYearScoreDictionary[sy][key];
                                #region 填入此學期的年級資料
                                if (!schoolYearGradeYear.ContainsKey(sy))
                                {
                                    schoolYearGradeYear.Add(sy, score.GradeYear);
                                }
                                #endregion
                                #region 直接修改已存在的成績資料的Detail
                                foreach (string field in args.ImportFields)
                                {
                                    string value = data[field];
                                    switch (field)
                                    {
                                    default: break;

                                    case "結算成績":
                                    case "補考成績":
                                    case "重修成績":
                                        if (score.Detail.GetAttribute(field) != value)
                                        {
                                            score.Detail.SetAttribute(field, value);
                                            hasChanged = true;
                                        }
                                        break;

                                    case "成績年級":
                                        int gy = int.Parse(data["成績年級"]);
                                        if (score.GradeYear != gy)
                                        {
                                            schoolYearGradeYear[sy] = gy;
                                            hasChanged = true;
                                        }
                                        break;
                                    }
                                }
                                decimal topScore = decimal.MinValue, tryParseScore;
                                foreach (var item in new string[] {
                                    "結算成績",
                                    "補考成績",
                                    "重修成績"
                                })
                                {
                                    if (decimal.TryParse(score.Detail.GetAttribute(item), out tryParseScore) && tryParseScore > topScore)
                                    {
                                        topScore = tryParseScore;
                                    }
                                }
                                score.Detail.SetAttribute("學年成績", "" + topScore);
                                #endregion
                            }
                            else//加入新成績至已存在的學期
                            {
                                //加入學期年級
                                int gy = int.Parse(data["成績年級"]);
                                if (!schoolYearGradeYear.ContainsKey(sy))
                                {
                                    schoolYearGradeYear.Add(sy, gy);
                                }
                                else
                                {
                                    schoolYearGradeYear[sy] = gy;
                                }
                                //加入新成績至已存在的學期
                                if (!updatedNewSchoolYearScore.ContainsKey(sy))
                                {
                                    updatedNewSchoolYearScore.Add(sy, new List <RowData>());
                                }
                                updatedNewSchoolYearScore[sy].Add(data);
                                hasChanged = true;
                            }
                            //真的有變更
                            if (hasChanged)
                            {
                                #region 登錄有變更的學期
                                if (!updatedSchoolYear.Contains(sy))
                                {
                                    updatedSchoolYear.Add(sy);
                                }
                                #endregion
                            }
                        }
                    }
                }
                #endregion
                //處理已登錄要更新的學期成績
                #region 處理已登錄要更新的學期成績
                foreach (int sy in updatedSchoolYear)
                {
                    string     scoreid          = schoolYearScoreID[sy];        //從學年抓ID
                    string     gradeyear        = "" + schoolYearGradeYear[sy]; //抓年級
                    XmlElement subjectScoreInfo = doc.CreateElement("SchoolYearSubjectScore");
                    #region 產生該學期學年成績的XML
                    foreach (SchoolYearSubjectScoreInfo scoreInfo in schoolYearScoreDictionary[sy].Values)
                    {
                        subjectScoreInfo.AppendChild(doc.ImportNode(scoreInfo.Detail, true));
                    }
                    if (updatedNewSchoolYearScore.ContainsKey(sy))
                    {
                        foreach (RowData row in updatedNewSchoolYearScore[sy])
                        {
                            XmlElement newScore = doc.CreateElement("Subject");
                            #region 建立newScore
                            foreach (string field in new string[] { "科目", "結算成績", "補考成績", "重修成績" })
                            {
                                if (args.ImportFields.Contains(field))
                                {
                                    string value = row[field];
                                    switch (field)
                                    {
                                    default: break;

                                    case "科目":
                                        newScore.SetAttribute("科目", value);
                                        break;

                                    case "結算成績":
                                    case "補考成績":
                                    case "重修成績":
                                        newScore.SetAttribute(field, value);
                                        break;
                                    }
                                }
                            }
                            decimal topScore = decimal.MinValue, tryParseScore;
                            foreach (var item in new string[] {
                                "結算成績",
                                "補考成績",
                                "重修成績"
                            })
                            {
                                if (decimal.TryParse(newScore.GetAttribute(item), out tryParseScore) && tryParseScore > topScore)
                                {
                                    topScore = tryParseScore;
                                }
                            }
                            newScore.SetAttribute("學年成績", "" + topScore);
                            #endregion
                            subjectScoreInfo.AppendChild(newScore);
                        }
                    }
                    #endregion
                    updateList.Add(new SmartSchool.Feature.Score.EditScore.UpdateInfo(scoreid, gradeyear, subjectScoreInfo));
                }
                #endregion
                //處理新增成績學期
                #region 處理新增成績學期
                foreach (int sy in insertNewSchoolYearScore.Keys)
                {
                    XmlElement subjectScoreInfo = doc.CreateElement("SchoolYearSubjectScore");
                    string     gradeyear        = "" + schoolYearGradeYear[sy];//抓年級
                    foreach (RowData row in insertNewSchoolYearScore[sy])
                    {
                        XmlElement newScore = doc.CreateElement("Subject");
                        #region 建立newScore
                        foreach (string field in new string[] { "科目", "結算成績", "補考成績", "重修成績" })
                        {
                            if (args.ImportFields.Contains(field))
                            {
                                string value = row[field];
                                switch (field)
                                {
                                default: break;

                                case "科目":
                                    newScore.SetAttribute("科目", value);
                                    break;

                                case "結算成績":
                                case "補考成績":
                                case "重修成績":
                                    newScore.SetAttribute(field, value);
                                    break;
                                }
                            }
                        }
                        decimal topScore = decimal.MinValue, tryParseScore;
                        foreach (var item in new string[] {
                            "結算成績",
                            "補考成績",
                            "重修成績"
                        })
                        {
                            if (decimal.TryParse(newScore.GetAttribute(item), out tryParseScore) && tryParseScore > topScore)
                            {
                                topScore = tryParseScore;
                            }
                        }
                        newScore.SetAttribute("學年成績", "" + topScore);
                        #endregion
                        subjectScoreInfo.AppendChild(newScore);
                    }
                    insertList.Add(new SmartSchool.Feature.Score.AddScore.InsertInfo(studentRec.StudentID, "" + sy, "", gradeyear, "", subjectScoreInfo));
                }
                #endregion
            }
            #endregion

            if (updateList.Count > 0)
            {
                #region 分批次兩路上傳
                List <List <SmartSchool.Feature.Score.EditScore.UpdateInfo> > updatePackages  = new List <List <SmartSchool.Feature.Score.EditScore.UpdateInfo> >();
                List <List <SmartSchool.Feature.Score.EditScore.UpdateInfo> > updatePackages2 = new List <List <SmartSchool.Feature.Score.EditScore.UpdateInfo> >();
                {
                    List <SmartSchool.Feature.Score.EditScore.UpdateInfo> package = null;
                    int count = 0;
                    foreach (SmartSchool.Feature.Score.EditScore.UpdateInfo var in updateList)
                    {
                        if (count == 0)
                        {
                            package = new List <SmartSchool.Feature.Score.EditScore.UpdateInfo>(30);
                            count   = 30;
                            if ((updatePackages.Count & 1) == 0)
                            {
                                updatePackages.Add(package);
                            }
                            else
                            {
                                updatePackages2.Add(package);
                            }
                        }
                        package.Add(var);
                        count--;
                    }
                }
                Thread threadUpdateSchoolYearSubjectScore = new Thread(new ParameterizedThreadStart(updateSchoolYearSubjectScore));
                threadUpdateSchoolYearSubjectScore.IsBackground = true;
                threadUpdateSchoolYearSubjectScore.Start(updatePackages);
                Thread threadUpdateSchoolYearSubjectScore2 = new Thread(new ParameterizedThreadStart(updateSchoolYearSubjectScore));
                threadUpdateSchoolYearSubjectScore2.IsBackground = true;
                threadUpdateSchoolYearSubjectScore2.Start(updatePackages2);

                threadUpdateSchoolYearSubjectScore.Join();
                threadUpdateSchoolYearSubjectScore2.Join();
                #endregion
            }
            if (insertList.Count > 0)
            {
                #region 分批次兩路上傳

                List <List <SmartSchool.Feature.Score.AddScore.InsertInfo> > insertPackages  = new List <List <SmartSchool.Feature.Score.AddScore.InsertInfo> >();
                List <List <SmartSchool.Feature.Score.AddScore.InsertInfo> > insertPackages2 = new List <List <SmartSchool.Feature.Score.AddScore.InsertInfo> >();
                {
                    List <SmartSchool.Feature.Score.AddScore.InsertInfo> package = null;
                    int count = 0;
                    foreach (SmartSchool.Feature.Score.AddScore.InsertInfo var in insertList)
                    {
                        if (count == 0)
                        {
                            package = new List <SmartSchool.Feature.Score.AddScore.InsertInfo>(30);
                            count   = 30;
                            if ((insertPackages.Count & 1) == 0)
                            {
                                insertPackages.Add(package);
                            }
                            else
                            {
                                insertPackages2.Add(package);
                            }
                        }
                        package.Add(var);
                        count--;
                    }
                }
                Thread threadInsertSchoolYearSubjectScore = new Thread(new ParameterizedThreadStart(insertSchoolYearSubjectScore));
                threadInsertSchoolYearSubjectScore.IsBackground = true;
                threadInsertSchoolYearSubjectScore.Start(insertPackages);
                Thread threadInsertSchoolYearSubjectScore2 = new Thread(new ParameterizedThreadStart(insertSchoolYearSubjectScore));
                threadInsertSchoolYearSubjectScore2.IsBackground = true;
                threadInsertSchoolYearSubjectScore2.Start(insertPackages2);

                threadInsertSchoolYearSubjectScore.Join();
                threadInsertSchoolYearSubjectScore2.Join();
                #endregion
            }
        }