WinForm登录模块设计开发
2010-10-14 11:19
162 查看
![](http://pic002.cnblogs.com/images/2010/138208/2010101411321065.jpg)
用户登录类:
public partial class UserLogin : DevComponents.DotNetBar.Office2007RibbonForm { private SceneViewer sceneViewer = new SceneViewer(); private UserManage userManage = new UserManage(); public UserLogin() { InitializeComponent(); } private void btnCancel_Click(object sender, EventArgs e) { this.Close(); //MessageBox.Show("请输入正确的用户名和密码!", "登陆失败!", MessageBoxButtons.OK, MessageBoxIcon.Warning); } private void btnLogin_Click(object sender, EventArgs e) { if (this.editUserName.Text == string.Empty) { MessageBox.Show("用户名不能为空!"); this.editUserName.Focus(); return; } else if(userManage.UserDictionary.ContainsKey(this.editUserName.Text)) { string psd = userManage.UserDictionary[this.editUserName.Text]; if (this.editPassword.Text == psd) { MessageBox.Show("欢迎登录本系统!", "登陆成功!", MessageBoxButtons.OK, MessageBoxIcon.Information); this.DialogResult = DialogResult.OK; } else { MessageBox.Show("密码错误,请重新输入!", "密码错误!", MessageBoxButtons.OK, MessageBoxIcon.Error); this.editPassword.Text = string.Empty; this.editPassword.Focus(); } } else { MessageBox.Show("用户名不存在!","登录失败!",MessageBoxButtons.OK,MessageBoxIcon.Warning); this.editUserName.Text = string.Empty; this.editPassword.Text = string.Empty; this.editUserName.Focus(); } } private void btnLogin_KeyDown(object sender, KeyEventArgs e) { if (e.KeyCode == Keys.Enter) { this.btnLogin.Click+=new EventHandler(btnLogin_Click); } } private void UserLogin_Load(object sender, EventArgs e) { if (this.editUserName.Text == string.Empty && this.editPassword.Text == string.Empty) { this.btnLogin.Enabled = false; } } private void editPassword_TextChanged(object sender, EventArgs e) { if (this.editUserName.Text == string.Empty && this.editPassword.Text == string.Empty) this.btnLogin.Enabled = false; else if (this.editUserName.Text == string.Empty && this.editPassword.Text != string.Empty) this.btnLogin.Enabled = false; else if (this.editUserName.Text != string.Empty && this.editPassword.Text == string.Empty) this.btnLogin.Enabled = false; else this.btnLogin.Enabled = true; } }
主程序类:
static class Program { /// <summary> /// The main entry point for the application. /// </summary> [STAThread] static void Main() { Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); UserLogin userLogin = new UserLogin(); try { if (userLogin.ShowDialog() == DialogResult.OK) Application.Run(new SceneViewer()); else Application.Exit(); } finally { userLogin.Close(); } } }
至于用户的管理,若用户数量很少,且内部使用可以用Dictionary<key,value>进行管理;
若用户数很多的话,就用数据库的方式进行管理
相关文章推荐
- C#人事管理系统开发(5)登录模块设计
- Winform开发框架中工作流模块的表设计分析
- C#数据库开发必备模块设计――登录模块
- 模块开发---- 数据仓库设计
- SSM整合开发的小Demo----毕业设计管理系统之学生模块
- App后台开发运维和架构实践学习总结(4)——APP的注册和登录功能设计
- Winform系统设计开发中的一些经验总结
- MySQL设计软件登录模块
- Windows2000 服务器端应用程序开发设计指南-系统登录
- winform开发框架之模块维护
- 基于JSP的开发实例--简单的登录模块
- 【商城开发九】登录设计
- 基于ArcGIS10.0和Oracle10g的空间数据管理平台二(C#开发)-登录功能模块
- [短彩信]C#短彩信模块开发设计(4)——其他
- DNN模块开发系列文章(1)——分析设计
- SSH物流开发系统设计:搭建框架并实现登录
- 登录模块设计思路
- 一步一步教你使用AgileEAS.NET基础类库进行应用开发-WinForm应用篇-库存查询模块
- [置顶] Struts2+Hibernate4开发学生信息管理功能--(三)用户登录模块
- Linux 驱动开发-内核模块设计笔记 0