def add_enr(self,surn, name, patr, addr, birth, passp, listbox): Enrollee.create(surn.get(), name.get(), patr.get(), addr.get(), birth.get(), passp.get()) surn.delete(0,END) name.delete(0, END) patr.delete(0, END) addr.delete(0, END) birth.delete(0, END) passp.delete(0, END) self.update_all(listbox)
def add_enrollee(): try: surname = input("Enter surname: ") name = input("Enter name: ") patronymic = input("Enter patronymic: ") address = input("Enter address: ") birthday = datetime.strptime( input("Enter date of birthday(DD.MM.YYYY): "), '%d.%m.%Y').date().strftime('%d.%m.%Y') passport = input("Enter number of passport: ") Enrollee.create(surname, name, patronymic, address, birthday, passport) except: print("Error")
def updateAllList(self): self.allEnrList.setEditTriggers(QAbstractItemView.NoEditTriggers) model = QStandardItemModel(self.allEnrList) for i in Enrollee.all(): item = QStandardItem(i.to_string()) model.appendRow(item) self.allEnrList.setModel(model)
def add_exam(): try: pass_time = datetime.strptime( input("Enter time of pass(DD.MM.YYYY HH:MM): "), '%d.%m.%Y %H:%M').strftime('%d.%m.%Y %H:%M') exam_name = input("Enter name of exam: ") score = input("Enter score of exam: ") enrollee_id = 0 examiner_id = 0 score = None if score != "": score = int(score) while True: #select enrollee by surname enrollee_surn = input("Enter surname of enrollee: ") if enrollee_surn == "-1": return enrollees = Enrollee.findBySurname(enrollee_surn) if len(enrollees) == 0: print( "No results. Enter '-1' to stop adding exam ornew surname to try again: " ) else: print_arr(enrollees) user_input = int( input( "Enter number of selected enrollee, or '-1' to stop adding exam: " )) if user_input >= 0 or user_input < len(enrollees): enrollee_id = enrollees[user_input - 1].id break elif user_input == -1: return else: print("Incorrect input") while True: #select examiner by surname examiner_surn = input("Enter surname of examiner: ") if examiner_surn == "-1": return examiners = Examiner.findBySurname(examiner_surn) if len(examiners) == 0: print( "No results. Enter '-1' to stop adding exam or new surname to try again: " ) else: print_arr(examiners) user_input = int( input( "Enter number of selected examiner, or '-1' to stop adding exam: " )) if user_input >= 0 or user_input < len(examiners): examiner_id = examiners[user_input - 1].id break elif user_input == -1: return else: print("Incorrect input") Exam.create(pass_time, exam_name, score, enrollee_id, examiner_id) except: print("Error")
def __init__(self, id): super().__init__() uic.loadUi("layouts\\manipulateEnrollee.ui", self) self.enrollee = Enrollee.get_by_id(id) self.newAddr.setText(self.enrollee.address) self.changeAddr.clicked.connect(self.changeAddressClick) self.deleteEnr.clicked.connect(self.deleteEnrolleeClick) self.exportBtn.clicked.connect(self.exportEnrolleeClick) self.updateAllList()
def exportXlsxClick(self): wb = openpyxl.load_workbook('..\\..\\Reports\\All.xlsx') if 'Enrollees' not in wb.sheetnames: wb.create_sheet('Enrollees') ws = wb['Enrollees'] ws.delete_cols(1, 6) ws.delete_rows(1, 100) all_list = Enrollee.all() for i in range (len(all_list)): ws.cell(row=i + 1, column=1).value = all_list[i].id ws.cell(row=i + 1, column=2).value = all_list[i].surname ws.cell(row=i + 1, column=3).value = all_list[i].name ws.cell(row=i + 1, column=4).value = all_list[i].patronymic ws.cell(row=i + 1, column=5).value = all_list[i].address ws.cell(row=i + 1, column=6).value = all_list[i].birthday ws.cell(row=i + 1, column=7).value = all_list[i].passport wb.save('..\\..\\Reports\\All.xlsx')
def all_enrollees(): try: enrollees = Enrollee.all() print_arr(enrollees) if len(enrollees) == 0: print("No results") else: res = int( input( "Enter number of selected enrollee or '-1' to go back: ")) if res > 0 and res <= len(enrollees): manipulate_enrollee(enrollees[res - 1]) return if res == -1: return else: print("Incorrect input") except: print("Error")
def find_enrollee(): try: sur = input("Enter surname to search: ") enrollees = Enrollee.findBySurname(sur) print_arr(enrollees) if len(enrollees) == 0: print("No results") else: res = int( input( "Enter number of selected enrollee or '-1' to go back: ")) if res > 0 and res <= len(enrollees): manipulate_enrollee(enrollees[res - 1]) return elif res == -1: return else: print("Incorrect input") except: print("Error")
def find_enrollee(self, listbox, find_label): listbox.delete(0, END) self.find_enrollee_list = Enrollee.findBySurname(find_label.get()) for elem in self.find_enrollee_list: listbox.insert(END, elem.to_string()) return
def findEnrolleeOnClick(self): model = QStandardItemModel(self.findEnrList) for i in Enrollee.findBySurname(self.findSurnameInput.text()): item = QStandardItem(i.to_string()) model.appendRow(item) self.findEnrList.setModel(model)
def exportDocxClick(self): for i in Enrollee.all(): enr_export(i)
def addEnrolleeOnClick(self): Enrollee.create(self.surnameEdit.text(), self.nameEdit.text(), self.patronymicEdit.text(), self.addressEdit.text(), self.birthdayEdit.date().toString("dd.MM.yyyy"), self.passportEdit.text()) self.updateAllList()
def update_all(self, listbox): listbox.delete(0, END) self.all_list = Enrollee.all() for elem in self.all_list: listbox.insert(END, elem.to_string()) return
def __init__(self, *args, **kwargs): Page.__init__(self, *args, **kwargs) all = Frame(self) all.pack(side=LEFT, fill=Y) Label(all, text="All enrollees").pack() self.all_listbox = Listbox(all, width=100) self.all_listbox.bind('<Double-1>', self.all_list_on_click) self.all_list = Enrollee.all() for person in self.all_list: self.all_listbox.insert(END, person.to_string()) self.all_listbox.pack(side="top", fill="both", expand=True) all_docx_report = Button(all, text = "Export info about all enrollees in docx files", command=self.all_docx_export) all_docx_report.pack(side="top") xlsx_report = Button(all, text = "Export info about all enrollees in Excel", command=self.xlsx_export) xlsx_report.pack(side="top") ################################################################################################# find = Frame(self) find.pack(side=LEFT, fill=Y) Label(find, text="Find enrollee").pack() find_entry = Entry(find) find_entry.pack() self.find_listbox = Listbox(find, width=100) self.find_listbox.bind('<Double-1>', self.find_list_on_click) find_enr = partial(self.find_enr, self.find_listbox, find_entry) find_btn = Button(find, text="Find", command = find_enr).pack() self.find_listbox.pack(side="top", fill="both", expand=True) ######################################################################################################## add = Frame(self) add.pack() Label(add, text="Add enrollee", font="Helvetica -14 bold").grid(columnspan=2) Label(add, text="Surname: ").grid(row=1, column=0) surn = Entry(add, width=50) surn.grid(row=1, column=1) Label(add, text="Name: ").grid(row=2, column=0) name = Entry(add, width=50) name.grid(row=2, column=1) Label(add, text="Patronymic: ").grid(row=3, column=0) patr = Entry(add, width=50) patr.grid(row=3, column=1) Label(add, text="Address: ").grid(row=4, column=0) addr = Entry(add, width=50) addr.grid(row=4, column=1) Label(add, text="Date of birthday: ").grid(row=5, column=0) birth = DateEntry(add, width=12, background='darkblue', foreground='white', borderwidth=2, date_pattern='dd.mm.y') birth.grid(row=5, column=1) Label(add, text="Number of passport: ").grid(row=6, column=0) passp = Entry(add, width=50) passp.grid(row=6, column=1) add_enr = partial(self.add_enr, surn, name, patr, addr, birth, passp, self.all_listbox) add_btn = Button(add, text="Add enrollee", command =add_enr) add_btn.grid(columnspan=2)