版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進(jìn)行舉報或認(rèn)領(lǐng)
文檔簡介
1、校園卡掌上管理系統(tǒng) -編碼與測試報告 制作人: 曹 靜 崔 文 傅小江 李國明 1、編碼1.1部分代碼1.1.1數(shù)據(jù)庫實施階段任務(wù)(1)建立數(shù)據(jù)庫(校園卡管理系統(tǒng))create database campuscard;建立數(shù)據(jù)表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) 轉(zhuǎn)賬信息表的建立 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) 學(xué)生信息表的建立 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) /設(shè)置起始卡號 schoolcard.nextcardno = new
13、startno; public int getcardno() return cardno; public string getuserid() /差卡的用戶號 return userid; public void setuserid(string uid) /設(shè)置卡的用戶號 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實現(xiàn)數(shù)據(jù)庫連接 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"/自定義數(shù)據(jù)源名 private string user="jane" private string pwd="1
18、23456" public string notes="數(shù)據(jù)庫操作提示" /實例方法:實現(xiàn)數(shù)據(jù)庫連接 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); /實現(xiàn)數(shù)據(jù)庫查詢并返回查詢記錄 public resultset dbselect(string selstring) try rs=stmt.executequery(selstring); catch (sqlexception es) system.out.println(es); notes="數(shù)據(jù)庫查詢出現(xiàn)異常" return rs; /數(shù)據(jù)庫更新 public string dbupdate(string updatestring) try prestmt=conn.prep
20、arestatement(updatestring); prestmt.executeupdate(); notes="記錄更新成功" catch (sqlexception es) system.out.println(es); notes="數(shù)據(jù)庫更新出現(xiàn)異常" return notes; /插入數(shù)據(jù) public string dbinsert(string insertstring) try prestmt=conn.preparestatement(insertstring); prestmt.executeupdate(); notes=&q
21、uot;插入記錄成功" catch (sqlexception es) system.out.println(es); notes="數(shù)據(jù)庫插入出現(xiàn)異常" return notes; /刪除 public string dbdelete(string delstring) try prestmt=conn.preparestatement(delstring); prestmt.executeupdate(); notes="刪除成功" catch (sqlexception es) system.out.println(es); notes=
22、"數(shù)據(jù)庫刪除現(xiàn)異常" return notes; /關(guān)閉數(shù)據(jù)庫 public void dbclose() if(conn!=null) try rs.close(); stmt.close(); conn.close(); catch (exception e) 1.2 系統(tǒng)主界面的截圖。校園卡管理界面校園卡管理主要功能是對校園卡信息進(jìn)行查詢,開戶銷戶等功能的操作。圖1登錄界面1.3系統(tǒng)部分功能界面的截圖。圖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") /顯示用戶名,并新建當(dāng)前用戶對象,存儲有關(guān)信息。 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,"已經(jīng)添加此用戶!"); 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); /*數(shù)據(jù)庫操作* 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); 修改密碼 /確定按鈕響應(yīng)事件代碼 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循環(huán)來控制密碼登陸次數(shù),次數(shù)為三次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. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負(fù)責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時也不承擔(dān)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 二零二五版設(shè)備砂石料購銷與設(shè)備性能優(yōu)化協(xié)議3篇
- 二零二五年度人事部人才與專家工作辦公室員工福利保障合同3篇
- 二零二五年度圖書館圖書修復(fù)與保護(hù)工程合同
- 個體物流配送員勞動協(xié)議格式(2024年版)一
- 二零二五版木材進(jìn)口關(guān)稅減免申請服務(wù)合同4篇
- 二零二五年度土地利用現(xiàn)狀變更測量合同
- 二零二五年度城市公共充電樁運營管理合同4篇
- 二零二五版大數(shù)據(jù)中心項目合作協(xié)議4篇
- 2025年度美容院連鎖加盟區(qū)域代理權(quán)及市場獨占協(xié)議
- 2025年度企業(yè)培訓(xùn)項目財務(wù)結(jié)算合同范本4篇
- 2024生態(tài)環(huán)境相關(guān)法律法規(guī)考試試題
- 有砟軌道施工工藝課件
- 兩辦意見八硬措施煤礦安全生產(chǎn)條例宣貫學(xué)習(xí)課件
- 40篇短文搞定高中英語3500單詞
- 人教版高中數(shù)學(xué)必修二《第九章 統(tǒng)計》同步練習(xí)及答案解析
- 兒科護(hù)理安全警示教育課件
- 三年級下冊口算天天100題
- 國家中英文名稱及代碼縮寫(三位)
- 人員密集場所消防安全培訓(xùn)
- 液晶高壓芯片去保護(hù)方法
- 拜太歲科儀文檔
評論
0/150
提交評論