Example #1
0
 // Thêm phiếu trả
 public bool Add(PhieuTra value)
 {
     try
     {
         _db.PhieuTra.Add(value);
         _db.SaveChanges();
         return true;
     }
     catch (Exception e)
     {
         Console.WriteLine(e.Message);
         return false;
     }
 }
Example #2
0
 // Cập nhật phiếu trả
 public bool Update(PhieuTra value)
 {
     try
     {
         PhieuTra record = _db.PhieuTra.SingleOrDefault(v => v.MaPhieuTra == value.MaPhieuTra);
         record.MaPhieuMuon = value.MaPhieuMuon;
         record.NgayTra = value.NgayTra;
         _db.SaveChanges();
         return true;
     }
     catch (Exception e)
     {
         Console.WriteLine(e.Message);
         return false;
     }
 }
Example #3
0
        //
        public PhieuTra _Search(int? phieumuon, DateTime? ngaytra)
        {
            try
            {
                var query = from c in _db.PhieuTra
                            where c.MaPhieuMuon.Equals(phieumuon)
                            select c;
                var temp = query.Where(v => v.NgayTra >= ngaytra).ToList();
                PhieuTra pt = new PhieuTra();
                foreach(var item in temp)
                {
                    pt.MaPhieuTra = item.MaPhieuTra;
                    pt.MaPhieuMuon = item.MaPhieuMuon;
                    pt.NgayTra = item.NgayTra;

                }
                return pt;
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
                return null;
            }
        }
        public ActionResult xulytrasach(FormCollection fc,String mapm)
        {
            int maphieumuon=int.Parse(mapm);

            PhieuTra phieutra = new PhieuTra();
            phieutra.MaPhieuMuon = maphieumuon;
            phieutra.NgayTra = DateTime.Parse(fc["ngay"]);
               pt.Add(phieutra);
            DateTime ngaytra = DateTime.Parse(fc["ngay"]);
            var list_ = pt.Search(maphieumuon, ngaytra).ToList();
            foreach(var item in list_)
            {
                maphieutra = item.MaPhieuTra;
            }
            int _id = int.Parse(mapm);
            var temp = ctpm.Search_id(_id).ToList();
            List<DataRow
             > list = new List<DataRow
             >();
            foreach (var item in temp)
            {

                System.Data.DataTable dt = dbsach.searchbyid(item.MaCuonSach);
                foreach (DataRow dr in dt.Rows)
                {
                    list.Add(dr);
                }
            }
            foreach(var item in list)
            {
                if (fc[item["MaCuonSach"].ToString()] == "check")
                {
                    int ma=int.Parse(item["MaCuonSach"].ToString());
                    CTPhieuTra ct = new CTPhieuTra();
                    ct.MaCuonSach=int.Parse(item["MaCuonSach"].ToString());
                    ct.MaPhieuTra = maphieutra;
                    ctpt.Add(ct);
                    var query=from c in _db.CTPhieuMuon
                              where c.MaCuonSach.Equals(ma)&&c.DaTra==false
                              select c;
                    foreach(CTPhieuMuon _ct in query)
                    {
                        _ct.DaTra = true;
                    }
                    _db.SaveChanges();
                    CuonSach cs = new CuonSach();
                    cs = dbsach.GetByID(int.Parse(item["MaCuonSach"].ToString()));
                    cs.MaTinhTrang = 1;
                    dbsach.Update(cs);
                }
            }
            int soluongsach = dbpm.soluongsachmuon(maphieumuon);
            if(!(soluongsach>0))
            {
                PhieuMuon pm = new PhieuMuon();
                pm = dbpm.GetByID(maphieumuon);
                pm.tinhtrang = true;
                dbpm.Update(pm);
            }

            return RedirectToAction("Index");
        }