private void pbxBack_Click(object sender, EventArgs e) { UserAllForm udf = new UserAllForm(aux); udf.Show(); this.Close(); }
private void pbxUser_Click(object sender, EventArgs e) { UserAllForm uaf = new UserAllForm(aux); uaf.Show(); this.Hide(); }
private void pbxSave_Click(object sender, EventArgs e) { SqlConnection sqlConnect = new SqlConnection(connectionString); if (string.IsNullOrEmpty(lblID.Text)) //----- { try { GetData(); UserProfile up = (UserProfile)cmbProfile.SelectedItem; User u = new User(name, password, email, up, active); sqlConnect.Open(); string sql = "INSERT INTO [USER](NAME, PASSWORD, EMAIL, ACTIVE, FK_USERPROFILE) VALUES (@name, @password, @email, @active, @user)"; SqlCommand cmd = new SqlCommand(sql, sqlConnect); cmd.Parameters.Add(new SqlParameter("@name", u.Name)); cmd.Parameters.Add(new SqlParameter("@password", UserHelper.Hash(u.Password))); cmd.Parameters.Add(new SqlParameter("@email", u.Email)); cmd.Parameters.Add(new SqlParameter("@active", u.Active)); cmd.Parameters.Add(new SqlParameter("@user", u.UserProfile.Id)); cmd.ExecuteNonQuery(); MessageBox.Show("Adicionado com sucesso!"); Log.SaveLog(sqlConnect, "Usuário Inserido", DateTime.Now, "Inserção"); CleanData(); } catch (Exception ex) { MessageBox.Show("Erro ao adicionar usuario!" + ex.Message); CleanData(); } finally { sqlConnect.Close(); } } else { try { GetData(); UserProfile up = (UserProfile)cmbProfile.SelectedItem; sqlConnect.Open(); string sql = "UPDATE [USER](NAME, PASSWORD, EMAIL, ACTIVE, FK_USERPROFILE) VALUES (@name, @password, @email, @active, @user) WHERE ID = @id"; SqlCommand cmd = new SqlCommand(sql, sqlConnect); cmd.Parameters.Add(new SqlParameter("@name", name)); cmd.Parameters.Add(new SqlParameter("@password", UserHelper.Hash(password))); cmd.Parameters.Add(new SqlParameter("@email", email)); cmd.Parameters.Add(new SqlParameter("@active", active)); cmd.Parameters.Add(new SqlParameter("@user", up.Id)); cmd.Parameters.Add(new SqlParameter("@id", lblID.Text)); cmd.ExecuteNonQuery(); MessageBox.Show("Altereções salvas com sucesso!"); Log.SaveLog(sqlConnect, "Usuário Editado", DateTime.Now, "Edição"); } catch (Exception Ex) { MessageBox.Show("Erro ao editar este usuário!" + "\n\n" + Ex.Message); throw; } finally { sqlConnect.Close(); UserAllForm mainForm = new UserAllForm(aux); mainForm.Show(); this.Hide(); } } }