예제 #1
0
def SQL(p_db, p_str):
    db = MySQLdb.connect(MYSQL_HOST,
                         MYSQL_USERNAME,
                         MYSQL_PASSWORD,
                         p_db,
                         charset='utf8')
    cursor = db.cursor()
    sql_cmd = p_str.split(' ')[0]
    try:
        cursor.execute(p_str)
        db.commit()
        if sql_cmd == 'SELECT':
            result = cursor.fetchall()
            # result = result.decode('utf-8').encode('gbk')
        else:
            result = True
        temp = "%s:成功!" % sql_cmd
        print format_str.color(temp, 'green', 'l')

    except:
        db.rollback()
        result = False
        temp = "%s:失败!" % sql_cmd
        print format_str.color(temp, 'red', 'l')
    db.close()
    return result
예제 #2
0
def regist_info_rc(p_ob):
    for items_feature in p_ob.feature_array:
        for items_record in items_feature.record_array:

            if items_feature.apellation == "用户名":
                rule_error = format_str.check_username_rule(
                    items_record.num)  #调用format_str模块的用户名规则检查方法
                if rule_error == True:
                    sql_cmd = "SELECT USER_APELLATION FROM User WHERE USER_APELLATION = '%s'" % items_record.num  # 查询数据库
                    result = SQL('Web_Shop_User_DB', sql_cmd)  # 以元组形式返回匹配到的结果。
                    if len(result) != 0:
                        rule_error = format_str.color("用户名已存在!", 'red', 'l')
                        return rule_error
                else:
                    rule_error = format_str.color(rule_error, 'red', 'l')
                    return rule_error

            elif items_feature.apellation == "密码":
                rule_error = format_str.check_password_rule(
                    items_record.num, 2)  #调用format_str模块的密码规则检查方法
                if rule_error != True:
                    rule_error = format_str.color(rule_error, 'red', 'l')
                    return rule_error

            elif items_feature.apellation == "电子邮箱":
                rule_error = format_str.check_email_rule(
                    items_record.num)  #调用format_str模块的电子邮箱规则检查方法
                if rule_error != True:
                    rule_error = format_str.color(rule_error, 'red', 'l')
                    return rule_error
    rule_error = True
    return rule_error
예제 #3
0
def fill_regist_info():

    for items in BASIC_FEATURE_ORDER:
        if items == "用户名":

            tmp_var = raw_input("请输入%s:  " % items)
            ob_user = build_user.User(tmp_var, "vip")  #构建用户
            ob_user.create_feature(items, FEATURE_ARRAY_D.get(items))  #构建用户属性
            ob_user.feature.create_record('str', tmp_var)  #构建用户属性记载

        elif items == "密码":

            while (True):
                tmp_var_1 = raw_input("请输入%s:  " % items)
                tmp_var_2 = raw_input("请再次输入%s:  " % items)
                if tmp_var_1 == tmp_var_2:
                    break
                else:
                    print format_str.color("密码不一致,请重新输入!", 'red', 'l')

            ob_user.create_feature(items, FEATURE_ARRAY_D.get(items))  #构建用户属性
            ob_user.feature.create_record('str', tmp_var_1)  #构建用户属性记载

        else:
            tmp_var = raw_input("请输入%s:  " % items)
            ob_user.create_feature(items, FEATURE_ARRAY_D.get(items))  #构建用户属性
            ob_user.feature.create_record('str', tmp_var)  #构建用户属性记载

    return ob_user  #返回用户对象
예제 #4
0
def select(p_db_name, p_table, p_key_1, p_value,
           p_key_2):  # 取p_key_1 = p_value 的 p_key_2 的值
    db = MySQLdb.connect(MYSQL_HOST,
                         MYSQL_USERNAME,
                         MYSQL_PASSWORD,
                         p_db_name,
                         charset='utf8')
    cursor = db.cursor()
    # sql = "SELECT %s FROM %s" % (p_key, p_table)
    sql = "SELECT %s FROM %s WHERE %s = '%s'" % (
        p_key_2, p_table, p_key_1, p_value)  # 取USERNAME = test_2 的 PASSWORD
    try:
        cursor.execute(sql)
        args = cursor.fetchall()
        for i in args:
            print i[0]

        result = p_table
        temp = "数据表:%s 读取成功!" % p_table
        print format_str.color(temp, 'green', 'l')
    except:
        result = False
        temp = "数据表:%s 读取失败!" % p_table
        print format_str.color(temp, 'red', 'l')
    db.close()
    return result
예제 #5
0
def delete_table(p_db_name, p_table):
    db = MySQLdb.connect(MYSQL_HOST, MYSQL_USERNAME, MYSQL_PASSWORD, p_db_name)
    cursor = db.cursor()
    sql = "DROP TABLE %s" % p_table
    try:
        cursor.execute(sql)
        result = p_table
        temp = "数据表:%s 删除成功!" % p_table
        print format_str.color(temp, 'green', 'l')
    except:
        result = False
        temp = "数据表:%s 删除失败!" % p_table
        print format_str.color(temp, 'red', 'l')
    db.close()
    return result
예제 #6
0
def create_database(p_db_name):
    db = MySQLdb.connect(MYSQL_HOST, MYSQL_USERNAME, MYSQL_PASSWORD)
    cursor = db.cursor()
    sql = "CREATE DATABASE %s" % p_db_name
    try:
        cursor.execute(sql)
        result = p_db_name
        temp = "数据库:%s 创建成功!" % p_db_name
        print format_str.color(temp, 'green', 'l')
    except:
        result = False
        temp = "数据库:%s 创建失败!" % p_db_name
        print format_str.color(temp, 'red', 'l')
    db.close()
    return result
예제 #7
0
def create_table(p_db_name, p_table):
    db = MySQLdb.connect(MYSQL_HOST, MYSQL_USERNAME, MYSQL_PASSWORD, p_db_name)
    cursor = db.cursor()
    # sql = "CREATE TABLE %s (FIRST_NAME CHAR(20) NOT NULL,LAST_NAME CHAR(20),AGE INT,INCOME FLOAT)" % p_table
    sql = "CREATE TABLE %s (USERNAME CHAR(20),PASSWORD CHAR(20))" % p_table
    try:
        cursor.execute(sql)
        result = p_table
        temp = "数据表:%s 创建成功!" % p_table
        print format_str.color(temp, 'green', 'l')
    except:
        result = False
        temp = "数据表:%s 创建失败!" % p_table
        print format_str.color(temp, 'red', 'l')
    db.close()
    return result
예제 #8
0
def clear_table(p_db_name, p_table):
    db = MySQLdb.connect(MYSQL_HOST, MYSQL_USERNAME, MYSQL_PASSWORD, p_db_name)
    cursor = db.cursor()
    sql = "DELETE FROM %s" % p_table
    try:
        cursor.execute(sql)
        db.commit()
        result = p_table
        temp = "数据表:%s 记录清空成功!" % p_table
        print format_str.color(temp, 'green', 'l')
    except:
        db.rollback()
        result = False
        temp = "数据表:%s 记录清空失败!" % p_table
        print format_str.color(temp, 'red', 'l')
    db.close()
    return result
예제 #9
0
def register_user():
    user_apellation = raw_input(
        format_str.color('Plaes input User apellation:\n', 'green', 'l'))
    ob = User(user_apellation, 'vip')

    while (1):
        feature_apellation = raw_input(
            format_str.color('Plaes input feature apellation:\n', 'blue', 'l'))
        num_apellation = raw_input(
            format_str.color('Plaes input record apellation:\n', 'yellow',
                             'l'))
        num = raw_input(format_str.color('Plaes input Vol:\n', 'red', 'l'))

        ob.create_feature(feature_apellation, 'personal', 'str')
        ob.feature.create_record(num_apellation, 'ing')
        ob.feature.num.create_num(num)

        ob.printf()

        tmp = raw_input(format_str.color('Plaes check!   y/n?\n', 'red', 'f'))
        if tmp == 'y':
            print 'Updata in MySQL'
            ob.input_db()

        tmp = raw_input(format_str.color('Qiut?   y/n\n', 'red', 'l'))
        if tmp == 'y':
            break
예제 #10
0
def insert_table(p_db_name, p_table, p_value1, p_value2):
    db = MySQLdb.connect(MYSQL_HOST,
                         MYSQL_USERNAME,
                         MYSQL_PASSWORD,
                         p_db_name,
                         charset='utf8')
    cursor = db.cursor()
    sql = "INSERT INTO %s VALUES ('%s','%s')" % (p_table, p_value1, p_value2)
    # sql = "INSERT INTO %s(USERNAME,PASSWORD) VALUES ('%s','%s')" % (p_table, p_key, p_value)
    try:
        cursor.execute(sql)
        db.commit()
        result = p_table
        temp = "数据表:%s 插入记录成功!" % p_table
        print format_str.color(temp, 'green', 'l')
    except:
        db.rollback()
        result = False
        temp = "数据表:%s 插入记录失败!" % p_table
        print format_str.color(temp, 'red', 'l')
    db.close()
    return result
예제 #11
0
def update_table(p_db_name, p_table, p_key, p_value):
    db = MySQLdb.connect(MYSQL_HOST,
                         MYSQL_USERNAME,
                         MYSQL_PASSWORD,
                         p_db_name,
                         charset='utf8')
    cursor = db.cursor()
    sql = "UPDATE %s SET PASSWORD = '******' WHERE %s = '%s'" % (p_table, p_key,
                                                              p_value)
    # sql = "INSERT INTO %s(USERNAME,PASSWORD) VALUES ('%s','%s')" % (p_table, p_key, p_value)
    try:
        cursor.execute(sql)
        db.commit()
        result = p_table
        temp = "数据表:%s 更新成功!" % p_table
        print format_str.color(temp, 'green', 'l')
    except:
        db.rollback()
        result = False
        temp = "数据表:%s 更新失败!" % p_table
        print format_str.color(temp, 'red', 'l')
    db.close()
    return result
예제 #12
0
 def printf(self):
     tmp = self.apellation + '   ' + self.feature.apellation + '   ' + \
         self.feature.record.apellation + '   ' + self.feature.record.num
     print format_str.color(tmp, 'red', 'l')
     print self.apellation, self.genre, self.feature.apellation, self.feature.genre, self.feature.record.apellation, self.feature.record.genre, self.feature.record.num
예제 #13
0
def regist_page():
    print format_str.color('''
    注册账户!
    ''', 'green', 'l')
예제 #14
0
def welcome_page():
    print format_str.color('''
    欢迎光临33网上商城!
    ''', 'red', 'l')
예제 #15
0
def display_regist_info(p_ob):
    for items_feature in p_ob.feature_array:
        for items_record in items_feature.record_array:
            if items_feature.apellation != "密码":
                tmp_strng = items_feature.apellation + ':     ' + items_record.num
                print format_str.color(tmp_strng, 'blue', 'l')