/// <summary> /// Lấy danh sách sinh viên thi của từng môn học /// </summary> private static void GetStudentList() { int SumStudents = 0; StudentByGroup = new Dictionary <String, List <String> >(); for (int GroupIndex = 0; GroupIndex < AlgorithmRunner.Groups.Count; GroupIndex++) { String SubjectID = AlgorithmRunner.GetSubjectID(AlgorithmRunner.Groups[GroupIndex]); String ClassList = AlgorithmRunner.GetClassList(AlgorithmRunner.Groups[GroupIndex]); //String IgnoreStudents = InputHelper.IgnoreStudents.ContainsKey(SubjectID) ? JsonConvert.SerializeObject(InputHelper.IgnoreStudents[SubjectID]) : "[]"; //IgnoreStudents = IgnoreStudents.Substring(1, IgnoreStudents.Length - 2).Replace("\"", "'"); IEnumerable <String> Result = InputHelper.db.Database.SqlQuery <String>("select sinhvien.MaSinhVien from pdkmh, sinhvien " + "where pdkmh.MaSinhVien = sinhvien.MaSinhVien " + "and MaMonHoc = '" + SubjectID + "' " // + (IgnoreStudents.Length > 0 ? "and not(sinhvien.MaSinhVien in (" + IgnoreStudents + ")) " : "") + "and pdkmh.Nhom in(" + ClassList + ") " + "order by (Ten + Ho)"); StudentByGroup.Add(AlgorithmRunner.Groups[GroupIndex], Result.ToList <String>()); SumStudents += Result.ToList <String>().Count; } if (SumStudents > SumContaint) { AlgorithmRunner.SaveOBJ("Status", "err Phòng thi không đủ"); AlgorithmRunner.IsBusy = false; Thread.CurrentThread.Abort(); } AlgorithmRunner.GroupsRoom = new List <Room> [AlgorithmRunner.Groups.Count]; AlgorithmRunner.GroupsRoomStudents = new List <String> [AlgorithmRunner.Groups.Count][]; }
private static void Save() { int GCount = AlgorithmRunner.Groups.Count; for (int GroupIndex = 0; GroupIndex < GCount; GroupIndex++) { Thi aRecord = new Thi(); aRecord.MaMonHoc = AlgorithmRunner.GetSubjectID(AlgorithmRunner.Groups[GroupIndex]); aRecord.Nhom = AlgorithmRunner.GetClassList(AlgorithmRunner.Groups[GroupIndex]); DateTime FirstShiftTime = InputHelper.Options.StartDate.AddHours(InputHelper.Options.Times[0].Hour) .AddMinutes(InputHelper.Options.Times[0].Minute); String ShiftID = "";// InputHelper.Options.StartDate.Year + "" + InputHelper.Options.StartDate.Month + "" + InputHelper.Options.StartDate.Day; ShiftID += RoomArrangement.CalcShift(FirstShiftTime, AlgorithmRunner.GroupsTime[GroupIndex]).ToString(); if ((from ct in db.CaThis where ct.MaCa == ShiftID select ct).Count() == 0) { var pa = new SqlParameter[] { new SqlParameter("@MaCa", SqlDbType.NVarChar) { Value = ShiftID }, new SqlParameter("@GioThi", SqlDbType.DateTime) { Value = AlgorithmRunner.GroupsTime[GroupIndex] }, }; db.Database.ExecuteSqlCommand("INSERT INTO CaThi (MaCa, GioThi) VALUES (@MaCa, @GioThi)", pa); } aRecord.MaCa = ShiftID; String SQLQuery = ""; for (int RoomIndex = 0; RoomIndex < AlgorithmRunner.GroupsRoom[GroupIndex].Count; RoomIndex++) { aRecord.MaPhong = AlgorithmRunner.GroupsRoom[GroupIndex][RoomIndex].RoomID; for (int StudentIndex = 0; StudentIndex < AlgorithmRunner.GroupsRoomStudents[GroupIndex][RoomIndex].Count; StudentIndex++) { aRecord.MaSinhVien = AlgorithmRunner.GroupsRoomStudents[GroupIndex][RoomIndex][StudentIndex]; SQLQuery += String.Format("INSERT INTO Thi (MaCa, MaMonHoc, Nhom, MaPhong, MaSinhVien) VALUES ('{0}', '{1}', '{2}', '{3}', '{4}')\r\n", aRecord.MaCa, aRecord.MaMonHoc, aRecord.Nhom, aRecord.MaPhong, aRecord.MaSinhVien ); } // sinh viên } // phòng try { AlgorithmRunner.SaveOBJ("Status", "inf Đang Lưu vào cơ sở dữ liệu (" + (GroupIndex + 1) + "/" + GCount + ")"); db.Database.ExecuteSqlCommand(SQLQuery); } catch { AlgorithmRunner.SaveOBJ("Status", "err Lỗi trong khi chèn thêm nội dung vào CSDL! Hãy thử lại hoặc liên hệ với quản trị nếu vẫn lỗi!"); AlgorithmRunner.IsBusy = false; Thread.CurrentThread.Abort(); } }// môn }
static int CheckGroups(String Group1ID, String Group2ID) { String Subject1ID = AlgorithmRunner.GetSubjectID(Group1ID); String Subject2ID = AlgorithmRunner.GetSubjectID(Group2ID); String Group1 = AlgorithmRunner.GetClassList(Group1ID); String Group2 = AlgorithmRunner.GetClassList(Group2ID); if (Subject1ID == Subject2ID && Group1 != Group2) { return(1); } /*String StudentsList1 = ""; * String StudentsList2 = ""; * try * { * foreach (String st in InputHelper.IgnoreStudents[Subject1ID]) * { * StudentsList1 += (StudentsList1.Length > 0 ? ", " : "") + "'" + st + "'"; * } * } * catch { } * * try * { * foreach (String st in InputHelper.IgnoreStudents[Subject2ID]) * { * StudentsList2 += (StudentsList2.Length > 0 ? ", " : "") + "'" + st + "'"; * } * } * catch { }*/ var pa = new SqlParameter[] { new SqlParameter("@S1ID", SqlDbType.NVarChar) { Value = Subject1ID }, new SqlParameter("@S2ID", SqlDbType.NVarChar) { Value = Subject2ID } }; int Result = db.Database.SqlQuery <int>("select count(s1.MaSinhVien) from pdkmh as s1 " + "where s1.MaSinhVien in (select s2.MaSinhVien from pdkmh as s2 " + "where s2.MaMonHoc = @S2ID " //+ (StudentsList2.Length > 0 ? "and not(s2.MaSinhVien in (" + StudentsList2 + "))" : "") + "and s2.Nhom in(" + Group2 + ")" + ") " // + (StudentsList1.Length > 0 ? "and not(s1.MaSinhVien in (" + StudentsList1 + "))" : "") + "and s1.MaMonHoc = @S1ID " + "and s1.Nhom in(" + Group1 + ")", pa).ElementAt(0); return(Result == 0 ? 0 : 1); }