rmy 2 месяцев назад
Родитель
Сommit
1586a47abd
1 измененных файлов: 113 добавлений и 20 удалений
  1. 113
    20
      Front/main.py

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

@@ -206,7 +206,7 @@ class ElTree(QWidget):
206 206
                 elif item.parent().parent() is None:
207 207
                     # 父节点菜单
208 208
                     action1 = QAction("删除", self)
209
-                    action1.triggered.connect(lambda: self.on_parent_action(item))
209
+                    action1.triggered.connect(self.delete_js)
210 210
                     context_menu.addAction(action1)
211 211
                 else:
212 212
                     # 子节点菜单
@@ -232,12 +232,55 @@ class ElTree(QWidget):
232 232
         except:
233 233
             pass
234 234
 
235
+    def delete_js(self):
236
+        #选中当前计算
237
+        selected_items = widgets.allTreeWidget.selectedItems()
238
+        item = selected_items[0]
239
+        parent_name = item.text(0)
240
+        # 获取父节点
241
+        db_item = item.parent()
242
+        if not db_item:
243
+            QMessageBox.warning(self, '警告', '所选项目没有父节点')
244
+            return
245
+        dbname = db_item.text(0)
246
+        dbpath = os.path.join(os.path.abspath('./SQL'), f"{dbname}.db")
247
+        # 确定要清空的表
248
+        tables_to_delete = []
249
+        if parent_name == '水准测段高差稳定计算':
250
+            tables_to_delete = ['GC_Input_Param', 'GC_Input_Point', 'GC_Output_Point']
251
+        elif parent_name == '控制网复测平面基准计算':
252
+            tables_to_delete = ['GS_Input_Param', 'GS_Input_Point', 'GS_Result_Point', 'GS_Trans_Param',
253
+                                'GS_Trans_Point']
254
+        elif parent_name == '平面控制网稳定性计算':
255
+            tables_to_delete = ['WD_Input_Param', 'WD_Input_Point', 'WD_Result_Param', 'WD_Result_Point']
256
+        else:
257
+            QMessageBox.warning(self, '警告', '未知的父节点')
258
+            return
259
+        # 确认删除操作
260
+        reply = QMessageBox.question(self, '确认删除', f'确定要删除所有 {parent_name} 的计算数据吗?',
261
+                                     QMessageBox.Yes | QMessageBox.No, QMessageBox.No)
262
+        if reply == QMessageBox.No:
263
+            return
264
+            # 清空表
265
+        try:
266
+            conn = sqlite3.connect(dbpath)
267
+            cursor = conn.cursor()
268
+            for table in tables_to_delete:
269
+                cursor.execute(f"DELETE FROM {table}")
270
+            conn.commit()
271
+            conn.close()
272
+            QMessageBox.information(self, '成功', f'计算 {parent_name} 中的数据已清空')
273
+            # 刷新树状图
274
+            self.refresh_tree()
275
+        except Exception as e:
276
+            QMessageBox.critical(self, '错误', f'删除数据时出错: {str(e)}')
277
+
235 278
     def delete_db(self):
236 279
         # 获取当前选中的项目
237 280
         selected_items = widgets.allTreeWidget.selectedItems()
238 281
         item = selected_items[0]
239 282
         dbname = item.text(0)
240
-        dbpath = os.path.join(os.path.abspath('../SQL'), f"{dbname}.db")
283
+        dbpath = os.path.join(os.path.abspath('./SQL'), f"{dbname}.db")
241 284
         # 确认删除操作
242 285
         reply = QMessageBox.question(self, '确认删除', f'确定要删除项目 {dbname} 吗?',
243 286
                                      QMessageBox.Yes | QMessageBox.No, QMessageBox.No)
@@ -256,8 +299,8 @@ class ElTree(QWidget):
256 299
             QMessageBox.information(self, '成功', f'项目 {dbname} 中的数据已删除')
257 300
             # 刷新树状图
258 301
             self.refresh_tree()
259
-            # 模拟点击 Enter 键  实现程序自动刷新的效果
260
-            QTest.keyClick(widgets.allTreeWidget, Qt.Key_Return)
302
+            # # 模拟点击 Enter 键  实现程序自动刷新的效果
303
+            # QTest.keyClick(widgets.allTreeWidget, Qt.Key_Return)
261 304
         except Exception as e:
262 305
             QMessageBox.critical(self, '错误', f'删除数据时出错: {str(e)}')
263 306
 
@@ -435,7 +478,7 @@ class ElTree1(QWidget):
435 478
                 elif item.parent().parent() is None:
436 479
                     # 父节点菜单
437 480
                     action1 = QAction("删除", self)
438
-                    action1.triggered.connect(lambda: self.on_parent_action(item))
481
+                    action1.triggered.connect(self.delete_js)
439 482
                     context_menu.addAction(action1)
440 483
                 else:
441 484
                     # 子节点菜单
@@ -449,12 +492,59 @@ class ElTree1(QWidget):
449 492
         except:
450 493
             pass
451 494
 
495
+    def delete_js(self):
496
+        #选中当前计算
497
+        selected_items = widgets.qureyTreeWidget.selectedItems()
498
+        item = selected_items[0]
499
+        parent_name = item.text(0)
500
+        # 获取父节点
501
+        db_item = item.parent()
502
+        if not db_item:
503
+            QMessageBox.warning(self, '警告', '所选项目没有父节点')
504
+            return
505
+        dbname = db_item.text(0)
506
+        dbpath = os.path.join(os.path.abspath('./SQL'), f"{dbname}.db")
507
+        # 确定要清空的表
508
+        tables_to_delete = []
509
+        if parent_name == '水准测段高差稳定计算':
510
+            tables_to_delete = ['GC_Input_Param', 'GC_Input_Point', 'GC_Output_Point']
511
+        elif parent_name == '控制网复测平面基准计算':
512
+            tables_to_delete = ['GS_Input_Param', 'GS_Input_Point', 'GS_Result_Point', 'GS_Trans_Param',
513
+                                'GS_Trans_Point']
514
+        elif parent_name == '平面控制网稳定性计算':
515
+            tables_to_delete = ['WD_Input_Param', 'WD_Input_Point', 'WD_Result_Param', 'WD_Result_Point']
516
+        else:
517
+            QMessageBox.warning(self, '警告', '未知的父节点')
518
+            return
519
+        # 确认删除操作
520
+        reply = QMessageBox.question(self, '确认删除', f'确定要删除所有 {parent_name} 的计算数据吗?',
521
+                                     QMessageBox.Yes | QMessageBox.No, QMessageBox.No)
522
+        if reply == QMessageBox.No:
523
+            return
524
+            # 清空表
525
+        try:
526
+            conn = sqlite3.connect(dbpath)
527
+            cursor = conn.cursor()
528
+            for table in tables_to_delete:
529
+                cursor.execute(f"DELETE FROM {table}")
530
+            conn.commit()
531
+            conn.close()
532
+            QMessageBox.information(self, '成功', f'计算 {parent_name} 中的数据已清空')
533
+            # 清空树状图
534
+            widgets.qureyTreeWidget.clear()
535
+            # 刷新树状图
536
+            self.refresh_tree()
537
+            # 模拟点击 Enter 键  实现程序自动刷新的效果
538
+            QTest.keyClick(widgets.qureyTreeWidget, Qt.Key_Return)
539
+        except Exception as e:
540
+            QMessageBox.critical(self, '错误', f'删除数据时出错: {str(e)}')
541
+
452 542
     def delete_db(self):
453 543
         # 获取当前选中的项目
454 544
         selected_items = widgets.qureyTreeWidget.selectedItems()
455 545
         item = selected_items[0]
456 546
         dbname = item.text(0)
457
-        dbpath = os.path.join(os.path.abspath('../SQL'), f"{dbname}.db")
547
+        dbpath = os.path.join(os.path.abspath('./SQL'), f"{dbname}.db")
458 548
         # 确认删除操作
459 549
         reply = QMessageBox.question(self, '确认删除', f'确定要删除项目 {dbname} 吗?',
460 550
                                      QMessageBox.Yes | QMessageBox.No, QMessageBox.No)
@@ -475,8 +565,8 @@ class ElTree1(QWidget):
475 565
             # 清空树状图
476 566
             widgets.qureyTreeWidget.clear()
477 567
             self.refresh_tree()
478
-            # 模拟点击 Enter 键  实现程序自动刷新的效果
479
-            QTest.keyClick(widgets.qureyTreeWidget, Qt.Key_Return)
568
+            # # 模拟点击 Enter 键  实现程序自动刷新的效果
569
+            # QTest.keyClick(widgets.qureyTreeWidget, Qt.Key_Return)
480 570
         except Exception as e:
481 571
             QMessageBox.critical(self, '错误', f'删除数据时出错: {str(e)}')
482 572
 
@@ -927,18 +1017,6 @@ class MainWindow(QMainWindow):
927 1017
                 pid = id
928 1018
                 id = id + 1
929 1019
                 # 三种方法
930
-                sqlitem.append(TreeWidgetItem(id, pid, '水准测段高差稳定计算', icon=QIcon(
931
-                    os.path.join(self.absPath, "images/icons/cil-description.png"))))
932
-                gcid = id
933
-                id = id + 1
934
-                sqlitem.append(TreeWidgetItem(id, pid, '控制网复测平面基准计算', icon=QIcon(
935
-                    os.path.join(self.absPath, "images/icons/cil-description.png"))))
936
-                gsid = id
937
-                id = id + 1
938
-                sqlitem.append(TreeWidgetItem(id, pid, '平面控制网稳定性计算', icon=QIcon(
939
-                    os.path.join(self.absPath, "images/icons/cil-description.png"))))
940
-                wdid = id
941
-                id = id + 1
942 1020
                 # 读取所有的表名(三种方式往下)
943 1021
                 db1 = sqlite3.connect(dbpath)
944 1022
                 # 获取游标
@@ -946,6 +1024,11 @@ class MainWindow(QMainWindow):
946 1024
                 sqlstr1 = 'SELECT TableName FROM GC_Input_Param;'
947 1025
                 cursor1.execute(sqlstr1)
948 1026
                 result1 = cursor1.fetchall()
1027
+                if len(result1) != 0:
1028
+                    sqlitem.append(TreeWidgetItem(id, pid, '水准测段高差稳定计算', icon=QIcon(
1029
+                        os.path.join(self.absPath, "images/icons/cil-description.png"))))
1030
+                    gcid = id
1031
+                    id = id + 1
949 1032
                 for re1 in result1:
950 1033
                     str1 = re1[0].decode('utf-8')
951 1034
                     list1 = []
@@ -959,6 +1042,11 @@ class MainWindow(QMainWindow):
959 1042
                 sqlstr2 = 'SELECT TableName FROM GS_Input_Param;'
960 1043
                 cursor1.execute(sqlstr2)
961 1044
                 result2 = cursor1.fetchall()
1045
+                if len(result2) != 0:
1046
+                    sqlitem.append(TreeWidgetItem(id, pid, '控制网复测平面基准计算', icon=QIcon(
1047
+                        os.path.join(self.absPath, "images/icons/cil-description.png"))))
1048
+                    gsid = id
1049
+                    id = id + 1
962 1050
                 for re2 in result2:
963 1051
                     str2 = re2[0].decode('utf-8')
964 1052
                     list2 = []
@@ -973,6 +1061,11 @@ class MainWindow(QMainWindow):
973 1061
                 sqlstr3 = 'SELECT TableName FROM WD_Input_Param;'
974 1062
                 cursor1.execute(sqlstr3)
975 1063
                 result3 = cursor1.fetchall()
1064
+                if len(result3) != 0:
1065
+                    sqlitem.append(TreeWidgetItem(id, pid, '平面控制网稳定性计算', icon=QIcon(
1066
+                        os.path.join(self.absPath, "images/icons/cil-description.png"))))
1067
+                    wdid = id
1068
+                    id = id + 1
976 1069
                 for re3 in result3:
977 1070
                     str3 = re3[0].decode('utf-8')
978 1071
                     list3 = []

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