Torna al Thread
Sub CaricaProdotti()
Dim MYSQL As String
Dim MyDS As DataSet
Dim MyDA As Data.OleDb.OleDbDataAdapter
Dim ID_cat As String
Dim cerca, TxtCerca As String
ID_cat = Request.QueryString("ID_cat")
cerca = Request.QueryString("cerca")
TxtCerca = Request.QueryString("TxtCerca")
Dim Conn As New Data.OleDb.OleDbConnection(System.Configuration.ConfigurationManager.AppSettings("ConnectionString"))
Conn.Open()
If cerca = "1" And TxtCerca = "" Then
TxtProdotti.Text = "Inserisci un criterio per la ricerca."
Else
If cerca = "1" And TxtCerca <> "" Then
MYSQL = "SELECT * FROM tab_prodotti WHERE titolo_prodotto LIKE '%" + TxtCerca + "%' AND elimina_prodotto = false ORDER BY " + session("ordina")
Else
If cerca = "" And TxtCerca = "" Then
If ID_cat <> "" Then
MYSQL = "SELECT * FROM tab_prodotti WHERE id_tree = " + ID_cat + " AND elimina_prodotto = false ORDER BY " + session("ordina")
Else
MYSQL = "SELECT * FROM tab_prodotti WHERE elimina_prodotto = false ORDER BY " + session("ordina")
End If
End If
End If
Dim startRecord As Integer = (Int32.Parse(CurrentPage) - 1) * Int32.Parse(PageSize)
MyDA = New Data.OleDb.OleDbDataAdapter(MYSQL, Conn)
MyDS = New DataSet
MyDA.Fill(MyDS, startRecord, Int32.Parse(PageSize), "tab_prodotti")
If Not MyDS Is Nothing And MyDS.Tables(0).Rows.Count > 0 Then
RptNews.DataSource = MyDS
RptNews.DataMember = "tab_prodotti"
RptNews.DataBind()
' conta i record totali
Dim ArrayCount As Array = Split(MYSQL, "ORDER BY")
Dim strSQLCount = ArrayCount(0)
' ricavo la query count
strSQLCount = "SELECT COUNT(*) as Totale " & strSQLCount.Substring(strSQLCount.IndexOf(" FROM "))
Dim myCommand As Data.OleDb.OleDbCommand = New Data.OleDb.OleDbCommand(strSQLCount, Conn)
Dim reader As Data.OleDb.OleDbDataReader = myCommand.ExecuteReader()
' conto i risultati
reader.Read()
TotalSize = reader("totale")
reader.Close()
' mostra avviso in alto con il numero dei risultati
If TotalSize = 0 Then
TxtProdotti.Text = "Non ci sono risultati per questa ricerca"
Else
TotalPages = Int32.Parse(TotalSize) \ Int32.Parse(PageSize) + 1
' fix per numero di pagine
If Fix(TotalSize / PageSize) = TotalSize / PageSize Then TotalPages = TotalPages - 1
If TotalSize = 1 Then
'TxtProdotti.Text += "Un risultato"
Else
'TxtProdotti.Text += TotalSize & " risultati"
End If
' fix per record finale
Dim EndRecords As Integer = startRecord + Int32.Parse(PageSize)
If EndRecords > TotalSize Then EndRecords = TotalSize
'TxtProdotti.Text += " - Pagina " & CurrentPage & " su " & TotalPages & " in totale - da " & startRecord + 1 & " a "
End If
If TotalSize = 0 Then
Paginazione.visible = False
End If
' costruisci la paginazione
BuildPagers()
Else
TxtProdotti.Text = "Nessun prodotto per la categoria prescelta.<br>Selezionare eventuali sottocategorie."
End If
End If
Conn.Close()
End Sub