您的当前位置:首页正文

电子通讯录系统的设计与实现

2020-05-09 来源:个人技术集锦


Web大作业设计

——电子通讯录系统的设计与实现

姓 班 学

名: 级: 号:

指导教师:

日 期:

一、 需求分析

现今,很多人会出现手机遗失、被盗等等问题引起的通讯录丢失,为日常的人际交往带来较大麻烦。当然,我们可以将通讯录备份在自己的电脑上,或者用纸质备份。但,我们不得不考虑的是,这些方法也存在空间的局限性。或许某一天,我们的手机丢了又或者没电了,现在有个很紧急的电话要打,纸质备份未携带在身边,又不能在第一时间赶到自己的电脑旁边等等。在这些情况下,是否能有一条其他的方法来解决我们的燃眉之急呢?这,就是“网络通讯存储系统”存在的原因。在信息技术发达、网络身边每个角落的时代,我们还找不到一台电脑上网吗?只要登录“网络通讯存储系统”,我们就能在一定程度上得到帮助。

二、 模块设计

1、登录模块

2、注册模块

三、设计程序段

1、登录模块:Default

(1)Default.aspx:

<%@ Page Language=\"C#\" AutoEventWireup=\"true\" CodeFile=\"Default.aspx.cs\" Inherits=\"_Default\" %>

电子通讯录

               

                         

     

           

   
       

         

                    

   

              color: #000033; font-family: 华文行楷\">登录通讯录




          

           用户名: ErrorMessage=\"用户名、\" Style=\"z-index: 103; left: 372px; position: absolute; top: 229px\"

Text=\"*\">

top: 221px\" Width=\"141px\" OnTextChanged=\"TextBox1_TextChanged\">        

           

                    

      

           密  码:

top: 265px\">

text=\"*\">

      


            
 

            

            

Text=\"注册\" OnClick =\"Button2_Click\" Font-Size=\"Medium\" Height=\"26px\" Width=\"50px\" CausesValidation=\"False\" />

                       

                       

         

                   

(2)Default.aspx.cs:

using System;

using System.Data;

using System.Configuration; using System.Web;

using System.Web.Security; using System.Web.UI;

using System.Web.UI.WebControls;

using System.Web.UI.WebControls.WebParts; using System.Web.UI.HtmlControls; using System.Data.SqlClient;

public partial class _Default : System.Web.UI.Page {

protected void Page_Load(object sender, EventArgs e) {

}

protected void btOK_Click(object sender, EventArgs e) {

string myConnStr = \"Data Source=.;Initial Catalog=contact;Integrated Security=True\"; SqlConnection myConn = new SqlConnection(myConnStr);

string queryStr = \"select count(*) from Login where user_id='\" + TextBox1.Text + \"'and user_pwd='\" + TextBox2.Text + \"'\"; myConn.Open();

SqlCommand cmd=new SqlCommand (queryStr, myConn);

int count=Convert.ToInt32(cmd.ExecuteScalar()); myConn.Close(); try {

if (count>0) {

Session[\"user_id\"] = TextBox1.Text; Session[\"user_pwd\"] = TextBox2.Text; Response.BufferOutput = true; Response.Redirect(\"Group.aspx\"); } else {

Label1.Text = \"用户名或密码不正确\"; } }

catch(Exception ex) {

Console.WriteLine(\"Exception in main:\" + ex.Message);

} }

protected void Button2_Click(object sender, EventArgs e) {

Response.Redirect(\"zhuce.aspx\"); }

protected void TextBox1_TextChanged(object sender, EventArgs e) {

} }

2、注册界面:zhuce: (1)Zhuce.aspx

<%@ Page Language=\"C#\" AutoEventWireup=\"true\" Inherits=\"zhuce\" %>

CodeFile=\"zhuce.aspx.cs\"

1.0 Transitional//EN\"

注册

          
      

              注册
 

             用户名:

top: 107px\">

Text =\"*\">   

Style=\"z-index: 103; left: 454px; position: absolute; top: 104px\" ValidationExpression=\"^[a-zA-Z_]+[a-zA-Z0-9]*\" ControlToValidate=\"TextBox1\">  

             密码:

top: 144px\" Width=\"151px\">

text=\"*\">    

ErrorMessage=\"密码要求在6到15位之间\" Style=\"z-index: 106; left: 447px;

position: absolute;

top: 140px\" ValidationExpression=\"\\w{6,15}\">

             确认密码:

top: 178px\" Width=\"149px\">

Text=\"*\" >

ControlToValidate=\"TextBox3\" >

             查询密码问题:

top: 223px\">

Style=\"z-index: 117; left: 446px; position: absolute; top: 266px\" ValidationExpression=\"\\w{8,}\" ControlToValidate=\"TextBox6\" Width=\"188px\">

             查询密码答案:

top: 263px\">  

                





top: 364px\" Text=\"提交\"

OnClick =\"btOK_Click\" Height=\"25px\" Width=\"42px\"/>                 Style=\"position: relative; top: -41px; left: 83px;\" Text=\"取消\" Width=\"43px\" />   Style=\"left: 100px; position: relative; top: -42px\" Text=\"登录\" Width=\"42px\" />

               

(2)Zhuce.aspx.cs

using System;

using System.Data;

using System.Configuration; using System.Web;

using System.Web.Security; using System.Web.UI;

using System.Web.UI.WebControls;

using System.Web.UI.WebControls.WebParts; using System.Web.UI.HtmlControls; using System.Data.SqlClient;

public partial class zhuce : System.Web.UI.Page {

protected void Page_Load(object sender, EventArgs e) { }

protected void btOK_Click(object sender, EventArgs e) {

string myConnStr = \"Data Source=.;Initial Catalog=contact;Integrated Security=True\"; SqlConnection conn = new SqlConnection(myConnStr);

string queryStr = \"insert into Login(user_id,user_pwd,user_ques,user_anss) values('\" + TextBox1.Text + \"','\" + TextBox2.Text + \"','\" + TextBox5.Text + \"','\" + TextBox6.Text + \"')\";

SqlCommand myCom = new SqlCommand(queryStr, conn); if (Page.IsValid == true) {

myCom.Connection.Open(); myCom.ExecuteNonQuery(); myCom.Connection.Close(); Response.Write(\"\"); } else {

TextBox1.Text = \"\"; TextBox2.Text = \"\";

TextBox5.Text = \"\"; TextBox6.Text = \"\"; }

}

protected void Button2_Click(object sender, EventArgs e) {

Response.Redirect(\"Default.aspx\"); }

protected void Button3_Click(object sender, EventArgs e) {

TextBox1.Text = \"\"; TextBox2.Text = \"\"; TextBox3.Text = \"\";

TextBox5.Text = \"\"; TextBox6.Text = \"\"; } }

3、主界面:Group

(1) Group.aspx

册成功!<%@ Page Language=\"C#\" AutoEventWireup=\"true\" CodeFile=\"Group.aspx.cs\" Inherits=\"Group\" %>

Group

NavigateUrl=\"../tongxunlu/Default.aspx\">首页

你好!                     

 

通信组的维护

通信组的查询

NavigateUrl=\"../tongxunlu/AddGroup.aspx\">通信组的创建










(2)Group.aspx.cs

using System;

using System.Data;

using System.Configuration; using System.Collections; using System.Web;

using System.Web.Security; using System.Web.UI;

using System.Web.UI.WebControls;

using System.Web.UI.WebControls.WebParts; using System.Web.UI.HtmlControls;

public partial class Group : System.Web.UI.Page {

protected void Page_Load(object sender, EventArgs e) {

this.Label1.Text = Convert.ToString(Session[\"user_id\"]); } }

4、添加新通讯录分组:AddGroup. (1)AddGroup.aspx

<%@ Page Language=\"C#\" AutoEventWireup=\"true\" CodeFile=\"AddGroup.aspx.cs\" Inherits=\"_Default\" %>

无标题页

首页

通信组管理 ID=\"HyperLink1\" runat=\"server\" NavigateUrl=\"../tongxunlu/AddGroup.aspx\">创建通信组 


          

     

  

 


html

PUBLIC

\"-//W3C//DTD

XHTML

1.0

Transitional//EN\"

\"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">

创建人:

通信组名:

通信组描述 :

                


(2)AddGroup.aspx.cs

using System;

using System.Data;

using System.Configuration; using System.Web;

using System.Web.Security; using System.Web.UI;

using System.Web.UI.WebControls;

using System.Web.UI.WebControls.WebParts; using System.Web.UI.HtmlControls; using System.Data.SqlClient;

public partial class _Default : System.Web.UI.Page {

protected void Page_Load(object sender, EventArgs e) {

if (Session[\"user_id\"] == null) {

Response.Write(\"\"); } else {

this.Label1.Text = this.Label1.Text = Convert.ToString(Session[\"user_id\"]); } }

protected void Button1_Click(object sender, EventArgs e) {

SqlConnection conn = new SqlConnection(\"Data Source=.;Initial Catalog=contact;Integrated Security=True\"); conn.Open();

string sql = \"insert into TableGroup(user_id,Gname,GDescription)Values('\" + Label1.Text + \"','\" + TextBox3.Text + \"','\" + TextBox4.Text + \"')\"; SqlCommand cmd = new SqlCommand(sql, conn); cmd.ExecuteNonQuery(); conn.Close();

Response.Write(\"\"); }

protected void Button2_Click(object sender, EventArgs e) {

TextBox3.Text = \"\"; TextBox4.Text = \"\"; } }

5、添加新的联系人:AltPerson

(1)AltPersom.aspx

<%@ Page Language=\"C#\" AutoEventWireup=\"true\" CodeFile=\"AltPerson.aspx.cs\" Inherits=\"Add\" %>

无标题页

首页      通信组管理

你好!


添加联系人:

通信组ID
联系人姓名

联系人性别

联系人地址

邮政编码

联系人电话

联系人手机

联系人E-Mail


                       

 

               





 

    

(2)AltPersom.aspx.cs

using System;

using System.Data;

using System.Configuration; using System.Collections; using System.Web;

using System.Web.Security; using System.Web.UI;

using System.Web.UI.WebControls;

using System.Web.UI.WebControls.WebParts; using System.Web.UI.HtmlControls; using System.Data.SqlClient;

public partial class Add : System.Web.UI.Page {

protected void Page_Load(object sender, EventArgs e) {

if (!IsPostBack) {

Bind(); }

this.Label1.Text = Convert.ToString(Session[\"user_id\"]); this.Label2.Text = Convert.ToString(Session[\"GID\"]); }

public void Bind()

{

SqlConnection conn = new SqlConnection(\"Data Source=.;Initial Catalog=contact;Integrated Security=True\");

string sql = \"select * from TableUser where GID ='\" + Session[\"GID\"] + \"'\"; SqlDataAdapter DA = new SqlDataAdapter(sql, conn); DataSet DS = new DataSet(); DA.Fill(DS);

GridView1.DataKeyNames = new string[] { \"UID\" }; GridView1.DataSource = DS.Tables[0]; GridView1.DataBind();

}

protected void GridView1_RowEditing(object sender, GridViewEditEventArgs e) {

GridView1.EditIndex = e.NewEditIndex; Bind(); }

protected void GridView1_RowCancelingEdit(object sender, GridViewCancelEditEventArgs e) {

GridView1.EditIndex = -1; Bind(); }

protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e) {

int UID = Convert.ToInt32(GridView1.DataKeys[e.RowIndex].Values[0].ToString());

string Name = ((TextBox)(GridView1.Rows[e.RowIndex].Cells[2].Controls[0])).Text; string Gender = ((TextBox)(GridView1.Rows[e.RowIndex].Cells[3].Controls[0])).Text; string Address = ((TextBox)(GridView1.Rows[e.RowIndex].Cells[4].Controls[0])).Text; string PostCode = ((TextBox)(GridView1.Rows[e.RowIndex].Cells[5].Controls[0])).Text; string Telephone = ((TextBox)(GridView1.Rows[e.RowIndex].Cells[6].Controls[0])).Text;

string Mobile = ((TextBox)(GridView1.Rows[e.RowIndex].Cells[7].Controls[0])).Text; string Email = ((TextBox)(GridView1.Rows[e.RowIndex].Cells[8].Controls[0])).Text;

SqlConnection conn = new SqlConnection(\"Data Source=.;Initial Catalog=contact;Integrated Security=True\");

string SqlStr = \"update TableUser set Name='\" + Name + \"',Gender='\" + Gender + \"',PostCode='\" + PostCode + \"',Telephone='\" + Telephone + \"',Address='\" + Address + \"',Mobile='\" + Mobile + \"',Email='\" + Email + \"' where UID='\" + UID + \"'\";

try {

if (conn.State.ToString() == \"Closed\") conn.Open(); SqlCommand comm = new SqlCommand(SqlStr, conn); comm.ExecuteNonQuery(); comm.Dispose();

if (conn.State.ToString() == \"Open\") conn.Close();

GridView1.EditIndex = -1; Bind(); }

catch (Exception ex) {

Response.Write(\"数据库错误,错误原因:\" + ex.Message); Response.End(); } }

protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e) {

SqlConnection conn = new SqlConnection(\"Data Source=.;Initial Catalog=contact;Integrated Security=True\"); conn.Open();

string strsql = \"delete from TableUser where UID='\" + GridView1.DataKeys[e.RowIndex].Value.ToString() + \"'\";

SqlCommand comm = new SqlCommand(strsql, conn);

comm.ExecuteNonQuery(); conn.Close(); Bind(); }

protected void Button1_Click(object sender, EventArgs e) {

SqlConnection conn = new SqlConnection(\"Data Source=.;Initial Catalog=contact;Integrated Security=True\"); conn.Open(); string sql = \"insert into TableUser(GID,Name,Gender,Address,PostCode,Telephone,Mobile,Email) values('\" + Session[\"GID\"] + \"','\" + TextBox2.Text + \"','\" + TextBox3.Text + \"','\" + TextBox4.Text + \"','\" + TextBox5.Text + \"','\" + TextBox6.Text + \"','\" + TextBox7.Text + \"','\" + TextBox8.Text + \"')\"; SqlCommand comm = new SqlCommand(sql, conn); comm.ExecuteNonQuery(); conn.Close();

Response.Write(\"\"); Bind(); }

protected void Button2_Click(object sender, EventArgs e) {

TextBox8.Text = \"\"; TextBox7.Text = \"\"; TextBox6.Text = \"\"; TextBox5.Text = \"\"; TextBox4.Text = \"\"; TextBox3.Text = \"\"; TextBox2.Text = \"\"; } }

6、修改分组:AltGroup

(1)AltGroup.aspx

<%@ Page Language=\"C#\" AutoEventWireup=\"true\" CodeFile=\"AddGroup.aspx.cs\" Inherits=\"_Default\" %>

无标题页

首页 通信组管理 ID=\"HyperLink1\" runat=\"server\" NavigateUrl=\"../tongxunlu/AddGroup.aspx\">创建通信组 


          

     

  

 


创建人:
通信组名:

通信组描述 :

                

Text=\"取消\" OnClick=\"Button2_Click\" />


(2)AltGroup.aspx.cs

using System;

using System.Data;

using System.Configuration; using System.Web;

using System.Web.Security; using System.Web.UI;

using System.Web.UI.WebControls;

using System.Web.UI.WebControls.WebParts; using System.Web.UI.HtmlControls; using System.Data.SqlClient;

public partial class _Default : System.Web.UI.Page {

protected void Page_Load(object sender, EventArgs e) {

if (Session[\"user_id\"] == null) {

Response.Write(\"\"); } else {

this.Label1.Text = this.Label1.Text = Convert.ToString(Session[\"user_id\"]); } }

protected void Button1_Click(object sender, EventArgs e) {

SqlConnection conn = new SqlConnection(\"Data Source=.;Initial Catalog=contact;Integrated Security=True\"); conn.Open();

string sql = \"insert into TableGroup(user_id,Gname,GDescription)Values('\" + Label1.Text + \"','\" + TextBox3.Text + \"','\" + TextBox4.Text + \"')\"; SqlCommand cmd = new SqlCommand(sql, conn);

cmd.ExecuteNonQuery(); conn.Close();

Response.Write(\"\"); }

protected void Button2_Click(object sender, EventArgs e) {

TextBox3.Text = \"\"; TextBox4.Text = \"\"; } }

四、运行程序,验证结果

1、登录

2.注册

3、添加分组

4、添加联系人

5.、查询联系人

五、设计总结

经过一个多星期的大作业设计,使我对C#有了更进一步的认识和了解,要学好它重在实践,要通过不断地上机操作才能更好地学习它。上课时学到的关于C#的东西比较少,都是一些枯燥的东西。通过大作业设计,自己动手、自己发现和解决问题,发现了许多自己的不足。平时没有掌握好的知识在设计中彻底暴露了出来,,比如与数据库连接时连接不上等等。

这次试验我视线了实验要求上的部分功能,例如通讯录的注册,创建通讯组,添加联系人,显示联系人信息与维护以及查找通讯录。但是没有实现密码修改以及编辑修改联系人的信息。

要熟悉这门语言,仅在上课时学习的那点东西是不够的,这门语言也要求我们有比较强的实践能力,因为我们学习的知识就是为了实践,而只有多实践,多编写程序,才能更好的理解与掌握课堂上所学到的东西。

因篇幅问题不能全部显示,请点此查看更多更全内容