def export_data(self): if (self.report_table.rowCount() == 0): gui_helper.prompt_error("Please enter a query") return file_path = gui_helper.prompt_file_save() if (not file_path): return with PdfPages(file_path) as pdf: conn = database.get_db_connection() for i in range(self.report_table.rowCount()): query_text = self.report_table.item(i, 1).text() graph_type = self.report_table.item(i, 0).text() dict_values = query.manual_sql_query(conn, query_text) try: plt = self.export_graph_options[graph_type](graph_type, dict_values) fig = plt.gcf() pdf.savefig() plt.close(fig) except Exception as e: gui_helper.prompt_error( "Failed to export graph {}: ".format(i) + repr(e)) conn.close() gui_helper.prompt_information( "Graphs has been successfully exported")
def run_query(self): try: dict_values = database.execute_query_result( str(self.cb.currentText())) if (dict_values): self.populateTable(dict_values) gui_helper.prompt_information("query executed successfully") except Exception as e: gui_helper.prompt_error("Failed to run Query: " + repr(e))
def removeClicked(self): try: index = self.cb.currentIndex() editid = self.preset_queries[index][0] presetquery.remove_preset(editid) gui_helper.prompt_information("query removed successfully") self._populate_preset_combobox() except Exception as e: gui_helper.prompt_error("Failed to remove preset query: " + repr(e))
def addpresetclicked(self): query_text = self.query.toPlainText() description_text = self.description.toPlainText() if (not query_text or not description_text): gui_helper.prompt_error("Please enter a query and description") return try: presetquery.write_preset(query_text, description_text) gui_helper.prompt_information("query added successfully") except Exception as e: gui_helper.prompt_error("Failed to add preset query: " + repr(e))
def run_query(self): query = self.query.toPlainText() if (len(query) == 0): prompt_error("Please enter a query") return try: dict_values = database.execute_query_result(query) if (dict_values): self.populateTable(dict_values) gui_helper.prompt_information("query executed successfully") except Exception as e: gui_helper.prompt_error(str(e))
def submit_new_iCare_template(self): template_name = self.iCare_template_name.text() if (not template_name): prompt_error("Please give a Template name") return if (not self.filepaths): prompt_error("Please select a Template file") return pyxl.add_new_template(template_name, self.filepaths[0]) prompt_information( "New template: '{}' has been added".format(template_name)) self.iCare_template_name.setText("") self.filepaths = []
def editClicked(self): query_text = self.query.toPlainText() description_text = self.description.toPlainText() if (not query_text or not description_text): gui_helper.prompt_error("Please enter a query and description") return try: index = self.cb.currentIndex() editid = self.preset_queries[index][0] presetquery.edit_preset(editid, self.query.toPlainText(), self.description.toPlainText()) gui_helper.prompt_information("query edited successfully") self._populate_preset_combobox() except Exception as e: gui_helper.prompt_error("Failed to edit preset query: " + repr(e))
def export_data(self): query_text = self.query.toPlainText() if (len(query_text) == 0): gui_helper.prompt_error("Please enter a query") return export_option = self.export_options[self.export_combobox.currentText()] file_path = gui_helper.prompt_file_save() if (not file_path): return try: export_option.export(file_path, query_text) gui_helper.prompt_information("Data has been succesfully exported!") except Exception as e: gui_helper.prompt_error("Failed to export data: " + repr(e))
def submit_new_iCare_template(self): template_name = self.iCare_template_name.text() if (not template_name): prompt_error("Please give a Template name") return if (not self.filepaths): prompt_error("Please select a Template file") return columnNames, columnTypes = self.aggregateTableData() database.add_new_template(template_name, columnNames, columnTypes) prompt_information( "New template: '{}' has been added".format(template_name)) self.iCare_template_name.setText("") self.filepaths = []
def submit_iCare_data(self): if (not self.filepaths): gui_helper.prompt_error("Please select an xlsx file") return template_name = self.iCare_combobox.currentText() if (not template_name): gui_helper.prompt_error("Please select a type") return for filepath in self.filepaths: try: database.insert_iCare_data(template_name, filepath) except Exception as e: gui_helper.prompt_error(repr(e)) return gui_helper.prompt_information( "Data has been successfully added to the database")
def add_agency(self): mydb_conn = mysql.connector.connect(host=db_config.host, database=db_config.database, user=db_config.user, password=db_config.password) mydb_conn.autocommit = True try: my_cursor = mydb_conn.cursor() my_cursor.execute("USE testdb") # Add agency information to the database my_cursor.execute( "INSERT INTO User(AgencyName, AgencyAddress, UserEmail, UserPassword, UserName, UserType) VALUES('%s', '%s', '%s', '%s', '%s', '%s')" % (''.join(self.agencyName.text()), ''.join( self.agencyAddress.text()), ''.join(self.userEmail.text()), ''.join(self.userPassword.text()), ''.join( self.userName.text()), ''.join(self.userType.text()))) # QMessageBox.about(self, 'Connection', "Agency Added!") emailAPI.sendEmail(self.userEmail.text(), self.userPassword.text()) gui_helper.prompt_information("User has been added") except Error as error: print(error) finally: mydb_conn.close()
def on_click(self): # show file dialog for user to name their file dialog = QFileDialog() dialog.setFileMode(QFileDialog.AnyFile) if dialog.exec_(): filepaths = dialog.selectedFiles() file_name = filepaths[0] # get the index of selected preset query index = self.cb.currentIndex() # get query at that index quer = self.preset_queries[index][1] # get selected export option export_option = self.export_options[ self.export_combobox.currentText()] try: export_option.export(file_name, quer) gui_helper.prompt_information( "Data has been succesfully exported!") except Exception as e: gui_helper.prompt_error("Failed to export data: " + str(e))
def file_save(self, file_path, dataframe): if (exportFile.exportCSV(file_path, dataframe)): gui_helper.prompt_information("File has been succesfully saved!") else: gui_helper.prompt_error("Failed to save file")