【实例简介】
c# access新生管理信息系统全代码
【实例截图】

【核心代码】
usingSystem;
usingSystem.Drawing;
usingSystem.Collections;
usingSystem.ComponentModel;
usingSystem.Windows.Forms;
usingSystem.Data;
usingSystem.Data.OleDb;
namespaceMasterMIS
{
/// <summary>
/// Form1 的摘要说明。
/// </summary>
publicclassLogin : System.Windows.Forms.Form
{
privateSystem.Windows.Forms.TextBox password;
privateSystem.Windows.Forms.TextBox name;
privateSystem.Windows.Forms.Label label3;
privateSystem.Windows.Forms.Label label2;
privateSystem.Windows.Forms.Label label1;
/// <summary>
/// 必需的设计器变量。
/// </summary>
privateSystem.ComponentModel.Container components =null;
privateOleDbConnection oleConnection1 =null;
privateSystem.Windows.Forms.Button btClose;
privateSystem.Windows.Forms.Button btAdd;
privateOleDbCommand oleCommand1 =null;
publicLogin()
{
//
// Windows 窗体设计器支持所必需的
//
InitializeComponent();
oleConnection1 =newOleDbConnection(MasterMIS.database.dbConnection.connection);
oleCommand1 =newOleDbCommand();
oleCommand1.Connection = oleConnection1;
//
// TODO: 在 InitializeComponent 调用后添加任何构造函数代码
//
}
/// <summary>
/// 清理所有正在使用的资源。
/// </summary>
protectedoverridevoidDispose(booldisposing )
{
if( disposing )
{
if(components !=null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
#region Windows 窗体设计器生成的代码
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
privatevoidInitializeComponent()
{
this.btClose =newSystem.Windows.Forms.Button();
this.btAdd =newSystem.Windows.Forms.Button();
this.password =newSystem.Windows.Forms.TextBox();
this.name =newSystem.Windows.Forms.TextBox();
this.label3 =newSystem.Windows.Forms.Label();
this.label2 =newSystem.Windows.Forms.Label();
this.label1 =newSystem.Windows.Forms.Label();
this.SuspendLayout();
//
// btClose
//
this.btClose.FlatStyle = System.Windows.Forms.FlatStyle.Popup;
this.btClose.ForeColor = System.Drawing.Color.DarkSlateGray;
this.btClose.Location =newSystem.Drawing.Point(168, 160);
this.btClose.Name ="btClose";
this.btClose.Size =newSystem.Drawing.Size(75, 23);
this.btClose.TabIndex = 13;
this.btClose.Text ="取消";
this.btClose.Click =newSystem.EventHandler(this.btClose_Click);
//
// btAdd
//
this.btAdd.FlatStyle = System.Windows.Forms.FlatStyle.Popup;
this.btAdd.ForeColor = System.Drawing.Color.DarkSlateGray;
this.btAdd.Location =newSystem.Drawing.Point(48, 160);
this.btAdd.Name ="btAdd";
this.btAdd.Size =newSystem.Drawing.Size(75, 23);
this.btAdd.TabIndex = 12;
this.btAdd.Text ="确定";
this.btAdd.Click =newSystem.EventHandler(this.btAdd_Click);
//
// password
//
this.password.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
this.password.Location =newSystem.Drawing.Point(128, 120);
this.password.Name ="password";
this.password.PasswordChar ='*';
this.password.Size =newSystem.Drawing.Size(100, 21);
this.password.TabIndex = 11;
this.password.Text ="admin";
//
// name
//
this.name.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
this.name.Location =newSystem.Drawing.Point(128, 80);
this.name.Name ="name";
this.name.Size =newSystem.Drawing.Size(100, 21);
this.name.TabIndex = 10;
this.name.Text ="admin";
//
// label3
//
this.label3.Font =newSystem.Drawing.Font("宋体", 10.5F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
this.label3.ForeColor = System.Drawing.Color.DarkSlateGray;
this.label3.Location =newSystem.Drawing.Point(64, 120);
this.label3.Name ="label3";
this.label3.Size =newSystem.Drawing.Size(56, 23);
this.label3.TabIndex = 9;
this.label3.Text ="密 码";
//
// label2
//
this.label2.Font =newSystem.Drawing.Font("宋体", 10.5F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
this.label2.ForeColor = System.Drawing.Color.DarkSlateGray;
this.label2.Location =newSystem.Drawing.Point(64, 80);
this.label2.Name ="label2";
this.label2.Size =newSystem.Drawing.Size(56, 23);
this.label2.TabIndex = 8;
this.label2.Text ="用户名";
//
// label1
//
this.label1.Font =newSystem.Drawing.Font("Microsoft Sans Serif", 18F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
this.label1.ForeColor = System.Drawing.Color.DarkSlateGray;
this.label1.Location =newSystem.Drawing.Point(32, 24);
this.label1.Name ="label1";
this.label1.Size =newSystem.Drawing.Size(232, 40);
this.label1.TabIndex = 7;
this.label1.Text ="研究生管理信息系统";
//
// Login
//
this.AutoScaleBaseSize =newSystem.Drawing.Size(6, 14);
this.BackColor = System.Drawing.Color.Lavender;
this.ClientSize =newSystem.Drawing.Size(339, 257);
this.Controls.Add(this.btClose);
this.Controls.Add(this.btAdd);
this.Controls.Add(this.password);
this.Controls.Add(this.name);
this.Controls.Add(this.label3);
this.Controls.Add(this.label2);
this.Controls.Add(this.label1);
this.MaximizeBox =false;
this.MinimizeBox =false;
this.Name ="Login";
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
this.Text ="登录";
this.Load =newSystem.EventHandler(this.Login_Load);
this.ResumeLayout(false);
this.PerformLayout();
}
#endregion
/// <summary>
/// 应用程序的主入口点。
/// </summary>
[STAThread]
staticvoidMain()
{
Application.Run(newLogin());
}
privatevoidbtAdd_Click(objectsender, System.EventArgs e)
{
if(name.Text.Trim()==""||password.Text.Trim()=="")
MessageBox.Show("请输入用户名和密码","提示");
else
{
oleConnection1.Open();
OleDbCommand cmd=newOleDbCommand("",oleConnection1);
stringsql="select RoleName from userinfo where UName='"name.Text.Trim()"' and PWD='"password.Text.Trim()"'";
cmd.CommandText=sql;
stringrolename;
if(null!=cmd.ExecuteScalar())
{
rolename=cmd.ExecuteScalar().ToString();
//隐藏登录窗口
this.Visible=false;
//创建并打开主界面
Main main=newMain();
main.Tag=this.FindForm();
sql="select * from roles where RoleName='"rolename"'";
OleDbDataReader dr;
cmd.CommandText=sql;
dr=cmd.ExecuteReader();
dr.Read();
main.menuItem1.Visible=(bool)(dr.GetValue(1));
main.menuItem4.Visible=(bool)(dr.GetValue(1));
main.menuItem5.Visible=(bool)(dr.GetValue(2));
main.menuItem6.Visible=(bool)(dr.GetValue(2));
main.menuItem7.Visible=(bool)(dr.GetValue(3));
main.statusBarPanel2.Text=name.Text.Trim();
main.ShowDialog();
}
else
MessageBox.Show("用户名或密码错误","警告");
oleConnection1.Close();
}
}
privatevoidbtClose_Click(objectsender, System.EventArgs e)
{
this.Close();
}
privatevoidLogin_Load(objectsender, EventArgs e)
{
}
}
}
网友评论
我要评论