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 }
private void RunNext() { IsBusy = true; if (OBJExits("AdjacencyMatrix") && !OBJExits("BeginI")) { SaveOBJ("Status", "inf Đang xếp lịch..."); ReadAdjacencyMatrix(RealPath("AdjacencyMatrix")); GraphColoringAlgorithm.Run(); SaveOBJ("Status", "inf Tô màu xong! Đang xếp thời gian..."); RoomArrangement.Run(); SaveOBJ("Status", "inf Xếp lịch xong! Hãy lưu kết quả vào CSDL (Tất cả các kết quả xếp lịch trước sẽ bị xoá)"); } else { SaveOBJ("Status", "err Chưa hoàn thiện quá trình phân tích CSDL"); } IsBusy = false; }
public static void Save(HandmadeData Data) { DKMHEntities db = new DKMHEntities(); var ClassList = ""; foreach (String cl in Data.Class) { ClassList += (ClassList.Length > 0 ? ", " : "") + "'" + cl + "'"; } var StudentList = db.Database.SqlQuery <StudentInfo>("select pdkmh.MaSinhVien, pdkmh.Nhom from pdkmh, sinhvien " + "where pdkmh.MaSinhVien = sinhvien.MaSinhVien and MaMonHoc = '" + Data.SubjectID + "' and Nhom in (" + ClassList + ") " ).ToList(); var DotQry = (from m in InputHelper.db.This select m.Dot).Max(); int dot = 1; if (DotQry != null) { dot = int.Parse(DotQry[0].ToString()); } DateTime FirstShiftTime = InputHelper.Options.StartDate.AddHours(InputHelper.Options.Times[0].Hour) .AddMinutes(InputHelper.Options.Times[0].Minute); String ShiftID = dot.ToString();//InputHelper.Options.StartDate.Year + "" + InputHelper.Options.StartDate.Month + "" + InputHelper.Options.StartDate.Day; ShiftID += "_" + RoomArrangement.CalcShift(FirstShiftTime, Data.Date).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 = Data.Date }, }; db.Database.ExecuteSqlCommand("INSERT INTO CaThi (MaCa, GioThi) VALUES (@MaCa, @GioThi)", pa); } Thi aRecord = new Thi(); aRecord.MaMonHoc = Data.SubjectID; aRecord.MaCa = ShiftID; ClassList = ""; foreach (String cl in Data.Class) { ClassList += cl + ","; } ClassList = ClassList.Remove(ClassList.Length - 1, 1); aRecord.Nhom = ClassList; String SQLQuery = ""; int StudentIndex = 0; for (int Index = 0; Index < Data.Room.Count; Index++) { aRecord.MaPhong = Data.Room[Index]; for (int i = 0; i < Data.Num[Index]; i++) { aRecord.MaSinhVien = StudentList[StudentIndex].MaSinhVien; SQLQuery += String.Format("INSERT INTO Thi (MaCa, MaMonHoc, Nhom, MaPhong, MaSinhVien, Dot) VALUES ('{0}', '{1}', '{2}', '{3}', '{4}','{5}')\r\n", aRecord.MaCa, aRecord.MaMonHoc, aRecord.Nhom, aRecord.MaPhong, aRecord.MaSinhVien, dot ); StudentIndex++; } int RoomIndex = InputHelper.Rooms.Find(m => m.Time == Data.Date).Rooms.FindIndex(m => m.RoomID == aRecord.MaPhong); InputHelper.Rooms.Find(m => m.Time == Data.Date).Rooms[RoomIndex].IsBusy = true; } db.Database.ExecuteSqlCommand(SQLQuery); AlgorithmRunner.SaveOBJ("Rooms", InputHelper.Rooms); }
public static void Save(HandmadeData Data) { DKMHEntities db = new DKMHEntities(); var ClassList = ""; foreach (String cl in Data.Class) { ClassList += (ClassList.Length > 0 ? ", " : "") + "'" + cl + "'"; } String IgnoreStudents = InputHelper.IgnoreStudents.ContainsKey(Data.SubjectData) ? JsonConvert.SerializeObject(InputHelper.IgnoreStudents[Data.SubjectData]) : "[]"; IgnoreStudents = IgnoreStudents.Substring(1, IgnoreStudents.Length - 2).Replace("\"", "'"); var StudentList = db.Database.SqlQuery <StudentInfo>("select pdkmh.MaSinhVien, pdkmh.Nhom from pdkmh, sinhvien " + "where pdkmh.MaSinhVien = sinhvien.MaSinhVien and MaMonHoc = '" + Data.SubjectData + "' and Nhom in (" + ClassList + ") " + (IgnoreStudents.Length > 0 ? "and not(sinhvien.MaSinhVien in (" + IgnoreStudents + ")) " : "") + "order by (sinhvien.Ten + sinhvien.ho)").ToList(); 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, Data.Date).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 = Data.Date }, }; db.Database.ExecuteSqlCommand("INSERT INTO CaThi (MaCa, GioThi) VALUES (@MaCa, @GioThi)", pa); } Thi aRecord = new Thi(); aRecord.MaMonHoc = Data.SubjectData; aRecord.MaCa = ShiftID; var ClassGroup = Data.SubjectData; foreach (var cl in Data.Class) { ClassGroup += "_" + cl; } aRecord.Nhom = ClassGroup; String SQLQuery = ""; int StudentIndex = 0; for (int Index = 0; Index < Data.Room.Count; Index++) { aRecord.MaPhong = Data.Room[Index]; for (int i = 0; i < Data.Num[Index]; i++) { aRecord.MaSinhVien = StudentList[StudentIndex].MaSinhVien; 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 ); StudentIndex++; } } db.Database.ExecuteSqlCommand(SQLQuery); }