def create_order(self, itemId, shopId, customerId, date): try: assert Additional.findExistingId( self.connection, "Item", itemId), '\033[91m item id isn\'t exist \033[0m' assert Additional.findExistingId( self.connection, "Shop", shopId), '\033[91m shop id isn\'t exist \033[0m' assert Additional.findExistingId(self.connection, "Customer", customerId), \ '\033[91m customer id isn\'t exist \033[0m' baseData.insert_one_order(self.connection, itemId, shopId, customerId, date) return True except Exception as err: print(err) return False
def update_shop(self, shopId, name, street): try: assert Additional.findExistingId(self.connection, self.tableName, shopId), \ '\033[91m id isn\'t exist \033[0m ' baseData.update_one_shop(self.connection, shopId, name, street) return True except Exception as err: print(err) return False
def delete_order(self, orderId): try: assert Additional.findExistingId(self.connection, self.tableName, orderId), \ '\033[91m id isn\'t exist \033[0m' baseData.delete_one(self.connection, orderId, self.tableName) return True except Exception as err: print(err) return False
def create_many_orders(self, count): try: itemId = Additional.findExistRow(self.connection, "Item") shopId = Additional.findExistRow(self.connection, "Shop") customerId = Additional.findExistRow(self.connection, "Customer") assert Additional.findExistingId( self.connection, "Item", itemId), '\033[91m item id isn\'t exist \033[0m' assert Additional.findExistingId( self.connection, "Shop", shopId), '\033[91m shop id isn\'t exist \033[0m' assert Additional.findExistingId(self.connection, "Customer", customerId), \ '\033[91m customer id isn\'t exist \033[0m' baseData.insert_many_random_orders(self.connection, count, itemId, customerId, shopId) return True except Exception as err: print(err) return False
def delete_shop(self, shopId): try: assert not Additional.findExistingIdOrderTable(self.connection, self.tableName, shopId), \ '\033[91m shop id bind with order \033[0m' assert Additional.findExistingId(self.connection, self.tableName, shopId), \ '\033[91m id isn\'t exist \033[0m' baseData.delete_one(self.connection, shopId, self.tableName) return True except Exception as err: print(err) return False
def delete_customer(self, customerId): try: assert not Additional.findExistingIdOrderTable(self.connection, self.tableName, customerId),\ '\033[91m You don\'t delete customer, because this customer bind with order \033[0m' assert Additional.findExistingId(self.connection, self.tableName, customerId), \ '\033[91m id isn\'t exist \033[0m' baseData.delete_one(self.connection, customerId, self.tableName) return True except Exception as err: print(err) return False
def update_customer(self, customerId, name, phone, sex): try: assert (sex == "male" or sex == "female"), \ '\033[91m sex isn\'t exist. You must input male or female \033[0m' assert Additional.findExistingId(self.connection, self.tableName, customerId), \ '\033[91m id isn\'t exist \033[0m ' baseData.update_one_customer(self.connection, customerId, name, phone, sex) return True except Exception as err: print(err) return False
def update_item(self, itemId, name, price, quantity, color, material, description): try: assert price > 0, '\033[91m price must be more zero \033[0m' assert quantity > 0, '\033[91m quantity must be > 0 \033[0m' assert Additional.findExistingId(self.connection, self.tableName, itemId), \ '\033[91m id isn\'t exist \033[0m' baseData.update_one_item(self.connection, itemId, name, price, quantity, color, material, description) return True except Exception as err: print(err) return False