Example #1
0
        public void UPDATE(Clientes1 cliente)
        {
            try
            {
                SqlConnection conexao = new SqlConnection(caminhobd); //Cria uma variável de conexão com o BD

                conexao.Open();                                       //Abre a conexão

                string UPDATE = "update Clientes set Nome = '" + cliente.Nome +
                                "', Sobrenome = '" + cliente.Sobrenome +
                                "', Email = '" + cliente.Email +
                                "', Senha = '" + cliente.Senha +
                                "', CPF = '" + cliente.CPF +
                                "', DataNascimento = '" + cliente.DataNascimento +
                                "', Telefone = '" + cliente.Telefone +
                                "', Endereco = '" + cliente.Endereco +
                                "', Numero = '" + cliente.Numero +
                                "', Complemento ='" + cliente.Complemento +
                                "', Bairro = '" + cliente.Bairro +
                                "', CEP = '" + cliente.CEP +
                                "', Estado = '" + cliente.Estado +
                                "', Cidade = '" + cliente.Cidade +
                                "' where Id = '" + cliente.Id + "';";

                SqlCommand    cmd = new SqlCommand(UPDATE, conexao);
                SqlDataReader myreader;
                myreader = cmd.ExecuteReader();
                conexao.Close();
            }
            catch (Exception ex)
            {
                throw new Exception("Erro de comandos " + ex.Message);
            }
        }
Example #2
0
        string caminhobd = @"Data Source=(localdb)\MSSQLLocalDB;Initial Catalog=Market_bdo;Integrated Security=True;"; //salva na variável os dados do BD

        public void INSERT(Clientes1 cliente)
        {
            try
            {
                SqlConnection conexao = new SqlConnection(caminhobd);

                string INSERT = "insert into Clientes (Nome, " +
                                "Sobrenome, " +
                                "Email, " +
                                "Senha, " +
                                "CPF, " +
                                "DataNascimento, " +
                                "Telefone, " +
                                "Endereco, " +
                                "Numero, " +
                                "Complemento, " +
                                "Bairro, " +
                                "CEP, " +
                                "Estado, " +
                                "Cidade) " +
                                "values ('" + cliente.Nome +
                                "','" + cliente.Sobrenome +
                                "','" + cliente.Email +
                                "','" + cliente.Senha +
                                "','" + cliente.CPF +
                                "','" + cliente.DataNascimento +
                                "','" + cliente.Telefone +
                                "','" + cliente.Endereco +
                                "','" + cliente.Numero +
                                "','" + cliente.Complemento +
                                "','" + cliente.Bairro +
                                "','" + cliente.CEP +
                                "','" + cliente.Estado +
                                "','" + cliente.Cidade +
                                "')";

                conexao.Open();

                var cmd = new SqlCommand(INSERT, conexao);

                SqlDataReader myreader;

                myreader = cmd.ExecuteReader();

                conexao.Close();
            }
            catch (Exception ex)
            {
                throw new Exception("Erro de comandos " + ex.Message);
            }
        }
Example #3
0
        private void btnSalvar_Click(object sender, EventArgs e)
        {
            Validacao val     = new Validacao();
            Clientes1 cliente = new Clientes1();
            DAO       dao     = new DAO();

            string validacao = (val.ValidarCamposPessoais(txtNome.Text, txtSobrenome.Text, txtEmail.Text, txtCPF.Text, txtDataNascimento.Text, txtSenha.Text, txtConfirmarSenha.Text));

            try
            {
                if (validacao == "")
                {
                    if ((val.ValidarCamposEndereco(txtEndereco.Text, txtNumero.Text, txtBairro.Text, txtCEP.Text, txtEstado.Text, txtCidade.Text)) == "")
                    {
                        cliente.Id             = Convert.ToInt16(txtCodigo.Text);
                        cliente.Nome           = txtNome.Text;
                        cliente.Sobrenome      = txtSobrenome.Text;
                        cliente.Email          = txtEmail.Text;
                        cliente.Senha          = txtSenha.Text;
                        cliente.CPF            = txtCPF.Text;
                        cliente.DataNascimento = txtDataNascimento.Text;
                        cliente.Telefone       = txtTelefone.Text;
                        cliente.Endereco       = txtEndereco.Text;
                        cliente.Numero         = Convert.ToInt32(txtNumero.Text);
                        cliente.Complemento    = txtComplemento.Text;
                        cliente.Bairro         = txtBairro.Text;
                        cliente.CEP            = txtCEP.Text;
                        cliente.Estado         = txtEstado.Text;
                        cliente.Cidade         = txtCidade.Text;


                        dao.UPDATE(cliente);

                        MessageBox.Show("Cliente alterado com sucesso !");

                        Limpar();
                        tabControl1.SelectedIndex = 0;
                        btnPesquisar.PerformClick();
                    }
                }
                else
                {
                    MessageBox.Show(validacao);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
        private void btnSalvar_Click(object sender, EventArgs e)
        {
            Validacao val     = new Validacao();
            Login     log     = new Login();
            Clientes1 cliente = new Clientes1();
            DAO       dao     = new DAO();

            try
            {
                string validacao = (val.ValidarCamposPessoais(txtNome.Text, txtSobrenome.Text, txtEmail.Text, txtCPF.Text, txtDataNascimento.Text, txtSenha.Text, txtConfirmarSenha.Text));


                if (validacao == "")
                {
                    if ((val.ValidarCamposEndereco(txtEndereco.Text, txtNumero.Text, txtBairro.Text, txtCEP.Text, txtEstado.Text, txtCidade.Text)) == "")
                    {
                        cliente.Nome           = txtNome.Text;
                        cliente.Sobrenome      = txtSobrenome.Text;
                        cliente.Email          = txtEmail.Text;
                        cliente.Senha          = txtSenha.Text;
                        cliente.CPF            = txtCPF.Text;
                        cliente.DataNascimento = txtDataNascimento.Text;
                        cliente.Telefone       = txtTelefone.Text;
                        cliente.Endereco       = txtEndereco.Text;
                        cliente.Numero         = Convert.ToInt32(txtNumero.Text);
                        cliente.Complemento    = txtComplemento.Text;
                        cliente.Bairro         = txtBairro.Text;
                        cliente.CEP            = txtCEP.Text;
                        cliente.Estado         = txtEstado.Text;
                        cliente.Cidade         = txtCidade.Text;

                        dao.INSERT(cliente);
                        MessageBox.Show("Cliente cadastrado com sucesso !");
                        log.Show();
                        this.Hide();
                    }
                }
                else
                {
                    MessageBox.Show(validacao);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
Example #5
0
        private void btnExcluir_Click(object sender, EventArgs e)
        {
            if ((MessageBox.Show("Todos os dados deste cliente serão excluidos, deseja realmente continuar ? ", "", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes))
            {
                Clientes1 cliente = new Clientes1();
                DAO       dao     = new DAO();

                cliente.Id = Convert.ToInt16(txtCodigo.Text);

                dao.DELETE(cliente);

                MessageBox.Show("Cliente excluido com sucesso !");

                Limpar();

                tabControl1.SelectedIndex = 0;

                btnPesquisar.PerformClick();
            }
        }
Example #6
0
        public void DELETE(Clientes1 cliente)
        {
            try
            {
                SqlConnection conexao = new SqlConnection(caminhobd); //Cria uma variável de conexão com o BD

                conexao.Open();                                       //Abre a conexão

                string DELETE = "delete from Clientes where Id = '" + cliente.Id + "';";

                SqlCommand    cmd = new SqlCommand(DELETE, conexao);
                SqlDataReader myreader;
                myreader = cmd.ExecuteReader();
                conexao.Close();
            }
            catch (Exception ex)
            {
                throw new Exception("Erro de comandos " + ex.Message);
            }
        }
Example #7
0
        public void SELECT(Clientes1 cliente)
        {
            try
            {
                string        caminhobd = @"Data Source=(localdb)\MSSQLLocalDB;Initial Catalog= Market_bdo;Integrated Security=True;";
                SqlConnection conexao   = new SqlConnection(caminhobd);
                string        SELECT    = "select CPF, Senha from Clientes where CPF =@CPF and Senha =@Senha";

                conexao.Open();
                var cmd = new SqlCommand(SELECT, conexao);

                SqlDataReader myreader;

                myreader = cmd.ExecuteReader();

                conexao.Close();
            }
            catch (Exception ex)
            {
                throw new Exception("Erro de comandos " + ex.Message);
            }
        }