using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Collections.Generic;
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.Home;
using JuSNS.UI.Control;
using JuSNS.Common;

namespace JuSNS.Web.home.ram
{
    public partial class city : JuSNS.UI.Page.UserPage
    {
        JuSNS.Home.User us = new JuSNS.Home.User();
        JuSNS.Home.Friend frd = new Friend();
        protected int nid = 0;
        protected string areanm = string.Empty;
        public bool isS = false;
        public string cName = string.Empty;
        protected void Page_Load(object sender, EventArgs e)
        {
            UserInfo ui = us.GetUserInfo(this.GetUserID());
            string r = Request.QueryString["r"];
            if (r != null && r != string.Empty)
            {
                nid = int.Parse(r);
            }
            else
            {
                nid = ui.City;
                r = ui.City.ToString();
            }
            JuSNS.Home.Dict dct = new Dict();
            areanm = dct.GetAreaName(nid);
            BindData();
            DataBind();
             Dict dict = new Dict();
             int pID = dict.GetParentCity(nid);
            this.oCity.InnerHtml = GetCityList(pID);
        }

        protected string  GetCityList(int rnid)
        {
            Dict dict = new Dict();
            string lists = string.Empty;
            IList<DictAreaInfo> list = dict.CityList(rnid);
            foreach (DictAreaInfo info in list)
            {
                if (nid == info.ID)
                {
                    cName = info.Name;
                    lists += "<li class=\"current\"><a href=\"../ram?r=" + info.ID + "\">" + info.Name + "</a></li>";
                }
                else
                {
                    lists += "<li><a href=\"../ram?r=" + info.ID  + "\">" + info.Name + "</a></li>";
                }
            }
            return "<ul class=\"acbg\">" + lists + "</ul>";
        }

        /// <summary>
        /// 分页绑定数据
        /// </summary>
        protected void BindData()
        {
            DataTable dt = us.GetUserByNetwork(PAGESZ, nid, this.GetUserID(), 1);
            this.RptData.DataSource = dt;
            this.RptData.DataBind();
        }
        /// <summary>
        /// 取得心情日记信息
        /// </summary>
        /// <param name="userid"></param>
        /// <returns></returns>
        protected string GetLastMiniBlog(object content, object time)
        {
            if (content != null && content != DBNull.Value && content.ToString().Trim() != string.Empty)//(info.ID > 0)
            {
                return Public.CheckSma(Input.HtmlDecode(content.ToString())) + " <span class=\"time\">" + Public.getTimeSpan((DateTime)time);
            }
            else
            {
                return string.Empty;
            }
        }
        /// <summary>
        /// 取简历
        /// </summary>
        /// <param name="uid"></param>
        /// <returns></returns>
        protected string GetResume(object Company, object JoinYear, object JoinMonth, object LeaveYear, object LeaveMonth)
        {
            if (Company != null && Company != DBNull.Value && Company.ToString().Trim() != string.Empty)
            {
                string s = "<div class=\"cpstr\">" + Company + "<span class=\"time\">(" + JoinYear + "-" + JoinMonth + " - ";
                if (LeaveYear == DBNull.Value || LeaveMonth == DBNull.Value)
                    s += "现在";
                else
                    s += LeaveYear + "-" + LeaveMonth;
                s += ")</span></div>";
                return s;
            }
            else
            {
                return string.Empty;
            }
        }
        /// <summary>
        /// 取学习经历
        /// </summary>
        /// <param name="uid"></param>
        /// <returns></returns>
        protected string GetSchoolWork(object SchlDegreeID, object SchlMatriculationYear, object SchoolName, object SchlAcdName)
        {
            if (SchlDegreeID != null && SchlDegreeID != DBNull.Value && SchoolName != null && SchoolName != DBNull.Value && SchoolName.ToString().Trim() != string.Empty)
            {
                string s = "<div class=\"cpstr\">" + EnumClass.GetEduGradeName((EnumStudyGrade)SchlDegreeID) + "：" + SchoolName + " - " + SchlAcdName;
                if (SchlMatriculationYear != DBNull.Value && (int)SchlMatriculationYear > 0)
                    s += " <span class=\"time\">(" + SchlMatriculationYear + "年入学)</span>";
                s += "</div>";
                return s;
            }
            else
            {
                return string.Empty;
            }
        }
        protected string AddFriend(object uid, object unm, object upic)
        {
            string ret = string.Empty;
            int usid = Convert.ToInt32(uid);
            if (usid != this.GetUserID())
            {
                int n = frd.GetRelation(this.GetUserID(), usid);
                if (n == 0)//无任何关系
                {
                    ret = "<li id=\"li_req_" + usid + "\"><a href=\"javascript:void(0);\" onclick=\"AddFriend(" + usid + ",'" + unm + "','" + upic + "','li_req_" + uid + "');\" class=\"complexlink friend-add\">加为好友</a></li>\r\n";
                }
                else if (n == 3)//已发出好友申请,等待确认好友申请
                {
                    ret = "<li>等待验证</li>";
                }
                else if (n == 4)//4被申请
                {
                    ret = "<li><a href=\"../friend/req.aspx\" class=\"complexlink friend-add\">处理请求</a></li>";
                }
            }
            return ret;
        }
    }
}
