Torna al Thread

Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick Dim indirizzoTo As String Dim credito As String Dim username As String Dim privilegi As String Dim totaleGior As String Dim ora As String Dim min As String Dim sec As String Dim giorno As String Dim mese As String Dim client As New SmtpClient("m************", 25) Dim ConnString As String = "Provider=SQLNCLI ;Server=***********;Database=**********;Uid=*****;Pwd=******;" Dim cn As New OleDbConnection(ConnString) Dim sqlSEL As String = "select username,email,credito,privilegi from login" Dim sqlSEL2 As String client.Credentials = New System.Net.NetworkCredential("********@****.com", "*******") 'All' Ora stabilita in questo IF si scatena l'evento... If (Hour(Now) = "23") And (Minute(Now) = "59") And (Second(Now) = "59") Then ' Per prima cosa si ferma il timer... Me.Timer1.Enabled = False ' SCATENO LA PROCEDURA '__________________________________________________________________________________________ cn.Open() Dim cmdSEL As New OleDbCommand(sqlSEL, cn) Dim dr As OleDbDataReader = cmdSEL.ExecuteReader While dr.Read() indirizzoTo = dr("email") credito = dr("credito") username = dr("username") privilegi = dr("privilegi") ora = Hour(Now) If ora.Length < 2 Then ora = "0" & ora End If min = Minute(Now) If min.Length < 2 Then min = "0" & min End If sec = Second(Now) If sec.Length < 2 Then sec = "0" & sec End If giorno = Microsoft.VisualBasic.DateAndTime.Day(Now) If giorno.Length < 2 Then giorno = "0" & giorno End If mese = Month(Now) If mese.Length < 2 Then mese = "0" & mese End If totaleGior = "0" sqlSEL2 = "SELECT COUNT(*) AS tot FROM archivio_sms WHERE (convert(varchar(10),data,101) LIKE '" & mese & "/" & giorno & "/" & Year(Now) & "%') AND (username = '" & username & "') GROUP BY username" Dim cmdSEL2 As New OleDbCommand(sqlSEL2, cn) Dim dr2 As OleDbDataReader = cmdSEL2.ExecuteReader While dr2.Read() totaleGior = dr2("tot") End While dr2.Close() Dim msg As New MailMessage("mercurio_sms@megabytesistemi.com", indirizzoTo) msg.IsBodyHtml = True msg.Subject = "Credito Residuo giornaliero" msg.Body = "TESTO DELLA MAIL CON I DATI CHE RICAVO DALLA QUERY" client.Send(msg) End While dr.Close() ' preparo la mail per l'amministratore Dim sqlADMIN As String = "select email from login where privilegi='admin'" Dim cmdADMIN As New OleDbCommand(sqlADMIN, cn) Dim dr3 As OleDbDataReader = cmdSEL.ExecuteReader While dr3.Read() indirizzoTo = dr3("email") Dim msg As New MailMessage("mercurio_sms@megabytesistemi.com", indirizzoTo) msg.IsBodyHtml = True msg.Subject = "Credito Residuo giornaliero" Dim sqlLISTA As String = "select * from login order by credito asc" Dim cmdLISTA As New OleDbCommand(sqlLISTA, cn) Dim dr4 As OleDbDataReader = cmdLISTA.ExecuteReader While dr4.Read() msg.Body = "compongo una riga per ogni iscitto" End While client.Send(msg) End While dr3.Close() cn.Close() '__________________________________________________________________________________________ End If Me.Timer1.Enabled = True End Sub End Class
Copyright © dotNetHell.it 2002-2025
Running on Windows Server 2008 R2 Standard, SQL Server 2012 & ASP.NET 3.5