C#通讯录管理系统方案.docx

上传人:b****1 文档编号:13223455 上传时间:2023-06-12 格式:DOCX 页数:36 大小:37.19KB
下载 相关 举报
C#通讯录管理系统方案.docx_第1页
第1页 / 共36页
C#通讯录管理系统方案.docx_第2页
第2页 / 共36页
C#通讯录管理系统方案.docx_第3页
第3页 / 共36页
C#通讯录管理系统方案.docx_第4页
第4页 / 共36页
C#通讯录管理系统方案.docx_第5页
第5页 / 共36页
C#通讯录管理系统方案.docx_第6页
第6页 / 共36页
C#通讯录管理系统方案.docx_第7页
第7页 / 共36页
C#通讯录管理系统方案.docx_第8页
第8页 / 共36页
C#通讯录管理系统方案.docx_第9页
第9页 / 共36页
C#通讯录管理系统方案.docx_第10页
第10页 / 共36页
C#通讯录管理系统方案.docx_第11页
第11页 / 共36页
C#通讯录管理系统方案.docx_第12页
第12页 / 共36页
C#通讯录管理系统方案.docx_第13页
第13页 / 共36页
C#通讯录管理系统方案.docx_第14页
第14页 / 共36页
C#通讯录管理系统方案.docx_第15页
第15页 / 共36页
C#通讯录管理系统方案.docx_第16页
第16页 / 共36页
C#通讯录管理系统方案.docx_第17页
第17页 / 共36页
C#通讯录管理系统方案.docx_第18页
第18页 / 共36页
C#通讯录管理系统方案.docx_第19页
第19页 / 共36页
C#通讯录管理系统方案.docx_第20页
第20页 / 共36页
亲,该文档总共36页,到这儿已超出免费预览范围,如果喜欢就下载吧!
下载资源
资源描述

C#通讯录管理系统方案.docx

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

C#通讯录管理系统方案.docx

C#通讯录管理系统方案

C#通讯录管理系统

一课程设计目的和内容概述

1.目的:

加深对《C#语言》课程所学知识的理解,进一步巩固C#语言编程方法。

学会编制结构清晰、风格良好、数据结构适当的C#语言程序,从而具备解决综合性实际问题的能力,加强动手能力。

2.内容:

设计一个简易的手机通讯录管理系统。

该题目要求在熟练掌握C#语言的基本知识:

数据类型〔整形、实型、字符型、指针、数组、结构等;运算类型〔算术运算、逻辑运算、自增自减运算、赋值运算等;程序结构〔顺序结构、判断选择结构、循环结构;大程序的功能分解方法〔即函数的使用等。

进一步掌握各种函数的应用,包括时间函数、、绘图函数,以及文件的读写操作等。

其中结构体,函数的调用,算法的设计是尤为重要的。

二题目

通讯录管理系统

[问题描述]

该系统模拟现实通讯录管理系统,实现对计算机中的通讯录进行管理

[基本要求]

要能提供以下几种功能:

<1>查看功能:

选择此功能时,列出下列三类选择:

A:

同学 B:

家人

<2>当选中某类时,显示出此类所有数据中的姓名和电话号码

<3>添加数据功能:

能录入新数据,每个结点包括:

姓名,电话号码,分类,电子邮件。

例如:

 杨春同学类 chuny@

当录入重复的姓名和电话号码时,则提示数据录入重复并取消录入;当通讯录中超过15条信息时,存储空间已满,不能再录入新数据;录入的新数据能按递增的顺序自动进行条目编号。

<4>修改功能:

选中某个人的姓名时,可对此人的相应数据进行修改。

<5>删除功能:

选中某个人的姓名时,可对此人的相应数据进行删除,并自动调整后续条目的编号。

三程序设计

1.总体设计

首先,因为每个个体有多种信息,所以要建立Main函数来储存和整合各个信息。

然后利用控件来分别实现程序的各个功能。

各个控件用c#函数来实现,进而实现所需功能。

最后将输入的信息存入数据苦,以便重复使用。

四程序源代码

frmLogin.cs:

usingSystem;

usingSystem.Collections.Generic;

usingSystem.ComponentModel;

usingSystem.Data;

usingSystem.Drawing;

usingSystem.Text;

usingSystem.Windows.Forms;

usingSystem.Data.SqlClient;

namespacePhoneBook

{

publicpartialclassfrmLogin:

Form

{

publicfrmLogin<>

{

InitializeComponent<>;

}

privatevoidbtnCancel_Click

{

Application.Exit<>;

}

privatevoidbtnOK_Click

{

try

{

//检测文本框内容

if==""||txtPassword.Text.Trim<>=="">

{

MessageBox.Show<"用户名和密码不能为空!

","登录失败",MessageBoxButtons.OK,MessageBoxIcon.Error>;

return;

}

//验证用户

SqlConnectionconn=newSqlConnection<>;

conn.ConnectionString="server=.;database=PhoneBook;uid=sa;pwd=;";

conn.Open<>;

stringsql="selectcount<*>from用户where用户名='"+txtUserName.Text.Trim<>+"'and密码='"+txtPassword.Text.Trim<>+"'";

SqlCommandcmd=newSqlCommand<>;

cmd.Connection=conn;

cmd.CommandText=sql;

intresult=Convert.ToInt32>;

conn.Close<>;

if

{

//登录成功

frmMainf=newfrmMain<>;

f.tsslUserName.Text=txtUserName.Text.Trim<>;

f.Show<>;

this.Hide<>;

}

else

{

MessageBox.Show<"用户名和密码错误!

","登录失败",MessageBoxButtons.OK,MessageBoxIcon.Error>;

return;

}

}

catch

{

MessageBox.Show<"发生错误/r/n"+ee.Message,"登录失败",MessageBoxButtons.OK,MessageBoxIcon.Error>;

return;

}

}

}

}

frmMain:

usingSystem;

usingSystem.Collections.Generic;

usingSystem.ComponentModel;

usingSystem.Data;

usingSystem.Drawing;

usingSystem.Text;

usingSystem.Windows.Forms;

usingSystem.Data.SqlClient;

usingSystem.Configuration;

namespacePhoneBook

{

publicpartialclassfrmMain:

Form

{

publicfrmMain<>

{

InitializeComponent<>;

}

privatestringstrConn=System.Configuration.ConfigurationManager.AppSettings["ConnectionString"];

privatevoidfrmMain_Load

{

LoadGroup<>;

if0>

{

trvGroup.SelectedNode=trvGroup.Nodes[0];

LoadList<>;

}

else

{

lvContact.Clear<>;

}

}

privatevoidLoadGroup<>

{

try

{

trvGroup.Nodes.Clear<>;

SqlConnectionconn=newSqlConnection;

SqlCommandcmd=newSqlCommand<>;

cmd.Connection=conn;

cmd.CommandText="selectdistinct组别from联系人where用户名='"+tsslUserName.Text+"'";

conn.Open<>;

SqlDataReadersdr=cmd.ExecuteReader<>;

while>

{

trvGroup.Nodes.Add>;

}

sdr.Close<>;

conn.Close<>;

}

catch

{}

}

privatevoidLoadList<>

{

if

{

lvContact.Clear<>;

return;

}

if=0>

{

stringstrGroup=trvGroup.SelectedNode.Text;

try

{

lvContact.Clear<>;

lvContact.Columns.Add<"姓名",100>;

lvContact.Columns.Add<"工作单位",150>;

lvContact.Columns.Add<"联系电话",100>;

lvContact.Columns.Add<"电子邮箱",150>;

SqlConnectionconn=newSqlConnection;

SqlCommandcmd=newSqlCommand<>;

cmd.Connection=conn;

cmd.CommandText="select编号,姓名,工作单位,联系电话,电子邮箱from联系人where组别='"+strGroup+"'and用户名='"+tsslUserName.Text+"'";

conn.Open<>;

SqlDataReadersdr=cmd.ExecuteReader<>;

intcount=0;

while>

{

ListViewItemlvi=newListViewItem<>;

lvi.Text=sdr["姓名"].ToString<>;

lvi.SubItems.Add>;

lvi.SubItems.Add>;

lvi.SubItems.Add>;

lvi.Tag=sdr["编号"];

lvi.ImageIndex=0;

lvContact.Items.Add;

count++;

}

tsslCount.Text="共计"+count.ToString<>+"个联系人";

sdr.Close<>;

conn.Close<>;

}

catch

{}

}

}

privatevoidfrmMain_FormClosed

{

Application.Exit<>;

}

privatevoidtrvGroup_AfterSelect

{

LoadList<>;

}

privatevoid详细信息ToolStripMenuItem_Click

{

lvContact.View=View.Details;

}

privatevoid详细信息ToolStripMenuItem1_Click

{

lvContact.View=View.Details;

}

privatevoid图标ToolStripMenuItem_Click

{

lvContact.View=View.LargeIcon;

}

privatevoid图标ToolStripMenuItem1_Click

{

lvContact.View=View.LargeIcon;

}

privatevoidAdd<>

{

frmAddf=newfrmAdd<>;

if==DialogResult.OK>

{

LoadGroup<>;

if0>

{

trvGroup.SelectedNode=trvGroup.Nodes[0];

LoadList<>;

}

else

{

lvContact.Clear<>;

}

}

}

privatevoidEdit<>

{

if

{

intid=Convert.ToInt32;

frmEditf=newfrmEdit;

if==DialogResult.OK>

{

LoadGroup<>;

if0>

{

trvGroup.SelectedNode=trvGroup.Nodes[0];

LoadList<>;

}

else

{

lvContact.Clear<>;

}

}

}

}

privatevoidDelete<>

{

if

{

return;

}

if

","删除确认",MessageBoxButtons.YesNo,MessageBoxIcon.Question>==DialogResult.Yes>

{

stringstrWhere="where编号in<";

foreach

{

strWhere+=lvi.Tag.ToString<>+",";

}

strWhere=strWhere.Substring<0,strWhere.Length-1>;

strWhere+=">";

try

{

SqlConnectionconn=newSqlConnection;

SqlCommandcmd=newSqlCommand<>;

cmd.Connection=conn;

cmd.CommandText="deletefrom联系人"+strWhere;

conn.Open<>;

cmd.ExecuteNonQuery<>;

conn.Close<>;

LoadGroup<>;

>0>

{

trvGroup.SelectedNode=trvGroup.Nodes[0];

LoadList<>;

}

else

{

lvContact.Clear<>;

}

}

catch{}

}

}

privatevoidSearch<>

{

frmSearchf=newfrmSearch;

f.ShowDialog<>;

}

privatevoidtsbtnAdd_Click

{

Add<>;

}

privatevoid增加ToolStripMenuItem_Click

{

Add<>;

}

privatevoid修改MToolStripMenuItem_Click

{

Edit<>;

}

privatevoidtsbtnEdit_Click

{

Edit<>;

}

privatevoid删除ToolStripMenuItem_Click

{

Delete<>;

}

privatevoidtsbtnDelete_Click

{

Delete<>;

}

privatevoidlvContact_MouseDoubleClick

{

Edit<>;

}

privatevoidlvContact_KeyDown

{

if

{

Delete<>;

}

}

privatevoidtsbtnSearch_Click

{

Search<>;

}

privatevoid搜索SToolStripMenuItem_Click

{

Search<>;

}

}

}

frmAdd.cs:

usingSystem;

usingSystem.Collections.Generic;

usingSystem.ComponentModel;

usingSystem.Data;

usingSystem.Drawing;

usingSystem.Text;

usingSystem.Windows.Forms;

usingSystem.Data.SqlClient;

usingSystem.Configuration;

usingSystem.IO;

namespacePhoneBook

{

publicpartialclassfrmAdd:

Form

{

publicfrmAdd<>

{

InitializeComponent<>;

}

privatestringstrUserName="";

privateintgroupCount=0;

privateintcontentCount=0;

privatestringtxtFilePath="";

ationManager.AppSettings["ConnectionString"];

privatevoidpic_Click

{

if==DialogResult.OK>

{

pic.Image=Image.FromFile;

txtFilePath=dlg.FileName;

}

}

privatevoid加载图片LToolStripMenuItem_Click

{

if==DialogResult.OK>

{

pic.Image=Image.FromFile;

txtFilePath=dlg.FileName;

}

}

protectedvoidbtnOK_Click

{

#region获取信息

//用户名

strUserName=<>.tsslUserName.Text;

//姓名

stringname;

if

{

MessageBox.Show<"联系人姓名不能为空!

","添加失败",MessageBoxButtons.OK,MessageBoxIcon.Error>;

return;

}

else

{

name=txtName.Text;

}

//组别

stringgroup;

if=="">

{

group="未分组";

}

else

{

group=cmbGroup.Text.Trim<>;

}

//电话

stringphone=txtPhone.Text.Trim<>;

//工作单位

stringcompany=txtCompany.Text.Trim<>;

//email

stringemail=txtEmail.Text.Trim<>;

//照片

byte[]b=null;

if

="">

{

try

{

FileStreamfs=newFileStream;

intlen=Convert.ToInt32;

b=newbyte[len];

fs.Read;

fs.Close<>;

}

catch

{

b=null;

}

}

#endregion获取信息

#region添加数据

try

{

SqlConnectionconn=newSqlConnection;

SqlCommandcmd_maxid=newSqlCommand<>;

cmd_maxid.Connection=conn;

//获取最大编号

cmd_maxid.CommandText="selectisnull,0>+1from联系人";

conn.Open<>;

intmaxid;

try

{

maxid=Convert.ToInt32>;

}

catch

{

maxid=1;

}

//insert

SqlCommandcmd_insert=newSqlCommand<>;

cmd_insert.Connection=conn;

cmd_insert.CommandText="insertinto联系人<编号,用户名,组别,姓名,工作单位,联系电话,电子

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

当前位置:首页 > 自然科学 > 物理

copyright@ 2008-2023 冰点文库 网站版权所有

经营许可证编号:鄂ICP备19020893号-2