def go(self, sonCode, material, relation, product, IdToCode, CodeToId): if sonCode in CodeToId: sonId = CodeToId[sonCode] a = some_functions.return_Table_Column_Value('relation', 'son',str(sonId)) if len(a)!=0: for i in a: fatherId = i[1] self.NUM += 1 temp1 = some_functions.return_Table_Column_Value('material', 'id', str(fatherId)) self.SHEET.write(self.NUM, 0, temp1[0][1]) self.SHEET.write(self.NUM, 1, i[3]) products = some_functions.findAllProduct(IdToCode[fatherId]) WE = '' for i in products: WE += '; '+i WE = WE[2:] self.SHEET.write(self.NUM, 2, WE) currentDIR = os.path.dirname(os.path.realpath(__file__)) self.EXCEL.save(os.path.join(currentDIR, "single_reverse_query.xls")) print 'done' else: print 'this material has no direct father!' else: print 'no such material code!'
def go(self, fatherCode, material, relation, product, IdToCode, CodeToId): if fatherCode in CodeToId: fatherId = CodeToId[fatherCode] self.gogo(0, 1, fatherId) products = some_functions.findAllProduct(fatherCode) # return fatherCode's all products WE = "" for i in products: WE += "; " + i WE = WE[2:] for i in range(1, self.NUM + 1): self.SHEET.write(i, self.MAX_IND, self.NUMArray[i - 1]) self.SHEET.write(i, self.MAX_IND + 1, WE) self.SHEET.write(0, 0, r"descendants") self.SHEET.write(0, self.MAX_IND, r"needed amount") self.SHEET.write(0, self.MAX_IND + 1, r"product code") currentDIR = os.path.dirname(os.path.realpath(__file__)) self.EXCEL.save(os.path.join(currentDIR, "multi_query.xls")) print "done" else: print "no such material code!"
def go(self, fatherCode, material, relation, product, IdToCode, CodeToId): self.EXCEL = xlwt.Workbook() self.SHEET = self.EXCEL.add_sheet('single_query', cell_overwrite_ok=False) self.SHEET.write(0,0,r'direct son') self.SHEET.write(0,1,r'needed amount') self.SHEET.write(0,2,r'product code') self.NUM = 0 if fatherCode in CodeToId: fatherId = CodeToId[fatherCode] a = some_functions.return_Table_Column_Value('relation', 'father',str(fatherId)) products = some_functions.findAllProduct(fatherCode) #return fatherCode's all products WE = '' for i in products: WE += '; '+i WE = WE[2:] if len(a)!=0: for i in a: sonId = i[2] self.NUM += 1 temp1 = some_functions.return_Table_Column_Value('material', 'id', str(sonId)) self.SHEET.write(self.NUM, 0, temp1[0][1]) self.SHEET.write(self.NUM, 1, i[3]) self.SHEET.write(self.NUM, 2, WE) currentDIR = os.path.dirname(os.path.realpath(__file__)) self.EXCEL.save(os.path.join(currentDIR, "single_query.xls")) print 'done' else: print 'this material has no direct son!' currentDIR = os.path.dirname(os.path.realpath(__file__)) self.EXCEL.save(os.path.join(currentDIR, "single_query.xls")) print 'done' else: print 'no such material code!'
def go(self, sonCode, material, relation, product, IdToCode, CodeToId): if sonCode in CodeToId: sonId = CodeToId[sonCode] self.STORE1 = [] self.gogo(sonId, [(sonId,1)]) self.STORE1.pop(self.STORE1.index([(sonId, 1)])) MAX_IND = 0 for i in self.STORE1: i.reverse() MAX_IND = max(MAX_IND, len(i)) self.STORE1.sort(cmp = self.mycmp) rowNum = 0 result = {} for i in self.STORE1: #first temp1 = self.isColumnXYIDexisted(1, 1, rowNum, i[0][0]) if temp1 == -1: #no exist rowNum += 1 result[rowNum] = (1, i[0][0], i[0][1]) upIndex = rowNum if 1 not in self.columnHash: self.columnHash[1] = [(rowNum, i[0][0], i[0][1])] else: self.columnHash[1].append((rowNum, i[0][0], i[0][1])) else: #exist ori1 = result[temp1] result[temp1] = (ori1[0], ori1[1], ori1[2]+i[0][1]) upIndex = temp1 L = len(i) for j in range(1,L): temp1 = self.isColumnXYIDexisted(j+1, upIndex+1, rowNum, i[j][0]) if temp1 == -1: rowNum += 1 result[rowNum] = (j+1, i[j][0], i[j][1]) upIndex = rowNum if j+1 not in self.columnHash: self.columnHash[j+1] = [(rowNum, i[j][0], i[j][1])] else: self.columnHash[j+1].append((rowNum, i[j][0], i[j][1])) else: oril = result[temp1] result[temp1] = (oril[0], oril[1], oril[2]+i[j][1]) upIndex = temp1 self.SHEET.write(0,0,r'ancestors') self.SHEET.write(0, MAX_IND, r'needed amount') self.SHEET.write(0, MAX_IND+1, r'product code') KK = [] for i in range(1, rowNum+1): if result[i][0]==1: part = result[i][1] if part in product: SS = IdToCode[part] else: pp = some_functions.findAllProduct(IdToCode[part]) SS = "" for i in pp: SS += '; '+i SS = SS[2:] KK.append(SS) for i in range(1, rowNum+1): self.SHEET.write(i, result[i][0]-1, IdToCode[result[i][1]]) self.SHEET.write(i, MAX_IND, str(result[i][2])) self.SHEET.write(i, MAX_IND+1, KK[i-1]) currentDIR = os.path.dirname(os.path.realpath(__file__)) self.EXCEL.save(os.path.join(currentDIR, "multi_reverse_query.xls")) print 'done' else: print 'no such material code!'