Example #1
0
 public bool UpdateSL(List <DanhSachMuon_DTO> sachMuon)
 {
     foreach (DanhSachMuon_DTO sachMuon_DTO in sachMuon)
     {
         Sach s = data.Saches.SingleOrDefault(u => u.MaSach == sachMuon_DTO.MaSach && u.TrangThai.Value == true);
         s.SoLuong -= sachMuon_DTO.SoLuong;
     }
     data.SaveChanges();
     return(true);
 }
Example #2
0
 public bool AddTheDocGiaAndUser(TheDocGiaDtos DocGia, UserDtos user)
 {
     try
     {
         using (var db = new QuanLyThuVienEntities())
         {
             int ID = TheDocGiaDAO.Instance.IDPlus();
             db.THEDOCGIAs.Add(new THEDOCGIA()
             {
                 IDDocGia   = ID,
                 HoTenDG    = DocGia.HoTenDG,
                 DiaChiDG   = DocGia.DiaChiDG,
                 EmailDG    = DocGia.EmailDG,
                 NgaySinhDG = DocGia.NgaySinhDG,
                 NgayLapThe = DocGia.NgayLapThe,
                 IDLoaiDG   = DocGia.IDLoaiDocGia,
                 TongNo     = 0,
                 NgayHetHan = TheDocGiaDAO.Instance.countHanThe(DocGia.NgayLapThe),
             });
             db.USERS.Add(new USER()
             {
                 IDDocGia = ID,
                 UserName = user.UserName,
                 Pwd      = user.Password,
             });
             db.SaveChanges();
             return(true);
         }
     }
     catch (Exception)
     {
         return(false);
     }
 }
Example #3
0
 private void btnXoa_Click(object sender, EventArgs e)
 {
     if (dataGridView1.SelectedRows.Count == 1)
     {
         int id     = (int)dataGridView1.SelectedRows[0].Cells[0].Value;
         var result = db.SinhViens.Find(id);
         db.SinhViens.Remove(result);
         db.SaveChanges();
         load();
     }
 }
        public bool ThemCTNhapSach(CTNhapSach_DTO CTNhapSach_DTO)
        {
            try
            {
                CTNhapSach cTNhapSach = new CTNhapSach();
                cTNhapSach.MaNhap    = CTNhapSach_DTO.MaNhap;
                cTNhapSach.MaSach    = CTNhapSach_DTO.MaSach;
                cTNhapSach.SoLuong   = CTNhapSach_DTO.SoLuong;
                cTNhapSach.DonGia    = (int)CTNhapSach_DTO.DonGia;
                cTNhapSach.TrangThai = true;

                data.CTNhapSaches.Add(cTNhapSach);
                data.SaveChanges();
                return(true);
            }
            catch (Exception)
            {
                return(false);
            }
        }
Example #5
0
 private void button2_Click(object sender, EventArgs e)
 {
     if (dataGridView1.SelectedRows.Count == 1)
     {
         string id = dataGridView1.SelectedRows[0].Cells[0].Value.ToString();
         var    rs = db.Thongtinsachs.Find(id);
         db.Thongtinsachs.Remove(rs);
         db.SaveChanges();
         loadsach();
     }
 }
Example #6
0
        //Xu ly xoa doc gia
        public ActionResult xoaDGia(int id)
        {
            QuanLyThuVienEntities data = new QuanLyThuVienEntities();
            NguoiDung             ngd  = (from ngds in data.NguoiDungs
                                          where ngds.MaNguoiDung == id
                                          select ngds).First();

            ngd.DeleteFlag = 1;
            data.SaveChanges();
            return(RedirectToAction("QLDGia"));
        }
Example #7
0
        public bool ThemDauSach(DauSach_DTO dauSach_DTO)
        {
            try
            {
                DauSach dauSach = new DauSach();
                dauSach.MaDauSach  = dauSach_DTO.MaDauSach;
                dauSach.TenDauSach = dauSach_DTO.TenDauSach;
                dauSach.MaTheLoai  = dauSach_DTO.MaTheLoai;
                dauSach.TrangThai  = true;


                data.DauSaches.Add(dauSach);
                data.SaveChanges();
                return(true);
            }
            catch (Exception)
            {
                return(false);
            }
        }
        public bool ThemNhapSach(NhapSach_DTO nhapSach_DTO)
        {
            try
            {
                NhapSach nhapSach = new NhapSach();
                nhapSach.MaNhap    = nhapSach_DTO.MaNhap;
                nhapSach.MaNV      = nhapSach_DTO.MaNV;
                nhapSach.NgayNhap  = nhapSach_DTO.NgayNhap;
                nhapSach.ThanhTien = (decimal)nhapSach_DTO.ThanhTien;
                nhapSach.TrangThai = true;

                data.NhapSaches.Add(nhapSach);
                data.SaveChanges();
                return(true);
            }
            catch (Exception)
            {
                return(false);
            }
        }
Example #9
0
        private void btnSave_Click(object sender, EventArgs e)
        {
            var result = db.SinhViens.Find(ID);

            result.Hoten           = txtName.Text;
            result.MSSV            = txtMSSV.Text;
            result.Khoa            = cbbKhoa.Text;
            db.Entry(result).State = EntityState.Modified;
            db.SaveChanges();
            this.Close();
        }
Example #10
0
        public bool SuaNhanVien(NhanVien_DTO nv_DTO)
        {
            try
            {
                NhanVien nv = data.NhanViens.SingleOrDefault(u => u.MaNV == nv_DTO.MaNV);

                nv.MaNV     = nv_DTO.MaNV;
                nv.HoTenNV  = nv_DTO.HoTenNV;
                nv.NgSinh   = nv_DTO.NgSinh;
                nv.SDT      = nv_DTO.SDT;
                nv.TaiKhoan = nv_DTO.TaiKhoan;
                nv.Quyen    = nv_DTO.Quyen;

                data.SaveChanges();
                return(true);
            }
            catch (Exception ex)
            {
                return(false);
            }
        }
Example #11
0
        private void btnSave_Click(object sender, EventArgs e)
        {
            var result = db.Thongtinsachs.Find(ID);

            result.TenSach         = txtTen.Text;
            result.SoLuong         = int.Parse(txtSL.Text);
            result.LoaiSach        = cbbLoai.Text;
            result.TacGia          = txtTG.Text;
            db.Entry(result).State = EntityState.Modified;
            db.SaveChanges();
            this.Close();
        }
Example #12
0
 public bool editFormDocGiaAndUser(TheDocGiaDTO thedocgia)
 {
     try
     {
         using (var db = new QuanLyThuVienEntities())
         {
             var Edit = (from a in db.THEDOCGIAs
                         where a.IDDocGia.Equals(thedocgia.IDDocGia)
                         select a).FirstOrDefault();
             if (Edit == null)
             {
                 return(false);
             }
             Edit.HoTenDG    = thedocgia.HoTenDG;
             Edit.DiaChiDG   = thedocgia.DiaChiDG;
             Edit.EmailDG    = thedocgia.EmailDG;
             Edit.NgaySinhDG = thedocgia.NgaySinhDG;
             Edit.NgayLapThe = thedocgia.NgayLapThe;
             Edit.IDLoaiDG   = thedocgia.IDLoaiDocGia;
             Edit.NgayHetHan = thedocgia.NgayHetHan;
             Edit.TongNo     = thedocgia.TongNo;
             db.SaveChanges();
             var EditUser = (from a in db.USERS
                             where a.IDDocGia.Equals(thedocgia.IDDocGia)
                             select a).FirstOrDefault();
             if (EditUser == null)
             {
                 return(false);
             }
             EditUser.Pwd      = thedocgia.Password;
             EditUser.UserName = thedocgia.UserName;
             db.SaveChanges();
             return(true);
         }
     }
     catch (Exception)
     {
         return(false);
     }
 }
Example #13
0
        private void btnSave_Click(object sender, EventArgs e)
        {
            var rs = new SinhVien
            {
                Hoten = txtName.Text,
                MSSV  = txtMSSV.Text,
                Khoa  = cbbKhoa.Text,
            };

            db.SinhViens.Add(rs);
            db.SaveChanges();
            this.Close();
        }
Example #14
0
        public bool ThemDocGia(DocGia_DTO dg_DTO)
        {
            try
            {
                DocGia dg = new DocGia();
                dg.MaDocGia  = dg_DTO.MaDocGia;
                dg.TenDocGia = dg_DTO.TenDocGia;
                dg.CMND      = dg_DTO.CMND;
                dg.DiaChi    = dg_DTO.DiaChi;
                dg.SoThe     = dg_DTO.SoThe;
                dg.TrangThai = true;

                data.DocGias.Add(dg);

                data.SaveChanges();
                return(true);
            }
            catch (Exception)
            {
                return(false);
            }
        }
Example #15
0
        private void btnSave_Click(object sender, EventArgs e)
        {
            var rs = new MuonSach
            {
                MaSach   = txtMa.Text,
                TenSach  = txtTen.Text,
                SoLuong  = int.Parse(txtSL.Text),
                LoaiSach = cbbLoai.Text,
                TacGia   = txtTG.Text
            };

            db.Thongtinsachs.Add(rs);
            db.SaveChanges();
            this.Close();
        }
Example #16
0
 public bool editFormDauSachAndSachAndCTPhieuNhap(SachDTO sach)
 {
     try
     {
         using (var db = new QuanLyThuVienEntities())
         {
             var EditDAUSACH = (from a in db.DAUSACHes
                                where a.IDDauSach.Equals(sach.IDDauSach)
                                select a).FirstOrDefault();
             if (EditDAUSACH == null)
             {
                 return(false);
             }
             EditDAUSACH.IDLoaiSach = GetDataDAO.Instance.getIDLoaiSachToTenLoaiSach(sach.TenLoaiSach);
             EditDAUSACH.TenDauSach = sach.TenDauSach;
             var EditSach = (from a in db.SACHes
                             where a.IDSach.Equals(sach.IDSach)
                             select a).FirstOrDefault();
             if (EditSach == null)
             {
                 return(false);
             }
             EditSach.IDDauSach  = sach.IDDauSach;
             EditSach.IDTacGia   = GetDataDAO.Instance.getIDTacGiaToTenTacGia(sach.TenTG);
             EditSach.NamXB      = sach.NamXB;
             EditSach.NhaXB      = sach.NhaXB;
             EditSach.SoLuongTon = sach.SoLuongTon + sach.SoLuong;
             EditSach.GiaTien    = sach.GiaTien;
             var EditCTPhieuNhap = (from a in db.CT_PHIEUNHAPSACH
                                    where a.IDCTPhieuNhap.Equals(sach.IDCTPhieuNhap)
                                    select a).FirstOrDefault();
             EditCTPhieuNhap.IDPhieuNhap = GetDataDAO.Instance.getIDPhieuNhapToNgayNhapSach(sach.NgayNhap);
             EditCTPhieuNhap.IDSach      = sach.IDSach;
             EditCTPhieuNhap.SoLuong     = sach.SoLuong;
             EditCTPhieuNhap.DonGia      = sach.DonGia;
             EditCTPhieuNhap.ThanhTien   = sach.SoLuong * sach.DonGia;
             db.SaveChanges();
             return(true);
         }
     }
     catch (Exception)
     {
         return(false);
     }
 }
Example #17
0
 public bool addFormCuonSach(int tb_SoLuongNhap, int IDsach)
 {
     using (var db = new QuanLyThuVienEntities())
     {
         for (int i = 0; i < tb_SoLuongNhap; i++)
         {
             int IDCuonSach = CuonSachDAO.Instance.IDPlus();
             db.CUONSACHes.Add(new CUONSACH()
             {
                 IDCuonSach = IDCuonSach,
                 IDSach     = IDsach,
                 TinhTrang  = "Chưa cho mượn",
             });
         }
         db.SaveChanges();
         return(true);
     }
 }
Example #18
0
        public bool ThemTheLoai(TheLoai_DTO theLoai_DTO)
        {
            try
            {
                TheLoai theLoai = new TheLoai();

                theLoai.MaTheLoai  = theLoai_DTO.MaTheLoai;
                theLoai.TenTheLoai = theLoai_DTO.TenTheLoai;
                theLoai.TrangThai  = true;

                data.TheLoais.Add(theLoai);
                data.SaveChanges();
                return(true);
            }
            catch (Exception)
            {
                return(false);
            }
        }
Example #19
0
        //Xu ly cap nhat doc gia
        public ActionResult suaDGia(FormCollection f)
        {
            int id = int.Parse(f["MaNguoiDung"]);
            QuanLyThuVienEntities data = new QuanLyThuVienEntities();
            NguoiDung             ngd  = (from ngds in data.NguoiDungs
                                          where ngds.MaNguoiDung == id
                                          select ngds).First();

            ngd.HoTen       = f["HoTen"];
            ngd.SoCMND      = f["SoCMND"];
            ngd.NgaySinh    = DateTime.Parse(f["NgaySinh"]);
            ngd.MSSV        = f["MSSV"];
            ngd.Email       = f["Email"];
            ngd.NgayHetHan  = DateTime.Parse(f["NgayHetHan"]);
            ngd.LoaiND      = f["LoaiND"];
            ngd.TenDangNhap = f["TenDangNhap"];
            //ngd.MatKhau = f["MatKhau"];
            data.SaveChanges();
            return(RedirectToAction("chitietDGia/" + ngd.MaNguoiDung));
        }
        // Gia hạn sách
        public ActionResult GiaHanSach(int id)
        {
            int SoLanGiaHan = (int)(from ct in data.ChiTietPhieuMuons where ct.MaChiTietPhieuMuon == id select ct.LanMuon).First();

            if (SoLanGiaHan >= SOLANGIAHAN)
            {
                @ViewBag.Message = "Bạn không thể tiếp tục gia hạn cho quyển sách này!";
                return(View("KqGiaHanSach"));
            }
            ChiTietPhieuMuon chitiet = data.ChiTietPhieuMuons.Find(id);

            chitiet.LanMuon++;
            if (ModelState.IsValid)
            {
                data.Entry(chitiet).State = EntityState.Modified;
                data.SaveChanges();
            }
            @ViewBag.Message = "Sách được gia hạn thành công! Lần gia hạn thứ " + chitiet.LanMuon.ToString();
            return(View("KqGiaHanSach"));
        }
Example #21
0
        public bool ThemTheThuVien(TheThuVien_DTO ttv_DTO)
        {
            try
            {
                TheThuVien ttv = new TheThuVien
                {
                    SoThe      = ttv_DTO.SoThe,
                    NgayBatDau = ttv_DTO.NgayBatDau,
                    TrangThai  = true
                };

                data.TheThuViens.Add(ttv);
                data.SaveChanges();
                return(true);
            }
            catch (Exception)
            {
                return(false);
            }
        }
        //Cập nhật thông tin nhân viên (Từ)
        public ActionResult SuaNhanVien(FormCollection f)
        {
            int      MaNguoiDung = int.Parse(f["MaNhanVien"]);
            DateTime NgaySinh;
            QuanLyThuVienEntities data = new QuanLyThuVienEntities();
            NhanVien ngd = (from ngds in data.NhanViens
                            where ngds.MaNhanVien == MaNguoiDung
                            select ngds).First();

            ngd.HoTen       = f["HoTen"];
            ngd.CMND        = f["CMND"];
            ngd.TenDangNhap = f["TenDangNhap"];
            if (DateTime.TryParse(f["NgaySinh"], out NgaySinh))
            {
                ngd.NgaySinh = DateTime.Parse(f["NgaySinh"]);
            }
            ngd.MatKhau = f["MatKhau"];
            data.SaveChanges();
            return(RedirectToAction("suadg", "Home", new { username = f["TenDangNhap"] }));
        }
        public ActionResult GopY(string tenDocGia, string emailDocGia, string tieude, string noidung)
        {
            QuanLyThuVien_N8.Models.EmailService mailService = new EmailService();
            string smtpUserName = "******";
            string smtpPassword = "******";
            string smtpHost     = "smtp.gmail.com";
            int    smtpPort     = 25;
            string emailTo      = "*****@*****.**";
            string subject      = "Góp ý thư viện KHTN - " + tenDocGia + "-" + tieude;
            string body         = string.Format("Bạn vừa nhận được liên hệ từ đọc giả <b>{0}</b> có email là: <b>{1} <br><br>  Nội dung:</b><br> <br> {2}", tenDocGia, emailDocGia, noidung);
            bool   kq           = mailService.Send(smtpUserName, smtpPassword, smtpHost, smtpPort, emailTo, subject, body);

            if (kq)
            {
                ViewBag.Result = "OK";
            }
            else
            {
                ViewBag.Result = "Fail";
            }
            QuanLyThuVienEntities data = new QuanLyThuVienEntities();
            GopY gy = new GopY();

            gy.NguoiGopY   = tenDocGia;
            gy.NoiDungGopY = noidung;
            gy.TimeGopY    = DateTime.Now;
            gy.Email       = emailDocGia;
            if (Session["user"] != null)
            {
                smtpUserName = Session["user"].ToString();
                NguoiDung user = (from use in data.NguoiDungs
                                  where use.TenDangNhap == smtpUserName
                                  select use).FirstOrDefault();
                gy.NguoiDungGopY = user.MaNguoiDung;
            }
            gy.DaXem      = 0;
            gy.DeleteFlag = 0;
            data.Gopies.Add(gy);
            data.SaveChanges();
            return(View(ViewBag));
        }
Example #24
0
 public bool ADDLoaiDocGia(LoaiDocGiaDtos LoaiDG)
 {
     try
     {
         using (var db = new QuanLyThuVienEntities())
         {
             int ID = LoaiDocGiaDAO.Instance.IDPlus();
             db.LOAIDOCGIAs.Add(new LOAIDOCGIA()
             {
                 IDLoaiDG  = ID,
                 TenLoaiDG = LoaiDG.TenLoaiDG,
             });
             db.SaveChanges();
             return(true);
         }
     }
     catch (Exception)
     {
         return(false);
     }
 }
Example #25
0
 //Add From "LoaiSach"
 public bool AddFromLoaiSach(LoaiSachDtos LS)
 {
     try
     {
         using (var db = new QuanLyThuVienEntities())
         {
             int ID = LoaiSachDAO.Instance.IDPlus();
             db.LOAISACHes.Add(new LOAISACH()
             {
                 IDLoaiSach  = ID,
                 TenLoaiSach = LS.TenLoaiSach,
             });
             db.SaveChanges();
             return(true);
         }
     }
     catch (Exception)
     {
         return(false);
     }
 }
Example #26
0
 public bool addFormPhieuNhapSach(PhieuNhapSachDtos phieuNhap)
 {
     try
     {
         using (var db = new QuanLyThuVienEntities())
         {
             int ID = PhieuNhapSachDAO.Instance.IDPlus();
             db.PHIEUNHAPSACHes.Add(new PHIEUNHAPSACH()
             {
                 IDPhieuNhap = ID,
                 NgayNhap    = phieuNhap.NgayNhap,
                 TongTien    = 0,
             });
             db.SaveChanges();
             return(true);
         }
     }
     catch (Exception)
     {
         return(false);
     }
 }
Example #27
0
        // Xu ly them doc gia roi goi view Quan Ly Doc Gia
        public ActionResult themdg(string hoten, string email, string cmnd, DateTime ngsinh, string mssv, DateTime ngayhh, string loaingdung, string tendn, string mkhau)
        {
            QuanLyThuVienEntities data = new QuanLyThuVienEntities();
            MD5       md5Hash          = MD5.Create();
            string    password         = GetMd5Hash(md5Hash, mkhau);
            NguoiDung dg = new NguoiDung();

            dg.HoTen       = hoten;
            dg.SoCMND      = cmnd;
            dg.NgaySinh    = ngsinh;
            dg.MSSV        = mssv;
            dg.Email       = email;
            dg.NgayHetHan  = ngayhh;
            dg.LoaiND      = loaingdung;
            dg.TenDangNhap = tendn;
            dg.MatKhau     = password;
            dg.NgayDangKy  = DateTime.Today;
            dg.DeleteFlag  = 0;
            data.NguoiDungs.Add(dg);
            data.SaveChanges();
            return(RedirectToAction("QLDGia"));
        }
Example #28
0
 public bool AddFormTacGia(TacGiaDtos tacGia)
 {
     try
     {
         using (var db = new QuanLyThuVienEntities())
         {
             int ID = TacGiaDAO.Instance.IDPlus();
             db.TACGIAs.Add(new TACGIA()
             {
                 IDTacGia  = ID,
                 TenTacGia = tacGia.TenTacGia,
                 NgaySinh  = tacGia.NgaySinh,
             });
             db.SaveChanges();
             return(true);
         }
     }
     catch (Exception)
     {
         return(false);
     }
 }
Example #29
0
 public bool editFormPhieuMuonAndCTPhieuMuon(PhieuMuonDTO phieumuon)
 {
     try
     {
         using (var db = new QuanLyThuVienEntities())
         {
             var Edit = (from a in db.PHIEUMUONs
                         where a.IDPhieuMuon.Equals(phieumuon.IDPhieuMuon)
                         select a).FirstOrDefault();
             if (Edit == null)
             {
                 return(false);
             }
             Edit.NgayMuon = phieumuon.NgayMuon;
             Edit.IDDocGia = phieumuon.IDDocGia;
             Edit.HanTra   = PhieuMuonDAO.Instance.HanMuonSach(phieumuon.NgayMuon);
             var EditCT = (from a in db.CT_PHIEUMUON
                           where a.IDCTPhieuMuon.Equals(phieumuon.IDCTPhieuMuon)
                           select a).FirstOrDefault();
             if (EditCT == null)
             {
                 return(false);
             }
             EditCT.IDCuonSach  = GetDataDAO.Instance.getIDCuonSach(phieumuon.TenDauSach);
             EditCT.IDPhieuMuon = phieumuon.IDPhieuMuon;
             var updateTinhTrang = (from a in db.CUONSACHes
                                    where a.IDCuonSach.Equals(GetDataDAO.Instance.getIDCuonSach(phieumuon.TenDauSach))
                                    select a).FirstOrDefault <CUONSACH>();
             updateTinhTrang.TinhTrang = "Đã cho mượn";
             db.SaveChanges();
             return(true);
         }
     }
     catch (Exception)
     {
         return(false);
     }
 }
Example #30
0
        public bool ThemTraSach(TraSach_DTO ts_DTO)
        {
            try
            {
                TraSach ts = new TraSach
                {
                    MaTra     = ts_DTO.MaTra,
                    NgayLap   = ts_DTO.NgayLap,
                    MaMuon    = ts_DTO.MaMuon,
                    TrangThai = true,
                };
                data.TraSaches.Add(ts);

                data.SaveChanges();


                return(true);
            }
            catch (Exception)
            {
                return(false);
            }
        }