实例介绍
【实例简介】c# access研究生管理信息系统全代码
如果使用时提示【未在本地计算机上注册“Microsoft.ACE.OLEDB.12.0”提供程序。】
解决方法:
1.下载2007 Office system 驱动程序,注意是2007,亲测2010english版本出错,原因未进一步确认,组件下载地址
http://download.microsoft.com/download/7/0/3/703ffbcb-dc0c-4e19-b0da-1463960fdcdb/AccessDatabaseEngine.exe
2.安装AccessDatabaseEngine.exe
3. 右键项目>>生成>目标平台 选择x86
4.运行即可
【实例截图】
【核心代码】
using System; using System.Drawing; using System.Collections; using System.ComponentModel; using System.Windows.Forms; using System.Data; using System.Data.OleDb; //Download by http://down.liehuo.net namespace MasterMIS { /// <summary> /// Form1 的摘要说明。 /// </summary> public class Login : System.Windows.Forms.Form { private System.Windows.Forms.TextBox password; private System.Windows.Forms.TextBox name; private System.Windows.Forms.Label label3; private System.Windows.Forms.Label label2; private System.Windows.Forms.Label label1; /// <summary> /// 必需的设计器变量。 /// </summary> private System.ComponentModel.Container components = null; private OleDbConnection oleConnection1 = null; private System.Windows.Forms.Button btClose; private System.Windows.Forms.Button btAdd; private OleDbCommand oleCommand1 = null; public Login() { // // Windows 窗体设计器支持所必需的 // InitializeComponent(); oleConnection1 = new OleDbConnection(MasterMIS.database.dbConnection.connection); oleCommand1 = new OleDbCommand(); oleCommand1.Connection = oleConnection1; // // TODO: 在 InitializeComponent 调用后添加任何构造函数代码 // } /// <summary> /// 清理所有正在使用的资源。 /// </summary> protected override void Dispose( bool disposing ) { if( disposing ) { if (components != null) { components.Dispose(); } } base.Dispose( disposing ); } #region Windows 窗体设计器生成的代码 /// <summary> /// 设计器支持所需的方法 - 不要使用代码编辑器修改 /// 此方法的内容。 /// </summary> private void InitializeComponent() { this.btClose = new System.Windows.Forms.Button(); this.btAdd = new System.Windows.Forms.Button(); this.password = new System.Windows.Forms.TextBox(); this.name = new System.Windows.Forms.TextBox(); this.label3 = new System.Windows.Forms.Label(); this.label2 = new System.Windows.Forms.Label(); this.label1 = new System.Windows.Forms.Label(); this.SuspendLayout(); // // btClose // this.btClose.FlatStyle = System.Windows.Forms.FlatStyle.Popup; this.btClose.ForeColor = System.Drawing.Color.DarkSlateGray; this.btClose.Location = new System.Drawing.Point(168, 160); this.btClose.Name = "btClose"; this.btClose.Size = new System.Drawing.Size(75, 23); this.btClose.TabIndex = 13; this.btClose.Text = "取消"; this.btClose.Click = new System.EventHandler(this.btClose_Click); // // btAdd // this.btAdd.FlatStyle = System.Windows.Forms.FlatStyle.Popup; this.btAdd.ForeColor = System.Drawing.Color.DarkSlateGray; this.btAdd.Location = new System.Drawing.Point(48, 160); this.btAdd.Name = "btAdd"; this.btAdd.Size = new System.Drawing.Size(75, 23); this.btAdd.TabIndex = 12; this.btAdd.Text = "确定"; this.btAdd.Click = new System.EventHandler(this.btAdd_Click); // // password // this.password.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle; this.password.Location = new System.Drawing.Point(128, 120); this.password.Name = "password"; this.password.PasswordChar = '*'; this.password.Size = new System.Drawing.Size(100, 21); this.password.TabIndex = 11; this.password.Text = "admin"; // // name // this.name.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle; this.name.Location = new System.Drawing.Point(128, 80); this.name.Name = "name"; this.name.Size = new System.Drawing.Size(100, 21); this.name.TabIndex = 10; this.name.Text = "admin"; // // label3 // this.label3.Font = new System.Drawing.Font("宋体", 10.5F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(134))); this.label3.ForeColor = System.Drawing.Color.DarkSlateGray; this.label3.Location = new System.Drawing.Point(64, 120); this.label3.Name = "label3"; this.label3.Size = new System.Drawing.Size(56, 23); this.label3.TabIndex = 9; this.label3.Text = "密 码"; // // label2 // this.label2.Font = new System.Drawing.Font("宋体", 10.5F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(134))); this.label2.ForeColor = System.Drawing.Color.DarkSlateGray; this.label2.Location = new System.Drawing.Point(64, 80); this.label2.Name = "label2"; this.label2.Size = new System.Drawing.Size(56, 23); this.label2.TabIndex = 8; this.label2.Text = "用户名"; // // label1 // this.label1.Font = new System.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 = new System.Drawing.Point(32, 24); this.label1.Name = "label1"; this.label1.Size = new System.Drawing.Size(232, 40); this.label1.TabIndex = 7; this.label1.Text = "研究生管理信息系统"; // // Login // this.AutoScaleBaseSize = new System.Drawing.Size(6, 14); this.BackColor = System.Drawing.Color.Lavender; this.ClientSize = new System.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 = new System.EventHandler(this.Login_Load); this.ResumeLayout(false); this.PerformLayout(); } #endregion /// <summary> /// 应用程序的主入口点。 /// </summary> [STAThread] static void Main() { Application.Run(new Login()); } private void btAdd_Click(object sender, System.EventArgs e) { if(name.Text.Trim()==""||password.Text.Trim()=="") MessageBox.Show("请输入用户名和密码","提示"); else { oleConnection1.Open(); OleDbCommand cmd=new OleDbCommand("",oleConnection1); string sql="select RoleName from userinfo where UName='" name.Text.Trim() "' and PWD='" password.Text.Trim() "'"; cmd.CommandText=sql; string rolename; if (null!=cmd.ExecuteScalar()) { rolename=cmd.ExecuteScalar().ToString(); //隐藏登录窗口 this.Visible=false; //创建并打开主界面 Main main=new Main(); 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(); } } private void btClose_Click(object sender, System.EventArgs e) { this.Close(); } private void Login_Load(object sender, EventArgs e) { } } }
小贴士
感谢您为本站写下的评论,您的评论对其它用户来说具有重要的参考价值,所以请认真填写。
- 类似“顶”、“沙发”之类没有营养的文字,对勤劳贡献的楼主来说是令人沮丧的反馈信息。
- 相信您也不想看到一排文字/表情墙,所以请不要反馈意义不大的重复字符,也请尽量不要纯表情的回复。
- 提问之前请再仔细看一遍楼主的说明,或许是您遗漏了。
- 请勿到处挖坑绊人、招贴广告。既占空间让人厌烦,又没人会搭理,于人于己都无利。
关于好例子网
本站旨在为广大IT学习爱好者提供一个非营利性互相学习交流分享平台。本站所有资源都可以被免费获取学习研究。本站资源来自网友分享,对搜索内容的合法性不具有预见性、识别性、控制性,仅供学习研究,请务必在下载后24小时内给予删除,不得用于其他任何用途,否则后果自负。基于互联网的特殊性,平台无法对用户传输的作品、信息、内容的权属或合法性、安全性、合规性、真实性、科学性、完整权、有效性等进行实质审查;无论平台是否已进行审查,用户均应自行承担因其传输的作品、信息、内容而可能或已经产生的侵权或权属纠纷等法律责任。本站所有资源不代表本站的观点或立场,基于网友分享,根据中国法律《信息网络传播权保护条例》第二十二与二十三条之规定,若资源存在侵权或相关问题请联系本站客服人员,点此联系我们。关于更多版权及免责申明参见 版权及免责申明
网友评论
我要评论