def msgInsertField(sSession): sSession = str(sSession) sMsg = "Price XX.XX" dict_sCodes = {} from dtm_functions import fGetSessionStatus from dtb_functions import fExecute, fGetSql iStatus = fGetSessionStatus(sSession) sFieldName = { 1: 'Shop/Network', 2: 'Product Group', 3: 'product to Product Group', 4: 'Trademark', 5: None }[iStatus] sTblName = { 1: 'dicNetwork', 2: 'dicProductGroup', 3: 'dicProductType', 4: 'dicTrademark', 5: None }[iStatus] res = fExecute("SELECT MAX(rowid) FROM " + sSession) iNRows = int(res[0][0]) if len(res) > 0 and res[0][0] is not None else 0 sFilter = '' if iNRows > 0: if iStatus == 3: res = fExecute("SELECT idProductGroup FROM " + sSession + " WHERE rowid = " + fGetSql(iNRows, 'INT')) sFilter = 'WHERE idProductGroup = ' + fGetSql( res[0][0], 'INT') if len(res) > 0 and res[0][0] is not None else '' if iStatus in range(1, 5): arr_sValues = fExecute("SELECT rowid, sName FROM " + sTblName + " " + sFilter) sMsg = '' sMsg += '1. Add new ' + sFieldName dict_sCodes = {"1": "add"} i = 1 for sValue in arr_sValues: i = i + 1 sMsg += chr(10) + str(i) + '. ' + sValue[1] dict_sCodes.update({str(i): sValue[0]}) elif iStatus == 5: if iNRows > 0: res = fExecute( "SELECT a.sParamAmount, a.sParam1, a.sParam2, a.sParam3 FROM dicUnit as a JOIN " + sSession + " as b on a.idProduct = b.idProduct and a.idTradeMark = b.idTrademark" ) if len(res) > 0: sMsg += ".." sMsg += res[0][0] if res[0][0] is not None else '' sMsg += ".." sMsg += res[0][1] if res[0][1] is not None else '' sMsg += ".." sMsg += res[0][2] if res[0][2] is not None else '' sMsg += ".." sMsg += res[0][3] if res[0][3] is not None else '' dict_sCodes = {} return {'sMsg': sMsg, 'dict_sCodes': dict_sCodes}
def fSetSessionStatus(sSessionTable, iValue): from dtb_functions import fExecute, fGetSql res = fExecute( "SELECT iStatus FROM tblInsertSessionsStatus WHERE sSessionTable = " + fGetSql(sSessionTable, 'TEXT')) if len(res) > 0: res = fExecute("UPDATE tblInsertSessionsStatus SET iStatus = " + fGetSql(iValue, 'INT') + " WHERE sSessionTable = " + fGetSql(sSessionTable, 'TEXT')) else: res = fExecute("INSERT INTO tblInsertSessionsStatus VALUES (" + fGetSql(sSessionTable, 'TEXT') + ", " + fGetSql(iValue, 'INT') + ")") return iValue
def fSetDialogStatus(idUser, iStatus): idUser = int(idUser) from dtb_functions import fExecute, fGetSql if len( fExecute("SELECT iStatus FROM tblDialogStatus WHERE idUser = "******"UPDATE tblDialogStatus SET iStatus = " + fGetSql(iStatus, 'INT') + " WHERE idUser = "******"INSERT INTO tblDialogStatus VALUES (" + fGetSql(idUser, 'INT') + ", " + fGetSql(iStatus, 'INT') + ")") return
def fSetCurrentSessionTable(idUser, sSession): from dtb_functions import fExecute, fGetSql res = fExecute( "SELECT sCurrentSessionTable FROM tblCurrentInsertSessions WHERE idUser = "******"UPDATE tblCurrentInsertSessions SET sCurrentSessionTable = " + fGetSql(sSession, 'TEXT') + " WHERE idUser = "******"INSERT INTO tblCurrentInsertSessions VALUES (" + fGetSql(idUser, 'INT') + ", " + fGetSql(sSession, 'TEXT') + ")") return sSession
def pPauseTempFillTable(sSessionTable): from dtb_functions import fExecute from dtb_functions import fGetSql iNRows = int( fExecute("SELECT MAX(rowid) FROM " + fGetSql(sSessionTable, "TEXT"))[0][0]) if iNRows > 0: res = fExecute("DELETE FROM " + sSessionTable + " WHERE fPrice IS NULL AND rowid = " + fGetSql(iNRows, "INT")) res = fSetSessionStatus(sSessionTable, None) res = fExecute( "UPDATE tblCurrentInsertSessions SET sCurrentSessionTable = NULL WHERE sCurrentSessionTable = " + fGetSql(sSessionTable, "TEXT")) res = fExecute( "UPDATE tblInsertSessionsStatus SET iStatus = 2 WHERE sSessionTable = " + fGetSql(sSessionTable, "TEXT")) iNRows = int( fExecute("SELECT COUNT(*) FROM " + fGetSql(sSessionTable, "TEXT"))[0][0]) if iNRows == 0: pDropTempFillTable(sSessionTable)
def fFillDictionnary(sSession, sValue): sSession = str(sSession) sValue = str(sValue) from dtm_functions import fGetSessionStatus from dtb_functions import fExecute, fGetSql iStatus = fGetSessionStatus(sSession) sTblName = { 1: 'dicNetwork', 2: 'dicProductGroup', 3: 'dicProductType', 4: 'dicTrademark', 5: 'dicUnit' }[iStatus] res = fExecute("SELECT MAX(rowid) FROM " + sSession) iNRows = int(res[0][0]) if len(res) > 0 and res[0][0] is not None else 0 sAdditionnal = '' if iNRows > 0: if iStatus == 3: res = fExecute("SELECT idProductGroup FROM " + sSession + " WHERE rowid = " + fGetSql(iNRows, 'INT')) sAdditionnal = fGetSql( res[0][0], 'INT') if len(res) > 0 and res[0][0] is not None else 'NULL' sAdditionnal = ", " + sAdditionnal elif iStatus == 4: res = fExecute("SELECT idProduct, idTrademark FROM " + sSession + " WHERE rowid = " + fGetSql(iNRows, 'INT')) sAdditionnal5 = '' sAdditionnal5 = fGetSql( res[0][0], 'INT') if len(res) > 0 and res[0][0] is not None else 'NULL' sAdditionnal5 += ", " sAdditionnal5 += fGetSql( res[0][1], 'INT') if len(res) > 0 and res[0][1] is not None else 'NULL' sAdditionnal5 += ", " if iStatus in range(1, 5): res = fExecute("INSERT INTO " + sTblName + " VALUES (" + fGetSql(sValue, 'TEXT') + sAdditionnal + ")") res = fExecute("SELECT MAX(rowid) FROM " + sTblName) iNRows = int( res[0][0]) if len(res) > 0 and res[0][0] is not None else 0 else: iNRows = 0 if iStatus == 4: # for iStatus = 5's JOIN print "INSERT INTO dicUnit VALUES (" + sAdditionnal5 + ", NULL, NULL, NULL, NULL)" res = fExecute("INSERT INTO dicUnit VALUES (" + sAdditionnal5 + " NULL, NULL, NULL, NULL)") return iNRows
def msgSessions(idUser): from dtb_functions import fExecute, fGetSql arr_sSessions = fExecute( "SELECT name FROM sqlite_master WHERE name LIKE 'temp_TblToFill_" + str(int(idUser)) + "%'") sMsg = '' sMsg += 'Choose your session :' + chr(10) sMsg += '1. Begin new' dict_sCodes = {"1": "new"} i = 1 for sSession in arr_sSessions: i = i + 1 res = fExecute( 'SELECT MAX(b.sName), MAX(a.dDate) FROM ' + fGetSql(sSession[0], "TEXT") + " as a JOIN dicNetwork as b ON a.idNetwork = b.rowid")[0] sMsg += chr(10) + str(i) + '. ' + str(res[0]) + " [" + str( res[1]) + "]" dict_sCodes.update({str(i): sSession[0]}) return {'sMsg': sMsg, 'dict_sCodes': dict_sCodes}