Ejemplo n.º 1
0
        public eChiTietPhieuMuon getChiTietPhieuMuon(int idPhieuMuon, int idDvd)
        {
            data = new DvdRentDbDataContext();
            ChiTietPhieuMuon item = data.ChiTietPhieuMuons.Single(n => n.IdDVD == idDvd && n.IdPhieuMuon == idPhieuMuon);

            return(new eChiTietPhieuMuon(item.IdPhieuMuon, item.IdDVD, item.PhiTre, (DateTime)item.NgayTra, (bool)item.TinhTrang));
        }
Ejemplo n.º 2
0
        //private void SuaPhieuMuon_PropertyChanging(object sender, PropertyChangingEventArgs e)
        //{
        //    ChiTietPhieuMuon ctpm = sender as ChiTietPhieuMuon;
        //    if (e.PropertyName == nameof(ChiTietPhieuMuon.SoLuong))
        //    {
        //        PropertyChangingCancelEventArgs<int> cancelArgs = e as PropertyChangingCancelEventArgs<int>;
        //        int soLuongNhap = cancelArgs.NewValue;
        //        if (soLuongNhap > ctpm.Sach.SoLuongHienCo)
        //        {
        //            datagrid_ChiTietPhieuMuon.CancelEdit();
        //            cancelArgs.Cancel = true;
        //            return;
        //        }
        //    }
        //}

        private void SuaPhieuMuon_PropertyChanged(object sender, PropertyChangedEventArgs e)
        {
            ChiTietPhieuMuon ctpm = sender as ChiTietPhieuMuon;

            ctpm.Sach.PropertyChanged  += Sach_PropertyChanged;
            ctpm.Sach.PropertyChanging += Sach_PropertyChanging;
        }
Ejemplo n.º 3
0
        private void btnluulai_Click_1(object sender, EventArgs e)
        {
            ChiTietPhieuMuon chitiet = new ChiTietPhieuMuon();
            List <Object>    lst     = new List <object>();

            lst = da.Convert(da.Query("select ma from Sach where ten=N'" + cbbmasach.Text + "'"));

            chitiet.sachma = lst[0].ToString();

            lst = da.Convert(da.Query("select ma from TacGia where ten=N'" + cbbtacgia.Text + "'"));
            chitiet.tacgiama = lst[0].ToString();
            List <Object> lst3 = new List <object>();

            lst3 = da.Convert(da.Query("select ma from NhaXuatBan where ten=N'" + cbbnhaxuatban.Text + "'"));
            chitiet.nhaxuatbanma = lst3[0].ToString();
            lst = da.Convert(da.Query("select ma from TheLoai where ten=N'" + cbbtheloai.Text + "'"));
            chitiet.theloaima = lst[0].ToString();
            string[] str = { chitiet.sachma, chitiet.theloaima, chitiet.tacgiama, chitiet.nhaxuatbanma };
            if (da.Dieukhien(str) == 1)
            {
                chitiet.ThemVaoChiTietPhieuMuon(chitiet.sachma, chitiet.nhaxuatbanma, chitiet.theloaima, chitiet.tacgiama);
                MessageBox.Show("Thành công");
                chitiet.phieumuonma           = txtphieumuon.Text;
                DSChitietphieumuon.DataSource = da.Query("DanhSachChiTietPhieuMuon", new SqlParameter("@phieumuonma", chitiet.phieumuonma));
            }
            else
            {
                MessageBox.Show("Chưa nhập đầy đủ thông tin");
            }
        }
 public static void MappingCTPM(this ChiTietPhieuMuonDTO ctpmDTO, ChiTietPhieuMuon ctpm)
 {
     ctpm.MaPM       = ctpmDTO.MaPM;
     ctpm.MaSach     = ctpmDTO.MaSach;
     ctpm.PhiMuon    = ctpmDTO.PhiMuon;
     ctpm.NgayHetHan = ctpmDTO.NgayHetHan;
     ctpm.GiaHan     = ctpmDTO.GiaHan;
 }
Ejemplo n.º 5
0
        private void add_to_data()
        {
            ChiTietPhieuMuon ctpm1 = new ChiTietPhieuMuon();

            ctpm1.MaCTPM = "CTPM" + mactpm.ToString();
            ctpm1.MaPM   = txtpm.Text;
            ctpm1.MaS    = txtmas.Text;
            list.Add(ctpm1);
        }
Ejemplo n.º 6
0
        public void deleteCTPhieuMuon(ChiTietPhieuMuon ct)
        {
            openConnection();
            string     query = "delete from ChiTietPhieuMuon where IDctPhieuMuon = @MaCTPhieuMuon";
            SqlCommand cmd   = new SqlCommand(query, Conn);

            cmd.Parameters.AddWithValue("@MaCTPhieuMuon", ct.ID_ChiTietPhieuMuon);
            cmd.ExecuteNonQuery();
        }
Ejemplo n.º 7
0
        public void ThemChiTietPhieuMuonSach(string maSach, int maPhieu)
        {
            ChiTietPhieuMuon p = new ChiTietPhieuMuon();

            p.MaSach      = Int32.Parse(maSach);
            p.MaPhieuMuon = maPhieu;
            qltvDB.ChiTietPhieuMuons.InsertOnSubmit(p);
            qltvDB.SubmitChanges();
        }
Ejemplo n.º 8
0
        private void ChiTietPhieuMuon_PropertyChanged(Object sender, PropertyChangedEventArgs e)
        {
            ChiTietPhieuMuon ctpm = sender as ChiTietPhieuMuon;

            if (e.PropertyName == nameof(ChiTietPhieuMuon.Sach))
            {
                ctpm.Sach.PropertyChanged  += new PropertyChangedEventHandler(ChiTietPhieuMuon_Sach_PropertyChanged);
                ctpm.Sach.PropertyChanging += new PropertyChangingEventHandler(ChiTietPhieuMuon_Sach_PropertyChanging);
            }
        }
 public static ChiTietPhieuMuonDTO MappingDTO(this ChiTietPhieuMuon ctpm)
 {
     return(new ChiTietPhieuMuonDTO
     {
         MaPM = ctpm.MaPM,
         MaSach = ctpm.MaSach,
         PhiMuon = ctpm.PhiMuon,
         NgayHetHan = ctpm.NgayHetHan,
         GiaHan = ctpm.GiaHan
     });
 }
Ejemplo n.º 10
0
        // trả sách

        public void CapNhatTraSach(string maSach, int maPhieu)
        {
            ChiTietPhieuMuon p1 = qltvDB.GetTable <ChiTietPhieuMuon>().
                                  Where(s => s.MaPhieuMuon.Equals(maPhieu)).Where(s => s.MaSach.Equals(maSach)).First();

            //ChiTietPhieuMuon p = qltvDB.ChiTietPhieuMuons.
            //    FirstOrDefault(s => s.MaPhieuMuon.Equals(maPhieu)
            //|| s.MaSach.Equals(maSach));
            p1.ngayTra = DateTime.Now;
            qltvDB.SubmitChanges();
        }
        public void ThemChiTietMuon(int nm, string masach, string tensach, string istra)
        {

            ChiTietPhieuMuon ct = new ChiTietPhieuMuon();
            ct.IsTra = istra;
            ct.TenSach = tensach;
            ct.MaPhieuMuon = nm;
            ct.MaSach = Int32.Parse(masach);
            tvD.ChiTietPhieuMuons.InsertOnSubmit(ct);
            tvD.SubmitChanges();
        }
Ejemplo n.º 12
0
        //update
        public void updateChiTietPhieuMuon(eChiTietPhieuMuon newitem)
        {
            data = new DvdRentDbDataContext();
            ChiTietPhieuMuon item = data.ChiTietPhieuMuons.Single(n => n.IdDVD == newitem.IdDvd && n.IdPhieuMuon == newitem.IdPhieuMuon);

            item.IdPhieuMuon = newitem.IdPhieuMuon;
            item.IdDVD       = newitem.IdDvd;
            item.PhiTre      = newitem.PhiTre;
            item.NgayTra     = newitem.NgayTra;
            item.TinhTrang   = newitem.TinhTrang;
            data.SubmitChanges();
        }
Ejemplo n.º 13
0
        public void insertCTPhieuMuon(ChiTietPhieuMuon ct)
        {
            openConnection();
            string     query = "insert into ChiTietPhieuMuon(IDctPhieuMuon, IDPhieuMuon, IDSach, SoLuong, TrangThai) values (@IDctPhieuMuon, @IDPhieuMuon, @IDSach, @SoLuong, @TrangThai)";
            SqlCommand cmd   = new SqlCommand(query, Conn);

            cmd.Parameters.AddWithValue("@IDctPhieuMuon", ct.ID_ChiTietPhieuMuon);
            cmd.Parameters.AddWithValue("@IDPhieuMuon", ct.ID_PhieuMuon);
            cmd.Parameters.AddWithValue("@IDSach", ct.ID_Sach);
            cmd.Parameters.AddWithValue("@SoLuong", ct.SoLuong);
            cmd.Parameters.AddWithValue("@TrangThai", ct.TrangThai);
            cmd.ExecuteNonQuery();
        }
Ejemplo n.º 14
0
        public void editCTPhieuMuon(ChiTietPhieuMuon ct)
        {
            openConnection();
            string     query = "update ChiTietPhieuMuon set IDPhieuMuon = @IDPhieuMuon, IDSach = @IDSach, SoLuong = @SoLuong, TrangThai = @TrangThai where IDctPhieuMuon = @IDctPhieuMuon";
            SqlCommand cmd   = new SqlCommand(query, Conn);

            cmd.Parameters.AddWithValue("@IDctPhieuMuon", ct.ID_ChiTietPhieuMuon);
            cmd.Parameters.AddWithValue("@IDPhieuMuon", ct.ID_PhieuMuon);
            cmd.Parameters.AddWithValue("@IDSach", ct.ID_Sach);
            cmd.Parameters.AddWithValue("@SoLuong", ct.SoLuong);
            cmd.Parameters.AddWithValue("@TrangThai", ct.TrangThai);
            cmd.ExecuteNonQuery();
        }
Ejemplo n.º 15
0
        public bool KiemTraDuSoLuongMuon(int maSach, int maPhieuMuon, int soLuongMoi)
        {
            ChiTietPhieuMuon ctpm = this.LayChiTietPhieuMuon(maPhieuMuon, maSach);

            if (ctpm == null)
            {
                int soLuongSachHienCo = SachBUS.Instance.LaySoLuongSachHienCo(maSach);
                if (soLuongSachHienCo == -1)
                {
                    throw new Exception("Không tìm thấy sách");
                }
                return(soLuongSachHienCo >= soLuongMoi);
            }
            return(soLuongMoi - ctpm.SoLuong <= ctpm.Sach.SoLuongHienCo);
        }
Ejemplo n.º 16
0
 public bool CapNhapTraSach(DTO_ChiTietMuonTra sach)
 {
     try
     {
         ChiTietPhieuMuon pm = tvD.ChiTietPhieuMuons.FirstOrDefault(p => p.MaCTPM == sach.MaCTPM);
         pm.IsTra   = sach.istra;
         pm.NgayTra = sach.ngaytra;
         tvD.SubmitChanges();
         return(true);
     }
     catch (Exception)
     {
         return(false);
     }
 }
Ejemplo n.º 17
0
        public ActionResult ChoMuonSach(string ListMaSach, int MaDocGia)
        {
            List <int> a = StringToListInt(ListMaSach);
            // Thêm phiếu mượn
            PhieuMuon pm = new PhieuMuon();

            try { pm.MaPhieuMuon = data.PhieuMuons.Max(u => u.MaPhieuMuon) + 1; }
            catch { pm.MaPhieuMuon = 1; }
            pm.NgayMuon  = DateTime.Today;
            pm.NguoiMuon = MaDocGia;
            if (ModelState.IsValid)
            {
                data.PhieuMuons.Add(pm);
                data.SaveChanges();
            }
            for (int i = 0; i < a.Count(); i++)
            {
                // Thêm các chi tiết phiếu mượn
                ChiTietPhieuMuon ct = new ChiTietPhieuMuon();
                try { ct.MaChiTietPhieuMuon = data.ChiTietPhieuMuons.Max(u => u.MaChiTietPhieuMuon) + 1; }
                catch { ct.MaChiTietPhieuMuon = 1; }
                ct.MaSach      = a[i];
                ct.NgayMuon    = DateTime.Today;
                ct.MaPhieuMuon = pm.MaPhieuMuon;
                ct.LanMuon     = 0;
                if (ModelState.IsValid)
                {
                    data.ChiTietPhieuMuons.Add(ct);
                }
                //Cập nhật trạng thái mượn cho sách
                Sach sach = data.Saches.Find(a[i]);
                sach.TinhTrangMuon = 1;
                if (ModelState.IsValid)
                {
                    data.Entry(sach).State = EntityState.Modified;
                    data.SaveChanges();
                }
            }
            var result = from sach in data.Saches where a.Contains(sach.MaSach) select sach;

            ViewBag.SoLuongSachMuon = result.Count();
            ViewBag.MaDocGia        = MaDocGia;
            ViewBag.NgayMuon        = DateTime.Today.ToString();
            return(View(result.ToList()));
        }
Ejemplo n.º 18
0
        private void frmchitietmuonsach_Load(object sender, EventArgs e)
        {
            ChiTietPhieuMuon chitiet = new ChiTietPhieuMuon();

            cbbmasach.DataSource     = da.Convert(da.Query("Select ten from Sach"));
            cbbnhaxuatban.DataSource = da.Convert(da.Query("select ten from Nhaxuatban"));
            cbbtacgia.DataSource     = da.Convert(da.Query("select ten from Tacgia"));
            cbbtheloai.DataSource    = da.Convert(da.Query("select ten from TheLoai"));
            List <Object> lst = new List <object>();

            lst = da.Convert(da.Query("select max(ma) from PhieuMuon"));
            txtphieumuon.Text = lst[0].ToString();
            if (txtphieumuon.Text != null)
            {
                chitiet.phieumuonma           = txtphieumuon.Text;
                DSChitietphieumuon.DataSource = da.Query("DanhSachChiTietPhieuMuon", new SqlParameter("@phieumuonma", chitiet.phieumuonma));
            }
        }
Ejemplo n.º 19
0
        // 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"));
        }
Ejemplo n.º 20
0
        private void btnluu_Click(object sender, EventArgs e)
        {
            try
            {
                dataDataContext db  = new dataDataContext();
                dataDataContext db1 = new dataDataContext();

                PhieuMuon pm = new PhieuMuon();
                pm.MaPM         = txtpm.Text;
                pm.MaHV         = txtmadg.Text;
                pm.ThoiGianMuon = datengaymuon.Value.Date;
                pm.Manv         = chitiet.Manv;
                pm.HanTraSach   = datengaymuon.Value.Date.AddDays(rbngay);
                db1.PhieuMuons.InsertOnSubmit(pm);
                // MessageBox.Show(pm.MaHV.ToString() + pm.MaPM.ToString() + pm.Manv.ToString());
                db1.SubmitChanges();
                foreach (ChiTietPhieuMuon prime in list)
                {
                    ChiTietPhieuMuon imp = prime;
                    db.ChiTietPhieuMuons.InsertOnSubmit(imp);
                    MessageBox.Show(prime.MaCTPM.ToString());
                    var sa = (from s in db.Saches where s.MaS == imp.MaS select s).First();
                    sa.TinhTrang = false;
                    db.SubmitChanges();

                    // MessageBox.Show(prime.MaCTPM.ToString() + prime.MaPM.ToString() + prime.MaS.ToString());
                }
                MessageBox.Show("Thêm thành công");
                load();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
                MessageBox.Show("xay ra loi", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
Ejemplo n.º 21
0
 public int InsertData(ChiTietPhieuMuon MA)
 {
     return(da.InsertDataCT(MA));
 }
 public int ThemCTPM(ChiTietPhieuMuon pm)
 {
     return(dal.ThemCTPM(pm));
 }
 public int SuaCTPM(ChiTietPhieuMuon pm)
 {
     return(dal.SuaCTPM(pm));
 }
Ejemplo n.º 24
0
 public int UpdateData(ChiTietPhieuMuon BP)
 {
     return(da.UpdateDataCT(BP));
 }
 public int Them(ChiTietPhieuMuon pChiTietPhieuMuon)
 {
     _context.ChiTietPhieuMuon.Add(pChiTietPhieuMuon);
     return(_context.SaveChanges());
 }