public EstatisticaResult GetEstatisticas(int id = 0) { EstatisticaResult result = new EstatisticaResult(); if (id == 0) { result = new EstatisticaRepository(_sqlConn).GetEstatisticas(); } else { result = new EstatisticaRepository(_sqlConn).GetEstatisticasVendedor(id); } return(result); }
public ActionResult Index() { HomeModel model = new HomeModel(); InterfaceBazar bazar = new InterfaceBazar(); EstatisticaResult estatisticas = new EstatisticaResult(); if (User.IsInRole("Admin")) { estatisticas = bazar.GetEstatisticas(); if (!estatisticas.ProccessOk) { ViewBag.MensagemErro = "Erro ao Capturar Estatísticas"; return(View(model)); } } else { var user = new AspNetUsersRepository().GetUsuarioByUsername(User.Identity.Name); var getVendedor = bazar.GetVendedorByIdUser(user.Id); estatisticas = bazar.GetEstatisticas(getVendedor.Vendedor.Id); if (!estatisticas.ProccessOk) { ViewBag.MensagemErro = "Erro ao Capturar Estatísticas"; return(View(model)); } } model.Compradores = estatisticas.Compradores; model.Produtos = estatisticas.Produtos; if (estatisticas.ProdutosPagos != 0 && estatisticas.ProdutosVendidos != 0) { model.ProdutosPagos = (100 * estatisticas.ProdutosPagos) / estatisticas.ProdutosVendidos; } model.ProdutosVendidos = estatisticas.ProdutosVendidos; model.Vendas = estatisticas.Vendas; model.Vendedores = estatisticas.Vendedores; return(View(model)); }
public EstatisticaResult GetEstatisticas() { EstatisticaResult result = new EstatisticaResult(); SqlConnection conn = new SqlConnection(_sqlConn.SqlConnection); string sql = "SELECT COUNT(*) AS Compradores FROM Comprador"; try { conn.Open(); SqlCommand cmd = new SqlCommand(sql, conn); SqlDataReader reader = cmd.ExecuteReader(); while (reader.Read()) { result.Compradores = int.Parse(reader["Compradores"].ToString()); } } catch (Exception ex) { result.MsgCatch = "Erro ao contas os Compradores"; result.ProccessOk = false; result.MsgError = ex.ToString(); return(result); } finally { conn.Close(); } sql = "SELECT COUNT(*) AS Vendedores FROM Vendedor"; try { conn.Open(); SqlCommand cmd = new SqlCommand(sql, conn); SqlDataReader reader = cmd.ExecuteReader(); while (reader.Read()) { result.Vendedores = int.Parse(reader["Vendedores"].ToString()); } } catch (Exception ex) { result.MsgCatch = "Erro ao contas os Vendedores"; result.ProccessOk = false; result.MsgError = ex.ToString(); return(result); } finally { conn.Close(); } sql = "SELECT COUNT(*) AS Produtos FROM Produto"; try { conn.Open(); SqlCommand cmd = new SqlCommand(sql, conn); SqlDataReader reader = cmd.ExecuteReader(); while (reader.Read()) { result.Produtos = int.Parse(reader["Produtos"].ToString()); } } catch (Exception ex) { result.MsgCatch = "Erro ao contas os Produtos"; result.ProccessOk = false; result.MsgError = ex.ToString(); return(result); } finally { conn.Close(); } sql = "SELECT COUNT(*) AS ProdutosVendidos FROM ProdutoVendido"; try { conn.Open(); SqlCommand cmd = new SqlCommand(sql, conn); SqlDataReader reader = cmd.ExecuteReader(); while (reader.Read()) { result.ProdutosVendidos = int.Parse(reader["ProdutosVendidos"].ToString()); } } catch (Exception ex) { result.MsgCatch = "Erro ao contas os Produtos"; result.ProccessOk = false; result.MsgError = ex.ToString(); return(result); } finally { conn.Close(); } sql = "SELECT COUNT(*) AS Vendas FROM Venda"; try { conn.Open(); SqlCommand cmd = new SqlCommand(sql, conn); SqlDataReader reader = cmd.ExecuteReader(); while (reader.Read()) { result.Vendas = int.Parse(reader["Vendas"].ToString()); } } catch (Exception ex) { result.MsgCatch = "Erro ao contas os Produtos"; result.ProccessOk = false; result.MsgError = ex.ToString(); return(result); } finally { conn.Close(); } sql = "SELECT COUNT(*) AS ProdutoVendido from ProdutoVendido WHERE Status = 1"; try { conn.Open(); SqlCommand cmd = new SqlCommand(sql, conn); SqlDataReader reader = cmd.ExecuteReader(); while (reader.Read()) { result.ProdutosPagos = int.Parse(reader["ProdutoVendido"].ToString()); } } catch (Exception ex) { result.MsgCatch = "Erro ao contas os ProdutoPagos"; result.ProccessOk = false; result.MsgError = ex.ToString(); return(result); } finally { conn.Close(); } result.ProccessOk = true; return(result); }
public EstatisticaResult GetEstatisticasVendedor(int idVendedor) { EstatisticaResult result = new EstatisticaResult(); SqlConnection conn = new SqlConnection(_sqlConn.SqlConnection); string sql = "SELECT COUNT(*) AS Compradores FROM Comprador"; sql = "SELECT COUNT(*) AS Produtos FROM Produto WHERE IdVendedor = " + idVendedor; try { conn.Open(); SqlCommand cmd = new SqlCommand(sql, conn); SqlDataReader reader = cmd.ExecuteReader(); while (reader.Read()) { result.Produtos = int.Parse(reader["Produtos"].ToString()); } } catch (Exception ex) { result.MsgCatch = "Erro ao contas os Produtos"; result.ProccessOk = false; result.MsgError = ex.ToString(); return(result); } finally { conn.Close(); } sql = @"SELECT COUNT(*) AS ProdutosVendidos FROM ProdutoVendido INNER JOIN Produto ON Produto.Id = ProdutoVendido.IdProduto WHERE IdVendedor = " + idVendedor; try { conn.Open(); SqlCommand cmd = new SqlCommand(sql, conn); SqlDataReader reader = cmd.ExecuteReader(); while (reader.Read()) { result.ProdutosVendidos = int.Parse(reader["ProdutosVendidos"].ToString()); } } catch (Exception ex) { result.MsgCatch = "Erro ao contas os Produtos"; result.ProccessOk = false; result.MsgError = ex.ToString(); return(result); } finally { conn.Close(); } sql = @"SELECT COUNT(*) AS ProdVendido FROM ProdutoVendido INNER JOIN Produto ON Produto.Id = ProdutoVendido.IdProduto WHERE IdVendedor = " + idVendedor + " AND Status = 1"; try { conn.Open(); SqlCommand cmd = new SqlCommand(sql, conn); SqlDataReader reader = cmd.ExecuteReader(); while (reader.Read()) { result.ProdutosPagos = int.Parse(reader["ProdVendido"].ToString()); } } catch (Exception ex) { result.MsgCatch = "Erro ao contas os ProdutoPagos"; result.ProccessOk = false; result.MsgError = ex.ToString(); return(result); } finally { conn.Close(); } result.ProccessOk = true; return(result); }