public bool ThemTaiLieu(TaiLieuDb tl) { try { String sql = "INSERT INTO [TaiLieu]([TenSach],[TacGia],[NamXuatBan],[Gia],[ID_TheLoaiSach],[ID_NganhHoc],[ID_NgonNguSach],[TaiBan],[SoLuong],[SoNgayMuon],[TrangThai]) " + " VALUES(@TenSach,@TacGia,@NamXuatBan ,@Gia,@ID_TheLoaiSach,@ID_NganhHoc,@ID_NgonNguSach,@TaiBan,@SoLuong,@SoNgayMuon,@TrangThai)"; dt = dpro.GetRecordSet(sql, new DatabaseParamCls[] { new DatabaseParamCls("TenSach", tl.TenSach), new DatabaseParamCls("TacGia", tl.TacGia), new DatabaseParamCls("NamXuatBan", tl.NamXuatBan), new DatabaseParamCls("Gia", tl.Gia), new DatabaseParamCls("ID_TheLoaiSach", tl.ID_TheLoaiSach), new DatabaseParamCls("ID_NganhHoc", tl.ID_NganhHoc), new DatabaseParamCls("ID_NgonNguSach", tl.ID_NgonNguSach), new DatabaseParamCls("TaiBan", tl.TaiBan), new DatabaseParamCls("SoLuong", tl.SoLuong), new DatabaseParamCls("SoNgayMuon", tl.SoNgayMuon), new DatabaseParamCls("TrangThai", tl.TrangThai) }); return(true); } catch (Exception e) { throw e; } return(false); }
public TaiLieuDb getTaiLieuById(int ID) { try { String sql = "select tl.*, nh.TenNganhHoc, nns.TenNgonNguSach, tls.TenTheLoai, " + " case tl.TrangThai when 1 then N'Được cho mượn' else N'Không được mượn' end as TrangThaiStr" + " from TaiLieu tl" + " left join NganhHoc nh on nh.ID = tl.ID_NganhHoc " + " left join NgonNguSach nns on nns.ID = tl.ID_NgonNguSach " + " left join TheLoaiSach tls on tls.ID = tl.ID_TheLoaiSach " + " where tl.id = @ID "; dt = dpro.GetRecordSet(sql, new DatabaseParamCls[] { new DatabaseParamCls("ID", ID) }); if (dt.Rows.Count >= 0) { var item = dt.Rows[0]; TaiLieuDb document = new TaiLieuDb(); document.Id = Convert.ToInt16(item["id"].ToString()); document.TenSach = item["TenSach"].ToString(); document.TacGia = item["TacGia"].ToString(); document.NamXuatBan = item["NamXuatBan"].ToString(); document.Gia = (float)Convert.ToDouble(item["Gia"].ToString()); document.ID_TheLoaiSach = Convert.ToInt16(item["ID_TheLoaiSach"].ToString()); document.ID_NganhHoc = Convert.ToUInt16(item["ID_NganhHoc"].ToString()); document.ID_NgonNguSach = Convert.ToInt16(item["ID_NgonNguSach"].ToString()); document.TaiBan = Convert.ToInt16(item["ID_NgonNguSach"].ToString()); document.SoLuong = Convert.ToInt16(item["SoLuong"].ToString()); document.SoNgayMuon = Convert.ToInt16(item["SoNgayMuon"].ToString()); document.TrangThai = Convert.ToBoolean(item["TrangThai"].ToString()); document.TenNganhHoc = item["TenNganhHoc"].ToString(); document.TenNgonNguSach = item["TenNgonNguSach"].ToString(); document.TenTheLoai = item["TenTheLoai"].ToString(); return(document); } } catch (Exception e) { Console.WriteLine(e.Message); } return(null); }
private void setInfoDialog(int idDocumentSelect) { tl = tlBll.getTaiLieuById(idDocumentSelect); if (tl == null) { MessageBox.Show("Không tồn tại dữ liệu tài liệu", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } //set info document in dialog txtTenSach.Text = tl.TenSach; txtTacGia.Text = tl.TacGia; txtNamXuatBan.Text = tl.NamXuatBan; txtGia.Text = Convert.ToString(tl.Gia); cboTheLoai.SelectedIndex = tl.ID_TheLoaiSach; cboNganhHoc.SelectedIndex = tl.ID_NganhHoc; cboNgonNguSach.SelectedIndex = tl.ID_NgonNguSach; txtTaiBan.Text = Convert.ToString(tl.TaiBan); txtSoLuong.Text = Convert.ToString(tl.SoLuong); txtSoNgayMuon.Text = Convert.ToString(tl.SoNgayMuon); cboTrangThai.SelectedIndex = tl.TrangThai == true ? 0 : 1;// 0: Được cho mượn, 1: không được cho mượn }
public bool SuaTaiLieu(TaiLieuDb tl) { try { String sql = "UPDATE [TaiLieu] " + " SET [TenSach] = @TenSach " + " ,[TacGia] = @TacGia" + " ,[NamXuatBan] = @NamXuatBan" + " ,[Gia] = @Gia" + " ,[ID_TheLoaiSach] = @ID_TheLoaiSach" + " ,[ID_NganhHoc] =@ID_NganhHoc" + " ,[ID_NgonNguSach] = @ID_NgonNguSach" + " ,[TaiBan] = @TaiBan" + " ,[SoLuong] = @SoLuong" + " ,[SoNgayMuon] = @SoNgayMuon" + " ,[TrangThai] = @TrangThai" + " WHERE TaiLieu.ID = @ID"; dt = dpro.GetRecordSet(sql, new DatabaseParamCls[] { new DatabaseParamCls("TenSach", tl.TenSach), new DatabaseParamCls("TacGia", tl.TacGia), new DatabaseParamCls("NamXuatBan", tl.NamXuatBan), new DatabaseParamCls("Gia", tl.Gia), new DatabaseParamCls("ID_TheLoaiSach", tl.ID_TheLoaiSach), new DatabaseParamCls("ID_NganhHoc", tl.ID_NganhHoc), new DatabaseParamCls("ID_NgonNguSach", tl.ID_NgonNguSach), new DatabaseParamCls("TaiBan", tl.TaiBan), new DatabaseParamCls("SoLuong", tl.SoLuong), new DatabaseParamCls("SoNgayMuon", tl.SoNgayMuon), new DatabaseParamCls("TrangThai", tl.TrangThai), new DatabaseParamCls("ID", tl.Id) }); return(true); } catch (Exception e) { throw e; } return(false); }
private void updateDocument(int idDocumentSelect) { // validate if (!validateDocument()) { return; } // Kiem tra lai nhan vien co ton tai khong? tl = tlBll.getTaiLieuById(idDocumentSelect); if (tl == null) { MessageBox.Show("Không tồn tại dữ liệu tài liệu", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } tl.TenSach = txtTenSach.Text; tl.TacGia = txtTacGia.Text; tl.NamXuatBan = txtNamXuatBan.Text; tl.Gia = (float)Convert.ToDouble(txtGia.Text); tl.ID_TheLoaiSach = Convert.ToInt32(cboTheLoai.SelectedIndex); tl.ID_NganhHoc = Convert.ToInt32(cboNganhHoc.SelectedIndex); tl.ID_NgonNguSach = Convert.ToInt32(cboNgonNguSach.SelectedIndex); tl.TaiBan = Convert.ToInt32(txtTaiBan.Text); tl.SoLuong = Convert.ToInt32(txtSoLuong.Text); tl.SoNgayMuon = Convert.ToInt32(txtSoNgayMuon.Text); tl.TrangThai = cboTrangThai.SelectedIndex == 0 ? true : false; //select index =="Được cho mượn" là true, còn ngược lại if (tlBll.SuaTaiLieu(tl)) { MessageBox.Show("Đã cập nhật thành công", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information); ucManagerDocuments.LoadGridView(); ucManagerDocuments.DisposeDialog(); return; } else { MessageBox.Show("Bạn đã nhập sai thông tin tài liệu cần sửa, yêu cầu nhập lại!", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
private void createDocument() { // validate if (!validateDocument()) { return; } tl = new TaiLieuDb(); tl.TenSach = txtTenSach.Text; tl.TacGia = txtTacGia.Text; tl.NamXuatBan = txtNamXuatBan.Text; if (!String.IsNullOrWhiteSpace(txtGia.Text)) { tl.Gia = (float)Convert.ToDouble(txtGia.Text.Trim()); } tl.ID_TheLoaiSach = cboTheLoai.SelectedIndex; tl.ID_NganhHoc = cboNganhHoc.SelectedIndex; tl.ID_NgonNguSach = cboNgonNguSach.SelectedIndex; tl.TaiBan = Convert.ToInt32(txtTaiBan.Text); tl.SoLuong = Convert.ToInt32(txtSoLuong.Text); tl.SoNgayMuon = Convert.ToInt32(txtSoNgayMuon.Text); tl.TrangThai = cboTrangThai.SelectedIndex == 0 ? true : false; //select index =="Được cho mượn" là true, còn ngược lại if (tlBll.ThemTaiLieu(tl)) { MessageBox.Show("Đã thêm mới thành công", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information); ucManagerDocuments.LoadGridView(); ucManagerDocuments.DisposeDialog(); return; } else { MessageBox.Show("Có lỗi xảy ra trong quá trình thêm mới", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } }
public bool SuaTaiLieu(TaiLieuDb tl) { return(tailieuDAL.SuaTaiLieu(tl)); }
public bool ThemTaiLieu(TaiLieuDb tl) { return(tailieuDAL.ThemTaiLieu(tl)); }