示例#1
0
        private void btXoaKhoa_Click(object sender, EventArgs e)
        {
            clickingButton = "ThemKhoa";
            var confirmResult = MessageBox.Show("Bạn chắc chắn muốn xóa ?",
                                                "Confirm Delete",
                                                MessageBoxButtons.YesNo, MessageBoxIcon.Question);

            if (confirmResult == DialogResult.Yes)
            {
                try
                {
                    string id = dgvKhoa.SelectedRows[0].Cells[1].Value.ToString();
                    int    sl = int.Parse(dgvKhoa.SelectedRows[0].Cells[4].Value.ToString());
                    string ma = id.Substring(0, 3) + "-000-000";
                    int    t  = bll.GetSL_BLL(ma) + bll.GetSLNhapKhoa_BLL(id);
                    bll.UpdateSL(ma, t, t * 10);
                    bll.DeleTSKhoa_BLL(id);
                    dgvKhoa.DataSource = null;
                    dgvKhoa.DataSource = bll.GetInfoNhapAllKhoa_BLL();
                    stt(dgvKhoa);


                    MessageBox.Show("Thành công !", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
                catch (Exception)
                {
                    MessageBox.Show("Không được phép xóa vì có ràng buộc với bảng CHỨNG TỪ GIẢM!!!", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
            }
            else
            {
                MessageBox.Show("Không thực hiện xóa !", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
        }