武汉轻工大学软件系统设计大作业专业:软件工程班级:软工1203班学号:1205110627姓名:司福江指导老师:蒋丽华2015年5月2日一.实验目的通过制作一个电子通信录系统来掌握使用访问与操纵数据库的方法,或者设计制作教材中所述的伪邮件系统,或者设计制作自己拟定的工资、学籍、图书管理系统之类的系统。
二.实验内容1、电子通信录包括三部分信息:用户登录注册信息通信组信息联系人信息2、电子通信录系统应至少包括下列功能页面(页面布局自定):用户首先要进行注册,注册成功后,还要允许用户进行密码修改。
通信组的创建AddGroup.aspx通信组的显示与维护AltGroup.aspx(包括通信组信息的删除和修改)通信组是根据联系人之间的关系建立不同性质的Group,以上页面主要访问数据库中的TableGroup数据表。
页面主要功能分别为:组的创建和维护。
比如,可以建立亲友通信组、工作通信组、同学通信组以及其他类型通信组等。
联系人信息的添加AddPerson.aspx联系人信息的显示与维护AltPerson.aspx(包括联系人信息的删除和修改)根据联系人与通信组的关系,对联系人进行分类添加和维护,以上页面涉及到对TableUser数据表的操作,同时需要考虑与TableGroup数据表之间的关系。
查找通信录Find.aspx设置查找条件,用户可以直接输入查询关键字,也可以先选择通信组,再输入查询关键字,系统返回查询结果,可以绑定DataGrid控件来显示查询结果。
三.需求分析本系统除了用户的注册设计外,还可设置收发邮件的查看删除功能。
包括:加强信息保管的安全性;提高信息准确度和全面性;提高信息获取的便捷性;确保信息管理的高效性。
以Windows为操作系统,运SQLsever数据库技术,开发以Windows XP为用户的操作平台,界面友善、功能齐全的通讯录系统。
新系统的运行硬件环境PC机,当用户使用系统时,通过正确的口令进入系统,进行数据库的维护操作和运用。
操作上是对IE浏览器的引用,该浏览器的使用,主要凭借使用浏览操作技术即可完成数据录入,方便简单。
使用前只要对用户进行简单的说明或阅读帮助文件即可使用该系统。
四.系统框架1、登陆页面模块:登陆,注册用户模块。
2、用户注册页面模块。
3、主界面模块。
4、添加分组模块。
5、查询联系人模块。
五.主要模块代码、截图。
1、登录模块代码://登录按钮响应事件protected void Buttondenglu_Click(object sender, EventArgs e){string ConnString = "server=localhost; Initial Catalog=liumail; Integrated Security = SSPI";SqlConnection Conn = new SqlConnection(ConnString);string QueryStr = "select count(*) from TAB_UserInfo where UserID='" + TextBoxUsername.Text + "'and Password='" + TextBoxPassword.Text + "'";Conn.Open();SqlCommand cmd = new SqlCommand(QueryStr, Conn);int count = Convert.ToInt32(cmd.ExecuteScalar());try{if (count > 0){Session["UserID"] =TextBoxUsername.Text;Session["Password"] = TextBoxPassword.Text;Response.BufferOutput = true;Response.Redirect("Global.aspx");}else{Response.Write("<script language='javascript'>alert('用户名或者密码不正确!请重新输入')</script>");}}catch (Exception ex){Console.WriteLine("Exception in main:" + ex.Message);}Conn.Close();}注册按钮事件代码:protected void Buttonzhuce_Click(object sender, EventArgs e){Response.Redirect("Register.aspx");}}2、注册模块代码://注册按钮事件protected void ButtonOK_Click(object sender, EventArgs e){string ConnString = "server=localhost; Initial Catalog=liumail; Integrated Security = SSPI";SqlConnection Conn = new SqlConnection(ConnString);try{string InsertStr = "insert into TAB_UserInfo(UserID,UserName,Password,Address,QQ,ConfEmail)" +"values('" + TextBoxLoginName.Text + "','" + TextBoxUserName.Text + "','" + TextBoxPassword.Text + "','" + TextBoxAddress.Text + "','" + TextBoxQQ.Text + "','" + TextBoxEmail.Text + "')";SqlCommand myCom = new SqlCommand(InsertStr, Conn);if (RadioButtonAccept.Checked == true){myCom.Connection.Open();myCom.ExecuteNonQuery();myCom.Connection.Close();Response.Write("<script>alert('注册成功!');location.href='Login.aspx';</script>");}else{Response.Write("<script>alert('不接受服务条款,不能注册!')</script>");}}catch (Exception ex){Response.Write("<script>alert('注册失败!');</script>");TextBoxLoginName.Text = "";TextBoxUserName.Text = "";TextBoxPassword.Text = "";TextBoxAddress.Text = "";TextBoxQQ.Text = "";TextBoxEmail.Text = "";LabelMessage.Text = "";}}验证用户名是否存在:protected void ButtonCheck_Click(object sender, EventArgs e){string ConnString = "server=localhost; Initial Catalog=liumail; Integrated Security = SSPI";SqlConnection Conn = new SqlConnection(ConnString);string QueryStr = "select count(*) from TAB_UserInfo where UserID='" + TextBoxLoginName.Text + "'";Conn.Open();SqlCommand cmd = new SqlCommand(QueryStr, Conn);int count = Convert.ToInt32(cmd.ExecuteScalar());if (count > 0){LabelMessage.Text = "此用户名已被使用";TextBoxLoginName.Text = "";}else{LabelMessage.Text = "恭喜你!此用户名可使用";}Conn.Close();}}3.主界面模块代码:<style type="text/css">#line-chart {height:300px;width:800px;margin: 0px auto;margin-top: 1em;}.navbar-default .navbar-brand, .navbar-default .navbar-brand:hover { color: #fff;}.dropdown-menu {text-align:center; font-weight:bold;}</style><script type="text/javascript">$(function() {var uls = $('.sidebar-nav > ul > *').clone();uls.addClass('visible-xs');$('#main-menu').append(uls.clone());});</script><link rel="shortcut icon" href="../assets/ico/favicon.ico"><link rel="apple-touch-icon-precomposed" sizes="144x144"href="../assets/ico/apple-touch-icon-144-precomposed.png"> <link rel="apple-touch-icon-precomposed" sizes="114x114"href="../assets/ico/apple-touch-icon-114-precomposed.png"><link rel="apple-touch-icon-precomposed" sizes="72x72"href="../assets/ico/apple-touch-icon-72-precomposed.png"><link rel="apple-touch-icon-precomposed"href="../assets/ico/apple-touch-icon-57-precomposed.png"><div class="navbar navbar-default" role="navigation" style="background:#00ffdc;"> <div class="navbar-header"><button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target=".navbar-collapse"><span class="sr-only">Toggle navigation</span><span class="icon-bar"></span><span class="icon-bar"></span><span class="icon-bar"></span></button><a class="" href="index.html"><span class="navbar-brand"><span class="fa fa-paper-plane"></span> 联系薄</span></a></div><div class="navbar-collapse collapse" style="height: 1px; "><ul id="main-menu" class="nav navbar-nav navbar-right"><li class="dropdown hidden-xs"><a href="#" class="dropdown-toggle" data-toggle="dropdown"><span class="glyphicon glyphicon-user padding-right-small"style="position:relative;top: 3px;"></span> <%=Session["userName"].T oString() %><i class="fa fa-caret-down"></i></a><ul class="dropdown-menu"><li><a href="./">切换账号</a></li></ul></li></ul></div></div></div><div class="sidebar-nav"><ul><!--通讯录--><li><a href="#" data-target=".legal-menu" class="nav-header collapsed" data-toggle="collapse"><i class="fa fa-fw fa-legal"></i> 通讯录<i class="fafa-collapse"></i></a></li><li><ul class="legal-menu nav nav-list collapse"><%String[] gnames = getGroupNames();foreach (String gname in gnames) {Response.Write("<li><a href='showcontacts.aspx?gname="+gname+"' target='contentFrame'><span class='fa fa-caret-right'></span>"+ gname+"</a></li>");}%><li id="search" ><a href="findcontact.aspx" target="contentFrame"><span class="fa fa-caret-right"></span> 查询</a></li><li><a href="groupmang.aspx" target="contentFrame"><span class="fafa-caret-right"></span>组管理</a></li></ul></li><li><a href="#" data-target=".accounts-menu" class="nav-header collapsed"data-toggle="collapse"><i class="fa fa-fw fa-briefcase"></i>用户<i class="fafa-collapse"></i></a></li><li><ul class="accounts-menu nav nav-list collapse"><li ><a href="sign-in.html"><span class="fa fa-caret-right"></span>签到</a></li><li ><a href="sign-up.html"><span class="fa fa-caret-right"></span>报名</a></li><li ><a href="reset-password.html"><span class="fa fa-caret-right"></span>修改密码</a></li></ul></li><li><a href="help.html" class="nav-header"><i class="fa fa-fw fa-question-circle"></i>黄页</a></li></ul></div><div class="content" style="border:1px solid #000000;height:900px;"><iframe name="contentFrame" frameborder="0" scrolling=no width="100%"height="100%"></iframe></div>4.查询模块代码:using System;using System.Collections;using System.Configuration;using System.Data;using System.Linq;using System.Web;using System.Web.Security;using System.Web.UI;using System.Web.UI.HtmlControls;using System.Web.UI.WebControls;using System.Web.UI.WebControls.WebParts;using System.Xml.Linq;using utils;namespace webpro5{public partial class findresult : System.Web.UI.Page{private QueryRunner qr = new QueryRunner();protected void Page_Load(object sender, EventArgs e){bind();}//查询语句的更改protected void FindView_RowEditing(object sender, GridViewEditEventArgs e){FindView.EditIndex = e.NewEditIndex;bind();}//删除protected void FindView_RowDeleting(object sender, GridViewDeleteEventArgs e){int index = e.RowIndex;string sql = "delete from table_contact where cid='" +FindView.DataKeys[e.RowIndex]["cid"].T oString() + "'";qr.ExecuteNonQuery(sql);bind();}//更新protected void FindView_RowUpdating(object sender, GridViewUpdateEventArgs e) {string sql = "update table_contact set cname='" +((TextBox)(FindView.Rows[e.RowIndex].Cells[2].Controls[0])).T ext.ToString().Trim()+ "',gender='" +((TextBox)(FindView.Rows[e.RowIndex].Cells[3].Controls[0])).T ext.ToString().Trim()+ "',address='" +((TextBox)(FindView.Rows[e.RowIndex].Cells[4].Controls[0])).T ext.ToString().Trim()+ "',postcode='" +((TextBox)(FindView.Rows[e.RowIndex].Cells[5].Controls[0])).T ext.ToString().Trim()+ "',telphone='" +((TextBox)(FindView.Rows[e.RowIndex].Cells[6].Controls[0])).T ext.ToString().Trim()+ "',email='" +((TextBox)(FindView.Rows[e.RowIndex].Cells[7].Controls[0])).T ext.ToString().Trim()+ "' where cid='" + FindView.DataKeys[e.RowIndex].Value.ToString() + "'";qr.ExecuteNonQuery(sql);FindView.EditIndex = -1;bind();}//取消protected void FindView_RowCancelingEdit(object sender, GridViewCancelEditEventArgs e) {FindView.EditIndex = -1;bind();}//绑定public void bind(){String uid = Session["userId"].T oString();String name = Request.QueryString["cname"];String tel = Request.QueryString["tel"];String sql = "select * from getContacts('" + uid + "') c where 1=1";//name和tel有效,name有效tel无效,name无效tel有效if (((name != null) && (name.Trim() != "")) && (tel != null && tel.Trim() != "")){sql += " and ame like '%" + name + "%' or c.telphone like '%" + tel + "%'";}else if (((name != null) && (name.Trim() != "")) && ((tel == null) || (tel.Trim() == ""))) {sql += " and ame like '%" + name + "%'";}else if (((tel != null) && (tel.Trim() != "")) && ((name == null) || (name.Trim() == ""))) {sql += " and c.telphone like'%" + tel + "%'";}DataSet contactDs = qr.ExcuteDataSet(sql);int count = contactDs.Tables[0].Rows.Count;if(count == 0){Response.Write("<center><font color=red>没有记录</font></center>");}FindView.DataSource = contactDs;FindView.DataBind();}protected void FindView_RowDataBound(object sender, GridViewRowEventArgs e) {if (e.Row.RowState == (DataControlRowState.Edit | DataControlRowState.Alternate) || e.Row.RowState == DataControlRowState.Edit){TextBox curText;for (int i = 0; i < e.Row.Cells.Count; i++){if (e.Row.Cells[i].Controls.Count != 0){curText = e.Row.Cells[i].Controls[0] as TextBox;if (curText != null){curText.Width = Unit.Pixel(80);}}}}}protected void FindView_PageIndexChanging(object sender, GridViewPageEventArgs e) {FindView.PageIndex = e.NewPageIndex;bind();}}}5.添加分组模块代码:<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="addcontact.aspx.cs" Inherits="webpro5.addcontact" %><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 4.0 Transitional//EN"><html lang="en"><head><meta charset="utf-8"><title>添加联系人</title><meta content="IE=edge,chrome=1" http-equiv="X-UA-Compatible"><meta name="viewport" content="width=device-width, initial-scale=1.0"><meta name="description" content=""><meta name="author" content=""><link href='/css?family=Open+Sans:400,700' rel='stylesheet' type='text/css'> <link rel="stylesheet" type="text/css" href="lib/bootstrap/css/bootstrap.css"><link rel="stylesheet" href="lib/font-awesome/css/font-awesome.css"><script src="lib/jquery-1.11.1.min.js" type="text/javascript"></script><link rel="stylesheet" type="text/css" href="stylesheets/premium.css"></head><body class=" theme-blue"><form id = "form1"><div class="content"><div class="header"><h2 class="page-title">增加联系人</h2></div><div class="main-content"><ul class="nav nav-tabs"><li></li><li><a href="#profile" data-toggle="tab"></a></li></ul><form id="tab" runat="server"><div class="form-group"><label>联系人姓名</label><asp:T extBox ID="txtName" class="form-control" runat="server" On Width="150px"ValidationGroup="contactGroup"></asp:T extBox><asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server"ControlToValidate="txtName" ErrorMessage="姓名不能为空"ValidationGroup="contactGroup"></asp:RequiredFieldValidator> </div><div class="form-group"><label>联系人性别</label><asp:DropDownList ID="ddListSex" class="form-control" runat="server"Width="80px"><asp:ListItem Selected="True">男</asp:ListItem><asp:ListItem>女</asp:ListItem></asp:DropDownList></div><div class="form-group"><label>联系人电话</label><asp:T extBox ID="txtTel" class="form-control" runat="server" Width="150px"ValidationGroup="contactGroup"></asp:T extBox><asp:RequiredFieldValidator ID="RequiredFieldValidator3" runat="server"ControlToValidate="txtTel" ErrorMessage="*"ValidationGroup="contactGroup"></asp:RequiredFieldValidator><asp:RegularExpressionValidator ID="RegularExpressionValidator4" runat="server"ControlToValidate="txtTel" ErrorMessage="号码无效"ValidationExpression="0{0,1}(13[0-9]|15[7-9]|153|156|18[7-9])[0-9]{8}$"ValidationGroup="contactGroup" ></asp:RegularExpressionValidator> </div><div class="form-group"><label>组</label><asp:DropDownList ID="ddListGroup" class="form-control" runat="server"Width="150px"></asp:DropDownList></div><div class="form-group"><label>联系人地址</label><asp:T extBox ID="txtAddr" class="form-control" runat="server"Width="200px"></asp:T extBox></div><div class="form-group"><label>邮编</label><asp:T extBox ID="txtPost" class="form-control" runat="server"Width="100px"></asp:T extBox></div><div class="form-group"><label>邮箱</label><asp:T extBox ID="txtEmail" runat="server" class="form-control"Width="200px"></asp:T extBox><asp:RegularExpressionValidator ID="RegularExpressionValidator2" runat="server"ControlToValidate="txtEmail" ErrorMessage="邮箱格式不正确"ValidationExpression="\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*"> </asp:RegularExpressionValidator></div><span id="msgSpan"></span><div class="btn-toolbar list-toolbar"><asp:Button ID="saveBtn" runat="server" onclick="OnSaveClick" Text="保存"CssClass="btn btn-primary" ValidationGroup="contactGroup"/> </div></form></div><div class="tab-pane fade" id="profile"><form id="tab2"><div class="form-group"><input type="password" class="form-control"></div><div class="btn-toolbar list-toolbar"><button class="btn btn-primary"><i class="fa fa-save"></i>保存</button></div></form></div></div></form><script type="text/javascript">window.onload = function(){document.getElementById("saveBtn").onclick = function(){if(!Page_ClientValidate("contactGroup")){document.getElementById("msgSpan").innerHTML="<font color=red>请按要求完善联系人和联系方式!</font>";return false;}}}</script><script></script><script src="lib/bootstrap/js/bootstrap.js"></script><script type="text/javascript">$("[rel=tooltip]").tooltip();$(function() {$('.demo-cancel-click').click(function(){return false;});});</script></body></html>6、实验总结通过本次实验,我大概学会了制作一个电子云端通讯录系统,因为以前没有做过软件开发类似项目,在知识经验方面存在着许多不足,所以做起来也感觉困难重重。