Ejemplo n.º 1
0
        private UDT.WeeklyRank createRankObject(UDT.WeeklyStats ws, int rank, int grade)
        {
            UDT.WeeklyRank wr = new UDT.WeeklyRank();
            wr.RefWeeklyStatsID = int.Parse(ws.UID);
            wr.SchoolYear       = int.Parse(this._schoolYear);
            wr.Semester         = int.Parse(this._semester);
            wr.RefClassID       = ws.RefClassID;
            wr.GradeYear        = grade;
            wr.WeekTotal        = ws.WeekTotal;
            wr.WeekNumber       = this._weekNumber;
            wr.CreateTime       = DateTime.Now;
            wr.CreatedBy        = this._userAccount;
            wr.PublicTime       = DateTime.Now;
            wr.PublicBy         = this._userAccount;
            wr.Rank             = rank;

            return(wr);
        }
        public void Execute()
        {
            GetScoreSheet();

            List <UDT.WeeklyStats> listInsertData = new List <UDT.WeeklyStats>();

            // 1.計算各班週成績
            foreach (string classID in this.dicClassCalculatorByID.Keys)
            {
                ClassWeeklyScoreCalculator calculator = this.dicClassCalculatorByID[classID];
                // 取得各班週成績
                decimal weeklyScore = calculator.CalculateWeeklyScore();
                // 取得班級各區週成績
                List <string> listAreaScore = calculator.ListAreaScore;
                // 資料整理
                UDT.WeeklyStats data = new UDT.WeeklyStats();
                data.SchoolYear      = int.Parse(this._schoolYear);
                data.Semester        = int.Parse(this._semester);
                data.StartDate       = DateTime.Parse(this._startDate);
                data.EndDate         = DateTime.Parse(this._endDate);
                data.RefClassID      = int.Parse(classID);
                data.GradeYear       = calculator.GradeYear;
                data.WeekTotal       = weeklyScore;
                data.AreaWeeklyTotal = string.Join(",", listAreaScore);
                data.WeekNumber      = this._weekNumber;
                data.CreateTime      = DateTime.Now;
                data.CreatedBy       = this._userName;

                listInsertData.Add(data);
            }

            // 0. 刪除日期區間週統計
            List <UDT.WeeklyStats> listWeeklyStats = this._access.Select <UDT.WeeklyStats>(string.Format("school_year = {0} AND semester = {1} AND week_number = {2}", this._schoolYear, this._semester, this._weekNumber));

            this._access.DeletedValues(listWeeklyStats);

            // 2.更新資料庫
            this._access.InsertValues(listInsertData);
        }