private void btnCrea_Click(object sender, EventArgs e) { String error = validation(); if (error != null) { MessageBox.Show("Il campo " + error + " non è corretto", "Inserimento dati non valido", MessageBoxButtons.OK); return; } Utente utente; if (checkboxAmm.Checked) { utente = new Amministratore { Nome = inputNome.Text, Cognome = inputCognome.Text, Email = inputEmail.Text, LoginRemoto = checkboxLoginRemoto.Checked, Username = inputUsername.Text } } ; else { utente = new UtenteNormale { Nome = inputNome.Text, Cognome = inputCognome.Text, Email = inputEmail.Text, LoginRemoto = checkboxLoginRemoto.Checked, Username = inputUsername.Text } }; utente.ImpostaPasswordDaOriginale(inputPassword.Text); bool res = Controller.Registra(utente); if (res) { this.ParentForm.DialogResult = DialogResult.Abort; } else { this.ParentForm.DialogResult = DialogResult.OK; } }
public static void Update(Amministratore item) { StringBuilder sql = new StringBuilder("UPDATE TblAmministratori SET nome = @Nome WHERE id_amministratori = @IdAmministratori"); try { using (SqlConnection cn = GetConnection()) { cn.Execute(sql.ToString(), item); } } catch (Exception ex) { throw new Exception("Errore durante la Update in AmministratoriDAO", ex); } }
public static Amministratore GetSingle(long idAmministratore) { Amministratore ret = new Amministratore(); StringBuilder sql = new StringBuilder("SELECT * FROM TblAmministratori WHERE id_amministratori = @idAmministratore "); try { using (SqlConnection cn = GetConnection()) { ret = cn.Query <Amministratore>(sql.ToString(), new { idAmministratore }).FirstOrDefault(); } } catch (Exception ex) { throw new Exception("Errore durante la GetSingle in AmministratoriDAO", ex); } return(ret); }