private void btnXoa_Click(object sender, EventArgs e) { BLKM = new BLKhuyenMai(); try { if (txtMaKM.Text != "") { DialogResult DL = MessageBox.Show("Bạn có muốn xóa mẫu tin này?", "xác nhận", MessageBoxButtons.YesNoCancel); if (DL == DialogResult.Yes) { int r = dgvKM.CurrentCell.RowIndex; if (BLKM.XoaKM(ref err, this.txtMaKM.Text)) { LoadData(); MessageBox.Show("Đã xóa xong"); } else { MessageBox.Show(err, "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Warning); } } } else { MessageBox.Show("Bạn chưa nhập ID", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Warning); } } catch { MessageBox.Show("Lỗi rồi"); } }
private void btnTimKiem_Click(object sender, EventArgs e) { BLKM = new BLKhuyenMai(); DTKM = new DataTable(); DTKM.Clear(); DataSet ds = BLKM.TimKiemKhuyenMai(txtTimKiem.Text); DTKM = ds.Tables[0]; dgvKM.DataSource = DTKM; }
private void btnLuu_Click(object sender, EventArgs e) { BLKM = new BLKhuyenMai(); if (Them) { if (this.txtMaKM.Text == "") { MessageBox.Show("Bạn chưa nhập mã!", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Warning); this.txtMaKM.Focus(); } else { try { if (BLKM.ThemKM(this.txtMaKM.Text, this.txtTenKM.Text, this.txtDiscount.Text, this.dateTimePicker_NgayBD.Value, this.dateTimePicker_NgayKT.Value, ref err)) { LoadData(); MessageBox.Show("Đã thêm xong!"); Default_Button(); } else { MessageBox.Show(err, "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Error); } } catch (SqlException) { MessageBox.Show("Không thêm được. Lỗi rồi!"); } } } else { try { if (BLKM.CapNhatKhuyenMai(this.txtMaKM.Text, this.txtTenKM.Text, this.txtDiscount.Text, this.dateTimePicker_NgayBD.Value, this.dateTimePicker_NgayKT.Value, ref err)) { LoadData(); MessageBox.Show("Đã sửa xong!"); Default_Button(); this.txtMaKM.Enabled = true; } else { MessageBox.Show(this.err); } } catch (SqlException) { MessageBox.Show("Không sửa được. Lỗi rồi!"); } } }
public void LoadData() { try { DTKM = new DataTable(); BLKM = new BLKhuyenMai(); DTKM.Clear(); DataSet ds = BLKM.LayKM(); DTKM = ds.Tables[0]; // Đưa dữ liệu lên DataGridView dgvKM.DataSource = DTKM; Default(); Default_Button(); dgvKM_CellClick(null, null); } catch (SqlException) { MessageBox.Show("Không lấy được nội dung trong bảng DICHVU. Lỗi rồi!!!"); } }