He añadio una pequeña mejora para contar las veces que se muestra un banner.
Añado una nueva columna en la tabla "tblAnuncios":
Creo el procedimiento almacenado "PA_AnunciosContador"
Código SQL:
Ver originalCREATE PROCEDURE PA_AnunciosContador (@id INT)
AS
BEGIN
UPDATE tblAnuncios SET AdCounter = AdCounter + 1 WHERE ID = @id
END
Y el control:
Código vb:
Ver originalProtected Overrides Sub Render(ByVal writer As System.Web.UI.HtmlTextWriter)
Dim ar As New tmpAdRotator()
Dim dt As DataTable = DTBanners(KeywordFilter)
If dt.Rows.Count <> 0 Then
ar.DataSource = dt
ar.DataBind()
ar.Target = "_blank"
Me.Controls.Add(ar)
Dim cmd As New SqlCommand("PA_AnunciosContador", conSQL)
cmd.CommandType = CommandType.StoredProcedure
cmd.Parameters.AddWithValue("@id", ar.EventArgs.AdProperties("ID"))
Dim generado As Boolean = False
Dim Height As Unit = CInt(ar.EventArgs.AdProperties("Height"))
Dim Width As Unit = CInt(ar.EventArgs.AdProperties("Width"))
If MaxWidth.ToString <> "" Then
If ar.EventArgs.AdProperties("Width") > MaxWidth.Value Then
Height = (MaxWidth.Value * Height.Value / Width.Value) - 5
Width = MaxWidth
End If
End If
ar.Target = _
IIf(String.Format("{0}", ar.EventArgs.AdProperties("Target")) <> "", _
ar.EventArgs.AdProperties("Target"), "_blank")
If ar.EventArgs.ImageUrl.ToLower.IndexOf(".swf") <> -1 Then
Dim StringFormat As StringBuilder = New StringBuilder("")
StringFormat.Append("<object type='application/x-shockwave-flash' data='{2}' width='{0}' height='{1}'>")
StringFormat.Append("<param name='movie' value='{2}' />")
StringFormat.Append("<img src='{2}' width='{0}' height='{1}' alt='Publicidad' />")
StringFormat.Append("</object>")
Dim OutPutString As StringBuilder = New StringBuilder()
OutPutString.AppendFormat(StringFormat.ToString, _
Width, _
Height, _
ResolveUrl(ar.EventArgs.ImageUrl))
writer.Write(OutPutString.ToString)
generado = True
Else
Me.Controls.Clear()
ar.Width = Width
ar.Height = Height
ar.ToolTip = ar.EventArgs.AdProperties("AlternateText")
Me.Controls.Add(ar)
MyBase.Render(writer)
generado = True
End If
If generado Then
Try
cmd.Connection.Open()
cmd.ExecuteNonQuery()
Catch ex As Exception
'No se gestiona la excepción
Finally
cmd.Connection.Close()
End Try
End If
End If
End Sub
Para otro día el control de clicks.
Un saludo.