private async void btnDelete_Click(object sender, EventArgs e) { // Lay tai khoan admin dang duoc chon trong bang AdminAccount adminAccount = GetSelectedAdminAccount(); // Neu hien tai khong co tai khoan nao duoc chon thi hien thong bao if (adminAccount == null) { MessageBox.Show("You must choose an account to edit!", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); return; } // Neu co tai khoan dang duoc chon thi sua cot IsActive lai thanh False adminAccount.IsActive = false; // Gui len server de cap nhat lai cot IsActive trong CSDL AdminAccountWrapper adminAccountWrapper = new AdminAccountWrapper(); bool isSuccess = await adminAccountWrapper.Put(adminAccount.ID, adminAccount); // Kiem tra ket qua tra ve if (isSuccess) { // Neu ket qua la thanh cong, hien thong bao thanh cong MessageBox.Show("Account status was set to inactive!", "Success", MessageBoxButtons.OK, MessageBoxIcon.Information); // Load lai bang LoadDataGridView(); } else { // Neu ket qua that bai, hien thong bao loi MessageBox.Show("An error has occurred!\n" + adminAccountWrapper.GetErrorMessage(), "Failed", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
private async void btnSubmit_Click(object sender, EventArgs e) { // Lay gia tri tren form gan vao account adminAccount.Username = txtUsername.Text; adminAccount.Name = txtName.Text; adminAccount.Role = txtRole.Text; adminAccount.IsActive = rbtnActive.Checked; // Neu dang o che do tao account moi thi phai lay gia tri trong o password gan vao account. // Neu dang o che do chinh sua ma gia tri trong o password khac voi gia tri password cua account // nghia la nguoi dung da thay doi password, phai cap nhat luon password if (mode == FormMode.CREATE || txtPassword.Text != adminAccount.Password) { adminAccount.Password = ARSUtilities.Md5Hash(txtPassword.Text); } // Tao mot API AdminAccountWrapper adminAccountWrapper = new AdminAccountWrapper(); // Tao bien luu ket qua tra ve bool isSuccess; // Kiem tra xem dang o che do nao if (mode == FormMode.CREATE) { // Neu dang o che do them moi (CREATE) // POST account len server isSuccess = await adminAccountWrapper.Post(adminAccount); } else { // Neu dang o che do chinh sua (EDIT) // PUT account len server isSuccess = await adminAccountWrapper.Put(adminAccount.ID, adminAccount); } // Kiem tra ket qua tra ve if (isSuccess) { // Neu thanh cong MessageBox.Show("Operation completed successfully!", "Success", MessageBoxButtons.OK, MessageBoxIcon.Information); // Tat form CE this.Close(); } else { // Neu that bai, hien thong bao loi MessageBox.Show("An error has occurred:\n" + adminAccountWrapper.GetErrorMessage(), "Failed", MessageBoxButtons.OK, MessageBoxIcon.Error); } }