示例#1
0
def add_duty(main_user):
    def go_back():
        root.destroy()
        windows_init.show_my_duties(main_user)

    def ok():
        date = e_date.get_date()
        select = list(t_lbox.curselection())
        if len(select) < 1 or not curr_students:
            mb.showerror("Ошибка", "Выберите диспетчера!")
            return
        if str(datetime.datetime.now()).split()[0] > str(date):
            mb.showerror("Ошибка", "Невозможно запланировать дежурство в прошлом!")
            return
        selected_s = curr_students[select[0]]
        duty = Duty(("", "", "", ""))
        duty.date = date
        duty.s_id = selected_s.id
        db.insert_duty(duty)
        go_back()

    root = tk.Tk()
    root.resizable(False, False)
    root.title("Добавление дежурства")
    screen_width = root.winfo_screenwidth() // 2 - 210
    screen_height = root.winfo_screenheight() // 2 - 125
    root.geometry('420x250+{}+{}'.format(screen_width, screen_height))

    db = DataBase()

    b_back = tk.Button(text="Назад", command=go_back)
    t_lbox = tk.Listbox(exportselection=0, width=40, height=10)

    global curr_students
    curr_students = db.get_dispatchers()
    if not curr_students:
        t_lbox.insert(tk.END, "Нет диспетчеров")
        curr_students = []
    else:
        for s in curr_students:
            t_lbox.insert(tk.END, s.name)

    b_ok = tk.Button(text="OK", command=ok)
    e_date = DateEntry(root, width=12, background='darkblue',
                       foreground='white', borderwidth=2, year=2019)

    e_date.pack(padx=10, pady=10)
    t_lbox.pack(side="top")
    b_ok.pack()
    b_back.place(x=0, y=230, width=40, height=20)

    root.mainloop()
def show_login(main_user):
    def try_login():
        login = enter_login.get()
        password = enter_password.get()
        user = db.get_user_by_login(login)
        if (login == ""):
            except_label['text'] = "Введите логин"
            return
        if (login != "" and password == ""):
            except_label['text'] = "Введите пароль"
            return
        if (not user):
            except_label['text'] = 'Несуществующий логин'
        elif user.password != password:
            except_label['text'] = 'Неверный пароль'
        else:
            except_label['text'] = 'Успешно'
            main_user = user
            if user.type == 'преподаватель':
                root.destroy()
                windows_init.show_teacher(main_user)
            elif user.type == "студент" and user.competence == "консультант":
                root.destroy()
                windows_init.show_consultant_window(main_user)
            elif user.type == "студент" and user.competence == "диспетчер":
                root.destroy()
                windows_init.show_dispatcher_window(main_user)
            elif user.type == "админ":
                root.destroy()
                windows_init.show_admin_window(main_user)
            elif user.type == "тьютор":
                root.destroy()
                windows_init.show_tutor_window(main_user)
            else:
                except_label['text'] = "Неизвестная роль!"

    root = tk.Tk()
    root.resizable(False, False)
    screen_width = root.winfo_screenwidth() // 2 - 200  # 2 - 150
    screen_height = root.winfo_screenheight() // 2 - 65  # 2 - 50
    root.geometry('400x130+{}+{}'.format(screen_width, screen_height))
    root.title("Авторизация")

    db = DataBase()

    enter_login = tk.Entry()
    enter_login.insert(0, main_user.login)
    enter_password = tk.Entry()
    b_enter = tk.Button(text="Войти", command=try_login)
    except_label = tk.Label(width=40)

    except_label['text'] = "Введите логин и пароль"

    enter_login.place(x=125, y=30, width=150, height=25)
    enter_password.place(x=125, y=60, width=150, height=25)
    b_enter.place(x=165, y=90, width=70, height=30)
    except_label.pack(side="top")

    root.mainloop()
def show_tutor(main_user):
    def leave_akk():
        root.destroy()
        windows_init.show_login(main_user)

    def show_students():
        root.destroy()
        windows_init.show_my_students(main_user)

    def show_my_cases():
        root.destroy()
        windows_init.show_my_cases(main_user)

    def show_my_profile():
        root.destroy()
        windows_init.show_my_profile(main_user)

    def show_duty():
        root.destroy()
        windows_init.show_my_duties(main_user)

    root = tk.Tk()
    root.resizable(False, False)
    root.title("Добро пожаловать, тьютор " + main_user.name)

    screen_width = root.winfo_screenwidth() // 2 - 210
    screen_height = root.winfo_screenheight() // 2 - 100
    root.geometry('420x200+{}+{}'.format(screen_width, screen_height))

    db = DataBase()

    b_show_my_students = tk.Button(text="Мои студенты", command=show_students)
    b_im = tk.Button(text="Мой профиль", command=show_my_profile)
    b_show_my_cases = tk.Button(text="Мои дела", command=show_my_cases)
    b_login = tk.Button(text="Выйти из аккаунта", command=leave_akk)
    b_duty = tk.Button(text="Дежурства", command=show_duty)

    b_im.place(x=0, y=0, width=420, height=40)
    b_show_my_cases.place(x=0, y=40, width=420, height=40)
    b_show_my_students.place(x=0, y=80, width=420, height=40)
    b_duty.place(x=0, y=120, width=420, height=40)
    b_login.place(x=0, y=160, width=420, height=40)

    root.mainloop()
示例#4
0
def show_dispatcher(main_user):
    def leave_akk():
        root.destroy()
        windows_init.show_login(main_user)

    def show_my_profile():
        root.destroy()
        windows_init.show_my_profile(main_user)

    def show_my_duties():
        root.destroy()
        windows_init.show_my_duties(main_user)

    def show_my_points():
        root.destroy()
        windows_init.show_my_points_window(main_user)

    def show_add_case():
        root.destroy()
        windows_init.show_add_case_window(main_user)

    root = tk.Tk()
    root.resizable(False, False)
    root.title("Здравствуйте, диспетчер " + main_user.name)
    screen_width = root.winfo_screenwidth() // 2 - 210
    screen_height = root.winfo_screenheight() // 2 - 100
    root.geometry('420x200+{}+{}'.format(screen_width, screen_height))

    db = DataBase()

    b_im = tk.Button(text="Мой профиль", command=show_my_profile)
    b_my_duties = tk.Button(text="Мои дежурства", command=show_my_duties)
    b_my_points = tk.Button(text="Мои баллы", command=show_my_points)
    b_add_case = tk.Button(text="Добавить обращение", command=show_add_case)
    b_login = tk.Button(text="Выйти из аккаунта", command=leave_akk)

    b_im.place(x=0, y=0, width=420, height=40)
    b_my_duties.place(x=0, y=40, width=420, height=40)
    b_my_points.place(x=0, y=80, width=420, height=40)
    b_add_case.place(x=0, y=120, width=420, height=40)
    b_login.place(x=0, y=160, width=420, height=40)

    root.mainloop()
示例#5
0
def show_consultant(main_user):
    def leave_akk():
        root.destroy()
        windows_init.show_login(main_user)

    def show_my_cases():
        root.destroy()
        windows_init.show_my_cases(main_user)

    def show_my_profile():
        root.destroy()
        windows_init.show_my_profile(main_user)

    def show_my_points():
        root.destroy()
        windows_init.show_my_points_window(main_user)

    root = tk.Tk()
    root.resizable(False, False)
    root.title("Здравствуйте, консультант " + main_user.name)
    screen_width = root.winfo_screenwidth() // 2 - 210
    screen_height = root.winfo_screenheight() // 2 - 80
    root.geometry('420x160+{}+{}'.format(screen_width, screen_height))

    db = DataBase()

    b_im = tk.Button(text="Мой профиль", command=show_my_profile)
    b_show_my_cases = tk.Button(text="Мои дела", command=show_my_cases)
    b_my_points = tk.Button(text="Мои баллы", command=show_my_points)
    b_login = tk.Button(text="Выйти из аккаунта", command=leave_akk)

    b_im.place(x=0, y=0, width=420, height=40)
    b_show_my_cases.place(x=0, y=40, width=420, height=40)
    b_my_points.place(x=0, y=80, width=420, height=40)
    b_login.place(x=0, y=120, width=420, height=40)

    root.mainloop()
示例#6
0
        if len(select) and curr_docs:
            select_doc = curr_docs[select[0]]
        else:
            mb.showerror("Ошибка", "Выберите документ")
            return
        db.delete_document_by_id(select_doc.document_id)
        refresh_docs()

    root = tk.Tk()
    root.resizable(False, False)
    root.title(case.title)
    screen_width = root.winfo_screenwidth() // 2 - 320
    screen_height = root.winfo_screenheight() // 2 - 290
    root.geometry('640x560+{}+{}'.format(screen_width, screen_height))

    db = DataBase()

    e_title = tk.Entry(width=50)
    e_title.insert(0, case.title)

    l_category = tk.Label(text="Категория: " + case.category)
    l_description = tk.Label(width=40, height=5)
    l_description['text'] = "Описание: "
    t_description = tk.Text(width=40, height=5)
    t_description.insert(0.0, case.description)

    l_st = tk.Label(width=40)
    if case.s_id and case.s_id != "None" and case.s_id != "null":
        st = db.get_user_by_id(case.s_id)
        l_st['text'] = "Консультант: " + st.name
    else:
示例#7
0
def show_admin(main_user):
    def leave_akk():
        root.destroy()
        windows_init.show_login(main_user)

    def show_students():
        root.destroy()
        windows_init.show_my_students(main_user)

    def show_my_profile():
        root.destroy()
        windows_init.show_my_profile(main_user)

    def show_teachers():
        root.destroy()
        windows_init.show_my_teachers_window(main_user)

    def add_users():
        file_name = fd.askopenfilename(filetypes=(("Json FILES", "*.json"),
                                                  ("All files", "*.*")))
        if not file_name:
            mb.showerror("Ошибка", "Вы не выбрали файл!")
            return
        f = open(file_name)
        new_data = json.load(f)
        f.close()
        logs_str = ""
        for data in new_data["users"]:
            user = User((data["id"], data["name"], data["type"],
                         data["competence"], data["login"], data["password"],
                         data["personal_data"], data["points"]))
            error = db.insert_users([user])
            if error and error != None and error != "None" and error != "null" and error != "none":
                logs_str += "\n" + "User " + user.name + \
                    " not added: " + str(error)
            else:
                logs_str += "\n" + "User " + user.name + " successful added in database"

        f_logs = open("D:/homeworks/university_databases/logs.txt", "w")
        f_logs.write(logs_str)
        f_logs.close()

    def insert_user():
        root.destroy()
        windows_init.show_add_one_user_window(main_user)

    root = tk.Tk()
    root.resizable(False, False)
    root.title("Добро пожаловать, админ " + main_user.name)

    screen_width = root.winfo_screenwidth() // 2 - 210
    screen_height = root.winfo_screenheight() // 2 - 120
    root.geometry('420x240+{}+{}'.format(screen_width, screen_height))

    db = DataBase()

    b_im = tk.Button(text="Мой профиль", command=show_my_profile)
    b_show_students = tk.Button(text="Студенты", command=show_students)
    b_show_teachers = tk.Button(text="Преподаватели", command=show_teachers)
    b_insert_user = tk.Button(text="Добавить пользователя",
                              command=insert_user)
    b_add_users = tk.Button(text="Добавить пользователей из файла",
                            command=add_users)
    b_login = tk.Button(text="Выйти из аккаунта", command=leave_akk)

    b_im.place(x=0, y=0, width=420, height=40)
    b_show_students.place(x=0, y=40, width=420, height=40)
    b_show_teachers.place(x=0, y=80, width=420, height=40)
    b_insert_user.place(x=0, y=120, width=420, height=40)
    b_add_users.place(x=0, y=160, width=420, height=40)
    b_login.place(x=0, y=200, width=420, height=40)

    root.mainloop()
def show_my_cases(main_user):
    def go_back():
        if main_user.type == "преподаватель":
            root.destroy()
            windows_init.show_teacher(main_user)
        elif main_user.type == "тьютор":
            root.destroy()
            windows_init.show_tutor_window(main_user)
        elif main_user.type == "студент":
            root.destroy()
            windows_init.show_consultant_window(main_user)
        else:  # какая-то ошибка
            root.destroy()
            windows_init.show_login(main_user)

    def show_all():
        lbox.delete(0, tk.END)
        global curr_cases
        if main_user.type == "тьютор":
            curr_cases = db.get_all_cases()
        elif main_user.type == "преподаватель":
            curr_cases = db.get_cases_by_teacher_id(main_user.id)
        elif main_user.type == "студент":
            curr_cases = db.get_cases_by_student_id(main_user.id)
        if not curr_cases:
            lbox.insert(tk.END, "Ничего не найдено")
            curr_cases = []
        for c in curr_cases:
            lbox.insert(tk.END, c.title)

    def show_check():
        lbox.delete(0, tk.END)
        global curr_cases
        if main_user.type == "тьютор":
            curr_cases = db.get_all_cases_waiting_for_appointment()
        elif main_user.type == "преподаватель":
            curr_cases = db.get_cases_which_need_teacher_editing(main_user.id)
        else:
            curr_cases = db.get_cases_which_need_student_editing(main_user.id)
        if not curr_cases:
            lbox.insert(tk.END, "Ничего не найдено")
            curr_cases = []
        for c in curr_cases:
            lbox.insert(tk.END, c.title)

    def show_finished():
        lbox.delete(0, tk.END)
        global curr_cases
        if main_user.type == "тьютор":
            pass
            curr_cases = db.get_all_completed_cases()
        elif main_user.type == "преподаватель":
            curr_cases = db.get_teacher_completed_cases(main_user.id)
        else:
            curr_cases = db.get_student_completed_cases(main_user.id)
        if not curr_cases:
            lbox.insert(tk.END, "Ничего не найдено")
            curr_cases = []
        for c in curr_cases:
            lbox.insert(tk.END, c.title)

    def show_case_win():
        global curr_cases
        select = list(lbox.curselection())
        if len(select) and curr_cases:
            select_case = curr_cases[select[0]]
            root.destroy()
            windows_init.show_case_window(main_user, select_case)
        else:
            mb.showerror("Ошибка", "Вы не выбрали дело!")
            return

    def change():
        if type_var.get() == 0:
            show_all()
        elif type_var.get() == 1:
            show_check()
        else:
            show_finished()

    root = tk.Tk()
    root.resizable(False, False)
    root.title("Мои дела")
    screen_width = root.winfo_screenwidth() // 2 - 265
    screen_height = root.winfo_screenheight() // 2 - 110
    root.geometry('530x220+{}+{}'.format(screen_width, screen_height))

    db = DataBase()

    type_var = tk.IntVar()
    type_var.set(0)

    r_all_cases = tk.Radiobutton(text="Все дела",
                                 variable=type_var,
                                 value=0,
                                 command=change)
    r_check_cases = tk.Radiobutton(text="Требующие подтверждения",
                                   variable=type_var,
                                   value=1,
                                   command=change)
    if main_user.type == "студент":
        r_check_cases = tk.Radiobutton(text="Требующие доработки",
                                       variable=type_var,
                                       value=1,
                                       command=change)
    r_finished_cases = tk.Radiobutton(text="Завершенные",
                                      variable=type_var,
                                      value=2,
                                      command=change)

    b_back = tk.Button(text="Назад", command=go_back)
    lbox = tk.Listbox(width=40, height=10)
    b_case_win = tk.Button(text="Просмотреть выбранное дело",
                           command=show_case_win)

    change()

    title = tk.Label()
    title['text'] = "Список дел:"

    title.place(x=0, y=0, width=300, height=20)
    lbox.place(x=0, y=20, width=300, height=150)
    r_all_cases.place(x=270, y=30, width=220, height=20)
    r_check_cases.place(x=310, y=80, width=220, height=20)
    r_finished_cases.place(x=285, y=130, width=220, height=20)
    b_case_win.place(x=0, y=170, width=300, height=30)
    b_back.place(x=0, y=200, width=40, height=20)

    show_all()
    root.mainloop()
示例#9
0
def show_my_teachers(main_user):
    def go_back():
        root.destroy()
        windows_init.show_admin_window(main_user)

    def show_teachers():
        lbox.delete(0, tk.END)
        global curr_teachers
        curr_teachers = []
        select = list(lb.curselection())
        if len(select):
            if competence_list[select[0]] == "Все":
                t = []
                for comp in competence_list[1:]:
                    t.append(db.get_teachers_by_competence(comp))
                for ans in t:
                    if ans != None and ans != "None" and ans != "null" and ans:
                        curr_teachers += ans
            else:
                curr_teachers = db.get_teachers_by_competence(
                    competence_list[select[0]])
        else:
            mb.showerror("Ошибка", "Выберите категорию!")
            return
        if not curr_teachers:
            lbox.insert(tk.END, "Ничего не найдено")
            curr_teachers = []
        for t in curr_teachers:
            lbox.insert(tk.END, t.name)

    def show_profile():
        global curr_teachers
        select = list(lbox.curselection())
        if len(select) and curr_teachers:
            select_user = curr_teachers[select[0]]
            root.destroy()
            windows_init.show_profile(main_user, select_user)
        else:
            mb.showerror("Ошибка", "Выберите преподавателя!")
            return

    def del_teacher():
        global curr_teachers
        select = list(lbox.curselection())
        if len(select) and curr_teachers:
            select_teacher = curr_teachers[select[0]]
            db.delete_user_by_id(select_teacher)
            show_teachers()
            return
        else:
            mb.showerror("Ошибка", "Выберите преподавателя!")
            return

    root = tk.Tk()
    root.resizable(False, False)
    root.title("Преподаватели")
    screen_width = root.winfo_screenwidth() // 2 - 230
    screen_height = root.winfo_screenheight() // 2 - 125
    root.geometry('460x250+{}+{}'.format(screen_width, screen_height))

    competence_list = [
        "Все", "гражданское право", "трудовое право", "административное право",
        "жилищное право"
    ]

    db = DataBase()

    lb = tk.Listbox(height=len(competence_list))
    for r in competence_list:
        lb.insert(tk.END, r)

    b_show_teachers = tk.Button(text="Показать",
                                compound=tk.TOP,
                                command=show_teachers)
    b_show_profile = tk.Button(text="Посмотреть профиль", command=show_profile)
    b_del = tk.Button(text="Удалить", command=del_teacher)
    b_back = tk.Button(text="Назад", command=go_back)
    lbox = tk.Listbox(width=40, height=10)

    title = tk.Label()
    title['text'] = "Список преподавателей:"
    title.place(x=0, y=0, width=300, height=20)

    lbox.place(x=0, y=20, width=300, height=150)

    category_label = tk.Label(text="Выберите категорию:")
    category_label.place(x=305, y=0, width=150, height=30)

    lb.place(x=305, y=40, width=150, height=100)

    b_show_teachers.place(x=390, y=140, width=60, height=30)

    b_show_profile.place(x=0, y=170, width=300, height=30)

    b_del.place(x=0, y=200, width=300, height=30)

    b_back.place(x=0, y=230, width=40, height=20)

    #show_teachers()
    root.mainloop()
def show_profile(main_user, user):
    def save():
        name = e_name.get()
        if len(name) < 6:
            mb.showerror("Ошибка", "Имя должно быть длиннее 6 символов!")
            return
        for c in name:
            if not (("a" <= c <= "z") or ("A" <= c <= "Z") or
                    ("а" <= c <= "я") or ("А" <= c <= "Я") or c == " "):
                mb.showerror("Ошибка", "Имя должно содержать только буквы!")
                return
        if main_user.type == "админ":
            login = e_login.get()
            u = db.get_user_by_login(login)
            if u and u.login != user.login:
                mb.showerror("Ошибка", "Данный логин уже существует!")
                return

            if len(login) < 4:
                mb.showerror("Ошибка", "Логин должен быть длиннее 4 символов!")
                return

            for c in login:
                if not (("a" <= c <= "z") or ("A" <= c <= "Z") or ("0" <= c <= "9")):
                    mb.showerror(
                        "Ошибка", "Логин должен содержать только латинские буквы и цифры!")
                    return
            user.login = login

        user.name = name

        select_comp = list(lb_comp.curselection())
        if len(select_comp):
            if user.type == "студент":
                user.competence = s_competence_list[select_comp[0]]
            else:
                user.competence = t_competence_list[select_comp[0]]

        db.update_user_by_id(user)
        go_back()

    def go_back():
        if main_user.type == "преподаватель":
            root.destroy()
            windows_init.show_my_students(main_user)
        elif main_user.type == "студент" and main_user.competence == "консультант":
            root.destroy()
            windows_init.show_consultant_window(main_user)
        elif main_user.type == "тьютор":
            root.destroy()
            windows_init.show_my_students(main_user)
        elif main_user.type == "студент" and main_user.competence == "диспетчер":
            root.destroy()
            windows_init.show_dispatcher_window(main_user)
        else:
            if user.type == "студент":
                root.destroy()
                windows_init.show_my_students(main_user)
            elif user.type == "преподаватель":
                root.destroy()
                windows_init.show_my_teachers_window(main_user)
            else:
                root.destroy()
                windows_init.show_admin_window(main_user)

    root = tk.Tk()
    root.resizable(False, False)
    root.title(user.name)
    screen_width = root.winfo_screenwidth() // 2 - 210
    screen_height = root.winfo_screenheight() // 2 - 120
    root.geometry('420x247+{}+{}'.format(screen_width, screen_height))

    t_competence_list = ["гражданское право", "трудовое право",
                         "административное право", "жилищное право"]
    s_competence_list = ["консультант", "диспетчер"]
    db = DataBase()

    label_name = tk.Label(text="ФИО: ")
    if (main_user.type == "админ"):
        e_name = tk.Entry(width=40)
        e_name.insert(0, user.name)
    else:
        l_name = tk.Label(text=user.name, width=40)

    label_type = tk.Label(text="ТИП: ")
    l_type = tk.Label(text=user.type)

    label_comp = tk.Label(text="КОМПЕТЕНЦИЯ: ")  # + user.competence)
    if main_user.type == "админ":
        if user.type == "студент":
            lb_comp = tk.Listbox(height=len(s_competence_list))
            for r in s_competence_list:
                lb_comp.insert(tk.END, r)
        else:
            lb_comp = tk.Listbox(height=len(t_competence_list))
            for r in t_competence_list:
                lb_comp.insert(tk.END, r)
    else:
        l_comp = tk.Label(text=user.competence)

    label_login = tk.Label(text="ЛОГИН: ")
    if main_user.type == "админ":
        e_login = tk.Entry(width=40)
        e_login.insert(0, user.login)
    else:
        l_login = tk.Label(text=user.login)

        #l_points = tk.Label(text="БАЛЛЫ: " + str(user.points))
    label_points = tk.Label(text="БАЛЛЫ: ")
    l_points = tk.Label(text=str(user.points))

    b_back = tk.Button(text="Назад", command=go_back)
    b_save = tk.Button(text="Сохранить и выйти", command=save)

    label_name.pack()
    if main_user.type == "админ":
        e_name.pack()
    else:
        l_name.pack()

    label_type.pack()
    l_type.pack()

    label_comp.pack()
    if main_user.type == "админ":
        lb_comp.pack()
    else:
        l_comp.pack()

    label_login.pack()
    if main_user.type == "админ":
        e_login.pack()
    else:
        l_login.pack()

    if user.type == "студент":
        label_points.pack()

    if user.type == "студент":
        l_points.pack()

    if main_user.type == "админ":
        b_save.pack(side="bottom")

    b_back.place(x=0, y=227, width=40, height=20)

    root.mainloop()
示例#11
0
        "personal_data": "",
        "points": "0.0"
    }, {
        "id": "id",
        "name": "Романов Борис Павлович",
        "type": "студент",
        "competence": "диспетчер",
        "login": "******",
        "password": "******",
        "personal_data": "",
        "points": "0.0"
    }]
}
user = User(("id", "Иванов Денис Юрьевич", "админ", "юридическая клиника",
             "admin", "1111", "", "0.0"))
db = DataBase()
db.insert_users([user])
"""
file_name = fd.askopenfilename(filetypes=(("Json FILES", "*.json"),
                                                        ("All files", "*.*") ))
if not file_name:
	mb.showerror("Ошибка", "Вы не выбрали файл!")
file_path_list = file_name.split("/")
print(file_path_list[-1])
# doc = Document((file_name,))


file_name = fd.askopenfilename()


with open(file_name, "w") as write_file:
示例#12
0
def add_cons_teach(main_user, case):
    def go_back():
        root.destroy()
        windows_init.show_case_window(main_user, case)

    def show_teachers():
        global curr_teachers
        comp = case.category
        curr_teachers = db.get_teachers_by_competence(comp)
        if not curr_teachers:
            t_lbox.insert(tk.END, "Не найдено подходящих кураторов")
            curr_teachers = []
        for t in curr_teachers:
            case_number = 0
            t_cases = db.get_cases_by_teacher_id(t.id)
            if t_cases and t_cases != "None" and t_cases != "null":
                case_number = len(t_cases)
            t_lbox.insert(tk.END, t.name + " (" + str(case_number) + ")")

    def show_student():
        global curr_students
        curr_students = db.get_сonsultants_order_by_points()
        if not curr_students:
            s_lbox.insert(tk.END, "Не найдено подходящих консультантов")
            curr_students = []
        for s in curr_students:
            s_lbox.insert(tk.END, s.name + " " + str(s.points))

    def ok():
        select_teachers = list(t_lbox.curselection())
        select_students = list(s_lbox.curselection())
        if len(select_teachers) < 1 or not curr_teachers:
            mb.showerror("Ошибка", "Выберите куратора среди преподавателей")
            return

        if len(select_students) < 1 or not curr_students:
            mb.showerror("Ошибка", "Выберите консультанта")
            return
        case.status = "ожидаются правки плана консультации"
        case.s_id = curr_students[select_students[0]].id
        case.t_id = curr_teachers[select_teachers[0]].id
        db.update_case_by_id(case)
        go_back()

    root = tk.Tk()
    root.resizable(False, False)
    root.title("Добавление исполнителей")
    screen_width = root.winfo_screenwidth() // 2 - 210
    screen_height = root.winfo_screenheight() // 2 - 135
    root.geometry('420x270+{}+{}'.format(screen_width, screen_height))

    db = DataBase()

    b_back = tk.Button(text="Назад", command=go_back)
    t_lbox = tk.Listbox(exportselection=0, width=40, height=5)
    s_lbox = tk.Listbox(exportselection=0, width=40, height=5)
    b_ok = tk.Button(text="OK", command=ok)

    curator_label = tk.Label(text="Выберите куратора дела")
    curator_label.pack()
    t_lbox.pack(side="top")

    student_label = tk.Label(text="Выберите консультанта по делу")
    student_label.pack()
    s_lbox.pack(side="top")

    b_ok.pack()
    b_back.place(x=0, y=250, width=40, height=20)

    show_teachers()
    show_student()
    root.mainloop()
def show_add_points(main_user, user):
    def go_back():
        root.destroy()
        windows_init.show_my_students(main_user)

    def add():
        user.points = max(user.points + float(varAsTxt.get()), 0.0)
        db.update_user_by_id(user)
        points_event = PointsEvent(("id", varAsTxt.get(), user.id,
                                    main_user.id, var_reason.get(), ""))
        list_events = [points_event]
        db.insert_points_event(list_events)
        l_exp['text'] = varAsTxt.get()
        go_back()

    def onSelect(val):
        sender = val.widget
        idx = sender.curselection()
        value = sender.get(idx)

        var_reason.set(value)

    root = tk.Tk()
    root.resizable(False, False)
    screen_width = root.winfo_screenwidth() // 2 - 150
    screen_height = root.winfo_screenheight() // 2 - 90
    root.geometry('300x180+{}+{}'.format(screen_width, screen_height))
    root.title("Добавление баллов")

    reason_list = ["Доклад"]
    if user.competence == "диспетчер":
        reason_list.append("Дежурство")
    db = DataBase()

    # an MVC-trick an indirect value-holder
    varAsTxt = tk.StringVar()
    scale = tk.Scale(
        root,
        variable=varAsTxt,  # MVC-Model-Part value holder
        from_=-1.0,  # MVC-Model-Part value-min-limit
        to=1.0,  # MVC-Model-Part value-max-limit
        length=600,  # MVC-Visual-Part layout geometry [px]
        digits=2,  # MVC-Visual-Part presentation trick
        resolution=0.1,
        orient=tk.HORIZONTAL  # MVC-Controller-Part stepping
    )

    var_reason = tk.StringVar()
    lb = tk.Listbox(height=len(reason_list))
    for r in reason_list:
        lb.insert(tk.END, r)

    lb.bind("<<ListboxSelect>>", onSelect)

    b_add = tk.Button(text="Отправить", command=add)
    b_back = tk.Button(text="Назад", command=go_back)
    l_exp = tk.Label(width=40)

    scale.pack()
    lb.pack(pady=15)
    l_exp.pack()
    b_add.pack()
    b_back.place(x=0, y=160, width=40, height=20)

    root.mainloop()
def add_one_user(main_user):
    def go_back():
        root.destroy()
        windows_init.show_admin_window(main_user)

    def add():
        user = User(("", "", "", "", "", "", "", "0.0"))
        name = e_name.get()
        if len(name) < 6:
            mb.showerror("Ошибка",
                         "Имя пользователя должно быть длиннее 5 символов!")
            return

        for c in name:
            if not (("a" <= c <= "z") or ("A" <= c <= "Z") or
                    ("а" <= c <= "я") or ("А" <= c <= "Я") or c == " "):
                mb.showerror(
                    "Ошибка",
                    "Имя пользователя должно содержать только буквы!")
                return
        user.name = name

        login = e_login.get()
        u = db.get_user_by_login(login)
        if u and u.login != user.login:
            mb.showerror("Ошибка", "Данный логин уже существует!")
            return

        if len(login) < 4:
            mb.showerror("Ошибка", "Логин должен быть длиннее 4 символов!")
            return

        for c in login:
            if not (("a" <= c <= "z") or ("A" <= c <= "Z") or
                    ("0" <= c <= "9")):
                mb.showerror(
                    "Ошибка",
                    "Логин должен содержать только латинские буквы и цифры!")
                return
        user.login = login

        select_comp = list(lb_comp.curselection())
        if len(select_comp):
            if type_var.get():
                user.competence = t_competence_list[select_comp[0]]
                user.type = "преподаватель"
            else:
                user.competence = s_competence_list[select_comp[0]]
                user.type = "студент"
        else:
            mb.showerror("Ошибка", "Выберите компетенцию у пользователя!")
            return

        password = e_password.get()
        if len(password) < 4:
            mb.showerror("Ошибка", "Пароль должен быть длиннее 3 символов!")
            return
        user.password = password
        db.insert_users([user])
        go_back()

    def change():
        lb_comp.delete(0, tk.END)
        if type_var.get():
            for c in t_competence_list:
                lb_comp.insert(tk.END, c)
        else:
            for c in s_competence_list:
                lb_comp.insert(tk.END, c)

    root = tk.Tk()
    root.resizable(False, False)
    root.title("Добавление нового пользователя")

    screen_width = root.winfo_screenwidth() // 2 - 210
    screen_height = root.winfo_screenheight() // 2 - 100
    root.geometry('420x290+{}+{}'.format(screen_width, screen_height))

    s_competence_list = ["консультант", "диспетчер"]
    t_competence_list = [
        "гражданское право", "трудовое право", "административное право",
        "жилищное право"
    ]

    db = DataBase()

    fio_label = tk.Label(text="ФИО")
    fio_label.pack()

    e_name = tk.Entry(width=40)
    type_var = tk.IntVar()
    type_var.set(0)
    r_s = tk.Radiobutton(text="Студент",
                         variable=type_var,
                         value=0,
                         command=change)
    r_t = tk.Radiobutton(text="Преподаватель",
                         variable=type_var,
                         value=1,
                         command=change)

    lb_comp = tk.Listbox(width=40, height=4)
    change()
    label_login = tk.Label(text="Логин:")
    e_login = tk.Entry(width=40)
    label_password = tk.Label(text="Пароль")
    e_password = tk.Entry(width=40)

    b_back = tk.Button(text="Назад", command=go_back)
    b_add = tk.Button(text="Добавить", command=add)

    e_name.pack()

    r_s.pack()
    r_t.pack()
    lb_comp.pack()
    label_login.pack()
    e_login.pack()
    label_password.pack()
    e_password.pack()

    b_add.pack()
    b_back.place(x=0, y=270, width=40, height=20)
    root.mainloop()
示例#15
0
def show_my_duties(main_user):
    def go_back():
        if main_user.type == "преподаватель":
            root.destroy()
            windows_init.show_teacher(main_user)
        elif main_user.type == "тьютор":
            root.destroy()
            windows_init.show_tutor_window(main_user)
        else:
            root.destroy()
            windows_init.show_dispatcher_window(main_user)

    def show_duties():
        lbox.delete(0, tk.END)
        global curr_duties
        if var.get() == 0:
            if main_user.type == "студент":
                curr_duties = db.get_prev_duties_for_particular_student(
                    main_user.id)
            else:
                curr_duties = db.get_prev_duties()
        else:
            if main_user.type == "студент":
                curr_duties = db.get_next_duties_for_particular_student(
                    main_user.id)
            else:
                curr_duties = db.get_next_duties()
        if not curr_duties:
            lbox.insert(tk.END, "Ничего не найдено")
            curr_duties = []

        for dut in curr_duties:
            user = db.get_user_by_id(dut.s_id)
            lbox.insert(tk.END, user.name + " " + dut.date)

    def add_duty():
        root.destroy()
        windows_init.show_add_duty(main_user)

    def change_der():
        global curr_duties
        select = list(lbox.curselection())
        if len(select) and curr_duties:
            select_duty = curr_duties[select[0]]
            root.destroy()
            windows_init.show_change_dispatcher_window(main_user, select_duty)
        else:
            mb.showerror("Ошибка", "Выберите дежурство!")

    root = tk.Tk()
    root.resizable(False, False)
    root.title("Мои дежурства")
    screen_width = root.winfo_screenwidth() // 2 - 240
    screen_height = root.winfo_screenheight() // 2 - 125
    root.geometry('480x250+{}+{}'.format(screen_width, screen_height))

    db = DataBase()

    var = tk.IntVar()
    var.set(1)
    r_prev = tk.Radiobutton(text="Прошедшие", variable=var, value=0)
    r_curr = tk.Radiobutton(text="Запланированные", variable=var, value=1)

    b_show_duties = tk.Button(text="Показать",
                              compound=tk.TOP,
                              command=show_duties)
    b_change_der = tk.Button(text="Изменить дежурство", command=change_der)
    b_add_duty = tk.Button(text="Добавить дежурство", command=add_duty)
    b_back = tk.Button(text="Назад", command=go_back)
    lbox = tk.Listbox(width=40, height=10)

    title = tk.Label()
    title['text'] = "Список дежурств:"

    title.place(x=0, y=0, width=300, height=20)
    lbox.place(x=0, y=20, width=300, height=150)

    r_curr.place(x=275, y=30, width=220, height=20)

    r_prev.place(x=260, y=80, width=220, height=20)

    b_show_duties.place(x=335, y=120, width=80, height=20)

    if main_user.type == "тьютор":
        b_add_duty.place(x=0, y=170, width=300, height=30)
        b_change_der.place(x=0, y=200, width=300, height=30)
    b_back.place(x=0, y=230, width=40, height=20)

    root.mainloop()
示例#16
0
def show_my_profile(main_user):
    def save():
        if main_user.type == "админ":
            name = e_name.get()
            if len(name) < 6:
                mb.showerror(
                    "Ошибка",
                    "Имя пользователя должно быть длиннее 5 символов!")
                return

            for c in name:
                if not (("a" <= c <= "z") or ("A" <= c <= "Z") or
                        ("а" <= c <= "я") or ("А" <= c <= "Я") or c == " "):
                    mb.showerror(
                        "Ошибка",
                        "Имя пользователя должно содержать только буквы!")
                    return
            user.name = name
        password = e_password.get()
        if len(password) < 4:
            mb.showerror("Ошибка", "Пароль должен быть длиннее 3 символов!")
            return
        user.password = password
        db.update_user_by_id(main_user)
        go_back()

    def go_back():
        if main_user.type == "преподаватель":
            root.destroy()
            windows_init.show_teacher(main_user)
        elif main_user.type == "студент" and main_user.competence == "консультант":
            root.destroy()
            windows_init.show_consultant_window(main_user)
        elif main_user.type == "тьютор":
            root.destroy()
            windows_init.show_tutor_window(main_user)
        elif main_user.type == "студент" and main_user.competence == "диспетчер":
            root.destroy()
            windows_init.show_dispatcher_window(main_user)
        else:
            root.destroy()
            windows_init.show_admin_window(main_user)

    root = tk.Tk()
    root.resizable(False, False)
    root.title("Мой профиль")
    screen_width = root.winfo_screenwidth() // 2 - 210
    screen_height = root.winfo_screenheight() // 2 - 120
    root.geometry('420x235+{}+{}'.format(screen_width, screen_height))

    db = DataBase()

    if (main_user.type == "админ"):
        e_name_text = tk.Label(width=40)
        e_name_text['text'] = "Изменить ФИО:"
        e_name_text.pack(side="top")

        e_name = tk.Entry(width=40)
        e_name.insert(0, main_user.name)
    else:
        l_nm = tk.Label(width=40)
        l_nm['text'] = "ФИО:"
        l_nm.pack(side="top")

        l_name = tk.Label(width=40)
        l_name['text'] = main_user.name
        l_name.pack(side="top")

    l_comp = tk.Label(text=main_user.competence)
    l_login = tk.Label(text=main_user.login)
    e_password = tk.Entry(width=20)
    e_password.insert(0, main_user.password)

    l_points = tk.Label()
    if main_user.type == "студент":
        l_points['text'] = main_user.points

    b_save = tk.Button(text="Сохранить и выйти", command=save)
    b_back = tk.Button(text="Назад", command=go_back)

    if main_user.type == "админ":
        e_name.pack()
    else:
        l_name.pack()

    if main_user.type == "студент" or main_user.type == "преподаватель":
        l_comp_text = tk.Label(width=40)
        l_comp_text['text'] = "КОМПЕТЕНЦИЯ:"
        l_comp_text.pack(side="top")

        l_comp.pack(side="top")

    if main_user.type == "студент":
        l_points_text = tk.Label(width=40)
        l_points_text['text'] = "МОИ БАЛЛЫ:"
        l_points_text.pack(side="top")
        l_points.pack(side="top")

    if main_user.type == "студент" or main_user.type == "преподаватель":
        l_login_text = tk.Label(width=40)
        l_login_text['text'] = "ЛОГИН:"
        l_login_text.pack(side="top")

        l_login.pack(side="top")

    if main_user.type == ("админ"):
        e_login_text = tk.Label(width=40)
        e_login_text['text'] = "Изменить логин:"
        e_login_text.pack(side="top")

        e_login = tk.Entry(width=40)
        e_login.insert(0, main_user.login)
        e_login.pack(side="top")

    e_password_text = tk.Label(width=40)
    e_password_text['text'] = "Изменить пароль:"
    e_password_text.pack(side="top")

    e_password.pack(side="top")
    b_save.pack(side="top")

    b_back.place(x=0, y=210, width=60, height=25)

    root.mainloop()
def show_my_students(main_user):
    def go_back():
        if main_user.type == "преподаватель":
            root.destroy()
            windows_init.show_teacher(main_user)
        elif main_user.type == "тьютор":
            root.destroy()
            windows_init.show_tutor_window(main_user)
        else:
            root.destroy()
            windows_init.show_admin_window(main_user)

    def show_students():
        lbox.delete(0, tk.END)
        global curr_students
        if var.get() == 0:
            if var_order.get() == 0:
                curr_students = db.get_all_students()
            elif var_order.get() == 1:
                curr_students = db.get_students_order_by_points()
            else:
                sts = db.get_students_order_by_points()
                if not sts:
                    curr_students = []
                else:
                    curr_students = sts[::-1]
        elif var.get() == 1:
            if var_order.get() == 0:
                curr_students = db.get_consultants()
            elif var_order.get() == 1:
                curr_students = db.get_сonsultants_order_by_points()
            else:
                sts = db.get_сonsultants_order_by_points()
                if not sts:
                    curr_students = []
                else:
                    curr_students = sts[::-1]
        else:
            if var_order.get() == 0:
                curr_students = db.get_dispatchers()
            elif var_order.get() == 1:
                curr_students = db.get_dispatchers_order_by_points()
            else:
                sts = db.get_dispatchers_order_by_points()
                if not sts:
                    curr_students = []
                else:
                    curr_students = sts[::-1]
        if not curr_students:
            lbox.insert(tk.END, "Ничего не найдено")
            curr_students = []
        for st in curr_students:
            lbox.insert(tk.END, st.name + " " +
                        st.competence + " " + str(st.points))

    def add_points():
        global curr_students
        select = list(lbox.curselection())
        if len(select) and curr_students:
            select_user = curr_students[select[0]]
            root.destroy()
            windows_init.show_add_points_window(main_user, select_user)
        else:
            mb.showerror("Ошибка", "Выберите студента!")
            return

    def show_profile():
        global curr_students
        select = list(lbox.curselection())
        if len(select) and curr_students:
            select_user = curr_students[select[0]]
            root.destroy()
            windows_init.show_profile(main_user, select_user)
        else:
            mb.showerror("Ошибка", "Выберите студента!")
            return

    root = tk.Tk()
    root.resizable(False, False)
    root.title("Мои студенты")
    screen_width = root.winfo_screenwidth() // 2 - 380
    screen_height = root.winfo_screenheight() // 2 - 125
    root.geometry('760x250+{}+{}'.format(screen_width, screen_height))

    db = DataBase()

    var = tk.IntVar()
    var.set(0)
    r_all = tk.Radiobutton(text="Все студенты", variable=var, value=0)
    r_cons = tk.Radiobutton(text="Консультанты", variable=var, value=1)
    r_disp = tk.Radiobutton(text="Диспетчеры", variable=var, value=2)

    var_order = tk.IntVar()
    var_order.set(0)
    r_by_name = tk.Radiobutton(text="По имени", variable=var_order, value=0)
    r_by_p_u = tk.Radiobutton(
        text="По возрастанию баллов", variable=var_order, value=1)
    r_by_p_d = tk.Radiobutton(
        text="По убыванию баллов", variable=var_order, value=2)

    b_show_students = tk.Button(
        text="Показать", compound=tk.TOP, command=show_students)
    b_add_points = tk.Button(text="Добавить баллы", command=add_points)
    b_show_profile = tk.Button(text="Посмотреть профиль", command=show_profile)
    b_back = tk.Button(text="Назад", command=go_back)
    
    lbox = tk.Listbox(width=40, height=10)

    title = tk.Label()
    title['text'] = "Список студентов:"
    title.place(x=0, y=0, width=300, height=20)
    lbox.place(x=0, y=20, width=300, height=150)
    r_all.place(x=305, y=20,  width=220, height=20)
    r_cons.place(x=310, y=70,  width=220, height=20)
    r_disp.place(x=305, y=120,  width=220, height=20)

    r_by_name.place(x=510, y=20, width=220, height=20)
    r_by_p_u.place(x=550, y=70, width=220, height=20)
    r_by_p_d.place(x=545, y=120, width=220, height=20)

    b_show_students.place(x=500, y=180, width=100, height=30)

    b_show_profile.place(x=0, y=170, width=300, height=30)

    if main_user.type != "админ":
        b_add_points.place(x=0, y=200, width=300, height=30)

    # label.pack()
    b_back.place(x=0, y=230, width=40, height=20)

    show_students()
    root.mainloop()