-
Notifications
You must be signed in to change notification settings - Fork 0
/
Conexao.cs
63 lines (52 loc) · 1.76 KB
/
Conexao.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
namespace $safeprojectname$
/* Classe Responsável pela conexão com o banco de dados */
{
public class Conexao
{
private SqlConnection Conection;
private DataSet DSet;
string conec = "Data Source=LOCALHOST;Initial Catalog=$safeprojectname$;User ID=Cledson;Password=151185;Language=Portuguese";
// abro a conexão no construtor e os métodos ficam encarregados de fecha-la .
public Conexao()
{
Conection = new SqlConnection(conec);
try
{
//abre a conexao
Conection.Open();
}
catch (System.Exception ex)
{
Console.WriteLine(ex.Message.ToString());
}
}
// Cadastra usuário no banco
public bool cadastraUsuario(Usuario usuario)
{
// Verifica se a conexão esta aberta
if (Conection.State == ConnectionState.Open)
{
Criptografia c = new Criptografia();
String senha = c.AcertaSenha(usuario.Senha);
//Query SQL
SqlCommand command = new SqlCommand("INSERT INTO usuario (email,nome,sobrenome,senha)" +
"VALUES('" + usuario.Email + "','" + usuario.Nome + "','" + usuario.Sobrenome + "','" + senha + "')", Conection);
//Executa a Query SQL
command.ExecuteNonQuery();
// Fecha a conexão
Conection.Close();
return true;
}
else
{
return false;
}
}
}
}