private void ModifyAssignmen(object sender, EventArgs e) { conn.Close(); Messages msg = new Messages(); conn.Open(); iin = TextIIN.Text; switch (sw) { case 0: sql = "SELECT COUNT(*) " + "FROM PERSON_HAS_ASSIGNMENT INNER JOIN ASSIGNMENT " + "ON PERSON_HAS_ASSIGNMENT.ASSIGNMENT_ID_ASSIGNMENT = ASSIGNMENT.ID_ASSIGNMENT " + "WHERE ASSIGNMENT.ASSIGNMENT_NAME = '" + CBSetAssign.Text + "'" + "AND PERSON_HAS_ASSIGNMENT.PERSON_PERSON_IIN = '" + iin + "'"; MySqlCommand check = new MySqlCommand(sql, conn); COUNT = Convert.ToInt32(check.ExecuteScalar()); if (COUNT == 0) { sql = "INSERT INTO PERSON_HAS_ASSIGNMENT (PERSON_PERSON_IIN, ASSIGNMENT_ID_ASSIGNMENT) " + "VALUES('" + iin + "', (SELECT ID_ASSIGNMENT FROM ASSIGNMENT " + "WHERE ASSIGNMENT_NAME = '" + CBSetAssign.Text + "'))"; MySqlCommand insert = new MySqlCommand(sql, conn); if (insert.ExecuteNonQuery() == 1) { msg.WriteSuccess(); conn.Close(); ChoosePanel.Visible = false; CBSetAssign.Items.Clear(); } else { msg.WriteError(); conn.Close(); } } else { msg.WriteError(); conn.Close(); } break; case 1: sql = "DELETE FROM PERSON_HAS_ASSIGNMENT " + "WHERE ASSIGNMENT_ID_ASSIGNMENT = (SELECT ID_ASSIGNMENT FROM ASSIGNMENT " + "WHERE ASSIGNMENT_NAME = '" + CBSetAssign.Text + "') " + "AND PERSON_PERSON_IIN = '" + iin + "'"; MySqlCommand del = new MySqlCommand(sql, conn); if (del.ExecuteNonQuery() == 1) { msg.DropSuccess(); conn.Close(); ChoosePanel.Visible = false; CBSetAssign.Items.Clear(); } else { msg.DropError(); conn.Close(); } break; } }