Esempio n. 1
0
 def get_selected_row(self, event):
     try:
         idx = self.list_lbx.curselection()[0]
         guest = self.database.find_guest(self.idx_to_id[idx])
         self.clear_inputfields_command()
         if guest.found:
             self.log.info(guest.first_name + ' ' + guest.last_name)
             self.guest_id = guest.id
             self.badge_code_txt.set(guest.badge_code)
             self.badge_number_txt.set(guest.badge_number)
             self.first_name_txt.set(guest.first_name)
             self.last_name_txt.set(guest.last_name)
             self.email_txt.set(guest.email)
             self.phone_txt.set(guest.phone)
             self.sub_type_txt.set(guest.subscription_type)
             self.select_subscription_type(guest.subscription_type)
             if guest.subscription_type == Guest.SUB_TYPE_SUBSCRIPTION:
                 self.sub_from_txt.set(
                     guest.subscribed_from.strftime('%d %B %Y'))
                 #self.sub_till_txt.set(FGR_DB.date_be_add_year(self.sub_from_txt.get(), 1))
                 self.sub_till_txt.set(
                     FGR_DB.add_years(guest.subscribed_from,
                                      1).strftime('%d %B %Y'))
             else:
                 self.payg_left_txt.set(guest.pay_as_you_go_left)
                 self.payg_max_txt.set(guest.pay_as_you_go_max)
     except IndexError:
         pass
Esempio n. 2
0
 def badge_entered(self, event):
     #check if the admin code is used.  If so, switch to admin mode
     guest_found = False
     if self.badge_ent.get() == '2500':
         self.change_mode(force_mode=self.Mode.admin)
     else:
         is_valid_code, is_rfid_code, code = process_code(
             self.badge_ent.get())
         if is_valid_code and is_rfid_code:
             guest = self.database.find_guest_from_badge(code)
             guest_found = guest.found
         if guest_found:
             direction = self.register.new_registration(guest)
             till_string = ''
             if direction == 'IN':
                 if guest.subscription_type == Guest.SUB_TYPE_SUBSCRIPTION:
                     delta = FGR_DB.add_years(guest.subscribed_from,
                                              1) - date.today()
                     if delta.days < 0:
                         messagebox.showwarning(
                             'Abonnement is verlopen',
                             'Opgelet, uw abonnement is verlopen.\nVraag info aan een medewerker'
                         )
                     else:
                         till_string = ', abonnement is nog {} dagen geldig'.format(
                             delta.days)
                 else:
                     guest.pay_as_you_go_left -= 1
                     if guest.pay_as_you_go_left < 0:
                         messagebox.showwarning(
                             'Beurtenkaart is verlopen',
                             'Opgelet, uw beurtenkaart is verlopen.\nVraag info aan een medewerker'
                         )
                     else:
                         till_string = ', er zijn nog {} geldige beurten'.format(
                             guest.pay_as_you_go_left)
                     rslt = self.database.update_guest(
                         guest.id, guest.badge_code, guest.badge_number,
                         guest.first_name, guest.last_name, guest.email,
                         guest.phone, guest.subscription_type,
                         guest.subscribed_from, guest.pay_as_you_go_left,
                         guest.pay_as_you_go_max)
             self.show_message(
                 "Hallo {}, u heb juist {} gebadged{}".format(
                     guest.first_name, direction, till_string), 4000,
                 'green')
         else:
             self.show_message(
                 "U bent nog niet geregistreerd, gelieve hulp te vragen",
                 5000, "red")
     self.badge_ent.delete(0, tk.END)
Esempio n. 3
0
    def __init__(self, root=None, log=None):

        self.log = log

        #initialize database
        self.database = FGR_DB(LOG_HANDLE)
        #{self.database.test_populate_database()

        #initialize register
        self.register = Register(root, self.database, LOG_HANDLE)

        #initialize Guests
        self.guests = Guests(root, self.database, LOG_HANDLE,
                             self.child_window_closes)

        #initialize Registrations
        self.registrations = Registrations(root, self.database, LOG_HANDLE,
                                           self.child_window_closes)

        #initialize Export
        self.export = Export(root, self.database, LOG_HANDLE,
                             self.child_window_closes)

        #initialize GUI
        self.root = root
        self.root_frm = tk.Frame(self.root)
        self.root_frm.grid()
        self.init_menu()
        self.init_widgets()

        #initialize mode
        self.mode = self.Mode.admin
        self.change_mode()

        #set the minimum size of the window
        root.update()
        root.minsize(root.winfo_width(), root.winfo_height())
Esempio n. 4
0
    def update_guest_command(self):
        guest = self.database.find_guest(self.guest_id)
        if guest.found:

            if self.sub_type_txt.get() == Guest.SUB_TYPE_SUBSCRIPTION:
                start_date = FGR_DB.date_be2iso(self.sub_from_txt.get())
                if not start_date:
                    start_date = datetime.date.today()
                self.payg_left_txt.set(0)
                self.payg_max_txt.set(0)
            else:
                start_date = None
                try:
                    int(self.payg_left_txt.get())
                except:
                    self.payg_left_txt.set(10)
                try:
                    int(self.payg_max_txt.get())
                except:
                    self.payg_max_txt.set(10)

            rslt = self.database.update_guest(self.guest_id,
                                              self.badge_code_txt.get(),
                                              self.badge_number_txt.get(),
                                              self.first_name_txt.get(),
                                              self.last_name_txt.get(),
                                              self.email_txt.get(),
                                              self.phone_txt.get(),
                                              self.sub_type_txt.get(),
                                              start_date,
                                              self.payg_left_txt.get(),
                                              self.payg_max_txt.get())
            if rslt:
                self.show_message('Gast is aangepast', color='green')
            else:
                self.show_message(
                    'Kon de gegevens niet aanpassen, onbekende reden',
                    color='red')
        else:
            self.show_message('Gast niet gevonden, is de badge code juist?',
                              color='red')
        self.clear_inputfields_command()
        self.show_guest_list_command()
Esempio n. 5
0
    def add_guest_command(self):
        badge_code = self.badge_code_txt.get()
        guest = self.database.find_guest_from_badge(badge_code)
        if guest.found:
            self.show_message('Opgepast, een gast met die badge bestaat al',
                              color='red')
        else:
            if self.sub_type_txt.get() == '':
                self.sub_type_txt.set(Guest.SUB_TYPE_SUBSCRIPTION)

            if self.sub_type_txt.get() == Guest.SUB_TYPE_SUBSCRIPTION:
                start_date = FGR_DB.date_be2iso(self.sub_from_txt.get())
                if not start_date:
                    start_date = datetime.date.today()
                self.payg_left_txt.set(0)
                self.payg_max_txt.set(0)
            else:
                start_date = None
                try:
                    int(self.payg_left_txt.get())
                except:
                    self.payg_left_txt.set(10)
                try:
                    int(self.payg_max_txt.get())
                except:
                    self.payg_max_txt.set(10)

            rslt = self.database.add_guest(badge_code,
                                           self.badge_number_txt.get(),
                                           self.first_name_txt.get(),
                                           self.last_name_txt.get(),
                                           self.email_txt.get(),
                                           self.phone_txt.get(),
                                           self.sub_type_txt.get(), start_date,
                                           self.payg_left_txt.get(),
                                           self.payg_max_txt.get())
            if rslt:
                self.show_message('Gast is toegevoegd', color='green')
            else:
                self.show_message(
                    'Kon de gast niet toevoegen, onbekende reden', color='red')
        self.clear_inputfields_command()
        self.show_guest_list_command()
Esempio n. 6
0
class FGR:
    class Mode:
        guest = 'GEBRUIKER'
        admin = 'BEHEERDER'

    def __init__(self, root=None, log=None):

        self.log = log

        #initialize database
        self.database = FGR_DB(LOG_HANDLE)
        #{self.database.test_populate_database()

        #initialize register
        self.register = Register(root, self.database, LOG_HANDLE)

        #initialize Guests
        self.guests = Guests(root, self.database, LOG_HANDLE,
                             self.child_window_closes)

        #initialize Registrations
        self.registrations = Registrations(root, self.database, LOG_HANDLE,
                                           self.child_window_closes)

        #initialize Export
        self.export = Export(root, self.database, LOG_HANDLE,
                             self.child_window_closes)

        #initialize GUI
        self.root = root
        self.root_frm = tk.Frame(self.root)
        self.root_frm.grid()
        self.init_menu()
        self.init_widgets()

        #initialize mode
        self.mode = self.Mode.admin
        self.change_mode()

        #set the minimum size of the window
        root.update()
        root.minsize(root.winfo_width(), root.winfo_height())

    #change mode from guest to admin and vice verse
    def change_mode(self, force_mode=None):
        if force_mode:
            self.mode = force_mode
        elif self.mode == self.Mode.guest:
            self.mode = self.Mode.admin
        else:
            self.mode = self.Mode.guest

        if self.mode == self.Mode.admin:
            #change mode to admin
            self.main_mnu.entryconfig('Menu', state='normal')
            #self.mode_btn.configure(text='Gast')
            self.root_frm.winfo_toplevel().title(
                "Fablab Gebruikers Registratie {} :: ADMIN MODE".format(
                    VERSION))
        else:
            #change mode to guest
            self.main_mnu.entryconfig('Menu', state='disabled')
            #self.mode_btn.configure(text='Beheerder')
            self.root_frm.winfo_toplevel().title(
                "Fablab Gebruikers Registratie {}".format(VERSION))
        #set focus to the badge entry
        self.badge_ent.focus()

    def get_mode(self):
        return self.mode

    def badge_entered(self, event):
        #check if the admin code is used.  If so, switch to admin mode
        guest_found = False
        if self.badge_ent.get() == '2500':
            self.change_mode(force_mode=self.Mode.admin)
        else:
            is_valid_code, is_rfid_code, code = process_code(
                self.badge_ent.get())
            if is_valid_code and is_rfid_code:
                guest = self.database.find_guest_from_badge(code)
                guest_found = guest.found
            if guest_found:
                direction = self.register.new_registration(guest)
                till_string = ''
                if direction == 'IN':
                    if guest.subscription_type == Guest.SUB_TYPE_SUBSCRIPTION:
                        delta = FGR_DB.add_years(guest.subscribed_from,
                                                 1) - date.today()
                        if delta.days < 0:
                            messagebox.showwarning(
                                'Abonnement is verlopen',
                                'Opgelet, uw abonnement is verlopen.\nVraag info aan een medewerker'
                            )
                        else:
                            till_string = ', abonnement is nog {} dagen geldig'.format(
                                delta.days)
                    else:
                        guest.pay_as_you_go_left -= 1
                        if guest.pay_as_you_go_left < 0:
                            messagebox.showwarning(
                                'Beurtenkaart is verlopen',
                                'Opgelet, uw beurtenkaart is verlopen.\nVraag info aan een medewerker'
                            )
                        else:
                            till_string = ', er zijn nog {} geldige beurten'.format(
                                guest.pay_as_you_go_left)
                        rslt = self.database.update_guest(
                            guest.id, guest.badge_code, guest.badge_number,
                            guest.first_name, guest.last_name, guest.email,
                            guest.phone, guest.subscription_type,
                            guest.subscribed_from, guest.pay_as_you_go_left,
                            guest.pay_as_you_go_max)
                self.show_message(
                    "Hallo {}, u heb juist {} gebadged{}".format(
                        guest.first_name, direction, till_string), 4000,
                    'green')
            else:
                self.show_message(
                    "U bent nog niet geregistreerd, gelieve hulp te vragen",
                    5000, "red")
        self.badge_ent.delete(0, tk.END)

    def update_time(self):
        self.time_lbl.configure(text=time.strftime('%d/%m/%Y %H:%M:%S'))
        root.after(1000, self.update_time)

    def clear_database(self):
        answer = tk.Message

    def init_menu(self):
        #menu
        self.main_mnu = tk.Menu()
        self.menu_mnu = tk.Menu()
        self.main_mnu.add_cascade(label="Menu", menu=self.menu_mnu)
        self.menu_mnu.add_command(label="Gasten",
                                  command=self.guests.show_guests_window)
        self.menu_mnu.add_command(
            label="Registraties",
            command=self.registrations.show_registrations_window)
        self.menu_mnu.add_command(label="Export",
                                  command=self.export.export_database)
        self.menu_mnu.add_separator()
        self.menu_mnu.add_command(label="Gast mode", command=self.change_mode)
        #self.menu_mnu.add_command(label="Wis", command=self.clear_database)
        self.root.configure(menu=self.main_mnu)

    def child_window_closes(self):
        self.change_mode(self.Mode.guest)

    def init_widgets(self):
        self.fr1_frm = tk.Frame(self.root_frm)
        self.fr1_frm.grid(row=0, column=0, sticky='W')

        tk.Label(self.root_frm,
                 text="Welkom bij het fablab\nGelieve uw badge aan te bieden",
                 font=("Times New Roman", 60)).grid(row=1, columnspan=3)

        self.time_lbl = tk.Label(self.root_frm,
                                 text=time.strftime('%d/%m/%Y %H:%M:%S'),
                                 font=("Times New Roman", 60))
        self.time_lbl.grid(row=2, columnspan=3)
        self.update_time()

        tk.Label(self.root_frm, text="",
                 font=("Times New Roman", 30)).grid(columnspan=3, sticky='E')

        self.fr2_frm = tk.Frame(self.root_frm)
        self.fr2_frm.grid(columnspan=3, sticky='W')
        tk.Label(self.fr2_frm, text="BADGE",
                 font=("Times New Roman", 30)).pack(side='left')
        self.badge_ent = tk.Entry(self.fr2_frm,
                                  show='*',
                                  font=("Times New Roman", 30))
        self.badge_ent.pack(side='left')
        self.badge_ent.bind('<Return>', self.badge_entered)

        self.guest_welcome_lbl = tk.Label(self.root_frm,
                                          text="",
                                          font=("Times New Roman", 20))
        self.guest_welcome_lbl.grid(columnspan=3, sticky='W')

        tk.Label(self.root_frm, text="",
                 font=("Times New Roman", 30)).grid(columnspan=3, sticky='E')

    def show_message(self, msg, time=2000, color='black'):
        def clear_msg():
            self.guest_welcome_lbl.config(text='')

        #self.root_frm.focus()
        self.guest_welcome_lbl.config(text=msg, fg=color)
        self.root_frm.after(time, clear_msg)
Esempio n. 7
0
 def sub_from_changed(self, index, value, op):
     self.sub_till_txt.set(
         FGR_DB.add_years_string(self.sub_from_txt.get(), 1))