private String validateScore22(ScoreRound22Model model) { StringBuilder sb = new StringBuilder(); /* * เนื้อหาสาระ(20) การออกเสียงอักขระ(20) บุคลิกภาพ(5) เวลา(5) * */ if (Convert.ToDouble(model.score11) > 20) { sb.Append("คะแนนกรรมการคนที่ 1 คอลัมภ์ที่ 1 มีการป้อน " + model.score11 + " ซึ่งมากกว่าคะแนนที่กำหนด (20 คะแนน)\n"); } if (Convert.ToDouble(model.score12) > 20) { sb.Append("คะแนนกรรมการคนที่ 1 คอลัมภ์ที่ 2 มีการป้อน " + model.score12 + " ซึ่งมากกว่าคะแนนที่กำหนด (20 คะแนน)\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.score21) > 20) { sb.Append("คะแนนกรรมการคนที่ 1 คอลัมภ์ที่ 1 มีการป้อน " + model.score21 + " ซึ่งมากกว่าคะแนนที่กำหนด (20 คะแนน)\n"); } if (Convert.ToDouble(model.score22) > 20) { sb.Append("คะแนนกรรมการคนที่ 1 คอลัมภ์ที่ 2 มีการป้อน " + model.score22 + " ซึ่งมากกว่าคะแนนที่กำหนด (20 คะแนน)\n"); } if (Convert.ToDouble(model.score23) > 5) { sb.Append("คะแนนกรรมการคนที่ 1 คอลัมภ์ที่ 3 มีการป้อน " + model.score23 + " ซึ่งมากกว่าคะแนนที่กำหนด (5 คะแนน)\n"); } if (Convert.ToDouble(model.score24) > 5) { sb.Append("คะแนนกรรมการคนที่ 1 คอลัมภ์ที่ 4 มีการป้อน " + model.score24 + " ซึ่งมากกว่าคะแนนที่กำหนด (5 คะแนน)\n"); } if (Convert.ToDouble(model.score31) > 20) { sb.Append("คะแนนกรรมการคนที่ 1 คอลัมภ์ที่ 1 มีการป้อน " + model.score31 + " ซึ่งมากกว่าคะแนนที่กำหนด (20 คะแนน)\n"); } if (Convert.ToDouble(model.score32) > 20) { sb.Append("คะแนนกรรมการคนที่ 1 คอลัมภ์ที่ 2 มีการป้อน " + model.score32 + " ซึ่งมากกว่าคะแนนที่กำหนด (20 คะแนน)\n"); } if (Convert.ToDouble(model.score33) > 5) { sb.Append("คะแนนกรรมการคนที่ 1 คอลัมภ์ที่ 3 มีการป้อน " + model.score33 + " ซึ่งมากกว่าคะแนนที่กำหนด (5 คะแนน)\n"); } if (Convert.ToDouble(model.score34) > 5) { sb.Append("คะแนนกรรมการคนที่ 1 คอลัมภ์ที่ 4 มีการป้อน " + model.score34 + " ซึ่งมากกว่าคะแนนที่กำหนด (5 คะแนน)\n"); } return(sb.ToString()); }
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)); }