Beispiel #1
0
        private void pbxBack_Click(object sender, EventArgs e)
        {
            UserAllForm uaf = new UserAllForm(aux);

            uaf.Show();
            this.Close();
        }
        private void pbxBack_Click(object sender, EventArgs e)
        {
            UserAllForm ua = new UserAllForm();

            ua.Show();
            this.Hide();
        }
Beispiel #3
0
        private void pbxDelete_Click(object sender, EventArgs e)
        {
            if (!string.IsNullOrEmpty(lblId.Text))
            {
                SqlConnection sqlConnect = new SqlConnection(connectionString);

                try
                {
                    sqlConnect.Open();
                    string sql = "UPDATE USER SET ACTIVE = @active WHERE ID = @id";

                    SqlCommand cmd = new SqlCommand(sql, sqlConnect);

                    cmd.Parameters.Add(new SqlParameter("@id", lblId.Text));
                    cmd.Parameters.Add(new SqlParameter("@active", false));

                    cmd.ExecuteNonQuery();

                    Log.SaveLog("Usuário Excluído", "Exclusão", DateTime.Now);

                    MessageBox.Show("Usuário inativo!");
                    UserAllForm uaf = new UserAllForm(aux);
                    uaf.Show();
                    this.Close();
                }
                catch (Exception Ex)
                {
                    MessageBox.Show("Erro ao desativar este usuário!" + "\n\n" + Ex.Message);
                    throw;
                }
                finally
                {
                    sqlConnect.Close();
                }
            }
        }
Beispiel #4
0
        private void pbxSave_Click(object sender, EventArgs e)
        {
            if (tbxConfPassword.Text == tbxConfPassword.Text)
            {
                if (string.IsNullOrEmpty(lblId.Text))
                {
                    SqlConnection sqlConnect = new SqlConnection(connectionString);
                    try
                    {
                        GetData();
                        if (confPassword == password)
                        {
                            sqlConnect.Open();
                            string sql = "INSERT INTO [USER](NAME, PASSWORD, EMAIL, ACTIVE, FK_USERPROFILE) VALUES (@name, @password, @email, @active, @fk_profile)";

                            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("@fk_profile", ((UserProfile)cmbProfile.SelectedItem).Id));
                            cmd.ExecuteNonQuery();

                            MessageBox.Show("Adicionado com sucesso!");
                            Log.SaveLog("Usuário Adicionado", "Adição", DateTime.Now);
                            CleanData();
                        }
                        else
                        {
                            MessageBox.Show("Senhas não coincidem!");
                        }
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show("Erro ao adicionar usuário!" + ex.Message);
                        CleanData();
                    }
                    finally
                    {
                        sqlConnect.Close();
                    }
                }
                else
                {
                    SqlConnection sqlConnect = new SqlConnection(connectionString);

                    try
                    {
                        GetData();

                        sqlConnect.Open();
                        string sql = "UPDATE [USER] SET NAME = @name, PASSWORD = @password, EMAIL = @email, ACTIVE = @active, FK_USERPROFILE = @fk_profile Where ID = @id ";

                        SqlCommand cmd = new SqlCommand(sql, sqlConnect);

                        cmd.Parameters.Add(new SqlParameter("@id", this.lblId.Text));
                        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("@fk_profile", ((UserProfile)cmbProfile.SelectedItem).Id));


                        cmd.ExecuteNonQuery();

                        MessageBox.Show("Altereções salvas com sucesso!");
                    }
                    catch (Exception Ex)
                    {
                        MessageBox.Show("Erro ao editar este usuário!" + "\n\n" + Ex.Message);
                        throw;
                    }
                    finally
                    {
                        sqlConnect.Close();

                        UserAllForm uaf = new UserAllForm(aux);
                        uaf.Show();
                        this.Close();
                    }
                }
            }
            else
            {
                MessageBox.Show("As senhas informadas não coincidem!");
            }
        }
        private void pbxSave_Click(object sender, EventArgs e)
        {
            SqlConnection sqlConnect = new SqlConnection(connectionString);

            if (string.IsNullOrEmpty(lblId.Text))
            {
                try
                {
                    GetData();
                    if (password == confirmpassword)
                    {
                        //Conectar
                        sqlConnect.Open();
                        string sql = "INSERT INTO [USER](NAME,PASSWORD, EMAIL, ACTIVE, FK_USERPROFILE) VALUES (@name,@password,@email, @active,@userprofile)";

                        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("@userprofile", ((UserProfile)cmbProfile.SelectedItem).Id));
                        cmd.ExecuteNonQuery();

                        MessageBox.Show("Adicionado com sucesso!");
                        Log.SalvarLog("Usuário adicionado", "Adição", DateTime.Now);
                    }
                    else
                    {
                        MessageBox.Show("Senhas não coincidem");
                    }
                }
                catch (Exception ex)
                {
                    //Tratar exceções
                    MessageBox.Show("Erro ao adicionar usuário!" + ex.Message);
                    CleanData();
                }
                finally
                {
                    //Fechar
                    sqlConnect.Close();
                }
            }
            else
            {
                try
                {
                    if (this.tbxPass.Text == this.tbxPassConfirm.Text)
                    {
                        sqlConnect.Open();
                        string sql = "UPDATE [USER] SET NAME = @name,PASSWORD =@password,EMAIL = @email, ACTIVE = @active, FK_USERPROFILE = @userprofile WHERE ID= @id";

                        SqlCommand cmd = new SqlCommand(sql, sqlConnect);

                        cmd.Parameters.Add(new SqlParameter("@id", this.lblId.Text));
                        cmd.Parameters.Add(new SqlParameter("@name", this.tbxName.Text));
                        cmd.Parameters.Add(new SqlParameter("@password", UserHelper.Hash(this.tbxPass.Text)));
                        cmd.Parameters.Add(new SqlParameter("@email", this.tbxEmail.Text));
                        cmd.Parameters.Add(new SqlParameter("@active", this.cbxActive.Checked));
                        cmd.Parameters.Add(new SqlParameter("@userprofile", ((UserProfile)cmbProfile.SelectedItem).Id));

                        cmd.ExecuteNonQuery();

                        MessageBox.Show("Altereções salvas com sucesso!");
                        Log.SalvarLog("Usuário editado", "Edição", DateTime.Now);
                    }
                    else
                    {
                        MessageBox.Show("Senhas não coincidem");
                    }
                }
                catch (Exception Ex)
                {
                    MessageBox.Show("Erro ao editar esta categoria!" + "\n\n" + Ex.Message);
                    throw;
                }
                finally
                {
                    sqlConnect.Close();

                    UserAllForm ua = new UserAllForm();
                    ua.Show();
                    this.Hide();
                }
            }
        }