public PhieuMuon getPhieuMuonById(int id) { String sql = @"SELECT [MaPhieu] ,[MaDG] ,[NgayMuon] ,[MaNV] FROM [dbo].[PhieuMuon] WHERE [MaPhieu]=" + id; DataTable table = dbcnn.getdata(sql); PhieuMuon newPhieuMuon = new PhieuMuon(); if (table.Rows.Count == 1) { newPhieuMuon.MaPhieu = (int)table.Rows[0]["MaPhieu"]; //đổ dữ liệu vào độc giả newPhieuMuon.docGia.MaDG = (int)table.Rows[0]["MaDG"]; DocGiaDAL dgDAL = new DocGiaDAL(); newPhieuMuon.docGia = dgDAL.getDocGiaById(newPhieuMuon.docGia.MaDG); newPhieuMuon.NgayMuon = (DateTime)table.Rows[0]["NgayMuon"]; //đổ dữ liệu vào nhân viên newPhieuMuon.nhanVien.MaNV = (int)table.Rows[0]["MaNV"]; NhanVienDAL nvDAL = new NhanVienDAL(); newPhieuMuon.nhanVien = nvDAL.getNhanVienByID(newPhieuMuon.nhanVien.MaNV); //đổ dữ liệu vào sách } return newPhieuMuon; }
public List<PhieuMuon> getListPhieuMuon() { String sql = @"SELECT [MaPhieu] ,[MaDG] ,[NgayMuon] ,[MaNV] FROM [dbo].[PhieuMuon]"; DataTable table = dbcnn.getdata(sql); List<PhieuMuon> listDG = new List<PhieuMuon>(); foreach (DataRow row in table.Rows) { PhieuMuon newPhieuMuon = new PhieuMuon(); newPhieuMuon.MaPhieu = (int)row["MaPhieu"]; //đổ dữ liệu vào độc giả newPhieuMuon.docGia.MaDG = (int)row["MaDG"]; DocGiaDAL dgDAL = new DocGiaDAL(); newPhieuMuon.docGia = dgDAL.getDocGiaById(newPhieuMuon.docGia.MaDG); newPhieuMuon.NgayMuon = (DateTime)row["NgayMuon"]; //đổ dữ liệu vào nhân viên newPhieuMuon.nhanVien.MaNV = (int)row["MaNV"]; NhanVienDAL nvDAL = new NhanVienDAL(); newPhieuMuon.nhanVien = nvDAL.getNhanVienByID(newPhieuMuon.nhanVien.MaNV); listDG.Add(newPhieuMuon); } return listDG; }