public ActionResult Special(ProcessStudentModel model) { if (Session["USER"] == null) { return(RedirectToAction("../Account/ManagementLogin")); } ViewBag.ResultMsg = ""; using (ChinaPhet10Entities context = new ChinaPhet10Entities()) { List <TB_APPLICATION_STUDENT> students = null; var _result = from a in db.TB_APPLICATION_STUDENT orderby a.STD_LEVEL_ID, a.STD_ID select a; var sitPlaned = from b in db.TB_STUDENT_SEAT select b.STUDENT_ID; var stdCodes = from b in db.TB_STUDENT_SEAT orderby b.STUDENT_CODE ascending select b; int lastLevel1 = 0; int lastLevel2 = 0; int lastLevel3 = 0; int lastLevel4 = 0; int lastLevel5 = 0; lastLevel1 = getLastStudentCode(stdCodes.ToList(), 1); lastLevel2 = getLastStudentCode(stdCodes.ToList(), 2); lastLevel3 = getLastStudentCode(stdCodes.ToList(), 3); lastLevel4 = getLastStudentCode(stdCodes.ToList(), 4); lastLevel5 = getLastStudentCode(stdCodes.ToList(), 5); //นำข้อมูลรายชื่อนักเรียนที่ยังไม่ได้จัดมาเก็บไว้ใน tmp var tmp = from x in _result where !sitPlaned.Contains(x.STD_ID) orderby x.STD_LEVEL_ID, x.STD_ID select x; students = tmp.ToList(); if (students.Count > 0) { var varRoom = from a in db.TB_ROOM where a.ROOM_FOR_LEVEL == 6 orderby a.ROOM_FOR_LEVEL, a.ROOM_ID select a; List <TB_ROOM> rooms = varRoom.ToList(); if (rooms != null) { int studentIndex = 0; String[] rowPrefix = { "A", "B", "C", "D", "E", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z" }; foreach (TB_ROOM room in rooms) { int sitIndex = 1; String[] rows = room.ROOM_ROW.ToUpper().Split('X'); if (rows.Length == 2) { int col = Convert.ToInt16(rows[0]); //c int row = Convert.ToInt16(rows[1]); //r // 1. วนแต่ละแถวเพื่อเรียงลำดับเลขที่นั่งสอบ for (int c = 0; c < col; c++) { int level = 0; switch (c + 1) { case 1: level = Convert.ToInt16(room.ROW_1); break; case 2: level = Convert.ToInt16(room.ROW_2); break; case 3: level = Convert.ToInt16(room.ROW_3); break; case 4: level = Convert.ToInt16(room.ROW_4); break; case 5: level = Convert.ToInt16(room.ROW_5); break; case 6: level = Convert.ToInt16(room.ROW_6); break; case 7: level = Convert.ToInt16(room.ROW_7); break; case 8: level = Convert.ToInt16(room.ROW_8); break; case 9: level = Convert.ToInt16(room.ROW_9); break; case 10: level = Convert.ToInt16(room.ROW_10); break; case 11: level = Convert.ToInt16(room.ROW_11); break; case 12: level = Convert.ToInt16(room.ROW_12); break; } for (int r = 0; r < row; r++) { if (studentIndex < students.Count) { if (level == students[studentIndex].STD_LEVEL_ID) { //get last index logger.Debug(c + 1 + "," + r + "=" + students[studentIndex].STD_ID + "," + room.ROOM_NUMBER + "\n"); TB_STUDENT_SEAT ss = new TB_STUDENT_SEAT(); ss.STUDENT_ID = students[studentIndex].STD_ID; switch (level) { case 1: ss.STUDENT_CODE = Convert.ToInt32(String.Format("{0}{1}", students[studentIndex].STD_LEVEL_ID, (lastLevel1 + sitIndex).ToString("0000"))); break; case 2: ss.STUDENT_CODE = Convert.ToInt32(String.Format("{0}{1}", students[studentIndex].STD_LEVEL_ID, (lastLevel2 + sitIndex).ToString("0000"))); break; case 3: ss.STUDENT_CODE = Convert.ToInt32(String.Format("{0}{1}", students[studentIndex].STD_LEVEL_ID, (lastLevel3 + sitIndex).ToString("0000"))); break; case 4: ss.STUDENT_CODE = Convert.ToInt32(String.Format("{0}{1}", students[studentIndex].STD_LEVEL_ID, (lastLevel4 + sitIndex).ToString("0000"))); break; case 5: ss.STUDENT_CODE = Convert.ToInt32(String.Format("{0}{1}", students[studentIndex].STD_LEVEL_ID, (lastLevel5 + sitIndex).ToString("0000"))); break; } ss.ROOM_ID = room.ROOM_ID; ss.SIT_NUMBER_PREFIX = rowPrefix[c]; ss.SIT_NUMBER = (r + 1); context.TB_STUDENT_SEAT.Add(ss); } else { continue; } } sitIndex++; studentIndex++; } } } else { logger.Debug(room.ROOM_NUMBER + ":ข้อมูล COLXROW ใน DB ของห้องไม่ถุกต้อง"); } } context.SaveChanges(); } else { logger.Debug("ไม่พบข้อมุลห้องว่าง"); } } else { ViewBag.ResultMsg = "ไม่พบข้อมูลนักเรียนที่ยังไม่ได้ที่นั่งสอบ"; return(View(model)); } } ViewBag.ResultMsg = "ประมวลผลที่นั่งสอบเรียบร้อยแล้ว"; return(View(model)); }
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 Index(ProcessStudentModel model) { if (Session["USER"] == null) { return(RedirectToAction("../Account/ManagementLogin")); } StringBuilder noRoomStd = new StringBuilder(); ViewBag.ResultMsg = ""; //int countOfCommittee = 0; int countOfSuccess = 0; //int countOfFail = 0; using (ChinaPhet10Entities context = new ChinaPhet10Entities()) { List <TB_APPLICATION_STUDENT> students = null; int studentLevel = Convert.ToInt16(model.StudentLevel); if (!String.IsNullOrWhiteSpace(model.StudentLevel)) { var varStudent = from a in db.TB_APPLICATION_STUDENT where a.STD_LEVEL_ID == studentLevel && a.STD_APPROVED_STATUS == 3 orderby a.STD_LEVEL_ID, a.STD_ID select a; students = varStudent.ToList(); } if (students != null) { /* * DELETE TB_STUDENT_SEAT BY LEVEL */ foreach (TB_APPLICATION_STUDENT std in students) { if (std.TB_STUDENT_SEAT != null) { TB_STUDENT_SEAT studentSeat = context.TB_STUDENT_SEAT.Where(s => s.STUDENT_CODE == std.TB_STUDENT_SEAT.STUDENT_CODE).FirstOrDefault(); context.TB_STUDENT_SEAT.Remove(studentSeat); } } var varRoom = from a in db.TB_ROOM where a.ROOM_FOR_LEVEL == studentLevel orderby a.ROOM_FOR_LEVEL, a.ROOM_ID select a; List <TB_ROOM> rooms = varRoom.ToList(); if (rooms != null) { int index = 0; int studentIndex = 1; int examSitIndex = 1; int tmpLevel = Convert.ToInt16(rooms[0].ROOM_FOR_LEVEL); String[] rowPrefix = { "A", "B", "C", "D", "E", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z" }; foreach (TB_ROOM room in rooms) { if (tmpLevel != room.ROOM_FOR_LEVEL) { studentIndex = 1; examSitIndex = 1; } String[] rows = room.ROOM_ROW.ToUpper().Split('X'); if (rows.Length == 2) { int width = Convert.ToInt16(rows[0]); int height = Convert.ToInt16(rows[1]); // 1. วนแต่ละแถวเพื่อเรียงลำดับเลขที่นั่งสอบ for (int w = 0; w < width; w++) { for (int h = 0; h < height; h++) { if (index < students.Count) { TB_STUDENT_SEAT ss = new TB_STUDENT_SEAT(); ss.STUDENT_ID = students[index].STD_ID; ss.STUDENT_CODE = Convert.ToInt32(String.Format("{0}{1}", students[index].STD_LEVEL_ID, studentIndex.ToString("0000"))); ss.ROOM_ID = room.ROOM_ID; ss.SIT_NUMBER_PREFIX = rowPrefix[w]; ss.SIT_NUMBER = (h + 1);//Convert.ToInt32(String.Format("{0}{1}", room.ROOM_FOR_LEVEL, examSitIndex.ToString("0000"))); context.TB_STUDENT_SEAT.Add(ss); index++; studentIndex++; examSitIndex++; countOfSuccess++; } else { Console.WriteLine("จำนวนคนไม่พอกับจำนวนห้อง !"); } } } } else { //generate row error. Console.WriteLine(); } } } context.SaveChanges(); } } List <TB_M_LEVEL> tbMLevel = db.TB_M_LEVEL.Where(l => l.LEVEL_ID > 0).ToList(); ViewBag.StudentLevel = new SelectList(tbMLevel, "LEVEL_ID", "LEVEL_NAME_TH", model.StudentLevel); ViewBag.ResultMsg = "ประมวลผลที่นั่งสอบเรียบร้อยแล้ว";//+ ("จำนวนนักเรียนทั้งหมด " + students. + " คน <br> สำเร็จ " + countOfSuccess + " รายการ <br> ไม่สำเร็จ " + countOfFail + " รายการ)"; return(View(model)); }