public ActionResult Round1() { if (Session["USER"] == null) { return(RedirectToAction("../Account/ManagementLogin")); } var model = new ScoreRound1Model { }; return(View("Round1", model)); }
public ActionResult doProcessRound1(ScoreRound1Model model) { if (Session["USER"] == null) { return(RedirectToAction("../Account/ManagementLogin")); } int _levelId = Convert.ToInt16(model.studentLevel); var items = from ss in db.TB_STUDENT_SEAT join r in db.TB_SCORE_ROUND_1 on ss.STUDENT_CODE equals r.STD_CODE join s in db.TB_APPLICATION_STUDENT on ss.STUDENT_ID equals s.STD_ID where s.STD_LEVEL_ID == _levelId && s.STD_NATION != 2 orderby s.STD_LEVEL_ID ascending, r.ROUND_SCORE descending select new { StdCode = ss.STUDENT_CODE, Score = r.ROUND_SCORE, StudentLevel = _levelId, s.STD_NATION, r.ROUND_SCORE }; if (items != null) { StringBuilder sb = new StringBuilder(); int index = 1; foreach (var item in items) { TB_SCORE_ROUND_1 sr = db.TB_SCORE_ROUND_1.Where(s => s.STD_CODE == item.StdCode).FirstOrDefault(); if (sr != null) { if (item.StudentLevel == 5) { //check condition if (index >= 1 && index <= 10) { sr.PRIZE_ID = 1;//เข้ารอบเพชรยอดมงกุฏ } else if (index > 10 && index <= 20) { sr.PRIZE_ID = 2;//รางวัลชอมเชย } else { sr.PRIZE_ID = 4; } } else { if (index >= 1 && index <= 10) { sr.PRIZE_ID = 1;//เข้ารอบเพชรยอดมงกุฏ } else if (index > 10 && index <= 50) { sr.PRIZE_ID = 2;//รางวัลชอมเชย } else if (index > 50 && index <= 100) { sr.PRIZE_ID = 3;//รางวัลผ่านเกณฑ์ } else { sr.PRIZE_ID = 4; } } index++; if (index % 200 == 0) { db.SaveChanges(); } } } db.SaveChanges(); } ViewBag.ResultMsg = "ปรับคะแนน 100 อันดับ ระดับชั้นที่ " + model.studentLevel + " รอบเจียรไนเพชรเรียบร้อยแล้ว"; return(View("ProcessRound1")); }
public ActionResult doProcessRound2(ScoreRound1Model model) { if (Session["USER"] == null) { return(RedirectToAction("../Account/ManagementLogin")); } int _levelId = Convert.ToInt16(model.studentLevel); var round2Result = from stdSeat in db.TB_STUDENT_SEAT join std in db.TB_APPLICATION_STUDENT on stdSeat.STUDENT_ID equals std.STD_ID join r1 in db.TB_SCORE_ROUND_1 on stdSeat.STUDENT_CODE equals r1.STD_CODE join r2 in db.TB_SCORE_ROUND_2 on stdSeat.STUDENT_CODE equals r2.STD_CODE where std.STD_LEVEL_ID == _levelId && std.STD_NATION != 2 orderby(r2.SCORE_1_11 + r2.SCORE_1_12 + r2.SCORE_1_13 + r2.SCORE_1_14 + r2.SCORE_1_15 + r2.SCORE_1_21 + r2.SCORE_1_22 + r2.SCORE_1_23 + r2.SCORE_1_24 + r2.SCORE_1_25 + r2.SCORE_1_31 + r2.SCORE_1_32 + r2.SCORE_1_33 + r2.SCORE_1_34 + r2.SCORE_1_35 + r2.SCORE_2_11 + r2.SCORE_2_12 + r2.SCORE_2_13 + r2.SCORE_2_14 + r2.SCORE_2_21 + r2.SCORE_2_22 + r2.SCORE_2_23 + r2.SCORE_2_24 + r2.SCORE_2_31 + r2.SCORE_2_32 + r2.SCORE_2_33 + r2.SCORE_2_34 ) descending select new { studentCode = std.TB_STUDENT_SEAT.STUDENT_CODE, studentFullName = std.TB_M_TITLE.TITLE_NAME_TH + "" + std.STD_NAME + " " + std.STD_SURNAME, round1Score = r1.ROUND_SCORE, round2Score = (r2.SCORE_1_11 + r2.SCORE_1_12 + r2.SCORE_1_13 + r2.SCORE_1_14 + r2.SCORE_1_15 + r2.SCORE_1_21 + r2.SCORE_1_22 + r2.SCORE_1_23 + r2.SCORE_1_24 + r2.SCORE_1_25 + r2.SCORE_1_31 + r2.SCORE_1_32 + r2.SCORE_1_33 + r2.SCORE_1_34 + r2.SCORE_1_35 + r2.SCORE_2_11 + r2.SCORE_2_12 + r2.SCORE_2_13 + r2.SCORE_2_14 + r2.SCORE_2_21 + r2.SCORE_2_22 + r2.SCORE_2_23 + r2.SCORE_2_24 + r2.SCORE_2_31 + r2.SCORE_2_32 + r2.SCORE_2_33 + r2.SCORE_2_34) }; if (round2Result != null) { int index = 1; foreach (var item in round2Result) { TB_SCORE_ROUND_2 round2 = db.TB_SCORE_ROUND_2.Where(s => s.STD_CODE == item.studentCode).FirstOrDefault(); if (round2 != null) { if (index == 1) { round2.PRIZE_ID = 5;//เหรียญทอง } else if (index == 2) { round2.PRIZE_ID = 6;//เหรียญเงิน } else if (index == 3) { round2.PRIZE_ID = 7;//เหรียญทองแดง } else if (index <= 10) { round2.PRIZE_ID = 8;//ชมเชย } else { round2.PRIZE_ID = 4; } round2.ROUND_1_SCORE = item.round1Score; index++; } } db.SaveChanges(); } ViewBag.ResultMsg = "ประมวลผลคะแนน ระดับชั้นที่ " + model.studentLevel + " รอบเพชรยอดมงกุฏเรียบร้อยแล้ว"; return(View("ProcessRound2")); }