private void pbxUserProfile_Click(object sender, EventArgs e) { UserProfileAllForm profile = new UserProfileAllForm(aux); profile.Show(); this.Close(); }
private void pbxSave_Click(object sender, EventArgs e) { SqlConnection sqlConnect = new SqlConnection(connectionString); //Save if (string.IsNullOrEmpty(lblId.Text)) { try { GetData(); UserProfile up = new UserProfile(name, active); sqlConnect.Open(); string sql = "INSERT INTO USER_PROFILE(NAME, ACTIVE) VALUES (@name, @active)"; SqlCommand cmd = new SqlCommand(sql, sqlConnect); cmd.Parameters.Add(new SqlParameter("@name", up.Name)); cmd.Parameters.Add(new SqlParameter("@active", up.Active)); cmd.ExecuteNonQuery(); MessageBox.Show("Adicionado com sucesso!"); Log.SaveLog(sqlConnect, "Perfil inserido", DateTime.Now, "Inserção"); CleanData(); } catch (Exception ex) { MessageBox.Show("Erro ao adicionar perfil!" + ex.Message); CleanData(); } finally { sqlConnect.Close(); } } //Edit else { try { GetData(); sqlConnect.Open(); string sql = "UPDATE USER_PROFILE(NAME, ACTIVE) VALUES (@name, @active) WHERE ID = @id"; SqlCommand cmd = new SqlCommand(sql, sqlConnect); cmd.Parameters.Add(new SqlParameter("@name", name)); cmd.Parameters.Add(new SqlParameter("@active", active)); cmd.Parameters.Add(new SqlParameter("@id", lblId.Text)); cmd.ExecuteNonQuery(); MessageBox.Show("Altereções salvas com sucesso!"); Log.SaveLog(sqlConnect, "Perfil editado", DateTime.Now, "Edição"); } catch (Exception Ex) { MessageBox.Show("Erro ao editar este perfil!" + "\n\n" + Ex.Message); throw; } finally { sqlConnect.Close(); UserProfileAllForm profile = new UserProfileAllForm(aux); profile.Show(); this.Close(); } } }