示例#1
0
 public void LimpaDados()
 {
     TxtIdUsuario.Clear();
     TxtNome.Clear();
     CboTipoUsuario.Text = "Selecione";
     TxtEmail.Clear();
     TxtUsuario.Clear();
     TxtSenha.Clear();
     TxtRepeteSenha.Clear();
     CboCadPor.Text       = "Selecione";
     BtnCadastrar.Enabled = true;
     CboCadPor.Enabled    = true;
 }
示例#2
0
 private void BtnCadastrar_Click(object sender, EventArgs e)
 {
     if (TxtNome.Text == "")
     {
         MessageBox.Show("Preencher Nome Completo!", "SIG", MessageBoxButtons.OK, MessageBoxIcon.Warning);
         TxtNome.Focus();
     }
     else if (TxtEmail.Text == "")
     {
         MessageBox.Show("Preencher E-mail!", "SIG", MessageBoxButtons.OK, MessageBoxIcon.Warning);
         TxtEmail.Focus();
     }
     else if (TxtUsuario.Text == "")
     {
         MessageBox.Show("Preencher Usuário!", "SIG", MessageBoxButtons.OK, MessageBoxIcon.Warning);
         TxtUsuario.Focus();
     }
     else if (TxtSenha.Text == "")
     {
         MessageBox.Show("Preencher Senha!", "SIG", MessageBoxButtons.OK, MessageBoxIcon.Warning);
         TxtSenha.Focus();
     }
     else if (TxtRepeteSenha.Text == "")
     {
         MessageBox.Show("Repita a Senha!", "SIG", MessageBoxButtons.OK, MessageBoxIcon.Warning);
         TxtRepeteSenha.Focus();
     }
     else if (CboTipoUsuario.Text == "Selecione")
     {
         MessageBox.Show("Selecione o Tipo de Usuário!", "SIG", MessageBoxButtons.OK, MessageBoxIcon.Warning);
         CboTipoUsuario.Focus();
     }
     else if (CboCadPor.Text == "Selecione")
     {
         MessageBox.Show("Selecione Usuário que está realizando a Operação!", "SIG", MessageBoxButtons.OK, MessageBoxIcon.Warning);
         CboCadPor.Focus();
     }
     else if (TxtSenha.Text != TxtRepeteSenha.Text)
     {
         MessageBox.Show("Senhas Não Conferem! Digite Novamente", "SIG", MessageBoxButtons.OK, MessageBoxIcon.Warning);
         TxtSenha.Text       = "";
         TxtRepeteSenha.Text = "";
         TxtSenha.Focus();
     }
     else
     {
         conn.Open();
         try
         {
             SqlCommand comando = new SqlCommand
             {
                 CommandType = CommandType.Text,
                 CommandText = "INSERT INTO Usuario(Nome,Email,Usuario,Senha,Tipo,Id_User,DataCad) VALUES ('" + TxtNome.Text + "','" + TxtEmail.Text + "','" + TxtUsuario.Text + "','" + TxtSenha.Text + "','" + CboTipoUsuario.Text + "',(select id_usuario from usuario where usuario.usuario='" + CboCadPor.Text + "'),'" + DateTime.Now + "')",
                 Connection  = conn
             };
             comando.ExecuteNonQuery();
             MessageBox.Show("Usuário Cadastrado com Sucesso!!", "SIG", MessageBoxButtons.OK, MessageBoxIcon.Information);
         }
         catch
         {
             MessageBox.Show("Erro ao Cadastrar Usuário! Tente Novamente.", "SIG", MessageBoxButtons.OK, MessageBoxIcon.Error);
         }
         conn.Close();
         LimpaDados();
     }
 }