示例#1
0
 private void btnDeleteAccount_Click(object sender, EventArgs e)
 {
     try
     {
         if (this.lstAccount.SelectedItems.Count > 0)
         {
             ListViewItem lvw = lstAccount.SelectedItems[0];
             AccountDTO   sp  = (AccountDTO)lvw.Tag;
             if (sp.ID == Program.sAccount.ID)
             {
                 MessageBox.Show("Bạn không thể sử dụng chức năng này với chính bạn.", "Thông báo", MessageBoxButtons.OK);
             }
             else
             {
                 frm_XacNhan frm_XN = new frm_XacNhan("Bạn vui lòng nhập mật khẩu để xác nhận thao tác này!", Program.sAccount);
                 if (frm_XN.ShowDialog() == DialogResult.OK)
                 {
                     if (AccountBUS.IsLogin(Program.sAccount.ID, frm_XN.txtXacNhap.Text))
                     {
                         if (!BillBUS.IsExistAccountInBill(sp.ID))
                         {
                             if (AccountBUS.DeleteAccount(sp) == true)
                             {
                                 MessageBox.Show("Bạn đã xóa thành công", "Thông báo", MessageBoxButtons.OK);
                                 ShowAccout();
                                 DeleteTextAccount();
                                 txtNameAcount.ReadOnly      = false;
                                 this.btnEditAccount.Visible = false;
                                 this.btnAddAccount.Visible  = true;
                                 btnDeleteAccount.Enabled    = false;
                             }
                             else
                             {
                                 MessageBox.Show("Xóa tài khoản thất bại.", "Thông báo", MessageBoxButtons.OK);
                             }
                         }
                         else
                         {
                             MessageBox.Show("Tài khoản này đang hoạt động với hệ thống. Nên bạn không thể xóa tài khoản này khỏi hệ thống.", "Thông báo", MessageBoxButtons.OK);
                         }
                     }
                     else
                     {
                         MessageBox.Show("Bạn đã nhập sai mật khẩu, vui lòng quay lại sau.", "Thông báo", MessageBoxButtons.OK);
                     }
                 }
             }
         }
         else
         {
             MessageBox.Show("Bạn chưa chọn được tài khoản nào.", "Thông báo", MessageBoxButtons.OK);
         }
     }
     catch
     {
         MessageBox.Show("Hệ thống đang bảo trì, bạn vui lòng thử lại.", "Thông báo", MessageBoxButtons.OK);
     }
 }