private void UploadWorker_DoWork(object sender, DoWorkEventArgs e)
        {
            List <JHSemesterScoreRecord> list = e.Argument as List <JHSemesterScoreRecord>;
            int total = list.Count;

            if (total == 0)
            {
                return;
            }
            int count = 0;

            foreach (JHSemesterScoreRecord record in list)
            {
                count++;
                //editor.Save();
                if (string.IsNullOrEmpty(record.ID))
                {
                    JHSemesterScore.Insert(record);
                }
                else
                {
                    JHSemesterScore.Update(record);
                }

                _upload_worker.ReportProgress((int)((double)count * 100 / (double)total), "上傳學期成績…");
            }
        }
Esempio n. 2
0
        private void insertSemesterSubjectScore(object item)
        {
            List <List <JHSemesterScoreRecord> > insertPackages = (List <List <JHSemesterScoreRecord> >)item;

            foreach (List <JHSemesterScoreRecord> package in insertPackages)
            {
                JHSemesterScore.Insert(package);
            }
        }
Esempio n. 3
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;
        }
Esempio n. 4
0
        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;
            //wizard.ImportableFields.AddRange("領域", "科目", "學年度", "學期", "權數", "節數", "分數評量", "努力程度", "文字描述", "註記");
            //wizard.ImportableFields.AddRange("領域", "科目", "學年度", "學期", "權數", "節數", "分數評量", "文字描述", "註記");

            //2015.1.27 Cloud新增
            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 "領域":
                        //if (value == "")
                        //{
                        //    inputFormatPass &= false;
                        //    e.ErrorFields.Add(field, "必須填寫");
                        //}
                        //else if (!Domains.Contains(value))
                        //{
                        //    inputFormatPass &= false;
                        //    e.ErrorFields.Add(field, "必須為七大領域");
                        //}
                        break;

                    case "科目":
                        if (value == "")
                        {
                            inputFormatPass &= false;
                            e.ErrorFields.Add(field, "必須填寫");
                        }
                        break;

                    case "學年度":
                        if (value == "" || !int.TryParse(value, out t))
                        {
                            inputFormatPass &= false;
                            e.ErrorFields.Add(field, "必須填入學年度");
                        }
                        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 "分數評量":
                    //    if (value != "" && !decimal.TryParse(value, out d))
                    //    {
                    //        inputFormatPass &= false;
                    //        e.ErrorFields.Add(field, "必須填入空白或數值");
                    //    }
                    //    break;
                    case "成績":
                        if (value != "" && !decimal.TryParse(value, out d))
                        {
                            inputFormatPass &= false;
                            e.ErrorFields.Add(field, "必須填入空白或數值");
                        }
                        break;

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

                    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;
                    }
                }
                #endregion
                //輸入格式正確才會針對情節做檢驗
                if (inputFormatPass)
                {
                    string errorMessage = "";

                    string subject    = 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 驗證新增科目成績
                        List <JHSemesterScoreRecord> semsList;
                        if (semsDict.ContainsKey(student.ID))
                        {
                            semsList = semsDict[student.ID];
                        }
                        else
                        {
                            semsList = new List <JHSemesterScoreRecord>();
                        }
                        foreach (JHSemesterScoreRecord record in semsList)
                        {
                            if (record.SchoolYear != sy)
                            {
                                continue;
                            }
                            if (record.Semester != se)
                            {
                                continue;
                            }

                            bool   isNewSubjectInfo = true;
                            string message          = "";
                            foreach (K12.Data.SubjectScore s in record.Subjects.Values)
                            {
                                if (s.Subject == subject)
                                {
                                    isNewSubjectInfo = false;
                                }
                            }
                            if (isNewSubjectInfo)
                            {
                                if (!e.WarningFields.ContainsKey("查無此科目"))
                                {
                                    e.WarningFields.Add("查無此科目", "學生在此學期並無此筆科目成績資訊,將會新增此科目成績");
                                }
                                foreach (string field in new string[] { "領域", "科目", "學年度", "學期", "權數", "節數" })
                                {
                                    if (!e.SelectFields.Contains(field))
                                    {
                                        message += (message == "" ? "發現此學期無此科目,\n將會新增成績\n缺少成績必要欄位" : "、") + field;
                                    }
                                }
                                if (message != "")
                                {
                                    errorMessage += (errorMessage == "" ? "" : "\n") + message;
                                }
                            }
                        }
                        #endregion
                        #region 驗證重複科目資料
                        //string skey = subject + "_" + le;
                        string skey = subject;
                        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])
                    {
                        int    t;
                        string subject    = 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(subject))
                        {
                            semesterImportScoreDictionary[info].Add(subject, 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 subject in semesterImportScoreDictionary[info].Keys)
                        {
                            RowData data = semesterImportScoreDictionary[info][subject];
                            //如果是本來沒有這筆學期的成績就加到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].Subjects.ContainsKey(subject))
                                {
                                    JHSemesterScoreRecord record = semesterScoreDictionary[info];

                                    #region 直接修改已存在的成績資料的Detail
                                    foreach (string field in e.ImportFields)
                                    {
                                        K12.Data.SubjectScore score = record.Subjects[subject];
                                        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.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;
                                        }
                                    }
                                    #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");
                                K12.Data.SubjectScore subjectScore = new K12.Data.SubjectScore();
                                #region 建立newScore
                                //foreach (string field in new string[] { "領域", "科目", "權數", "節數", "分數評量", "努力程度", "文字描述", "註記" })
                                //foreach (string field in new string[] { "領域", "科目", "權數", "節數", "分數評量", "文字描述", "註記" })
                                foreach (string field in new string[] { "領域", "科目", "權數", "節數", "成績", "原始成績", "補考成績", "文字描述", "註記" })
                                {
                                    if (e.ImportFields.Contains(field))
                                    {
                                        decimal d;

                                        #region 填入科目資訊
                                        string value = row[field];
                                        switch (field)
                                        {
                                        default:
                                            break;

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

                                        case "科目":
                                            subjectScore.Subject = value;
                                            break;

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

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

                                        //case "分數評量":
                                        //    decimal d;
                                        //    if (decimal.TryParse(value, out d))
                                        //        subjectScore.Score = d;
                                        //    else
                                        //        subjectScore.Score = null;
                                        //    break;
                                        case "成績":
                                            if (decimal.TryParse(value, out d))
                                            {
                                                subjectScore.Score = d;
                                            }
                                            else
                                            {
                                                subjectScore.Score = null;
                                            }
                                            break;

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

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

                                        //case "努力程度":
                                        //    int i;
                                        //    if (int.TryParse(value, out i))
                                        //        subjectScore.Effort = i;
                                        //    else
                                        //        subjectScore.Effort = null;
                                        //    break;
                                        case "文字描述":
                                            subjectScore.Text = value;
                                            break;

                                        case "註記":
                                            subjectScore.Comment = value;
                                            break;
                                        }
                                        #endregion
                                    }
                                }
                                #endregion
                                //subjectScoreInfo.AppendChild(newScore);
                                JHSemesterScoreRecord record = semesterScoreDictionary[info];
                                if (!record.Subjects.ContainsKey(subjectScore.Subject))
                                {
                                    record.Subjects.Add(subjectScore.Subject, subjectScore);
                                }
                                else
                                {
                                    record.Subjects[subjectScore.Subject] = subjectScore;
                                }

                                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])
                        {
                            K12.Data.SubjectScore subjectScore = new K12.Data.SubjectScore();
                            //foreach (string field in new string[] { "領域", "科目", "權數", "節數", "分數評量", "努力程度", "文字描述", "註記" })
                            //foreach (string field in new string[] { "領域", "科目", "權數", "節數", "分數評量", "文字描述", "註記" })
                            foreach (string field in new string[] { "領域", "科目", "權數", "節數", "成績", "原始成績", "補考成績", "文字描述", "註記" })
                            {
                                if (e.ImportFields.Contains(field))
                                {
                                    decimal d;

                                    string value = row[field];
                                    switch (field)
                                    {
                                    default: break;

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

                                    case "科目":
                                        subjectScore.Subject = value;
                                        break;

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

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

                                    //case "分數評量":
                                    //    decimal d;
                                    //    if (decimal.TryParse(value, out d))
                                    //        subjectScore.Score = d;
                                    //    else
                                    //        subjectScore.Score = null;
                                    //    break;
                                    case "成績":
                                        if (decimal.TryParse(value, out d))
                                        {
                                            subjectScore.Score = d;
                                        }
                                        else
                                        {
                                            subjectScore.Score = null;
                                        }
                                        break;

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

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

                                    //case "努力程度":
                                    //    int i;
                                    //    if (int.TryParse(value, out i))
                                    //        subjectScore.Effort = i;
                                    //    else
                                    //        subjectScore.Effort = null;
                                    //    break;
                                    case "文字描述":
                                        subjectScore.Text = value;
                                        break;

                                    case "註記":
                                        subjectScore.Comment = value;
                                        break;
                                    }
                                }
                            }
                            //subjectScoreInfo.AppendChild(newScore);
                            JHSemesterScoreRecord record = new JHSemesterScoreRecord();
                            record.SchoolYear   = info.SchoolYear;
                            record.Semester     = info.Semester;
                            record.RefStudentID = studentRec.ID;
                            //record.GradeYear = gradeyear;

                            if (!record.Subjects.ContainsKey(subjectScore.Subject))
                            {
                                record.Subjects.Add(subjectScore.Subject, subjectScore);
                            }
                            else
                            {
                                record.Subjects[subjectScore.Subject] = subjectScore;
                            }

                            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 JHSemesterScoreRecord());
                    }
                    JHSemesterScoreRecord newRecord = iList[key];
                    newRecord.RefStudentID = record.RefStudentID;
                    newRecord.SchoolYear   = record.SchoolYear;
                    newRecord.Semester     = record.Semester;

                    foreach (var subject in record.Subjects.Keys)
                    {
                        if (!newRecord.Subjects.ContainsKey(subject))
                        {
                            newRecord.Subjects.Add(subject, record.Subjects[subject]);
                        }
                    }
                }

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

                    foreach (var subject in record.Subjects.Keys)
                    {
                        if (!newRecord.Subjects.ContainsKey(subject))
                        {
                            newRecord.Subjects.Add(subject, record.Subjects[subject]);
                        }
                    }
                }

                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 domain in origs[record.ID].Domains.Keys)
                        {
                            if (!record.Domains.ContainsKey(domain))
                            {
                                record.Domains.Add(domain, origs[record.ID].Domains[domain]);
                            }
                        }
                    }
                }

                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("匯入完成");
            };
        }
Esempio n. 5
0
        private void btnSave_Click(object sender, EventArgs e)
        {
            if (!inputed)
            {
                MsgBox.Show("尚未輸入成績");
                return;
            }

            // 驗證所有權數欄位
            ValidAllPCTextBox();

            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;

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

                // 檢查科目名稱是否相同,因為科目名稱重複會造成新增錯誤,科目名稱是唯一值。
                foreach (DataGridViewRow row in dgv.Rows)
                {
                    if (row.Cells[chsSubject.Index].Value != null)
                    {
                        string tmpSubjName = "" + row.Cells[chsSubject.Index].Value;
                        if (checkSubjName.Contains(tmpSubjName))
                        {
                            FISCA.Presentation.Controls.MsgBox.Show("科目名稱重複,無法儲存。");
                            return;
                        }
                        else
                        {
                            checkSubjName.Add(tmpSubjName);
                        }
                    }
                }

                //2018/4/16 穎驊因應高雄項目[02-03][06]學期成績,快速新增功能如無原始成績,則結算學期領域成績時快速新增的成績都會變成"0"分
                // 新增原始成績登錄、語文領域,另外看來以前不流行 datagridView 這土法煉鋼有點驚人呀!!。

                //2018/5/22 穎驊再次註解,恩正說不必新增原始成績欄位給屬用者輸入,直接抓分數就好,所以將上一版的輸入格拿掉

                if (CheckDomainValid(txtPC1, txtScore1, txtScore1, txtEffort1))
                {
                    newRecord.Domains.Add("國語文", GetDomainScore("國語文", txtPC1, txtScore1, txtScore1, txtEffort1, txtText1));
                }
                if (CheckDomainValid(txtPC2, txtScore2, txtScore2, txtEffort2))
                {
                    newRecord.Domains.Add("英語", GetDomainScore("英語", txtPC2, txtScore2, txtScore2, txtEffort2, txtText2));
                }
                if (CheckDomainValid(txtPC3, txtScore3, txtScore3, txtEffort3))
                {
                    newRecord.Domains.Add("數學", GetDomainScore("數學", txtPC3, txtScore3, txtScore3, txtEffort3, txtText3));
                }
                if (CheckDomainValid(txtPC4, txtScore4, txtScore4, txtEffort4))
                {
                    newRecord.Domains.Add("社會", GetDomainScore("社會", txtPC4, txtScore4, txtScore4, txtEffort4, txtText4));
                }
                //if (CheckDomainValid(txtPC5, txtScore5, txtScore5, txtEffort5))
                //    newRecord.Domains.Add("藝術與人文", GetDomainScore("藝術與人文", txtPC5, txtScore5, txtScore5, txtEffort5, txtText5));
                //if (CheckDomainValid(txtPC6, txtScore6, txtScore6, txtEffort6))
                //    newRecord.Domains.Add("自然與生活科技", GetDomainScore("自然與生活科技", txtPC6, txtScore6, txtScore6, txtEffort6, txtText6));
                if (CheckDomainValid(txtPC5, txtScore5, txtScore5, txtEffort5))
                {
                    newRecord.Domains.Add("自然科學", GetDomainScore("自然科學", txtPC5, txtScore5, txtScore5, txtEffort5, txtText5));
                }
                if (CheckDomainValid(txtPC6, txtScore6, txtScore6, txtEffort6))
                {
                    newRecord.Domains.Add("藝術", GetDomainScore("藝術", txtPC6, txtScore6, txtScore6, txtEffort6, txtText6));
                }
                if (CheckDomainValid(txtPC7, txtScore7, txtScore7, txtEffort7))
                {
                    newRecord.Domains.Add("健康與體育", GetDomainScore("健康與體育", txtPC7, txtScore7, txtScore7, txtEffort7, txtText7));
                }
                if (CheckDomainValid(txtPC8, txtScore8, txtScore8, txtEffort8))
                {
                    newRecord.Domains.Add("綜合活動", GetDomainScore("綜合活動", txtPC8, txtScore8, txtScore8, txtEffort8, txtText8));
                }
                if (CheckDomainValid(txtPC9, txtScore9, txtScore9, txtEffort9))
                {
                    newRecord.Domains.Add("語文", GetDomainScore("語文", txtPC9, txtScore9, txtScore9, txtEffort9, txtText9));
                }
                if (CheckDomainValid(txtPC10, txtScore10, txtScore10, txtEffort10))
                {
                    newRecord.Domains.Add("科技", GetDomainScore("科技", txtPC10, txtScore10, txtScore10, txtEffort10, txtText10));
                }

                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.ScoreOrigin = decimal.Parse("" + row.Cells[chsScore.Index].Value); // 2018/5/22 穎華聽從恩正建議,原始成績直接抓取成績即可
                    subject.Effort      = int.Parse("" + row.Cells[chsEffort.Index].Value);
                    subject.Text        = "" + row.Cells[chsText.Index].Value;

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

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

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

            this.DialogResult = DialogResult.OK;
        }
        public void Save()
        {
            List <JHSemesterScoreRecord> addSemsScore      = new List <JHSemesterScoreRecord>();
            List <JHSemesterScoreRecord> updateSemsScore   = new List <JHSemesterScoreRecord>();
            SubjectScoreLogFormater      subjLogFormater   = new SubjectScoreLogFormater();
            DomainScoreLogFormater       domainLogFormater = new DomainScoreLogFormater();

            foreach (StudentScore student in Students)
            {
                #region 決定要新增還是更新。
                JHSemesterScoreRecord JHScore = GetJHSemesterScore(student.Id, student.SemestersScore[SemesterData.Empty]);
                SCSemsScore           SCScore = student.SemestersScore[SemesterData.Empty];

                if (string.IsNullOrEmpty(JHScore.ID))
                {
                    addSemsScore.Add(JHScore);
                }
                else
                {
                    updateSemsScore.Add(JHScore);
                }
                #endregion

                #region 產生科目資料。
                JHScore.Subjects.Clear();
                foreach (string strSubject in SCScore.Subject)
                {
                    SemesterSubjectScore objSCSubject = SCScore.Subject[strSubject];
                    SubjectScore         objJHSubject = GetJHSubjectScore(strSubject, objSCSubject);
                    LogData subjLog = new LogData(strSubject);
                    subjLog.Formater = subjLogFormater;

                    decimal?score = objSCSubject.Value.HasValue ? (decimal?)(double)objSCSubject.Value : null;

                    //記錄 Log
                    subjLog.Add(new LogData("成績", objJHSubject.Score + "", score.ToString()));
                    subjLog.Add(new LogData("權重", objJHSubject.Credit + "", objSCSubject.Weight + ""));
                    subjLog.Add(new LogData("節數", objJHSubject.Period + "", objSCSubject.Period + ""));
                    if (Program.Mode == ModuleMode.KaoHsiung)
                    {
                        subjLog.Add(new LogData("努力程度", objJHSubject.Effort + "", objSCSubject.Effort + ""));
                    }
                    subjLog.Add(new LogData("文字評量", objJHSubject.Text + "", objSCSubject.Text));
                    subjLog.Add(new LogData("領域", objJHSubject.Domain + "", objSCSubject.Domain));
                    SCScore.Subject.Log.Add(subjLog);

                    objJHSubject.Score  = score;
                    objJHSubject.Credit = objSCSubject.Weight;
                    objJHSubject.Period = objSCSubject.Period;
                    objJHSubject.Effort = objSCSubject.Effort;
                    objJHSubject.Text   = objSCSubject.Text;
                    objJHSubject.Domain = objSCSubject.Domain;

                    JHScore.Subjects.Add(strSubject, objJHSubject);
                }

                //排序科目名稱。
                Dictionary <string, SubjectScore> orderSubject = new Dictionary <string, SubjectScore>(JHScore.Subjects);
                JHScore.Subjects.Clear();
                foreach (string subjName in Util.SortSubjectDomain(orderSubject.Keys))
                {
                    JHScore.Subjects.Add(subjName, orderSubject[subjName]);
                }
                #endregion

                #region 產生領域資料。
                JHScore.Domains.Clear();
                foreach (string strDomain in SCScore.Domain)
                {
                    //彈性課程不記錄領域領域。
                    if (Util.IsVariableDomain(strDomain))
                    {
                        continue;
                    }

                    SemesterDomainScore objSCDomain = SCScore.Domain[strDomain];
                    DomainScore         objJHDomain = GetJHDomainScore(strDomain, objSCDomain);
                    LogData             domainLog   = new LogData(strDomain);
                    domainLog.Formater = subjLogFormater;

                    decimal?score = objSCDomain.Value.HasValue ? (decimal?)(double)objSCDomain.Value : null;

                    //記錄 Log
                    domainLog.Add(new LogData("成績", objJHDomain.Score + "", score + ""));
                    domainLog.Add(new LogData("權重", objJHDomain.Credit + "", objSCDomain.Weight + ""));
                    domainLog.Add(new LogData("節數", objJHDomain.Period + "", objSCDomain.Period + ""));
                    if (Program.Mode == ModuleMode.KaoHsiung)
                    {
                        domainLog.Add(new LogData("努力程度", objJHDomain.Effort + "", objSCDomain.Effort + ""));
                    }
                    domainLog.Add(new LogData("文字評量", objJHDomain.Text + "", objSCDomain.Text));
                    SCScore.Domain.Log.Add(domainLog);

                    objJHDomain.Score  = score;
                    objJHDomain.Credit = objSCDomain.Weight;
                    objJHDomain.Period = objSCDomain.Period;
                    objJHDomain.Effort = objSCDomain.Effort;
                    objJHDomain.Text   = objSCDomain.Text;

                    JHScore.Domains.Add(strDomain, objJHDomain);
                }

                //記錄 Log
                SCScore.LearningLog.Formater    = domainLogFormater;
                SCScore.LearningLog.OriginValue = JHScore.CourseLearnScore + "";
                SCScore.LearningLog.NewValue    = SCScore.LearnDomainScore + "";
                SCScore.CourseLog.Formater      = domainLogFormater;
                SCScore.CourseLog.OriginValue   = JHScore.CourseLearnScore + "";
                SCScore.CourseLog.NewValue      = SCScore.CourseLearnScore + "";

                JHScore.LearnDomainScore = SCScore.LearnDomainScore;
                JHScore.CourseLearnScore = SCScore.CourseLearnScore;

                //排序領域名稱。
                Dictionary <string, DomainScore> orderDomain = new Dictionary <string, DomainScore>(JHScore.Domains);
                JHScore.Domains.Clear();
                foreach (string domainName in Util.SortSubjectDomain(orderDomain.Keys))
                {
                    JHScore.Domains.Add(domainName, orderDomain[domainName]);
                }
                #endregion
            }

            #region 新增科目成績
            FunctionSpliter <JHSemesterScoreRecord, JHSemesterScoreRecord> addSpliter =
                new FunctionSpliter <JHSemesterScoreRecord, JHSemesterScoreRecord>(500, 5);
            addSpliter.Function = delegate(List <JHSemesterScoreRecord> part)
            {
                // 加入檢查當科目與領域成績筆數0不新增
                List <JHSemesterScoreRecord> insertPart = new List <JHSemesterScoreRecord> ();

                foreach (JHSemesterScoreRecord rec in part)
                {
                    // 沒有任何領域或科目成績
                    if (rec.Domains.Count == 0 && rec.Subjects.Count == 0)
                    {
                        continue;
                    }

                    insertPart.Add(rec);
                }

                if (insertPart.Count > 0)
                {
                    JHSemesterScore.Insert(insertPart);
                }

                return(new List <JHSemesterScoreRecord>());
            };
            addSpliter.ProgressChange = delegate(int progress)
            {
                Reporter.Feedback("新增科目成績...", Util.CalculatePercentage(addSemsScore.Count, progress));
            };
            addSpliter.Execute(addSemsScore);
            #endregion

            #region 更新科目成績
            FunctionSpliter <JHSemesterScoreRecord, JHSemesterScoreRecord> updateSpliter =
                new FunctionSpliter <JHSemesterScoreRecord, JHSemesterScoreRecord>(500, 5);
            updateSpliter.Function = delegate(List <JHSemesterScoreRecord> part)
            {
                JHSemesterScore.Update(part);
                return(new List <JHSemesterScoreRecord>());
            };
            updateSpliter.ProgressChange = delegate(int progress)
            {
                Reporter.Feedback("更新科目成績...", Util.CalculatePercentage(updateSemsScore.Count, progress));
            };
            updateSpliter.Execute(updateSemsScore);
            #endregion
        }
Esempio n. 7
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;

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

                // 檢查科目名稱是否相同,因為科目名稱重複會造成新增錯誤,科目名稱是唯一值。
                foreach (DataGridViewRow row in dgv.Rows)
                {
                    if (row.Cells[chsSubject.Index].Value != null)
                    {
                        string tmpSubjName = "" + row.Cells[chsSubject.Index].Value;
                        if (checkSubjName.Contains(tmpSubjName))
                        {
                            FISCA.Presentation.Controls.MsgBox.Show("科目名稱重複,無法儲存。");
                            return;
                        }
                        else
                        {
                            checkSubjName.Add(tmpSubjName);
                        }
                    }
                }


                if (CheckDomainValid(txtPC1, txtScore1, txtEffort1))
                {
                    newRecord.Domains.Add("國語文", GetDomainScore("國語文", txtPC1, txtScore1, txtEffort1, txtText1));
                }
                if (CheckDomainValid(txtPC2, txtScore2, txtEffort2))
                {
                    newRecord.Domains.Add("英語", GetDomainScore("英語", txtPC2, txtScore2, txtEffort2, txtText2));
                }
                if (CheckDomainValid(txtPC3, txtScore3, txtEffort3))
                {
                    newRecord.Domains.Add("數學", GetDomainScore("數學", txtPC3, txtScore3, txtEffort3, txtText3));
                }
                if (CheckDomainValid(txtPC4, txtScore4, txtEffort4))
                {
                    newRecord.Domains.Add("社會", GetDomainScore("社會", txtPC4, txtScore4, txtEffort4, txtText4));
                }
                if (CheckDomainValid(txtPC5, txtScore5, txtEffort5))
                {
                    newRecord.Domains.Add("藝術與人文", GetDomainScore("藝術與人文", txtPC5, txtScore5, txtEffort5, txtText5));
                }
                if (CheckDomainValid(txtPC6, txtScore6, txtEffort6))
                {
                    newRecord.Domains.Add("自然與生活科技", GetDomainScore("自然與生活科技", txtPC6, txtScore6, txtEffort6, txtText6));
                }
                if (CheckDomainValid(txtPC7, txtScore7, txtEffort7))
                {
                    newRecord.Domains.Add("健康與體育", GetDomainScore("健康與體育", txtPC7, txtScore7, txtEffort7, txtText7));
                }
                if (CheckDomainValid(txtPC8, txtScore8, txtEffort8))
                {
                    newRecord.Domains.Add("綜合活動", GetDomainScore("綜合活動", txtPC8, txtScore8, txtEffort8, txtText8));
                }

                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.Text    = "" + row.Cells[chsText.Index].Value;

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

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

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

            this.DialogResult = DialogResult.OK;
        }
        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;

                // 2018.09.22 [ischoolKingdom] Vicky依據 [J成績][HC][03] 快速新增學期成績修正,將語文領域的子領域兩個項目欄位拿掉,僅保留輸入語文領域成績的單一功能。
                if (CheckDomainValid(textBoxPC1, textBoxScore1, textBoxEffort1))
                {
                    newRecord.Domains.Add("語文", GetDomainScore("語文", textBoxPC1, textBoxScore1, textBoxEffort1, textBoxText1));
                }
                if (CheckDomainValid(textBoxPC2, textBoxScore2, textBoxEffort2))
                {
                    newRecord.Domains.Add("數學", GetDomainScore("數學", textBoxPC2, textBoxScore2, textBoxEffort2, textBoxText2));
                }
                if (CheckDomainValid(textBoxPC3, textBoxScore3, textBoxEffort3))
                {
                    newRecord.Domains.Add("社會", GetDomainScore("社會", textBoxPC3, textBoxScore3, textBoxEffort3, textBoxText3));
                }
                //if (CheckDomainValid(textBoxPC4, textBoxScore4, textBoxEffort4))
                //    newRecord.Domains.Add("藝術與人文", GetDomainScore("藝術與人文", textBoxPC4, textBoxScore4, textBoxEffort4, textBoxText4));
                //if (CheckDomainValid(textBoxPC5, textBoxScore5, textBoxEffort5))
                //    newRecord.Domains.Add("自然與生活科技", GetDomainScore("自然與生活科技", textBoxPC5, textBoxScore5, textBoxEffort5, textBoxText5));
                if (CheckDomainValid(textBoxPC4, textBoxScore4, textBoxEffort4))
                {
                    newRecord.Domains.Add("藝術", GetDomainScore("藝術", textBoxPC4, textBoxScore4, textBoxEffort4, textBoxText4));
                }
                if (CheckDomainValid(textBoxPC5, textBoxScore5, textBoxEffort5))
                {
                    newRecord.Domains.Add("自然科學", GetDomainScore("自然科學", textBoxPC5, textBoxScore5, textBoxEffort5, textBoxText5));
                }
                if (CheckDomainValid(textBoxPC6, textBoxScore6, textBoxEffort6))
                {
                    newRecord.Domains.Add("健康與體育", GetDomainScore("健康與體育", textBoxPC6, textBoxScore6, textBoxEffort6, textBoxText6));
                }
                if (CheckDomainValid(textBoxPC7, textBoxScore7, textBoxEffort7))
                {
                    newRecord.Domains.Add("綜合活動", GetDomainScore("綜合活動", textBoxPC7, textBoxScore7, textBoxEffort7, textBoxText7));
                }
                if (CheckDomainValid(textBoxPC8, textBoxScore8, textBoxEffort8))
                {
                    newRecord.Domains.Add("科技", GetDomainScore("科技", textBoxPC8, textBoxScore8, textBoxEffort8, textBoxText8));
                }

                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);
                    // 2018.09.22 [ischoolKingdom] Vicky 依據 [J成績][HC][03]快速新增學期成績修正 項目,使輸入成績一併儲存至原始成績。
                    subject.ScoreOrigin = 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;
        }