예제 #1
0
    def create_tables(self, path):
        self._conn.executescript("""
                CREATE TABLE Employees(
                    id INTEGER PRIMARY KEY, 
                    name TEXT NOT NULL,
                    salary REAL NOT NULL,
                    coffee_stand INTEGER REFERENCES Coffee_stands(id)        
                 );

                 CREATE TABLE Suppliers(
                    id INTEGER PRIMARY KEY,
                    name TEXT NOT NULL,
                    contact_information TEXT
                 );

                 CREATE TABLE Products(
                    id INTEGER PRIMARY KEY,
                    description TEXT NOT NULL,
                    price REAL NOT NULL,
                    quantity INTEGER NOT NULL
                 );

                 CREATE TABLE Coffee_stands(
                    id INTEGER PRIMARY KEY,
                    location TEXT NOT NULL,
                    number_of_employees INTEGER
                 );

                 CREATE TABLE Activities(
                    product_id INTEGER REFERENCES Products(id),
                    quantity INTEGER NOT NULL,
                    activator_id INTEGER NOT NULL,
                    date DATE NOT NULL
                 );
            """)

        text = open(path).readlines()
        for line in text:
            line = line.split(', ')
            for element in range(0, line.__len__()):
                line[element] = str(line[element]).replace("\n", '')

            if (line[0] == "C"):
                coffee_stand = DTO.Coffee_stand(int(line[1]), line[2],
                                                int(line[3]))
                self.coffee_stands.insert(coffee_stand)
            elif (line[0] == "S"):
                supplier = DTO.Supplier(int(line[1]), line[2], line[3])
                self.suppliers.insert(supplier)
            elif (line[0] == "E"):
                employee = DTO.Employee(int(line[1]), line[2], float(line[3]),
                                        int(line[4]))
                self.employees.insert(employee)
            elif (line[0] == "P"):
                product = DTO.Product(int(line[1]), line[2], float(line[3]), 0)
                self.products.insert(product)
예제 #2
0
def enter(entry, repo):
    if entry[0] == 'C':
        repo.coffeeStands.insert(DTO.CoffeeStand(entry[1], entry[2], entry[3]))
    elif entry[0] == 'E':
        repo.employees.insert(
            DTO.Employee(entry[1], entry[2], entry[3], entry[4]))
    elif entry[0] == 'P':
        repo.products.insert(DTO.Product(entry[1], entry[2], entry[3]))
    elif entry[0] == 'S':
        repo.suppliers.insert(DTO.Supplier(entry[1], entry[2], entry[3]))