コード例 #1
0
        private void btnDelete_Click(object sender, EventArgs e)
        {
            try
            {
                if (this.grvCompany.SelectedRows.Count > 0)
                {
                    DialogResult result = MessageBox.Show("Bạn thự sự muốn xóa doanh nghiệp đã chọn?", "Cảnh báo!", MessageBoxButtons.YesNo);
                    if (result == DialogResult.Yes)
                    {
                        int selectedIndex = grvCompany.SelectedRows[0].Index;

                        // gets the RowID from the first column in the grid
                        var companyCode = grvCompany[0, selectedIndex].Value.ToString();

                        tblCompany company = CompanyFactory.FindByCode(companyCode);
                        if (company == null)
                        {
                            MessageBox.Show("Loại hình này không còn tồn tại trong Cơ Sở Dữ Liệu. Bạn hãy kiểm tra lại", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                            return;
                        }

                        if (CompanyFactory.Delete(companyCode) > 0)
                        {
                            search();
                            MessageBox.Show("Xóa doanh nghiệp thành công", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        }
                        else
                        {
                            search();
                            MessageBox.Show("Xóa doanh nghiệp không thành công", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        }
                    }
                    else
                    {
                        return;
                    }
                }
                else
                {
                    MessageBox.Show("Bạn cần chọn một bản ghi để xóa", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                }
            }
            catch (Exception ex)
            {
                if (GlobalInfo.IsDebug)
                {
                    MessageBox.Show(ex.ToString());
                }
            }
        }