예제 #1
0
        private void ScoreSaver_DoWork(object sender, DoWorkEventArgs e)
        {
            List <JHSCETakeRecord> sceList = new List <JHSCETakeRecord>();

            List <StudentData> sdList = AttendManager.Instance.GetStudentDataList();
            int count = 0;

            foreach (StudentData sd in sdList)
            {
                count++;
                sceList.AddRange(sd.GetCopiedScores(Config.SourceSubject, Config.TargetSubjects));
                ScoreSaver.ReportProgress(Util.CalculatePercentage(sdList.Count, count), "複製評量成績中...");
            }

            List <JHSCETakeRecord> insertList = new List <JHSCETakeRecord>();
            List <JHSCETakeRecord> updateList = new List <JHSCETakeRecord>();

            foreach (JHSCETakeRecord sce in sceList)
            {
                if (string.IsNullOrEmpty(sce.ID))
                {
                    insertList.Add(sce);
                }
                else
                {
                    updateList.Add(sce);
                }
            }

            if (insertList.Count > 0)
            {
                FunctionSpliter <JHSCETakeRecord, string> spliterInsert = new FunctionSpliter <JHSCETakeRecord, string>(100, Util.MaxThread);
                spliterInsert.Function = delegate(List <JHSCETakeRecord> part)
                {
                    JHSCETake.Insert(part);
                    return(null);
                };
                spliterInsert.ProgressChange = delegate(int progress)
                {
                    ScoreSaver.ReportProgress(Util.CalculatePercentage(insertList.Count, progress), "儲存評量成績中...");
                };
                spliterInsert.Execute(insertList);
            }
            if (updateList.Count > 0)
            {
                FunctionSpliter <JHSCETakeRecord, string> spliterUpdate = new FunctionSpliter <JHSCETakeRecord, string>(100, Util.MaxThread);
                spliterUpdate.Function = delegate(List <JHSCETakeRecord> part)
                {
                    JHSCETake.Update(part);
                    return(null);
                };
                spliterUpdate.ProgressChange = delegate(int progress)
                {
                    ScoreSaver.ReportProgress(Util.CalculatePercentage(updateList.Count, progress), "儲存評量成績中...");
                };
                spliterUpdate.Execute(updateList);
            }
        }
예제 #2
0
        private void Insert(object item)
        {
            List <List <HC.JHSCETakeRecord> > insertPackages = (List <List <HC.JHSCETakeRecord> >)item;

            foreach (List <HC.JHSCETakeRecord> package in insertPackages)
            {
                JHSCETake.Insert(package.AsJHSCETakeRecords());
            }
        }
예제 #3
0
 private void Insert(object item)
 {
     try
     {
         List <List <KH.JHSCETakeRecord> > insertPackages = (List <List <KH.JHSCETakeRecord> >)item;
         foreach (List <KH.JHSCETakeRecord> package in insertPackages)
         {
             JHSCETake.Insert(package.AsJHSCETakeRecords());
         }
     }
     catch (Exception ex)
     {
     }
 }
예제 #4
0
        private void btnSave_Click(object sender, EventArgs e)
        {
            dgv.EndEdit();

            if (!IsValid())
            {
                return;
            }

            try
            {
                List <HC.JHSCETakeRecord> sceUpdateList = new List <HC.JHSCETakeRecord>();
                List <HC.JHSCETakeRecord> sceInsertList = new List <HC.JHSCETakeRecord>();
                List <HC.JHSCETakeRecord> sceDeleteList = new List <HC.JHSCETakeRecord>();

                bool scattendNeedSave = false;

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

                    if ("" + row.Tag == "課程總成績")
                    {
                        #region 課程總成績
                        if ("" + row.Cells[chScore.Index].Value != "" + _scattend.Score)
                        {
                            scattendNeedSave = true;
                            decimal d;
                            if (decimal.TryParse("" + row.Cells[chScore.Index].Value, out d))
                            {
                                _scattend.Score = d;
                            }
                            else
                            {
                                _scattend.Score = null;
                            }
                        }
                        //if ("" + row.Cells[chAssignmentScore.Index].Value != "" + _scattend.Effort)
                        //{
                        //    scattendNeedSave = true;
                        //    int i;
                        //    if (int.TryParse("" + row.Cells[chScore.Index].Value, out i))
                        //        _scattend.Score = i;
                        //    else
                        //        _scattend.Score = null;
                        //}
                        if ("" + row.Cells[chText.Index].Value != _scattend.Text)
                        {
                            scattendNeedSave = true;
                            _scattend.Text   = "" + row.Cells[chText.Index].Value;
                        }
                        #endregion
                    }
                    else if (row.Tag != null)
                    {
                        #region  評量成績記錄的情況
                        HC.JHSCETakeRecord sce = row.Tag as HC.JHSCETakeRecord;

                        if (!string.IsNullOrEmpty("" + row.Cells[chScore.Index].Value))
                        {
                            sce.Score = decimal.Parse("" + row.Cells[chScore.Index].Value);
                        }
                        else
                        {
                            sce.Score = null;
                        }

                        if (!string.IsNullOrEmpty("" + row.Cells[chAssignmentScore.Index].Value))
                        {
                            sce.AssignmentScore = decimal.Parse("" + row.Cells[chAssignmentScore.Index].Value);
                        }
                        else
                        {
                            sce.AssignmentScore = null;
                        }

                        sce.Text = "" + row.Cells[chText.Index].Value;

                        if (!sce.Score.HasValue && !sce.AssignmentScore.HasValue && string.IsNullOrEmpty(sce.Text))
                        {
                            sceDeleteList.Add(sce);
                        }
                        else
                        {
                            sceUpdateList.Add(sce);
                        }
                        #endregion
                    }
                    else
                    {
                        #region 無評量成績記錄的情況
                        bool needsave = false;
                        if (!string.IsNullOrEmpty("" + row.Cells[chScore.Index].Value))
                        {
                            needsave = true;
                        }
                        if (!string.IsNullOrEmpty("" + row.Cells[chAssignmentScore.Index].Value))
                        {
                            needsave = true;
                        }
                        if (!string.IsNullOrEmpty("" + row.Cells[chText.Index].Value))
                        {
                            needsave = true;
                        }
                        if (needsave)
                        {
                            JHSCETakeRecord    jh  = new JHSCETakeRecord();
                            HC.JHSCETakeRecord sce = new HC.JHSCETakeRecord(jh);
                            sce.RefCourseID   = _course.ID;
                            sce.RefExamID     = "" + row.Cells[chExamName.Index].Tag;
                            sce.RefSCAttendID = _scattend != null ? _scattend.ID : "";
                            sce.RefStudentID  = _student.ID;
                            if (!string.IsNullOrEmpty("" + row.Cells[chScore.Index].Value))
                            {
                                sce.Score = decimal.Parse("" + row.Cells[chScore.Index].Value);
                            }
                            else
                            {
                                sce.Score = null;
                            }

                            if (!string.IsNullOrEmpty("" + row.Cells[chAssignmentScore.Index].Value))
                            {
                                sce.AssignmentScore = decimal.Parse("" + row.Cells[chAssignmentScore.Index].Value);
                            }
                            else
                            {
                                sce.AssignmentScore = null;
                            }

                            sce.Text = "" + row.Cells[chText.Index].Value;
                            sceInsertList.Add(sce);
                        }
                        #endregion
                    }
                }

                if (sceUpdateList.Count > 0)
                {
                    JHSCETake.Update(sceUpdateList.AsJHSCETakeRecords());
                }
                if (sceInsertList.Count > 0)
                {
                    JHSCETake.Insert(sceInsertList.AsJHSCETakeRecords());
                }
                if (sceDeleteList.Count > 0)
                {
                    JHSCETake.Delete(sceDeleteList.AsJHSCETakeRecords());
                }

                if (scattendNeedSave)
                {
                    JHSCAttend.Update(_scattend);
                }

                // log 處理
                SetSaveDataToLog();
                prlp.SetActionBy("學生", "評量成績輸入");
                prlp.SetAction("評量成績輸入");
                prlp.SetDescTitle("");
                prlp.SaveLog("", "", "Student", _student.ID);
                SetLoadDataToLog();
                this.DialogResult = DialogResult.OK;
                this.Close();
            }
            catch (Exception ex)
            {
                MsgBox.Show("儲存失敗。" + ex.Message);
            }
        }
예제 #5
0
        // 上傳
        void _upload_DoWork(object sender, DoWorkEventArgs e)
        {
            // 傳送與回傳筆數
            int SendCount = 0, RspCount = 0;

            // 刪除舊資料
            SendCount = _deleteScoreList.Count;

            // 取得 del id
            List <string> delIDList = _deleteScoreList.Select(x => x.ID).ToList();

            // 執行
            try
            {
                JHSCETake.Delete(_deleteScoreList);
            }
            catch (Exception ex)
            {
                e.Result = ex.Message;
                e.Cancel = true;
            }
            //    RspCount = JHSCETake.SelectByIDs(delIDList).Count;

            //// 刪除未完成
            //    if (RspCount > 0)
            //        e.Cancel = true;

            try
            {
                //新增資料,分筆上傳
                Dictionary <int, List <JHSCETakeRecord> > batchDict = new Dictionary <int, List <JHSCETakeRecord> >();
                int bn = 150;
                int n1 = (int)(_addScoreList.Count / bn);

                if ((_addScoreList.Count % bn) != 0)
                {
                    n1++;
                }

                for (int i = 0; i <= n1; i++)
                {
                    batchDict.Add(i, new List <JHSCETakeRecord>());
                }


                if (_addScoreList.Count > 0)
                {
                    int idx = 0, count = 1;
                    // 分批
                    foreach (JHSCETakeRecord rec in _addScoreList)
                    {
                        // 100 分一批
                        if ((count % bn) == 0)
                        {
                            idx++;
                        }

                        batchDict[idx].Add(rec);
                        count++;
                    }
                }


                // 上傳資料
                foreach (KeyValuePair <int, List <JHSCETakeRecord> > data in batchDict)
                {
                    SendCount = 0; RspCount = 0;
                    if (data.Value.Count > 0)
                    {
                        SendCount = data.Value.Count;
                        try
                        {
                            JHSCETake.Insert(data.Value);
                        }
                        catch (Exception ex)
                        {
                            e.Cancel = true;
                            e.Result = ex.Message;
                        }

                        counter += SendCount;
                    }
                }
                e.Result = _addScoreList.Count;
            }
            catch (Exception ex)
            {
                e.Result = ex.Message;
                e.Cancel = true;
            }
        }