public BEL_TacGia(BEL_TacGia TacGia) { _Ma = TacGia._Ma; _Ten = TacGia._Ten; _DienThoai = TacGia._DienThoai; _TrangThai = TacGia.TrangThai; }
private void btnThem_Click(object sender, EventArgs e) { string maTacGia = txtMaTacGia.Text; string tenTacGia = txtTenTacGia.Text; string dienThoai = txtDienThoai.Text; string trangThai = "Tồn tại"; BEL_TacGia tacGia = new BEL_TacGia(maTacGia, tenTacGia, dienThoai, trangThai); // try { if (BAL_TacGia.Add(tacGia)) { MessageBox.Show("Thêm thành công!", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information); // txtMaTacGia.Text = "TG" + (BAL_TacGia.Count() + 1); txtTenTacGia.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); } }
public static bool Update(BEL_TacGia TacGia) { if (TacGia.Ma == "") { throw new Exception("Mã tác giả không được rỗng!"); } if (TacGia.Ten == "") { throw new Exception("Tên tác giả không được rỗng!"); } if (TacGia.DienThoai == "") { throw new Exception("Điện thoại không được rỗng!"); } if (TacGia.TrangThai == "") { throw new Exception("Trạng thái không được rỗng!"); } try { return(DAL_TacGia.Update(TacGia)); } catch (Exception Err) { throw; } }
public static BEL_TacGia GetObjectById(string Id) { try { GetConnection(); string Query = string.Format("select* from TACGIA where MaTacGia = '{0}'", Id); SqlCommand Command = new SqlCommand(Query, Connection); SqlDataReader DataReader = Command.ExecuteReader(); DataReader.Read(); string MaTacGia = (string)DataReader["MaTacGia"]; string TenTacGia = (string)DataReader["TenTacGia"]; string DienThoai = (string)DataReader["DienThoai"]; string TrangThai = (string)DataReader["TrangThai"]; BEL_TacGia TacGia = new BEL_TacGia(MaTacGia, TenTacGia, DienThoai, TrangThai); return(TacGia); } catch (Exception Err) { throw; } finally { Connection.Close(); } }
private void btnSuaTacGia_Click(object sender, EventArgs e) { string maTacGia = txtMaTacGia.Text; string tenTacGia = txtTenTacGia.Text; string dienThoai = txtDienThoaiTacGia.Text; string trangThai = "Tồn tại"; BEL_TacGia tacGia = new BEL_TacGia(maTacGia, tenTacGia, dienThoai, trangThai); try { if (BAL_TacGia.Update(tacGia)) { MessageBox.Show("Cập nhật thành công!", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information); loadDanhSachTacGia(dgvDanhSachTacGia, BAL_TacGia.Load()); // for (int i = 0; i < dgvDanhSachTacGia.RowCount; i++) { if (dgvDanhSachTacGia["MaTacGia", i].Value.ToString() == maTacGia) { dgvDanhSachTacGia["MaTacGia", 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 dgvDanhSachTacGia_CellClick(object sender, DataGridViewCellEventArgs e) { string maTacGia = dgvDanhSachTacGia.CurrentRow.Cells["MaTacGia"].Value.ToString().Trim(); BEL_TacGia tacGia = BAL_TacGia.GetObjectById(maTacGia); txtMaTacGia.Text = tacGia.Ma; txtTenTacGia.Text = tacGia.Ten; txtDienThoaiTacGia.Text = tacGia.DienThoai; }
public static bool Update(BEL_TacGia TacGia) { try { GetConnection(); string Query = string.Format("update TACGIA set TenTacGia = N'{0}', DienThoai = '{1}' where MaTacGia = '{2}'", TacGia.Ten, TacGia.DienThoai, TacGia.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_TacGia TacGia) { try { GetConnection(); string Query = string.Format("insert into TACGIA(MaTacGia, TenTacGia, DienThoai, TrangThai) values('{0}', N'{1}', N'{2}', N'{3}')", TacGia.Ma, TacGia.Ten, TacGia.DienThoai, TacGia.TrangThai); SqlCommand Command = new SqlCommand(Query, Connection); int Result = Command.ExecuteNonQuery(); return(Result == 1); } catch (Exception Err) { throw; } finally { Connection.Close(); } }