public static void Insert(BANGDIEM _bangdiem)
        {
            try
            {
                _bangdiem.CreatedDate = DateTime.Now;
                _bangdiem.CreatedBy   = GlobalSettings.UserCode;
                _bangdiem.CreatedLog  = GlobalSettings.SessionMyIP;
                _bangdiem.IsRemove    = 0;
                Database.BANGDIEMs.InsertOnSubmit(_bangdiem);
                Database.SubmitChanges();
                int _id = _bangdiem.BangDiemId;

                //Insert Bang diem chi tiet
                List <KHOAHOC_MONHOC> _khmh = KhoaHocMonHocLogic.SelectTheoKhoaHoc(_bangdiem.KhoaHocId);
                foreach (var item in _khmh)
                {
                    BANGDIEMCHITIET _chitiet = new BANGDIEMCHITIET();
                    _chitiet.BangDiemId = _id;
                    _chitiet.MonHocId   = item.MonHocId ?? 0;
                    _chitiet.TenMonHoc  = item.TenMonHoc;
                    _chitiet.IsRemove   = 0;
                    //_chitiet.CreatedDate = DateTime.Now;
                    //_chitiet.CreatedBy = GlobalSettings.UserCode;
                    //_chitiet.CreatedLog = GlobalSettings.SessionMyIP;
                    Database.BANGDIEMCHITIETs.InsertOnSubmit(_chitiet);
                    Database.SubmitChanges();
                }
            }
            catch (Exception ex)
            {
                O2S_Common.Logging.LogSystem.Error(ex);
            }
        }
        public static void Update(BANGDIEMCHITIET kh)
        {
            try
            {
                var khoaHocCu = Select(kh.BangDiemChiTietId);

                khoaHocCu.Diem = kh.Diem;
                Database.SubmitChanges();
            }
            catch (System.Exception ex)
            {
                O2S_Common.Logging.LogSystem.Error(ex);
            }
        }
        public static bool UpdateFull(BangDiemFullDTO _bdct)
        {
            bool result = false;

            try
            {
                using (TransactionScope ts = new TransactionScope())
                {
                    decimal _tongdiem = 0;
                    foreach (var item in _bdct.BangDiemChiTiets)
                    {
                        BANGDIEMCHITIET _chitiet = new BANGDIEMCHITIET();
                        _chitiet.BangDiemChiTietId = (int)item.BangDiemChiTietId;
                        _chitiet.BangDiemId        = (int)item.BangDiemId;
                        _chitiet.MonHocId          = item.MonHocId;
                        _chitiet.TenMonHoc         = item.TenMonHoc;
                        _chitiet.Diem = item.Diem;
                        BangDiemChiTietLogic.Update(_chitiet);

                        _tongdiem += item.Diem ?? 0;
                    }
                    //Cap nhat BANGDIEM + diem trung binh
                    var _bangdiemtmp = Select(_bdct.HocVienId ?? 0, _bdct.LopHocId ?? 0);
                    _bangdiemtmp.DiemTrungBinh = Math.Round(_tongdiem / _bdct.BangDiemChiTiets.Count, 2);
                    _bangdiemtmp.TrangThai     = 3;
                    Database.SubmitChanges();
                    ts.Complete();
                    return(true);
                }
            }
            catch (Exception ex)
            {
                return(result);

                O2S_Common.Logging.LogSystem.Error(ex);
            }
            return(result);
        }
        public static bool InsertPGDFull_XepLop(PHIEUGHIDANH _phieughidanh, PHIEUTHU _phieuthu, List <HOCPHIHOCVIEN> _lsthphv, BANGDIEM _bangdiem, ref int _PhieuGhiDanhId, ref int _PhieuThuId)
        {
            try
            {
                //   O2S_Common.Logging.LogSystem.Error("Luu log InsertPGDFull");
                using (TransactionScope ts = new TransactionScope())
                {
                    //Phieu ghi danh
                    _phieughidanh.CoSoId      = GlobalSettings.CoSoId;
                    _phieughidanh.CreatedDate = DateTime.Now;
                    _phieughidanh.CreatedBy   = GlobalSettings.UserCode;
                    _phieughidanh.CreatedLog  = GlobalSettings.SessionMyIP;
                    _phieughidanh.IsRemove    = 0;
                    Database.PHIEUGHIDANHs.InsertOnSubmit(_phieughidanh);
                    Database.SubmitChanges();
                    _PhieuGhiDanhId = _phieughidanh.PhieuGhiDanhId;
                    _phieughidanh.MaPhieuGhiDanh = string.Format("{0}{1:D7}", "PGD", _PhieuGhiDanhId);
                    Database.SubmitChanges();

                    //insert bang PHIEUTHU
                    if (_phieuthu != null && _phieuthu.HocVienId > 0)
                    {
                        _phieuthu.PhieuGhiDanhId = _PhieuGhiDanhId;
                        _phieuthu.CreatedDate    = DateTime.Now;
                        _phieuthu.CreatedBy      = GlobalSettings.UserCode;
                        _phieuthu.CreatedLog     = GlobalSettings.SessionMyIP;
                        _phieuthu.IsRemove       = 0;
                        Database.PHIEUTHUs.InsertOnSubmit(_phieuthu);
                        Database.SubmitChanges();
                        _PhieuThuId          = _phieuthu.PhieuThuId;
                        _phieuthu.MaPhieuThu = string.Format("{0}{1:D7}", "PT", _phieuthu.PhieuThuId);
                        Database.SubmitChanges();
                    }
                    //Hocphihocvien
                    if (_lsthphv != null && _lsthphv.Count > 0)
                    {
                        foreach (var item in _lsthphv)
                        {
                            item.PhieuGhiDanhId = _PhieuGhiDanhId;
                            item.PhieuThuId     = _phieuthu.PhieuThuId;
                            item.CreatedDate    = DateTime.Now;
                            item.CreatedBy      = GlobalSettings.UserCode;
                            item.CreatedLog     = GlobalSettings.SessionMyIP;
                            item.IsRemove       = 0;
                            Database.HOCPHIHOCVIENs.InsertOnSubmit(item);
                            Database.SubmitChanges();
                        }
                    }
                    //insert BANGDIEM
                    if (_bangdiem.LopHocId != 0)
                    {
                        _bangdiem.PhieuGhiDanhId = _PhieuGhiDanhId;
                        _bangdiem.CreatedDate    = DateTime.Now;
                        _bangdiem.CreatedBy      = GlobalSettings.UserCode;
                        _bangdiem.CreatedLog     = GlobalSettings.SessionMyIP;
                        _bangdiem.IsRemove       = 0;
                        Database.BANGDIEMs.InsertOnSubmit(_bangdiem);
                        Database.SubmitChanges();
                        int _id = _bangdiem.BangDiemId;

                        //Insert Bang diem chi tiet
                        List <KHOAHOC_MONHOC> _khmh = KhoaHocMonHocLogic.SelectTheoKhoaHoc(_bangdiem.KhoaHocId);
                        foreach (var item in _khmh)
                        {
                            BANGDIEMCHITIET _chitiet = new BANGDIEMCHITIET();
                            _chitiet.BangDiemId = _id;
                            _chitiet.MonHocId   = item.MonHocId ?? 0;
                            _chitiet.TenMonHoc  = item.TenMonHoc;
                            _chitiet.IsRemove   = 0;
                            //_chitiet.CreatedDate = DateTime.Now;
                            //_chitiet.CreatedBy = GlobalSettings.UserCode;
                            //_chitiet.CreatedLog = GlobalSettings.SessionMyIP;
                            Database.BANGDIEMCHITIETs.InsertOnSubmit(_chitiet);
                            Database.SubmitChanges();
                        }

                        //Update  SiSo cua LOPHOC
                        LOPHOC _lophoc = LopHocLogic.SelectSingle(_bangdiem.LopHocId);
                        LopHocLogic.Update(new LOPHOC()
                        {
                            //LopHocId = _lophoc.LopHocId,
                            //TenLopHoc = _lophoc.TenLopHoc,
                            //NgayBatDau = _lophoc.NgayBatDau,
                            //NgayKetThuc = _lophoc.NgayKetThuc,
                            //SiSoToiDa = _lophoc.SiSoToiDa,
                            SiSo = _lophoc.SiSo + 1,
                            //KhoaHocId = _lophoc.KhoaHocId,
                            //IsLock = _lophoc.IsLock
                        });
                    }

                    //Update HOCVIEN = Hoc vien chinh thuc
                    HOCVIEN _hocvien = HocVienLogic.SelectSingle(_phieughidanh.HocVienId ?? 0);
                    _hocvien.LOAIHOCVIEN = LoaiHocVienLogic.Select(KeySetting.LOAIHOCVIEN_CHINHTHUC);
                    //Database.SubmitChanges();
                    //Update TAIKHOAN = được sử dụng
                    TAIKHOAN _taikhoan = TaiKhoanLogic.SelectTheoTenDangNhap(_hocvien.MaHocVien);
                    _taikhoan.IsRemove = 0;
                    Database.SubmitChanges();
                    ts.Complete();
                    return(true);
                }
            }
            catch (Exception ex)
            {
                O2S_Common.Logging.LogSystem.Error(ex);
                return(false);
            }
        }
 public static void Insert(BANGDIEMCHITIET bd)
 {
     bd.IsRemove = 0;
     Database.BANGDIEMCHITIETs.InsertOnSubmit(bd);
     Database.SubmitChanges();
 }