private void btnThem_Click(object sender, EventArgs e) { string maLoaiSach = txtMaLoaiSach.Text; string tenLoaiSach = txtTenLoaiSach.Text; string trangThai = "Tồn tại"; BEL_LoaiSach loaiSach = new BEL_LoaiSach(maLoaiSach, tenLoaiSach, trangThai); // try { if (BAL_LoaiSach.Add(loaiSach)) { MessageBox.Show("Thêm thành công!", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information); // txtMaLoaiSach.Text = "LS" + (BAL_LoaiSach.Count() + 1); txtTenLoaiSach.Focus(); } else { MessageBox.Show("Thêm thất bại!", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Error); } } catch (Exception err) { MessageBox.Show(err.Message, "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
private void btnSuaLoaiSach_Click(object sender, EventArgs e) { string maLoaiSach = txtMaLoaiSach.Text; string tenLoaiSach = txtTenLoaiSach.Text; string trangThai = "Tồn tại"; BEL_LoaiSach loaiSach = new BEL_LoaiSach(maLoaiSach, tenLoaiSach, trangThai); try { if (BAL_LoaiSach.Update(loaiSach)) { MessageBox.Show("Cập nhật thành công!", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information); loadDanhSachLoaiSach(dgvDanhSachLoaiSach, BAL_LoaiSach.Load()); // for (int i = 0; i < dgvDanhSachLoaiSach.RowCount; i++) { if (dgvDanhSachLoaiSach["MaLoai", i].Value.ToString() == maLoaiSach) { dgvDanhSachLoaiSach["TenLoai", i].Selected = true; } } } else { MessageBox.Show("Cập nhật thất bại!", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Error); } } catch (Exception err) { MessageBox.Show(err.Message, "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
private void dgvDanhSachLoaiSach_CellClick(object sender, DataGridViewCellEventArgs e) { string maLoaiSach = dgvDanhSachLoaiSach.CurrentRow.Cells["MaLoai"].Value.ToString().Trim(); BEL_LoaiSach loaiSach = BAL_LoaiSach.GetObjectById(maLoaiSach); txtMaLoaiSach.Text = loaiSach.Ma; txtTenLoaiSach.Text = loaiSach.Ten; }
public static bool Update(BEL_LoaiSach LoaiSach) { try { GetConnection(); string Query = string.Format("update LOAISACH set TenLoai = N'{0}' where MaLoai = '{1}'", LoaiSach.Ten, LoaiSach.Ma); SqlCommand Command = new SqlCommand(Query, Connection); int Result = Command.ExecuteNonQuery(); return(Result == 1); } catch (Exception Err) { throw; } finally { Connection.Close(); } }
public static bool Add(BEL_LoaiSach LoaiSach) { try { GetConnection(); string Query = string.Format("insert into LOAISACH(MaLoai, TenLoai, TrangThai) values('{0}', N'{1}', N'{2}')", LoaiSach.Ma, LoaiSach.Ten, LoaiSach.TrangThai); SqlCommand Command = new SqlCommand(Query, Connection); int Result = Command.ExecuteNonQuery(); return(Result == 1); } catch (Exception Err) { throw; } finally { Connection.Close(); } }
public static bool Update(BEL_LoaiSach LoaiSach) { if (LoaiSach.Ma == "") { throw new Exception("Mã loại sách không được trống!"); } if (LoaiSach.Ten == "") { throw new Exception("Tên loại sách không được trống!"); } if (LoaiSach.TrangThai == "") { throw new Exception("Trạng thái không được trống!"); } try { return(DAL_LoaiSach.Update(LoaiSach)); } catch (Exception Err) { throw; } }
public static BEL_LoaiSach GetObjectById(string Id) { try { GetConnection(); string Query = string.Format("select* from LOAISACH where MaLoai = '{0}'", Id); SqlCommand Command = new SqlCommand(Query, Connection); SqlDataReader DataReader = Command.ExecuteReader(); DataReader.Read(); string MaLoai = (string)DataReader["MaLoai"]; string TenLoai = (string)DataReader["TenLoai"]; string TrangThai = (string)DataReader["TrangThai"]; BEL_LoaiSach LoaiSach = new BEL_LoaiSach(MaLoai, TenLoai, TrangThai); return(LoaiSach); } catch (Exception Err) { throw; } finally { Connection.Close(); } }
public BEL_LoaiSach(BEL_LoaiSach LoaiSach) { _Ma = LoaiSach._Ma; _Ten = LoaiSach._Ten; _TrangThai = LoaiSach._TrangThai; }