1、 信息与电气工程学院 软件程序设计三级项目 设计说明书 (2015/2016学年第一学期) 题 目 : 抽奖模拟软件 专业班级 : 电子信息工程 学生学号 : 学生姓名 : 阿三三 指导教师 : 吴开兴、马小进、崔冬 设计周数 : 2周 设计成绩 : 年
2、1月8日 1 .课程设计目的 3 2.技术要求及开发环境 3 2.1技术要求 3 2.2开发环境 3 3 .系统设计 3 3.1系统分析 3 3.2 系统设计 4 3.2.1 系统功能模块设计 4 3.2.2 数据库系统设计 4 3.2.3系统功能图 4 3.2.4 系统流程图 6 4. 程序设计 6 4.1管理员登陆模块 6 4.1.1界面分析与设计 6 4.1.2主要代码 7 4.2抽奖系统主体模块 8 4.2.1界面分析与设计 8 4.2.2主要代码 9 4.3获奖名额设置模块 12 4.3.1界面分析与设计 12 4.2.2主要代码 13
3、 4.4奖项抽取模块 17 4.4.1界面分析与设计 17 4.4.2主要代码 19 4.5结果查看模块 33 4.5.1界面分析与设计 33 4.5.2主要代码 33 4.6奖品查看模块 36 4.6.1界面分析与设计 36 4.6.2主要代码 37 4.7清空抽奖记录及退出模块 38 4.7.1界面分析与设计 38 4.7.2代码实现 39 5.系统调试及相关问题 39 6. 课程设计总结或结论 40 参考文献 40 1 .课程设计目的 本设计将进一步加强学生对面向对象程序设计思想的理解,增强对C#程序语言的灵活运用。要求学生能结
4、合数据库知识和visual studio中的windows窗体 ,实现基本的应用软件,培养学生的兴趣,掌握相关的知识,为以后积累经验。 2.技术要求及开发环境 2.1技术要求 奖项规则基础数据维护 随机抽奖功能 能将获奖数据进行存储、管理并实现灵活的查询功能。 2.2开发环境 开发环境为Visual Studio 2008,使用.net 2.0开发。使用采用windows窗体和C#语言来进行实际设计。涉及到了多用户等相关操作和SQL SERVER数据库连接使用。 3 .系统设计 3.1系统分析 模拟抽奖系统所需实现的基本功能是实现随机抽奖功能,并且可以查看抽奖结果、
5、进行抽奖人数设置、能对获奖数据进行存储以及清空抽奖记录的功能。根据功能分析出系统的设计思路如下: 管理员登录方可使用本软件。设置特等奖、一等奖、二等奖、三等奖、四等奖、五等奖共六个奖项。用户可以选择抽取中任意一个奖项。抽取每个奖项之前可以设置各个奖项获奖名额,若不进行获奖名额设置则默认使用系统设置的获奖名额。中奖号的抽取使用数字0~100作为抽奖号,编程实现抽奖号码的滚动,按下停止键时得到的数字便是中奖号,选择是否保存中奖号码。每个奖项对应的中奖号及对应奖品可以在结果查看和奖品查看中查看,抽奖结束后可以对中奖信息进行清除。 3.2 系统设计 3.2.1 系统功能模块设计 系统管理员登录
6、模块:账号登录对中奖信息进行管理。 抽奖设置模块:能够对抽取的各个奖项人数进行设置。 抽奖模块:利用抽奖号滚动的方法实现抽奖功能. 查看结果模块:能够查看当前各个奖项对应的的中奖号码。 查看奖品模块:能够查看各个奖项对应的奖品。 清除结果模块:删除中奖信息。 3.2.2 数据库系统设计 管理员信息表(Table1) 列名 数据类型 长度 是否为主键 是否为空 注释 UserName Char 50 是 否 管理员账号 UsrPsw Char 50 否 否 登录密码 图3-1 3.2.3系
7、统功能图 图3-2 3.2.4 系统流程图 图3-3 4. 程序设计 4.1管理员登陆模块 4.1.1界面分析与设计 本软件可以可以查看抽奖结果、进行获奖名额设置、能对获奖数据进行存储以及清空抽奖记录。而这些功能需要用户用户通过登录验证密码后方可使用,故设计用户登录模块界面如图4-1所示。 图4-1 4.1.2主要代码 private void button1_Click(object sender, EventArgs e) { string connString = (@"Data Sourc
8、e=.\SQLEXPRESS;AttachDbFilename=E:\三级项目抽奖软件\抽奖软件\Database1.mdf;Integrated Security=True;User Instance=True"); SqlConnection conn = new SqlConnection(connString); conn.Open(); string sql = "select * from denglu where Name='" + txtUsername.Text.Trim().ToLowe
9、r() + "'and Pwd='" + txtPassword.Text.Trim() + "'"; SqlCommand cmd = new SqlCommand(sql, conn); SqlDataReader dr = cmd.ExecuteReader(); if (dr.Read()) { // txtUsername = this.txtUsername.Text.Trim(); ResultForm frm
10、 = new ResultForm(); frm.Show(); this.Hide(); } else { MessageBox.Show("用户名或密码错误", "出错了", MessageBoxButtons.OK, MessageBoxIcon.Error); } conn.Close(); ResultForm re = new ResultForm();
11、 re.ShowDialog(); } 4.2抽奖系统主体模块 4.2.1界面分析与设计 抽取每个奖项之前用户可以按抽奖设置按钮设置特等奖、一等奖、二等奖、三等奖、四等奖、五等奖的获奖名额。用户可以选择抽取其中任意一个奖项,点击开始抽奖按钮进行抽奖。每个奖项对应的中奖号及对应奖品可以在结果查看和奖品查看中查看,抽奖结束后可以点击清空记录按钮对中奖信息进行清除。抽奖系统主体模块界面如图4-2所示。 图4-2 4.2.2主要代码 private void btnstart_Click(object sender, EventArgs e)
12、 { if (rdo1.Checked == true) { LuckyForm luck1 = new LuckyForm(); luck1.choose = 1; luck1.ShowDialog(); } else if (rdo2.Checked == true) { LuckyForm luck2 = n
13、ew LuckyForm(); luck2.choose = 2; luck2.ShowDialog(); } else if (rdo3.Checked == true) { LuckyForm luck3 = new LuckyForm(); luck3.choose = 3; luck3.ShowDialog(); }
14、 else if (rdo4.Checked == true) { LuckyForm luck4= new LuckyForm(); luck4.choose = 4; luck4.ShowDialog(); } else if (rdo5.Checked == true) { LuckyForm luck5 = new Luck
15、yForm(); luck5.choose = 5; luck5.ShowDialog(); } else if (rdot.Checked == true) { LuckyForm luck = new LuckyForm(); luck.choose = 0; luck.ShowDialog(); }
16、} //查看结果 private void btnresult_Click(object sender, EventArgs e) { frm1 cha = new frm1(); cha.Show(); } //查看奖品 private void btnsee_Click(object sender, EventArgs e) { ShowForm re = new ShowForm();
17、 re.ShowDialog(); } //退出 private void LoginForm_FormClosing(object sender, FormClosingEventArgs e) { if (restart==false) { DialogResult re = MessageBox.Show("您要退出抽奖系统吗?", "关闭提示", MessageBoxButt
18、ons.YesNo, MessageBoxIcon.Information); if (re == DialogResult.Yes) { DialogResult ree = MessageBox.Show("退出后本次抽奖记录将消失,确认要退出吗?", "重要提醒", MessageBoxButtons.OKCancel, MessageBoxIcon.Question); if (ree == DialogResult.Cancel)
19、 { e.Cancel = true; } } else { e.Cancel = true; } } } private void LoginForm_FormClosed(object sender, FormClosedEv
20、entArgs e) { GC.Collect(); this.Dispose(); } //清空 private void btnrestart_Click(object sender, EventArgs e) { DialogResult re = MessageBox.Show("您确定要清空抽奖记录吗?", "提示", MessageB
21、oxButtons.OKCancel, MessageBoxIcon.Information); if (re == DialogResult.OK) { restart = true; Application.Restart(); } 4.3获奖名额设置模块 4.3.1界面分析与设计 用户点击抽奖设置按钮后弹出获奖名额设置窗口,用户可以修改每个奖项抽出的获奖人数。
22、若用户设置名额超出该奖项设定个数,则弹出用户设置名额超出范围对话框,要求用户重新修改获奖人数。获奖名额设置模块界面设计如图4-3、4-4所示。 图4-3 图4-4 4.2.2主要代码 private void SetForm_Load(object sender, EventArgs e) { txt.Text = UserHelper.te.ToString(); txt1.Text = UserHelper.one.ToString
23、); txt2.Text = UserHelper.two.ToString(); txt3.Text = UserHelper.three.ToString(); txt4.Text = UserHelper.four.ToString(); txt5.Text = UserHelper.five.ToString(); } //保存设置 private void saveset() { t
24、ry { UserHelper.te = Convert.ToInt32(txt.Text); UserHelper.one = Convert.ToInt32(txt1.Text); UserHelper.two = Convert.ToInt32(txt2.Text); UserHelper.three = Convert.ToInt32(txt3.Text); UserHelper.four =
25、 Convert.ToInt32(txt4.Text); UserHelper.five = Convert.ToInt32(txt5.Text); UserHelper.allset = Convert.ToInt32(txt.Text) + Convert.ToInt32(txt1.Text) + Convert.ToInt32(txt2.Text) + Convert.ToInt32(txt3.Text) + Convert.ToInt32(txt4.Text) + Convert.ToInt32(txt5.Text);
26、 } private bool vliainput() { bool result = true; try { int txtno1 = Convert.ToInt32(txt1.Text); if (txtno1 < 0 || txtno1 > 100) { txt1.Clear();
27、 txt1.Focus(); MessageBox.Show("你输入的数字大小不符合!请输入~100之间的数字!", "错误提示", MessageBoxButtons.OK, MessageBoxIcon.Information); result = false; } } catch (Exception) { txt1.Clear()
28、 txt1.Focus(); MessageBox.Show("输入不符合要求!","错误提示",MessageBoxButtons.OK,MessageBoxIcon.Stop); result = false; } try { int txtno2 = Convert.ToInt32(txt2.Text); if (txtno2 < 1 ||
29、txtno2 > 1000) { txt2.Clear(); txt2.Focus(); MessageBox.Show("你输入的数字大小不符合!", "错误提示", MessageBoxButtons.OK, MessageBoxIcon.Information); result = false; } }
30、catch (Exception) { txt2.Clear(); txt2.Focus(); MessageBox.Show("请输入数字!", "错误提示", MessageBoxButtons.OK, MessageBoxIcon.Stop); result = false; } try { int txtno3 =
31、Convert.ToInt32(txt3.Text); if (txtno3 < 1 || txtno3 > 1000) { txt3.Clear(); txt3.Focus(); MessageBox.Show("你输入的数字大小不符合!", "错误提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
32、result = false; } } catch (Exception) { txt3.Clear(); txt3.Focus(); MessageBox.Show("请输入数字!", "错误提示", MessageBoxButtons.OK, MessageBoxIcon.Stop); result = false; }
33、 try { int txtno4 = Convert.ToInt32(txt4.Text); if (txtno4 < 1 || txtno4 > 1000) { txt4.Clear(); txt4.Focus(); MessageBox.Show("你输入的数字大小不符合!", "错误提示", MessageBo
34、xButtons.OK, MessageBoxIcon.Information); result = false; } } catch (Exception) { txt4.Clear(); txt4.Focus(); MessageBox.Show("请输入数字!", "错误提示", MessageBoxButtons.OK, Messag
35、eBoxIcon.Stop); result = false; } try { int txtno5 = Convert.ToInt32(txt5.Text); if (txtno5 < 1 || txtno5 > 1000) { txt5.Clear(); txt5.Focus();
36、 MessageBox.Show("你输入的数字大小不符合!", "错误提示", MessageBoxButtons.OK, MessageBoxIcon.Information); result = false; } } catch (Exception) { txt5.Clear(); txt5.Focus();
37、 MessageBox.Show("请输入数字!", "错误提示", MessageBoxButtons.OK, MessageBoxIcon.Stop); result = false; } return result; } } 4.4奖项抽取模块 4.4.1界面分析与设计 中奖号的抽取使用数字0~100作为抽奖号,编程实现抽奖号码的滚动,按下停止键时得到的数字便是中奖号,选择是否保存中奖号码。若选择保存则显示保存的号码,不保存则重新抽取获奖号。界面右下角显示设
38、置的获奖名额个数及已抽出的获奖号个数。若获奖号全部抽出时,用户继续抽取该奖项,则弹出提醒对话框,提醒用户该奖项已全部抽出,并返回抽奖主界面。奖项抽取模块界面如图4-5、4-6所示。 图4-5 图4-6 4.4.2主要代码 public partial class LuckyForm : Form { public int choose; int pernum; //总人数(图片的数量) int i =
39、 0; //图片下标(总人数) int index; //中奖者的下标(滚动下标) int dj = 1; //抽奖等级 int save=0; //是否保存 String winner=""; //中奖者下标 bool go = true; //判断开始按钮 int wined = 0; //已抽出的中奖人数
40、 Random ran = new Random(DateTime.Now.Millisecond); int tmpadd = 0; private static int aset = 0; private static int setnum=0; public LuckyForm() { InitializeComponent(); } private void zhongjianglist() {
41、 if (dj == 1) { foreach (string a in UserHelper.yiwinner) { if (a != null) { listBox1.Items.Add(a); } else {
42、 break; } } } else if (dj == 2) { foreach (string b in UserHelper.erwinner) { if (b != null) { listBox1.Ite
43、ms.Add(b); } else { break; } } } else if (dj == 3) { foreach (string c in UserHelper.sanwinner) {
44、 if (c != null) { listBox1.Items.Add(c); } else { break; } } } else if (dj == 4)
45、 { foreach (string d in UserHelper.siwinner) { if (d != null) { listBox1.Items.Add(d); } else { break;
46、 } } } else if (dj == 5) { foreach (string e in UserHelper.wuwinner) { if (e != null) { listBox1.Items.Add(e);
47、 } else { break; } } } else if (dj == 0) { foreach (string t in UserHelper.twinner) { if (t !
48、 null) { listBox1.Items.Add(t); } else { break; } } } } private void LuckyForm_Load(object sende
49、r, EventArgs e) { try { //显示抽几等奖 if (choose == 1) { lblno.Text = "一等奖"; lblset.Text = UserHelper.one.ToString(); //设置名额 lblcc.Text = readnum(1).ToSt
50、ring(); //抽出名额 dj = 1; } else if (choose == 2) { lblno.Text = "二等奖"; lblset.Text = UserHelper.two.ToString(); lblcc.Text = readnum(2).ToString();






