コード例 #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._weekNo;
            wr.CreateTime       = DateTime.Now;
            wr.CreatedBy        = "";
            wr.Rank             = rank;

            return(wr);
        }
        private void calculateScore()
        {
            // 0. 刪除日期區間週統計
            AccessHelper           access          = new AccessHelper();
            List <UDT.WeeklyStats> listWeeklyStats = access.Select <UDT.WeeklyStats>(string.Format("school_year = {0} AND semester = {1} AND week_number = {2}", this._schoolYear, this._semester, this._weekNo));

            access.DeletedValues(listWeeklyStats);

            // 1. 針對每個班級
            foreach (string classID in dicClassDataByID.Keys)
            {
                decimal score = _baseScore;
                //  1.1 找出該班級的所有評分紀錄
                if (dicRecordsByClassID.ContainsKey(classID))
                {
                    //  1.2 計算總分
                    foreach (UDT.ScoreSheet sheet in dicRecordsByClassID[classID])
                    {
                        if (this._listExistCheckItem.Contains("" + sheet.RefCheckItemID))// 如果評分項目存在系統的話採計扣分
                        {
                            score += sheet.Score;
                        }
                    }
                }
                UDT.WeeklyStats weeklyStats = new UDT.WeeklyStats();
                weeklyStats.SchoolYear = int.Parse(this._schoolYear);
                weeklyStats.semester   = int.Parse(this._semester);
                weeklyStats.RefClassID = int.Parse(classID);
                weeklyStats.GradeYear  = int.Parse("" + dicClassDataByID[classID]["grade_year"]);
                weeklyStats.WeekTotal  = (int)score;
                weeklyStats.WeekNumber = this._weekNo;
                weeklyStats.CreateTime = DateTime.Now;
                weeklyStats.CreatedBy  = "";
                weeklyStats.StartDate  = this._startDate;
                weeklyStats.EndDate    = this._endDate;

                _listInsertWeeklyStats.Add(weeklyStats);
            }
            //  1.3 更新資料庫
            access.InsertValues(_listInsertWeeklyStats);
        }