예제 #1
0
def getCols():
    data = False
    info = ''
    obj = (request.args.get('obj'))
    try:
        data = eval((request.args.get('data')))
    except:
        print('no data')
    # print(data)
    DB = SqlOp()
    print('1')
    if data == True:
        cond = (request.args.get('cond'))
        print(cond)
        info = (DB.select(obj, condition=cond, flag=False))
        print(info)
        info = list(info)
        print(info)
        #处理返回的info中特殊的datetime数据类型

        for i, v in enumerate(info[0]):
            if 'int' not in str(type(v)):
                info[0][i] = str(v)

    try:
        # data = DB.select(obj,condition=cond)
        cols = DB.getCol(obj)
    except:
        # data = 'ERROR'
        cols = 'ERROR'
    print(str([cols, info]))
    if data == True:
        return str([cols, info])
    else:
        return str(cols)
예제 #2
0
def getNicknameByUsername(username):
    s = SqlOp()  #s.select('USER','username like "Showi"')
    allData = s.select('USER', 'USERNAME is "{}"'.format(username))
    print('#USER_DBOP.getNicknameByUsername', allData)
    # nickname = allData[0][1]#!!!!!!!!!!!!!!!!!!!????
    nickname = 'undefined'
    for i in allData:
        if i[0] == username:
            nickname = i[1]
    return nickname
예제 #3
0
def login(username, pwd):
    s = SqlOp()
    users = s.select(table_name='USER')
    for i in users:
        print(i[0], i[2])
        if i[0] == username and i[2] == pwd:
            return str([{
                'isOk': 1,
                'nickname': getNicknameByUsername(username)
            }])
    return str([{'isOk': 0}])
예제 #4
0
def signup(username, pwd, name, age):
    if getNameByID(username) == 'Wrong':
        s = SqlOp(
        )  # s.insert('USER',{'USERNAME':'******','NICKNAME':'Showi','PWD':'Showi666','AGE':'20'})
        s.insert('USER', {
            'USERNAME': username,
            'NICKNAME': name,
            'PWD': pwd,
            'AGE': age
        })
        return name
    return '0'
예제 #5
0
def getNameByID(username):
    '''
    通过ID获得名字
    :param username:
    :return:
    '''
    s = SqlOp()
    users = s.select('USER')
    for i in users:
        if i[0] == username:
            return i[1]
    return 'Wrong'
예제 #6
0
def delData():
    obj = (request.args.get('obj'))
    cond = (request.args.get('cond'))
    DB = SqlOp()
    try:
        # data = DB.select(obj,condition=cond)
        print(obj, cond)
        DB.delete(obj, cond)
        res = 1
    except:
        # data = 'ERROR'
        res = 0
        print(str(res))
    return str(res)
예제 #7
0
def showTable():
    obj = (request.args.get('obj'))
    cond = (request.args.get('cond'))
    print(cond)
    DB = SqlOp()
    # print(obj,cond)
    try:
        data = DB.select(obj, condition=cond)
        cols = DB.getCol(obj)
    except:
        data = 'ERROR'
        cols = 'ERROR'
    if obj == 'rcxc_info':
        return render_template('showTable.html', data=data, colnames=cols)
    elif obj == 'dqjcpzd_info':
        return render_template('showTable_dinqi.html',
                               data=data,
                               colnames=cols)
    else:
        return render_template('showTable.html', data=data, colnames=cols)
예제 #8
0
def insertData():
    obj = (request.args.get('obj'))
    data = eval((request.args.get('data')))
    DB = SqlOp()

    sql = '''
    insert into {} values ('''.format(obj)
    sql = sql + ','.join(data.split(';'))[:-1] + ')'
    #     sql=sql+i
    # sql = sql[:-2]+')'
    print(sql)
    try:
        # data = DB.select(obj,condition=cond)
        # cols = DB.getCol(obj)
        DB.runSql(sql)
        res = 1
    except:
        # data = 'ERROR'
        res = 0

    return str(res)
예제 #9
0
def showPre():
    cond = (request.args.get('cond'))
    s = SqlOp()
    data = s.select('dqjcsh_info', 'road_id=' + cond.split('=')[-1])
    print(data)
    cols = ''
    datas = ''
    for i in [
            '路面类型', '起止位置', '检查总长', '检查总宽', '损坏类型', '损坏长', '损坏宽', '损坏高',
            '损坏位置及损坏情况描述', '损坏面积'
    ]:
        cols = cols + '<td>' + i + '</td>'
    for i in data[0][3:]:
        datas = datas + '<td>' + str(i) + '</td>'
    print(datas)
    return '''<div id="showPre" style="position:absolute;right : 0px;">
<table class="table table-bordered  table-hover table-success">
        <thead id="tableHead">
                ''' + cols + '''
        </thead>

        <tbody>
                <tr>
                        ''' + datas + '''