-
Notifications
You must be signed in to change notification settings - Fork 0
/
kütüphane_codes.py
1011 lines (870 loc) · 43.8 KB
/
kütüphane_codes.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.QtCore import *
from PyQt5.QtGui import *
from PyQt5.QtWidgets import *
from PyQt5.uic import loadUiType
ui,_ = loadUiType('kutuphane.ui')
login,_ = loadUiType('login.ui')
import psycopg2
from datetime import datetime
from datetime import timedelta
from xlrd import *
from xlsxwriter import *
import time
from pyzbar.pyzbar import decode
import cv2
import numpy as np
import sys
class Login(QWidget,login):
def __init__(self):
QWidget.__init__(self)
self.setupUi(self)
self.pushButton.clicked.connect(self.Giris_Ekrani)
style = open('themes/darkorange.css' , 'r')
style = style.read()
self.setStyleSheet(style)
def Giris_Ekrani(self):
username = self.lineEdit.text()
password = self.lineEdit_2.text()
self.connection = psycopg2.connect(user = "postgres",
password = "1234",
host = "localhost",
port = "5432",
database = "postgres")
self.cursor = self.connection.cursor()
self.cursor.execute("""SELECT * FROM yöneticiler""")
data = self.cursor.fetchall()
for row in data:
if username == row[0] and password == row[1]:
self.label_2.setText("Başarılı Giriş")
self.window2 = MainApp()
self.close()
self.window2.show()
else:
self.label_2.setText("Hatalı Giriş")
class MainApp(QMainWindow , ui):
def __init__(self):
QMainWindow.__init__(self)
self.setupUi(self)
self.Handel_UI_Changes()
self.Handel_Buttons()
self.Dark_Orange_Theme()
self.Show_Author()
self.Show_Category()
self.Show_Publisher()
self.Show_All_Lend_Operations()
self.Show_Category_Combobox()
self.Show_Author_Combobox()
self.Show_Publisher_Combobox()
self.Show_Book_Combobox()
self.Show_All_Books()
def Handel_UI_Changes(self):
self.Hiding_Themes()
self.tabWidget.tabBar().setVisible(False)
def Handel_Buttons(self):
self.pushButton_31.clicked.connect(self.Barkod_Oku)
self.pushButton_12.clicked.connect(self.Excel_Lend)
self.pushButton_30.clicked.connect(self.Excel_All_Book)
self.pushButton_5.clicked.connect(self.Show_Themes)
self.pushButton_25.clicked.connect(self.Hiding_Themes)
self.pushButton.clicked.connect(self.Open_Lend_Operations)
self.pushButton_2.clicked.connect(self.Open_Books_Tab)
self.pushButton_3.clicked.connect(self.Open_Users_Tab)
self.pushButton_4.clicked.connect(self.Open_Settings_Tab)
self.pushButton_8.clicked.connect(self.Add_New_Book)
self.pushButton_13.clicked.connect(self.Search_Books)
self.pushButton_9.clicked.connect(self.Edit_Books)
self.pushButton_14.clicked.connect(self.Delete_Books)
self.pushButton_32.clicked.connect(self.Show_All_Books)
self.pushButton_20.clicked.connect(self.Add_Category)
self.pushButton_19.clicked.connect(self.Add_Author)
self.pushButton_18.clicked.connect(self.Add_Publisher)
self.pushButton_27.clicked.connect(self.Delete_Category)
self.pushButton_29.clicked.connect(self.Delete_Author)
self.pushButton_28.clicked.connect(self.Delete_Publisher)
self.pushButton_15.clicked.connect(self.Add_New_User)
self.pushButton_16.clicked.connect(self.Login)
self.pushButton_17.clicked.connect(self.Edit_User)
self.pushButton_26.clicked.connect(self.Delete_User)
self.pushButton_23.clicked.connect(self.Dark_Orange_Theme)
self.pushButton_21.clicked.connect(self.Dark_Blue_Theme)
self.pushButton_22.clicked.connect(self.Dark_Gray_Theme)
self.pushButton_24.clicked.connect(self.QDark_Theme)
self.pushButton_11.clicked.connect(self.Show_All_Lend_Operations)
self.pushButton_6.clicked.connect(self.Add_Lend_Operation)
self.pushButton_7.clicked.connect(self.Lend_Remove)
self.tableWidget.cellClicked.connect(self.ogrenci_bilgileri_goster)
self.tableWidget_4.cellClicked.connect(self.Category_Selected)
self.tableWidget_3.cellClicked.connect(self.Author_Selected)
self.tableWidget_2.cellClicked.connect(self.Publisher_Selected)
def Kontrol(self):
satir_sayisi = self.tableWidget.rowCount()
bugun = datetime.now()
bugun= datetime.strftime(bugun,"%x")
for i in range(satir_sayisi-1):
teslim_tarihi = self.tableWidget.item(i,7)
teslim_tarihi = teslim_tarihi.text()
id = self.tableWidget.item(i,0)
print(id.text())
if bugun > teslim_tarihi:
self.connection = psycopg2.connect(user = "postgres",
password = "1234",
host = "localhost",
port = "5432",
database = "postgres")
self.cursor = self.connection.cursor()
self.tableWidget.setItem(i,3,QTableWidgetItem("Gecikti"))
self.cursor.execute("""UPDATE islemler SET kitap_durum = 'Gecikti' WHERE id =%s""",[(int(id.text()))])
self.connection.commit()
self.connection.close()
elif bugun == teslim_tarihi:
self.connection = psycopg2.connect(user = "postgres",
password = "1234",
host = "localhost",
port = "5432",
database = "postgres")
self.cursor = self.connection.cursor()
self.tableWidget.setItem(i,3,QTableWidgetItem("teslim günü"))
self.cursor.execute("""UPDATE islemler SET kitap_durum = 'teslim günü' WHERE id=%s""",[(int(id.text()))])
self.connection.commit()
self.connection.close()
else:
self.connection = psycopg2.connect(user = "postgres",
password = "1234",
host = "localhost",
port = "5432",
database = "postgres")
self.cursor = self.connection.cursor()
self.tableWidget.setItem(i,3,QTableWidgetItem("Süresi Var"))
self.cursor.execute("""UPDATE islemler SET kitap_durum = 'Bekleniyor' WHERE id=%s""",[(int(id.text()))])
self.connection.commit()
self.connection.close()
self.connection.close()
def Barkod_Oku(self):
def barcodeReader(image, bgr):
gray_img = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
barcodes = decode(gray_img)
for decodedObject in barcodes:
points = decodedObject.polygon
pts = np.array(points, np.int32)
pts = pts.reshape((-1, 1, 2))
cv2.polylines(image, [pts], True, (0, 255, 0), 3)
for bc in barcodes:
cv2.putText(frame, bc.data.decode("utf-8") + " - " + bc.type, (30, 30), cv2.FONT_HERSHEY_SIMPLEX, 1,
bgr, 2)
if bc.data.decode("utf-8") is not None:
return bc.data.decode("utf-8")
bgr = (8, 70, 208)
cap = cv2.VideoCapture(0)
while (True):
ret, frame = cap.read()
barcode = barcodeReader(frame, bgr)
print(type(barcode))
cv2.imshow('Barcode reader', frame)
if barcode is not None:
self.lineEdit_4.setText(barcode)
break
code = cv2.waitKey(10)
if code == ord('q') :
break
def ogrenci_bilgileri_goster(self,row,column):
item = self.tableWidget.item(row,5)
item1 = self.tableWidget.item(row,0)
item2 = self.tableWidget.item(row,1)
self.connection = psycopg2.connect(user = "postgres",
password = "1234",
host = "localhost",
port = "5432",
database = "postgres")
self.cursor = self.connection.cursor()
sql = """SELECT concat(ogrenci_adi,' ',ogrenci_soyadi) AS isim,
ogrenci_email,
ogrenci_tel,
ogrenci_tc
FROM
ogrenciler
WHERE ogrenci_tc=%s"""
self.cursor.execute(sql,[(item.text())])
data = self.cursor.fetchone()
self.label_39.setText(item2.text())
self.label_41.setText(item1.text())
self.label_7.setText(data[0])
self.label_23.setText(data[1])
self.label_24.setText(data[2])
self.label_28.setText(data[3])
self.connection.commit()
self.connection.close()
def Show_Themes(self):
self.groupBox_4.show()
def Hiding_Themes(self):
self.groupBox_4.hide()
####################################
######### opening tabs #############
def Open_Lend_Operations(self):
self.tabWidget.setCurrentIndex(0)
def Open_Books_Tab(self):
self.tabWidget.setCurrentIndex(1)
def Open_Users_Tab(self):
self.tabWidget.setCurrentIndex(2)
def Open_Settings_Tab(self):
self.tabWidget.setCurrentIndex(3)
########################################
######### Day Operations ###############
def Add_Lend_Operation(self):
try:
ogrenci_tc = self.lineEdit_2.text()
ogrenci_kitap = self.comboBox_3.currentText()
gun = self.comboBox_2.currentText()
bugun = datetime.now()
bugun_text = datetime.strftime(bugun,'%x')
fark = timedelta(days=int(gun))
teslim_tarihi = bugun + fark
teslim_tarihi_text = datetime.strftime(teslim_tarihi,'%x')
durum = "Bekleniyor"
self.connection = psycopg2.connect(user = "postgres",
password = "1234",
host = "localhost",
port = "5432",
database = "postgres")
self.cursor = self.connection.cursor()
self.cursor.execute("""SELECT * FROM kitaplar WHERE kitap_adi = %s""",[(ogrenci_kitap)])
isbn = self.cursor.fetchone()
print(isbn)
self.connection.close()
adet = int(isbn[6])
print(adet)
if adet>0:
self.connection = psycopg2.connect(user = "postgres",
password = "1234",
host = "localhost",
port = "5432",
database = "postgres")
self.cursor = self.connection.cursor()
sql = """INSERT INTO islemler(ogrenci_tc,kitap_isbn,kitap_durum,alindi_tarihi,teslim_tarihi) VALUES(%s,%s,%s,%s,%s)"""
self.cursor.execute(sql,(ogrenci_tc,isbn[0],durum,bugun_text,teslim_tarihi_text))
self.connection.commit()
self.connection.close()
self.connection = psycopg2.connect(user = "postgres",
password = "1234",
host = "localhost",
port = "5432",
database = "postgres")
self.cursor = self.connection.cursor()
sql = """UPDATE kitaplar SET kitap_adet = kitap_adet - 1 WHERE isbn = %s"""
self.cursor.execute(sql,[(isbn[0])])
self.connection.commit()
self.connection.close()
self.Show_All_Lend_Operations()
self.lineEdit_2.setText("")
QMessageBox.about(self,"Bilgilendirme","Kitap öğrenciye teslim edildi.")
self.Show_All_Books()
else:
self.lineEdit_2.setText("")
QMessageBox.warning(self,"Uyarı","{} adlı kitaptan kalmamıştır.".format(isbn[1]))
except psycopg2.errors.ForeignKeyViolation:
QMessageBox.warning(self,"Uyarı","{} kimlik nolu öğrenci sistemde bulunmamaktadır.".format(ogrenci_tc))
def Show_All_Lend_Operations(self):
self.connection = psycopg2.connect(user = "postgres",
password = "1234",
host = "localhost",
port = "5432",
database = "postgres")
self.cursor = self.connection.cursor()
sql="""SELECT
id,
kitap_isbn,
kitap_adi,
kitap_durum,
concat(ogrenci_adi,' ',ogrenci_soyadi) AS isim,
ogrenciler.ogrenci_tc,
alindi_tarihi,
teslim_tarihi
FROM islemler
INNER JOIN kitaplar
ON islemler.kitap_isbn = kitaplar.isbn
INNER JOIN ogrenciler
ON ogrenciler.ogrenci_tc = islemler.ogrenci_tc"""
self.cursor.execute(sql)
data = self.cursor.fetchall()
self.tableWidget.setRowCount(0)
self.tableWidget.insertRow(0)
for row,form in enumerate(data):
for column,item in enumerate(form):
self.tableWidget.setItem(row,column,QTableWidgetItem(str(item)))
column+=1
row_position = self.tableWidget.rowCount()
self.tableWidget.insertRow(row_position)
self.label_29.setText("Toplam {} kayıt".format(row_position))
self.connection.close()
self.Kontrol()
def Lend_Remove(self):
o_id = int(self.label_41.text())
o_kitap =str(self.label_39.text())
self.connection = psycopg2.connect(user = "postgres",
password = "1234",
host = "localhost",
port = "5432",
database = "postgres")
self.cursor = self.connection.cursor()
self.cursor.execute("""DELETE FROM islemler WHERE id=%s""",[o_id])
self.connection.commit()
self.connection.close()
self.connection = psycopg2.connect(user = "postgres",
password = "1234",
host = "localhost",
port = "5432",
database = "postgres")
self.cursor = self.connection.cursor()
self.cursor.execute("""UPDATE kitaplar SET kitap_adet = kitap_adet + 1 WHERE isbn=%s""",[(o_kitap)])
self.connection.commit()
self.connection.close()
self.Show_All_Lend_Operations()
self.label_41.setText("")
self.label_39.setText("")
self.Show_All_Books()
###############################
######### Books ###############
def Show_All_Books(self):
self.connection = psycopg2.connect(user = "postgres",
password = "1234",
host = "localhost",
port = "5432",
database = "postgres")
self.cursor = self.connection.cursor()
sql = """SELECT isbn,kitap_adi,kitap_yazar,kitap_kategori,kitap_yayinevi,kitap_aciklama,kitap_sayfa,kitap_adet FROM kitaplar"""
self.cursor.execute(sql)
data = self.cursor.fetchall()
self.tableWidget_5.setRowCount(0)
self.tableWidget_5.insertRow(0)
for row,form in enumerate(data):
for column,item in enumerate(form):
self.tableWidget_5.setItem(row,column,QTableWidgetItem(str(item)))
column+=1
row_position = self.tableWidget_5.rowCount()
self.tableWidget_5.insertRow(row_position)
self.label_46.setText("Toplam {} kayıt".format(row_position))
self.connection.close()
def Add_New_Book(self):
isbn = self.lineEdit_4.text()
kitap_adi = self.comboBox.currentText()
kitap_yazar = self.comboBox_7.currentText()
kitap_kategori = self.comboBox_6.currentText()
kitap_yayinevi = self.comboBox_8.currentText()
kitap_aciklama = self.textEdit_2.toPlainText()
kitap_sayfa = self.lineEdit_6.text()
kitap_adet = self.spinBox.value()
if len(isbn) == 13 and len(kitap_yazar) > 0 and len(kitap_kategori) > 0 and len(kitap_yayinevi) > 0 and kitap_adet >0 and len(kitap_adi) > 0:
try:
self.connection = psycopg2.connect(user = "postgres",
password = "1234",
host = "localhost",
port = "5432",
database = "postgres")
self.cursor = self.connection.cursor()
self.cursor.execute("""INSERT INTO kitaplar(isbn,kitap_adi,kitap_yazar,kitap_kategori,kitap_yayinevi,kitap_aciklama,kitap_sayfa,kitap_adet)
VALUES(%s,%s,%s,%s,%s,%s,%s,%s)""",(isbn,kitap_adi,kitap_yazar,kitap_kategori,kitap_yayinevi,kitap_aciklama,kitap_sayfa,int(kitap_adet)))
self.connection.commit()
self.connection.close()
QMessageBox.about(self,"Bilgilendirme","Yeni kitap başarıyla eklendi.")
self.Show_All_Books()
self.Show_Book_Combobox()
self.lineEdit_4.setText("")
self.textEdit_2.setPlainText("")
self.lineEdit_6.setText("")
self.spinBox.setValue(1)
except psycopg2.errors.UniqueViolation:
self.connection = psycopg2.connect(user = "postgres",
password = "1234",
host = "localhost",
port = "5432",
database = "postgres")
self.cursor = self.connection.cursor()
QMessageBox.about(self,"Bilgilendirme","Eklemek istediğiniz kitap listede mevcut.Girdiğiniz adet kadar eklenecektir.")
sql = """UPDATE kitaplar SET kitap_adet = kitap_adet + %s WHERE isbn = %s"""
self.cursor.execute(sql,(kitap_adet,isbn))
self.connection.commit()
self.connection.close()
self.statusBar().showMessage("İşlem başarıyla gerçekleşti.")
isbn = self.lineEdit_4.setText("")
kitap_adi = self.comboBox.setCurrentIndex(0)
kitap_yazar = self.comboBox_7.setCurrentIndex(0)
kitap_kategori = self.comboBox_6.setCurrentIndex(0)
kitap_yayinevi = self.comboBox_8.setCurrentIndex(0)
kitap_aciklama = self.textEdit_2.setText("")
kitap_sayfa = self.lineEdit_6.setText("")
kitap_adet = self.spinBox.setValue(1)
else:
QMessageBox.warning(self,"Dikkat","-ISBN numarası 13 haneli olmak zorundadır.\n-Kitap adı,kategori,yazar ve yayinevi girilmesi zorunlu alanlardır.\n")
def Search_Books(self):
try:
aranan_kitap = self.comboBox_5.currentText()
self.connection = psycopg2.connect(user = "postgres",
password = "1234",
host = "localhost",
port = "5432",
database = "postgres")
self.cursor = self.connection.cursor()
sql = """SELECT * FROM kitaplar WHERE kitap_adi = %s"""
self.cursor.execute(sql,[(aranan_kitap)])
data = self.cursor.fetchone()
print(data)
self.lineEdit_7.setText(data[0])
self.lineEdit.setText(data[1])
self.comboBox_11.setCurrentText(data[3])
self.comboBox_9.setCurrentText(data[2])
self.comboBox_10.setCurrentText(data[7])
self.textEdit.setText(data[4])
self.lineEdit_9.setText(str(data[5]))
self.spinBox_2.setValue(data[6])
except TypeError:
QMessageBox.about(self,"Hata","Aradığınız kitap listede bulunmamaktadır.")
def Edit_Books(self):
self.connection = psycopg2.connect(user = "postgres",
password = "1234",
host = "localhost",
port = "5432",
database = "postgres")
self.cursor = self.connection.cursor()
aranan_kitap = self.comboBox_5.currentText()
isbn = self.lineEdit_7.text()
kitap_adi = self.lineEdit.text()
kitap_yazar = self.comboBox_11.currentText()
kitap_kategori = self.comboBox_9.currentText()
kitap_yayinevi = self.comboBox_10.currentText()
kitap_aciklama = self.textEdit.toPlainText()
kitap_sayfa = self.lineEdit_9.text()
kitap_adet = self.spinBox_2.value()
if len(isbn) == 13:
sql = """UPDATE kitaplar SET isbn = %s ,kitap_adi=%s ,kitap_yazar=%s ,kitap_kategori=%s ,kitap_yayinevi=%s ,kitap_aciklama=%s ,kitap_sayfa=%s ,kitap_adet=%s WHERE kitap_adi=%s"""
self.cursor.execute(sql,(isbn,kitap_adi,kitap_yazar,kitap_kategori,kitap_yayinevi,kitap_aciklama,kitap_sayfa,kitap_adet,aranan_kitap))
self.connection.commit()
self.statusBar().showMessage("Kitap başarıyla güncellendi.")
QMessageBox.about(self,"Başlık","Kitap başarıyla güncellendi")
else:
QMessageBox.warning(self,"Dikkat","ISBN numarası 13 haneli olmak zorundadır.")
self.connection.close()
self.Show_All_Books()
def Delete_Books(self):
if len(self.lineEdit.text()) > 0 and len(self.lineEdit_7.text()) > 0:
self.connection = psycopg2.connect(user = "postgres",
password = "1234",
host = "localhost",
port = "5432",
database = "postgres")
self.cursor = self.connection.cursor()
silinecek_kitap = self.comboBox_5.currentText()
warning = QMessageBox.warning(self,"Kitap Sil","{} isimli kitabı silmek istediğinize emin misiniz ?".format(silinecek_kitap),QMessageBox.Yes,QMessageBox.No)
if warning == QMessageBox.Yes:
sql = """DELETE FROM kitaplar WHERE kitap_adi=%s"""
self.cursor.execute(sql,[(silinecek_kitap)])
self.connection.commit()
self.connection.close()
self.statusBar().showMessage("Kitap başarıyla silindi.")
self.Show_All_Books()
else:
QMessageBox.warning(self,"Uyarı","Tc kimlik numarası 11 haneli olmak zorundadır.")
########################################
############## USERS ###################
def Add_New_User(self):
ogrenci_tc = self.lineEdit_21.text()
ogrenci_adi= self.lineEdit_34.text()
ogrenci_soyadi = self.lineEdit_35.text()
ogrenci_email = self.lineEdit_22.text()
ogrenci_tel = self.lineEdit_23.text()
if len(ogrenci_tc) == 11 and len(ogrenci_adi) > 0 and len(ogrenci_soyadi) > 0:
try:
self.connection = psycopg2.connect(user = "postgres",
password = "1234",
host = "localhost",
port = "5432",
database = "postgres")
self.cursor = self.connection.cursor()
self.cursor.execute("""INSERT INTO ogrenciler(ogrenci_tc,ogrenci_adi,ogrenci_soyadi,ogrenci_email,ogrenci_tel)
VALUES(%s,%s,%s,%s,%s)""",(str(ogrenci_tc),ogrenci_adi,ogrenci_soyadi,ogrenci_email,ogrenci_tel))
self.connection.commit()
QMessageBox.about(self,"Bilgilendirme","Yeni öğrenci başarıya eklendi.")
self.lineEdit_21.setText("")
self.lineEdit_34.setText("")
self.lineEdit_35.setText("")
self.lineEdit_22.setText("")
self.lineEdit_23.setText("")
except psycopg2.errors.UniqueViolation:
QMessageBox.warning(self,"Uyarı","{} kimlik nolu öğrenci zaten kayıtlı.".format(ogrenci_tc))
self.lineEdit_21.setText("")
self.lineEdit_34.setText("")
self.lineEdit_35.setText("")
self.lineEdit_22.setText("")
self.lineEdit_23.setText("")
else:
QMessageBox.warning(self,"Uyarı","-Lütfen zorunlu alanları doldurunuz.\n -Kimlik numarası 11 haneli olmak zorundadır.")
def Login(self):
ogrenci_tc = self.lineEdit_26.text()
if len(ogrenci_tc) == 11:
self.connection = psycopg2.connect(user = "postgres",
password = "1234",
host = "localhost",
port = "5432",
database = "postgres")
self.cursor = self.connection.cursor()
self.cursor.execute("""SELECT * FROM ogrenciler""")
data = self.cursor.fetchall()
for i in data:
if i[0] == ogrenci_tc :
self.groupBox_5.setEnabled(True)
self.statusBar().showMessage("Giriş Başarılı")
self.lineEdit_37.setText(i[0])
self.lineEdit_29.setText(i[1])
self.lineEdit_36.setText(i[2])
self.lineEdit_30.setText(i[3])
self.lineEdit_38.setText(i[4])
else:
QMessageBox.warning(self,"Uyarı","Tc kimlik no 11 haneli olmak zorundadır.")
def Edit_User(self):
ogrenci_tc = self.lineEdit_37.text()
ogrenci_adi= self.lineEdit_29.text()
ogrenci_soyadi = self.lineEdit_36.text()
ogrenci_email = self.lineEdit_30.text()
ogrenci_tel = self.lineEdit_38.text()
original_tc = self.lineEdit_26.text()
if len(ogrenci_tc) == 11 and len(ogrenci_adi) > 0 and len(ogrenci_soyadi) > 0 and len(ogrenci_email) > 0:
self.connection = psycopg2.connect(user = "postgres",
password = "1234",
host = "localhost",
port = "5432",
database = "postgres")
self.cursor = self.connection.cursor()
self.cursor.execute("""UPDATE ogrenciler SET ogrenci_tc = %s ,ogrenci_adi = %s, ogrenci_soyadi = %s ,ogrenci_email = %s ,ogrenci_tel = %s WHERE ogrenci_tc = %s""",
(ogrenci_tc,ogrenci_adi,ogrenci_soyadi,ogrenci_email,ogrenci_tel,original_tc))
self.connection.commit()
self.groupBox_5.setEnabled(False)
QMessageBox.about(self,"Bilgilendirme","Öğrenci başarılı bir şekilde düzenlendi. ")
self.lineEdit_37.setText("")
self.lineEdit_29.setText("")
self.lineEdit_36.setText("")
self.lineEdit_30.setText("")
self.lineEdit_38.setText("")
else:
QMessageBox.warning(self,"Dikkat","-TCKNo 11 haneli olmak zorundadır.\n-TCKNo,ad,soyad,email girilmesi zorunlu alanlardır.\n")
def Delete_User(self):
ogrenci_tc = self.lineEdit_26.text()
self.connection = psycopg2.connect(user = "postgres",
password = "1234",
host = "localhost",
port = "5432",
database = "postgres")
self.cursor = self.connection.cursor()
self.cursor.execute("""DELETE FROM ogrenciler WHERE ogrenci_tc = %s""",[(ogrenci_tc)])
self.connection.commit()
self.connection.close()
QMessageBox.about(self,"Bilgilendirme","Başarıyla silindi.")
self.lineEdit_37.setText("")
self.lineEdit_29.setText("")
self.lineEdit_36.setText("")
self.lineEdit_30.setText("")
self.lineEdit_38.setText("")
self.lineEdit_26.setText("")
self.groupBox_5.setEnabled(False)
####################################
######### settings #################
def Publisher_Selected(self,row,column):
item = self.tableWidget_2.item(row,column)
self.lineEdit_31.setText(item.text())
def Author_Selected(self,row,column):
item = self.tableWidget_3.item(row,0)
self.lineEdit_32.setText(item.text())
def Category_Selected(self,row,column):
item = self.tableWidget_4.item(row,0)
self.lineEdit_33.setText(item.text())
def Delete_Category(self):
kategori = self.lineEdit_33.text()
self.connection = psycopg2.connect(user = "postgres",
password = "1234",
host = "localhost",
port = "5432",
database = "postgres")
self.cursor = self.connection.cursor()
self.cursor.execute("""DELETE FROM kategori WHERE kategori=%s""",[kategori])
self.connection.commit()
self.connection.close()
self.Show_Category()
def Delete_Author(self):
yazar = self.lineEdit_32.text()
self.connection = psycopg2.connect(user = "postgres",
password = "1234",
host = "localhost",
port = "5432",
database = "postgres")
self.cursor = self.connection.cursor()
self.cursor.execute("""DELETE FROM yazar WHERE yazar = %s""",[yazar])
self.connection.commit()
self.connection.close()
self.Show_Author()
def Delete_Publisher(self):
yayinevi = self.lineEdit_31.text()
self.connection = psycopg2.connect(user = "postgres",
password = "1234",
host = "localhost",
port = "5432",
database = "postgres")
self.cursor = self.connection.cursor()
self.cursor.execute("""DELETE FROM yayinevi WHERE yayinevi=%s""",[yayinevi])
self.connection.commit()
self.connection.close()
self.Show_Publisher()
def Add_Category(self):
try :
self.connection = psycopg2.connect(user = "postgres",
password = "1234",
host = "localhost",
port = "5432",
database = "postgres")
self.cursor = self.connection.cursor()
yeni_kategori = self.lineEdit_33.text()
self.cursor.execute("""INSERT INTO kategori(kategori) VALUES(%s)""",(yeni_kategori,))
self.connection.commit()
self.Show_Category()
self.Show_Category_Combobox()
QMessageBox.about(self,"Bilgilendirme","Yeni kategori eklendi.")
except psycopg2.errors.UniqueViolation:
QMessageBox.warning(self,"Uyarı","Böyle bir kategori zaten mevcut.")
def Show_Category(self):
self.connection = psycopg2.connect(user = "postgres",
password = "1234",
host = "localhost",
port = "5432",
database = "postgres")
self.cursor = self.connection.cursor()
self.cursor.execute(''' SELECT kategori FROM kategori''')
data = self.cursor.fetchall()
if data :
self.tableWidget_4.setRowCount(0)
self.tableWidget_4.insertRow(0)
for row , form in enumerate(data):
for column , item in enumerate(form) :
self.tableWidget_4.setItem(row , column , QTableWidgetItem(str(item)))
column += 1
row_position = self.tableWidget_4.rowCount()
self.tableWidget_4.insertRow(row_position)
def Add_Author(self):
try:
self.connection = psycopg2.connect(user = "postgres",
password = "1234",
host = "localhost",
port = "5432",
database = "postgres")
self.cursor = self.connection.cursor()
yeni_yazar = self.lineEdit_32.text()
self.cursor.execute("""INSERT INTO yazar(yazar) VALUES(%s)""",(yeni_yazar,))
self.connection.commit()
self.Show_Author()
self.Show_Author_Combobox()
QMessageBox.about(self,"Bilgilendirme","Yeni yazar eklendi.")
except psycopg2.errors.UniqueViolation:
QMessageBox.warning(self,"Uyarı","Böyle bir yazar zaten mevcut.")
def Show_Author(self):
self.connection = psycopg2.connect(user = "postgres",
password = "1234",
host = "localhost",
port = "5432",
database = "postgres")
self.cursor = self.connection.cursor()
self.cursor.execute(''' SELECT yazar FROM yazar''')
data = self.cursor.fetchall()
if data :
self.tableWidget_3.setRowCount(0)
self.tableWidget_3.insertRow(0)
for row , form in enumerate(data):
for column , item in enumerate(form) :
self.tableWidget_3.setItem(row , column , QTableWidgetItem(str(item)))
column += 1
row_position = self.tableWidget_3.rowCount()
self.tableWidget_3.insertRow(row_position)
def Add_Publisher(self):
try:
self.connection = psycopg2.connect(user = "postgres",
password = "1234",
host = "localhost",
port = "5432",
database = "postgres")
self.cursor = self.connection.cursor()
yeni_yayinevi = self.lineEdit_31.text()
self.cursor.execute("INSERT INTO yayinevi(yayinevi) VALUES(%s)",(yeni_yayinevi,))
self.connection.commit()
self.Show_Publisher()
self.Show_Publisher_Combobox()
QMessageBox.about(self,"Bilgilendirme","Yeni yayınevi eklendi.")
except psycopg2.errors.UniqueViolation:
QMessageBox.warning(self,"Uyarı","Böyle bir yayınevi zaten mevcut.")
def Show_Publisher(self):
self.connection = psycopg2.connect(user = "postgres",
password = "1234",
host = "localhost",
port = "5432",
database = "postgres")
self.cursor = self.connection.cursor()
self.cursor.execute(''' SELECT yayinevi FROM yayinevi''')
data = self.cursor.fetchall()
if data :
self.tableWidget_2.setRowCount(0)
self.tableWidget_2.insertRow(0)
for row , form in enumerate(data):
for column , item in enumerate(form):
self.tableWidget_2.setItem(row , column , QTableWidgetItem(str(item)))
column += 1
row_position = self.tableWidget_2.rowCount()
self.tableWidget_2.insertRow(row_position)
######### Create Excel #######
###############################
def Excel_All_Book(self):
self.connection = psycopg2.connect(user = "postgres",
password = "1234",
host = "localhost",
port = "5432",
database = "postgres")
self.cursor = self.connection.cursor()
sql = """SELECT isbn,kitap_adi,kitap_yazar,kitap_kategori,kitap_yayinevi,kitap_aciklama,kitap_sayfa,kitap_adet FROM kitaplar"""
self.cursor.execute(sql)
data = self.cursor.fetchall()
wb = Workbook('All_Books.xlsx')
sheet1 = wb.add_worksheet()
sheet1.write(0,0,'ISBN')
sheet1.write(0,1,'Kitap Adı')
sheet1.write(0,2,'Yazar')
sheet1.write(0,3,'Kategori')
sheet1.write(0,4,'Yayınevi')
sheet1.write(0,5,'Açıklama')
sheet1.write(0,6,'Sayfa')
sheet1.write(0,7,'Adet')
row_number = 1
for row in data:
column_number = 0
for item in row:
sheet1.write(row_number,column_number,str(item))
column_number+=1
row_number+=1
wb.close()
self.connection.close()
QMessageBox.about(self,"Bilgilendirme","Tüm kitaplar tablosunun excel raporu çıkartıldı.")
def Excel_Lend(self):
self.connection = psycopg2.connect(user = "postgres",
password = "1234",
host = "localhost",
port = "5432",
database = "postgres")
self.cursor = self.connection.cursor()
sql="""SELECT
id,
kitap_isbn,
kitap_adi,
kitap_durum,
concat(ogrenci_adi,' ',ogrenci_soyadi) AS isim,
ogrenciler.ogrenci_tc,
alindi_tarihi,
teslim_tarihi
FROM islemler
INNER JOIN kitaplar
ON islemler.kitap_isbn = kitaplar.isbn
INNER JOIN ogrenciler
ON ogrenciler.ogrenci_tc = islemler.ogrenci_tc"""
self.cursor.execute(sql)
data = self.cursor.fetchall()
wb = Workbook('lend_Operations.xlsx')
sheet1 = wb.add_worksheet()
sheet1.write(0,0,'ID')
sheet1.write(0,1,'ISBN')
sheet1.write(0,2,'Kitap Adı')
sheet1.write(0,3,'Kitap Durum')
sheet1.write(0,4,'İsim')
sheet1.write(0,5,'Öğrenci Tc')
sheet1.write(0,6,'Alındı Tarihi')
sheet1.write(0,7,'Teslim Tarihi')
row_number = 1
for row in data:
column_number = 0
for item in row:
sheet1.write(row_number,column_number,str(item))
column_number+=1
row_number+=1
wb.close()
self.connection.close()
QMessageBox.about(self,"Bilgilendirme","Ödünç tablosunun excel raporu çıkartıldı.")
##################################################
######### show settings data in UI ###############
def Show_Category_Combobox(self):
self.connection = psycopg2.connect(user = "postgres",
password = "1234",
host = "localhost",
port = "5432",
database = "postgres")
self.cursor = self.connection.cursor()
self.cursor.execute(''' SELECT kategori FROM kategori ''')
data = self.cursor.fetchall()
self.comboBox_9.clear()
for category in data :
self.comboBox_9.addItem(category[0])
self.comboBox_6.addItem(category[0])
def Show_Author_Combobox(self):
self.connection = psycopg2.connect(user = "postgres",
password = "1234",
host = "localhost",
port = "5432",
database = "postgres")
self.cursor = self.connection.cursor()
self.cursor.execute(''' SELECT yazar FROM yazar ''')
data = self.cursor.fetchall()
self.comboBox_7.clear()
for author in data :
self.comboBox_7.addItem(author[0])
self.comboBox_11.addItem(author[0])
def Show_Publisher_Combobox(self):
self.connection = psycopg2.connect(user = "postgres",
password = "1234",
host = "localhost",
port = "5432",
database = "postgres")
self.cursor = self.connection.cursor()
self.cursor.execute(''' SELECT yayinevi FROM yayinevi ''')
data = self.cursor.fetchall()
self.comboBox_10.clear()
for yayinevi in data :
self.comboBox_10.addItem(yayinevi[0])
self.comboBox_8.addItem(yayinevi[0])
def Show_Book_Combobox(self):
self.connection = psycopg2.connect(user = "postgres",
password = "1234",
host = "localhost",
port = "5432",
database = "postgres")
self.cursor = self.connection.cursor()
self.cursor.execute(''' SELECT kitap_adi FROM kitaplar ''')
data = self.cursor.fetchall()
self.comboBox_3.clear()
self.comboBox_5.clear()
for kitap in data :
self.comboBox_3.addItem(kitap[0])
self.comboBox_5.addItem(kitap[0])
self.comboBox.addItem(kitap[0])
########################################
######### UI Themes ###################
def Dark_Blue_Theme(self):
style = open('themes/darkblue.css' , 'r')
style = style.read()
self.setStyleSheet(style)
def Dark_Gray_Theme(self):
style = open('themes/darkgray.css' , 'r')
style = style.read()
self.setStyleSheet(style)
def Dark_Orange_Theme(self):
style = open('themes/darkorange.css' , 'r')
style = style.read()
self.setStyleSheet(style)
def QDark_Theme(self):
style = open('themes/qdark.css' , 'r')
style = style.read()
self.setStyleSheet(style)