Przeglądaj źródła

更新了选择指定项目(指定数据库路径)进行计算,而不是指定数据库路径

Mr.wzp 5 miesięcy temu
rodzic
commit
e9933e1451

+ 238
- 0
Back/GS/GSExport.py Wyświetl plik

1
+import openpyxl
2
+import sqlite3
3
+import os
4
+from openpyxl.styles import Alignment
5
+
6
+def Arrange_Data1(list1):
7
+    #最终return的
8
+    list2 = []
9
+    for data1 in list1:
10
+        #点名
11
+        #存每一行的数据
12
+        resultlist = []
13
+        pn = data1[0].decode('utf-8')
14
+        resultlist.append(pn)
15
+        resultlist.append(data1[1])
16
+        resultlist.append(data1[2])
17
+        resultlist.append(data1[3])
18
+        resultlist.append(data1[4])
19
+        resultlist.append(data1[5])
20
+        #判定
21
+        an1 = data1[6].decode('utf-8')
22
+        resultlist.append(an1)
23
+        #两个结果名字(旧新)
24
+        name1 = data1[7].decode('utf-8')
25
+        resultlist.append(name1)
26
+        name2 = data1[8].decode('utf-8')
27
+        resultlist.append(name2)
28
+        list2.append(resultlist)
29
+    return list2
30
+
31
+#复测成果表
32
+def Arrange_Data2(list1):
33
+    #最终return的
34
+    list2 = []
35
+    for data1 in list1:
36
+        #点名
37
+        #存每一行的数据
38
+        resultlist = []
39
+        pn = data1[0].decode('utf-8')
40
+        resultlist.append(pn)
41
+        resultlist.append(data1[1])
42
+        resultlist.append(data1[2])
43
+        resultlist.append(data1[3])
44
+        resultlist.append(data1[4])
45
+        resultlist.append(data1[5])
46
+        resultlist.append(data1[6])
47
+        resultlist.append(data1[7])
48
+        #判定
49
+        an1 = data1[8].decode('utf-8')
50
+        resultlist.append(an1)
51
+        #两个结果名字(旧新)
52
+        name1 = data1[9].decode('utf-8')
53
+        resultlist.append(name1)
54
+        name2 = data1[10].decode('utf-8')
55
+        resultlist.append(name2)
56
+        list2.append(resultlist)
57
+    
58
+    return list2
59
+
60
+def openpyxl_write(outpath,dbpath,filename):
61
+    utf_en = filename.encode('utf-8')
62
+    #新建对应的excel
63
+    wb = openpyxl.Workbook()
64
+    ws2 = wb.create_sheet('复测成果表')
65
+    ws1 = wb.create_sheet('复测基准归算表')
66
+    ws3 = wb.create_sheet('基准归算模型')
67
+    ws5 = wb['Sheet']
68
+    wb.remove(ws5)
69
+
70
+    #w1部分(基准归算表)
71
+    #提取数据
72
+    db = sqlite3.connect(dbpath)
73
+    cursor1 = db.cursor()
74
+    sqlstr11 = 'select PointName,Cal_X,Cal_Y,Last_CalX,Last_CalY,Last_CalP,Dis_Ass,Last_ResultName,New_ResultName from GS_Result_Point WHERE TableName = ?'
75
+    cursor1.execute(sqlstr11,(utf_en,))
76
+    #获取结果集
77
+    result1 = cursor1.fetchall()
78
+    #整理数据
79
+    plist1 = Arrange_Data1(result1)
80
+    ws1.column_dimensions['A'].width = 5
81
+    ws1.column_dimensions['B'].width = 15
82
+    ws1.column_dimensions['C'].width = 15
83
+    ws1.column_dimensions['D'].width = 8
84
+    ws1.column_dimensions['E'].width = 8
85
+    ws1.column_dimensions['F'].width = 8
86
+    ws1.column_dimensions['G'].width = 5
87
+    ws1.merge_cells(start_row=1, end_row=1,
88
+                    start_column=1, end_column=7)
89
+    ws1.cell(1, 1).value = '复测基准归算与位移判定'
90
+    ws1.merge_cells(start_row=2, end_row=3,
91
+                    start_column=1, end_column=1)
92
+    ws1.cell(2, 1).value = '点名'
93
+    ws1.merge_cells(start_row=2, end_row=2,
94
+                    start_column=2, end_column=3)
95
+    ws1.cell(2, 2).value = plist1[0][8] + '基准归算成果'
96
+    ws1.merge_cells(start_row=2, end_row=2,
97
+                    start_column=4, end_column=6)
98
+    ws1.cell(2, 4).value = plist1[0][7] + '-归算成果(mm)'
99
+    ws_area = ws1["A1:H3"]
100
+    alignment_center = Alignment(horizontal='center', vertical='center')# 指定区域单元格居中
101
+    for i in ws_area:
102
+        for j in i:
103
+            j.alignment = alignment_center
104
+    alignment_right = Alignment(horizontal='right', vertical='center')
105
+    ws1.merge_cells(start_row=2, end_row=3,
106
+        start_column=7, end_column=7)
107
+    ws1.cell(2, 7).value = '位移判定'
108
+    ws1.cell(2, 7).alignment = Alignment(wrap_text=True)
109
+    ws1.cell(3, 2).value = 'X(mm)'
110
+    ws1.cell(3, 3).value = 'Y(mm)'
111
+    ws1.cell(3, 4).value = '△X'
112
+    ws1.cell(3, 5).value = '△Y'
113
+    ws1.cell(3, 6).value = '△P'
114
+    row1 = 4
115
+    for data1 in plist1:
116
+        ws1.cell(row1,1).value = data1[0]
117
+        ws1.cell(row1,2).value = round(data1[1],4)
118
+        ws1.cell(row1,3).value = round(data1[2],4)
119
+        ws1.cell(row1,4).value = round(data1[3],1)
120
+        ws1.cell(row1,5).value = round(data1[4],1)
121
+        ws1.cell(row1,6).value = round(data1[5],1)
122
+        if data1[6] == '稳定':
123
+            ws1.cell(row1,7).value = ''
124
+        else:
125
+            ws1.cell(row1,7).value = data1[6]
126
+        row1 = row1 + 1
127
+
128
+    #ws2部分(复测成果表)
129
+    #提取数据
130
+    sqlstr1 = 'select PointName,Last_X,Last_Y,Result_X,Result_Y,Last_ResultX,Last_ResultY,Last_ResultP,Dis_Ass,Last_ResultName,New_ResultName from GS_Result_Point WHERE TableName = ?'
131
+    cursor1.execute(sqlstr1,(utf_en,))
132
+    #获取结果集
133
+    result2 = cursor1.fetchall()
134
+    #整理数据
135
+    plist2 = Arrange_Data2(result2)
136
+    ws2.column_dimensions['A'].width = 5
137
+    ws2.column_dimensions['B'].width = 15
138
+    ws2.column_dimensions['C'].width = 15
139
+    ws2.column_dimensions['D'].width = 15
140
+    ws2.column_dimensions['E'].width = 15
141
+    ws2.column_dimensions['F'].width = 8
142
+    ws2.column_dimensions['G'].width = 8
143
+    ws2.column_dimensions['H'].width = 8
144
+    ws2.column_dimensions['I'].width = 5
145
+    ws2.merge_cells(start_row=1, end_row=1,
146
+                    start_column=1, end_column=3)
147
+    ws2.cell(1, 1).value = '前期成果'
148
+    ws2.merge_cells(start_row=1, end_row=1,
149
+                    start_column=4, end_column=9)
150
+    ws2.cell(1, 4).value = '本期成果'
151
+    ws_area = ws2["A1:I2"]
152
+    alignment_center = Alignment(horizontal='center', vertical='center')# 指定区域单元格居中
153
+    for i in ws_area:
154
+        for j in i:
155
+            j.alignment = alignment_center
156
+    alignment_right = Alignment(horizontal='right', vertical='center')
157
+    ws2.merge_cells(start_row=2, end_row=3,
158
+                    start_column=1, end_column=1)
159
+    ws2.cell(2, 1).value = '点名'
160
+    ws2.merge_cells(start_row=2, end_row=2,
161
+                    start_column=2, end_column=3)
162
+    ws2.cell(2, 2).value = plist2[0][9]
163
+    ws2.merge_cells(start_row=2, end_row=2,
164
+                    start_column=4, end_column=5)
165
+    ws2.cell(2, 4).value = plist2[0][10]
166
+    ws2.merge_cells(start_row=2, end_row=2,
167
+                    start_column=6, end_column=8)
168
+    newname_1 = plist2[0][9] + '-' + plist2[0][10] + '(mm)'
169
+    ws2.cell(2, 6).value = newname_1
170
+    ws2.merge_cells(start_row=2, end_row=3,
171
+                    start_column=9, end_column=9)
172
+    ws2.cell(2, 9).value = '位移判定'
173
+    ws2.cell(2, 9).alignment = Alignment(wrap_text=True)
174
+    ws2.cell(3, 2).value = 'X(m)'
175
+    ws2.cell(3, 3).value = 'Y(m)'
176
+    ws2.cell(3, 4).value = 'X(m)'
177
+    ws2.cell(3, 5).value = 'Y(m)'
178
+    ws2.cell(3, 6).value = '△X'
179
+    ws2.cell(3, 7).value = '△Y'
180
+    ws2.cell(3, 8).value = '△XY'
181
+    row2 = 4
182
+    for data2 in plist2:
183
+        ws2.cell(row2,1).value = data2[0]
184
+        ws2.cell(row2,2).value = round(data2[1],4)
185
+        ws2.cell(row2,3).value = round(data2[2],4)
186
+        ws2.cell(row2,4).value = round(data2[3],4)
187
+        ws2.cell(row2,5).value = round(data2[4],4)
188
+        ws2.cell(row2,6).value = round(data2[5],1)
189
+        ws2.cell(row2,7).value = round(data2[6],1)
190
+        ws2.cell(row2,8).value = round(data2[7],1)
191
+        if data2[8] == '稳定':
192
+            ws2.cell(row2,9).value = ''
193
+        else:
194
+            ws2.cell(row2,9).value = data2[8]
195
+        row2 = row2 + 1
196
+    
197
+    #ws3部分(公式)
198
+    #提取数据
199
+    sqlstr2 = 'select Last_ResultName,New_ResultName,Formula_X1,Formula_X2,Formula_X3,Formula_Y1,Formula_Y2,Formula_Y3 from GS_Trans_Param WHERE TableName = ?'
200
+    cursor1.execute(sqlstr2,(utf_en,))
201
+    #获取结果集
202
+    result3 = cursor1.fetchall() 
203
+    newname = result3[0][1].decode('utf-8')
204
+    lastname = result3[0][0].decode('utf-8')
205
+    ws3.column_dimensions['A'].width = 75
206
+    ws_area = ws3["A1:A5"]
207
+    alignment_center = Alignment(horizontal='left', vertical='center')# 指定区域单元格居中
208
+    for i in ws_area:
209
+        for j in i:
210
+            j.alignment = alignment_center
211
+    str1 = newname + '--' + lastname + '已知系统转换公式:'
212
+    ws3.cell(1, 1).value = str1
213
+    str2 = 'X=(' + str(round(result3[0][2],14)) + ')·x+(' + str(round(result3[0][3],14)) + ')·y+(' + str(round(result3[0][4],11)) + ')'
214
+    ws3.cell(2, 1).value = str2
215
+    str3 = 'Y=(' + str(round(result3[0][5],14)) + ')·x+(' + str(round(result3[0][6],14)) + ')·y+(' + str(round(result3[0][7],11)) + ')'
216
+    ws3.cell(3, 1).value = str3
217
+    str4 = '式中:x、y为' + newname
218
+    ws3.cell(4, 1).value = str4
219
+    str5 = '     X、Y为' + lastname + '已知系统的' + newname + '归算坐标'
220
+    ws3.cell(5, 1).value = str5
221
+    #保存
222
+    wb.save(outpath)
223
+    
224
+
225
+# 主函数 写入excel文件
226
+def main_function(outpath,dbpath,file_path):
227
+    dbpath = r"D:\4work_now\20240819GS\ControlNetwork\ControlNetwork\UI\SQL\DataBase.db"
228
+    outpath = r'D:\4work_now\20240819GS\JPG\GS成果表.xlsx'
229
+    file_path = r'D:\4work_now\20240819GS\二滩_20240816.xls'
230
+    file_name = os.path.basename(file_path)
231
+    # outpath为包含输出excel名字的全路径
232
+    openpyxl_write(outpath,dbpath,file_name)
233
+# dbpath = r"D:\4work_now\20240819GS\ControlNetwork\ControlNetwork\UI\SQL\DataBase.db"
234
+# outpath = r'D:\4work_now\20240819GS\JPG\GS成果表.xlsx'
235
+# file_path = r'D:\4work_now\20240819GS\二滩_20240816.xls'
236
+# file_name = os.path.basename(file_path)
237
+# # outpath为包含输出excel名字的全路径
238
+# openpyxl_write(outpath,dbpath,file_name)

+ 9
- 1
Back/Program_Run/file_system_watching.py Wyświetl plik

4
 from watchdog.observers import Observer
4
 from watchdog.observers import Observer
5
 import os
5
 import os
6
 
6
 
7
+
7
 class ComboBoxUpdater(FileSystemEventHandler):
8
 class ComboBoxUpdater(FileSystemEventHandler):
8
     def __init__(self, comboBox, sql_folder):
9
     def __init__(self, comboBox, sql_folder):
9
         super().__init__()
10
         super().__init__()
10
         self.comboBox = comboBox
11
         self.comboBox = comboBox
11
         self.sql_folder = sql_folder
12
         self.sql_folder = sql_folder
13
+        self.selected_db = None  # 新增属性来存储当前选中的数据库
12
 
14
 
13
     def on_modified(self, event):
15
     def on_modified(self, event):
14
         if event.is_directory:
16
         if event.is_directory:
29
             self.update_combo_box()
31
             self.update_combo_box()
30
 
32
 
31
     def update_combo_box(self):
33
     def update_combo_box(self):
34
+        # 保存当前选中的数据库
35
+        self.selected_db = self.comboBox.currentText()
32
         # 清空现有的 comboBox 内容
36
         # 清空现有的 comboBox 内容
33
         self.comboBox.clear()
37
         self.comboBox.clear()
34
 
38
 
42
 
46
 
43
         # 如果没有找到任何数据库文件,显示提示信息
47
         # 如果没有找到任何数据库文件,显示提示信息
44
         if not db_files:
48
         if not db_files:
45
-            self.comboBox.addItem(QCoreApplication.translate("MainWindow", "未找到数据库文件", None))
49
+            self.comboBox.addItem(QCoreApplication.translate("MainWindow", "未找到数据库文件", None))
50
+
51
+        # 重新设置之前选中的数据库为选中状态
52
+        if self.selected_db in [self.comboBox.itemText(i) for i in range(self.comboBox.count())]:
53
+            self.comboBox.setCurrentText(self.selected_db)

+ 201
- 0
Back/WD/WDExport.py Wyświetl plik

1
+import openpyxl
2
+import sqlite3
3
+import os
4
+from openpyxl.styles import Alignment
5
+
6
+def Arrange_Data1(list1):
7
+    #最终return的
8
+    list2 = []
9
+    for data1 in list1:
10
+        #点名
11
+        #存每一行的数据
12
+        resultlist = []
13
+        pn = data1[0].decode('utf-8')
14
+        resultlist.append(pn)
15
+        resultlist.append(data1[1])
16
+        resultlist.append(data1[2])
17
+        resultlist.append(data1[3])
18
+        resultlist.append(data1[4])
19
+        resultlist.append(data1[5])
20
+        resultlist.append(data1[6])
21
+        resultlist.append(data1[7])
22
+        resultlist.append(data1[8])
23
+        resultlist.append(data1[9])
24
+        resultlist.append(data1[10])
25
+        resultlist.append(data1[11])
26
+        #判定1
27
+        an1 = data1[12].decode('utf-8')
28
+        resultlist.append(an1)
29
+        resultlist.append(data1[13])
30
+        resultlist.append(data1[14])
31
+        resultlist.append(data1[15])
32
+        #判定2
33
+        an2 = data1[16].decode('utf-8')
34
+        resultlist.append(an2)
35
+        #3个名字(首,上,新)
36
+        name1 = data1[17].decode('utf-8')
37
+        resultlist.append(name1)
38
+        name2 = data1[18].decode('utf-8')
39
+        resultlist.append(name2)
40
+        name3 = data1[19].decode('utf-8')
41
+        resultlist.append(name3)
42
+        list2.append(resultlist)
43
+    
44
+    return list2
45
+
46
+def openpyxl_write(outpath,dbpath,filename):
47
+    utf_en = filename.encode('utf-8')
48
+    #新建对应的excel
49
+    wb = openpyxl.Workbook()
50
+    ws1 = wb.create_sheet('稳定性分析成果表')
51
+    ws2 = wb.create_sheet('改算模型')
52
+    ws3 = wb['Sheet']
53
+    wb.remove(ws3)
54
+
55
+    #ws1部分(成果表)
56
+    #提取数据
57
+    db1 = sqlite3.connect(dbpath)
58
+    #获取游标
59
+    cursor1 = db1.cursor()
60
+    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,First_ResultName,Last_ResultName,New_ResultName from WD_Result_Point WHERE TableName = ?'
61
+    cursor1.execute(sqlstr1,(utf_en,))
62
+    #获取结果集
63
+    result1 = cursor1.fetchall()
64
+    #整理数据
65
+    plist1 = Arrange_Data1(result1)
66
+    ws1.column_dimensions['B'].width = 15
67
+    ws1.column_dimensions['C'].width = 15
68
+    ws1.column_dimensions['D'].width = 15
69
+    ws1.column_dimensions['E'].width = 15
70
+    ws1.column_dimensions['F'].width = 5
71
+    ws1.column_dimensions['G'].width = 15
72
+    ws1.column_dimensions['H'].width = 15
73
+    ws1.column_dimensions['I'].width = 5
74
+    ws1.column_dimensions['M'].width = 5
75
+    ws1.column_dimensions['Q'].width = 5
76
+    ws1.column_dimensions['J'].width = 8
77
+    ws1.column_dimensions['K'].width = 8
78
+    ws1.column_dimensions['L'].width = 8
79
+    ws1.column_dimensions['N'].width = 8
80
+    ws1.column_dimensions['O'].width = 8
81
+    ws1.column_dimensions['P'].width = 8
82
+    ws1.merge_cells(start_row=1, end_row=1,
83
+                    start_column=1, end_column=17)
84
+    ws1.cell(1, 1).value = '稳定性分析成果表'
85
+    ws_area = ws1["A1:Q2"]
86
+    alignment_center = Alignment(horizontal='center', vertical='center')# 指定区域单元格居中
87
+    for i in ws_area:
88
+        for j in i:
89
+            j.alignment = alignment_center
90
+    alignment_right = Alignment(horizontal='right', vertical='center')
91
+    ws1.merge_cells(start_row=2, end_row=3,
92
+                    start_column=1, end_column=1)
93
+    ws1.cell(2, 1).value = '点号'
94
+    ws1.merge_cells(start_row=2, end_row=2,
95
+                    start_column=2, end_column=3)
96
+    ws1.cell(2, 2).value = plist1[0][17]
97
+    ws1.merge_cells(start_row=2, end_row=2,
98
+                    start_column=4, end_column=6)
99
+    ws1.cell(2, 4).value = plist1[0][18]
100
+    ws1.merge_cells(start_row=2, end_row=2,
101
+                    start_column=7, end_column=9)
102
+
103
+    ws1.cell(2, 7).value = plist1[0][19]
104
+    ws1.merge_cells(start_row=2, end_row=2,
105
+                    start_column=10, end_column=12)
106
+    ws1.cell(2, 10).value = '本期-首期(mm)'
107
+    ws1.merge_cells(start_row=2, end_row=3,
108
+                    start_column=13, end_column=13)
109
+    ws1.cell(2, 13).value = '变形判定'
110
+    ws1.merge_cells(start_row=2, end_row=2,
111
+                    start_column=14, end_column=16)
112
+    ws1.cell(2, 14).value = '本期-上期(mm)'
113
+    ws1.merge_cells(start_row=2, end_row=3,
114
+                    start_column=17, end_column=17)
115
+    ws1.cell(2, 17).value = '变形判定'
116
+    ws1.cell(2, 13).alignment = Alignment(wrap_text=True)
117
+    ws1.cell(2, 17).alignment = Alignment(wrap_text=True)
118
+    ws1.cell(3, 2).value = 'X(m)'
119
+    ws1.cell(3, 3).value = 'Y(m)'
120
+    ws1.cell(3, 4).value = 'X(m)'
121
+    ws1.cell(3, 5).value = 'Y(m)'
122
+    ws1.cell(3, 6).value = '权'
123
+    ws1.cell(3, 7).value = 'X(m)'
124
+    ws1.cell(3, 8).value = 'Y(m)'
125
+    ws1.cell(3, 9).value = '权'
126
+    ws1.cell(3, 10).value = '△X'
127
+    ws1.cell(3, 11).value = '△Y'
128
+    ws1.cell(3, 12).value = '△XY'
129
+    ws1.cell(3, 14).value = '△X'
130
+    ws1.cell(3, 15).value = '△Y'
131
+    ws1.cell(3, 16).value = '△XY'
132
+
133
+    row1 = 4
134
+    for data1 in plist1:
135
+        ws1.cell(row1,1).value = data1[0]
136
+        ws1.cell(row1,2).value = round(data1[1],4)
137
+        ws1.cell(row1,3).value = round(data1[2],4)
138
+        ws1.cell(row1,4).value = round(data1[3],4)
139
+        ws1.cell(row1,5).value = round(data1[4],4)
140
+        ws1.cell(row1,6).value = int(data1[5])
141
+        ws1.cell(row1,7).value = round(data1[6],4)
142
+        ws1.cell(row1,8).value = round(data1[7],4)
143
+        ws1.cell(row1,9).value = int(data1[8])
144
+        ws1.cell(row1,10).value = round(data1[9],1)
145
+        ws1.cell(row1,11).value = round(data1[10],1)
146
+        ws1.cell(row1,12).value = round(data1[11],1)
147
+        if data1[12] == '稳定':
148
+            ws1.cell(row1,13).value = ''
149
+        else:
150
+            ws1.cell(row1,13).value = data1[12]
151
+        ws1.cell(row1,14).value = round(data1[13],1)
152
+        ws1.cell(row1,15).value = round(data1[14],1)
153
+        ws1.cell(row1,16).value = round(data1[15],1)
154
+        if data1[16] == '稳定':
155
+            ws1.cell(row1,17).value = ''
156
+        else:
157
+            ws1.cell(row1,17).value = data1[16]
158
+        row1 = row1 + 1
159
+
160
+    #ws2部分(公式)
161
+    #提取数据
162
+    sqlstr2 = 'select Last_ResultName,New_ResultName,Formula_X1,Formula_X2,Formula_X3,Formula_Y1,Formula_Y2,Formula_Y3 from WD_Result_Param WHERE TableName = ?'
163
+    cursor1.execute(sqlstr2,(utf_en,))
164
+    #获取结果集
165
+    result3 = cursor1.fetchall() 
166
+    newname = result3[0][1].decode('utf-8')
167
+    lastname = result3[0][0].decode('utf-8')
168
+    ws2.column_dimensions['A'].width = 75
169
+    ws_area = ws2["A1:A5"]
170
+    alignment_center = Alignment(horizontal='left', vertical='center')# 指定区域单元格居中
171
+    for i in ws_area:
172
+        for j in i:
173
+            j.alignment = alignment_center
174
+    str1 = newname + '--' + lastname + '已知系统转换公式:'
175
+    ws2.cell(1, 1).value = str1
176
+    str2 = 'X=(' + str(round(result3[0][2],14)) + ')·x+(' + str(round(result3[0][3],14)) + ')·y+(' + str(round(result3[0][4],11)) + ')'
177
+    ws2.cell(2, 1).value = str2
178
+    str3 = 'Y=(' + str(round(result3[0][5],14)) + ')·x+(' + str(round(result3[0][6],14)) + ')·y+(' + str(round(result3[0][7],11)) + ')'
179
+    ws2.cell(3, 1).value = str3
180
+    str4 = '式中:x、y为' + newname
181
+    ws2.cell(4, 1).value = str4
182
+    str5 = '     X、Y为' + lastname + '已知系统的' + newname + '归算坐标'
183
+    ws2.cell(5, 1).value = str5
184
+    #保存
185
+    wb.save(outpath)
186
+
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)

+ 8
- 1
Front/main.py Wyświetl plik

21
 import os
21
 import os
22
 import platform
22
 import platform
23
 
23
 
24
+import Back.Program_Run.database_operations
24
 # IMPORT / GUI AND MODULES AND WIDGETS
25
 # IMPORT / GUI AND MODULES AND WIDGETS
25
 # ///////////////////////////////////////////////////////////////
26
 # ///////////////////////////////////////////////////////////////
26
 from modules import *
27
 from modules import *
66
         # ///////////////////////////////////////////////////////////////
67
         # ///////////////////////////////////////////////////////////////
67
         self.ui = Ui_MainWindow()
68
         self.ui = Ui_MainWindow()
68
         self.ui.setupUi(self)
69
         self.ui.setupUi(self)
70
+        self.ui.createFile.clicked.connect(self.on_create_file_clicked)
69
         # self.comboBox_2 = QComboBox(self)
71
         # self.comboBox_2 = QComboBox(self)
70
         # ...此处为省略代码...
72
         # ...此处为省略代码...
71
         global widgets
73
         global widgets
245
             # 触发按钮点击事件
247
             # 触发按钮点击事件
246
             btn.click()
248
             btn.click()
247
 
249
 
250
+
251
+    # 新增槽函数来调用 create_database_and_tables
252
+    def on_create_file_clicked(self):
253
+        Back.Program_Run.database_operations.create_database_and_tables(self.ui)
254
+
248
     # RESIZE EVENTS
255
     # RESIZE EVENTS
249
     # ///////////////////////////////////////////////////////////////
256
     # ///////////////////////////////////////////////////////////////
250
     def resizeEvent(self, event):
257
     def resizeEvent(self, event):
270
     app.setWindowIcon(QIcon("icon.ico"))
277
     app.setWindowIcon(QIcon("icon.ico"))
271
     window = MainWindow()
278
     window = MainWindow()
272
     # window.resize(1440, 960)  # 高宽
279
     # window.resize(1440, 960)  # 高宽
273
-    sys.exit(app.exec_())
280
+    sys.exit(app.exec())

+ 223
- 3
Front/main_new.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
-from PySide6.QtWidgets import QFileDialog
17
-from PySide6.QtCore import Signal, Slot
16
+from PySide6.QtWidgets import QFileDialog,QWidget, QVBoxLayout, QTreeWidget, QApplication, QTreeWidgetItem
17
+from PySide6.QtCore import Signal,  Qt, Slot, QObject
18
 from PySide6.QtSql import QSqlTableModel,QSqlDatabase
18
 from PySide6.QtSql import QSqlTableModel,QSqlDatabase
19
 import sqlite3
19
 import sqlite3
20
+from PySide6.QtGui import QIcon
20
 
21
 
21
 
22
 
22
 import sys
23
 import sys
65
             return self._data[index.row()][index.column()]
66
             return self._data[index.row()][index.column()]
66
         return None
67
         return None
67
 
68
 
69
+class TreeWidgetItem:
70
+    def __init__(self, id: any, parent_id: any, name: str, icon: QIcon = None, extend: object = None):
71
+        """
72
+        菜单数据接口
73
+        :param id: ID
74
+        :param parent_id: 父ID
75
+        :param name: 菜单名称
76
+        :param icon: 图标
77
+        :param extend: 扩展数据
78
+        """
79
+        self.id: any = id
80
+        self.parent_id: any = parent_id
81
+        self.name: str = name
82
+        self.extend: object = extend
83
+        # 实例化
84
+        self.treeWidgetItem = QTreeWidgetItem([self.name])
85
+        # 存储相关数据
86
+        self.treeWidgetItem.setData(0, Qt.UserRole + 1, extend)
87
+        self.treeWidgetItem.setIcon(0, QIcon(':/icons/default.png'))
88
+        if icon is not None:
89
+            self.treeWidgetItem.setIcon(0, icon)
90
+
91
+class ElTreeData(QObject):
92
+    """
93
+    Data Model
94
+    """
95
+    items_changed: Signal = Signal(str)
96
+    styleSheet_changed: Signal = Signal(str)
97
+ 
98
+    def __init__(self, items: list[TreeWidgetItem] = None, styleSheet: str = None):
99
+        super(ElTreeData, self).__init__()
100
+        # 定义数据
101
+        self._items: list[TreeWidgetItem]
102
+        self._styleSheet: str
103
+        # 初始化数据
104
+        self.items = items
105
+        self.styleSheet = styleSheet
106
+ 
107
+    @property
108
+    def items(self):
109
+        return self._items
110
+ 
111
+    @items.setter
112
+    def items(self, value):
113
+        self._items = value
114
+        # 数据改变时发出信号
115
+        self.items_changed.emit(self.items)
116
+ 
117
+    @property
118
+    def styleSheet(self):
119
+        return self._styleSheet
120
+ 
121
+    @styleSheet.setter
122
+    def styleSheet(self, value):
123
+        self._styleSheet = value
124
+        # 数据改变时发出信号
125
+        self.styleSheet_changed.emit(self.styleSheet)
126
+
127
+
68
 class MainWindow(QMainWindow):
128
 class MainWindow(QMainWindow):
69
     def __init__(self):
129
     def __init__(self):
70
         QMainWindow.__init__(self)
130
         QMainWindow.__init__(self)
132
 
192
 
133
         widgets.settingsTopBtn.clicked.connect(openCloseRightBox)
193
         widgets.settingsTopBtn.clicked.connect(openCloseRightBox)
134
 
194
 
195
+
196
+
197
+
135
         # 展示APP
198
         # 展示APP
136
         # ///////////////////////////////////////////////////////////////
199
         # ///////////////////////////////////////////////////////////////
137
         self.show()
200
         self.show()
145
         useCustomTheme = True
208
         useCustomTheme = True
146
         self.useCustomTheme = useCustomTheme
209
         self.useCustomTheme = useCustomTheme
147
         self.absPath = absPath
210
         self.absPath = absPath
148
-        themeFile = r"Front\themes\py_dracula_light.qss"
211
+        # themeFile = r"Front\themes\py_dracula_light.qss"
212
+        themeFile = r"D:\4work_now\20240819GS\20241211\Front\themes\py_dracula_light.qss"
149
 
213
 
150
         # 设置主题和HACKS
214
         # 设置主题和HACKS
151
         if useCustomTheme:
215
         if useCustomTheme:
159
         # ///////////////////////////////////////////////////////////////
223
         # ///////////////////////////////////////////////////////////////
160
         widgets.stackedWidget.setCurrentWidget(widgets.home)
224
         widgets.stackedWidget.setCurrentWidget(widgets.home)
161
         widgets.btn_home.setStyleSheet(UIFunctions.selectMenu(widgets.btn_home.styleSheet()))
225
         widgets.btn_home.setStyleSheet(UIFunctions.selectMenu(widgets.btn_home.styleSheet()))
226
+
227
+        #初始化树状组件
228
+        #///////////////////////////////////////////////////////////////
229
+        self.itemClicked: Signal = Signal(object)
230
+        self.itemDoubleClicked: Signal = Signal(object)
231
+        sqll = self.sql_init()
232
+        sqltree = ElTreeData(items=sqll)
233
+        self.data = sqltree
234
+        # 将按钮的点击信号绑定到当前类的点击信号
235
+        # 信号改为展示方法,这里同导出展示
236
+        widgets.allTreeWidget.itemClicked.connect(lambda extend: print("单击->扩展数据为:", extend))
237
+        widgets.allTreeWidget.itemDoubleClicked.connect(lambda extend: print("双击->扩展数据为:", extend))
238
+        self.__render_items(True)
239
+
162
         self.bind()
240
         self.bind()
163
 
241
 
242
+
243
+    def __render_items(self, is_clear: bool):
244
+        if is_clear:
245
+            widgets.allTreeWidget.clear()
246
+        widgets.allTreeWidget.setColumnCount(1)
247
+        widgets.allTreeWidget.setHeaderHidden(True)
248
+        if self.data.items is not None:
249
+            # 转为字典
250
+            mapping: dict[any, TreeWidgetItem] = dict(zip([i.id for i in self.data.items], self.data.items))
251
+            # 树容器
252
+            treeWidgetItems: list[QTreeWidgetItem] = []
253
+            for d in self.data.items:
254
+                # 如果找不到父级项,则是根节点
255
+                parent: TreeWidgetItem = mapping.get(d.parent_id)
256
+                if parent is None:
257
+                    treeWidgetItems.append(d.treeWidgetItem)
258
+                else:
259
+                    parent.treeWidgetItem.addChild(d.treeWidgetItem)
260
+
261
+            # 挂载到树上
262
+            widgets.allTreeWidget.insertTopLevelItems(0, treeWidgetItems)
263
+
264
+
164
     #绑定组件
265
     #绑定组件
165
     def bind(self):
266
     def bind(self):
166
         # 计算
267
         # 计算
167
         widgets.compute.clicked.connect(self.computeClick)
268
         widgets.compute.clicked.connect(self.computeClick)
269
+        widgets.search.clicked.connect(self.searchClick)
168
 
270
 
169
     #删除tableview
271
     #删除tableview
170
     def delete_table_view(table_view):
272
     def delete_table_view(table_view):
414
             xx = xx + 1 
516
             xx = xx + 1 
415
         return model
517
         return model
416
 
518
 
519
+    #设一个全局变量,存数据库中所有的包含内容(数据库-三种方法-表)
520
+    dblist = []
521
+    global dblist
522
+    #初始化数据一览(数据库全展示)
523
+    def sql_init(self):
524
+        #初始化全部数据库
525
+        inpath = r'D:\4work_now\20240819GS\20241211\SQL'
526
+        #读取所有的数据库名
527
+        sqlitem = []
528
+        id = 1
529
+        for filename in os.listdir(inpath):
530
+            #数据库
531
+            dbname = filename.split('.',-1)[0]
532
+            dbpath = os.path.join(inpath,filename)
533
+            sqlitem.append(TreeWidgetItem(id,0,dbname,icon=QIcon("D:/4work_now/20240819GS/20241211/Front/images/icons/cil-clone.png")))
534
+            pid = id
535
+            id = id + 1
536
+            #三种方法
537
+            sqlitem.append(TreeWidgetItem(id, pid, '水准测段高差稳定计算', icon=QIcon("D:/4work_now/20240819GS/20241211/Front/images/icons/cil-description.png")))
538
+            gcid = id
539
+            id = id + 1
540
+            sqlitem.append(TreeWidgetItem(id, pid, '控制网复测平面基准计算', icon=QIcon("D:/4work_now/20240819GS/20241211/Front/images/icons/cil-description.png")))
541
+            gsid = id
542
+            id = id + 1
543
+            sqlitem.append(TreeWidgetItem(id, pid, '平面控制网稳定性计算', icon=QIcon("D:/4work_now/20240819GS/20241211/Front/images/icons/cil-description.png")))
544
+            wdid = id
545
+            id = id + 1
546
+            #读取所有的表名(三种方式往下)
547
+            db1 = sqlite3.connect(dbpath)
548
+            #获取游标
549
+            cursor1 = db1.cursor()
550
+            sqlstr1 = 'SELECT TableName FROM GC_Input_Param;'
551
+            cursor1.execute(sqlstr1)
552
+            result1 = cursor1.fetchall()
553
+            for re1 in result1:
554
+                str1 = re1[0].decode('utf-8')
555
+                sqlitem.append(TreeWidgetItem(id, gcid, str1, icon=QIcon("D:/4work_now/20240819GS/20241211/Front/images/icons/cil-file.png"),extend=str1))
556
+                list1 = []
557
+                list1.append(dbname)
558
+                list1.append('水准测段高差稳定计算')
559
+                list1.append(str1)
560
+                dblist.append(list1)
561
+                id = id + 1
562
+            sqlstr2 = 'SELECT TableName FROM GS_Input_Param;'
563
+            cursor1.execute(sqlstr2)
564
+            result2 = cursor1.fetchall()
565
+            for re2 in result2:
566
+                str2 = re2[0].decode('utf-8')
567
+                sqlitem.append(TreeWidgetItem(id, gsid, str2, icon=QIcon("D:/4work_now/20240819GS/20241211/Front/images/icons/cil-file.png"),extend=str2))
568
+                list2 = []
569
+                list2.append(dbname)
570
+                list2.append('控制网复测平面基准计算')
571
+                list2.append(str2)
572
+                dblist.append(list2)
573
+                id = id + 1
574
+            sqlstr3 = 'SELECT TableName FROM WD_Input_Param;'
575
+            cursor1.execute(sqlstr3)
576
+            result3 = cursor1.fetchall()
577
+            for re3 in result3:
578
+                str3 = re3[0].decode('utf-8')
579
+                sqlitem.append(TreeWidgetItem(id, wdid, str3, icon=QIcon("D:/4work_now/20240819GS/20241211/Front/images/icons/cil-file.png"),extend=str3))
580
+                list3 = []
581
+                list3.append(dbname)
582
+                list3.append('平面控制网稳定性计算')
583
+                list3.append(str3)
584
+                dblist.append(list3)
585
+                id = id + 1
586
+        return sqlitem
587
+
588
+    #关键词查询
589
+    def sql_search(self):
590
+        # GET BUTTON CLICKED
591
+        btn = self.sender()
592
+        btnName = btn.objectName()
593
+        #获取文本
594
+        text1 = self.ui.lineEdit_2.text()
595
+        #符合的list
596
+        fhlist = []
597
+        #查询(待优化)
598
+        for list1 in dblist:
599
+            for li in list1:
600
+                if text1 in li:
601
+                    fhlist.append(list1)
602
+                    break
603
+        #更新item值
604
+        sqlitem = []
605
+        #前两层是否一致
606
+        str1 = ''
607
+        str2 = ''
608
+        id = 1
609
+        pid = 0
610
+        fid = 0
611
+        for list2 in fhlist:
612
+            dbname = list2[0]
613
+            if dbname != str1:
614
+                str1 = dbname
615
+                sqlitem.append(TreeWidgetItem(id, 0, dbname, icon=QIcon(
616
+                    "D:/4work_now/20240819GS/20241211/Front/images/icons/cil-clone.png")))
617
+                pid = id
618
+            id = id + 1
619
+            mename = list2[1]
620
+            if mename != str2:
621
+                str2 = mename
622
+                sqlitem.append(TreeWidgetItem(id, pid, mename, icon=QIcon(
623
+                    "D:/4work_now/20240819GS/20241211/Front/images/icons/cil-description.png")))
624
+                fid = id
625
+            id = id + 1
626
+            sqlitem.append(TreeWidgetItem(id, fid, list2[2], icon=QIcon(
627
+                "D:/4work_now/20240819GS/20241211/Front/images/icons/cil-file.png"), extend=list2[2]))
628
+        #展示
629
+
630
+
631
+
632
+
633
+
634
+
635
+
636
+    #直接这个基础上改点选输出表格(未改)
417
     def computeClick(self):
637
     def computeClick(self):
418
         # GET BUTTON CLICKED
638
         # GET BUTTON CLICKED
419
         btn = self.sender()
639
         btn = self.sender()

+ 17
- 3
Front/modules/ui_functions.py Wyświetl plik

296
     # 上传文件的方法
296
     # 上传文件的方法
297
     def execute_script_based_on_selection(self, file_path):
297
     def execute_script_based_on_selection(self, file_path):
298
         current_text = self.ui.comboBox_2.currentText()
298
         current_text = self.ui.comboBox_2.currentText()
299
-        db_path = r"D:/Code/ControlNetwork/UI/SQL/DataBase.db"
299
+        # db_path = r"D:/Code/ControlNetwork/UI/SQL/DataBase.db"
300
+        # 获取当前脚本所在的目录
301
+        current_dir = os.path.dirname(os.path.abspath(__file__))
302
+        # 构建 SQL 文件夹的相对路径(上一级的上一级中的 SQL 文件夹)
303
+        sql_folder = os.path.join(current_dir, '..', '..', 'SQL')
304
+        # 将相对路径转换为绝对路径
305
+        sql_folder = os.path.abspath(sql_folder)
306
+        db_path = os.path.join(sql_folder, f"{self.ui.comboBox.currentText()}.db")
300
         file_path = file_path
307
         file_path = file_path
301
         if current_text == "水准测段高差稳定计算":
308
         if current_text == "水准测段高差稳定计算":
302
             GC.main_function(file_path, db_path)
309
             GC.main_function(file_path, db_path)
311
     # 计算与展示文件的方法
318
     # 计算与展示文件的方法
312
     def compute_show_process_excel_file(self, file_path):
319
     def compute_show_process_excel_file(self, file_path):
313
         current_text = self.ui.comboBox_2.currentText()
320
         current_text = self.ui.comboBox_2.currentText()
314
-        db_path = r"D:/Code/ControlNetwork/UI/SQL/DataBase.db"
315
-        #转换为utf-8
321
+        # db_path = r"D:/Code/ControlNetwork/UI/SQL/DataBase.db"
322
+        # 获取当前脚本所在的目录
323
+        current_dir = os.path.dirname(os.path.abspath(__file__))
324
+        # 构建 SQL 文件夹的相对路径(上一级的上一级中的 SQL 文件夹)
325
+        sql_folder = os.path.join(current_dir, '..', '..', 'SQL')
326
+        # 将相对路径转换为绝对路径
327
+        sql_folder = os.path.abspath(sql_folder)
328
+        db_path = os.path.join(sql_folder, f"{self.ui.comboBox.currentText()}.db")
329
+        # 转换为utf-8
316
         excelname = os.path.basename(file_path)
330
         excelname = os.path.basename(file_path)
317
         utf_en = excelname.encode('utf-8')
331
         utf_en = excelname.encode('utf-8')
318
         if current_text == "水准测段高差稳定计算":
332
         if current_text == "水准测段高差稳定计算":

+ 12
- 8
Front/modules/ui_main.py Wyświetl plik

8
 ## WARNING! All changes made in this file will be lost when recompiling UI file!
8
 ## WARNING! All changes made in this file will be lost when recompiling UI file!
9
 ################################################################################
9
 ################################################################################
10
 
10
 
11
+import sys
12
+sys.path.append("../..")
13
+
11
 import sqlite3
14
 import sqlite3
12
 import os
15
 import os
13
 from PySide6.QtCore import (QCoreApplication, QDate, QDateTime, QLocale,
16
 from PySide6.QtCore import (QCoreApplication, QDate, QDateTime, QLocale,
21
                                QFrame, QGridLayout, QHBoxLayout, QHeaderView,
24
                                QFrame, QGridLayout, QHBoxLayout, QHeaderView,
22
                                QLabel, QLineEdit, QListView, QMainWindow,
25
                                QLabel, QLineEdit, QListView, QMainWindow,
23
                                QPushButton, QSizePolicy, QStackedWidget, QTabWidget,
26
                                QPushButton, QSizePolicy, QStackedWidget, QTabWidget,
24
-                               QTableView, QTextEdit, QVBoxLayout, QWidget, QMessageBox)
27
+                               QTableView, QTextEdit, QVBoxLayout, QWidget, QMessageBox,QTreeWidget)
25
 from Back.Program_Run.data_show import Arrange_Data, Arrange_Data1, Arrange_Data2, Data_in_Cell, Data_in_Cell1, Data_in_Cell2
28
 from Back.Program_Run.data_show import Arrange_Data, Arrange_Data1, Arrange_Data2, Data_in_Cell, Data_in_Cell1, Data_in_Cell2
26
 from Back.Program_Run.database_operations import create_database_and_tables
29
 from Back.Program_Run.database_operations import create_database_and_tables
27
 from Back.Program_Run.file_system_watching import ComboBoxUpdater
30
 from Back.Program_Run.file_system_watching import ComboBoxUpdater
30
 from .resources_rc import *
33
 from .resources_rc import *
31
 
34
 
32
 
35
 
36
+
33
 # class ComboBoxUpdater(FileSystemEventHandler):
37
 # class ComboBoxUpdater(FileSystemEventHandler):
34
 #     def __init__(self, comboBox, sql_folder):
38
 #     def __init__(self, comboBox, sql_folder):
35
 #         super().__init__()
39
 #         super().__init__()
1384
         self.createFile.setCursor(QCursor(Qt.CursorShape.PointingHandCursor))
1388
         self.createFile.setCursor(QCursor(Qt.CursorShape.PointingHandCursor))
1385
         self.createFile.setStyleSheet(u"background-color: rgb(52, 59, 72);")
1389
         self.createFile.setStyleSheet(u"background-color: rgb(52, 59, 72);")
1386
         # 将 createFile 按钮的点击事件与 自身的create_database_and_tables 函数关联,用于创建数据库
1390
         # 将 createFile 按钮的点击事件与 自身的create_database_and_tables 函数关联,用于创建数据库
1387
-        self.createFile.clicked.connect(create_database_and_tables)
1391
+        # self.createFile.clicked.connect(create_database_and_tables)
1388
         icon4 = QIcon()
1392
         icon4 = QIcon()
1389
         icon4.addFile(u":/icons/images/icons/cil-folder-open.png", QSize(), QIcon.Mode.Normal, QIcon.State.Off)
1393
         icon4.addFile(u":/icons/images/icons/cil-folder-open.png", QSize(), QIcon.Mode.Normal, QIcon.State.Off)
1390
         self.createFile.setIcon(icon4)
1394
         self.createFile.setIcon(icon4)
1658
 
1662
 
1659
         self.verticalLayout_24.addWidget(self.comboBox_3)
1663
         self.verticalLayout_24.addWidget(self.comboBox_3)
1660
 
1664
 
1661
-        self.qureyListView = QListView(self.datainfo)
1662
-        self.qureyListView.setObjectName(u"qureyListView")
1665
+        self.qureyTreeWidget = QTreeWidget(self.datainfo)
1666
+        self.qureyTreeWidget.setObjectName(u"qureyTreeWidget")
1663
 
1667
 
1664
-        self.verticalLayout_24.addWidget(self.qureyListView)
1668
+        self.verticalLayout_24.addWidget(self.qureyTreeWidget)
1665
 
1669
 
1666
         self.comboBox_4 = QComboBox(self.datainfo)
1670
         self.comboBox_4 = QComboBox(self.datainfo)
1667
         self.comboBox_4.setObjectName(u"comboBox_4")
1671
         self.comboBox_4.setObjectName(u"comboBox_4")
1675
 
1679
 
1676
         self.verticalLayout_24.addWidget(self.comboBox_4)
1680
         self.verticalLayout_24.addWidget(self.comboBox_4)
1677
 
1681
 
1678
-        self.allListView = QListView(self.datainfo)
1679
-        self.allListView.setObjectName(u"allListView")
1682
+        self.allTreeWidget = QTreeWidget(self.datainfo)
1683
+        self.allTreeWidget.setObjectName(u"allTreeWidget")
1680
 
1684
 
1681
-        self.verticalLayout_24.addWidget(self.allListView)
1685
+        self.verticalLayout_24.addWidget(self.allTreeWidget)
1682
 
1686
 
1683
         self.formLayout_3.setLayout(0, QFormLayout.LabelRole, self.verticalLayout_24)
1687
         self.formLayout_3.setLayout(0, QFormLayout.LabelRole, self.verticalLayout_24)
1684
 
1688
 

Ładowanie…
Anuluj
Zapisz