コード例 #1
0
ファイル: Repository.py プロジェクト: bardabun/Assignment4
 def receive_shipment(self, name, amount, date):
     cursor = self._dbcon.cursor()
     # finding the unique id
     id = DAO.Vaccines.counter
     supp_id = DAO.Suppliers.find(self.suppliers, name)
     new_row_vaccine = DTO.Vaccines(id, date, supp_id, amount)
     DAO.Vaccines.insert(self.vaccines, new_row_vaccine)
     cursor.execute("""SELECT logistic FROM suppliers WHERE name=(?)""",
                    [name])
     sup_logistic_id = cursor.fetchone()[0]
     self.update_count_suppliers(sup_logistic_id, int(amount))
コード例 #2
0
ファイル: Repository.py プロジェクト: bardabun/Assignment4
    def read_insert(self, config_file):
        with open(config_file) as f:
            f = f.readlines()  # f stands for file -- make my file a list
        config_first_line = f[0]
        config_first_line = config_first_line[:-1]
        split_config_first_line = config_first_line.split(",")

        list_entries_vaccines = []
        list_entries_suppliers = []
        list_entries_clinics = []
        list_entries_logistics = []
        lines_to_read_vac = int(split_config_first_line[0])
        lines_to_read_sup = int(split_config_first_line[1])
        lines_to_read_clin = int(split_config_first_line[2])
        lines_to_read_log = int(split_config_first_line[3])
        range1 = range(1, 1 + lines_to_read_vac)
        range2 = range(1 + lines_to_read_vac,
                       lines_to_read_sup + 1 + lines_to_read_vac)
        range3 = range(
            lines_to_read_sup + 1 + lines_to_read_vac,
            lines_to_read_sup + 1 + lines_to_read_vac + lines_to_read_clin)
        range4 = range(
            lines_to_read_sup + 1 + lines_to_read_vac + lines_to_read_clin,
            lines_to_read_sup + 1 + lines_to_read_vac + lines_to_read_clin +
            lines_to_read_log)

        for i in range1:
            list_entries_vaccines.append(f[i])
        for i in range2:
            list_entries_suppliers.append(f[i])
        for i in range3:
            list_entries_clinics.append(f[i])
        for i in range4:
            list_entries_logistics.append(f[i])

        for i in list_entries_vaccines:
            i = i[:-1]
            i = i.split(',')
            vaccine = DTO.Vaccines(*i)
            insert_vac = DAO.Vaccines(self._dbcon)
            insert_vac.insert(vaccine)

        for i in list_entries_suppliers:
            i = i[:-1]
            i = i.split(',')
            supplier = DTO.Suppliers(*i)
            insert_sup = DAO.Suppliers(self._dbcon)
            insert_sup.insert(supplier)

        for i in list_entries_clinics:
            i = i[:-1]
            i = i.split(',')
            clinic = DTO.Clinics(*i)
            insert_cli = DAO.Clinics(self._dbcon)
            insert_cli.insert(clinic)

        for i in list_entries_logistics:
            if i[-1] == '\n':
                i = i[:-1]
            i = i.split(',')
            logistic = DTO.Logistic(*i)
            insert_log = DAO.Logistics(self._dbcon)
            insert_log.insert(logistic)
コード例 #3
0
 def find(self, vaccine_id):
     c = self._dbcon.cursor()
     c.execute(
         """
                 SELECT * FROM vaccines WHERE id = ?""", [vaccine_id])
     return DTO.Vaccines(*c.fetchone())