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