public static List <LICHHOC> GetLichHoc(LOPHOCPHAN lopHocPhan, THOIKHOABIEU thoiKhoaBieu) { using (var db = new UMS_HUSCEntities()) { var ngayBatDauHoc = lopHocPhan.NgayBatDauHoc; var ngayKetThucHoc = lopHocPhan.NgayKetThucHoc; var ngayTrongTuan = thoiKhoaBieu.NgayTrongTuan - 1; var lichHoc = new List <LICHHOC>(); for (var index = ngayBatDauHoc; index <= ngayKetThucHoc; index = index.AddHours(24)) { if (index.DayOfWeek.GetHashCode() == ngayTrongTuan) { var item = new LICHHOC() { MaLopHocPhan = lopHocPhan.MaLopHocPhan, PhongHoc = thoiKhoaBieu.PhongHoc, TietHocBatDau = thoiKhoaBieu.TietHocBatDau, TietHocKetThuc = thoiKhoaBieu.TietHocKetThuc, NgayHoc = index }; lichHoc.Add(item); } } return(lichHoc); } }
public ActionResult DemoAddScheduleSecond(FormCollection form) { var maLopHocPhan = form["maLopHocPhan"]; var tietHocBatDau = form["tietHocBatDau"]; var tietHocKetThuc = form["tietHocKetThuc"]; var ngayHoc = form["ngayHoc"]; var phongHoc = form["phongHoc"]; var lichHoc = new LICHHOC() { MaLopHocPhan = maLopHocPhan, PhongHoc = int.Parse(phongHoc), TietHocBatDau = int.Parse(tietHocBatDau), TietHocKetThuc = int.Parse(tietHocKetThuc), NgayHoc = DateTime.ParseExact(ngayHoc, "yyyy-MM-dd", CultureInfo.InvariantCulture) }; DemoKetQua demo = new DemoKetQua(); if (LopHocPhanDao.TonTaiLichHoc(lichHoc)) { demo.PhanHoi = "Lịch học đã tồn tại"; return(RedirectToAction("DemoAddScheduleFirst", "Demo", demo)); } LopHocPhanDao.AddLichHoc(lichHoc); FCMController fcm = new FCMController(); string notification = fcm.CreateScheduleNotification(lichHoc); string response = fcm.SendMessage(notification); demo.PhanHoi = response; demo.TinGuiDi = notification; return(RedirectToAction("DemoAddScheduleFirst", "Demo", demo)); }
public static void AddLichHoc(LICHHOC lichHoc) { using (var db = new UMS_HUSCEntities()) { db.LICHHOCs.Add(lichHoc); db.SaveChanges(); } }
public static bool TonTaiLichHoc(LICHHOC lichHoc) { using (var db = new UMS_HUSCEntities()) { var current = db.LICHHOCs.FirstOrDefault(i => i.MaLopHocPhan.Equals(lichHoc.MaLopHocPhan) && i.NgayHoc.Day == lichHoc.NgayHoc.Day && i.NgayHoc.Month == lichHoc.NgayHoc.Month && i.NgayHoc.Year == lichHoc.NgayHoc.Year && i.PhongHoc == lichHoc.PhongHoc && i.TietHocBatDau == lichHoc.TietHocBatDau && i.TietHocKetThuc == lichHoc.TietHocKetThuc); return(current != null); } }
public ActionResult QR(int?id) { using (MemoryStream ms = new MemoryStream()) { //id user int iduser = Convert.ToInt32(Session["IDNGUOIDUNG"]); string idgiangvien = Convert.ToString(Session["IDNGUOIDUNG"]); //ramdon int Numrd; string Numrd_str; Random rd = new Random(); Numrd = rd.Next(10000000, 1000000000); //biến Numrd sẽ nhận có giá trị ngẫu nhiên Numrd_str = rd.Next(10000000, 1000000000).ToString(); //Chuyển giá trị ramdon về kiểu string //ngay thang DateTime dt = DateTime.Now; string strDate = dt.ToString("dd/MM/yy,hh:mm"); //lay idlopmonhoc string idlopmonhoc = Convert.ToString(id); //chuyển id ở trên qua string //string dayqr = idmonhoc+'-'+Numrd_str+'-'+strDate; string dayqr = idgiangvien + '-' + idlopmonhoc + '-' + Numrd_str + '-' + strDate; //linq LICHHOC lichhoc = new LICHHOC(); lichhoc.THOIGIANDIEMDANH = DateTime.Now; lichhoc.MAQR = dayqr; lichhoc.IDLOPMH = id.Value; lichhoc.IDNGUOIDUNG = iduser; db.LICHHOCs.Add(lichhoc); db.SaveChangesAsync(); QRCodeGenerator qrGenerator = new QRCodeGenerator(); QRCodeData qrCodeData = qrGenerator.CreateQrCode(dayqr, QRCodeGenerator.ECCLevel.Q); QRCode qrCode = new QRCode(qrCodeData); Bitmap qrCodeImage = qrCode.GetGraphic(20); using (Bitmap bitMap = qrCode.GetGraphic(20)) { bitMap.Save(ms, ImageFormat.Png); ViewBag.QRCodeImage = "data:image/png;base64," + Convert.ToBase64String(ms.ToArray()); } } return(View()); }
public int delete(string code) { using (QLTTEntities qltt = new QLTTEntities()) { LICHHOC lh = qltt.LICHHOCs.Where(p => p.MALH == code).FirstOrDefault(); if (lh != null) { qltt.LICHHOCs.Remove(lh); qltt.SaveChanges(); return(1); } } return(0); }
public DataTable get(string code) { using (QLTTEntities qltt = new QLTTEntities()) { LICHHOC lh = qltt.LICHHOCs.Where(p => p.MALH == code).FirstOrDefault(); if (lh != null) { DataTable rtnTable = new DataTable(); rtnTable.Columns.Add("MALH", typeof(string)); rtnTable.Columns.Add("NGAYHOC", typeof(string)); rtnTable.Columns.Add("GIOHOC", typeof(string)); rtnTable.Rows.Add(lh.MALH, lh.NGAYHOC, lh.GIOHOC); return(rtnTable); } } return(null); }
public string CreateScheduleNotification(LICHHOC lichHoc) { var arrRegid = FireBaseDao.GetFireBaseTokenByClass(lichHoc.MaLopHocPhan); if (arrRegid.Length == 0) return null; var lopHocPhan = LopHocPhanDao.GetLopHocPhan(lichHoc.MaLopHocPhan); var phongHoc = LopHocPhanDao.GetPhongHoc(lichHoc.PhongHoc); var giangVien = LopHocPhanDao.GetGiangVien(lopHocPhan.GiangVienPhuTrach); ThoiKhoaBieu thoiKhoaBieu = new ThoiKhoaBieu() { MaLopHocPhan = lopHocPhan.MaLopHocPhan, TenLopHocPhan = lopHocPhan.TenLopHocPhan, NgayHoc = lichHoc.NgayHoc, HoVaTen = giangVien.HoVaTen, NgayTrongTuan = lichHoc.NgayHoc.DayOfWeek.GetHashCode() + 1, PhongHoc = phongHoc.MaPhong, TenPhong = phongHoc.TenPhong, TietHocBatDau = lichHoc.TietHocBatDau, TietHocKetThuc = lichHoc.TietHocKetThuc, HocKy = LopHocPhanDao.MaxMaHocKy(), MaSinhVien = "" }; string notiBody = JsonConvert.SerializeObject(thoiKhoaBieu); PushNotification notification = new PushNotification() { registration_ids = arrRegid, data = new Data() { title = "Lịch học bù", body = notiBody, postTime = DateTime.Now.ToString(), type = SCHEDULE_NOTIFICATION } }; string postData = JsonConvert.SerializeObject(notification); return postData; }
public int insert(string malh, string ngayhoc, string giohoc) { try { using (QLTTEntities qltt = new QLTTEntities()) { LICHHOC lh = new LICHHOC() { MALH = malh, NGAYHOC = ngayhoc, GIOHOC = giohoc }; qltt.LICHHOCs.Add(lh); qltt.SaveChanges(); return(1); } } catch { return(0); } }
public int update(string malh, string ngayhoc, string giohoc) { try { using (QLTTEntities qltt = new QLTTEntities()) { LICHHOC lh = qltt.LICHHOCs.Where(p => p.MALH == malh).FirstOrDefault(); if (lh != null) { lh.NGAYHOC = ngayhoc; lh.GIOHOC = giohoc; qltt.SaveChanges(); return(1); } return(0); } } catch { return(0); } }