Example #1
0
 // Thêm chi tiết phiếu trả
 public bool Add(CTPhieuTra value)
 {
     try
     {
         _db.CTPhieuTra.Add(value);
         _db.SaveChanges();
         return true;
     }
     catch (Exception e)
     {
         Console.WriteLine(e.Message);
         return false;
     }
 }
Example #2
0
 // Cập nhật chi tiết phiếu trả
 public bool Update(CTPhieuTra value)
 {
     try
     {
         CTPhieuTra record = _db.CTPhieuTra.SingleOrDefault(v => v.ID == value.ID);
         record.MaCuonSach = value.MaCuonSach;
         _db.SaveChanges();
         return true;
     }
     catch (Exception e)
     {
         Console.WriteLine(e.Message);
         return false;
     }
 }
        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");
        }