Beispiel #1
0
 def find(self, id):
     c = self.conn.cursor()
     c.execute(
         """
             SELECT * FROM Employees WHERE id = ?
         """, [id])
     return Employee(*c.fetchone())
Beispiel #2
0
def main(args):
    # imports
    import os
    # delete DataBase if exists
    if os.path.exists('moncafe.db'):
        os.remove('moncafe.db')
    from Repository import repo
    repo.create_tables()
    from DTO import Employee, Coffee_stand, Product, Supplier

    # with open('config.txt') as inputFile:
    #     for line in inputFile:
    #         print(line)
    inputfilename = args[1]
    with open(inputfilename) as inputfile:
        for line in inputfile:
            words = line.split(",")
            if words[0] == 'C':
                repo.coffee_stands.insert(
                    Coffee_stand(words[1].strip(' '), words[2].strip(' '),
                                 words[3].strip(' ')))
            if words[0] == 'S':
                repo.suppliers.insert(
                    Supplier(words[1].strip(' '), words[2].strip(' '),
                             words[3][:-1].strip(' ')))
            if words[0] == 'E':
                repo.employees.insert(
                    Employee(words[1].strip(' '), words[2].strip(' '),
                             words[3].strip(' '), words[4].strip(' ')))
            if words[0] == 'P':
                repo.products.insert(
                    Product(words[1].strip(' '), words[2].strip(' '),
                            words[3].strip(' '), 0))
    def find_all(self):
        c = self._conn.cursor()
        all = c.execute("""
            SELECT id, name, salary, coffee_stand FROM Employees ORDER BY Employees.id
        """).fetchall()

        return [Employee(*row) for row in all]
Beispiel #4
0
def main(args):
        repo.create_tables()
        inputfilename = args[1]
        with open(inputfilename) as inputfile:

            for line in inputfile:
                line = line.strip('\n')
                args = line.split(', ')
                orginal2= args[2]
                orginal3 = args[3]
                args[1] = str(args[1]).replace(" ", "")
                args[2] = str(args[2]).replace(" ", "")
                args[3] = str(args[3]).replace(" ", "")
                if args[0] == "C":
                    currCoffee_stand = Coffee_stand(args[1], "'{}'".format(args[2]), args[3])
                    repo.coffee_stands.insert(currCoffee_stand)
                if args[0] == "S":
                    args[3] = orginal3
                    currSupplier = Supplier(args[1],"'{}'".format(args[2]),"'{}'".format(args[3]))
                    repo.suppliers.insert(currSupplier)
                if args[0] == "E":
                    args[4] = str(args[4]).replace(" ", "")
                    currEmployee = Employee(args[1],args[2],args[3],args[4])
                    repo.employees.insert(currEmployee)
                if args[0] == "P":
                    args[2]=orginal2
                    currProduct = Product(args[1], "'{}'".format(args[2]), args[3], 0)
                    repo.products.insert(currProduct)
Beispiel #5
0
    def find(self, employee_id):
        c = self._conn.cursor()
        c.execute(
            """
            SELECT id, name FROM Employees WHERE id = ?
        """, [employee_id])

        return Employee(*c.fetchone())
Beispiel #6
0
def load_configuration():
    config = sys.argv[1]
    # file_action = open(sys.argv[2])
    file = open(config, 'r')
    content = file.read()
    lines = content.split("\n")

    for line in lines:
        p = line.split(", ")
        if p[0] == "E":
            repo.employee.insert(Employee(p[1], p[2], p[3], p[4]))
        if p[0] == "S":
            repo.supplier.insert(Supplier(p[1], p[2], p[3]))
        if p[0] == "P":
            repo.product.insert(Product(p[1], p[2], p[3], 0))
        if p[0] == "C":
            repo.coffee_stand.insert(Coffee_stand(p[1], p[2], p[3]))
Beispiel #7
0
def main():
    repo.create_table()

    with open(sys.argv[0], 'r') as config_file:
        for line in config_file:
            line = line.strip('\n')
            line = line.replace(' ', '').split(',')
            if line[0] == 'E':
                tmp = Employee(int(line[1]), line[2], float(line[3]),
                               int(line[4]))
                repo.Employees.insert(tmp)
            if line[0] == 'S':
                tmp = Supplier(int(line[1]), line[2], line[3])
                repo.Suppliers.insert(tmp)
            if line[0] == 'P':
                tmp = Product(int(line[1]), line[2], float(line[3]))
                repo.Products.insert(tmp)
            if line[0] == 'C':
                tmp = Coffee_stand(line[1], line[2], line[3])
                repo.Coffee_stands.insert(tmp)
Beispiel #8
0
def insert_to_tables():
    with open(sys.argv[1], "r") as file:
        for line in file:
            if line[-1] == '\n':
                line = line[:-1]
            lineList = line.split(', ')
            if lineList[0] == "C":
                coffee_stand = Coffee_stand(lineList[1], lineList[2],
                                            lineList[3])
                repo.Coffee_stands.insert(coffee_stand)
            elif lineList[0] == 'S':
                supplier = Supplier(lineList[1], lineList[2], lineList[3])
                repo.Suppliers.insert(supplier)
            elif lineList[0] == 'E':
                employee = Employee(lineList[1], lineList[2], lineList[3],
                                    lineList[4])
                repo.Employees.insert(employee)
            elif lineList[0] == 'P':
                product = Product(lineList[1], lineList[2], lineList[3], 0)
                repo.Products.insert(product)
Beispiel #9
0
def main(args):

    repo.create_tables()

    inputfilename = args[1]
    with open(inputfilename) as inputfile:
        for line in inputfile:
            line.split(", ")
            if line[0]=="C":
                #print(line[:-1].split(", ")[1:])
                repo.Coffee_stands.insert(Coffee_stand(*line.split(", ")[1:]))

            if line[0]=="E":
                #print(line[:-1].split(", ")[1:])
                repo.Employees.insert(Employee(*line.split(", ")[1:]))

            if line[0]=="S":
                #print(line[:-1].split(", ")[1:])
                repo.Suppliers.insert(Supplier(*line.split(", ")[1:]))

            if line[0]=="P":
                #print(line[:-1].split(", ")[1:].__add__(["0"]))
                repo.Products.insert(Product(*line.split(", ")[1:].__add__(["0"])))
Beispiel #10
0
 def findAllByName(self):
     c = self._conn.cursor()
     all = c.execute("SELECT * FROM Employees order by name ASC")
     return [Employee(*row) for row in all]
Beispiel #11
0
 def find_all_sorted_by_name(self):
     c = self.conn.cursor()
     all = c.execute("""
                SELECT * FROM Employees ORDER BY name ASC
            """).fetchall()
     return [Employee(*row) for row in all]