Class : gestion de tickets consommables

Soyez le premier à donner votre avis sur cette source.

Snippet vu 12 194 fois - Téléchargée 31 fois

Contenu du snippet

Cette classe permet facilement de gérer des tickets consommables, vous pouvez créer un ticket unique et le consommer ! ce code est simple, et vous pourrez très facilement l'utiliser sous SQLServer ou MySQL (la version publiée est sous SQLServer).
et voici le script SQL pour la création de la table :
CREATE TABLE [dbo].[AA_TICKETS] (
[TIC_ID] [nvarchar] (30) COLLATE French_CI_AS NOT NULL ,
[TIC_Valid] [int] NOT NULL ,
[TIC_MAILON] [nvarchar] (255) COLLATE French_CI_AS NULL ,
[TIC_MAILOFF] [nvarchar] (255) COLLATE French_CI_AS NULL
) ON [PRIMARY]

Je l'utilise pour mon site de <a href="http://www.margo-cartes-virtuelles.com" target="_blanc">cartes virtuelles gratuites</a>

Bon Code !

Source / Exemple :


Imports System.Data.SqlClient
Imports System.Configuration

    Public Class Tickets

        Public Function NewTicket(ByVal MAILOFF As String) As String
            If IsDejaParrain(MAILOFF) Then
                Return ""
            Else
                Dim tick As New AA_ENGINE.cryptologie.Password(20)
                Dim tictemp As String = tick.strpassword
                While (IsTicketExist(tictemp))
                    tick.regenerate(20)
                    tictemp = tick.strpassword
                End While
                If Addticket(tictemp) Then
                    Return tictemp
                Else
                    Return ""
                End If
            End If
        End Function

        Public Function Addticket(ByVal Idticket As String) As Boolean
            Dim NbRecord As Integer = 0
            Dim retour As Boolean = False
            Dim conn As New SqlConnection(ConfigurationSettings.AppSettings("ConnectionString"))
            Dim com As New SqlCommand("INSERT INTO AA_TICKETS (TIC_ID) VALUES ('" & Replace(Idticket, "'", "''") & "')", conn)
            Try
                conn.Open()
                NbRecord = com.ExecuteNonQuery()
                If NbRecord > 0 Then
                    retour = True
                Else
                    retour = False
                End If
            Catch ex As Exception
                retour = False
            Finally
                com = Nothing
                conn.Close()
                conn = Nothing
            End Try
            Return retour
        End Function

        Public Function IsTicketExist(ByVal Idticket As String) As Boolean
            Dim retour As Boolean = False
            Dim lereader As SqlDataReader
            Dim conn As New SqlConnection(ConfigurationSettings.AppSettings("ConnectionString"))
            Dim com As New SqlCommand("SELECT TIC_ID FROM AA_TICKETS WHERE TIC_ID='" & Idticket & "'", conn)
            Try
                conn.Open()
                lereader = com.ExecuteReader
                If lereader.Read() Then
                    retour = True
                Else
                    retour = False
                End If
            Catch ex As Exception
                retour = False
            Finally
                com = Nothing
                conn.Close()
                conn = Nothing
            End Try
            Return retour
        End Function

        Public Function UpdateMailsTicket(ByVal IdTicket As String, ByVal MailON As String, ByVal MailOFF As String) As Boolean
            Dim NbRecord As Integer = 0
            Dim retour As Boolean
            Dim conn As New SqlConnection(ConfigurationSettings.AppSettings("ConnectionString"))
            Dim com As New SqlCommand("UPDATE AA_TICKETS SET TIC_MAILON='" & Replace(MailON, "'", "''") & "', TIC_MAILOFF='" & Replace(MailOFF, "'", "''") & "' WHERE TIC_ID='" & Replace(IdTicket, "'", "''") & "'", conn)
            Try
                conn.Open()
                NbRecord = com.ExecuteNonQuery()
            Catch ex As Exception
                retour = False
            End Try
            If NbRecord = 1 Then
                retour = True
            Else
                retour = False
            End If
            com = Nothing
            conn.Close()
            conn = Nothing
            Return retour
        End Function

        Public Function IsDejaParrain(ByVal email As String) As Boolean
            Dim retour As Boolean = False
            Dim lereader As SqlDataReader
            Dim conn As New SqlConnection(ConfigurationSettings.AppSettings("ConnectionString"))
            Dim com As New SqlCommand("SELECT TIC_ID FROM AA_TICKETS WHERE TIC_MAILOFF='" & Replace(email, "'", "''") & "'", conn)
            Try
                conn.Open()
                lereader = com.ExecuteReader
                If lereader.Read() Then
                    retour = True
                Else
                    retour = False
                End If
            Catch ex As Exception
                retour = False
            Finally
                com = Nothing
                conn.Close()
                conn = Nothing
            End Try
            Return retour
        End Function

        Public Function IsTicketValid(ByVal Idticket As String) As Boolean
            Dim NbRecord As Integer = 0
            Dim retour As Boolean = False
            Dim IdValid As Integer
            Dim conn As New SqlConnection(ConfigurationSettings.AppSettings("ConnectionString"))
            Dim com As New SqlCommand("SELECT TIC_Valid FROM AA_TICKETS WHERE TIC_ID='" & Replace(Idticket, "'", "''") & "'", conn)
            Try
                conn.Open()
                IdValid = com.ExecuteScalar()
                If IdValid = 1 Then
                    retour = True
                Else
                    retour = False
                End If
            Catch ex As Exception
                retour = False
            End Try
            com = Nothing
            conn.Close()
            conn = Nothing
            Return retour
        End Function

        Public Function DelTicket(ByVal Idticket As String) As Boolean
            Dim NbRecord As Integer = 0
            Dim retour As Boolean
            Dim conn As New SqlConnection(ConfigurationSettings.AppSettings("ConnectionString"))
            Try
                conn.Open()
            Catch ex As Exception
                retour = False
            End Try
            Dim com As New SqlCommand("DELETE AA_TICKETS WHERE TIC_ID='" & Replace(Idticket, "'", "''") & "'", conn)
            Try
                NbRecord = com.ExecuteNonQuery()
            Catch ex As Exception
                retour = False
            End Try
            If NbRecord > 0 Then retour = True Else  : retour = False
            com = Nothing
            conn.Close()
            conn = Nothing
            Return retour
        End Function

        Public Function ValidTicket(ByVal Idticket As String) As Boolean
            Dim NbRecord As Integer = 0
            Dim retour As Boolean
            Dim conn As New SqlConnection(ConfigurationSettings.AppSettings("ConnectionString"))
            Try
                conn.Open()
            Catch ex As Exception
                retour = False
            End Try
            Dim com As New SqlCommand("UPDATE AA_TICKETS SET TIC_Valid=1 WHERE TIC_ID='" & Replace(Idticket, "'", "''") & "'", conn)
            Try
                NbRecord = com.ExecuteNonQuery()
            Catch ex As Exception
                retour = False
            End Try
            If NbRecord > 0 Then retour = True Else  : retour = False
            com = Nothing
            conn.Close()
            conn = Nothing
            Return retour
        End Function

        Public Function InvalideTicket(ByVal Idticket As String) As Boolean
            Dim NbRecord As Integer = 0
            Dim retour As Boolean
            Dim conn As New SqlConnection(ConfigurationSettings.AppSettings("ConnectionString"))
            Dim com As New SqlCommand("UPDATE AA_TICKETS SET TIC_Valid=0 WHERE TIC_ID='" & Replace(Idticket, "'", "''") & "'", conn)
            Try
                conn.Open()
                NbRecord = com.ExecuteNonQuery()
                If NbRecord = 1 Then
                    retour = True
                Else
                    retour = False
                End If
            Catch ex As Exception
                retour = False
            End Try
            com = Nothing
            conn.Close()
            conn = Nothing
            Return retour
        End Function

    End Class

Conclusion :


J'utilise cette classe sur mes trois sites :
<a href="http://www.euros-laser.com" target="_blanc">vente de consommables pour imprimante</a>
<a href="http://www.margo-cartes-virtuelles.com" target="_blanc">cartes virtuelles gratuites</a>
<a href="http://www.que-du-gratuit.org" target="_blanc">annuaire des sites gratuits</a> (pas encore terminé)

A voir également

Vous n'êtes pas encore membre ?

inscrivez-vous, c'est gratuit et ça prend moins d'une minute !

Les membres obtiennent plus de réponses que les utilisateurs anonymes.

Le fait d'être membre vous permet d'avoir un suivi détaillé de vos demandes et codes sources.

Le fait d'être membre vous permet d'avoir des options supplémentaires.