예제 #1
0
 /// <summary>
 /// 根据用户id 获取用户文章概况信息
 /// </summary>
 /// <param name="userId"></param>
 /// <param name="conn"></param>
 /// <returns></returns>
 public static UserArticleInfo GetArticleInfoByUserId(int userId, OleDbConnection conn)
 {
     try
     {
         string          sql         = String.Format(GET_TOTAL_ARTICLEINFO_BY_USERID, userId);
         OleDbCommand    cmd         = new OleDbCommand(sql, conn);
         OleDbDataReader reader      = cmd.ExecuteReader();
         UserArticleInfo articleInfo = null;
         if (reader.Read())
         {
             articleInfo                 = new UserArticleInfo();
             articleInfo.ID              = (int)reader["ID"];
             articleInfo.User_id         = (int)reader["UserID"];
             articleInfo.Article_num     = (int)reader["Article_Num"];
             articleInfo.Del_Article_num = (int)reader["Del_Article_Num"];
             articleInfo.MComment_num    = (int)reader["MComment_Num"];
             articleInfo.Comment_num     = (int)reader["Comment_Num"];
             articleInfo.Favour_num      = (int)reader["Favour_Num"];
             articleInfo.Browse_num      = (int)reader["Browse_Num"];
         }
         reader.Close();
         return(articleInfo);
     }
     catch (Exception)
     {
         return(null);
     }
 }
예제 #2
0
    /// <summary>
    /// 设置制定字段值
    /// </summary>
    /// <param name="type"></param>
    /// <param name="articleInfo"></param>
    /// <returns></returns>
    private static UserArticleInfo SetNum(int type, UserArticleInfo articleInfo)
    {
        switch (type)
        {
        case 1:
            articleInfo.Article_num = articleInfo.Article_num + 1;
            break;

        case 2:
            articleInfo.Del_Article_num = articleInfo.Del_Article_num + 1;
            break;

        case 3:
            articleInfo.Comment_num = articleInfo.Comment_num + 1;
            break;

        case 4:
            articleInfo.MComment_num = articleInfo.MComment_num + 1;
            break;

        case 5:
            articleInfo.Favour_num = articleInfo.Favour_num + 1;
            break;

        case 6:
            articleInfo.Browse_num = articleInfo.Browse_num + 1;
            break;

        case 7:
            articleInfo.Favour_num = articleInfo.Favour_num - 1;
            break;
        }

        return(articleInfo);
    }
예제 #3
0
    /// <summary>
    /// 根据用户ID获取用户发文信息
    /// </summary>
    /// <param name="userId"></param>
    /// <returns></returns>
    public static UserArticleInfo GetArticleInfoByUserId(int userId)
    {
        UserArticleInfo articleInfo = null;

        lock (mLockObj)
        {
            mdb.Connect();
            articleInfo = UserArticleInfoData.GetArticleInfoByUserId(userId, mdb.GetConn);
            mdb.Disconnect();
        }
        return(articleInfo);
    }
예제 #4
0
    /// <summary>
    /// 根据用户ID更新用户发文概况表信息
    /// </summary>
    /// <param name="articleInfo"></param>
    /// <param name="userId"></param>
    /// <returns></returns>
    public static bool UpdateArticleInfoByUserId(UserArticleInfo articleInfo, int userId)
    {
        bool result = false;

        lock (mLockObj)
        {
            mdb.Connect();
            result = UserArticleInfoData.UpdateInfoByUserId(userId, articleInfo, mdb.GetConn);
            mdb.Disconnect();
        }
        return(result);
    }
예제 #5
0
    /// <summary>
    /// 插入用户发文概况信息
    /// </summary>
    /// <param name="articleInfo"></param>
    /// <returns></returns>
    public static bool InsertNewArticleInfo(int userId, UserArticleInfo articleInfo)
    {
        bool result = false;

        lock (mLockObj)
        {
            mdb.Connect();
            result = UserArticleInfoData.InsertUserArticleInfo(userId, articleInfo, mdb.GetConn);
            mdb.Disconnect();
        }
        return(result);
    }
예제 #6
0
 /// <summary>
 /// 根据用户ID更新信息
 /// </summary>
 /// <param name="userId"></param>
 /// <param name="articleInfo"></param>
 /// <param name="conn"></param>
 /// <returns></returns>
 public static bool UpdateInfoByUserId(int userId, UserArticleInfo articleInfo, OleDbConnection conn)
 {
     try
     {
         string sql = String.Format(UPDATE_ARTICLE_INFO_BY_USERID, articleInfo.Article_num, articleInfo.Del_Article_num, articleInfo.MComment_num,
                                    articleInfo.Comment_num, articleInfo.Favour_num, articleInfo.Browse_num, userId);
         OleDbCommand cmd = new OleDbCommand(sql, conn);
         int          row = cmd.ExecuteNonQuery();
         return(row > 0);
     }
     catch (Exception)
     {
         return(false);
     }
 }
예제 #7
0
 /// <summary>
 /// 根据用户ID更新用户概况表的各个值
 /// type = 1 => 总文章数 + 1
 /// type = 2 => 删除文章总数 + 1
 /// type = 3 => 评论数 + 1
 /// type = 4 => 被评论数 + 1
 /// type = 5 => 点赞数 + 1
 /// type = 6 => 总浏览数 + 1
 /// type = 7 => 点赞数 - 1
 /// </summary>
 /// <param name="userId"></param>
 /// <param name="type"></param>
 public static void SetNumByUserId(int userId, int type)
 {
     if (GetArticleInfoByUserId(userId) == null) // 是看是否存在记录,不存在则新建
     {
         UserArticleInfo articleInfo = new UserArticleInfo();
         if (InsertNewArticleInfo(userId, articleInfo)) // 新建用户发文概况信息
         {
             UserArticleInfo userAInfo = GetArticleInfoByUserId(userId);
             UpdateArticleInfoByUserId(SetNum(type, userAInfo), userId);
         }
     }
     else
     {
         UserArticleInfo userAInfo = GetArticleInfoByUserId(userId);
         UpdateArticleInfoByUserId(SetNum(type, userAInfo), userId); // 更新信息
     }
 }
예제 #8
0
 /// <summary>
 /// 新建用户发文信息
 /// </summary>
 /// <param name="articleInfo"></param>
 /// <param name="conn"></param>
 /// <returns></returns>
 public static bool InsertUserArticleInfo(int userId, UserArticleInfo articleInfo, OleDbConnection conn)
 {
     try
     {
         int row = 0;
         if (GetArticleInfoByUserId(userId, conn) == null) // 判断是否存在记录
         {
             string sql = String.Format(INSERT_USER_ARTICLE_INFO, userId, articleInfo.Article_num, articleInfo.Del_Article_num,
                                        articleInfo.MComment_num, articleInfo.Comment_num, articleInfo.Favour_num, articleInfo.Browse_num);
             OleDbCommand cmd = new OleDbCommand(sql, conn);
             row = cmd.ExecuteNonQuery();
         }
         return(row > 0);
     }
     catch (Exception)
     {
         return(false);
     }
 }
예제 #9
0
    protected void Button1_Click(object sender, EventArgs e)
    {
        string newuser = newUser.Text.Trim();
        string newpsw  = newPsw.Text.Trim();
        string newrpsw = newRpsw.Text.Trim();
        string newtel  = newTel.Text.Trim();

        // 检测用户名是否有效
        System.Text.RegularExpressions.Regex regex_name =
            new System.Text.RegularExpressions.Regex("[A-Za-z0-9\u4e00-\u9fa5]+");

        System.Text.RegularExpressions.Regex regex_psw =
            new System.Text.RegularExpressions.Regex("[A-Za-z0-9]+");

        System.Text.RegularExpressions.Regex regex_tel =
            new System.Text.RegularExpressions.Regex("0?(13|14|15|18)[0-9]{9}");

        registerMsg.Text = "";

        if (regex_name.IsMatch(newuser))
        {
            if (newpsw.Equals(newrpsw))
            {
                if (regex_psw.IsMatch(newpsw))
                {
                    if (regex_tel.IsMatch(newtel))
                    {
                        // 注册成功
                        // 保存用户信息,并对密码进行加密
                        if (UserHelper.Register(newuser, MD5Encryption.EnCondingMD5(newpsw), newtel))
                        {
                            UserArticleInfo articleInfo = new UserArticleInfo();
                            User            user        = UserHelper.GetUserInfoByUserName(newuser); // 获取新用户信息,以便获取用户ID
                            UserArticleInfoHelper.InsertNewArticleInfo(user.userID, articleInfo);    // 新建用户发文概况信息

                            Page.ClientScript.RegisterStartupScript(this.GetType(), "",
                                                                    "alert('注册成功!前往登录...');window.location.href='Login.aspx'", true);
                        }
                        else
                        {
                            registerMsg.Text = "用户名已存在!";
                        }
                    }
                    else
                    {
                        registerMsg.Text = "请输入正确手机号!";
                    }
                }
                else
                {
                    registerMsg.Text = "无效密码!(大小写母、数字)";
                }
            }
            else
            {
                registerMsg.Text = "输入两次密码不一样!";
            }
        }
        else
        {
            registerMsg.Text = "无效用户名!(中文、大小写母、数字、'-'或'_')";
        }
    }