# Form implementation generated from reading ui file 'proje.ui' # # Created by: PyQt6 UI code generator 6.4.2 # # WARNING: Any manual changes made to this file will be lost when pyuic6 is # run again. Do not edit this file unless you know what you are doing. from PyQt6 import QtCore, QtGui, QtWidgets from PyQt6.QtWidgets import QApplication, QMainWindow, QTableWidgetItem, QMessageBox, QGraphicsScene, QGraphicsView, QFileDialog import pyodbc from PyQt6.QtCore import Qt from PyQt6.QtGui import QPixmap import os import json import shutil import sys from PIL import Image def connect(): conn_str = 'DRIVER={SQL Server};SERVER=SAVITAR\SQLEXPRESS01;DATABASE=kayit;Trusted_Connection=yes;' connection = pyodbc.connect(conn_str) return connection class Ui_MainWindow(object): def setupUi(self, MainWindow): MainWindow.setObjectName("MainWindow") MainWindow.resize(613, 773) font = QtGui.QFont() font.setBold(True) font.setItalic(False) font.setUnderline(False) font.setWeight(75) font.setStrikeOut(False) MainWindow.setFont(font) self.centralwidget = QtWidgets.QWidget(parent=MainWindow) self.centralwidget.setObjectName("centralwidget") self.lineEdit = QtWidgets.QLineEdit(parent=self.centralwidget) self.lineEdit.setGeometry(QtCore.QRect(160, 10, 201, 31)) self.lineEdit.setText("") self.lineEdit.setObjectName("lineEdit") self.label = QtWidgets.QLabel(parent=self.centralwidget) self.label.setGeometry(QtCore.QRect(0, 10, 121, 31)) font = QtGui.QFont() font.setFamily("Calibri") font.setPointSize(12) self.label.setFont(font) self.label.setAutoFillBackground(False) self.label.setTextFormat(QtCore.Qt.TextFormat.AutoText) self.label.setWordWrap(False) self.label.setObjectName("label") self.label_2 = QtWidgets.QLabel(parent=self.centralwidget) self.label_2.setGeometry(QtCore.QRect(0, 40, 121, 51)) font = QtGui.QFont() font.setFamily("Calibri") font.setPointSize(12) self.label_2.setFont(font) self.label_2.setObjectName("label_2") self.lineEdit_2 = QtWidgets.QLineEdit(parent=self.centralwidget) self.lineEdit_2.setGeometry(QtCore.QRect(160, 50, 201, 31)) self.lineEdit_2.setText("") self.lineEdit_2.setObjectName("lineEdit_2") self.label_3 = QtWidgets.QLabel(parent=self.centralwidget) self.label_3.setGeometry(QtCore.QRect(0, 120, 121, 51)) font = QtGui.QFont() font.setFamily("Calibri") font.setPointSize(12) self.label_3.setFont(font) self.label_3.setObjectName("label_3") self.label_4 = QtWidgets.QLabel(parent=self.centralwidget) self.label_4.setGeometry(QtCore.QRect(0, 170, 151, 31)) font = QtGui.QFont() font.setFamily("Calibri") font.setPointSize(12) self.label_4.setFont(font) self.label_4.setAutoFillBackground(False) self.label_4.setTextFormat(QtCore.Qt.TextFormat.AutoText) self.label_4.setWordWrap(False) self.label_4.setObjectName("label_4") self.lineEdit_4 = QtWidgets.QLineEdit(parent=self.centralwidget) self.lineEdit_4.setGeometry(QtCore.QRect(160, 170, 201, 31)) self.lineEdit_4.setText("") self.lineEdit_4.setObjectName("lineEdit_4") self.pushButton_2 = QtWidgets.QPushButton(parent=self.centralwidget) self.pushButton_2.setGeometry(QtCore.QRect(0, 220, 51, 41)) self.pushButton_2.setObjectName("pushButton_2") self.pushButton_2.clicked.connect(self.button_clicked) self.pushButton_4 = QtWidgets.QPushButton(parent=self.centralwidget) self.pushButton_4.setGeometry(QtCore.QRect(60, 220, 51, 41)) self.pushButton_4.setObjectName("pushButton_4") self.tableWidget = QtWidgets.QTableWidget(parent=self.centralwidget) self.tableWidget.setGeometry(QtCore.QRect(0, 280, 611, 471)) self.tableWidget.setObjectName("tableWidget") self.tableWidget.setColumnCount(0) self.tableWidget.setRowCount(0) self.tableWidget.setEditTriggers(QtWidgets.QAbstractItemView.EditTrigger.NoEditTriggers) #TABLOYU OKUMA MODUNA ALDI self.graphicsView = QGraphicsView(parent=self.centralwidget) self.graphicsView.setGeometry(QtCore.QRect(370, 10, 241, 261)) self.graphicsView.setObjectName("graphicsView") self.graphicsScene = QGraphicsScene(self.graphicsView) self.graphicsView.setScene(self.graphicsScene) self.graphicsView.setAlignment(QtCore.Qt.AlignmentFlag.AlignCenter) self.graphicsView.fitInView(self.graphicsScene.sceneRect(), QtCore.Qt.AspectRatioMode.KeepAspectRatio) self.graphicsView.mousePressEvent = self.showFileDialog self.checkBox = QtWidgets.QCheckBox(parent=self.centralwidget) self.checkBox.setGeometry(QtCore.QRect(120, 230, 81, 20)) self.checkBox.setObjectName("checkBox") self.checkBox.stateChanged.connect(self.checkbox_changed) self.label_5 = QtWidgets.QLabel(parent=self.centralwidget) self.label_5.setGeometry(QtCore.QRect(0, 80, 121, 51)) font = QtGui.QFont() font.setFamily("Calibri") font.setPointSize(12) self.label_5.setFont(font) self.label_5.setObjectName("label_5") self.comboBox = QtWidgets.QComboBox(parent=self.centralwidget) self.comboBox.setGeometry(QtCore.QRect(160, 90, 201, 31)) self.comboBox.setObjectName("comboBox") self.comboBox.currentIndexChanged.connect(self.fill_sehir_combo) self.comboBox_2 = QtWidgets.QComboBox(parent=self.centralwidget) self.comboBox_2.setGeometry(QtCore.QRect(160, 130, 201, 31)) self.comboBox_2.setObjectName("comboBox_2") MainWindow.setCentralWidget(self.centralwidget) self.statusbar = QtWidgets.QStatusBar(parent=MainWindow) self.statusbar.setObjectName("statusbar") MainWindow.setStatusBar(self.statusbar) self.retranslateUi(MainWindow) QtCore.QMetaObject.connectSlotsByName(MainWindow) self.lineEdit.returnPressed.connect(self.on_line_edit_1_enter) self.lineEdit_2.returnPressed.connect(self.on_line_edit_2_enter) self.comboBox.currentIndexChanged.connect(self.on_combo_box_1_index_changed) self.comboBox_2.currentIndexChanged.connect(self.on_combo_box_2_index_changed) self.lineEdit_4.returnPressed.connect(self.on_line_edit_4_enter) self.centralwidget.keyPressEvent = self.keyPressEvent self.tableWidget.itemClicked.connect(self.table_item_clicked) try: # Veritabanına bağlantı oluşturma connection = connect() # Bağlantı üzerinden bir cursor (imleç) oluşturma cursor = connection.cursor() # SQL sorgusuyla tablodan verileri alma cursor.execute("SELECT ad, id, ulke, sehir, sektor FROM Musteriler") data = cursor.fetchall() # Veritabanı bağlantısını ve cursoru kapatma cursor.close() connection.close() # Tabloya verileri ekleme self.tabloyu_guncelle() # Tablo başlıkları header_labels = ["Müşteri Adı", "Müşteri No", "Ülke","Şehir", "Sektor"] self.tableWidget.setHorizontalHeaderLabels(header_labels) # Ülkeleri "comboBox" combobox'ına doldur self.fill_ulke_combo() except pyodbc.Error as error: print("Hata:", error) def on_line_edit_1_enter(self): self.lineEdit_2.setFocus() def on_line_edit_2_enter(self): self.comboBox.setFocus() def on_combo_box_1_index_changed(self): self.comboBox_2.setFocus() def on_combo_box_2_index_changed(self): self.lineEdit_4.setFocus() def on_line_edit_4_enter(self): self.ekle() self.lineEdit.setFocus() # İmleci tekrar ilk line edite taşı def retranslateUi(self, MainWindow): _translate = QtCore.QCoreApplication.translate MainWindow.setWindowTitle(_translate("MainWindow", "MainWindow")) self.label.setText(_translate("MainWindow", "MUSTERİ ADI:")) self.label_2.setText(_translate("MainWindow", "MÜŞTERİ NO:")) self.label_3.setText(_translate("MainWindow", "ŞEHİR:")) self.label_4.setText(_translate("MainWindow", "MÜŞTERİ SEKTÖR:")) self.pushButton_2.setText(_translate("MainWindow", "EKLE")) self.pushButton_4.setText(_translate("MainWindow", "FİLTRE")) self.checkBox.setText(_translate("MainWindow", "SİL")) self.label_5.setText(_translate("MainWindow", "ÜLKE:")) def showFileDialog(self, event): # Resim seçme penceresini aç file_path, _ = QtWidgets.QFileDialog.getOpenFileName(self.centralwidget, "Resim Seç", "", "Resim Dosyaları (*.jpg *.jpeg *.png *.bmp);;Tüm Dosyalar (*)") if file_path: print("Seçilen dosya:", file_path) self.saveImage(file_path) def saveImage(self, file_path): # Klasörü oluştur ve resmi kopyala target_folder = os.path.join("resimler", self.lineEdit_2.text()) os.makedirs(target_folder, exist_ok=True) target_path = os.path.join(target_folder, os.path.basename(file_path)) shutil.copyfile(file_path, target_path) # Veritabanındaki resim yolunu güncelle try: connection = connect() with connection: cursor = connection.cursor() query = "UPDATE Musteriler SET resim_yolu = ? WHERE id = ?" cursor.execute(query, (target_path, self.lineEdit_2.text())) connection.commit() print("Veritabanı güncellendi.") self.showImageInGraphicsView(target_path) # Resmi burada göster except pyodbc.Error as error: print("Hata:", error) def showImageInGraphicsView(self, image_path): pixmap = QtGui.QPixmap(image_path) self.graphicsScene.addPixmap(pixmap) self.graphicsView.setScene(self.graphicsScene) def clearGraphicsView(self): self.graphicsScene.clear() self.graphicsView.setScene(self.graphicsScene) def table_item_clicked(self, item): # Seçilen satırın verilerini alın selected_row = item.row() musteri_adi = self.tableWidget.item(selected_row, 0).text() musteri_no = self.tableWidget.item(selected_row, 1).text() ulke = self.tableWidget.item(selected_row, 2).text() sehir = self.tableWidget.item(selected_row, 3).text() sektor = self.tableWidget.item(selected_row, 4).text() # Resim yolunu alma ve kontrol etme resim_yolu_item = self.tableWidget.item(selected_row, 5) # 6. sütun (indeks 5) if resim_yolu_item is not None: resim_yolu = resim_yolu_item.text() # Resmi QGraphicsView'da göster if resim_yolu: self.showImageInGraphicsView(resim_yolu) else: self.clearGraphicsView() # Verileri ilgili LineEdit ve ComboBox'lara yerleştirin self.lineEdit.setText(musteri_adi) self.lineEdit_2.setText(musteri_no) self.comboBox.setCurrentText(ulke) self.comboBox_2.setCurrentText(sehir) self.lineEdit_4.setText(sektor) self.tabloyu_guncelle() def button_clicked(self): if not self.checkBox.isChecked(): self.ekle() else: self.sil() def checkbox_changed(self, state): if state == 2: # Qt.Checked self.pushButton_2.setText("SİL") else: self.pushButton_2.setText("EKLE") def keyPressEvent(self, event): if event.key() == Qt.Key.Key_F1: # Tüm LineEdit ve ComboBox bilgilerini temizle self.lineEdit.clear() self.lineEdit_2.clear() self.comboBox.setCurrentIndex(0) self.comboBox_2.setCurrentIndex(0) self.lineEdit_4.clear() self.lineEdit.setFocus() def fill_ulke_combo(self): try: connection = connect() cursor = connection.cursor() cursor.execute("SELECT ulke_id, ulke FROM ulkeler") ulkeler = cursor.fetchall() for ulke in ulkeler: self.comboBox.addItem(ulke[1], userData=ulke[0]) connection.close() except pyodbc.Error as error: print("Hata:", error) def fill_sehir_combo(self): ulke_id = self.comboBox.currentData() self.comboBox_2.clear() if ulke_id is not None: try: connection = connect() cursor = connection.cursor() cursor.execute("SELECT sehir FROM sehirler WHERE ulke_id = ?", (ulke_id,)) sehirler = cursor.fetchall() for sehir in sehirler: self.comboBox_2.addItem(sehir[0]) connection.close() except pyodbc.Error as error: print("Hata:", error) def tabloyu_guncelle(self, data=None): try: connection = connect() if data is None: # Tabloyu veritabanındaki verilerle güncelle with connection: cursor = connection.cursor() cursor.execute("SELECT ad, id, ulke, sehir, sektor FROM Musteriler") data = cursor.fetchall() # Tablo widget’ını temizle self.tableWidget.clearContents() self.tableWidget.setRowCount(0) # Tabloya verileri ekleme self.tableWidget.setRowCount(len(data)) self.tableWidget.setColumnCount(5 if len(data) == 0 else len(data[0])) for row_num, row_data in enumerate(data): for col_num, col_data in enumerate(row_data): item = QtWidgets.QTableWidgetItem(str(col_data)) self.tableWidget.setItem(row_num, col_num, item) except pyodbc.Error as error: print("Hata:", error) def ekle(self): try: connection = connect() musteri_adi = self.lineEdit.text() musteri_no = self.lineEdit_2.text() ulke = self.comboBox.currentText() sehir = self.comboBox_2.currentText() musteri_sektor = self.lineEdit_4.text() if not musteri_adi or not musteri_no or not ulke or not sehir or not musteri_sektor: reply = QMessageBox.critical(self.centralwidget, "HATA", "Boş alanları doldurun.", QMessageBox.StandardButton.Ok) if reply == QMessageBox.StandardButton.Ok: if not musteri_adi: self.lineEdit.setFocus() elif not musteri_no: self.lineEdit_2.setFocus() elif not ulke: self.comboBox.setFocus() elif not sehir: self.comboBox_2.setFocus() elif not musteri_sektor: self.lineEdit_4.setFocus() return with connection: cursor = connection.cursor() cursor.execute("SELECT COUNT(*) FROM Musteriler WHERE id = ?", (musteri_no,)) result = cursor.fetchone() if result and result[0] > 0: reply = QMessageBox.critical(self.centralwidget, "HATA", "Müşteri numarasına ait kayıt bulunmakta.", QMessageBox.StandardButton.Ok) if reply == QMessageBox.StandardButton.Ok: self.lineEdit_2.setFocus() return reply = QMessageBox.question(self.centralwidget, "Onay", "Müşteriyi eklemek istiyor musunuz?", QMessageBox.StandardButton.Yes | QMessageBox.StandardButton.No, QMessageBox.StandardButton.Yes) if reply == QMessageBox.StandardButton.Yes: query = "INSERT INTO Musteriler (ad, id, ulke, sehir, sektor) VALUES (?, ?, ?, ?, ?)" cursor.execute(query, (musteri_adi, musteri_no, ulke, sehir, musteri_sektor)) self.lineEdit.setFocus() connection.commit() print("Müşteri başarıyla eklendi.") self.lineEdit.clear() self.lineEdit_2.clear() self.comboBox.clear() self.comboBox_2.clear() self.lineEdit_4.clear() self.tabloyu_guncelle() self.fill_ulke_combo() connection.close() except pyodbc.Error as error: print("Hata:", error) def sil(self): try: connection = connect() selected_items = self.tableWidget.selectedItems() if selected_items: selected_row = selected_items[0].row() musteri_no = self.tableWidget.item(selected_row, 1).text() # Müşteriyi silmek istediğinizden emin olun reply = QMessageBox.question(self.centralwidget, "Onay", f"{musteri_no} nolu müşteri kaydını silmek istiyor musunuz?", QMessageBox.StandardButton.Yes | QMessageBox.StandardButton.No, QMessageBox.StandardButton.No) if reply == QMessageBox.StandardButton.Yes: with connection: cursor = connection.cursor() # İlgili müşteri kaydını veritabanından silin query = "DELETE FROM Musteriler WHERE id = ?" cursor.execute(query, (musteri_no,)) connection.commit() print(f"{musteri_no} nolu müşteri kaydı başarıyla silindi.") self.tableWidget.removeRow(selected_row) # Tabloyu güncelleme QMessageBox.information(self.centralwidget, "Başarılı", "Kayıt başarıyla silindi.", QMessageBox.StandardButton.Ok) self.tabloyu_guncelle() except pyodbc.Error as error: print("Hata:", error) if __name__ == "__main__": app = QApplication(sys.argv) MainWindow = QMainWindow() ui = Ui_MainWindow() ui.setupUi(MainWindow) MainWindow.show() sys.exit(app.exec())