登陆页面
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Text;
using CXES.Model;
using CXES.BLL;
public partial class Main : System.Web.UI.MasterPage {
private string msg = "";
private List functions;
private readonly string LoginURL = "LoginPage.aspx";
private readonly string SessionUserInfo = "SessionUserInfo";
private readonly string SessionUserType = "SessionUserType";
private DictionaryManager dicManager = new DictionaryManager();
private SystemUsersManager suManager = new SystemUsersManager();
private SystemParametersManager spManager = new SystemParametersManager();
private FunctionsManager funcManager = new FunctionsManager();
private AdminsManager adminsManager = new AdminsManager();
protected void Page_Load(object sender, EventArgs e)
{
bool haveSession = HaveSession();
if (haveSession)
{
if (!CheckSystemIsOpen())
{
int type = Convert.ToInt32(Session[SessionUserType]);
if (type != 92)
{
Page.ClientScript.RegisterStartupScript(this.GetType(), "it", "");
foreach (System.Web.UI.Control objControl in this.Controls)
{
if (objControl is
System.Web.UI.HtmlControls.HtmlForm)
{
foreach (System.Web.UI.Control objHtmlControl in objControl.Controls)
{
System.Web.UI.WebControls.WebControl
objWebCon;
objWebCon = objHtmlControl as WebControl;
if (objWebCon != null)
{
objWebCon.Enabled = false;
}
}
}
}
return;
}
}
}
if (!IsPostBack)
{
UpdateDLL();
if (!haveSession)
{
this.txtLoginId.Enabled = true;
this.txtLoginPWD.Enabled = true;
this.btnLogin.Enabled = true;
this.ddlUserType.Enabled = true;
//this.btnReset.Enabled = false;
this.btnReset.Visible = false;
if
(Request.Url.ToString().Substring(Request.Url.ToString().LastIndex
Of('/') + 1) != LoginURL)
{
Response.Redirect(LoginURL);
}
return;
}
this.txtLoginId.Enabled = false;
this.txtLoginPWD.Enabled = false;
this.btnLogin.Enabled = false;
this.ddlUserType.Enabled = false;
//this.txtLoginId.Visible = false;
//this.txtLoginPWD.Visible = false;
//this.btnLogin.Visible = false;
//this.btnReset.Enabled = true;
int userType = Convert.ToInt32(Session[SessionUserType]);
if (userType!=92)
{
SystemUsersInfo user = Session[SessionUserInfo] as SystemUsersInfo;
this.ltUserInfo.Text = user == null ? "Î?µÇÂ?" : user.LoginId;
this.ddlUserType.SelectedValue = userType.ToString();
}
else
{
AdminsInfo admin = Session[SessionUserInfo] as AdminsInfo;
this.ltUserInfo.Text = admin == null ? "Î?µÇÂ?" : admin.LoginId;
this.ddlUserType.SelectedValue = userType.ToString();
}
UpdateTree();
}
}
#region ??Öú????
private bool CheckSystemIsOpen()
{
return spManager.CheckSystemIsOpen();
}
private bool HaveSession()
{
return Session[SessionUserInfo] == null || Session[SessionUserType] == null ? false : true;
}
private void UpdateDLL()
{
List dics =
dicManager.GetDictionaryInfoByGroupName("UserType");
this.ddlUserType.DataSource = dics;
this.ddlUserType.DataTextField = "Content";
this.ddlUserType.DataValueField = "DicId";
this.ddlUserType.DataBind();
}
private bool CheckLogin(SystemUsersInfo user)
{
return suManager.CheckLogin(user, ref msg);
}
private void UpdateTree()
{
int userType = Convert.ToInt32(Session[SessionUserType]);
if (userType == 92)
{
functions = funcManager.GetAllInfo();
UpdateNodes();
}
else
{
SystemUsersInfo user = Session[SessionUserInfo] as
SystemUsersInfo;
if (user != null)
{
functions =
funcManager.GetFunctionsByLoginId(user.LoginId);
UpdateNodes();
}
}
}
private void UpdateNodes()
{
foreach (FunctionsInfo item in functions.Where(p => p.FId ==
0))
{
TreeNode father = new TreeNode();
father.Value = item.FunctionId.ToString();
father.Text = item.Describe;
father.NavigateUrl = item.URL;
UpdateChildNodes(father);
this.tvPower.Nodes.Add(father);
}
}
private void UpdateChildNodes(TreeNode father)
{
foreach (FunctionsInfo item in functions.Where(p => p.FId == Convert.ToInt32(father.Value)))
{
TreeNode child = new TreeNode();
child.Value = item.FunctionId.ToString();
child.Text = item.Describe;
child.NavigateUrl = item.URL;
UpdateChildNodes(child);
father.ChildNodes.Add(child);
}
}
#endregion
protected void btnLogin_Click(object sender, EventArgs e)
{
if (this.txtLoginId.Text.Trim() == "" || this.txtLoginPWD.Text == "")
{
Page.ClientScript.RegisterStartupScript(this.GetType(), "it", "");
return;
}
if (Convert.ToInt32(this.ddlUserType.SelectedValue)!=92)
{
SystemUsersInfo user = new SystemUsersInfo();
user.LoginId = this.txtLoginId.Text.Trim();
user.LoginPWD = this.txtLoginPWD.Text;
user.UserType =
Convert.ToInt32(this.ddlUserType.SelectedValue);
if (!CheckLogin(user))
{
Page.ClientScript.RegisterStartupScript(this.GetType(), "it", string.Format("", msg));
return;
}
else
{
user.LastLoginTime = System.DateTime.Now;
user.State = 91;
suManager.Update_State_LastLoginTime(user);
Session[SessionUserInfo] = user;
Session[SessionUserType] = user.UserType;
Response.Redirect("MainPage.aspx");
}
}
else
{
AdminsInfo admin=new AdminsInfo();
admin.LoginId=this.txtLoginId.Text.Trim();
admin.LoginPWD=this.txtLoginPWD.Text;
if (!adminsManager.CheckLogin(admin,ref msg))
{
Page.ClientScript.RegisterStartupScript(this.GetType(), "it", string.Format("", msg));
return;
}
else
{
Session[SessionUserInfo] = admin;
Session[SessionUserType] =
this.ddlUserType.SelectedValue;
Response.Redirect("MainPage.aspx");
}
}
}
protected void btnReset_Click(object sender, EventArgs e)
{
Session[SessionUserInfo] = null;
Session[SessionUserType] = null;
this.tvPower.Nodes.Clear();
Response.Redirect("LoginPage.aspx");
}
}