def __init__(self): self.__Orders_Data = GetData(ORDER_FILE).readData() self.__Orders = [] self.__DataSaver = SaveData(ORDER_FILE) for order in self.__Orders_Data: newOrder = Order(order[0], order[1], order[2], order[3], order[4], order[5]) #TODO: Add constants self.__Orders.append(newOrder)
def __init__(self): self.__Orders_Data = GetData(ORDER_FILE).readData() self.__Orders = [] self.__DataSaver = SaveData(ORDER_FILE) for order in self.__Orders_Data: newOrder = Order(order[ORDER_ID], order[CAR_REG], order[CUSTOMER_SSN], order[DATE_FROM], order[DATE_TO], order[PRICE]) self.__Orders.append(newOrder)
def __init__(self): self.__Vehicles_Data = GetData(VEHICLE_FILE).readData() self.__Vehicles = [] self.__AvailableVehicles = [] self.__VehiclesInRent = [] self.__DataSaver = SaveData(VEHICLE_FILE) self.loadVehicles() self.loadRentedVehicles() self.loadAvailableVehicles()
class CustomerManager(object): def __init__(self): self.__customer_data = GetData(CUSTOMERS_FILE).readData() self.__customers = [] self.__data_saver = SaveData(CUSTOMERS_FILE) self.loadCustomers() def save(self): self.updateCustomerData() self.__data_saver.writeCustomersData(self.__customer_data) def loadCustomers(self): for line in self.__customer_data: name = line[NAME] ssn = int(line[SSN]) address = line[ADDRESS] phone_number = int(line[PHONENUMBER]) driverslicense_number = int(line[DRIVERSLICENSENUMBER]) customer = Customer(name, ssn, address, phone_number, driverslicense_number) self.__customers.append(customer) def registerNewCustomer(self, name, ssn, address, phone_number, driverslicense_number): new_customer = Customer(name, ssn, address, phone_number, driverslicense_number) self.__customers.append(new_customer) self.save() return new_customer def removeCustomer(self, customer): self.__customers.remove(customer) self.save() def updateCustomerData(self): self.__customer_data.clear() for cust in self.__customers: self.__customer_data.append([ cust.getName(), cust.getSSN(), cust.getAddress(), cust.getPhoneNumber(), cust.getDriversLicenseNumber() ]) def findCustomer(self, search_key): #hægt að leita að name, ssn for cust in self.__customers: if str(cust.getName()) == search_key: return cust if str(cust.getSSN()) == search_key: return cust return None #ef engin kúnni finnst
def loadVehicles(self): self.__Vehicles_Data = GetData(VEHICLE_FILE).readData() self.__Vehicles.clear() for line in self.__Vehicles_Data: regnum = line[REGISTRATION_NUMBER] if line[RENTED] == 'True': rented = True else: rented = False model_year = int(line[MODEL_YEAR]) brand = line[BRAND] price = int(line[PRICE]) car_type = int(line[CAR_TYPE]) car = Vehicle(regnum, model_year, rented, brand, price, car_type) self.__Vehicles.append(car)
class Login: def __init__(self): self.__user_data = GetData('users.csv') self.__check_login_info = IsInfoValid() self.__raw_data = self.__user_data.readData() # Sendi usernameið og password í servicehelper til að athuga hvort það sé til def validUser(self, username, password): valid_user = self.__check_login_info.check_acc(self.__raw_data, username) valid_password = self.__check_login_info.check_pw( self.__raw_data, password) if valid_user: if valid_password: return True def isAdmin(self, username): is_admin = self.__check_login_info.check_admin(self.__raw_data, username) if is_admin: return True else: return False def getFullname(self, username): fullname = self.__check_login_info.get_fullname( self.__raw_data, username) return fullname
class OrderManager(object): def __init__(self): self.__Orders_Data = GetData(ORDER_FILE).readData() self.__Orders = [] self.__DataSaver = SaveData(ORDER_FILE) for order in self.__Orders_Data: newOrder = Order(order[0], order[1], order[2], order[3], order[4], order[5]) #TODO: Add constants self.__Orders.append(newOrder) def createOrder(self, order_id, car_reg, customer_SSN, date_from, date_to, price): newOrder = Order(order_id, car_reg, customer_SSN, date_from, date_to, price) self.__Orders.append(newOrder) self.__Orders_Data.append( [order_id, car_reg, customer_SSN, date_from, date_to, price]) self.Save() return newOrder def removeOrder(self, order_id): order_id -= 1 # Ekki nice en works self.__Orders.pop(order_id) self.__Orders_Data.pop(order_id) def getOrders(self, by_dates=False): if by_dates: return self.__Orders #TODO: Látta þetta virka else: return self.__Orders def findOrder(self, search_key): # Hægt að search ID, Registration Number og SSN for order in self.__Orders: if str(order.getOrderid()) == search_key: return order if str(order.getCarRegistration()) == search_key: return order if str(order.getCustomerSSN()) == search_key: return order return None #Ef ekkert order er found þá returnar hann none def Save(self): self.__DataSaver.WritOrdersData(self.__Orders_Data)
def __init__(self): self.__user_data = GetData('users.csv') self.__check_login_info = IsInfoValid() self.__raw_data = self.__user_data.readData()
def __init__(self): self.__customer_data = GetData(CUSTOMERS_FILE).readData() self.__customers = [] self.__data_saver = SaveData(CUSTOMERS_FILE) self.loadCustomers()
class OrderManager(object): def __init__(self): self.__Orders_Data = GetData(ORDER_FILE).readData() self.__Orders = [] self.__DataSaver = SaveData(ORDER_FILE) for order in self.__Orders_Data: newOrder = Order(order[ORDER_ID], order[CAR_REG], order[CUSTOMER_SSN], order[DATE_FROM], order[DATE_TO], order[PRICE]) self.__Orders.append(newOrder) def createOrder(self, order_id, car_reg, customer_SSN, date_from, date_to, price): newOrder = Order(order_id, car_reg, customer_SSN, date_from, date_to, price) self.__Orders.append(newOrder) self.save() return newOrder def removeOrder(self, order): self.__Orders.remove(order) self.save() def updateOrderData(self): self.__Orders_Data.clear() for order in self.__Orders: self.__Orders_Data.append([ order.getOrderid(), order.getCarRegistration(), order.getCustomerSSN(), datetime.strftime(order.getDateFrom(), "%d/%m/%y %H:%M"), datetime.strftime(order.getDateTo(), "%d/%m/%y %H:%M"), order.getPrice() ]) def getUpCommingOrders(self): sorted_orders = self.getOrders(by_dates=True) up_comming = list() for order in sorted_orders: if order.getDateFrom() > datetime.now(): up_comming.append(order) return up_comming def getOrders(self, by_dates=False): if by_dates: sorted_orders = sorted(self.__Orders, key=lambda Order: Order.getDateFrom()) return sorted_orders else: return self.__Orders def getOrdersByVehicle(self, reg_number): vehicle_history = list() for order in self.__Orders: if order.getCarRegistration().lower() == reg_number.lower(): vehicle_history.append(order) return vehicle_history def getOrdersByCustomer(self, SSN): customer_history = list() for order in self.__Orders: if int(order.getCustomerSSN()) == int(SSN): customer_history.append(order) return customer_history def findOrder(self, search_key): # Hægt að search ID, Registration Number og SSN for order in self.__Orders: if str(order.getOrderid()) == search_key: return order if str(order.getCarRegistration()) == search_key: return order if str(order.getCustomerSSN()) == search_key: return order return None #Ef ekkert order er found þá returnar hann none def save(self): self.updateOrderData() self.__DataSaver.writeOrdersData(self.__Orders_Data)
class VehicleManager(object): def __init__(self): self.__Vehicles_Data = GetData(VEHICLE_FILE).readData() self.__Vehicles = [] self.__AvailableVehicles = [] self.__VehiclesInRent = [] self.__DataSaver = SaveData(VEHICLE_FILE) self.loadVehicles() self.loadRentedVehicles() self.loadAvailableVehicles() def loadVehicles(self): self.__Vehicles_Data = GetData(VEHICLE_FILE).readData() self.__Vehicles.clear() for line in self.__Vehicles_Data: regnum = line[REGISTRATION_NUMBER] if line[RENTED] == 'True': rented = True else: rented = False model_year = int(line[MODEL_YEAR]) brand = line[BRAND] price = int(line[PRICE]) car_type = int(line[CAR_TYPE]) car = Vehicle(regnum, model_year, rented, brand, price, car_type) self.__Vehicles.append(car) def loadAvailableVehicles(self): self.__AvailableVehicles.clear() for vehicle in self.__Vehicles: if not vehicle.isRented(): self.__AvailableVehicles.append(vehicle) def loadRentedVehicles(self): self.__VehiclesInRent.clear() for vehicle in self.__Vehicles: if vehicle.isRented(): self.__VehiclesInRent.append(vehicle) def registerNewVehicle(self, registration_number, rented, model_year, brand, price, car_type): newVehicle = Vehicle(registration_number, model_year, rented, brand, price, car_type) self.__Vehicles.append(newVehicle) self.__Vehicles_Data.append( [registration_number, rented, model_year, brand, price, car_type]) self.save() #Save-a í hvert sinn sem við bætum við nýjum bíl return newVehicle #Looks for regnum, if found deregisters car and returns TRUE #Else returns False def deregisterVehicle(self, registration_number): vehid = self.findVehicleID(registration_number) if vehid: self.__Vehicles.pop(vehid) self.__Vehicles_Data.pop(vehid) self.save() return True else: return False def changeVehicleStatus(self, registration_number): try: veh = self.findVehicle(registration_number) if veh.isRented(): veh.setRented(False) else: veh.setRented(True) self.loadAvailableVehicles() self.loadRentedVehicles() self.save() return True except: print("Not a Valid Registration number") def findVehicle(self, registration_number): for vehicle in self.__Vehicles: if vehicle.getRegistrationNum().lower( ) == registration_number.lower(): return vehicle return None def findVehicleID(self, registration_number): for index, vehicle in enumerate(self.__Vehicles): if vehicle.getRegistrationNum() == registration_number: return index return None def getVehicles(self): return self.__Vehicles def getAvailable(self): return self.__AvailableVehicles def getRentedVehicles(self): return self.__VehiclesInRent def updateVehicleData(self): self.__Vehicles_Data.clear() for vehicle in self.__Vehicles: self.__Vehicles_Data.append([ vehicle.getRegistrationNum(), vehicle.isRented(), vehicle.getModelYear(), vehicle.getBrand(), vehicle.getPrice(), vehicle.getType() ]) def save(self): self.updateVehicleData() self.__DataSaver.writeVehicleData(self.__Vehicles_Data)