1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463
| ;
; ------------------------------------------------------------
; APP TIRELIRE
; www.agencedesfacs.fr
; By Sébastien CASANOVA v1.0.0 le 28/08/2020
; le 03/09/2020 v1.1 graphique fonctionne
; ------------------------------------------------------------
;
;https://www.tutorialspoint.com/sqlite/sqlite_using_autoincrement.htm
;pr commande sqlite v3
Global lstico= 6 ;,txt_id=70,txt_tel=71,txt_com=72
;Global txt_idctn=80,txt_prix=81,txt_duree=82,Date1 ;,txt_idp =inutile
;Global lstico2= 7, lstico3= 8
;Global nb_ctn=83,nb_pres=84, ListView1=90
;Global selecItmRch=0 ;selection de itm 0
Global selecItmLstico=-1, wintx.i=0,winty.i=0
Global pannel=10
Global Date1,edit_montant,edit_totmontant
Global Editor3
Global nb.i=36+1
Global Dim ab.s(36, 5)
;pr gestion graph image
Global tx.i = 800 , ty.i = 300
Global tailleCol.i = 15, maxV.f = 12.2 , maxH.i = 10
Global sizeX.i = 9 ;equart
Global posannee.i = 0
Global img_graph=99,imgg=100
Global mrkV.f,val.f,i
Global ty_tbl.f=1
! var v_wintx=document.body.clientWidth;
! var v_winty=document.body.clientHeight;
!function resizefunc(e){ //dans la function setup()
! var v_wintx=document.body.clientWidth;
! var v_winty=document.body.clientHeight;
ResizeWindow(0, 0, 0, wintx, winty)
ResizeGadget(pannel, 5, #PB_Ignore, WindowWidth(0)-10, #PB_Ignore)
ResizeGadget(lstico, 5, #PB_Ignore, WindowWidth(0)-20, #PB_Ignore)
; ResizeGadget(lstico2, 10, #PB_Ignore, WindowWidth(0)-20, #PB_Ignore)
; ResizeGadget(lstico3, 10, #PB_Ignore, WindowWidth(0)-20, #PB_Ignore)
; ResizeGadget(ListView1, 10, #PB_Ignore, WindowWidth(0)-20, #PB_Ignore)
ResizeGadget(Editor3, 5, #PB_Ignore, WindowWidth(0)-20, #PB_Ignore)
; If 160+220 > v_wintx+10
; ResizeGadget(txt_com, 160, 70, (v_wintx+10)-160, 20)
; Else
; ResizeGadget(txt_com, 160, 70, 220, 20)
; EndIf
!}
!window.addEventListener("resize", function(e) { resizefunc(e); });
Procedure CreateFileCallback(Status, Filename$, File, SizeRead)
Select Status
Case #PB_Status_Loaded
Debug "Database file found and loaded: " + Filename$
*DatabaseBuffer = ExportFileMemory(File)
If OpenDatabase(0, *DatabaseBuffer)
ExportFile(0, "application/octet-stream")
CloseFile(0)
Debug "export du fichier sqlite: réussit."
Else
Debug "export du fichier sqlite: échec."
EndIf
Case #PB_Status_Saved
Debug "Database file saved: " + Filename$
Debug "Please relaunch the program to test the persitency."
Case #PB_Status_Error : Debug "Can't save the database: " + Filename$
EndSelect
EndProcedure
Procedure Loaded(Type, Filename$, ObjectId) : ImageGadget(#PB_Any, 5, 5, ImageWidth(ObjectId), ImageHeight(ObjectId), ImageID(ObjectId)) : EndProcedure
Procedure LoadingError(Type, Filename$, ObjectId) : Debug Filename$ + ": loading error" : EndProcedure
Procedure Generer_img_graph()
lol=StartDrawing(ImageOutput(img_graph))
If lol
;For a=0 To ArraySize(ab(),1) ;nb
; Debug Str(a)+": "+ab(a,0)+" , "+ab(a,1)+" , "+ab(a,2)+" , "+ab(a,3)+" , "+ab(a,4)+" , "+ab(a,5)
;Next
vert =RGB(0,157,160)
fond =RGB(104,147,155)
gris =RGB(192,203,237)
grisclair =RGB(222,233,255)
jaune =RGB(160,157,0)
grdlng =RGB(128,128,128)
grisplus =RGB(150,150,150)
blanc =RGB(255,255,255)
noir =RGB(0,0,0)
Box(0,0,tx,ty, blanc) ;equivalent: Line(0, 0, tx-1, 1 ,gris) : Line(0, ty-1, tx, 1 ,gris) : Line(0, 0, 1, ty-1 ,gris) : Line(tx-1, 0, 1, ty ,gris)
Line(tailleCol+1+10, 0, 1, ty ,gris) ;axe vertical
Line(0, ty-tailleCol-1, tx, 1 ,gris) ;axe horizontal
Box(0,0,tx,tailleCol, gris)
Box(0,0,tailleCol+10,ty, gris)
Box(tailleCol+10,0,1,ty, noir) ;axe V
Box(0,ty-tailleCol,tx,1, noir) ;axe H
Box(tailleCol+9,0,1,ty, blanc)
Box(0,ty-tailleCol+1,tx,1, blanc)
FrontColor(blanc) : LoadFont(1, "times", 15) : DrawingFont(FontID(1))
For iz=1 To 3
For io=1 To 3
DrawText(450+io-2, iz,"Gain journallier")
Next
Next
FrontColor(noir)
DrawText(450+io-2, iz+1,"Gain journallier")
; ty=300;;
ty_tbl.f= ty-(2*tailleCol)
x=tailleCol+11
oldx=x
offy=ty-tailleCol
; ParseJSON(0, "[["+Chr(34)+"2020-08-01"+Chr(34)+" , 17 , 10 , 419 , "+Chr(34)+"2020-08"+Chr(34)+" , 610],["+Chr(34)+"2020-08-02"+Chr(34)+" , 16 , 11 , 419 , "+Chr(34)+"2020-08"+Chr(34)+" , 610],["+Chr(34)+"2020-08-03"+Chr(34)+" , 16 , 11 , 419 , "+Chr(34)+"2020-08"+Chr(34)+" , 610],["+Chr(34)+"2020-08-04"+Chr(34)+" , 21 , 17 , 419 , "+Chr(34)+"2020-08"+Chr(34)+" , 610],["+Chr(34)+"2020-08-05"+Chr(34)+" , 21 , 15 , 419 , "+Chr(34)+"2020-08"+Chr(34)+" , 610],["+Chr(34)+"2020-08-06"+Chr(34)+" , 44 , 18 , 419 , "+Chr(34)+"2020-08"+Chr(34)+" , 610],["+Chr(34)+"2020-08-07"+Chr(34)+" , 10 , 9 , 419 , "+Chr(34)+"2020-08"+Chr(34)+" , 610],["+Chr(34)+"2020-08-08"+Chr(34)+" , 21 , 19 , 419 , "+Chr(34)+"2020-08"+Chr(34)+" , 610],["+Chr(34)+"2020-08-09"+Chr(34)+" , 12 , 10 , 419 , "+Chr(34)+"2020-08"+Chr(34)+" , 610],["+Chr(34)+"2020-08-10"+Chr(34)+" , 24 , 16 , 419 , "+Chr(34)+"2020-08"+Chr(34)+" , 610],["+Chr(34)+"2020-08-11"+Chr(34)+" , 52 , 11 , 419 , "+Chr(34)+"2020-08"+Chr(34)+" , 610],["+Chr(34)+"2020-08-12"+Chr(34)+" , 79 , 14 , 419 , "+Chr(34)+"2020-08"+Chr(34)+" , 610],["+Chr(34)+"2020-08-13"+Chr(34)+" , 50 , 23 , 419 , "+Chr(34)+"2020-08"+Chr(34)+" , 610],["+Chr(34)+"2020-08-14"+Chr(34)+" , 14 , 12 , 419 , "+Chr(34)+"2020-08"+Chr(34)+" , 610],["+Chr(34)+"2020-08-15"+Chr(34)+" , 24 , 10 , 419 , "+Chr(34)+"2020-08"+Chr(34)+" , 610],["+Chr(34)+"2020-08-16"+Chr(34)+" , 38 , 35 , 419 , "+Chr(34)+"2020-08"+Chr(34)+" , 610],["+Chr(34)+"2020-08-17"+Chr(34)+" , 46 , 33 , 419 , "+Chr(34)+"2020-08"+Chr(34)+" , 610],["+Chr(34)+"2020-08-18"+Chr(34)+" , 28 , 25 , 419 , "+Chr(34)+"2020-08"+Chr(34)+" , 610],["+Chr(34)+"2020-08-19"+Chr(34)+" , 40 , 29 , 419 , "+Chr(34)+"2020-08"+Chr(34)+" , 610],["+Chr(34)+"2020-08-20"+Chr(34)+" , 21 , 18 , 419 , "+Chr(34)+"2020-08"+Chr(34)+" , 610],["+Chr(34)+"2020-08-21"+Chr(34)+" , 17 , 16 , 419 , "+Chr(34)+"2020-08"+Chr(34)+" , 610],["+Chr(34)+"2020-08-22"+Chr(34)+" , 14 , 14 , 419 , "+Chr(34)+"2020-08"+Chr(34)+" , 610],["+Chr(34)+"2020-08-23"+Chr(34)+" , 17 , 16 , 419 , "+Chr(34)+"2020-08"+Chr(34)+" , 610],["+Chr(34)+"2020-08-24"+Chr(34)+" , 22 , 22 , 419 , "+Chr(34)+"2020-08"+Chr(34)+" , 610],["+Chr(34)+"2020-08-25"+Chr(34)+" , 5 , 5 , 419 , "+Chr(34)+"2020-08"+Chr(34)+" , 610],["+Chr(34)+"2020-09-01"+Chr(34)+" , 5 , 5 , 419 , "+Chr(34)+"2020-09"+Chr(34)+" , 610]]" )
; Dim ab(0, 0)
; ExtractJSONArray(JSONValue(0), ab())
; For xb = 0 To 26-1
; Debug Str(ab(xb, 0))+","+Str(ab(xb, 1))+","+Str(ab(xb, 2))+","+Str(ab(xb, 3))+","+Str(ab(xb, 4))+","+Str(ab(xb, 5))
; Next
For i=0 To 9
mrkV= i/9
val= ty_tbl * mrkV
If (i<>0) And (i<>9) : LineXY( x+6,offy-val,tx,offy-val, gris ) : EndIf ; } //on gradu l'axe verticale
Next
LoadFont(2, "times", 10) : DrawingFont(FontID(2))
For xb = 0 To ArraySize(ab(),1) ;nb-1 ; While ($dnb2 = mysqli_fetch_array($result2)){
Debug Str(xb)+" xb: "+ab(xb,0)+" , "+ab(xb,1)+" , "+ab(xb,2)+" , "+ab(xb,3)+" , "+ab(xb,4)+" , "+ab(xb,5)
v_cnt.f= ValF(ab(xb, 2)) ; $v_cnt= $dnb2['MaxVueDesMois'];
vmax_cnt.f= ValF(ab(xb, 5)) ;= $dnb2['max_cnt'];
vj_cnt.f= ValF(ab(xb, 3)) ;=$dnb2['visiteur_unique'];
; ff.f = (vmax_cnt.f *10)
y2.f= vj_cnt.f *12* ty_tbl.f/ ( vmax_cnt.f *10*1.1) ; //zoom 10foix
vAct_cnt.f= 0;ValF(ab(xb, 1)) ;=$dnb2['activite'];
y3.f= 0;vAct_cnt*1.5* ty_tbl/( (vmax_cnt)*1.1) ; //zoom 10foix
y.f= v_cnt*ty_tbl/(vmax_cnt *1.1)
Debug "ty "+StrF( y2 )
If (x=oldx) : oldy=y : oldy2=y2 : oldy3=y3 : EndIf
LineXY( x-(sizeX/2),tailleCol,x-(sizeX/2),offy-1 , grisclair )
If ab(xb, 4)<>vdate.s ; If ($vdate!=$dnb2['mmAA']){
vdate=ab(xb, 4) ;=$dnb2['mmAA'];
If (x<>oldx)
LineXY( x-(sizeX/2),tailleCol,x-(sizeX/2),offy , gris )
DrawText( x-(sizeX/2)-15,offy+5, vdate )
LineXY( x-(sizeX/2),offy-5,x-(sizeX/2),offy+5 , noir )
EndIf
EndIf
;LineXY(oldx,offy-oldy3,x,offy-y3 , jaune) ;vue journallier activité
LineXY(oldx,offy-oldy2,x,offy-y2 , vert) ;vue journallier
LineXY(oldx,offy-oldy,x,offy-y , noir) ;vue mensuel
oldx=x : x= x+sizeX ;scale echele horizontal
oldy=y : oldy2=y2 : oldy3=y3 : maxV.f=vmax_cnt*1.1
Next
x=tailleCol+11
;BackColor(RGB(255,155,155)) ;changer la couleur de fond du text
LoadFont(0, "times", 10) : DrawingFont(FontID(0))
For i=0 To 9
mrkV= i*maxV/9
val= ty_tbl * mrkV / maxV
xxx.s= Str(Round( i * maxV /9 ,#PB_Round_Nearest ))
Line(x-5,offy-val,10, 1 ,noir)
If i<>0 : DrawText(1,offy-val-6, xxx) : EndIf ;:Debug (offy-val-6) ;on gradu l'axe verticale
Next
StopDrawing()
EndIf
SetGadgetState(imgg,ImageID(img_graph));,img_graph) ;refrech image
EndProcedure
Procedure ReadFileCallback(Status, Filename$, File, SizeRead)
Select Status
Case #PB_Status_Loaded
Debug "Database file found and loaded: " + Filename$
*DatabaseBuffer = ExportFileMemory(File)
If OpenDatabase(0, *DatabaseBuffer)
If DatabaseQuery(0, "SELECT SUM(montant) as montant FROM compte")
Debug "calcul du montant total sur compte"
While NextDatabaseRow(0)
Debug "montant: " + GetDatabaseDouble(0, 0)
SetGadgetText(edit_totmontant, StrF(GetDatabaseDouble(0, 0),2))
Wend
FinishDatabaseQuery(0)
Else
Debug "DatabaseQuery() failed: " + DatabaseError()
EndIf
If DatabaseQuery(0, "SELECT id,strftime('%d/%m/%Y',compte.date) As date,montant FROM `compte` ORDER by date DESC, id DESC LIMIT 0,30")
Debug "0erreur? : "+DatabaseError()
ClearGadgetItems(lstico)
While NextDatabaseRow(0)
;`ddate`, `activite`,`visiteur_unique`, `MaxVueDesMois` ,`mmAA` ,`max_cnt`
Debug "id: " + GetDatabaseString(0, 0)+ " -date: " + GetDatabaseString(0, 1) + " -montant: " + GetDatabaseDouble(0, 2)
AddGadgetItem(lstico, -1, GetDatabaseString(0, 1)+Chr(10)+GetDatabaseDouble(0, 2))
SetGadgetItemData(lstico, CountGadgetItems(lstico)-1, Val(GetDatabaseString(0, 0)) )
Wend
FinishDatabaseQuery(0)
EndIf
For a=0 To ArraySize(ab(),1) ;nb
ab(a,0)=FormatDate("%dd/%mm/%yyyy", Date()-(a*60*60*24))
ab(a,1)="0"
ab(a,2)="0"
ab(a,3)="0"
ab(a,4) = FormatDate("%yyyy-%mm", Date()-(a*60*60*24))
ab(a,5)="0"
Next
max.f=0
If DatabaseQuery(0, "SELECT id,strftime('%d/%m/%Y',compte.date) As date, SUM(montant) As montant FROM `compte` GROUP BY date ORDER by date DESC, id DESC LIMIT 0,30")
Debug "0erreur? : "+DatabaseError()
While NextDatabaseRow(0)
;`ddate`, `activite`,`visiteur_unique`, `MaxVueDesMois` ,`mmAA` ,`max_cnt`
; Debug "oid: " + GetDatabaseString(0, 0)+ " -date: " + GetDatabaseString(0, 1) + " -montant: " + GetDatabaseDouble(0, 2)
If max < GetDatabaseFloat(0, 2) : max = GetDatabaseFloat(0, 2) : EndIf
For a=0 To ArraySize(ab(),1) ;nb
If ab(a,0) = GetDatabaseString(0, 1)
ab(a,1)= StrF(GetDatabaseFloat(0, 2))
ab(a,2)= StrF(GetDatabaseFloat(0, 2))
EndIf
Next
Wend
FinishDatabaseQuery(0)
For a=0 To ArraySize(ab(),1) ;nb
ab(a,3)= StrF(max)
ab(a,5)= StrF(max)
Next
Generer_img_graph()
EndIf
Else : Debug "OpenDatabase() failed"
EndIf
Case #PB_Status_Error
Debug "Database not found in localstorage: " + Filename$
Debug "Creating a new database..."
If OpenDatabase(0)
DatabaseUpdate(0, "CREATE TABLE `compte` ( `id` INTEGER PRIMARY KEY AUTOINCREMENT ,`date` DATE, `montant` REAL)")
Debug "0erreur? : "+DatabaseError()
DatabaseUpdate(0, "INSERT INTO compte (date,montant) Values ('2020-08-27', '12.80')")
DatabaseUpdate(0, "INSERT INTO compte (date,montant) Values ('2020-08-28', '20.00')")
DatabaseUpdate(0, "INSERT INTO compte (date,montant) Values ('2020-08-29', '6.14')")
ClearGadgetItems(lstico)
If DatabaseQuery(0, "SELECT SUM(montant) as montant FROM compte")
; Debug "calcul du montant total sur compte"
While NextDatabaseRow(0)
; Debug "montant: " + GetDatabaseDouble(0, 0)
SetGadgetText(edit_totmontant, StrF(GetDatabaseDouble(0, 0),2))
Wend
FinishDatabaseQuery(0)
Else
Debug "DatabaseQuery() failed: " + DatabaseError()
EndIf
If DatabaseQuery(0, "SELECT id,strftime('%d/%m/%Y',compte.date) As date,montant FROM `compte` ORDER by date DESC, id DESC LIMIT 0,30")
Debug "0erreur? : "+DatabaseError()
ClearGadgetItems(lstico)
While NextDatabaseRow(0)
; Debug "id: " + GetDatabaseString(0, 0)+ " -date: " + GetDatabaseString(0, 1) + " -montant: " + GetDatabaseDouble(0, 2)
AddGadgetItem(lstico, -1, GetDatabaseString(0, 1)+Chr(10)+GetDatabaseDouble(0, 2))
SetGadgetItemData(lstico, CountGadgetItems(lstico)-1, Val(GetDatabaseString(0, 0)) )
Wend
FinishDatabaseQuery(0)
EndIf
*DatabaseBuffer = ExportDatabaseMemory(DB)
If CreateFile(0, "testdbv3.sqlite", @CreateFileCallback(), #PB_LocalStorage)
WriteData(0, *DatabaseBuffer, 0, MemorySize(*DatabaseBuffer))
CloseFile(0)
EndIf
CloseDatabase(0)
Else : Debug "OpenDatabase() failed"
EndIf
EndSelect
EndProcedure
Procedure OnSavDB() : ReadFile(0, "testdbv3.sqlite", @CreateFileCallback(), #PB_LocalStorage) : EndProcedure
Procedure OnChangeSelectItm() ;quand on clique sur un item selectionner d'un menu deroulant lstico3
Select EventGadget()
Case lstico
Select EventType()
Case #PB_EventType_LeftClick ;| #PB_EventType_RightClick
If selecItmLstico <> GetGadgetState(lstico )
selecItmLstico = GetGadgetState(lstico )
Str(GetGadgetItemData(lstico, selecItmLstico))
EndIf
EndSelect
EndSelect
EndProcedure
Procedure suprowFileCallback(Status, Filename$, File, SizeRead)
Select Status
Case #PB_Status_Loaded
Debug "Database file found and loaded: " + Filename$
*DatabaseBuffer = ExportFileMemory(File)
If OpenDatabase(0, *DatabaseBuffer)
Debug "updateDB..."
vv= GetGadgetState(lstico)
Debug "ligne selec "+vv+" sup de l'id: "+GetGadgetItemData(lstico, vv )
If vv>-1
Debug "eeeee "+GetGadgetItemData(lstico, vv )
If 0<>GetGadgetItemData(lstico, vv )
If DatabaseUpdate(0, "DELETE FROM compte WHERE id = "+GetGadgetItemData(lstico, vv )+" ;") : Debug "0erreur? : "+DatabaseError() : EndIf
Debug "DELETE FROM compte WHERE id = "+GetGadgetItemData(lstico, vv )+" ;"
EndIf
EndIf
ClearGadgetItems(lstico)
If DatabaseQuery(0, "SELECT SUM(montant) as montant FROM compte")
; Debug "calcul du montant total sur compte"
While NextDatabaseRow(0)
; Debug "montant: " + GetDatabaseDouble(0, 0)
SetGadgetText(edit_totmontant, StrF(GetDatabaseFloat(0, 0),2))
Wend
FinishDatabaseQuery(0)
Else
Debug "DatabaseQuery() failed: " + DatabaseError()
EndIf
If DatabaseQuery(0, "SELECT id,strftime('%d/%m/%Y',compte.date) As date,montant FROM `compte` ORDER by date DESC, id DESC LIMIT 0,30")
Debug "0erreur? : "+DatabaseError()
ClearGadgetItems(lstico)
While NextDatabaseRow(0)
; Debug "id: " + GetDatabaseString(0, 0)+ " -date: " + GetDatabaseString(0, 1) + " -montant: " + GetDatabaseDouble(0, 2)
AddGadgetItem(lstico, -1, GetDatabaseString(0, 1)+Chr(10)+GetDatabaseFloat(0, 2))
SetGadgetItemData(lstico, CountGadgetItems(lstico)-1, Val(GetDatabaseString(0, 0)) )
Wend
FinishDatabaseQuery(0)
EndIf
Debug "fin"
*DatabaseBuffer = ExportDatabaseMemory(DB)
If CreateFile(0, "testdbv3.sqlite", @CreateFileCallback(), #PB_LocalStorage)
WriteData(0, *DatabaseBuffer, 0, MemorySize(*DatabaseBuffer))
CloseFile(0)
EndIf
Else : Debug "OpenDatabase() failed"
EndIf
Case #PB_Status_Error : Debug "impossible de sav modif DB."
EndSelect
EndProcedure
Procedure updateFileCallback(Status, Filename$, File, SizeRead)
Select Status
Case #PB_Status_Loaded
Debug "Database file found and loaded: " + Filename$
*DatabaseBuffer = ExportFileMemory(File)
If OpenDatabase(0, *DatabaseBuffer)
If GetGadgetText(Date1)=""
SetGadgetState(Date1, Date())
SetGadgetText(Date1, "%dd/%mm/%yyyy")
EndIf
vd.s = FormatDate("%yyyy-%mm-%dd", GetGadgetState(Date1))
;SetGadgetItemData(lstico2, vv, Val(GetGadgetText(txt_idctn)) )
If DatabaseUpdate(0, "INSERT INTO compte (date,montant) Values ('"+vd+"', '"+GetGadgetText(edit_montant)+"')")
Debug "0erreur? : "+DatabaseError()
;FinishDatabaseQuery(0)
Else
Debug "DatabaseQuery() failed: " + DatabaseError()
EndIf
If DatabaseQuery(0, "SELECT SUM(montant) as montant FROM compte")
Debug "calcul du montant total sur compte"
While NextDatabaseRow(0)
Debug "montant: " + GetDatabaseDouble(0, 0)
SetGadgetText(edit_totmontant, StrF(GetDatabaseDouble(0, 0),2))
Wend
FinishDatabaseQuery(0)
Else
Debug "DatabaseQuery() failed: " + DatabaseError()
EndIf
If DatabaseQuery(0, "SELECT id,strftime('%d/%m/%Y',compte.date) As date,montant FROM `compte` ORDER by date DESC, id DESC LIMIT 0,30")
Debug "0erreur? : "+DatabaseError()
ClearGadgetItems(lstico)
While NextDatabaseRow(0)
Debug "id: " + GetDatabaseString(0, 0)+ " -date: " + GetDatabaseString(0, 1) + " -montant: " + GetDatabaseDouble(0, 2)
AddGadgetItem(lstico, -1, GetDatabaseString(0, 1)+Chr(10)+GetDatabaseDouble(0, 2))
SetGadgetItemData(lstico, CountGadgetItems(lstico)-1, Val(GetDatabaseString(0, 0)) )
Wend
FinishDatabaseQuery(0)
EndIf
For a=0 To ArraySize(ab(),1) ;nb
ab(a,0)=FormatDate("%dd/%mm/%yyyy", Date()-(a*60*60*24))
ab(a,1)="0"
ab(a,2)="0"
ab(a,3)="0"
ab(a,4) = FormatDate("%yyyy-%mm", Date()-(a*60*60*24))
ab(a,5)="0"
Next
max.f=0
If DatabaseQuery(0, "SELECT id,strftime('%d/%m/%Y',compte.date) As date, SUM(montant) As montant FROM `compte` GROUP BY date ORDER by date DESC, id DESC LIMIT 0,30")
Debug "0erreur? : "+DatabaseError()
While NextDatabaseRow(0)
;`ddate`, `activite`,`visiteur_unique`, `MaxVueDesMois` ,`mmAA` ,`max_cnt`
; Debug "oid: " + GetDatabaseString(0, 0)+ " -date: " + GetDatabaseString(0, 1) + " -montant: " + GetDatabaseDouble(0, 2)
If max < GetDatabaseFloat(0, 2) : max = GetDatabaseFloat(0, 2) : EndIf
For a=0 To ArraySize(ab(),1) ;nb
If ab(a,0) = GetDatabaseString(0, 1)
ab(a,1)= StrF(GetDatabaseFloat(0, 2))
ab(a,2)= StrF(GetDatabaseFloat(0, 2))
EndIf
Next
Wend
FinishDatabaseQuery(0)
For a=0 To ArraySize(ab(),1) ;nb
ab(a,3)= StrF(max)
ab(a,5)= StrF(max)
Next
Generer_img_graph()
EndIf
*DatabaseBuffer = ExportDatabaseMemory(DB)
If CreateFile(0, "testdbv3.sqlite", @CreateFileCallback(), #PB_LocalStorage) : WriteData(0, *DatabaseBuffer, 0, MemorySize(*DatabaseBuffer)) : CloseFile(0) : EndIf
Else : Debug "OpenDatabase() failed"
EndIf
Case #PB_Status_Error : Debug "impossible de sav modif DB."
EndSelect
EndProcedure
Procedure OnCredit() : ReadFile(0, "testdbv3.sqlite", @updateFileCallback(), #PB_LocalStorage) : EndProcedure
Procedure OnSuprLng() : ReadFile(0, "testdbv3.sqlite", @suprowFileCallback(), #PB_LocalStorage) : EndProcedure
If OpenWindow(0, 0, 0, 400, 450, "DB TIRELIRE v1.1 by Sébastien C.", #PB_Window_Background | #PB_Window_ScreenCentered | #PB_Window_SizeGadget | #PB_Window_BorderLess)
! var v_wintx=document.body.clientWidth;
! var v_winty=document.body.clientHeight;
ResizeWindow(0, 0, 0, wintx, winty)
PanelGadget(pannel, 5, 5, WindowWidth(0)-10, WindowHeight(0)-10)
AddGadgetItem(pannel, -1, "compte") ;-- pannel compte
TextGadget (#PB_Any, 5, 20, 300, 20, "entrer un montant")
edit_montant= StringGadget(#PB_Any,90+70,45,70,20,"0.00")
btn_cred =ButtonGadget(#PB_Any, 210, 45, 110, 20, "Inserer")
btn_supr =ButtonGadget(#PB_Any, 240, 100, 110, 20, "sup lng")
edit_totmontant= StringGadget(#PB_Any,90+70,20,70,20,"?.??",#PB_String_ReadOnly)
Date1 = DateGadget(#PB_Any, 10, 45, 130, 20)
SetGadgetState(Date1, Date())
SetGadgetText(Date1, "%dd/%mm/%yyyy")
TextGadget(#PB_Any, 210, 5, 160, 20, "aujourd'hui le: "+GetGadgetText(Date1))
ListIconGadget(lstico, 5, 130, 400-20, 275, "Date", 50, #PB_ListIcon_FullRowSelect | #PB_ListIcon_AlwaysShowSelection)
AddGadgetColumn(lstico, 1, "Montant", 70)
AddGadgetItem(pannel, -1, "graphique") ;-- pannel graphique
TextGadget(#PB_Any, 10,10, 200, 20, "graphique journallier à faire")
;image graphique
tx=400
If CreateImage(img_graph, tx, ty)
; Generer_img_graph()
EndIf
ImageGadget(imgg, 5, 35, tx, ty, ImageID(img_graph))
AddGadgetItem(pannel, -1, "a propos") ;pannel a propos
;ButtonGadget(#PB_Any, 250, 10, 120, 20, "load/ecrase DB file")
btn_savDB =ButtonGadget(#PB_Any, 230, 40, 120, 20, "sav DB file")
Editor3 = EditorGadget(#PB_Any, 5, 100+70+20, 400-20, 350-20-100-20+5, #PB_Editor_ReadOnly | #PB_Editor_WordWrap)
SetGadgetText(Editor3, "Ceci est un petit logiciel pour mettre de côté des économies." + #LF$ + "Il est limité aux 30 derniers resultat." + #LF$ + "Heureux de savoir que ce logiciel t'es util." + #LF$ + "Réalisé le 29/08/2020" + #LF$ + "killer128k@hotmail.fr")
BindGadgetEvent(btn_cred, @OnCredit())
BindGadgetEvent(btn_supr, @OnSuprLng())
ReadFile(0, "testdbv3.sqlite", @ReadFileCallback(), #PB_LocalStorage)
BindGadgetEvent(btn_savDB, @OnSavDB())
; BindEvent(#PB_Event_Gadget, @OnChangeSelectItm())
BindEvent(#PB_Event_Loading, @Loaded())
BindEvent(#PB_Event_LoadingError, @LoadingError())
LoadImage(20, "img/auteur_seb.jpg")
EndIf |
Partager