ИСПОЛЬЗОВАНИЕ РЕЗУЛЬТАТОВ ПОИСКА В SQLITE3 И РАЗМЕЩЕНИЕ ЕГО В GUI PYQT6 [закрыто]Python

Программы на Python
Anonymous
ИСПОЛЬЗОВАНИЕ РЕЗУЛЬТАТОВ ПОИСКА В SQLITE3 И РАЗМЕЩЕНИЕ ЕГО В GUI PYQT6 [закрыто]

Сообщение Anonymous »

Я использую PyQt6, Sqlite3 и Python для создания настольного приложения, но возникла тупиковая ситуация: у меня есть следующее окно, в котором он выполняет поиск в базе данных и помещает нужную мне информацию в Qwitget, когда я дважды щелкаю, он должен открыть искомую информацию и поместить ее в новое окно, но у меня все пусто.

Код: Выделить всё

`import sqlite3
import sys
from time import strftime
from PyQt6 import uic
from PyQt6.QtCore import Qt,pyqtSignal
from PyQt6 import QtCore, QtGui, QtWidgets
from PyQt6.QtGui import QPixmap
from PyQt6.QtWidgets import (
QApplication,
QCheckBox,
QComboBox,
QDateEdit,
QDateTimeEdit,
QDial,
QDoubleSpinBox,
QFontComboBox,
QLabel,
QLCDNumber,
QLineEdit,
QAbstractItemView,
QMainWindow,
QProgressBar,
QPushButton,
QRadioButton,
QSlider,
QSpinBox,
QTimeEdit,
QVBoxLayout,
QWidget,
QTableWidgetItem
)
from editar import EditarUi_Dialog
from logistica import Ui_LogisticaDialog
from logisticaform import  WindowPedidoLogEditar

class WindowLogisticsview(QtWidgets.QDialog, EditarUi_Dialog):
def __init__(self):
super().__init__()
self.setupUi(self)
self.label.setPixmap(QPixmap('UI/Logo Sirf.png'))
self.BtnLogBuscar.clicked.connect(self.searchPedLog)
self.tableWidget.clearContents()
self.procesador = WindowPedidoLogEditar()

def searchPedLog(self):

try:
Id_Ped = self.TxtLogpedido.text()
Pendiente = self.ChkPendiente.isChecked()
Despachado = self.ChkDespachado.isChecked()

condiciones = []
parametros = []

if Id_Ped:
condiciones.append("Id_Pedido LIKE ?")
parametros.append(f'%{Id_Ped}%')

if Pendiente:
condiciones.append("status = ?")
parametros.append("Pendiente")

if Despachado:
condiciones.append("status = ?")
parametros.append("Despachado")
#if todo:
#condiciones.append("Pendiente OR despachado = ?")
#parametros.append(1)

db = sqlite3.connect('dbsirf.db')
cursor = db.cursor()
query = "SELECT Id_Pedido, cliente, destino, status, CASE WHEN status = status THEN 'Pendiente' WHEN status = status THEN 'Despachado' ELSE 'todo' END FROM pedidosencab"
#params = (f'%{Id_Ped}%','%{pedido}%',)
if condiciones:
query += " WHERE " + " AND ".join(condiciones)
cursor = db.cursor()
cursor.execute(query, tuple(parametros))
ResultSearch = cursor.fetchall()

if ResultSearch:
mbox = QtWidgets.QMessageBox()
mbox.setIcon(QtWidgets.QMessageBox.Icon.Information)
mbox.setWindowTitle(" 🍑 Oops!")
mbox.setText("buscando[/b] ")[b]                mbox.exec()
self.datos = ResultSearch
self.tableWidget.setColumnCount(4)
self.tableWidget.setHorizontalHeaderLabels(['Pedido', 'cliente', 'destino', 'estado'])
self.tableWidget.setEditTriggers(QAbstractItemView.EditTrigger.NoEditTriggers)
self.tableWidget.setRowCount(len(self.datos))
for fila_index, fila_datos in enumerate(self.datos):
for col_index, dato in enumerate(fila_datos):
item = QTableWidgetItem(str(dato))
self.tableWidget.setItem(fila_index, col_index, item)

self.tableWidget.cellDoubleClicked.connect(self.editar_pedido)
else:
mbox = QtWidgets.QMessageBox()
mbox.setIcon(QtWidgets.QMessageBox.Icon.Critical)
mbox.setWindowTitle(" 🍑 Oops!")
mbox.setText("No se encontraron registros[/b] ")[b]                mbox.exec()
except sqlite3.Error as e:
mbox = QtWidgets.QMessageBox()
mbox.setIcon(QtWidgets.QMessageBox.Icon.Critical)
mbox.setWindowTitle("  🍑 Oops!")
mbox.setText("Error al buscar el pedido: {}[/b] ".format(e))[b]                mbox.exec()
finally:
cursor.close()
db.close()

def editar_pedido(self,row, col):
#print(f"Doble clic en la fila: {row}, columna: {col}")
row_content = []
for col in range(self.tableWidget.columnCount()):
cell_item = self.tableWidget.item(row, 0)
if cell_item is not None:
row_content.append(cell_item.text())
order_found = cell_item.text()
ped = WindowPedidoLogEditar()
self.procesador.load_order_details(order_found)
ped.exec()

else:
mbox = QtWidgets.QMessageBox()
mbox.setIcon(QtWidgets.QMessageBox.Icon.Critical)
mbox.setWindowTitle(" 🍑 Oops!")
mbox.setText("Error al buscar el pedido: {}[/b] ")
mbox.exec()
return order_found

if __name__ == '__main__':
app = QtWidgets.QApplication([QMainWindow])

window = WindowLogisticsview()
window.show()
sys.exit(app.exec())
`
после этого я использую следующее окно, чтобы назначить результаты qlabels, но оно не позволяет их использовать

Код: Выделить всё

`import sqlite3
import sys
from time import strftime
from PyQt6 import uic
from PyQt6.QtCore import Qt,pyqtSignal
from PyQt6 import QtCore, QtGui, QtWidgets
from PyQt6.QtGui import QPixmap
from PyQt6.QtWidgets import (
QApplication,
QCheckBox,
QComboBox,
QDateEdit,
QDateTimeEdit,
QDial,
QDoubleSpinBox,
QFontComboBox,
QLabel,
QLCDNumber,
QLineEdit,
QAbstractItemView,
QMainWindow,
)
from editar import EditarUi_Dialog
from logistica import Ui_LogisticaDialog

class WindowPedidoLogEditar(QtWidgets.QDialog, Ui_LogisticaDialog):

def __init__(self):
super().__init__()
self.setupUi(self)
self.label.setPixmap(QPixmap('UI/Logo Sirf.png'))
self.TxtPlaNumeroPedido.setText("")
self.LlenarFormularioLog()
def LlenarFormularioLog(self):
self.TxtLogCliente.setText("Hola Luis Vidal")

def load_order_details(self,order_found):
self.FinalNumber = str(order_found)
print(self.FinalNumber)
try:
db = sqlite3.connect('dbsirf.db')
cursor = db.cursor()
cursor.execute("SELECT * FROM pedidosencab WHERE id_Pedido = '{}'".format(order_found))
ResultSearch = cursor.fetchone()
print(ResultSearch)
self.TxtLogCliente.setText(cliente) #deberia traerme la información del Cliente
self.TxtLogPedido.setText(Id_Pedido)#deberia traerme la información del pedido
Valor
return ResultSearch

except sqlite3.Error as e:
print(f"Error de base de datos: {e}")
finally:
cursor.close()
db.close()

if __name__ == '__main__':
app = QtWidgets.QApplication([QMainWindow])

window = WindowPedidoLogEditar()
window.show()
sys.exit(app.exec())`
Я ценю вашу помощь

Подробнее здесь: https://stackoverflow.com/questions/797 ... i-de-pyqt6

Вернуться в «Python»