Exemplo n.º 1
0
        public static bool HuyPhieuThuTien(PHIEUTHU _phieuthu)
        {
            try
            {
                using (TransactionScope ts = new TransactionScope())
                {
                    var phieuthuCu = SelectSingle(_phieuthu.PhieuThuId);
                    phieuthuCu.IsRemove     = _phieuthu.IsRemove;
                    phieuthuCu.LyDoHuy      = _phieuthu.LyDoHuy;
                    phieuthuCu.NguoiHuy     = _phieuthu.NguoiHuy;
                    phieuthuCu.ThoiGianHuy  = _phieuthu.ThoiGianHuy;
                    phieuthuCu.ModifiedDate = DateTime.Now;
                    phieuthuCu.ModifiedBy   = GlobalSettings.UserCode;
                    phieuthuCu.ModifiedLog  = GlobalSettings.SessionMyIP;
                    Database.SubmitChanges();
                    //update PHIEUGHIDANH
                    PHIEUGHIDANH _pgdanh = PhieuGhiDanhLogic.SelectSingle(_phieuthu.PhieuGhiDanhId ?? 0);
                    _pgdanh.DaDong       = _pgdanh.DaDong - _phieuthu.SoTien;
                    _pgdanh.ConNo        = _pgdanh.ConNo + _phieuthu.SoTien;
                    _pgdanh.ModifiedDate = DateTime.Now;
                    _pgdanh.ModifiedBy   = GlobalSettings.UserCode;
                    _pgdanh.ModifiedLog  = GlobalSettings.SessionMyIP;
                    ts.Complete();
                    return(true);
                }
            }
            catch (System.Exception ex)
            {
                return(false);

                O2S_Common.Logging.LogSystem.Error(ex);
            }
        }
        public static bool InsertQLHocPhi_Option1(PHIEUGHIDANH _phieughidanh, PHIEUTHU _phieuthu, HOCPHIHOCVIEN _hocphiHV, ref int _PhieuThuId)
        {
            try
            {
                using (TransactionScope ts = new TransactionScope())
                {
                    //update Phieu ghi danh
                    PHIEUGHIDANH _PGD_select = PhieuGhiDanhLogic.SelectSingle(_phieughidanh.PhieuGhiDanhId);
                    _PGD_select.DaDong       = _phieughidanh.DaDong;
                    _PGD_select.ConNo        = _phieughidanh.ConNo;
                    _PGD_select.ModifiedDate = DateTime.Now;
                    _PGD_select.ModifiedBy   = GlobalSettings.UserCode;
                    _PGD_select.ModifiedLog  = GlobalSettings.SessionMyIP;
                    Database.SubmitChanges();

                    //insert bang PHIEUTHU
                    if (_phieuthu != null && _phieuthu.HocVienId > 0)
                    {
                        _phieuthu.PhieuGhiDanhId = _phieughidanh.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();
                    }
                    //Insert HocPhiHocVien
                    if (_phieuthu.PhieuThuId != 0)
                    {
                        _hocphiHV.PhieuThuId  = _phieuthu.PhieuThuId;
                        _hocphiHV.CreatedDate = DateTime.Now;
                        _hocphiHV.CreatedBy   = GlobalSettings.UserCode;
                        _hocphiHV.CreatedLog  = GlobalSettings.SessionMyIP;
                        _hocphiHV.IsRemove    = 0;
                        Database.HOCPHIHOCVIENs.InsertOnSubmit(_hocphiHV);
                        Database.SubmitChanges();
                    }
                    ts.Complete();
                    return(true);
                }
            }
            catch (System.Exception ex)
            {
                return(false);

                O2S_Common.Logging.LogSystem.Error(ex);
            }
        }
        public static bool Delete(int _hocvienId) //xoa hoc vien
        {
            try
            {
                using (TransactionScope ts = new TransactionScope())
                {
                    //Xoa LICHSUTUVAN
                    List <LICHSUTUVAN> _lstTuVan = LichSuTuVanLogic.SelectTheoHocVien(_hocvienId);
                    if (_lstTuVan != null && _lstTuVan.Count > 0)
                    {
                        Database.LICHSUTUVANs.DeleteAllOnSubmit(_lstTuVan);
                    }
                    //Xoa PHIEUGHIDANH
                    List <PHIEUGHIDANH> _lstPhieuGD = PhieuGhiDanhLogic.SelectTheoHocVien(_hocvienId);
                    if (_lstPhieuGD != null && _lstPhieuGD.Count > 0)
                    {
                        Database.PHIEUGHIDANHs.DeleteAllOnSubmit(_lstPhieuGD);
                    }
                    //XOA HOCVIENs
                    var temp = SelectSingle(_hocvienId);
                    //int _loaihocvien = temp.LoaiHocVienId ?? 0;
                    int _TaiKhoanId = temp.TaiKhoanId ?? 0;

                    Database.HOCVIENs.DeleteOnSubmit(temp);

                    //Xoa tai khoan
                    //Xoa phan quyen tai khoan
                    List <PHANQUYENTAIKHOAN> _lstPhanQuyen = PhanQuyenTaiKhoanLogic.SelectTheoTaiKhoan(_TaiKhoanId);
                    Database.PHANQUYENTAIKHOANs.DeleteAllOnSubmit(_lstPhanQuyen);
                    var temp_TK = (from p in Database.TAIKHOANs
                                   where p.TaiKhoanId == _TaiKhoanId
                                   select p).Single();

                    Database.TAIKHOANs.DeleteOnSubmit(temp_TK);

                    Database.SubmitChanges();
                    ts.Complete();
                    return(true);
                }
            }
            catch (System.Exception ex)
            {
                return(false);

                O2S_Common.Logging.LogSystem.Error(ex);
            }
        }
        public static bool XoaPhieuGhiDanh(PHIEUGHIDANH _phieuGD)
        {
            try
            {
                using (TransactionScope ts = new TransactionScope())
                {
                    //xoa HOCPHIHOCVIEN
                    List <HOCPHIHOCVIEN> _lstHPHV = HocPhiHocVienLogic.SelectTheoPhieuGhiDanh(_phieuGD.PhieuGhiDanhId);
                    if (_lstHPHV != null && _lstHPHV.Count > 0)
                    {
                        Database.HOCPHIHOCVIENs.DeleteAllOnSubmit(_lstHPHV);
                        //Database.SubmitChanges();
                    }
                    //Xoa bang PHIEUTHU;
                    List <PHIEUTHU> _lstPhieuThu = PhieuThuLogic.SelectTheoPhieuGhiDanh(_phieuGD.PhieuGhiDanhId);
                    if (_lstPhieuThu != null && _lstPhieuThu.Count > 0)
                    {
                        Database.PHIEUTHUs.DeleteAllOnSubmit(_lstPhieuThu);
                        // Database.SubmitChanges();
                    }
                    //update=Xoa bang PHIEUGHIDANH
                    //PHIEUGHIDANH _phieuGDUpdate = SelectSingle(_phieuGD.PhieuGhiDanhId);
                    _phieuGD.IsRemove     = _phieuGD.IsRemove;
                    _phieuGD.LyDoXoa      = _phieuGD.LyDoXoa;
                    _phieuGD.NguoiXoa     = _phieuGD.NguoiXoa;
                    _phieuGD.ModifiedDate = DateTime.Now;
                    _phieuGD.ModifiedBy   = GlobalSettings.UserCode;
                    _phieuGD.ModifiedLog  = GlobalSettings.SessionMyIP;
                    //Database.SubmitChanges();
                    //cap nhat bang HOCVIEN va bang tai khoan: kiem tra HV hoc khoa nao ko? neu=1 thi update
                    PhieuGhiDanhFilter _filter = new PhieuGhiDanhFilter();
                    _filter.HocVienId = _phieuGD.HocVienId;
                    List <PhieuGhiDanh_PlusDTO> _PGD_Kiemtra = PhieuGhiDanhLogic.Select(_filter);
                    if (_PGD_Kiemtra == null || _PGD_Kiemtra.Count <= 1)
                    {
                        HOCVIEN _hocvien = HocVienLogic.SelectSingle(_phieuGD.HocVienId ?? 0);
                        _hocvien.LOAIHOCVIEN = LoaiHocVienLogic.Select(KeySetting.LOAIHOCVIEN_TIEMNANG);
                        Database.SubmitChanges();

                        TAIKHOAN _taikhoan = TaiKhoanLogic.SelectTheoTenDangNhap(_hocvien.TAIKHOAN.TenDangNhap);
                        _taikhoan.IsRemove = 1;
                        //Database.SubmitChanges();
                    }
                    //Kiem tra lop hoc va xoa bang diem
                    List <BANGDIEM> _bangdiem = BangDiemLogic.SelectTheoPhieuGhiDanh(_phieuGD.PhieuGhiDanhId);
                    if (_bangdiem != null && _bangdiem.Count > 0)
                    {
                        Database.BANGDIEMs.DeleteAllOnSubmit(_bangdiem);
                        //Update So luong hoc vien trong lop hoc...
                        LOPHOC _lopHoc = LopHocLogic.SelectSingle(_phieuGD.LopHocId ?? 0);
                        if (_lopHoc != null)
                        {
                            _lopHoc.SiSo = (from p in Database.BANGDIEMs
                                            where p.LopHocId == (_phieuGD.LopHocId ?? 0) && p.IsRemove != 1
                                            select p).Count();
                            _lopHoc.ModifiedDate = DateTime.Now;
                            _lopHoc.ModifiedBy   = GlobalSettings.UserCode;
                            _lopHoc.ModifiedLog  = GlobalSettings.SessionMyIP;
                            Database.SubmitChanges();
                        }
                    }

                    Database.SubmitChanges();
                    ts.Complete();
                    return(true);
                }
            }
            catch (System.Exception ex)
            {
                return(false);

                O2S_Common.Logging.LogSystem.Error(ex);
            }
        }