您好,欢迎访问三七文档
当前位置:首页 > 商业/管理/HR > 宣传企划 > 校园卡掌上管理系统编码与测试报告-第十组
校园卡掌上管理系统----编码与测试报告制作人:曹静崔文傅小江李国明1、编码1.1部分代码1.1.1数据库实施阶段任务(1)建立数据库(校园卡管理系统)createdatabasecampuscard;⑵建立数据表1)用户信息表的建立Createtabletb_admin(Idint(10)notnullprimarykey,usernamevarchar(32)notnull,passwordvarchar(32)notnull,typesmallint(1)notnull,createdatedatenotnull);2)校园卡信息表的建立createtabletb_card(Idint(10)notnullprimarykey,Stuidvarchar(10)notnull,cardidvarchar(13)notnull,passwordvarchar(32)notnull,balancedouble(5)notnull,statusint(1)notnull,createdatedatenotnull);3)消费信息表的建立Createtabletb_consumption(Idint(10)notnullprimarykey,cardidvarchar(13)notnull,moneydoublae(5)notnull,addressvarchar(32)notnull,createdatedatenotnull);4)转账信息表的建立Createtabletb_recharge(Idint(10)notnullprimarykey,cardidvarchar(13)notnull,moneydoublae(5)notnull,createdatedatenotnull);5)学生信息表的建立Createtabletb_student(Idint(10)notnullprimarykey,Stuidvarchar(10)notnull,Namevarchar(32)notnull,cardidvarchar(18)notnull,bankcardvarchar(19)notnull,createdatedatenotnull);1.1.2实体类CardUsers类源代码packageuserGUI;publicclassCardUsers{publicStringUserID;//用户编号publicStringUserName;//用户名;publicStringUserSex;publicStringUserPwd;publicStringUserType;publicCardUsers(StringUserID){this.UserID=UserID;}publicCardUsers(StringUserID,StringUserName,StringUserSex,StringUserPwd,StringUserType)throwsPwdShortException{if(UserPwd.length()6)throw(newPwdShortException());else{this.UserID=UserID;this.UserName=UserName;this.UserSex=UserSex;this.UserPwd=UserPwd;this.UserType=UserType;}}publicStringgetUserID(){returnUserID;}publicvoidsetUserID(StringUserID){this.UserID=UserID;}publicStringgetUserName(){returnUserName;}publicvoidsetUserName(StringUserName){this.UserName=UserName;}publicStringgetUserPwd(){returnUserPwd;}publicvoidsetUserPwd(StringUserPwd)throwsPwdShortException{if(UserPwd.length()6)throw(newPwdShortException());elsethis.UserPwd=UserPwd;}publicStringgetUserSdx(){returnUserSex;}publicvoidsetUserSdx(StringUserSdx){this.UserSex=UserSex;}publicStringgetUserType(){returnUserType;}publicvoidsetUserType(StringUserType){this.UserType=UserType;}@OverridepublicStringtoString(){return用户编号=+UserID+,姓名=+UserName+,性别=+UserSex+,密码=+UserPwd+,身份=+UserType;}}CardUseRecords类源代码packageoperationGUI;publicclassCardUseRecords{privatelongCardNo;privateStringUseItems;privatedoublemoney;privateStringUseTime;publicCardUseRecords(longcardNo,Stringitem,doublemoney,Stringtime){this.CardNo=cardNo;this.UseItems=item;this.money=money;this.UseTime=time;}publiclonggetCardNo(){returnCardNo;}publicStringgetUseItems(){returnUseItems;}publicStringgetUseTime(){returnUseTime;}publicdoublegetMoney(){returnmoney;}@OverridepublicStringtoString(){return卡号=+CardNo+,名目=+UseItems+,费用=+money+,时间=+UseTime;}}SchoolCard类源代码packagecardGUI;importjavax.swing.JOptionPane;publicclassSchoolCard{publicintcardNo;//卡号staticintNextCardNo=111003200;//起始卡号privateStringUserID;//卡所属的用户编号privateStringpassword;privatedoublebalance;privatebooleanisUsing;publicSchoolCard(){this.cardNo=NextCardNo++;}publicSchoolCard(StringUserID,Stringpassword){this();this.UserID=UserID;this.password=password;this.balance=0;this.isUsing=true;}publicstaticvoidsetNextCardNo(intnewStartNo){//设置起始卡号SchoolCard.NextCardNo=newStartNo;}publicintgetCardNo(){returncardNo;}publicStringgetUserID(){//差卡的用户号returnUserID;}publicvoidsetUserID(Stringuid){//设置卡的用户号this.UserID=uid;}publicdoublegetBalance(){//查询余额returnbalance;}publicStringgetPassword(){returnpassword;}publicvoidsetPassword(Stringupwd)throwsUseStateException{if(check())this.password=upwd;elsethrow(newUseStateException());}publicvoiddeposit(doublemoney)throwsUseStateException{if(check())this.balance=balance+money;elsethrow(newUseStateException());}publicvoidconsume(doublemoney)throwsUseStateException{if(check()){if(this.balance=money)this.balance=balance-money;elseJOptionPane.showMessageDialog(null,卡上余额不够消费,请先充值!);}elsethrow(newUseStateException());}publicbooleangetCardState(){returnisUsing;}publicvoidsetState(booleanstate){this.isUsing=state;}publicbooleancheck(){if(this.isUsing)returntrue;elsereturnfalse;}@OverridepublicStringtoString(){return卡号=+cardNo+,用户号=+UserID+,密码=+password+,余额=+balance+,是否可用=+isUsing;}1.1.3实现数据库连接packageoperationGUI;importjava.sql.*;publicclassDBAccess{privateConnectionconn=null;privateStatementstmt=null;publicResultSetrs=null;privatePreparedStatementprestmt=null;privateStringdriver=sun.jdbc.odbc.JdbcOdbcDriver;privateStringurl=jdbc:odbc:CardConn;//自定义数据源名privateStringuser=jane;privateStringpwd=123456;publicStringnotes=数据库操作提示;//实例方法:实现数据库连接publicvoiddbconn(){try{Class.forName(driver);conn=DriverManager.getConnection(url,user,pwd);stmt=conn.createStatement();}catch(ClassNotFoundExceptionec){System.out.println(ec);}catch(SQLExceptiones){System.out.println(es);}catch(Exceptionex){System.out.println(ex);}}//实现数据库查询并返回查询记录publicResultSetdbSelect(StringselString){try{rs=stmt.executeQuery(selString);}catch(SQLExceptiones){System.out.println(es);notes=数据库查询出现异常;}returnrs;}//数据库更新publicStringdbUpdate(StringupdateString){try{prestmt=conn.prepareStatement(updateString);prestmt.executeUpdate();
本文标题:校园卡掌上管理系统编码与测试报告-第十组
链接地址:https://www.777doc.com/doc-2293966 .html