php中while($row = $results->fetch_row())调用出错

本文探讨了在PHP编程中使用while循环遍历数据库查询结果时遇到的常见错误,并提供了有效的解决策略,帮助开发者高效定位和修复问题。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

php中while($row = $results->fetch_row())调用出错

 

 

错误处在sql语句上

转载于:https://www.cnblogs.com/Chenshuai7/p/5244945.html

db_config.py里有HOST='localhost' USER='root' PWD='root' DB_PORT=3306 DB_NAME='test'def get_header(tab_name='course'): ''' 根据表名称返回表的标题 :param tab_name: 表的名称 :return: list, 表的标题行 ''' header=None if tab_name=='course': header=['Cno', 'Cname', 'Cpno', 'Ccredit'] elif tab_name=='student': header=['Sno', 'Sname', 'Ssex', 'Sage', 'Sdept'] elif tab_name=='sc': header=['Sno', 'Cno', 'Grade'] elif tab_name=='homework': header=['Sno','Sname','Cno','Hyime','Grade'] elif tab_name=='ducsum': header=['Sno','Sname','Algrade','Avagrade','Rankwork'] return header def trans_data(dict_results): ''' 将[ {'Cno': '01', 'Cname': '高等数学', 'Cpno': None, 'Ccredit': 4}, {'Cno': '02', 'Cname': '大学物理', 'Cpno': '01', 'Ccredit': 3} ] 转换为:[('01', '高等数学', None, 4), ('02', '大学物理', '01', 3) ] :param dict_results: :return: ''' ll=[] for dict in dict_results: ll.append(list(dict.values())) return ll fetch_data_mysql.py里有import pymysql.cursors import db_config def getData(tab_name='tbcourse'): # Connect to the database connection = pymysql.connect(host=db_config.HOST, user=db_config.USER, port=db_config.DB_PORT, password=db_config.PWD, database=db_config.DB_NAME, cursorclass=pymysql.cursors.Cursor) # 使用pymysql.cursors.Cursor时,结果类似于: ( ('01', '高等数学', None, 4), ('02', '大学物理', '01', 3) ) # 使用pymysql.cursors.DictCursor时,结果类似于:[ {'Cno': '01', 'Cname': '高等数学', 'Cpno': None, 'Ccredit': 4}, {'Cno': '02', 'Cname': '大学物理', 'Cpno': '01', 'Ccredit': 3} ] with connection: with connection.cursor() as cursor: # Read a single record sql = f"SELECT * FROM {tab_name};" # cursor.execute(sql, ('webmaster@python.org',)) cursor.execute(sql) results = cursor.fetchall() return results 这里有问题(下面) def getData_aim(tab_name='tbcourse'): # Connect to the database connection = pymysql.connect(host=db_config.HOST, user=db_config.USER, port=db_config.DB_PORT, password=db_config.PWD, database=db_config.DB_NAME, cursorclass=pymysql.cursors.Cursor) # 使用pymysql.cursors.Cursor时,结果类似于: ( ('01', '高等数学', None, 4), ('02', '大学物理', '01', 3) ) # 使用pymysql.cursors.DictCursor时,结果类似于:[ {'Cno': '01', 'Cname': '高等数学', 'Cpno': None, 'Ccredit': 4}, {'Cno': '02', 'Cname': '大学物理', 'Cpno': '01', 'Ccredit': 3} ] with connection: with connection.cursor() as cursor: # Read a single record sql = f"SELECT * FROM {tab_name} where department = 'Sno';" # cursor.execute(sql, ('webmaster@python.org',)) cursor.execute(sql) results = cursor.fetchall() return results def del_row(cno, tab_name='tbCourse'): # Connect to the database connection = pymysql.connect(host=db_config.HOST, user=db_config.USER, port=db_config.DB_PORT, password=db_config.PWD, database=db_config.DB_NAME, cursorclass=pymysql.cursors.Cursor) with connection: try: with connection.cursor() as cursor: # 表格名称不能使用占位符,只能拼接字符串 sql = f"DELETE FROM {tab_name} where CNO=%s;" affected_rows=cursor.execute(sql, (cno,)) # connection is not autocommit by default. So you must commit to save your changes. connection.commit() except: return 0 return affected_rows def insert_row(values, tab_name='tbCourse'): # 这里我们只处理输入值数目为4个的情况 if ((not isinstance(values, list)) and (not isinstance(values,tuple))) or len(values)!=4: raise Exception('type error or length incorrect!!!') # Connect to the database connection = pymysql.connect(host=db_config.HOST, user=db_config.USER, port=db_config.DB_PORT, password=db_config.PWD, database=db_config.DB_NAME, cursorclass=pymysql.cursors.Cursor) with connection: try: with connection.cursor() as cursor: # 表格名称不能使用占位符,只能拼接字符串 sql = f"insert into {tab_name} values (%s, %s, %s, %s);" affected_rows = cursor.execute(sql, values) # connection is not autocommit by default. So you must commit to save your changes. connection.commit() except: return 0 return affected_rows def insert_workrow(values, tab_name='homework'): # 这里我们只处理输入值数目为5个的情况 if ((not isinstance(values, list)) and (not isinstance(values,tuple))) or len(values)!=5: raise Exception('type error or length incorrect!!!') # Connect to the database connection = pymysql.connect(host=db_config.HOST, user=db_config.USER, port=db_config.DB_PORT, password=db_config.PWD, database=db_config.DB_NAME, cursorclass=pymysql.cursors.Cursor) with connection: try: with connection.cursor() as cursor: # 表格名称不能使用占位符,只能拼接字符串 sql = f"insert into {tab_name} values (%s, %s, %s, %s, %s);" affected_rows = cursor.execute(sql, values) # connection is not autocommit by default. So you must commit to save your changes. connection.commit() except: return 0 return affected_rows if __name__ == '__main__': results=getData() print(results) for row in results: print(row) main_gui.py文件里有import FreeSimpleGUI as sg #需要切换为MySQL数据库,请将fetch_data_mssql更改为:fetch_data_mysql from fetch_data_mysql import getData, del_row, insert_row,insert_workrow,getData_aim这里和fetch.data.mysql里的问题一样连一起 from db_config import get_header def open_homework_search(): sublayout_homesearch = [ [sg.T('请输入要查询的学号:', justification='right'), sg.Input('', size=(50, None), key='-sub_Rname-')], [sg.Button('查询', key='-btn_search-')] # 修正2:添加缺失的查询按钮 ] subwin_homeworksearch = sg.Window('搜索', sublayout_homesearch, font=('微软雅黑', 13), modal=True) while True: ev2, dict_vals2 = subwin_homeworksearch.read() # 修正4:read()应小写 if ev2 in (sg.WIN_CLOSED, 'Exit'): break elif ev2 == '-btn_search-': # 修正5:匹配正确的按钮key student_id = dict_vals2['-sub_Rname-'].strip() or None # 修正6:实际执行查询逻辑(原代码直接获取全部数据) result = search_homework_by_student(student_id) sg.popup(f"找到{len(result)}条记录" if result else "未找到记录") break subwin_homeworksearch.close() return result if 'result' in locals() else None def open_rank_system(): layout = [ [sg.T('输入分数:', size=(10,None), justification='right'), sg.Input('', (20, None), key='-INPUT_SCORE-')], [sg.T('等级结果:', size=(10,None), justification='right'), sg.Text('', size=(20,1), key='-OUTPUT_GRADE-')], [sg.Button('转换', key='-btn_rank_system', size=(10,None))] ] window = sg.Window('分数等级转换器', layout, font=('微软雅黑', 13)) while True: event, values = window.read() if event == sg.WIN_CLOSED: break elif event == '-btn_rank_system': try: score = float(values['-INPUT_SCORE-']) if score >= 90: grade = 'A' elif score >= 80: grade = 'B' elif score >= 70: grade = 'C' elif score >= 60: grade = 'D' else: grade = 'E' window['-OUTPUT_GRADE-'].update(grade) except ValueError: sg.popup_error('请输入有效数字!') window.close() def open_hundredsystem(): layout = [ [sg.T('原始数值:', size=(10,None), justification='right'), sg.Input('', (20, None), key='-INPUT_VALUE-')], [sg.T('百分制结果:', size=(10,None), justification='right'), sg.Text('', size=(20,1), key='-OUTPUT_PERCENT-')], [sg.Button('转换', key='-btn_hundred_system', size=(10,None))] ] window = sg.Window('百分制转换器', layout, font=('微软雅黑', 13)) while True: event, values = window.read() if event == sg.WIN_CLOSED: break elif event == '-btn_hundred_system': try: raw_value = float(values['-INPUT_VALUE-']) percent_value = raw_value * 0.1 *0.1 window['-OUTPUT_PERCENT-'].update(f"{percent_value:.2f}%") except ValueError: sg.popup_error('请输入有效数字!') window.close() def open_addHomeworkWindow(): sublayout_homework = [ [sg.T('学号:', size=(None,None), justification='right'), sg.Input('', (50, None), key='-sub_Sno-' )], [sg.T('姓名:', size=(None,None), justification='right'), sg.Input('', (50, None), key='-sub_Sname-' )], [sg.T('课后任务:', size=(None,None), justification='right'), sg.Input('', (50, None), key='-sub_Cno-' )], [sg.T('提交日期:', size=(None,None), justification='right'), sg.Input('', (50, None), key='-sub_Hyime-' )], [sg.T('评分:', size=(None,None), justification='right'), sg.Input('', (50, None), key='-sub_Grade-' )], [sg.Ok('发布', key='-btn_sub_addhomework-',size=(10,None))] ] subwin_addhomework = sg.Window('添加新任务(作业)', sublayout_homework, font=('微软雅黑', 13), modal=True) add_affected_rows = 0 while True: ev2, dict_vals2 = subwin_addhomework.Read() if ev2 == sg.WIN_CLOSED or ev2 == 'Exit': break elif ev2 == '-btn_sub_addhomework-': dict_vals2['-sub_Sno-'] = None if dict_vals2['-sub_Sno-']=='' else dict_vals2['-sub_Sno-'] add_affected_rows = insert_workrow(list(dict_vals2.values()), tab_name='homework') break subwin_addhomework.close() if add_affected_rows>0: sg.popup_timed('发布成功!') if add_affected_rows<=0: sg.popup_timed('发布失败!') return add_affected_rows def open_addCourseWindow(): sublayout_course = [ [sg.T('课程号:', size=(10,None), justification='right'), sg.Input('', (50, None), key='-sub_cno-' )], [sg.T('课程名称:', size=(10,None), justification='right'), sg.Input('', (50, None), key='-sub_cname-' )], [sg.T('先修课:', size=(10,None), justification='right'), sg.Input('', (50, None), key='-sub_cpno-' )], [sg.T('学分:', size=(10,None), justification='right'), sg.Input('', (50, None), key='-sub_ccredit-' )], [sg.Ok('确定', key='-btn_sub_addcourse-',size=(10,None))] ] subwin_addCourse = sg.Window('添加课程信息', sublayout_course, font=('微软雅黑', 13), modal=True) add_affected_rows = 0 while True: ev2, dict_vals2 = subwin_addCourse.Read() if ev2 == sg.WIN_CLOSED or ev2 == 'Exit': break elif ev2 == '-btn_sub_addcourse-': dict_vals2['-sub_cpno-'] = None if dict_vals2['-sub_cpno-']=='' else dict_vals2['-sub_cpno-'] add_affected_rows = insert_row(list(dict_vals2.values()), tab_name='tbCourse') break subwin_addCourse.close() if add_affected_rows>0: sg.popup_timed('插入课程信息成功!') return add_affected_rows def refreshData(table_key='-TABLE_course-', tab_name='tbcourse'): # 刷新表的显示 data_courses = getData(tab_name=tab_name) window[table_key].update(data_courses) return data_courses if __name__ == '__main__': sg.theme('DefaultNoMoreNagging') data_ducsum = getData(tab_name='ducsum') header_ducsum = get_header(tab_name='ducsum') data_homework = getData(tab_name='homework') header_homework = get_header(tab_name='homework') data_courses = getData(tab_name='tbcourse') header_courses = get_header(tab_name='course') data_students = getData(tab_name='tbStuinfo') header_students = get_header(tab_name='student') header_sc = get_header(tab_name='sc') Alsum_layout = [ [sg.Button(button_text='导入'),sg.Button(button_text='导出')], [sg.Table(values=data_ducsum, headings=header_ducsum, size=(550,400), max_col_width=100, auto_size_columns=False, display_row_numbers=False, justification='left', num_rows=15, alternating_row_color='lightyellow', key='-TABLE_course-', selected_row_colors='red on yellow', enable_events=True, expand_x=True, expand_y=True, enable_click_events=True, # Comment out to not enable header and other clicks tooltip='This is a course table') ] ] Grade_layout = [ [sg.Column([ [sg.Text('评分标准模式', justification='center', expand_x=True)], [sg.Push(), sg.Button('百分制',key='-btn_hundred_system'), sg.Push(), sg.Button('分级制',key='-btn_rank_system'), sg.Push()] ], expand_x=True)] ] homework_layout = [ [sg.InputText(),sg.Button(button_text='搜索',key='-btn_homework_search'), sg.Button(button_text='添加',key='-btn_add_homework'), sg.Button(button_text='删除'), sg.Button(button_text='修改') ], [sg.Table(values=data_homework, headings=header_homework, size=(550,400), max_col_width=100, auto_size_columns=False, display_row_numbers=False, justification='left', num_rows=15, alternating_row_color='lightyellow', key='-TABLE_course-', selected_row_colors='red on yellow', enable_events=True, expand_x=True, expand_y=True, enable_click_events=True, # Comment out to not enable header and other clicks tooltip='This is a course table') ], [sg.Button(button_text='上一页', key='-btn_refresh_course-'), sg.Button(button_text='下一页', key='-btn_del_course-') ] ] course_layout = [ [sg.Table(values=data_courses, headings=header_courses, size=(550,400), max_col_width=100, auto_size_columns=False, display_row_numbers=False, justification='left', num_rows=15, alternating_row_color='lightyellow', key='-TABLE_course-', selected_row_colors='red on yellow', enable_events=True, expand_x=True, expand_y=True, enable_click_events=True, # Comment out to not enable header and other clicks tooltip='This is a course table') ], [sg.Button(button_text='刷新', key='-btn_refresh_course-'), sg.Button(button_text='删除', key='-btn_del_course-'), sg.Button(button_text='添加', key='-btn_add_course-') ] ] student_layout = [ [sg.Table(values=data_students, headings=header_students, size=(550, 400), max_col_width=100, auto_size_columns=False, display_row_numbers=False, justification='left', num_rows=15, alternating_row_color='lightyellow', key='-TABLE_Student-', selected_row_colors='red on yellow', enable_events=True, expand_x=True, expand_y=True, enable_click_events=True, # Comment out to not enable header and other clicks tooltip='This is a student table') ], [sg.Button(button_text='刷新', key='-btn_refresh_student-'), sg.Button(button_text='删除', key='-btn_del_student-'), sg.Button(button_text='添加', key='-btn_add_student-') ] ] SC_layout = [[sg.Table(values=[[]], headings=header_sc, # size=(550, 400), max_col_width=100, auto_size_columns=False, display_row_numbers=False, justification='left', num_rows=15, alternating_row_color='lightyellow', key='-TABLE_SC-', selected_row_colors='red on yellow', enable_events=True, expand_x=True, expand_y=True, enable_click_events=True, # Comment out to not enable header and other clicks tooltip='This is a SC table') ], [sg.Button(button_text='刷新', key='-btn_refresh_sc-'), sg.Button(button_text='删除', key='-btn_del_sc-'), sg.Button(button_text='添加', key='-btn_add_sc-') ] ] layout = [[sg.TabGroup([[sg.Tab('首页', homework_layout, key='-tab_homework'), sg.Tab('设置', Grade_layout,key='-tab_course-'), sg.Tab('汇总', Alsum_layout,key='-tab_course-'), sg.Tab('课程表', course_layout, key='-tab_course-'), sg.Tab('学生表', student_layout, key='-tab_student-'), sg.Tab('选课表', SC_layout, key='-tab_sc-')]], key='-group2-', title_color='red', selected_title_color='green', tab_location='left') ]] window = sg.Window('课后作业评分系统', layout, default_element_size=(10, 1),size=(740,580), font=('微软雅黑', 14)) cur_cno=None #当前的选择的课程号 cur_course_row_number=None #当前课程表中被选择的行号,行号从0开始,-1为标题行 subwin_addCourse_active = False subwin_addCourse = None while True: event, values = window.read() # sg.popup_non_blocking(event, values) # print(event) # print(values) if event == sg.WIN_CLOSED: # always, always give a way out! break if event=='-btn_del_course-': # 删除选择的课程号 aff_rows = del_row(cno=cur_cno, tab_name='tbCourse') print('影响的行数:', aff_rows) if(aff_rows>0): data_courses = list(data_courses) data_courses.pop(cur_course_row_number) #从数据表格中移除选择的行数据 window['-TABLE_course-'].update(data_courses) cur_course_row_number = None cur_cno = None elif event=='-btn_add_course-': # 添加课程 # 先弹窗,获取信息 add_affected_rows = open_addCourseWindow() if add_affected_rows>0: data_courses = refreshData(table_key='-TABLE_course-', tab_name='tbcourse') elif event=='-btn_refresh_course-': # 刷新课程表的显示 data_courses = refreshData(table_key='-TABLE_course-', tab_name='tbcourse') elif event=='-btn_add_homework': add_affected_row = open_addHomeworkWindow() if add_affected_row>0: data_courses = refreshData(table_key='-TABLE_course-',tab_name='tbcourse') elif event=='-btn_hundred_system': add_affected_row = open_hundredsystem() if add_affected_row>0: data_courses = refreshData(table_key='-TABLE_course-',tab_name='tbcourse') elif event=='-btn_rank_system': add_affected_row = open_rank_system() if add_affected_row>0: data_courses = refreshData(table_key='-TABLE_course-',tab_name='tbcourse') elif event=='-btn_homework_search': add_affected_row = open_homework_search() if add_affected_row>0: data_courses = refreshData(table_key='-TABLE_course-',tab_name='tbcourse') if isinstance(event, tuple): # TABLE CLICKED Event has value in format ('-TABLE-', '+CLICKED+', (row,col)) if event[0] == '-TABLE_course-': cur_course_row_number = event[2][0] col_number = event[2][1] if cur_course_row_number is not None: # 获取鼠标点击行的数据 cur_row_value = data_courses[cur_course_row_number] # 获取点击行的Cno cur_cno = cur_row_value[0] print('当前选择的课程号:', cur_cno) window.close() 根据上述代码修改优化,使代码能成功运行,实现功能
06-20
db_config.py里有# 1. MySQL数据库连接信息 HOST='localhost' USER='root' PWD='root' DB_PORT=3306 DB_NAME='test' def get_header(tab_name='course'): ''' 根据表名称返回表的标题 :param tab_name: 表的名称 :return: list, 表的标题行 ''' header=None if tab_name=='course': header=['Cno', 'Cname', 'Cpno', 'Ccredit'] elif tab_name=='student': header=['Sno', 'Sname', 'Ssex', 'Sage', 'Sdept'] elif tab_name=='sc': header=['Sno', 'Cno', 'Grade'] elif tab_name=='homework': header=['Sno','Sname','Cno','Hyime','Grade'] elif tab_name=='ducsum': header=['Sno','Sname','Algrade','Avagrade','Rankwork'] return header def trans_data(dict_results): ''' 将[ {'Cno': '01', 'Cname': '高等数学', 'Cpno': None, 'Ccredit': 4}, {'Cno': '02', 'Cname': '大学物理', 'Cpno': '01', 'Ccredit': 3} ] 转换为:[('01', '高等数学', None, 4), ('02', '大学物理', '01', 3) ] :param dict_results: :return: ''' ll=[] for dict in dict_results: ll.append(list(dict.values())) return ll fetch_data_mysql.py里有import pymysql.cursors import db_config def getData(tab_name='tbcourse'): # Connect to the database connection = pymysql.connect(host=db_config.HOST, user=db_config.USER, port=db_config.DB_PORT, password=db_config.PWD, database=db_config.DB_NAME, cursorclass=pymysql.cursors.Cursor) # 使用pymysql.cursors.Cursor时,结果类似于: ( ('01', '高等数学', None, 4), ('02', '大学物理', '01', 3) ) # 使用pymysql.cursors.DictCursor时,结果类似于:[ {'Cno': '01', 'Cname': '高等数学', 'Cpno': None, 'Ccredit': 4}, {'Cno': '02', 'Cname': '大学物理', 'Cpno': '01', 'Ccredit': 3} ] with connection: with connection.cursor() as cursor: # Read a single record sql = f"SELECT * FROM {tab_name};" # cursor.execute(sql, ('webmaster@python.org',)) cursor.execute(sql) results = cursor.fetchall() return results def getData_aim(Sno,tab_name='tbcourse'): # Connect to the database connection = pymysql.connect(host=db_config.HOST, user=db_config.USER, port=db_config.DB_PORT, password=db_config.PWD, database=db_config.DB_NAME, cursorclass=pymysql.cursors.Cursor) # 使用pymysql.cursors.Cursor时,结果类似于: ( ('01', '高等数学', None, 4), ('02', '大学物理', '01', 3) ) # 使用pymysql.cursors.DictCursor时,结果类似于:[ {'Cno': '01', 'Cname': '高等数学', 'Cpno': None, 'Ccredit': 4}, {'Cno': '02', 'Cname': '大学物理', 'Cpno': '01', 'Ccredit': 3} ] with connection: with connection.cursor() as cursor: # Read a single record sql = f"SELECT * FROM {tab_name} where SNO=%s;" cursor.execute(sql, ('Sno',)) # cursor.execute(sql,(department,)) results = cursor.fetchall() return results def del_row(cno, tab_name='tbCourse'): # Connect to the database connection = pymysql.connect(host=db_config.HOST, user=db_config.USER, port=db_config.DB_PORT, password=db_config.PWD, database=db_config.DB_NAME, cursorclass=pymysql.cursors.Cursor) with connection: try: with connection.cursor() as cursor: # 表格名称不能使用占位符,只能拼接字符串 sql = f"DELETE FROM {tab_name} where CNO=%s;" affected_rows=cursor.execute(sql, (cno,)) # connection is not autocommit by default. So you must commit to save your changes. connection.commit() except: return 0 return affected_rows def insert_row(values, tab_name='tbCourse'): # 这里我们只处理输入值数目为4个的情况 if ((not isinstance(values, list)) and (not isinstance(values,tuple))) or len(values)!=4: raise Exception('type error or length incorrect!!!') # Connect to the database connection = pymysql.connect(host=db_config.HOST, user=db_config.USER, port=db_config.DB_PORT, password=db_config.PWD, database=db_config.DB_NAME, cursorclass=pymysql.cursors.Cursor) with connection: try: with connection.cursor() as cursor: # 表格名称不能使用占位符,只能拼接字符串 sql = f"insert into {tab_name} values (%s, %s, %s, %s);" affected_rows = cursor.execute(sql, values) # connection is not autocommit by default. So you must commit to save your changes. connection.commit() except: return 0 return affected_rows def insert_workrow(values, tab_name='homework'): # 这里我们只处理输入值数目为5个的情况 if ((not isinstance(values, list)) and (not isinstance(values,tuple))) or len(values)!=5: raise Exception('type error or length incorrect!!!') # Connect to the database connection = pymysql.connect(host=db_config.HOST, user=db_config.USER, port=db_config.DB_PORT, password=db_config.PWD, database=db_config.DB_NAME, cursorclass=pymysql.cursors.Cursor) with connection: try: with connection.cursor() as cursor: # 表格名称不能使用占位符,只能拼接字符串 sql = f"insert into {tab_name} values (%s, %s, %s, %s, %s);" affected_rows = cursor.execute(sql, values) # connection is not autocommit by default. So you must commit to save your changes. connection.commit() except: return 0 return affected_rows if __name__ == '__main__': results=getData() print(results) for row in results: print(row) main_gui.py文件里有import FreeSimpleGUI as sg #需要切换为MySQL数据库,请将fetch_data_mssql更改为:fetch_data_mysql from fetch_data_mysql import getData, del_row, insert_row,insert_workrow,getData_aim from db_config import get_header def open_homework_search(): sublayout_homesearch = [ [sg.T('请输入要查询的学号:', justification='right'), sg.Input('', size=(50, None), key='-sub_Rname-')], [sg.Button('查询', key='-btn_search-')] ] subwin_homeworksearch = sg.Window('搜索', sublayout_homesearch, font=('微软雅黑', 13), modal=True) while True: ev2, dict_vals2 = subwin_homeworksearch.read() if ev2 in (sg.WIN_CLOSED, 'Exit'): break elif ev2 == '-btn_search-': student_id = dict_vals2['-sub_Rname-'].strip() or None result = getData_aim(student_id,tab_name='tbcourse') sg.popup(f"找到{len(result)}条记录" if result else "未找到记录") break subwin_homeworksearch.close() return result if 'result' in locals() else None def open_rank_system(): layout = [ [sg.T('输入分数:', size=(10,None), justification='right'), sg.Input('', (20, None), key='-INPUT_SCORE-')], [sg.T('等级结果:', size=(10,None), justification='right'), sg.Text('', size=(20,1), key='-OUTPUT_GRADE-')], [sg.Button('转换', key='-btn_rank_system', size=(10,None))] ] window = sg.Window('分数等级转换器', layout, font=('微软雅黑', 13)) while True: event, values = window.read() if event == sg.WIN_CLOSED: break elif event == '-btn_rank_system': try: score = float(values['-INPUT_SCORE-']) if score >= 90: grade = 'A' elif score >= 80: grade = 'B' elif score >= 70: grade = 'C' elif score >= 60: grade = 'D' else: grade = 'E' window['-OUTPUT_GRADE-'].update(grade) except ValueError: sg.popup_error('请输入有效数字!') window.close() def open_hundredsystem(): layout = [ [sg.T('原始数值:', size=(10,None), justification='right'), sg.Input('', (20, None), key='-INPUT_VALUE-')], [sg.T('百分制结果:', size=(10,None), justification='right'), sg.Text('', size=(20,1), key='-OUTPUT_PERCENT-')], [sg.Button('转换', key='-btn_hundred_system', size=(10,None))] ] window = sg.Window('百分制转换器', layout, font=('微软雅黑', 13)) while True: event, values = window.read() if event == sg.WIN_CLOSED: break elif event == '-btn_hundred_system': try: raw_value = float(values['-INPUT_VALUE-']) percent_value = raw_value * 0.1 *0.1 window['-OUTPUT_PERCENT-'].update(f"{percent_value:.2f}%") except ValueError: sg.popup_error('请输入有效数字!') window.close() def open_addHomeworkWindow(): sublayout_homework = [ [sg.T('学号:', size=(None,None), justification='right'), sg.Input('', (50, None), key='-sub_Sno-' )], [sg.T('姓名:', size=(None,None), justification='right'), sg.Input('', (50, None), key='-sub_Sname-' )], [sg.T('课后任务:', size=(None,None), justification='right'), sg.Input('', (50, None), key='-sub_Cno-' )], [sg.T('提交日期:', size=(None,None), justification='right'), sg.Input('', (50, None), key='-sub_Hyime-' )], [sg.T('评分:', size=(None,None), justification='right'), sg.Input('', (50, None), key='-sub_Grade-' )], [sg.Ok('发布', key='-btn_sub_addhomework-',size=(10,None))] ] subwin_addhomework = sg.Window('添加新任务(作业)', sublayout_homework, font=('微软雅黑', 13), modal=True) add_affected_rows = 0 while True: ev2, dict_vals2 = subwin_addhomework.Read() if ev2 == sg.WIN_CLOSED or ev2 == 'Exit': break elif ev2 == '-btn_sub_addhomework-': dict_vals2['-sub_Sno-'] = None if dict_vals2['-sub_Sno-']=='' else dict_vals2['-sub_Sno-'] add_affected_rows = insert_workrow(list(dict_vals2.values()), tab_name='homework') break subwin_addhomework.close() if add_affected_rows>0: sg.popup_timed('发布成功!') if add_affected_rows<=0: sg.popup_timed('发布失败!') return add_affected_rows def open_addCourseWindow(): sublayout_course = [ [sg.T('课程号:', size=(10,None), justification='right'), sg.Input('', (50, None), key='-sub_cno-' )], [sg.T('课程名称:', size=(10,None), justification='right'), sg.Input('', (50, None), key='-sub_cname-' )], [sg.T('先修课:', size=(10,None), justification='right'), sg.Input('', (50, None), key='-sub_cpno-' )], [sg.T('学分:', size=(10,None), justification='right'), sg.Input('', (50, None), key='-sub_ccredit-' )], [sg.Ok('确定', key='-btn_sub_addcourse-',size=(10,None))] ] subwin_addCourse = sg.Window('添加课程信息', sublayout_course, font=('微软雅黑', 13), modal=True) add_affected_rows = 0 while True: ev2, dict_vals2 = subwin_addCourse.Read() if ev2 == sg.WIN_CLOSED or ev2 == 'Exit': break elif ev2 == '-btn_sub_addcourse-': dict_vals2['-sub_cpno-'] = None if dict_vals2['-sub_cpno-']=='' else dict_vals2['-sub_cpno-'] add_affected_rows = insert_row(list(dict_vals2.values()), tab_name='tbCourse') break subwin_addCourse.close() if add_affected_rows>0: sg.popup_timed('插入课程信息成功!') return add_affected_rows def refreshData(table_key='-TABLE_course-', tab_name='tbcourse'): # 刷新表的显示 data_courses = getData(tab_name=tab_name) window[table_key].update(data_courses) return data_courses if __name__ == '__main__': sg.theme('DefaultNoMoreNagging') data_ducsum = getData(tab_name='ducsum') header_ducsum = get_header(tab_name='ducsum') data_homework = getData(tab_name='homework') header_homework = get_header(tab_name='homework') data_courses = getData(tab_name='tbcourse') header_courses = get_header(tab_name='course') data_students = getData(tab_name='tbStuinfo') header_students = get_header(tab_name='student') header_sc = get_header(tab_name='sc') Alsum_layout = [ [sg.Button(button_text='导入'),sg.Button(button_text='导出')], [sg.Table(values=data_ducsum, headings=header_ducsum, size=(550,400), max_col_width=100, auto_size_columns=False, display_row_numbers=False, justification='left', num_rows=15, alternating_row_color='lightyellow', key='-TABLE_course-', selected_row_colors='red on yellow', enable_events=True, expand_x=True, expand_y=True, enable_click_events=True, # Comment out to not enable header and other clicks tooltip='This is a course table') ] ] Grade_layout = [ [sg.Column([ [sg.Text('评分标准模式', justification='center', expand_x=True)], [sg.Push(), sg.Button('百分制',key='-btn_hundred_system'), sg.Push(), sg.Button('分级制',key='-btn_rank_system'), sg.Push()] ], expand_x=True)] ] homework_layout = [ [sg.InputText(),sg.Button(button_text='搜索',key='-btn_homework_search'), sg.Button(button_text='添加',key='-btn_add_homework'), sg.Button(button_text='删除'), sg.Button(button_text='修改') ], [sg.Table(values=data_homework, headings=header_homework, size=(550,400), max_col_width=100, auto_size_columns=False, display_row_numbers=False, justification='left', num_rows=15, alternating_row_color='lightyellow', key='-TABLE_course-', selected_row_colors='red on yellow', enable_events=True, expand_x=True, expand_y=True, enable_click_events=True, # Comment out to not enable header and other clicks tooltip='This is a course table') ], [sg.Button(button_text='上一页', key='-btn_refresh_course-'), sg.Button(button_text='下一页', key='-btn_del_course-') ] ] course_layout = [ [sg.Table(values=data_courses, headings=header_courses, size=(550,400), max_col_width=100, auto_size_columns=False, display_row_numbers=False, justification='left', num_rows=15, alternating_row_color='lightyellow', key='-TABLE_course-', selected_row_colors='red on yellow', enable_events=True, expand_x=True, expand_y=True, enable_click_events=True, # Comment out to not enable header and other clicks tooltip='This is a course table') ], [sg.Button(button_text='刷新', key='-btn_refresh_course-'), sg.Button(button_text='删除', key='-btn_del_course-'), sg.Button(button_text='添加', key='-btn_add_course-') ] ] student_layout = [ [sg.Table(values=data_students, headings=header_students, size=(550, 400), max_col_width=100, auto_size_columns=False, display_row_numbers=False, justification='left', num_rows=15, alternating_row_color='lightyellow', key='-TABLE_Student-', selected_row_colors='red on yellow', enable_events=True, expand_x=True, expand_y=True, enable_click_events=True, # Comment out to not enable header and other clicks tooltip='This is a student table') ], [sg.Button(button_text='刷新', key='-btn_refresh_student-'), sg.Button(button_text='删除', key='-btn_del_student-'), sg.Button(button_text='添加', key='-btn_add_student-') ] ] SC_layout = [[sg.Table(values=[[]], headings=header_sc, # size=(550, 400), max_col_width=100, auto_size_columns=False, display_row_numbers=False, justification='left', num_rows=15, alternating_row_color='lightyellow', key='-TABLE_SC-', selected_row_colors='red on yellow', enable_events=True, expand_x=True, expand_y=True, enable_click_events=True, # Comment out to not enable header and other clicks tooltip='This is a SC table') ], [sg.Button(button_text='刷新', key='-btn_refresh_sc-'), sg.Button(button_text='删除', key='-btn_del_sc-'), sg.Button(button_text='添加', key='-btn_add_sc-') ] ] layout = [[sg.TabGroup([[sg.Tab('首页', homework_layout, key='-tab_homework'), sg.Tab('设置', Grade_layout,key='-tab_course-'), sg.Tab('汇总', Alsum_layout,key='-tab_course-'), sg.Tab('课程表', course_layout, key='-tab_course-'), sg.Tab('学生表', student_layout, key='-tab_student-'), sg.Tab('选课表', SC_layout, key='-tab_sc-')]], key='-group2-', title_color='red', selected_title_color='green', tab_location='left') ]] window = sg.Window('课后作业评分系统', layout, default_element_size=(10, 1),size=(740,580), font=('微软雅黑', 14)) cur_cno=None #当前的选择的课程号 cur_course_row_number=None #当前课程表中被选择的行号,行号从0开始,-1为标题行 subwin_addCourse_active = False subwin_addCourse = None while True: event, values = window.read() # sg.popup_non_blocking(event, values) # print(event) # print(values) if event == sg.WIN_CLOSED: # always, always give a way out! break if event=='-btn_del_course-': # 删除选择的课程号 aff_rows = del_row(cno=cur_cno, tab_name='tbCourse') print('影响的行数:', aff_rows) if(aff_rows>0): data_courses = list(data_courses) data_courses.pop(cur_course_row_number) #从数据表格中移除选择的行数据 window['-TABLE_course-'].update(data_courses) cur_course_row_number = None cur_cno = None elif event=='-btn_add_course-': # 添加课程 # 先弹窗,获取信息 add_affected_rows = open_addCourseWindow() if add_affected_rows>0: data_courses = refreshData(table_key='-TABLE_course-', tab_name='tbcourse') elif event=='-btn_refresh_course-': # 刷新课程表的显示 data_courses = refreshData(table_key='-TABLE_course-', tab_name='tbcourse') elif event=='-btn_add_homework': add_affected_row = open_addHomeworkWindow() if add_affected_row>0: data_courses = refreshData(table_key='-TABLE_course-',tab_name='tbcourse') elif event=='-btn_hundred_system': add_affected_row = open_hundredsystem() if add_affected_row>0: data_courses = refreshData(table_key='-TABLE_course-',tab_name='tbcourse') elif event=='-btn_rank_system': add_affected_row = open_rank_system() if add_affected_row>0: data_courses = refreshData(table_key='-TABLE_course-',tab_name='tbcourse') elif event=='-btn_homework_search': add_affected_row = open_homework_search() if add_affected_row>0: data_courses = refreshData(table_key='-TABLE_course-',tab_name='tbcourse') if isinstance(event, tuple): # TABLE CLICKED Event has value in format ('-TABLE-', '+CLICKED+', (row,col)) if event[0] == '-TABLE_course-': cur_course_row_number = event[2][0] col_number = event[2][1] if cur_course_row_number is not None: # 获取鼠标点击行的数据 cur_row_value = data_courses[cur_course_row_number] # 获取点击行的Cno cur_cno = cur_row_value[0] print('当前选择的课程号:', cur_cno) window.close() 请修正以上代码,使全部代码正常实现功能
06-21
//classDiagram // class Bancai { // Integer id // Caizhi caizhi // Mupi mupi1 // Mupi mupi2 // Double houdu // Kucun kucun // } // // class Caizhi { // String name // List~Bancai~ bancai // } // // class Mupi { // String name // Boolean you // List~Bancai~ bancaisForMupi1 // List~Bancai~ bancaisForMupi2 // } // // class Chanpin { // String bianhao // List~Chanpin_zujian~ chanpin_zujian // List~Dingdan_chanpin~ dingdan_chanpin // } // // class Zujian { // String name // List~Chanpin_zujian~ chanping_zujian // } // // class Chanpin_zujian { // Bancai bancai // Double one_howmany // Double zujianshu // } // // class Dingdan { // String number // Date xiadan // Date jiaohuo // List~Dingdan_chanpin~ dingdan_chanpin // } // // class Dingdan_chanpin { // Integer shuliang // } // // class Kucun { // Integer shuliang // Dingdan reservedOrder // } // // class Jinhuo { // Integer shuliang // Date date // } // // class User { // String name // String andy // String pass // int role // } // // Bancai "1" -- "1" Caizhi // Bancai "1" -- "1" Mupi : mupi1 // Bancai "1" -- "1" Mupi : mupi2 // Bancai "1" -- "1" Kucun // Caizhi "1" -- "*" Bancai // Mupi "1" -- "*" Bancai : mupi1 // Mupi "1" -- "*" Bancai : mupi2 // Chanpin "1" -- "*" Chanpin_zujian // Chanpin "1" -- "*" Dingdan_chanpin // Zujian "1" -- "*" Chanpin_zujian // Chanpin_zujian "1" -- "1" Bancai // Dingdan "1" -- "*" Dingdan_chanpin // Dingdan_chanpin "1" -- "1" Chanpin // Kucun "0..1" -- "1" Dingdan : reservedOrder // Jinhuo "1" -- "1" Dingdan_bancai // Jinhuo "1" -- "1" User function resolveDataReferences(data) { // 获取 data 对象的所有顶层键 const keys = Object.keys(data); // 遍历每个顶层键(如 users, posts 等) for (const key of keys) { const entities = data[key]; // 遍历该顶层键下的每个实体(如每个 user 或 post) for (const entity of entities) { // 遍历实体的每个属性 for (const attribute in entity) { if (entity?.hasOwnProperty(attribute)) { var trpe=attribute?.replace(/\d/g, ''); // 确保属性属于当前实体 if (Array.isArray(entity[attribute])) { if(data[trpe]==null){ trpe+="s" } // 如果属性是一个数组,则将数组中的每个 ID 替换为对应的实际对象 entity[attribute] = entity[attribute].map(item => data[trpe ]?.find(updateItem => updateItem.id === item.id) || item ); } else if (typeof entity[attribute] === "object" && entity[attribute] !== null) { // 如果属性是一个对象,则将其替换为对应的实际对象 entity[attribute] = data[trpe + "s"]?.find(updateItem => updateItem.id === entity[attribute].id); } } } } } console.log(data) return data; } /** * 数据管理器类,负责与后端API通信并管理数据 */ class DataManager { constructor(baseUrl) { this.baseUrl = baseUrl; this.data = { bancais: [], dingdans: [], mupis: [], chanpins: [], kucuns: [], dingdan_bancais:[], chanpin_zujians: [], zujians: [], caizhis: [], dingdan_chanpins: [], users: [], jinhuos: [] }; this.isSyncing = false; this.lastSync = null; this.callbacks = { all: [], bancais: [], dingdan: [], mupi: [], chanpin: [], kucun: [], chanpin_zujian: [], dingdan_bancai:[], zujian: [], caizhi: [], dingdan_chanpin: [], user: [], jinhuo: [] }; this.syncQueue = Promise.resolve(); } /** * 获取所有数据 * @returns {Promise<boolean>} 是否成功 */ async fetchAll() { console.log(this) try { const response = await fetch(`${this.baseUrl}/app/all`); if (!response.ok) throw new Error('Network response was not ok'); const result = await response.json(); if (result.status !== 200) throw new Error(result.text || 'API error'); const resolvedData = resolveDataReferences(result.data); // 更新本地数据 Object.keys(this.data).forEach(key => { if (resolvedData[key]) { this.data[key] = resolvedData[key]; } }); this.lastSync = new Date(); // 关键改进:数据更新后触发刷新回调 this.triggerCallbacks('refresh', 'all', this.data); return true; } catch (error) { console.error('Fetch error:', error); // 触发错误回调 this.triggerCallbacks('fetch_error', 'all', { error }); return false; } } /** * 注册回调函数 * @param {string} entity - 实体类型(如'bancai')或'all'表示全局回调 * @param {Function} callback - 回调函数,参数为(operation, data) */ registerCallback(entity, callback) { if (!this.callbacks[entity]) { this.callbacks[entity] = []; } this.callbacks[entity].push(callback); } /** * 移除回调函数 * @param {string} entity - 实体类型单数性质 * @param {Function} callback - 要移除的回调函数 */ unregisterCallback(entity, callback) { if (!this.callbacks[entity]) return; const index = this.callbacks[entity].indexOf(callback); if (index !== -1) { this.callbacks[entity].splice(index, 1); } } /** * 触发回调 * @param {string} operation - 操作类型('add', 'update', 'delete') * @param {string} entity - 实体类型单数性质 * @param {Object} data - 相关数据 */ triggerCallbacks(operation, entity, data) { // 触发全局回调 this.callbacks.all.forEach(cb => cb(operation, entity, data)); // 触发特定实体回调 if (this.callbacks[entity]) { this.callbacks[entity].forEach(cb => cb(operation, data)); } } /** * 执行CRUD操作并触发回调 */ async crudOperation(operation, entity, data) { try { const response = await fetch(`${this.baseUrl}/app/${operation}/${entity}`, { method: 'POST', headers: {'Content-Type': 'application/json'}, body: JSON.stringify(data) }); if (!response.ok) throw new Error('Network response was not ok'); const result = await response.json(); if (result.status !== 200) throw new Error(result.text || 'API error'); // 自动同步数据 this.syncData(); // 触发操作成功的回调 this.triggerCallbacks(operation, entity, data); return result; } catch (error) { console.error('CRUD error:', error); // 触发操作失败的回调 this.triggerCallbacks(`${operation}_error`, entity, { data, error: error.message }); throw error; } } /** * 执行CRUD操作 * @param {string} operation - 'add', 'delete', 'update' * @param {string} entity - 实体名称单数性质(小写) * @param {Object} data - 要发送的数据 后端要求数据格式为{属性: "值", 关联对象: {id:0}, 关联对象集: [{id:0}]} * @returns {Promise<Object>} 响应结果 */ async crudOperation(operation, entity, data) { try { const response = await fetch(`${this.baseUrl}/app/${operation}/${entity}`, { method: 'POST', headers: {'Content-Type': 'application/json'}, body: JSON.stringify(data) }); if (!response.ok) throw new Error('Network response was not ok'); const result = await response.json(); if (result.status !== 200) throw new Error(result.text || 'API error'); // 自动同步数据 this.syncQueue = this.syncQueue.then(async () => { await this.syncData(); // 同步完成后触发操作回调 this.triggerCallbacks(operation, entity, data); }); return result; } catch (error) { console.error('CRUD error:', error); // 触发操作失败的回调 this.triggerCallbacks(`${operation}_error`, entity, { data, error: error.message }); throw error; } } /** * 自动同步数据(防止频繁请求) */ async syncData() { if (this.isSyncing) { this.pendingSync = true; return; } this.isSyncing = true; try { await this.fetchAll(); } catch (error) { console.error('Sync failed:', error); } finally { this.isSyncing = false; // 处理等待中的同步请求 if (this.pendingSync) { this.pendingSync = false; setTimeout(() => this.syncData(), 1000); } } } /** * 添加实体 * @param {string} entity - 实体名称单数性质 * @param {Object} data - 实体数据 */ async addEntity(entity, data) { return this.crudOperation('add', entity, data); } /** * 更新实体 * @param {string} entity - 实体名称单数性质 * @param {Object} data - 实体数据(必须包含id) */ async updateEntity(entity, data) { return this.crudOperation('update', entity, data); } /** * 删除实体 * @param {string} entity - 实体名称单数性质 * @param {number} id - 实体ID */ async deleteEntity(entity, id) { return this.crudOperation('delete', entity, {id}); } /** * 新增方法:手动触发数据刷新 */ async refreshData() { return this.syncQueue = this.syncQueue.then(() => this.syncData()); } } export { DataManager }; // 创建单例实例 //const dataManager = new DataManager('http://127.0.0.1:8080/KuCun2'); //// 初始化时获取所有数据 //dataManager.fetchAll().then(() => { // console.log('Initial data loaded'); //}); // 导出数据对象,外部可以直接访问 data.bancais, data.dingdans 等 //export const data = dataManager.data; //// 导出操作方法 //export const addEntity = dataManager.addEntity.bind(dataManager); //export const updateEntity = dataManager.updateEntity.bind(dataManager); //export const deleteEntity = dataManager.deleteEntity.bind(dataManager); //export const fetchAll = dataManager.fetchAll.bind(dataManager);<!DOCTYPE html> <html lang="zh-CN"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>板材库存查询系统</title> <!-- 引入外部CSS --> <link rel="stylesheet" href="../css/dingdan.css"> <!-- 引入jQuery --> <script src="https://code.jquery.com/jquery-3.6.0.min.js"></script> <!-- 引入Bootstrap --> <link href="../js/bootstrap-5.3.0-alpha1-dist/css/bootstrap.min.css" rel="stylesheet"> <script src="../js/bootstrap-5.3.0-alpha1-dist/umd/popper.min.js"></script> <script src="../js/bootstrap-5.3.0-alpha1-dist/js/bootstrap.min.js"></script> <!-- 引入Bootstrap Icons --> <link rel="stylesheet" href="../js/bootstrap-icons-1.8.1/bootstrap-icons.css"> <!-- 引入主JS文件 --> <script src="../js/main.js"></script> </head> <body> <div class="container py-4"> <!-- 标题部分 --> <div class="text-center mb-4"> <h1 class="text-primary"><i class="bi bi-boxes"></i> 板材库存管理系统</h1> <p class="text-muted">查询订单、产品、板材及库存信息</p> </div> <!-- 统计卡片 --> <div class="row mb-4"> <div class="col-md-3"> <div class="card stats-card border-primary"> <div class="card-body"> <h5 class="card-title">订单总数</h5> <p class="card-text fs-3 text-primary" id="orderCount">0</p> </div> </div> </div> <div class="col-md-3"> <div class="card stats-card border-info"> <div class="card-body"> <h5 class="card-title">产品种类</h5> <p class="card-text fs-3 text-info" id="productCount">0</p> </div> </div> </div> <div class="col-md-3"> <div class="card stats-card border-success"> <div class="card-body"> <h5 class="card-title">板材库存</h5> <p class="card-text fs-3 text-success" id="materialCount">0</p> </div> </div> </div> <div class="col-md-3"> <div class="card stats-card border-warning"> <div class="card-body"> <h5 class="card-title">库存总量</h5> <p class="card-text fs-3 text-warning" id="totalStock">0</p> </div> </div> </div> </div> <!-- 搜索区域 --> <div class="card search-section mb-4"> <div class="card-header"> <h5 class="mb-0"><i class="bi bi-search me-2"></i>高级搜索</h5> </div> <div class="card-body"> <div class="row g-3"> <!-- 订单搜索 --> <div class="col-md-4"> <div class="search-control"> <i class="bi bi-clipboard-search search-icon"></i> <input type="text" class="form-control with-icon" id="orderSearch" placeholder="搜索订单号..." aria-label="订单号搜索"> </div> </div> <!-- 产品搜索 --> <div class="col-md-4"> <div class="search-control"> <i class="bi bi-grid search-icon"></i> <input type="text" class="form-control with-icon" id="productSearch" placeholder="搜索产品编号..." aria-label="产品编号搜索"> </div> </div> <!-- 板材搜索 --> <div class="col-md-4"> <div class="search-control"> <i class="bi bi-box search-icon"></i> <input type="text" class="form-control with-icon" id="materialSearch" placeholder="搜索板材ID或材质..." aria-label="板材搜索"> </div> </div> <!-- 木皮搜索 --> <div class="col-md-4"> <div class="search-control"> <i class="bi bi-tree search-icon"></i> <input type="text" class="form-control with-icon" id="woodSearch" placeholder="搜索木皮名称..." aria-label="木皮搜索"> </div> </div> <!-- 厚度搜索 --> <div class="col-md-4"> <div class="search-control"> <i class="bi bi-arrows-vertical search-icon"></i> <input type="number" class="form-control with-icon" id="thicknessSearch" placeholder="厚度(mm)" min="0" step="0.1"> </div> </div> <!-- 库存范围搜索 --> <div class="col-md-4"> <div class="input-group"> <span class="input-group-text"><i class="bi bi-box"></i></span> <input type="number" class="form-control" id="minStock" placeholder="最小库存" min="0"> <input type="number" class="form-control" id="maxStock" placeholder="最大库存" min="0"> <button class="btn btn-primary" type="button" id="stockStatusBtn"> <i class="bi bi-search"></i> </button> </div> </div> </div> </div> </div> <!-- 结果区域 --> <div class="card"> <div class="card-header d-flex justify-content-between align-items-center"> <h5 class="mb-0"><i class="bi bi-table me-2"></i>查询结果</h5> <div class="text-secondary"> <span id="resultCount">0</span> 条记录 <span class="ms-2"><i class="bi bi-info-circle"></i> <small>实时数据更新时间: <span id="lastUpdate">--:--:--</span></small></span> </div> </div> <div class="card-body result-section"> <div class="table-responsive"> <table class="table table-hover" id="resultsTable"> <thead class="table-light sticky-top"> <tr> <th data-sortable>订单号 <span class="sort-indicator"></span></th> <th data-sortable>产品信息 <span class="sort-indicator"></span></th> <th data-sortable>产品数量 <span class="sort-indicator"></span></th> <th data-sortable>组件 <span class="sort-indicator"></span></th> <th data-sortable>板材 <span class="sort-indicator"></span></th> <th data-sortable>单件用量 <span class="sort-indicator"></span></th> <th data-sortable>订单用量 <span class="sort-indicator"></span></th> <th data-sortable>库存数量 <span class="sort-indicator"></span></th> <th>操作</th> </tr> </thead> <tbody id="resultBody"> <!-- 数据加载中 --> <tr id="loadingRow"> <td colspan="9" class="text-center py-5"> <div class="d-flex align-items-center justify-content-center"> <div class="spinner-border text-primary" role="status"> <span class="visually-hidden">加载中...</span> </div> <div class="ms-3">正在加载数据,请稍候...</div> </div> </td> </tr> </tbody> </table> </div> <!-- 空结果提示 --> <div id="noResults" class="no-results text-center py-5" style="display: none;"> <div> <i class="bi bi-inboxes text-muted" style="font-size: 3rem;"></i> <h4 class="mt-3 text-muted">没有找到匹配的记录</h4> <p class="text-muted">请尝试调整您的搜索条件</p> </div> </div> </div> </div> </div> <!-- 引入订单JS --> <script src="../js/test.js"></script> </body> </html> 实现页面功能,DataManager.js已经在父级页面加载过了,直接到父级调用, 业务基本逻辑 一个订单有很多产品不同数量,每个产品可以再很多订单中,一个产品有很多组件,一个组件可以在很多产品中,因为每个组件因为在不同的产品中有不同的生产工艺,所以使用不同的板材和板材能生产组件数量,每个板材有不同的材质和两面木皮,木皮表面可能有油漆, 订购时可能直接购入板材,也可能按订单和产品订购板材,也用可能按订单产品组件订购板材,每次采购不标准,一个订单可能订购几次,用户有姓名 账号 密码 权限, 一个记录进货和消耗,查看的时候会查看订单下有多少板材可用
06-24
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值