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()
|
||||
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()
|
||||
firstInit()
|
||||
dbConnect()
|
||||
|
|
19
gui.py
19
gui.py
|
@ -192,10 +192,14 @@ class EditForm(QMainWindow):
|
|||
lblList = []
|
||||
editList = []
|
||||
|
||||
def __init__(self, tblName, tblDescr):
|
||||
def __init__(self, tblName, tblDescr, action):
|
||||
super().__init__()
|
||||
self.tblName = tblName
|
||||
self.setWindowTitle("Добавление записи")
|
||||
self.action = action
|
||||
if action == 'edit':
|
||||
self.setWindowTitle("Редактирование записи")
|
||||
elif action == 'add':
|
||||
self.setWindowTitle("Добавление записи")
|
||||
#self.setGeometry(300, 300, 400, 400)
|
||||
scroll_widget = QWidget()
|
||||
self.general_layout = QVBoxLayout()
|
||||
|
@ -307,7 +311,10 @@ class EditForm(QMainWindow):
|
|||
listFieldData.append([item[0], item[1].text()])
|
||||
listData.append(listFieldData)
|
||||
#print(listData)
|
||||
dm.insertDataIntoBD(listData)
|
||||
if self.action == 'add':
|
||||
dm.insertDataIntoBD(listData)
|
||||
elif self.action == 'edit':
|
||||
dm.editDataIntoBD(listData)
|
||||
self.close()
|
||||
# выбираем данные для связанной таблицы
|
||||
def openRelationTable(self):
|
||||
|
@ -477,7 +484,7 @@ def addNewRecord():
|
|||
tblName = i[0]
|
||||
|
||||
#print(tblName)
|
||||
editForm = EditForm(tblName, tblDescr)
|
||||
editForm = EditForm(tblName, tblDescr, 'add')
|
||||
editForm.show()
|
||||
#editForm.setParent(listDBTables)
|
||||
#editForm.show()
|
||||
|
@ -533,7 +540,7 @@ def deleteRecord(tableWidget, row, dbTableName, valueList):
|
|||
# Редактирование записи
|
||||
def editRecord(tableWidget, row, dbTableName, valueList):
|
||||
global dbFieldRelationValueList
|
||||
editForm = EditForm(dbTableName, dm.getTablesDescriptionOfName(dbTableName))
|
||||
editForm = EditForm(dbTableName, dm.getTablesDescriptionOfName(dbTableName), 'edit')
|
||||
editForm.show()
|
||||
i = 0
|
||||
for val in valueList:
|
||||
|
@ -586,7 +593,7 @@ def main():
|
|||
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.show()
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user