def add(self): if self.fld_regNo.get() == '' or self.fld_colour.get( ) == '' or self.fld_numOfDoors.get() == '' or self.combo_modelName.get( ) == '': mb.showwarning('Message from system', 'Some field values are empty, check it.') else: # Covert the model name to model Id modelId = OfficeStaff().covert_modelId(self.combo_modelName.get()) # Read the value from each input from user that will add to car class car = Car(self.fld_regNo.get(), self.fld_colour.get(), self.fld_numOfDoors.get(), modelId) # Call the add car function from office staff class and pass carModel object # The return value store in output variable output = OfficeStaff().addCar(car) if output: mb.showinfo('Message from system', 'Successfully add car on database') self.fld_regNo.delete(0, 'end') self.fld_colour.delete(0, 'end') self.fld_numOfDoors.delete(0, 'end') self.combo_modelName.delete(0, 'end') else: mb.showwarning( 'Message from system', 'The insertion is failed registration number already exist. try again' )
def carData(self, regNo): """The selected car car data fetches from database using this method. """ try: connect = self.get_connection() cursor = connect.cursor() logging.info('Connect the database successfully for fetch the car data') query = "SELECT car.reg_no, colour, num_of_doors, model_name, manufacture_name from car, model, manufacture WHERE car.model_id = model.model_id and model.manufacture_id = manufacture.manufacture_id and reg_no = ?" cursor.execute(query, (regNo,)) record = cursor.fetchall() cursor.close() logging.info("Fetch the car data successfully") # create car, model, manufacture object to encapsulate fetch the values from database car = Car(record[0][0], record[0][1], record[0][2]) model = CarModel(modelName=record[0][3]) manufacture = Manufacture(manufactureName=record[0][4]) # create a list and add those object into this list and returns to caller. detailsList = [car, model, manufacture] return detailsList except (Exception, sqlite3.Error) as error: logging.error('%s while get car data', error) finally: self.close_connection(connect)
def fetchAvailableCarRegNO(self): connect = None try: connect = self.get_connection() cursor = connect.cursor() logging.info( 'Connect the database successfully for fetch available car') # Query fetch the reg no that are not present in sales table. query = "select reg_no from car where reg_no not in (select reg_no from sale)" cursor.execute(query) record = cursor.fetchall() cursor.close() logging.info('Successfully fetched the data from car table') carList = [] for row in record: regNo = row[0] car = Car(regNo) carList.append(car) return carList except (Exception, sqlite3.Error) as error: logging.error('%s while getting data', error) finally: self.close_connection(connect)
def fetchCarDetails(self): connect = self.get_connection() cursor = connect.cursor() logging.info('Connect the database successfully for insert value') try: # Query for fetch the car information from car table query = 'SELECT * FROM car' cursor.execute(query) records = cursor.fetchall() cursor.close() logging.info('Successfully fetched the data from car table') car_list = [] for row in records: reg_no = row[0] colour = row[1] num_of_doors = row[2] model_id = row[3] car = Car(reg_no, colour, num_of_doors, model_id) car_list.append(car) return car_list except (Exception, sqlite3.Error) as error: logging.error('%s Error while getting data', error) finally: self.close_connection(connect)
def saleCar(self): """When press the sale button, the method will be called. this open a new window to confirm sell- the selected car. this automatically add the selected car and final amount on newly open window.""" if self.combo_selectCar.get() == '': mb.showwarning('Message from system', 'Please select one of car above') else: car = Car(self.combo_selectCar.get()) finalPrice = Seller().selectCarPrice(car) SaleView(self.combo_selectCar.get(), finalPrice)
def delete(self): if self.combo_selectCar.get() == '': mb.showwarning('Message from system', 'The car not selected') else: car = Car(regNo=self.combo_selectCar.get()) output = OfficeStaff().deleteCar(car) if output: mb.showinfo('Message from system', 'Successfully deleted car') self.combo_selectCar.delete(0, 'end') else: mb.showwarning('Message from system', 'The operation failed')
def carDetails(self): """The user want to get the details of the selected car. he can press the Selected Car upgrades- button when the function will be called. it calls the function in seller to update the selected car upgrade information.""" if self.combo_selectCar.get() == '': mb.showwarning('Message from system', 'Please select one of car above') else: car = Car() car.setRegNo(self.combo_selectCar.get()) carRecord = Seller().selectedCarDetails(car) tempWindow = Tk() tempWindow.title('Selected car details') for i in range(len(carRecord)): tempEntry = Entry(tempWindow, width=20, fg='blue', font=('Arial', 16, 'bold')) tempEntry.grid(row=i, column=0) tempEntry.insert(END, carRecord[i]) tempWindow.mainloop()
def search(self): """Call the viewSoldCarDetails method from controller class and get all sold car details finally add those values into particular entries. the for loops use for enter the upgrades- values one by one into entries.""" if self.combo_selectCar.get() == '': mb.showwarning('Message from system', 'Please select one car above') else: car = Car(regNo=self.combo_selectCar.get()) soldCarDetails = OfficeStaff().viewSoldCarDetails(car) self.fld_showFinalPrice.insert(END, soldCarDetails[1]) # for i in range(1, len(soldCarDetails[0])): # self.fld_showUpgrades.insert(END, soldCarDetails[0][i]) # self.fld_showUpgrades.insert(END, ',') for i in soldCarDetails[0]: self.fld_showUpgrades.insert(END, i) self.fld_showUpgrades.insert(END, ',')