Web大作业伪邮件系统
武汉轻工大学
2012-2013 学年第2 学期
网站开发工具大作业
姓 名: 刘 兵
学 号: 100511713
班 级:数字媒体与技术1001班
院 系:数学与计算机学院
指导老师: 蒋 丽 华
2013年6月6日
【实验目的】
通过制作一个电子通信录系统来掌握使用ADO.NET访问与操纵数据库的方法,或者设计制作教材中所述的伪邮件系统,或者设计制作自己拟定的工资、学籍、图书管理系统之类的系统。
【实验内容】
一、电子通信录包括三部分信息:
1. 用户登录注册信息
2. 通信组信息
3. 联系人信息
二、电子通信录系统应至少包括下列功能页面(页面布局自定): 1. 用户首先要进行注册,注册成功后,还要允许用户进行密码修改。 2. 通信组的创建 AddGroup.aspx
3. 通信组的显示与维护AltGroup.aspx(包括通信组信息的删除和修改)
通信组是根据联系人之间的关系建立不同性质的Group,以上页面主要
访问数据库中的TableGroup数据表。页面主要功能分别为:组的创建和维护。
比如,可以建立亲友通信组、工作通信组、同学通信组以及其他类型通信组
等。
4. 联系人信息的添加 AddPerson.aspx
5. 联系人信息的显示与维护AltPerson.aspx(包括联系人信息的删除和修改)
根据联系人与通信组的关系,对联系人进行分类添加和维护,以上页面涉及到对TableUser数据表的操作,同时需要考虑与TableGroup数据表之间的关系。
6. 查找通信录 Find.aspx
设置查找条件,用户可以直接输入查询关键字,也可以先选择通信组,再输入查询关键字,系统返回查询结果,可以绑定DataGrid控件来显示查询结果。
三、伪邮件系统数据字典如书中描述,包括常规的收邮件、发邮件、附件操作等。
扩展要求:可制作管理员登录页面,被授权的用户才有资格创建和维护信息,普通用户只可进行信息查询。电子通信录系统也要求能处理附件信息,能在数据可操作中应用存储过程,对触发器能有一定的认识和了解。
【需求分析】
本系统除了用户的注册设计外,还可设置收发邮件的查看删除功能。包括: 加强信息保管的安全性;提高信息准确度和全面性;提高信息获取的便捷性;确保信息管理的高效性。以Windows为操作系统,运用Access数据库技术,开发以Windows XP为用户的操作平台,界面友善、功能齐全的通讯录系统。新系统的运行硬件环境PC机,当用户使用系统时,通过正确的口令进入系统,进行数据库的维护操作和运用。操作上是对IE浏览器的引用,该浏览器的使用,主要凭借使用浏览操作技术即可完成数据录入,方便简单。使用前只要对用户进行简单的说明或阅读帮助文件即可使用该系统。
【系统框架】
1、登陆页面模块:登陆,注册用户模块
2、用户注册页面模块:提交用户信息模块
3、发送邮件页面模块:发送邮件,上传附件,保存邮件模块
4、草稿箱页面模块:查看邮件,删除邮件
5、发件箱模块:查看已发送邮件,删除已发送邮件
【模块设计】
个人伪邮件系统
用户登录模块注册模块发送邮件模块查收邮件模块草稿箱邮件模块
【注册页面】
是否存在该用户按钮:连接数据库,查看该用户是否存在
提交用户注册信息按钮:将用户信息添加到数据库用户表中
部分关键代码:
提交按钮事件:
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("");
}
else
{
Response.Write("");
}
}
catch (Exception ex)
{
Response.Write("");
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();
}
}
【登录邮箱】
登陆按钮事件代码:
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();
cmd = new SqlCommand(QueryStr, Conn); SqlCommand
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("");
}
}
catch (Exception ex)
{
Console.WriteLine("Exception in main:" + ex.Message);
}
Conn.Close();
}
注册按钮事件代码:
protected void Buttonzhuce_Click(object sender, EventArgs e)
{
Response.Redirect("Register.aspx");
}
}
【发件箱界面】
protected void ButtonSend_Click(object sender, EventArgs e)
{
string extraFile = Convert.ToString(Session["FileName"]);
string annxFile = "";
string ConnString = "server=localhost; Initial Catalog=liumail; Integrated Security =
SSPI";
SqlConnection Conn = new SqlConnection(ConnString);
if (extraFile == "")
annxFile = "否";
else
annxFile = extraFile;
string CreateTime = Convert.ToString(DateTime.Today.ToShortDateString()) + " " + Convert.ToString(DateTime.Now.ToLongTimeString());
string InsertSql = "insert into
TAB_SendInfo(SenderName,ReceiveName,Topic,Contention,CreateTime,annxLetter) values('" + TextBox1.Text + "','" + TextBox2.Text + "','" + TextBox3.Text + "','" + TextBoxMessage.Text +
"','" + CreateTime + "','" + annxFile + "')";
string ReceiveSql = "insert into
TAB_ReceiveInfo(ReceiveName,SenderName,Topic,Contention,ReceiveTime,IsReaded,annxLetter)
values('" + TextBox2.Text + "','" + TextBox1.Text + "','" + TextBox3.Text + "','" + TextBoxMessage.Text + "','" + CreateTime + "','False','" + annxFile + "')";
try
{
Conn.Open();
SqlCommand cmd = new SqlCommand(InsertSql, Conn);
SqlCommand RecCmd = new SqlCommand(ReceiveSql, Conn);
cmd.ExecuteNonQuery();
RecCmd.ExecuteNonQuery();
Response.Write("");
Conn.Close();
}
catch (Exception ex)
{
Response.Write("");
}
}
protected void ButtonSave_Click(object sender, EventArgs e)
{
string extraFile = Convert.ToString(Session["FileName"]);
string annxFile = "";
string ConnString = "server=localhost; Initial Catalog=liumail; Integrated Security =
SSPI";
SqlConnection Conn = new SqlConnection(ConnString);
if (extraFile == "")
annxFile = "否";
else
annxFile = extraFile;
string SaveTime = Convert.ToString(DateTime.Today.ToShortDateString()) + " " + Convert.ToString(DateTime.Now.ToLongTimeString());
string InsertSql = "insert into
TAB_SaveInfo(SendID,ReceiveID,Topic,Contention,SaveTime,AnnxLetter) values('" + TextBox1.Text
+ "','" + TextBox2.Text + "','" + TextBox3.Text + "','" + TextBoxMessage.Text + "','" + SaveTime
+ "','" + annxFile + "')";
try
{
Conn.Open();
SqlCommand cmd = new SqlCommand(InsertSql, Conn);
cmd.ExecuteNonQuery();
Response.Write("");
Conn.Close();
}
catch (Exception ex)
{
Response.Write("");
}
}
上传文件代码:
protected void ButtonUpLoad_Click(object sender, EventArgs e) //上传文件
{
if (File1.PostedFile.FileName == "")
{
Response.Write("");
return;
}
string upfilename = File1.PostedFile.FileName;
ArrayList(); ArrayList arrFileName = new
arrFileName.AddRange(File1.Value.Split('\\'));
string fileName = arrFileName[arrFileName.Count - 1].ToString();
string uploadPath = Server.MapPath("") +
"\\UploadFiles\\";
File1.PostedFile.SaveAs(uploadPath + fileName);
Session["FileName"] = fileName;
Response.Write("");
}
【收件箱界面】
查看有邮件按钮事件:
protected void ButtonQue_Click(object sender, EventArgs e)
{
string ConnString = "server=localhost; Initial Catalog=liumail; Integrated Security =
SSPI";
SqlConnection Conn = new SqlConnection(ConnString);
Conn.Open();
ArrayList selectedMessages = GetSelected();
if (selectedMessages.Count != 1)
{
Response.Write("");
return;
}
Session["ReceiveID"] = selectedMessages[0].ToString();
Response.BufferOutput = true;
Response.Redirect("QueryReceiveMessage.aspx");
Conn.Close();
}
删除邮件按钮事件:
protected void ButtonCancel_Click(object sender, EventArgs e)
{
string ConnString = "server=localhost; Initial Catalog=liumail; Integrated Security =
SSPI";
SqlConnection Conn = new SqlConnection(ConnString);
Conn.Open();
ArrayList selectedMessages = GetSelected();
if (selectedMessages.Count < 1)
{
Response.Write("");
return;
}
else
{
foreach (string SelectID in selectedMessages)
{
string extraFile = "";
string delfilename = "";
string SelectSql = "select * from TAB_ReceiveInfo where ReceiveID='" + SelectID ;
string CancelSql = "Delete from TAB_ReceiveInfo where ReceiveID='" + SelectID ;
SqlCommand selectCmd = new SqlCommand(SelectSql, Conn);
SqlDataAdapter da = new SqlDataAdapter();
da.SelectCommand = selectCmd;
SqlDataReader dr = selectCmd.ExecuteReader();
if (dr.Read())
{
extraFile = dr["annxLetter"].ToString().Trim();
}
dr.Close();
if (extraFile != "否")
{
delfilename = Server.MapPath("") + "\\UploadFiles\\" + extraFile;
if (System.IO.File.Exists(delfilename))
System.IO.File.Delete(delfilename);
}
SqlCommand CanCom = new SqlCommand(CancelSql, Conn);
CanCom.ExecuteNonQuery();
}
}
GridViewConn();
Conn.Close();
}
}
【实验总结】
通过本次实验,我大概学会了制作一个伪邮件系统,因为以前没有做过软件开发类似项目,在知识经验方面存在着许多不足,所以做起来也感觉困难重重。而且最近实验比较多,时间也很紧张,所以做出来的东西功能不是很齐全。由于对伪邮件整个系统不是很熟悉,在需求分析时不能完全满足用户的需求。这次实验中最大的困难是连接数据库,因为以前学数据库时没有学好,所以不知道如何去做,请教同学后才明白。
由于这个实验是边学边做,所以我也查阅了不少书籍和网上资料。但 即便如此,我也不能很准确的区别相近功能指令各自的特点。因此,无法实现一些想要的功能和设想。这个实验中,最大收获并不是学会了几种开发工具的应用,而是学会了设计系统的思维方法。总而言之,这次实验是一次难得的锻炼机会,通过这次实验,我将书本上的知识从实践上巩固了一遍,感觉很有意义。通过与同学们讨论,经过自己的思考,感觉学到了很多知识,而这种学习效率是在课堂上无法达到的。所以,希望以后能多做几次这样的实验,然后真正学习到一些知识,为以后走向社会做铺垫。