Beispiel #1
0
        private bool validaCampos()
        {
            bool          _return = true;
            List <String> campos  = new List <string>();

            if (txtLogin.Text.Equals("") || txtLogin.Text == null)
            {
                campos.Add("Login");
            }
            if (txtNome.Text.Equals("") || txtNome.Text == null)
            {
                campos.Add("Nome");
            }
            if (txtSenha.Text.Equals("") || txtSenha.Text == null)
            {
                campos.Add("Senha");
            }
            if (txtConfirmaSenha.Text.Equals("") || txtConfirmaSenha.Text == null)
            {
                campos.Add("Confirmação da Senha");
            }
            if ((txtEmail.Text.Equals("") || txtEmail.Text == null) && chkEmail.Checked)
            {
                campos.Add("Email");
            }

            if (campos.Count > 0)
            {
                _return = false;
                FrmAlerta alerta = new FrmAlerta("Atenção! Alguns campos obrigatórios não foram informados: " + string.Join(", ", campos.ToArray()), usu_logado.usu_id);
                alerta.ShowDialog();
            }

            if (!txtSenha.Text.Equals(txtConfirmaSenha.Text))
            {
                _return = false;
                FrmAlerta alerta = new FrmAlerta("Atenção! O campo senha difere do campo de confirmação de senha!", usu_logado.usu_id);
                alerta.ShowDialog();
            }

            Usuario aux = new Usuario();

            if (aux.selectGenerico("count(usu_login)", "usu_login = '******'") != "0" && !editando)
            {
                _return = false;
                FrmAlerta alerta = new FrmAlerta("Atenção! Já existe um usuário cadastrado com esse login!", usu_logado.usu_id);
                alerta.ShowDialog();
            }

            return(_return);
        }
Beispiel #2
0
        private void btnSalvar_Click(object sender, EventArgs e)
        {
            if (validaCampos())
            {
                novoUsuario.usu_nome         = txtNome.Text;
                novoUsuario.usu_senha        = txtSenha.Text;
                novoUsuario.usu_senha        = txtConfirmaSenha.Text;
                novoUsuario.usu_email        = txtEmail.Text;
                novoUsuario.usu_login        = txtLogin.Text;
                novoUsuario.usu_ativo        = chkAtivo.Checked;
                novoUsuario.usu_enviaemail   = chkEmail.Checked;
                novoUsuario.CTAdicionar      = chkCTAdicionar.Checked;
                novoUsuario.CTAutoriaPropria = chkCTAutoriaPropria.Checked;
                novoUsuario.CTEditar         = chkCTEditar.Checked;
                novoUsuario.CTListar         = chkCTListar.Checked;
                novoUsuario.CTRemover        = chkCTRemover.Checked;
                novoUsuario.ExCTAbrir        = chkExCTAbrir.Checked;
                novoUsuario.ExCTIniFim       = chkExCTIniFim.Checked;
                novoUsuario.ExCTListar       = chkExCTListar.Checked;
                novoUsuario.ExCTOutrosUsu    = chkExCTOutrosUsu.Checked;
                novoUsuario.OutrasConfig     = chkOutrasConfig.Checked;
                novoUsuario.RevAdicionar     = chkRevAdicionar.Checked;
                novoUsuario.RevEditar        = chkRevEditar.Checked;
                novoUsuario.RevListar        = chkRevListar.Checked;
                novoUsuario.RevRemover       = chkRevRemover.Checked;
                novoUsuario.UsuAdicionar     = chkUsuAdicionar.Checked;
                novoUsuario.UsuEditar        = chkUsuEditar.Checked;
                novoUsuario.UsuListar        = chkUsuListar.Checked;
                novoUsuario.UsuPermissoes    = chkUsuPermissoes.Checked;
                novoUsuario.UsuRemover       = chkUsuRemover.Checked;

                if (!editando)
                {
                    novoUsuario.usu_dataCad     = DateTime.Parse(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"));
                    novoUsuario.usu_usuario_cad = usu_logado.usu_id;
                }
                novoUsuario.usu_dataAlteracao     = DateTime.Parse(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"));
                usu_logado.usu_terminal_alteracao = Environment.MachineName.ToString();

                if (editando ? novoUsuario.update() : novoUsuario.Salvar())
                {
                    FrmAlerta alerta = new FrmAlerta("Salvo com sucesso!", usu_logado.usu_id);
                    alerta.ShowDialog();
                    this.Close();
                }
            }
        }