Exemplo n.º 1
0
        private void BTN_CONF_Click(object sender, EventArgs e)
        {
            DataBaseConnection bd = new DataBaseConnection();

            bd.openConnection();



            String nome  = textBox1.Text;
            String cpf   = Validador.FormataCpfAndRg(CPF_CLIE.Text);
            String tel   = Validador.FormataTelAndCel(TEL_CLIE.Text);
            String cel   = Validador.FormataTelAndCel(CEL_CLIE.Text);
            float  saldo = 1000;


            if ((Validador.campoPreenchido(cpf) &&
                 Validador.campoPreenchido(nome) &&
                 Validador.campoPreenchido(tel)) ||
                (Validador.campoPreenchido(cpf) &&
                 Validador.campoPreenchido(nome) &&
                 Validador.campoPreenchido(cel)))



            {
                String query = "INSERT INTO CLIENTE " +
                               "(CPF_CLIENTE, NOME_CLIENTE, TELEFONE_CLIENTE, CEL_CLIENTE, SALDO_ATUAL_CLIENTE)" +
                               " VALUES ('" + cpf + "','" + nome + "','" + tel + "','" + cel + "','" + saldo + "')";

                //MessageBox.Show(query);

                MySqlCommand cmd = new MySqlCommand(query, bd.retornaConexao());
                cmd.ExecuteNonQuery();
                System.Windows.Forms.MessageBox.Show("Cliente cadastrado com sucesso");

                this.Close();
            }

            else
            {
                MessageBox.Show("Preencha os campos obrigatorios");
            }


            bd.closeConnection();
        }
Exemplo n.º 2
0
        private void BTN_CONF_Click(object sender, EventArgs e)
        {
            DataBaseConnection bd = new DataBaseConnection();

            bd.openConnection();

            String nome = TXT_NOME_CLIENTE.Text;
            String cpf  = Validador.FormataCpfAndRg(TXT_CPF_CLIENTE.Text);
            String tel  = Validador.FormataTelAndCel(TXT_TEL_CLIENTE.Text);
            String cel  = Validador.FormataTelAndCel(TXT_CEL_CLIENTE.Text);

            cpfAnterior = Validador.FormataCpfAndRg(cpfAnterior);

            String query = "UPDATE cliente SET " +
                           "NOME_CLIENTE = '" + nome +
                           "', CPF_CLIENTE = '" + cpfAnterior +
                           "', TELEFONE_CLIENTE = '" + tel +
                           "', CEL_CLIENTE = '" + cel +
                           "' WHERE CPF_CLIENTE = " + cpfAnterior;


            if (Validador.campoPreenchido(nome))
            {
                MySqlCommand cmd = new MySqlCommand(query, bd.retornaConexao());
                try
                {
                    int numRowAfetada = cmd.ExecuteNonQuery();
                    if (numRowAfetada > 0)
                    {
                        System.Windows.Forms.MessageBox.Show("DADOS ALTERADOS COM SUCESSO");
                        this.Hide();
                    }
                }
                catch (MySqlException ex)
                {
                    MessageBox.Show(ex.ToString());
                    System.Windows.Forms.MessageBox.Show("ERRO NA ALTERAÇÃO");
                }
            }
            else
            {
                MessageBox.Show("PREENCHA OS CAMPOS OBRIGATÓRIOS");
            }

            bd.closeConnection();
        }
Exemplo n.º 3
0
 //Mesma ideia do consultar user
 private void botaoConsultar(object sender, EventArgs e)
 {
     cpf = Validador.FormataCpfAndRg(TXT_CPF_CLIENTE.Text);
     if (cpf.Equals(""))
     {
         MessageBox.Show("DIGITE O CPF");
     }
     else
     {
         DataBaseConnection bd = new DataBaseConnection();
         bd.openConnection();
         string          Query  = "SELECT * FROM CLIENTE WHERE CPF_CLIENTE = '" + this.cpf + "'";
         MySqlCommand    cmd    = new MySqlCommand(Query, bd.retornaConexao());
         MySqlDataReader reader = cmd.ExecuteReader();
         if (!reader.HasRows)
         {
             MessageBox.Show("Usúario não existe.");
         }
         else
         {
             while (reader.Read())
             {
                 textBox2.Text = reader["NOME_CLIENTE"].ToString();
                 //textBox3.Text = reader["CPF_CLIENTE"].ToString();
                 TXT_TEL_CLIENTE.Text    = reader["TELEFONE_CLIENTE"].ToString();
                 TXT_DIVIDA_CLIENTE.Text = reader["SALDO_ATUAL_CLIENTE"].ToString();
                 TXT_CEL_CLIENTE.Text    = reader["CEL_CLIENTE"].ToString();
             }
             bd.closeConnection();
             if (float.Parse(TXT_DIVIDA_CLIENTE.Text) < 0.0)
             {
                 //label2.Hide();
                 label9.Show();
             }
         }
     }
 }
Exemplo n.º 4
0
        private void BTN_CONF_Click(object sender, EventArgs e)
        {
            DataBaseConnection bd = new DataBaseConnection();

            bd.openConnection();

            if (TXT_CPF_CLIENTE.TextLength > 0)
            {
                String nome = "";

                String       query       = "SELECT * FROM CLIENTE WHERE CPF_CLIENTE ='" + Validador.FormataCpfAndRg(TXT_CPF_CLIENTE.Text) + "'";
                String       queryDelete = "DELETE FROM CLIENTE WHERE CPF_CLIENTE ='" + Validador.FormataCpfAndRg(TXT_CPF_CLIENTE.Text) + "'";
                MySqlCommand cmd         = new MySqlCommand(query, bd.retornaConexao());

                MySqlDataReader reader = cmd.ExecuteReader();


                while (reader.Read())
                {
                    encontrouCliente = true;
                    nome             = reader["NOME_CLIENTE"].ToString();
                }

                if (!encontrouCliente)
                {
                    MessageBox.Show("CLIENTE NÃO ENCONTRADO");
                    encontrouCliente = false;
                }
                else
                {
                    if (nome.Length < 0)
                    {
                        MessageBox.Show("CLIENTE NÃO EXCLUÍDO");
                    }
                    else
                    {
                        DialogResult dr = System.Windows.Forms.MessageBox.Show("DESEJA EXCLUIR CLIENTE " + nome.ToUpper() + " ?",
                                                                               "CONFIRMA:", MessageBoxButtons.YesNo);
                        switch (dr)
                        {
                        case DialogResult.Yes:
                            DataBaseConnection bdDelete = new DataBaseConnection();
                            bdDelete.openConnection();
                            MySqlCommand cmdDelete = new MySqlCommand(queryDelete, bdDelete.retornaConexao());
                            cmdDelete.ExecuteNonQuery();
                            System.Windows.Forms.MessageBox.Show("CLIENTE EXCLUÍDO COM SUCESSO");
                            this.Hide();
                            break;

                        case DialogResult.No:
                            System.Windows.Forms.MessageBox.Show("EXCLUSÃO CANCELADA");
                            break;
                        }
                    }
                }
            }
            bd.closeConnection();
        }
Exemplo n.º 5
0
        private void BTN_CONF_Click(object sender, EventArgs e)
        {
            DataBaseConnection bd = new DataBaseConnection();

            bd.openConnection();



            String nome          = textBox1.Text;
            String dtnascimento  = dateTimePicker1.Value.ToString("yyyy-MM-dd HH:mm:ss");
            String rg            = Validador.FormataCpfAndRg(RG_FUNC.Text);
            String cpf           = Validador.FormataCpfAndRg(CPF_FUNC.Text);
            String tel           = Validador.FormataTelAndCel(TEL_FUNC.Text);
            String cel           = Validador.FormataTelAndCel(CEL_FUNC.Text);
            String email         = textBox4.Text;
            String senha         = textBox7.Text;
            String confirmasenha = textBox8.Text;
            String sexo          = null;
            String tipo          = null;



            if (radioButton1.Checked == true)
            {
                sexo = "m";
            }
            else if (radioButton2.Checked == true)
            {
                sexo = "f";
            }

            if (radioButton3.Checked == true)
            {
                tipo = "B";
            }
            else if (radioButton4.Checked == true)
            {
                tipo = "A";
            }



            if (Validador.campoPreenchido(rg) &&
                Validador.campoPreenchido(cpf) &&
                Validador.campoPreenchido(senha) &&
                Validador.campoPreenchido(confirmasenha) &&
                Validador.campoPreenchido(nome))
            {
                if (senha == confirmasenha)
                {
                    String query = "INSERT INTO USUARIO " +
                                   "(CPF_USER, NOME_USER, TEL_USER, CEL_USER, EMAIL_USER, NIVEL_USER, DTNASCIMENTO_USER, SEXO_USER, RG_USER, SENHA_USER)" +
                                   " VALUES ('" + cpf + "','" + nome + "','" + tel + "','" + cel + "','" +
                                   email + "','" + tipo + "','" + dtnascimento + "','" + sexo + "','" + rg + "','" + senha + "')";

                    //MessageBox.Show(query);

                    MySqlCommand cmd = new MySqlCommand(query, bd.retornaConexao());
                    cmd.ExecuteNonQuery();
                    System.Windows.Forms.MessageBox.Show("USUÁRIO CADASTRADO COM SUCESSO");

                    this.Close();
                }
                else
                {
                    System.Windows.Forms.MessageBox.Show("AS SENHAS DEVEM SER IGUAIS");
                    textBox7.Text = "";
                    textBox8.Text = "";
                }
            }
            else
            {
                MessageBox.Show("PREENCHA OS CAMPOS OBRIGATÓRIOS");
            }


            bd.closeConnection();
        }
Exemplo n.º 6
0
        private void BTN_CONF_Click(object sender, EventArgs e)
        {
            DataBaseConnection bd = new DataBaseConnection();

            bd.openConnection();

            String nome           = TXT_NOME.Text;
            String cpf            = TXT_CPF.Text;
            String tel            = Validador.FormataTelAndCel(TXT_TEL.Text);
            String cel            = Validador.FormataTelAndCel(TXT_CEL.Text);
            String email          = TXT_EMAIL.Text;
            String senha          = TXT_SENHA.Text;
            String rg             = Validador.FormataCpfAndRg(TXT_RG.Text);
            String datanascimento = TXT_DATE.Value.ToString("yyyy-MM-dd HH:mm:ss");

            String nivel = null;
            String sexo  = null;

            if (RD_ADMIN.Checked == true)
            {
                nivel = "A";
            }
            else if (RD_FUNC.Checked == true)
            {
                nivel = "B";
            }

            if (RD_FEM.Checked == true)
            {
                sexo = "f";
            }
            else if (RD_MASC.Checked == true)
            {
                sexo = "m";
            }

            cpfAnterior = Validador.FormataCpfAndRg(cpfAnterior);

            String query = "UPDATE USUARIO SET " +
                           "NOME_USER = '******', CPF_USER = '******', TEL_USER = '******', CEL_USER = '******', EMAIL_USER = '******', NIVEL_USER = '******', SEXO_USER = '******', SENHA_USER = '******', RG_USER = '******', DTNASCIMENTO_USER = '******' WHERE CPF_USER = "******"DADOS ALTERADOS COM SUCESSO");
                        new GerenUser().Show();
                        this.Hide();
                    }
                }
                catch (MySqlException ex)
                {
                    MessageBox.Show(ex.ToString());
                    System.Windows.Forms.MessageBox.Show("ERRO NA ALTERAÇÃO");
                }
            }
            else
            {
                MessageBox.Show("PREENCHA OS CAMPOS OBRIGATÓRIOS");
            }

            bd.closeConnection();
        }
Exemplo n.º 7
0
        private void BTN_CONF_Click(object sender, EventArgs e)
        {
            DataBaseConnection bd = new DataBaseConnection();

            bd.openConnection();

            if (TXT_CPF.TextLength > 0)
            {
                String nome = "", adm = "A", nivel = "";

                String       query       = "SELECT * FROM USUARIO WHERE CPF_USER ='******'";
                String       queryDelete = "DELETE FROM USUARIO WHERE CPF_USER ='******'";
                MySqlCommand cmd         = new MySqlCommand(query, bd.retornaConexao());

                MySqlDataReader reader = cmd.ExecuteReader();

                while (reader.Read())
                {
                    nome  = reader["NOME_USER"].ToString();
                    nivel = reader["NIVEL_USER"].ToString();
                }
                bd.closeConnection();

                if (nome.Length < 0 || adm.Equals(nivel))
                {
                    System.Windows.Forms.MessageBox.Show("USUÁRIO NÃO EXCLUÍDO");
                }
                else
                {
                    DialogResult dr = System.Windows.Forms.MessageBox.Show("DESEJA EXCLUIR?",
                                                                           "CONFIRMA:", MessageBoxButtons.YesNo);
                    switch (dr)
                    {
                    case DialogResult.Yes:
                        DataBaseConnection bdDelete = new DataBaseConnection();
                        bdDelete.openConnection();
                        MySqlCommand cmdDelete = new MySqlCommand(queryDelete, bdDelete.retornaConexao());
                        cmdDelete.ExecuteNonQuery();
                        System.Windows.Forms.MessageBox.Show("USUÁRIO EXCLUÍDO COM SUCESSO");
                        new GerenUser().Show();
                        this.Hide();
                        break;

                    case DialogResult.No:
                        System.Windows.Forms.MessageBox.Show("EXCLUSÃO CANCELADA");
                        break;
                    }
                }
            }
            bd.closeConnection();
        }