C#——WinForm登录界面
来源:互联网 发布:曾舜晞粤读软件 编辑:程序博客网 时间:2024/05/16 15:27
登录界面概述:
系统登录主要用于对用户进行安全性检查,以防止非法用户进入系统。在登录时,只有合法的用户才可以进入该系统。
登录界面技术分析:
登录模块的重点在于将用户输入的用户名和密码与数据库中的用户名和密码进行比较,如果相同则允许用户进入系统的操作界面;否则弹出提示框,提示用户输入的用户名或密码错误。该模块的实现原理是,根据用户输入的用户名和密码在数据库中查找是否有相符的记录,并将查询结果填充到DataSet数据集中,然后判断该数据集中所包含表的行数是否大于零,如果大于零,则表示输入的用户和密码正确,从而成功登陆系统;否则,弹出提示信息。
窗体控件
窗体界面
代码
登陆按钮
private void btnLogin_Click(object sender, EventArgs e) { if (txtName.Text == "") { errorProName.SetError(txtName, "用户名不能为空!"); } else { errorProName.Clear(); string strSql = "select * from tb_admin where name='" + txtName.Text + "' and pwd='" + txtPwd.Text + "'"; DataSet ds = dataoperate.getDs(strSql, "tb_admin"); if (ds.Tables[0].Rows.Count > 0) { this.Hide(); frmMain frmmain = new frmMain(); frmmain.Show(); } else { MessageBox.Show("用户名或密码错误!", "警告", MessageBoxButtons.OK, MessageBoxIcon.Warning); } } }
退出按钮
private void btnExit_Click(object sender, EventArgs e) { Application.Exit(); }
用户名输入
private void txtName_KeyPress(object sender, KeyPressEventArgs e) { if (e.KeyChar == 13) { txtPwd.Focus(); e.Handled = true; } }
密码输入
private void txtPwd_KeyPress(object sender, KeyPressEventArgs e) { if (e.KeyChar == 13) { btnLogin.Focus(); e.Handled = true; } }
程序:
using System;using System.Collections.Generic;using System.ComponentModel;using System.Data;using System.Drawing;using System.Text;using System.Windows.Forms;//添加的命名空间using System.Data.OleDb;using VWMS.CommonClass;namespace VWMS{ public partial class frmLogin : Form { public frmLogin() { InitializeComponent(); } DataCon datacon = new DataCon(); DataOperate dataoperate = new DataOperate(); private void btnLogin_Click(object sender, EventArgs e) { if (txtName.Text == "") { errorProName.SetError(txtName, "用户名不能为空!"); } else { errorProName.Clear(); string strSql = "select * from tb_admin where name='" + txtName.Text + "' and pwd='" + txtPwd.Text + "'"; DataSet ds = dataoperate.getDs(strSql, "tb_admin"); if (ds.Tables[0].Rows.Count > 0) { this.Hide(); frmMain frmmain = new frmMain(); frmmain.Show(); } else { MessageBox.Show("用户名或密码错误!", "警告", MessageBoxButtons.OK, MessageBoxIcon.Warning); } } } private void btnExit_Click(object sender, EventArgs e) { Application.Exit(); } private void txtName_KeyPress(object sender, KeyPressEventArgs e) { if (e.KeyChar == 13) { txtPwd.Focus(); e.Handled = true; } } private void txtPwd_KeyPress(object sender, KeyPressEventArgs e) { if (e.KeyChar == 13) { btnLogin.Focus(); e.Handled = true; } } }}
0 1
- C#——WinForm登录界面
- 【winform】使用winform开发一个登录界面
- C#winform界面刷新
- LINQ 做的登录界面(winform)
- C#-winform-设计登录窗体
- winform操作系统,登录后怎么关闭登录界面。
- unity3D——登录界面
- web——界面登录
- 登录界面制作(c++build)
- c语言编写登录界面
- C#Winform线程操作界面控件
- [C#]winform使用html做界面
- C#/.NET Winform 界面库推荐
- C#-WinForm跨线程修改UI界面
- 关于C#WINFORM登录窗口的做法
- C#-—登陆界面
- android——miniTwitter登录界面 详解
- android——miniTwitter登录界面 详解
- KVM虚拟机通信
- XPCOM (Cross Platform Component Object Model)
- js提交form表单,并传递参数
- JSP显示服务器图片
- sed 使用 $var
- C#——WinForm登录界面
- 让webView适应屏幕大小
- Hbase 统计表行数的3种方式总结
- IOS开发之实现App消息推送(最新)
- 基类加析构函数加virtual的重要性
- css3圆角tab选项卡代码
- 【趋势科技实习录】UI添加滚动条
- CKEditor实现图片上传
- mysql 高性能的索引