def click_ok(self): if self.user_input.get() == "" or self.pass_input.get() == "": tkinter.messagebox.showwarning("Login page", "The User Name or Password is empty.") return configuration.data['username'] = self.user_input.get() configuration.data['password'] = self.pass_input.get() self.pass_input.delete(0, len(configuration.data['password'])) if configuration.debug: if self.ip.get() != '': connection.ip = self.ip.get() if self.port.get() != '': connection.port = int(self.port.get()) json_str = json.dumps(configuration.data) json_str = str(defineCommands.LOGIN) + ';' + json_str result = connection.send_request_to_server(json_str) if result: get_data = str(defineCommands.GET_EMPLOYEE_LIST) + ';{}' received_data = connection.send_request_to_server(get_data) configuration.employees_dict = json.loads(received_data) count_workers(self) self.main_buttons_panel() else: tkinter.messagebox.showwarning( "Login page", "The User Name or Password is incorrect.")
def make_update(self, selection, window, id): if (self.add_status.get() == '' or self.add_address.get() == '' or self.add_last_name.get() == '' or self.add_name.get() == ''): tkinter.messagebox.showinfo("Update", "You should fill all fields") return try: address = validate_address.validate_address(self.add_address.get()) except: address = False if not address: tkinter.messagebox.showinfo( "Update", "Address is not valid, please enter valid address") return add_data = { 'firstname': self.add_name.get(), 'lastname': self.add_last_name.get(), 'address': self.add_address.get(), 'empID': id, 'status': self.add_status.get() } json_str = json.dumps(add_data) json_str = str(defineCommands.UPDATE) + ';' + json_str result = connection.send_request_to_server(json_str) if result: tkinter.messagebox.showinfo("Update", "Success") configuration.employees_dict[selection[0]] = add_data self.employees_page(0) window.destroy() else: tkinter.messagebox.showinfo("Update", "Error")
def check_algorithm_status(self): forget_frames(self) self.check_frame = tk.Frame(self) self.check_frame.pack(anchor='n', expand=False, side='top', fill='y', pady=150) self.check_frame.configure(bg=configuration.bgrd_color) configuration.active_frame.append(self.check_frame) request = str(defineCommands.CHECK_ALGORITHM_STATUS) + ';{}' result = connection.send_request_to_server(request) if result: tkinter.messagebox.showinfo("Check route status", "Creating in process.") else: tkinter.messagebox.showinfo("Check route status", "No process found") if result: self.kill_lbl = tk.Label(self.check_frame, text='You have running process', bg=configuration.lbl_bg_color, fg=configuration.lbl_color, font=configuration.lbl_font) self.kill_lbl.pack() self.kill_btn = tk.Button(self.check_frame, text='Stop Process of Creating Routes', default='active', font=configuration.main_btn_font, bg=configuration.btn_bg_color, command=lambda: kill_process(self)) self.kill_btn.pack()
def add_send_to_db(self): if (self.add_name.get() == "" or self.add_last_name.get() == "" or self.add_address.get() == "" or self.add_id.get() == ""): tkinter.messagebox.showinfo("Add Employee", "One or more entries is empty") return try: address = validate_address.validate_address(self.add_address.get()) except: address = False if not address: tkinter.messagebox.showinfo( "Update", "Address is not valid, please enter valid address") return if not self.add_id.get().isdigit(): tkinter.messagebox.showinfo("Update", "Id must be only digit") return add_data = { 'firstname': self.add_name.get(), 'lastname': self.add_last_name.get(), 'address': self.add_address.get(), 'empID': self.add_id.get(), 'status': 0 } json_str = json.dumps(add_data) json_str = str(defineCommands.ADD_EMPLOYEE) + ';' + json_str result = connection.send_request_to_server(json_str) if result: get_data = str(defineCommands.GET_EMPLOYEE_LIST) + ';{}' configuration.employees_dict = connection.send_request_to_server( get_data) if not configuration.employees_dict: tkinter.messagebox.showinfo( "Add Employee", 'Error when updating employee list.\nLogged out.') self.logout() configuration.employees_dict = json.loads(configuration.employees_dict) if result: tkinter.messagebox.showinfo( "Add Employee", "Employee {} {} successfully added.".format( add_data['firstname'], add_data['lastname'])) else: tkinter.messagebox.showinfo( "Add Employee", "Failed to add employee, try later or contact your help desc")
def update_shift_or_delete_worker(self, set_shift, employees): selection = self.listbox1.curselection() if len(selection) == 0: tkinter.messagebox.showinfo("Update", "No one is selected") return message = "" sub_message = [ 'unselected for tomorrow', 'selected for tomorrow', 'deleted' ] shift_data = [] for index, each in enumerate(selection): message = message + employees[each]['firstname'] + ' ' + employees[ each]['lastname'] + "\n" shift_data.append({}) shift_data[index]['empID'] = employees[each]['empID'] shift_data[index]['status'] = set_shift if set_shift != 2: json_str = json.dumps(shift_data) json_str = str(defineCommands.SET_WORKER) + ';' + json_str result = connection.send_request_to_server(json_str) else: msg = tkinter.messagebox.askyesno( "Delete", "Are you sure you want to delete this worker?") if msg: json_str = json.dumps(shift_data) json_str = str(defineCommands.REMOVE_EMPLOYEE) + ';' + json_str result = connection.send_request_to_server(json_str) else: return if result: tkinter.messagebox.showinfo("Update", message + sub_message[set_shift]) for i in selection: if set_shift == 2: configuration.employees_dict.pop(i) else: configuration.employees_dict[i]['status'] = set_shift else: tkinter.messagebox.showinfo( "Update", "We got some error...\nApparently aliens stole your data") self.employees_page(0)
def kill_process(self): kill_msg = tk.messagebox.askokcancel("Stop", "Are you sure to stop running?") if not kill_msg: return kill_data = str(defineCommands.KILL_PROCESS) + ';{}' result = connection.send_request_to_server(kill_data) if result: tkinter.messagebox.showinfo("Check route status", "Stoped") self.kill_lbl.forget() self.kill_btn.forget()
def show_route_page(self): forget_frames(self) self.route_frame = tk.Frame(self) self.route_frame.pack(anchor='n', expand=False, side='top', fill='y', pady=20) self.route_frame.configure(bg=configuration.bgrd_color) configuration.active_frame.append(self.route_frame) route_data = str(defineCommands.GET_ROUTES) + ";{}" received_data = connection.send_request_to_server(route_data) if not received_data: tkinter.messagebox.showwarning( "Get Routes", "There is no routes in the system.\nPlease, create routes first" ) return received_data = json.loads(received_data) index = 0 routes = [] for index, vehicle in enumerate(received_data): i = 1 tk.Button(self.route_frame, bg=configuration.btn_bg_color, text='Route {}'.format(index + 1), font=("Times New Roman", 10), command=lambda j=index: openmap.openmap(routes, j)).grid( row=0, column=index, sticky='w', pady=15) for employee in received_data[vehicle]: routes.append([]) routes[index].append( received_data[vehicle][employee]["address"]) my_str = received_data[vehicle][employee][ 'firstname'] + ' ' + received_data[vehicle][employee][ 'lastname'] tk.Label(self.route_frame, text=my_str, bg=configuration.lbl_bg_color, fg=configuration.lbl_color, font=("Times New Roman", 14)).grid(row=i, column=index, sticky='w') i += 1
def search_send_to_db(self, var): if self.search_input.get() == "": tkinter.messagebox.showinfo("Search", "Search field is empty") return if var == 0: tkinter.messagebox.showinfo("Search", "Please, check one parameter") return search_types = ['firstname', 'empID', 'address'] search_data = { 'searchby': search_types[var.get() - 1], search_types[var.get() - 1]: self.search_input.get() } json_str = json.dumps(search_data) json_str = str(defineCommands.SEARCH) + ';' + json_str result = connection.send_request_to_server(json_str) if result: self.employees_page(result) else: tkinter.messagebox.showinfo("Search", "Not Found")
def run(self, var): quality = ['low', 'medium', 'high'] if self.num_of_vehicles.get() == "" or self.vehicle_capacity.get() == "": tkinter.messagebox.showinfo( "Create Routes", "Please, enter number of vehicles and vehicle capacity.") return if not self.num_of_vehicles.get().isdigit( ) or not self.vehicle_capacity.get().isdigit(): tkinter.messagebox.showinfo("Create Routes", "Please, enter only digits.") return if configuration.employees_to_work == 0: tkinter.messagebox.showinfo( "Create Routes", "You need to choose at least one employee") return if (configuration.employees_to_work / int(self.num_of_vehicles.get())) > int( self.vehicle_capacity.get()): tkinter.messagebox.showinfo("Create Routes", "You need more vehicles!") return alg_data = { 'numofvehicles': int(self.num_of_vehicles.get()), 'routequality': quality[var.get()], 'vehiclecapacity': int(self.vehicle_capacity.get()) } json_str = json.dumps(alg_data) json_str = str(defineCommands.RUN_ALGORITHM) + ';' + json_str result = connection.send_request_to_server(json_str) if result: tkinter.messagebox.showinfo("Create Routes", "Creating in process.") else: tkinter.messagebox.showinfo("Create Routes", "Creating fail.")
def employees_page(self, employee_list): forget_frames(self) configuration.select_text = True self.show_employee_frame = tk.Frame(self) self.show_employee_frame.pack(anchor='n', expand=False, side='top', fill='y', pady=130) configuration.active_frame.append(self.show_employee_frame) self.show_employee_frame.configure(bg=configuration.bgrd_color) self.scrollbar_V = tk.Scrollbar(self.show_employee_frame, orient='vertical') self.listbox1 = tk.Listbox(self.show_employee_frame, yscrollcommand=self.scrollbar_V.set, height=15, width=40, selectmode='multiple') if employee_list == 0: if configuration.employees_dict: received_data = configuration.employees_dict else: get_data = str(defineCommands.GET_EMPLOYEE_LIST) + ';{}' received_data = connection.send_request_to_server(get_data) configuration.employees_dict = json.loads(received_data) received_data = json.loads(received_data) else: received_data = employee_list received_data = json.loads(received_data) for employee in received_data: self.listbox1.insert( 'end', employee['firstname'] + ' ' + employee['lastname'] + ' - Status ' + str(employee['status'])) count_workers(self) self.scrollbar_V.grid(row=0, rowspan=4, column=2, sticky='sn', pady=50) self.listbox1.grid(row=0, column=1, rowspan=4, sticky='nesw', pady=50) tk.Label(self.show_employee_frame, text='You have {} employees tomorrow'.format( configuration.employees_to_work), bg=configuration.lbl_bg_color, fg=configuration.lbl_color, font=configuration.lbl_font).grid(row=8, column=1, sticky='nesw') self.scrollbar_V.config(command=self.listbox1.yview) tk.Button(self.show_employee_frame, bg=configuration.btn_bg_color, text='Set Shift', font=configuration.employee_btn_font, command=lambda: update_shift_or_delete_worker( self, 1, received_data)).grid(row=0, column=0, sticky='w', ipady=10, ipadx=20, pady=20, padx=30) tk.Button(self.show_employee_frame, bg=configuration.btn_bg_color, text='Unset Shift', font=configuration.employee_btn_font, command=lambda: update_shift_or_delete_worker( self, 0, received_data)).grid(row=1, column=0, sticky='w', ipady=10, ipadx=12, pady=20, padx=30) tk.Button(self.show_employee_frame, bg=configuration.btn_bg_color, text='Remove', font=configuration.employee_btn_font, command=lambda: update_shift_or_delete_worker( self, 2, received_data)).grid(row=2, column=0, sticky='w', pady=20, ipady=10, ipadx=22, padx=30) tk.Button(self.show_employee_frame, bg=configuration.btn_bg_color, text='Update', font=configuration.employee_btn_font, command=lambda: self.update_worker(received_data)).grid( row=3, column=0, sticky='w', ipady=10, ipadx=25, pady=20, padx=30) tk.Button(self.show_employee_frame, bg=configuration.btn_bg_color, text='Search Employee', font=configuration.employee_btn_font, command=lambda: self.search_employee()).grid(row=0, column=4, ipady=10, padx=30) tk.Button(self.show_employee_frame, bg=configuration.btn_bg_color, text='Add Employee', font=configuration.employee_btn_font, command=lambda: self.add_employee()).grid(row=1, column=4, ipady=10, ipadx=10, padx=30) select_btn = tk.Button(self.show_employee_frame, bg=configuration.btn_bg_color, text='Select All', font=configuration.employee_btn_font, command=lambda: select_all(self, select_btn)) select_btn.grid(row=2, column=4, ipady=10, ipadx=30, padx=30)