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)
"/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 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;
{
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!");
}
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;
}
}
}
Response.Write("Username do not match !");
}
else
{
int _flag = objAccountDB.UpdateAccount(accdetail);
if (_flag == 1)
{
Response.Write("Update success");
return;
}
else
{
Response.Write("Update Account is not success!");
}
}
}
protected void chkAdministrator_CheckedChanged(object sender, EventArgs e)
{
}
}
2.Nhân viên:
a.Xóa nhân viên:
*Giao diện:
*Code:
using System;
using System.Data;
using System.Configuration;
using System.Collections;
EmployeeDB objEmployeeDB = new EmployeeDB();
EmployeeDetails objEmployeeDetails = new EmployeeDetails();
SetRangOfList(lstDayOfDateOfBirth, 1, 31);
SetRangOfList(lstDayOfEndDate, 1, 31);
SetRangOfList(lstDayOfIssuedDate, 1, 31);
SetRangOfList(lstDayOfProbEnd, 1, 31);
SetRangOfList(lstDayOfStartDate, 1, 31);
SetRangOfList(lstMonthOfDateOfBirth, 1, 12);
SetRangOfList(lstMonthOfEndDate, 1, 12);
SetRangOfList(lstMonthOfIssuedDate, 1, 12);
SetRangOfList(lstMonthOfStartDate, 1, 12);
SetRangOfList(lstMonthOfProbEnd, 1, 12);
SetRangOfList(lstYearOfDateOfBirth, 1970, 2007);
SetRangOfList(lstYearOfEndDate, 2000, 2020);
SetRangOfList(lstYearOfProbEnd, 2000, 2020);
SetRangOfList(lstYearOfStartDate, 2000, 2020);
SetRangOfList(lstYearOfIssuedDate, 2000, 2020);
objEmployeeDetails =
objEmployeeDB.GetEmployee(Request.QueryString["employeeID"]);
if(!IsPostBack) {
if (objEmployeeDB.Error == 0)
{
this.txtEmployeeID.Text = objEmployeeDetails.EmployeeID;
this.txtFirstName.Text = objEmployeeDetails.FirstName;
this.txtLastName.Text = objEmployeeDetails.LastName;
this.lstDayOfDateOfBirth.Text =
objEmployeeDetails.DateOfBirth.Day.ToString();
this.lstMonthOfDateOfBirth.Text =
objEmployeeDetails.DateOfBirth.Month.ToString();
this.lstYearOfDateOfBirth.Text =