2022年源码C#登录注册小程序源码 .pdf

上传人:Q****o 文档编号:27868378 上传时间:2022-07-26 格式:PDF 页数:5 大小:40.11KB
返回 下载 相关 举报
2022年源码C#登录注册小程序源码 .pdf_第1页
第1页 / 共5页
2022年源码C#登录注册小程序源码 .pdf_第2页
第2页 / 共5页
点击查看更多>>
资源描述

《2022年源码C#登录注册小程序源码 .pdf》由会员分享,可在线阅读,更多相关《2022年源码C#登录注册小程序源码 .pdf(5页珍藏版)》请在得力文库 - 分享文档赚钱的网站上搜索。

1、C#登录及注册的小程序1) 主界面( Form1 ) :privatevoid linkLabel1_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e) this .Hide(); Form3 f3 = new Form3 (); f3.ShowDialog(); / 显示注册界面;privatevoid linkLabel2_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e) this .Hide(); Form2 f = new Form2 (); f.S

2、howDialog(); if (f.DialogResult = DialogResult.OK) this .Visible = true ; / 显示登录界面;privatevoid Form1_FormClosing(object sender, FormClosingEventArgs e) try System.Diagnostics.Process myProcesses = System.Diagnostics.Process .GetProcesses(); foreach (System.Diagnostics.Process myProcess in myProcesse

3、s) if (LoginInterface.exe = myProcess.ProcessName) myProcess.Kill(); catch (Exception ee) MessageBox.Show(ee.Message); / 关掉程序;2) 注册界面( Form3 )名师资料总结 - - -精品资料欢迎下载 - - - - - - - - - - - - - - - - - - 名师精心整理 - - - - - - - 第 1 页,共 5 页 - - - - - - - - - 本文使用的数据库是sql sever2005,先在引用里加入:using System.Data.S

4、qlClient; 以下为程序代码:publicpartialclass Form3 : Form public Form3() InitializeComponent(); boolflagRegister;/ 定义标志位,确认用户注册string strConnect = Data Source=CAI-PCSQLEXPRESS;Initial Catalog=MyData1;Persist Security Info=True;User ID=sa;Password=*; / 连接数据库字符串privatevoid button1_Click(object sender, EventAr

5、gs e) if (textBox1.Text.Length = 4) & (textBox1.Text.Length = 6) & (textBox3.Text.Length = 6) flagRegister = true ; else if (textBox1.Text.Length 12) MessageBox.Show( 用户名长度不在约定范围内,请重新输入! , 提示 ); return ; if (textBox2.Text.Length 6) MessageBox.Show( 密码长度不足 6位,请重新输入!,提示 ); return ; if (textBox3.Text.L

6、ength 6) MessageBox.Show( 请重新输入邮箱!, 提示 ); return ; / 判断用户名条件;if (UserFlag = true ) MessageBox.Show( 用户已经存在,请重新输入!); return ; 名师资料总结 - - -精品资料欢迎下载 - - - - - - - - - - - - - - - - - - 名师精心整理 - - - - - - - 第 2 页,共 5 页 - - - - - - - - - if (flagRegister = true ) / 确认用户注册后,把用户写入数据库 SqlConnection conConne

7、ction = new SqlConnection(strConnect); conConnection.Open(); string cmd = insert into 用户 (用户名 ,密码 ,email) values ( + textBox1.Text + ,+ + textBox2.Text + , + + textBox3.Text + ) ; SqlCommand com = new SqlCommand(cmd, conConnection); com.ExecuteNonQuery(); conConnection.Close(); MessageBox.Show( 注册成功

8、!点击确定,返回登录界面。, 提示 ); this .Close(); Form1 f1 = new Form1 (); f1.label2.Text = 欢迎你, + textBox1.Text; f1.label1.Visible = false ; f1.label3.Visible = false ; f1.linkLabel1.Visible = false ; f1.linkLabel2.Visible = false ; f1.label2.Visible = true ; f1.Show(); publicbool UserFlag; / 定义标志位,来确认用户是否存在priv

9、atevoid textBox1_TextChanged(object sender, EventArgs e) SqlConnection conConnection = new SqlConnection(strConnect); conConnection.Open(); string cmd = select 用户名from 用户 ; SqlCommand com = new SqlCommand(cmd, conConnection); SqlDataReader readerUser = com.ExecuteReader(); while (readerUser.Read() i

10、f (textBox1.Text = readerUser用户名 .ToString().Trim() label5.Text = 用户已存在,请重新输入!; UserFlag = true ; /textBox1.Text = ; return ; else if (textBox1.Text != readerUser用户名 .ToString().Trim() 名师资料总结 - - -精品资料欢迎下载 - - - - - - - - - - - - - - - - - - 名师精心整理 - - - - - - - 第 3 页,共 5 页 - - - - - - - - - label5.

11、Text = 恭喜你,该用户名可以使用。; UserFlag = false ; / 判断用户名是否满足条件privatevoid textBox3_TextChanged(object sender, EventArgs e) int index = textBox3.Text.IndexOf( ); if (index 1) label7.Text = 邮箱格式不正确,请重新输入!; else label7.Text = 邮箱格式正确 ; / 判断邮箱格式是否正确 3) 登录界面( Form2 )本文使用的数据库是sql sever2005,先在引用里加入:using System.Dat

12、a.SqlClient; 以下为程序代码:string User, Pwd; / 用户名,密码bool flagshow = false ;/ 用来标注登录名是否存在于数据库privatevoid linkLabel1_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e) this .Hide(); Form3 f3 = new Form3 (); f3.ShowDialog(); / 显示注册界面privatevoid button1_Click(object sender, EventArgs e) / 登录string s

13、trConnect = Data Source=CAI-PCSQLEXPRESS;Initial Catalog=MyData1;Persist Security Info=True;User ID=sa;Password=*; SqlConnection conConnection = new SqlConnection(strConnect); conConnection.Open(); string cmd = select 用户名 ,密码 ,email from 用户 ; 名师资料总结 - - -精品资料欢迎下载 - - - - - - - - - - - - - - - - - -

14、名师精心整理 - - - - - - - 第 4 页,共 5 页 - - - - - - - - - SqlCommand com = new SqlCommand(cmd, conConnection); SqlDataReader reader = com.ExecuteReader(); while (reader.Read()/ 从数据库读取用户信息 User = reader用户名 .ToString(); Pwd = reader密码 .ToString(); if (User.Trim () = textBox1.Text & Pwd.Trim () = textBox2.Tex

15、t) flagshow = true ; / 用户名存在于数据库,则为true reader.Close(); conConnection.Close(); if (flagshow = true ) showMainForm();/ 用户存在,返回登录界面 else MessageBox.Show( 用户不存在或密码错误!, 提示 ); return ; privatevoid showMainForm()/ 登录成功,显示主界面 this .Close(); Form1 f1 = new Form1 (); f1.label1.Visible = false ; f1.label3.Visible = false ; f1.linkLabel1.Visible = false ; f1.linkLabel2.Visible = false ; f1.label2.Visible = true ; f1.label2.Text = 欢迎你, + textBox1 .Text ; f1.Show(); 名师资料总结 - - -精品资料欢迎下载 - - - - - - - - - - - - - - - - - - 名师精心整理 - - - - - - - 第 5 页,共 5 页 - - - - - - - - -

展开阅读全文
相关资源
相关搜索

当前位置:首页 > 技术资料 > 技术总结

本站为文档C TO C交易模式,本站只提供存储空间、用户上传的文档直接被用户下载,本站只是中间服务平台,本站所有文档下载所得的收益归上传人(含作者)所有。本站仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。若文档所含内容侵犯了您的版权或隐私,请立即通知得利文库网,我们立即给予删除!客服QQ:136780468 微信:18945177775 电话:18904686070

工信部备案号:黑ICP备15003705号-8 |  经营许可证:黑B2-20190332号 |   黑公网安备:91230400333293403D

© 2020-2023 www.deliwenku.com 得利文库. All Rights Reserved 黑龙江转换宝科技有限公司 

黑龙江省互联网违法和不良信息举报
举报电话:0468-3380021 邮箱:hgswwxb@163.com