private void BOPHIEU_Click_1(object sender, EventArgs e) { if (idList.Count() == 3) { try { string query = "DELETE FROM TESTADMIN.PHIEUBAU WHERE MA_THANHVIEN = '" + User.Username + "'"; OracleDataController.Delete(query); string insert = "INSERT INTO TESTADMIN.PHIEUBAU (MA_THANHVIEN, UCV1, UCV2, UCV3) VALUES('" + User.Username + "','" + idList[0] + "','" + idList[1] + "','" + idList[2] + "')"; OracleDataController.Insert(insert); MessageBox.Show("Bỏ phiếu thành công"); } catch (Exception ex) { MessageBox.Show(ex.Message); } this.Load_PhieuBau(); this.Load_Form(); } else { MessageBox.Show(" Vui lòng bỏ phiếu tối đa 3 ứng cử viên !"); } }
private void Delete_Click(object sender, EventArgs e) { string userName = null; if (comboUserDelete.SelectedIndex != -1) { userName = comboUserDelete.SelectedItem.ToString(); } string query = "drop user " + userName; bool checkIsDeleted = OracleDataController.Delete(query); if (checkIsDeleted) { MessageBox.Show("Delete user successfully!"); } else { MessageBox.Show("Delete user failed!"); } }
private void btnDeleteRole_Click(object sender, EventArgs e) { if (comboDeleteRole.SelectedIndex != -1) { OracleDataController.ConnectDB(FormLogin.connectionStr); string query = "drop role " + comboDeleteRole.SelectedItem.ToString(); bool checkIsDelete = OracleDataController.Delete(query); if (checkIsDelete) { MessageBox.Show("Delete role successfully!"); } else { MessageBox.Show("Delete role failed!"); } } else { MessageBox.Show("You didn't choose the role yet!"); return; } }
public static void DeleteData(DataGridView dgv, List <string> listOfColumns, string textboxValue, string errorMess, string query, string tableName, bool loadGrid = true) { if (string.IsNullOrEmpty(textboxValue)) { MessageBox.Show($"{errorMess} cannot be empty!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } try { OracleDataController.ConnectDB(OracleDataController.GetDBConnection()); OracleDataController.Delete(query); MessageBox.Show("Delete successfully!", "Success", MessageBoxButtons.OK, MessageBoxIcon.Information); if (loadGrid) { LoadDataToGrid(dgv, listOfColumns, tableName); } } catch (Exception ex) { MessageBox.Show("ERROR: " + ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
private void DataUCV_CellContentClick(object sender, DataGridViewCellEventArgs e) { string ma_uv = dataUCV.Rows[e.RowIndex].Cells["MAUV"].FormattedValue.ToString(); string name = dataUCV.Columns[e.ColumnIndex].Name; switch (name) { case "DELETE": { string query = "DELETE FROM TESTADMIN.UNGCUVIEN WHERE MAUV = '" + ma_uv + "'"; try { OracleDataController.Delete(query); } catch (Exception ex) { MessageBox.Show(ex.Message); } this.Load_UCV(); break; } case "EDIT": { dataUCV.Rows[e.RowIndex].Cells["HOTEN"].ReadOnly = false; dataUCV.Rows[e.RowIndex].Cells["NAMSINH"].ReadOnly = false; dataUCV.Rows[e.RowIndex].Cells["CHUCVU"].ReadOnly = false; dataUCV.Rows[e.RowIndex].Cells["KHOA"].ReadOnly = false; dataUCV.Rows[e.RowIndex].Cells["HOTEN"].Style.ForeColor = Color.Blue; dataUCV.Rows[e.RowIndex].Cells["NAMSINH"].Style.ForeColor = Color.Blue; dataUCV.Rows[e.RowIndex].Cells["CHUCVU"].Style.ForeColor = Color.Blue; dataUCV.Rows[e.RowIndex].Cells["KHOA"].Style.ForeColor = Color.Blue; dataUCV.Columns[e.ColumnIndex].Name = "UPDATE"; break; } case "UPDATE": { string hoten = dataUCV.Rows[e.RowIndex].Cells["HOTEN"].FormattedValue.ToString(); int namsinh = Int32.Parse(dataUCV.Rows[e.RowIndex].Cells["NAMSINH"].FormattedValue.ToString()); string chucvu = dataUCV.Rows[e.RowIndex].Cells["CHUCVU"].FormattedValue.ToString(); int khoa = Int32.Parse(dataUCV.Rows[e.RowIndex].Cells["KHOA"].FormattedValue.ToString()); string query = "UPDATE TESTADMIN.UNGCUVIEN SET HOTEN= '" + hoten + "',NAMSINH='" + namsinh + "',CHUCVU = '" + chucvu + "', KHOA = '" + khoa + "'WHERE MAUV = '" + ma_uv + "'"; try { OracleDataController.Update(query); } catch (Exception ex) { MessageBox.Show(ex.Message); } this.Load_UCV(); dataUCV.Columns[e.ColumnIndex].Name = "EDIT"; break; } default: break; } }
private void DataTheoDoi_CellContentClick(object sender, DataGridViewCellEventArgs e) { string ma_tl = dataTheoDoi.Rows[e.RowIndex].Cells["MA_THEODOI"].FormattedValue.ToString(); string name = dataTheoDoi.Columns[e.ColumnIndex].Name; switch (name) { case "DELETE_TD": { string query = "DELETE FROM TESTADMIN.THEODOI WHERE MA_THEODOI = '" + ma_tl + "'"; try { OracleDataController.Delete(query); } catch (Exception ex) { MessageBox.Show(ex.Message); } this.Load_TheoDoi(); break; } case "EDIT_TD": { dataTheoDoi.Rows[e.RowIndex].Cells["HOTEN_TD"].ReadOnly = false; dataTheoDoi.Rows[e.RowIndex].Cells["NAMSINH_TD"].ReadOnly = false; dataTheoDoi.Rows[e.RowIndex].Cells["GIOITINH_TD"].ReadOnly = false; dataTheoDoi.Rows[e.RowIndex].Cells["HOTEN_TD"].Style.ForeColor = Color.Blue; dataTheoDoi.Rows[e.RowIndex].Cells["NAMSINH_TD"].Style.ForeColor = Color.Blue; dataTheoDoi.Rows[e.RowIndex].Cells["GIOITINH_TD"].Style.ForeColor = Color.Blue; dataTheoDoi.Columns[e.ColumnIndex].Name = "UPDATE_TD"; break; } case "UPDATE_TD": { string hoten = dataTheoDoi.Rows[e.RowIndex].Cells["HOTEN_TD"].FormattedValue.ToString(); int namsinh = Int32.Parse(dataTheoDoi.Rows[e.RowIndex].Cells["NAMSINH_TD"].FormattedValue.ToString()); string gioitinh = dataTheoDoi.Rows[e.RowIndex].Cells["GIOITINH_TD"].FormattedValue.ToString(); string query = "UPDATE TESTADMIN.THEODOI SET HOTEN= '" + hoten + "',NAMSINH='" + namsinh + "',GIOITINH = '" + gioitinh + "'WHERE MA_THEODOI = '" + ma_tl + "'"; try { OracleDataController.Update(query); } catch (Exception ex) { MessageBox.Show(ex.Message); } this.Load_TheoDoi(); dataTheoDoi.Columns[e.ColumnIndex].Name = "EDIT_TD"; break; } default: break; } }