Getting Values from GridFilters do save on database

  1. #1

    Getting Values from GridFilters do save on database

    Hi all,

    I am trying to get the values of my gridfilters to save on database for the user can select then and set in execution time on the grid.


    The set is working good, but the get dont.


    The GridFilters:
    <plugins>
                    <ext:GridFilters runat="server" ID="grdFilterGeral" Local="false">
                        <filters>
                            <ext:StringFilter DataIndex="cod_pedido" />
                            <ext:StringFilter DataIndex="produto" />
                            <ext:StringFilter DataIndex="cliente" />
                            <ext:StringFilter DataIndex="segmento" />
                            <ext:StringFilter DataIndex="endereco" />
                            <ext:StringFilter DataIndex="cidade" />
                            <ext:StringFilter DataIndex="status" />
                            <ext:StringFilter DataIndex="pendencia" />
                            <ext:NumericFilter DataIndex="valor_req" />
                            <ext:NumericFilter DataIndex="valor_n_req" />
                            <ext:DateFilter DataIndex="dt_pedido" AfterText="Depois de" BeforeText="Antes de">
                                <datepickeroptions runat="server" todaytext="Now" />
                            </ext:DateFilter>
                            <ext:DateFilter DataIndex="dt_rfb" AfterText="Depois de" BeforeText="Antes de" >
                                <datepickeroptions runat="server" todaytext="Now" />
                            </ext:DateFilter>
                            <ext:DateFilter DataIndex="dt_canc" AfterText="Depois de" BeforeText="Antes de" >
                                <datepickeroptions runat="server" todaytext="Now" />
                            </ext:DateFilter>
                            <ext:StringFilter DataIndex="lp" />
                            <ext:DateFilter DataIndex="dt_rfs" AfterText="Depois de" BeforeText="Antes de" >
                                <datepickeroptions runat="server" todaytext="Now"/>
                            </ext:DateFilter>
                        </Filters>
                    </ext:GridFilters>
                    </Plugins>

    CodeBehind (where i try to get the values to save in the database):

            If e.ExtraParams("fltGeral").ToString = "{}" Then
                Mensagem("Não existe nenhum Filtro ativo no momento.", Coolite.Ext.Web.MessageBox.Icon.INFO, Coolite.Ext.Web.MessageBox.Button.OK, "Salvar Filtro")
            ElseIf txtGeral.Text = vbNullString Then
                Mensagem("Você deve definir um nome para o Filtro que deseja Salvar.", Coolite.Ext.Web.MessageBox.Icon.INFO, Coolite.Ext.Web.MessageBox.Button.OK, "Salvar Filtro")
                txtGeral.Focus()
            Else
                Dim Values As String = vbNullString
                Dim sf As Coolite.Ext.Web.StringFilter
                Dim nf As Coolite.Ext.Web.NumericFilter
                Dim df As Coolite.Ext.Web.DateFilter
                Dim I As Integer
                For I = 0 To 7
                    sf = grdFilterGeral.Filters(I)
                    sf.ParentGrid = grdGeral
                    If I = 0 Then
                        Values = sf.Value
                    Else
                        Values = Values &amp; ", " &amp; sf.Value
                    End If
                Next
                nf = grdFilterGeral.Filters(8)
                nf.ParentGrid = grdGeral
                If nf.EqualValue = Nothing Then
                    Values = Values &amp; ", " &amp; nf.GreaterThanValue &amp; ", " &amp; nf.LessThanValue
                Else
                    Values = Values &amp; ", " &amp; nf.EqualValue &amp; ", NULL"
                End If
                nf = grdFilterGeral.Filters(9)
                nf.ParentGrid = grdGeral
                If nf.EqualValue = Nothing Then
                    Values = Values &amp; ", " &amp; nf.GreaterThanValue &amp; ", " &amp; nf.LessThanValue
                Else
                    Values = Values &amp; ", " &amp; nf.EqualValue &amp; ", NULL"
                End If
                df = grdFilterGeral.Filters(10)
                df.ParentGrid = grdGeral
                If df.OnValue = Nothing Then
                    Values = Values &amp; df.AfterValue &amp; ", " &amp; df.BeforeValue
                Else
                    Values = Values &amp; df.OnValue &amp; ", NULL"
                End If
                df = grdFilterGeral.Filters(11)
                df.ParentGrid = grdGeral
                If df.OnValue = Nothing Then
                    Values = Values &amp; df.AfterValue &amp; ", " &amp; df.BeforeValue
                Else
                    Values = Values &amp; df.OnValue &amp; ", NULL"
                End If
                df = grdFilterGeral.Filters(12)
                df.ParentGrid = grdGeral
                If df.OnValue = Nothing Then
                    Values = Values &amp; df.AfterValue &amp; ", " &amp; df.BeforeValue
                Else
                    Values = Values &amp; df.OnValue &amp; ", NULL"
                End If
                sf = grdFilterGeral.Filters(13)
                sf.ParentGrid = grdGeral
                Values = Values &amp; ", " &amp; sf.Value
                df = grdFilterGeral.Filters(14)
                df.ParentGrid = grdGeral
                If df.OnValue = Nothing Then
                    Values = Values &amp; df.AfterValue &amp; ", " &amp; df.BeforeValue
                Else
                    Values = Values &amp; df.OnValue &amp; ", NULL"
                End If
                Executar("INSERT INTO time.tb_filtros (cod_usuario, nome, cod_pedido, produto, segmento, endereco, cidade, status, pendencia, valor_min_req, valor_max_req, valor_min_n_req, valor_max_n_req, dt_min_pedido, dt_max_pedido, dt_min_rfb, dt_max_rfb, servico, dt_min_canc, dt_max_canc, lp, dt_min_rfs, dt_max_rfs) VALUES (" &amp; Session("CodigoUsuario").ToString &amp; ", " &amp; Aspas(txtGeral.Text, False) &amp; ", " &amp; Values &amp; ")")
                txtGeral.Text = vbNullString
                strFiltroGeral.DataSource = RS("SELECT cod_filtro, nome FROM time.tb_filtros WHERE cod_usuario = " &amp; Session("CodigoUsuario").ToString &amp; " ORDER BY filtro")
                strFiltroGeral.DataBind()
                cmbGeralFiltro.SetValue(txtGeral.Text)
            End If

    What is wrong ??? Any clue ???


    Regards,


    Puia.
  2. #2

    RE: Getting Values from GridFilters do save on database

    The idea is to save the values to a hidden field using javascript before the roundtrip to the server

    http://forums.ext.net/showthread.php?4106

    hth
    Last edited by geoffrey.mcgill; Jan 10, 2011 at 6:18 PM.
  3. #3

    RE: Getting Values from GridFilters do save on database

    Tks Peter,

    But i found another solution, as follow:


    
    
            If e.ExtraParams("fltGeral").ToString = "{}" Then
                Mensagem("Não existe nenhum Filtro ativo no momento.", Coolite.Ext.Web.MessageBox.Icon.INFO, Coolite.Ext.Web.MessageBox.Button.OK, "Salvar Filtro")
            ElseIf txtGeral.Text = vbNullString Then
                Mensagem("Você deve definir um nome para o Filtro que deseja Salvar.", Coolite.Ext.Web.MessageBox.Icon.INFO, Coolite.Ext.Web.MessageBox.Button.OK, "Salvar Filtro")
                txtGeral.Focus()
            Else
                Dim Fields As String = vbNullString
                Dim Values As String = vbNullString
                Dim Valores() As String = Nothing
                Valores = Split(Replace(Replace(Replace(e.ExtraParams("fltGeral").ToString(), "{", ""), "}", ""), Chr(34), ""), ",")
                For I = 0 To UBound(Valores)
                    If InStr(Valores(I), "field") > 0 Then
                        If Fields = vbNullString Then
                            If InStr(Valores(I + 1), "date") > 0 Or InStr(Valores(I + 1), "numeric") > 0 Then
                                Fields = Right(Valores(I), Len(Valores(I)) - InStr(Valores(I), ":")) &amp; "_" &amp; Right(Valores(I + 2), Len(Valores(I + 2)) - InStr(Valores(I + 2), ":"))
                            Else
                                Fields = Right(Valores(I), Len(Valores(I)) - InStr(Valores(I), ":"))
                            End If
                        Else
                            If InStr(Valores(I + 1), "date") > 0 Or InStr(Valores(I + 1), "numeric") > 0 Then
                                Fields = Fields &amp; ", " &amp; Right(Valores(I), Len(Valores(I)) - InStr(Valores(I), ":")) &amp; "_" &amp; Right(Valores(I + 2), Len(Valores(I + 2)) - InStr(Valores(I + 2), ":"))
                            Else
                                Fields = Fields &amp; ", " &amp; Right(Valores(I), Len(Valores(I)) - InStr(Valores(I), ":"))
                            End If
                        End If
                    ElseIf InStr(Valores(I), "value") > 0 Then
                        If InStr(Valores(I - 2), "date") > 0 Then
                            If Values = vbNullString Then
                                Values = "'" &amp; Right(Right(Valores(I), Len(Valores(I)) - InStr(Valores(I), ":")), 4) &amp; "-" &amp; Left(Right(Valores(I), Len(Valores(I)) - InStr(Valores(I), ":")), 2) &amp; "-" &amp; Mid(Right(Valores(I), Len(Valores(I)) - InStr(Valores(I), ":")), 4, 2) &amp; "'"
                            Else
                                Values = Values &amp; ", '" &amp; Right(Right(Valores(I), Len(Valores(I)) - InStr(Valores(I), ":")), 4) &amp; "-" &amp; Left(Right(Valores(I), Len(Valores(I)) - InStr(Valores(I), ":")), 2) &amp; "-" &amp; Mid(Right(Valores(I), Len(Valores(I)) - InStr(Valores(I), ":")), 4, 2) &amp; "'"
                            End If
                        Else
                            If Values = vbNullString Then
                                Values = Aspas(Right(Valores(I), Len(Valores(I)) - InStr(Valores(I), ":")), False)
                            Else
                                Values = Values &amp; ", " &amp; Aspas(Right(Valores(I), Len(Valores(I)) - InStr(Valores(I), ":")), False)
                            End If
                        End If
                    End If
                Next
                Executar("INSERT INTO time.tb_filtros (cod_usuario, nome, " &amp; Fields &amp; ") VALUES (" &amp; Session("CodigoUsuario").ToString &amp; ", " &amp; Aspas(txtGeral.Text, False) &amp; ", " &amp; Values &amp; ")")
                txtGeral.Text = vbNullString
                strFiltroGeral.DataSource = RS("SELECT cod_filtro, nome FROM time.tb_filtros WHERE cod_usuario = " &amp; Session("CodigoUsuario").ToString &amp; " ORDER BY nome")
                strFiltroGeral.DataBind()
                cmbGeralFiltro.SetValue(txtGeral.Text)
            End If
        End Sub

    I get the parameter and parse him to save on database.


    Tks for your help anyway.


  4. #4

    RE: Getting Values from GridFilters do save on database

    Dudes,

    Another question:


    If the user only put AfterDate, for example. How to set only this value to the date filter and ignore the other ???


    SetValue(av, bv) return a error if one of the params are nothing or null.
    df.SetValue(date1, date2)
    df.SetActive(True)

    And if i pass the params to the property datefilter.BeforeValue = date, for example the filter dont activate.
    df.DateBefore = date1
    df.DateAfter = date2
    df.SetActive(True)

    Any suggestion ???




Similar Threads

  1. [CLOSED] Save ext:GridPanel.getState() in SQL Server database
    By supera in forum 2.x Legacy Premium Help
    Replies: 2
    Last Post: May 03, 2012, 11:17 AM
  2. Replies: 12
    Last Post: Feb 20, 2012, 1:58 PM
  3. How to save DataView to the database?
    By wkcode in forum 1.x Help
    Replies: 1
    Last Post: Jan 19, 2011, 8:24 AM
  4. [CLOSED] How to get GridFilters Values (server side)
    By VALUELAB in forum 1.x Legacy Premium Help
    Replies: 10
    Last Post: May 05, 2009, 1:03 PM
  5. Save in database
    By flaviodamaia in forum 1.x Help
    Replies: 4
    Last Post: Nov 06, 2008, 7:16 AM

Posting Permissions