using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using JuSNS.Model;
using JuSNS.UI.Control;
using JuSNS.Common;

namespace JuSNS.Web.home.Group
{
    public partial class member : JuSNS.UI.Page.UserPage
    {
        JuSNS.Home.Friend friend = new JuSNS.Home.Friend();
        JuSNS.Home.Mood blog = new JuSNS.Home.Mood();
        protected void Page_Load(object sender, EventArgs e)
        {
            Response.CacheControl = "no-cache";
            CheckPublicity();
            LoadList();
        }

        /// <summary>
        /// 检查是否允许被访问,并加载页面初始信息
        /// </summary>
        protected void CheckPublicity()
        {
            bool tf = false;
            string s_GroupID = Request.QueryString["GroupID"];
            if (s_GroupID == null || s_GroupID == "")
                PageError("参数传递错误!", "dyangroup.aspx");

            int GroupID = Convert.ToInt32(s_GroupID);
            JuSNS.Home.UserGroup usergroup = new JuSNS.Home.UserGroup();
            JuSNS.Model.UserGroupInfo usergroupinfo = usergroup.Info(GroupID);

            tf = usergroup.CheckPublicity(GroupID, UserID, false);
            if (!tf)
                PageError("您没有访问权限!", "dyangroup.aspx");

            this.H_GroupName.InnerHtml = usergroupinfo.GroupName + "群组成员列表";
            this.ptitle.InnerText = usergroupinfo.GroupName + "群组成员列表";
            this.A_GroupMember.HRef = "groupmember.aspx?GroupID=" + s_GroupID;
            this.A_ReturnGroup.HRef = "group.aspx?GroupID=" + s_GroupID;
            this.P_GroupMemCnt.InnerHtml = usergroupinfo.Members.ToString() + " 个成员";
            this.Hid_GroupID.Value = s_GroupID;
        }

        /// <summary>
        /// 加载分页
        /// </summary>
        /// <param name="PageIndex">当前页数</param>
        protected void LoadList()
        {
            DivPage.Visible = false;
            int r, p, PageIndex = 0;
            PageIndex = Convert.ToInt32(Request.QueryString["Page"]);
            SqlConditionInfo st = new SqlConditionInfo("@GroupID", Hid_GroupID.Value, TypeCode.Int32);
            DataTable dt = JuSNS.Home.UtilPage.GetPage("GroupMember_aspx", PageIndex, 20, out r, out p, st);
            if (dt != null)
            {
                Rpt_GroupMemList.DataSource = dt;
                Rpt_GroupMemList.DataBind();
                dt.Clear();
                dt.Dispose();
            }
            //判断是否调用分页
            if (r > 20)
            {
                DivPage.Visible = true;
                DivPage.InnerHtml = PageNavigator.Pagination(PageIndex, p, "member.aspx?GroupID=" + Hid_GroupID.Value);
            }
        }

        /// <summary>
        /// 取得最新迷你BLOG
        /// </summary>
        /// <param name="UserID">会员编号</param>
        /// <returns></returns>
        protected string getBlog(object userId)
        {
            MiniBlogInfo bloginfo = blog.GetLastInfo(UserID, Convert.ToInt32(userId));
            if (bloginfo.ID > 0)
                return JuSNS.Common.Public.CheckSma(bloginfo.Content) + " <span class=\"time\">" + JuSNS.Common.Public.getTimeSpan(bloginfo.PostTime) + "</span>";
            else
                return string.Empty;
        }

        /// <summary>
        /// 取得会员教育信息
        /// </summary>
        /// <param name="UserID">会员编号</param>
        /// <returns></returns>
        protected string getSchool(object UserID)
        {
            string s_School = "";
            string s_Academy = "";
            string s_DateTime = "";
            JuSNS.Home.User user = new JuSNS.Home.User();
            UserEducationInfo educinfo = new UserEducationInfo();
            educinfo = user.LastEducInfo(Convert.ToInt32(UserID));
            DictSchoolInfo schoolinfo = new DictSchoolInfo();
            schoolinfo = user.GetSchoolInfo(educinfo.SchoolID);

            if (educinfo.DegreeID >= 3 && educinfo.AcademyID != 0)
            {
                DictAcademyInfo AcademyInfo = new DictAcademyInfo();
                AcademyInfo = user.GetAcademyInfo(educinfo.AcademyID);
                s_Academy = " - " + AcademyInfo.Name;
            }
            else
            {
                //s_DateTime = "<a href=\"/SearchUser.aspx?SchoolID=" + educinfo.SchoolID + "&Year=" + educinfo.MatriculationYear + "\">";
            }
            if (educinfo.DegreeID > 0)
            {
                if (educinfo.MatriculationYear > 0)
                {
                    s_School = "<tr><th>" + getDegreeName(educinfo.DegreeID) + "：</th>" +
                               "<td align=\"left\">" + schoolinfo.SchoolName + s_Academy + " " +
                               "<span class=\"time\">(" + educinfo.MatriculationYear.ToString() + "年入学)</span></td></tr>";
                }
                else
                {
                    s_School = "<tr><th>" + getDegreeName(educinfo.DegreeID) + "：</th>" +
                               "<td align=\"left\">" + schoolinfo.SchoolName + s_Academy + " " +
                               "</td></tr>";
                }
            }
            return s_School;
        }

        /// <summary>
        /// 取得学历类型
        /// </summary>
        /// <param name="DegreeID">编号</param>
        /// <returns></returns>
        protected string getDegreeName(int DegreeID)
        {
            string s_DegreeName = "";
            switch (DegreeID)
            {
                case 1:
                    s_DegreeName = "初中";
                    break;
                case 2:
                    s_DegreeName = "高中";
                    break;
                case 3:
                    s_DegreeName = "大学";
                    break;
                case 4:
                    s_DegreeName = "研究生";
                    break;
                case 5:
                    s_DegreeName = "博士";
                    break;
            }
            return s_DegreeName;
        }

        /// <summary>
        /// 取得操作类型 
        /// </summary>
        /// <param name="UID">会员编号</param>
        /// <param name="UserName">会员姓名</param>
        /// <param name="FilePath">头像</param>
        /// <returns></returns>
        protected string getOp(object UID, object UserName, object FilePath)
        {
            string s_Op = "";
            if (Convert.ToInt32(UID) == UserID)
            {
                s_Op = "<li><a href=\"../friend?r=" + UserID + "\">他的好友</a></li>";
            }
            else
            {
                string s_Temp = "";
                switch (friend.GetRelation(UserID, Convert.ToInt32(UID)))
                {
                    case 0:
                        s_Temp = "<li id=\"LI" + UID.ToString() + "\"><a href=\"javascript:void(0);\" " +
                                 "onclick=\"javascript:AddFriend(" + UID.ToString() + ",'" + UserName + "'," +
                                 "'" + this.GetHeadImage(UID) + "','LI" + UID.ToString() + "')\">" +
                                 "加为好友</a></li>";
                        break;
                    case 1:
                        break;
                    case 2:
                        break;
                    case 3:
                        s_Temp = "<li>等待好友验证</li>";
                        break;
                    case 4:
                        s_Temp = "<li id=\"LI" + UID.ToString() + "\"><a href=\"javascript:void(0);\" " +
                                "onclick=\"javascript:AddFriend(" + UID.ToString() + ",'" + UserName + "'," +
                                "'" + this.GetHeadImage(UID, 2) + "','LI" + UID.ToString() + "')\">" +
                                "加为好友</a></li>";
                        break;
                }
                s_Op = "<li><a href=\"javascript:void(0);\" onclick=\"mailto('" + UID.ToString() + "','您好！')\">发送私信</a></li>" +
                       "<li><a href=\"javascript:void(0);\" " +
                       "onclick=\"javascript:Greet(" + UID.ToString() + ",'" + UserName.ToString() + "','" + this.GetHeadImage(UID, 2) + "');\" " +
                       "class=\"complexlink poke-send\">打招呼</a></li>" +
                       "<li><a href=\"../friend?r=" + UID.ToString() + "\">他的好友</a></li>" + s_Temp;
            }
            return s_Op;
        }

    }
}
