At that time, when I started to rebuild, I saw a lot of people's computer room reconfiguration login. Almost everyone had a summary about the computer room reconfiguration login. I also struggled for a long time and plan to share my own. If there is something wrong, please correct it. . Most people log in with two login windows, one for general users and one for operator administrators. What I did was only a login window, and then judged their permissions and then popped up the corresponding function menus.
I won’t go into details here
namespace Entity
{
public class UserInfo
{
public int UserName {
get ; set ; }
public string PWD {
get ; set ; }
public string Level {
get ; set ; }
public string UserID {
get ; set ; }
}
}
namespace IDAL
{
public interface LoginIDAL
{
DataTable SelectUser ( Entity. UserInfo userInfo) ;
}
}
public class LoginDAL : IDAL. LoginIDAL
{
public DataTable SelectUser ( Entity. UserInfo user)
{
SQLHelper sqlHelper = new SQLHelper ( ) ;
SqlParameter[ ] sqlparams =
{
new SqlParameter ( "@userid" , user. UserID ) ,
new SqlParameter ( "@password" , user. PWD)
} ;
string sql = @"select * from User_Info where UserID=@userid and PWD=@password" ;
DataTable table = sqlHelper. ExecuteQuery ( sql, sqlparams, CommandType. Text) ;
return table;
}
}
public class LoginFactory
{
string StrDB = System. Configuration. ConfigurationManager. AppSettings[ "DB" ] ;
public IDAL. LoginIDAL CreateUser ( )
{
string ClassName = StrDB + "." + "LoginDAL" ;
return ( IDAL. LoginIDAL) Assembly. Load ( StrDB) . CreateInstance ( ClassName) ;
}
}
public class LoginBLL
{
public bool UserBLL ( Entity. UserInfo user)
{
Factory. LoginFactory fact = new Factory. LoginFactory ( ) ;
IDAL. LoginIDAL idal = fact. CreateUser ( ) ;
DataTable table = idal. SelectUser ( user) ;
bool flag;
if ( table. Rows. Count == 0 )
{
flag = false ;
}
else
{
flag = true ;
}
return flag;
}
public DataTable LevelBLL ( Entity . UserInfo userInfo)
{
Factory. LoginFactory fact = new Factory. LoginFactory ( ) ;
IDAL. LoginIDAL idal = fact. CreateUser ( ) ;
DataTable Level = idal. SelectUser ( userInfo) ;
return Level;
}
}
a
public class LoginFacade
{
public Boolean SelectUser ( Entity. UserInfo user)
{
bool flag;
BLL. LoginBLL userBLL = new BLL. LoginBLL ( ) ;
flag = userBLL. UserBLL ( user) ;
return flag;
}
public DataTable SelectLevel ( Entity . UserInfo Level1)
{
BLL. LoginBLL LevelBLL = new BLL. LoginBLL ( ) ;
DataTable Level = LevelBLL. LevelBLL ( Level1) ;
return Level;
}
}
a
public partial class FrmLogin : Form
{
public FrmLogin ( )
{
InitializeComponent ( ) ;
}
private void btnLogin_Click ( object sender, EventArgs e)
{
if ( txtUserID . Text== "" || txtPassWord. Text == "" )
{
MessageBox. Show ( "账号和密码不能为空!" , "温馨提示" , MessageBoxButtons. OK, MessageBoxIcon. Information) ;
}
else
{
Facade. LoginFacade facade = new Facade. LoginFacade ( ) ;
Entity. UserInfo user = new Entity. UserInfo ( ) ;
user. UserID= Convert. ToString ( txtUserID. Text) ;
user. PWD = txtPassWord. Text;
Boolean flag = false ;
Facade. LoginFacade FLogin = new Facade. LoginFacade ( ) ;
flag = FLogin. SelectUser ( user) ;
if ( flag != false )
{
this . Hide ( ) ;
Until. HelpUntil. UserID = this . txtUserID. Text. Trim ( ) ;
this . DialogResult = System. Windows. Forms. DialogResult. OK;
DataTable Level = FLogin. SelectLevel ( user) ;
if ( Level. Rows[ 0 ] [ 2 ] . ToString ( ) . Trim ( ) == "用户" )
{
FrmMain frmstu = new FrmMain ( ) ;
frmstu. Show ( ) ;
}
else if ( Level. Rows [ 0 ] [ 2 ] . ToString ( ) . Trim ( ) == "操作员" )
{
FrmOpert frmopert = new FrmOpert ( ) ;
frmopert. Show ( ) ;
}
else
{
FrmAdmin frmadmin = new FrmAdmin ( ) ;
frmadmin. Show ( ) ;
}
}
else
{
MessageBox. Show ( "用户名或密码不正确" ) ;
}
}
}