private void btnBuscar_Click(object sender, EventArgs e) { try { if (txtDiaD.Enabled == true && cmbMesM.Enabled == false && cmbAnoM.Enabled == false && cmbAnoA.Enabled == false && txtDeT.Enabled == false && txtAteT.Enabled == false) { //BUSCA POR DIA Filtro.dataDia = txtDiaD.Text; SortableBindingList <Pedido> _lst = new SortableBindingList <Pedido>(); var lst = Filtro.lucroFiltrarPorDia(); foreach (var item in lst) { _lst.Add(item); } grdLucro.AutoGenerateColumns = false; grdLucro.DataSource = null; grdLucro.DataSource = _lst; grdLucro.Show(); decimal valorTotal = 0; foreach (DataGridViewRow col in grdLucro.Rows) { valorTotal = valorTotal + Convert.ToDecimal(col.Cells[3].Value); } lblCustoTotal.Text = $"Total de Vendas: R$ {valorTotal.ToString("N2")}"; } else if (txtDiaD.Enabled == false && cmbMesM.Enabled == true && cmbAnoM.Enabled == true && cmbAnoA.Enabled == false && txtDeT.Enabled == false && txtAteT.Enabled == false) { //BUSCA POR MES Filtro.dataMes = cmbMesM.Text; Filtro.dataAno = cmbAnoM.Text; SortableBindingList <Pedido> _lst = new SortableBindingList <Pedido>(); var lst = Filtro.lucroFiltrarPorMes(); foreach (var item in lst) { _lst.Add(item); } grdLucro.AutoGenerateColumns = false; grdLucro.DataSource = null; grdLucro.DataSource = _lst; grdLucro.Show(); decimal valorTotal = 0; foreach (DataGridViewRow col in grdLucro.Rows) { valorTotal = valorTotal + Convert.ToDecimal(col.Cells[3].Value); } lblCustoTotal.Text = $"Total de Vendas: R$ {valorTotal.ToString("N2")}"; } else if (txtDiaD.Enabled == false && cmbMesM.Enabled == false && cmbAnoM.Enabled == false && cmbAnoA.Enabled == true && txtDeT.Enabled == false && txtAteT.Enabled == false) { //BUSCA POR ANO Filtro.dataAno = cmbAnoA.Text; SortableBindingList <Pedido> _lst = new SortableBindingList <Pedido>(); var lst = Filtro.lucroFiltrarPorAno(); foreach (var item in lst) { _lst.Add(item); } grdLucro.AutoGenerateColumns = false; grdLucro.DataSource = null; grdLucro.DataSource = _lst; grdLucro.Show(); decimal valorTotal = 0; foreach (DataGridViewRow col in grdLucro.Rows) { valorTotal = valorTotal + Convert.ToDecimal(col.Cells[3].Value); } lblCustoTotal.Text = $"Total de Vendas: R$ {valorTotal.ToString("N2")}"; } else if (txtDiaD.Enabled == false && cmbMesM.Enabled == false && cmbAnoM.Enabled == false && cmbAnoA.Enabled == false && txtDeT.Enabled == true && txtAteT.Enabled == true) { //BUSCA POR TUDO Filtro.dataDeLucro = txtDeT.Text; Filtro.dataAteLucro = txtAteT.Text; SortableBindingList <Pedido> _lst = new SortableBindingList <Pedido>(); var lst = Filtro.lucroFiltrarPorTudo(); foreach (var item in lst) { _lst.Add(item); } grdLucro.AutoGenerateColumns = false; grdLucro.DataSource = null; grdLucro.DataSource = _lst; grdLucro.Show(); decimal valorTotal = 0; foreach (DataGridViewRow col in grdLucro.Rows) { valorTotal = valorTotal + Convert.ToDecimal(col.Cells[3].Value); } lblCustoTotal.Text = $"Total de Vendas: R$ {valorTotal.ToString("N2")}"; } } catch (Exception ex) { MessageBox.Show(ex.Message, "Erro", MessageBoxButtons.OK, MessageBoxIcon.Error); } }