標籤:泛型 基礎 時間 狀態 line txt 指令 jce 返回
using System; //指令+系統(命名空間)
using System.Collections.Generic; // 集合,泛型
using System.Linq; // Language-integrated Query (LINQ) 只有.net 3.5才有 你把項目設定一下為3.5的運行環境
using System.Web; // 引用使用者介面控制項集前必加 system.web
using System.Web.UI; // 供的類和介面使您得以建立將作為使用者介面元素出現在您的 Web 應用程式中的 ASP.NET 伺服器控制項和頁。
using System.Web.UI.WebControls; //命名空間包含一些類,可使用這些類在網頁上建立 Web 伺服器控制項。
using wangshi.common;
using wangshi.data;
public partial class Login : System.Web.UI.Page ////這個是 聲明一個 Login 類,繼承自System.Web.UI.Page,它是一個公用部分類
{
protected void Page_Load(object sender, EventArgs e) // 當然是頁面載入的時候執行了函數!
{
if (!IsPostBack) //IsPostBack 是.net判斷頁面是否第一次載入的屬性,這樣在第一次載入的時候調用下面的函數, 在首次載入後向伺服器提交資料,然後伺服器把處理好的資料傳遞到用戶端並顯示出來,就叫postback.IsPostBack判斷頁面是否是回傳,if(!Ispostback)表示一個頁面只能載入一次,但可以在載入後反覆postback.
{
HttpCookie cookies = Request.Cookies["USER_COOKIE"]; // 從用戶端請求中讀取Cookie
if (cookies != null)
{
//如果Cookie不為空白,則將Cookie裡面的使用者名稱和密碼讀取出來賦值給前台的文字框。
this.txt_username.Text = cookies["UserName"];
//this.txt_password.Attributes.Add("value", cookies["UserPassword"]);
//這裡依然把記住密碼的選項給選中。
this.ckb_rememer.Checked = true;
//開始登入 //建立一個 ws.V3MobileSoapClient()
ws.V3MobileSoapClient client = new ws.V3MobileSoapClient(); //ws:web service SoapClient 就是可以基於SOAP協議訪問webservice的用戶端
//定義一個類型是String的 變數 result,將某個方法的返回結果作為值賦給result; 建立的選擇儲蓄用戶端的資料及互動的分類
string result = client.CheckAccount(cookies["UserName"], cookies["UserPassword"], Opal.CheckTag);
//使用自訂代碼調試
System.Diagnostics.Debug.WriteLine(result);
StateObj _stateObj = JsonTools.GetStateObj(result);
if (_stateObj.Success)
{
BgUserInfo user = (BgUserInfo)JsonTools.ToObj(typeof(BgUserInfo), _stateObj.Memo);
if (user != null && user.Id > 0)
{
Session["opal_user"] = user; //儲存的opal_user" 設定成user
Response.Redirect("Default.aspx"); //跳轉頁面的後台寫法
}
}
}
}
}
protected void btn_login_Click(object sender, EventArgs e) //當點擊 btn_login_Click 時候執行的函數事件
object類型的參數,是頂級類型 e只是一個自訂的變數罷了,它被定義為EventArgs類型
{
if (string.IsNullOrEmpty(txt_username.Text) || string.IsNullOrEmpty(txt_password.Text)) //判斷使用者名稱或密碼是否為空白
{
//ClientScript.RegisterStartupScript用來向前台頁面註冊script指令碼
ClientScript.RegisterStartupScript(this.GetType(), "提醒", "<script>alert(‘請輸入使用者名稱或密碼!‘);<"/script>");
return;
}
//調用web服務
ws.V3MobileSoapClient client = new ws.V3MobileSoapClient();
string result = client.CheckAccount(txt_username.Text, txt_password.Text, Opal.CheckTag);
System.Diagnostics.Debug.WriteLine(result);
if (string.IsNullOrEmpty(result))
{
ClientScript.RegisterStartupScript(this.GetType(), "提醒", "<script>alert(‘使用者名稱或密碼錯誤!‘);<" + "/script>");
}
else
{
StateObj _stateObj = JsonTools.GetStateObj(result);
if (_stateObj.Success)
{
BgUserInfo user = (BgUserInfo)JsonTools.ToObj(typeof(BgUserInfo), _stateObj.Memo);
if (user != null)
{
Session["opal_user"] = user;
HttpCookie cookie = new HttpCookie("USER_COOKIE");
if (ckb_rememer.Checked)
{
//所有的驗證資訊檢測之後,如果使用者選擇的記住密碼,則將使用者名稱和密碼寫入Cookie裡面儲存起來。
cookie.Values.Add("UserName", this.txt_username.Text.Trim());
cookie.Values.Add("UserPassword", this.txt_password.Text.Trim());
//這裡是設定Cookie的到期時間,這裡設定一個星期的時間,過了一個星期之後狀態保持自動清空
cookie.Expires = System.DateTime.Now.AddDays(7.0);
HttpContext.Current.Response.Cookies.Add(cookie);
}
else
{
if (cookie != null)
{
//如果使用者沒有選擇記住密碼,那麼立即將Cookie裡面的資訊情況,並且設定狀態保持立即到期
Response.Cookies["USER_COOKIE"].Expires = DateTime.Now;
}
}
Response.Redirect("Default.aspx");
}
else
{
ClientScript.RegisterStartupScript(this.GetType(), "提醒", "<script>alert(‘" + _stateObj.Msg + "!‘);<" + "/script>");
}
}
else
{
ClientScript.RegisterStartupScript(this.GetType(), "提醒", "<script>alert(‘" + _stateObj.Msg + "!‘);<" + "/script>");
}
}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
就是引用了以上四個名稱空間。
引用的這幾個名稱空間都是.NET架構中的基礎類庫,用於實現一些基本的類。
login.aspx.cs