private void completaSQL() { ClassControl.conectar(); try { string sql = "SELECT c.nome_cliente,c.email_cliente,c.username_cliente, c.estado_cliente FROM cliente AS c"; NpgsqlCommand cmd = new NpgsqlCommand(); cmd.CommandText = sql; cmd.Connection = ClassControl.cn; NpgsqlDataReader dr_myAccount = cmd.ExecuteReader(); if (dr_myAccount.Read()) { txtContaNome.Text = dr_myAccount[0].ToString(); txtContaEmail.Text = dr_myAccount[1].ToString(); txtContaUsername.Text = dr_myAccount[2].ToString(); txtContaEstado.Text = dr_myAccount[3].ToString(); } } catch (NpgsqlException Ex) { throw new ApplicationException(Ex.Message); } finally { ClassControl.desconectar(); } }
private void btnCadCadastrar_Click(object sender, EventArgs e) { ClassControl.conectar(); if (txtCadPwd.Text == txtCadConfirmPwd.Text) { NpgsqlCommand cmd = new NpgsqlCommand(); cmd.Parameters.AddWithValue("@NameUser", txtCadNome.Text); cmd.Parameters.AddWithValue("@Username", txtCadUsername.Text); cmd.Parameters.AddWithValue("@email", txtCadEmail.Text); cmd.Parameters.AddWithValue("@UserLivingState", cmbCadEstado.SelectedItem); cmd.Parameters.AddWithValue("@userpwd", txtCadConfirmPwd.Text); try { string sql = "SELECT * FROM cliente WHERE email_cliente = @email OR username_cliente = @Username"; cmd.CommandText = sql; cmd.Connection = ClassControl.cn; NpgsqlDataReader dr = cmd.ExecuteReader(); bool Selected = dr.HasRows; if (Selected) { MessageBox.Show("Username ou Email já em uso", "", MessageBoxButtons.OK, MessageBoxIcon.Information); } else { try { dr.Close(); sql = "INSERT INTO CLIENTE(nome_cliente, email_cliente, username_cliente, estado_cliente, senha_cliente)" + " VALUES(@NameUser, @email, @Username, @UserLivingState, @userpwd)"; cmd.CommandText = sql; cmd.Connection = ClassControl.cn; int rows = cmd.ExecuteNonQuery(); if (rows > 0) { MessageBox.Show("Cadastro realizado com sucesso", "", MessageBoxButtons.OK, MessageBoxIcon.Information); } } catch (NpgsqlException ex) { throw new ApplicationException(ex.Message); } } } catch (NpgsqlException sqlError) { throw new ApplicationException(sqlError.Message); } finally { ClassControl.desconectar(); } } else { MessageBox.Show("As senhas não conferem", "Senhas não conferem", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } }
private void btnLogin_Click(object sender, EventArgs e) { NpgsqlCommand cmd = new NpgsqlCommand(); cmd.Parameters.AddWithValue("@EmailOrUser", txtLoginUsername.Text); cmd.Parameters.AddWithValue("@LoginPwd", txtLoginSenha.Text); try { ClassControl.conectar(); string sqlLogin = "******" + "WHERE (email_admin = @EmailOrUser OR user_admin = @EmailOrUser) AND senha_admin = @LoginPwd"; cmd.CommandText = sqlLogin; cmd.Connection = ClassControl.cn; NpgsqlDataReader dr = cmd.ExecuteReader(); bool IsAdmin = dr.HasRows; if (IsAdmin) { ClassControl.desconectar(); this.Hide(); frmMenuAdmin formAdmin = new frmMenuAdmin(); formAdmin.Show(); } else { dr.Close(); sqlLogin = "******" + "WHERE (email_cliente = @EmailOrUser OR username_cliente = @EmailOrUser) AND senha_cliente = @LoginPwd"; cmd.CommandText = sqlLogin; cmd.Connection = ClassControl.cn; dr = cmd.ExecuteReader(); bool logged = dr.HasRows; if (logged) { ClassControl.desconectar(); MessageBox.Show("Login efetuado com sucesso!", "", MessageBoxButtons.OK, MessageBoxIcon.Information); this.Hide(); frmMenuUser formMenuUsuario = new frmMenuUser(txtLoginUsername.Text); formMenuUsuario.ShowDialog(); this.Activate(); this.Show(); } else { if (txtLoginUsername.Text != "admin" && txtLoginSenha.Text != "admin") { MessageBox.Show("Credencias erradas ou usuário inesistente", "Login Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } ClassControl.desconectar(); } } } catch (NpgsqlException ex) { throw new ApplicationException(ex.Message); } }
private void btnCadCadastrarAdmin_Click(object sender, EventArgs e) { ClassControl.conectar(); if (txtCadPwdAdmin.Text == txtCadConfirmPwdAdmin.Text) { NpgsqlCommand cmd = new NpgsqlCommand(); cmd.Parameters.AddWithValue("@NomeAdmin", txtCadNomeAdmin.Text); cmd.Parameters.AddWithValue("@UserAdmin", txtCadUsernameAdmin.Text); cmd.Parameters.AddWithValue("@EmailAdmin", txtCadEmailAdmin.Text); cmd.Parameters.AddWithValue("@PwdAdmin", txtCadPwdAdmin.Text); try { string sql = "SELECT * FROM admin WHERE user_admin=@UserAdmin OR email_admin=@EmailAdmin"; cmd.CommandText = sql; cmd.Connection = ClassControl.cn; NpgsqlDataReader dr = cmd.ExecuteReader(); bool AdminAlreadyExists = dr.HasRows; if (AdminAlreadyExists) { MessageBox.Show("Username ou Email Já cadastrados no sistema!!!", "", MessageBoxButtons.OK, MessageBoxIcon.Information); } else { dr.Close(); sql = "INSERT INTO admin(nome_admin, user_admin, email_admin, senha_admin) " + "VALUES (@NomeAdmin,@UserAdmin,@EmailAdmin,@PwdAdmin)"; try { cmd.CommandText = sql; cmd.Connection = ClassControl.cn; int rows = cmd.ExecuteNonQuery(); if (rows > 0) { MessageBox.Show("Administrador Cadastrado com sucesso!!!", "", MessageBoxButtons.OK, MessageBoxIcon.Information); } } catch (NpgsqlException ex) { throw new ApplicationException(ex.Message); } } }catch (NpgsqlException ex) { throw new ApplicationException(ex.Message); } finally { ClassControl.desconectar(); } } else { MessageBox.Show("Senhas não conferem", "", MessageBoxButtons.OK, MessageBoxIcon.Information); } }
private void btnCadCadastrarFilme_Click(object sender, EventArgs e) { ClassControl.conectar(); NpgsqlCommand cmd = new NpgsqlCommand(); cmd.Parameters.AddWithValue("@NomeFilme", txtNomeFilme.Text); cmd.Parameters.AddWithValue("@DescricaoFilme", txtDescricaoFilme.Text); cmd.Parameters.AddWithValue("@AnoFilme", Convert.ToInt32(mskAnoFilme.Text)); cmd.Parameters.AddWithValue("@GenFilme", cmbGeneroFilme.SelectedItem); cmd.Connection = ClassControl.cn; try { string sql = "SELECT * FROM filmes WHERE titulo_filme = @NomeFilme"; cmd.CommandText = sql; NpgsqlDataReader dr = cmd.ExecuteReader(); if (dr.HasRows) { MessageBox.Show("Filme já cadastrado", "", MessageBoxButtons.OK, MessageBoxIcon.Information); } else { dr.Close(); NpgsqlDataReader dr2; string sql2 = "SELECT id_genero FROM genero WHERE nome_gen = @GenFilme"; cmd.CommandText = sql2; dr2 = cmd.ExecuteReader(); if (dr2.Read()) { int id_gen = Convert.ToInt32(dr2["id_genero"]); cmd.Parameters.AddWithValue("@idGenFilme", id_gen); } dr2.Close(); sql = "INSERT INTO filmes(titulo_filme,descricao_filme, ano_filme, id_genero)" + " VALUES(@NomeFilme, @DescricaoFilme, @AnoFilme, @idGenFilme)"; cmd.CommandText = sql; int rows = cmd.ExecuteNonQuery(); if (rows > 0) { MessageBox.Show("Filme adicionado com sucesso", "", MessageBoxButtons.OK, MessageBoxIcon.Information); } } } catch (NpgsqlException ex) { throw new ApplicationException(ex.Message); } finally { ClassControl.desconectar(); } }
private void btnCadastrarGen_Click(object sender, EventArgs e) { ClassControl.conectar(); NpgsqlCommand cmd = new NpgsqlCommand(); cmd.Parameters.AddWithValue("@GenFilme", txtGenFilme.Text); cmd.Connection = ClassControl.cn; try { string sql = "SELECT * FROM genero WHERE nome_gen = @GenFilme"; cmd.CommandText = sql; NpgsqlDataReader dr = cmd.ExecuteReader(); bool GenRegistred = dr.HasRows; if (GenRegistred) { MessageBox.Show("Genero já cadastrado", "", MessageBoxButtons.OK, MessageBoxIcon.Information); } else { try { dr.Close(); sql = "INSERT INTO genero(nome_gen) VALUES(@GenFilme)"; cmd.CommandText = sql; int Registrou = cmd.ExecuteNonQuery(); if (Registrou > 0) { MessageBox.Show("Genero cadastrado com sucesso!", "", MessageBoxButtons.OK, MessageBoxIcon.Information); } }catch (NpgsqlException ex) { throw new ApplicationException(ex.Message); } } }catch (NpgsqlException ex) { throw new ApplicationException(ex.Message); } finally { ClassControl.desconectar(); } }
private void CarregaComboBoxGen() { ClassControl.conectar(); string sql = "SELECT COUNT(*) FROM genero"; NpgsqlCommand cmd = new NpgsqlCommand(sql, ClassControl.cn); sql = "SELECT nome_gen FROM genero"; cmd.CommandText = sql; NpgsqlDataReader dr = cmd.ExecuteReader(); if (dr.HasRows) { cmbGeneros.Items.Add("---"); while (dr.Read()) { for (int i = 0; i < dr.FieldCount; i++) { cmbGeneros.Items.Add(dr.GetString(i)); } } } dr.Close(); }
private void frmCadFilmes_Load(object sender, EventArgs e) { ClassControl.conectar(); string sql = "SELECT COUNT(*) FROM genero"; NpgsqlCommand cmd = new NpgsqlCommand(sql, ClassControl.cn); sql = "SELECT nome_gen FROM genero"; cmd.CommandText = sql; NpgsqlDataReader dr = cmd.ExecuteReader(); if (dr.HasRows) { cmbGeneroFilme.Items.Add("---"); while (dr.Read()) { for (int i = 0; i < dr.FieldCount; i++) { cmbGeneroFilme.Items.Add(dr.GetString(i)); } } } dr.Close(); //MessageBox.Show(count.ToString(), "", MessageBoxButtons.OK, MessageBoxIcon.Error); }