This commit is contained in:
Андрей Дувакин 2025-01-13 22:52:16 +05:00
parent 37481d4fa6
commit fa100392c2
6 changed files with 505 additions and 12 deletions

4
Desktop/1.py Normal file
View File

@ -0,0 +1,4 @@
# 0, 1, 2, 3, 4
# -3 -2 -1
a = [1, 2, 3, 4, 5]
print(a[-1])

View File

@ -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

View File

@ -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()

View File

@ -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)

View File

@ -7,19 +7,19 @@
<x>0</x>
<y>0</y>
<width>450</width>
<height>130</height>
<height>150</height>
</rect>
</property>
<property name="minimumSize">
<size>
<width>450</width>
<height>130</height>
<height>150</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>450</width>
<height>130</height>
<height>150</height>
</size>
</property>
<property name="sizeIncrement">
@ -42,7 +42,7 @@ background-color: rgb(228, 244, 204);
<x>0</x>
<y>0</y>
<width>461</width>
<height>131</height>
<height>149</height>
</rect>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
@ -94,19 +94,26 @@ background-color: rgb(228, 244, 204);
<widget class="QPushButton" name="pushButton">
<property name="geometry">
<rect>
<x>0</x>
<x>359</x>
<y>0</y>
<width>450</width>
<height>130</height>
<width>91</width>
<height>81</height>
</rect>
</property>
<property name="font">
<font>
<family>Wingdings 2</family>
<pointsize>24</pointsize>
</font>
</property>
<property name="styleSheet">
<string notr="true">#pushButton {
background-color: rgba(255, 255, 255, 0);
}</string>
<string notr="true"/>
</property>
<property name="text">
<string/>
<string>!</string>
</property>
<property name="flat">
<bool>true</bool>
</property>
</widget>
</widget>

View File

@ -0,0 +1,290 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>Dialog</class>
<widget class="QDialog" name="Dialog">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>718</width>
<height>579</height>
</rect>
</property>
<property name="minimumSize">
<size>
<width>400</width>
<height>400</height>
</size>
</property>
<property name="windowTitle">
<string>ИС &quot;Российские дороги&quot; - Управление персоналом - Редактирование/добавление сотрудника</string>
</property>
<property name="windowIcon">
<iconset>
<normaloff>../res/Logo.png</normaloff>../res/Logo.png</iconset>
</property>
<property name="styleSheet">
<string notr="true">QPushButton {
background-color: rgb(228, 244, 204);
}
QPushButton:hover {
background-color: #2f9836;
}</string>
</property>
<layout class="QGridLayout" name="gridLayout">
<item row="1" column="1">
<spacer name="verticalSpacer_2">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item>
<item row="4" column="1">
<widget class="QLineEdit" name="lineEdit_3">
<property name="placeholderText">
<string>Отчество</string>
</property>
</widget>
</item>
<item row="15" column="1">
<widget class="QLineEdit" name="lineEdit_6">
<property name="inputMask">
<string>+7 (000) 000-00-00</string>
</property>
<property name="maxLength">
<number>18</number>
</property>
</widget>
</item>
<item row="2" column="2">
<spacer name="horizontalSpacer_2">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item row="14" column="1">
<widget class="QLabel" name="label_4">
<property name="text">
<string>Рабочий телефон</string>
</property>
</widget>
</item>
<item row="7" column="1">
<widget class="QDateEdit" name="dateEdit">
<property name="calendarPopup">
<bool>true</bool>
</property>
</widget>
</item>
<item row="20" column="1">
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item>
<item row="18" column="1">
<widget class="QLineEdit" name="lineEdit_9">
<property name="placeholderText">
<string>Прочая информация</string>
</property>
</widget>
</item>
<item row="9" column="1">
<widget class="QLineEdit" name="lineEdit_5">
<property name="text">
<string/>
</property>
<property name="readOnly">
<bool>true</bool>
</property>
</widget>
</item>
<item row="6" column="1">
<widget class="QLineEdit" name="lineEdit_4">
<property name="inputMask">
<string>+7 (000) 000-00-00</string>
</property>
<property name="maxLength">
<number>18</number>
</property>
<property name="placeholderText">
<string>Мобильный телефон</string>
</property>
</widget>
</item>
<item row="19" column="1">
<widget class="QPushButton" name="pushButton_2">
<property name="text">
<string>Сохранить</string>
</property>
</widget>
</item>
<item row="3" column="1">
<widget class="QLineEdit" name="lineEdit_2">
<property name="placeholderText">
<string>Имя</string>
</property>
</widget>
</item>
<item row="0" column="1">
<spacer name="horizontalSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item row="0" column="0">
<spacer name="horizontalSpacer_3">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item row="0" column="2">
<widget class="QPushButton" name="pushButton">
<property name="text">
<string>Назад</string>
</property>
</widget>
</item>
<item row="10" column="1">
<widget class="QLabel" name="label_2">
<property name="text">
<string>Должности</string>
</property>
</widget>
</item>
<item row="5" column="1">
<widget class="QLabel" name="label">
<property name="text">
<string>Мобильный телефон</string>
</property>
</widget>
</item>
<item row="13" column="1">
<widget class="QComboBox" name="comboBox_2"/>
</item>
<item row="12" column="1">
<widget class="QLabel" name="label_3">
<property name="text">
<string>Помошник</string>
</property>
</widget>
</item>
<item row="2" column="1">
<widget class="QLineEdit" name="lineEdit">
<property name="placeholderText">
<string>Фамилия</string>
</property>
</widget>
</item>
<item row="11" column="1">
<widget class="QComboBox" name="comboBox"/>
</item>
<item row="16" column="1">
<widget class="QLineEdit" name="lineEdit_7">
<property name="placeholderText">
<string>Электронная почта</string>
</property>
</widget>
</item>
<item row="17" column="1">
<widget class="QLineEdit" name="lineEdit_8">
<property name="maxLength">
<number>10</number>
</property>
<property name="placeholderText">
<string>Кабинет</string>
</property>
</widget>
</item>
<item row="2" column="0">
<spacer name="horizontalSpacer_4">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item row="8" column="1">
<widget class="QLabel" name="label_5">
<property name="text">
<string>Департамент</string>
</property>
</widget>
</item>
</layout>
</widget>
<tabstops>
<tabstop>lineEdit</tabstop>
<tabstop>lineEdit_2</tabstop>
<tabstop>lineEdit_3</tabstop>
<tabstop>lineEdit_4</tabstop>
<tabstop>dateEdit</tabstop>
<tabstop>lineEdit_5</tabstop>
<tabstop>comboBox</tabstop>
<tabstop>comboBox_2</tabstop>
<tabstop>lineEdit_6</tabstop>
<tabstop>lineEdit_7</tabstop>
<tabstop>lineEdit_8</tabstop>
<tabstop>lineEdit_9</tabstop>
<tabstop>pushButton_2</tabstop>
<tabstop>pushButton</tabstop>
</tabstops>
<resources/>
<connections>
<connection>
<sender>pushButton</sender>
<signal>clicked()</signal>
<receiver>Dialog</receiver>
<slot>close()</slot>
<hints>
<hint type="sourcelabel">
<x>616</x>
<y>27</y>
</hint>
<hint type="destinationlabel">
<x>630</x>
<y>228</y>
</hint>
</hints>
</connection>
</connections>
</ui>