예제 #1
0
 protected void Page_Load(object sender, EventArgs e)
 {
     if (Session["user"] == null)
     {
         Response.Redirect("Login.aspx");
     }
     else
     {
         txtSaying.Attributes.Add("style", "word-break:break-all;word-wrap:break-word");
         if (!IsPostBack)
         {
             Users     user   = (Users)Session["user"];
             int       userid = user.Userid;
             string    sql    = "select * from UsersSaying where userid='" + userid + "' order by publishtime desc";
             DataTable dt     = DataClass.DataT(sql);
             RptSaying.DataSource = dt;
             RptSaying.DataBind();
         }
     }
 }
예제 #2
0
    protected void Page_Load(object sender, EventArgs e)
    {
        if (Session["user"] == null)
        {
            Response.Redirect("Login.aspx");
        }
        else
        {
            txtSaying.Attributes.Add("style", "word-break:break-all;word-wrap:break-word");
            if (!IsPostBack)
            {
                //绑定repeater RptSaying
                Users     user   = (Users)Session["user"];
                int       userid = user.Userid;
                string    sql    = "select * from UsersSaying where userid in ( select friendid from Friend where userid='" + userid + "' union select userid from Friend where friendid='" + userid + "' union select userid from Users where userid='" + userid + "') order by publishtime desc"; //查询出当前用户所有好友的所有说说
                DataTable alldt  = DataClass.DataT(sql);
                //查询出对当前用户不可见的所有说说信息
                for (int i = 0; i < alldt.Rows.Count; i++)
                {
                    string allow    = alldt.Rows[i][7].ToString();                  //获取当前说说的访问权限对应的字符串
                    int    sayingid = Convert.ToInt32(alldt.Rows[i][3].ToString()); //获取当前说说的id
                    int    authorid = Convert.ToInt32(alldt.Rows[i][0].ToString()); //获取发表当前说说的用户id
                    if (userid != authorid)
                    {
                        DataRow dr = alldt.Rows[i];                                                                                             //获取当前行
                        if (allow == "self")                                                                                                    //若权限设置为仅自己可见
                        {
                            alldt.Rows.Remove(dr);                                                                                              //从数据表中删除该行
                        }
                        else if (allow == "defined")                                                                                            //若权限设置为自定义
                        {
                            string checksql = "select * from SayingAllow where sayingid='" + sayingid + "' and friendid='" + user.Userid + "'"; //查询说说权限表当前说说对当前用户是否可见
                            int    result   = DataClass.Select(checksql);
                            if (result == 0)                                                                                                    //若当前说说对当前用户不可见
                            {
                                alldt.Rows.Remove(dr);                                                                                          //从数据表中删除该行
                            }
                        }
                    }
                }
                for (int i = 0; i < alldt.Rows.Count; i++)
                {
                    int     authorid = Convert.ToInt32(alldt.Rows[i][0].ToString()); //获取发表当前说说的用户id
                    DataRow dr       = alldt.Rows[i];                                //获取当前行
                    if (authorid != user.Userid)
                    {
                        string unablesql = "select * from Friend where ((userid='" + user.Userid + "' and friendid='" + authorid + "') or (userid='" + authorid + "' and friendid='" + userid + "')) and unable='yes'";
                        int    result    = DataClass.Select(unablesql);
                        if (result == 0)
                        {
                            alldt.Rows.Remove(dr);  //从数据表中删除该行
                        }
                    }
                }
                RptSaying.DataSource = alldt;  //绑定repeater
                RptSaying.DataBind();

                //绑定repeater rptList
                string    listsql  = "select * from Users where userid in (select friendid from Friend where userid='" + user.Userid + "' union select userid from Friend where friendid='" + user.Userid + "')";
                DataTable frienddt = DataClass.DataT(listsql);
                this.rptList.DataSource = frienddt;
                this.rptList.DataBind();

                foreach (RepeaterItem item in this.RptSaying.Items)                                                                   //遍历repeater
                {
                    LinkButton lbtPraise = item.FindControl("lbtPraise") as LinkButton;                                               //获取当前行的LinkButton
                    int        i         = item.ItemIndex;                                                                            //获取当前行的id
                    int        sayingid  = Convert.ToInt32(alldt.Rows[i][3].ToString());                                              //获取该行绑定数据对应的说说id
                    string     checksql  = "select * from Praise where userid='" + user.Userid + "' and sayingid='" + sayingid + "'"; //查询当前用户是否对该说说点过赞
                    int        result    = DataClass.Select(checksql);
                    if (result == 1)
                    {
                        lbtPraise.Text = "已赞";
                    }
                    else
                    {
                        lbtPraise.Text = "赞";
                    }
                }

                //绑定repeater rptLable
                string    lablesql = "select distinct lablename from Lable where userid='" + user.Userid + "'";
                DataTable labledt  = DataClass.DataT(lablesql);
                rptLable.DataSource = labledt;
                rptLable.DataBind();
            }
        }
    }
예제 #3
0
    protected void Page_Load(object sender, EventArgs e)
    {
        if (Session["user"] == null || Session["friend"] == null)
        {
            Response.Redirect("Login.aspx");
        }
        else
        {
            if (!IsPostBack)
            {
                Friends friend = (Friends)Session["friend"];
                Users   user   = (Users)Session["user"];
                if (user.Userid == friend.Friendid)
                {
                    Response.Redirect("Mycenter.aspx");
                }
                else
                {
                    string    sql = "select * from UsersSaying where userid='" + friend.Friendid + "' order by publishtime desc"; //查询出该好友的所有说说
                    DataTable dt  = DataClass.DataT(sql);
                    for (int i = 0; i < dt.Rows.Count; i++)
                    {
                        string  allow    = dt.Rows[i][7].ToString();                                                                                                                                                       //获取当前说说的访问权限对应的字符串
                        int     sayingid = Convert.ToInt32(dt.Rows[i][3].ToString());                                                                                                                                      //获取当前说说的id
                        DataRow dr       = dt.Rows[i];                                                                                                                                                                     //获取当前行
                        if (allow == "self")                                                                                                                                                                               //若权限设置为仅自己可见
                        {
                            dt.Rows.Remove(dr);                                                                                                                                                                            //从数据表中删除该行
                        }
                        else if (allow == "friends")                                                                                                                                                                       //若权限设置为好友可见
                        {
                            string checksql = "select * from Friend where (friendid='" + friend.Friendid + "' and userid='" + user.Userid + "') or (friendid='" + user.Userid + "' and userid='" + friend.Friendid + "')"; //查询当前用户是否为被访问用户的好友
                            int    result   = DataClass.Select(checksql);
                            if (result == 0)                                                                                                                                                                               //若当前用户不是被访问用户的好友
                            {
                                dt.Rows.Remove(dr);                                                                                                                                                                        //从数据表中删除该行
                            }
                        }
                        else if (allow == "defined")                                                                                            //若权限设置为自定义
                        {
                            string checksql = "select * from SayingAllow where sayingid='" + sayingid + "' and friendid='" + user.Userid + "'"; //查询说说权限表当前说说对当前用户是否可见
                            int    result   = DataClass.Select(checksql);
                            if (result == 0)                                                                                                    //若当前说说对当前用户不可见
                            {
                                dt.Rows.Remove(dr);                                                                                             //从数据表中删除该行
                            }
                        }
                    }
                    RptSaying.DataSource = dt;  //repeater绑定数据源
                    RptSaying.DataBind();

                    foreach (RepeaterItem item in this.RptSaying.Items)  //遍历repeater
                    {
                        LinkButton lbtPraise = item.FindControl("lbtPraise") as LinkButton;
                        int        i         = item.ItemIndex;
                        int        sayingid  = Convert.ToInt32(dt.Rows[i][3].ToString());
                        string     checksql  = "select * from Praise where userid='" + user.Userid + "' and sayingid='" + sayingid + "'"; //查询当前用户是否已给当前说说点过赞
                        int        result    = DataClass.Select(checksql);
                        if (result == 1)
                        {
                            lbtPraise.Text = "已赞";
                        }
                        else
                        {
                            lbtPraise.Text = "赞";
                        }
                    }
                }

                DateTime time      = DateTime.Now;
                string   selectsql = "select top 1 * from Visitor where hostid='" + friend.Friendid + "' and userid='" + user.Userid + "' order by time desc"; //查询出当前用户在该好友访客表中时间最近的一条数据
                int      exist     = DataClass.Select(selectsql);                                                                                              //查询当前用户是否访问过该好友
                if (exist == 0)                                                                                                                                //若未访问过
                {
                    string insertsql = "insert into Visitor values('" + friend.Friendid + "','" + user.Userid + "','" + time + "')";                           //将访问记录存入访客表
                    DataClass.Save(insertsql);
                }
                else  //若已访问过
                {
                    string t1 = time.ToShortDateString().ToString(); //获取当前日期
                    string t2 = DateTime.Parse(DataClass.DataT(selectsql).Rows[0][3].ToString()).ToShortDateString().ToString();         //获取最新一条访问记录的日期
                    if (t2 != t1)                                                                                                        //若当日未访问过
                    {
                        string insertsql = "insert into Visitor values('" + friend.Friendid + "','" + user.Userid + "','" + time + "')"; //将访问记录存入访客表
                        DataClass.Save(insertsql);
                    }
                }
            }
        }
    }