Exemple #1
0
 public bool NewTKB(int lop, string namHoc)
 {
     try
     {
         if (namHoc.Length > 0)
         {
             DeleteTKB(lop, namHoc);
             using (var db = new TKBEntities())
             {
                 ThoiKhoaBieu tkb = new ThoiKhoaBieu()
                 {
                     Lop = db.Lops.FirstOrDefault(p => p.MaLop == lop),
                     NamHoc = namHoc
                 };
                 db.AddToThoiKhoaBieux(tkb);
                 db.SaveChanges();
                 return true;
             }
         }
         return false;
     }
     catch (Exception ex)
     {
         return false;
     }
 }
Exemple #2
0
        private void SaveTKB(List<ThoiKhoaBieu> lstTKB, List<Lop> dsLop)
        {
            using (var db = new TKBEntities())
            {

                foreach (ThoiKhoaBieu oTKB in lstTKB)
                {
                    if (oTKB.MaTKB == 0)
                    {
                        ThoiKhoaBieu tkb = new ThoiKhoaBieu()
                        {
                            Lop = db.Lops.FirstOrDefault(p => p.MaLop == oTKB.Lop.MaLop),
                            NamHoc = oTKB.NamHoc
                        };
                        db.AddToThoiKhoaBieux(tkb);
                        db.SaveChanges();
                        foreach (ChiTietTKB ct in oTKB.ChiTietTKBs.ToList())
                        {
                            ChiTietTKB chiTiet = new ChiTietTKB()
                            {
                                ThoiKhoaBieu = tkb,
                                MonHoc = db.MonHocs.FirstOrDefault(p => p.MaMonHoc == ct.MonHoc.MaMonHoc),
                                GiaoVien = db.GiaoViens.FirstOrDefault(p => p.MaGiaoVien == ct.GiaoVien.MaGiaoVien),
                                Phong = db.Phongs.FirstOrDefault(p => p.MaPhong == ct.Phong.MaPhong),
                                TietBatDau = ct.TietBatDau + 1,
                                TietKetThuc = ct.TietKetThuc + 1,
                                Thu = ct.Thu + 2
                            };
                            db.AddToChiTietTKBs(chiTiet);
                            db.SaveChanges();
                        }
                    }
                }
            }
        }