locked
Query Filter Issues RRS feed

  • Question

  • User662762443 posted

    When filtering by date I can not load gridview with data, I do not know if it is related to my code that may be wrong. Can anybody help me?

    using Dominio.APL;
    using Dominio.Domain;
    using dap.Models;
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using System.Web.UI;
    using System.Web.UI.HtmlControls;
    using System.Web.UI.WebControls;
    
    namespace dapView.Reports.RelFinancReleasedBaseMonth
    {
        public partial class RelFinancReleasedBaseMonth : System.Web.UI.Page
        {
            private AplFinancing aplFinancing = new AplFinancing();
            private List<Financing> financing= new List<Financing>();
            private static bool keyJS { get; set; }
            protected void Page_Load(object sender, EventArgs e)
            {
                keyJS = true;
               
            }
        
            protected void btnConsult_Click(object sender, EventArgs e)
            {
                LoadsReport();
            }
    
            public void LoadsReport()
            {
                
                financing = aplFinancing .listAll();
                var dados = (from financing in financing
                             where DateTime.Compare(financing.BaseMonth, Convert.ToDateTime(txtBaseMonth.Text.ToString())) == 0
    
                             group financing by new { financing.Cod, financing.Company.Stateregistration, financing.Company.CompanyName, financing.Company.Cnpj, financing.Company.Shortname, financing.YearBaseMonth } into g
                             select new
                             {
                                 codigo = g.Key.Cod,
                                 AnoMesBase = g.Key.YearBaseMonth,
                                 InscricaoEstadual = g.Key.Stateregistration,
                                 RazaoSocial = g.Key.CompanyName,
                                 Cnpj = g.Key.Cnpj,
                                 NmeAbreviado = g.Key.Shortname
                             }).OrderBy(o => o.codigo).ToList();
                if (dados.Count() > 0)
                {
                    //Loads query gridview data
                    gv.DataSource = dados;
                    gv.DataBind();
                    gv.UseAccessibleHeader = true;
                    gv.HeaderRow.TableSection = TableRowSection.TableHeader;
    
                    //Loads gridview data used for printing
                    gvPrint.DataSource = dados;
                    gvPrint.DataBind();
                    gvPrint.UseAccessibleHeader = true;
                    gvPrint.HeaderRow.TableSection = TableRowSection.TableHeader;
    
                  
                }
                else
                {
                    if (keyJS) chamarSwal("Alert", "No funding found for that date.");
                   
                }
    
            }
    
            private void chamarSwal(string tipo, string mensagem)
            {
                var body = (HtmlGenericControl)(Page.Master.FindControl("body"));
                body.Attributes["onload"] = $"{tipo}(\"{mensage}\")";
                keyJS = false;
            }
    
        }
    }
    using Dominio.DataAccess;
    using Dominio.Domain;
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    
    namespace Domain.APL
    {
        public class AplFinancing
        {
            public void gravar(Financing financing)
            {
                FinancingDAO.InsertOrUpdate(financing);
            }
    
            public void delete(Financing financing)
            {
                FinancingDAO.Delete(financing);
            }
    
            public List<Financing> listAll()
            {
                return FinancingDAO.ListAll();
            }
    
        }
    } 
    using Dominio.Domain;
    using NHibernate;
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    
    namespace Domain.DataAccess
    {
        public class FinancingDAO
        {
            public static List<Financing> ListAll()
            {
                try
                {
                    ISession sessao = NhibernateHelper.CurrentSession;
                    Financing financing= new Financing();
                    ICriteria criteria = session.CreateCriteria(financing.GetType());
                    return criteria.List<Financing>().ToList();
                }
                catch (Exception e)
                {
                    throw new Exception(e.ToString());
                }
            }
       }
    }
    <%@ Page Title="" Language="C#" MasterPageFile="~/Content/MasterPage.Master" AutoEventWireup="true"
    
        CodeBehind="RelFinanciamento.aspx.cs" Inherits="dapView.Relatorios.RelFinancLiberadoMesBase.RelFinancLiberadoMesBase" %>
    
     
    
    <asp:Content ID="head" ContentPlaceHolderID="headPlaceHolder" runat="server">
    
        <link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.6.3/css/all.css">
    
        <script src="../JsRelatorioFinancLiberadoMesBase.js"></script>
    
        <script>
    
            var d = "16/09/2019" // date received from card
    
            function filldate() {
    
                document.getElementById('cardexpirydate').value = d.split('/').reverse().join("-");
    
            }
    
        </script>
    
        <script>
    
            function exibir_ocultar(val) {
    
                if (val.value == 'LiberadoMesBase') {
    
                    document.getElementById('periodo').style.display = 'none';
    
                    document.getElementById('MesBase').style.display = 'block';
    
                    document.getElementById('periodo').style.display = 'none';
    
                }
    
                else {
    
                    document.getElementById('periodo').style.display = 'block';
    
                    document.getElementById('MesBase').style.display = 'none';
    
                }
    
            };
    
        </script>
    
    </asp:Content>
    
    <asp:Content ID="ContentForm" ContentPlaceHolderID="formPlaceHolder" runat="server">
    
        <asp:ScriptManager runat="server"></asp:ScriptManager>
    
        <div class="row">
    
            <div class="col-md-12">
    
                <div class="content-box">
    
                    <div class="box-title">Financiamento</div>
    
                    <div class="box-body">
    
                        <div id="triage">
    
                            <label for="category">Liberado:</label>
    
                            <div class="form-inline">
    
                             
    
                                <div class="col-md-2">
    
                                    <label class="radio-inline control-label">
    
                                        <input checked="checked" name="TaskLog.TaskTypeId" type="radio" value="2">
    
                                        SIM
    
                                    </label>
    
                                    <label class="radio-inline control-label">
    
                                        <input id="TaskLog_TaskTypeId" name="TaskLog.TaskTypeId" type="radio" value="1">
    
                                        NÃO
    
                                    </label>
    
                                </div>
    
                                 <div id="category-select">
    
     
    
                                    <select onchange="exibir_ocultar(this)" class="col-md-3 form-control" id="category" name="category" style="width: auto">
    
                                        <option value="LiberadoMesBase">-----------Selecione----------</option>
    
                                        <option value="LiberadoMesBase">Mês Base</option>
    
                                        <option value="LiberadoPeriodo">Período</option>
    
                                    </select>
    
                                </div>
    
                            </div>
    
                            <br />
    
                            <div class="row">
    
     
    
                                <div class="form-group">
    
                                    <label class="radio-inline control-label">
    
                                        <input type="radio" name="optradio" checked>Sim</label>
    
                                    <label class="radio-inline">
    
                                        <input type="radio" name="optradio">Não</label>
    
                                </div>
    
                                <br />
    
                                <div id="periodo">
    
                                    <asp:TextBox type="Month" Style="width: 10%" runat="server" ClientIDMode="Static" class="form-control " ID="TextBox1" MaxLength="30"></asp:TextBox>
    
                                    <br />
    
                                </div>
    
                                <br />
    
                                <div id="MesBase">
    
                                    <asp:TextBox type="date" Style="width: 10%" runat="server" ClientIDMode="Static" class="form-control " ID="TextBox2" MaxLength="30"></asp:TextBox>
    
                                    <br />
    
                                </div>
    
     
    
                            </div>
    
     
    
                        </div>
    
     
    
                        <div class="row">
    
                            <div class="content-box content-box-tabela" id="tabela" style="visibility: hidden">
    
                                <asp:GridView class="col-md-12" CssClass="tabela-padrao tabela-padrao-borda dataTable" runat="server" AutoGenerateColumns="False" PageSize="9" ID="gv" Width="100%">
    
                                    <Columns>
    
                                        <asp:TemplateField HeaderText="Empresa" ItemStyle-HorizontalAlign="Left">
    
                                            <ItemTemplate>
    
                                                <asp:Label ID="lblCodigo" runat="server" Text='<%# Bind("Codigo") %>'></asp:Label>
    
                                            </ItemTemplate>
    
                                        </asp:TemplateField>
    
                                        <asp:TemplateField HeaderText="Valor Financiamento" ItemStyle-HorizontalAlign="Center">
    
                                            <ItemTemplate>
    
                                                <asp:Label ID="lblValorFinanciamento" runat="server" Text='<%# Bind("ValorFinanciamento") %>'></asp:Label>
    
                                            </ItemTemplate>
    
                                        </asp:TemplateField>
    
                                        <asp:TemplateField HeaderText="Inscricao Estadual" ItemStyle-HorizontalAlign="Center">
    
                                            <ItemTemplate>
    
                                                <asp:Label ID="lblInscricaoEstadual" runat="server" Text='<%# Bind("InscricaoEstadual") %>'></asp:Label>
    
                                            </ItemTemplate>
    
                                        </asp:TemplateField>
    
                                        <asp:TemplateField HeaderText="Ano mes base" ItemStyle-HorizontalAlign="Right">
    
                                            <ItemTemplate>
    
                                                <asp:Label ID="lblAnoMesBase" runat="server" Text='<%# Bind("AnoMesBase") %>'></asp:Label>
    
                                            </ItemTemplate>
    
                                        </asp:TemplateField>
    
                                    </Columns>
    
                                    <PagerStyle CssClass="" HorizontalAlign="Center" />
    
                                </asp:GridView>
    
                            </div>
    
                        </div>
    
                    </div>
    
                    <div class="box-footer">
    
                        <button runat="server" class="btn btn-padrao" id="btnConsultar" onserverclick="btnConsultar_Click">Consultar</button>
    
                    </div>
    
                </div>
    
     
    
                <%--IMPRIMIR--%>
    
                <div class="container" style="visibility: hidden" id="ConteinerImprimir">
    
                    <div class="table" runat="server" style="margin: 0 auto; width: auto;">
    
                        <div class="row">
    
                            <div class="col-lg-12">
    
                                <img src="http://internet.sefaz.es.gov.br/imagens/topo_brasao.png" alt="">
    
                                <br>
    
                                <br>
    
                            </div>
    
                        </div>
    
                        <div class="row" runat="server" style="border-bottom: 2px solid #B0BEC5">
    
                            <div class="col-lg-5">
    
                                <strong>Financiamento</strong>
    
                            </div>
    
                            <div class="col-lg-5" style="text-align: end;" runat="server" id="totalRegistros"></div>
    
                        </div>
    
                    </div>
    
                    <div class="row">
    
     
    
                        <div class="content-box content-box-tabela">
    
                            <asp:GridView class="col-md-12 grid" runat="server" AutoGenerateColumns="False" PageSize="9" ID="gvImprimir" GridLines="None"
    
                                RowStyle-HorizontalAlign="Center" Width="100%">
    
                                <Columns>
    
                                    <asp:TemplateField HeaderText="Empresa" ItemStyle-HorizontalAlign="Left">
    
                                        <ItemTemplate>
    
                                            <asp:Label ID="lblCodigo" runat="server" Text='<%# Bind("Codigo") %>'></asp:Label>
    
                                        </ItemTemplate>
    
                                    </asp:TemplateField>
    
                                    <asp:TemplateField HeaderText="Valor Financiamento" ItemStyle-HorizontalAlign="Center">
    
                                        <ItemTemplate>
    
                                            <asp:Label ID="lblValorFinanciamento" runat="server" Text='<%# Bind("ValorFinanciamento") %>'></asp:Label>
    
                                        </ItemTemplate>
    
                                    </asp:TemplateField>
    
                                    <asp:TemplateField HeaderText="Inscricao Estadual" ItemStyle-HorizontalAlign="Center">
    
                                        <ItemTemplate>
    
                                            <asp:Label ID="lblInscricaoEstadual" runat="server" Text='<%# Bind("InscricaoEstadual") %>'></asp:Label>
    
                                        </ItemTemplate>
    
                                    </asp:TemplateField>
    
                                    <asp:TemplateField HeaderText="Ano mes base" ItemStyle-HorizontalAlign="Right">
    
                                        <ItemTemplate>
    
                                            <asp:Label ID="lblAnoMesBase" runat="server" Text='<%# Bind("AnoMesBase") %>'></asp:Label>
    
                                        </ItemTemplate>
    
                                    </asp:TemplateField>
    
                                </Columns>
    
                                <PagerStyle CssClass="" HorizontalAlign="Center" />
    
                            </asp:GridView>
    
                        </div>
    
                    </div>
    
                </div>
    
            </div>
    
        </div>
    
    </asp:Content>
    
     

    Please help me, I can't filter by date, my application is aspnet webforms. Aprenda a pronunciar When the date is by period is from dd / MM / yyyy to dd / MM / yyyy, but when it is base month is only MM / yyyy. If I choose by base month, the date by period mask should be invisible to the user, if I choose the period option in the comboBox the date by month mask should also be invisible to the user.

    Wednesday, October 16, 2019 11:24 AM

Answers

  • User-719153870 posted

    Hi rtaVix,

     Aprenda a pronunciar When the date is by period is from dd / MM / yyyy to dd / MM / yyyy, but when it is base month is only MM / yyyy.

    This is little confusing, i guess below is where you get your Filter Issue?

    where DateTime.Compare(financing.BaseMonth, Convert.ToDateTime(txtBaseMonth.Text.ToString())) == 0

    What type is your BaseMonth then? since it seems no where to be found in your code and what kind of value will you input into your txtBaseMonth? Is there any sample about these two parameter?

    Maybe you can use Date Time. To String Method to update your code to change your BaseMonth to the format you need.

    Best Regard,

    Yang Shen

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, October 17, 2019 4:12 AM