public List <Lucro> DataReaderLucroParaList(SqlDataReader dataReader) { if (!dataReader.HasRows) { return(new List <Lucro>()); } List <Lucro> lucros = new List <Lucro>(); while (dataReader.Read()) { try { Lucro lucro = new Lucro { Valor = Convert.ToDouble(dataReader["Valor"]), Data = dataReader["Data"].ToString() }; lucros.Add(lucro); } catch (Exception e) { throw e; } } dataReader.Close(); return(lucros); }
private void txt_PrecoVenda_Leave(object sender, EventArgs e) { try { if (txt_PrecoVenda.Text != "") { txt_PrecoVenda.Text = Convert.ToDecimal(txt_PrecoVenda.Text.Trim()).ToString("0.00"); if (txt_PrecoVenda.Text != "" && txt_PrecoCusto.Text != "") { PrecoCusto = decimal.Parse(txt_PrecoCusto.Text); PrecoVenda = decimal.Parse(txt_PrecoVenda.Text); Lucro = PrecoVenda - PrecoCusto; txt_Lucro.Text = Lucro.ToString(); } } } catch (Exception ex) { MessageBox.Show(ex.Message, "Caixa Fácil", MessageBoxButtons.OK, MessageBoxIcon.Error); txt_PrecoVenda.Clear(); } }
public string Processar(EntidadeDominio entidade) { if (entidade.GetType().Name.Equals("Lucro")) { Lucro lucro = (Lucro)entidade; if (string.IsNullOrEmpty(lucro.DataInicial) || string.IsNullOrEmpty(lucro.DataFinal) || string.IsNullOrWhiteSpace(lucro.DataInicial) || string.IsNullOrWhiteSpace(lucro.DataFinal)) { return("Informe um período válido."); } if (lucro.DataInicial.ToString().Length < 10 || !lucro.DataInicial.ToString().Contains('/')) { return("Data inicial em formato incorreto."); } if (lucro.DataFinal.ToString().Length < 10 || !lucro.DataFinal.ToString().Contains('/')) { return("Data final em formato incorreto."); } if (lucro.DataInicial.Equals(lucro.DataFinal)) { return("A data inicial não pode ser igual à data final."); } if (Convert.ToDateTime(lucro.DataInicial) > Convert.ToDateTime(lucro.DataFinal)) { return("A data inicial não pode ser maior que a data final."); } if (Convert.ToDateTime(lucro.DataInicial).AddDays(30) > Convert.ToDateTime(lucro.DataFinal)) { return("Informe um período igual ou superior a 30 dias"); } } else { return("Deve ser consultado um lucro."); } return(null); }
public override List <EntidadeDominio> Consultar(EntidadeDominio entidade) { Lucro lucro = (Lucro)entidade; List <Lucro> lucros = new List <Lucro>(); string cmdTextoLucro; try { Conectar(); cmdTextoLucro = "SELECT PedidoId, SUM(ValorItem) AS ValorItem " + "INTO #tmpValoresItens " + "FROM " + "(" + "SELECT DISTINCT P.PedidoId, " + "((PI.PrecoUnitario - E.ValorCusto) * PI.Qtde) AS ValorItem " + "FROM Pedidos P " + "JOIN PedidosItens PI ON(P.PedidoId = PI.PedidoId) " + "JOIN Estoque E ON(PI.ItemId = E.ProdutoId)" + ") AS TB " + "GROUP BY PedidoId " + "SELECT PedidoId, SUM(ValorCupom) AS ValorCupom " + "INTO #tmpValoresCupons " + "FROM " + "( " + " SELECT DISTINCT P.PedidoId, " + " C.Valor AS ValorCupom " + " FROM Pedidos P " + " JOIN PedidosItens PI ON(P.PedidoId = PI.PedidoId) " + " JOIN PedidosCupons PC ON(PC.PedidoId = PI.PedidoId) " + " JOIN Cupons C ON(C.CupomId = PC.CupomId) " + ") AS TB " + "GROUP BY PedidoId " + "SELECT SUM(ValorTotalPedido) AS Valor, Data " + "FROM " + "(" + "SELECT " + " PedidoId, " + " Data, " + " CASE " + " WHEN ValorTotalPedido < 0 THEN 0 " + " ELSE ValorTotalPedido " + " END AS ValorTotalPedido " + "FROM " + "(" + "SELECT " + " P.PedidoId, " + " FORMAT(V.DataVenda, 'MM/yyyy') AS Data, " + " CASE " + " WHEN(TMP1.ValorItem - ISNULL(TMP2.ValorCupom, 0)) < 0 THEN 0 " + " ELSE(TMP1.ValorItem - ISNULL(TMP2.ValorCupom, 0)) " + " END AS ValorTotalPedido " + "FROM Pedidos P " + "JOIN #tmpValoresItens TMP1 ON(P.PedidoId = TMP1.PedidoId) " + "LEFT JOIN #tmpValoresCupons TMP2 ON(TMP1.PedidoId = TMP2.PedidoId) " + "JOIN StatusDePedidos SDP ON(P.Status = SDP.Status) " + "JOIN Vendas V ON(P.PedidoId = V.PedidoId) " + "WHERE P.Status <> 'P' AND P.Status <> 'R' AND P.Status <> 'C' AND " + "V.DataVenda BETWEEN @DataInicial AND @DataFinal " + ")AS Tb " + ")AS Tb2 " + "GROUP BY Data " + "DROP TABLE #tmpValoresItens " + "DROP TABLE #tmpValoresCupons "; SqlCommand comandoLucro = new SqlCommand(cmdTextoLucro, conexao); comandoLucro.Parameters.AddWithValue("@DataInicial", Convert.ToDateTime(lucro.DataInicial)); comandoLucro.Parameters.AddWithValue("@DataFinal", Convert.ToDateTime(lucro.DataFinal)); SqlDataReader drLucro = comandoLucro.ExecuteReader(); comandoLucro.Parameters.Clear(); lucros = DataReaderLucroParaList(drLucro); comandoLucro.Dispose(); } catch (SqlException e) { throw e; } catch (InvalidOperationException e) { throw e; } finally { Desconectar(); } return(lucros.ToList <EntidadeDominio>()); }