Przeglądaj źródła

完善了WD的计算和展示,GC的导出为excel文件,修复了未填写项目名直接点击新建没有弹窗提示的bug

wzp 5 miesięcy temu
rodzic
commit
83c1a156cb

+ 115
- 0
Back/GC/GCExport.py Wyświetl plik

1
+import time
2
+import pandas as pd
3
+import sqlite3
4
+import os
5
+from PySide6.QtWidgets import QMessageBox
6
+from openpyxl.styles import Font, NamedStyle
7
+from openpyxl.utils.dataframe import dataframe_to_rows
8
+
9
+
10
+def main_function(ui, file_path, utf_en, db_path):
11
+    export_folder = os.path.dirname(file_path)
12
+    if not os.path.exists(export_folder):
13
+        os.makedirs(export_folder)
14
+
15
+    # 连接数据库
16
+    conn = sqlite3.connect(db_path)
17
+
18
+    try:
19
+        # 查询数据库表为DataFrame,添加 TableName 条件
20
+        query = "SELECT * FROM GC_Output_Point WHERE TableName=?"
21
+        df = pd.read_sql_query(query, conn, params=(utf_en,))
22
+
23
+        # 检查是否有匹配的数据
24
+        if df.empty:
25
+            QMessageBox.warning(ui, '警告', '没有找到匹配的数据进行导出')
26
+            conn.close()
27
+            return
28
+
29
+        # 假设 TableName 字段是以字节序列存储的 UTF-8 编码字符串
30
+        if 'TableName' in df.columns:
31
+            try:
32
+                df['TableName'] = df['TableName'].apply(lambda x: x.decode('utf-8') if isinstance(x, bytes) else x)
33
+            except Exception as e:
34
+                QMessageBox.critical(ui, '错误', f'TableName 字段解码失败: {str(e)}')
35
+                conn.close()
36
+                return
37
+
38
+        # new HDiff 保留小数点后6位
39
+        if 'New_HDiff' in df.columns:
40
+            df['New_HDiff'] = df['New_HDiff'].round(6)
41
+        # New_RLen 保留小数点后6位
42
+        if 'New_RLen' in df.columns:
43
+            df['New_RLen'] = df['New_RLen'].round(6)
44
+        # Correct_Factor 保留小数点后2位
45
+        if 'Correct_Factor' in df.columns:
46
+            df['Correct_Factor'] = df['Correct_Factor'].round(2)
47
+        # Period_Diff 保留小数点后2位
48
+        if 'Period_Diff' in df.columns:
49
+            df['Period_Diff'] = df['Period_Diff'].round(2)
50
+
51
+        # 重命名指定的列
52
+        column_mapping = {
53
+            'TableName': '文件名',
54
+            'New_ID': '序号',
55
+            'New_ResultName': '结果期数',
56
+            'New_SPName': '起点',
57
+            'New_EPName': '终点',
58
+            'New_HDiff': '高差',
59
+            'New_RLen': '路线长',
60
+            'Correct_Factor': '修正数',
61
+            'Period_Diff': '期间差异',
62
+            'Dis_Ass': '变形判定'
63
+        }
64
+        df.rename(columns=column_mapping, inplace=True)
65
+
66
+        # 创建一个新的 Excel 工作簿
67
+        from openpyxl import Workbook
68
+        wb = Workbook()
69
+        ws = wb.active
70
+
71
+        # 将 DataFrame 写入工作表
72
+        for r in dataframe_to_rows(df, index=False, header=True):
73
+            ws.append(r)
74
+
75
+        # 定义自定义样式
76
+        style_0_000000 = NamedStyle(name="style_0_000000", number_format='0.000000')
77
+        style_0_00 = NamedStyle(name="style_0_00", number_format='0.00')
78
+
79
+        # 添加样式到工作簿
80
+        wb.add_named_style(style_0_000000)
81
+        wb.add_named_style(style_0_00)
82
+
83
+        # 应用样式到相应列
84
+        hdiff_col_index = df.columns.get_loc('高差') + 1  # 获取“高差”列的索引(+1 因为 Excel 列索引从 1 开始)
85
+        rlen_col_index = df.columns.get_loc('路线长') + 1  # 获取“路线长”列的索引
86
+        correct_factor_col_index = df.columns.get_loc('修正数') + 1  # 获取“修正数”列的索引
87
+        period_diff_col_index = df.columns.get_loc('期间差异') + 1  # 获取“期间差异”列的索引
88
+
89
+        for row in range(2, ws.max_row + 1):  # 从第二行开始,因为第一行为标题行
90
+            ws.cell(row=row, column=hdiff_col_index).style = style_0_000000
91
+            ws.cell(row=row, column=rlen_col_index).style = style_0_000000
92
+            ws.cell(row=row, column=correct_factor_col_index).style = style_0_00
93
+            ws.cell(row=row, column=period_diff_col_index).style = style_0_00
94
+
95
+        # 设置 Dis_Ass 列为“变形”的行的字体颜色为红色
96
+        red_font = Font(color="FF0000")
97
+        dis_ass_col_index = df.columns.get_loc('变形判定') + 1  # 获取“变形判定”列的索引
98
+
99
+        for row in range(2, ws.max_row + 1):  # 从第二行开始,因为第一行为标题行
100
+            cell_value = ws.cell(row=row, column=dis_ass_col_index).value
101
+            if cell_value == '变形':
102
+                for col in range(1, ws.max_column + 1):
103
+                    ws.cell(row=row, column=col).font = red_font
104
+
105
+        # 保存 Excel 文件
106
+        excel_filename = f"水准测段高差计算成果表{time.strftime('%Y%m%d_%H%M%S')}.xlsx"
107
+        excel_filepath = os.path.join(export_folder, excel_filename)
108
+        wb.save(excel_filepath)
109
+
110
+        QMessageBox.information(ui, '成功', f'数据库已成功导出到 {excel_filepath}')
111
+    except Exception as e:
112
+        QMessageBox.critical(ui, '错误', f'导出过程中发生错误: {str(e)}')
113
+    finally:
114
+        # 关闭数据库连接
115
+        conn.close()

+ 6
- 6
Back/Program_Run/database_operations.py Wyświetl plik

4
 from PySide6.QtWidgets import QMessageBox
4
 from PySide6.QtWidgets import QMessageBox
5
 
5
 
6
 
6
 
7
-def create_database_and_tables(self):
8
-    db_name = self.lineEdit.text().strip()
7
+def create_database_and_tables(main_window,ui):
8
+    db_name = main_window.ui.lineEdit.text().strip()
9
 
9
 
10
     if not db_name:
10
     if not db_name:
11
-        QMessageBox.warning(self, "警告", "请输入数据库名称")
11
+        QMessageBox.warning(main_window, "警告", "请输入数据库名称")
12
         return
12
         return
13
     # 转换为UTF-8编码
13
     # 转换为UTF-8编码
14
     # db_name_utf8 = db_name.encode('utf-8')
14
     # db_name_utf8 = db_name.encode('utf-8')
28
     # 读取现有的数据库结构
28
     # 读取现有的数据库结构
29
     existing_db_path = os.path.join(sql_folder, 'DataBase.db')
29
     existing_db_path = os.path.join(sql_folder, 'DataBase.db')
30
     if not os.path.exists(existing_db_path):
30
     if not os.path.exists(existing_db_path):
31
-        QMessageBox.critical(self.main_window, "错误", "找不到现有的数据库结构文件 DataBase.db")
31
+        QMessageBox.critical(main_window.main_window, "错误", "找不到现有的数据库结构文件 DataBase.db")
32
         return
32
         return
33
     try:
33
     try:
34
         # 连接到现有的数据库以获取表结构
34
         # 连接到现有的数据库以获取表结构
49
 
49
 
50
                 new_conn.commit()
50
                 new_conn.commit()
51
 
51
 
52
-        QMessageBox.information(self.main_window, "成功", f"项目{db_name}已成功创建")
52
+        QMessageBox.information(main_window, "成功", f"项目{db_name}已成功创建")
53
     except Exception as e:
53
     except Exception as e:
54
-        QMessageBox.critical(self.main_window, "错误", f"创建项目时出错: {str(e)}")
54
+        QMessageBox.critical(main_window, "错误", f"创建项目时出错: {str(e)}")

+ 51
- 39
Back/WD/WD.py Wyświetl plik

2
 import xlrd
2
 import xlrd
3
 import sqlite3
3
 import sqlite3
4
 import os
4
 import os
5
+
6
+from PySide6.QtWidgets import QMessageBox
5
 from openpyxl import Workbook
7
 from openpyxl import Workbook
6
 import tkinter as tk
8
 import tkinter as tk
7
 from tkinter import messagebox
9
 from tkinter import messagebox
8
 import math
10
 import math
9
 import numpy as np
11
 import numpy as np
10
 
12
 
13
+
11
 def to_utf8(text):
14
 def to_utf8(text):
12
     str1 = text.encode('utf-8')
15
     str1 = text.encode('utf-8')
13
     return str1
16
     return str1
14
 
17
 
18
+
15
 # 弹窗提示用户是否更新数据
19
 # 弹窗提示用户是否更新数据
16
 def ask_for_update(file_name):
20
 def ask_for_update(file_name):
17
-    root = tk.Tk()
18
-    root.withdraw()  # 隐藏主窗口
19
-    response = messagebox.askyesno("提示", f"检测到数据库中存在相同文件名 '{file_name}',是否更新数据?")
20
-    return response
21
+    response = QMessageBox.question(None, "提示", f"检测到数据库中存在相同文件 '{file_name}',是(Yes)否(No)更新数据?",
22
+                                    QMessageBox.Yes | QMessageBox.No)
23
+    return response == QMessageBox.Yes
24
+
21
 
25
 
22
 # 读取Excel文件并计算公式结果
26
 # 读取Excel文件并计算公式结果
23
-def load_and_calculate_excel(file_path,cell0):
27
+def load_and_calculate_excel(file_path, cell0):
24
     # 加载Excel文件并计算单元格的公式结果。
28
     # 加载Excel文件并计算单元格的公式结果。
25
     workbook = openpyxl.load_workbook(file_path, data_only=True)
29
     workbook = openpyxl.load_workbook(file_path, data_only=True)
26
     sheet = workbook.active
30
     sheet = workbook.active
27
     h1_value = sheet[cell0].value
31
     h1_value = sheet[cell0].value
28
     return h1_value
32
     return h1_value
29
 
33
 
34
+
30
 # 数据库插入函数
35
 # 数据库插入函数
31
-def insert_into_database(database,pastname,newname,beforename,excelname,listname1,listpastx1,listpasty1,listcgcs1,pjbc,fxzwc,points,zbs,zfxs,sf,pjbcs,pjfxs,listbex,listbey,listnewx,listnewy):
32
-    #先把输入的录入数据库
36
+def insert_into_database(database, pastname, newname, beforename, excelname, listname1, listpastx1, listpasty1,
37
+                         listcgcs1, pjbc, fxzwc, points, zbs, zfxs, sf, pjbcs, pjfxs, listbex, listbey, listnewx,
38
+                         listnewy):
39
+    # 先把输入的录入数据库
33
     db = sqlite3.connect(database)
40
     db = sqlite3.connect(database)
34
-    #获取游标
41
+    # 获取游标
35
     cursor = db.cursor()
42
     cursor = db.cursor()
36
-    #字符类的都需要转换成字节存进去
43
+    # 字符类的都需要转换成字节存进去
37
     utf_pan = to_utf8(pastname)
44
     utf_pan = to_utf8(pastname)
38
     utf_nn = to_utf8(newname)
45
     utf_nn = to_utf8(newname)
39
     utf_bn = to_utf8(beforename)
46
     utf_bn = to_utf8(beforename)
59
                 SET First_ResultName = ?,Last_ResultName=?,New_ResultName=?,Avg_SL=?,Ms_Dir=?,Pt_Count=?,SL_Count=?,Dir_Count=?,Scale_Value=?,Avg_MSL=?,Avg_Dir=?
66
                 SET First_ResultName = ?,Last_ResultName=?,New_ResultName=?,Avg_SL=?,Ms_Dir=?,Pt_Count=?,SL_Count=?,Dir_Count=?,Scale_Value=?,Avg_MSL=?,Avg_Dir=?
60
                 WHERE TableName = ?
67
                 WHERE TableName = ?
61
                 """,
68
                 """,
62
-                (utf_bn,utf_pan,utf_nn,pjbc,fxzwc,points,zbs,zfxs,sf,pjbcs,pjfxs,utf_tn,)
69
+                (utf_bn, utf_pan, utf_nn, pjbc, fxzwc, points, zbs, zfxs, sf, pjbcs, pjfxs, utf_tn,)
63
             )
70
             )
64
             # 更新现有记录WD_Input_Point 
71
             # 更新现有记录WD_Input_Point 
65
-            #删了已有的数据,重新插入
72
+            # 删了已有的数据,重新插入
66
             cursor.execute(
73
             cursor.execute(
67
                 """
74
                 """
68
                 DELETE FROM WD_Input_Point WHERE TableName = ?
75
                 DELETE FROM WD_Input_Point WHERE TableName = ?
84
                     """
91
                     """
85
                     INSERT INTO WD_Input_Point(TableName,First_ResultName,Last_ResultName,New_ResultName,Last_X,Last_Y,New_X,New_Y,PointName,Wight,First_X,First_Y) VALUES (?,?,?,?,?,?,?,?,?,?,?,?)
92
                     INSERT INTO WD_Input_Point(TableName,First_ResultName,Last_ResultName,New_ResultName,Last_X,Last_Y,New_X,New_Y,PointName,Wight,First_X,First_Y) VALUES (?,?,?,?,?,?,?,?,?,?,?,?)
86
                     """,
93
                     """,
87
-                    (utf_tn,utf_bn,utf_pan,utf_nn,rr2,rr3,rr5,rr6,utf_rr1,rr4,rr7,rr8,)
94
+                    (utf_tn, utf_bn, utf_pan, utf_nn, rr2, rr3, rr5, rr6, utf_rr1, rr4, rr7, rr8,)
88
                 )
95
                 )
89
                 rr = rr + 1
96
                 rr = rr + 1
90
-            messagebox.showinfo("提示",
91
-                                f"文件 '{excelname}' 已成功更新到本地数据库中,点击确认以关闭此对话框。对话框关闭后,请点击“计算”以重新计算数据")
97
+            QMessageBox.information(None, "提示",
98
+                                    f"文件 '{excelname}' 已成功更新到本地数据库中,点击'OK'以关闭此对话框。对话框关闭后,请点击“计算”以重新计算数据")
92
         else:
99
         else:
93
             # 插入新记录WD_Input_Param 
100
             # 插入新记录WD_Input_Param 
94
             cursor.execute(
101
             cursor.execute(
96
                 INSERT INTO WD_Input_Param (TableName,First_ResultName,Last_ResultName,New_ResultName,Avg_SL,Ms_Dir,Pt_Count,SL_Count,Dir_Count,Scale_Value,Avg_MSL,Avg_Dir) 
103
                 INSERT INTO WD_Input_Param (TableName,First_ResultName,Last_ResultName,New_ResultName,Avg_SL,Ms_Dir,Pt_Count,SL_Count,Dir_Count,Scale_Value,Avg_MSL,Avg_Dir) 
97
                 VALUES (?,?,?,?,?,?,?,?,?,?,?,?)
104
                 VALUES (?,?,?,?,?,?,?,?,?,?,?,?)
98
                 """,
105
                 """,
99
-                (utf_tn,utf_bn,utf_pan,utf_nn,pjbc,fxzwc,points,zbs,zfxs,sf,pjbcs,pjfxs,)
106
+                (utf_tn, utf_bn, utf_pan, utf_nn, pjbc, fxzwc, points, zbs, zfxs, sf, pjbcs, pjfxs,)
100
             )
107
             )
101
             # 插入新记录WD_Input_Point 
108
             # 插入新记录WD_Input_Point 
102
             rr = 0
109
             rr = 0
114
                     """
121
                     """
115
                     INSERT INTO WD_Input_Point(TableName,First_ResultName,Last_ResultName,New_ResultName,Last_X,Last_Y,New_X,New_Y,PointName,Wight,First_X,First_Y) VALUES (?,?,?,?,?,?,?,?,?,?,?,?)
122
                     INSERT INTO WD_Input_Point(TableName,First_ResultName,Last_ResultName,New_ResultName,Last_X,Last_Y,New_X,New_Y,PointName,Wight,First_X,First_Y) VALUES (?,?,?,?,?,?,?,?,?,?,?,?)
116
                     """,
123
                     """,
117
-                    (utf_tn,utf_bn,utf_pan,utf_nn,rr2,rr3,rr5,rr6,utf_rr1,rr4,rr7,rr8,)
124
+                    (utf_tn, utf_bn, utf_pan, utf_nn, rr2, rr3, rr5, rr6, utf_rr1, rr4, rr7, rr8,)
118
                 )
125
                 )
119
                 rr = rr + 1
126
                 rr = rr + 1
120
-            messagebox.showinfo("提示",
121
-                                f"文件 '{excelname}' 已成功添加到本地数据库中,点击确认以关闭此对话框。对话框关闭后,请点击“计算”以计算数据")
127
+            QMessageBox.information(None, "提示",
128
+                                    f"文件 '{excelname}' 已成功添加到本地数据库中,点击'OK'以关闭此对话框。对话框关闭后,请点击“计算”以计算数据")
122
 
129
 
123
         db.commit()
130
         db.commit()
124
     except sqlite3.Error as e:
131
     except sqlite3.Error as e:
128
     finally:
135
     finally:
129
         db.close()
136
         db.close()
130
 
137
 
131
-#读取xls
132
-def xlrd_read(excelpath,dbpath):
138
+
139
+# 读取xls
140
+def xlrd_read(excelpath, dbpath):
133
     global gszbx
141
     global gszbx
134
     global gszby
142
     global gszby
135
     listname1 = []
143
     listname1 = []
136
     listpastx1 = []
144
     listpastx1 = []
137
     listpasty1 = []
145
     listpasty1 = []
138
     listcgcs1 = []
146
     listcgcs1 = []
139
-    #excel表名就是表名
147
+    # excel表名就是表名
140
     excelname = os.path.basename(excelpath)
148
     excelname = os.path.basename(excelpath)
141
     # 读取excel
149
     # 读取excel
142
     xlr = xlrd.open_workbook(excelpath)
150
     xlr = xlrd.open_workbook(excelpath)
224
         listpasty1.append(rr3)
232
         listpasty1.append(rr3)
225
         listcgcs1.append(rr4)
233
         listcgcs1.append(rr4)
226
         rr = rr + 1
234
         rr = rr + 1
227
-    #存入数据库
228
-    insert_into_database(dbpath,lastname,finalname,befname,excelname,listname1,listpastx1,listpasty1,listcgcs1,pjbc,fxzwc,points,zbs,zfxs,sf,pjbcs,pjfxs,listbex,listbey,listnewx,listnewy)
235
+    # 存入数据库
236
+    insert_into_database(dbpath, lastname, finalname, befname, excelname, listname1, listpastx1, listpasty1, listcgcs1,
237
+                         pjbc, fxzwc, points, zbs, zfxs, sf, pjbcs, pjfxs, listbex, listbey, listnewx, listnewy)
238
+
229
 
239
 
230
-#读取xlsx
231
-def openpyxl_read(excelpath,dbpath):
240
+# 读取xlsx
241
+def openpyxl_read(excelpath, dbpath):
232
     global gszbx
242
     global gszbx
233
     global gszby
243
     global gszby
234
     listname1 = []
244
     listname1 = []
236
     listpasty1 = []
246
     listpasty1 = []
237
     listcgcs1 = []
247
     listcgcs1 = []
238
 
248
 
239
-    #excel表名就是表名
249
+    # excel表名就是表名
240
     excelname = os.path.basename(excelpath)
250
     excelname = os.path.basename(excelpath)
241
     # 读取excel
251
     # 读取excel
242
     xlr = openpyxl.load_workbook(excelpath)
252
     xlr = openpyxl.load_workbook(excelpath)
254
     listpastx = []
264
     listpastx = []
255
     listpasty = []
265
     listpasty = []
256
     listcgcs = []
266
     listcgcs = []
257
-    listbex=[]
258
-    listbey=[]
267
+    listbex = []
268
+    listbey = []
259
     sumnewx = 0
269
     sumnewx = 0
260
     sumnewy = 0
270
     sumnewy = 0
261
     sumpastx = 0
271
     sumpastx = 0
270
     try:
280
     try:
271
         zbs = float(tabler['J3'].value)
281
         zbs = float(tabler['J3'].value)
272
     except:
282
     except:
273
-        zbs = load_and_calculate_excel(excelpath,'J3')
283
+        zbs = load_and_calculate_excel(excelpath, 'J3')
274
     try:
284
     try:
275
         zfxs = float(tabler['J4'].value)
285
         zfxs = float(tabler['J4'].value)
276
     except:
286
     except:
277
-        zfxs = load_and_calculate_excel(excelpath,'J4')
287
+        zfxs = load_and_calculate_excel(excelpath, 'J4')
278
     pjbcs = zbs / points
288
     pjbcs = zbs / points
279
     pjfxs = zfxs / points
289
     pjfxs = zfxs / points
280
     sf = float(tabler['J5'].value)
290
     sf = float(tabler['J5'].value)
288
     wypd3 = math.sqrt(wypd1 + wypd2)
298
     wypd3 = math.sqrt(wypd1 + wypd2)
289
     wypd = round((wypd3 * 2 * math.sqrt(2)), 9)
299
     wypd = round((wypd3 * 2 * math.sqrt(2)), 9)
290
     wypd0 = wypd
300
     wypd0 = wypd
291
-    befname=tabler['G1'].value
301
+    befname = tabler['G1'].value
292
     lastname = tabler['D1'].value
302
     lastname = tabler['D1'].value
293
     finalname = tabler['B1'].value
303
     finalname = tabler['B1'].value
294
     while row <= rows:
304
     while row <= rows:
328
         listpasty1.append(rr3)
338
         listpasty1.append(rr3)
329
         listcgcs1.append(rr4)
339
         listcgcs1.append(rr4)
330
         rr = rr + 1
340
         rr = rr + 1
331
-    #存入数据库
332
-    insert_into_database(dbpath,lastname,finalname,befname,excelname,listname1,listpastx1,listpasty1,listcgcs1,pjbc,fxzwc,points,zbs,zfxs,sf,pjbcs,pjfxs,listbex,listbey,listnewx,listnewy)
341
+    # 存入数据库
342
+    insert_into_database(dbpath, lastname, finalname, befname, excelname, listname1, listpastx1, listpasty1, listcgcs1,
343
+                         pjbc, fxzwc, points, zbs, zfxs, sf, pjbcs, pjfxs, listbex, listbey, listnewx, listnewy)
344
+
333
 
345
 
334
 # 主函数 读取excel文件
346
 # 主函数 读取excel文件
335
-def main_function(file_path,dbpath):
347
+def main_function(file_path, dbpath):
336
     # 调用读取Excel文件的函数
348
     # 调用读取Excel文件的函数
337
     file_name = os.path.basename(file_path)
349
     file_name = os.path.basename(file_path)
338
-    #两种加载方式,对于不同的文件
350
+    # 两种加载方式,对于不同的文件
339
     if ".xlsx" in file_path:
351
     if ".xlsx" in file_path:
340
-        #采用openpyxl
341
-        openpyxl_read(file_path,dbpath)
352
+        # 采用openpyxl
353
+        openpyxl_read(file_path, dbpath)
342
     else:
354
     else:
343
-        #采用xlrd
344
-        xlrd_read(file_path,dbpath)
355
+        # 采用xlrd
356
+        xlrd_read(file_path, dbpath)

+ 17
- 14
Back/WD/WDExport.py Wyświetl plik

185
     wb.save(outpath)
185
     wb.save(outpath)
186
 
186
 
187
 
187
 
188
-# # 主函数 写入excel文件
189
-# def main_function(outpath,dbpath,file_path):
190
-#     dbpath = r"D:\4work_now\20240819GS\ControlNetwork\ControlNetwork\UI\SQL\DataBase.db"
191
-#     outpath = r'D:\4work_now\20240819GS\JPG\WD成果表.xlsx'
192
-#     file_path = r'D:\4work_now\20240819GS\test_wd.xls'
193
-#     file_name = os.path.basename(file_path)
194
-#     # outpath为包含输出excel名字的全路径
195
-#     openpyxl_write(outpath,dbpath,file_name)
196
-dbpath = r"D:\4work_now\20240819GS\ControlNetwork\ControlNetwork\UI\SQL\DataBase.db"
197
-outpath = r'D:\4work_now\20240819GS\JPG\WD成果表.xlsx'
198
-file_path = r'D:\4work_now\20240819GS\test_wd.xls'
199
-file_name = os.path.basename(file_path)
200
-# outpath为包含输出excel名字的全路径
201
-openpyxl_write(outpath,dbpath,file_name)
188
+# 主函数 写入excel文件
189
+def main_function(outpath,dbpath,file_path):
190
+    dbpath = r"D:\4work_now\20240819GS\ControlNetwork\ControlNetwork\UI\SQL\DataBase.db"
191
+    outpath = r'D:\4work_now\20240819GS\JPG\WD成果表.xlsx'
192
+    file_path = r'D:\4work_now\20240819GS\test_wd.xls'
193
+    file_name = os.path.basename(file_path)
194
+    # outpath为包含输出excel名字的全路径
195
+    openpyxl_write(outpath,dbpath,file_name)
196
+
197
+
198
+# dbpath = r"D:\4work_now\20240819GS\ControlNetwork\ControlNetwork\UI\SQL\DataBase.db"
199
+# # dbpath = r"D:/Code/ControlNetwork/UI/SQL/DataBase.db"
200
+# outpath = r'D:\4work_now\20240819GS\JPG\WD成果表.xlsx'
201
+# file_path = r'D:\4work_now\20240819GS\test_wd.xls'
202
+# file_name = os.path.basename(file_path)
203
+# # outpath为包含输出excel名字的全路径
204
+# openpyxl_write(outpath,dbpath,file_name)

+ 142
- 108
Back/WD/WDcompute.py Wyświetl plik

10
 from tkinter import messagebox
10
 from tkinter import messagebox
11
 from tkinter import *
11
 from tkinter import *
12
 
12
 
13
-#region 各种方法
13
+from PySide6.QtWidgets import QMessageBox
14
+
15
+
16
+# region 各种方法
14
 def to_utf8(text):
17
 def to_utf8(text):
15
     str1 = text.encode('utf-8')
18
     str1 = text.encode('utf-8')
16
     return str1
19
     return str1
17
 
20
 
21
+
18
 def jzys1(listy, zxzby, listx, zxzbx, sf):
22
 def jzys1(listy, zxzby, listx, zxzbx, sf):
19
     rlist = []
23
     rlist = []
20
     listlen = len(listy)
24
     listlen = len(listy)
30
         ll = ll + 1
34
         ll = ll + 1
31
     return rlist
35
     return rlist
32
 
36
 
37
+
33
 def jzys2(listy, zxzby, listx, zxzbx, sf):
38
 def jzys2(listy, zxzby, listx, zxzbx, sf):
34
     rlist = []
39
     rlist = []
35
     listlen = len(listy)
40
     listlen = len(listy)
43
         ll = ll + 1
48
         ll = ll + 1
44
     return rlist
49
     return rlist
45
 
50
 
51
+
46
 def jzys3(listy, aa, bb):
52
 def jzys3(listy, aa, bb):
47
     rlist = []
53
     rlist = []
48
     listlen = len(listy)
54
     listlen = len(listy)
56
         ll = ll + 1
62
         ll = ll + 1
57
     return rlist
63
     return rlist
58
 
64
 
65
+
59
 def jzys4(listpasty, zxzbpasty, listpastx, zxzbpastx, listnewy, zxzbnewy, listnewx, zxzbnewx, sf):
66
 def jzys4(listpasty, zxzbpasty, listpastx, zxzbpastx, listnewy, zxzbnewy, listnewx, zxzbnewx, sf):
60
     rlist = []
67
     rlist = []
61
     listlen = len(listnewx)
68
     listlen = len(listnewx)
68
         ll = ll + 1
75
         ll = ll + 1
69
     return rlist
76
     return rlist
70
 
77
 
78
+
71
 def jzys5(listp, zxzbp, sf):
79
 def jzys5(listp, zxzbp, sf):
72
     rlist = []
80
     rlist = []
73
     listlen = len(listp)
81
     listlen = len(listp)
78
         ll = ll + 1
86
         ll = ll + 1
79
     return rlist
87
     return rlist
80
 
88
 
89
+
81
 def jzys6(listp, num):
90
 def jzys6(listp, num):
82
     rlist = []
91
     rlist = []
83
     listlen = len(listp)
92
     listlen = len(listp)
88
         ll = ll + 1
97
         ll = ll + 1
89
     return rlist
98
     return rlist
90
 
99
 
100
+
91
 def cjh(listp):
101
 def cjh(listp):
92
     rp = 0
102
     rp = 0
93
     listlen = len(listp)
103
     listlen = len(listp)
98
         ll = ll + 1
108
         ll = ll + 1
99
     return rp
109
     return rp
100
 
110
 
111
+
101
 def cjh2(lista, listb):
112
 def cjh2(lista, listb):
102
     rp = 0
113
     rp = 0
103
     listlen = len(lista)
114
     listlen = len(lista)
108
         ll = ll + 1
119
         ll = ll + 1
109
     return rp
120
     return rp
110
 
121
 
122
+
111
 def gsys(listnewp, jxlist1, jylist1, lxlist, lylist, arrz, sf, zxzbnewp, zxzbpastp, ii):
123
 def gsys(listnewp, jxlist1, jylist1, lxlist, lylist, arrz, sf, zxzbnewp, zxzbpastp, ii):
112
     # 新x+(矩阵[jx1 jy1 lx1 ly1]*矩阵z)*缩放-新重心坐标x+旧重心坐标x
124
     # 新x+(矩阵[jx1 jy1 lx1 ly1]*矩阵z)*缩放-新重心坐标x+旧重心坐标x
113
     rlist = []
125
     rlist = []
115
     ll = 0
127
     ll = 0
116
     while ll < listlen:
128
     while ll < listlen:
117
         arr0 = np.array((jxlist1[ll], jylist1[ll],
129
         arr0 = np.array((jxlist1[ll], jylist1[ll],
118
-                        lxlist[2*ll+ii], lylist[2*ll+ii]))
130
+                         lxlist[2 * ll + ii], lylist[2 * ll + ii]))
119
         arr1 = np.matmul(arr0, arrz)
131
         arr1 = np.matmul(arr0, arrz)
120
         arr3 = sf * arr1
132
         arr3 = sf * arr1
121
         newp = listnewp[ll] + arr3 - zxzbnewp + zxzbpastp
133
         newp = listnewp[ll] + arr3 - zxzbnewp + zxzbpastp
123
         ll = ll + 1
135
         ll = ll + 1
124
     return rlist
136
     return rlist
125
 
137
 
138
+
126
 def xcys(newlist, pastlist):
139
 def xcys(newlist, pastlist):
127
     listlen = len(newlist)
140
     listlen = len(newlist)
128
     ll = 0
141
     ll = 0
134
         ll = ll + 1
147
         ll = ll + 1
135
     return rlist
148
     return rlist
136
 
149
 
150
+
137
 def takeFirst(elem):
151
 def takeFirst(elem):
138
     return elem[0]
152
     return elem[0]
139
-#endregion
140
 
153
 
141
-def insert_into_database1(database,pastname,newname,beforename,excelname,listname1,listpastx1,listpasty1,listcgcs1,listbex,listbey,sxylist,wypd,gsx,gsy,listcgcs):
142
-    #转换下汉字
154
+
155
+# endregion
156
+
157
+def insert_into_database1(database, pastname, newname, beforename, excelname, listname1, listpastx1, listpasty1,
158
+                          listcgcs1, listbex, listbey, sxylist, wypd, gsx, gsy, listcgcs):
159
+    # 转换下汉字
143
     utf_tn = to_utf8(excelname)
160
     utf_tn = to_utf8(excelname)
144
     utf_nn = to_utf8(newname)
161
     utf_nn = to_utf8(newname)
145
     utf_pn = to_utf8(pastname)
162
     utf_pn = to_utf8(pastname)
146
     utf_bn = to_utf8(beforename)
163
     utf_bn = to_utf8(beforename)
147
     utf_bx = to_utf8('变形')
164
     utf_bx = to_utf8('变形')
148
     utf_wd = to_utf8('稳定')
165
     utf_wd = to_utf8('稳定')
149
-    #将结果输出到数据库
166
+    # 将结果输出到数据库
150
     db1 = sqlite3.connect(database)
167
     db1 = sqlite3.connect(database)
151
-    #获取游标
168
+    # 获取游标
152
     cursor1 = db1.cursor()
169
     cursor1 = db1.cursor()
153
-    #先清除已有数据,用来更新
170
+    # 先清除已有数据,用来更新
154
     try:
171
     try:
155
         sqlstr3 = 'delete from WD_Result_Param WHERE TableName = ?'
172
         sqlstr3 = 'delete from WD_Result_Param WHERE TableName = ?'
156
         sqlstr4 = 'delete from WD_Result_Point WHERE TableName = ?'
173
         sqlstr4 = 'delete from WD_Result_Point WHERE TableName = ?'
157
-        cursor1.execute(sqlstr3,(utf_tn,))
158
-        cursor1.execute(sqlstr4,(utf_tn,))
174
+        cursor1.execute(sqlstr3, (utf_tn,))
175
+        cursor1.execute(sqlstr4, (utf_tn,))
159
     except:
176
     except:
160
         pass
177
         pass
161
-    cursor1.execute('INSERT INTO WD_Result_Param(TableName,Last_ResultName,New_ResultName,Formula_X1,Formula_X2,Formula_X3,Formula_Y1,Formula_Y2,Formula_Y3) VALUES(?,?,?,?,?,?,?,?,?)',(utf_tn,utf_pn,utf_nn,sxylist[0],sxylist[1],sxylist[2],sxylist[3],sxylist[4],sxylist[5],))
162
-    #WD_Result_Point的输入
178
+    cursor1.execute(
179
+        'INSERT INTO WD_Result_Param(TableName,Last_ResultName,New_ResultName,Formula_X1,Formula_X2,Formula_X3,Formula_Y1,Formula_Y2,Formula_Y3) VALUES(?,?,?,?,?,?,?,?,?)',
180
+        (utf_tn, utf_pn, utf_nn, sxylist[0], sxylist[1], sxylist[2], sxylist[3], sxylist[4], sxylist[5],))
181
+    # WD_Result_Point的输入
163
     kk = -1
182
     kk = -1
164
     kk1 = -1
183
     kk1 = -1
165
     if (-1) in listcgcs:
184
     if (-1) in listcgcs:
166
         kk = 1
185
         kk = 1
167
-    #记位移点个数
186
+    # 记位移点个数
168
     wyd = 0
187
     wyd = 0
169
     for lname in listname1:
188
     for lname in listname1:
170
-        #获取对应索引号
189
+        # 获取对应索引号
171
         index1 = listname1.index(lname)
190
         index1 = listname1.index(lname)
172
         PointName = lname
191
         PointName = lname
173
         First_X = listbex[index1]
192
         First_X = listbex[index1]
176
         Last_Y = listpasty1[index1]
195
         Last_Y = listpasty1[index1]
177
         Last_Wight = listcgcs1[index1]
196
         Last_Wight = listcgcs1[index1]
178
         New_Wight = listcgcs[index1]
197
         New_Wight = listcgcs[index1]
179
-        #位移点
198
+        # 位移点
180
         if New_Wight == -1:
199
         if New_Wight == -1:
181
             # 获取他原本的坐标和初始改算值进行对比
200
             # 获取他原本的坐标和初始改算值进行对比
182
             for smx in jslist:
201
             for smx in jslist:
183
                 if First_X == smx[0] and First_Y == smx[1]:
202
                 if First_X == smx[0] and First_Y == smx[1]:
184
                     numa3 = sxylist[0] * jslist1[index1][0]
203
                     numa3 = sxylist[0] * jslist1[index1][0]
185
                     numa4 = sxylist[1] * jslist1[index1][1]
204
                     numa4 = sxylist[1] * jslist1[index1][1]
186
-                    numa5 = numa3 + numa4+ sxylist[2]
205
+                    numa5 = numa3 + numa4 + sxylist[2]
187
                     numa6 = sxylist[3] * jslist1[index1][0]
206
                     numa6 = sxylist[3] * jslist1[index1][0]
188
                     numa7 = sxylist[4] * jslist1[index1][1]
207
                     numa7 = sxylist[4] * jslist1[index1][1]
189
-                    numa8 = numa6 + numa7+sxylist[5]
208
+                    numa8 = numa6 + numa7 + sxylist[5]
190
                     Result_X = numa5
209
                     Result_X = numa5
191
                     Result_Y = numa8
210
                     Result_Y = numa8
192
                     New_Wight = 1
211
                     New_Wight = 1
193
                     numb1 = (numa5 - First_X) * 1000
212
                     numb1 = (numa5 - First_X) * 1000
194
                     numb2 = (numa8 - First_Y) * 1000
213
                     numb2 = (numa8 - First_Y) * 1000
195
-                    numb3 = numb1 *numb1
196
-                    numb4 = numb2 *numb2
214
+                    numb3 = numb1 * numb1
215
+                    numb4 = numb2 * numb2
197
                     numb5 = math.sqrt(numb3 + numb4)
216
                     numb5 = math.sqrt(numb3 + numb4)
198
                     New_FirstX = numb1
217
                     New_FirstX = numb1
199
                     New_FirstY = numb2
218
                     New_FirstY = numb2
200
                     New_FirstP = numb5
219
                     New_FirstP = numb5
201
-                    #新-首有个位移判定
220
+                    # 新-首有个位移判定
202
                     if numb5 > wypd:
221
                     if numb5 > wypd:
203
                         NFDis_Ass = utf_bx
222
                         NFDis_Ass = utf_bx
204
                     else:
223
                     else:
205
                         NFDis_Ass = utf_wd
224
                         NFDis_Ass = utf_wd
206
-                    
225
+
207
                     numc1 = (numa5 - Last_X) * 1000
226
                     numc1 = (numa5 - Last_X) * 1000
208
                     numc2 = (numa8 - Last_Y) * 1000
227
                     numc2 = (numa8 - Last_Y) * 1000
209
-                    numc3 = numc1 *numc1
210
-                    numc4 = numc2 *numc2
228
+                    numc3 = numc1 * numc1
229
+                    numc4 = numc2 * numc2
211
                     numc5 = math.sqrt(numc3 + numc4)
230
                     numc5 = math.sqrt(numc3 + numc4)
212
                     New_LastX = numc1
231
                     New_LastX = numc1
213
                     New_LastY = numc2
232
                     New_LastY = numc2
216
                     kk1 = 1
235
                     kk1 = 1
217
                     wyd = wyd + 1
236
                     wyd = wyd + 1
218
                     break
237
                     break
219
-        #不是位移点
238
+        # 不是位移点
220
         else:
239
         else:
221
-            #全部都是稳定点
240
+            # 全部都是稳定点
222
             if kk == -1:
241
             if kk == -1:
223
                 num3 = Last_X * Last_Wight
242
                 num3 = Last_X * Last_Wight
224
                 num4 = num3 + gsx[index1]
243
                 num4 = num3 + gsx[index1]
238
                 New_FirstX = numd1
257
                 New_FirstX = numd1
239
                 New_FirstY = numd2
258
                 New_FirstY = numd2
240
                 New_FirstP = numd5
259
                 New_FirstP = numd5
241
-                #新-首有个位移判定
260
+                # 新-首有个位移判定
242
                 if numd5 > wypd:
261
                 if numd5 > wypd:
243
                     NFDis_Ass = utf_bx
262
                     NFDis_Ass = utf_bx
244
                 else:
263
                 else:
245
                     NFDis_Ass = utf_wd
264
                     NFDis_Ass = utf_wd
246
                 nume1 = (num6 - Last_X) * 1000
265
                 nume1 = (num6 - Last_X) * 1000
247
                 nume2 = (num10 - Last_Y) * 1000
266
                 nume2 = (num10 - Last_Y) * 1000
248
-                nume3 = nume1 *nume1
249
-                nume4 = nume2 *nume2
267
+                nume3 = nume1 * nume1
268
+                nume4 = nume2 * nume2
250
                 nume5 = math.sqrt(nume3 + nume4)
269
                 nume5 = math.sqrt(nume3 + nume4)
251
                 New_LastX = nume1
270
                 New_LastX = nume1
252
                 New_LastY = nume2
271
                 New_LastY = nume2
253
                 New_LastP = nume5
272
                 New_LastP = nume5
254
                 NLDis_Ass = utf_wd
273
                 NLDis_Ass = utf_wd
255
-            #有位移点,且已经走过了
274
+            # 有位移点,且已经走过了
256
             if kk == 1 and kk1 == 1:
275
             if kk == 1 and kk1 == 1:
257
                 num3 = Last_X * Last_Wight
276
                 num3 = Last_X * Last_Wight
258
                 num4 = num3 + gsx[index1 - wyd]
277
                 num4 = num3 + gsx[index1 - wyd]
272
                 New_FirstX = numd1
291
                 New_FirstX = numd1
273
                 New_FirstY = numd2
292
                 New_FirstY = numd2
274
                 New_FirstP = numd5
293
                 New_FirstP = numd5
275
-                #新-首有个位移判定
294
+                # 新-首有个位移判定
276
                 if numd5 > wypd:
295
                 if numd5 > wypd:
277
                     NFDis_Ass = utf_bx
296
                     NFDis_Ass = utf_bx
278
                 else:
297
                 else:
279
                     NFDis_Ass = utf_wd
298
                     NFDis_Ass = utf_wd
280
                 nume1 = (num6 - Last_X) * 1000
299
                 nume1 = (num6 - Last_X) * 1000
281
                 nume2 = (num10 - Last_Y) * 1000
300
                 nume2 = (num10 - Last_Y) * 1000
282
-                nume3 = nume1 *nume1
283
-                nume4 = nume2 *nume2
301
+                nume3 = nume1 * nume1
302
+                nume4 = nume2 * nume2
284
                 nume5 = math.sqrt(nume3 + nume4)
303
                 nume5 = math.sqrt(nume3 + nume4)
285
                 New_LastX = nume1
304
                 New_LastX = nume1
286
                 New_LastY = nume2
305
                 New_LastY = nume2
287
                 New_LastP = nume5
306
                 New_LastP = nume5
288
                 NLDis_Ass = utf_wd
307
                 NLDis_Ass = utf_wd
289
-            #有位移点,但没有走过
308
+            # 有位移点,但没有走过
290
             if kk == 1 and kk1 == -1:
309
             if kk == 1 and kk1 == -1:
291
                 num3 = Last_X * Last_Wight
310
                 num3 = Last_X * Last_Wight
292
                 num4 = num3 + gsx[index1]
311
                 num4 = num3 + gsx[index1]
306
                 New_FirstX = numd1
325
                 New_FirstX = numd1
307
                 New_FirstY = numd2
326
                 New_FirstY = numd2
308
                 New_FirstP = numd5
327
                 New_FirstP = numd5
309
-                #新-首有个位移判定
328
+                # 新-首有个位移判定
310
                 if numd5 > wypd:
329
                 if numd5 > wypd:
311
                     NFDis_Ass = utf_bx
330
                     NFDis_Ass = utf_bx
312
                 else:
331
                 else:
313
                     NFDis_Ass = utf_wd
332
                     NFDis_Ass = utf_wd
314
                 nume1 = (num6 - Last_X) * 1000
333
                 nume1 = (num6 - Last_X) * 1000
315
                 nume2 = (num10 - Last_Y) * 1000
334
                 nume2 = (num10 - Last_Y) * 1000
316
-                nume3 = nume1 *nume1
317
-                nume4 = nume2 *nume2
335
+                nume3 = nume1 * nume1
336
+                nume4 = nume2 * nume2
318
                 nume5 = math.sqrt(nume3 + nume4)
337
                 nume5 = math.sqrt(nume3 + nume4)
319
                 New_LastX = nume1
338
                 New_LastX = nume1
320
                 New_LastY = nume2
339
                 New_LastY = nume2
321
                 New_LastP = nume5
340
                 New_LastP = nume5
322
                 NLDis_Ass = utf_wd
341
                 NLDis_Ass = utf_wd
323
-        #在这里整体输出
324
-        cursor1.execute('INSERT INTO WD_Result_Point(TableName,First_ResultName,Last_ResultName,New_ResultName,First_X,First_Y,Last_X,Last_Y,Result_X,Result_Y,Last_Wight,New_Wight,New_FirstX,New_FirstY,New_FirstP,NFDis_Ass,New_LastX,New_LastY,New_LastP,NLDis_Ass,PointName) VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)',(utf_tn,utf_bn,utf_pn,utf_nn,First_X,First_Y,Last_X,Last_Y,Result_X,Result_Y,Last_Wight,New_Wight,New_FirstX,New_FirstY,New_FirstP,NFDis_Ass,New_LastX,New_LastY,New_LastP,NLDis_Ass,PointName,))
325
-    #数据库执行
342
+        # 在这里整体输出
343
+        cursor1.execute(
344
+            'INSERT INTO WD_Result_Point(TableName,First_ResultName,Last_ResultName,New_ResultName,First_X,First_Y,Last_X,Last_Y,Result_X,Result_Y,Last_Wight,New_Wight,New_FirstX,New_FirstY,New_FirstP,NFDis_Ass,New_LastX,New_LastY,New_LastP,NLDis_Ass,PointName) VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)',
345
+            (
346
+                utf_tn, utf_bn, utf_pn, utf_nn, First_X, First_Y, Last_X, Last_Y, Result_X, Result_Y, Last_Wight,
347
+                New_Wight,
348
+                New_FirstX, New_FirstY, New_FirstP, NFDis_Ass, New_LastX, New_LastY, New_LastP, NLDis_Ass, PointName,))
349
+    # 数据库执行
326
     db1.commit()
350
     db1.commit()
327
-    #做完一切后,先关闭游标,再关闭数据库
351
+    # 做完一切后,先关闭游标,再关闭数据库
328
     cursor1.close()
352
     cursor1.close()
329
     db1.close()
353
     db1.close()
330
 
354
 
333
 gszby = []
357
 gszby = []
334
 jslist = []
358
 jslist = []
335
 jslist1 = []
359
 jslist1 = []
336
-def bhjs(listcgcs1, listname1, listpastx1, listpasty1, wypd, listname, listnewx, listnewy, listpastx, listpasty, points, listcgcs, listbex, listbey, sf, dbpath, befname, finalname, lastname, js,file_name):
360
+
361
+
362
+def bhjs(listcgcs1, listname1, listpastx1, listpasty1, wypd, listname, listnewx, listnewy, listpastx, listpasty, points,
363
+         listcgcs, listbex, listbey, sf, dbpath, befname, finalname, lastname, js, file_name):
337
     np.set_printoptions(suppress=False)
364
     np.set_printoptions(suppress=False)
338
     # pt用于给点数point计数
365
     # pt用于给点数point计数
339
     # point会随着回递函数而减少
366
     # point会随着回递函数而减少
372
     dy2 = cjh(dylist)
399
     dy2 = cjh(dylist)
373
     # 这里再创建矩阵1
400
     # 这里再创建矩阵1
374
     arr1 = np.array(((k2, 0, 0, 0), (0, s2, 0, 0),
401
     arr1 = np.array(((k2, 0, 0, 0), (0, s2, 0, 0),
375
-                    (0, 0, dx2, 0), (0, 0, 0, dy2)))
402
+                     (0, 0, dx2, 0), (0, 0, 0, dy2)))
376
     # 矩阵1的逆矩阵矩阵2
403
     # 矩阵1的逆矩阵矩阵2
377
     arr2 = np.linalg.inv(arr1)
404
     arr2 = np.linalg.inv(arr1)
378
     # 求矩阵l
405
     # 求矩阵l
379
     llist = jzys4(listpasty, zxzbpasty, listpastx, zxzbpastx,
406
     llist = jzys4(listpasty, zxzbpasty, listpastx, zxzbpastx,
380
-                    listnewy, zxzbnewy, listnewx, zxzbnewx, sf)
407
+                  listnewy, zxzbnewy, listnewx, zxzbnewx, sf)
381
     # 得到数列e1,e2,e3,e4
408
     # 得到数列e1,e2,e3,e4
382
     e1 = cjh2(klist, llist)
409
     e1 = cjh2(klist, llist)
383
     e2 = cjh2(slist, llist)
410
     e2 = cjh2(slist, llist)
396
     lylist = jzys3(jylist1, 0, 1)
423
     lylist = jzys3(jylist1, 0, 1)
397
     # 求改算坐标
424
     # 求改算坐标
398
     gsx = gsys(listnewx, jxlist1, jylist1, lxlist,
425
     gsx = gsys(listnewx, jxlist1, jylist1, lxlist,
399
-                lylist, arrz, sf, zxzbnewx, zxzbpastx, 0)
426
+               lylist, arrz, sf, zxzbnewx, zxzbpastx, 0)
400
     gsy = gsys(listnewy, jxlist2, jylist2, lxlist,
427
     gsy = gsys(listnewy, jxlist2, jylist2, lxlist,
401
-                lylist, arrz, sf, zxzbnewy, zxzbpasty, 1)
428
+               lylist, arrz, sf, zxzbnewy, zxzbpasty, 1)
402
     # 还是要先求较差
429
     # 还是要先求较差
403
     xcx = xcys(gsx, listpastx)
430
     xcx = xcys(gsx, listpastx)
404
     xcy = xcys(gsy, listpasty)
431
     xcy = xcys(gsy, listpasty)
447
         n3 = zxzbpastx - zxzbnewx - s1 - s2 + float(arrz[2])
474
         n3 = zxzbpastx - zxzbnewx - s1 - s2 + float(arrz[2])
448
         n4 = (-1) * float(arrz[1])
475
         n4 = (-1) * float(arrz[1])
449
         n5 = n1
476
         n5 = n1
450
-        s3 = (-1)*float(arrz[0])*zxzbnewy
451
-        s4 = float(arrz[1])*zxzbnewx
452
-        n6 = s3 + s4 + float(arrz[3])+zxzbpasty-zxzbnewy
477
+        s3 = (-1) * float(arrz[0]) * zxzbnewy
478
+        s4 = float(arrz[1]) * zxzbnewx
479
+        n6 = s3 + s4 + float(arrz[3]) + zxzbpasty - zxzbnewy
453
         sxylist = []
480
         sxylist = []
454
         sxylist.append(n1)
481
         sxylist.append(n1)
455
         sxylist.append(n2)
482
         sxylist.append(n2)
466
         relist1.append(gszbx)
493
         relist1.append(gszbx)
467
         relist1.append(gszby)
494
         relist1.append(gszby)
468
         relist1.append(sxylist)
495
         relist1.append(sxylist)
469
-        #存入数据库
470
-        insert_into_database1(dbpath,lastname,finalname,befname,file_name,listname1,listpastx1,listpasty1,listcgcs1,listbex,listbey,sxylist,wypd,gsx,gsy,listcgcs)
496
+        # 存入数据库
497
+        insert_into_database1(dbpath, lastname, finalname, befname, file_name, listname1, listpastx1, listpasty1,
498
+                              listcgcs1, listbex, listbey, sxylist, wypd, gsx, gsy, listcgcs)
471
     else:
499
     else:
472
-            # 先把所有的合在一起,方便删除
473
-            lenlist1 = len(xcx)
474
-            ii = 0
475
-            relist1 = []
476
-            while ii < lenlist1:
477
-                smlist1 = []
478
-                nn2 = xcx[ii] * xcx[ii]
479
-                mm2 = xcy[ii] * xcy[ii]
480
-                nm2 = math.sqrt(nn2 + mm2)
481
-                smlist1.append(nm2)
482
-                smlist1.append(listname[ii])
483
-                smlist1.append(listnewx[ii])
484
-                smlist1.append(listnewy[ii])
485
-                smlist1.append(listpastx[ii])
486
-                smlist1.append(listpasty[ii])
487
-                relist1.append(smlist1)
488
-                ii = ii + 1
489
-            # 直接删除最大的那个
490
-            relist1.sort(key=takeFirst, reverse=True)
491
-            num1 = relist1[0]
492
-            # 获取name
493
-            num2 = num1[1]
494
-            ii2 = 0
495
-            mm2 = 0
496
-            while ii2 < lenlist1:
497
-                if listname[ii2] == num2:
498
-                    del listname[ii2]
499
-                    del listnewx[ii2]
500
-                    del listnewy[ii2]
501
-                    del listpastx[ii2]
502
-                    del listpasty[ii2]
503
-                    points = points - 1
504
-                    break
505
-                else:
506
-                    ii2 = ii2 + 1
507
-            while mm2 < len(listcgcs):
508
-                if listname1[mm2] == num2:
509
-                    listcgcs[mm2] = -1
510
-                    break
511
-                else:
512
-                    mm2 = mm2 + 1
513
-            print(" Finish!")
514
-            js1 = 1
515
-            bhjs(listcgcs1, listname1, listpastx1, listpasty1, wypd, listname, listnewx, listnewy, listpastx,
516
-                 listpasty, points, listcgcs, listbex, listbey, sf, dbpath, befname, finalname, lastname, js1,file_name)
500
+        # 先把所有的合在一起,方便删除
501
+        lenlist1 = len(xcx)
502
+        ii = 0
503
+        relist1 = []
504
+        while ii < lenlist1:
505
+            smlist1 = []
506
+            nn2 = xcx[ii] * xcx[ii]
507
+            mm2 = xcy[ii] * xcy[ii]
508
+            nm2 = math.sqrt(nn2 + mm2)
509
+            smlist1.append(nm2)
510
+            smlist1.append(listname[ii])
511
+            smlist1.append(listnewx[ii])
512
+            smlist1.append(listnewy[ii])
513
+            smlist1.append(listpastx[ii])
514
+            smlist1.append(listpasty[ii])
515
+            relist1.append(smlist1)
516
+            ii = ii + 1
517
+        # 直接删除最大的那个
518
+        relist1.sort(key=takeFirst, reverse=True)
519
+        num1 = relist1[0]
520
+        # 获取name
521
+        num2 = num1[1]
522
+        ii2 = 0
523
+        mm2 = 0
524
+        while ii2 < lenlist1:
525
+            if listname[ii2] == num2:
526
+                del listname[ii2]
527
+                del listnewx[ii2]
528
+                del listnewy[ii2]
529
+                del listpastx[ii2]
530
+                del listpasty[ii2]
531
+                points = points - 1
532
+                break
533
+            else:
534
+                ii2 = ii2 + 1
535
+        while mm2 < len(listcgcs):
536
+            if listname1[mm2] == num2:
537
+                listcgcs[mm2] = -1
538
+                break
539
+            else:
540
+                mm2 = mm2 + 1
541
+        print(" Finish!")
542
+        js1 = 1
543
+        bhjs(listcgcs1, listname1, listpastx1, listpasty1, wypd, listname, listnewx, listnewy, listpastx,
544
+             listpasty, points, listcgcs, listbex, listbey, sf, dbpath, befname, finalname, lastname, js1, file_name)
545
+
517
 
546
 
518
-def tablein(dbpath,file_name):
547
+def tablein(dbpath, file_name):
519
     # 收集每一列的数据,方便后期计算
548
     # 收集每一列的数据,方便后期计算
520
     listname1 = []
549
     listname1 = []
521
     listpastx1 = []
550
     listpastx1 = []
532
     listbex = []
561
     listbex = []
533
     listbey = []
562
     listbey = []
534
     points = 0
563
     points = 0
535
-    #查询,提取需要的数据
564
+    # 查询,提取需要的数据
536
     db2 = sqlite3.connect(dbpath)
565
     db2 = sqlite3.connect(dbpath)
537
     cursor2 = db2.cursor()
566
     cursor2 = db2.cursor()
538
     utfstr1 = to_utf8(file_name)
567
     utfstr1 = to_utf8(file_name)
539
     sqlstr1 = 'SELECT * FROM WD_Input_Point WHERE TableName = ?'
568
     sqlstr1 = 'SELECT * FROM WD_Input_Point WHERE TableName = ?'
540
-    cursor2.execute(sqlstr1,(utfstr1,))
569
+    cursor2.execute(sqlstr1, (utfstr1,))
541
     all_da = cursor2.fetchall()
570
     all_da = cursor2.fetchall()
542
     for da in all_da:
571
     for da in all_da:
543
         listbex.append(da[4])
572
         listbex.append(da[4])
554
         listname.append(da[11])
583
         listname.append(da[11])
555
         listname1.append(da[11])
584
         listname1.append(da[11])
556
     sqlstr2 = 'SELECT * FROM WD_Input_Param WHERE TableName = ?'
585
     sqlstr2 = 'SELECT * FROM WD_Input_Param WHERE TableName = ?'
557
-    cursor2.execute(sqlstr2,(utfstr1,))
586
+    cursor2.execute(sqlstr2, (utfstr1,))
558
     all_par = cursor2.fetchall()
587
     all_par = cursor2.fetchall()
559
     befname = all_par[0][0].decode('utf-8')
588
     befname = all_par[0][0].decode('utf-8')
560
     lastname = all_par[0][1].decode('utf-8')
589
     lastname = all_par[0][1].decode('utf-8')
561
-    finalname = all_par[0][2].decode('utf-8')    
590
+    finalname = all_par[0][2].decode('utf-8')
562
     # pjbc是平均边长
591
     # pjbc是平均边长
563
     # fxzwc是方向中误差,zrbzwc是最弱边边长相对中误差,pjbcs是平均边数,pjfxs是平均方向数,sf是缩放值
592
     # fxzwc是方向中误差,zrbzwc是最弱边边长相对中误差,pjbcs是平均边数,pjfxs是平均方向数,sf是缩放值
564
     # 新增总边数zbs,总方向数zfxs
593
     # 新增总边数zbs,总方向数zfxs
580
     wypd3 = math.sqrt(wypd1 + wypd2)
609
     wypd3 = math.sqrt(wypd1 + wypd2)
581
     wypd = round((wypd3 * 2 * math.sqrt(2)), 9)
610
     wypd = round((wypd3 * 2 * math.sqrt(2)), 9)
582
     wypd0 = wypd
611
     wypd0 = wypd
583
-    js=0
584
-    return listcgcs1, listname1, listpastx1, listpasty1, wypd0, listname, listnewx, listnewy, listpastx,listpasty, points, listcgcs, listbex, listbey, sf, befname, finalname, lastname, js
612
+    js = 0
613
+    return listcgcs1, listname1, listpastx1, listpasty1, wypd0, listname, listnewx, listnewy, listpastx, listpasty, points, listcgcs, listbex, listbey, sf, befname, finalname, lastname, js
585
 
614
 
586
 
615
 
587
 # 主函数 计算
616
 # 主函数 计算
588
-def main_function(dbpath,file_name):
589
-    #从数据库中调用
590
-    listcgcs1, listname1, listpastx1, listpasty1, wypd0, listname, listnewx, listnewy, listpastx,listpasty, points, listcgcs, listbex, listbey, sf, befname, finalname, lastname, js = tablein(dbpath,file_name)
591
-    #计算
592
-    bhjs(listcgcs1, listname1, listpastx1, listpasty1, wypd0, listname, listnewx, listnewy, listpastx,listpasty, points, listcgcs, listbex, listbey, sf, dbpath, befname, finalname, lastname, js,file_name)
593
-    messagebox.showinfo("提示",f"文件 '{file_name}' 计算成功!")
617
+def main_function(file_name, dbpath):
618
+    try:
619
+        # 从数据库中调用
620
+        listcgcs1, listname1, listpastx1, listpasty1, wypd0, listname, listnewx, listnewy, listpastx, listpasty, points, listcgcs, listbex, listbey, sf, befname, finalname, lastname, js = tablein(
621
+            dbpath, file_name)
622
+        # 计算
623
+        bhjs(listcgcs1, listname1, listpastx1, listpasty1, wypd0, listname, listnewx, listnewy, listpastx, listpasty,
624
+             points, listcgcs, listbex, listbey, sf, dbpath, befname, finalname, lastname, js, file_name)
625
+        QMessageBox.information(None, "提示", f"文件 '{file_name}' 计算成功!")
626
+    except Exception as e:
627
+        QMessageBox.critical(None, "错误", f"文件 '{file_name}' 计算失败!错误信息: {str(e)}")

+ 39
- 27
Back/WD/WDshow.py Wyświetl plik

3
 
3
 
4
 from PySide6.QtGui import QStandardItemModel
4
 from PySide6.QtGui import QStandardItemModel
5
 
5
 
6
+
6
 def main_function(ui, db_path, utf_en):
7
 def main_function(ui, db_path, utf_en):
7
-    #只显示头两个tab
8
-    ui.tabWidget.setTabVisible(0,True)
9
-    ui.tabWidget.setTabVisible(1,True)
10
-    ui.tabWidget.setTabVisible(2,False)
11
-    #重新设置文字名称
12
-    ui.tabWidget.setTabText(0,'稳定性分析成果表')
13
-    ui.tabWidget.setTabText(1,'自由网成果归算模型')
14
-    #链接数据库并显示
8
+    # 只显示头两个tab
9
+    ui.tabWidget.setTabVisible(0, True)
10
+    ui.tabWidget.setTabVisible(1, True)
11
+    ui.tabWidget.setTabVisible(2, False)
12
+    # 重新设置文字名称
13
+    ui.tabWidget.setTabText(0, '稳定性分析成果表')
14
+    ui.tabWidget.setTabText(1, '自由网成果归算模型')
15
+    # 链接数据库并显示
15
     # 连接到数据库
16
     # 连接到数据库
16
-    #将结果输出到数据库
17
+    # 将结果输出到数据库
17
     db1 = sqlite3.connect(db_path)
18
     db1 = sqlite3.connect(db_path)
18
-    #获取游标
19
+    # 获取游标
19
     cursor1 = db1.cursor()
20
     cursor1 = db1.cursor()
20
-    #查询表内符合的所有数据
21
+    # 查询表内符合的所有数据
21
     sqlstr1 = 'select PointName,First_X,First_Y,Last_X,Last_Y,Last_Wight,Result_X,Result_Y,New_Wight,New_FirstX,New_FirstY,New_FirstP,NFDis_Ass,New_LastX,New_LastY,New_LastP,NLDis_Ass from WD_Result_Point WHERE TableName = ?'
22
     sqlstr1 = 'select PointName,First_X,First_Y,Last_X,Last_Y,Last_Wight,Result_X,Result_Y,New_Wight,New_FirstX,New_FirstY,New_FirstP,NFDis_Ass,New_LastX,New_LastY,New_LastP,NLDis_Ass from WD_Result_Point WHERE TableName = ?'
22
-    cursor1.execute(sqlstr1,(utf_en,))
23
-    #获取结果集
23
+    cursor1.execute(sqlstr1, (utf_en,))
24
+    # 获取结果集
24
     result = cursor1.fetchall()
25
     result = cursor1.fetchall()
25
-    #对结果集进行处理,把汉字转换过来,添加表头部分
26
-    nlist,plist = Arrange_Data(result)
26
+    # 对结果集进行处理,把汉字转换过来,添加表头部分
27
+    nlist, plist = Arrange_Data(result)
27
     # 创建一个数据模型
28
     # 创建一个数据模型
28
     model = QStandardItemModel()
29
     model = QStandardItemModel()
29
-    #把数据放进去
30
+    # 把数据放进去
30
     model1 = Data_in_Cell(plist)
31
     model1 = Data_in_Cell(plist)
31
-    #设置表头
32
-    model1.setHorizontalHeaderLabels(['点名', '首期X','首期Y','上期X', '上期Y','权','本期X','本期Y','权','本期-首期X','本期-首期Y','本期-首期P','位移判定', '本期-上期X','本期-上期Y','本期-上期P','位移判定'])
32
+    # 设置表头
33
+    model1.setHorizontalHeaderLabels(
34
+        ['点名', '首期X', '首期Y', '上期X', '上期Y', '权', '本期X', '本期Y', '权', '本期-首期X', '本期-首期Y',
35
+         '本期-首期P', '位移判定', '本期-上期X', '本期-上期Y', '本期-上期P', '位移判定'])
33
     model1.setVerticalHeaderLabels(nlist)
36
     model1.setVerticalHeaderLabels(nlist)
34
-    #QTableView并将数据模型与之关联
37
+
38
+    # QTableView并将数据模型与之关联
35
     ui.resultTableView.setModel(model1)
39
     ui.resultTableView.setModel(model1)
36
     ui.resultTableView.show()
40
     ui.resultTableView.show()
37
 
41
 
38
-    #富文本的html
42
+    # 隐藏 QLabel(默认提示语言)
43
+    ui.default_remind.hide()
44
+    # 富文本的html
39
     sqlstr2 = 'select Last_ResultName,New_ResultName,Formula_X1,Formula_X2,Formula_X3,Formula_Y1,Formula_Y2,Formula_Y3 from WD_Result_Param WHERE TableName = ?'
45
     sqlstr2 = 'select Last_ResultName,New_ResultName,Formula_X1,Formula_X2,Formula_X3,Formula_Y1,Formula_Y2,Formula_Y3 from WD_Result_Param WHERE TableName = ?'
40
-    cursor1.execute(sqlstr2,(utf_en,))
41
-    #获取结果集
46
+    cursor1.execute(sqlstr2, (utf_en,))
47
+    # 获取结果集
42
     result1 = cursor1.fetchall()
48
     result1 = cursor1.fetchall()
43
     str1 = result1[0][0].decode('utf-8')
49
     str1 = result1[0][0].decode('utf-8')
44
     str2 = result1[0][1].decode('utf-8')
50
     str2 = result1[0][1].decode('utf-8')
55
 li.unchecked::marker { content: "\2610"; }
61
 li.unchecked::marker { content: "\2610"; }
56
 li.checked::marker { content: "\2612"; }
62
 li.checked::marker { content: "\2612"; }
57
 </style></head><body style=" font-family:'Microsoft YaHei UI'; font-size:9pt; font-weight:400; font-style:normal;">
63
 </style></head><body style=" font-family:'Microsoft YaHei UI'; font-size:9pt; font-weight:400; font-style:normal;">
58
-<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-size:14pt; color:#000000;">"""+str2+"""--"""+str1+"""</span><span style=" font-size:14pt;">已知系统转换公式:</span></p>
59
-<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-size:14pt; font-weight:700;">X</span><span style=" font-size:14pt;">=(</span><span style=" font-size:14pt; color:#aa0000;">"""+str(n1)+"""</span><span style=" font-size:14pt;">)</span><span style=" font-size:14pt; font-weight:700;">x</span><span style=" font-size:14pt;">+(</span><span style=" font-size:14pt; color:#00aa00;">"""+str(n2)+"""</span><span style=" font-size:14pt;">)</span><span style=" font-size:14pt; font-weight:700;">y</span><span style=" font-size:14pt;">+(</span><span style=" font-size:14pt; color:#00007f;">"""+str(n3)+"""</span><span style=" font-size:14pt;">)</span></p>
60
-<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-size:14pt; font-weight:700;">Y</span><span style=" font-size:14pt;">=(</span><span style=" font-size:14pt; color:#aa0000;">"""+str(n4)+"""</span><span style=" font-size:14pt;">)</span><span style=" font-size:14pt; font-weight:700;">x</span><span style=" font-size:14pt;">+(</span><span style=" font-size:14pt; color:#00aa00;">"""+str(n5)+"""</span><span style=" font-size:14pt;">)</span><span style=" font-size:14pt; font-weight:700;">y</span><span style=" font-size:14pt;">+(</span><span style=" font-size:14pt; color:#00007f;">"""+str(n6)+"""</span><span style=" font-size:14pt;">)</span></p>
61
-<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-size:14pt;">式中:</span><span style=" font-size:14pt; font-weight:700; color:#000000;">x、y</span><span style=" font-size:14pt;">为</span><span style=" font-size:14pt; color:#000000;">"""+str2+"""</span><span style=" font-size:14pt;">坐标;</span></p>
62
-<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-size:14pt;">          </span><span style=" font-size:14pt; font-weight:700;">X、Y</span><span style=" font-size:14pt;">为"""+str1+"""已知系统的"""+str2+"""归算坐标。</span></p></body></html>"""
64
+<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-size:14pt; color:#000000;">""" + str2 + """--""" + str1 + """</span><span style=" font-size:14pt;">已知系统转换公式:</span></p>
65
+<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-size:14pt; font-weight:700;">X</span><span style=" font-size:14pt;">=(</span><span style=" font-size:14pt; color:#aa0000;">""" + str(
66
+        n1) + """</span><span style=" font-size:14pt;">)</span><span style=" font-size:14pt; font-weight:700;">x</span><span style=" font-size:14pt;">+(</span><span style=" font-size:14pt; color:#00aa00;">""" + str(
67
+        n2) + """</span><span style=" font-size:14pt;">)</span><span style=" font-size:14pt; font-weight:700;">y</span><span style=" font-size:14pt;">+(</span><span style=" font-size:14pt; color:#00007f;">""" + str(
68
+        n3) + """</span><span style=" font-size:14pt;">)</span></p>
69
+<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-size:14pt; font-weight:700;">Y</span><span style=" font-size:14pt;">=(</span><span style=" font-size:14pt; color:#aa0000;">""" + str(
70
+        n4) + """</span><span style=" font-size:14pt;">)</span><span style=" font-size:14pt; font-weight:700;">x</span><span style=" font-size:14pt;">+(</span><span style=" font-size:14pt; color:#00aa00;">""" + str(
71
+        n5) + """</span><span style=" font-size:14pt;">)</span><span style=" font-size:14pt; font-weight:700;">y</span><span style=" font-size:14pt;">+(</span><span style=" font-size:14pt; color:#00007f;">""" + str(
72
+        n6) + """</span><span style=" font-size:14pt;">)</span></p>
73
+<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-size:14pt;">式中:</span><span style=" font-size:14pt; font-weight:700; color:#000000;">x、y</span><span style=" font-size:14pt;">为</span><span style=" font-size:14pt; color:#000000;">""" + str2 + """</span><span style=" font-size:14pt;">坐标;</span></p>
74
+<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-size:14pt;">          </span><span style=" font-size:14pt; font-weight:700;">X、Y</span><span style=" font-size:14pt;">为""" + str1 + """已知系统的""" + str2 + """归算坐标。</span></p></body></html>"""
63
     ui.printTableView.setHtml(str0)
75
     ui.printTableView.setHtml(str0)

+ 10
- 2
Front/main.py Wyświetl plik

67
         # ///////////////////////////////////////////////////////////////
67
         # ///////////////////////////////////////////////////////////////
68
         self.ui = Ui_MainWindow()
68
         self.ui = Ui_MainWindow()
69
         self.ui.setupUi(self)
69
         self.ui.setupUi(self)
70
+        # 连接信号与槽函数,实现点击操作
70
         self.ui.createFile.clicked.connect(self.on_create_file_clicked)
71
         self.ui.createFile.clicked.connect(self.on_create_file_clicked)
72
+        self.ui.export_2.clicked.connect(self.on_export_2_clicked)
71
         # self.comboBox_2 = QComboBox(self)
73
         # self.comboBox_2 = QComboBox(self)
72
         # ...此处为省略代码...
74
         # ...此处为省略代码...
73
         global widgets
75
         global widgets
247
             # 触发按钮点击事件
249
             # 触发按钮点击事件
248
             btn.click()
250
             btn.click()
249
 
251
 
250
-
251
     # 新增槽函数来调用 create_database_and_tables
252
     # 新增槽函数来调用 create_database_and_tables
252
     def on_create_file_clicked(self):
253
     def on_create_file_clicked(self):
253
-        Back.Program_Run.database_operations.create_database_and_tables(self.ui)
254
+        Back.Program_Run.database_operations.create_database_and_tables(self, self.ui)
255
+
256
+    # 定义导出数据库的槽函数
257
+    def on_export_2_clicked(self):
258
+        if self.file_path:
259
+            UIFunctions.export_database_to_excel(self, self.file_path)
260
+        else:
261
+            QMessageBox.warning(self, '警告', '请先选择项目并上传文件')
254
 
262
 
255
     # RESIZE EVENTS
263
     # RESIZE EVENTS
256
     # ///////////////////////////////////////////////////////////////
264
     # ///////////////////////////////////////////////////////////////

+ 28
- 6
Front/modules/ui_functions.py Wyświetl plik

13
 # https://doc.qt.io/qtforpython/licenses.html
13
 # https://doc.qt.io/qtforpython/licenses.html
14
 #
14
 #
15
 # ///////////////////////////////////////////////////////////////
15
 # ///////////////////////////////////////////////////////////////
16
-
16
+from PySide6.QtWidgets import QMessageBox
17
 # MAIN FILE
17
 # MAIN FILE
18
 # ///////////////////////////////////////////////////////////////
18
 # ///////////////////////////////////////////////////////////////
19
 
19
 
20
 
20
 
21
 from main import *
21
 from main import *
22
 import importlib
22
 import importlib
23
-from Back.GC import GC
24
-from Back.GS import GS
25
-from Back.WD import WD
23
+from Back.GC import GC, GCExport
24
+from Back.GS import GS, GSExport
25
+from Back.WD import WD, WDExport
26
 from Back.GC import GCcompute
26
 from Back.GC import GCcompute
27
 from Back.GS import GScompute
27
 from Back.GS import GScompute
28
 from Back.WD import WDcompute
28
 from Back.WD import WDcompute
320
     # 计算与展示文件的方法
320
     # 计算与展示文件的方法
321
     def compute_show_process_excel_file(self, file_path):
321
     def compute_show_process_excel_file(self, file_path):
322
         current_text = self.ui.comboBox_2.currentText()
322
         current_text = self.ui.comboBox_2.currentText()
323
-        # db_path = r"D:/Code/ControlNetwork/UI/SQL/DataBase.db"
324
         # 获取当前脚本所在的目录
323
         # 获取当前脚本所在的目录
325
         current_dir = os.path.dirname(os.path.abspath(__file__))
324
         current_dir = os.path.dirname(os.path.abspath(__file__))
326
         # 构建 SQL 文件夹的相对路径(上一级的上一级中的 SQL 文件夹)
325
         # 构建 SQL 文件夹的相对路径(上一级的上一级中的 SQL 文件夹)
338
             GScompute.main_function(excelname, db_path)
337
             GScompute.main_function(excelname, db_path)
339
             GSshow.main_function(self.ui, db_path, utf_en)
338
             GSshow.main_function(self.ui, db_path, utf_en)
340
         elif current_text == "平面控制网稳定性计算":
339
         elif current_text == "平面控制网稳定性计算":
341
-            WDcompute.main_function(file_path, db_path)
340
+            WDcompute.main_function(excelname, db_path)
342
             WDshow.main_function(self.ui, db_path, utf_en)
341
             WDshow.main_function(self.ui, db_path, utf_en)
342
+
343
+    # 文件导出的方法
344
+    def export_database_to_excel(self, file_path):
345
+        current_text = self.ui.comboBox_2.currentText()
346
+        # 获取当前脚本所在的目录
347
+        current_dir = os.path.dirname(os.path.abspath(__file__))
348
+        # 构建 SQL 文件夹的相对路径(上一级的上一级中的 SQL 文件夹)
349
+        sql_folder = os.path.join(current_dir, '..', '..', 'SQL')
350
+        # 将相对路径转换为绝对路径
351
+        sql_folder = os.path.abspath(sql_folder)
352
+        db_path = os.path.join(sql_folder, f"{self.ui.comboBox.currentText()}.db")
353
+        # 转换为utf-8
354
+        excelname = os.path.basename(file_path)  # 文件名
355
+        utf_en = excelname.encode('utf-8')  # 转换文件名为utf-8编码形式
356
+        if current_text == "水准测段高差稳定计算":
357
+            GCExport.main_function(self, file_path, utf_en, db_path)
358
+        elif current_text == "控制网复测平面基准计算":
359
+            GSExport.main_function(self, db_path, file_path)
360
+        elif current_text == "平面控制网稳定性计算":
361
+            # WDExport.main_function(self, file_path)
362
+            pass
363
+        else:
364
+            QMessageBox.warning(self, '警告', '请选择有效的计算类型')
343
     # END - GUI DEFINITIONS
365
     # END - GUI DEFINITIONS

+ 1
- 44
Front/modules/ui_main.py Wyświetl plik

33
 from .resources_rc import *
33
 from .resources_rc import *
34
 
34
 
35
 
35
 
36
-
37
-# class ComboBoxUpdater(FileSystemEventHandler):
38
-#     def __init__(self, comboBox, sql_folder):
39
-#         super().__init__()
40
-#         self.comboBox = comboBox
41
-#         self.sql_folder = sql_folder
42
-#
43
-#     def on_modified(self, event):
44
-#         if event.is_directory:
45
-#             return
46
-#         if event.src_path.endswith('.db'):
47
-#             self.update_combo_box()
48
-#
49
-#     def on_created(self, event):
50
-#         if event.is_directory:
51
-#             return
52
-#         if event.src_path.endswith('.db'):
53
-#             self.update_combo_box()
54
-#
55
-#     def on_deleted(self, event):
56
-#         if event.is_directory:
57
-#             return
58
-#         if event.src_path.endswith('.db'):
59
-#             self.update_combo_box()
60
-#
61
-#     def update_combo_box(self):
62
-#         # 清空现有的 comboBox 内容
63
-#         self.comboBox.clear()
64
-#
65
-#         # 列出 SQL 文件夹中的所有 .db 文件
66
-#         db_files = [f for f in os.listdir(self.sql_folder) if f.endswith('.db')]
67
-#
68
-#         # 将数据库文件名添加到 comboBox 中
69
-#         for db_file in db_files:
70
-#             self.comboBox.addItem(QCoreApplication.translate("MainWindow", db_file, None))
71
-#
72
-#         # 如果没有找到任何数据库文件,显示提示信息
73
-#         if not db_files:
74
-#             self.comboBox.addItem(QCoreApplication.translate("MainWindow", "未找到数据库文件", None))
75
-
76
-
77
-
78
-
79
 class Ui_MainWindow(object):
36
 class Ui_MainWindow(object):
80
     # UI界面
37
     # UI界面
81
     def setupUi(self, MainWindow):
38
     def setupUi(self, MainWindow):
1359
 
1316
 
1360
         # 确保 SQL 文件夹存在
1317
         # 确保 SQL 文件夹存在
1361
         if not os.path.exists(sql_folder):
1318
         if not os.path.exists(sql_folder):
1362
-            QMessageBox.critical(MainWindow, "错误", "SQL 文件夹不存在")
1319
+            QMessageBox.critical(MainWindow, "错误", "项目文件夹不存在")
1363
             return
1320
             return
1364
         # 初始化 ComboBoxUpdater
1321
         # 初始化 ComboBoxUpdater
1365
         self.updater = ComboBoxUpdater(self.comboBox, sql_folder)
1322
         self.updater = ComboBoxUpdater(self.comboBox, sql_folder)

BIN
SQL/DataBase.db Wyświetl plik


Ładowanie…
Anuluj
Zapisz