private List <K12.Data.DomainScore> CalculateDomainScore(List <K12.Data.SubjectScore> subjectScoreList)
        {
            Dictionary <string, DomainCalc> domainScores = new Dictionary <string, DomainCalc>();

            foreach (K12.Data.SubjectScore subject in subjectScoreList)
            {
                if (!domainScores.ContainsKey(subject.Domain))
                {
                    domainScores.Add(subject.Domain, new DomainCalc());
                }

                domainScores[subject.Domain].AddScore(subject.Score, (decimal)subject.Credit, (decimal)subject.Period);
                domainScores[subject.Domain].AddText(subject.Subject, subject.Text);
            }

            List <K12.Data.DomainScore> list = new List <K12.Data.DomainScore>();

            foreach (string key in domainScores.Keys)
            {
                K12.Data.DomainScore domain = new K12.Data.DomainScore();
                domain.Domain = key;
                domain.Credit = domainScores[key].Credit;
                domain.Period = domainScores[key].Period;
                domain.Text   = domainScores[key].GetText();
                domain.Score  = domainScores[key].GetScore();
                domain.Effort = GetEffortCode((decimal)domain.Score);

                list.Add(domain);
            }

            return(list);
        }
 public bool Add(SemesterData semester, K12.Data.DomainScore domain)
 {
     if (!_scores.ContainsKey(semester))
     {
         _scores.Add(semester, new ScoreData("" + domain.Period, "" + domain.Credit, "" + domain.Score));
         return(true);
     }
     return(false);
 }
Ejemplo n.º 3
0
        private K12.Data.DomainScore GetDomainScore(string p, TextBoxX pc, TextBoxX score, TextBoxX effort, TextBoxX text)
        {
            PeriodCredit temp = new PeriodCredit();

            temp.Parse(pc.Text);
            K12.Data.DomainScore domain = new K12.Data.DomainScore();
            domain.Domain = p;
            domain.Period = temp.Period;
            domain.Credit = temp.Credit;
            domain.Effort = int.Parse(effort.Text);
            domain.Score  = decimal.Parse(score.Text);
            domain.Text   = text.Text;
            return(domain);
        }
Ejemplo n.º 4
0
        private K12.Data.DomainScore GetElasticDomain()
        {
            K12.Data.DomainScore domain = new K12.Data.DomainScore();
            domain.Domain = "彈性課程";
            domain.Score  = decimal.Parse(txtElastic.Text);

            PeriodCredit pc   = new PeriodCredit();
            PeriodCredit temp = new PeriodCredit();
            //int pc = 0;
            int    effort = 0;
            int    count  = 0;
            string text   = "";

            foreach (DataGridViewRow row in dgv.Rows)
            {
                if (row.IsNewRow)
                {
                    continue;
                }

                // 修改彈性課程處理方式,當領域名稱是空白,當作彈性課程。
                //if ("" + row.Cells[chsDomain.Index].Value == "彈性課程")
                if ("" + row.Cells[chsDomain.Index].Value == "")
                {
                    count++;
                    temp.Parse("" + row.Cells[chsPeriodCredit.Index].Value);
                    pc.Credit += temp.Credit;
                    pc.Period += temp.Period;
                    effort    += int.Parse("" + row.Cells[chsEffort.Index].Value);
                    if (!string.IsNullOrEmpty("" + row.Cells[chsText.Index].Value))
                    {
                        text += "" + row.Cells[chsSubject.Index].Value + ":" + row.Cells[chsText.Index].Value;
                    }
                }
            }

            domain.Period = pc.Period;
            domain.Credit = pc.Credit;
            if (count == 0)
            {
                domain.Effort = 0;
            }
            else
            {
                domain.Effort = (int)decimal.Round((decimal)effort / (decimal)count, 0, MidpointRounding.AwayFromZero);
            }
            domain.Text = text;
            return(domain);
        }
        private K12.Data.DomainScore GetDomainScore(string p, TextBoxX pc, TextBoxX score, TextBoxX effort, TextBoxX text)
        {
            PeriodCredit temp = new PeriodCredit();

            temp.Parse(pc.Text);
            K12.Data.DomainScore domain = new K12.Data.DomainScore();
            domain.Domain = p;
            domain.Period = temp.Period;
            domain.Credit = temp.Credit;
            //domain.Effort = int.Parse(effort.Text);
            domain.Effort      = 1;
            domain.Score       = decimal.Parse(score.Text);
            domain.ScoreOrigin = decimal.Parse(score.Text); // 2018.09.22 [ischoolKingdom] Vicky依據 [J成績][HC][03] 快速新增學期成績修正,將語文領域的子領域兩個項目欄位拿掉,僅保留輸入語文領域成績的單一功能。
            domain.Text        = text.Text;
            return(domain);
        }
Ejemplo n.º 6
0
        private K12.Data.DomainScore GetDomainScore(string p, TextBoxX pc, TextBoxX score, TextBoxX Oriscore, TextBoxX effort, TextBoxX text)
        {
            PeriodCredit temp = new PeriodCredit();

            temp.Parse(pc.Text);
            K12.Data.DomainScore domain = new K12.Data.DomainScore();
            domain.Domain = p;
            domain.Period = temp.Period;
            domain.Credit = temp.Credit;
            domain.Effort = int.Parse(effort.Text);
            domain.Score  = decimal.Parse(score.Text);
            //2018/4/16 穎驊因應高雄項目[02-03][06]學期成績,快速新增功能如無原始成績,則結算學期領域成績時快速新增的成績都會變成"0"分
            // 新增原始成績登錄
            domain.ScoreOrigin = decimal.Parse(Oriscore.Text);
            domain.Text        = text.Text;
            return(domain);
        }
        private K12.Data.DomainScore GetElasticDomain()
        {
            K12.Data.DomainScore domain = new K12.Data.DomainScore();
            domain.Domain      = "彈性課程";
            domain.Score       = decimal.Parse(textBoxX33.Text);
            domain.ScoreOrigin = decimal.Parse(textBoxX33.Text); // 2018.09.22 [ischoolKingdom] Vicky依據 [J成績][HC][03] 快速新增學期成績修正,輸入成績一併存入原始成績。

            PeriodCredit pc   = new PeriodCredit();
            PeriodCredit temp = new PeriodCredit();
            //int pc = 0;
            //int effort = 0;
            int    count = 0;
            string text  = "";

            foreach (DataGridViewRow row in dgv.Rows)
            {
                if (row.IsNewRow)
                {
                    continue;
                }
                if ("" + row.Cells[chsDomain.Index].Value == "彈性課程" || "" + row.Cells[chsDomain.Index].Value == "")
                {
                    count++;
                    temp.Parse("" + row.Cells[chsPeriodCredit.Index].Value);
                    pc.Credit += temp.Credit;
                    pc.Period += temp.Period;
                    //effort += int.Parse("" + row.Cells[chsEffort.Index].Value);
                    if (!string.IsNullOrEmpty("" + row.Cells[chsText.Index].Value))
                    {
                        text += "" + row.Cells[chsSubject.Index].Value + ":" + row.Cells[chsText.Index].Value;
                    }
                }
            }

            domain.Period = pc.Period;
            domain.Credit = pc.Credit;
            //domain.Effort = (int)decimal.Round((decimal)effort / (decimal)count, 0, MidpointRounding.AwayFromZero);
            domain.Effort = 1;
            domain.Text   = text;
            return(domain);
        }
Ejemplo n.º 8
0
        private void btnSave_Click(object sender, EventArgs e)
        {
            if (!inputed)
            {
                MsgBox.Show("尚未輸入成績");
                return;
            }

            if (!IsValid())
            {
                return;
            }

            try
            {
                int schoolYear = int.Parse(cboSchoolYear.Text);
                int semester   = int.Parse(cboSemester.Text);
                //int gradeYear = 0;

                //SemesterScoreRecordEditor editor = new SemesterScoreRecordEditor(_student, schoolYear, semester, gradeYear);
                JHSemesterScoreRecord newRecord = new JHSemesterScoreRecord();
                newRecord.RefStudentID = _student.ID;
                newRecord.SchoolYear   = schoolYear;
                newRecord.Semester     = semester;

                K12.Data.DomainScore liter    = new K12.Data.DomainScore();
                PeriodCredit         literpc1 = new PeriodCredit();
                PeriodCredit         literpc2 = new PeriodCredit();
                literpc1.Parse(textBoxX25.Text);
                literpc2.Parse(textBoxX26.Text);
                //if (!int.TryParse(textBoxX25.Text, out literpc1))
                //    literpc1 = 0;
                //if (!int.TryParse(textBoxX26.Text, out literpc2))
                //    literpc2 = 0;
                int effort1, effort2;
                if (!int.TryParse(textBoxX17.Text, out effort1))
                {
                    effort1 = 0;
                }
                if (!int.TryParse(textBoxX18.Text, out effort2))
                {
                    effort2 = 0;
                }

                liter.Period = literpc1.Period + literpc2.Period;
                liter.Credit = literpc1.Credit + literpc2.Credit;
                liter.Domain = "語文";
                //liter.Effort = (int)((effort1 + effort2) / 2);
                liter.Effort = 1;
                decimal d;
                liter.Score = decimal.TryParse(labelX14.Text, out d) ? (decimal?)d : null;
                liter.Text  = textBoxX9.Text + " " + textBoxX10.Text;

                newRecord.Domains.Add("語文", liter);

                if (CheckDomainValid(textBoxX27, textBoxX3, textBoxX19))
                {
                    newRecord.Domains.Add("數學", GetDomainScore("語文", textBoxX27, textBoxX3, textBoxX19, textBoxX11));
                }
                if (CheckDomainValid(textBoxX28, textBoxX4, textBoxX20))
                {
                    newRecord.Domains.Add("社會", GetDomainScore("社會", textBoxX28, textBoxX4, textBoxX20, textBoxX12));
                }
                if (CheckDomainValid(textBoxX29, textBoxX5, textBoxX21))
                {
                    newRecord.Domains.Add("藝術與人文", GetDomainScore("藝術與人文", textBoxX29, textBoxX5, textBoxX21, textBoxX13));
                }
                if (CheckDomainValid(textBoxX30, textBoxX6, textBoxX22))
                {
                    newRecord.Domains.Add("自然與生活科技", GetDomainScore("自然與生活科技", textBoxX30, textBoxX6, textBoxX22, textBoxX14));
                }
                if (CheckDomainValid(textBoxX31, textBoxX7, textBoxX23))
                {
                    newRecord.Domains.Add("健康與體育", GetDomainScore("健康與體育", textBoxX31, textBoxX7, textBoxX23, textBoxX15));
                }
                if (CheckDomainValid(textBoxX32, textBoxX8, textBoxX24))
                {
                    newRecord.Domains.Add("綜合活動", GetDomainScore("綜合活動", textBoxX32, textBoxX8, textBoxX24, textBoxX16));
                }

                if (textBoxX25.Enabled)
                {
                    K12.Data.SubjectScore subject1 = new K12.Data.SubjectScore();
                    subject1.Domain  = "語文";
                    subject1.Subject = textBoxX36.Text;
                    subject1.Score   = decimal.Parse(textBoxX1.Text);
                    //subject1.Effort = int.Parse(textBoxX17.Text);
                    subject1.Effort = 1;
                    subject1.Text   = textBoxX9.Text;
                    //subject1.Period = subject1.Credit = int.Parse(textBoxX25.Text);
                    subject1.Period = literpc1.Period;
                    subject1.Credit = literpc1.Credit;
                    newRecord.Subjects.Add(subject1.Subject, subject1);
                }

                if (textBoxX26.Enabled)
                {
                    K12.Data.SubjectScore subject2 = new K12.Data.SubjectScore();
                    subject2.Domain  = "語文";
                    subject2.Subject = textBoxX37.Text;
                    subject2.Score   = decimal.Parse(textBoxX2.Text);
                    subject2.Effort  = int.Parse(textBoxX18.Text);
                    subject2.Text    = textBoxX10.Text;
                    //subject2.Period = subject2.Credit = int.Parse(textBoxX26.Text);
                    subject2.Period = literpc2.Period;
                    subject2.Credit = literpc2.Credit;
                    newRecord.Subjects.Add(subject2.Subject, subject2);
                }

                foreach (DataGridViewRow row in dgv.Rows)
                {
                    if (row.IsNewRow)
                    {
                        continue;
                    }
                    PeriodCredit pc = new PeriodCredit();
                    pc.Parse("" + row.Cells[chsPeriodCredit.Index].Value);
                    K12.Data.SubjectScore subject = new K12.Data.SubjectScore();
                    subject.Domain  = "" + row.Cells[chsDomain.Index].Value;
                    subject.Subject = "" + row.Cells[chsSubject.Index].Value;
                    subject.Period  = pc.Period;
                    subject.Credit  = pc.Credit;
                    subject.Score   = decimal.Parse("" + row.Cells[chsScore.Index].Value);
                    //subject.Effort = int.Parse("" + row.Cells[chsEffort.Index].Value);
                    subject.Effort = 1;
                    subject.Text   = "" + row.Cells[chsText.Index].Value;

                    newRecord.Subjects.Add(subject.Subject, subject);
                }

                if (!string.IsNullOrEmpty(textBoxX33.Text))
                {
                    newRecord.Domains.Add("彈性課程", GetElasticDomain());
                }
                if (!string.IsNullOrEmpty(textBoxX34.Text))
                {
                    newRecord.LearnDomainScore = decimal.Parse(textBoxX34.Text);
                }
                if (!string.IsNullOrEmpty(textBoxX35.Text))
                {
                    newRecord.CourseLearnScore = decimal.Parse(textBoxX35.Text);
                }

                JHSemesterScore.Insert(newRecord);
                SaveLog(newRecord);
            }
            catch (Exception ex)
            {
                MsgBox.Show("儲存失敗");
                this.DialogResult = DialogResult.Cancel;
                this.Close();
                return;
            }

            this.DialogResult = DialogResult.OK;
        }
        public override void InitializeImport(SmartSchool.API.PlugIn.Import.ImportWizard wizard)
        {
            Dictionary <string, int>             _ID_SchoolYear_Semester_GradeYear = new Dictionary <string, int>();
            Dictionary <string, List <string> >  _ID_SchoolYear_Semester_Subject   = new Dictionary <string, List <string> >();
            Dictionary <string, JHStudentRecord> _StudentCollection = new Dictionary <string, JHStudentRecord>();
            Dictionary <JHStudentRecord, Dictionary <int, decimal> > _StudentPassScore = new Dictionary <JHStudentRecord, Dictionary <int, decimal> >();
            Dictionary <string, List <JHSemesterScoreRecord> >       semsDict          = new Dictionary <string, List <JHSemesterScoreRecord> >();

            wizard.PackageLimit = 3000;

            //2017/6/16 穎驊新增,因應[02-02][06] 計算學期科目成績新增清空原成績模式 項目, 新增 "刪除"欄位,使使用者能匯入 刪除成績資料
            wizard.ImportableFields.AddRange("領域", "學年度", "學期", "權數", "節數", "成績", "原始成績", "補考成績", "努力程度", "文字描述", "註記", "刪除");
            //wizard.ImportableFields.AddRange("領域", "學年度", "學期", "權數", "節數", "分數評量", "文字描述", "註記");
            wizard.RequiredFields.AddRange("領域", "學年度", "學期");

            wizard.ValidateStart += delegate(object sender, SmartSchool.API.PlugIn.Import.ValidateStartEventArgs e)
            {
                #region ValidateStart
                _ID_SchoolYear_Semester_GradeYear.Clear();
                _ID_SchoolYear_Semester_Subject.Clear();
                _StudentCollection.Clear();

                List <JHStudentRecord> list = JHStudent.SelectByIDs(e.List);

                MultiThreadWorker <JHStudentRecord> loader = new MultiThreadWorker <JHStudentRecord>();
                loader.MaxThreads     = 3;
                loader.PackageSize    = 250;
                loader.PackageWorker += delegate(object sender1, PackageWorkEventArgs <JHStudentRecord> e1)
                {
                    foreach (var item in JHSemesterScore.SelectByStudents(e1.List))
                    {
                        if (!semsDict.ContainsKey(item.RefStudentID))
                        {
                            semsDict.Add(item.RefStudentID, new List <JHSchool.Data.JHSemesterScoreRecord>());
                        }
                        semsDict[item.RefStudentID].Add(item);
                    }
                };
                loader.Run(list);

                foreach (JHStudentRecord stu in list)
                {
                    if (!_StudentCollection.ContainsKey(stu.ID))
                    {
                        _StudentCollection.Add(stu.ID, stu);
                    }
                }
                #endregion
            };
            wizard.ValidateRow += delegate(object sender, SmartSchool.API.PlugIn.Import.ValidateRowEventArgs e)
            {
                #region ValidateRow
                int             t;
                decimal         d;
                JHStudentRecord student;
                if (_StudentCollection.ContainsKey(e.Data.ID))
                {
                    student = _StudentCollection[e.Data.ID];
                }
                else
                {
                    e.ErrorMessage = "壓根就沒有這個學生" + e.Data.ID;
                    return;
                }
                bool inputFormatPass = true;
                #region 驗各欄位填寫格式
                foreach (string field in e.SelectFields)
                {
                    string value = e.Data[field];
                    switch (field)
                    {
                    default:
                        break;

                    case "領域":
                        break;

                    case "權數":
                    case "節數":
                        if (value == "" || !decimal.TryParse(value, out d))
                        {
                            inputFormatPass &= false;
                            e.ErrorFields.Add(field, "必須填入數值");
                        }
                        break;

                    case "學年度":
                        if (value == "" || !int.TryParse(value, out t))
                        {
                            inputFormatPass &= false;
                            e.ErrorFields.Add(field, "必須填入學年度");
                        }
                        break;

                    case "學期":
                        if (value == "" || !int.TryParse(value, out t) || t > 2 || t < 1)
                        {
                            inputFormatPass &= false;
                            e.ErrorFields.Add(field, "必須填入1或2");
                        }
                        break;

                    case "成績":
                    case "原始成績":
                    case "補考成績":
                        if (value != "" && !decimal.TryParse(value, out d))
                        {
                            inputFormatPass &= false;
                            e.ErrorFields.Add(field, "必須填入空白或數值");
                        }
                        break;

                    case "努力程度":
                        if (value != "" && !int.TryParse(value, out t))
                        {
                            inputFormatPass &= false;
                            e.ErrorFields.Add(field, "必須填入空白或數值");
                        }
                        break;

                    case "刪除":
                        if (value != "" && value != "是")
                        {
                            inputFormatPass &= false;
                            e.ErrorFields.Add(field, "必須填入空白或 '是'");
                        }
                        break;
                    }
                }
                #endregion
                //輸入格式正確才會針對情節做檢驗
                if (inputFormatPass)
                {
                    string errorMessage = "";

                    string domain     = e.Data["領域"];
                    string schoolYear = e.Data["學年度"];
                    string semester   = e.Data["學期"];
                    int?   sy         = null;
                    int?   se         = null;
                    if (int.TryParse(schoolYear, out t))
                    {
                        sy = t;
                    }
                    if (int.TryParse(semester, out t))
                    {
                        se = t;
                    }
                    if (sy != null && se != null)
                    {
                        string key = e.Data.ID + "_" + sy + "_" + se;
                        #region 驗證重複科目資料
                        //string skey = subject + "_" + le;
                        string skey = domain;
                        if (!_ID_SchoolYear_Semester_Subject.ContainsKey(key))
                        {
                            _ID_SchoolYear_Semester_Subject.Add(key, new List <string>());
                        }
                        if (_ID_SchoolYear_Semester_Subject[key].Contains(skey))
                        {
                            errorMessage += (errorMessage == "" ? "" : "\n") + "同一學期不允許多筆相同領域的資料";
                        }
                        else
                        {
                            _ID_SchoolYear_Semester_Subject[key].Add(skey);
                        }
                        #endregion
                    }
                    e.ErrorMessage = errorMessage;
                }
                #endregion
            };

            wizard.ImportPackage += delegate(object sender, SmartSchool.API.PlugIn.Import.ImportPackageEventArgs e)
            {
                #region ImportPackage
                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 <JHSemesterScoreRecord> insertList = new List <JHSemesterScoreRecord>();
                List <JHSemesterScoreRecord> updateList = new List <JHSemesterScoreRecord>();
                //交叉比對各學生資料
                #region 交叉比對各學生資料
                foreach (string id in id_Rows.Keys)
                {
                    XmlDocument     doc        = new XmlDocument();
                    JHStudentRecord studentRec = _StudentCollection[id];
                    //該學生的學期科目成績
                    Dictionary <SemesterInfo, JHSemesterScoreRecord> semesterScoreDictionary = new Dictionary <SemesterInfo, JHSemesterScoreRecord>();
                    #region 整理現有的成績資料
                    List <JHSchool.Data.JHSemesterScoreRecord> semsList;
                    if (semsDict.ContainsKey(studentRec.ID))
                    {
                        semsList = semsDict[studentRec.ID];
                    }
                    else
                    {
                        semsList = new List <JHSchool.Data.JHSemesterScoreRecord>();
                    }
                    foreach (JHSemesterScoreRecord var in semsList)
                    {
                        SemesterInfo info = new SemesterInfo();
                        info.SchoolYear = var.SchoolYear;
                        info.Semester   = var.Semester;

                        if (!semesterScoreDictionary.ContainsKey(info))
                        {
                            semesterScoreDictionary.Add(info, var);
                        }

                        //string key = var.Subject + "_" + var.Level;
                        //if (!semesterScoreDictionary.ContainsKey(var.SchoolYear))
                        //    semesterScoreDictionary.Add(var.SchoolYear, new Dictionary<int, Dictionary<string, SemesterSubjectScoreInfo>>());
                        //if (!semesterScoreDictionary[var.SchoolYear].ContainsKey(var.Semester))
                        //    semesterScoreDictionary[var.SchoolYear].Add(var.Semester, new Dictionary<string, SemesterSubjectScoreInfo>());
                        //if (!semesterScoreDictionary[var.SchoolYear][var.Semester].ContainsKey(key))
                        //    semesterScoreDictionary[var.SchoolYear][var.Semester].Add(key, var);
                    }
                    #endregion

                    //要匯入的學期科目成績
                    Dictionary <SemesterInfo, Dictionary <string, RowData> > semesterImportScoreDictionary = new Dictionary <SemesterInfo, Dictionary <string, RowData> >();

                    #region 整理要匯入的資料
                    foreach (RowData row in id_Rows[id])
                    {
                        string domain     = row["領域"];
                        string schoolYear = row["學年度"];
                        string semester   = row["學期"];
                        int    sy         = int.Parse(schoolYear);
                        int    se         = int.Parse(semester);

                        SemesterInfo info = new SemesterInfo();
                        info.SchoolYear = sy;
                        info.Semester   = se;

                        if (!semesterImportScoreDictionary.ContainsKey(info))
                        {
                            semesterImportScoreDictionary.Add(info, new Dictionary <string, RowData>());
                        }
                        if (!semesterImportScoreDictionary[info].ContainsKey(domain))
                        {
                            semesterImportScoreDictionary[info].Add(domain, row);
                        }
                    }
                    #endregion

                    //學期年級重整
                    //Dictionary<SemesterInfo, int> semesterGradeYear = new Dictionary<SemesterInfo, int>();
                    //要變更成績的學期
                    List <SemesterInfo> updatedSemester = new List <SemesterInfo>();
                    //在變更學期中新增加的成績資料
                    Dictionary <SemesterInfo, List <RowData> > updatedNewSemesterScore = new Dictionary <SemesterInfo, List <RowData> >();
                    //要增加成績的學期
                    Dictionary <SemesterInfo, List <RowData> > insertNewSemesterScore = new Dictionary <SemesterInfo, List <RowData> >();
                    //開始處理ImportScore
                    #region 開始處理ImportScore
                    foreach (SemesterInfo info in semesterImportScoreDictionary.Keys)
                    {
                        foreach (string domain in semesterImportScoreDictionary[info].Keys)
                        {
                            RowData data = semesterImportScoreDictionary[info][domain];
                            //如果是本來沒有這筆學期的成績就加到insertNewSemesterScore
                            if (!semesterScoreDictionary.ContainsKey(info))
                            {
                                if (!insertNewSemesterScore.ContainsKey(info))
                                {
                                    insertNewSemesterScore.Add(info, new List <RowData>());
                                }
                                insertNewSemesterScore[info].Add(data);
                            }
                            else
                            {
                                bool hasChanged = false;
                                //修改已存在的資料
                                if (semesterScoreDictionary[info].Domains.ContainsKey(domain))
                                {
                                    JHSemesterScoreRecord record = semesterScoreDictionary[info];

                                    #region 直接修改已存在的成績資料的Detail
                                    foreach (string field in e.ImportFields)
                                    {
                                        K12.Data.DomainScore score = record.Domains[domain];
                                        string value = data[field];
                                        //"分數評量", "努力程度", "文字描述", "註記"
                                        switch (field)
                                        {
                                        default:
                                            break;

                                        case "領域":
                                            if (score.Domain != value)
                                            {
                                                score.Domain = value;
                                                hasChanged   = true;
                                            }
                                            break;

                                        case "權數":
                                            if ("" + score.Credit != value)
                                            {
                                                score.Credit = decimal.Parse(value);
                                                hasChanged   = true;
                                            }
                                            break;

                                        case "節數":
                                            if ("" + score.Period != value)
                                            {
                                                score.Period = decimal.Parse(value);
                                                hasChanged   = true;
                                            }
                                            break;

                                        //case "成績年級":
                                        //    int gy = int.Parse(data["成績年級"]);
                                        //    if (record.GradeYear != gy)
                                        //    {
                                        //        semesterGradeYear[info] = gy;
                                        //        hasChanged = true;
                                        //    }
                                        //    break;
                                        case "成績":
                                            if ("" + score.Score != value)
                                            {
                                                decimal d;
                                                if (decimal.TryParse(value, out d))
                                                {
                                                    score.Score = d;
                                                }
                                                else
                                                {
                                                    score.Score = null;
                                                }
                                                hasChanged = true;
                                            }
                                            break;

                                        case "原始成績":
                                            if ("" + score.ScoreOrigin != value)
                                            {
                                                decimal d;
                                                if (decimal.TryParse(value, out d))
                                                {
                                                    score.ScoreOrigin = d;
                                                }
                                                else
                                                {
                                                    score.ScoreOrigin = null;
                                                }
                                                hasChanged = true;
                                            }
                                            break;

                                        case "補考成績":
                                            if ("" + score.ScoreMakeup != value)
                                            {
                                                decimal d;
                                                if (decimal.TryParse(value, out d))
                                                {
                                                    score.ScoreMakeup = d;
                                                }
                                                else
                                                {
                                                    score.ScoreMakeup = null;
                                                }
                                                hasChanged = true;
                                            }
                                            break;

                                        case "努力程度":
                                            if ("" + score.Effort != value)
                                            {
                                                int i;
                                                if (int.TryParse(value, out i))
                                                {
                                                    score.Effort = i;
                                                }
                                                else
                                                {
                                                    score.Effort = null;
                                                }
                                                hasChanged = true;
                                            }
                                            break;

                                        case "文字描述":
                                            if ("" + score.Text != value)
                                            {
                                                score.Text = value;
                                                hasChanged = true;
                                            }
                                            break;

                                        case "註記":
                                            if (score.Comment != value)
                                            {
                                                score.Comment = value;
                                                hasChanged    = true;
                                            }
                                            break;

                                        case "刪除":
                                            if (value == "是")
                                            {
                                                record.Domains.Remove(domain);
                                                hasChanged = true;
                                            }
                                            break;
                                        }
                                    }
                                    //}
                                    #endregion
                                }
                                else//加入新成績至已存在的學期
                                {
                                    //加入新成績至已存在的學期
                                    if (!updatedNewSemesterScore.ContainsKey(info))
                                    {
                                        updatedNewSemesterScore.Add(info, new List <RowData>());
                                    }
                                    updatedNewSemesterScore[info].Add(data);
                                    hasChanged = true;
                                }
                                //真的有變更
                                if (hasChanged)
                                {
                                    #region 登錄有變更的學期
                                    if (!updatedSemester.Contains(info))
                                    {
                                        updatedSemester.Add(info);
                                    }
                                    #endregion
                                }
                            }
                        }
                    }
                    #endregion
                    //處理已登錄要更新的學期成績
                    #region 處理已登錄要更新的學期成績
                    foreach (SemesterInfo info in updatedSemester)
                    {
                        //Dictionary<int, Dictionary<int, string>> semeScoreID = (Dictionary<int, Dictionary<int, string>>)studentRec.Fields["SemesterSubjectScoreID"];
                        //string semesterScoreID = semeScoreID[sy][se];//從學期抓ID
                        //int gradeyear = semesterGradeYear[info];//抓年級
                        //XmlElement subjectScoreInfo = doc.CreateElement("SemesterSubjectScoreInfo");
                        #region 產生該學期科目成績的XML
                        //foreach (SemesterSubjectScoreInfo scoreInfo in semesterScoreDictionary[sy][se].Values)
                        //{
                        //    subjectScoreInfo.AppendChild(doc.ImportNode(scoreInfo.Detail, true));
                        //}

                        updateList.Add(semesterScoreDictionary[info]);

                        //if (updatedNewSemesterScore.ContainsKey(sy) && updatedNewSemesterScore[sy].ContainsKey(se))
                        if (updatedNewSemesterScore.ContainsKey(info))
                        {
                            foreach (RowData row in updatedNewSemesterScore[info])
                            {
                                //XmlElement newScore = doc.CreateElement("Subject");
                                JHSemesterScoreRecord record      = semesterScoreDictionary[info];
                                K12.Data.DomainScore  domainScore = null;

                                string domain = row["領域"];
                                domainScore = new K12.Data.DomainScore();

                                bool contain_deleted_words = false;

                                #region 建立newScore
                                foreach (string field in new string[] { "領域", "科目", "權數", "節數", "成績", "原始成績", "補考成績", "努力程度", "文字描述", "註記", "刪除" })
                                {
                                    if (e.ImportFields.Contains(field))
                                    {
                                        #region 填入領域資訊
                                        string value = row[field];
                                        switch (field)
                                        {
                                        default:
                                            break;

                                        case "領域":
                                            domainScore.Domain = value;
                                            break;

                                        case "權數":
                                            domainScore.Credit = decimal.Parse(value);
                                            break;

                                        case "節數":
                                            domainScore.Period = decimal.Parse(value);
                                            break;

                                        case "成績":
                                            decimal d;
                                            if (decimal.TryParse(value, out d))
                                            {
                                                domainScore.Score = d;
                                            }
                                            else
                                            {
                                                domainScore.Score = null;
                                            }
                                            break;

                                        case "原始成績":
                                            decimal d1;
                                            if (decimal.TryParse(value, out d1))
                                            {
                                                domainScore.ScoreOrigin = d1;
                                            }
                                            else
                                            {
                                                domainScore.ScoreOrigin = null;
                                            }
                                            break;

                                        case "補考成績":
                                            decimal d2;
                                            if (decimal.TryParse(value, out d2))
                                            {
                                                domainScore.ScoreMakeup = d2;
                                            }
                                            else
                                            {
                                                domainScore.ScoreMakeup = null;
                                            }
                                            break;

                                        case "努力程度":
                                            int i;
                                            if (int.TryParse(value, out i))
                                            {
                                                domainScore.Effort = i;
                                            }
                                            else
                                            {
                                                domainScore.Effort = null;
                                            }
                                            break;

                                        case "文字描述":
                                            domainScore.Text = value;
                                            break;

                                        case "註記":
                                            domainScore.Comment = value;
                                            break;

                                        case "刪除":
                                            if (value == "是")
                                            {
                                                contain_deleted_words = true;
                                            }
                                            break;
                                        }
                                        #endregion
                                    }
                                }
                                #endregion
                                //}
                                //subjectScoreInfo.AppendChild(newScore);

                                if (!contain_deleted_words)
                                {
                                    if (domainScore != null)
                                    {
                                        if (!record.Domains.ContainsKey(domainScore.Domain))
                                        {
                                            record.Domains.Add(domainScore.Domain, domainScore);
                                        }
                                        else
                                        {
                                            record.Domains[domainScore.Domain] = domainScore;
                                        }
                                    }
                                    updateList.Add(record);
                                }
                            }
                        }
                        #endregion
                        //updateList.Add(new SmartSchool.Feature.Score.EditScore.UpdateInfo(semesterScoreID, gradeyear, subjectScoreInfo));
                    }
                    #endregion
                    //處理新增成績學期
                    #region 處理新增成績學期
                    foreach (SemesterInfo info in insertNewSemesterScore.Keys)
                    {
                        //int gradeyear = semesterGradeYear[info];//抓年級
                        foreach (RowData row in insertNewSemesterScore[info])
                        {
                            JHSemesterScoreRecord record      = new JHSchool.Data.JHSemesterScoreRecord();
                            K12.Data.DomainScore  domainScore = null;

                            bool contain_deleted_words = false;

                            string domain = row["領域"];
                            domainScore = new K12.Data.DomainScore();
                            foreach (string field in new string[] { "領域", "科目", "權數", "節數", "成績", "原始成績", "補考成績", "努力程度", "文字描述", "註記", "刪除" })
                            {
                                if (e.ImportFields.Contains(field))
                                {
                                    #region 填入領域資訊
                                    string value = row[field];
                                    switch (field)
                                    {
                                    default: break;

                                    case "領域":
                                        domainScore.Domain = value;
                                        break;

                                    case "權數":
                                        domainScore.Credit = decimal.Parse(value);
                                        break;

                                    case "節數":
                                        domainScore.Period = decimal.Parse(value);
                                        break;

                                    case "成績":
                                        decimal d;
                                        if (decimal.TryParse(value, out d))
                                        {
                                            domainScore.Score = d;
                                        }
                                        else
                                        {
                                            domainScore.Score = null;
                                        }
                                        break;

                                    case "原始成績":
                                        decimal d1;
                                        if (decimal.TryParse(value, out d1))
                                        {
                                            domainScore.ScoreOrigin = d1;
                                        }
                                        else
                                        {
                                            domainScore.ScoreOrigin = null;
                                        }
                                        break;

                                    case "補考成績":
                                        decimal d2;
                                        if (decimal.TryParse(value, out d2))
                                        {
                                            domainScore.ScoreMakeup = d2;
                                        }
                                        else
                                        {
                                            domainScore.ScoreMakeup = null;
                                        }
                                        break;

                                    case "努力程度":
                                        int i;
                                        if (int.TryParse(value, out i))
                                        {
                                            domainScore.Effort = i;
                                        }
                                        else
                                        {
                                            domainScore.Effort = null;
                                        }
                                        break;

                                    case "文字描述":
                                        domainScore.Text = value;
                                        break;

                                    case "註記":
                                        domainScore.Comment = value;
                                        break;

                                    case "刪除":
                                        if (value == "是")
                                        {
                                            contain_deleted_words = true;
                                        }
                                        break;
                                    }
                                    #endregion
                                }
                            }
                            //}
                            //subjectScoreInfo.AppendChild(newScore);
                            record.SchoolYear   = info.SchoolYear;
                            record.Semester     = info.Semester;
                            record.RefStudentID = studentRec.ID;
                            //record.GradeYear = gradeyear;

                            if (domainScore != null)
                            {
                                if (!record.Domains.ContainsKey(domainScore.Domain))
                                {
                                    record.Domains.Add(domainScore.Domain, domainScore);
                                }
                                else
                                {
                                    record.Domains[domainScore.Domain] = domainScore;
                                }
                            }

                            if (!contain_deleted_words)
                            {
                                insertList.Add(record);
                            }
                        }
                        //insertList.Add(new SmartSchool.Feature.Score.AddScore.InsertInfo(studentRec.StudentID, "" + sy, "" + se, gradeyear, "", subjectScoreInfo));
                    }
                    #endregion
                }
                #endregion

                Dictionary <string, JHSemesterScoreRecord> iList = new Dictionary <string, JHSemesterScoreRecord>();
                Dictionary <string, JHSemesterScoreRecord> uList = new Dictionary <string, JHSemesterScoreRecord>();

                foreach (var record in insertList)
                {
                    string key = record.RefStudentID + "_" + record.SchoolYear + "_" + record.Semester;
                    if (!iList.ContainsKey(key))
                    {
                        iList.Add(key, new JHSchool.Data.JHSemesterScoreRecord());
                    }
                    JHSchool.Data.JHSemesterScoreRecord newRecord = iList[key];
                    newRecord.RefStudentID = record.RefStudentID;
                    newRecord.SchoolYear   = record.SchoolYear;
                    newRecord.Semester     = record.Semester;

                    foreach (var domain in record.Domains.Keys)
                    {
                        if (!newRecord.Domains.ContainsKey(domain))
                        {
                            newRecord.Domains.Add(domain, record.Domains[domain]);
                        }
                    }
                    if (record.CourseLearnScore.HasValue)
                    {
                        newRecord.CourseLearnScore = record.CourseLearnScore;
                    }
                    if (record.LearnDomainScore.HasValue)
                    {
                        newRecord.LearnDomainScore = record.LearnDomainScore;
                    }

                    if (record.CourseLearnScoreOrigin.HasValue)
                    {
                        newRecord.CourseLearnScoreOrigin = record.CourseLearnScoreOrigin;
                    }
                    if (record.LearnDomainScoreOrigin.HasValue)
                    {
                        newRecord.LearnDomainScoreOrigin = record.LearnDomainScoreOrigin;
                    }
                }

                foreach (var record in updateList)
                {
                    string key = record.RefStudentID + "_" + record.SchoolYear + "_" + record.Semester;
                    if (!uList.ContainsKey(key))
                    {
                        uList.Add(key, new JHSemesterScoreRecord());
                    }
                    JHSemesterScoreRecord newRecord = uList[key];
                    newRecord.RefStudentID = record.RefStudentID;
                    newRecord.SchoolYear   = record.SchoolYear;
                    newRecord.Semester     = record.Semester;
                    newRecord.ID           = record.ID;

                    foreach (var domain in record.Domains.Keys)
                    {
                        if (!newRecord.Domains.ContainsKey(domain))
                        {
                            newRecord.Domains.Add(domain, record.Domains[domain]);
                        }
                    }
                    if (record.CourseLearnScore.HasValue)
                    {
                        newRecord.CourseLearnScore = record.CourseLearnScore;
                    }
                    if (record.LearnDomainScore.HasValue)
                    {
                        newRecord.LearnDomainScore = record.LearnDomainScore;
                    }

                    if (record.CourseLearnScoreOrigin.HasValue)
                    {
                        newRecord.CourseLearnScoreOrigin = record.CourseLearnScoreOrigin;
                    }
                    if (record.LearnDomainScoreOrigin.HasValue)
                    {
                        newRecord.LearnDomainScoreOrigin = record.LearnDomainScoreOrigin;
                    }
                }

                List <string> ids = new List <string>(id_Rows.Keys);
                Dictionary <string, JHSemesterScoreRecord> origs = new Dictionary <string, JHSemesterScoreRecord>();
                foreach (var record in JHSemesterScore.SelectByStudentIDs(ids))
                {
                    if (!origs.ContainsKey(record.ID))
                    {
                        origs.Add(record.ID, record);
                    }
                }
                foreach (var record in uList.Values)
                {
                    if (origs.ContainsKey(record.ID))
                    {
                        foreach (var subject in origs[record.ID].Subjects.Keys)
                        {
                            if (!record.Subjects.ContainsKey(subject))
                            {
                                record.Subjects.Add(subject, origs[record.ID].Subjects[subject]);
                            }
                        }
                    }
                }

                JHSemesterScore.Insert(new List <JHSemesterScoreRecord>(iList.Values));

                JHSemesterScore.Update(new List <JHSemesterScoreRecord>(uList.Values));

                FISCA.LogAgent.ApplicationLog.Log("成績系統.匯入匯出", "匯入學期領域成績", "總共匯入" + (insertList.Count + updateList.Count) + "筆學期領域成績。");
                #endregion
            };
            wizard.ImportComplete += delegate
            {
                MsgBox.Show("匯入完成");
            };
        }
Ejemplo n.º 10
0
 public RDomainScore(K12.Data.DomainScore score)
 {
     Name  = score.Domain;
     Score = score.Score;
 }