public ActionResult registerMember(MM.MemberModel memberModel) { string msg = ""; MM.Member mb = new MM.Member(); msg = mb.registerMember(memberModel); return(Content(msg)); }
public ActionResult loginMember(MM.MemberModel memberModel) { MM.MemberModel mbdata = new MM.MemberModel(); MM.Member mb = new MM.Member(); mbdata = mb.loginMember(memberModel); //儲存seesion userID ,如果沒登入則會存null Session["suserID"] = mbdata.User_ID; Session["suserName"] = mbdata.UserName; return(Json(mbdata)); }
// 新增會員 [ 會員model的attr. 皆為填入項目 ] public string registerMember(MM.MemberModel rMember) { #region [做DB連線 以及 執行DB處理] // 建立DB連線 Tools.DBConnection bsc = new Tools.DBConnection(); // 確認user_ID是否重複 MemberModel mms = memberData(rMember.UserName); if (mms.User_ID != "") { return("重複會員名稱!需換會員名稱"); } // 放入 UserID的資料 string doDB = bsc.ActionDB( string.Format( @"INSERT INTO [Account] (USER_ID,USERNAME,PASSWORD,RE_TIME) VALUES('{0}','{1}','{2}',CURRENT_TIMESTAMP);" , rMember.User_ID, rMember.UserName, rMember.PassWord) ); // 如果 doDB為"success" ,代表DB連線成功 ,反之失敗 if (doDB != "success") { return("DB處理錯誤"); } #endregion #region [檢查DB內容,用 UserName做檢查] // 查看是否新增成功 MemberModel cm = this.memberData(rMember.UserName); // 檢查MemberModel if ((rMember.User_ID == cm.User_ID) && (rMember.UserName == cm.UserName) && (rMember.PassWord == cm.PassWord) ) { return("insert success!"); } else { return("insert error!"); } #endregion }
// 會員功能 登入 [ 會員model的attr. 皆為填入項目 ] public MM.MemberModel loginMember(MM.MemberModel lMember) { MemberModel mm = this.memberData(lMember.UserName); // 檢查MemberModel if ((lMember.UserName == mm.UserName) && (lMember.PassWord == mm.PassWord) ) { System.Diagnostics.Debug.Print("後端登入成功"); return(mm); } else { mm.User_ID = ""; System.Diagnostics.Debug.Print("後端登入失敗"); return(mm); } }
// 使用UserName,瀏覽會員DB資料,也判斷新增/登入是否成功 public MM.MemberModel memberData(string UserName) { MM.MemberModel bMemberModel = new MM.MemberModel(); #region [做DB連線 以及 取出DB資料] // 建立DB連線 Tools.DBConnection bsc = new Tools.DBConnection(); // 取出 會員資料 DataTable dt = bsc.ReadDB( string.Format( @"SELECT * FROM [Account] AS A WHERE 1=1 AND A.USERNAME = '******'" , UserName) ); // 將DataTable的資料轉換為model ,資料行小於0則塞空資料 if (dt.Rows.Count > 0) { bMemberModel.User_ID = dt.Rows[0][0].ToString(); bMemberModel.UserName = dt.Rows[0][1].ToString(); bMemberModel.PassWord = dt.Rows[0][2].ToString(); bMemberModel.Re_Time = dt.Rows[0][3].ToString(); } else { bMemberModel.User_ID = ""; bMemberModel.UserName = ""; bMemberModel.PassWord = ""; bMemberModel.Re_Time = null; } return(bMemberModel); #endregion }