Add "edit records" procedure
This commit is contained in:
parent
c6a63b972e
commit
9cc5c6cd57
41
dm.py
41
dm.py
|
@ -459,6 +459,47 @@ def deleteRecordsFromDB(tableName, valueList):
|
||||||
conn.commit()
|
conn.commit()
|
||||||
return
|
return
|
||||||
|
|
||||||
|
# Редактирование записи в БД
|
||||||
|
def editDataIntoBD(dataList):
|
||||||
|
global c, conn
|
||||||
|
dbConnect()
|
||||||
|
tableName = dataList[0]
|
||||||
|
qwery = 'UPDATE {} SET '.format(tableName)
|
||||||
|
#qweryData = ''
|
||||||
|
qweryField = ''
|
||||||
|
qweryWhere = ''
|
||||||
|
for item in dataList[1]:
|
||||||
|
fType = getFieldType(tableName, item[0])
|
||||||
|
# проверяем если значение поля пустое то в запрос оно не включается
|
||||||
|
if item[1] != '':
|
||||||
|
qweryField = '{}{}='.format(qweryField,item[0])
|
||||||
|
|
||||||
|
if fType == 'integer':
|
||||||
|
qweryField = '{}{},'.format(qweryField,item[1])
|
||||||
|
elif fType == 'datetime':
|
||||||
|
# преобразуем дату всяко разно
|
||||||
|
dt = datetime.strptime(item[1], "%d.%m.%y %H:%M")
|
||||||
|
item[1] = str(dt)
|
||||||
|
qweryField = "{}'{}',".format(qweryField,item[1])
|
||||||
|
elif fType == 'date':
|
||||||
|
d = item[1].split('.')
|
||||||
|
myDate = '{}-{}-{}'.format(d[2], d[1], d[1])
|
||||||
|
item[1] = str(myDate)
|
||||||
|
qweryField = "{}'{}',".format(qweryField, item[1])
|
||||||
|
else:
|
||||||
|
qweryField = "{}'{}',".format(qweryField, item[1])
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
qwery = '{}{} WHERE {};'.format(qwery, qweryField.rstrip(','), qweryWhere)
|
||||||
|
|
||||||
|
print(qwery)
|
||||||
|
#c.execute(qwery)
|
||||||
|
#conn.commit()
|
||||||
|
#c.close()
|
||||||
|
return
|
||||||
|
|
||||||
|
|
||||||
#initDBstructure()
|
#initDBstructure()
|
||||||
firstInit()
|
firstInit()
|
||||||
dbConnect()
|
dbConnect()
|
||||||
|
|
19
gui.py
19
gui.py
|
@ -192,10 +192,14 @@ class EditForm(QMainWindow):
|
||||||
lblList = []
|
lblList = []
|
||||||
editList = []
|
editList = []
|
||||||
|
|
||||||
def __init__(self, tblName, tblDescr):
|
def __init__(self, tblName, tblDescr, action):
|
||||||
super().__init__()
|
super().__init__()
|
||||||
self.tblName = tblName
|
self.tblName = tblName
|
||||||
self.setWindowTitle("Добавление записи")
|
self.action = action
|
||||||
|
if action == 'edit':
|
||||||
|
self.setWindowTitle("Редактирование записи")
|
||||||
|
elif action == 'add':
|
||||||
|
self.setWindowTitle("Добавление записи")
|
||||||
#self.setGeometry(300, 300, 400, 400)
|
#self.setGeometry(300, 300, 400, 400)
|
||||||
scroll_widget = QWidget()
|
scroll_widget = QWidget()
|
||||||
self.general_layout = QVBoxLayout()
|
self.general_layout = QVBoxLayout()
|
||||||
|
@ -307,7 +311,10 @@ class EditForm(QMainWindow):
|
||||||
listFieldData.append([item[0], item[1].text()])
|
listFieldData.append([item[0], item[1].text()])
|
||||||
listData.append(listFieldData)
|
listData.append(listFieldData)
|
||||||
#print(listData)
|
#print(listData)
|
||||||
dm.insertDataIntoBD(listData)
|
if self.action == 'add':
|
||||||
|
dm.insertDataIntoBD(listData)
|
||||||
|
elif self.action == 'edit':
|
||||||
|
dm.editDataIntoBD(listData)
|
||||||
self.close()
|
self.close()
|
||||||
# выбираем данные для связанной таблицы
|
# выбираем данные для связанной таблицы
|
||||||
def openRelationTable(self):
|
def openRelationTable(self):
|
||||||
|
@ -477,7 +484,7 @@ def addNewRecord():
|
||||||
tblName = i[0]
|
tblName = i[0]
|
||||||
|
|
||||||
#print(tblName)
|
#print(tblName)
|
||||||
editForm = EditForm(tblName, tblDescr)
|
editForm = EditForm(tblName, tblDescr, 'add')
|
||||||
editForm.show()
|
editForm.show()
|
||||||
#editForm.setParent(listDBTables)
|
#editForm.setParent(listDBTables)
|
||||||
#editForm.show()
|
#editForm.show()
|
||||||
|
@ -533,7 +540,7 @@ def deleteRecord(tableWidget, row, dbTableName, valueList):
|
||||||
# Редактирование записи
|
# Редактирование записи
|
||||||
def editRecord(tableWidget, row, dbTableName, valueList):
|
def editRecord(tableWidget, row, dbTableName, valueList):
|
||||||
global dbFieldRelationValueList
|
global dbFieldRelationValueList
|
||||||
editForm = EditForm(dbTableName, dm.getTablesDescriptionOfName(dbTableName))
|
editForm = EditForm(dbTableName, dm.getTablesDescriptionOfName(dbTableName), 'edit')
|
||||||
editForm.show()
|
editForm.show()
|
||||||
i = 0
|
i = 0
|
||||||
for val in valueList:
|
for val in valueList:
|
||||||
|
@ -586,7 +593,7 @@ def main():
|
||||||
print(dm.getTablesNameOfDescription(listDBTables.model().data(listDBTables.currentIndex())))
|
print(dm.getTablesNameOfDescription(listDBTables.model().data(listDBTables.currentIndex())))
|
||||||
|
|
||||||
|
|
||||||
mainWin.setGeometry(300, 300, 800, 600)
|
mainWin.setGeometry(300, 300, 1024, 800)
|
||||||
mainWin.setWindowTitle('Data manipulator')
|
mainWin.setWindowTitle('Data manipulator')
|
||||||
mainWin.show()
|
mainWin.show()
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user