由于附件大小限制,我只把数据库文件传了上来,登陆框的代码(由于字节限制,窗体设计代码没贴):
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Drawing.Drawing2D;
namespace SupermarketProject
{
/// <summary>
/// frmLogin
/// </summary>
public class frmLogin : System.Windows.Forms.Form
{
private System.Windows.Forms.Label lblUserName;
private System.Windows.Forms.Label lblPwd;
private System.Windows.Forms.Button btnOK;
private System.Windows.Forms.Button btnCancel;
private System.Windows.Forms.TextBox txtUserId;
private System.Windows.Forms.TextBox txtPwd;
/// <summary>
/// </summary>
private System.ComponentModel.Container components = null;
private Menu mainmenu;
private ToolBar toolbar;
public static string loginId;
private bool reLogin;
public frmLogin(Menu mnu,ToolBar tool,bool reLog)
{
//
// Windows
//
InitializeComponent();
//
// TODO: InitializeComponent
mainmenu = mnu;
toolbar = tool;
reLogin = reLog;
}
/// <summary>
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if(components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
//Starting Point
/*[STAThread]
static void Main()
{
Application.Run(new frmLogin());
}*/
private void btnCancel_Click(object sender, System.EventArgs e)
{
if(this.reLogin == true)
{
frmMainMenu.varReLogin = 0;
this.Close();
}
else
{
Application.Exit();
}
}
private void ClearData()
{
this.txtUserId.Text ="";
this.txtPwd.Text ="";
}
private void EnableDisableMenu(int prior)
{
// For System Admin Users
if(prior ==1 )
{
mainmenu.MenuItems[0].Enabled = true;
mainmenu.MenuItems[1].Enabled = false;
mainmenu.MenuItems[2].Enabled = false;
mainmenu.MenuItems[3].Enabled = false;
mainmenu.MenuItems[4].Enabled = false;
toolbar.Buttons[0].Enabled = true;
toolbar.Buttons[1].Enabled= false;
toolbar.Buttons[3].Enabled= false;
toolbar.Buttons[4].Enabled= false;
toolbar.Buttons[5].Enabled= false;
}
// For Stock Manager Users
else if (prior == 2)
{
mainmenu.MenuItems[0].Enabled = false;
mainmenu.MenuItems[1].Enabled = true;
mainmenu.MenuItems[2].Enabled = true;
mainmenu.MenuItems[3].Enabled = false;
mainmenu.MenuItems[4].Enabled = false;
toolbar.Buttons[0].Enabled = false;
toolbar.Buttons[1].Enabled= false;
toolbar.Buttons[3].Enabled= true;
toolbar.Buttons[4].Enabled= true;
toolbar.Buttons[5].Enabled= false;
}
// For Teller Users
else if(prior == 4)
{
mainmenu.MenuItems[0].Enabled = false;
mainmenu.MenuItems[1].Enabled = false;
mainmenu.MenuItems[2].Enabled = false;
mainmenu.MenuItems[3].Enabled = false;
mainmenu.MenuItems[4].Enabled = true;
toolbar.Buttons[0].Enabled = false;
toolbar.Buttons[1].Enabled= true;
toolbar.Buttons[3].Enabled= false;
toolbar.Buttons[4].Enabled= false;
toolbar.Buttons[5].Enabled= false;
}
//For Sales Admin Users
else if(prior == 8)
{
mainmenu.MenuItems[0].Enabled = false;
mainmenu.MenuItems[1].Enabled = false;
mainmenu.MenuItems[2].Enabled = false;
mainmenu.MenuItems[3].Enabled = true;
mainmenu.MenuItems[4].MenuItems[0].Enabled= false;
mainmenu.MenuItems[4].MenuItems[1].Enabled= true;
toolbar.Buttons[0].Enabled = false;
toolbar.Buttons[1].Enabled= false;
toolbar.Buttons[3].Enabled= false;
toolbar.Buttons[4].Enabled= false;
toolbar.Buttons[5].Enabled= true;
}
// For System Admin + Stock Manager
else if (prior == 3)
{
mainmenu.MenuItems[0].Enabled = true;
mainmenu.MenuItems[1].Enabled = true;
mainmenu.MenuItems[2].Enabled = true;
mainmenu.MenuItems[3].Enabled = false;
mainmenu.MenuItems[4].Enabled = false;
toolbar.Buttons[0].Enabled = true;
toolbar.Buttons[1].Enabled= false;
toolbar.Buttons[3].Enabled= true;
toolbar.Buttons[4].Enabled= true;
toolbar.Buttons[5].Enabled= false;
}
//For System Admin + Teller
else if(prior == 5)
{
mainmenu.MenuItems[0].Enabled = true;
mainmenu.MenuItems[1].Enabled = false;
mainmenu.MenuItems[2].Enabled = false;
mainmenu.MenuItems[3].Enabled = false;
mainmenu.MenuItems[4].Enabled = true;
toolbar.Buttons[0].Enabled = true;
toolbar.Buttons[1].Enabled= true;
toolbar.Buttons[3].Enabled= false;
toolbar.Buttons[4].Enabled= false;
toolbar.Buttons[5].Enabled= false;
}
//For Teller + Stock Manager
else if(prior == 6)
{
mainmenu.MenuItems[0].Enabled = false;
mainmenu.MenuItems[1].Enabled = true;
mainmenu.MenuItems[2].Enabled = true;
mainmenu.MenuItems[3].Enabled = false;
mainmenu.MenuItems[4].Enabled = true;
toolbar.Buttons[0].Enabled = false;
toolbar.Buttons[1].Enabled= true;
toolbar.Buttons[3].Enabled= true;
toolbar.Buttons[4].Enabled= true;
toolbar.Buttons[5].Enabled= false;
}
//For System Admin + Teller + Stock Manager
else if (prior == 7)
{
mainmenu.MenuItems[0].Enabled = true;
mainmenu.MenuItems[1].Enabled = true;
mainmenu.MenuItems[2].Enabled = true;
mainmenu.MenuItems[3].Enabled = false;
mainmenu.MenuItems[4].Enabled = true;
toolbar.Buttons[0].Enabled = true;
toolbar.Buttons[1].Enabled= true;
toolbar.Buttons[3].Enabled= true;
toolbar.Buttons[4].Enabled= true;
toolbar.Buttons[5].Enabled= false;
}
//For System Admin + Sales Admin
else if(prior == 9)
{
mainmenu.MenuItems[0].Enabled = true;
mainmenu.MenuItems[1].Enabled = false;
mainmenu.MenuItems[2].Enabled = false;
mainmenu.MenuItems[3].Enabled = true;
mainmenu.MenuItems[4].MenuItems[0].Enabled = false;
mainmenu.MenuItems[4].MenuItems[1].Enabled = true;
toolbar.Buttons[0].Enabled = true;
toolbar.Buttons[1].Enabled = false;
toolbar.Buttons[3].Enabled = false;
toolbar.Buttons[4].Enabled = false;
toolbar.Buttons[5].Enabled = true;
}
//For Stock Manager + Sales Admin
else if(prior == 10)
{
mainmenu.MenuItems[0].Enabled = false;
mainmenu.MenuItems[1].Enabled = true;
mainmenu.MenuItems[2].Enabled = true;
mainmenu.MenuItems[3].Enabled = true;
mainmenu.MenuItems[4].MenuItems[0].Enabled = false;
mainmenu.MenuItems[4].MenuItems[1].Enabled = true;
toolbar.Buttons[0].Enabled = false;
toolbar.Buttons[1].Enabled= false;
toolbar.Buttons[3].Enabled= true;
toolbar.Buttons[4].Enabled= true;
toolbar.Buttons[5].Enabled= true;
}
//For System Admin + Stock Manager + Sales Admin
else if(prior == 11)
{
mainmenu.MenuItems[0].Enabled = true;
mainmenu.MenuItems[1].Enabled = true;
mainmenu.MenuItems[2].Enabled = true;
mainmenu.MenuItems[3].Enabled = true;
mainmenu.MenuItems[4].MenuItems[0].Enabled = false;
mainmenu.MenuItems[4].MenuItems[1].Enabled = true;
toolbar.Buttons[0].Enabled = true;
toolbar.Buttons[1].Enabled= false;
toolbar.Buttons[3].Enabled= true;
toolbar.Buttons[4].Enabled= true;
toolbar.Buttons[5].Enabled= true;
}
//For Teller + Sales Admin
else if(prior == 12)
{
mainmenu.MenuItems[0].Enabled = false;
mainmenu.MenuItems[1].Enabled = false;
mainmenu.MenuItems[2].Enabled = false;
mainmenu.MenuItems[3].Enabled = true;
mainmenu.MenuItems[4].Enabled = true;
toolbar.Buttons[0].Enabled = false;
toolbar.Buttons[1].Enabled= true;
toolbar.Buttons[3].Enabled= false;
toolbar.Buttons[4].Enabled= false;
toolbar.Buttons[5].Enabled= true;
}
//For a user with all rights
else if(prior == 15)
{
mainmenu.MenuItems[0].Enabled = true;
mainmenu.MenuItems[1].Enabled = true;
mainmenu.MenuItems[2].Enabled = true;
mainmenu.MenuItems[3].Enabled = true;
mainmenu.MenuItems[4].Enabled = true;
toolbar.Buttons[0].Enabled = true;
toolbar.Buttons[1].Enabled= true;
toolbar.Buttons[3].Enabled= true;
toolbar.Buttons[4].Enabled= true;
toolbar.Buttons[5].Enabled= true;
}
}
private void btnOK_Click(object sender, System.EventArgs e)
{
this.checkLogin();
}
private void frmLogin_Closing(object sender, System.ComponentModel.CancelEventArgs e)
{
frmMainMenu.varReLogin = 0;
}
private void txtPwd_Leave(object sender, System.EventArgs e)
{
this.btnOK.Focus();
}
private void txtPwd_KeyPress(object sender, System.Windows.Forms.KeyPressEventArgs e)
{
if (e.KeyChar ==13)
{
this.btnOK.Focus();
this.checkLogin();
}
}
private void btnOK_KeyPress(object sender, System.Windows.Forms.KeyPressEventArgs e)
{
if (e.KeyChar ==13)
{
this.checkLogin();
}
}
private void checkLogin()
{
bool status;
if(this.txtUserId.Text !="")
{
UserManagement usrMgmt = new UserManagement();
status = usrMgmt.Login(this.txtUserId.Text,this.txtPwd.Text);
if (status == true)
{
if(loginId != this.txtUserId.Text)
{
frmSplash splash = new frmSplash(this.txtUserId.Text);
loginId = this.txtUserId.Text;
frmMainMenu.varReLogin = 0;
this.Close();
Application.DoEvents();
splash.ShowDialog();
splash.Refresh();
Application.DoEvents();
MainForm mFrm = new MainForm(this.txtUserId.Text);
int prior = mFrm.DisplayMainMenuByPriority();
this.EnableDisableMenu(prior);
this.Close();
}
else
{
MessageBox.Show("您已登录");
this.Close();
}
}
else
{
MessageBox.Show("拒绝访问");
this.ClearData();
this.txtUserId.Focus();
}
}
else
{
this.txtUserId.Focus();
MessageBox.Show("输入用户名");
}
}
private void frmLogin_Load(object sender, System.EventArgs e)
{
}
}
}