def sAdd(self): title = "Table "+self.name+" Add" #get ID for default record #row = self.model.getDefaultTableRow() dbRow = self.model.getDefaultRow() #print row dbRow['id'] = uiAccesories.showMessage(title,"ID: ", MSGTYPE.get_integer, dbRow['id']) if dbRow['id'] == None: return #this ID exist? res = db.getParId(self.name, dbRow['id']) if(res): uiAccesories.showMessage(title,"Record with this ID already exist!") return #dstore.Set("user_actions", False) if(dbRow != None): db.insert_from_dict(self.name, dbRow) uiAccesories.showMessage(title,"succesfully (id="+str(dbRow['id'])+")", MSGTYPE.statusbar) self.Update()
def sImport(self): """import""" #gui dialog filename = uiAccesories.getOpenFileName("Import CSV to table "+self.name,"dir_import_csv","Csv Files (*.csv)", self.name+".csv") #cancel or close window if(filename == ""): return #IMPORT CSV TO DATABASE #load csv to df try: df = pd.DataFrame.from_csv(str(filename), sep=";", encoding = "utf8") #df.drop([df.columns[-1]], axis=1, inplace=True) df.fillna("", inplace=True) except: uiAccesories.showMessage(self.name+" CSV Import", "NOT Succesfully imported\n empty file or wrong format") return df["id"] = df.index #callback try: df = self.importDf2dbDdf(df) except KeyError: title = "Table '"+self.name + "' CSV Import" uiAccesories.showMessage(title, "NOT Succesfully"+"\n\n" +"Wrong format or not existing data.") return #counters state = {'ko':0, 'ok':0} #adding rows to DB for i,row in df.iterrows(): try: self.importRow2dbRow(row) except: state['ko'] += 1 continue #to dict because of CZ row = dict(row) #if(db.insert_from_lists(self.name, columns, row, commit_flag = False) != False): if(db.insert_from_dict(self.name, row, commit = False) != False): state['ok'] += 1 else: state['ko'] += 1 #increment errors for error message db.commit() self.model.Update() self.sImportDialog(state)