namespace FourTypesApp
{
// IDisposable 를 상속받아 클래스를 작성
public class MEMBER : IDisposable
{
// Properties
private int userid;
private string username;
private int generation;
private string gender;
private int typeid;
private short dryscore;
private short hotscore;
private short coldscore;
private short humidscore;
// Dispose 상태인지 아닌지 확인하기 위한 변수
private bool isDispose = false;
// 메모리에 객체를 띄우기 위한 컴포넌트 생성
private Component component = new Component();
// get, set Metchod
public int UserId
{
get { return this.userid; }
set { this.userid = value; }
}
public string UserName
{
get {return this.username; }
set {this.username = value; }
}
public int Generation
{
get { return this.generation; }
set { this.generation = value; }
}
public string Gender
{
get { return this.gender; }
set { this.gender = value; }
}
public int TypeId
{
get { return this.typeid; }
set { this.typeid = value; }
}
public short DryScore
{
get { return this.dryscore; }
set { this.dryscore = value; }
}
public short HotScore
{
get { return this.hotscore; }
set { this.hotscore = value; }
}
public short ColdScore
{
get { return this.coldscore; }
set { this.coldscore = value; }
}
public short HumidScore
{
get { return this.humidscore; }
set { this.humidscore = value; }
}
// destructor
~MEMBER()
{
if (!isDispose)
{
Dispose();
}
}
// Dispose를 오버로딩 해서 재정의 한다. 컴포넌트를 소멸시켜 줌.
public void Dispose()
{
isDispose = true;
component.Dispose();
component = null;
GC.SuppressFinalize(this);
}
// LOGIN 처리
public MEMBER login(string UserName, string PassWord)
{
try
{
using (var model = new FourTypesModel())
{
// 모델로부터 users 테이블의 값을 가져와서 사용자명과 패스워드가 일치하는 항목의 id값을 가져온다.
var targetUserId = model.users
.Where(user => user.username == UserName)
.Where(user => user.password == PassWord)
.Select(user => user.id)
.FirstOrDefault();
if (targetUserId == 0)
{
// 일치하는 항목이 없는 경우에는 null을 리턴해서 에러출력.
return null;
}
else
{
// 타겟이 되는 사용자id를 가지고 두 테이블을 내부결합 한 후 값을 변수에 담는다.
// query 는 생략.
// var query = model.users.Join(........);
userid = query.userid;
username = query.username;
generation = query.generation;
gender = query.gender;
typeid = query.typeid;
dryscore = (short)query.dryscore;
hotscore = (short)query.hotscore;
humidscore = (short)query.humidscore;
coldscore = (short)query.coldscore;
}
}
// MEMBER객체를 반환한다.
return this;
}
catch (Exception)
{
// 에러인 경우에는 오류처리
throw;
}
}
}
}
댓글
댓글 쓰기