欢迎来到天天文库
浏览记录
ID:10846748
大小:33.50 KB
页数:7页
时间:2018-07-08
《全国省市查询系统(课程设计)源代码》由会员上传分享,免费在线阅读,更多相关内容在行业资料-天天文库。
1、全国省市查询系统(课程设计)源代码usingSystem;usingSystem.Collections.Generic;usingSystem.ComponentModel;usingSystem.Data;usingSystem.Drawing;usingSystem.Linq;usingSystem.Text;usingSystem.Windows.Forms;usingSystem.Data.SqlClient;usingSystem.Configuration;namespace全国省市查询系统{publicpartialclassForm1:Form{publicForm1(){
2、InitializeComponent();}privatevoidForm1_Load(objectsender,EventArgse){this.AcceptButton=button2;txtpassword.PasswordChar='*';this.CancelButton=button4;}privatevoidbutton2_Click(objectsender,EventArgse){SqlConnectionconn=null;stringconstr=ConfigurationManager.ConnectionStrings["conStr"].ConnectionSt
3、ring;try{stringusername1=txtusername.Text;stringpassword=txtpassword.Text;stringusername2=username1.ToLower();//转换成小写stringusername=username2.Trim();//去掉两边的空格Form2form2=newForm2();Form3form3=newForm3();using(conn=newSqlConnection(constr)){conn.Open();//MessageBox.Show("连接数据库成功!");using(SqlCommandcm
4、d=conn.CreateCommand()){if(txtusername.Text=="")MessageBox.Show("请输入用户名!");else{cmd.CommandText="select*fromtb_usernamewhereUsername=@UN";//查询语句cmd.Parameters.Add(newSqlParameter("UN",username));using(SqlDataReaderreader=cmd.ExecuteReader())//使用ExecuteReader方法实例一个SqlDataReader对象{if(username=="bingc
5、heng")//管理员登录{if(password=="910220"){this.Hide();//返回管理员界面form2.Show();}else{MessageBox.Show("密码错误,登录失败!");txtpassword.Text="";//清空}}elseif(reader.Read()&&username!="bingcheng")//遍历数据库第一例并判断用户登录{stringPassword=reader.GetString(reader.GetOrdinal("password"));//遍历数据库中的password属性if(password==Password)
6、{this.Hide();//返回用户界面form3.Show();}else{MessageBox.Show("密码错误,登录失败!");txtpassword.Text="";}}else{MessageBox.Show("用户名错误!");txtusername.Text="";//清空txtpassword.Text="";}}}//conn.Close();}}}catch(Exceptionex){MessageBox.Show("数据连接异常!");}finally{try{conn.Close();}catch(Exceptionex){}}}privatevoidbutto
7、n1_Click(objectsender,EventArgse){Form4form4=newForm4();//连接注册界面this.Hide();form4.Show();}privatevoidbutton3_Click(objectsender,EventArgse){Form5form5=newForm5();//连接找回密码界面this.Hide();form5.Show();}privatev
此文档下载收益归作者所有