diff --git a/Desktop/1.py b/Desktop/1.py
new file mode 100644
index 0000000..24ee04a
--- /dev/null
+++ b/Desktop/1.py
@@ -0,0 +1,4 @@
+# 0, 1, 2, 3, 4
+# -3 -2 -1
+a = [1, 2, 3, 4, 5]
+print(a[-1])
\ No newline at end of file
diff --git a/Desktop/employee_dialog_widget.py b/Desktop/employee_dialog_widget.py
new file mode 100644
index 0000000..3bc8934
--- /dev/null
+++ b/Desktop/employee_dialog_widget.py
@@ -0,0 +1,165 @@
+from PyQt6 import uic
+from PyQt6.QtWidgets import QDialog, QMessageBox
+
+from data.connect import connect, Post, User
+
+
+class EmployeeDialogWidget(QDialog):
+ def __init__(self, department, employees, parent, user=None):
+ super().__init__()
+
+ uic.loadUi('ui/employee_dialog_window.ui', self)
+
+ self.pushButton.clicked.connect(self.close)
+
+ self.lineEdit_5.setText(department.title)
+
+ self.user = user
+ self.department = department
+ self.parent = parent
+
+ for employee in employees:
+ self.comboBox_2.addItem(f'{employee.last_name} {employee.first_name} - {str(employee.id)}')
+
+ if user is not None:
+ if user.helper_id == employee.id:
+ self.comboBox_2.setCurrentText(f'{employee.last_name} {employee.first_name} - {str(employee.id)}')
+
+ with connect() as session:
+ self.posts = session.query(Post).all()
+
+ for post in self.posts:
+ self.comboBox.addItem(f'{post.title} - {str(post.id)}')
+
+ if user is not None:
+ if post.id == user.post_id:
+ self.comboBox.setCurrentText(f'{post.title} - {str(post.id)}')
+
+ self.pushButton_2.clicked.connect(self.check_form)
+
+ if user is not None:
+ self.lineEdit_2.setText(user.first_name)
+ self.lineEdit.setText(user.last_name)
+ self.lineEdit_3.setText(user.patronymic)
+ self.lineEdit_6.setText(user.work_phone)
+ self.lineEdit_4.setText(user.phone)
+ self.lineEdit_8.setText(user.office)
+ self.dateEdit.setDate(user.birthday)
+ self.lineEdit_9.setText(user.other_info)
+ self.lineEdit_7.setText(user.email)
+
+ def check_form(self):
+ if not self.lineEdit.text() or not self.lineEdit_2.text() or not self.lineEdit_3.text():
+ QMessageBox.warning(
+ self,
+ 'Внимание',
+ 'Поля: Фамилия, имя, отчество обязательны для заполнения'
+ )
+ return
+
+ if not self.lineEdit_7.text():
+ QMessageBox.warning(
+ self,
+ 'Внимание',
+ 'Поле электронной почты обязательно для заполнения'
+ )
+ return
+
+ if not self.lineEdit_8.text():
+ QMessageBox.warning(
+ self,
+ 'Внимание',
+ 'Поле кабинета обязательно для заполнения'
+ )
+ return
+
+ email_text = self.lineEdit_7.text()
+
+ # 'andrei@duvakin.ru'
+
+ if '@' in email_text:
+ splited_email = email_text.split('@')
+
+ if len(splited_email) == 2:
+ user, server = splited_email
+
+ splited_server = server.split('.')
+
+ if len(splited_server) != 2:
+ QMessageBox.warning(
+ self,
+ 'Внимание',
+ 'Неверный формат почты'
+ )
+ return
+ else:
+ QMessageBox.warning(
+ self,
+ 'Внимание',
+ 'Неверный формат почты'
+ )
+ return
+ else:
+ QMessageBox.warning(
+ self,
+ 'Внимание',
+ 'Неверный формат почты'
+ )
+ return
+
+ if self.user is None:
+ new_user = User(
+ first_name=self.lineEdit_2.text(),
+ last_name=self.lineEdit.text(),
+ patronymic=self.lineEdit_3.text(),
+ work_phone=self.lineEdit_6.text(),
+ phone=self.lineEdit_4.text(),
+ office=self.lineEdit_8.text(),
+ birthday=self.dateEdit.date().toPyDate(),
+ other_info=self.lineEdit_9.text(),
+ email=self.lineEdit_7.text(),
+ helper_id=int(self.comboBox_2.currentText().split()[-1]),
+ post_id=int(self.comboBox.currentText().split()[-1]),
+ department_id=self.department.id
+ )
+ with connect() as session:
+ session.add(
+ new_user
+ )
+ session.commit()
+
+ QMessageBox.information(
+ self,
+ 'Данные сохранены',
+ 'Сотрудник был успешно добавлен'
+ )
+ self.parent.select_department(self.department.id)
+
+ self.close()
+ return
+ else:
+ with connect() as session:
+ user = session.query(User).filter(User.id == self.user.id).first()
+
+ user.first_name = self.lineEdit_2.text(),
+ user.last_name = self.lineEdit.text(),
+ user.patronymic = self.lineEdit_3.text(),
+ user.work_phone = self.lineEdit_6.text(),
+ user.phone = self.lineEdit_4.text(),
+ user.office = self.lineEdit_8.text(),
+ user.birthday = self.dateEdit.date().toPyDate(),
+ user.other_info = self.lineEdit_9.text(),
+ user.email = self.lineEdit_7.text(),
+ user.helper_id = int(self.comboBox_2.currentText().split()[-1]),
+ user.post_id = int(self.comboBox.currentText().split()[-1]),
+ user.department_id = self.department.id
+
+ session.commit()
+
+ QMessageBox.information(
+ self,
+ 'Данные сохранены',
+ 'Данные сотрудника были обновлены'
+ )
+ self.parent.select_department(self.department.id)
+ return
diff --git a/Desktop/main_window.py b/Desktop/main_window.py
index d25c706..e5ef7b7 100644
--- a/Desktop/main_window.py
+++ b/Desktop/main_window.py
@@ -1,6 +1,7 @@
from PyQt6 import uic
from PyQt6.QtWidgets import QMainWindow
+from employee_dialog_widget import EmployeeDialogWidget
from employee_card_widget import EmployeeCardWidget
from data.connect import connect, User, Department
from structure_widget import DepartmentGraph
@@ -9,25 +10,45 @@ from structure_widget import DepartmentGraph
class MainWindow(QMainWindow):
def __init__(self):
super().__init__()
-
uic.loadUi('ui/main.ui', self)
+ self.selected_department = None
+
self.department_employees = []
+ self.pushButton.clicked.connect(self.create_new_employee)
+
self.structer_company_widget = DepartmentGraph(self)
self.gridLayout_2.addWidget(self.structer_company_widget)
+ def create_new_employee(self):
+ self.create_employee_dialog = EmployeeDialogWidget(self.selected_department, self.department_employees, self)
+ self.create_employee_dialog.exec()
+
def select_department(self, department_id):
self.department_employees = []
self.search_employees(department_id)
+ with connect() as session:
+ self.selected_department = session.query(Department).filter(Department.id == department_id).first()
+
for i in range(self.verticalLayout.count()):
self.verticalLayout.itemAt(i).widget().close()
for employee in self.department_employees:
employee_card = EmployeeCardWidget(employee)
+ employee_card.pushButton.clicked.connect(self.edit_employee)
+ employee_card.pushButton.employee = employee
+
self.verticalLayout.addWidget(employee_card)
+ def edit_employee(self):
+ button = self.sender()
+ employee = button.employee
+
+ self.create_employee_dialog = EmployeeDialogWidget(self.selected_department, self.department_employees, self, employee)
+ self.create_employee_dialog.exec()
+
def search_employees(self, department_id):
with connect() as session:
employees = session.query(User).filter(User.department_id == department_id).all()
diff --git a/Desktop/structure_widget.py b/Desktop/structure_widget.py
index d74de0b..1922a72 100644
--- a/Desktop/structure_widget.py
+++ b/Desktop/structure_widget.py
@@ -16,6 +16,8 @@ class DepartmentGraph(QGraphicsView):
self.pushed_button = None
self.parent = parent
+ self.is_first_button = True
+
self.nodes = {}
self.render_graph()
@@ -59,6 +61,10 @@ class DepartmentGraph(QGraphicsView):
}
''')
+ if self.is_first_button:
+ button.click()
+ self.is_first_button = False
+
proxy = QGraphicsProxyWidget()
proxy.setWidget(button)
proxy.setPos(x, y)
diff --git a/Desktop/ui/card_widget.ui b/Desktop/ui/card_widget.ui
index 26a2961..415c3ac 100644
--- a/Desktop/ui/card_widget.ui
+++ b/Desktop/ui/card_widget.ui
@@ -7,19 +7,19 @@
0
0
450
- 130
+ 150
450
- 130
+ 150
450
- 130
+ 150
@@ -42,7 +42,7 @@ background-color: rgb(228, 244, 204);
0
0
461
- 131
+ 149
@@ -94,19 +94,26 @@ background-color: rgb(228, 244, 204);
- 0
+ 359
0
- 450
- 130
+ 91
+ 81
+
+
+ Wingdings 2
+ 24
+
+
- #pushButton {
- background-color: rgba(255, 255, 255, 0);
-}
+
-
+ !
+
+
+ true
diff --git a/Desktop/ui/employee_dialog_window.ui b/Desktop/ui/employee_dialog_window.ui
new file mode 100644
index 0000000..33fd6d5
--- /dev/null
+++ b/Desktop/ui/employee_dialog_window.ui
@@ -0,0 +1,290 @@
+
+
+ Dialog
+
+
+
+ 0
+ 0
+ 718
+ 579
+
+
+
+
+ 400
+ 400
+
+
+
+ ИС "Российские дороги" - Управление персоналом - Редактирование/добавление сотрудника
+
+
+
+ ../res/Logo.png../res/Logo.png
+
+
+ QPushButton {
+background-color: rgb(228, 244, 204);
+}
+QPushButton:hover {
+background-color: #2f9836;
+}
+
+
+ -
+
+
+ Qt::Vertical
+
+
+
+ 20
+ 40
+
+
+
+
+ -
+
+
+ Отчество
+
+
+
+ -
+
+
+ +7 (000) 000-00-00
+
+
+ 18
+
+
+
+ -
+
+
+ Qt::Horizontal
+
+
+
+ 40
+ 20
+
+
+
+
+ -
+
+
+ Рабочий телефон
+
+
+
+ -
+
+
+ true
+
+
+
+ -
+
+
+ Qt::Vertical
+
+
+
+ 20
+ 40
+
+
+
+
+ -
+
+
+ Прочая информация
+
+
+
+ -
+
+
+
+
+
+ true
+
+
+
+ -
+
+
+ +7 (000) 000-00-00
+
+
+ 18
+
+
+ Мобильный телефон
+
+
+
+ -
+
+
+ Сохранить
+
+
+
+ -
+
+
+ Имя
+
+
+
+ -
+
+
+ Qt::Horizontal
+
+
+
+ 40
+ 20
+
+
+
+
+ -
+
+
+ Qt::Horizontal
+
+
+
+ 40
+ 20
+
+
+
+
+ -
+
+
+ Назад
+
+
+
+ -
+
+
+ Должности
+
+
+
+ -
+
+
+ Мобильный телефон
+
+
+
+ -
+
+
+ -
+
+
+ Помошник
+
+
+
+ -
+
+
+ Фамилия
+
+
+
+ -
+
+
+ -
+
+
+ Электронная почта
+
+
+
+ -
+
+
+ 10
+
+
+ Кабинет
+
+
+
+ -
+
+
+ Qt::Horizontal
+
+
+
+ 40
+ 20
+
+
+
+
+ -
+
+
+ Департамент
+
+
+
+
+
+
+ lineEdit
+ lineEdit_2
+ lineEdit_3
+ lineEdit_4
+ dateEdit
+ lineEdit_5
+ comboBox
+ comboBox_2
+ lineEdit_6
+ lineEdit_7
+ lineEdit_8
+ lineEdit_9
+ pushButton_2
+ pushButton
+
+
+
+
+ pushButton
+ clicked()
+ Dialog
+ close()
+
+
+ 616
+ 27
+
+
+ 630
+ 228
+
+
+
+
+