private void BtnLocationSub_Click(object sender, EventArgs e) { string username = tbUsername.Text; string password = tbPassword.Text; string role = cbRole.Text; string number = Convert.ToString(nubNumber.Value); string color = cbColor.Text; string beschikbaarheid = cbBeschikbaarheid.Text; // Genereerd aanmaaktijd. string timeAndDate = DateTime.Now.ToString("MM/dd/yyyy h:mm tt"); // Query voor het invoegen van waarden uit formulier. string insertQuery = "INSERT INTO account (account.username, account.password, account.rol, account.account_sinds) VALUES('" + username + "', '" + password + "', '" + role + "', '" + timeAndDate + "');" + "INSERT INTO administratie(administratie.account_id_account, administratie.appartmentnummer, administratie.kleur, beschikbaarheid)" + "VALUES(LAST_INSERT_ID(), '" + number + "', '" + color + "', '" + beschikbaarheid + "'); "; if (username == "" || password == "" || role == "" || number == "" || color == "") { MessageBox.Show("Controleer de gegevens, een of meerdere velden zijn niet juist ingevuld", "Onvolledige gegevens"); } else { conn.Open(); MySqlCommand insert = new MySqlCommand(insertQuery, conn); try { if (insert.ExecuteNonQuery() == 2) { dashboard.PopulateData(); //force refresh this.Close(); } else { MessageBox.Show("Data Not Inserted"); } } catch (Exception ex) { MessageBox.Show(ex.Message); } } }
private void BtnLocationSub_Click(object sender, EventArgs e) { // ID moet nog automatisch meegegeven worden van vorige actie (klik op bewerk in het dashboard) . string username = tbUsername.Text; string password = tbPassword.Text; string role = cbRole.Text; decimal number = nubNumber.Value; string color = cbColor.Text; string beschikbaarheid = cbBeschikbaarheid.Text; // string voor het vervangen van data voor specifieke ID string updateQuery = "UPDATE account, administratie " + " SET account.username = '******', account.password = '******', account.rol = '" + role + "',administratie.appartmentnummer = '" + number + "',administratie.kleur = '" + color + "',administratie.beschikbaarheid = '" + beschikbaarheid + "'" + "WHERE account.id_account = " + id + " AND administratie.account_id_account = " + id; conn.Open(); MySqlCommand update = new MySqlCommand(updateQuery, conn); try { if (update.ExecuteNonQuery() == 2) { dashboard.PopulateData(); //force refresh this.Close(); } else { MessageBox.Show("Data Not Inserted"); } } catch (Exception ex) { MessageBox.Show(ex.Message); } conn.Close(); }