示例#1
0
        private void buttonXoa_Click(object sender, EventArgs e)
        {
            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 = dgvTS.SelectedRows[0].Cells[3].Value.ToString();
                    int    sl = int.Parse(dgvTS.SelectedRows[0].Cells[6].Value.ToString());
                    string ma = id.Substring(0, 7) + "-000";
                    int    t  = bll.GetSL_BLL(ma) + sl;
                    bll.UpdateSL(ma, t, t * 10);
                    bll.DeleTS_BLL(id);
                    dgvTS.DataSource = null;
                    dgvTS.DataSource = bll.GetInfoTSAllPhong_BLL();
                    stt(dgvTS);

                    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);
            }
        }