发布于2022年11月4日2年前 C#结合数据库开发通讯录管理系统 通讯录管理系统,数据库关系模式为:账户(账户名,登录密码,头像),联系人(ID,姓名,电话,QQ,Email)。主要功能包括:注册,登录,注销账号,修改账户名以及密码,更换头像,以及对联系人的增删改查。工具:Visual Studio 2015,sql server2014数据库关系表:Account: Contact: http://images2015.cnblogs.com/blog/865264/201605/865264-20160505225400419-2140861622.png http://images2015.cnblogs.com/blog/865264/201605/865264-20160505225848888-896174822.png VS中主要界面及代码:登录主界面:Loginhttp://images2015.cnblogs.com/blog/865264/201605/865264-20160505230235091-1205153169.png using System;using System.Collections.Generic;using System.ComponentModel;using System.Data;using System.Drawing;using System.Linq;using System.Text;using System.Threading.Tasks;using System.Windows.Forms;using System.Data.SqlClient; namespace Contact_Manage{ /// <summary> /// 登录 /// </summary> public partial class Login : Form { //存取用户登录名 public static String txtLogin_Username; public Login() { InitializeComponent(); } //登录 private void btt_Login_Click(object sender, EventArgs e) { //获取用户输入的用户名和密码 txtLogin_Username = tB_Account_Username.Text; String password = tB_Account_Password.Text; if (txtLogin_Username == "" || password == "") { MessageBox.Show("请输入用户名和密码!"); return; } //连接数据库进行数据判断 string sqlcon = "server=.;database=phone_Book;uid=sa;pwd=666888"; String sqlcom = " select * from Account where Account_Username='" + txtLogin_Username + "' and Account_password='" + password + "'"; SqlConnection con = new SqlConnection(sqlcon); SqlCommand com = new SqlCommand(sqlcom, con); con.Open(); SqlDataReader reader = com.ExecuteReader(); if (reader.Read()) { //打开菜单页面 Menu menu = new Menu(); menu.Show(); } else { MessageBox.Show("用户名或密码错误,请重新输入!"); } con.Close(); //清空文本框 foreach (Control item in this.Controls) { if (item is TextBox) { item.Text = ""; } } } //注册账号事件 private void lb_Regist_Click(object sender, EventArgs e) { Regist rigist = new Regist(); rigist.Show(); } //注销账户事件 private void lb_Logout_Click(object sender, EventArgs e) { //跳出注销界面,验证输入的用户名及密码是否正确 Logout logout = new Logout(); logout.Show(); } //点击密码文本框时将登录头像显示在pictureBox控件中 private void tB_Account_Password_MouseClick(object sender, MouseEventArgs e) { //获取输入的用户名 String username = tB_Account_Username.Text; if (username != "") { //连接数据库,如果该用户名存在则将头像显示 string sqlcon = "server=.;database=phone_Book;uid=sa;pwd=666888"; String sqlcom = " select * from Account where Account_Username='" + username + "'"; SqlConnection con = new SqlConnection(sqlcon); SqlCommand com = new SqlCommand(sqlcom, con); con.Open(); SqlDataReader reader = com.ExecuteReader();
创建帐户或登录后发表意见