Edit record procedure fixing has began
This commit is contained in:
parent
8ca81184a9
commit
77da13fbaa
2
.gitignore
vendored
Normal file
2
.gitignore
vendored
Normal file
|
@ -0,0 +1,2 @@
|
|||
.idea/
|
||||
__pycache__/
|
|
@ -6,7 +6,7 @@
|
|||
"fieldList": [
|
||||
{
|
||||
"fName": "id",
|
||||
"fDescription": "Номер п.п.",
|
||||
"fDescription": "UID",
|
||||
"fType": "INTEGER",
|
||||
"index": "PRIMARY KEY",
|
||||
"autoIncrement": "yes",
|
||||
|
@ -60,7 +60,7 @@
|
|||
"fieldList": [
|
||||
{
|
||||
"fName": "id",
|
||||
"fDescription": "Номер п.п.",
|
||||
"fDescription": "UID",
|
||||
"fType": "INTEGER",
|
||||
"index": "PRIMARY KEY",
|
||||
"autoIncrement": "yes",
|
||||
|
@ -106,7 +106,7 @@
|
|||
"fieldList": [
|
||||
{
|
||||
"fName": "id",
|
||||
"fDescription": "Номер п.п.",
|
||||
"fDescription": "UID",
|
||||
"fType": "INTEGER",
|
||||
"index": "PRIMARY KEY",
|
||||
"autoIncrement": "yes",
|
||||
|
@ -122,7 +122,7 @@
|
|||
},
|
||||
{
|
||||
"fName": "city",
|
||||
"fDescription": "Населеннй пункт",
|
||||
"fDescription": "Населенный пункт",
|
||||
"fType": "varchar(200)",
|
||||
"index": "no",
|
||||
"autoIncrement": "no",
|
||||
|
@ -147,54 +147,116 @@
|
|||
]
|
||||
},
|
||||
{
|
||||
"tableName": "test",
|
||||
"tableDescription": "Шляпа",
|
||||
"tableName": "items",
|
||||
"tableDescription": "Оборудование",
|
||||
"fieldList": [
|
||||
{
|
||||
"fName": "id",
|
||||
"fDescription": "Номер п.п.",
|
||||
"fDescription": "UID",
|
||||
"fType": "INTEGER",
|
||||
"index": "PRIMARY KEY",
|
||||
"autoIncrement": "yes",
|
||||
"relation": []
|
||||
},
|
||||
{
|
||||
"fName": "user",
|
||||
"fDescription": "Юзер шляпы",
|
||||
"fName": "item_name",
|
||||
"fDescription": "Наименование",
|
||||
"fType": "VARCHAR(100)",
|
||||
"index": "no",
|
||||
"autoIncrement": "no",
|
||||
"relation": []
|
||||
},
|
||||
{
|
||||
"fName": "item_address",
|
||||
"fDescription": "Место расположения",
|
||||
"fType": "INTEGER",
|
||||
"index": "no",
|
||||
"autoIncrement": "no",
|
||||
"relation": ["users.id", "last_name, name, middle_name"]
|
||||
"relation": ["address.id", "city, street, house"]
|
||||
},
|
||||
{
|
||||
"fName": "item_type",
|
||||
"fDescription": "Тип",
|
||||
"fType": "CHAR(20)",
|
||||
"index": "no",
|
||||
"autoIncrement": "no",
|
||||
"relation": ["itemtype.id", "type_name"]
|
||||
},
|
||||
{
|
||||
"fName": "inventory_number",
|
||||
"fDescription": "Инвентарный номер",
|
||||
"fType": "CHAR(10)",
|
||||
"index": "no",
|
||||
"autoIncrement": "no",
|
||||
"relation": []
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"tableName": "test2",
|
||||
"tableDescription": "Шляпа2",
|
||||
"tableName": "itemtype",
|
||||
"tableDescription": "Тип оборудования",
|
||||
"fieldList": [
|
||||
{
|
||||
"fName": "id",
|
||||
"fDescription": "Номер п.п.",
|
||||
"fDescription": "UID",
|
||||
"fType": "INTEGER",
|
||||
"index": "PRIMARY KEY",
|
||||
"autoIncrement": "yes",
|
||||
"relation": []
|
||||
},
|
||||
{
|
||||
"fName": "ins_date",
|
||||
"fDescription": "Дата добавления",
|
||||
"fName": "type_name",
|
||||
"fDescription": "Тип",
|
||||
"fType": "VARCHAR(100)",
|
||||
"index": "no",
|
||||
"autoIncrement": "no",
|
||||
"relation": []
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"tableName": "itemrelocation",
|
||||
"tableDescription": "Перемещения",
|
||||
"fieldList": [
|
||||
{
|
||||
"fName": "id",
|
||||
"fDescription": "UID",
|
||||
"fType": "INTEGER",
|
||||
"index": "PRIMARY KEY",
|
||||
"autoIncrement": "yes",
|
||||
"relation": []
|
||||
},
|
||||
{
|
||||
"fName": "item_id",
|
||||
"fDescription": "Оборудование",
|
||||
"fType": "INTEGER",
|
||||
"index": "no",
|
||||
"autoIncrement": "no",
|
||||
"relation": ["items.id", "item_name, inventory_number"]
|
||||
},
|
||||
{
|
||||
"fName": "source_place",
|
||||
"fDescription": "Откуда",
|
||||
"fType": "INTEGER",
|
||||
"index": "no",
|
||||
"autoIncrement": "no",
|
||||
"relation": ["address.id", "city, street, house"]
|
||||
},
|
||||
{
|
||||
"fName": "destination_place",
|
||||
"fDescription": "Куда",
|
||||
"fType": "INTEGER",
|
||||
"index": "no",
|
||||
"autoIncrement": "no",
|
||||
"relation": ["address.id", "city, street, house"]
|
||||
},
|
||||
{
|
||||
"fName": "create_datetime",
|
||||
"fDescription": "Дата перемещения",
|
||||
"fType": "DATETIME",
|
||||
"index": "no",
|
||||
"autoIncrement": "no",
|
||||
"relation": []
|
||||
},
|
||||
{
|
||||
"fName": "user",
|
||||
"fDescription": "Юзер шляпы",
|
||||
"fType": "INTEGER",
|
||||
"index": "no",
|
||||
"autoIncrement": "no",
|
||||
"relation": ["users.id", "last_name, name, middle_name"]
|
||||
}
|
||||
]
|
||||
}
|
||||
|
|
12
dm.py
12
dm.py
|
@ -3,8 +3,8 @@ import json, os, configparser, shutil, re
|
|||
from datetime import datetime, date, time
|
||||
|
||||
def firstInit():
|
||||
# Инициализация переменныхб создание конфигруационного файла, копирование шаблонов
|
||||
global db_type, db_hostname, db_user, db_password, db_name, template_file, db_type
|
||||
# Инициализация переменных создание конфигруационного файла, копирование шаблонов
|
||||
global db_type, db_hostname, db_user, db_password, db_name, template_file, db_type, template_dir
|
||||
config = configparser.RawConfigParser()
|
||||
# проверяем тип ОС
|
||||
if os.name == "nt":
|
||||
|
@ -39,6 +39,7 @@ def firstInit():
|
|||
config.read(cfg_file)
|
||||
|
||||
work_dir = config.get('Directory', 'work_dir')
|
||||
global template_dir
|
||||
template_dir = config.get('Directory', 'template_dir')
|
||||
db_type = config.get('DataBase', 'db_type')
|
||||
db_hostname = config.get('DataBase', 'db_hostname')
|
||||
|
@ -177,9 +178,9 @@ def initDBstructure():
|
|||
global dbTablesDescriptionList, template_file, tblNamesList
|
||||
table_list = open(template_file, "r", encoding="utf-8")
|
||||
data = json.load(table_list, encoding="utf-8")
|
||||
tbl_list = data["tables"]
|
||||
tblNamesList = createTables(tbl_list)
|
||||
|
||||
#tbl_list = data["tables"]
|
||||
#tblNamesList = createTables(tbl_list)
|
||||
tblNamesList = createTables(data["tables"])
|
||||
return tblNamesList
|
||||
|
||||
# выборка данных из заданной таблицы
|
||||
|
@ -188,6 +189,7 @@ def selectData(tbl):
|
|||
# если юольше 1 поля добавить CONCAT
|
||||
qwery = "SELECT "
|
||||
subqwery = ""
|
||||
#print(dbTablesStructList)
|
||||
for item in dbTablesStructList:
|
||||
if item[0] == tbl:
|
||||
for field in item[1]:
|
||||
|
|
56
gui.py
56
gui.py
|
@ -5,6 +5,8 @@ import sys
|
|||
from PyQt5.QtCore import *
|
||||
from PyQt5.QtGui import *
|
||||
from PyQt5.QtWidgets import *
|
||||
#from PyQt5.QtWidgets import (QMainWindow, QTextEdit, QAction, QFileDialog, QApplication)
|
||||
#from PyQt5.QtGui import QIcon
|
||||
|
||||
#import pymysql
|
||||
import dm
|
||||
|
@ -83,13 +85,17 @@ class MyTable(QTableWidget):
|
|||
#print(self.dbTableName, row, self.statusTip())
|
||||
i = 0
|
||||
#print(self.columnCount())
|
||||
#print(self.verticalHeaderItem(row).text(), '---')
|
||||
while i < self.columnCount():
|
||||
if self.item(row, i):
|
||||
valueList.append(self.item(row, i).text())
|
||||
val = self.item(row, i).text()
|
||||
print(val)
|
||||
valueList.append(str(val))
|
||||
else:
|
||||
valueList.append('')
|
||||
#print(self.item(row, i).text())
|
||||
|
||||
i += 1
|
||||
print(valueList)
|
||||
editRecord(self, row, self.dbTableName, valueList)
|
||||
|
||||
# Диалог выбора связанных данных
|
||||
|
@ -274,15 +280,15 @@ class EditForm(QMainWindow):
|
|||
hboxEdit.addWidget(lbl2)
|
||||
hboxEdit.addWidget(edit)
|
||||
# добавляем к полю кнопку для вызова связанных
|
||||
print(fName)
|
||||
#print(fName)
|
||||
listRelationTableAndField = dm.getRelationsForField(tblName, fName)
|
||||
|
||||
print(listRelationTableAndField)
|
||||
#print(listRelationTableAndField)
|
||||
if listRelationTableAndField != 'q':
|
||||
tableRelation = listRelationTableAndField[0]
|
||||
fieldRelation = listRelationTableAndField[1]
|
||||
replaceField = listRelationTableAndField[2]
|
||||
print(tableRelation + '-' + fieldRelation +'-'+replaceField)
|
||||
#print(tableRelation + '-' + fieldRelation +'-'+replaceField)
|
||||
btnRelations = QPushButton('...')
|
||||
btnRelations.setFixedWidth(30)
|
||||
# добавляем название виджета в список соответсвия кнопок и таблиц БД
|
||||
|
@ -386,6 +392,7 @@ def addDataIntoTable(dbTableName, tblDataWidget, data='NULL'):
|
|||
dbFieldRelationValueList = []
|
||||
for key in data:
|
||||
n = 0
|
||||
print(key)
|
||||
for item in key:
|
||||
listRelationTableAndField = dm.getRelationsForField(dbTableName, fieldNames[n][0])
|
||||
if listRelationTableAndField != 'q':
|
||||
|
@ -397,15 +404,26 @@ def addDataIntoTable(dbTableName, tblDataWidget, data='NULL'):
|
|||
else:
|
||||
newitem = QTableWidgetItem(str(item))
|
||||
dbFieldRelationValueList.append([newitem, m, n, 'None', 'None'])
|
||||
|
||||
else:
|
||||
newitem = QTableWidgetItem(str(item))
|
||||
# преобразуем все типы в строку
|
||||
newitem = QTableWidgetItem(str(item))
|
||||
#print(fieldNames[n][0])
|
||||
#print(str(item))
|
||||
# проверяем название поля и если это id то данные вносим в заголовок строки
|
||||
# таким образом внесем уникальный ID в чётко определенное поле
|
||||
#if fieldNames[n][0] == "id":
|
||||
# tblDataWidget.setVerticalHeaderItem(m, QTableWidgetItem(str(item)))
|
||||
tblDataWidget.setItem(m, n, newitem)
|
||||
n += 1
|
||||
m += 1
|
||||
|
||||
# Показ меню и панели инструментов
|
||||
def showMenuToolbar(window):
|
||||
openFileAction = QAction(QIcon('img/open.gif'), 'Открыть', window)
|
||||
openFileAction.setShortcut('Ctrl+O')
|
||||
openFileAction.setStatusTip('Открыть')
|
||||
openFileAction.triggered.connect(openTemplate)
|
||||
|
||||
newAction = QAction(QIcon('img/new.gif'), 'Добавить', window)
|
||||
newAction.setShortcut('Ins')
|
||||
newAction.setStatusTip('Добавить')
|
||||
|
@ -414,12 +432,11 @@ def showMenuToolbar(window):
|
|||
deleteAction = QAction(QIcon('img/delete.gif'), 'Удалить', window)
|
||||
deleteAction.setShortcut('Del')
|
||||
deleteAction.setStatusTip('Удалить')
|
||||
# deleteAction.triggered.connect(window.qqqq)
|
||||
|
||||
exitAction = QAction(QIcon('img/exit.gif'), 'Выход', window)
|
||||
exitAction.setShortcut('Ctrl+Q')
|
||||
exitAction.setStatusTip('Выход')
|
||||
exitAction.triggered.connect(window.close)
|
||||
exitAction.setStatusTip('Выйти')
|
||||
exitAction.triggered.connect(exit)
|
||||
|
||||
structureAction = QAction(QIcon('img/table.gif'), 'Показать структуру', window)
|
||||
#structureAction.setShortcut('Ctrl+Q')
|
||||
|
@ -429,32 +446,28 @@ def showMenuToolbar(window):
|
|||
cutAction = QAction(QIcon('img/cut.gif'), 'Вырезать', window)
|
||||
cutAction.setShortcut('Ctrl+X')
|
||||
cutAction.setStatusTip('Вырезать')
|
||||
# cutAction.triggered.connect(window.close)
|
||||
|
||||
copyAction = QAction(QIcon('img/copy.gif'), 'Копировать', window)
|
||||
copyAction.setShortcut('Ctrl+С')
|
||||
copyAction.setStatusTip('Копировать')
|
||||
# copyAction.triggered.connect(window.close)
|
||||
|
||||
pasteAction = QAction(QIcon('img/paste.gif'), 'Вставить', window)
|
||||
pasteAction.setShortcut('Ctrl+V')
|
||||
pasteAction.setStatusTip('Вставить')
|
||||
# pasteAction.triggered.connect(window.close)
|
||||
|
||||
findAction = QAction(QIcon('img/find.gif'), 'Поиск', window)
|
||||
findAction.setShortcut('Ctrl+F')
|
||||
findAction.setStatusTip('Искать')
|
||||
# findAction.triggered.connect(window.close)
|
||||
|
||||
printAction = QAction(QIcon('img/print.gif'), 'Печатать', window)
|
||||
printAction.setShortcut('Ctrl+P')
|
||||
printAction.setStatusTip('Печатать')
|
||||
# printAction.triggered.connect(window.close)
|
||||
|
||||
window.statusBar()
|
||||
|
||||
menubar = window.menuBar()
|
||||
fileMenu = menubar.addMenu('&Файл')
|
||||
fileMenu.addAction(openFileAction)
|
||||
fileMenu.addAction(newAction)
|
||||
fileMenu.addAction(deleteAction)
|
||||
fileMenu.addAction(printAction)
|
||||
|
@ -472,6 +485,7 @@ def showMenuToolbar(window):
|
|||
# toolbar = window.addToolBar('Редактирование')
|
||||
|
||||
toolbar = window.addToolBar('Панель инструментов')
|
||||
#toolbar.addAction(openFileAction)
|
||||
toolbar.addAction(newAction)
|
||||
toolbar.addAction(deleteAction)
|
||||
toolbar.addAction(copyAction)
|
||||
|
@ -556,11 +570,12 @@ def editRecord(tableWidget, row, dbTableName, valueList):
|
|||
valueList.pop(i)
|
||||
valueList.insert(i, item[3])
|
||||
val = item[3]
|
||||
#print(val)
|
||||
editForm.widgetsList[i][1].setText(val)
|
||||
i += 1
|
||||
print(valueList)
|
||||
#print(valueList)
|
||||
|
||||
print(editForm.widgetsList)
|
||||
#print(editForm.widgetsList)
|
||||
#dm.deleteRecordsFromDB(dbTableName, valueList)
|
||||
|
||||
|
||||
|
@ -576,6 +591,12 @@ def showStructure():
|
|||
print(dm.getFields(tblName))
|
||||
print(dm.getTableStructureFromDB(tblName))
|
||||
|
||||
def openTemplate():
|
||||
global template_file, template_dir
|
||||
template_file = QFileDialog.getOpenFileName(None, 'Open file', template_dir)[0]
|
||||
dm.initDBstructure(template_file)
|
||||
|
||||
|
||||
def main():
|
||||
global dbTablesList, listDBTables, tabRelationsData, dbFieldRelationValueList
|
||||
dbFieldRelationValueList = []
|
||||
|
@ -620,3 +641,4 @@ def main():
|
|||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
print(template_dir)
|
||||
|
|
Loading…
Reference in New Issue
Block a user