Просмотр исходного кода

20241231 除高差编辑会报错,其他数据编辑已实现

rmy 3 месяцев назад
Родитель
Сommit
2c84cd6788
4 измененных файлов: 268 добавлений и 5 удалений
  1. 51
    0
      Back/GC/GC.py
  2. 56
    5
      Front/main.py
  3. 153
    0
      Front/modules/ui_functions.py
  4. 8
    0
      Front/modules/ui_main.py

+ 51
- 0
Back/GC/GC.py Просмотреть файл

@@ -189,6 +189,57 @@ def insert_data_into_database(data, file_name, cell_values, db_path, file_name_u
189 189
     finally:
190 190
         conn.close()
191 191
 
192
+# 读取指定单元格的数据(编辑)
193
+def read_cells_from_excel1(list1):
194
+    cell_values = {}
195
+    cell_values['D1'] = list1[0][1]
196
+    cell_values['C1'] = list1[0][11]
197
+    cell_values['I1'] = list1[0][6]
198
+    return cell_values
199
+
200
+#获取最后一行有数字的单元格值(编辑)
201
+def get_last_numeric_cell_value1(list1,index):
202
+    ii = 0
203
+    while ii < len(list1):
204
+        if list1[ii][index] == '' or list1[ii][index] == ' ' or list1[ii][index] == None:
205
+            ii = ii + 1
206
+            break
207
+        else:
208
+            ii = ii + 1
209
+    return ii
210
+
211
+# 计算指定列中数值型数据的总和(编辑)
212
+def calculate_column_sum1(list1,index):
213
+    sum = 0
214
+    for li in list1:
215
+        if li[index] == '' or li[index] == ' ' or li[index] == None:
216
+            break
217
+        else:
218
+            sum = sum + float(li[index])
219
+    return sum
220
+
221
+# 遍历获取序号的数据(修改数据)
222
+def get_data_from_excel1(list1):
223
+    data = []
224
+    for row in range(len(list1)):
225
+        a_value = list1[row][0]
226
+        b_value = list1[row][2]
227
+        c_value = list1[row][3]
228
+        try:
229
+            d_value = float(list1[row][4])
230
+            e_value = float(list1[row][5])
231
+        except:
232
+            d_value = ''
233
+            e_value = ''
234
+        f_value = list1[row][0]
235
+        g_value = list1[row][7]
236
+        h_value = list1[row][8]
237
+        i_value = float(list1[row][9])
238
+        j_value = float(list1[row][10])
239
+        if a_value is not None or f_value is not None:
240
+            data.append((a_value, b_value, c_value, d_value, e_value, f_value, g_value, h_value, i_value, j_value))
241
+    return data
242
+
192 243
 
193 244
 # 主函数 读取excel文件
194 245
 def main_function(file_path, db_path):

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

@@ -630,7 +630,7 @@ class MainWindow(QMainWindow):
630 630
         action_1.triggered.connect(self.del_Dataclicked)
631 631
         menu.addAction(action_1)
632 632
         action_2 = QAction("编辑单元格", self)
633
-        action_2.triggered.connect(self.del_Dataclicked)
633
+        action_2.triggered.connect(self.edit_dataclicked)
634 634
         menu.addAction(action_2)
635 635
         action_3 = QAction("添加数据", self)
636 636
         action_3.triggered.connect(self.add_Dataclicked)
@@ -1006,6 +1006,8 @@ class MainWindow(QMainWindow):
1006 1006
                 # 模拟 search 按钮点击事件
1007 1007
                 self.ui.search.click()
1008 1008
             #用于编辑完成操作
1009
+            else:
1010
+                self.update_dataclicked()
1009 1011
         else:
1010 1012
             # 调用默认的 keyPressEvent 处理其他按键事件
1011 1013
             super(widgets.datainfo.__class__, widgets.datainfo).keyPressEvent(event)
@@ -1044,16 +1046,65 @@ class MainWindow(QMainWindow):
1044 1046
         # 关联自定义的右键菜单方法到customContextMenuRequested信号
1045 1047
         self.ui.resultTableView1.customContextMenuRequested.connect(self.show_custom_context_menu)
1046 1048
 
1047
-    def test(self):
1048
-        print('1')
1049
+    def update_dataclicked(self):
1050
+        inputmodel = self.ui.resultTableView1.model()
1051
+        #转化为list
1052
+        list1 = []
1053
+        ii = 0
1054
+        while ii < inputmodel.rowCount():
1055
+            list2 = []
1056
+            jj = 0
1057
+            while jj < inputmodel.columnCount():
1058
+                index1 = inputmodel.index(ii,jj)
1059
+                list2.append(inputmodel.data(index1))
1060
+                jj = jj + 1
1061
+            list1.append(list2)
1062
+            ii = ii + 1
1063
+        #读取对应的db和方法
1064
+        select_item = self.ui.allTreeWidget.currentItem()
1065
+        if select_item == None:
1066
+            select_item = self.ui.qureyTreeWidget.currentItem()
1067
+        # 获取数据库路径和表名
1068
+        tablename = select_item.text(0)
1069
+        tablename_utf8 = tablename.encode('utf-8')
1070
+        # 获取父节点
1071
+        parent_item = select_item.parent()
1072
+        parent_name = parent_item.text(0)
1073
+        dbname = parent_item.parent().text(0)
1074
+        dbpath = os.path.join(os.path.abspath('../SQL'), f"{dbname}.db")
1075
+        # 重新组织表的内容,方便重新计算
1076
+        UIFunctions.update_to_db(self, list1, parent_name, tablename_utf8, dbpath)
1077
+        # 1秒后自动跳转
1078
+        QTimer.singleShot(1000, lambda: self.simulateButtonClick("btn_new"))
1079
+        # 刷新树和tableview
1080
+        self.refresh_tree()
1081
+
1082
+        # 数据库路径,哪种方法,表名
1083
+        self.selectModel = UIFunctions.search_data_to_show(self, dbpath, parent_name, tablename)
1084
+        # self.ui.resultTableView1.doubleClicked.connect(self.seleceModel_itemclicked)
1085
+
1086
+        # 设置右键菜单策略为CustomContextMenu
1087
+        self.ui.resultTableView1.setContextMenuPolicy(Qt.CustomContextMenu)
1088
+
1089
+        # 关联自定义的右键菜单方法到customContextMenuRequested信号
1090
+        self.ui.resultTableView1.customContextMenuRequested.connect(self.show_custom_context_menu)
1091
+
1092
+        #把编辑状态改回去
1093
+        self.ui.resultTableView1.setEditTriggers(QTableView.EditTrigger.NoEditTriggers)
1094
+
1095
+    def edit_dataclicked(self):
1096
+        # 所有条件都可以开启编辑
1097
+        self.ui.resultTableView1.setEditTriggers(QTableView.EditTrigger.AllEditTriggers)
1049 1098
 
1050 1099
     def add_Dataclicked(self):
1051
-        #获取显示用的model
1100
+        # 获取显示用的model
1052 1101
         inputmodel = self.ui.resultTableView1.model()
1053 1102
         rowcount = inputmodel.rowCount()
1054 1103
         colcount = inputmodel.columnCount()
1055
-        #添加一行
1104
+        # 添加一行
1056 1105
         self.ui.resultTableView1.model().insertRow(rowcount)
1106
+        # 所有条件都可以开启编辑
1107
+        self.ui.resultTableView1.setEditTriggers(QTableView.EditTrigger.AllEditTriggers)
1057 1108
 
1058 1109
 
1059 1110
 

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

@@ -463,4 +463,157 @@ class UIFunctions(MainWindow):
463 463
             db1.close()
464 464
             WDcompute.main_function(tableName, dbPath)
465 465
             WDshow.main_function(self.ui, dbPath, tableName_utf8)
466
+
467
+    #编辑完后的数据更新
468
+    #输入模型,方法,表名utf8,数据库
469
+    def update_to_db(self,model1,methodName, tableName_utf8, dbPath):
470
+        db1 = sqlite3.connect(dbPath)
471
+        cursor1 = db1.cursor()
472
+        # 通过行锁定对应的字段
473
+        if methodName == '水准测段高差稳定计算':
474
+            #读取有用的数据,按格式录入
475
+            data = GC.get_data_from_excel1(model1)
476
+            cell_values = GC.read_cells_from_excel1(model1)
477
+            ms_station = float(model1[0][12])
478
+            last_station_count = GC.get_last_numeric_cell_value1(model1, 2)
479
+            new_station_count = GC.get_last_numeric_cell_value1(model1, 7)
480
+            last_sum_hdiff = GC.calculate_column_sum1(model1, 4)
481
+            last_sum_rlen = GC.calculate_column_sum1(model1, 5)
482
+            new_sum_hdiff = GC.calculate_column_sum1(model1, 9)
483
+            new_sum_rlen = GC.calculate_column_sum1(model1, 10)
484
+            # 把所有相关的表都删除
485
+            sqlstr1 = """DELETE FROM GC_Input_Point WHERE TableName = ? """
486
+            cursor1.execute(sqlstr1, (tableName_utf8,))
487
+            sqlstr2 = """DELETE FROM GC_Input_Param WHERE TableName = ? """
488
+            cursor1.execute(sqlstr2, (tableName_utf8,))
489
+
490
+            # 先把结果相关的点和参数删一下
491
+            sqlstr3 = """DELETE FROM GC_Output_Point  WHERE TableName = ?"""
492
+            cursor1.execute(sqlstr3, (tableName_utf8,))
493
+            # 提交事务
494
+            db1.commit()
495
+            # 关闭db
496
+            db1.close()
497
+            # 直接使用计算方式
498
+            tableName = tableName_utf8.decode('utf-8')
499
+            # 重新更新数据库
500
+            GC.insert_into_database(tableName, cell_values, ms_station, last_station_count, new_station_count,
501
+                                 last_sum_hdiff,
502
+                                 new_sum_hdiff, last_sum_rlen, new_sum_rlen, dbPath, tableName_utf8)
503
+            GC.insert_data_into_database(data, tableName, cell_values, dbPath, tableName_utf8)
504
+            GCcompute.main_function(tableName, dbPath)
505
+            GCshow.main_function(self.ui, dbPath, tableName_utf8)
506
+        elif methodName == '控制网复测平面基准计算':
507
+            #读取模型
508
+            ii = 0
509
+            pastname = model1[0][6]
510
+            newname = model1[0][7]
511
+            pjbc = float(model1[0][8])
512
+            fxzwc = float(model1[0][9])
513
+            zrbzwc = float(model1[0][10])
514
+            points = len(model1)
515
+            zbs = float(model1[0][11])
516
+            zfxs = float(model1[0][12])
517
+            sf = float(model1[0][13])
518
+            pjbcs = zbs / points
519
+            pjfxs = zfxs / points
520
+            listname1 = []
521
+            listpastx1 = []
522
+            listpasty1 = []
523
+            listcgcs1 = []
524
+            listnewx1 = []
525
+            listnewy1 = []
526
+            while ii < len(model1):
527
+                if model1[ii][0] == '' or model1[ii][0] == None:
528
+                    ii = ii + 1
529
+                else:
530
+                    listname1.append(model1[ii][0])
531
+                    listpastx1.append(model1[ii][1])
532
+                    listpasty1.append(model1[ii][2])
533
+                    listnewx1.append(model1[ii][3])
534
+                    listnewy1.append(model1[ii][4])
535
+                    listcgcs1.append(model1[ii][5])
536
+                    ii = ii + 1
537
+
538
+            #把所有相关的表都删除
539
+            sqlstr1 = """DELETE FROM GS_Input_Point WHERE TableName = ? """
540
+            cursor1.execute(sqlstr1, (tableName_utf8, ))
541
+            sqlstr2 = """DELETE FROM GS_Input_Param WHERE TableName = ? """
542
+            cursor1.execute(sqlstr2, (tableName_utf8,))
543
+
544
+            # 先把结果相关的点和参数删一下
545
+            sqlstr3 = """DELETE FROM GS_Result_Point  WHERE TableName = ?"""
546
+            cursor1.execute(sqlstr3, (tableName_utf8,))
547
+            sqlstr4 = """DELETE FROM GS_Trans_Point  WHERE TableName = ?"""
548
+            cursor1.execute(sqlstr4, (tableName_utf8,))
549
+            sqlstr5 = """DELETE FROM GS_Trans_Param  WHERE TableName = ?"""
550
+            cursor1.execute(sqlstr5, (tableName_utf8,))
551
+            # 提交事务
552
+            db1.commit()
553
+            # 关闭db
554
+            db1.close()
555
+            # 直接使用计算方式
556
+            tableName = tableName_utf8.decode('utf-8')
557
+            #重新更新数据库
558
+            GS.insert_into_database(dbPath, pastname, newname, tableName, listname1, listpastx1, listpasty1, listcgcs1, listnewx1,
559
+                         listnewy1, pjbc, fxzwc, zrbzwc, points, zbs, zfxs, sf, pjbcs, pjfxs)
560
+            GScompute.main_function(tableName, dbPath)
561
+            GSshow.main_function(self.ui, dbPath, tableName_utf8)
562
+        else:
563
+            # 读取模型
564
+            ii = 0
565
+            bename = model1[0][8]
566
+            pastname = model1[0][9]
567
+            newname = model1[0][10]
568
+            pjbc = float(model1[0][11])
569
+            fxzwc = float(model1[0][12])
570
+            points = len(model1)
571
+            zbs = float(model1[0][13])
572
+            zfxs = float(model1[0][14])
573
+            sf = float(model1[0][15])
574
+            pjbcs = zbs / points
575
+            pjfxs = zfxs / points
576
+            listbex1 = []
577
+            listbey1 = []
578
+            listname1 = []
579
+            listpastx1 = []
580
+            listpasty1 = []
581
+            listcgcs1 = []
582
+            listnewx1 = []
583
+            listnewy1 = []
584
+            while ii < len(model1):
585
+                if model1[ii][0] == '' or model1[ii][0] == None:
586
+                    ii = ii + 1
587
+                else:
588
+                    listname1.append(model1[ii][0])
589
+                    listbex1.append(model1[ii][1])
590
+                    listbey1.append(model1[ii][2])
591
+                    listpastx1.append(model1[ii][3])
592
+                    listpasty1.append(model1[ii][4])
593
+                    listcgcs1.append(model1[ii][5])
594
+                    listnewx1.append(model1[ii][6])
595
+                    listnewy1.append(model1[ii][7])
596
+                    ii = ii + 1
597
+            # 平面控制网稳定性计算
598
+            sqlstr1 = """DELETE FROM WD_Input_Point WHERE TableName = ?"""
599
+            cursor1.execute(sqlstr1, (tableName_utf8, ))
600
+            sqlstr2 = """DELETE FROM WD_Input_Param  WHERE TableName = ?"""
601
+            cursor1.execute(sqlstr2, (tableName_utf8,))
602
+
603
+            # 先把结果相关的点和参数删一下
604
+            sqlstr3 = """DELETE FROM WD_Result_Point  WHERE TableName = ?"""
605
+            cursor1.execute(sqlstr3, (tableName_utf8,))
606
+            sqlstr4 = """DELETE FROM WD_Result_Param  WHERE TableName = ?"""
607
+            cursor1.execute(sqlstr4, (tableName_utf8,))
608
+            # 提交事务
609
+            db1.commit()
610
+            # 关闭db
611
+            db1.close()
612
+            # 直接使用计算方式
613
+            tableName = tableName_utf8.decode('utf-8')
614
+            WD.insert_into_database(dbPath, pastname, newname, bename, tableName, listname1, listpastx1, listpasty1,
615
+                                    listcgcs1, pjbc, fxzwc, points, zbs, zfxs, sf, pjbcs, pjfxs, listbex1, listbey1,
616
+                                    listnewx1, listnewy1)
617
+            WDcompute.main_function(tableName, dbPath)
618
+            WDshow.main_function(self.ui, dbPath, tableName_utf8)
466 619
     # END - GUI DEFINITIONS

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

@@ -1763,6 +1763,14 @@ class Ui_MainWindow(object):
1763 1763
         # self.reconTableView1.setSortingEnabled(True)
1764 1764
         # self.inputTableView1.setSortingEnabled(True)
1765 1765
 
1766
+        #都不能编辑
1767
+        self.resultTableView.setEditTriggers(QTableView.EditTrigger.NoEditTriggers)
1768
+        self.resultTableView1.setEditTriggers(QTableView.EditTrigger.NoEditTriggers)
1769
+        self.reconTableView.setEditTriggers(QTableView.EditTrigger.NoEditTriggers)
1770
+        self.reconTableView1.setEditTriggers(QTableView.EditTrigger.NoEditTriggers)
1771
+        self.inputTableView1.setEditTriggers(QTableView.EditTrigger.NoEditTriggers)
1772
+
1773
+
1766 1774
         self.formLayout_3.setLayout(0, QFormLayout.FieldRole, self.verticalLayout_30)
1767 1775
 
1768 1776
         self.stackedWidget.addWidget(self.datainfo)

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