public void Create(ThoiKhoaBieu tkb)
        {
            LopTinChiBLL contextLTC = new LopTinChiBLL();
            MonHocBLL    contextMH  = new MonHocBLL();
            // lấy thông tin lớp tín chỉ của thời khóa biểu.
            LopTinChi ltc = contextLTC.GetById(tkb.MaLopTC);
            //Lasays thông tin môn học
            MonHoc mh = contextMH.GetById(ltc.MaMonHoc);

            int soBuoi = 0;
            int sotc   = mh.SoTinChiLyThuyet + mh.SoTinChiThucHanh;

            if (sotc * 15 % 4 != 0)
            {
                soBuoi = (int)(sotc * 15 / 4) + 1;
            }
            else
            {
                soBuoi = sotc * 15 / 4;
            }
            try
            {
                for (int i = 0; i < soBuoi; i++)
                {
                    context.Create(tkb);
                    tkb.Ngay = tkb.Ngay.AddDays(7);
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex);
            }
        }
        /// <summary>
        /// Lấy số tiết trong khaongr ngày
        /// </summary>
        /// <param name="dtStart"></param>
        /// <param name="dtEnd"></param>
        /// <param name="soBuoiHocTrongTuan"></param>
        /// <returns></returns>
        public int SoTietHocCoTheMo(DateTime dtStart, DateTime dtEnd, int soBuoiHocTrongTuan)
        {
            LopTinChiBLL     contextLTC      = new LopTinChiBLL();
            List <LopTinChi> lstLTC          = contextLTC.GetAll();
            Date             supportDateTime = new Date();
            int dem = 0;

            if (dtStart.DayOfYear > dtEnd.DayOfYear)
            {
                return(0);
            }
            if (soBuoiHocTrongTuan < 0 && soBuoiHocTrongTuan > 48)
            {
                return(0);
            }
            //lấy tuần bắt đầu và tuần kết thúc
            int tuanBD = 0, tuanKT = 0, tongSoTuan = 0;

            if (dtStart.Year == dtEnd.Year)
            {
                List <string> lstTuan = supportDateTime.GetListDate(dtStart.Year);
                for (int i = 0; i < lstTuan.Count; i++)
                {
                    DateTime tempDTStart = new DateTime();
                    DateTime tempDTEnd   = new DateTime();
                    // Lấy datetime từ list Tuần và format về "dd/mm/yy"
                    tempDTStart = DateTime.Parse(lstTuan[i].Split('-')[1], new CultureInfo("en-US"));
                    tempDTEnd   = DateTime.Parse(lstTuan[i].Split('-')[3], new CultureInfo("en-US"));
                    // Nếu ngày bắt đầu không phải là thứ 2 thì lấy thứ 2 của tuần kế tiếp
                    if (dtStart.DayOfWeek != DayOfWeek.Monday)
                    {
                        while (dtStart.DayOfWeek != DayOfWeek.Monday)
                        {
                            dtStart = dtStart.AddDays(1);
                        }
                    }
                    if (dtStart.DayOfYear >= tempDTStart.DayOfYear && dtStart.DayOfYear <= tempDTEnd.DayOfYear)
                    {
                        tuanBD = i;
                    }
                    if (dtEnd.DayOfYear >= tempDTStart.DayOfYear && dtEnd.DayOfYear <= tempDTEnd.DayOfYear)
                    {
                        tuanKT = i;
                    }
                    if (tuanBD != 0 && tuanKT != 0)
                    {
                        break;
                    }
                }
            }
            // nếu 2 năm khác nhau vì 1 học kỳ chỉ ở trong 1 năm
            else
            {
                return(0);
            }
            tongSoTuan = tuanKT - tuanBD + 1;
            dem        = tongSoTuan * soBuoiHocTrongTuan * 4;
            return(dem);
        }
示例#3
0
        /// <summary>
        /// Lay 1 record dua vao ma lop
        /// </summary>
        /// <param name="maLop"></param>
        /// <returns>Lop</returns>
        public LopTinChi GetById(int maLop)
        {
            GiangVienBLL     ctGV        = new GiangVienBLL();
            LopTinChiBLL     contextLTC  = new LopTinChiBLL();
            MonHocBLL        contextMH   = new MonHocBLL();
            NienKhoaHocKyBLL contextNKHK = new NienKhoaHocKyBLL();

            try
            {
                LopTinChi lopTinChi = context.GetById(maLop);
                lopTinChi.NienKhoaHocKy = contextNKHK.GetById(lopTinChi.NienKhoa);
                lopTinChi.MonHoc        = contextMH.GetById(lopTinChi.MaMonHoc);
                lopTinChi.GiangVien     = ctGV.GetById(lopTinChi.MaGV);
                return(lopTinChi);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex);
                return(null);
            }
        }
        /// <summary>
        /// Lấy tất cả record trong  hiện tại, trước  và sau 1 năm
        /// </summary>
        /// <returns>List</returns>
        public List <ThoiKhoaBieu> GetTKBCurent()
        {
            LopTinChiBLL contextLopTC = new LopTinChiBLL();
            GiangVienBLL contextGV    = new GiangVienBLL();
            int          yearNow      = DateTime.UtcNow.Year;
            int          yearLast     = yearNow - 1;
            int          yearFt       = yearNow + 1;

            List <ThoiKhoaBieu> listThoiKhoaBieu = context.GetAll();

            foreach (ThoiKhoaBieu tkb in listThoiKhoaBieu)
            {
                if (tkb.Ngay.Year < yearNow && tkb.Ngay.Year > yearLast)
                {
                    listThoiKhoaBieu.Remove(tkb);
                }
                else
                {
                    tkb.LopTinChi           = contextLopTC.GetById(tkb.MaLopTC);
                    tkb.LopTinChi.GiangVien = contextGV.GetById(tkb.LopTinChi.MaGV);
                }
            }
            return(listThoiKhoaBieu);
        }