using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using JuSNS.Factory;
using JuSNS.Model;
using JuSNS.Config;

namespace JuSNS.Home
{
    public class User
    {
        JuSNS.Factory.IUser dal;
        public User()
        {
            dal = DataAccess.CreateUser();
        }

        /// <summary>
        /// 判断信箱是否已经注册
        /// </summary>
        /// <param name="UserEmail">用户Email</param>
        /// <returns></returns>
        public bool IsExist(string UserEmail)
        {
            return dal.IsExist(UserEmail);
        }
        /// <summary>
        /// 用户注册
        /// </summary>
        /// <param name="ui">用户对象</param>
        /// <returns>所影响的行数</returns>
        public EnumRegister Register(UserInfo ui, UserBasicInfo bi)
        {
            return dal.Register(ui, bi);
        }

        /// <summary>
        /// 注册确认,验证后同时设置最后登录
        /// </summary>
        /// <param name="code"></param>
        /// <param name="userId"></param>
        /// <param name="userName"></param>
        /// <param name="md5Password"></param>
        /// <returns>0成功,-1验证码不正确,-2该用户已通过验证,-3数据修改失败</returns>
        public int RegisterConfirm(string code, string email, out int userId, out string userName, out string md5Password)
        {
            return dal.RegisterConfirm(code, email, out  userId, out  userName, out  md5Password);
        }

        /// <summary>
        /// 激活电子邮件
        /// </summary>
        /// <param name="email"></param>
        /// <returns></returns>
        public int EmailActive(string email, UserInfo ui)
        {
            return dal.EmailActive(email, ui);
        }

        /// <summary>
        /// 邀请用户注册
        /// </summary>
        /// <param name="ui"></param>
        /// <param name="code"></param>
        /// <returns></returns>
        public EnumRegister InviterRegister(UserInfo ui,UserBasicInfo bi, EnumFriendInviteMode mode, string code, out int userId)
        {
            return dal.InviterRegister(ui, bi, mode, code, out userId);
        }
        /// <summary>
        /// 退出
        /// </summary>
        /// <param name="Email">用户Email</param>
        /// <returns></returns>
        public int Exit(int userID)
        {
            return dal.Exit(userID);
        }

        /// <summary>
        /// 修改Email
        /// </summary>
        /// <param name="UserID">用户ID</param>
        /// <param name="Email">新Email</param>
        /// <returns></returns>
        public int ChangeEmail(int UserID, string Email)
        {
            return dal.ChangeEmail(UserID, Email);
        }
        /// <summary>
        /// 修改密码
        /// </summary>
        /// <param name="UserID">用户ID</param>
        /// <param name="Password">新Password</param>
        /// <returns></returns>
        public int ChangePassword(int UserID, string Password)
        {
            return dal.ChangePassword(UserID, Password);
        }
        /// <summary>
        /// 修改所在地
        /// </summary>
        /// <param name="UserID">用户ID</param>
        /// <param name="Province">省份</param>
        /// <param name="City">城市</param>
        /// <returns></returns>
        public int ChangeAddr(int UserID, int Province, int City)
        {
            return dal.ChangeAddr(UserID, Province, City);
        }
        /// <summary>
        /// 保存MSN
        /// </summary>
        /// <param name="UserID">用户ID</param>
        /// <param name="MSN">MSN帐号</param>
        /// <returns></returns>
        public int ChangeMSN(int UserID, string MSN)
        {
            return dal.ChangeMSN(UserID, MSN);
        }
        /// <summary>
        /// 保存GTalk
        /// </summary>
        ///  <param name="UserID">用户ID</param>
        /// <param name="MSN">GTalk帐号</param>
        /// <returns></returns>
        public int ChangeGTalk(int UserID, string GTalk)
        {
            return dal.ChangeGTalk(UserID, GTalk);
        }
        /// <summary>
        /// 保存Mobile
        /// </summary>
        /// <param name="UserID">用户ID</param>
        /// <param name="MSN">Mobile帐号</param>
        /// <returns></returns>
        public int ChangeMobile(int UserID, string Mobile)
        {
            return dal.ChangeMobile(UserID, Mobile);
        }

        #region 检查登录
        /// <summary>
        /// 登录
        /// </summary>
        /// <param name="Email">用户Email</param>
        /// <param name="Password">密码</param>
        /// <returns></returns>
        public EnumLoginState Login(string email, string password, out int userId, out string userName, out string portrait,out int loginNum)
        {
            return dal.Login(email, password, out userId, out userName, out portrait,out loginNum);
        }

        /// <summary>
        /// 检查登录
        /// </summary>
        /// <param name="userId"></param>
        /// <param name="password"></param>
        /// <returns></returns>
        public EnumLoginState CheckLogin(int userId, string password)
        {
            int loginNum = 0;
            return CheckLogin(userId, password, out loginNum);
        }

        /// <summary>
        /// 检查登录
        /// </summary>
        /// <param name="userId"></param>
        /// <param name="password"></param>
        /// <returns></returns>
        public EnumLoginState CheckLogin(int userId, string password, out int loginNum)
        {
            return dal.CheckLogin(userId, password,out loginNum);
        }
        #endregion

        /// <summary>
        /// 取回密码申请
        /// </summary>
        /// <param name="Email">Email</param>
        /// <returns>0,成功,-2,邮箱无效</returns>
        public int Retrieve(string email)
        {
            return dal.Retrieve(email);
        }

        /// <summary>
        /// 重设密码,并修改最后登录时间
        /// </summary>
        /// <param name="email"></param>
        /// <param name="newPwd"></param>
        /// <param name="code"></param>
        /// <returns>0成功，-1没有找到相关的申请记录,-2该申请已完成重设而无效,-3邮箱无效</returns>
        public int ResetPwd(string email, string newPwd, string code, out int userId, out string userName, out string userPortrait)
        {
            return dal.ResetPwd(newPwd, code, out userId, out userName, out userPortrait);
        }

        public bool getRestPwdRecord(string r, string email)
        {
            return dal.getRestPwdRecord(r, email);
        }

        /// <summary>
        /// 获取用户实体类
        /// </summary>
        /// <param name="UserID">用户ID</param>
        /// <returns></returns>
        public UserInfo GetUserInfo(int UserID)
        {
            return dal.GetUserInfo(UserID);
        }
        /// <summary>
        /// 获取用户基本信息实体类
        /// </summary>
        /// <param name="UserID">用户ID</param>
        /// <returns></returns>
        public UserBasicInfo GetUserBasic(int UserID)
        {
            return dal.GetUserBasic(UserID);
        }
        #region
        //编辑（个人信息）
        //编辑（个人信息）
        /// <summary>
        /// 保存基本信息
        /// </summary>
        /// <param name="ubi">用户基本信息对象</param>
        /// <returns></returns>
        public int SaveBasic(JuSNS.Model.UserBasicInfo ubi, int Province, int City)
        {
            return dal.SaveBasic(ubi, Province, City);
        }

        /// <summary>
        /// 保存教育信息
        /// </summary>
        /// <param name="listEdu">教育信息对象数组</param>
        /// <returns></returns>
        public int SaveEducation(List<JuSNS.Model.UserEducationInfo> listEdu)
        {
            return dal.SaveEducation(listEdu);
        }
        /// <summary>
        /// 保存工作信息
        /// </summary>
        /// <param name="listCareer">工作信息对象数组</param>
        /// <returns></returns>
        public int SaveCareer(List<JuSNS.Model.UserCareerInfo> listCareer)
        {
            return dal.SaveCareer(listCareer);
        }
        /// <summary>
        /// 删除工作信息
        /// </summary>
        /// <param name="ID">工作信息ID</param>
        /// <returns></returns>
        public int DelCareer(int ID)
        {
            return dal.DelCareer(ID);
        }
        /// <summary>
        /// 获取隐私及个人动态设置类实例
        /// </summary>
        /// <param name="UserID">用户ID</param>
        /// <returns></returns>
        public UserSettingInfo GetUSetInfo(int UserID)
        {
            return dal.GetUSetInfo(UserID);
        }

        #endregion
        #region 取得用户一些相关的信息
        /// <summary>
        /// 取得用户的教育信息
        /// </summary>
        /// <param name="userid">查看者ID</param>
        /// <param name="friendid">被查看者ID</param>
        /// <returns></returns>
        public DataTable GetEducation(int userid, int friendid)
        {
            return dal.GetEducation(userid, friendid);
        }
        /// <summary>
        /// 取得工作相关的信息
        /// </summary>
        /// <param name="userid">查看者ID</param>
        /// <param name="friendid">被查看者ID</param>
        /// <returns></returns>
        public DataTable GetCareer(int userid, int friendid)
        {
            return dal.GetCareer(userid, friendid);
        }
        #endregion

        /// <summary>
        /// 取得用户最高教育相关信息
        /// </summary>
        /// <param name="UserID">会员编号</param>
        /// <returns></returns>
        public UserEducationInfo LastEducInfo(int UserID)
        {
            return dal.LastEducInfo(UserID);
        }

        /// <summary>
        /// 取得学校信息
        /// </summary>
        /// <param name="SchoolID">学校编号</param>
        /// <returns></returns>
        public DictSchoolInfo GetSchoolInfo(int SchoolID)
        {
            return dal.GetSchoolInfo(SchoolID);
        }

        /// <summary>
        /// 取得院系信息
        /// </summary>
        /// <param name="AcademyID">院系编号</param>
        /// <returns></returns>
        public DictAcademyInfo GetAcademyInfo(int AcademyID)
        {
            return dal.GetAcademyInfo(AcademyID);
        }
        /// <summary>
        /// 随机取出某一网络的用户
        /// </summary>
        /// <param name="topNum"></param>
        /// <param name="networkId"></param>
        /// <returns></returns>
        public DataTable GetUserByNetwork(int topNum, int networkId, int userId,int f)
        {
            return dal.GetUserByNetwork(topNum, networkId, userId, f);
        }

        /// <summary>
        /// 取得隐私信息
        /// </summary>
        /// <param name="UserID">用户ID信息</param>
        /// <returns></returns>
        public PrivacyInfo GetPrivacy(int UserID)
        {
            return dal.GetPrivacy(UserID);
        }
        /// <summary>
        /// 设置隐私信息
        /// </summary>
        /// <param name="UserID">用户ID</param>
        /// <param name="privacyinfo">隐私信息</param>
        /// <returns></returns>
        public int SetPrivacy(int UserID, PrivacyInfo privacyinfo)
        {
            return dal.SetPrivacy(UserID, privacyinfo);
        }

        /// <summary>
        /// 更新用户
        /// </summary>
        /// <param name="us">实例类</param>
        /// <param name="UserID">会员编号</param>
        /// <returns></returns>
        public int UpdateUser(JuSNS.Model.UserInfo us, int UserID)
        {
            return dal.UpdateUser(us, UserID);
        }

        /// <summary>
        /// 更新积分，金币及访问次数
        /// </summary>
        /// <param name="UserID"></param>
        /// <param name="integral"></param>
        /// <param name="inteyb"></param>
        /// <param name="Click"></param>
        /// <returns></returns>
        public int UpdateBer(int UserID, int integral, int inteyb, int Click)
        {
            return dal.UpdateBer(UserID, integral, inteyb, Click);
        }
        /// <summary>
        /// 删除会员
        /// </summary>
        /// <param name="UserID"></param>
        /// <returns></returns>
        public int DelUser(int UserID, int flag)
        {
            return dal.DelUser(UserID,flag);
        }

        /// <summary>
        /// 删除所有会员
        /// </summary>
        /// <param name="UserID"></param>
        /// <returns></returns>
        public int DelUserAll()
        {
            return dal.DelUserAll();
        }

        /// <summary>
        /// 更新会员基本信息
        /// </summary>
        /// <param name="info"></param>
        /// <returns></returns>
        public int UpdateUserBase(UserBasicInfo info)
        {
            return dal.UpdateUserBase(info);
        }

        /// <summary>
        /// 修改会员联系信息可见度
        /// </summary>
        /// <param name="ub"></param>
        /// <returns></returns>
        public int UpdateUserPrivacy(UserBasicInfo ub)
        {
            return dal.UpdateUserPrivacy(ub);
        }

        /// <summary>
        /// 删除学校
        /// </summary>
        /// <param name="ID"></param>
        /// <returns></returns>
        public int DelEducation(int ID)
        {
            return dal.DelEducation(ID);
        }

        /// <summary>
        /// 根据ID读取教育信息
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public DataTable getEducationByID(int id)
        {
            return dal.getEducationByID(id);
        }

        /// <summary>
        /// 根据ID读取教育信息
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public DataTable getCareerByID(int id)
        {
            return dal.getCareerByID(id);
        }

        /// <summary>
        /// 锁定、解锁教育信息
        /// </summary>
        /// <param name="ID"></param>
        /// <returns></returns>
        public int LockEducation(int ID, int value)
        {
            return dal.LockEducation(ID, value);
        }


        /// <summary>
        /// 锁定、解锁、删除地区信息
        /// </summary>
        /// <param name="ID">地区编号</param>
        /// <param name="value"></param>
        /// <param name="flag"></param>
        /// <returns></returns>
        public int LockDelArea(int ID, int value, int flag)
        {
            return dal.LockDelArea(ID, value, flag);
        }

        /// <summary>
        /// 添加、修改地区信息
        /// </summary>
        /// <param name="ID">地区编号</param>
        /// <param name="name"></param>
        /// <param name="flag"></param>
        /// <returns></returns>
        public int UpdateAddArea(int ID, int ParentID, string name, int flag)
        {
            return dal.UpdateAddArea(ID, ParentID, name, flag);
        }

        /// <summary>
        /// 判断地区有几级
        /// </summary>
        /// <param name="ParentID"></param>
        /// <returns></returns>
        public int getArea(int ParentID)
        {
            return dal.getArea(ParentID);
        }

        #region 邀请用户注册相关
        /// <summary>
        /// 取得邀请相关信息
        /// </summary>
        /// <param name="code"></param>
        /// <param name="mode">1为email邀请,2为</param>
        /// <param name="friends">好友列表</param>
        /// <returns></returns>
        public InviteInfo GetInviteInfo(string code, EnumFriendInviteMode mode, out Dictionary<string, string> friends)
        {
            return dal.GetInviteInfo(code, mode, out friends);
        }
        #endregion

        /// <summary>
        /// 判断用户是否存在
        /// </summary>
        /// <param name="UserId"></param>
        public bool CheckUser(int UserId)
        {
            return dal.CheckUser(UserId);
        }

        public int GetUserCity(int UserID)
        {
            return dal.GetUserCity(UserID);
        }



        /// <summary>
        /// 取得最大的USerID
        /// </summary>
        /// <returns></returns>
        public int GetMaxUserID()
        {
            return dal.GetMaxUserID();
        }

        /// <summary>
        /// 获取邀请注册的
        /// </summary>
        /// <param name="UserID"></param>
        /// <returns></returns>
        public void GetInvReg(int UserID)
        {
            dal.GetInvReg(UserID);
        }

        /// <summary>
        /// 增加积分或者金币
        /// </summary>
        /// <param name="UserID">用户ID</param>
        /// <param name="Point">增加数量单位</param>
        /// <param name="Flag">0积分，1金币</param>
        /// <param name="ifoat">0增加，1减少</param>
        /// <param name="Content">描述</param>
        public void updateinte(int UserID, int Point, int Flag, int ifoat, string Content)
        {
            dal.updateinte(UserID, Point, Flag, ifoat, Content);
        }

        public IDataReader GetUserPoint(int UserID)
        {
            return dal.GetUserPoint(UserID);
        }

        public DataTable SearchPointHistoryPage(int UserID,string sTime, string eTime, int PageIndex, int PageSize, out int RecordCount, out int PageCount)
        {
            return dal.SearchPointHistoryPage(UserID,sTime, eTime, PageIndex, PageSize, out RecordCount, out PageCount);
        }
        /// <summary>
        /// 取得用户名
        /// </summary>
        /// <param name="userid">用户ID</param>
        /// <returns></returns>
        public string GetUserName(int userid)
        {
            return dal.GetUserName(userid);
        }
        /// <summary>
        /// 取得用户性别
        /// </summary>
        /// <param name="userid"></param>
        /// <returns></returns>
        public int GetUserSex(int userid)
        {
            return dal.GetUserSex(userid);
        }
        /// <summary>
        /// 取得头像名称
        /// </summary>
        /// <param name="userid"></param>
        /// <returns></returns>
        public string GetUserHeadPic(int userid)
        {
            return dal.GetUserHeadPic(userid);
        }

        /// <summary>
        /// 删除用户高级操作。
        /// </summary>
        /// <param name="UserID"></param>
        /// <param name="Type"></param>
        /// <returns></returns>
        public int DelUserAdv(int UserID, string Type)
        {
            return dal.DelUserAdv(UserID, Type);
        }

        public int DelAllAdv(string Type)
        {
            return dal.DelAllAdv(Type);
        }
        /// <summary>
        /// 删除用户高级操作(评论)。
        /// </summary>
        /// <param name="UserID"></param>
        /// <param name="Type"></param>
        /// <returns></returns>
        public int DelUserCommAdv(int UserID, string Type)
        {
            return dal.DelUserCommAdv(UserID, Type);
        }

        public int InserDefaultFriend(int UserID)
        {
            return dal.InserDefaultFriend(UserID);
        }
    }

}