123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828 |
- # ///////////////////////////////////////////////////////////////
- #
- # BY: WANDERSON M.PIMENTA
- # PROJECT MADE WITH: Qt Designer and PySide6
- # V: 1.0.0
- #
- # This project can be used freely for all uses, as long as they maintain the
- # respective credits only in the Python scripts, any information in the visual
- # interface (GUI) can be modified without any implication.
- #
- # There are limitations on Qt licenses if you want to use your products
- # commercially, I recommend reading them on the official website:
- # https://doc.qt.io/qtforpython/licenses.html
- #
- # ///////////////////////////////////////////////////////////////
- from PySide6.QtWidgets import QMessageBox
-
- from Front.back.Program_Run.utils import resource_path
- # MAIN FILE
- # ///////////////////////////////////////////////////////////////
-
-
- from Front.main import *
- import importlib
- import sqlite3
-
- from select import select
-
- from Front.back.GC import GC, GCExport
- from Front.back.GS import GS, GSExport
- from Front.back.WD import WD, WDExport
- from Front.back.GC import GCcompute
- from Front.back.GS import GScompute
- from Front.back.WD import WDcompute
- from Front.back.GC import GCshow
- from Front.back.GS import GSshow
- from Front.back.WD import WDshow
-
- import os
-
- from Front.main import MainWindow
- from Front.modules import Settings
-
- # GLOBALS
- # ///////////////////////////////////////////////////////////////
- GLOBAL_STATE = False
- GLOBAL_TITLE_BAR = True
-
-
- class UIFunctions(MainWindow):
- # MAXIMIZE/RESTORE
- # ///////////////////////////////////////////////////////////////
- def maximize_restore(self):
- global GLOBAL_STATE
- status = GLOBAL_STATE
- if status == False:
- self.showMaximized()
- GLOBAL_STATE = True
- self.ui.appMargins.setContentsMargins(0, 0, 0, 0)
- self.ui.maximizeRestoreAppBtn.setToolTip("Restore")
- self.ui.maximizeRestoreAppBtn.setIcon(QIcon(u":/icons/images/icons/icon_restore.png"))
- self.ui.frame_size_grip.hide()
- self.left_grip.hide()
- self.right_grip.hide()
- self.top_grip.hide()
- self.bottom_grip.hide()
- else:
- GLOBAL_STATE = False
- self.showNormal()
- self.resize(self.width() + 1, self.height() + 1)
- self.ui.appMargins.setContentsMargins(10, 10, 10, 10)
- self.ui.maximizeRestoreAppBtn.setToolTip("Maximize")
- self.ui.maximizeRestoreAppBtn.setIcon(QIcon(u":/icons/images/icons/icon_maximize.png"))
- self.ui.frame_size_grip.show()
- self.left_grip.show()
- self.right_grip.show()
- self.top_grip.show()
- self.bottom_grip.show()
-
- # RETURN STATUS
- # ///////////////////////////////////////////////////////////////
- def returStatus(self):
- return GLOBAL_STATE
-
- # SET STATUS
- # ///////////////////////////////////////////////////////////////
- def setStatus(self, status):
- global GLOBAL_STATE
- GLOBAL_STATE = status
-
- # TOGGLE MENU
- # ///////////////////////////////////////////////////////////////
- def toggleMenu(self, enable):
- if enable:
- # GET WIDTH
- width = self.ui.leftMenuBg.width()
- maxExtend = Settings.MENU_WIDTH
- standard = 60
-
- # SET MAX WIDTH
- if width == 60:
- widthExtended = maxExtend
- else:
- widthExtended = standard
-
- # ANIMATION
- self.animation = QPropertyAnimation(self.ui.leftMenuBg, b"minimumWidth")
- self.animation.setDuration(Settings.TIME_ANIMATION)
- self.animation.setStartValue(width)
- self.animation.setEndValue(widthExtended)
- self.animation.setEasingCurve(QEasingCurve.InOutQuart)
- self.animation.start()
-
- # TOGGLE LEFT BOX
- # ///////////////////////////////////////////////////////////////
- def toggleLeftBox(self, enable):
- if enable:
- # GET WIDTH
- width = self.ui.extraLeftBox.width()
- widthRightBox = self.ui.extraRightBox.width()
- maxExtend = Settings.LEFT_BOX_WIDTH
- color = Settings.BTN_LEFT_BOX_COLOR
- standard = 0
-
- # GET BTN STYLE
- style = self.ui.toggleLeftBox.styleSheet()
-
- # SET MAX WIDTH
- if width == 0:
- widthExtended = maxExtend
- # SELECT BTN
- self.ui.toggleLeftBox.setStyleSheet(style + color)
- if widthRightBox != 0:
- style = self.ui.settingsTopBtn.styleSheet()
- self.ui.settingsTopBtn.setStyleSheet(style.replace(Settings.BTN_RIGHT_BOX_COLOR, ''))
- else:
- widthExtended = standard
- # RESET BTN
- self.ui.toggleLeftBox.setStyleSheet(style.replace(color, ''))
-
- UIFunctions.start_box_animation(self, width, widthRightBox, "left")
-
- # TOGGLE RIGHT BOX
- # ///////////////////////////////////////////////////////////////
- def toggleRightBox(self, enable):
- if enable:
- # GET WIDTH
- width = self.ui.extraRightBox.width()
- widthLeftBox = self.ui.extraLeftBox.width()
- maxExtend = Settings.RIGHT_BOX_WIDTH
- color = Settings.BTN_RIGHT_BOX_COLOR
- standard = 0
-
- # GET BTN STYLE
- style = self.ui.settingsTopBtn.styleSheet()
-
- # SET MAX WIDTH
- if width == 0:
- widthExtended = maxExtend
- # SELECT BTN
- self.ui.settingsTopBtn.setStyleSheet(style + color)
- if widthLeftBox != 0:
- style = self.ui.toggleLeftBox.styleSheet()
- self.ui.toggleLeftBox.setStyleSheet(style.replace(Settings.BTN_LEFT_BOX_COLOR, ''))
- else:
- widthExtended = standard
- # RESET BTN
- self.ui.settingsTopBtn.setStyleSheet(style.replace(color, ''))
-
- UIFunctions.start_box_animation(self, widthLeftBox, width, "right")
-
- def start_box_animation(self, left_box_width, right_box_width, direction):
- right_width = 0
- left_width = 0
-
- # Check values
- if left_box_width == 0 and direction == "left":
- left_width = 240
- else:
- left_width = 0
- # Check values
- if right_box_width == 0 and direction == "right":
- right_width = 240
- else:
- right_width = 0
-
- # ANIMATION LEFT BOX
- self.left_box = QPropertyAnimation(self.ui.extraLeftBox, b"minimumWidth")
- self.left_box.setDuration(Settings.TIME_ANIMATION)
- self.left_box.setStartValue(left_box_width)
- self.left_box.setEndValue(left_width)
- self.left_box.setEasingCurve(QEasingCurve.InOutQuart)
-
- # ANIMATION RIGHT BOX
- self.right_box = QPropertyAnimation(self.ui.extraRightBox, b"minimumWidth")
- self.right_box.setDuration(Settings.TIME_ANIMATION)
- self.right_box.setStartValue(right_box_width)
- self.right_box.setEndValue(right_width)
- self.right_box.setEasingCurve(QEasingCurve.InOutQuart)
-
- # GROUP ANIMATION
- self.group = QParallelAnimationGroup()
- self.group.addAnimation(self.left_box)
- self.group.addAnimation(self.right_box)
- self.group.start()
-
- # SELECT/DESELECT MENU
- # ///////////////////////////////////////////////////////////////
- # SELECT
- def selectMenu(getStyle):
- select = getStyle + Settings.MENU_SELECTED_STYLESHEET
- return select
-
- # DESELECT
- def deselectMenu(getStyle):
- deselect = getStyle.replace(Settings.MENU_SELECTED_STYLESHEET, "")
- return deselect
-
- # START SELECTION
- def selectStandardMenu(self, widget):
- for w in self.ui.topMenu.findChildren(QPushButton):
- if w.objectName() == widget:
- w.setStyleSheet(UIFunctions.selectMenu(w.styleSheet()))
-
- # RESET SELECTION
- def resetStyle(self, widget):
- for w in self.ui.topMenu.findChildren(QPushButton):
- if w.objectName() != widget:
- w.setStyleSheet(UIFunctions.deselectMenu(w.styleSheet()))
-
- # IMPORT THEMES FILES QSS/CSS
- # ///////////////////////////////////////////////////////////////
- def theme(self, file, useCustomTheme):
- if useCustomTheme:
- str = open(file, 'r').read()
- self.ui.styleSheet.setStyleSheet(str)
-
- # START - GUI DEFINITIONS
- # ///////////////////////////////////////////////////////////////
- def uiDefinitions(self):
- def dobleClickMaximizeRestore(event):
- # IF DOUBLE CLICK CHANGE STATUS
- if event.type() == QEvent.MouseButtonDblClick:
- QTimer.singleShot(250, lambda: UIFunctions.maximize_restore(self))
-
- # self.ui.titleRightInfo.mouseDoubleClickEvent = dobleClickMaximizeRestore
-
- if Settings.ENABLE_CUSTOM_TITLE_BAR:
- # STANDARD TITLE BAR
- self.setWindowFlags(Qt.FramelessWindowHint)
- self.setAttribute(Qt.WA_TranslucentBackground)
-
- # MOVE WINDOW / MAXIMIZE / RESTORE
- def moveWindow(event):
- # IF MAXIMIZED CHANGE TO NORMAL
- # 仅在窗口未最大化时处理移动
- if not UIFunctions.returStatus(self):
- # 仅当鼠标左键按下时处理移动
- if event.buttons() == Qt.LeftButton:
- self.move(self.pos() + event.globalPos() - self.dragPos)
- self.dragPos = event.globalPos()
- event.accept()
-
- self.ui.titleRightInfo.mouseMoveEvent = moveWindow
-
- # CUSTOM GRIPS
- self.left_grip = CustomGrip(self, Qt.LeftEdge, True)
- self.right_grip = CustomGrip(self, Qt.RightEdge, True)
- self.top_grip = CustomGrip(self, Qt.TopEdge, True)
- self.bottom_grip = CustomGrip(self, Qt.BottomEdge, True)
-
- else:
- self.ui.appMargins.setContentsMargins(0, 0, 0, 0)
- self.ui.minimizeAppBtn.hide()
- self.ui.maximizeRestoreAppBtn.hide()
- self.ui.closeAppBtn.hide()
- self.ui.frame_size_grip.hide()
-
- # DROP SHADOW
- self.shadow = QGraphicsDropShadowEffect(self)
- self.shadow.setBlurRadius(17)
- self.shadow.setXOffset(0)
- self.shadow.setYOffset(0)
- self.shadow.setColor(QColor(0, 0, 0, 150))
- self.ui.bgApp.setGraphicsEffect(self.shadow)
-
- # RESIZE WINDOW
- self.sizegrip = QSizeGrip(self.ui.frame_size_grip)
- self.sizegrip.setStyleSheet("width: 20px; height: 20px; margin 0px; padding: 0px;")
-
- # MINIMIZE
- self.ui.minimizeAppBtn.clicked.connect(lambda: self.showMinimized())
-
- # # MAXIMIZE/RESTORE
- self.ui.maximizeRestoreAppBtn.clicked.connect(lambda: UIFunctions.maximize_restore(self))
-
- # CLOSE APPLICATION
- self.ui.closeAppBtn.clicked.connect(lambda: self.close())
-
- def resize_grips(self):
- if Settings.ENABLE_CUSTOM_TITLE_BAR:
- self.left_grip.setGeometry(0, 10, 10, self.height())
- self.right_grip.setGeometry(self.width() - 10, 10, 10, self.height())
- self.top_grip.setGeometry(0, 0, self.width(), 10)
- self.bottom_grip.setGeometry(0, self.height() - 10, self.width(), 10)
-
- # 上传文件的方法
- def execute_script_based_on_selection(self, file_path):
- current_text = self.ui.comboBox_2.currentText()
- # db_path = r"D:/Code/ControlNetwork/UI/SQL/DataBase.db"
- # 获取当前脚本所在的目录
- # current_dir = os.getcwd()
- # # 构建 SQL 文件夹的相对路径(上一级的上一级中的 SQL 文件夹)
- # sql_folder = os.path.join(current_dir, '..', '..', 'SQL')
- # # 将相对路径转换为绝对路径
- # sql_folder = os.path.abspath(sql_folder)
- # db_path = os.path.join(resource_path(sql_folder), f"{self.ui.comboBox.currentText()}.db")
- db_path = os.path.join(resource_path('SQL'), f"{self.ui.comboBox.currentText()}.db")
- print(db_path)
- utf_en = file_path.encode('utf-8')
- if current_text == "水准测段高差稳定计算":
- try:
- GC.main_function(file_path, db_path)
- except:
- UIFunctions.clear_db_data(self,current_text,utf_en, db_path)
- # 添加水准执行代码
- elif current_text == "控制网复测平面基准计算":
- try:
- GS.main_function(file_path, db_path)
- except:
- UIFunctions.clear_db_data(self,current_text,utf_en, db_path)
- # 添加控制网执行代码
- elif current_text == "平面控制网稳定性计算":
- try:
- WD.main_function(file_path, db_path)
- except:
- UIFunctions.clear_db_data(self,current_text,utf_en, db_path)
- # 添加平面控制网执行代码
-
- # 计算与展示文件的方法
- def compute_show_process_excel_file(self, file_path):
- current_text = self.ui.comboBox_2.currentText()
- db_path = os.path.join(resource_path('SQL'), f"{self.ui.comboBox.currentText()}.db")
- # 转换为utf-8
- excelname = os.path.basename(file_path) # 文件名
- utf_en = excelname.encode('utf-8') # 转换文件名为utf-8编码形式
- #返回一个值,不跳转结果界面
- if current_text == "水准测段高差稳定计算":
- try:
- bool_2 = GCcompute.main_function(file_path, db_path)
- if bool_2 == 1:
- GCshow.main_function(self.ui, db_path, utf_en)
- return 1
- else:
- # 清除所有与之相关的数据库
- UIFunctions.clear_db_data(self, current_text, utf_en, db_path)
- return -1
- except:
- #清除所有与之相关的数据库
- UIFunctions.clear_db_data(self,current_text,utf_en, db_path)
- return -1
- elif current_text == "控制网复测平面基准计算":
- try:
- bool_3 = GScompute.main_function(excelname, db_path)
- if bool_3 == 1:
- GSshow.main_function(self.ui, db_path, utf_en)
- return 1
- else:
- UIFunctions.clear_db_data(self, current_text, utf_en, db_path)
- return -1
- except:
- UIFunctions.clear_db_data(self,current_text,utf_en, db_path)
- return -1
- elif current_text == "平面控制网稳定性计算":
- try:
- bool_4 = WDcompute.main_function(excelname, db_path)
- if bool_4 == 1:
- WDshow.main_function(self.ui, db_path, utf_en)
- return 1
- else:
- UIFunctions.clear_db_data(self, current_text, utf_en, db_path)
- return -1
- except:
- UIFunctions.clear_db_data(self,current_text,utf_en, db_path)
- return -1
-
- #统一删除数据库内的错误信息
- def clear_db_data(self,methodName,tableName_utf8, dbPath):
- db1 = sqlite3.connect(dbPath)
- cursor1 = db1.cursor()
- # 通过行锁定对应的字段
- if methodName == '水准测段高差稳定计算':
- try:
- # 把所有相关的表都删除
- sqlstr1 = """DELETE FROM GC_Input_Point WHERE TableName = ? """
- cursor1.execute(sqlstr1, (tableName_utf8,))
- except:
- pass
- try:
- sqlstr2 = """DELETE FROM GC_Input_Param WHERE TableName = ? """
- cursor1.execute(sqlstr2, (tableName_utf8,))
- except:
- pass
- try:
- # 先把结果相关的点和参数删一下
- sqlstr3 = """DELETE FROM GC_Output_Point WHERE TableName = ?"""
- cursor1.execute(sqlstr3, (tableName_utf8,))
- except:
- pass
- # 提交事务
- db1.commit()
- # 关闭db
- db1.close()
- elif methodName == '控制网复测平面基准计算':
- try:
- # 把所有相关的表都删除
- sqlstr1 = """DELETE FROM GS_Input_Point WHERE TableName = ? """
- cursor1.execute(sqlstr1, (tableName_utf8,))
- except:
- pass
- try:
- sqlstr2 = """DELETE FROM GS_Input_Param WHERE TableName = ? """
- cursor1.execute(sqlstr2, (tableName_utf8,))
- except:
- pass
- try:
- # 先把结果相关的点和参数删一下
- sqlstr3 = """DELETE FROM GS_Result_Point WHERE TableName = ?"""
- cursor1.execute(sqlstr3, (tableName_utf8,))
- except:
- pass
- try:
- sqlstr4 = """DELETE FROM GS_Trans_Point WHERE TableName = ?"""
- cursor1.execute(sqlstr4, (tableName_utf8,))
- except:
- pass
- try:
- sqlstr5 = """DELETE FROM GS_Trans_Param WHERE TableName = ?"""
- cursor1.execute(sqlstr5, (tableName_utf8,))
- except:
- pass
- # 提交事务
- db1.commit()
- # 关闭db
- db1.close()
- else:
- try:
- # 平面控制网稳定性计算
- sqlstr1 = """DELETE FROM WD_Input_Point WHERE TableName = ?"""
- cursor1.execute(sqlstr1, (tableName_utf8,))
- except:
- pass
- try:
- sqlstr2 = """DELETE FROM WD_Input_Param WHERE TableName = ?"""
- cursor1.execute(sqlstr2, (tableName_utf8,))
- except:
- pass
- try:
- # 先把结果相关的点和参数删一下
- sqlstr3 = """DELETE FROM WD_Result_Point WHERE TableName = ?"""
- cursor1.execute(sqlstr3, (tableName_utf8,))
- except:
- pass
- try:
- sqlstr4 = """DELETE FROM WD_Result_Param WHERE TableName = ?"""
- cursor1.execute(sqlstr4, (tableName_utf8,))
- except:
- pass
- # 提交事务
- db1.commit()
- # 关闭db
- db1.close()
-
- # 文件导出的方法
- def export_database_to_excel(self, file_path,folder_name,file_name):
- current_text = self.ui.comboBox_2.currentText()
- # # 获取当前脚本所在的目录
- # current_dir = os.getcwd()
- # # 构建 SQL 文件夹的相对路径(上一级的上一级中的 SQL 文件夹)
- # sql_folder = os.path.join(current_dir, '..', '..', 'SQL')
- # # 将相对路径转换为绝对路径
- # sql_folder = os.path.abspath(sql_folder)
- # db_path = os.path.join(sql_folder, f"{self.ui.comboBox.currentText()}.db")
- db_path = os.path.join(resource_path('SQL'), f"{self.ui.comboBox.currentText()}.db")
- # 转换为utf-8
- excelname = os.path.basename(file_path) # 文件名
- utf_en = excelname.encode('utf-8') # 转换文件名为utf-8编码形式
- if current_text == "水准测段高差稳定计算":
- GCExport.main_function_combined(self, utf_en, db_path,folder_name,file_name)
- elif current_text == "控制网复测平面基准计算":
- # GSExport.main_function(self, db_path, excelname,folder_name,file_name)
- GSExport.main_function_combined(self, db_path, excelname, folder_name, file_name)
- elif current_text == "平面控制网稳定性计算":
- WDExport.main_function_combined(self, db_path, excelname,folder_name,file_name)
- else:
- QMessageBox.warning(self, '警告', '请选择有效的计算类型')
-
- # 数据一览,点击查询
- def search_data_to_show(self, file_path, current_text, tablename):
- utf_en = tablename.encode('utf-8') # 转换文件名为utf-8编码形式
- if current_text == "水准测段高差稳定计算":
- selectModel = GCshow.search_show_function(self.ui, file_path, utf_en)
- return selectModel
- elif current_text == "控制网复测平面基准计算":
- selectModel = GSshow.search_show_function(self.ui, file_path, utf_en)
- return selectModel
- elif current_text == "平面控制网稳定性计算":
- selectModel = WDshow.search_show_function(self.ui, file_path, utf_en)
- return selectModel
-
- # 删除行数据
- def del_row_from_db(self, row, methodName, tableName_utf8, dbPath):
- db1 = sqlite3.connect(dbPath)
- cursor1 = db1.cursor()
- # 通过行锁定对应的字段
- if methodName == '水准测段高差稳定计算':
- sqlstr1 = """SELECT * FROM GC_Input_Point WHERE TableName = ? LIMIT 1 OFFSET ?"""
- cursor1.execute(sqlstr1, (tableName_utf8, row,))
- result1 = cursor1.fetchall()
- list1 = result1[0]
- # 100%准确查询
- # sqlstr3 = """SELECT * FROM GC_Input_Point WHERE TableName = ? and New_SPName = ? and New_EPName = ? and New_HDiff = ? and New_RLen = ?"""
- # cursor1.execute(sqlstr3, (tableName_utf8, list1[7], list1[8], list1[11], list1[12],))
- # result3 = cursor1.fetchall()
- sqlstr2 = """DELETE FROM GC_Input_Point WHERE TableName = ? and New_SPName = ? and New_EPName = ? and New_HDiff = ? and New_RLen = ?"""
- cursor1.execute(sqlstr2, (tableName_utf8, list1[7], list1[8], list1[11], list1[12],))
- # # 获取删除的记录数量
- # deleted_count = cursor1.rowcount
- # 直接使用计算方式
- tableName = tableName_utf8.decode('utf-8')
- # 先把结果相关的点数据删一下
- sqlstr3 = """DELETE FROM GC_Output_Point WHERE TableName = ?"""
- cursor1.execute(sqlstr3, (tableName_utf8,))
- # 提交事务
- db1.commit()
- # 关闭db
- db1.close()
- GCcompute.main_function(tableName, dbPath)
- GCshow.main_function(self.ui, dbPath, tableName_utf8)
- elif methodName == '控制网复测平面基准计算':
- sqlstr1 = """SELECT * FROM GS_Input_Point WHERE TableName = ? LIMIT 1 OFFSET ?"""
- cursor1.execute(sqlstr1, (tableName_utf8, row,))
- result1 = cursor1.fetchall()
- list1 = result1[0]
- # 100%准确查询
- # sqlstr3 = """SELECT * FROM GC_Input_Point WHERE TableName = ? and New_SPName = ? and New_EPName = ? and New_HDiff = ? and New_RLen = ?"""
- # cursor1.execute(sqlstr3, (tableName_utf8, list1[7], list1[8], list1[11], list1[12],))
- # result3 = cursor1.fetchall()
- sqlstr2 = """DELETE FROM GS_Input_Point WHERE TableName = ? and PointName = ? and New_X = ? and New_Y = ?"""
- cursor1.execute(sqlstr2, (tableName_utf8, list1[7], list1[5], list1[6],))
- # # 获取删除的记录数量
- # deleted_count = cursor1.rowcount
- # 直接使用计算方式
- tableName = tableName_utf8.decode('utf-8')
- # 先把结果相关的点和参数删一下
- sqlstr3 = """DELETE FROM GS_Result_Point WHERE TableName = ?"""
- cursor1.execute(sqlstr3, (tableName_utf8,))
- sqlstr4 = """DELETE FROM GS_Trans_Point WHERE TableName = ?"""
- cursor1.execute(sqlstr4, (tableName_utf8,))
- sqlstr5 = """DELETE FROM GS_Trans_Param WHERE TableName = ?"""
- cursor1.execute(sqlstr5, (tableName_utf8,))
- # 提交事务
- db1.commit()
- # 关闭db
- db1.close()
- GScompute.main_function(tableName, dbPath)
- GSshow.main_function(self.ui, dbPath, tableName_utf8)
- else:
- # 平面控制网稳定性计算
- sqlstr1 = """SELECT * FROM WD_Input_Point WHERE TableName = ? LIMIT 1 OFFSET ?"""
- cursor1.execute(sqlstr1, (tableName_utf8, row,))
- result1 = cursor1.fetchall()
- list1 = result1[0]
- # 100%准确查询
- # sqlstr3 = """SELECT * FROM GC_Input_Point WHERE TableName = ? and New_SPName = ? and New_EPName = ? and New_HDiff = ? and New_RLen = ?"""
- # cursor1.execute(sqlstr3, (tableName_utf8, list1[7], list1[8], list1[11], list1[12],))
- # result3 = cursor1.fetchall()
- sqlstr2 = """DELETE FROM WD_Input_Point WHERE TableName = ? and PointName = ? and New_X = ? and New_Y = ?"""
- cursor1.execute(sqlstr2, (tableName_utf8, list1[11], list1[8], list1[9],))
- # # 获取删除的记录数量
- # deleted_count = cursor1.rowcount
- # 直接使用计算方式
- tableName = tableName_utf8.decode('utf-8')
- # 先把结果相关的点和参数删一下
- sqlstr3 = """DELETE FROM WD_Result_Point WHERE TableName = ?"""
- cursor1.execute(sqlstr3, (tableName_utf8,))
- sqlstr4 = """DELETE FROM WD_Result_Param WHERE TableName = ?"""
- cursor1.execute(sqlstr4, (tableName_utf8,))
- # 提交事务
- db1.commit()
- # 关闭db
- db1.close()
- WDcompute.main_function(tableName, dbPath)
- WDshow.main_function(self.ui, dbPath, tableName_utf8)
-
- #编辑完后的数据更新
- #输入模型,方法,表名utf8,数据库
- def update_to_db(self,model1,methodName, tableName_utf8, dbPath):
- print(dbPath)
- db1 = sqlite3.connect(dbPath)
- cursor1 = db1.cursor()
- #副本名
- copyname = tableName_utf8 + 'copy'.encode('utf-8')
- #初始化三个布尔值
- bool_1 = 1
- bool_2 = 1
- bool_3 = 1
- # 通过行锁定对应的字段
- if methodName == '水准测段高差稳定计算':
- try:
- #读取有用的数据,按格式录入
- data = GC.get_data_from_excel1(model1)
- cell_values = GC.read_cells_from_excel1(model1)
- ms_station = float(model1[0][12])
- last_station_count = GC.get_last_numeric_cell_value1(model1, 2)
- new_station_count = GC.get_last_numeric_cell_value1(model1, 7)
- last_sum_hdiff = GC.calculate_column_sum1(model1, 4)
- last_sum_rlen = GC.calculate_column_sum1(model1, 5)
- new_sum_hdiff = GC.calculate_column_sum1(model1, 9)
- new_sum_rlen = GC.calculate_column_sum1(model1, 10)
-
- #存个副本,如果有错还能回退
- sqlnew1 = """UPDATE GC_Input_Point SET TableName = ? WHERE TableName = ? """
- cursor1.execute(sqlnew1, (copyname,tableName_utf8,))
- sqlnew2 = """UPDATE GC_Input_Param SET TableName = ? WHERE TableName = ? """
- cursor1.execute(sqlnew2, (copyname, tableName_utf8,))
- sqlnew3 = """UPDATE GC_Output_Point SET TableName = ? WHERE TableName = ? """
- cursor1.execute(sqlnew3, (copyname, tableName_utf8,))
- # 提交事务
- db1.commit()
- # 关闭db
- db1.close()
- # 直接使用计算方式
- tableName = tableName_utf8.decode('utf-8')
- # 重新更新数据库
- GC.insert_into_database(tableName, cell_values, ms_station, last_station_count, new_station_count,
- last_sum_hdiff,
- new_sum_hdiff, last_sum_rlen, new_sum_rlen, dbPath, tableName_utf8)
- GC.insert_data_into_database(data, tableName, cell_values, dbPath, tableName_utf8)
- bool_1 = GCcompute.main_function(tableName, dbPath)
- except:
- bool_1 = -1
-
- if bool_1 == 1:
- GCshow.main_function(self.ui, dbPath, tableName_utf8)
- # 把所有相关的表都删除
- UIFunctions.clear_db_data(self, methodName, copyname, dbPath)
- else:
- # 把所有相关的表都删除
- UIFunctions.clear_db_data(self,methodName,tableName_utf8, dbPath)
- #把副本改回来
- db1 = sqlite3.connect(dbPath)
- cursor1 = db1.cursor()
- # 存个副本,如果有错还能回退
- sqlnew1 = """UPDATE GC_Input_Point SET TableName = ? WHERE TableName = ? """
- cursor1.execute(sqlnew1, (tableName_utf8,copyname,))
- sqlnew2 = """UPDATE GC_Input_Param SET TableName = ? WHERE TableName = ? """
- cursor1.execute(sqlnew2, (tableName_utf8,copyname, ))
- sqlnew3 = """UPDATE GC_Output_Point SET TableName = ? WHERE TableName = ? """
- cursor1.execute(sqlnew3, (tableName_utf8,copyname, ))
- # 提交事务
- db1.commit()
- # 关闭db
- db1.close()
- elif methodName == '控制网复测平面基准计算':
- try:
- #读取模型
- ii = 0
- pastname = model1[0][6]
- newname = model1[0][7]
- pjbc = float(model1[0][8])
- fxzwc = float(model1[0][9])
- zrbzwc = float(model1[0][10])
- points = len(model1)
- zbs = float(model1[0][11])
- zfxs = float(model1[0][12])
- sf = float(model1[0][13])
- pjbcs = zbs / points
- pjfxs = zfxs / points
- listname1 = []
- listpastx1 = []
- listpasty1 = []
- listcgcs1 = []
- listnewx1 = []
- listnewy1 = []
- while ii < len(model1):
- if model1[ii][0] == '' or model1[ii][0] == None:
- ii = ii + 1
- else:
- listname1.append(model1[ii][0])
- listpastx1.append(model1[ii][1])
- listpasty1.append(model1[ii][2])
- listnewx1.append(model1[ii][3])
- listnewy1.append(model1[ii][4])
- listcgcs1.append(model1[ii][5])
- ii = ii + 1
- sqlnew1 = """UPDATE GS_Input_Point SET TableName = ? WHERE TableName = ? """
- cursor1.execute(sqlnew1, (copyname, tableName_utf8,))
- sqlnew2 = """UPDATE GS_Input_Param SET TableName = ? WHERE TableName = ? """
- cursor1.execute(sqlnew2, (copyname, tableName_utf8,))
- sqlnew3 = """UPDATE GS_Result_Point SET TableName = ? WHERE TableName = ? """
- cursor1.execute(sqlnew3, (copyname, tableName_utf8,))
- sqlnew4 = """UPDATE GS_Trans_Point SET TableName = ? WHERE TableName = ? """
- cursor1.execute(sqlnew4, (copyname, tableName_utf8,))
- sqlnew5 = """UPDATE GS_Trans_Param SET TableName = ? WHERE TableName = ? """
- cursor1.execute(sqlnew5, (copyname, tableName_utf8,))
-
- # 提交事务
- db1.commit()
- # 关闭db
- db1.close()
- # 直接使用计算方式
- tableName = tableName_utf8.decode('utf-8')
- #重新更新数据库
- GS.insert_into_database(dbPath, pastname, newname, tableName, listname1, listpastx1, listpasty1, listcgcs1, listnewx1,
- listnewy1, pjbc, fxzwc, zrbzwc, points, zbs, zfxs, sf, pjbcs, pjfxs)
- bool_2 = GScompute.main_function(tableName, dbPath)
- except:
- bool_2 = -1
- if bool_2 == 1:
- GSshow.main_function(self.ui, dbPath, tableName_utf8)
- # 把所有相关的表都删除
- UIFunctions.clear_db_data(self, methodName, copyname, dbPath)
- else:
- # 把所有相关的表都删除
- UIFunctions.clear_db_data(self, methodName, tableName_utf8, dbPath)
- # 把副本改回来
- db1 = sqlite3.connect(dbPath)
- cursor1 = db1.cursor()
- # 存个副本,如果有错还能回退
- sqlnew1 = """UPDATE GS_Input_Point SET TableName = ? WHERE TableName = ? """
- cursor1.execute(sqlnew1, (tableName_utf8,copyname, ))
- sqlnew2 = """UPDATE GS_Input_Param SET TableName = ? WHERE TableName = ? """
- cursor1.execute(sqlnew2, (tableName_utf8,copyname, ))
- sqlnew3 = """UPDATE GS_Result_Point SET TableName = ? WHERE TableName = ? """
- cursor1.execute(sqlnew3, (tableName_utf8,copyname, ))
- sqlnew4 = """UPDATE GS_Trans_Point SET TableName = ? WHERE TableName = ? """
- cursor1.execute(sqlnew4, (tableName_utf8,copyname, ))
- sqlnew5 = """UPDATE GS_Trans_Param SET TableName = ? WHERE TableName = ? """
- cursor1.execute(sqlnew5, (tableName_utf8,copyname, ))
- # 提交事务
- db1.commit()
- # 关闭db
- db1.close()
- else:
- try:
- # 读取模型
- ii = 0
- bename = model1[0][8]
- pastname = model1[0][9]
- newname = model1[0][10]
- pjbc = float(model1[0][11])
- fxzwc = float(model1[0][12])
- points = len(model1)
- zbs = float(model1[0][13])
- zfxs = float(model1[0][14])
- sf = float(model1[0][15])
- pjbcs = zbs / points
- pjfxs = zfxs / points
- listbex1 = []
- listbey1 = []
- listname1 = []
- listpastx1 = []
- listpasty1 = []
- listcgcs1 = []
- listnewx1 = []
- listnewy1 = []
- while ii < len(model1):
- if model1[ii][0] == '' or model1[ii][0] == None:
- ii = ii + 1
- else:
- listname1.append(model1[ii][0])
- listbex1.append(model1[ii][1])
- listbey1.append(model1[ii][2])
- listpastx1.append(model1[ii][3])
- listpasty1.append(model1[ii][4])
- listcgcs1.append(model1[ii][5])
- listnewx1.append(model1[ii][6])
- listnewy1.append(model1[ii][7])
- ii = ii + 1
- sqlnew1 = """UPDATE WD_Input_Point SET TableName = ? WHERE TableName = ? """
- cursor1.execute(sqlnew1, (copyname, tableName_utf8,))
- sqlnew2 = """UPDATE WD_Input_Param SET TableName = ? WHERE TableName = ? """
- cursor1.execute(sqlnew2, (copyname, tableName_utf8,))
- sqlnew3 = """UPDATE WD_Result_Point SET TableName = ? WHERE TableName = ? """
- cursor1.execute(sqlnew3, (copyname, tableName_utf8,))
- sqlnew5 = """UPDATE WD_Result_Param SET TableName = ? WHERE TableName = ? """
- cursor1.execute(sqlnew5, (copyname, tableName_utf8,))
- # 提交事务
- db1.commit()
- # 关闭db
- db1.close()
- # 直接使用计算方式
- tableName = tableName_utf8.decode('utf-8')
- WD.insert_into_database(dbPath, pastname, newname, bename, tableName, listname1, listpastx1, listpasty1,
- listcgcs1, pjbc, fxzwc, points, zbs, zfxs, sf, pjbcs, pjfxs, listbex1, listbey1,
- listnewx1, listnewy1)
- bool_3 = WDcompute.main_function(tableName, dbPath)
- except:
- bool_3 = -1
- if bool_3 == 1:
- WDshow.main_function(self.ui, dbPath, tableName_utf8)
- # 把所有相关的表都删除
- UIFunctions.clear_db_data(self, methodName, copyname, dbPath)
- else:
- # 把所有相关的表都删除
- UIFunctions.clear_db_data(self, methodName, tableName_utf8, dbPath)
- # 把副本改回来
- db1 = sqlite3.connect(dbPath)
- cursor1 = db1.cursor()
- # 存个副本,如果有错还能回退
- sqlnew1 = """UPDATE WD_Input_Point SET TableName = ? WHERE TableName = ? """
- cursor1.execute(sqlnew1, (tableName_utf8, copyname,))
- sqlnew2 = """UPDATE WD_Input_Param SET TableName = ? WHERE TableName = ? """
- cursor1.execute(sqlnew2, (tableName_utf8, copyname,))
- sqlnew3 = """UPDATE WD_Result_Point SET TableName = ? WHERE TableName = ? """
- cursor1.execute(sqlnew3, (tableName_utf8, copyname,))
- sqlnew5 = """UPDATE WD_Result_Param SET TableName = ? WHERE TableName = ? """
- cursor1.execute(sqlnew5, (tableName_utf8, copyname,))
- # 提交事务
- db1.commit()
- # 关闭db
- db1.close()
- if bool_1 == -1 or bool_2 == -1 or bool_3 == -1:
- return -1
- else:
- return 1
- # END - GUI DEFINITIONS
|