Esempio n. 1
0
        public ProdutoModel ConsultarID(int id)
        {
            MySqlCommand cmd = new MySqlCommand();

            cmd.CommandText = @"select *
                            from produto
                            where idproduto=@id";

            cmd.Parameters.AddWithValue("id", id);

            InstrucaoDAO objDAL = new InstrucaoDAO();
            DataTable    dt     = objDAL.retornoDataTable(cmd);
            ProdutoModel item   = new ProdutoModel();

            if (dt != null)
            {
                item = new ProdutoModel
                {
                    Idproduto      = Convert.ToInt32(dt.Rows[0]["idproduto"].ToString()),
                    Nome           = dt.Rows[0]["nome"].ToString(),
                    Descricao      = dt.Rows[0]["descricao"].ToString(),
                    Preco_unitario = Convert.ToDecimal(dt.Rows[0]["preco_unitario"].ToString()),
                    Quantidade     = Convert.ToInt32(dt.Rows[0]["quantidade"].ToString()),
                    ContentType    = dt.Rows[0]["contenttype"].ToString(),
                    Foto           = (!Convert.IsDBNull(dt.Rows[0]["foto"]) ? (byte[])dt.Rows[0]["foto"] : null)
                };
            }
            else
            {
                item = null;
            }

            return(item);
        }
Esempio n. 2
0
        public VendaModel ConsultarID(int id)
        {
            MySqlCommand cmd = new MySqlCommand();

            cmd.CommandText = @"select *
                            from venda
                            where idvenda=@id";

            cmd.Parameters.AddWithValue("id", id);

            InstrucaoDAO objDAL = new InstrucaoDAO();
            DataTable    dt     = objDAL.retornoDataTable(cmd);
            VendaModel   item   = new VendaModel();

            if (dt != null)
            {
                item = new VendaModel
                {
                    Idvenda  = Convert.ToInt32(dt.Rows[0]["idvenda"].ToString()),
                    Data     = dt.Rows[0]["data"].ToString(),
                    Total    = Convert.ToDecimal(dt.Rows[0]["total"].ToString()),
                    Cliente  = dt.Rows[0]["fk_idcliente"].ToString(),
                    Vendedor = dt.Rows[0]["fk_idvendedor"].ToString()
                };
            }
            else
            {
                item = null;
            }
            return(item);
        }
        public List <GraficoModel> RetornarGRAPH()
        {
            MySqlCommand cmd = new MySqlCommand();

            cmd.CommandText = @"SELECT sum(total) as valor, 
                                date_format(data, '%d-%m-%y') as data
                                FROM venda
                                where data between (date_sub(CURDATE(), INTERVAL 6 DAY)) 
                                and (date_add(CURDATE(), interval 1 DAY))
                                group by date_format(data, '%d-%m-%y')
                                order by data asc";

            InstrucaoDAO        objDAL = new InstrucaoDAO();
            DataTable           dt     = objDAL.retornoDataTable(cmd);
            List <GraficoModel> lista  = new List <GraficoModel>();

            if (dt != null)
            {
                for (int i = 0; i < dt.Rows.Count; i++)
                {
                    GraficoModel item = new GraficoModel
                    {
                        Datadia  = dt.Rows[i]["data"].ToString(),
                        Valordia = Convert.ToDecimal(dt.Rows[i]["valor"].ToString())
                    };
                    lista.Add(item);
                }
            }
            return(lista);
        }
Esempio n. 4
0
        public List <ClienteModel> listarClientes()
        {
            MySqlCommand cmd = new MySqlCommand();

            cmd.CommandText = @"select *
                            from cliente";

            InstrucaoDAO        objDAL = new InstrucaoDAO();
            DataTable           dt     = objDAL.retornoDataTable(cmd);
            List <ClienteModel> lista  = new List <ClienteModel>();

            if (dt != null)
            {
                for (int i = 0; i < dt.Rows.Count; i++)
                {
                    ClienteModel item = new ClienteModel
                    {
                        Idcliente   = Convert.ToInt32(dt.Rows[i]["idcliente"].ToString()),
                        Nome        = dt.Rows[i]["nome"].ToString(),
                        Email       = dt.Rows[i]["email"].ToString(),
                        Cep         = dt.Rows[i]["cep"].ToString(),
                        Logradouro  = dt.Rows[i]["logradouro"].ToString(),
                        Numero      = dt.Rows[i]["numero"].ToString(),
                        Complemento = dt.Rows[i]["complemento"].ToString(),
                        Bairro      = dt.Rows[i]["bairro"].ToString(),
                        Cidade      = dt.Rows[i]["cidade"].ToString(),
                        UF          = dt.Rows[i]["uf"].ToString(),
                    };
                    lista.Add(item);
                }
            }
            return(lista);
        }
        public VendedorModel ConsultarID(int id)
        {
            MySqlCommand cmd = new MySqlCommand();

            cmd.CommandText = @"select *
                            from vendedor
                            where idvendedor=@id";

            cmd.Parameters.AddWithValue("id", id);

            InstrucaoDAO  objDAL = new InstrucaoDAO();
            DataTable     dt     = objDAL.retornoDataTable(cmd);
            VendedorModel item   = new VendedorModel();

            if (dt != null)
            {
                item = new VendedorModel
                {
                    Idvendedor = Convert.ToInt32(dt.Rows[0]["idvendedor"].ToString()),
                    Nome       = dt.Rows[0]["nome"].ToString(),
                    Sexo       = dt.Rows[0]["sexo"].ToString(),
                    Email      = dt.Rows[0]["email"].ToString(),
                    Senha      = dt.Rows[0]["senha"].ToString(),
                    Nivel      = dt.Rows[0]["nivel"].ToString(),
                    Status     = dt.Rows[0]["status"].ToString(),
                    Foto       = (!Convert.IsDBNull(dt.Rows[0]["foto"]) ? (byte[])dt.Rows[0]["foto"] : null)
                };
            }
            else
            {
                item = null;
            }

            return(item);
        }
Esempio n. 6
0
        public List <ProdutoModel> listarProdutos()
        {
            MySqlCommand cmd = new MySqlCommand();

            cmd.CommandText = @"select *
                            from produto";

            InstrucaoDAO        objDAL = new InstrucaoDAO();
            DataTable           dt     = objDAL.retornoDataTable(cmd);
            List <ProdutoModel> lista  = new List <ProdutoModel>();

            if (dt != null)
            {
                for (int i = 0; i < dt.Rows.Count; i++)
                {
                    ProdutoModel item = new ProdutoModel
                    {
                        Idproduto      = Convert.ToInt32(dt.Rows[i]["idproduto"].ToString()),
                        Nome           = dt.Rows[i]["nome"].ToString(),
                        Descricao      = dt.Rows[i]["descricao"].ToString(),
                        Preco_unitario = Convert.ToDecimal(dt.Rows[i]["preco_unitario"].ToString()),
                        Quantidade     = Convert.ToInt32(dt.Rows[i]["quantidade"].ToString()),
                        ContentType    = dt.Rows[i]["contenttype"].ToString(),
                        Foto           = (!Convert.IsDBNull(dt.Rows[i]["foto"]) ? (byte[])dt.Rows[i]["foto"] : null)
                    };
                    lista.Add(item);
                }
            }
            return(lista);
        }
Esempio n. 7
0
        public void Editar(ClienteModel cli)
        {
            MySqlCommand cmd = new MySqlCommand();



            cmd.CommandText = @"update cliente
                                set nome = @nome,
                                cep = @cep, 
                                logradouro = @logradouro, 
                                numero = @numero,
                                complemento = @complemento,
                                bairro = @bairro,
                                cidade = @cidade,
                                uf = @uf,
                                email = @email
                                where idcliente = @id";

            cmd.Parameters.AddWithValue("id", cli.Idcliente);
            cmd.Parameters.AddWithValue("nome", cli.Nome);
            cmd.Parameters.AddWithValue("cep", cli.Cep);
            cmd.Parameters.AddWithValue("logradouro", cli.Logradouro);
            cmd.Parameters.AddWithValue("numero", cli.Numero);
            cmd.Parameters.AddWithValue("complemento", cli.Complemento);
            cmd.Parameters.AddWithValue("bairro", cli.Bairro);
            cmd.Parameters.AddWithValue("cidade", cli.Cidade);
            cmd.Parameters.AddWithValue("uf", cli.UF);
            cmd.Parameters.AddWithValue("email", cli.Email);

            InstrucaoDAO objDAL = new InstrucaoDAO();

            objDAL.executarSQL(cmd);
        }
        public List <VendedorModel> listarVendedores()
        {
            MySqlCommand cmd = new MySqlCommand();

            cmd.CommandText = @"select *
                            from vendedor";

            InstrucaoDAO         objDAL = new InstrucaoDAO();
            DataTable            dt     = objDAL.retornoDataTable(cmd);
            List <VendedorModel> lista  = new List <VendedorModel>();

            if (dt != null)
            {
                for (int i = 0; i < dt.Rows.Count; i++)
                {
                    VendedorModel item = new VendedorModel
                    {
                        Idvendedor = Convert.ToInt32(dt.Rows[i]["idvendedor"].ToString()),
                        Nome       = dt.Rows[i]["nome"].ToString(),
                        Sexo       = dt.Rows[i]["sexo"].ToString(),
                        Email      = dt.Rows[i]["email"].ToString(),
                        Nivel      = dt.Rows[i]["nivel"].ToString(),
                        Status     = dt.Rows[i]["status"].ToString(),
                        Foto       = (!Convert.IsDBNull(dt.Rows[i]["foto"]) ? (byte[])dt.Rows[i]["foto"] : null)
                    };
                    lista.Add(item);
                }
            }
            return(lista);
        }
Esempio n. 9
0
        public List <VendaModel> listarVendas()
        {
            MySqlCommand cmd = new MySqlCommand();

            cmd.CommandText = @"select C.nome as cliente, V.idvenda, V.data, 
                            V.total, Ve.nome as vendedor
                            from cliente C
                            inner join venda V
                            on C.idcliente = V.fk_idcliente
                            inner join vendedor Ve
                            on Ve.idvendedor = V.fk_idvendedor
                            order by idvenda desc";

            InstrucaoDAO      objDAL = new InstrucaoDAO();
            DataTable         dt     = objDAL.retornoDataTable(cmd);
            List <VendaModel> lista  = new List <VendaModel>();

            if (dt != null)
            {
                for (int i = 0; i < dt.Rows.Count; i++)
                {
                    VendaModel item = new VendaModel
                    {
                        Idvenda  = Convert.ToInt32(dt.Rows[i]["idvenda"].ToString()),
                        Data     = Convert.ToDateTime(dt.Rows[i]["data"].ToString()).ToString("dd/MM/yyyy"),
                        Total    = Convert.ToDecimal(dt.Rows[i]["total"].ToString()),
                        Cliente  = dt.Rows[i]["cliente"].ToString(),
                        Vendedor = dt.Rows[i]["vendedor"].ToString()
                    };
                    lista.Add(item);
                }
            }
            return(lista);
        }
Esempio n. 10
0
        public void Inserir(VendaModel ven)
        {
            MySqlCommand cmd = new MySqlCommand();

            cmd.CommandText = @"insert into venda(data, total, fk_idvendedor, fk_idcliente)
                            values (@data, @total, @fk_idvendedor, @fk_idcliente)";

            cmd.Parameters.AddWithValue("data", DateTime.Now.ToString("yyyy/MM/dd hh:mm:ss"));
            cmd.Parameters.AddWithValue("total", ven.Total);
            cmd.Parameters.AddWithValue("fk_idvendedor", ven.Vendedor);
            cmd.Parameters.AddWithValue("fk_idcliente", ven.Cliente);

            InstrucaoDAO objDAL = new InstrucaoDAO();

            objDAL.executarSQL(cmd);

            //Recuper o ID da venda
            cmd.CommandText = @"select LAST_INSERT_ID();";
            DataTable dt      = objDAL.retornoDataTable(cmd);
            string    IDvenda = dt.Rows[0][0].ToString();

            //Deserializar o JSON de produtos
            cmd.CommandText = @"insert into itens_venda(fk_idvenda, fk_idproduto, qtd, valor)
                            values (@venda_id, @produto_id, @qtde_produto, @preco_produto)";
            cmd.Parameters.AddWithValue("venda_id", IDvenda);

            //Comando SQL para baixa do produto
            MySqlCommand baixa = new MySqlCommand();

            baixa.CommandText = @"update produto 
                                set quantidade = quantidade - @qt_produto
                                where idproduto = @prod_id";

            List <Itens_VendaModel> lstProdutos =
                JsonConvert.DeserializeObject <List <Itens_VendaModel> >(ven.ListaProdutosJSON);

            foreach (var item in lstProdutos)
            {
                //Inserir Itens da Venda
                cmd.Parameters.AddWithValue("produto_id", item.Fk_idproduto);
                cmd.Parameters.AddWithValue("qtde_produto", item.Qtd);
                cmd.Parameters.AddWithValue("preco_produto", Convert.ToDouble(item.Valor));
                objDAL.executarSQL(cmd);

                //Efetivar baixa de produto do estoque
                baixa.Parameters.AddWithValue("prod_id", item.Fk_idproduto);
                baixa.Parameters.AddWithValue("qt_produto", item.Qtd);
                objDAL.executarSQL(baixa);

                //Limpar Parâmetros
                cmd.Parameters.RemoveAt("produto_id");
                cmd.Parameters.RemoveAt("qtde_produto");
                cmd.Parameters.RemoveAt("preco_produto");
                baixa.Parameters.RemoveAt("prod_id");
                baixa.Parameters.RemoveAt("qt_produto");
            }
        }
Esempio n. 11
0
        public void Excluir(int id)
        {
            MySqlCommand cmd = new MySqlCommand();

            cmd.CommandText = @"delete from cliente
                                where idcliente = @id";

            cmd.Parameters.AddWithValue("id", id);
            InstrucaoDAO objDAL = new InstrucaoDAO();

            objDAL.executarSQL(cmd);
        }
Esempio n. 12
0
        public List <VendaModel> ListagemVendasPorData(RelatorioDataModel rel)
        {
            MySqlCommand cmd = new MySqlCommand();

            if (rel.DataInicio.Year != 1)
            {
                cmd.CommandText = @"select V1.idvenda, V1.data, V1.total, 
                                    V2.nome as vendedor, C.nome as cliente
                                    from cliente C 
                                    inner join venda V1
                                    on C.idcliente = V1.fk_idcliente
                                    inner join vendedor V2
                                    on V2.idvendedor = V1.fk_idvendedor                             
                                    where v1.data between @DataInicio and @DataFim
                                    order by V1.data, V1.total";
            }
            else
            {
                cmd.CommandText = @"select V1.idvenda, V1.data, V1.total, 
                                    V2.nome as vendedor, C.nome as cliente
                                    from cliente C 
                                    inner join venda V1
                                    on C.idcliente = V1.fk_idcliente
                                    inner join vendedor V2
                                    on V2.idvendedor = V1.fk_idvendedor
                                    order by V1.data, V1.total";
            }

            cmd.Parameters.AddWithValue("@DataInicio", rel.DataInicio.ToString("yyyy/MM/dd 00:00:00"));
            cmd.Parameters.AddWithValue("@DataFim", rel.DataFim.ToString("yyyy/MM/dd 23:59:59"));

            InstrucaoDAO      objDAL = new InstrucaoDAO();
            DataTable         dt     = objDAL.retornoDataTable(cmd);
            List <VendaModel> lista  = new List <VendaModel>();

            if (dt != null)
            {
                for (int i = 0; i < dt.Rows.Count; i++)
                {
                    VendaModel item = new VendaModel
                    {
                        Idvenda  = Convert.ToInt32(dt.Rows[i]["idvenda"].ToString()),
                        Data     = Convert.ToDateTime(dt.Rows[i]["data"].ToString()).ToString("dd/MM/yyyy"),
                        Total    = Convert.ToDecimal(dt.Rows[i]["total"].ToString()),
                        Cliente  = dt.Rows[i]["cliente"].ToString(),
                        Vendedor = dt.Rows[i]["vendedor"].ToString()
                    };
                    lista.Add(item);
                }
            }
            return(lista);
        }
Esempio n. 13
0
        public void Excluir(int id)
        {
            MySqlCommand cmd = new MySqlCommand();

            cmd.CommandText = @"select *
                            from itens_venda
                            where fk_idvenda = @id";

            cmd.Parameters.AddWithValue("@id", id);

            InstrucaoDAO objDAL = new InstrucaoDAO();
            DataTable    dt     = objDAL.retornoDataTable(cmd);

            int codProduto;
            int qtProduto;

            MySqlCommand extorno = new MySqlCommand();

            extorno.CommandText = @"update produto 
                                set quantidade = @qt_produto+quantidade
                                where idproduto = @prod_id";

            foreach (DataRow row in dt.Rows)
            {
                qtProduto  = Convert.ToInt32(row["qtd"].ToString());
                codProduto = Convert.ToInt32(row["fk_idproduto"].ToString());

                extorno.Parameters.AddWithValue("qt_produto", qtProduto);
                extorno.Parameters.AddWithValue("prod_id", codProduto);
                objDAL.executarSQL(extorno);

                //Limpar Parâmetros
                extorno.Parameters.RemoveAt("@prod_id");
                extorno.Parameters.RemoveAt("@qt_produto");
            }

            //Apaga os Itens da Venda referentes a Venda
            cmd.CommandText = @"delete from itens_venda                                 
                                where fk_idvenda = @fk_idv";
            cmd.Parameters.AddWithValue("fk_idv", id);
            objDAL.executarSQL(cmd);

            //Apaga a Venda
            cmd.CommandText = @"delete from venda                                 
                                where idvenda = @idv";
            cmd.Parameters.AddWithValue("idv", id);
            objDAL.executarSQL(cmd);
        }
Esempio n. 14
0
        public void alterarSenha(SenhaModel sen)
        {
            MySqlCommand cmd = new MySqlCommand();

            cmd.CommandText = @"update vendedor
                                set senha = @senha
                                where idvendedor = @id";


            cmd.Parameters.AddWithValue("id", sen.Id);
            cmd.Parameters.AddWithValue("senha", sen.NovaSenha);

            InstrucaoDAO objDAL = new InstrucaoDAO();

            objDAL.executarSQL(cmd);
        }
        public void Editar(VendedorModel ven)
        {
            try
            {
                MySqlCommand cmd = new MySqlCommand();

                if (ven.Foto != null)
                {
                    cmd.CommandText = @"update vendedor
                                set nome = @nome,
                                sexo = @sexo, 
                                email = @email, 
                                nivel = @nivel,
                                status = @status,
                                foto = @foto,
                                contenttype = @contenttype
                                where idvendedor = @id";
                }
                else
                {
                    cmd.CommandText = @"update vendedor
                                set nome = @nome,
                                sexo = @sexo, 
                                email = @email, 
                                nivel = @nivel,
                                status = @status
                                where idvendedor = @id";
                }

                cmd.Parameters.AddWithValue("id", ven.Idvendedor);
                cmd.Parameters.AddWithValue("nome", ven.Nome);
                cmd.Parameters.AddWithValue("sexo", ven.Sexo);
                cmd.Parameters.AddWithValue("email", ven.Email);
                cmd.Parameters.AddWithValue("nivel", ven.Nivel);
                cmd.Parameters.AddWithValue("status", ven.Status);
                cmd.Parameters.AddWithValue("foto", ven.Foto);
                cmd.Parameters.AddWithValue("contenttype", ven.ContentType);

                InstrucaoDAO objDAL = new InstrucaoDAO();
                objDAL.executarSQL(cmd);
            }
            catch (Exception ex)
            {
                var erro = ex.Message;
            }
        }
        public void Excluir(int id)
        {
            try
            {
                MySqlCommand cmd = new MySqlCommand();

                cmd.CommandText = @"delete from vendedor
                                where idvendedor = @id";

                cmd.Parameters.AddWithValue("id", id);
                InstrucaoDAO objDAL = new InstrucaoDAO();
                objDAL.executarSQL(cmd);
            }
            catch (Exception ex)
            {
                var erro = ex.Message;
            }
        }
Esempio n. 17
0
        public void Editar(ProdutoModel pro)
        {
            try
            {
                MySqlCommand cmd = new MySqlCommand();

                if (pro.Foto != null)
                {
                    cmd.CommandText = @"update produto
                                set nome = @nome,
                                descricao = @descricao, 
                                preco_unitario = @preco_unitario, 
                                quantidade = @quantidade,
                                foto = @foto,
                                contenttype = @contenttype
                                where idproduto = @id";
                }
                else
                {
                    cmd.CommandText = @"update vendedor
                                set nome = @nome,
                                descricao = @descricao, 
                                preco_unitario = @preco_unitario, 
                                quantidade = @quantidade,                                                                
                                where idvendedor = @id";
                }

                cmd.Parameters.AddWithValue("id", pro.Idproduto);
                cmd.Parameters.AddWithValue("nome", pro.Nome);
                cmd.Parameters.AddWithValue("descricao", pro.Descricao);
                cmd.Parameters.AddWithValue("preco_unitario", pro.Preco_unitario);
                cmd.Parameters.AddWithValue("quantidade", pro.Quantidade);
                cmd.Parameters.AddWithValue("foto", pro.Foto);
                cmd.Parameters.AddWithValue("contenttype", pro.ContentType);


                InstrucaoDAO objDAL = new InstrucaoDAO();
                objDAL.executarSQL(cmd);
            }
            catch (Exception ex)
            {
                var erro = ex.Message;
            }
        }
        public void Inserir(VendedorModel ven)
        {
            MySqlCommand cmd = new MySqlCommand();

            cmd.CommandText = @"insert into vendedor(nome, sexo, email, senha, nivel, status, foto)
                            values (@nome, @sexo, @email, @senha, @nivel, @status, @foto)";

            cmd.Parameters.AddWithValue("nome", ven.Nome);
            cmd.Parameters.AddWithValue("sexo", ven.Sexo);
            cmd.Parameters.AddWithValue("email", ven.Email);
            cmd.Parameters.AddWithValue("senha", ven.Senha);
            cmd.Parameters.AddWithValue("nivel", ven.Nivel);
            cmd.Parameters.AddWithValue("status", ven.Status);
            cmd.Parameters.AddWithValue("foto", ven.Foto);

            InstrucaoDAO objDAL = new InstrucaoDAO();

            objDAL.executarSQL(cmd);
        }
Esempio n. 19
0
        public void Inserir(ProdutoModel pro)
        {
            MySqlCommand cmd = new MySqlCommand();

            cmd.CommandText = @"insert into produto(nome, descricao, preco_unitario, 
                                quantidade, foto, contenttype)
                                values (@nome, @descricao, @preco_unitario, 
                                @quantidade, @foto, @contenttype)";

            cmd.Parameters.AddWithValue("nome", pro.Nome);
            cmd.Parameters.AddWithValue("descricao", pro.Descricao);
            cmd.Parameters.AddWithValue("preco_unitario", pro.Preco_unitario);
            cmd.Parameters.AddWithValue("quantidade", pro.Quantidade);
            cmd.Parameters.AddWithValue("foto", pro.Foto);
            cmd.Parameters.AddWithValue("contenttype", pro.ContentType);

            InstrucaoDAO objDAL = new InstrucaoDAO();

            objDAL.executarSQL(cmd);
        }
Esempio n. 20
0
        public void Inserir(ClienteModel cli)
        {
            MySqlCommand cmd = new MySqlCommand();

            cmd.CommandText = @"insert into cliente
                                (nome, cep, logradouro, numero, 
                                complemento, bairro, cidade, uf, email)
                                values 
                                (@nome, @cep, @logradouro, @numero, 
                                @complemento, @bairro, @cidade, @uf, @email)";
            cmd.Parameters.AddWithValue("nome", cli.Nome);
            cmd.Parameters.AddWithValue("cep", cli.Cep);
            cmd.Parameters.AddWithValue("logradouro", cli.Logradouro);
            cmd.Parameters.AddWithValue("numero", cli.Numero);
            cmd.Parameters.AddWithValue("complemento", cli.Complemento);
            cmd.Parameters.AddWithValue("bairro", cli.Bairro);
            cmd.Parameters.AddWithValue("cidade", cli.Cidade);
            cmd.Parameters.AddWithValue("uf", cli.UF);
            cmd.Parameters.AddWithValue("email", cli.Email);
            InstrucaoDAO objDAL = new InstrucaoDAO();

            objDAL.executarSQL(cmd);
        }
Esempio n. 21
0
        public ClienteModel ConsultarID(int id)
        {
            MySqlCommand cmd = new MySqlCommand();

            cmd.CommandText = @"select *
                            from cliente
                            where idcliente=@id";

            cmd.Parameters.AddWithValue("id", id);

            InstrucaoDAO objDAL = new InstrucaoDAO();
            DataTable    dt     = objDAL.retornoDataTable(cmd);
            ClienteModel item   = new ClienteModel();

            if (dt != null)
            {
                item = new ClienteModel
                {
                    Idcliente   = Convert.ToInt32(dt.Rows[0]["idcliente"].ToString()),
                    Nome        = dt.Rows[0]["nome"].ToString(),
                    Cep         = dt.Rows[0]["cep"].ToString(),
                    Logradouro  = dt.Rows[0]["logradouro"].ToString(),
                    Numero      = dt.Rows[0]["numero"].ToString(),
                    Complemento = dt.Rows[0]["complemento"].ToString(),
                    Bairro      = dt.Rows[0]["bairro"].ToString(),
                    Cidade      = dt.Rows[0]["cidade"].ToString(),
                    UF          = dt.Rows[0]["uf"].ToString(),
                    Email       = dt.Rows[0]["email"].ToString()
                };
            }
            else
            {
                item = null;
            }

            return(item);
        }
Esempio n. 22
0
        public List <VendaModel> ListagemVendasPorVendedor(RelatorioVendedorModel rel)
        {
            MySqlCommand cmd = new MySqlCommand();

            cmd.CommandText = @"select V1.idvenda, v1.data, v1.total, 
                                V2.nome as vendedor, C.nome as cliente
                                from cliente C                                
                                inner join venda V1 
                                on C.idcliente = V1.fk_idcliente
                                inner join vendedor V2
                                on V2.idvendedor = V1.fk_idvendedor
                                where V1.fk_idvendedor = @fk_idvendedor";

            cmd.Parameters.AddWithValue("@fk_idvendedor", rel.Vendedor);

            InstrucaoDAO      objDAL = new InstrucaoDAO();
            DataTable         dt     = objDAL.retornoDataTable(cmd);
            List <VendaModel> lista  = new List <VendaModel>();

            if (dt != null)
            {
                for (int i = 0; i < dt.Rows.Count; i++)
                {
                    VendaModel item = new VendaModel
                    {
                        Idvenda  = Convert.ToInt32(dt.Rows[i]["idvenda"].ToString()),
                        Data     = Convert.ToDateTime(dt.Rows[i]["data"].ToString()).ToString("dd/MM/yyyy"),
                        Total    = Convert.ToDecimal(dt.Rows[i]["total"].ToString()),
                        Cliente  = dt.Rows[i]["cliente"].ToString(),
                        Vendedor = dt.Rows[i]["vendedor"].ToString()
                    };
                    lista.Add(item);
                }
            }
            return(lista);
        }
Esempio n. 23
0
        public List <VendedorModel> validarLogin(LoginModel login)
        {
            MySqlCommand cmd = new MySqlCommand();

            cmd.CommandText = @"select *
                            from vendedor
                            where Email=@email";

            cmd.Parameters.AddWithValue("email", login.Email);

            InstrucaoDAO objDAL = new InstrucaoDAO();
            DataTable    dt     = objDAL.retornoDataTable(cmd);
            var          lista  = new List <VendedorModel>();

            foreach (DataRow linha in dt.Rows)
            {
                if (!string.IsNullOrEmpty(linha["idvendedor"].ToString()))
                {
                    var res = new VendedorModel();
                    res.Idvendedor = Convert.ToInt32(dt.Rows[0]["idvendedor"].ToString());
                    res.Nome       = dt.Rows[0]["nome"].ToString();
                    res.Sexo       = dt.Rows[0]["sexo"].ToString();
                    res.Email      = dt.Rows[0]["email"].ToString();
                    res.Senha      = dt.Rows[0]["senha"].ToString();
                    res.Nivel      = dt.Rows[0]["nivel"].ToString();
                    res.Status     = dt.Rows[0]["status"].ToString();
                    res.Foto       = (!Convert.IsDBNull(dt.Rows[0]["foto"]) ? (byte[])dt.Rows[0]["foto"] : null);
                    lista.Add(res);
                }
                else
                {
                    lista = null;
                }
            }
            return(lista);
        }
        public GraficoModel RetornarCARDS()
        {
            MySqlCommand cmd    = new MySqlCommand();
            InstrucaoDAO objDAL = new InstrucaoDAO();

            DataTable    dt;
            GraficoModel item = new GraficoModel();

            string faturamento = "0", cliente = "0", vendedor = "0", produto = "0";

            //CARD FATURAMENTO
            cmd.CommandText = @"select sum(total) as faturamento
                                from venda";

            dt = objDAL.retornoDataTable(cmd);

            if (dt != null)
            {
                faturamento = dt.Rows[0]["faturamento"].ToString();
            }

            //CARD CLIENTE
            cmd.CommandText = @"select count(idcliente) as cliente
                                from cliente";

            dt = objDAL.retornoDataTable(cmd);

            if (dt != null)
            {
                cliente = dt.Rows[0]["cliente"].ToString();
            }

            //CARD Produtos
            cmd.CommandText = @"select count(idproduto) as produto
                                from produto";

            dt = objDAL.retornoDataTable(cmd);

            if (dt != null)
            {
                produto = dt.Rows[0]["produto"].ToString();
            }

            //CARD Vendedor
            cmd.CommandText = @"select count(idvendedor) as vendedor
                                from vendedor";

            dt = objDAL.retornoDataTable(cmd);

            if (dt != null)
            {
                vendedor = dt.Rows[0]["vendedor"].ToString();
            }


            //MODEL
            if (dt != null)
            {
                item = new GraficoModel
                {
                    Faturamento = Convert.ToDecimal(faturamento),
                    Produto     = Convert.ToInt32(produto),
                    Cliente     = Convert.ToInt32(cliente),
                    Vendedor    = Convert.ToInt32(vendedor)
                };
            }
            return(item);
        }