CẤU TRÚC CHƯƠNG TRÌNH ĐƯỢC ÁP DỤNG MÔ HÌNH MVC Chương trình được cấu trúc gồm 3 phần,đúng với cấu trúc của mô hình MVC,gồm các phần như sau: I.View(Interface_Hiển thị): 1.Truy cập vào web: *Login: -phần này người quản lý hệ thống dùng để đăng nhập vào chương trình: *Giao diện: *code: using System; using System.Data; using System.Configuration; using System.Collections; using System.Web; using System.Web.Security; using System.Web.UI; using System.Web.UI.WebControls; using System.Web.UI.WebControls.WebParts; using System.Web.UI.HtmlControls; public partial class Interface_AccessWebsite_login : System.Web.UI.Page { private AccountDB objAccountDB = new AccountDB(); protected void Page_Load(object sender, EventArgs e) { } public string GetApplicationPath() { string applicationPath = ""; if (this.Page.Request.Url != null) applicationPath = this.Page.Request.Url.AbsoluteUri.Substring( 0, this.Request.Url.AbsoluteUri.ToLower().IndexOf( this.Request.ApplicationPath.ToLower(), this.Request.Url.AbsoluteUri.ToLower().IndexOf( this.Page.Request.Url.Authority.ToLower()) + this.Page.Request.Url.Authority.Length) + this.Request.ApplicationPath.Length); return applicationPath; } protected void btnLogin_Click(object sender, EventArgs e) { string strUsername = this.txtUsername.Text; string strPassword = this.txtPassword.Text; AccountDetails objAccountDetails = new AccountDetails(strUsername, strPassword); int intCount = objAccountDB.CheckAccount(objAccountDetails); Session["sesUsername"] = strUsername; Session["sesPassword"] = strPassword; if (intCount == -1) { Response.Write(objAccountDB.ErrorDetail); Response.Write("<br>"); return; } if (intCount != 0) { Response.Redirect(GetApplicationPath() + "/Interface/home.aspx?page=interface/wellcome.aspx"); } Response.Write("don't access right!"); } } a.Danh sách tài khoản: *Giao diện: Code: using System.Web.UI; using System.Web.UI.WebControls; using System.Web.UI.WebControls.WebParts; using System.Web.UI.HtmlControls; public partial class Interface_AccessWebsite_AccountList : System.Web.UI.Page { private AccountDB objAccountDB = new AccountDB(); private AccountDetails[] arrAccountDetails; protected void Page_Load(object sender, EventArgs e) { arrAccountDetails = objAccountDB.GetAllAccounts(); this.grdAccounts.DataSource = arrAccountDetails; grdAccounts.DataBind(); } protected string GetApplicationPath() { string applicationPath = ""; if (this.Page.Request.Url != null) applicationPath = this.Page.Request.Url.AbsoluteUri.Substring( 0, this.Request.Url.AbsoluteUri.ToLower().IndexOf( this.Request.ApplicationPath.ToLower(), this.Request.Url.AbsoluteUri.ToLower().IndexOf( this.Page.Request.Url.Authority.ToLower()) + this.Page.Request.Url.Authority.Length) + this.Request.ApplicationPath.Length); return applicationPath; } protected void grdAccounts_SelectedIndexChanged(object sender, EventArgs e) { } } b.Thay đổi Mật mã: *Giao diện: *Code: public partial class Interface_AccessWebsite_ChangPassword : System.Web.UI.Page { private AccountDB objAccountDB = new AccountDB(); private AccountDetails objAccountDetails = new AccountDetails(); protected void Page_Load(object sender, EventArgs e) { } public string GetApplicationPath() { string applicationPath = ""; if (this.Page.Request.Url != null) applicationPath = this.Page.Request.Url.AbsoluteUri.Substring( 0, this.Request.Url.AbsoluteUri.ToLower().IndexOf( this.Request.ApplicationPath.ToLower(), this.Request.Url.AbsoluteUri.ToLower().IndexOf( this.Page.Request.Url.Authority.ToLower()) + this.Page.Request.Url.Authority.Length) + this.Request.ApplicationPath.Length); return applicationPath; } protected void btnChange_Click(object sender, EventArgs e) { // Check suitable between Password and ConfirmPassword if (this.txtConfirmPassword.Text != this.txtPassword.Text) { this.lblMessage.Text = "Password anh confirm is suitable!"; return; } // Change Password objAccountDetails.Username = (string)Session["sesUsername"]; objAccountDetails.Password = this.txtPassword.Text; int intError = objAccountDB.ChangePassword(objAccountDetails); // check blank pass //if (objAccountDB.ChangePassword(objAccountDetails) == 1 ) //{ // check error if (intError == 0) { this.lblMessage.Text = "Don't use blank password"; return; } else { this.lblMessage.Text = "Password chage successfully!"; return; } } } c.Tạo người dùng mới: *Giao diện: *Code: public partial class Interface_AccessWebsite_CreateUser : System.Web.UI.Page { private AccountDB accdb = new AccountDB(); private AccountDetails accdetail = new AccountDetails(); private Common objCommon = new Common(); protected void Page_Load(object sender, EventArgs e) { } protected void Accept_Click(object sender, EventArgs e) { string _username = this.txtUsername.Text; string _password = this.txtPassword.Text; if (objCommon.CheckEmpty(this.txtUsername.Text) == 1) { Response.Write("Don't use blank Username !"); return; } if (objCommon.CheckEmpty(this.txtPassword.Text) == 1) { Response.Write ("Don't use blank password !"); return; } if (this.txtPassword.Text != this.txtConf.Text) { Response.Write("Password anh confirm is suitable!"); return; } string _administrator; if (CheckBox1.Checked) _administrator = "1"; else _administrator = "0"; AccountDetails accdetail = new AccountDetails(_username, _password, _administrator); int _count = accdb.CheckAccount(_username); if (_count == 0) { Response.Write("Account is not readly!"); int _flag = accdb.InsertAccount(accdetail); if (_flag == 1) { Response.Write("Insert Account is success!"); } else { Response.Write("Insert Account is not success!"); } } else { Response.Write("Account is readly!"); } } } d.Xóa tài khoản: *Giao diện: *Code: public partial class Interface_AccessWebsite_DeleteAcount : System.Web.UI.Page { private AccountDB objAccountDB = new AccountDB(); protected void Page_Load(object sender, EventArgs e) { DialogResult reply; reply = MessageBox.Show("Are you sure ?", "Yes or No Demo", MessageBoxButtons.YesNo, MessageBoxIcon.Question); if (reply == DialogResult.Yes) { int intError = objAccountDB.DeleteAccount(Request.QueryString["username"]); if (intError == 1) { Response.Redirect("~/interface/accesswebsite/AccountList.aspx"); return; } Response.Write(objAccountDB.ErrorDetail); return; } else Response.Redirect("~/interface/accesswebsite/AccountList.aspx"); } e.Chỉnh sửa tài khoản: public partial class Interface_AccessWebsite_EditAccount : System.Web.UI.Page { private AccountDB objAccountDB = new AccountDB(); private AccountDetails objAccountDetails = new AccountDetails(); private Common objCommon = new Common(); protected void Page_Load(object sender, EventArgs e) { objAccountDetails = objAccountDB.GetAccount(Request.QueryString["Username"]); this.txtUsername.Text = objAccountDetails.Username; if (IsPostBack) { if (objAccountDetails.Administrator == "1") { chkAdministrator.Checked = true; } else { chkAdministrator.Checked = false; } } } protected void CheckBox1_CheckedChanged(object sender, EventArgs e) { } protected void btOK_Click(object sender, EventArgs e) { string _username = this.txtUsername.Text; string _password = this.txtPassword.Text; if (objCommon.CheckEmpty(this.txtPassword.Text) == 1) { Response.Write("Dont use Blank Username !!"); } if (this.txtPassword.Text != this.txtConfirmPassword.Text) { Response.Write("Password anh confirm is suitable"); } string _administrator; if (chkAdministrator.Checked) { _administrator = "1"; } else { _administrator = "0"; } AccountDetails accdetail = new AccountDetails(_username, _password, _administrator); int _count = objAccountDB.UpdateAccount(accdetail); if (_count == 0) { Response.Write("Username do not match !"); [...]... objMenuDB.DeleteMenuAccount(Request.QueryString["Username"], Request.QueryString["IDMenu"]); if (intError == 1) { Response.Redirect("~/interface/accesswebsite/EditAccMenu.aspx"); return; } Response.Write("Error"); return; } } II.Model (Mô hình) Gồm AccountDetails (Chi tiết tài khoản), MenuDetails (Chi tiết danh bạ) và EmployeeDetails (Chi tiết nhân viên): *Code: using using using using using using using System; System.Data; System.Configuration; . CẤU TRÚC CHƯƠNG TRÌNH ĐƯỢC ÁP DỤNG MÔ HÌNH MVC Chương trình được cấu trúc gồm 3 phần,đúng với cấu trúc của mô hình MVC, gồm các phần như. vào web: *Login: -phần này người quản lý hệ thống dùng để đăng nhập vào chương trình: *Giao diện: *code: using System; using System.Data; using System.Configuration;