This commit is contained in:
ada-dmitry
2024-05-14 22:45:45 +03:00
parent 9e62179855
commit 7adca1884d
16 changed files with 293 additions and 76 deletions
+138 -43
View File
@@ -1,5 +1,7 @@
import sys
import texts
import math
import os
# import time
sys.path.append('tables')
@@ -17,10 +19,16 @@ TODO:
4) UPDATE для категорий - done
5) Красивый вывод - done
6) Доделать ограничение на выбор категории - done
7) UPDATE для блюд - done
8) Постраничный вывод - indev
7) UPDATE для блюд - done 0.7
8) Постраничный вывод - indev 0.8 - реализация через offset.
9) Реализовать отдельный просмотр(offset)
10) И отдельный вывод(offset)
FIXME:
1) Откомментировать os.cls
2) Исправить вылет при неверном вводе в самое начало(сделать выход на предыдущую менюшку)
3) При вводе текста пропуск сделать с помощью пустой строки.
'''
@@ -33,33 +41,29 @@ class Main:
def __init__(self):
DbTable.dbconn = self.connection
return
def db_init(self):
cth = CathTable()
d = DishTable()
cth.create()
d.create()
return
def db_insert_somethings(self):
cth = CathTable()
dsh = DishTable()
cth.example_insert()
dsh.example_insert()
dsh.example_insert()
def db_drop(self):
cth = CathTable()
d = DishTable()
d.drop()
cth.drop()
return
def show_main_menu(self):
menu = texts.show_main_menu_txt
print(menu)
print('Катя и Дима хорошенькие, тюк')
return
def read_next_step(self):
return input("=> ").strip()
@@ -75,20 +79,44 @@ class Main:
return "0"
else:
return next_step
def show_cath(self):
self.cath_id = -1
self.cath_arr = []
menu = texts.show_cath_1txt
print(menu)
lst = CathTable().all()
self.max_cath_index = (len(lst))
for i in lst:
self.cath_arr.append(str(i[0]))
self.max_cath_index = len(CathTable().all())
self.cath_page = 1
lst = CathTable().get_page(self.cath_page)
action = '>'
max_page = math.ceil(self.max_cath_index/10)
while True:
for i in range(len(self.cath_arr)):
print(str(i+1) + "\t" + self.cath_arr[i])
self.cath_arr = []
for i in lst:
self.cath_arr.append(str(i[0]))
os.system('cls')
for i in range(len(self.cath_arr)):
print(add_func.add_zero_before(str((i+1)+(10*(self.cath_page-1))), len(str(self.max_cath_index))) + "\t" + self.cath_arr[i])
action = input('-------------------------------------------------------------------------------------------\n\
Для переключения между страницами используйте "<" и ">"\nКол-во записей на странице: 10\n\
Для выхода в меню действий нажмите любую другую клавишу\n=> ')
if(action=='>'):
if(self.cath_page==max_page):
self.cath_page = 1
else:
self.cath_page += 1
lst = CathTable().get_page(self.cath_page)
elif(action=='<'):
if(self.cath_page==1):
self.cath_page = max_page
else:
self.cath_page -= 1
lst = CathTable().get_page(self.cath_page)
else:
break
menu = texts.show_cath_2txt
print(menu)
return
@@ -98,9 +126,17 @@ class Main:
"""
while True:
if next_step == "4": # Удаление категории
x = add_func.validate_input('Введите номер удаляемой категории (0 - для отмены): ', 0, self.max_cath_index)
if(self.cath_page<(self.max_cath_index//10)):
left = ((self.cath_page-1)*10)+1
right = left+9
print(left)
else:
left = 1+((self.cath_page-1)*10)
right = self.max_cath_index
x = add_func.validate_input('Введите номер удаляемой категории (0 - для отмены): ', left, right)
if(x!=-1):
CathTable().delete(self.cath_arr[int(x)-1])
CathTable().delete(self.cath_arr[(int(x)-1)-((self.cath_page-1)*10)])
return "1"
elif next_step == "6": #Добавление блюда в категорию
@@ -108,9 +144,16 @@ class Main:
next_step = "5"
elif next_step == "7":#Удаление блюда из категории
x = add_func.validate_input('Введите номер удаляемого блюда (0 - для отмены): ', 0, self.max_index)
if(self.dish_page<(self.max_index//10)):
left = ((self.dish_page-1)*10)+(self.dish_page==1)
right = left+9
else:
left = 1+((self.dish_page-1)*10)+(self.dish_page!=1)
right = self.max_index
x = add_func.validate_input('Введите номер удаляемого блюда (0 - для отмены): ', left, right)
if(x!=-1):
DishTable().delete(self.dish_arr[int(x)-1][0])
DishTable().delete(self.dish_arr[(int(x)-1)-((self.dish_page-1)*10)][0])
else:
return "1"
next_step = "5"
@@ -119,14 +162,28 @@ class Main:
next_step = self.show_dish_in_cath()
elif next_step == "8": # Обновление названия категории
x = add_func.validate_input('Введите номер обновляемой категории (0 - для отмены): ', 0, self.max_cath_index)
if(self.cath_page<(self.max_cath_index//10)):
left = 1+((self.cath_page-1)*10)
right = left+9
else:
left = 1+((self.cath_page-1)*10)
right = self.max_cath_index
x = add_func.validate_input('Введите номер обновляемой категории (0 - для отмены): ', left, right)
if(x!=-1):
CathTable().cath_update(self.cath_arr[int(x)-1])
CathTable().cath_update(self.cath_arr[(int(x)-1)-((self.cath_page-1)*10)])
return "1"
elif next_step == "88":
x = add_func.validate_input('Введите номер изменяемого блюда (0 - для отмены): ', 0, self.max_index)
if(self.dish_page<(self.max_index//10)):
left = 1+((self.dish_page-1)*10)
right = left+9
else:
left = 0+((self.dish_page-1)*10)
right = self.max_index
x = add_func.validate_input('Введите номер обновляемого блюда (0 - для отмены): ', left, right)
if(x!=-1):
DishTable().update_dish(self.dish_arr[int(x)-1][0])
DishTable().update_dish(self.dish_arr[(int(x)-1)-((self.cath_page-1)*10)][0])
else:
return "1"
@@ -160,38 +217,75 @@ class Main:
def show_dish_in_cath(self):
"""Вывод всех блюд в выбранной пользователем категории
"""
self.dish_arr = []
if self.cath_id == -1:
while True:
x = add_func.validate_input('Выберите номер интересуемой категории (0 - отмена): ', 0, self.max_cath_index)
if(self.cath_page<(self.max_cath_index//10)):
left = 1+((self.cath_page-1)*10)
right = left+9
else:
left = 1+((self.cath_page-1)*10)+(self.cath_page!=1)
right = self.max_cath_index
x = add_func.validate_input('Выберите номер интересуемой категории (0 - отмена): ', left, right)
os.system('cls')
if(x!=-1):
self.cath_id = CathTable().find_by_name(self.cath_arr[x-1])
self.cath_obj = self.cath_arr[x-1]
self.cath_id = CathTable().find_by_name(self.cath_arr[(int(x)-1)-((self.cath_page-1)*10)])
self.cath_obj = self.cath_arr[(int(x)-1)-((self.cath_page-1)*10)]
else:
return "1"
print("Выбрана категория: " + self.cath_obj)
print("Блюда:")
lst = DishTable().all_by_cath_id(self.cath_id)
self.dish_page = 1
lst = DishTable().get_page_dish(self.cath_id, self.dish_page)
self.max_len_name = 0
self.max_index = len(lst)
for i in lst:
self.dish_arr.append([i[2], str(i[1]), str(i[4])])
self.max_len_name = max(self.max_len_name, len(i[2]))
print("" + " "*(self.max_index + 1)+ "Название" + " "*(self.max_len_name - 4)\
+"Время приготовления Краткая инструкция\
\n-------------------------------------------------------------------------------------------")
for i in range(len(self.dish_arr)):
txt = str(i+1) + " "*(2+self.max_index-len(str(i)))
txt += self.dish_arr[i][0] + " "*(4+self.max_len_name - len(self.dish_arr[i][0]))
txt += self.dish_arr[i][1] + " "*(5+19-len(self.dish_arr[i][1]))
txt += self.dish_arr[i][2]
print(txt)
self.max_index = len(DishTable().all_by_cath_id(self.cath_id))
action = '>'
max_page = math.ceil(self.max_index/10)
lst = DishTable().get_page_dish(self.cath_id, self.dish_page)
while True:
self.dish_arr = []
for i in lst:
self.dish_arr.append([i[2], str(i[1]), str(i[4])])
self.max_len_name = max(self.max_len_name, len(i[2]))
os.system('cls')
print("" + " "*(len(str(self.max_index)) + 1)+ "Название" + " "*(self.max_len_name - 4)\
+"Время приготовления Краткая инструкция\
\n-------------------------------------------------------------------------------------------")
for i in range(len(self.dish_arr)):
txt = add_func.add_zero_before(str((i+1)+(10*(self.dish_page-1))), len(str(self.max_index))) + " "*(2+len(str(self.max_index)))
txt += self.dish_arr[i][0] + " "*(4+self.max_len_name - len(self.dish_arr[i][0]))
txt += self.dish_arr[i][1] + " "*(5+19-len(self.dish_arr[i][1]))
txt += self.dish_arr[i][2]
print(txt)
action = input('-------------------------------------------------------------------------------------------\n\
Для переключения между страницами используйте "<" и ">"\nКол-во записей на странице: 10\n\
Для выхода в меню действий нажмите любую другую клавишу\n=> ')
if(action=='>'):
if(self.dish_page==max_page):
self.dish_page = 1
else:
self.dish_page += 1
lst = DishTable().get_page_dish(self.cath_id, self.dish_page)
elif(action=='<'):
if(self.dish_page==1):
self.dish_page = max_page
else:
self.dish_page -= 1
lst = DishTable().get_page_dish(self.cath_id, self.dish_page)
else:
break
menu = texts.show_dish_in_cath_txt
print(menu)
return self.read_next_step()
def main_cycle(self):
"""Основной цикл программы, регулирующий порядок действий
"""
@@ -224,5 +318,6 @@ class Main:
DbTable.dbconn.test()
m = Main()
# m.test()
m.main_cycle()