public ActionResult clearRound21Score(int id) { if (Session["USER"] == null) { return(RedirectToAction("../Account/ManagementLogin")); } using (ChinaPhet10Entities context = new ChinaPhet10Entities()) { Int32 stdCode = Convert.ToInt32(id); TB_SCORE_ROUND_2 score21 = context.TB_SCORE_ROUND_2.Where(s21 => s21.STD_CODE == stdCode).FirstOrDefault(); if (score21 != null) { score21.SCORE_1_11 = 0; score21.SCORE_1_12 = 0; score21.SCORE_1_13 = 0; score21.SCORE_1_14 = 0; score21.SCORE_1_15 = 0; score21.SCORE_1_21 = 0; score21.SCORE_1_22 = 0; score21.SCORE_1_23 = 0; score21.SCORE_1_24 = 0; score21.SCORE_1_25 = 0; score21.SCORE_1_31 = 0; score21.SCORE_1_32 = 0; score21.SCORE_1_33 = 0; score21.SCORE_1_34 = 0; score21.SCORE_1_35 = 0; context.SaveChanges(); ViewBag.ResultMsg = "ล้างข้อมูลเรียบร้อยแล้ว"; } else { ViewBag.ResultErrorMsg = "ยังไม่มีการบันทึกข้อมูล ไม่สามารถลบได้"; } } return(View("Round2_1", new ScoreRound21Model())); }
public ActionResult Round2_2(ScoreRound22Model model) { if (Session["USER"] == null) { return(RedirectToAction("../Account/ManagementLogin")); } switch (model.actionName) { case "ค้นหา": if (!CommonUtils.isNumber(model.studentCode)) { ViewBag.ResultErrorMsg = "เลขผู้สมัครต้องเป็นตัวเลขเท่านั้น"; model.studentCode = ""; model.studentName = null; model.score11 = ""; model.score12 = ""; model.score13 = ""; model.score14 = ""; model.score21 = ""; model.score22 = ""; model.score23 = ""; model.score24 = ""; model.score31 = ""; model.score32 = ""; model.score33 = ""; model.score34 = ""; ModelState.Clear(); } else { int studentCodeSearch = Convert.ToInt32(model.studentCode); TB_STUDENT_SEAT resultStudent = db.TB_STUDENT_SEAT.Where(s => s.STUDENT_CODE == studentCodeSearch).FirstOrDefault(); if (resultStudent != null) { if (resultStudent.TB_APPLICATION_STUDENT != null) { model.student = resultStudent; model.studentName = resultStudent.TB_APPLICATION_STUDENT.TB_M_TITLE.TITLE_NAME_TH + "" + resultStudent.TB_APPLICATION_STUDENT.STD_NAME + " " + resultStudent.TB_APPLICATION_STUDENT.STD_SURNAME + " (โรงเรียน" + resultStudent.TB_APPLICATION_STUDENT.TB_APPLICATION_SCHOOL.SCHOOL_NAME + ")"; TB_SCORE_ROUND_2 score22 = db.TB_SCORE_ROUND_2.Where(k => k.STD_CODE == resultStudent.STUDENT_CODE).FirstOrDefault(); if (score22 != null) { ModelState.Clear(); model.score11 = Convert.ToString(score22.SCORE_2_11); model.score12 = Convert.ToString(score22.SCORE_2_12); model.score13 = Convert.ToString(score22.SCORE_2_13); model.score14 = Convert.ToString(score22.SCORE_2_14); model.score21 = Convert.ToString(score22.SCORE_2_21); model.score22 = Convert.ToString(score22.SCORE_2_22); model.score23 = Convert.ToString(score22.SCORE_2_23); model.score24 = Convert.ToString(score22.SCORE_2_24); model.score31 = Convert.ToString(score22.SCORE_2_31); model.score32 = Convert.ToString(score22.SCORE_2_32); model.score33 = Convert.ToString(score22.SCORE_2_33); model.score34 = Convert.ToString(score22.SCORE_2_34); } else { ModelState.Clear(); model.score11 = ""; model.score12 = ""; model.score13 = ""; model.score14 = ""; model.score21 = ""; model.score22 = ""; model.score23 = ""; model.score24 = ""; model.score31 = ""; model.score32 = ""; model.score33 = ""; model.score34 = ""; } } else { ViewBag.ResultErrorMsg = "ไม่พบข้อมูลนักเรียน-ไม่มีข้อมูลโรงเรียน"; } } else { ViewBag.ResultErrorMsg = "ไม่พบข้อมูลนักเรียน"; } } break; case "บันทึก": if (String.IsNullOrEmpty(model.score11) || String.IsNullOrEmpty(model.score12) || String.IsNullOrEmpty(model.score13) || String.IsNullOrEmpty(model.score14) || String.IsNullOrEmpty(model.score21) || String.IsNullOrEmpty(model.score22) || String.IsNullOrEmpty(model.score23) || String.IsNullOrEmpty(model.score24) || String.IsNullOrEmpty(model.score31) || String.IsNullOrEmpty(model.score32) || String.IsNullOrEmpty(model.score33) || String.IsNullOrEmpty(model.score34) ) { ViewBag.ResultErrorMsg = "ยังไม่ได้ป้อนคะแนน"; } else if (!CommonUtils.isDouble(model.score11) || !CommonUtils.isDouble(model.score12) || !CommonUtils.isDouble(model.score13) || !CommonUtils.isDouble(model.score14) || !CommonUtils.isDouble(model.score21) || !CommonUtils.isDouble(model.score22) || !CommonUtils.isDouble(model.score23) || !CommonUtils.isDouble(model.score24) || !CommonUtils.isDouble(model.score31) || !CommonUtils.isDouble(model.score32) || !CommonUtils.isDouble(model.score33) || !CommonUtils.isDouble(model.score34) ) { ViewBag.ResultErrorMsg = "ตรวจสอบคะแนนที่บันทึกต้องเป็นตัวเลขหรือทศนิยมเท่านั้น"; } else if (validateScore22(model).Length > 0) { ViewBag.ResultErrorMsg = validateScore22(model); } else { int stuentCodeSave = Convert.ToInt32(model.studentCode); TB_SCORE_ROUND_2 score22 = db.TB_SCORE_ROUND_2.Where(k => k.STD_CODE == stuentCodeSave).FirstOrDefault(); if (score22 == null) { TB_SCORE_ROUND_2 round2 = new TB_SCORE_ROUND_2(); round2.STD_CODE = stuentCodeSave; round2.SCORE_2_11 = Convert.ToDecimal(model.score11); round2.SCORE_2_12 = Convert.ToDecimal(model.score12); round2.SCORE_2_13 = Convert.ToDecimal(model.score13); round2.SCORE_2_14 = Convert.ToDecimal(model.score14); round2.SCORE_2_21 = Convert.ToDecimal(model.score21); round2.SCORE_2_22 = Convert.ToDecimal(model.score22); round2.SCORE_2_23 = Convert.ToDecimal(model.score23); round2.SCORE_2_24 = Convert.ToDecimal(model.score24); round2.SCORE_2_31 = Convert.ToDecimal(model.score31); round2.SCORE_2_32 = Convert.ToDecimal(model.score32); round2.SCORE_2_33 = Convert.ToDecimal(model.score33); round2.SCORE_2_34 = Convert.ToDecimal(model.score34); db.TB_SCORE_ROUND_2.Add(round2); } else { score22.STD_CODE = stuentCodeSave; score22.SCORE_2_11 = model.score11.Equals("") ? Convert.ToDecimal(0) : Convert.ToDecimal(model.score11); score22.SCORE_2_12 = model.score12.Equals("") ? Convert.ToDecimal(0) : Convert.ToDecimal(model.score12); score22.SCORE_2_13 = model.score13.Equals("") ? Convert.ToDecimal(0) : Convert.ToDecimal(model.score13); score22.SCORE_2_14 = model.score14.Equals("") ? Convert.ToDecimal(0) : Convert.ToDecimal(model.score14); score22.SCORE_2_21 = model.score21.Equals("") ? Convert.ToDecimal(0) : Convert.ToDecimal(model.score21); score22.SCORE_2_22 = model.score22.Equals("") ? Convert.ToDecimal(0) : Convert.ToDecimal(model.score22); score22.SCORE_2_23 = model.score23.Equals("") ? Convert.ToDecimal(0) : Convert.ToDecimal(model.score23); score22.SCORE_2_24 = model.score24.Equals("") ? Convert.ToDecimal(0) : Convert.ToDecimal(model.score24); score22.SCORE_2_31 = model.score31.Equals("") ? Convert.ToDecimal(0) : Convert.ToDecimal(model.score31); score22.SCORE_2_32 = model.score32.Equals("") ? Convert.ToDecimal(0) : Convert.ToDecimal(model.score32); score22.SCORE_2_33 = model.score33.Equals("") ? Convert.ToDecimal(0) : Convert.ToDecimal(model.score33); score22.SCORE_2_34 = model.score34.Equals("") ? Convert.ToDecimal(0) : Convert.ToDecimal(model.score34); //db.ObjectStateManager.ChangeObjectState(score22, System.Data.EntityState.Modified); } db.SaveChanges(); model.studentCode = ""; model.studentName = null; model.score11 = ""; model.score12 = ""; model.score13 = ""; model.score14 = ""; model.score21 = ""; model.score22 = ""; model.score23 = ""; model.score24 = ""; model.score31 = ""; model.score32 = ""; model.score33 = ""; model.score34 = ""; ModelState.Clear(); ViewBag.ResultMsg = "บันทึกข้อมูลเรียบร้อยแล้ว"; } break; default: break; } return(View("Round2_2", model)); }
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")); }