private String validateScore21(ScoreRound21Model model) { StringBuilder sb = new StringBuilder(); /* การนำเข้าสู่เนื้อหา (5) เนื้อหาสาระ (25) สรุป (5) ความคิดสร้างสรรค์ (5) ความถูกต้องของตัวอักษร (10) */ //กรรมการคนที่ 1 if (Convert.ToDouble(model.score11) > 5) { sb.Append("คะแนนกรรมการคนที่ 1 คอลัมภ์ที่ 1 มีการป้อน " + model.score11 + " ซึ่งมากกว่าคะแนนที่กำหนด (5 คะแนน)\n"); } if (Convert.ToDouble(model.score12) > 25) { sb.Append("คะแนนกรรมการคนที่ 1 คอลัมภ์ที่ 2 มีการป้อน " + model.score12 + " ซึ่งมากกว่าคะแนนที่กำหนด (25 คะแนน)\n"); } if (Convert.ToDouble(model.score13) > 5) { sb.Append("คะแนนกรรมการคนที่ 1 คอลัมภ์ที่ 3 มีการป้อน " + model.score13 + " ซึ่งมากกว่าคะแนนที่กำหนด (5 คะแนน)\n"); } if (Convert.ToDouble(model.score14) > 5) { sb.Append("คะแนนกรรมการคนที่ 1 คอลัมภ์ที่ 4 มีการป้อน " + model.score14 + " ซึ่งมากกว่าคะแนนที่กำหนด (5 คะแนน)\n"); } if (Convert.ToDouble(model.score15) > 10) { sb.Append("คะแนนกรรมการคนที่ 1 คอลัมภ์ที่ 5 มีการป้อน " + model.score15 + " ซึ่งมากกว่าคะแนนที่กำหนด (10 คะแนน)\n"); } //กรรมการคนที่ 2 if (Convert.ToDouble(model.score21) > 5) { sb.Append("คะแนนกรรมการคนที่ 2 คอลัมภ์ที่ 1 มีการป้อน " + model.score21 + " ซึ่งมากกว่าคะแนนที่กำหนด (5 คะแนน)\n"); } if (Convert.ToDouble(model.score22) > 25) { sb.Append("คะแนนกรรมการคนที่ 2 คอลัมภ์ที่ 2 มีการป้อน " + model.score22 + " ซึ่งมากกว่าคะแนนที่กำหนด (25 คะแนน)\n"); } if (Convert.ToDouble(model.score23) > 5) { sb.Append("คะแนนกรรมการคนที่ 2 คอลัมภ์ที่ 3 มีการป้อน " + model.score23 + " ซึ่งมากกว่าคะแนนที่กำหนด (5 คะแนน)\n"); } if (Convert.ToDouble(model.score24) > 5) { sb.Append("คะแนนกรรมการคนที่ 2 คอลัมภ์ที่ 4 มีการป้อน " + model.score24 + " ซึ่งมากกว่าคะแนนที่กำหนด (5 คะแนน)\n"); } if (Convert.ToDouble(model.score25) > 10) { sb.Append("คะแนนกรรมการคนที่ 2 คอลัมภ์ที่ 5 มีการป้อน " + model.score25 + " ซึ่งมากกว่าคะแนนที่กำหนด (10 คะแนน)\n"); } //กรรมการคนที่ 3 if (Convert.ToDouble(model.score31) > 5) { sb.Append("คะแนนกรรมการคนที่ 3 คอลัมภ์ที่ 1 มีการป้อน " + model.score31 + " ซึ่งมากกว่าคะแนนที่กำหนด (5 คะแนน)\n"); } if (Convert.ToDouble(model.score32) > 25) { sb.Append("คะแนนกรรมการคนที่ 3 คอลัมภ์ที่ 2 มีการป้อน " + model.score32 + " ซึ่งมากกว่าคะแนนที่กำหนด (25 คะแนน)\n"); } if (Convert.ToDouble(model.score33) > 5) { sb.Append("คะแนนกรรมการคนที่ 3 คอลัมภ์ที่ 3 มีการป้อน " + model.score33 + " ซึ่งมากกว่าคะแนนที่กำหนด (5 คะแนน)\n"); } if (Convert.ToDouble(model.score34) > 5) { sb.Append("คะแนนกรรมการคนที่ 3 คอลัมภ์ที่ 4 มีการป้อน " + model.score34 + " ซึ่งมากกว่าคะแนนที่กำหนด (5 คะแนน)\n"); } if (Convert.ToDouble(model.score35) > 10) { sb.Append("คะแนนกรรมการคนที่ 3 คอลัมภ์ที่ 5 มีการป้อน " + model.score35 + " ซึ่งมากกว่าคะแนนที่กำหนด (10 คะแนน)\n"); } return(sb.ToString()); }
public ActionResult Round2_1(ScoreRound21Model 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.score15 = ""; model.score21 = ""; model.score22 = ""; model.score23 = ""; model.score24 = ""; model.score25 = ""; model.score31 = ""; model.score32 = ""; model.score33 = ""; model.score34 = ""; model.score35 = ""; 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 score21 = db.TB_SCORE_ROUND_2.Where(k => k.STD_CODE == resultStudent.STUDENT_CODE).FirstOrDefault(); if (score21 != null) { ModelState.Clear(); model.score11 = Convert.ToString(score21.SCORE_1_11); model.score12 = Convert.ToString(score21.SCORE_1_12); model.score13 = Convert.ToString(score21.SCORE_1_13); model.score14 = Convert.ToString(score21.SCORE_1_14); model.score15 = Convert.ToString(score21.SCORE_1_15); model.score21 = Convert.ToString(score21.SCORE_1_21); model.score22 = Convert.ToString(score21.SCORE_1_22); model.score23 = Convert.ToString(score21.SCORE_1_23); model.score24 = Convert.ToString(score21.SCORE_1_24); model.score25 = Convert.ToString(score21.SCORE_1_25); model.score31 = Convert.ToString(score21.SCORE_1_31); model.score32 = Convert.ToString(score21.SCORE_1_32); model.score33 = Convert.ToString(score21.SCORE_1_33); model.score34 = Convert.ToString(score21.SCORE_1_34); model.score35 = Convert.ToString(score21.SCORE_1_35); } else { ModelState.Clear(); model.score11 = ""; model.score12 = ""; model.score13 = ""; model.score14 = ""; model.score15 = ""; model.score21 = ""; model.score22 = ""; model.score23 = ""; model.score24 = ""; model.score25 = ""; model.score31 = ""; model.score32 = ""; model.score33 = ""; model.score34 = ""; model.score35 = ""; } } 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.score15) || String.IsNullOrEmpty(model.score21) || String.IsNullOrEmpty(model.score22) || String.IsNullOrEmpty(model.score23) || String.IsNullOrEmpty(model.score24) || String.IsNullOrEmpty(model.score25) || String.IsNullOrEmpty(model.score31) || String.IsNullOrEmpty(model.score32) || String.IsNullOrEmpty(model.score33) || String.IsNullOrEmpty(model.score34) || String.IsNullOrEmpty(model.score35) ) { ViewBag.ResultErrorMsg = "ยังไม่ได้ป้อนคะแนน"; } else if (validateScore21(model).Length > 0) { ViewBag.ResultErrorMsg = validateScore21(model); } else if ( !CommonUtils.isDouble(model.score11) || !CommonUtils.isDouble(model.score12) || !CommonUtils.isDouble(model.score13) || !CommonUtils.isDouble(model.score14) || !CommonUtils.isDouble(model.score15) || !CommonUtils.isDouble(model.score21) || !CommonUtils.isDouble(model.score22) || !CommonUtils.isDouble(model.score23) || !CommonUtils.isDouble(model.score24) || !CommonUtils.isDouble(model.score25) || !CommonUtils.isDouble(model.score31) || !CommonUtils.isDouble(model.score32) || !CommonUtils.isDouble(model.score33) || !CommonUtils.isDouble(model.score34) || !CommonUtils.isDouble(model.score35) ) { ViewBag.ResultErrorMsg = "ตรวจสอบคะแนนที่บันทึกต้องเป็นตัวเลขหรือทศนิยมเท่านั้น"; } else { int stuentCodeSave = Convert.ToInt32(model.studentCode); TB_SCORE_ROUND_2 score21 = db.TB_SCORE_ROUND_2.Where(k => k.STD_CODE == stuentCodeSave).FirstOrDefault(); if (score21 == null) { TB_SCORE_ROUND_2 round2 = new TB_SCORE_ROUND_2(); round2.STD_CODE = stuentCodeSave; round2.SCORE_1_11 = model.score11.Equals("") ? Convert.ToDecimal(0) : Convert.ToDecimal(model.score11); round2.SCORE_1_12 = model.score12.Equals("") ? Convert.ToDecimal(0) : Convert.ToDecimal(model.score12); round2.SCORE_1_13 = model.score13.Equals("") ? Convert.ToDecimal(0) : Convert.ToDecimal(model.score13); round2.SCORE_1_14 = model.score14.Equals("") ? Convert.ToDecimal(0) : Convert.ToDecimal(model.score14); round2.SCORE_1_15 = model.score15.Equals("") ? Convert.ToDecimal(0) : Convert.ToDecimal(model.score15); round2.SCORE_1_21 = model.score21.Equals("") ? Convert.ToDecimal(0) : Convert.ToDecimal(model.score21); round2.SCORE_1_22 = model.score22.Equals("") ? Convert.ToDecimal(0) : Convert.ToDecimal(model.score22); round2.SCORE_1_23 = model.score23.Equals("") ? Convert.ToDecimal(0) : Convert.ToDecimal(model.score23); round2.SCORE_1_24 = model.score24.Equals("") ? Convert.ToDecimal(0) : Convert.ToDecimal(model.score24); round2.SCORE_1_25 = model.score25.Equals("") ? Convert.ToDecimal(0) : Convert.ToDecimal(model.score25); round2.SCORE_1_31 = model.score21.Equals("") ? Convert.ToDecimal(0) : Convert.ToDecimal(model.score21); round2.SCORE_1_32 = model.score22.Equals("") ? Convert.ToDecimal(0) : Convert.ToDecimal(model.score22); round2.SCORE_1_33 = model.score23.Equals("") ? Convert.ToDecimal(0) : Convert.ToDecimal(model.score23); round2.SCORE_1_34 = model.score24.Equals("") ? Convert.ToDecimal(0) : Convert.ToDecimal(model.score24); round2.SCORE_1_35 = model.score25.Equals("") ? Convert.ToDecimal(0) : Convert.ToDecimal(model.score25); db.TB_SCORE_ROUND_2.Add(round2); } else { score21.STD_CODE = stuentCodeSave; score21.SCORE_1_11 = model.score11.Equals("") ? Convert.ToDecimal(0) : Convert.ToDecimal(model.score11); score21.SCORE_1_12 = model.score12.Equals("") ? Convert.ToDecimal(0) : Convert.ToDecimal(model.score12); score21.SCORE_1_13 = model.score13.Equals("") ? Convert.ToDecimal(0) : Convert.ToDecimal(model.score13); score21.SCORE_1_14 = model.score14.Equals("") ? Convert.ToDecimal(0) : Convert.ToDecimal(model.score14); score21.SCORE_1_15 = model.score15.Equals("") ? Convert.ToDecimal(0) : Convert.ToDecimal(model.score15); score21.SCORE_1_21 = model.score21.Equals("") ? Convert.ToDecimal(0) : Convert.ToDecimal(model.score21); score21.SCORE_1_22 = model.score22.Equals("") ? Convert.ToDecimal(0) : Convert.ToDecimal(model.score22); score21.SCORE_1_23 = model.score23.Equals("") ? Convert.ToDecimal(0) : Convert.ToDecimal(model.score23); score21.SCORE_1_24 = model.score24.Equals("") ? Convert.ToDecimal(0) : Convert.ToDecimal(model.score24); score21.SCORE_1_25 = model.score25.Equals("") ? Convert.ToDecimal(0) : Convert.ToDecimal(model.score25); score21.SCORE_1_31 = model.score31.Equals("") ? Convert.ToDecimal(0) : Convert.ToDecimal(model.score31); score21.SCORE_1_32 = model.score32.Equals("") ? Convert.ToDecimal(0) : Convert.ToDecimal(model.score32); score21.SCORE_1_33 = model.score33.Equals("") ? Convert.ToDecimal(0) : Convert.ToDecimal(model.score33); score21.SCORE_1_34 = model.score34.Equals("") ? Convert.ToDecimal(0) : Convert.ToDecimal(model.score34); score21.SCORE_1_35 = model.score35.Equals("") ? Convert.ToDecimal(0) : Convert.ToDecimal(model.score35); //db.ObjectStateManager.ChangeObjectState(score21, System.Data.EntityState.Modified); } db.SaveChanges(); model.studentCode = ""; model.studentName = null; model.score11 = ""; model.score12 = ""; model.score13 = ""; model.score14 = ""; model.score15 = ""; model.score21 = ""; model.score22 = ""; model.score23 = ""; model.score24 = ""; model.score25 = ""; model.score31 = ""; model.score32 = ""; model.score33 = ""; model.score34 = ""; model.score35 = ""; ModelState.Clear(); ViewBag.ResultMsg = "บันทึกข้อมูลเรียบร้อยแล้ว"; } break; default: break; } return(View("Round2_1", model)); }