版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
1、校园卡掌上管理系统 -编码与测试报告 制作人: 曹 静 崔 文 傅小江 李国明 1、编码1.1部分代码1.1.1数据库实施阶段任务(1)建立数据库(校园卡管理系统)create database campuscard;建立数据表1) 用户信息表的建立 create table tb_admin (id int(10) not null primary key, username varchar(32) not null, password varchar(32) not null,type smallint(1) not null,createdate date not null ); 2)
2、校园卡信息表的建立 create table tb_card ( id int(10) not null primary key, stuid varchar(10) not null,cardid varchar(13) not null, password varchar(32) not null,balance double(5) not null,status int(1) not null,createdate date not null );3) 消费信息表的建立 create table tb_consumption (id int(10) not null primary ke
3、y, cardid varchar(13) not null, money doublae(5) not null,address varchar(32) not null,createdate date not null );4) 转账信息表的建立 create table tb_recharge (id int(10) not null primary key, cardid varchar(13) not null, money doublae(5) not null,createdate date not null );5) 学生信息表的建立 create table tb_stude
4、nt (id int(10) not null primary key,stuid varchar(10) not null,name varchar(32) not null, cardid varchar(18) not null,bankcard varchar(19) not null,createdate date not null );1.1.2实体类cardusers类源代码package usergui;public class cardusers public string userid;/用户编号 public string username;/用户名; public st
5、ring usersex; public string userpwd; public string usertype; public cardusers(string userid) this.userid = userid; public cardusers(string userid, string username, string usersex, string userpwd, string usertype) throws pwdshortexception if(userpwd.length()<6) throw (new pwdshortexception(); else
6、 this.userid = userid; this.username = username; this.usersex = usersex; this.userpwd = userpwd; this.usertype = usertype; public string getuserid() return userid; public void setuserid(string userid) this.userid = userid; public string getusername() return username; public void setusername(string u
7、sername) this.username = username; public string getuserpwd() return userpwd; public void setuserpwd(string userpwd) throws pwdshortexception if(userpwd.length()<6) throw(new pwdshortexception(); else this.userpwd = userpwd; public string getusersdx() return usersex; public void setusersdx(string
8、 usersdx) this.usersex = usersex; public string getusertype() return usertype; public void setusertype(string usertype) this.usertype = usertype; override public string tostring() return "用户编号=" + userid + ", 姓名=" + username + ", 性别=" + usersex + ", 密码=" + use
9、rpwd + ", 身份=" + usertype ; carduserecords类源代码package operationgui;public class carduserecords private long cardno; private string useitems; private double money; private string usetime; public carduserecords(long cardno, string item, double money, string time) this.cardno = cardno; this.u
10、seitems = item; this.money = money; this.usetime = time; public long getcardno() return cardno; public string getuseitems() return useitems; public string getusetime() return usetime; public double getmoney() return money; override public string tostring() return "卡号=" + cardno + ", 名
11、目=" + useitems + ", 费用=" + money + ", 时间=" + usetime; schoolcard类源代码package cardgui;import javax.swing.joptionpane;public class schoolcard public int cardno;/卡号 static int nextcardno=111003200;/起始卡号 private string userid;/卡所属的用户编号 private string password; private double bala
12、nce; private boolean isusing; public schoolcard() this.cardno=nextcardno+; public schoolcard(string userid, string password) this(); this.userid = userid; this.password = password; this.balance=0; this.isusing=true; public static void setnextcardno(int newstartno) /设置起始卡号 schoolcard.nextcardno = new
13、startno; public int getcardno() return cardno; public string getuserid() /差卡的用户号 return userid; public void setuserid(string uid) /设置卡的用户号 this.userid = uid; public double getbalance() /查询余额 return balance; public string getpassword() return password; public void setpassword(string upwd) throws uses
14、tateexception if(check() this.password = upwd; else throw (new usestateexception(); public void deposit(double money) throws usestateexception if(check() this.balance=balance+money; else throw (new usestateexception(); public void consume(double money) throws usestateexception if(check() if(this.bal
15、ance>=money) this.balance=balance-money; else joptionpane.showmessagedialog(null,"卡上余额不够消费,请先充值!"); else throw (new usestateexception(); public boolean getcardstate() return isusing; public void setstate(boolean state) this.isusing = state; public boolean check() if(this.isusing) return
16、 true; else return false; override public string tostring() return "卡号=" + cardno + ", 用户号=" + userid + ", 密码=" + password + ", 余额=" + balance + ", 是否可用=" + isusing ; 1.1.3实现数据库连接 package operationgui;import java.sql.*;public class dbaccess private c
17、onnection conn=null; private statement stmt=null; public resultset rs=null; private preparedstatement prestmt=null; private string driver="sun.jdbc.odbc.jdbcodbcdriver" private string url="jdbc:odbc:cardconn"/自定义数据源名 private string user="jane" private string pwd="1
18、23456" public string notes="数据库操作提示" /实例方法:实现数据库连接 public void dbconn() try class.forname(driver); conn=drivermanager.getconnection(url, user, pwd); stmt=conn.createstatement(); catch (classnotfoundexception ec) system.out.println(ec); catch (sqlexception es) system.out.println(es); c
19、atch (exception ex) system.out.println(ex); /实现数据库查询并返回查询记录 public resultset dbselect(string selstring) try rs=stmt.executequery(selstring); catch (sqlexception es) system.out.println(es); notes="数据库查询出现异常" return rs; /数据库更新 public string dbupdate(string updatestring) try prestmt=conn.prep
20、arestatement(updatestring); prestmt.executeupdate(); notes="记录更新成功" catch (sqlexception es) system.out.println(es); notes="数据库更新出现异常" return notes; /插入数据 public string dbinsert(string insertstring) try prestmt=conn.preparestatement(insertstring); prestmt.executeupdate(); notes=&q
21、uot;插入记录成功" catch (sqlexception es) system.out.println(es); notes="数据库插入出现异常" return notes; /删除 public string dbdelete(string delstring) try prestmt=conn.preparestatement(delstring); prestmt.executeupdate(); notes="删除成功" catch (sqlexception es) system.out.println(es); notes=
22、"数据库删除现异常" return notes; /关闭数据库 public void dbclose() if(conn!=null) try rs.close(); stmt.close(); conn.close(); catch (exception e) 1.2 系统主界面的截图。校园卡管理界面校园卡管理主要功能是对校园卡信息进行查询,开户销户等功能的操作。图1登录界面1.3系统部分功能界面的截图。图2 个人信息查询界面图3 修改密码界面图4 开户界面图5销户界面图6 丢失界面图7 补办界面图8 校园卡信息查询界面2、测试2.1测试分析用户登录界面/确定
23、按钮代码private void jbtnokactionperformed(java.awt.event.actionevent evt) if(jradiobuttonp.isselected() chtype="普通用户" else chtype="管理员" db.dbconn(); sql="select * from cardusers" db.dbselect(sql); try while(db.rs.next() system.out.println("b");/如果用户号,密码,身份相符 if(t
24、xtuid.gettext().equals(db.rs.getstring("userid") && string.valueof(txtpwd.getpassword().equals(db.rs.getstring("userpwd") && chtype.equals(db.rs.getstring("usertype") /显示用户名,并新建当前用户对象,存储有关信息。 currentuser=new cardusers(txtuid.gettext(); currentuser.userpw
25、d= string.valueof(txtpwd.getpassword(); currentuser.userid=txtuid.gettext(); currentuser.usertype=chtype; currentuser.username=db.rs.getstring("username"); jlbnote.settext("欢迎你:"+currentuser.username+"!");system.out.println("b"); new schoolcardmaingui(currentu
26、ser).setvisible(true);system.out.println("c");/主界面 this.dispose(); db.dbclose(); else jlbnote.settext("账号,密码,身份不符,请检查输入信息是否正确!"); catch (sqlexception e) system.err.print(e.tostring(); db.dbclose(); 主界面用户信息录入界面/添加用户代码 private void jbtnaddactionperformed(java.awt.event.actionevent
27、evt) try connection con=drivermanager.getconnection("jdbc:odbc:cardconn","jane","123456"); java.sql.statement sql=con.createstatement(resultset.type_scroll_sensitive,resultset.concur_updatable); resultset rs=sql.executequery("select * from cardusers"); while(r
28、s.next() if(rs.getstring(1).equals(jtxtuserid.gettext() break; if(rs.isafterlast()=false) joptionpane.showmessagedialog(this,"已经添加此用户!"); else m.removeallelements(); checkvaliddate ck=new checkvaliddate(jtxtuserid); if(ck.check(0) string uid=jtxtuserid.gettext(); string uname=jtxtusername.
29、gettext(); string upwd=jtxtpwd.gettext(); try user=new cardusers(uid,uname,usex,upwd,utype); /userlist.add(user); m=new defaultlistmodel(); catch(pwdshortexception e) userlist.add(user); for(int j=0;j<userlist.size();j+) m.addelement(userlist.get(j); jlistuser.setmodel(m); /*数据库操作* sqls="ins
30、ert into cardusers values ('"+uid+"','"+uname+"','"+usex+"','"+upwd+"','"+utype+"')" dbo.dboperation(sqls, 2); catch (sqlexception ex) logger.getlogger(dbusereditnew.class.getname().log(level.severe, null,
31、 ex); 修改密码 /确定按钮响应事件代码 private void jbtnokactionperformed(java.awt.event.actionevent evt) checkvaliddate ck=new checkvaliddate(txtpwdnew); if(ck.check(0) && txtpwdnew.gettext().length()>=6) if(txtpwdnew.gettext().equals(txtpwdna.gettext() db.dbconn(); string sql="update cardusers set
32、 userpwd='"+txtpwdnew.gettext()+"'where userid='"+currentuser.userid+"'" db.dbupdate(sql); db.dbclose(); jlbnote.settext("修改密码成功!"); / joptionpane.showmessagedialog(this, "chenggong", "tishi",joptionpane.warning_message); else jl
33、bnote.settext("两次输入密码不一致!"); 2.2黑盒测试void mima()char a7,b="533159"int i,j;for (j=1;j<=3;j+)/for循环来控制密码登陆次数,次数为三次printf("tt请输入密码:");for (i=0;i<6;i+)ai=getch();if(ai=8) i=i-2;printf("b b");elseif (ai=13)break;printf("*");ai='0'printf("n");if (strcmp(a,b)=0)/比较两个字符串的大小,两个字符串相同时返回0.printf("密码正确n");break;elseprintf("tt输入密码错误!请重新输入:n");本程序代码功
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 2025~2026学年云南省大理州鹤庆县上学期期末考试高一地理试卷
- 外科护理跨学科合作与交流
- 危机应对中的护理信息技术应用
- 护理实践中的法律规范
- 交通运输工程学课件 第五章 城市交通运输系统及组织
- 第3课 路径动画和遮罩动画教学设计初中信息技术闽教版2020七年级下册-闽教版2020
- 人教部编版七年级历史下册第三单元第14课 明朝的统治教学设计
- 2026山东滨州市某汽车服务公司招聘考试笔试历年参考题库附带答案详解
- 2026云南昆明豪生大酒店招聘笔试历年参考题库附带答案详解
- 2026中国纺织出版社有限公司招聘笔试历年参考题库附带答案详解
- 步进电机培训课件教学
- 生物样本库伦理与法律合规管理
- 2025年五类人员进乡镇班子结构化笔试及答案
- 心理志愿者培训课件
- 原料不合格处置管理培训
- 2024武威辅警考试真题及答案
- GB/T 42706.4-2025电子元器件半导体器件长期贮存第4部分:贮存
- 2026年中考语文专题复习:标点符号 讲义
- 红色革命歌曲经典赏析与应用
- 2024糖尿病视网膜病变临床诊疗指南
- 常见病小儿推拿培训
评论
0/150
提交评论