public async Task <IActionResult> Edit(int id, [Bind("ThiId,TenThi,NguoiDungId")] Thi thi) { if (id != thi.ThiId) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(thi); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!ThiExists(thi.ThiId)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } ViewData["NguoiDungId"] = new SelectList(_context.NguoiDungs, "NguoiDungId", "DiaChi", thi.NguoiDungId); return(View(thi)); }
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 }
public async Task <IActionResult> Create([Bind("ThiId,TenThi,NguoiDungId")] Thi thi) { if (ModelState.IsValid) { _context.Add(thi); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } ViewData["NguoiDungId"] = new SelectList(_context.NguoiDungs, "NguoiDungId", "DiaChi", thi.NguoiDungId); return(View(thi)); }
public IActionResult TracNghiem() { var listCauHoi = _context.CauHoi.ToList(); var cauHois = new List <CauHoi>(); var i = 0; var rd = new Random(); while (i < 3) { int a = rd.Next(0, listCauHoi.Count); cauHois.Add(listCauHoi.ToArray()[a]); listCauHoi.RemoveAt(a); i++; } //Thi thi = new Thi(); //appDataContext.Thi.Add(thi); var Thi = new Thi(); return(View(cauHois)); }
// đổi mã lớp private void maLop_SelectedIndexChanged(object sender, EventArgs e) { string maLop = cbMain.Text; if (thi == null) { thi = new Thi(); } DataTable dt = thi.findDiemThiByMaLop(AccountHelper.getAccountId(), AccountHelper.getAccoutPassword(), maLop); // sửa cột kết quả int endColumn = dt.Columns.Count - 1; //dt.Columns[endColumn].DataType = typeof(string); dt.Columns.Add("Kết quả", typeof(string)); DataRowCollection rows = dt.Rows; for (int i = 0; i < rows.Count; i++) { if (rows[i].Field <int>(endColumn).Equals(0)) { rows[i].SetField(endColumn + 1, "rớt"); } else { rows[i].SetField(endColumn + 1, "đậu"); } } dt.Columns.RemoveAt(endColumn); DateTime today = DateTime.Today; name = today.Month + "-" + today.Day + "-" + today.Year + "_KetQuaHocTap_" + maLop; ShowTable(dt); }
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); }