C#通讯录管理系统.doc

上传人:韩长文 文档编号:8635412 上传时间:2020-12-08 格式:DOC 页数:32 大小:387KB
返回 下载 相关 举报
C#通讯录管理系统.doc_第1页
第1页 / 共32页
C#通讯录管理系统.doc_第2页
第2页 / 共32页
C#通讯录管理系统.doc_第3页
第3页 / 共32页
C#通讯录管理系统.doc_第4页
第4页 / 共32页
C#通讯录管理系统.doc_第5页
第5页 / 共32页
点击查看更多>>
资源描述

《C#通讯录管理系统.doc》由会员分享,可在线阅读,更多相关《C#通讯录管理系统.doc(32页珍藏版)》请在三一文库上搜索。

1、.C#通讯录管理系统一 课程设计目的和内容概述1.目的:加深对C#语言课程所学知识的理解,进一步巩固C#语言编程方法。学会编制结构清晰、风格良好、数据结构适当的C#语言程序,从而具备解决综合性实际问题的能力,加强动手能力。2.内容:设计一个简易的手机通讯录管理系统。该题目要求在熟练掌握C#语言的基本知识:数据类型(整形、实型、字符型、指针、数组、结构等);运算类型(算术运算、逻辑运算、自增自减运算、赋值运算等);程序结构(顺序结构、判断选择结构、循环结构);大程序的功能分解方法(即函数的使用)等。进一步掌握各种函数的应用,包括时间函数、绘图函数,以及文件的读写操作等。其中结构体,函数的调用,算

2、法的设计是尤为重要的。二 题目 通讯录管理系统问题描述 该系统模拟现实通讯录管理系统,实现对计算机中的通讯录进行管理 基本要求 要能提供以下几种功能: (1)查看功能:选择此功能时,列出下列三类选择精品.:A:同学B:家人(2)当选中某类时,显示出此类所有数据中的姓名和电话号码 (3)添加数据功能:能录入新数据,每个结点包括:姓名,电话号码,分类,电子邮件。 例如:杨春13589664454同学类 当录入重复的姓名和电话号码时,则提示数据录入重复并取消录入;当通讯录中超过15条信息时,存储空间已满,不能再录入新数据;录入的新数据能按递增的顺序自动进行条目编号。 (4)修改功能:选中某个人的姓名

3、时,可对此人的相应数据进行修改。 (5)删除功能:选中某个人的姓名时,可对此人的相应数据进行删除,并自动调整后续条目的编号。三 程序设计1.总体设计 首先,因为每个个体有多种信息,所以要建立Main函数来储存和整合各个信息。然后利用控件来分别实现程序的各个功能。各个精品.控件用c#函数来实现,进而实现所需功能。最后将输入的信息存入数据苦,以便重复使用。四 程序源代码frmLogin.cs:using System;using System.Collections.Generic;using System.ComponentModel;using System.Data;using System

4、.Drawing;using System.Text;using System.Windows.Forms;using System.Data.SqlClient;namespace PhoneBook public partial class frmLogin : Form public frmLogin() InitializeComponent(); private void btnCancel_Click(object sender, EventArgs e) Application.Exit(); private void btnOK_Click(object sender, Eve

5、ntArgs e) try /检测文本框内容 if (txtUserName.Text.Trim() = | txtPassword.Text.Trim() = ) MessageBox.Show(用户名和密码不能为空!,登录失败,MessageBoxButtons.OK,MessageBoxIcon.Error); return;精品. /验证用户 SqlConnection conn = new SqlConnection();conn.ConnectionString=server=.;database=PhoneBook;uid=sa;pwd=; conn.Open();string

6、sql = select count(*) from 用户 where 用户名=+txtUserName.Text.Trim()+ and 密码=+txtPassword.Text.Trim()+; SqlCommand cmd = new SqlCommand();cmd.Connection=conn;cmd.CommandText=sql; int result = Convert.ToInt32(cmd.ExecuteScalar(); conn.Close(); if (result = 1) /登录成功 frmMain f = new frmMain(); f.tsslUserNa

7、me.Text = txtUserName.Text.Trim(); f.Show(); this.Hide(); else MessageBox.Show(用户名和密码错误!, 登录失败, MessageBoxButtons.OK, MessageBoxIcon.Error); return; catch (Exception ee) MessageBox.Show(发生错误/r/n+ee.Message, 登录失败, MessageBoxButtons.OK, MessageBoxIcon.Error); return; frmMain:using System;using System.

8、Collections.Generic;using System.ComponentModel;using System.Data;精品.using System.Drawing;using System.Text;using System.Windows.Forms;using System.Data.SqlClient;using System.Configuration;namespace PhoneBook public partial class frmMain : Form public frmMain() InitializeComponent(); private string

9、 strConn = System.Configuration.ConfigurationManager.AppSettingsConnectionString; private void frmMain_Load(object sender, EventArgs e) LoadGroup(); if (trvGroup.Nodes.Count 0) trvGroup.SelectedNode = trvGroup.Nodes0; LoadList(); else lvContact.Clear(); private void LoadGroup() try trvGroup.Nodes.Cl

10、ear(); SqlConnection conn = new SqlConnection(strConn); SqlCommand cmd = new SqlCommand(); cmd.Connection = conn; cmd.CommandText = select distinct 组别 from 联系人 where 用户名=+tsslUserName.Text+; conn.Open();精品. SqlDataReader sdr = cmd.ExecuteReader(); while (sdr.Read() trvGroup.Nodes.Add(sdr0.ToString()

11、; sdr.Close(); conn.Close(); catch private void LoadList() if (trvGroup.Nodes.Count = 0) lvContact.Clear(); return; if (trvGroup.SelectedNode.Index = 0) string strGroup = trvGroup.SelectedNode.Text; try lvContact.Clear(); lvContact.Columns.Add(姓名,100); lvContact.Columns.Add(工作单位, 150); lvContact.Col

12、umns.Add(联系电话, 100); lvContact.Columns.Add(电子邮箱, 150); SqlConnection conn = new SqlConnection(strConn); SqlCommand cmd = new SqlCommand(); cmd.Connection = conn; cmd.CommandText = select 编号,姓名,工作单位,联系电话,电子邮箱 from 联系人 where 组别= + strGroup + and 用户名= + tsslUserName.Text + ; conn.Open(); SqlDataReader

13、sdr = cmd.ExecuteReader(); int count = 0; while (sdr.Read() ListViewItem lvi = new ListViewItem(); lvi.Text = sdr姓名.ToString(); lvi.SubItems.Add(sdr工作单位.ToString();精品. lvi.SubItems.Add(sdr联系电话.ToString(); lvi.SubItems.Add(sdr电子邮箱.ToString(); lvi.Tag = sdr编号; lvi.ImageIndex = 0; lvContact.Items.Add(l

14、vi); count+; tsslCount.Text = 共计+count.ToString()+个联系人; sdr.Close(); conn.Close(); catch private void frmMain_FormClosed(object sender, FormClosedEventArgs e) Application.Exit(); private void trvGroup_AfterSelect(object sender, TreeViewEventArgs e) LoadList(); private void 详细信息ToolStripMenuItem_Clic

15、k(object sender, EventArgs e) lvContact.View = View.Details; private void 详细信息ToolStripMenuItem1_Click(object sender, EventArgs e) lvContact.View = View.Details; 精品. private void 图标ToolStripMenuItem_Click(object sender, EventArgs e) lvContact.View = View.LargeIcon; private void 图标ToolStripMenuItem1_

16、Click(object sender, EventArgs e) lvContact.View = View.LargeIcon; private void Add() frmAdd f = new frmAdd(); if (f.ShowDialog(this) = DialogResult.OK) LoadGroup(); if (trvGroup.Nodes.Count 0) trvGroup.SelectedNode = trvGroup.Nodes0; LoadList(); else lvContact.Clear(); private void Edit() if (lvCon

17、tact.SelectedItems.Count = 1) int id = Convert.ToInt32(lvContact.SelectedItems0.Tag); frmEdit f = new frmEdit(id); if (f.ShowDialog(this) = DialogResult.OK) LoadGroup(); if (trvGroup.Nodes.Count 0) trvGroup.SelectedNode = trvGroup.Nodes0; LoadList();精品. else lvContact.Clear(); private void Delete()

18、if (lvContact.SelectedItems.Count 0) trvGroup.SelectedNode = trvGroup.Nodes0; LoadList(); else lvContact.Clear();精品. catch private void Search() frmSearch f = new frmSearch(tsslUserName.Text); f.ShowDialog(); private void tsbtnAdd_Click(object sender, EventArgs e) Add(); private void 增加ToolStripMenu

19、Item_Click(object sender, EventArgs e) Add(); private void 修改MToolStripMenuItem_Click(object sender, EventArgs e) Edit(); private void tsbtnEdit_Click(object sender, EventArgs e) Edit(); private void 删除ToolStripMenuItem_Click(object sender, EventArgs e) Delete(); private void tsbtnDelete_Click(objec

20、t sender, EventArgs e) Delete(); 精品. private void lvContact_MouseDoubleClick(object sender, MouseEventArgs e) Edit(); private void lvContact_KeyDown(object sender, KeyEventArgs e) if (e.KeyCode = Keys.Delete) Delete(); private void tsbtnSearch_Click(object sender, EventArgs e) Search(); private void

21、 搜索SToolStripMenuItem_Click(object sender, EventArgs e) Search(); frmAdd.cs:using System;using System.Collections.Generic;using System.ComponentModel;using System.Data;using System.Drawing;using System.Text;using System.Windows.Forms;using System.Data.SqlClient;using System.Configuration;using Syste

22、m.IO;namespace PhoneBook public partial class frmAdd : Form public frmAdd()精品. InitializeComponent(); private string strUserName = ; private int groupCount = 0; private int contentCount = 0; private string txtFilePath = ; private string strConn = System.Configuration.ConfigurationManager.AppSettings

23、ConnectionString; private void pic_Click(object sender, EventArgs e) if (dlg.ShowDialog() = DialogResult.OK) pic.Image = Image.FromFile(dlg.FileName); txtFilePath = dlg.FileName; private void 加载图片LToolStripMenuItem_Click(object sender, EventArgs e) if (dlg.ShowDialog() = DialogResult.OK) pic.Image =

24、 Image.FromFile(dlg.FileName); txtFilePath = dlg.FileName; protected void btnOK_Click(object sender, EventArgs e) #region 获取信息 /用户名 strUserName = (frmMain)(this.Owner).tsslUserName.Text; /姓名 string name; if (txtName.Text = ) MessageBox.Show(联系人姓名不能为空!, 添加失败, MessageBoxButtons.OK, MessageBoxIcon.Erro

25、r); return; 精品. else name = txtName.Text; /组别 string group; if (cmbGroup.Text.Trim() = ) group = 未分组; else group = cmbGroup.Text.Trim(); /电话 string phone = txtPhone.Text.Trim(); /工作单位 string company = txtCompany.Text.Trim(); /email string email = txtEmail.Text.Trim(); /照片 byte b=null; if (txtFilePat

26、h != ) try FileStream fs = new FileStream(txtFilePath, FileMode.Open, FileAccess.Read); int len = Convert.ToInt32(fs.Length); b = new bytelen; fs.Read(b, 0, len); fs.Close(); catch b = null; #endregion 获取信息 #region 添加数据 try SqlConnection conn = new SqlConnection(strConn);精品. SqlCommand cmd_maxid = new SqlCommand(); cmd_maxid.Connection = conn; /获取最大编号 cmd_maxid.CommandText = select isnull(max(编号),0)+1 from 联系人; conn.Open(); int maxid ; try maxid = Convert.ToInt32(cmd_maxid.ExecuteScalar(); catch maxid = 1; /insert SqlCommand cmd_insert = new SqlCommand(); cmd_insert.Connect

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 科普知识


经营许可证编号:宁ICP备18001539号-1