-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathApp.xojo_code
More file actions
488 lines (375 loc) · 15.3 KB
/
App.xojo_code
File metadata and controls
488 lines (375 loc) · 15.3 KB
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
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
#tag Class
Protected Class App
Inherits DesktopApplication
#tag Event
Sub Opening()
App.MainDB = new MySQLCommunityServer
App.MainDB.Host="127.0.0.1"
App.MainDB.Port=3306
App.MainDB.UserName="testuser"
App.MainDB.Password="xampp"
App.MainDB.DatabaseName="xojodatabase"
End Sub
#tag EndEvent
#tag Method, Flags = &h0
Function RunSqlQuery(SqlOrder as String) As Boolean
Try
MainDB.ExecuteSQL(SqlOrder)
Return true
Catch error As DatabaseException
MessageBox("DB Error: " + error.Message)
Return false
End Try
End Function
#tag EndMethod
#tag Method, Flags = &h0
Function SuperRound(nombre as double, nbrdec as Integer) As Double
// Procedure for rounding numbers in a better way than native xojo instructions
Dim i as Int64
Dim multipli as int64
multipli=1
for i=1 to nbrdec
multipli = 10 * multipli
next i
nombre = nombre * multipli
nombre = round(nombre)
nombre = nombre/multipli
return nombre
End Function
#tag EndMethod
#tag Method, Flags = &h0
Function Valide_TxtNumKeydown(byref myNumFieldTxt as DesktopTextField, Key as string, IsAnInteger as Boolean = false) As Boolean
// The purpose of this procedure is to manage the entry of numbers according to certain criteria.
// This procedure must be called from a text field during the KeyDown event
if IsNumeric( Key ) then
// In case you try to write a number before the minus sign the cursor is placed at the end of the TargetField
if myNumFieldTxt.SelectionStart=0 and myNumFieldTxt.SelectionLength=0 and myNumFieldTxt.Text.Left(1)="-" then
myNumFieldTxt.SelectionStart=myNumFieldTxt.Text.Length
end if
// All numbers must be entered
return false
end if
// Handling the case where the person wants to enter decimals in an integer field
if Key = SymbDecimal and IsAnInteger then
return true
end if
//Managing cases where the person types the decimal symbol
if ( Key = SymbDecimal ) and myNumFieldTxt.Text.Contains(SymbDecimal)=false then
if myNumFieldTxt.Text.Length = 0 or myNumFieldTxt.SelectionLength=myNumFieldTxt.Text.Length then
myNumFieldTxt.Text="0"
myNumFieldTxt.SelectionStart=myNumFieldTxt.Text.Length
end if
if myNumFieldTxt.Text= "-" then
myNumFieldTxt.Text="-0"
myNumFieldTxt.SelectionStart=myNumFieldTxt.Text.Length
end if
return false
end if
// Allows certain keys like backspace and delete
if ASC( Key ) < 32 or ASC( Key ) =127 then
return false
end if
//Management of the minus sign
if ASC( Key ) = 45 then
if myNumFieldTxt.Text.Length >0 then
if myNumFieldTxt.Text.Left(1)="-" then
// Transformation of a negative number into a positive number
myNumFieldTxt.Text=myNumFieldTxt.Text.Right(myNumFieldTxt.Text.Length - 1 )
else
// Transformation of a positive number into a negative number
myNumFieldTxt.Text="-"+myNumFieldTxt.Text
end if
else
myNumFieldTxt.text= "-"
end if
// We place the cursor at the end
myNumFieldTxt.SelectionStart=myNumFieldTxt.Text.Length
end if
// Everything that has not been permitted is forbidden.
return true
End Function
#tag EndMethod
#tag Method, Flags = &h0
Function Valide_TxtNumLostFocus(byref myNumFieldTxt as DesktopTextField, IsAnInteger as Boolean = false, Precision as integer = 0, ValMin as Double = -9999999999999, ValMax as Double = 9999999999999, ValDefaut as double = 0) As Boolean
// The purpose of this procedure is to manage the entry of numbers according to certain criteria.
// This procedure must be called from a text field during the LostFocus event
Dim MyNbr as Double
// Cleaning up spaces and tabs that could result from an unfortunate copy and paste
myNumFieldTxt.Text=myNumFieldTxt.Text.ReplaceAll(" ","")
myNumFieldTxt.Text=myNumFieldTxt.Text.ReplaceAll(chr(9),"")
// In case the field is empty and a default value has been defined
if myNumFieldTxt.Text.Length=0 then
myNumFieldTxt.Text=ValDefaut.ToString
return true
end if
// If the field is an integer and a decimal value has been entered, it is rounded down to the nearest integer.
if IsAnInteger then
myNumFieldTxt.Text=floor(myNumFieldTxt.Text.CDbl).ToString
return true
end if
MyNbr = myNumFieldTxt.Text.CDbl
// If the user enters more decimals than necessary, the value is rounded.
if Precision > 0 then
MyNbr = SuperRound(myNumFieldTxt.Text.CDbl,precision)
end if
// Case where the user has exceeded the minimum or maximum values
if MyNbr<ValMin then
MessageBox "The value you entered ("+MyNbr.ToString+") is less than the minimum allowed value ("+ValMin.ToString+"), "+EndOfLine+_
"the program assigned the minimum value to the field"
myNumFieldTxt.Text = ValMin.ToString
return false
end if
if MyNbr>ValMax then
MessageBox "The value you entered ("+MyNbr.ToString+") is greater than the maximum allowed value ("+ValMin.ToString+"), "+EndOfLine+_
"the program assigned the maximum value to the field"
myNumFieldTxt.Text = ValMin.ToString
return false
end if
//Everything that has not been forbidden is permitted
myNumFieldTxt.Text=MyNbr.ToString
return true
End Function
#tag EndMethod
#tag Note, Name = Licence MIT
MIT License
Copyright (c) 2025 Fabrice Garcia, 20290 Borgo, Corsica Island , France, Europe.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
#tag EndNote
#tag Note, Name = ReadMe : MySQL Prerequisites
1- In order for this program to work correctly: you must log in with a user who has certain rights at the MySQL database level.
2- The user must have the following rights in particular: : SHOW, SELECT, INSERT, UPDATE, DELETE, CREATE TABLE...
3- To work : this example program will need to create a CUSTOMERS table and manipulate the data inside
4- WARNING: This program is intended to provide you with an example of using xojo with MySQL: it is strongly recommended to use it ONLY on a test database without any important data.
5- Please remember that this program is provided to you under the MIT License.
#tag EndNote
#tag Note, Name = ReadMe: About missing images
When you first open the project, Xojo may not find the images.
This is a common problem when a Xojo project is moved to another computer.
The images are all located in the pictures folder : Don't panic, none are missing.
In the alert window asking you to locate the missing images, check all the images and click the Resolve button, go to the pictures folder ( inside the project folder ) and designate them.
The images used were all generated by the software author using AI and are royalty-free. You are free to use them in other projects as you wish. They are also covered by the MIT license.
#tag EndNote
#tag Note, Name = ReadMe: Adapting to your needs
I wrote in the comments a tag : // [Update-XojoCode-NextLines]
When you see this tag in comments, it means that the program probably needs to be modified in the following lines to meet your needs.
If you see this tag in the declaration of a variable, it means that you will probably need to modify the name of the variable or its default value to adapt the program to your needs.
Please note: This does not mean that depending on what you want to do, you will only need to modify these lines.
This is simply an aid to help you locate important points that most likely need to be modified to suit your needs.
I do not claim to be exhaustive on this subject.
#tag EndNote
#tag Note, Name = ReadMe: Excel data export
------------------------------------------------------
* Procedure to unlock data export to Microsoft Excel *
------------------------------------------------------
1- You will need to copy the MSOfficeAutomation plugin (located in the Extras folder of the xojo installation) to the Plugins folder before you can use this functionality.
2- Exit Xojo and relaunch the application
3- You must have Microsoft Excel installed on your computer, ONLY works on Windows PC.
4- Open Class Class_Export, open methods Export_Excel : read the comments
5- Inside Class_Export.Export_Excel : Uncomment the area defined by the comments (From: #If Target Windows ... until #Endif)
#tag EndNote
#tag Note, Name = ReadMe: Project structure
The project includes 3 windows :
- A start window ( Win_Welcome ) that includes the menu for opening, creating, and closing databases and a number of indications.
- A data list window ( Win_CustomerList ) that allows you to Create, Read, Modify, Delete records from the MySQL database.
- A customer data entry form (Win_CustomerForm)
________________________________
At the Object class level :
1 - Class_Customer :
This class allows you to create an abstraction layer to manage data from the MySQL database.
This class allows you to create, add, modify, delete, read records from the database.
The advantages of using a class and not typing instructions directly into the project windows are numerous.
This greatly facilitates project maintenance and avoids code duplication.
Furthermore, if you ever want to change the database type and the database operations need to be handled differently, you'll only have to modify this class.
There's no need to travel to all the project windows to modify code, which is tiring.
In addition, this makes the code more independent of Xojo instructions.
In the event that these instructions change or their uses change, your program is not to be thrown away.
Using classes ensures a certain longevity of the project.
2 - Class_XojoDBDict :
The purpose of this class is to initialize the MySQL database.
This class creates the blank tables necessary for the program to function.
3- Class_MenuTable and Class_MenuWelcome
Manages the program menus.
4- Class_Export
The purpose of this class is to export the database data in CSV or Microsoft Excel format.
#tag EndNote
#tag Property, Flags = &h0
MainDB As MySQLCommunityServer
#tag EndProperty
#tag Constant, Name = kEditClear, Type = String, Dynamic = False, Default = \"&Delete", Scope = Public
#Tag Instance, Platform = Windows, Language = Default, Definition = \"&Delete"
#Tag Instance, Platform = Linux, Language = Default, Definition = \"&Delete"
#tag EndConstant
#tag Constant, Name = kFileQuit, Type = String, Dynamic = False, Default = \"&Quit", Scope = Public
#Tag Instance, Platform = Windows, Language = Default, Definition = \"E&xit"
#tag EndConstant
#tag Constant, Name = kFileQuitShortcut, Type = String, Dynamic = False, Default = \"", Scope = Public
#Tag Instance, Platform = Mac OS, Language = Default, Definition = \"Cmd+Q"
#Tag Instance, Platform = Linux, Language = Default, Definition = \"Ctrl+Q"
#tag EndConstant
#tag Constant, Name = SymbDecimal, Type = String, Dynamic = False, Default = \".", Scope = Public
#Tag Instance, Platform = Mac OS, Language = Default, Definition = \"\x2C"
#Tag Instance, Platform = Linux, Language = Default, Definition = \"."
#Tag Instance, Platform = Windows, Language = Default, Definition = \"."
#tag EndConstant
#tag ViewBehavior
#tag ViewProperty
Name="Name"
Visible=false
Group="ID"
InitialValue=""
Type="String"
EditorType=""
#tag EndViewProperty
#tag ViewProperty
Name="Index"
Visible=false
Group="ID"
InitialValue=""
Type="Integer"
EditorType=""
#tag EndViewProperty
#tag ViewProperty
Name="Super"
Visible=false
Group="ID"
InitialValue=""
Type="String"
EditorType=""
#tag EndViewProperty
#tag ViewProperty
Name="Left"
Visible=false
Group="Position"
InitialValue=""
Type="Integer"
EditorType=""
#tag EndViewProperty
#tag ViewProperty
Name="Top"
Visible=false
Group="Position"
InitialValue=""
Type="Integer"
EditorType=""
#tag EndViewProperty
#tag ViewProperty
Name="AllowAutoQuit"
Visible=false
Group="Behavior"
InitialValue=""
Type="Boolean"
EditorType=""
#tag EndViewProperty
#tag ViewProperty
Name="AllowHiDPI"
Visible=false
Group="Behavior"
InitialValue=""
Type="Boolean"
EditorType=""
#tag EndViewProperty
#tag ViewProperty
Name="BugVersion"
Visible=false
Group="Behavior"
InitialValue=""
Type="Integer"
EditorType=""
#tag EndViewProperty
#tag ViewProperty
Name="Copyright"
Visible=false
Group="Behavior"
InitialValue=""
Type="String"
EditorType="MultiLineEditor"
#tag EndViewProperty
#tag ViewProperty
Name="Description"
Visible=false
Group="Behavior"
InitialValue=""
Type="String"
EditorType="MultiLineEditor"
#tag EndViewProperty
#tag ViewProperty
Name="LastWindowIndex"
Visible=false
Group="Behavior"
InitialValue=""
Type="Integer"
EditorType=""
#tag EndViewProperty
#tag ViewProperty
Name="MajorVersion"
Visible=false
Group="Behavior"
InitialValue=""
Type="Integer"
EditorType=""
#tag EndViewProperty
#tag ViewProperty
Name="MinorVersion"
Visible=false
Group="Behavior"
InitialValue=""
Type="Integer"
EditorType=""
#tag EndViewProperty
#tag ViewProperty
Name="NonReleaseVersion"
Visible=false
Group="Behavior"
InitialValue=""
Type="Integer"
EditorType=""
#tag EndViewProperty
#tag ViewProperty
Name="RegionCode"
Visible=false
Group="Behavior"
InitialValue=""
Type="Integer"
EditorType=""
#tag EndViewProperty
#tag ViewProperty
Name="StageCode"
Visible=false
Group="Behavior"
InitialValue=""
Type="Integer"
EditorType=""
#tag EndViewProperty
#tag ViewProperty
Name="Version"
Visible=false
Group="Behavior"
InitialValue=""
Type="string"
EditorType="MultiLineEditor"
#tag EndViewProperty
#tag ViewProperty
Name="_CurrentEventTime"
Visible=false
Group="Behavior"
InitialValue=""
Type="Integer"
EditorType=""
#tag EndViewProperty
#tag EndViewBehavior
End Class
#tag EndClass