C#通讯录系统实习报告

  • 格式:doc
  • 大小:1.42 MB
  • 文档页数:22

经济管理学院C#语言课程设计专业班级电子商务091 学生姓名王晓敏学号 090207107指导教师陈军霞王玉恒李庆恒董绍辉2011年 2 月第一部分软件设计内容 (3)1.1设计构思 (3)1.2软件功能的验收标准 (3)1.3系统数据流程图 (4)1.4软件功能说明 (4)1、用户登录 (4)2、添加联系人 (4)3、查找联系人 (4)4、修改联系人 (5)5、删除联系人 (5)1.5开发及运行环境 (5)第二部分数据库设计 (5)2.1用户信息表(tuser) (5)2.2资料信息表(my) (6)第三部分通讯录系统的实现 (6)3.1登录界面的设计 (6)3.2主页面的设计 (8)3.3追加窗口的设计 (10)} (12)3.4查找、删除、修改界面的设计 (12)} (16)3.5显示所有联系人 (16)3.6结果分析 (18)总结 (21)第一部分软件设计内容1.1设计构思通讯录系统主要功能用户的登录以及数据的维护。

用户登录:在数据库里设置user表,对具有用户名和密码的人方可访问数据库中其他数据。

数据的维护:包括数据的查询、添加、修改、删除的功能,对数据库中联系人进行各种操作。

1.2软件功能的验收标准一、有较为美观简洁大方的菜单,能保证用户方便、直观、快捷的熟悉并使用软件的各项功能。

二、有严密正确的数据验证功能和数据处理功能,能够求和、求平均成绩,对总成绩进行排序,对数据进行保存和读取,能按学号查找学生信息,以及插入和删除学生信息。

三、系统要有一定的可靠性。

1.3系统数据流程图1.4软件功能说明1、用户登录该系统为私人所用,所以只有在user表中存在的用户名及密码可以登录该系统,可以防止载入的联系人信息被非法利用。

2、添加联系人此功能是添加新的数据,把所需添加的联系人信息输入到数据库中的my表中,为以后使用做准备3、查找联系人此功能是根据姓名查找表中存在的联系人各种信息,为后面的各种操作做准备。

4、修改联系人此功能是把查出的联系人的各种信息做修改,并保存在数据库中的my表中。

5、删除联系人此功能是把my表中存在的某条不需要的信息删除。

1.5开发及运行环境本系统开发平台及运行环境如下:系统开发平台:Microsoft Visual Studio 2005系统开发语言:C#数据库管理软件:SQL Server 2000运行平台:Windows XP (SP2) / Windows2000 (SP4) / Windows Server 2003 (SP1)运行环境: Framework SDK v2.0分辨率: 最佳效果 1024×768 像素说明:SP(Service Pack)为Windows操作系统补丁。

第二部分数据库设计2.1用户信息表(tuser)2.2资料信息表(my)第三部分通讯录系统的实现3.1登录界面的设计登录界面如下:说明:密码为1。

主要代码实现如下:using System;using System.Collections.Generic;using ponentModel;using System.Data;using System.Data.SqlClient;using System.Drawing;using System.Text.RegularExpressions;using System.Windows.Forms;namespace WindowsApplication1{public partial class Form1 : Form{public Form1(){InitializeComponent();}private void button1_Click(object sender, EventArgs e){if (textBox1.Text.Trim() == ""){MessageBox.Show("用户名不能为空!");return;}else if (textBox2.Text.Trim() == ""){MessageBox.Show("密码不能为空");return;}string cs = "select name,pwd from tuser where name='" + textBox1.Text + "'and pwd ='" + textBox2.Text + "'";try{SqlConnection cn = new SqlConnection();cn.ConnectionString = "Initial Catalog=通讯录系统;DataSource=(local);Integrated Security=true";SqlCommand cmd = new SqlCommand();cn.Open();mandText = cs;cmd.Connection = cn;SqlDataReader dr = cmd.ExecuteReader();if (dr.HasRows){dr.Read();Form2 f2 = new Form2();f2.Show();this.Hide();}else{MessageBox.Show(" 该用户不存在!!");}}catch (Exception error){MessageBox.Show(error.ToString());}}private void button2_Click(object sender, EventArgs e){Application.Exit();}private void Form1_Closed(object sender, System.EventArgs e) {Application.Exit();}private void Form1_Load(object sender, EventArgs e){}}}3.2主页面的设计主页面设计如下:主要代码如下:using System;using System.Collections.Generic;using ponentModel;using System.Data;using System.Drawing;using System.Text;using System.Windows.Forms;namespace WindowsApplication1{public partial class Form2 : Form{public Form2(){InitializeComponent();}private void button1_Click(object sender, EventArgs e) {Form3 f3 = new Form3();f3.Show();this.Close();}private void button2_Click(object sender, EventArgs e) {Form4 f4 = new Form4();f4.Show();this.Close();}private void Form2_Closed(object sender, EventArgs e) {Application.Exit();}private void Form2_Load(object sender, EventArgs e){}private void button3_Click(object sender, EventArgs e) {Application.Exit();}private void button4_Click(object sender, EventArgs e) {Form5 f5 = new Form5(); f5.Show();this.Hide();}}}3.3追加窗口的设计添加联系人窗口设计:主要代码如下显示:using System;using System.Collections.Generic; using ponentModel;using System.Data;using System.Data.SqlClient;using System.Drawing;using System.Text;using System.Windows.Forms;namespace WindowsApplication1{public partial class Form3 : Form {public Form3(){InitializeComponent();}private void Form3_Load(object sender, EventArgs e){}private void button1_Click(object sender, EventArgs e){if (textBox1.Text.Trim() == ""){MessageBox.Show("姓名不能为空!");}else if (textBox2.Text.Trim() == ""){MessageBox.Show("班级不能为空!");}else if (textBox3.Text.Trim() == ""){MessageBox.Show("手机不能为空");}else{SqlConnection conn = new SqlConnection();conn.ConnectionString = "initial catalog=通讯录系统;DataSource=(local);integrated security=true;";conn.Open();SqlCommand cmd = new SqlCommand();cmd.Connection = conn;mandText = "insert into my(name,class,tele,qq,hometown,hobby,birthday) values('"+ textBox1.Text + "','"+ textBox2.Text + "','"+ textBox3.Text + "','"+ textBox4.Text + "','" + textBox5.Text + "','" + textBox6.Text + "','" + textBox7.Text + "')";cmd.ExecuteNonQuery();MessageBox.Show("已插入联系人!");Form2 f2 = new Form2();f2.Show();this.Close();}}private void button2_Click(object sender, EventArgs e){Form2 f2 = new Form2();f2.Show();this.Close();}private void Form3_Closed(object sender, System.EventArgs e) {Application.Exit();}}}3.4查找、删除、修改界面的设计窗口设计:主要代码如下显示:using System;using System.Collections.Generic;using ponentModel;using System.Data;using System.Data.SqlClient;using System.Drawing;using System.Text;using System.Windows.Forms;namespace WindowsApplication1{public partial class Form4 : Form{public Form4(){InitializeComponent();}private void button3_Click(object sender, EventArgs e){string a = "select name,class,tele ,qq,hometown,hobby,birthday from my where name='" + textBox1.Text + "'";string b = "Initial Catalog= 通讯录系统;Data Source=(local);IntegratedSecurity=true";SqlConnection conn;SqlCommand cmd;SqlDataReader myReader;conn = new SqlConnection(b);conn.Open();cmd = new SqlCommand(a, conn);myReader = cmd.ExecuteReader();if (myReader.Read()){textBox2.Text = myReader["class"].ToString();textBox3.Text = myReader["tele"].ToString();textBox4.Text = myReader["qq"].ToString();textBox5.Text = myReader["hometown"].ToString();textBox6.Text = myReader["hobby"].ToString();textBox7.Text = myReader["birthday"].ToString();}else{MessageBox.Show("不存在此人信息!");}}private void button1_Click(object sender, EventArgs e){string a = textBox1.Text.Trim();string b = textBox2.Text.Trim();string c = textBox3.Text.Trim();string d = textBox4.Text.Trim();string f = textBox5.Text.Trim();string g = textBox6.Text.Trim();string h = textBox7.Text.Trim();xiugai(a, b, c, d, f, g, h);MessageBox.Show("修改成功!!!");}public int xiugai(string nm, string cl, string te, string qq, string home, string hobby, string birthday){SqlConnection conn = new SqlConnection(@"Data Source=(local);Initial Catalog=通讯录系统;Integrated Security=True");//Initial Catalog后面跟你数据库的名字,如果你的SqlServer服务器名称后面不带SQLEXPRESS,那么Data Source=.conn.Open();string sql = "update my setname=@nm,class=@cl,tele=@te,qq=@qq,hometown=@home,hobby=@hobby,birthday=@birthday where name=@nm";SqlCommand cmd = new SqlCommand(sql, conn);SqlParameter parn = new SqlParameter("@nm", nm);cmd.Parameters.Add(parn);SqlParameter parp = new SqlParameter("@cl", cl);cmd.Parameters.Add(parp);SqlParameter para = new SqlParameter("@te", te);cmd.Parameters.Add(para);SqlParameter parb = new SqlParameter("@qq", qq);cmd.Parameters.Add(parb);SqlParameter parc = new SqlParameter("@home", home);cmd.Parameters.Add(parc);SqlParameter pard = new SqlParameter("@hobby", hobby);cmd.Parameters.Add(pard);SqlParameter pare = new SqlParameter("@birthday", birthday);cmd.Parameters.Add(pare);int result = cmd.ExecuteNonQuery();//result接收受影响行数,也就是说result大于的话表示添加成功conn.Close();cmd.Dispose();return result;}private void button4_Click(object sender, EventArgs e){string t = textBox1.Text.Trim();//string f = textBox2.Text.Trim();string g = textBox3.Text.Trim();//string a = textBox4.Text.Trim();//string b = textBox5.Text.Trim();//string h = textBox6.Text.Trim();//string c = textBox7.Text.Trim();shanchu(t, g);textBox1.Clear();textBox2.Clear();textBox3.Clear();textBox4.Clear();textBox5.Clear();textBox6.Clear();textBox7.Clear();MessageBox.Show("删除成功!!!");}public int shanchu(string nm, string te){SqlConnection conn = new SqlConnection(@"Data Source=(local);Initial Catalog=通讯录系统;Integrated Security=True");//Initial Catalog后面跟你数据库的名字,如果你的SqlServer服务器名称后面不带SQLEXPRESS,那么Data Source=.conn.Open();string sql = "delete from my where name=@nm and tele=@te";SqlCommand cmd = new SqlCommand(sql, conn);SqlParameter parn = new SqlParameter("@nm", nm);cmd.Parameters.Add(parn);// SqlParameter parp = new SqlParameter("@cl", cl);// cmd.Parameters.Add(parp);SqlParameter para = new SqlParameter("@te", te);cmd.Parameters.Add(para);//SqlParameter parb = new SqlParameter("@qq", qq);//cmd.Parameters.Add(parb);//SqlParameter parc = new SqlParameter("@home", home);//cmd.Parameters.Add(parc);//SqlParameter parv = new SqlParameter("@hobby", hobby);//cmd.Parameters.Add(parv);//SqlParameter parr = new SqlParameter("@birth", birth);// cmd.Parameters.Add(parr);int result = cmd.ExecuteNonQuery();//result接收受影响行数,也就是说result大于的话表示添加成功conn.Close();cmd.Dispose();return result;}private void button2_Click(object sender, EventArgs e) {Form2 f4 = new Form2();f4.Show();this.Hide();}private void Form4_Load(object sender, EventArgs e){}private void button5_Click(object sender, EventArgs e) {Application.Exit();}}}3.5显示所有联系人窗口设计:代码编写:using System;using System.Collections.Generic;using ponentModel;using System.Data;using System.Drawing;using System.Text;using System.Windows.Forms;namespace WindowsApplication1{public partial class Form5 : Form{public Form5(){InitializeComponent();}private void Form5_Load(object sender, EventArgs e){// TODO: 这行代码将数据加载到表“通讯录系统DataSet.my”中。