#Region Module Attributes
#StartAtBoot: True
#StartCommandReturnValue: android.app.Service.START_STICKY
#End Region
'Service module
Sub Process_Globals
'These global variables will be declared once when the application starts.
'These variables can be accessed from all modules.
Dim Counter = 0 As Int
Dim nAct As Notification
Dim smsTimer As Timer
Dim currentDayOfYear,currentYear,currentdayOfAllYears As Int
Dim SMTP As SMTP
Dim Datedujour As String
Dim PE As PhoneEvents
Dim ps As PhoneSms
Dim PhoneId As PhoneId
End Sub
Sub Service_Create
SMTP.Initialize(Main.SMTP_Server, Main.SMPT_Port, Main.SMTP_Username, Main.SMTP_Password, "SMTP")
SMTP.StartTLSMode = True
nAct.Initialize
nAct.icon="icon2"
nAct.Sound = False
nAct.Vibrate = False
nAct.Light = False
nAct.OnGoingEvent = True
nAct.SetInfo(Main.Progname &" Started", Counter & " Opérations", Main)
nAct.Notify(1)
'smsTimer.Initialize("sendsms", 1000)
'smsTimer.Enabled = True
currentYear= DateTime.GetYear(DateTime.Now)
currentDayOfYear= DateTime.GetDayOfYear(DateTime.Now)
' on pourrait multiplier par 365, easier par 1000
currentdayOfAllYears= currentDayOfYear*1000 + currentYear
DateTime.dateformat="dd/MM/yyyy"
Datedujour = DateTime.Date(DateTime.now)
DateTime.dateformat = "yyyy-MM-dd"
PE.Initialize("PhEvents")
PE.InitializeWithPhoneState("PhEvents",PhoneId)
End Sub
Sub Service_Start(StartingIntent As Intent)
StartServiceAt(Null, TimeToNextMinute, True) 'Service will restart every minute
CallSub(Null, IsItMidnight)
End Sub
Sub TimeToNextMinute As Long
Dim NextMin As Long
NextMin = DateTime.Now + DateTime.TicksPerMinute
NextMin = NextMin - (NextMin Mod DateTime.TicksPerMinute)
Return NextMin
End Sub
Sub Service_Destroy
nAct.Cancel(1)
End Sub
Sub IsItMidnight
Dim dayndf As FactDay
Dim cBody As String
DateTime.TimeFormat = "HH:mm"
Log ("now " & DateTime.Time(DateTime.Now))
If DateTime.Time(DateTime.Now) = "00:00" Then
dayndf.Initialize
dayndf= tools.getexpense(currentDayOfYear,currentYear,-1)
If dayndf.total > 0 Then
'send mail
cBody=createbody(dayndf)
If Main.cSmsNo.Trim.Length >0 Then
sendsms(Main.cSmsNo.Trim,cBody)
End If
If Main.cEmailTxt.Trim.Length >0 Then
sendmail(Main.cEmailTxt.Trim,cBody,dayndf.Datedujour)
End If
End If
nAct.SetInfo(Main.ProgName & " : " & Main.ProgVersion , "Opérations envoyés par eMail & SMS", "main")
nAct.Notify(1)
currentYear = DateTime.GetYear(DateTime.Now)
currentDayOfYear = DateTime.GetDayOfYear(DateTime.Now)
currentdayOfAllYears= currentDayOfYear *1000 + currentYear
DateTime.dateformat="dd/MM/yyyy"
Datedujour = DateTime.Date(DateTime.now)
DateTime.dateformat = "yyyy-MM-dd"
Counter=0
CallSub(Main,"affiche_day")
End If
End Sub