控制网复测平面基准归算程序(包含控制网复测平面基准计算,平面控制网稳定性计算,水准测段高差稳定计算三个程序功能)
Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

ui_functions.py 37KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828
  1. # ///////////////////////////////////////////////////////////////
  2. #
  3. # BY: WANDERSON M.PIMENTA
  4. # PROJECT MADE WITH: Qt Designer and PySide6
  5. # V: 1.0.0
  6. #
  7. # This project can be used freely for all uses, as long as they maintain the
  8. # respective credits only in the Python scripts, any information in the visual
  9. # interface (GUI) can be modified without any implication.
  10. #
  11. # There are limitations on Qt licenses if you want to use your products
  12. # commercially, I recommend reading them on the official website:
  13. # https://doc.qt.io/qtforpython/licenses.html
  14. #
  15. # ///////////////////////////////////////////////////////////////
  16. from PySide6.QtWidgets import QMessageBox
  17. from Front.back.Program_Run.utils import resource_path
  18. # MAIN FILE
  19. # ///////////////////////////////////////////////////////////////
  20. from Front.main import *
  21. import importlib
  22. import sqlite3
  23. from select import select
  24. from Front.back.GC import GC, GCExport
  25. from Front.back.GS import GS, GSExport
  26. from Front.back.WD import WD, WDExport
  27. from Front.back.GC import GCcompute
  28. from Front.back.GS import GScompute
  29. from Front.back.WD import WDcompute
  30. from Front.back.GC import GCshow
  31. from Front.back.GS import GSshow
  32. from Front.back.WD import WDshow
  33. import os
  34. from Front.main import MainWindow
  35. from Front.modules import Settings
  36. # GLOBALS
  37. # ///////////////////////////////////////////////////////////////
  38. GLOBAL_STATE = False
  39. GLOBAL_TITLE_BAR = True
  40. class UIFunctions(MainWindow):
  41. # MAXIMIZE/RESTORE
  42. # ///////////////////////////////////////////////////////////////
  43. def maximize_restore(self):
  44. global GLOBAL_STATE
  45. status = GLOBAL_STATE
  46. if status == False:
  47. self.showMaximized()
  48. GLOBAL_STATE = True
  49. self.ui.appMargins.setContentsMargins(0, 0, 0, 0)
  50. self.ui.maximizeRestoreAppBtn.setToolTip("Restore")
  51. self.ui.maximizeRestoreAppBtn.setIcon(QIcon(u":/icons/images/icons/icon_restore.png"))
  52. self.ui.frame_size_grip.hide()
  53. self.left_grip.hide()
  54. self.right_grip.hide()
  55. self.top_grip.hide()
  56. self.bottom_grip.hide()
  57. else:
  58. GLOBAL_STATE = False
  59. self.showNormal()
  60. self.resize(self.width() + 1, self.height() + 1)
  61. self.ui.appMargins.setContentsMargins(10, 10, 10, 10)
  62. self.ui.maximizeRestoreAppBtn.setToolTip("Maximize")
  63. self.ui.maximizeRestoreAppBtn.setIcon(QIcon(u":/icons/images/icons/icon_maximize.png"))
  64. self.ui.frame_size_grip.show()
  65. self.left_grip.show()
  66. self.right_grip.show()
  67. self.top_grip.show()
  68. self.bottom_grip.show()
  69. # RETURN STATUS
  70. # ///////////////////////////////////////////////////////////////
  71. def returStatus(self):
  72. return GLOBAL_STATE
  73. # SET STATUS
  74. # ///////////////////////////////////////////////////////////////
  75. def setStatus(self, status):
  76. global GLOBAL_STATE
  77. GLOBAL_STATE = status
  78. # TOGGLE MENU
  79. # ///////////////////////////////////////////////////////////////
  80. def toggleMenu(self, enable):
  81. if enable:
  82. # GET WIDTH
  83. width = self.ui.leftMenuBg.width()
  84. maxExtend = Settings.MENU_WIDTH
  85. standard = 60
  86. # SET MAX WIDTH
  87. if width == 60:
  88. widthExtended = maxExtend
  89. else:
  90. widthExtended = standard
  91. # ANIMATION
  92. self.animation = QPropertyAnimation(self.ui.leftMenuBg, b"minimumWidth")
  93. self.animation.setDuration(Settings.TIME_ANIMATION)
  94. self.animation.setStartValue(width)
  95. self.animation.setEndValue(widthExtended)
  96. self.animation.setEasingCurve(QEasingCurve.InOutQuart)
  97. self.animation.start()
  98. # TOGGLE LEFT BOX
  99. # ///////////////////////////////////////////////////////////////
  100. def toggleLeftBox(self, enable):
  101. if enable:
  102. # GET WIDTH
  103. width = self.ui.extraLeftBox.width()
  104. widthRightBox = self.ui.extraRightBox.width()
  105. maxExtend = Settings.LEFT_BOX_WIDTH
  106. color = Settings.BTN_LEFT_BOX_COLOR
  107. standard = 0
  108. # GET BTN STYLE
  109. style = self.ui.toggleLeftBox.styleSheet()
  110. # SET MAX WIDTH
  111. if width == 0:
  112. widthExtended = maxExtend
  113. # SELECT BTN
  114. self.ui.toggleLeftBox.setStyleSheet(style + color)
  115. if widthRightBox != 0:
  116. style = self.ui.settingsTopBtn.styleSheet()
  117. self.ui.settingsTopBtn.setStyleSheet(style.replace(Settings.BTN_RIGHT_BOX_COLOR, ''))
  118. else:
  119. widthExtended = standard
  120. # RESET BTN
  121. self.ui.toggleLeftBox.setStyleSheet(style.replace(color, ''))
  122. UIFunctions.start_box_animation(self, width, widthRightBox, "left")
  123. # TOGGLE RIGHT BOX
  124. # ///////////////////////////////////////////////////////////////
  125. def toggleRightBox(self, enable):
  126. if enable:
  127. # GET WIDTH
  128. width = self.ui.extraRightBox.width()
  129. widthLeftBox = self.ui.extraLeftBox.width()
  130. maxExtend = Settings.RIGHT_BOX_WIDTH
  131. color = Settings.BTN_RIGHT_BOX_COLOR
  132. standard = 0
  133. # GET BTN STYLE
  134. style = self.ui.settingsTopBtn.styleSheet()
  135. # SET MAX WIDTH
  136. if width == 0:
  137. widthExtended = maxExtend
  138. # SELECT BTN
  139. self.ui.settingsTopBtn.setStyleSheet(style + color)
  140. if widthLeftBox != 0:
  141. style = self.ui.toggleLeftBox.styleSheet()
  142. self.ui.toggleLeftBox.setStyleSheet(style.replace(Settings.BTN_LEFT_BOX_COLOR, ''))
  143. else:
  144. widthExtended = standard
  145. # RESET BTN
  146. self.ui.settingsTopBtn.setStyleSheet(style.replace(color, ''))
  147. UIFunctions.start_box_animation(self, widthLeftBox, width, "right")
  148. def start_box_animation(self, left_box_width, right_box_width, direction):
  149. right_width = 0
  150. left_width = 0
  151. # Check values
  152. if left_box_width == 0 and direction == "left":
  153. left_width = 240
  154. else:
  155. left_width = 0
  156. # Check values
  157. if right_box_width == 0 and direction == "right":
  158. right_width = 240
  159. else:
  160. right_width = 0
  161. # ANIMATION LEFT BOX
  162. self.left_box = QPropertyAnimation(self.ui.extraLeftBox, b"minimumWidth")
  163. self.left_box.setDuration(Settings.TIME_ANIMATION)
  164. self.left_box.setStartValue(left_box_width)
  165. self.left_box.setEndValue(left_width)
  166. self.left_box.setEasingCurve(QEasingCurve.InOutQuart)
  167. # ANIMATION RIGHT BOX
  168. self.right_box = QPropertyAnimation(self.ui.extraRightBox, b"minimumWidth")
  169. self.right_box.setDuration(Settings.TIME_ANIMATION)
  170. self.right_box.setStartValue(right_box_width)
  171. self.right_box.setEndValue(right_width)
  172. self.right_box.setEasingCurve(QEasingCurve.InOutQuart)
  173. # GROUP ANIMATION
  174. self.group = QParallelAnimationGroup()
  175. self.group.addAnimation(self.left_box)
  176. self.group.addAnimation(self.right_box)
  177. self.group.start()
  178. # SELECT/DESELECT MENU
  179. # ///////////////////////////////////////////////////////////////
  180. # SELECT
  181. def selectMenu(getStyle):
  182. select = getStyle + Settings.MENU_SELECTED_STYLESHEET
  183. return select
  184. # DESELECT
  185. def deselectMenu(getStyle):
  186. deselect = getStyle.replace(Settings.MENU_SELECTED_STYLESHEET, "")
  187. return deselect
  188. # START SELECTION
  189. def selectStandardMenu(self, widget):
  190. for w in self.ui.topMenu.findChildren(QPushButton):
  191. if w.objectName() == widget:
  192. w.setStyleSheet(UIFunctions.selectMenu(w.styleSheet()))
  193. # RESET SELECTION
  194. def resetStyle(self, widget):
  195. for w in self.ui.topMenu.findChildren(QPushButton):
  196. if w.objectName() != widget:
  197. w.setStyleSheet(UIFunctions.deselectMenu(w.styleSheet()))
  198. # IMPORT THEMES FILES QSS/CSS
  199. # ///////////////////////////////////////////////////////////////
  200. def theme(self, file, useCustomTheme):
  201. if useCustomTheme:
  202. str = open(file, 'r').read()
  203. self.ui.styleSheet.setStyleSheet(str)
  204. # START - GUI DEFINITIONS
  205. # ///////////////////////////////////////////////////////////////
  206. def uiDefinitions(self):
  207. def dobleClickMaximizeRestore(event):
  208. # IF DOUBLE CLICK CHANGE STATUS
  209. if event.type() == QEvent.MouseButtonDblClick:
  210. QTimer.singleShot(250, lambda: UIFunctions.maximize_restore(self))
  211. # self.ui.titleRightInfo.mouseDoubleClickEvent = dobleClickMaximizeRestore
  212. if Settings.ENABLE_CUSTOM_TITLE_BAR:
  213. # STANDARD TITLE BAR
  214. self.setWindowFlags(Qt.FramelessWindowHint)
  215. self.setAttribute(Qt.WA_TranslucentBackground)
  216. # MOVE WINDOW / MAXIMIZE / RESTORE
  217. def moveWindow(event):
  218. # IF MAXIMIZED CHANGE TO NORMAL
  219. # 仅在窗口未最大化时处理移动
  220. if not UIFunctions.returStatus(self):
  221. # 仅当鼠标左键按下时处理移动
  222. if event.buttons() == Qt.LeftButton:
  223. self.move(self.pos() + event.globalPos() - self.dragPos)
  224. self.dragPos = event.globalPos()
  225. event.accept()
  226. self.ui.titleRightInfo.mouseMoveEvent = moveWindow
  227. # CUSTOM GRIPS
  228. self.left_grip = CustomGrip(self, Qt.LeftEdge, True)
  229. self.right_grip = CustomGrip(self, Qt.RightEdge, True)
  230. self.top_grip = CustomGrip(self, Qt.TopEdge, True)
  231. self.bottom_grip = CustomGrip(self, Qt.BottomEdge, True)
  232. else:
  233. self.ui.appMargins.setContentsMargins(0, 0, 0, 0)
  234. self.ui.minimizeAppBtn.hide()
  235. self.ui.maximizeRestoreAppBtn.hide()
  236. self.ui.closeAppBtn.hide()
  237. self.ui.frame_size_grip.hide()
  238. # DROP SHADOW
  239. self.shadow = QGraphicsDropShadowEffect(self)
  240. self.shadow.setBlurRadius(17)
  241. self.shadow.setXOffset(0)
  242. self.shadow.setYOffset(0)
  243. self.shadow.setColor(QColor(0, 0, 0, 150))
  244. self.ui.bgApp.setGraphicsEffect(self.shadow)
  245. # RESIZE WINDOW
  246. self.sizegrip = QSizeGrip(self.ui.frame_size_grip)
  247. self.sizegrip.setStyleSheet("width: 20px; height: 20px; margin 0px; padding: 0px;")
  248. # MINIMIZE
  249. self.ui.minimizeAppBtn.clicked.connect(lambda: self.showMinimized())
  250. # # MAXIMIZE/RESTORE
  251. self.ui.maximizeRestoreAppBtn.clicked.connect(lambda: UIFunctions.maximize_restore(self))
  252. # CLOSE APPLICATION
  253. self.ui.closeAppBtn.clicked.connect(lambda: self.close())
  254. def resize_grips(self):
  255. if Settings.ENABLE_CUSTOM_TITLE_BAR:
  256. self.left_grip.setGeometry(0, 10, 10, self.height())
  257. self.right_grip.setGeometry(self.width() - 10, 10, 10, self.height())
  258. self.top_grip.setGeometry(0, 0, self.width(), 10)
  259. self.bottom_grip.setGeometry(0, self.height() - 10, self.width(), 10)
  260. # 上传文件的方法
  261. def execute_script_based_on_selection(self, file_path):
  262. current_text = self.ui.comboBox_2.currentText()
  263. # db_path = r"D:/Code/ControlNetwork/UI/SQL/DataBase.db"
  264. # 获取当前脚本所在的目录
  265. # current_dir = os.getcwd()
  266. # # 构建 SQL 文件夹的相对路径(上一级的上一级中的 SQL 文件夹)
  267. # sql_folder = os.path.join(current_dir, '..', '..', 'SQL')
  268. # # 将相对路径转换为绝对路径
  269. # sql_folder = os.path.abspath(sql_folder)
  270. # db_path = os.path.join(resource_path(sql_folder), f"{self.ui.comboBox.currentText()}.db")
  271. db_path = os.path.join(resource_path('SQL'), f"{self.ui.comboBox.currentText()}.db")
  272. print(db_path)
  273. utf_en = file_path.encode('utf-8')
  274. if current_text == "水准测段高差稳定计算":
  275. try:
  276. GC.main_function(file_path, db_path)
  277. except:
  278. UIFunctions.clear_db_data(self,current_text,utf_en, db_path)
  279. # 添加水准执行代码
  280. elif current_text == "控制网复测平面基准计算":
  281. try:
  282. GS.main_function(file_path, db_path)
  283. except:
  284. UIFunctions.clear_db_data(self,current_text,utf_en, db_path)
  285. # 添加控制网执行代码
  286. elif current_text == "平面控制网稳定性计算":
  287. try:
  288. WD.main_function(file_path, db_path)
  289. except:
  290. UIFunctions.clear_db_data(self,current_text,utf_en, db_path)
  291. # 添加平面控制网执行代码
  292. # 计算与展示文件的方法
  293. def compute_show_process_excel_file(self, file_path):
  294. current_text = self.ui.comboBox_2.currentText()
  295. db_path = os.path.join(resource_path('SQL'), f"{self.ui.comboBox.currentText()}.db")
  296. # 转换为utf-8
  297. excelname = os.path.basename(file_path) # 文件名
  298. utf_en = excelname.encode('utf-8') # 转换文件名为utf-8编码形式
  299. #返回一个值,不跳转结果界面
  300. if current_text == "水准测段高差稳定计算":
  301. try:
  302. bool_2 = GCcompute.main_function(file_path, db_path)
  303. if bool_2 == 1:
  304. GCshow.main_function(self.ui, db_path, utf_en)
  305. return 1
  306. else:
  307. # 清除所有与之相关的数据库
  308. UIFunctions.clear_db_data(self, current_text, utf_en, db_path)
  309. return -1
  310. except:
  311. #清除所有与之相关的数据库
  312. UIFunctions.clear_db_data(self,current_text,utf_en, db_path)
  313. return -1
  314. elif current_text == "控制网复测平面基准计算":
  315. try:
  316. bool_3 = GScompute.main_function(excelname, db_path)
  317. if bool_3 == 1:
  318. GSshow.main_function(self.ui, db_path, utf_en)
  319. return 1
  320. else:
  321. UIFunctions.clear_db_data(self, current_text, utf_en, db_path)
  322. return -1
  323. except:
  324. UIFunctions.clear_db_data(self,current_text,utf_en, db_path)
  325. return -1
  326. elif current_text == "平面控制网稳定性计算":
  327. try:
  328. bool_4 = WDcompute.main_function(excelname, db_path)
  329. if bool_4 == 1:
  330. WDshow.main_function(self.ui, db_path, utf_en)
  331. return 1
  332. else:
  333. UIFunctions.clear_db_data(self, current_text, utf_en, db_path)
  334. return -1
  335. except:
  336. UIFunctions.clear_db_data(self,current_text,utf_en, db_path)
  337. return -1
  338. #统一删除数据库内的错误信息
  339. def clear_db_data(self,methodName,tableName_utf8, dbPath):
  340. db1 = sqlite3.connect(dbPath)
  341. cursor1 = db1.cursor()
  342. # 通过行锁定对应的字段
  343. if methodName == '水准测段高差稳定计算':
  344. try:
  345. # 把所有相关的表都删除
  346. sqlstr1 = """DELETE FROM GC_Input_Point WHERE TableName = ? """
  347. cursor1.execute(sqlstr1, (tableName_utf8,))
  348. except:
  349. pass
  350. try:
  351. sqlstr2 = """DELETE FROM GC_Input_Param WHERE TableName = ? """
  352. cursor1.execute(sqlstr2, (tableName_utf8,))
  353. except:
  354. pass
  355. try:
  356. # 先把结果相关的点和参数删一下
  357. sqlstr3 = """DELETE FROM GC_Output_Point WHERE TableName = ?"""
  358. cursor1.execute(sqlstr3, (tableName_utf8,))
  359. except:
  360. pass
  361. # 提交事务
  362. db1.commit()
  363. # 关闭db
  364. db1.close()
  365. elif methodName == '控制网复测平面基准计算':
  366. try:
  367. # 把所有相关的表都删除
  368. sqlstr1 = """DELETE FROM GS_Input_Point WHERE TableName = ? """
  369. cursor1.execute(sqlstr1, (tableName_utf8,))
  370. except:
  371. pass
  372. try:
  373. sqlstr2 = """DELETE FROM GS_Input_Param WHERE TableName = ? """
  374. cursor1.execute(sqlstr2, (tableName_utf8,))
  375. except:
  376. pass
  377. try:
  378. # 先把结果相关的点和参数删一下
  379. sqlstr3 = """DELETE FROM GS_Result_Point WHERE TableName = ?"""
  380. cursor1.execute(sqlstr3, (tableName_utf8,))
  381. except:
  382. pass
  383. try:
  384. sqlstr4 = """DELETE FROM GS_Trans_Point WHERE TableName = ?"""
  385. cursor1.execute(sqlstr4, (tableName_utf8,))
  386. except:
  387. pass
  388. try:
  389. sqlstr5 = """DELETE FROM GS_Trans_Param WHERE TableName = ?"""
  390. cursor1.execute(sqlstr5, (tableName_utf8,))
  391. except:
  392. pass
  393. # 提交事务
  394. db1.commit()
  395. # 关闭db
  396. db1.close()
  397. else:
  398. try:
  399. # 平面控制网稳定性计算
  400. sqlstr1 = """DELETE FROM WD_Input_Point WHERE TableName = ?"""
  401. cursor1.execute(sqlstr1, (tableName_utf8,))
  402. except:
  403. pass
  404. try:
  405. sqlstr2 = """DELETE FROM WD_Input_Param WHERE TableName = ?"""
  406. cursor1.execute(sqlstr2, (tableName_utf8,))
  407. except:
  408. pass
  409. try:
  410. # 先把结果相关的点和参数删一下
  411. sqlstr3 = """DELETE FROM WD_Result_Point WHERE TableName = ?"""
  412. cursor1.execute(sqlstr3, (tableName_utf8,))
  413. except:
  414. pass
  415. try:
  416. sqlstr4 = """DELETE FROM WD_Result_Param WHERE TableName = ?"""
  417. cursor1.execute(sqlstr4, (tableName_utf8,))
  418. except:
  419. pass
  420. # 提交事务
  421. db1.commit()
  422. # 关闭db
  423. db1.close()
  424. # 文件导出的方法
  425. def export_database_to_excel(self, file_path,folder_name,file_name):
  426. current_text = self.ui.comboBox_2.currentText()
  427. # # 获取当前脚本所在的目录
  428. # current_dir = os.getcwd()
  429. # # 构建 SQL 文件夹的相对路径(上一级的上一级中的 SQL 文件夹)
  430. # sql_folder = os.path.join(current_dir, '..', '..', 'SQL')
  431. # # 将相对路径转换为绝对路径
  432. # sql_folder = os.path.abspath(sql_folder)
  433. # db_path = os.path.join(sql_folder, f"{self.ui.comboBox.currentText()}.db")
  434. db_path = os.path.join(resource_path('SQL'), f"{self.ui.comboBox.currentText()}.db")
  435. # 转换为utf-8
  436. excelname = os.path.basename(file_path) # 文件名
  437. utf_en = excelname.encode('utf-8') # 转换文件名为utf-8编码形式
  438. if current_text == "水准测段高差稳定计算":
  439. GCExport.main_function_combined(self, utf_en, db_path,folder_name,file_name)
  440. elif current_text == "控制网复测平面基准计算":
  441. # GSExport.main_function(self, db_path, excelname,folder_name,file_name)
  442. GSExport.main_function_combined(self, db_path, excelname, folder_name, file_name)
  443. elif current_text == "平面控制网稳定性计算":
  444. WDExport.main_function_combined(self, db_path, excelname,folder_name,file_name)
  445. else:
  446. QMessageBox.warning(self, '警告', '请选择有效的计算类型')
  447. # 数据一览,点击查询
  448. def search_data_to_show(self, file_path, current_text, tablename):
  449. utf_en = tablename.encode('utf-8') # 转换文件名为utf-8编码形式
  450. if current_text == "水准测段高差稳定计算":
  451. selectModel = GCshow.search_show_function(self.ui, file_path, utf_en)
  452. return selectModel
  453. elif current_text == "控制网复测平面基准计算":
  454. selectModel = GSshow.search_show_function(self.ui, file_path, utf_en)
  455. return selectModel
  456. elif current_text == "平面控制网稳定性计算":
  457. selectModel = WDshow.search_show_function(self.ui, file_path, utf_en)
  458. return selectModel
  459. # 删除行数据
  460. def del_row_from_db(self, row, methodName, tableName_utf8, dbPath):
  461. db1 = sqlite3.connect(dbPath)
  462. cursor1 = db1.cursor()
  463. # 通过行锁定对应的字段
  464. if methodName == '水准测段高差稳定计算':
  465. sqlstr1 = """SELECT * FROM GC_Input_Point WHERE TableName = ? LIMIT 1 OFFSET ?"""
  466. cursor1.execute(sqlstr1, (tableName_utf8, row,))
  467. result1 = cursor1.fetchall()
  468. list1 = result1[0]
  469. # 100%准确查询
  470. # sqlstr3 = """SELECT * FROM GC_Input_Point WHERE TableName = ? and New_SPName = ? and New_EPName = ? and New_HDiff = ? and New_RLen = ?"""
  471. # cursor1.execute(sqlstr3, (tableName_utf8, list1[7], list1[8], list1[11], list1[12],))
  472. # result3 = cursor1.fetchall()
  473. sqlstr2 = """DELETE FROM GC_Input_Point WHERE TableName = ? and New_SPName = ? and New_EPName = ? and New_HDiff = ? and New_RLen = ?"""
  474. cursor1.execute(sqlstr2, (tableName_utf8, list1[7], list1[8], list1[11], list1[12],))
  475. # # 获取删除的记录数量
  476. # deleted_count = cursor1.rowcount
  477. # 直接使用计算方式
  478. tableName = tableName_utf8.decode('utf-8')
  479. # 先把结果相关的点数据删一下
  480. sqlstr3 = """DELETE FROM GC_Output_Point WHERE TableName = ?"""
  481. cursor1.execute(sqlstr3, (tableName_utf8,))
  482. # 提交事务
  483. db1.commit()
  484. # 关闭db
  485. db1.close()
  486. GCcompute.main_function(tableName, dbPath)
  487. GCshow.main_function(self.ui, dbPath, tableName_utf8)
  488. elif methodName == '控制网复测平面基准计算':
  489. sqlstr1 = """SELECT * FROM GS_Input_Point WHERE TableName = ? LIMIT 1 OFFSET ?"""
  490. cursor1.execute(sqlstr1, (tableName_utf8, row,))
  491. result1 = cursor1.fetchall()
  492. list1 = result1[0]
  493. # 100%准确查询
  494. # sqlstr3 = """SELECT * FROM GC_Input_Point WHERE TableName = ? and New_SPName = ? and New_EPName = ? and New_HDiff = ? and New_RLen = ?"""
  495. # cursor1.execute(sqlstr3, (tableName_utf8, list1[7], list1[8], list1[11], list1[12],))
  496. # result3 = cursor1.fetchall()
  497. sqlstr2 = """DELETE FROM GS_Input_Point WHERE TableName = ? and PointName = ? and New_X = ? and New_Y = ?"""
  498. cursor1.execute(sqlstr2, (tableName_utf8, list1[7], list1[5], list1[6],))
  499. # # 获取删除的记录数量
  500. # deleted_count = cursor1.rowcount
  501. # 直接使用计算方式
  502. tableName = tableName_utf8.decode('utf-8')
  503. # 先把结果相关的点和参数删一下
  504. sqlstr3 = """DELETE FROM GS_Result_Point WHERE TableName = ?"""
  505. cursor1.execute(sqlstr3, (tableName_utf8,))
  506. sqlstr4 = """DELETE FROM GS_Trans_Point WHERE TableName = ?"""
  507. cursor1.execute(sqlstr4, (tableName_utf8,))
  508. sqlstr5 = """DELETE FROM GS_Trans_Param WHERE TableName = ?"""
  509. cursor1.execute(sqlstr5, (tableName_utf8,))
  510. # 提交事务
  511. db1.commit()
  512. # 关闭db
  513. db1.close()
  514. GScompute.main_function(tableName, dbPath)
  515. GSshow.main_function(self.ui, dbPath, tableName_utf8)
  516. else:
  517. # 平面控制网稳定性计算
  518. sqlstr1 = """SELECT * FROM WD_Input_Point WHERE TableName = ? LIMIT 1 OFFSET ?"""
  519. cursor1.execute(sqlstr1, (tableName_utf8, row,))
  520. result1 = cursor1.fetchall()
  521. list1 = result1[0]
  522. # 100%准确查询
  523. # sqlstr3 = """SELECT * FROM GC_Input_Point WHERE TableName = ? and New_SPName = ? and New_EPName = ? and New_HDiff = ? and New_RLen = ?"""
  524. # cursor1.execute(sqlstr3, (tableName_utf8, list1[7], list1[8], list1[11], list1[12],))
  525. # result3 = cursor1.fetchall()
  526. sqlstr2 = """DELETE FROM WD_Input_Point WHERE TableName = ? and PointName = ? and New_X = ? and New_Y = ?"""
  527. cursor1.execute(sqlstr2, (tableName_utf8, list1[11], list1[8], list1[9],))
  528. # # 获取删除的记录数量
  529. # deleted_count = cursor1.rowcount
  530. # 直接使用计算方式
  531. tableName = tableName_utf8.decode('utf-8')
  532. # 先把结果相关的点和参数删一下
  533. sqlstr3 = """DELETE FROM WD_Result_Point WHERE TableName = ?"""
  534. cursor1.execute(sqlstr3, (tableName_utf8,))
  535. sqlstr4 = """DELETE FROM WD_Result_Param WHERE TableName = ?"""
  536. cursor1.execute(sqlstr4, (tableName_utf8,))
  537. # 提交事务
  538. db1.commit()
  539. # 关闭db
  540. db1.close()
  541. WDcompute.main_function(tableName, dbPath)
  542. WDshow.main_function(self.ui, dbPath, tableName_utf8)
  543. #编辑完后的数据更新
  544. #输入模型,方法,表名utf8,数据库
  545. def update_to_db(self,model1,methodName, tableName_utf8, dbPath):
  546. print(dbPath)
  547. db1 = sqlite3.connect(dbPath)
  548. cursor1 = db1.cursor()
  549. #副本名
  550. copyname = tableName_utf8 + 'copy'.encode('utf-8')
  551. #初始化三个布尔值
  552. bool_1 = 1
  553. bool_2 = 1
  554. bool_3 = 1
  555. # 通过行锁定对应的字段
  556. if methodName == '水准测段高差稳定计算':
  557. try:
  558. #读取有用的数据,按格式录入
  559. data = GC.get_data_from_excel1(model1)
  560. cell_values = GC.read_cells_from_excel1(model1)
  561. ms_station = float(model1[0][12])
  562. last_station_count = GC.get_last_numeric_cell_value1(model1, 2)
  563. new_station_count = GC.get_last_numeric_cell_value1(model1, 7)
  564. last_sum_hdiff = GC.calculate_column_sum1(model1, 4)
  565. last_sum_rlen = GC.calculate_column_sum1(model1, 5)
  566. new_sum_hdiff = GC.calculate_column_sum1(model1, 9)
  567. new_sum_rlen = GC.calculate_column_sum1(model1, 10)
  568. #存个副本,如果有错还能回退
  569. sqlnew1 = """UPDATE GC_Input_Point SET TableName = ? WHERE TableName = ? """
  570. cursor1.execute(sqlnew1, (copyname,tableName_utf8,))
  571. sqlnew2 = """UPDATE GC_Input_Param SET TableName = ? WHERE TableName = ? """
  572. cursor1.execute(sqlnew2, (copyname, tableName_utf8,))
  573. sqlnew3 = """UPDATE GC_Output_Point SET TableName = ? WHERE TableName = ? """
  574. cursor1.execute(sqlnew3, (copyname, tableName_utf8,))
  575. # 提交事务
  576. db1.commit()
  577. # 关闭db
  578. db1.close()
  579. # 直接使用计算方式
  580. tableName = tableName_utf8.decode('utf-8')
  581. # 重新更新数据库
  582. GC.insert_into_database(tableName, cell_values, ms_station, last_station_count, new_station_count,
  583. last_sum_hdiff,
  584. new_sum_hdiff, last_sum_rlen, new_sum_rlen, dbPath, tableName_utf8)
  585. GC.insert_data_into_database(data, tableName, cell_values, dbPath, tableName_utf8)
  586. bool_1 = GCcompute.main_function(tableName, dbPath)
  587. except:
  588. bool_1 = -1
  589. if bool_1 == 1:
  590. GCshow.main_function(self.ui, dbPath, tableName_utf8)
  591. # 把所有相关的表都删除
  592. UIFunctions.clear_db_data(self, methodName, copyname, dbPath)
  593. else:
  594. # 把所有相关的表都删除
  595. UIFunctions.clear_db_data(self,methodName,tableName_utf8, dbPath)
  596. #把副本改回来
  597. db1 = sqlite3.connect(dbPath)
  598. cursor1 = db1.cursor()
  599. # 存个副本,如果有错还能回退
  600. sqlnew1 = """UPDATE GC_Input_Point SET TableName = ? WHERE TableName = ? """
  601. cursor1.execute(sqlnew1, (tableName_utf8,copyname,))
  602. sqlnew2 = """UPDATE GC_Input_Param SET TableName = ? WHERE TableName = ? """
  603. cursor1.execute(sqlnew2, (tableName_utf8,copyname, ))
  604. sqlnew3 = """UPDATE GC_Output_Point SET TableName = ? WHERE TableName = ? """
  605. cursor1.execute(sqlnew3, (tableName_utf8,copyname, ))
  606. # 提交事务
  607. db1.commit()
  608. # 关闭db
  609. db1.close()
  610. elif methodName == '控制网复测平面基准计算':
  611. try:
  612. #读取模型
  613. ii = 0
  614. pastname = model1[0][6]
  615. newname = model1[0][7]
  616. pjbc = float(model1[0][8])
  617. fxzwc = float(model1[0][9])
  618. zrbzwc = float(model1[0][10])
  619. points = len(model1)
  620. zbs = float(model1[0][11])
  621. zfxs = float(model1[0][12])
  622. sf = float(model1[0][13])
  623. pjbcs = zbs / points
  624. pjfxs = zfxs / points
  625. listname1 = []
  626. listpastx1 = []
  627. listpasty1 = []
  628. listcgcs1 = []
  629. listnewx1 = []
  630. listnewy1 = []
  631. while ii < len(model1):
  632. if model1[ii][0] == '' or model1[ii][0] == None:
  633. ii = ii + 1
  634. else:
  635. listname1.append(model1[ii][0])
  636. listpastx1.append(model1[ii][1])
  637. listpasty1.append(model1[ii][2])
  638. listnewx1.append(model1[ii][3])
  639. listnewy1.append(model1[ii][4])
  640. listcgcs1.append(model1[ii][5])
  641. ii = ii + 1
  642. sqlnew1 = """UPDATE GS_Input_Point SET TableName = ? WHERE TableName = ? """
  643. cursor1.execute(sqlnew1, (copyname, tableName_utf8,))
  644. sqlnew2 = """UPDATE GS_Input_Param SET TableName = ? WHERE TableName = ? """
  645. cursor1.execute(sqlnew2, (copyname, tableName_utf8,))
  646. sqlnew3 = """UPDATE GS_Result_Point SET TableName = ? WHERE TableName = ? """
  647. cursor1.execute(sqlnew3, (copyname, tableName_utf8,))
  648. sqlnew4 = """UPDATE GS_Trans_Point SET TableName = ? WHERE TableName = ? """
  649. cursor1.execute(sqlnew4, (copyname, tableName_utf8,))
  650. sqlnew5 = """UPDATE GS_Trans_Param SET TableName = ? WHERE TableName = ? """
  651. cursor1.execute(sqlnew5, (copyname, tableName_utf8,))
  652. # 提交事务
  653. db1.commit()
  654. # 关闭db
  655. db1.close()
  656. # 直接使用计算方式
  657. tableName = tableName_utf8.decode('utf-8')
  658. #重新更新数据库
  659. GS.insert_into_database(dbPath, pastname, newname, tableName, listname1, listpastx1, listpasty1, listcgcs1, listnewx1,
  660. listnewy1, pjbc, fxzwc, zrbzwc, points, zbs, zfxs, sf, pjbcs, pjfxs)
  661. bool_2 = GScompute.main_function(tableName, dbPath)
  662. except:
  663. bool_2 = -1
  664. if bool_2 == 1:
  665. GSshow.main_function(self.ui, dbPath, tableName_utf8)
  666. # 把所有相关的表都删除
  667. UIFunctions.clear_db_data(self, methodName, copyname, dbPath)
  668. else:
  669. # 把所有相关的表都删除
  670. UIFunctions.clear_db_data(self, methodName, tableName_utf8, dbPath)
  671. # 把副本改回来
  672. db1 = sqlite3.connect(dbPath)
  673. cursor1 = db1.cursor()
  674. # 存个副本,如果有错还能回退
  675. sqlnew1 = """UPDATE GS_Input_Point SET TableName = ? WHERE TableName = ? """
  676. cursor1.execute(sqlnew1, (tableName_utf8,copyname, ))
  677. sqlnew2 = """UPDATE GS_Input_Param SET TableName = ? WHERE TableName = ? """
  678. cursor1.execute(sqlnew2, (tableName_utf8,copyname, ))
  679. sqlnew3 = """UPDATE GS_Result_Point SET TableName = ? WHERE TableName = ? """
  680. cursor1.execute(sqlnew3, (tableName_utf8,copyname, ))
  681. sqlnew4 = """UPDATE GS_Trans_Point SET TableName = ? WHERE TableName = ? """
  682. cursor1.execute(sqlnew4, (tableName_utf8,copyname, ))
  683. sqlnew5 = """UPDATE GS_Trans_Param SET TableName = ? WHERE TableName = ? """
  684. cursor1.execute(sqlnew5, (tableName_utf8,copyname, ))
  685. # 提交事务
  686. db1.commit()
  687. # 关闭db
  688. db1.close()
  689. else:
  690. try:
  691. # 读取模型
  692. ii = 0
  693. bename = model1[0][8]
  694. pastname = model1[0][9]
  695. newname = model1[0][10]
  696. pjbc = float(model1[0][11])
  697. fxzwc = float(model1[0][12])
  698. points = len(model1)
  699. zbs = float(model1[0][13])
  700. zfxs = float(model1[0][14])
  701. sf = float(model1[0][15])
  702. pjbcs = zbs / points
  703. pjfxs = zfxs / points
  704. listbex1 = []
  705. listbey1 = []
  706. listname1 = []
  707. listpastx1 = []
  708. listpasty1 = []
  709. listcgcs1 = []
  710. listnewx1 = []
  711. listnewy1 = []
  712. while ii < len(model1):
  713. if model1[ii][0] == '' or model1[ii][0] == None:
  714. ii = ii + 1
  715. else:
  716. listname1.append(model1[ii][0])
  717. listbex1.append(model1[ii][1])
  718. listbey1.append(model1[ii][2])
  719. listpastx1.append(model1[ii][3])
  720. listpasty1.append(model1[ii][4])
  721. listcgcs1.append(model1[ii][5])
  722. listnewx1.append(model1[ii][6])
  723. listnewy1.append(model1[ii][7])
  724. ii = ii + 1
  725. sqlnew1 = """UPDATE WD_Input_Point SET TableName = ? WHERE TableName = ? """
  726. cursor1.execute(sqlnew1, (copyname, tableName_utf8,))
  727. sqlnew2 = """UPDATE WD_Input_Param SET TableName = ? WHERE TableName = ? """
  728. cursor1.execute(sqlnew2, (copyname, tableName_utf8,))
  729. sqlnew3 = """UPDATE WD_Result_Point SET TableName = ? WHERE TableName = ? """
  730. cursor1.execute(sqlnew3, (copyname, tableName_utf8,))
  731. sqlnew5 = """UPDATE WD_Result_Param SET TableName = ? WHERE TableName = ? """
  732. cursor1.execute(sqlnew5, (copyname, tableName_utf8,))
  733. # 提交事务
  734. db1.commit()
  735. # 关闭db
  736. db1.close()
  737. # 直接使用计算方式
  738. tableName = tableName_utf8.decode('utf-8')
  739. WD.insert_into_database(dbPath, pastname, newname, bename, tableName, listname1, listpastx1, listpasty1,
  740. listcgcs1, pjbc, fxzwc, points, zbs, zfxs, sf, pjbcs, pjfxs, listbex1, listbey1,
  741. listnewx1, listnewy1)
  742. bool_3 = WDcompute.main_function(tableName, dbPath)
  743. except:
  744. bool_3 = -1
  745. if bool_3 == 1:
  746. WDshow.main_function(self.ui, dbPath, tableName_utf8)
  747. # 把所有相关的表都删除
  748. UIFunctions.clear_db_data(self, methodName, copyname, dbPath)
  749. else:
  750. # 把所有相关的表都删除
  751. UIFunctions.clear_db_data(self, methodName, tableName_utf8, dbPath)
  752. # 把副本改回来
  753. db1 = sqlite3.connect(dbPath)
  754. cursor1 = db1.cursor()
  755. # 存个副本,如果有错还能回退
  756. sqlnew1 = """UPDATE WD_Input_Point SET TableName = ? WHERE TableName = ? """
  757. cursor1.execute(sqlnew1, (tableName_utf8, copyname,))
  758. sqlnew2 = """UPDATE WD_Input_Param SET TableName = ? WHERE TableName = ? """
  759. cursor1.execute(sqlnew2, (tableName_utf8, copyname,))
  760. sqlnew3 = """UPDATE WD_Result_Point SET TableName = ? WHERE TableName = ? """
  761. cursor1.execute(sqlnew3, (tableName_utf8, copyname,))
  762. sqlnew5 = """UPDATE WD_Result_Param SET TableName = ? WHERE TableName = ? """
  763. cursor1.execute(sqlnew5, (tableName_utf8, copyname,))
  764. # 提交事务
  765. db1.commit()
  766. # 关闭db
  767. db1.close()
  768. if bool_1 == -1 or bool_2 == -1 or bool_3 == -1:
  769. return -1
  770. else:
  771. return 1
  772. # END - GUI DEFINITIONS