Beispiel #1
0
def find_station_data():
    conn = db_con()
    cursor = conn.cursor()
    cursor.execute('select * from Link')
    station = cursor.fetchall()
    # 关闭cursor
    cursor.close()
    # 提交事务
    conn.commit()
    # 关闭数据库连接
    conn.close()
    return station
Beispiel #2
0
def delete_yx_data():
    yxIDs = request.form.get("ids")
    yx_IDs = json.loads(yxIDs)

    conn = db_con()
    cursor = conn.cursor()
    for yx_ID in yx_IDs:
        cursor.execute('delete from Digital1 where ID = ?', (yx_ID,))
    cursor.close()
    conn.commit()
    conn.close()
    return '删除成功!'
Beispiel #3
0
def find_yx_data():
    conn = db_con()
    # 创建一个cursor 游标(用于执行SQL语句)
    cursor = conn.cursor()
    cursor.execute('select * from Digital1')
    yxdata = cursor.fetchall()
    # print(yxdata[0][1])
    # 关闭cursor
    cursor.close()
    # 提交事务
    conn.commit()
    # 关闭数据库连接
    conn.close()
    return yxdata
Beispiel #4
0
def update_station_data():
    updatestation = request.form.get("data")
    update_station = json.loads(updatestation)

    conn = db_con()
    cursor = conn.cursor()
    for ID, NAME, DESCRIBE, RULEID, ADDRESS, PORT, ROLE in zip(json.loads(update_station[0]),
                                                               json.loads(update_station[1]),
                                                               json.loads(update_station[2]),
                                                               json.loads(update_station[3]),
                                                               json.loads(update_station[4]),
                                                               json.loads(update_station[5]),
                                                               json.loads(update_station[6])):
        cursor.execute('update Link set NAME=?,DESCRIBE=?,RULEID=?,ADDRESS=?,PORT=?,ROLE=?'
                       'where ID = ?',
                       (NAME, DESCRIBE, RULEID, ADDRESS, PORT, ROLE, ID)
                       )
    cursor.close()
    conn.commit()
    conn.close()
    return '修改成功!';
Beispiel #5
0
def insert_station_data():
    newstation = request.form.get("data")
    new_station = json.loads(newstation)

    conn = db_con()
    cursor = conn.cursor()
    for ID, NAME, DESCRIBE, RULEID, ADDRESS, PORT, ROLE in zip(json.loads(new_station[0]),
                                                               json.loads(new_station[1]),
                                                               json.loads(new_station[2]),
                                                               json.loads(new_station[3]),
                                                               json.loads(new_station[4]),
                                                               json.loads(new_station[5]),
                                                               json.loads(new_station[6])):
        cursor.execute(
            'INSERT INTO Link (ID, NAME, DESCRIBE, RULEID, ADDRESS, PORT, ROLE )'
            'VALUES (?, ?, ?, ?, ?, ?, ?)',
            (ID, NAME, DESCRIBE, RULEID, ADDRESS, PORT, ROLE)
        )
    cursor.close()
    conn.commit()
    conn.close()
    return '添加成功!'
Beispiel #6
0
def update_yx_data():
    updateyx = request.form.get("data")
    update_yx = json.loads(updateyx)

    conn = db_con()
    cursor = conn.cursor()
    for ID, NAME, DESCRIBE, ASDU, WORD, BYTE, NUMBYTE, ADDRESS in zip(json.loads(update_yx[0]),
                                                                      json.loads(update_yx[1]),
                                                                      json.loads(update_yx[2]),
                                                                      json.loads(update_yx[3]),
                                                                      json.loads(update_yx[4]),
                                                                      json.loads(update_yx[5]),
                                                                      json.loads(update_yx[6]),
                                                                      json.loads(update_yx[7])):
        cursor.execute('update Digital1 set NAME=?,DESCRIBE=?,ASDU=?,WORD=?,BYTE=?,NUMBYTE=?,ADDRESS=? '
                       'where ID = ?',
                       (NAME, DESCRIBE, ASDU, WORD, BYTE, NUMBYTE, ADDRESS, ID)
                       )
    cursor.close()
    conn.commit()
    conn.close()
    return '修改成功!';
Beispiel #7
0
def update_station_data(update_data):
    # print("%s: %s" % (type(update_data), update_data))
    nameLen = len(update_data[1])
    # print(nameLen)
    names = []
    for i in range(nameLen):
        name = (
            update_data[1][i]).encode('unicode_escape').decode('string_escape')
        names.append(name)
    # print(names)

    conn = db_con()
    conn.text_factory = str
    cursor = conn.cursor()
    for ID, NAME, DESCRIBE, RULEID, ADDRESS, PORT, ROLE in zip(
            update_data[0], names, update_data[2], update_data[3],
            update_data[4], update_data[5], update_data[6]):
        cursor.execute(
            'update Link set NAME=?,DESCRIBE=?,RULEID=?,ADDRESS=?,PORT=?,ROLE=?'
            'where ID = ?', (NAME, DESCRIBE, RULEID, ADDRESS, PORT, ROLE, ID))
    cursor.close()
    conn.commit()
    conn.close()
    socketio.emit('update_response', '修改成功!', namespace='/update_station_data')
Beispiel #8
0
def insert_station_data(new_data):
    nameLen = len(new_data[1])
    # print(nameLen)
    names = []
    for i in range(nameLen):
        name = (
            new_data[1][i]).encode('unicode_escape').decode('string_escape')
        names.append(name)
    # print(names)

    conn = db_con()
    conn.text_factory = str
    cursor = conn.cursor()
    for ID, NAME, DESCRIBE, RULEID, ADDRESS, PORT, ROLE in zip(
            new_data[0], names, new_data[2], new_data[3], new_data[4],
            new_data[5], new_data[6]):
        cursor.execute(
            'INSERT INTO Link (ID, NAME, DESCRIBE, RULEID, ADDRESS, PORT, ROLE )'
            'VALUES (?, ?, ?, ?, ?, ?, ?)',
            (ID, NAME, DESCRIBE, RULEID, ADDRESS, PORT, ROLE))
    cursor.close()
    conn.commit()
    conn.close()
    socketio.emit('insert_response', '添加成功!', namespace='/new_station_data')
Beispiel #9
0
def insert_yx_data():
    newyx = request.form.get("data")
    new_yx = json.loads(newyx)
    # print(type(new_data))

    conn = db_con()
    cursor = conn.cursor()
    for ID, NAME, DESCRIBE, ASDU, WORD, BYTE, NUMBYTE, ADDRESS in zip(json.loads(new_yx[0]),
                                                                      json.loads(new_yx[1]),
                                                                      json.loads(new_yx[2]),
                                                                      json.loads(new_yx[3]),
                                                                      json.loads(new_yx[4]),
                                                                      json.loads(new_yx[5]),
                                                                      json.loads(new_yx[6]),
                                                                      json.loads(new_yx[7])):
        cursor.execute(
            'INSERT INTO Digital1 (ID, NAME, DESCRIBE, ASDU, WORD, BYTE, NUMBYTE, ADDRESS )'
            'VALUES (?, ?, ?, ?, ?, ?, ?, ?)',
            (ID, NAME, DESCRIBE, ASDU, WORD, BYTE, NUMBYTE, ADDRESS)
        )
    cursor.close()
    conn.commit()
    conn.close()
    return '添加成功!'