rmy 3 месяцев назад
Родитель
Сommit
223f289391
2 измененных файлов: 108 добавлений и 6 удалений
  1. 22
    6
      Front/main.py
  2. 86
    0
      Front/modules/ui_functions.py

+ 22
- 6
Front/main.py Просмотреть файл

@@ -956,12 +956,6 @@ class MainWindow(QMainWindow):
956 956
             # 关联自定义的右键菜单方法到customContextMenuRequested信号
957 957
             self.ui.resultTableView1.customContextMenuRequested.connect(self.show_custom_context_menu)
958 958
 
959
-    # 右键对应行可删除对应行(只是视图上)
960
-    def seleceModel_itemclicked(self):
961
-        curIndex = self.selectModel.currentIndex()
962
-        self.ui.resultTableView1.model().removeRow(curIndex.row())
963
-        kk = 1
964
-
965 959
     # 搜索的item展示
966 960
     def itembuttonClick1(self):
967 961
         # 判定是否获取的是根节点
@@ -1009,6 +1003,28 @@ class MainWindow(QMainWindow):
1009 1003
             # 调用默认的 keyPressEvent 处理其他按键事件
1010 1004
             super(widgets.datainfo.__class__, widgets.datainfo).keyPressEvent(event)
1011 1005
 
1006
+    # 右键对应行可删除对应行(所有的,搜索的再写一份,免得弄错)
1007
+    def seleceModel_itemclicked(self):
1008
+        selected_items = widgets.allTreeWidget.selectedItems()
1009
+        item = selected_items[0]
1010
+        data = item.data(0, Qt.UserRole + 1)
1011
+        # 获取数据库路径和表名
1012
+        dbname = data['listData'][0]
1013
+        tablename = data['listData'][2]
1014
+        dbpath = os.path.join(os.path.abspath('../SQL'), f"{dbname}.db")
1015
+        tablename_utf8 = tablename.encode('utf-8')
1016
+        # 获取父节点
1017
+        parent_item = item.parent()
1018
+        parent_name = parent_item.text(0)
1019
+        curIndex = self.selectModel.currentIndex()
1020
+        # self.ui.resultTableView1.model().removeRow(curIndex.row())
1021
+        col = curIndex.column()
1022
+        row = curIndex.row()
1023
+        # 重新组织表的内容,方便重新计算
1024
+        UIFunctions.del_row_from_db(self, row, parent_name, tablename_utf8, dbpath)
1025
+        # 1秒后自动跳转
1026
+        QTimer.singleShot(1000, lambda: self.simulateButtonClick("btn_new"))
1027
+
1012 1028
 
1013 1029
 if __name__ == "__main__":
1014 1030
     app = QApplication(sys.argv)

+ 86
- 0
Front/modules/ui_functions.py Просмотреть файл

@@ -20,6 +20,7 @@ from PySide6.QtWidgets import QMessageBox
20 20
 
21 21
 from main import *
22 22
 import importlib
23
+import sqlite3
23 24
 
24 25
 from select import select
25 26
 
@@ -377,4 +378,89 @@ class UIFunctions(MainWindow):
377 378
         elif current_text == "平面控制网稳定性计算":
378 379
             selectModel = WDshow.search_show_function(self.ui, file_path, utf_en)
379 380
             return selectModel
381
+
382
+    # 删除行数据
383
+    def del_row_from_db(self, row, methodName, tableName_utf8, dbPath):
384
+        db1 = sqlite3.connect(dbPath)
385
+        cursor1 = db1.cursor()
386
+        # 通过行锁定对应的字段
387
+        if methodName == '水准测段高差稳定计算':
388
+            sqlstr1 = """SELECT * FROM GC_Input_Point WHERE TableName = ? LIMIT 1 OFFSET ?"""
389
+            cursor1.execute(sqlstr1, (tableName_utf8, row,))
390
+            result1 = cursor1.fetchall()
391
+            list1 = result1[0]
392
+            # 100%准确查询
393
+            # sqlstr3 = """SELECT * FROM GC_Input_Point  WHERE TableName = ? and New_SPName = ? and New_EPName = ? and New_HDiff = ? and New_RLen = ?"""
394
+            # cursor1.execute(sqlstr3, (tableName_utf8, list1[7], list1[8], list1[11], list1[12],))
395
+            # result3 = cursor1.fetchall()
396
+            sqlstr2 = """DELETE FROM GC_Input_Point  WHERE TableName = ? and New_SPName = ? and New_EPName = ? and New_HDiff = ? and New_RLen = ?"""
397
+            cursor1.execute(sqlstr2, (tableName_utf8, list1[7], list1[8], list1[11], list1[12],))
398
+            # # 获取删除的记录数量
399
+            # deleted_count = cursor1.rowcount
400
+            # 直接使用计算方式
401
+            tableName = tableName_utf8.decode('utf-8')
402
+            # 先把结果相关的点数据删一下
403
+            sqlstr3 = """DELETE FROM GC_Output_Point  WHERE TableName = ?"""
404
+            cursor1.execute(sqlstr3, (tableName_utf8,))
405
+            # 提交事务
406
+            db1.commit()
407
+            # 关闭db
408
+            db1.close()
409
+            GCcompute.main_function(tableName, dbPath)
410
+            GCshow.main_function(self.ui, dbPath, tableName_utf8)
411
+        elif methodName == '控制网复测平面基准计算':
412
+            sqlstr1 = """SELECT * FROM GS_Input_Point WHERE TableName = ? LIMIT 1 OFFSET ?"""
413
+            cursor1.execute(sqlstr1, (tableName_utf8, row,))
414
+            result1 = cursor1.fetchall()
415
+            list1 = result1[0]
416
+            # 100%准确查询
417
+            # sqlstr3 = """SELECT * FROM GC_Input_Point  WHERE TableName = ? and New_SPName = ? and New_EPName = ? and New_HDiff = ? and New_RLen = ?"""
418
+            # cursor1.execute(sqlstr3, (tableName_utf8, list1[7], list1[8], list1[11], list1[12],))
419
+            # result3 = cursor1.fetchall()
420
+            sqlstr2 = """DELETE FROM GS_Input_Point  WHERE TableName = ? and PointName = ? and New_X = ? and New_Y = ?"""
421
+            cursor1.execute(sqlstr2, (tableName_utf8, list1[7], list1[5], list1[6],))
422
+            # # 获取删除的记录数量
423
+            # deleted_count = cursor1.rowcount
424
+            # 直接使用计算方式
425
+            tableName = tableName_utf8.decode('utf-8')
426
+            # 先把结果相关的点和参数删一下
427
+            sqlstr3 = """DELETE FROM GS_Result_Point  WHERE TableName = ?"""
428
+            cursor1.execute(sqlstr3, (tableName_utf8,))
429
+            sqlstr4 = """DELETE FROM GS_Trans_Point  WHERE TableName = ?"""
430
+            cursor1.execute(sqlstr4, (tableName_utf8,))
431
+            sqlstr5 = """DELETE FROM GS_Trans_Param  WHERE TableName = ?"""
432
+            cursor1.execute(sqlstr5, (tableName_utf8,))
433
+            # 提交事务
434
+            db1.commit()
435
+            # 关闭db
436
+            db1.close()
437
+            GScompute.main_function(tableName, dbPath)
438
+            GSshow.main_function(self.ui, dbPath, tableName_utf8)
439
+        else:
440
+            # 平面控制网稳定性计算
441
+            sqlstr1 = """SELECT * FROM WD_Input_Point WHERE TableName = ? LIMIT 1 OFFSET ?"""
442
+            cursor1.execute(sqlstr1, (tableName_utf8, row,))
443
+            result1 = cursor1.fetchall()
444
+            list1 = result1[0]
445
+            # 100%准确查询
446
+            # sqlstr3 = """SELECT * FROM GC_Input_Point  WHERE TableName = ? and New_SPName = ? and New_EPName = ? and New_HDiff = ? and New_RLen = ?"""
447
+            # cursor1.execute(sqlstr3, (tableName_utf8, list1[7], list1[8], list1[11], list1[12],))
448
+            # result3 = cursor1.fetchall()
449
+            sqlstr2 = """DELETE FROM WD_Input_Point  WHERE TableName = ? and PointName = ? and New_X = ? and New_Y = ?"""
450
+            cursor1.execute(sqlstr2, (tableName_utf8, list1[11], list1[8], list1[9],))
451
+            # # 获取删除的记录数量
452
+            # deleted_count = cursor1.rowcount
453
+            # 直接使用计算方式
454
+            tableName = tableName_utf8.decode('utf-8')
455
+            # 先把结果相关的点和参数删一下
456
+            sqlstr3 = """DELETE FROM WD_Result_Point  WHERE TableName = ?"""
457
+            cursor1.execute(sqlstr3, (tableName_utf8,))
458
+            sqlstr4 = """DELETE FROM WD_Result_Param  WHERE TableName = ?"""
459
+            cursor1.execute(sqlstr4, (tableName_utf8,))
460
+            # 提交事务
461
+            db1.commit()
462
+            # 关闭db
463
+            db1.close()
464
+            WDcompute.main_function(tableName, dbPath)
465
+            WDshow.main_function(self.ui, dbPath, tableName_utf8)
380 466
     # END - GUI DEFINITIONS

Загрузка…
Отмена
Сохранить