-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDepot.bas
124 lines (93 loc) · 3.2 KB
/
Depot.bas
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
B4A=true
Group=Default Group
ModulesStructureVersion=1
Type=Activity
Version=8.8
@EndOfDesignText@
#Region Activity Attributes
#FullScreen: False
#IncludeTitle: True
#End Region
Sub Process_Globals
'These global variables will be declared once when the application starts.
'These variables can be accessed from all modules.
Dim bmpBack As Bitmap
Dim SQL1 As SQL
Dim EltsExiste As Boolean = False
End Sub
Sub Globals
'These global variables will be redeclared each time the activity is created.
'These variables can only be accessed from this module.
Private ButtonValidDepot As Button
Private SpinnerCodeL As Spinner
Private SpinnerEmailAdh As Spinner
End Sub
Sub Activity_Create(FirstTime As Boolean)
'Do not forget to load the layout file created with the visual designer. For example:
Activity.LoadLayout("Depot")
SQL1.Initialize(File.DirInternal, "gbiblio.db", False)
bmpBack.Initialize(File.DirAssets, "background.jpg")
Activity.SetBackgroundImage(bmpBack)
ReadTable
SpinnerCodeL.SelectedIndex = 0
SpinnerEmailAdh.SelectedIndex = 0
End Sub
'transactionLivre (id INT PRIMARY KEY, codeLivre TEXT, emailAdh TEXT, dateEmprunt DATE, dateDepot DATE DEFAULT NULL)
Sub ReadTable
Dim Row As Int
Dim Cursor1 As Cursor
Dim RowNumber = 0 As Int
SpinnerCodeL.Clear
SpinnerEmailAdh.Clear
'On remplit avec les emails
Cursor1 = SQL1.ExecQuery("SELECT codeLivre, emailAdh FROM transactionLivre WHERE dateDepot IS NULL ")
If Cursor1.RowCount > 0 Then
RowNumber = Cursor1.RowCount
For Row = 0 To RowNumber - 1
Cursor1.Position = Row
SpinnerCodeL.Add(Cursor1.GetString("codeLivre"))
SpinnerEmailAdh.Add(Cursor1.GetString("emailAdh"))
EltsExiste = True
Next
End If
Cursor1.Close
End Sub
Sub SaveDepot
Dim Query, Query2 As String
Dim nbre As Int = 0
Dim Cursor1 As Cursor
Dim exist As Boolean = False
Cursor1 = SQL1.ExecQuery2("SELECT * FROM transactionLivre WHERE codeLivre = ? AND emailAdh = ?", Array As String(SpinnerCodeL.SelectedItem, SpinnerEmailAdh.SelectedItem))
Cursor1.Position = 0
If Cursor1.RowCount > 0 Then
exist = True
End If
If exist Then
Cursor1 = SQL1.ExecQuery2("SELECT nbreExple FROM livre WHERE codeLivre = ?", Array As String(SpinnerCodeL.SelectedItem))
Cursor1.Position = 0
nbre = Cursor1.GetInt("nbreExple")
Query = "UPDATE transactionLivre SET dateDepot = date('now') WHERE codeLivre = ? AND emailAdh = ?"
SQL1.ExecNonQuery2(Query, Array As String(SpinnerCodeL.SelectedItem, SpinnerEmailAdh.SelectedItem))
'livre (codeLivre TEXT PRIMARY KEY, nomAuteur TEXT, titreLivre TEXT, datePub DATE, nbreExple INT, resume TEXT)
Query2 = "UPDATE livre SET nbreExple = "& (nbre + 1) &" WHERE codeLivre = ? "
SQL1.ExecNonQuery2(Query2, Array As String(SpinnerCodeL.SelectedItem))
ToastMessageShow("Dépôt validé avec succès !", True)
Else
ToastMessageShow("Aucun emprunt de ce type !", True)
End If
End Sub
Sub Activity_Resume
EltsExiste = False
ReadTable
End Sub
Sub Activity_Pause (UserClosed As Boolean)
If UserClosed Then
SQL1.Close 'if the user closes the program we close the database
End If
End Sub
Sub ButtonValidDepot_Click
If EltsExiste Then
SaveDepot
StartActivity(Dashboard)
End If
End Sub