-
Notifications
You must be signed in to change notification settings - Fork 0
/
MainWindow.py
1750 lines (1414 loc) · 87.4 KB
/
MainWindow.py
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
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
from PyQt5.QtWidgets import QApplication, QMessageBox, QMainWindow, QTableWidgetItem
from PyQt5 import QtCore, QtGui, QtWidgets
import sqlite3
from datetime import datetime
import random
from PyQt5 import QtCore, QtGui, QtWidgets
import CustomerInfo
class Ui_MainWindow(QMainWindow):
def __init__(self):
"""
Initialize the class instance and establish a connection to the SQLite database.
This method is the constructor of the class and is automatically called when an instance of the class is created.
It establishes a connection to the SQLite database named 'BankDatabase.db' and creates a cursor object to perform database operations.
Parameters:
- self: The instance of the class.
Returns:
None
"""
super(Ui_MainWindow, self).__init__()
# Establish a connection to the SQLite database named 'BankDatabase.db'
self.connect = sqlite3.connect('BankDatabase.db')
# Create a cursor object to perform database operations
self.cursor = self.connect.cursor()
def setupUi(self, MainWindow):
MainWindow.setObjectName("MainWindow")
MainWindow.resize(1000, 940)
MainWindow.setMinimumSize(QtCore.QSize(1000, 940))
MainWindow.setMaximumSize(QtCore.QSize(1000, 940))
font = QtGui.QFont()
font.setPointSize(12)
MainWindow.setFont(font)
self.centralwidget = QtWidgets.QWidget(MainWindow)
self.centralwidget.setObjectName("centralwidget")
self.groupBox_5 = QtWidgets.QGroupBox(self.centralwidget)
self.groupBox_5.setGeometry(QtCore.QRect(340, 430, 641, 481))
self.groupBox_5.setObjectName("groupBox_5")
self.verticalLayout = QtWidgets.QVBoxLayout(self.groupBox_5)
self.verticalLayout.setObjectName("verticalLayout")
self.formLayout_3 = QtWidgets.QFormLayout()
self.formLayout_3.setObjectName("formLayout_3")
self.label_5 = QtWidgets.QLabel(self.groupBox_5)
self.label_5.setObjectName("label_5")
self.formLayout_3.setWidget(0, QtWidgets.QFormLayout.LabelRole, self.label_5)
self.txt_lastActivity = QtWidgets.QLineEdit(self.groupBox_5)
self.txt_lastActivity.setEnabled(False)
self.txt_lastActivity.setFrame(False)
self.txt_lastActivity.setObjectName("txt_lastActivity")
self.formLayout_3.setWidget(0, QtWidgets.QFormLayout.FieldRole, self.txt_lastActivity)
self.label_6 = QtWidgets.QLabel(self.groupBox_5)
self.label_6.setObjectName("label_6")
self.formLayout_3.setWidget(1, QtWidgets.QFormLayout.LabelRole, self.label_6)
self.tct_openingDate = QtWidgets.QLineEdit(self.groupBox_5)
self.tct_openingDate.setEnabled(False)
self.tct_openingDate.setFrame(False)
self.tct_openingDate.setObjectName("tct_openingDate")
self.formLayout_3.setWidget(1, QtWidgets.QFormLayout.FieldRole, self.tct_openingDate)
self.label_7 = QtWidgets.QLabel(self.groupBox_5)
self.label_7.setObjectName("label_7")
self.formLayout_3.setWidget(2, QtWidgets.QFormLayout.LabelRole, self.label_7)
self.txt_nameSurname = QtWidgets.QLineEdit(self.groupBox_5)
self.txt_nameSurname.setEnabled(False)
self.txt_nameSurname.setFrame(False)
self.txt_nameSurname.setObjectName("txt_nameSurname")
self.formLayout_3.setWidget(2, QtWidgets.QFormLayout.FieldRole, self.txt_nameSurname)
self.label_8 = QtWidgets.QLabel(self.groupBox_5)
self.label_8.setObjectName("label_8")
self.formLayout_3.setWidget(3, QtWidgets.QFormLayout.LabelRole, self.label_8)
self.txt_customerNumber = QtWidgets.QLineEdit(self.groupBox_5)
self.txt_customerNumber.setEnabled(False)
self.txt_customerNumber.setFrame(False)
self.txt_customerNumber.setObjectName("txt_customerNumber")
self.formLayout_3.setWidget(3, QtWidgets.QFormLayout.FieldRole, self.txt_customerNumber)
self.label_9 = QtWidgets.QLabel(self.groupBox_5)
self.label_9.setObjectName("label_9")
self.formLayout_3.setWidget(4, QtWidgets.QFormLayout.LabelRole, self.label_9)
self.txt_accountName = QtWidgets.QLineEdit(self.groupBox_5)
self.txt_accountName.setEnabled(False)
self.txt_accountName.setFrame(False)
self.txt_accountName.setObjectName("txt_accountName")
self.formLayout_3.setWidget(4, QtWidgets.QFormLayout.FieldRole, self.txt_accountName)
self.label_10 = QtWidgets.QLabel(self.groupBox_5)
self.label_10.setObjectName("label_10")
self.formLayout_3.setWidget(6, QtWidgets.QFormLayout.LabelRole, self.label_10)
self.txt_balance = QtWidgets.QLineEdit(self.groupBox_5)
self.txt_balance.setEnabled(False)
self.txt_balance.setFrame(False)
self.txt_balance.setObjectName("txt_balance")
self.formLayout_3.setWidget(6, QtWidgets.QFormLayout.FieldRole, self.txt_balance)
self.txt_accountNumber = QtWidgets.QLineEdit(self.groupBox_5)
self.txt_accountNumber.setEnabled(False)
self.txt_accountNumber.setFrame(False)
self.txt_accountNumber.setObjectName("txt_accountNumber")
self.formLayout_3.setWidget(7, QtWidgets.QFormLayout.FieldRole, self.txt_accountNumber)
self.label_11 = QtWidgets.QLabel(self.groupBox_5)
self.label_11.setObjectName("label_11")
self.formLayout_3.setWidget(7, QtWidgets.QFormLayout.LabelRole, self.label_11)
self.label_12 = QtWidgets.QLabel(self.groupBox_5)
self.label_12.setObjectName("label_12")
self.formLayout_3.setWidget(5, QtWidgets.QFormLayout.LabelRole, self.label_12)
self.txt_currency = QtWidgets.QLineEdit(self.groupBox_5)
self.txt_currency.setEnabled(False)
self.txt_currency.setFrame(False)
self.txt_currency.setObjectName("txt_currency")
self.formLayout_3.setWidget(5, QtWidgets.QFormLayout.FieldRole, self.txt_currency)
self.verticalLayout.addLayout(self.formLayout_3)
self.btn_changeAccount = QtWidgets.QPushButton(self.groupBox_5)
sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Minimum, QtWidgets.QSizePolicy.Expanding)
sizePolicy.setHorizontalStretch(0)
sizePolicy.setVerticalStretch(0)
sizePolicy.setHeightForWidth(self.btn_changeAccount.sizePolicy().hasHeightForWidth())
self.btn_changeAccount.setSizePolicy(sizePolicy)
self.btn_changeAccount.setObjectName("btn_changeAccount")
self.verticalLayout.addWidget(self.btn_changeAccount)
self.groupBox_6 = QtWidgets.QGroupBox(self.centralwidget)
self.groupBox_6.setGeometry(QtCore.QRect(10, 160, 321, 271))
self.groupBox_6.setObjectName("groupBox_6")
self.formLayoutWidget = QtWidgets.QWidget(self.groupBox_6)
self.formLayoutWidget.setGeometry(QtCore.QRect(9, 29, 301, 231))
self.formLayoutWidget.setObjectName("formLayoutWidget")
self.formLayout_4 = QtWidgets.QFormLayout(self.formLayoutWidget)
self.formLayout_4.setContentsMargins(0, 0, 0, 0)
self.formLayout_4.setObjectName("formLayout_4")
self.label_13 = QtWidgets.QLabel(self.formLayoutWidget)
self.label_13.setObjectName("label_13")
self.formLayout_4.setWidget(0, QtWidgets.QFormLayout.LabelRole, self.label_13)
self.txt_accountName_Account = QtWidgets.QLineEdit(self.formLayoutWidget)
self.txt_accountName_Account.setFrame(False)
self.txt_accountName_Account.setObjectName("txt_accountName_Account")
self.formLayout_4.setWidget(0, QtWidgets.QFormLayout.FieldRole, self.txt_accountName_Account)
self.label_14 = QtWidgets.QLabel(self.formLayoutWidget)
self.label_14.setObjectName("label_14")
self.formLayout_4.setWidget(1, QtWidgets.QFormLayout.LabelRole, self.label_14)
self.currency_choice = QtWidgets.QComboBox(self.formLayoutWidget)
self.currency_choice.setObjectName("currency_choice")
self.currency_choice.addItem("")
self.currency_choice.addItem("")
self.currency_choice.addItem("")
self.currency_choice.addItem("")
self.formLayout_4.setWidget(1, QtWidgets.QFormLayout.FieldRole, self.currency_choice)
self.btn_newBankAccount = QtWidgets.QPushButton(self.formLayoutWidget)
self.btn_newBankAccount.setObjectName("btn_newBankAccount")
self.formLayout_4.setWidget(3, QtWidgets.QFormLayout.SpanningRole, self.btn_newBankAccount)
self.btn_deleteBankAccount = QtWidgets.QPushButton(self.formLayoutWidget)
self.btn_deleteBankAccount.setObjectName("btn_deleteBankAccount")
self.formLayout_4.setWidget(4, QtWidgets.QFormLayout.SpanningRole, self.btn_deleteBankAccount)
self.btn_updateBankAccount = QtWidgets.QPushButton(self.formLayoutWidget)
self.btn_updateBankAccount.setObjectName("btn_updateBankAccount")
self.formLayout_4.setWidget(5, QtWidgets.QFormLayout.SpanningRole, self.btn_updateBankAccount)
self.chckBox_mainAccount = QtWidgets.QCheckBox(self.formLayoutWidget)
self.chckBox_mainAccount.setObjectName("chckBox_mainAccount")
self.formLayout_4.setWidget(2, QtWidgets.QFormLayout.SpanningRole, self.chckBox_mainAccount)
self.groupBox_7 = QtWidgets.QGroupBox(self.centralwidget)
self.groupBox_7.setGeometry(QtCore.QRect(10, 430, 321, 241))
self.groupBox_7.setObjectName("groupBox_7")
self.formLayoutWidget_2 = QtWidgets.QWidget(self.groupBox_7)
self.formLayoutWidget_2.setGeometry(QtCore.QRect(9, 29, 301, 201))
self.formLayoutWidget_2.setObjectName("formLayoutWidget_2")
self.formLayout_5 = QtWidgets.QFormLayout(self.formLayoutWidget_2)
self.formLayout_5.setContentsMargins(0, 0, 0, 0)
self.formLayout_5.setObjectName("formLayout_5")
self.btn_loadAccounts = QtWidgets.QPushButton(self.formLayoutWidget_2)
self.btn_loadAccounts.setObjectName("btn_loadAccounts")
self.formLayout_5.setWidget(0, QtWidgets.QFormLayout.SpanningRole, self.btn_loadAccounts)
self.label_16 = QtWidgets.QLabel(self.formLayoutWidget_2)
self.label_16.setObjectName("label_16")
self.formLayout_5.setWidget(1, QtWidgets.QFormLayout.LabelRole, self.label_16)
self.account_choice_Money = QtWidgets.QComboBox(self.formLayoutWidget_2)
self.account_choice_Money.setFrame(False)
self.account_choice_Money.setObjectName("account_choice_Money")
self.formLayout_5.setWidget(1, QtWidgets.QFormLayout.FieldRole, self.account_choice_Money)
self.label_15 = QtWidgets.QLabel(self.formLayoutWidget_2)
self.label_15.setObjectName("label_15")
self.formLayout_5.setWidget(2, QtWidgets.QFormLayout.LabelRole, self.label_15)
self.txt_amount_Money = QtWidgets.QLineEdit(self.formLayoutWidget_2)
self.txt_amount_Money.setFrame(False)
self.txt_amount_Money.setObjectName("txt_amount_Money")
self.formLayout_5.setWidget(2, QtWidgets.QFormLayout.FieldRole, self.txt_amount_Money)
self.btn_withDrawMoney = QtWidgets.QPushButton(self.formLayoutWidget_2)
self.btn_withDrawMoney.setObjectName("btn_withDrawMoney")
self.formLayout_5.setWidget(3, QtWidgets.QFormLayout.SpanningRole, self.btn_withDrawMoney)
self.btn_DepositMoney = QtWidgets.QPushButton(self.formLayoutWidget_2)
self.btn_DepositMoney.setObjectName("btn_DepositMoney")
self.formLayout_5.setWidget(4, QtWidgets.QFormLayout.SpanningRole, self.btn_DepositMoney)
self.groupBox_8 = QtWidgets.QGroupBox(self.centralwidget)
self.groupBox_8.setGeometry(QtCore.QRect(10, 670, 321, 241))
self.groupBox_8.setObjectName("groupBox_8")
self.formLayoutWidget_3 = QtWidgets.QWidget(self.groupBox_8)
self.formLayoutWidget_3.setGeometry(QtCore.QRect(9, 30, 301, 201))
self.formLayoutWidget_3.setObjectName("formLayoutWidget_3")
self.formLayout_6 = QtWidgets.QFormLayout(self.formLayoutWidget_3)
self.formLayout_6.setContentsMargins(0, 0, 0, 0)
self.formLayout_6.setObjectName("formLayout_6")
self.label_18 = QtWidgets.QLabel(self.formLayoutWidget_3)
self.label_18.setObjectName("label_18")
self.formLayout_6.setWidget(1, QtWidgets.QFormLayout.LabelRole, self.label_18)
self.customer_choice_Transfer = QtWidgets.QComboBox(self.formLayoutWidget_3)
self.customer_choice_Transfer.setFrame(False)
self.customer_choice_Transfer.setObjectName("customer_choice_Transfer")
self.formLayout_6.setWidget(1, QtWidgets.QFormLayout.FieldRole, self.customer_choice_Transfer)
self.label_17 = QtWidgets.QLabel(self.formLayoutWidget_3)
self.label_17.setObjectName("label_17")
self.formLayout_6.setWidget(2, QtWidgets.QFormLayout.LabelRole, self.label_17)
self.account_chose_transfer = QtWidgets.QComboBox(self.formLayoutWidget_3)
self.account_chose_transfer.setFrame(False)
self.account_chose_transfer.setObjectName("account_chose_transfer")
self.formLayout_6.setWidget(2, QtWidgets.QFormLayout.FieldRole, self.account_chose_transfer)
self.label_3 = QtWidgets.QLabel(self.formLayoutWidget_3)
self.label_3.setObjectName("label_3")
self.formLayout_6.setWidget(3, QtWidgets.QFormLayout.LabelRole, self.label_3)
self.txt_amount_Transfer = QtWidgets.QLineEdit(self.formLayoutWidget_3)
self.txt_amount_Transfer.setFrame(False)
self.txt_amount_Transfer.setObjectName("txt_amount_Transfer")
self.formLayout_6.setWidget(3, QtWidgets.QFormLayout.FieldRole, self.txt_amount_Transfer)
self.btn_loadCustomers = QtWidgets.QPushButton(self.formLayoutWidget_3)
self.btn_loadCustomers.setObjectName("btn_loadCustomers")
self.formLayout_6.setWidget(0, QtWidgets.QFormLayout.SpanningRole, self.btn_loadCustomers)
self.btn_moneyTransfer = QtWidgets.QPushButton(self.formLayoutWidget_3)
self.btn_moneyTransfer.setObjectName("btn_moneyTransfer")
self.formLayout_6.setWidget(4, QtWidgets.QFormLayout.SpanningRole, self.btn_moneyTransfer)
self.groupBox_9 = QtWidgets.QGroupBox(self.centralwidget)
self.groupBox_9.setGeometry(QtCore.QRect(340, 10, 641, 221))
self.groupBox_9.setObjectName("groupBox_9")
self.widget = QtWidgets.QWidget(self.groupBox_9)
self.widget.setGeometry(QtCore.QRect(10, 29, 621, 185))
self.widget.setObjectName("widget")
self.horizontalLayout = QtWidgets.QHBoxLayout(self.widget)
self.horizontalLayout.setContentsMargins(0, 0, 0, 0)
self.horizontalLayout.setObjectName("horizontalLayout")
self.verticalLayout_5 = QtWidgets.QVBoxLayout()
self.verticalLayout_5.setObjectName("verticalLayout_5")
self.btn_newCreditCard = QtWidgets.QPushButton(self.widget)
self.btn_newCreditCard.setObjectName("btn_newCreditCard")
self.verticalLayout_5.addWidget(self.btn_newCreditCard)
self.btn_useCard = QtWidgets.QPushButton(self.widget)
self.btn_useCard.setObjectName("btn_useCard")
self.verticalLayout_5.addWidget(self.btn_useCard)
self.btn_payCreditCardDept = QtWidgets.QPushButton(self.widget)
self.btn_payCreditCardDept.setObjectName("btn_payCreditCardDept")
self.verticalLayout_5.addWidget(self.btn_payCreditCardDept)
self.btn_showCreditCardDept = QtWidgets.QPushButton(self.widget)
self.btn_showCreditCardDept.setObjectName("btn_showCreditCardDept")
self.verticalLayout_5.addWidget(self.btn_showCreditCardDept)
self.horizontalLayout.addLayout(self.verticalLayout_5)
self.formLayout_7 = QtWidgets.QFormLayout()
self.formLayout_7.setObjectName("formLayout_7")
self.label_19 = QtWidgets.QLabel(self.widget)
self.label_19.setObjectName("label_19")
self.formLayout_7.setWidget(1, QtWidgets.QFormLayout.LabelRole, self.label_19)
self.txt_cardLimit_CreditCard = QtWidgets.QLineEdit(self.widget)
self.txt_cardLimit_CreditCard.setFrame(False)
self.txt_cardLimit_CreditCard.setObjectName("txt_cardLimit_CreditCard")
self.formLayout_7.setWidget(1, QtWidgets.QFormLayout.FieldRole, self.txt_cardLimit_CreditCard)
self.label_20 = QtWidgets.QLabel(self.widget)
self.label_20.setObjectName("label_20")
self.formLayout_7.setWidget(3, QtWidgets.QFormLayout.LabelRole, self.label_20)
self.txt_spendMoney_CreditCard = QtWidgets.QLineEdit(self.widget)
self.txt_spendMoney_CreditCard.setFrame(False)
self.txt_spendMoney_CreditCard.setObjectName("txt_spendMoney_CreditCard")
self.formLayout_7.setWidget(3, QtWidgets.QFormLayout.FieldRole, self.txt_spendMoney_CreditCard)
self.label_21 = QtWidgets.QLabel(self.widget)
self.label_21.setObjectName("label_21")
self.formLayout_7.setWidget(4, QtWidgets.QFormLayout.LabelRole, self.label_21)
self.txt_payDebt_CreditCard = QtWidgets.QLineEdit(self.widget)
self.txt_payDebt_CreditCard.setFrame(False)
self.txt_payDebt_CreditCard.setObjectName("txt_payDebt_CreditCard")
self.formLayout_7.setWidget(4, QtWidgets.QFormLayout.FieldRole, self.txt_payDebt_CreditCard)
self.label_24 = QtWidgets.QLabel(self.widget)
self.label_24.setObjectName("label_24")
self.formLayout_7.setWidget(2, QtWidgets.QFormLayout.LabelRole, self.label_24)
self.cardNumber_chose = QtWidgets.QComboBox(self.widget)
self.cardNumber_chose.setFrame(False)
self.cardNumber_chose.setObjectName("cardNumber_chose")
self.formLayout_7.setWidget(2, QtWidgets.QFormLayout.FieldRole, self.cardNumber_chose)
self.btn_loadCards = QtWidgets.QPushButton(self.widget)
self.btn_loadCards.setObjectName("btn_loadCards")
self.formLayout_7.setWidget(0, QtWidgets.QFormLayout.SpanningRole, self.btn_loadCards)
self.horizontalLayout.addLayout(self.formLayout_7)
self.groupBox_10 = QtWidgets.QGroupBox(self.centralwidget)
self.groupBox_10.setGeometry(QtCore.QRect(340, 230, 641, 201))
self.groupBox_10.setObjectName("groupBox_10")
self.widget1 = QtWidgets.QWidget(self.groupBox_10)
self.widget1.setGeometry(QtCore.QRect(10, 26, 621, 151))
self.widget1.setObjectName("widget1")
self.horizontalLayout_2 = QtWidgets.QHBoxLayout(self.widget1)
self.horizontalLayout_2.setContentsMargins(0, 0, 0, 0)
self.horizontalLayout_2.setObjectName("horizontalLayout_2")
self.verticalLayout_3 = QtWidgets.QVBoxLayout()
self.verticalLayout_3.setObjectName("verticalLayout_3")
self.btn_newCredit = QtWidgets.QPushButton(self.widget1)
self.btn_newCredit.setObjectName("btn_newCredit")
self.verticalLayout_3.addWidget(self.btn_newCredit)
self.btn_payCreditLoan = QtWidgets.QPushButton(self.widget1)
self.btn_payCreditLoan.setObjectName("btn_payCreditLoan")
self.verticalLayout_3.addWidget(self.btn_payCreditLoan)
self.btn_showLoan = QtWidgets.QPushButton(self.widget1)
self.btn_showLoan.setObjectName("btn_showLoan")
self.verticalLayout_3.addWidget(self.btn_showLoan)
self.horizontalLayout_2.addLayout(self.verticalLayout_3)
self.formLayout_8 = QtWidgets.QFormLayout()
self.formLayout_8.setObjectName("formLayout_8")
self.label_22 = QtWidgets.QLabel(self.widget1)
self.label_22.setObjectName("label_22")
self.formLayout_8.setWidget(1, QtWidgets.QFormLayout.LabelRole, self.label_22)
self.txt_CreditAmount_Credit = QtWidgets.QLineEdit(self.widget1)
self.txt_CreditAmount_Credit.setFrame(False)
self.txt_CreditAmount_Credit.setObjectName("txt_CreditAmount_Credit")
self.formLayout_8.setWidget(1, QtWidgets.QFormLayout.FieldRole, self.txt_CreditAmount_Credit)
self.creditNumber_chose = QtWidgets.QComboBox(self.widget1)
self.creditNumber_chose.setFrame(False)
self.creditNumber_chose.setObjectName("creditNumber_chose")
self.formLayout_8.setWidget(2, QtWidgets.QFormLayout.FieldRole, self.creditNumber_chose)
self.label_23 = QtWidgets.QLabel(self.widget1)
self.label_23.setObjectName("label_23")
self.formLayout_8.setWidget(3, QtWidgets.QFormLayout.LabelRole, self.label_23)
self.txt_payLoan_Credit = QtWidgets.QLineEdit(self.widget1)
self.txt_payLoan_Credit.setFrame(False)
self.txt_payLoan_Credit.setObjectName("txt_payLoan_Credit")
self.formLayout_8.setWidget(3, QtWidgets.QFormLayout.FieldRole, self.txt_payLoan_Credit)
self.label_4 = QtWidgets.QLabel(self.widget1)
self.label_4.setObjectName("label_4")
self.formLayout_8.setWidget(2, QtWidgets.QFormLayout.LabelRole, self.label_4)
self.btn_loadCredits = QtWidgets.QPushButton(self.widget1)
self.btn_loadCredits.setObjectName("btn_loadCredits")
self.formLayout_8.setWidget(0, QtWidgets.QFormLayout.SpanningRole, self.btn_loadCredits)
self.horizontalLayout_2.addLayout(self.formLayout_8)
self.groupBox_4 = QtWidgets.QGroupBox(self.centralwidget)
self.groupBox_4.setGeometry(QtCore.QRect(10, 10, 321, 151))
self.groupBox_4.setObjectName("groupBox_4")
self.widget2 = QtWidgets.QWidget(self.groupBox_4)
self.widget2.setGeometry(QtCore.QRect(9, 30, 301, 111))
self.widget2.setObjectName("widget2")
self.verticalLayout_2 = QtWidgets.QVBoxLayout(self.widget2)
self.verticalLayout_2.setContentsMargins(0, 0, 0, 0)
self.verticalLayout_2.setObjectName("verticalLayout_2")
self.formLayout = QtWidgets.QFormLayout()
self.formLayout.setObjectName("formLayout")
self.label = QtWidgets.QLabel(self.widget2)
self.label.setObjectName("label")
self.formLayout.setWidget(0, QtWidgets.QFormLayout.LabelRole, self.label)
self.label_2 = QtWidgets.QLabel(self.widget2)
self.label_2.setObjectName("label_2")
self.formLayout.setWidget(1, QtWidgets.QFormLayout.LabelRole, self.label_2)
self.txt_username_User = QtWidgets.QLineEdit(self.widget2)
self.txt_username_User.setEnabled(False)
self.txt_username_User.setFrame(False)
self.txt_username_User.setObjectName("txt_username_User")
self.formLayout.setWidget(0, QtWidgets.QFormLayout.FieldRole, self.txt_username_User)
self.txt_email_User = QtWidgets.QLineEdit(self.widget2)
self.txt_email_User.setEnabled(False)
self.txt_email_User.setFrame(False)
self.txt_email_User.setObjectName("txt_email_User")
self.formLayout.setWidget(1, QtWidgets.QFormLayout.FieldRole, self.txt_email_User)
self.verticalLayout_2.addLayout(self.formLayout)
self.btn_customerInformations = QtWidgets.QPushButton(self.widget2)
self.btn_customerInformations.setObjectName("btn_customerInformations")
self.verticalLayout_2.addWidget(self.btn_customerInformations)
MainWindow.setCentralWidget(self.centralwidget)
self.statusbar = QtWidgets.QStatusBar(MainWindow)
self.statusbar.setObjectName("statusbar")
MainWindow.setStatusBar(self.statusbar)
self.retranslateUi(MainWindow)
QtCore.QMetaObject.connectSlotsByName(MainWindow)
# Connect button clicks to corresponding methods for customer information
self.btn_customerInformations.clicked.connect(self.showCustomerInfo)
self.btn_newBankAccount.clicked.connect(self.CreateBankAccount)
self.btn_deleteBankAccount.clicked.connect(self.deleteBankAccount)
self.btn_updateBankAccount.clicked.connect(self.updateBankAccount)
# Connect button clicks to methods for loading lists
self.btn_loadAccounts.clicked.connect(self.getAccountList)
self.btn_loadCustomers.clicked.connect(self.getCustomerList)
self.btn_loadCustomers.clicked.connect(self.getCustomerAccountList)
# Connect button clicks to methods for financial transactions
self.btn_withDrawMoney.clicked.connect(self.withdrawMoney)
self.btn_DepositMoney.clicked.connect(self.depositMoney)
# Connect button clicks to methods for account management
self.btn_changeAccount.clicked.connect(self.changeAccount)
self.btn_moneyTransfer.clicked.connect(self.transferMoney)
# Connect button clicks to methods for credit card operations
self.btn_newCreditCard.clicked.connect(self.newCreditCard)
self.btn_useCard.clicked.connect(self.useCreditCard)
self.btn_loadCards.clicked.connect(self.getCreditCardNumbers)
self.btn_payCreditCardDept.clicked.connect(self.payCreditCard)
self.btn_showCreditCardDept.clicked.connect(self.showCardDebt)
# Connect button clicks to methods for loan operations
self.btn_newCredit.clicked.connect(self.takeCredit)
self.btn_payCreditLoan.clicked.connect(self.payCreditLoan)
self.btn_loadCredits.clicked.connect(self.getLoanNumbers)
self.btn_showLoan.clicked.connect(self.showLoanDetails)
def retranslateUi(self, MainWindow):
_translate = QtCore.QCoreApplication.translate
MainWindow.setWindowTitle(_translate("MainWindow", "Bank System"))
self.groupBox_5.setTitle(_translate("MainWindow", "Account Details"))
self.label_5.setText(_translate("MainWindow", "Last Activity:"))
self.label_6.setText(_translate("MainWindow", "Opening Date:"))
self.label_7.setText(_translate("MainWindow", "Name Surname:"))
self.label_8.setText(_translate("MainWindow", "Customer Number:"))
self.label_9.setText(_translate("MainWindow", "Account Name:"))
self.label_10.setText(_translate("MainWindow", "Balance:"))
self.label_11.setText(_translate("MainWindow", "Account Number:"))
self.label_12.setText(_translate("MainWindow", "Currency:"))
self.btn_changeAccount.setText(_translate("MainWindow", "Account Details"))
self.groupBox_6.setTitle(_translate("MainWindow", "Account"))
self.label_13.setText(_translate("MainWindow", "Account Name:"))
self.label_14.setText(_translate("MainWindow", "Currency:"))
self.currency_choice.setItemText(0, _translate("MainWindow", "USD"))
self.currency_choice.setItemText(1, _translate("MainWindow", "CAD"))
self.currency_choice.setItemText(2, _translate("MainWindow", "TRY"))
self.currency_choice.setItemText(3, _translate("MainWindow", "EUR"))
self.btn_newBankAccount.setText(_translate("MainWindow", "New Bank Account"))
self.btn_deleteBankAccount.setText(_translate("MainWindow", "Delete Bank Account"))
self.btn_updateBankAccount.setText(_translate("MainWindow", "Update Bank Account"))
self.chckBox_mainAccount.setText(_translate("MainWindow", "Main Account"))
self.groupBox_7.setTitle(_translate("MainWindow", "Money Transactions"))
self.btn_loadAccounts.setText(_translate("MainWindow", "Load Accounts and Customers"))
self.label_16.setText(_translate("MainWindow", "Account:"))
self.label_15.setText(_translate("MainWindow", "Amount:"))
self.btn_withDrawMoney.setText(_translate("MainWindow", "Withdraw Money"))
self.btn_DepositMoney.setText(_translate("MainWindow", "Deposit Money"))
self.groupBox_8.setTitle(_translate("MainWindow", "Transfer"))
self.label_18.setText(_translate("MainWindow", "Customer:"))
self.label_17.setText(_translate("MainWindow", "Account:"))
self.label_3.setText(_translate("MainWindow", "Amount:"))
self.btn_loadCustomers.setText(_translate("MainWindow", "Load Customers"))
self.btn_moneyTransfer.setText(_translate("MainWindow", "Money Transfer"))
self.groupBox_9.setTitle(_translate("MainWindow", "Credit Card"))
self.btn_newCreditCard.setText(_translate("MainWindow", "New Credit Card"))
self.btn_useCard.setText(_translate("MainWindow", "Use Card"))
self.btn_payCreditCardDept.setText(_translate("MainWindow", "Pay Card Dept"))
self.btn_showCreditCardDept.setText(_translate("MainWindow", "Show Card Debt"))
self.label_19.setText(_translate("MainWindow", "Card Limit:"))
self.label_20.setText(_translate("MainWindow", "Spend Money:"))
self.label_21.setText(_translate("MainWindow", "Pay Debt:"))
self.label_24.setText(_translate("MainWindow", "Card Number:"))
self.btn_loadCards.setText(_translate("MainWindow", "Load Card Numbers"))
self.groupBox_10.setTitle(_translate("MainWindow", "Credit"))
self.btn_newCredit.setText(_translate("MainWindow", "Take Credit"))
self.btn_payCreditLoan.setText(_translate("MainWindow", "Pay Loan"))
self.btn_showLoan.setText(_translate("MainWindow", "Show Loan"))
self.label_22.setText(_translate("MainWindow", "Credit Amount:"))
self.label_23.setText(_translate("MainWindow", "Pay Loan:"))
self.label_4.setText(_translate("MainWindow", "Credit Number:"))
self.btn_loadCredits.setText(_translate("MainWindow", "Load Credit Numbers"))
self.groupBox_4.setTitle(_translate("MainWindow", "User"))
self.label.setText(_translate("MainWindow", "Username:"))
self.label_2.setText(_translate("MainWindow", "E-mail:"))
self.btn_customerInformations.setText(_translate("MainWindow", "Customer Informations"))
def showCustomerInfo(self):
"""
Retrieve and display the customer information associated with the current customer ID.
This method retrieves the current customer ID using the getCustomerID method,
fetches the customer data from the Customers table in the database based on the retrieved customer ID,
and displays the customer information in a new form.
Parameters:
- self: The instance of the class containing the cursor for database operations.
Returns:
None
"""
try:
# Retrieve the current customer ID
customer_id = self.getCustomerID()
# Execute the SQL query to fetch the customer data based on the retrieved customer ID
customer_data = self.cursor.execute('''
SELECT * FROM Customers WHERE id = ?
''', (customer_id,)).fetchone()
# Check if customer data exists
if customer_data:
# Extract customer data into a list of tuples
data = [
("Name", f"{customer_data[1]}"),
("Surname", f"{customer_data[2]}"),
("Age", customer_data[3]),
("Username", customer_data[4]),
("Password", customer_data[5]),
("Email", customer_data[6]),
("Number of Accounts", customer_data[7]),
("Join Date", customer_data[8]),
("Number of Credit Cards", customer_data[9]),
("Balance", f"{customer_data[10]} $"),
("Debt", f"{customer_data[11]} $")
]
# Create and show the CustomerInfo form
self.customerInfoWindow = CustomerInfo.Ui_customerInfo(data)
self.customerInfoWindow.show()
else:
# Display an error message if customer data is not found
self.messageBox(QMessageBox.Warning, "Error", "Customer not found.")
except Exception as e:
# Display an error message for any unexpected exceptions
self.messageBox(QMessageBox.Critical, "Error", f"An error occurred: {str(e)}")
def getCustomerID(self):
"""
Retrieve the customer ID associated with the provided username from the database.
This method retrieves the username entered by the user from the UI,
executes an SQL query to retrieve the customer ID associated with the provided username,
and returns the retrieved customer ID.
Parameters:
- self: The instance of the class containing the cursor for database operations.
Returns:
int - The customer ID associated with the provided username.
"""
try:
# Retrieve the username entered by the user from the UI
username = self.txt_username_User.text()
# Execute the SQL query to retrieve the customer ID associated with the provided username
customer_id = self.cursor.execute('''
SELECT id FROM Customers WHERE username = ?
''', (username,)).fetchone()[0]
# Return the retrieved customer ID
return customer_id
except Exception as e:
# Display an error message for any unexpected exceptions
self.messageBox(QMessageBox.Critical, "Error", f"An error occurred: {str(e)}")
return None
def messageBox(self, icon, title, message):
"""
Display a QMessageBox with the specified icon, title, and message.
Parameters:
- icon: QMessageBox.Icon (e.g., QMessageBox.Warning, QMessageBox.Information)
- title: str - The title of the QMessageBox
- message: str - The message to display in the QMessageBox
Returns:
None
"""
try:
# Create a QMessageBox instance
msg_box = QMessageBox()
# Set the icon, title, and message for the QMessageBox
msg_box.setIcon(icon)
msg_box.setWindowTitle(title)
msg_box.setText(message)
# Execute the QMessageBox
msg_box.exec_()
except Exception as e:
# Display an error message for any unexpected exceptions
print(f"An error occurred: {str(e)}")
def CreateBankAccount(self):
"""
Create a new bank account for the current customer.
This method retrieves the account name, currency choice, and main account checkbox status from the UI,
generates a random account number, sets the initial balance and opening date,
retrieves the customer ID using the getCustomerID method,
inserts the new account details into the Accounts table in the database,
and displays a success or warning message based on the result of the account creation operation.
Parameters:
- self: The instance of the class containing the cursor for database operations.
Returns:
None
"""
try:
# Retrieve account name, currency choice, and main account checkbox status from the UI
account_name = self.txt_accountName_Account.text()
if account_name:
account_number = random.randint(10000000000, 999999999999)
balance = 0.0
currency = self.currency_choice.currentText()
opening_date = datetime.now()
last_activity = opening_date
customer_id = self.getCustomerID()
is_main = 1 if self.chckBox_mainAccount.isChecked() else 0
# Pass values as a tuple
values = (account_name, account_number, balance, currency, opening_date, last_activity, customer_id, is_main)
# Execute the SQL query to insert the new account details into the Accounts table
self.cursor.execute('''
INSERT INTO Accounts (account_name, account_number, balance, currency, opening_date, last_activity, customer_id, is_main)
VALUES (?, ?, ?, ?, ?, ?, ?, ?)
''', values)
# Commit the changes to the database
self.connect.commit()
# Clear the account name field in the UI
self.txt_accountName_Account.setText("")
# Display a success message
self.messageBox(QMessageBox.Information, "Success", "Account created successfully.")
else:
# Display a warning message for invalid account name
self.messageBox(QMessageBox.Warning, "Warning", "Invalid account name.")
except Exception as e:
# Display an error message for any unexpected exceptions
self.messageBox(QMessageBox.Critical, "Error", f"An error occurred: {str(e)}")
def getAccountID(self):
"""
Retrieve the account ID associated with the current customer from the database.
This method retrieves the customer ID using the getCustomerID method,
executes an SQL query to retrieve the account ID associated with the retrieved customer ID,
and returns the retrieved account ID.
Parameters:
- self: The instance of the class containing the cursor for database operations.
Returns:
int - The account ID associated with the current customer.
"""
try:
# Retrieve the customer ID using the getCustomerID method
customer_id = self.getCustomerID()
# Execute the SQL query to retrieve the account ID associated with the retrieved customer ID
account_id = self.cursor.execute('''
SELECT id FROM Accounts WHERE customer_id = ?
''', (customer_id,)).fetchone()
# Return the retrieved account ID if found, otherwise return None
return account_id[0] if account_id else None
except Exception as e:
# Display an error message for any unexpected exceptions
self.messageBox(QMessageBox.Critical, "Error", f"An error occurred: {str(e)}")
return None
def getAccountName(self, account_id):
"""
Retrieve the account name associated with the provided account ID from the database.
This method executes an SQL query to retrieve the account name associated with the provided account ID,
and returns the retrieved account name or "No Account Yet" if the account does not exist.
Parameters:
- self: The instance of the class containing the cursor for database operations.
- account_id: int - The ID of the account for which the account name is to be retrieved.
Returns:
str - The account name associated with the provided account ID, or "No Account Yet" if the account does not exist.
"""
try:
# Execute the SQL query to retrieve the account name associated with the provided account ID
account_name = self.cursor.execute('''
SELECT account_name FROM Accounts WHERE id = ?
''', (account_id,)).fetchone()
# Return the retrieved account name if found, otherwise return "No Account Yet"
return account_name[0] if account_name else "No Account Yet"
except Exception as e:
# Display an error message for any unexpected exceptions
self.messageBox(QMessageBox.Critical, "Error", f"An error occurred: {str(e)}")
return "No Account Yet"
def deleteBankAccount(self):
"""
Delete a bank account associated with the current customer.
This method retrieves the customer ID and account name from the UI,
checks if the provided account name exists for the current customer in the Accounts table,
deletes the account from the Accounts table if it exists,
and displays a success or warning message based on the result of the account deletion operation.
Parameters:
- self: The instance of the class containing the cursor for database operations.
Returns:
None
"""
try:
# Retrieve customer ID and account name from the UI
customer_id = self.getCustomerID()
account_name = self.txt_accountName_Account.text()
# Check if the provided account name exists for the current customer in the Accounts table
does_Exist = self.cursor.execute('SELECT account_name FROM Accounts WHERE account_name = ? AND customer_id = ?', (account_name, customer_id)).fetchone()
if does_Exist:
# Execute the SQL query to delete the account from the Accounts table
self.cursor.execute('DELETE FROM Accounts WHERE customer_id = ? AND account_name = ?', (customer_id, account_name))
# Commit the changes to the database
self.connect.commit()
# Display a success message
self.messageBox(QMessageBox.Information, "Success", "Account deleted successfully.")
else:
# Display a warning message if the account does not exist
self.messageBox(QMessageBox.Warning, "Warning", "Account doesn't exist.")
# Clear the account name field in the UI
self.txt_accountName_Account.setText("")
except Exception as e:
# Display an error message for any unexpected exceptions
self.messageBox(QMessageBox.Critical, "Error", f"An error occurred: {str(e)}")
def updateBankAccount(self):
"""
Update the details of a bank account associated with the current customer.
This method retrieves the customer ID, account name, currency choice, and main account checkbox status from the UI,
checks if the provided account name exists for the current customer in the Accounts table,
updates the currency and is_main fields of the account in the Accounts table if it exists,
and displays a success or warning message based on the result of the account update operation.
Parameters:
- self: The instance of the class containing the cursor for database operations.
Returns:
None
"""
try:
# Retrieve customer ID, account name, currency choice, and main account checkbox status from the UI
customer_id = self.getCustomerID()
account_name = self.txt_accountName_Account.text()
currency = self.currency_choice.currentText()
is_main = 1 if self.chckBox_mainAccount.isChecked() else 0
# Check if the provided account name exists for the current customer in the Accounts table
does_Exist = self.cursor.execute('SELECT account_name FROM Accounts WHERE account_name = ? AND customer_id = ?', (account_name, customer_id)).fetchone()
if does_Exist:
# Execute the SQL query to update the currency and is_main fields of the account in the Accounts table
self.cursor.execute('''
UPDATE Accounts
SET currency = ?, is_main = ?
WHERE customer_id = ? AND account_name = ?
''', (currency, is_main, customer_id, account_name))
# Commit the changes to the database
self.connect.commit()
# Display a success message
self.messageBox(QMessageBox.Information, "Success", "Account updated successfully.")
else:
# Display a warning message if the account does not exist
self.messageBox(QMessageBox.Warning, "Warning", "Account doesn't exist.")
# Clear the account name field in the UI
self.txt_accountName_Account.setText("")
except Exception as e:
# Display an error message for any unexpected exceptions
self.messageBox(QMessageBox.Critical, "Error", f"An error occurred: {str(e)}")
def getAccountList(self):
"""
Retrieve and populate the combo box with the account names associated with the current customer.
This method retrieves the customer ID using the getCustomerID method,
executes an SQL query to fetch the account names associated with the retrieved customer ID,
extracts the account names from the fetched rows,
and populates the combo box with the account names.
Parameters:
- self: The instance of the class containing the cursor for database operations.
Returns:
None
"""
try:
# Clear the existing items in the combo box
self.account_choice_Money.clear()
# Retrieve customer ID using the getCustomerID method
customer_id = self.getCustomerID()
# Execute the SQL query to fetch the account names associated with the retrieved customer ID
account_names = self.cursor.execute('SELECT account_name FROM Accounts WHERE customer_id = ?', (customer_id,)).fetchall()
# Extract account names from the fetched rows
account_names_list = [row[0] for row in account_names]
# Populate the combo box with the account names
self.account_choice_Money.addItems(account_names_list)
except Exception as e:
# Display an error message for any unexpected exceptions
self.messageBox(QMessageBox.Critical, "Error", f"An error occurred: {str(e)}")
def depositMoney(self):
"""
Deposit money into a selected bank account associated with the current customer.
This method retrieves the selected account name, deposit amount, and customer ID from the UI,
validates the deposit amount,
updates the account balance and total balance of the customer in the database,
and displays a success or warning message based on the result of the deposit operation.
Parameters:
- self: The instance of the class containing the cursor for database operations.
Returns:
None
"""
try:
# Retrieve selected account name, deposit amount, and customer ID from the UI
account_name = self.account_choice_Money.currentText()
amount = float(self.txt_amount_Money.text())
customer_id = self.getCustomerID()
# Retrieve current account balance
balance = self.cursor.execute('SELECT balance FROM Accounts WHERE customer_id = ? AND account_name = ?', (customer_id, account_name)).fetchone()
# Validate deposit amount
if amount <= 0:
self.messageBox(QMessageBox.Warning, "Warning", "Amount can't be less than zero.")
return
# Calculate new account balance
new_balance = balance[0] + amount
# Update account balance
self.cursor.execute('UPDATE Accounts SET balance = ? WHERE customer_id = ? AND account_name = ?', (new_balance, customer_id, account_name))
# Update total balance of the customer
current_total_balance = self.cursor.execute('SELECT balance FROM Customers WHERE id = ?', (customer_id,)).fetchone()[0]
new_total_balance = current_total_balance + amount
self.cursor.execute('UPDATE Customers SET balance = ? WHERE id = ?', (new_total_balance, customer_id))
# Commit the changes to the database
self.connect.commit()
# Display a success message
self.messageBox(QMessageBox.Information, "Success", f"New balance: {new_balance}")
# Clear the deposit amount field in the UI
self.txt_amount_Money.setText("")
except ValueError:
# Display an error message for invalid amount format
self.messageBox(QMessageBox.Warning, "Warning", "Please enter a valid amount.")
except Exception as e:
# Display an error message for any unexpected exceptions
self.messageBox(QMessageBox.Critical, "Error", f"An error occurred: {str(e)}")
def withdrawMoney(self):
"""
Withdraw money from a selected bank account associated with the current customer.
This method retrieves the selected account name, withdrawal amount, and customer ID from the UI,
validates the withdrawal amount,
updates the account balance and total balance of the customer in the database,
and displays a success or warning message based on the result of the withdrawal operation.
Parameters:
- self: The instance of the class containing the cursor for database operations.
Returns:
None
"""
try:
# Retrieve selected account name, withdrawal amount, and customer ID from the UI
account_name = self.account_choice_Money.currentText()
amount = float(self.txt_amount_Money.text())
customer_id = self.getCustomerID()
# Retrieve current account balance
balance = self.cursor.execute('SELECT balance FROM Accounts WHERE customer_id = ? AND account_name = ?', (customer_id, account_name)).fetchone()
# Validate withdrawal amount
if amount <= 0:
self.messageBox(QMessageBox.Warning, "Warning", "Amount can't be less than zero.")
return
if amount > balance[0]:
self.messageBox(QMessageBox.Warning, "Warning", "Amount can't be more than balance.")
return
# Calculate new account balance
new_balance = balance[0] - amount
# Update total balance of the customer
current_total_balance = self.cursor.execute('SELECT balance FROM Customers WHERE id = ?', (customer_id,)).fetchone()[0]
new_total_balance = current_total_balance - amount
self.cursor.execute('UPDATE Customers SET balance = ? WHERE id = ?', (new_total_balance, customer_id))
# Update account balance
self.cursor.execute('UPDATE Accounts SET balance = ? WHERE customer_id = ? AND account_name = ?', (new_balance, customer_id, account_name))
# Commit the changes to the database
self.connect.commit()
# Display a success message
self.messageBox(QMessageBox.Information, "Success", f"Here is your money. New balance: {new_balance}")
# Clear the withdrawal amount field in the UI
self.txt_amount_Money.setText("")
except ValueError:
# Display an error message for invalid amount format
self.messageBox(QMessageBox.Warning, "Warning", "Please enter a valid amount.")
except Exception as e:
# Display an error message for any unexpected exceptions
self.messageBox(QMessageBox.Critical, "Error", f"An error occurred: {str(e)}")
def getCustomerList(self):
"""
Retrieve and populate the combo box with the usernames of all customers.
This method executes an SQL query to fetch the usernames of all customers,
extracts the usernames from the fetched rows,
and populates the combo box with the usernames.
Parameters:
- self: The instance of the class containing the cursor for database operations.
Returns:
None
"""
try:
# Clear the existing items in the combo box
self.customer_choice_Transfer.clear()
# Execute the SQL query to fetch the usernames of all customers
customer_names = self.cursor.execute('SELECT username FROM Customers').fetchall()
# Extract usernames from the fetched rows
customer_names_list = [row[0] for row in customer_names]
# Populate the combo box with the usernames
self.customer_choice_Transfer.addItems(customer_names_list)
except Exception as e:
# Display an error message for any unexpected exceptions
self.messageBox(QMessageBox.Critical, "Error", f"An error occurred: {str(e)}")
def getCustomerAccountList(self):
"""
Retrieve and populate the combo box with the account names associated with the chosen customer.
This method retrieves the chosen customer's username and ID from the UI,
executes an SQL query to fetch the account names associated with the chosen customer,
extracts the account names from the fetched rows,
and populates the combo box with the account names.
Parameters:
- self: The instance of the class containing the cursor for database operations.
Returns:
None
"""
try:
# Clear the existing items in the combo box
self.account_chose_transfer.clear()
# Retrieve the chosen customer's username and ID from the UI
customer_username = self.customer_choice_Transfer.currentText()
customer_id = self.getChosenCustomerID(customer_username)