using System;
using System.Data;
using SK.MemberDAL;

namespace SK.MemberBLL
{
	/// <summary>
	/// MemberSystem 的摘要说明。
	/// </summary>
	public struct MemberInfo
	{
		int _MemberID;
		public int MemberID
		{
			get{return _MemberID;}
			set{_MemberID=value;}
		}
		string _MemberNO;
		public string MemberNO
		{
			get{return _MemberNO;}
			set{_MemberNO=value;}
		}
		string _MemberName;
		public string MemberName
		{
			get{return _MemberName;}
			set{_MemberName=value;}
		}
		string _TrueName;
		public string TrueName
		{
			get{return _TrueName;}
			set{_TrueName=value;}
		}
		string _Password;
		public string Password
		{
			get{return _Password;}
			set{_Password=value;}
		}
		int _Sex;
		public int Sex
		{
			get{return _Sex;}
			set{_Sex=value;}
		}
		string _Email;
		public string Email
		{
			get{return _Email;}
			set{_Email=value;}
		}
		string _Email2;
		public string Email2
		{
			get{return _Email2;}
			set{_Email2=value;}
		}
		int _QuestionID;
		public int QuestionID
		{
			get{return _QuestionID;}
			set{_QuestionID=value;}
		}
		string _Answer;
		public string Answer
		{
			get{return _Answer;}
			set{_Answer=value;}
		}
		DateTime _BirthDay;
		public DateTime BirthDay
		{
			get{return _BirthDay;}
			set{_BirthDay=value;}
		}
		string _Zip;
		public string Zip
		{
			get{return _Zip;}
			set{_Zip=value;}
		}
		int _CountryID;
		public int CountryID
		{
			get{return _CountryID;}
			set{_CountryID=value;}
		}
		int _ProvinceID;
		public int ProvinceID
		{
			get{return _ProvinceID;}
			set{_ProvinceID=value;}
		}
		string _City;
		public string City
		{
			get{return _City;}
			set{_City=value;}
		}
		bool _EmailHasValid;
		public bool EmailHasValid
		{
			get{return _EmailHasValid;}
			set{_EmailHasValid=value;}
		}
		string _EmailValidCode;
		public string EmailValidCode
		{
			get{return _EmailValidCode;}
			set{_EmailValidCode=value;}
		}
		string _Roles;
		public string Roles
		{
			get{return _Roles;}
			set{_Roles=value;}
		}
		int _Point;
		public int Point
		{
			get{return _Point;}
			set{_Point=value;}
		}
		bool _IsDenied;
		public bool IsDenied
		{
			get{return _IsDenied;}
			set{_IsDenied=value;}
		}
		DateTime _RegTime;
		public DateTime RegTime
		{
			get{return _RegTime;}
			set{_RegTime=value;}
		}

		int _CompanyMemberID;
		public int CompanyMemberID
		{
			get{return _CompanyMemberID;}
			set{_CompanyMemberID=value;}
		}

		bool _IsCompany;
		public bool IsCompany
		{
			get{return _IsCompany;}
			set{_IsCompany=value;}
		}
	}
	public class MemberSystem
	{
		Member member = new Member();
		public MemberSystem()
		{
			//
			// TODO: 在此处添加构造函数逻辑
			//
		}
		public void Add(object MemberNO,object MemberName,object TrueName,object Password,object Sex,object Email,
			object Email2,object QuestionID,object Answer,object BirthDay,object Zip,object CountryID,
			object ProvinceID,object City,object EmailHasValid,object EmailValidCode)
		{
			MainSystem main = new MainSystem();
			member.Add(MemberNO,MemberName,TrueName,Password,Sex,Email,
				Email2,QuestionID,Answer,BirthDay,Zip,CountryID,
				ProvinceID,City,EmailHasValid,EmailValidCode,main.GetValue("RegPoint"));
		}
		public int Count()
		{
			return member.Count();
		}
		public int Count_Today()
		{
			return member.Count_Today();
		}
		public void Update(object MemberID,object MemberNO,object MemberName,object TrueName,object Sex,
			object Email2,object QuestionID,object Answer,object BirthDay,object Zip,object CountryID,
			object ProvinceID,object City,object Tel)
		{
			member.Update(MemberID,MemberNO,MemberName,TrueName,Sex,Email2,QuestionID,Answer,BirthDay,Zip,CountryID,ProvinceID,City,Tel);
		}
		public void Update(object MemberID,object MemberNO,object MemberName,object TrueName,object Sex,
			object Email2,object QuestionID,object Answer,object BirthDay,object Zip,object CountryID,
			object ProvinceID,object City,object Point,object Score,object IsDenied)
		{
			member.Update(MemberID,MemberNO,MemberName,TrueName,Sex,Email2,QuestionID,Answer,BirthDay,Zip,CountryID,ProvinceID,City,Point,Score,IsDenied);
		}
		public DataRow Info(object MemberID)
		{
			return member.Info(MemberID);
		}

		

		public bool MemberHasCompany(object MemberID)
		{
			return member.MemberHasCompany(MemberID);
		}

		public MemberInfo Info_Struct(object MemberID)
		{
			DataRow dr = member.Info(MemberID);
			
			MemberInfo info = new MemberInfo();
			if(dr!=null)
			{
				info.MemberID = Convert.ToInt32(dr["MemberID"]);
				info.MemberName = dr["MemberName"].ToString();
				info.TrueName = dr["TrueName"].ToString();
				info.Email = dr["Email"].ToString();
				info.Email2 = dr["Email2"].ToString();
				info.Password = dr["Password"].ToString();
				info.QuestionID = dr.IsNull("QuestionID")?0:Convert.ToInt32(dr["QuestionID"]);
				info.Answer = dr["Answer"].ToString();
				info.BirthDay = Convert.ToDateTime(dr["BirthDay"]);
				info.CountryID = dr.IsNull("CountryID")?0:Convert.ToInt32(dr["CountryID"]);
				info.ProvinceID = dr.IsNull("ProvinceID")?0:Convert.ToInt32(dr["ProvinceID"]);
				info.City = dr["City"].ToString();
				info.Sex = Convert.ToInt16(dr["sex"]);
				info.Point = Convert.ToInt32(dr["Point"]);
				info.RegTime = Convert.ToDateTime(dr["RegTime"]);
				info.Roles = dr["Roles"].ToString();
				info.Zip = dr["Zip"].ToString();
				info.EmailHasValid = Convert.ToBoolean(dr["EmailHasValid"]);
				info.EmailValidCode = dr["EmailValidCode"].ToString();
				info.IsDenied = Convert.ToBoolean(dr["IsDenied"]);
				
				try
				{
					info.CompanyMemberID = Convert.ToInt32(dr["CompanyMemberID"]);
					info.IsCompany = Convert.ToBoolean(dr["IsCompany"]);
				}
				catch
				{
				
				}
			}
			
			return info;
		}
		/// <summary>
		/// 登录验证
		/// </summary>
		/// <param name="MemberName"></param>
		/// <param name="Password"></param>
		/// <returns></returns>
		public object Login(object MemberName,object Password)
		{
			if(member.Exists_MemberName(MemberName)==null)
				return DBNull.Value;
			return member.Login(MemberName,Password);
		}
		public object Login_MD5(object MemberName,object Password)
		{
			return member.Login_MD5(MemberName,Password);
		}
		/// <summary>
		/// 重设密码
		/// </summary>
		/// <param name="MemberID">会员编号</param>
		/// <param name="Password">密码</param>
		public void UpdatePassword(object MemberID,object Password)
		{
			member.UpdatePassword(MemberID,Password);
		}
		public void UpdatePassword_MD5(object MemberID,object Password)
		{
			member.UpdatePassword_MD5(MemberID,Password);
		}
		public DataRow Info_Name(object MemberName)
		{
			return member.Info_Name(MemberName);
		}
		public void UpdatePoint(object MemberID,object Point)
		{
			member.UpdatePoint(MemberID,Point);
		}
		public void UpdateCompany(object MemberID,object IsCompany)
		{
			member.UpdateCompany(MemberID,IsCompany);
		}

		public void UpdateCompanyID(object MemberName,object CompanyID)
		{
			member.UpdateCompanyID(MemberName,CompanyID);
		}
		/// <summary>
		/// 搜索包含指定关键字的用户
		/// </summary>
		/// <param name="MemberName">关键字</param>
		/// <param name="PageSize">每页显示记录数</param>
		/// <param name="PageIndex">页号</param>
		/// <returns></returns>
		public DataSet Search(object MemberName,object PageSize,object PageIndex)
		{
			MainSystem main = new MainSystem();
			return member.Search(MemberName,PageSize,PageIndex);
		}
		/// <summary>
		/// 返回指定关键字的用户数量
		/// </summary>
		/// <param name="MemberName">关键字</param>
		/// <returns></returns>
		public int Search_Count(object MemberName)
		{
			return member.Search_Count(MemberName);
		}
		/// <summary>
		/// 删除用户
		/// </summary>
		/// <param name="MemberID">编号</param>
		public void Delete(object MemberID)
		{
			member.Delete(MemberID);
		}
		public void Delete_MemberName(object MemberName)
		{
			member.Delete_MemberName(MemberName);
		}
		public void Deduct_Point(object MemberID,object Point,object Remark)
		{
			member.Deduct_Point(MemberID,Point,Remark);
		}
		public object Exists_MemberName(object MemberName)
		{
			return member.Exists_MemberName(MemberName);
		}
		public bool Exists_Email(object Email)
		{
			return member.Exists_Email(Email);
		}
		public bool EmailValidCode_Right(object MemberID,object EmailValidCode)
		{
			return member.EmailValidCode_Right(MemberID,EmailValidCode);
		}
		public void ActiveEmail(object MemberID)
		{
			member.ActiveEmail(MemberID);
		}
		public void SetRoles(object MemberID,object Roles)
		{
			member.SetRoles(MemberID,Roles);
		}
		public bool LoginOK(object MemberName,object Password)
		{
			return member.Login(MemberName,Password)!=DBNull.Value;
		}
		public DataSet ManagerList()
		{
			return member.ManagerList();
		}
		public string MemberName(object MemberID)
		{
			return member.MemberName(MemberID);
		}
		public void AddPoint(object Point)
		{
			member.AddPoint(Point);
		}
		public void Score2Point(object MemberID,object Score,object Score2Point)
		{
			member.Score2Point( MemberID, Score, Score2Point);
		}
		public DataSet MemberList(object MemberName)
		{
			return member.MemberList(MemberName);

		}
		public DataSet MemberList_Company()
		{
			return member.MemberList_Company();
		}

		public DataSet MemberList_Member()
		{
			return member.MemberList_Member();
		}

		public DataSet CompanyHadMember(object MemberID)
		{
			return member.CompanyHadMember(MemberID);
		}
	}
}
