【Asp.net精品源码栏目提醒】:网学会员鉴于大家对Asp.net精品源码十分关注,论文会员在此为大家搜集整理了“投票系统_基于.NET的WEB程序设计大作业 - 其它资料”一文,供大家参考学习
上海电力学院基于.NET的WEB程序设计 大作业 题目: 一个简单的投票系统 姓名: 徐雯雯 院系: 国际交流学院 专业: 计算机科学与技术 班级: 200905w1 2012 年 6月 5日 -1- 基于.NET 的 WEB 程序设计大作业报告书 20093598 徐雯雯摘要: 本系统基于 Microsoft Visual Studio 2008 为前台,Microsoft SQL Server 2005 为数据库后台支持的一个简单的投票系统。
本系统完成的功能有用户注册;用户登录;显示、添加、删除、修改投票项目及选项;进行投票、计数和显示投票功能。
界面友好,操作简单。
关键字:
ASP.NET Microsoft Visual Studio 2008 Microsoft SQL Server 2005 简单投票系统引言: 基于.NET 的 WEB 程序设计是计算机科学与技术专业学生的专业课程。
它运用 MicrosoftVisual Studio 网页制作,通过 Microsoft SQL Server 后台支持,完成一些网站的基本功能。
我们知道,如今大量的数据被存放在服务器上,通过服务器的数据库暂存这些数据,我们才可以调用自如。
因此,为了更加熟练的掌握
ASP.NET 调用数据库的方法,我选用了一个简单的投票系统为题,做了报告如下的网站,完成投票系统的基本功能。
正文:功能描述 本系统基于 Microsoft Visual Studio 2008 为前台,Microsoft SQL Server 2005 为数据库后台支持的一个简单的投票系统。
本系统完成如下功能: 1、 主页、关于页、联系页的静态页面显示功能; 2、 注册功能; 3、 登录功能; 4、 发邮件给作者功能; 5、 友情链接功能; 6、 显示、添加、修改、删除投票标题功能; (显示有翻页) 7、 显示、添加、修改、删除投票选项功能; 8、 对单选题和复选题的投票功能; 9、 显示投票结果功能;功能详细描述(附部分功能截图):1、 静态页面: (1) home 主页:首页,友好的欢迎界面; 信息链接功能:用户可以通过 链接到相应页 面,也可以通过 Friendly Links 链接到友情链接网站(其他投票网站); (2) aboutus 页面:关于,友好的介绍页面,让用户可以知晓本系统的主要功能; -2- 基于.NET 的 WEB 程序设计大作业报告书 20093598 徐雯雯2、 动态页面(实现功能) : (1) registerlogin 页面: 注册功能:用户可以在此页面进行注册。
在此,我使用了 Microsoft Visual Studio 2008 软件里的登陆注册控件(如右 图)。
其注册控件 CreateUserWizard 后台功能相对完善,它 可以触发各种验证,如用户名是否已被使用、密码长度、 绑定电子邮箱、密码安全问题等等; 登录功能:已注册的用户可以通过用户名和密码登录(使用 Login 控件) ,登录后 跳转到 aboutus 页面, 浏览本系统的介绍,其后每个页面都将显示用户登录名(使 用 LoginName 控件) ; (2) Contact 页面: 显示版权信息功能:显示作者姓名、电话、公司和说明; 给作者发邮件功能:用户可以通过 启动 Miscrosoft Outlook 给 作者发邮件; 信息链接功能: 用户可以通过 链接到作者所在公 司,通过 链接到本网站模版参考文献,通过 Friendly Links 链 接到友情链接网站(其他投票网站) ; (3) Votes 页面(本系统核心功能) a Titleopertation 页面(用户对投票标题信息的编写) : 链接各投票操作页面功能: 用户可点击链接至 optionoperation/votingampresults 页面 用 gridview 倒叙显示所有投票项目标题功能; Gridview 翻页功能:用户点击 1/2 即可翻页 -3- 基于.NET 的 WEB 程序设计大作业报告书 20093598 徐雯雯 编辑(Modify Title)和更新(Update/Cancel)标题功能: 用户可点击 Modify Title 进行对投票标题信息的修改; 删除标题(Delete Title)功能: 用户可点击 Delete Title 对投票标题删除,系统会跳出是否确认删除的信息; 添加标题(ADD Title)和取消添加(Cancel Adding)标题功能: 用户点击 ADD Title 即可跳出添加投票标题信息的 formview,填写相应信息 后,点击 Insert Title 添加成功,添加成功后, 将按 titleid 倒叙显示在 gridview title 中(其中,titleid 由数据库自动生成递增数据) ;点击 Cancel Adding 取消添加 投票标题;b Optionoperation 页面(用户对投票选项信息的编写): 链接各投票操作页面功能:用户点击进入 titleoperation/votingampshowresults 页 面 用 dropdownlist 显示所有投票标题功能: 用户可点击任一标题,点击 display options 即可查看此标题的选项;点击 Cancel Displaying 取消查看; -4- 基于.NET 的 WEB 程序设计大作业报告书 20093598 徐雯雯 查看该标题的选项信息功能: 编辑(Modify Options)和更新(Update/Cancel)选项功能 用户可点击 Modify Option 进行对投票选项信息的修改; 删除(Delete Options)选项功能: 用户可点击 Delete Options 对投票选项删除,系统会跳出是否确认删除的信息 添加选项(ADD Options)和取消添加(Cancel Adding)选项功能: 用户点击 ADD Options 即可跳出添加投票选项信息的 formview,填写相应信 息后,点击 Insert 添加成功, titleid 自动显示;optionid 由数据库自动生成递 增数据);点击 Cancel Adding 取消添加投票选项; -5- 基于.NET 的 WEB 程序设计大作业报告书 20093598 徐雯雯c Voting amp Show Results 页面: 链接各投票操作功能: 用 dropdownlist 显示所有投票标题功能: 用户可点击任一标题,点击 display options 即可查看此标题的选项;点击 Cancel Displaying 取消查看;查看时,即会显示此题是单选还是复选; 投票功能; 用户可点击 To Vote 列中的 Checkbox,投票成功; 用户可点击 To Vote 列中的 Checkbox,当题目是单选时,点选多余两个,点 击提交(Submit Voting)即会报错; -6- 基于.NET 的 WEB 程序设计大作业报告书 20093598 徐雯雯 查看结果功能: 用户点击 Show Results 即可出现 gridview 显示投票结果,其中 total 表示投票 总数(在单选题中,totalsum(ballots) ,在复选题中,totalSubmit Voting 的次数); 单选题结果: 复选题结果: 重新投票功能: 用户点击 Vote Again 即可回到开始投票页面重新重新或再次投票;附七个页面截图: -7-基于.NET 的 WEB 程序设计大作业报告书 20093598 徐雯雯 -8- 基于.NET 的 WEB 程序设计大作业报告书 20093598 徐雯雯数据库结构设计: 此课题中,我创建了两个数据表: 和 (存放投票项目) (存放投票标题) voteoption votetitle 。
创建数据库过程如下:进入 Microsoft SQL Server 2005 后,Votetitle 表:(注:titleid 是主键,由“IDENTITY11”语句表示自动生成 int 数字,从 1 开始逐增; 、 Singlemode 判断投票项目是否是单选,取值为“yes”“no” ; 三个变量都不能为空)代码如下: USE Vote GO / 对象: Table dbo.votetitle 脚本日期: 06/04/2012 18:12:44 / SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO SET ANSI_PADDING ON GO CREATE TABLE dbo.votetitle titleid int IDENTITY11 NOT NULL title varchar50 NOT NULL singlemode nvarchar128 NOT NULL CONSTRAINT PK__votetitle__00551192 PRIMARY KEY CLUSTERED titleid ASC WITH PAD_INDEX OFF STATISTICS_NORECOMPUTE OFF IGNORE_DUP_KEY OFF ALLOW_ROW_LOCKS ON ALLOW_PAGE_LOCKS ON ON PRIMARY UNIQUE NONCLUSTERED title ASC WITH PAD_INDEX OFF STATISTICS_NORECOMPUTE OFF IGNORE_DUP_KEY OFF ALLOW_ROW_LOCKS ON ALLOW_PAGE_LOCKS ON ON PRIMARY ON PRIMARY GO SET ANSI_PADDING OFF -9- 基于.NET 的 WEB 程序设计大作业报告书 20093598 徐雯雯Voteoption 表:(注:optionid 为主键,由“IDENTITY11”语句表示自动生成 int 数字,从 1 开始逐增; Ballots 默认为 0;titleid 为外键;字段 submitballots 记录提交次数。
)代码如下: USE Vote GO / 对象: Table dbo.voteoption 脚本日期: 06/04/2012 18:14:09 / SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO SET ANSI_PADDING ON GO CREATE TABLE dbo.voteoption optionid int IDENTITY11 NOT NULL options varcharmax NOT NULL ballots int NOT NULL CONSTRAINT DF_voteoption_ballots DEFAULT 0 titleid int NOT NULL submitballots int NOT NULL CONSTRAINT PK__voteoption__3D5E1FD2 PRIMARY KEY CLUSTERED optionid ASC WITH PAD_INDEX OFF STATISTICS_NORECOMPUTE OFF IGNORE_DUP_KEY OFF ALLOW_ROW_LOCKS ON ALLOW_PAGE_LOCKS ON ON PRIMARY ON PRIMARY GO SET ANSI_PADDING OFF GO ALTER TABLE dbo.voteoption WITH CHECK ADD CONSTRAINT FK_titleid FOREIGN KEYtitleid REFERENCES dbo.votetitle titleid GO ALTER TABLE dbo.voteoption CHECK CONSTRAINT FK_titleid表中数据为: - 10 - 基于.NET 的 WEB 程序设计大作业报告书 20093598 徐雯雯功能实现的关键代码: 【1】 对于投票标题操作的页面(titleoperation.aspx) 用 gridview 分页显示、添加、删除、修改投票标题: 前台关键脚本:ltasp:GridView IDquotGridView1quot runatquotserverquot AutoGenerateColumnsquotFalsequot Heightquot247pxquot Widthquot900pxquotDataKeyNamesquotidquot onroweditingquotGridView1_RowEditingquot onrowcancelingeditquotGridView1_RowCancelingEditquotonrowdataboundquotGridView1_RowDataBoundquot onrowdeletingquotGridView1_RowDeletingquotonrowupdatingquotGridView1_RowUpdatingquot AllowPagingquotTruequot onpageindexchangingquotGridView1_PageIndexChangingquotgtltColumnsgtltasp:BoundField HeaderTextquottitleidquot DataFieldquottitleidquot InsertVisiblequotFalsequot ReadOnlyquotTruequotSortExpressionquotidquot /gtltasp:BoundField HeaderTextquottitlequot DataFieldquottitlequot SortExpressionquottitlequot /gt ltasp:TemplateField HeaderTextquotsinglemodequotgtltEditItemTemplategtltasp:DropDownList IDquotDropDownList3quotrunatquotserverquotgtltasp:ListItemgtyeslt/asp:ListItemgtltasp:ListItemgtnolt/asp:ListItemgtlt/asp:DropDownListgtlt/EditItemTemplategtltItemTemplategtltasp:Label IDquotLabel13quot runatquotserverquotTextlt DataBinder.EvalContainer.DataItemquotsinglemodequot gtgtlt/asp:Labelgtlt/ItemTemplategtlt/asp:TemplateFieldgtltasp:CommandField HeaderTextquotEditquot ShowEditButtonquotTruequot SelectTextquot详情quot EditTextquotModify TitlequotCancelTextquotCancelquot UpdateTextquotUpdatequot /gtltasp:CommandField HeaderTextquotDeletequot ShowDeleteButtonquotTruequotDeleteTextquotDelete Titlequot /gtlt/Columnsgtlt/asp:GridViewgt 后台cs文件中的代码: 分页显示投票标题: string strCon quotData SourcelocalhostSQLEXPRESSDatabaseVoteUidsaPwd297276038quot SqlConnection sqlcon protected void Page_Loadobject sender EventArgs e if IsPostBack bind public void bind string sqlstr quotselect from votetitle order by titleid descquot sqlcon new SqlConnectionstrCon SqlDataAdapter myda new SqlDataAdaptersqlstr sqlcon - 11 - 基于.NET 的 WEB 程序设计大作业报告书 20093598 徐雯雯 DataSet myds new DataSet sqlcon.Open myda.Fillmyds quotvotetitlequot GridView1.DataSource myds GridView1.DataKeyNames new string quottitleidquot GridView1.DataBind sqlcon.Close protected void GridView1_PageIndexChangingobject sender GridViewPageEventArgs e GridView1.PageIndex e.NewPageIndex bind 编辑、更新投票标题信息: protected void GridView1_RowEditingobject sender GridViewEditEventArgs e GridView1.EditIndex e.NewEditIndex bind protected void GridView1_RowUpdatingobject sender GridViewUpdateEventArgs e string title TextBoxthis.GridView1.Rowse.RowIndex.Cells1.Controls0.Text.Trim string singlemode DropDownListthis.GridView1.Rowse.RowIndex.Cells2.Controls1.SelectedValue.Trim string titleid this.GridView1.Rowse.RowIndex.Cells0.Text string txtCommand quotupdate votetitle set titlequot title quot singlemodequot singlemode quotwhere titleidquot titleid quotquot SqlConnection conn new SqlConnectionstrCon conn.Open //Response.WritetxtCommand SqlCommand objSqlCommand new SqlCommandtxtCommand conn objSqlCommand.ExecuteNonQuery conn.Close GridView1.EditIndex -1 //this.DataBind bind protected void GridView1_RowCancelingEditobject sender GridViewCancelEditEventArgs e GridView1.EditIndex -1 bind 删除投票信息: protected void GridView1_RowDeletingobject sender GridViewDeleteEventArgs e string sqlstr quotdelete from votetitle where titleidquot GridView1.DataKeyse.RowIndex.Value.ToString quotquot SqlConnection sqlcon new SqlConnectionstrCon SqlCommand sqlcom new SqlCommandsqlstr sqlcon sqlcon.Open sqlcom.ExecuteNonQuery sqlcon.Close bind protected void GridView1_RowDataBoundobject sender GridViewRowEventArgs e //如果是绑定数据行 if e.Row.RowType DataControlRowType.DataRow - 12 - 基于.NET 的 WEB 程序设计大作业报告书 20093598 徐雯雯 if e.Row.RowState DataControlRowState.Normal e.Row.RowState DataControlRowState.Alternate LinkButtone.Row.Cells4.Controls0.Attributes.Addquotonclickquot quotjavascript:returnconfirmBe sure to Deletequotquot e.Row.Cells1.Text quotquotquot 添加投票信息:前台关键脚本: ltasp:FormView IDquotFormView1quot runatquotserverquotgtltInsertItemTemplategtlttable classquotstyle15quotgt lttrgtlttd classquotstyle14quotgttitle:lt/tdgt lttdgtltasp:TextBox IDquotTextBox31quot runatquotserverquot Widthquot335pxquotgtlt/asp:TextBoxgtlt/tdgtlt/trgt lttrgtlttd classquotstyle14quotgtsinglemode:lt/tdgt lttdgtltasp:RadioButtonList IDquotRadioButtonList1quot runatquotserverquot RepeatDirectionquotHorizontalquotgt ltasp:ListItemgtyeslt/asp:ListItemgtltasp:ListItemgtnolt/asp:ListItemgtlt/asp:RadioButtonListgt lt/tdgtlt/trgtlt/tablegt ltbr /gtltasp:Button IDquotButton10quot runatquotserverquot onclickquotButton10_Clickquot TextquotInsert Titlequot /gt lt/InsertItemTemplategtlt/asp:FormViewgt后台 CS 文件中代码: protected void Button10_Clickobject sender EventArgs e string txtCommand quotinsert into votetitle valuesquot TextBoxthis.FormView1.FindControlquotTextBox31quot.Text.Trim quot quot RadioButtonListthis.FormView1.FindControlquotRadioButtonList1quot.SelectedValue.Trim quotquot SqlConnection conn new SqlConnectionstrCon conn.Open SqlCommand objSqlCommand new SqlCommandtxtCommand conn objSqlCommand.ExecuteNonQuery conn.Close GridView1.EditIndex -1 bind FormView1.Visible false 【2】 对于投票选项操作的页面(optionoperation.aspx): 对投票选项的显示、添加、删除、修改 用 dropdownlist 显示所有投票标题: 前台关键脚本:ltasp:DropDownList IDquotDropDownList1quot runatquotserverquot DataSourceIDquotSqlDataSource1quot DataText.
上一篇:
【精品】WebConfig配置
下一篇:
餐饮管理系统