-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEditCustomerClass.py
More file actions
77 lines (64 loc) · 3.3 KB
/
EditCustomerClass.py
File metadata and controls
77 lines (64 loc) · 3.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
import typing
from PyQt6 import QtCore, QtWidgets, uic
from PyQt6.QtCore import QDate
from PyQt6.QtWidgets import QApplication, QMessageBox,QMainWindow, QTableWidget, QTableWidgetItem, QVBoxLayout, QWidget, QHeaderView
import sys
import pyodbc
from ConnectionString import connection, cursor
class EditCustomerScreen(QtWidgets.QMainWindow):
customerUpdated = QtCore.pyqtSignal()
def __init__(self, customer_data):
super(EditCustomerScreen, self).__init__()
uic.loadUi('Screens/EditCustomer.ui', self)
self.setWindowTitle("Edit Customer")
# Assuming your UI file has QLineEdit widgets named vendorNameEdit, contactNumberEdit, emailEdit, addressEdit
self.nameText.setText(customer_data[1])
self.contactText.setText(customer_data[3])
self.backupText.setText(customer_data[4])
self.emailText.setText(customer_data[5])
self.addressText.setText(customer_data[6])
gender_index = self.genderComboBox.findText(customer_data[2])
if gender_index != -1:
self.genderComboBox.setCurrentIndex(gender_index)
# Save customer_data as an instance variable
self.customer_data = customer_data
self.clearButton.clicked.connect(self.ClearEntries)
self.saveButton.clicked.connect(self.SaveChanges)
def ClearEntries(self):
# Reset the text of the QLineEdit widgets to an empty string
self.nameText.clear()
self.contactText.clear()
self.backupText.clear()
self.emailText.clear()
self.addressText.clear()
def SaveChanges(self):
# Get the updated information from the QLineEdit widgets
updated_name = self.nameText.text()
updated_gender = self.genderComboBox.currentText()
updated_contact = self.contactText.text()
updated_backup = self.backupText.text()
updated_email = self.emailText.text()
updated_address = self.addressText.text()
# Assuming vendor_id is the first element in vendor_data
customer_id = self.customer_data[0]
self.msg = QtWidgets.QMessageBox()
if updated_name == '' or updated_contact == '' or updated_backup == '' or updated_email == '' or updated_address == '':
self.msg.setWindowTitle("Error")
self.msg.setText("Please enter complete information.")
self.msg.show()
elif not updated_contact.isdigit() or not updated_backup.isdigit():
self.msg.setWindowTitle("Error")
self.msg.setText("Contact and backup contact should be numeric")
self.msg.show()
else:
# Run SQL query to update records in the database
update_query = "UPDATE Customer SET customerName=?, gender=?, contactNumber=?, backupContact=?, email=?, address=? WHERE customerID=?"
cursor.execute(update_query, (updated_name, updated_gender ,updated_contact, updated_backup, updated_email, updated_address, customer_id))
connection.commit()
# Optionally, show a success message
self.msg = QtWidgets.QMessageBox()
self.msg.setWindowTitle("Success")
self.msg.setText("Customer information updated successfully.")
self.msg.show()
# Emit the signal indicating that the Customer has been updated
self.customerUpdated.emit()