Ejemplo n.º 1
0
        static void Main(string[] args)
        {
            var mc = new DTO.Cliente();

            mc.setValue("Nome", "Adelson");
            System.Console.WriteLine("------------------------------\n");
            System.Console.WriteLine("Instrução Select para a classe\n");
            System.Console.Write(mc.TSQLSelectByID(1));
            System.Console.ReadKey();

            var ListProp = mc.GetType().GetProperties();

            ListProp.ToList().ForEach(p => System.Console.WriteLine(buscaInfo(mc, p)));



            System.Console.WriteLine("Altera os valores");
            System.Console.ReadKey();

            for (int i = 0; i < ListProp.ToList().Count; i++)
            {
                alterarValor(objeto: mc, membro: ListProp[i], valor: i);
            }

            System.Console.WriteLine("Atualiza com os novos valores");
            System.Console.ReadKey();

            //ListProp = mc.GetType().GetProperties();
            ListProp.ToList().ForEach(p => System.Console.WriteLine(buscaInfo(mc, p)));


            System.Console.WriteLine("\nPressione uma tecla pra continuar");
            System.Console.ReadKey();
        }
Ejemplo n.º 2
0
        public DTO.Cliente localizar(DTO.Cliente cliente)
        {
            Banco banco = new Banco();

            string sql = "select id i, nome n, sobrenome s, email e, cpf c, data_nascimento d, "
                         + "telefone t, celular ce from cliente cl where cl.cpf = " + cliente.Cpf;

            DataTable table = banco.dataServiceSelect(sql, null);

            DTO.Cliente c = new DTO.Cliente();

            try
            {
                c.Id              = int.Parse(table.Rows[0]["i"].ToString());
                c.Nome            = table.Rows[0]["n"].ToString();
                c.Sobrenome       = table.Rows[0]["s"].ToString();
                c.Cpf             = table.Rows[0]["c"].ToString();
                c.Email           = table.Rows[0]["e"].ToString();
                c.Data_nascimento = DateTime.Parse(table.Rows[0]["d"].ToString());
                c.Telefone        = table.Rows[0]["t"].ToString();
                c.Celular         = table.Rows[0]["ce"].ToString();

                return(c);
            }
            catch (Exception)
            {
                return(new DTO.Cliente());
            }
        }
Ejemplo n.º 3
0
        public DataTable localizarTodo(DTO.Cliente cliente)
        {
            Banco banco = new Banco();

            string sql = "select cep ce, logradouro lo, numero nu, complemento co, bairro ba, cidade ci, estado es, pais pa from endereco";

            DataTable table = banco.dataServiceSelect(sql, null);

            //List<DTO.Endereco> enderecos = new List<DTO.Endereco>();

            //foreach (var item in table.Rows)
            //{

            //    DTO.Endereco endereco = new DTO.Endereco();

            //    endereco.Cep = table.Rows[iten]["ce"].ToString();
            //    endereco.Logradouro = table.Rows[0]["lo"].ToString();
            //    endereco.Numero = table.Rows[0]["nu"].ToString();
            //    endereco.Complemento = table.Rows[0]["co"].ToString();
            //    endereco.Bairro = table.Rows[0]["ba"].ToString();
            //    endereco.Cidade = table.Rows[0]["ci"].ToString();
            //    endereco.Estado = table.Rows[0]["es"].ToString();
            //    endereco.Pais = table.Rows[0]["pa"].ToString();

            //    enderecos.Add(endereco);
            //}


            return(table);
        }
Ejemplo n.º 4
0
        public DataTable localizarTodo(DTO.Cliente cliente)
        {
            DataTable table;

            DAL.Endereco e = new DAL.Endereco();

            return(table = e.localizarTodo(cliente));
        }
Ejemplo n.º 5
0
        public List <Venda> getVendas(string select)
        {
            using (var i = Conexion())
            {
                i.Open();
                using (MySqlCommand c = new MySqlCommand())
                {
                    c.Connection = i;
                    if (string.IsNullOrEmpty(select))
                    {
                        c.CommandText = "SELECT * FROM venda";
                    }
                    else
                    {
                        c.CommandText = $"SELECT * FROM venda {select}";
                    }
                    using (MySqlDataReader r = c.ExecuteReader())
                    {
                        List <Venda> v = new List <Venda>();
                        while (r.Read())
                        {
                            DateTime data_ini = Convert.ToDateTime(r["data_inicio"]);
                            DateTime data_fi  = DateTime.MinValue;
                            if (!r.IsDBNull(5))
                            {
                                data_fi = Convert.ToDateTime(r["data_finalizado"]);
                            }

                            int  a     = Convert.ToInt32(r["finalizado"]);
                            bool isfin = false;
                            if (a == 1)
                            {
                                isfin = true;
                            }
                            else
                            {
                                isfin = false;
                            }
                            Tipo t = new Tipo()
                            {
                                Id = Convert.ToInt32(r[1])
                            };
                            DTO.Cliente cli = new DTO.Cliente();
                            if (!r.IsDBNull(8))
                            {
                                cli.Id = Convert.ToInt32(r["id_cliente"]);
                            }
                            v.Add(new Venda()
                            {
                                Id = Convert.ToInt32(r[0]), Data_finalizado = data_fi, Finalizado = isfin, Nome = r["nome"].ToString(), Valor_total = Convert.ToDecimal(r["valor_total"]), Data_inicio = data_ini, Metodo_pagamento = r["metodo_pagamento"].ToString(), Tipo = t, Cliente = cli
                            });
                        }
                        return(v);
                    }
                }
            }
        }
Ejemplo n.º 6
0
 public DTO.Cliente localizar(DTO.Cliente cliente)
 {
     DAL.Cliente c = new DAL.Cliente();
     if (cliente.Cpf != "")
     {
         return(c.localizar(cliente));
     }
     return(new DTO.Cliente());
 }
        protected void Page_Load(object sender, EventArgs e)
        {
            BLL.Cliente  validaCliente  = new BLL.Cliente();
            BLL.Endereco validaEndereco = new BLL.Endereco();
            DTO.Cliente  cliente        = new DTO.Cliente();
            DTO.Endereco endereco       = new DTO.Endereco();



            GridView1.DataSource = validaCliente.localizarTodo();
        }
Ejemplo n.º 8
0
        private static void efetuaCadastro(DTO.Cliente cliente, DTO.Endereco endereco, DTO.Conta conta)
        {
            BLL.Cliente  validaCliente  = new BLL.Cliente();
            BLL.Conta    validaConta    = new BLL.Conta();
            BLL.Endereco validaEndereco = new BLL.Endereco();

            endereco.Cliente_id = validaCliente.cadastrar(cliente);
            validaEndereco.cadastrar(endereco);

            conta.Cliente_id = endereco.Cliente_id;
            validaConta.cadastrar(conta);
        }
Ejemplo n.º 9
0
        public int dataService(DTO.Cliente cliente)
        {
            Banco banco = new Banco();

            string sql = "insert into cliente(nome, sobrenome, email, cpf, data_nascimento, telefone, celular) values"
                         + "(?nome, ?sobrenome, ?email, ?cpf, ?data_nascimento, ?telefone, ?celular)";

            banco.dataServiceInsertUpdateDelete(sql, cliente);

            banco = new Banco();

            cliente.Id = Convert.ToInt32(banco.dataServiceSelectScalar("select max(id) from cliente", null));

            return(cliente.Id);
        }
Ejemplo n.º 10
0
        public int update(DTO.Cliente cliente)
        {
            Banco banco = new Banco();

            string sql = "update cliente set nome = ?nome, sobrenome = ?sobrenome, email = ?email, cpf = ?cpf, data_nascimento = ?data_nascimento, "
                         + "telefone = ?telefone, celular = ?celular where cpf = ?cpf";

            banco.dataServiceInsertUpdateDelete(sql, cliente);

            banco = new Banco();

            cliente.Id = Convert.ToInt32(banco.dataServiceSelectScalar("select max(id) from cliente", null));

            return(cliente.Id);
        }
Ejemplo n.º 11
0
 public void Insert(DTO.Cliente c)
 {
     using (var i = Conexion())
     {
         i.Open();
         using (var cmd = new MySqlCommand())
         {
             cmd.Connection  = i;
             cmd.CommandText = $"INSERT INTO cliente VALUES(NULL,@NOME,@ENDERECO,0,@OBS,@TELL,0)";
             cmd.Parameters.AddWithValue("@NOME", c.Nome_cliente);
             cmd.Parameters.AddWithValue("@ENDERECO", c.Endereco);
             cmd.Parameters.AddWithValue("@OBS", c.Observacoes);
             cmd.Parameters.AddWithValue("@TELL", c.Telefone);
             cmd.ExecuteNonQuery();
         }
     }
 }
Ejemplo n.º 12
0
 public void alterCliente(DTO.Cliente c)
 {
     using (var i = Conexion())
     {
         i.Open();
         using (var cmd = new MySqlCommand())
         {
             cmd.Connection  = i;
             cmd.CommandText = $"UPDATE cliente SET nome_cliente=@NOME,endereco=@ENDERECO,casa_number=0,observacoes=@OBS,telefone=@TELL WHERE id = {c.Id}";
             cmd.Parameters.AddWithValue("@NOME", c.Nome_cliente);
             cmd.Parameters.AddWithValue("@ENDERECO", c.Endereco);
             cmd.Parameters.AddWithValue("@OBS", c.Observacoes);
             cmd.Parameters.AddWithValue("@TELL", c.Telefone);
             cmd.ExecuteNonQuery();
         }
     }
 }
Ejemplo n.º 13
0
        protected void cadastrar_Click(object sender, EventArgs e)
        {
            BLL.Cliente  validaCliente  = new BLL.Cliente();
            BLL.Endereco validaEndereco = new BLL.Endereco();
            DTO.Cliente  cliente        = new DTO.Cliente();
            DTO.Endereco endereco       = new DTO.Endereco();



            cliente.Cpf = cpf.Text;


            cliente = validaCliente.localizar(cliente);

            limpaaErros();
            if (cliente.Email != null)
            {
                nome.Text           = cliente.Nome;
                sobreNome.Text      = cliente.Sobrenome;
                cpf.Text            = cliente.Cpf;
                telefone.Text       = cliente.Telefone;
                email.Text          = cliente.Email;
                celular.Text        = cliente.Celular;
                dataNascimento.Text = cliente.Data_nascimento.ToShortDateString();

                endereco.Cliente_id = cliente.Id;
                endereco            = validaEndereco.localizar(endereco);

                cep.Text         = endereco.Cep;
                logradouro.Text  = endereco.Logradouro;
                numero.Text      = endereco.Numero;
                complemento.Text = endereco.Complemento;
                bairro.Text      = endereco.Bairro;
                cidade.Text      = endereco.Cidade;
                estado.Text      = endereco.Estado;
                pais.Text        = endereco.Pais;
            }
            else
            {
                cpfErro.Text = "Cpf invalido ou o cliente não é cadastrado!";
            }
        }
Ejemplo n.º 14
0
 private void btn_ok_Click(object sender, EventArgs e)
 {
     if (grid_client.SelectedItems.Count > 0)
     {
         try
         {
             List <DTO.Cliente> ac = new dao_Cliente().getClientes($"WHERE id = {Convert.ToInt32(grid_client.SelectedItems[0].SubItems[0].Text)}");
             c = ac[0];
             this.DialogResult = DialogResult.OK;
         }
         catch (Exception ex)
         {
             MessageBox.Show(ex.Message);
         }
     }
     else
     {
         MessageBox.Show("Escolha um cliente!");
     }
 }
Ejemplo n.º 15
0
        public void Inserir(DTO.Cliente dto)
        {
            try
            {
                con = new Conexao();

                con.Conectar();
                string comando = "INSERT INTO cliente VALUES (null, '" + dto.Nome + "', '" + dto.Cpf + "', '" + dto.Rg + "', '" + dto.Data_nasc + "')";
                con.ExecutarComandoSQL(comando);
            }

            catch (Exception ex)
            {
                MessageBox.Show("Erro ao Tentar Cadastrar o Cliente: " + ex.Message);
            }

            finally
            {
                con = null;
            }
        }
Ejemplo n.º 16
0
        public void Alterar(DTO.Cliente dto)
        {
            try
            {
                con = new Conexao();

                con.Conectar();
                string comando = "UPDATE cliente SET nome='" + dto.Nome + "', cpf='" + dto.Cpf + "', rg='" + dto.Rg + "', data_nasc='" + dto.Data_nasc + "'";
                con.ExecutarComandoSQL(comando);
            }

            catch (Exception ex)
            {
                MessageBox.Show("Erro ao Tentar Atualizar o CLiente: " + ex.Message);
            }

            finally
            {
                con = null;
            }
        }
Ejemplo n.º 17
0
        //adiciona venda e retorna o id
        public int addVenda(string nome, decimal valor, DTO.Cliente c, int tipoid, string metodo = "")
        {
            int id = 0;

            using (var i = Conexion())
            {
                i.Open();
                using (MySqlCommand cmd = new MySqlCommand())
                {
                    cmd.Connection = i;
                    string sql = null;

                    /*verificar se o mesmo nome existe ja em uma venda nao finalizada*/
                    if (c == null)
                    {
                        sql = "INSERT INTO venda(nome,finalizado,valor_total,id_tipo,metodo_pagamento) VALUES (@NOME,0,@VALOR,@TIPO,@METODO);";
                    }
                    else
                    {
                        sql = "INSERT INTO venda(nome,finalizado,valor_total,id_cliente,id_tipo,metodo_pagamento) VALUES (@NOME,0,@VALOR,@IDCLI,@TIPO,@METODO);";
                        cmd.Parameters.AddWithValue("@IDCLI", c.Id);
                    }
                    cmd.CommandText = sql;
                    cmd.Parameters.AddWithValue("@NOME", nome);
                    cmd.Parameters.AddWithValue("@VALOR", valor);
                    cmd.Parameters.AddWithValue("@TIPO", tipoid);
                    cmd.Parameters.AddWithValue("@METODO", metodo);
                    cmd.ExecuteNonQuery();

                    sql             = "SELECT * FROM `venda` ORDER BY id DESC LIMIT 1;";
                    cmd.CommandText = sql;
                    using (MySqlDataReader rd = cmd.ExecuteReader())
                    {
                        rd.Read();
                        id = rd.GetInt32(0);
                    }
                }
            }
            return(id);
        }
Ejemplo n.º 18
0
        protected void cadastrar_Click(object sender, EventArgs e)
        {
            limpaaErros();
            DTO.ContaCorrente contaCorrente;
            DTO.ContaPoupanca contaPoupanca;

            DTO.Cliente  cliente  = new DTO.Cliente();
            DTO.Endereco endereco = new DTO.Endereco();

            cliente.Nome      = nome.Text;
            cliente.Sobrenome = sobreNome.Text;
            cliente.Email     = email.Text;
            cliente.Cpf       = cpf.Text;
            cliente.Celular   = celular.Text;
            cliente.Telefone  = telefone.Text;

            DateTime loadedDate = DateTime.ParseExact(dataNascimento.Text, "d", null);

            cliente.Data_nascimento = loadedDate.Date;

            endereco.Cep         = cep.Text;
            endereco.Logradouro  = logradouro.Text;
            endereco.Numero      = numero.Text;
            endereco.Complemento = complemento.Text;
            endereco.Bairro      = bairro.Text;
            endereco.Cidade      = cidade.Text;
            endereco.Estado      = estado.Text;
            endereco.Pais        = pais.Text;



            if ((DTO.TiposDeConta)Enum.Parse(typeof(DTO.TiposDeConta), tiposDeConta.SelectedValue) == DTO.TiposDeConta.Corrente)
            {
                contaCorrente            = new DTO.ContaCorrente();
                contaCorrente.Tipo       = (DTO.TiposDeConta)Enum.Parse(typeof(DTO.TiposDeConta), tiposDeConta.SelectedValue);
                contaCorrente.Saldo      = decimal.Parse(saldoDeEntrada.Text);
                contaCorrente.Cliente_id = cliente.Id;

                if (agencia.SelectedIndex != 0)
                {
                    contaCorrente.Agencia = (DTO.Agencia)Enum.Parse(typeof(DTO.Agencia), agencia.SelectedValue);
                    efetuaCadastro(cliente, endereco, contaCorrente);
                }
                else
                {
                    agenciaErro.Text = error;
                }
            }
            else
            {
                contaPoupanca            = new DTO.ContaPoupanca();
                contaPoupanca.Tipo       = (DTO.TiposDeConta)Enum.Parse(typeof(DTO.TiposDeConta), tiposDeConta.SelectedValue);
                contaPoupanca.Saldo      = decimal.Parse(saldoDeEntrada.Text);
                contaPoupanca.Cliente_id = cliente.Id;
                if (agencia.SelectedIndex != 0)
                {
                    contaPoupanca.Agencia = (DTO.Agencia)Enum.Parse(typeof(DTO.Agencia), agencia.SelectedValue);
                    efetuaCadastro(cliente, endereco, contaPoupanca);
                }
                else
                {
                    agenciaErro.Text = error;
                }
            }
        }
Ejemplo n.º 19
0
 public int update(DTO.Cliente cliente)
 {
     DAL.Cliente c = new DAL.Cliente();
     return(c.update(cliente));
 }
Ejemplo n.º 20
0
 public int cadastrar(DTO.Cliente cliente)
 {
     DAL.Cliente c = new DAL.Cliente();
     return(c.dataService(cliente));
 }