Ejemplo n.º 1
0
        private void btnDeleteUser_Click(object sender, EventArgs e)
        {
            string username = currentItem.Username;    // = lstUserAccount1.SelectedItem.ToString();

            if (string.Equals(username, Program.username))
            {
                MessageBox.Show("Lỗi. Tài khoản " + Program.username + " đang được đăng nhập",
                    "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            DataAccess da = new DataAccess();
            Nhanvien employee = da.getNhanvienbyUserName(username);
            DialogResult dresult = MessageBox.Show("Tài khoản: " + employee.Username + " sẽ bị xóa?",
                "Cảnh báo",
                MessageBoxButtons.YesNo, MessageBoxIcon.Warning);

            if (dresult == DialogResult.Yes)
            {
                if (da.deleteNhanvien(employee))
                {
                    MessageBox.Show("Đã xóa tài khoản: " + employee.Username,
                        "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    currentIndex = customListBoxOtherUser.SelectedIndex;
                    customListBoxOtherUser.Items.RemoveAt(currentIndex);
                    if (customListBoxOtherUser.Items.Count > 0)
                    {
                        if (currentIndex < customListBoxOtherUser.Items.Count)
                            customListBoxOtherUser.SelectedIndex = currentIndex;
                        else
                            customListBoxOtherUser.SelectedIndex = currentIndex - 1;
                    }
                }
            }
        }