SelectLogDialog.py 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254
  1. import sys
  2. from stringprep import in_table_c11
  3. from PyQt6.QtWidgets import QApplication, QMainWindow, QVBoxLayout, QHBoxLayout, QWidget, QPushButton, QTabWidget, QLabel, QLineEdit, QTextEdit, QFormLayout, QMessageBox, QTreeWidget, QTreeWidgetItem, QDialog, QVBoxLayout as QDialogVBoxLayout, QLineEdit as QDialogLineEdit, QDialogButtonBox, QCheckBox, QComboBox
  4. from PyQt6.QtCore import Qt
  5. import requests as req
  6. import time,random,numpy as np
  7. import threading
  8. import asyncio
  9. import json
  10. from PyQt6.QtWidgets import QFileDialog
  11. from PyQt6.QtCore import pyqtSignal, QObject,pyqtSlot
  12. import sqlite3
  13. from EditSelectLogDialog import EditSelectLogDialog
  14. class SelectLogDialog(QDialog):
  15. def __init__(self, parent=None, title="添加选品日志"):
  16. super().__init__(parent)
  17. self.setWindowTitle(title)
  18. self.setGeometry(100, 100, 600, 400)
  19. layout = QDialogVBoxLayout()
  20. # 商品ID输入框
  21. item_id_label = QLabel("商品ID")
  22. self.item_id_edit = QDialogLineEdit()
  23. layout.addWidget(item_id_label)
  24. layout.addWidget(self.item_id_edit)
  25. # 商品名称输入框
  26. item_name_label = QLabel("商品名称")
  27. self.item_name_edit = QDialogLineEdit()
  28. layout.addWidget(item_name_label)
  29. layout.addWidget(self.item_name_edit)
  30. # 磨损最低值输入框
  31. min_wear_label = QLabel("磨损最低值")
  32. self.min_wear_edit = QDialogLineEdit()
  33. layout.addWidget(min_wear_label)
  34. layout.addWidget(self.min_wear_edit)
  35. # 磨损最高值输入框
  36. max_wear_label = QLabel("磨损最高值")
  37. self.max_wear_edit = QDialogLineEdit()
  38. layout.addWidget(max_wear_label)
  39. layout.addWidget(self.max_wear_edit)
  40. # 全磨损区间最低价输入框
  41. min_full_wear_price_label = QLabel("全磨损区间最低价")
  42. self.min_full_wear_price_edit = QDialogLineEdit()
  43. layout.addWidget(min_full_wear_price_label)
  44. layout.addWidget(self.min_full_wear_price_edit)
  45. # 扫货价输入框
  46. sweep_price_label = QLabel("扫货价")
  47. self.sweep_price_edit = QDialogLineEdit()
  48. layout.addWidget(sweep_price_label)
  49. layout.addWidget(self.sweep_price_edit)
  50. # 判断价输入框
  51. judge_price_label = QLabel("判断价")
  52. self.judge_price_edit = QDialogLineEdit()
  53. layout.addWidget(judge_price_label)
  54. layout.addWidget(self.judge_price_edit)
  55. # 时间输入框
  56. timestamp_label = QLabel("时间")
  57. self.timestamp_edit = QDialogLineEdit()
  58. layout.addWidget(timestamp_label)
  59. layout.addWidget(self.timestamp_edit)
  60. button_box = QDialogButtonBox(QDialogButtonBox.StandardButton.Ok | QDialogButtonBox.StandardButton.Cancel)
  61. button_box.accepted.connect(self.accept)
  62. button_box.rejected.connect(self.reject)
  63. layout.addWidget(button_box)
  64. self.setLayout(layout)
  65. @staticmethod
  66. def export_selected_logs(self):
  67. # 获取选中的日志项
  68. selected_items = self.select_log_tree_widget.selectedItems()
  69. if not selected_items:
  70. QMessageBox.warning(self, "导出选品日志", "请选择要导出的日志项")
  71. return
  72. # 将选中的日志项转换为字典列表
  73. logs = {}
  74. for item in selected_items:
  75. logs[item.text(1)] = {
  76. "price":item.text(6),
  77. "min_paintwear":item.text(3),
  78. "max_paintwear" :item.text(4),
  79. "name":item.text(2),
  80. '商品ID': item.text(1),
  81. '商品名称': item.text(2),
  82. '磨损最低值': item.text(3),
  83. '磨损最高值': item.text(4),
  84. '全磨损区间最低价': item.text(5),
  85. '扫货价': item.text(6),
  86. '判断价': item.text(7),
  87. '时间': item.text(8)
  88. }
  89. # 选择保存文件的路径
  90. file_path, _ = QFileDialog.getSaveFileName(self, "导出选品日志", "", "JSON Files (*.json)")
  91. if file_path:
  92. try:
  93. with open(file_path, 'w', encoding='utf-8') as f:
  94. json.dump(logs, f, ensure_ascii=False, indent=4)
  95. QMessageBox.information(self, "导出选品日志", f"日志已成功导出到 {file_path}")
  96. except Exception as e:
  97. QMessageBox.critical(self, "导出选品日志", f"导出日志时发生错误: {e}")
  98. @staticmethod
  99. def save_select_logs(self):
  100. # 连接到SQLite数据库
  101. conn = sqlite3.connect('buff.db')
  102. cursor = conn.cursor()
  103. # 清空表中的数据
  104. cursor.execute('DELETE FROM select_logs')
  105. # 获取树形控件中的所有项
  106. for i in range(self.select_log_tree_widget.topLevelItemCount()):
  107. item = self.select_log_tree_widget.topLevelItem(i)
  108. item_id = item.text(1)
  109. item_name = item.text(2)
  110. min_wear = item.text(3)
  111. max_wear = item.text(4)
  112. #判断item.text(5)是否为''
  113. if item.text(5) == '':
  114. min_full_wear_price = 0
  115. else:
  116. min_full_wear_price = float(item.text(5))
  117. #判断item.text(6)是否为''
  118. if item.text(6) == '':
  119. sweep_price = 0
  120. else:
  121. sweep_price = float(item.text(6))
  122. #判断item.text(7)是否为''
  123. if item.text(7) == '':
  124. judge_price = 0
  125. else:
  126. judge_price = float(item.text(7))
  127. timestamp = item.text(8)
  128. # 插入数据到表中
  129. cursor.execute('''
  130. INSERT INTO select_logs (item_id, item_name, min_wear, max_wear, min_full_wear_price, sweep_price, judge_price, timestamp)
  131. VALUES (?, ?, ?, ?, ?, ?, ?, ?)
  132. ''', (item_id, item_name, min_wear, max_wear, min_full_wear_price, sweep_price, judge_price, timestamp))
  133. # 提交更改并关闭连接
  134. conn.commit()
  135. conn.close()
  136. QMessageBox.information(self, "保存选品日志", "选品日志已成功保存")
  137. @staticmethod
  138. def edit_select_log(self):
  139. # 获取选中的日志项
  140. selected_items = self.select_log_tree_widget.selectedItems()
  141. if len(selected_items) != 1:
  142. QMessageBox.warning(self, "编辑选品日志", "请选择一个选品日志进行编辑")
  143. return
  144. item = selected_items[0]
  145. # 获取当前选中的日志项的数据
  146. current_data = {
  147. '商品ID': item.text(1),
  148. '商品名称': item.text(2),
  149. '磨损最低值': item.text(3),
  150. '磨损最高值': item.text(4),
  151. '全磨损区间最低价': item.text(5),
  152. '扫货价': item.text(6),
  153. '判断价': item.text(7),
  154. '时间': item.text(8)
  155. }
  156. # 弹出编辑对话框
  157. dialog = EditSelectLogDialog(self, "编辑选品日志", current_data)
  158. if dialog.exec():
  159. # 获取编辑后的数据
  160. new_item_id = dialog.item_id_edit.text()
  161. new_item_name = dialog.item_name_edit.text()
  162. new_min_wear = dialog.min_wear_edit.text()
  163. new_max_wear = dialog.max_wear_edit.text()
  164. new_min_full_wear_price = dialog.min_full_wear_price_edit.text()
  165. new_sweep_price = dialog.sweep_price_edit.text()
  166. new_judge_price = dialog.judge_price_edit.text()
  167. new_timestamp = dialog.timestamp_edit.text()
  168. # 更新日志项的数据
  169. item.setText(1, new_item_id)
  170. item.setText(2, new_item_name)
  171. item.setText(3, new_min_wear)
  172. item.setText(4, new_max_wear)
  173. item.setText(5, new_min_full_wear_price)
  174. item.setText(6, new_sweep_price)
  175. item.setText(7, new_judge_price)
  176. item.setText(8, new_timestamp)
  177. @staticmethod
  178. def delete_select_log(self):
  179. # 获取选中的日志项
  180. selected_items = self.select_log_tree_widget.selectedItems()
  181. for item in selected_items:
  182. (item.parent() or self.select_log_tree_widget).takeTopLevelItem(self.select_log_tree_widget.indexOfTopLevelItem(item))
  183. @staticmethod
  184. def show_add_select_log_dialog(self):
  185. dialog = SelectLogDialog(self, "添加选品日志")
  186. if dialog.exec():
  187. item_id = dialog.item_id_edit.text()
  188. item_name = dialog.item_name_edit.text()
  189. min_wear = dialog.min_wear_edit.text()
  190. max_wear = dialog.max_wear_edit.text()
  191. min_full_wear_price = dialog.min_full_wear_price_edit.text()
  192. sweep_price = dialog.sweep_price_edit.text()
  193. judge_price = dialog.judge_price_edit.text()
  194. timestamp = dialog.timestamp_edit.text()
  195. SelectLogDialog.add_select_log(self,item_id, item_name, min_wear, max_wear, min_full_wear_price, sweep_price, judge_price, timestamp)
  196. @staticmethod
  197. def add_select_log(self, item_id, item_name, min_wear, max_wear, min_full_wear_price, sweep_price, judge_price, timestamp):
  198. # 创建一个字典来存储记录的详细信息
  199. record = {
  200. '商品ID': item_id,
  201. '商品名称': item_name,
  202. '磨损最低值': min_wear,
  203. '磨损最高值': max_wear,
  204. '全磨损区间最低价': min_full_wear_price,
  205. '扫货价': sweep_price,
  206. '判断价': judge_price,
  207. '时间': timestamp
  208. }
  209. # 将新记录添加到树形控件中
  210. item = QTreeWidgetItem(self.select_log_tree_widget)
  211. item.setText(0, "") # 选择列为空
  212. item.setText(1, record['商品ID'])
  213. item.setText(2, record['商品名称'])
  214. item.setText(3, str(record['磨损最低值']))
  215. item.setText(4, str(record['磨损最高值']))
  216. item.setText(5, str(record['全磨损区间最低价']))
  217. item.setText(6, str(record['扫货价']))
  218. item.setText(7, str(record['判断价']))
  219. item.setText(8, record['时间'])
  220. # 创建复选框
  221. checkbox = QCheckBox()
  222. checkbox.setChecked(False)
  223. self.select_log_tree_widget.setItemWidget(item, 0, checkbox)