網(wǎng)上書(shū)店信息管理系統(tǒng)“加”代碼“加”數(shù)據(jù)庫(kù)表_第1頁(yè)
網(wǎng)上書(shū)店信息管理系統(tǒng)“加”代碼“加”數(shù)據(jù)庫(kù)表_第2頁(yè)
網(wǎng)上書(shū)店信息管理系統(tǒng)“加”代碼“加”數(shù)據(jù)庫(kù)表_第3頁(yè)
網(wǎng)上書(shū)店信息管理系統(tǒng)“加”代碼“加”數(shù)據(jù)庫(kù)表_第4頁(yè)
網(wǎng)上書(shū)店信息管理系統(tǒng)“加”代碼“加”數(shù)據(jù)庫(kù)表_第5頁(yè)
已閱讀5頁(yè),還剩168頁(yè)未讀, 繼續(xù)免費(fèi)閱讀

下載本文檔

版權(quán)說(shuō)明:本文檔由用戶(hù)提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)

文檔簡(jiǎn)介

學(xué)生姓名:蔣斌指導(dǎo)老師:羅永紅摘要本課程設(shè)計(jì)主要是設(shè)計(jì)一個(gè)書(shū)店信息管理的系統(tǒng),實(shí)現(xiàn)用戶(hù)的注冊(cè)、登加、刪除、修改、查詢(xún)及圖書(shū)的購(gòu)買(mǎi)等功能。程序設(shè)計(jì)平臺(tái)初步實(shí)現(xiàn)了目標(biāo)。TheDesignandImplementationofnformationagementSystemNameJiangBinAdvisorLuoYonghongAbstractThiscoursedesignismainlytomakeainformationmanagementsystemofaonlinebookstore,Thefunctionofthesystemincludebook’adding,deletingandqueryingandpurchasebooks.ProgramdesignplatformisWindowsXP,programminglanguageisJAVA,aretheconnecteddatabaseisOracle10g.Intheprogramprocess,Iadoptedtwosolutionofthestructuredandobject-oriented.Programrunthroughthedebugger,achievingtheinitialgoal.KeywordsDatabase;oracle10g;JAVA;OnlineBookstoreInformationManagement目錄 1.1課題背景 11.2課程設(shè)計(jì)目的 1 結(jié)構(gòu)分析 22.1需求分析 22.2功能模塊圖 3 3.1概念結(jié)構(gòu)設(shè)計(jì) 4 實(shí)現(xiàn) 10 4.2登錄界面 11 4.5書(shū)籍修改 134.6圖書(shū)刪除 144.7圖書(shū)刪除 144.8訂單查詢(xún)修改 15 19特別重要。因此網(wǎng)上書(shū)店的出現(xiàn)成為必然。統(tǒng),以達(dá)到上述的目的。管理,修改管理,查詢(xún)管理。登錄,客戶(hù)的購(gòu)書(shū)等。與開(kāi)發(fā),采用Eclipse和oracle10g等軟件為開(kāi)發(fā)工具。通過(guò)對(duì)計(jì)算機(jī)硬件和軟開(kāi)發(fā)實(shí)踐。在指導(dǎo)老師的幫助下,已經(jīng)基本上成功地實(shí)現(xiàn)了設(shè)計(jì)任務(wù)書(shū)的要求,使得設(shè)計(jì)的數(shù)據(jù)庫(kù)系統(tǒng)能夠?qū)崿F(xiàn)一般數(shù)據(jù)庫(kù)的管理。構(gòu)分析需求分析發(fā)設(shè)計(jì)的。通過(guò)對(duì)書(shū)籍信息管理,使客戶(hù)能輕松購(gòu)買(mǎi)書(shū)籍。經(jīng)過(guò)綜合分析,確定了網(wǎng)上書(shū)店信息管理系統(tǒng)的主要包括以下功能:(1)商家:此模塊的主要功能是用于商家注冊(cè)賬號(hào);此模塊的主要功能是用于擁有商家賬號(hào)的用戶(hù)登陸系統(tǒng)對(duì)自己的書(shū)店進(jìn)行管理;此模塊的主要功能是用于商家發(fā)布一些新書(shū)共客戶(hù)查看及購(gòu)買(mǎi);此模塊的主要功能是用于商家修改自己書(shū)店書(shū)籍的信息;此模塊的主要功能是用于商家刪除一些書(shū)籍信息;此模塊的主要功能是用于商家查詢(xún)自己書(shū)店的書(shū)籍;此模塊的主要功能是用于商家查詢(xún)自己書(shū)店賣(mài)書(shū)的記錄;(2)客戶(hù):此模塊的主要功能是用于商家注冊(cè)賬號(hào);此模塊的主要功能是對(duì)擁有客戶(hù)賬號(hào)的用戶(hù)登錄;此模塊的主要功能是用于客戶(hù)查看所有商家的書(shū)籍信息;商家注冊(cè)登錄書(shū)籍查詢(xún)書(shū)籍上傳書(shū)籍修改書(shū)籍刪除訂單查詢(xún)客戶(hù)注冊(cè)登錄書(shū)籍查詢(xún)購(gòu)買(mǎi)書(shū)籍訂單查詢(xún)商家注冊(cè)登錄書(shū)籍查詢(xún)書(shū)籍上傳書(shū)籍修改書(shū)籍刪除訂單查詢(xún)客戶(hù)注冊(cè)登錄書(shū)籍查詢(xún)購(gòu)買(mǎi)書(shū)籍訂單查詢(xún)能用于客戶(hù)購(gòu)買(mǎi)書(shū)籍此模塊的主要功能是用于客戶(hù)查詢(xún)自己的購(gòu)書(shū)記錄;能模塊圖上述的功能,可以設(shè)計(jì)出系統(tǒng)的總體功能模塊,如圖2.1所示,息管理系統(tǒng) buyer_id庫(kù)設(shè)計(jì)概念結(jié)構(gòu)設(shè)計(jì)得該系統(tǒng)的E-R圖,ER所示, pwdaddressbuyer_namebuyer_namebuyer pwdaddressamidamidumdd pricediscountnumyeridER得到總E-R圖,如圖3.5所示。邏輯結(jié)構(gòu)設(shè)計(jì)根據(jù)上述的概念結(jié)構(gòu)設(shè)計(jì)出邏輯結(jié)構(gòu),將E-R圖轉(zhuǎn)換為關(guān)系模型。r(1)商家信息表seller所示,varchar20)varchar20)pwdvarchar20)書(shū)店地址varchar200)所示,buyer_idvarchar20)buyer_namevarchar20)pwdvarchar20)客戶(hù)住址varchar200)3-3所示,sidvarchar0)namevarchar0)price價(jià)格tum訂單信息表order用來(lái)保存訂單號(hào)、書(shū)籍編名等信息。表order的結(jié)構(gòu)如表3-4所示,idsidvarchar0)varchar0)buyer_idum量數(shù)據(jù)庫(kù)表的建立據(jù)tablesellerlleridvarcharprimarykeyernamevarcharpwdvarchar2(20),dressvarchartablebuyerbuyer_idvarchar(20)primarykey,buyer_namevarchar(20),pwdvarchar2(20),ressvarcharetablegoodsodsidintprimarykeyridvarcharoodsnamevarcharpriceint,ntintnumintconstraintfkselleridforeignkeyselleridreferencesseller(seller_id)tableorderseridintprimarykeydsidintridvarcharbuyer_idvarchar(20),numintconstraintfkgoodsidforeignkeygoodsidreferencesgoods(goods_id),constraintfksellersidforeignkeyselleridreferencesseller(seller_id),constraintfkbuyeridforeignkeybuyeridreferencesbuyer(buyer_id)該程序?qū)崿F(xiàn)了網(wǎng)上書(shū)店信息管理系統(tǒng)應(yīng)有的功能,即賬號(hào)注冊(cè)、登錄功能、書(shū)籍查詢(xún)、書(shū)籍添加、書(shū)籍刪除、書(shū)籍修改、書(shū)籍購(gòu)買(mǎi)功能。界面成功,如圖4.1所示,圖4.1注冊(cè)界面實(shí)現(xiàn)注冊(cè)功能的核心代碼如下:/構(gòu)建客戶(hù)對(duì)象BuyerbuyernewBuyer();/設(shè)置客戶(hù)的信息buyer.setId(fieldCus0.getText());buyer.setName(fieldCus1.getText());buyer.setPwd(fieldCus2.getText());buyer.setAddress(fieldCus3.getText());/構(gòu)建BuyerDao對(duì)象BuyerDaodaonewBuyerDao();/把該客戶(hù)插入到數(shù)據(jù)庫(kù)中錄界面成功,如圖4.2所示,圖4.2登錄界面功時(shí),進(jìn)入主界面,實(shí)現(xiàn)登錄功能的核心代碼如下:/通過(guò)輸入姓名和密碼獲取一個(gè)用戶(hù)對(duì)象SellersellerSellerDaogetSelleruseNameTextgetTextpwsgetText));/判斷隊(duì)形是否為空/隱藏當(dāng)前窗口blefalse/構(gòu)建用戶(hù)主窗口,并顯示出來(lái)newSellerFramesetVisibletrue界面登錄成功后商家和客戶(hù)分別進(jìn)入兩個(gè)不同的主界面,如圖4.3所示,圖4.3主界面圖4.3主界面界面主界面里面商家可以查看到自己的商品信息及商品出售后生成的訂單信息,客戶(hù)則可以瀏覽所有商家的商品信息和自己的購(gòu)物記錄。添加圖4.4書(shū)籍添加界面心代碼如下:/構(gòu)建GoodsDao對(duì)象GoodsDaodaonewGoodsDao;/設(shè)置goods的屬性goodssetDiscountIntegervalueOffieldDiscountgetText)));goodssetNamefieldNamegetText;goodssetNumIntegervalueOffieldNumgetText)));goodssetPriceIntegervalueOffieldPricegetText)));//調(diào)用dao.insertGoods()方法,把商品插入到數(shù)據(jù)庫(kù)中insertGoodsgoods籍修改要用于商家修改自己的書(shū)籍的信息,如圖4.5所示,圖4.4書(shū)籍修改界面以對(duì)商品進(jìn)行修改,實(shí)現(xiàn)修改功能的核心代碼如下:odsDaoGoodsDaodaonewGoodsDao;/讀取對(duì)應(yīng)文本框的信息并設(shè)置到goods里面goodssetDiscountIntegervalueOffieldDiscountgetText)));goodssetNamefieldNamegetText;goodssetNumIntegervalueOffieldNumgetText)));goodssetPriceIntegervalueOffieldPricegetText)));/修改goods信息updateGoodsgoods6圖書(shū)刪除要用于商家對(duì)書(shū)籍進(jìn)行刪除操作,如圖4.6所示,圖4.6書(shū)籍刪除界面當(dāng)商家往文本框里輸入書(shū)籍編號(hào)后,點(diǎn)擊刪除,則可以對(duì)書(shū)籍進(jìn)行刪除,下:/獲取文本框中輸入的書(shū)籍編號(hào)intidIntegerparseInt(field.getText());/構(gòu)建GoodsDaoGoodsDaodaonewGoodsDao;/調(diào)用//調(diào)用deleteById方法,刪除書(shū)籍eleteByIdid7圖書(shū)刪除要用于客戶(hù)購(gòu)買(mǎi)書(shū)籍,如圖4.7所示,圖4.7圖書(shū)購(gòu)買(mǎi)現(xiàn)客戶(hù)對(duì)書(shū)籍的購(gòu)買(mǎi)。如果書(shū)籍編號(hào)錯(cuò)誤或商品數(shù)量不夠時(shí),系統(tǒng)會(huì)彈出提示,實(shí)現(xiàn)購(gòu)書(shū)功能的核心代碼如下:/構(gòu)建GoodsDao對(duì)象GoodsDaodaonewGoodsDao;/構(gòu)建goods對(duì)象GoodsgoodsnewGoods;/減少庫(kù)存數(shù)量goodssetNumgoodsgetNumnum);/修改商品信息updateGoodsgoods/構(gòu)建訂單對(duì)象OrderDaoordernewOrderDao;/插入一條訂單數(shù)據(jù)rderinserOerderByGoodsgoodsnum訂單查詢(xún)修改要用于客戶(hù)查看生成的訂單,如圖4.8所示,序設(shè)計(jì)語(yǔ)言,它繼承了C++語(yǔ)言面向?qū)ο蠹夹g(shù)的核心,Java舍棄了C++語(yǔ)言中容易引起錯(cuò)誤的指針(以引用取代)、運(yùn)算符重載(operatoroverloading)、多重繼承(以接口取代)等特性,增加了垃圾回收器功能用于回收不再被引用的對(duì)象所占據(jù)的內(nèi)存空間,使得程序員不用再為內(nèi)存管理而擔(dān)憂(yōu)。在JavaSE1.5版本中,Java又引入了泛型編程(GenericProgramming)、類(lèi)型安全的枚舉、不定長(zhǎng)參數(shù)和自動(dòng)裝/拆箱等語(yǔ)言特性。代碼編譯成二進(jìn)制字節(jié)碼(bytecode),然后依賴(lài)各種不同平臺(tái)上的虛擬機(jī)來(lái)解釋執(zhí)行字節(jié)碼,從而實(shí)現(xiàn)了“一次編譯、到處執(zhí)行”的跨平臺(tái)特性[2]。leOracle數(shù)據(jù)庫(kù)包括Oracle數(shù)據(jù)庫(kù)服務(wù)器和客戶(hù)端。Oracle數(shù)據(jù)庫(kù)服務(wù)器:OracleServer是一個(gè)對(duì)象一關(guān)系數(shù)據(jù)庫(kù)管理系統(tǒng)。它提供開(kāi)放的、全面的、和集成的信息管理方法。每個(gè)Server由一個(gè)OracleDB和一個(gè)OracleServer實(shí)例組成。它具有場(chǎng)地自治性(SiteAutonomy)和提供數(shù)據(jù)存儲(chǔ)透明機(jī)制,以此可實(shí)現(xiàn)數(shù)據(jù)存儲(chǔ)透明性。每個(gè)Oracle數(shù)據(jù)庫(kù)對(duì)應(yīng)唯一的一個(gè)實(shí)例名SID,Oracle數(shù)據(jù)庫(kù)服務(wù)器啟動(dòng)后,一般至少有以下幾個(gè)用戶(hù):Internal,它不是一個(gè)真實(shí)的用戶(hù)名,而是具有務(wù),包括啟動(dòng)和關(guān)閉數(shù)據(jù)庫(kù);Sys,它是一個(gè)DBA用戶(hù)名,具有最大的數(shù)據(jù)庫(kù)System一個(gè)DBA用戶(hù)名,權(quán)限僅次于Sys用戶(hù)??蛻?hù)端:必須連接到一服務(wù)器,該數(shù)據(jù)庫(kù)稱(chēng)為本地?cái)?shù)據(jù)庫(kù)(LocalDB)。在網(wǎng)絡(luò)環(huán)境下其它服務(wù)器上的DB稱(chēng)為遠(yuǎn)程數(shù)據(jù)庫(kù)(RemoteDB)。用戶(hù)要存取遠(yuǎn)程DB上的數(shù)據(jù)時(shí),必須建立數(shù)據(jù)庫(kù)鏈。Oracle結(jié)構(gòu)。由于它們是相分離的,所以在管理數(shù)據(jù)的物理存儲(chǔ)結(jié)構(gòu)時(shí)并不會(huì)影響對(duì)邏輯存儲(chǔ)結(jié)構(gòu)的存取。存儲(chǔ)結(jié)構(gòu)模式對(duì)象是直接引用數(shù)據(jù)庫(kù)數(shù)據(jù)的邏輯結(jié)構(gòu)。模式對(duì)象包括這樣一些結(jié)構(gòu):表、表關(guān)系形成了數(shù)據(jù)庫(kù)的關(guān)系設(shè)計(jì)。數(shù)據(jù)塊(Block):是數(shù)據(jù)庫(kù)進(jìn)行UO操作的最小單位,它與操作系統(tǒng)的塊不Oracle數(shù)據(jù)庫(kù)塊為單位。段(Segment):是表空間中一個(gè)指定類(lèi)型的邏輯存儲(chǔ)結(jié)構(gòu),它由一個(gè)或多個(gè)范圍組成,段將占用并增長(zhǎng)存儲(chǔ)空間。其中包括:數(shù)據(jù)段:用來(lái)存放表數(shù)據(jù);索引段:用來(lái)存放表索引;用來(lái)存放中間結(jié)果;回滾段:用于出現(xiàn)異常時(shí),恢復(fù)事務(wù)。范圍(Extent):是數(shù)據(jù)庫(kù)存儲(chǔ)空間分配的邏輯單位,一個(gè)范圍由許多連續(xù)范圍[3]。一步學(xué)習(xí)了Java的基礎(chǔ)語(yǔ)法以及熟悉了用Java編次再去做類(lèi)似的東西我覺(jué)得我一定會(huì)做的更好。[1]薩師煊,王珊.數(shù)據(jù)庫(kù)系統(tǒng)概論(第三版)[M].北京:高等教育出版社.YDanielLiangJavaM北京:機(jī)械工業(yè)出版社.2006.[3]夏幫貴,劉凡馨.JDBCAP數(shù)據(jù)庫(kù)編程實(shí)材作教.北京:北京希望電子出版2001.[4]王立福.軟件工程(第二版)[M].北京:北京大學(xué)出版社.2002.附錄全部源代碼packagecom.shoeShop.db;ortjavasqlConnectionortjavasqlDriverManagerortjavasqlSQLExceptionpublicclassConnect{privatestaticConnectioncon=null;privatestaticStringurl="jdbc:oracle:thin:@localhost:1521:ORCL";privatestaticStringdriver="oracle.jdbc.driver.OracleDriver";privatestaticStringuser="scott";privatestaticStringpwd="tiger";publicstaticConnectiongetConnection(){try{forNamedriverconDriverManagergetConnectionurluserpwd);}catch(ClassNotFoundExceptione){}catch(SQLExceptione){}returncon;}publicstaticvoidmain(String[]args){ctgetConnection}}packagecom.shoeShop.action;portjavaawteventActionEventportjavaawteventActionListenerortjavaxswingJPanelportcomshoeShopviewRegisterFramepublicclassdocMenuActionimplementsActionListener{RegisterFrameregisternullJPanelcusPanelnullJPaneldocPanelnullpublicdocMenuAction(RegisterFrameregister){thisregisterregister;thiscusPanel=register.cusPanel;thisdocPanelregister.docPanel;}publicvoidactionPerformed(ActionEvente){//TODOAuto-generatedmethodstubregister.flag=1;//System.out.println(register.flag);registerremovecusPanel);registeradddocPanel);anelupdateUI}}packagecom.shoeShop.dao;ortjavasqlConnectionortjavasqlResultSetortjavasqlSQLExceptionortjavasqlStatementportcomshoeShopdbConnectportcomshoeShopentityBuyerportcomshoeShopentitySellerpublicclassBuyerDao{privatestaticConnectionconn;privatestaticStatementstatement;privatestaticResultSetresultSet;/插入數(shù)據(jù),用于注冊(cè)publicintinsertBuyer(Buyerbuyer){intflag0;nnConnectgetConnectiontry{mentconncreateStatementStringsql="insertintobuyervalues+buyer.getId()+"','"+buyer.getName()+"','"+buyer.getPwd()+"','"+buyer.getAddress+"')";System.out.println("buyer"+sql);gstatementexecuteUpdatesqlntcloseclose}catch(SQLExceptione){//TODOAuto-generatedcatchblocktStackTrace}System.out.println(flag);returnflag}/通過(guò)用戶(hù)名和密碼查詢(xún),用于登錄publicstaticBuyergetBuyer(Stringname,Stringpwd){nnConnectgetConnectionBuyerbuyernewBuyer();try{mentconncreateStatementStringsql="select*frombuyerwherebuyer_id='"+name+"'andpwd=dresultSetstatement.executeQuery(sql);whileresultSetnext()){buyer.setId(resultSet.getString("buyer_id"));buyer.setName(resultSet.getString("buyer_name"));buyer.setPwd(resultSet.getString("pwd"));buyer.setAddress(resultSet.getString("address"));}resultSetclose);ntcloseclose}catch(SQLExceptione){//TODOAuto-generatedcatchblocktStackTrace}returnbuyer}publicstaticvoidmain(String[]args){BuyerDaodaonewBuyerDao();SystemoutprintlndaogetBuyerzxk1"));////BuyerbuyernewBuyer();buyer.setId("lily");//buyer.setName("長(zhǎng)理專(zhuān)賣(mài)");//buyer.setPwd("123456");//buyer.setAddress("湖南長(zhǎng)沙");//dao.insertBuyer(buyer);}}packagecom.shoeShop.dao;ortjavasqlConnectionortjavasqlResultSetortjavasqlSQLExceptionortjavasqlStatementortjavautilArrayListportcomshoeShopdbConnectportcomshoeShopentityGoodsportcomshoeShopentitySellerportcomshoeShopimpUserpublicclassGoodsDao{privatestaticConnectionconn;privatestaticStatementstatement;privatestaticResultSetresultSet;/查詢(xún)登錄商家的所有商品,用于商家管理自己的商品publicArrayListgetAllGoods(){ArrayListlist=newArrayList();nnConnectgetConnectiontry{mentconncreateStatementStringsql="select*fromgoodsa,sellerbwherea.seller_id=b.seller_idandbselleridUsergetUserName)+"'";resultSetstatement.executeQuery(sql);whileresultSetnext()){sellernewSellerllersetNameresultSetgetStringsellernamelersetAddressresultSetgetStringaddressoodsgoodsnewGoodsssetSellersellergoodssetIdresultSetgetIntgoodsid));goodssetNameresultSetgetStringgoodsname);goodssetSelleridresultSetgetStringsellerid));goodssetDiscountresultSetgetIntdiscount;goodssetNumresultSetgetIntnum;goodssetPriceresultSetgetIntprice;//tprintlngoodstoStringtaddgoods}}catch(SQLExceptione){//TODOAuto-generatedcatchblocktStackTracetry{resultSetclose);ntcloseclose}catch(SQLExceptione){//TODOAuto-generatedcatchblocktStackTrace}}returnlist}/查詢(xún)所有商家的所有商品.用于用戶(hù)搜索商品publicArrayListgetAllSellerGoods(){ArrayListlist=newArrayList();nnConnectgetConnectiontry{mentconncreateStatementStringsql="select*fromgoodsa,sellerbwhereelleridbselleridresultSetstatement.executeQuery(sql);whileresultSetnext()){sellernewSellerllersetNameresultSetgetStringsellernamelersetAddressresultSetgetStringaddressoodsgoodsnewGoodsssetSellersellergoodssetIdresultSetgetIntgoodsid));goodssetNameresultSetgetStringgoodsname);goodssetSelleridresultSetgetStringsellerid));goodssetDiscountresultSetgetIntdiscount;goodssetNumresultSetgetIntnum;goodssetPriceresultSetgetIntprice;//}tprintlngoodstoStringtaddgoods}}catch(SQLExceptione){//TODOAuto-generatedcatchblocktStackTracetry{resultSetclose);ntcloseclose}catch(SQLExceptione){//TODOAuto-generatedcatchblocktStackTrace}}returnlist/根據(jù)商品號(hào)查詢(xún)商品信息publicGoodsgetOneGoods(intid){oodsgoodsnewGoodsnnConnectgetConnectiontry{mentconncreateStatementStringsqlselectfromgoodswheregoodsid+id;resultSetstatement.executeQuery(sql);whileresultSetnext()){dssetIdidgoodssetNameresultSetgetStringgoodsname);goodssetPriceresultSetgetIntprice;goodssetNumresultSetgetIntnum;goodssetDiscountresultSetgetIntdiscount;goodssetSelleridresultSetgetStringsellerid"));goodssetNumresultSetgetIntnum;}}catch(SQLExceptione){//TODOAuto-generatedcatchblocktStackTracetry{resultSetclose);ntcloseclose}catch(SQLExceptione){//TODOAuto-generatedcatchblocktStackTrace}}returngoods;}/修改商品信息publicintupdateGoods(Goodsgoods){intflag0;nnConnectgetConnectiontry{mentconncreateStatementStringsqlupdategoodssetgoodsname'"+goods.getName()+"',pricegoodsgetPrice)iscount="+goods.getDiscount()+",num="+goods.getNum()+"wheregoodsidgoodsgetIdgstatementexecuteUpdatesql}catch(SQLExceptione){//TODOAuto-generatedcatchblocktStackTracetry{ntcloseclose}catch(SQLExceptione){//TODOAuto-generatedcatchblocktStackTrace}}returnflag}dpublicintdeleteById(intid){intflag0;nnConnectgetConnectiontry{mentconncreateStatementStringsqldeletegoodswheregoodsid+id;gstatementexecuteUpdatesql}catch(SQLExceptione){//TODOAuto-generatedcatchblocktStackTracetry{ntcloseclose}catch(SQLExceptione){//TODOAuto-generatedcatchblocktStackTrace}}returnflag}//添加publicintinsertGoods(Goodsgoods){intflag0;nnConnectgetConnectiontry{mentconncreateStatementStringsql="insertintogoodsvalues((selectmax(goods_id+1)fromgoodsUsergetUserName+"','"+goods.getName()+"',"+goods.getPrice()+","+goodsgetDiscountgoods.getNum()+")";gstatementexecuteUpdatesql}catch(SQLExceptione){//TODOAuto-generatedcatchblocktStackTracetry{ntcloseclose}catch(SQLExceptione){//TODOAuto-generatedcatchblocktStackTrace}}returnflag}publicstaticvoidmain(String[]args){oodsDaodaonewGoodsDao////////////////oodsgoodsnewGoodsgoodssetNamec;oodssetPriceUsersetUserName"niclascage");odssetDiscountoodssetNumprintlnmainmoutprintlniidaoinsertGoodsgoodsSystem.out.println(dao.deleteById(4));//Goodsgoods=newGoods();//goods.setId(1);//goods.setName("oracle");//goods.setPrice(50);//goods.setDiscount(8);//goods.setNum(5);System.out.println(dao.updateGoods(goods));etAllSellerGoodsSystem.out.println(dao.getOneGoods(1));}}packagecom.shoeShop.dao;ortjavasqlConnectionortjavasqlResultSetortjavasqlSQLExceptionortjavasqlStatementortjavautilArrayListportcomshoeShopdbConnectportcomshoeShopentityGoodsmportcomshoeShopentityOrderportcomshoeShopentitySellerportcomshoeShopimpUserpublicclassOrderDao{privatestaticConnectionconn;privatestaticStatementstatement;privatestaticResultSetresultSet;//插入publicintinserOerderByGoods(Goodsgoods,intnum){intflag0;nnConnectgetConnectiontry{mentconncreateStatementStringsql="insertintoordersvalues((selectmax(order_id+1)fromorders"+goods.getId()+",'"+goods.getSeller_id()+"','"+User.getUserName()+"',"+num)";gstatementexecuteUpdatesql}catch(SQLExceptione){//TODOAuto-generatedcatchblocktStackTracetry{ntcloseclose}catch(SQLExceptione){//TODOAuto-generatedcatchblocktStackTrace}}returnflag}/查詢(xún)登錄用戶(hù)的所有訂單publicArrayListgetOrder(){ArrayListlist=newArrayList();nnConnectgetConnectiontry{mentconncreateStatementStringsql="select*fromordersa,sellerb,goodscwhereaselleridbselleridanda.goods_id=c.goods_idanda.buyer_id=UsergetUserName";resultSetstatement.executeQuery(sql);whileresultSetnext()){OrderordernewOrderoodsgoodsnewGoodssellernewSellerordersetIdresultSetgetIntorderid);ordersetNumresultSetgetIntnumordersetGoodsidresultSetgetIntgoodsid));goodssetIdresultSetgetIntgoodsid));goodssetPriceresultSetgetShortprice;goodssetPriceresultSetgetIntprice;goodssetDiscountresultSetgetIntdiscount;goodssetNameresultSetgetStringgoodsname);llersetNameresultSetgetStringsellernamelersetAddressresultSetgetStringaddresssetSellersellerrsetGoodsgoods//tprintlnordertoString//addorder}}catch(SQLExceptione){//TODOAuto-generatedcatchblocktStackTracetry{resultSetclose);ntcloseclose}catch(SQLExceptione){//TODOAuto-generatedcatchblocktStackTrace}}returnlist}/查詢(xún)登錄商家的所有訂單publicArrayListgetSellerOrder(){ArrayListlist=newArrayList();nnConnectgetConnectiontry{mentconncreateStatementStringsql="select*fromordersa,sellerb,goodscwhereaselleridbsellerid"+"anda.goods_id=c.goods_idanda.seller_id=UsergetUserName;resultSetstatement.executeQuery(sql);whileresultSetnext()){OrderordernewOrderoodsgoodsnewGoodssellernewSellerordersetIdresultSetgetIntorderid);ordersetNumresultSetgetIntnumordersetGoodsidresultSetgetIntgoodsid));ordersetBuyeridresultSetgetStringbuyerid);goodssetIdresultSetgetIntgoodsid));goodssetPriceresultSetgetShortprice;goodssetPriceresultSetgetIntprice;goodssetDiscountresultSetgetIntdiscount;goodssetNameresultSetgetStringgoodsname);llersetNameresultSetgetStringsellernamelersetAddressresultSetgetStringaddresssetSellersellerrsetGoodsgoodsaddorder}}catch(SQLExceptione){//TODOAuto-generatedcatchblocktStackTracetry{resultSetclose);ntcloseclose}catch(SQLExceptione){//TODOAuto-generatedcatchblocktStackTrace}}returnlist}publicstaticvoidmain(String[]args){OrderDaodaonewOrderDaoetOrder}}packagecom.shoeShop.dao;ortjavasqlConnectionortjavasqlResultSetortjavasqlSQLExceptionortjavasqlStatementportcomshoeShopdbConnectportcomshoeShopentitySellerpublicclassSellerDao{privatestaticConnectionconn;privatestaticStatementstatement;privatestaticResultSetresultSet;/插入數(shù)據(jù),用于注冊(cè)publicintinsertSeller(Sellerseller){intflag0;nnConnectgetConnectiontry{mentconncreateStatementStringsql="insertintosellervalues"+seller.getId()+"','"+seller.getName()+"','"+seller.getPwd()+"','"+seller.getAddress+"')";gstatementexecuteUpdatesqlntcloseclose}catch(SQLExceptione){//TODOAuto-generatedcatchblocktStackTrace}returnflag}/通過(guò)用戶(hù)名和密碼查詢(xún),用于登錄publicstaticSellergetSeller(Stringname,Stringpwd){nnConnectgetConnectionsellernewSellertry{mentconncreateStatementStringsql="select*fromsellerwhereseller_id='"+name+"'andpwd='"+pwd+"'";resultSetstatement.executeQuery(sql);whileresultSetnext()){llersetIdresultSetgetStringselleridllersetNameresultSetgetStringsellernamelersetPwdresultSetgetStringpwdlersetAddressresultSetgetStringaddress}resultSetclose);ntcloseclose}catch(SQLExceptione){//TODOAuto-generatedcatchblocktStackTrace}returnseller}publicstaticvoidmain(String[]args){aodaonewSellerDaoSystem.out.println(dao.getSeller("蔣斌","654321"));Sellerseller=newSeller();//seller.setId("lily");//seller.setName("長(zhǎng)理專(zhuān)賣(mài)");//seller.setPwd("123456");//seller.setAddress("湖南長(zhǎng)沙");//dao.insertSeller(seller);}}packagecom.shoeShop.entity;**publicclassBuyer{privateStringid;privateStringname;privateStringaddress;privateStringpwd;publicStringgetPwd(){returnpwd}publicvoidsetPwd(Stringpwd){thispwdpwd;}publicStringgetId(){returnid}publicvoidsetId(Stringid){this.id=id;}publicStringgetName(){returnname}publicvoidsetName(Stringname){thisnamename;}publicStringgetAddress(){returnaddress}publicvoidsetAddress(Stringaddress){thisaddress=address;}publicStringtoString(){returnBuyer[id="+id+",name="+name+",address="+address"]";}}packagecom.shoeShop.entity;***publicclassGoods{privateintid;privateStringseller_id;privateSellerseller;privateStringname;privateintprice;privateintdiscount;privateintnum;publicSellergetSeller(){returnseller}publicvoidsetSeller(Sellerseller){thisseller=seller;}publicintgetDiscount(){returndiscount}publicvoidsetDiscount(intdiscount){this.discount=discount;}publicintgetNum(){returnnum}publicvoidsetNum(intnum){thisnumnum;}publicintgetId(){returnid}publicvoidsetId(intid){this.id=id;}publicStringgetSeller_id(){returnseller_id;}publicvoidsetSeller_id(Stringseller_id){thissellerid=seller_id;}publicStringgetName(){returnname}publicvoidsetName(Stringname){thisnamename;}publicintgetPrice(){returnprice}publicvoidsetPrice(intprice){thispriceprice;}publicStringtoString(){returnGoods[id="+id+",seller_id="+seller_id+",seller="seller",name="+name+",price="+price",discount="+discount+",num="+num+"]";}}packagecom.shoeShop.entity;***publicclassOrder{privateintid;privateintgoods_id;privateStringseller_id;privateStringbuyer_id;privateGoodsgoods;privateSellerseller;privateBuyerbuyer;privateintnum;publicintgetNum(){returnnum}publicvoidsetNum(intnum){thisnumnum;}publicGoodsgetGoods(){returngoods;}publicvoidsetGoods(Goodsgoods){thisgoods=goods;}publicSellergetSeller(){returnseller}publicvoidsetSeller(Sellerseller){thisseller=seller;}publicBuyergetBuyer(){returnbuyer}publicvoidsetBuyer(Buyerbuyer){thisbuyerbuyer;}publicintgetId(){returnid}publicvoidsetId(intid){this.id=id;}publicintgetGoods_id(){returngoods_id;}publicvoidsetGoods_id(intgoods_id){thisgoodsid=goods_id;}publicStringgetSeller_id(){returnseller_id;}packagecom.shoeShop.entity;publicvoidsetSeller_id(Stringseller_id){thissellerid=seller_id;}publicStringgetBuyer_id(){returnbuyerid;}publicvoidsetBuyer_id(Stringbuyer_id){thisbuyerid=buyer_id;}publicStringtoString(){returnOrder[id="+id+",goods_id="+goods_id+",seller_id="sellerid",buyer_id="+buyer_id+",goods="+goodsseller="+seller+",buyer="+buyer+",num="+num"]";}}**publicclassSeller{privateStringid;privateStringname;privateStringpwd;privateStringaddress;publicStringgetPwd(){returnpwd}publicvoidsetPwd(Stringpwd){thispwdpwd;}publicStringgetId(){returnid}publicvoidsetId(Stringid){this.id=id;}publicStringgetName(){returnname}publicvoidsetName(Stringname){thisnamename;}publicStringgetAddress(){returnaddress}publicvoidsetAddress(Stringaddress){thisaddress=address;}publicStringtoString(){returnSeller[id="+id+",name="+name+",pwd="+pwdaddress="+address+"]";}}packagecom.shoeShop.imp;publicclassUser{privatestaticintflag=0;privatestaticStringuserName;privatestaticStringpwd;publicstaticStringgetPwd(){returnpwd}publicstaticvoidsetPwd(Stringpwd){Userpwd=pwd;}publicstaticStringgetUserName(){returnuserName}publicstaticvoidsetUserName(StringuserName){UseruserName=userName;}publicstaticintgetFlag(){returnflag}publicstaticvoidsetFlag(intflag){User.flag=flag;}}packagecom.shoeShop.view;portjavaawteventActionEventportjavaawteventActionListenerortjavaxswingImageIconortjavaxswingJButtonortjavaxswingJFrameortjavaxswingJLabelortjavaxswingJOptionPaneortjavaxswingJTextFieldportcomshoeShopdaoGoodsDaoportcomshoeShopentityGoodspublicclassAddGoodsFrameextendsJFrame{privatestaticfinalGoodsGoods=null;privateJTextFieldfieldName=newJTextField(20);privateJTextFieldfieldPrice=newJTextField(20);privateJTextFieldfieldDiscount=newJTextField(20);privateJTextFieldfieldNum=newJTextField(20);privateJButtonbtSure=newJButton("確定");privateJButtonbtCancel=newJButton("取消");privateGoodsgoods=newGoods();publicAddGoodsFrame(){}privatevoidinit(){thissetSize320,330);thissetTitle商品添加");thissetIconImagenewImageIcon("images/1.png").getImage());thissetLayoutnull;thissetLocationRelativeTonull;thissetResizablefalse;//this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);thissetLayoutnull;tPanel}privatevoidsetContentPanel(){lbNamesetBounds,80,30);fieldNamesetBounds0,150,30);lbPricesetBounds90,80,30);fieldPricesetBounds0,150,30);lbDiscountsetBounds150,80,30);fieldDiscountsetBounds50,150,30);lbNumsetBounds200,80,30);fieldNumsetBounds00,150,30);btCancel.setBounds(30,250,70,30);btSure.setBounds(210,250,70,30);thisaddlbName;thisaddfieldName;thisaddlbPrice;thisaddfieldPrice;thisaddlbDiscount;thisaddfieldDiscount;thisaddlbNum);thisaddfieldNum;thisaddbtCancel;thisaddbtSure);btCancel.addActionListener(newActionListener(){publicvoidactionPerformed(ActionEvente){//TODOAuto-generatedmethodstubefalse}btSure.addActionListener(newActionListener(){publicvoidactionPerformed(ActionEvente){//TODOAuto-generatedmethodstuboodsDaodaonewGoodsDaogoodssetDiscountIntegervalueOffieldDiscountgetText);oodssetNamefieldNamegetTextgoodssetNumIntegervalueOffieldNumgetText);goodssetPriceIntegervalueOffieldPricegetText);nsertGoodsgoodsefalse//}}}publicGoodsgetGoods(){returngoods;}publicvoidsetGoods(Goodsgoods){thisgoods=goods;}publicstaticvoidmain(String[]args){UpdateFrameframe=newUpdateFrame();etVisibletrue}}packagecom.shoeShop.view;ortjavaawtBorderLayoutportjavaawtColorportjavaawteventActionEventportjavaawteventActionListenerortjavautilArrayListortjavaxswingImageIconortjavaxswingJButtonortjavaxswingJComboBoxortjavaxswingJFrameortjavaxswingJLabelortjavaxswingJMenuortjavaxswingJMenuBarortjavaxswingJMenuItemortjavaxswingJOptionPaneortjavaxswingJPanelortjavaxswingJScrollPaneortjavaxswingJTableortjavaxswingJTextFieldportcomshoeShopdaoGoodsDaoportcomshoeShopdaoOrderDaoportcomshoeShopentityGoodsmportcomshoeShopentityOrderpublicclassBuyerFrameextendsJFrame{privateJPanelgoodsPanel=newJPanel();//中間面板privateJPanelorderPanel=newJPanel();//訂單面板privateJPanelsouthPanel=newJPanel();//南邊用于方按鈕的面板privateJMenuBarmenuBar=newJMenuBar();privateJMenugoodsMenu=newJMenu("商品管理");privateJMenuorderMenu=newJMenu("訂單管理");privateJMenuItemgoodsMenuItem=newJMenuItem("商品購(gòu)買(mǎi)");privateJMenuItemorderMenuItem=newJMenuItem("訂單管理");//privateJButtonbtDelet=newJButton("刪除");privateJButtonbtAdd=newJButton("購(gòu)買(mǎi)");privateJComboBoxnumBox=newJComboBox(newString4","5","6","7","8","9"});//privateJButtonbtUpdate=newJButton("修改");privateJTextFieldfieldId=newJTextField(15);ObjectarnewObject80][8];ObjectornewObject80][9];publicBuyerFrame(){}privatevoidinit(){rthissetTitle網(wǎng)上鞋購(gòu)系統(tǒng)");thissetIconImagenewImageIcon("images/1.png").getImage());thissetSize600,400);thissetDefaultCloseOperationJFrameEXIT_ON_CLOSE);thissetLocationRelativeTonull;thisaddmenuBarBorderLayout.NORTH);aneldsPanelsetBackgroundColorGRAYthisaddgoodsPanel,BorderLayout.CENTER);erPanelsetBackgroundColorLIGHTGRAYanelanelthisaddsouthPanel,BorderLayout.SOUTH);}//borderlayout北邊面板設(shè)置privatevoidsetMenuBar(){menuBaraddgoodsMenu);dsMenuaddgoodsMenuItemgoodsMenuItem.addActionListener(newActionListener(){publicvoidactionPerformed(ActionEvente){//TODOAuto-generatedmethodstubremoveorderPanel;dsPanelsPanelupdateUI}menuBaraddorderMenu);MenuaddorderMenuItemorderMenuItem.addActionListener(newActionListener(){publicvoidactionPerformed(ActionEvente){//TODOAuto-generatedmethodstubremovegoodsPanel;erPanelPanelupdateUI}}//borderlayout南邊面板設(shè)置privatevoidsetSouthPanel(){eladdfieldIdeladdnumBox//修改eladdbtAddbtAdd.addActionListener(newActionListener(){publicvoidactionPerformed(ActionEvente){//TODOAuto-generatedmethodstuboodsDaodaonewGoodsDaooodsgoodsnewGoodsifequalsfieldIdgetText))){JOptionPane.showMessageDialog(null,"請(qǐng)輸入商品編號(hào)或商intidIntegerparseIntfieldIdgetText());intnumIntegerparseIntString)numBox.getSelectedItem());oodsdaogetOneGoodsidif(JOptionPane.showConfirmDialog(null,"您確定要購(gòu)買(mǎi)嗎?ifgoodsgetId){llifgoodsgetNumnumJOptionPane.showMessageDialog(null,"商品數(shù)量goodssetNumgoodsgetNumnumpdateGoodsgoodsOrderDaoordernewOrderDaoerinserOerderByGoodsgoodsnumJOptionPane.showMessageDialog(null,"購(gòu)買(mǎi)成sPanelupdateUI}}}}}}//borderlayout中間商品面板設(shè)置privatevoidsetGoodsPanel(

溫馨提示

  • 1. 本站所有資源如無(wú)特殊說(shuō)明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶(hù)所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁(yè)內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒(méi)有圖紙預(yù)覽就沒(méi)有圖紙。
  • 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫(kù)網(wǎng)僅提供信息存儲(chǔ)空間,僅對(duì)用戶(hù)上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對(duì)用戶(hù)上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對(duì)任何下載內(nèi)容負(fù)責(zé)。
  • 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請(qǐng)與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶(hù)因使用這些下載資源對(duì)自己和他人造成任何形式的傷害或損失。

最新文檔

評(píng)論

0/150

提交評(píng)論