書(shū)店管理系統(tǒng):
項(xiàng)目練習(xí)目標(biāo) :
1、Java應(yīng)用程序基本分析
2、培養(yǎng)面向?qū)ο缶幊痰幕舅枷?br />
3、Java基本設(shè)計(jì)模式綜合應(yīng)用
4、掌握分層和接口的基本設(shè)計(jì)
5、構(gòu)建合理的Java應(yīng)用程序包結(jié)構(gòu)
6、綜合應(yīng)用JSE所學(xué)習(xí)的知識(shí)
7、在應(yīng)用中合理使用集合框架
8、在應(yīng)用中綜合使用swing的常用組件
9、基本的表現(xiàn)層的實(shí)現(xiàn)機(jī)制
10、IO流和文件的基本操作
11、培養(yǎng)良好的Java編程習(xí)慣
12、培養(yǎng)調(diào)試Java程序的能力,培養(yǎng)改錯(cuò)的能力
項(xiàng)目功能需求 :
1、能進(jìn)行操作用戶(hù)的注冊(cè),修改基本信息,刪除和查詢(xún)。
2、能對(duì)圖書(shū)的基本信息進(jìn)行增加、刪除、修改和查詢(xún)操作。
3、能填寫(xiě)進(jìn)貨單,一張進(jìn)貨單帶有多條具體的進(jìn)貨信息,進(jìn)貨的書(shū)籍必須是圖書(shū)管理里面已經(jīng)有的;進(jìn)貨的同時(shí)修改庫(kù)存對(duì)應(yīng)書(shū)籍的存貨量。
4、能填寫(xiě)銷(xiāo)售單,一張銷(xiāo)售單帶有多條具體的銷(xiāo)售信息,銷(xiāo)售的書(shū)籍必須是圖書(shū)管理里面已經(jīng)有的,而且銷(xiāo)售的數(shù)量不能超過(guò)當(dāng)前庫(kù)存的數(shù)量;銷(xiāo)售的同時(shí)修改庫(kù)存對(duì)應(yīng)書(shū)籍的存貨量。
5、可以查看庫(kù)存的明細(xì),可以按照條件進(jìn)行查找具體的圖書(shū)的庫(kù)存值。
6、權(quán)限方面進(jìn)行簡(jiǎn)化,做固定的權(quán)限控制。把用戶(hù)按照模塊分成不同操作權(quán)限的人員,特設(shè)一個(gè)admin的用戶(hù),可以操作全部的功能。
項(xiàng)目基本設(shè)計(jì) :
★ 架構(gòu)設(shè)計(jì)
整體框架、模塊劃分
模塊劃分:用戶(hù)、圖書(shū)、進(jìn)貨、銷(xiāo)售和庫(kù)存5個(gè)模塊
★ 系統(tǒng)功能結(jié)構(gòu)設(shè)計(jì)
每個(gè)功能模塊的具體功能子模塊
★ 數(shù)據(jù)庫(kù)設(shè)計(jì)
項(xiàng)目框架實(shí)現(xiàn):分模塊、分層、分包、構(gòu)建應(yīng)用程序
1、用戶(hù)管理(User.txt)
說(shuō)明:其中的type為int類(lèi)型,用來(lái)表示操作用戶(hù)的類(lèi)型。
1——表示為admin,可以進(jìn)行全部操作
2——表示為能操作圖書(shū)模塊的人員
3——表示為能操作進(jìn)貨模塊的人員
4——表示為能操作銷(xiāo)售模塊的人員
5——表示為能操作庫(kù)存模塊的人員
2、圖書(shū)管理(Book.txt)
3、進(jìn)貨管理(InMain.txt)
4、進(jìn)貨明細(xì)管理(InDetail.txt)
5、銷(xiāo)售管理(OutMain.txt)
6、銷(xiāo)售明細(xì)管理(OutDetail.txt)
7、庫(kù)存管理(Stock.txt)
項(xiàng)目分包
第一層:按照模塊分
用戶(hù)模塊(user)、
圖書(shū)(book)、
進(jìn)貨(in)、
銷(xiāo)售(out)、
庫(kù)存(store)
第二層:按照三層模式分
表現(xiàn)層(ui)、邏輯層(business) 和 數(shù)據(jù)層(dao)
通常還要增加一個(gè)值對(duì)象層(vo)
第三層:按照層內(nèi)劃分去分
視具體情況而定,如business和dao內(nèi)還要再采用鐵三角的形式建子包,而ui和vo則不需要再劃分子包)。
項(xiàng)目分層思想:
未完善,請(qǐng)繼續(xù)關(guān)注本系列(二)
下面為部分代碼:(util里面的一個(gè)公共類(lèi))
cn.hncu.bookStore.util
FileIoUtil.java:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
|
package cn.hncu.bookStore.util; import java.io.File; import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.IOException; import java.io.ObjectInputStream; import java.io.ObjectOutputStream; import java.util.ArrayList; import java.util.List; import javax.swing.JOptionPane; /** * 用戶(hù)的公用數(shù)據(jù)讀取寫(xiě)入類(lèi) * @author 陳浩翔 * * @version 1.0 */ public class FileIoUtil { public FileIoUtil() { } /** * 從數(shù)據(jù)庫(kù)中讀取所有的數(shù)據(jù)并返回出來(lái) * * @param fileName(數(shù)據(jù)表對(duì)應(yīng)的文件名字) * @param ee(傳遞過(guò)來(lái)的泛型的類(lèi)型!) * @return 所有表的記錄! */ @SuppressWarnings ( "unchecked" ) //壓警告 public static <E> List<E> readFormFile(String fileName,E ee){ List<E> list = new ArrayList<E>(); final File file = new File(fileName); ObjectInputStream in = null ; if (!file.exists()){ JOptionPane.showMessageDialog( null , "數(shù)據(jù)表不存在!" ); return list; } try { in = new ObjectInputStream( new FileInputStream(fileName)); try { list = (List<E>) in.readObject(); } catch (ClassNotFoundException e) { e.printStackTrace(); } } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } finally { if (in!= null ){ try { in.close(); } catch (IOException e) { throw new RuntimeException( "數(shù)據(jù)庫(kù)關(guān)閉失敗" ); } } } return list; } /** * 寫(xiě)入一個(gè)list集合進(jìn)入數(shù)據(jù)文件fileName * * @param list(需要存儲(chǔ)的數(shù)據(jù)集合) * @param fileName(寫(xiě)入到哪個(gè)文件的文件名字) */ public static void write2file(List<Object> list, String fileName){ ObjectOutputStream out = null ; try { out = new ObjectOutputStream( new FileOutputStream(fileName)); out.writeObject(list); } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } finally { if (out!= null ){ try { out.close(); } catch (IOException e) { throw new RuntimeException( "數(shù)據(jù)庫(kù)關(guān)閉失敗!" ); } } } } } |
封裝的用戶(hù)數(shù)據(jù):
cn.hncu.bookStore.user.vo;
UserModel.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
|
package cn.hncu.bookStore.user.vo; /** * @author 陳浩翔 * @version 1.0 * * <br/> * 用于保存用戶(hù)信息的值對(duì)象<br/> * 1、可序列化<br/> * 2、私有化所有變量成員,補(bǔ)setter-getters方法<br/> * 3、寫(xiě)equals和hashCode方法----用主鍵(uuid)唯一標(biāo)識(shí)碼<br/> * 4、toString方法<br/> * 5,空參構(gòu)造方法<br/> */ public class UserModel { private String uuid; //用戶(hù)唯一標(biāo)識(shí)碼 private String name; //用戶(hù)名 private int type; //用戶(hù)類(lèi)型 private String pwd; //用戶(hù)密碼 public UserModel() { } /** * 功能:得到uuid-用戶(hù)唯一的標(biāo)識(shí)碼 * * @return 返回uuid-用戶(hù)唯一的標(biāo)識(shí)碼 */ public String getUuid() { return uuid; } /** * 功能:設(shè)置uuid-用戶(hù)唯一的標(biāo)識(shí)碼 * @param uuid-用戶(hù)唯一的標(biāo)識(shí)碼-String型參數(shù) */ public void setUuid(String uuid) { this .uuid = uuid; } /** * 功能:得到用戶(hù)的用戶(hù)名 * @return---name-用戶(hù)名 */ public String getName() { return name; } /** * 功能:設(shè)置用戶(hù)的用戶(hù)名 * * @param name--用戶(hù)設(shè)置的用戶(hù)名,String型參數(shù) */ public void setName(String name) { this .name = name; } /** * 功能:得到用戶(hù)的類(lèi)型: * 1——表示為admin,可以進(jìn)行全部操作 * 2——表示為能操作圖書(shū)模塊的人員 * 3——表示為能操作進(jìn)貨模塊的人員 * 4——表示為能操作銷(xiāo)售模塊的人員 * 5——表示為能操作庫(kù)存模塊的人員 * @return 用戶(hù)的類(lèi)型 */ public int getType() { return type; } /** * 功能:設(shè)置用戶(hù)的類(lèi)型: * 1——表示為admin,可以進(jìn)行全部操作 * 2——表示為能操作圖書(shū)模塊的人員 * 3——表示為能操作進(jìn)貨模塊的人員 * 4——表示為能操作銷(xiāo)售模塊的人員 * 5——表示為能操作庫(kù)存模塊的人員 * @param type--用戶(hù)的類(lèi)型-int型參數(shù) */ public void setType( int type) { this .type = type; } /** *功能:得到用戶(hù)的密碼 * @return String型,用戶(hù)的密碼 */ public String getPwd() { return pwd; } /** * 功能:設(shè)置用戶(hù)的密碼 * @param pwd--String型參數(shù) */ public void setPwd(String pwd) { this .pwd = pwd; } @Override public int hashCode() { final int prime = 31 ; int result = 1 ; result = prime * result + ((uuid == null ) ? 0 : uuid.hashCode()); return result; } @Override public boolean equals(Object obj) { if ( this == obj) return true ; if (obj == null ) return false ; if (getClass() != obj.getClass()) return false ; UserModel other = (UserModel) obj; if (uuid == null ) { if (other.uuid != null ) return false ; } else if (!uuid.equals(other.uuid)) return false ; return true ; } @Override public String toString() { return "UserModel [uuid=" + uuid + ", name=" + name + ", type=" + type + ", pwd=" + pwd + "]" ; } } |
封裝的用戶(hù)查詢(xún)數(shù)據(jù):
cn.hncu.bookStore.user.vo;
UserQueryModel.java
1
2
3
4
|
package cn.hncu.bookStore.user.vo; public class UserQueryModel extends UserModel{ } |
雖然這個(gè)類(lèi)什么都沒(méi)有,就只是繼承了UserModel,但還是必須寫(xiě),這是大家都遵守的java編寫(xiě)規(guī)范!
用戶(hù)Dao(數(shù)據(jù)層):(接口)
cn.hncu.bookStore.user.dao.dao;
UserDao.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
|
package cn.hncu.bookStore.user.dao.dao; import java.util.List; import cn.hncu.bookStore.user.vo.UserModel; import cn.hncu.bookStore.user.vo.UserQueryModel; /** * * @author 陳浩翔 * * @version 1.0 * 用戶(hù)模塊的數(shù)據(jù)層接口 */ public interface UserDao { /** * 功能:創(chuàng)建一個(gè)用戶(hù) * * @param userModel---將要?jiǎng)?chuàng)建的用戶(hù)數(shù)據(jù) * @return---true表示創(chuàng)建成功,false表示創(chuàng)建失敗 */ public boolean create(UserModel user); /** * 功能:刪除一個(gè)用戶(hù) * * @param uuid---用戶(hù)唯一的標(biāo)識(shí)碼,每個(gè)用戶(hù)都不會(huì)相同 * @return---true表示刪除成功,false表示刪除失敗 */ public boolean delete(String uuid); /** * 功能:修改用戶(hù)數(shù)據(jù)資料 * * @param user---需要修改的用戶(hù)數(shù)據(jù)參數(shù)名 * @return 返回true-表示修改成功了,返回false-表示修改失敗 */ public boolean update(UserModel user); /** * 功能:得到所有的用戶(hù)數(shù)據(jù) * * @return---一個(gè)UserModel集合,也就是用戶(hù)的數(shù)據(jù) */ public List<UserModel> getAll(); /** * 功能:按照一定的查找條件進(jìn)行查找, * <br/> * 把滿足查找條件的用戶(hù)數(shù)據(jù)返回。 * * @param uqm---被封裝的查找條件 * @return---滿足查找條件的用戶(hù)數(shù)據(jù)集合 */ public List<UserModel> getbyCondition(UserQueryModel uqm); /** * 功能:得到一個(gè)確定的用戶(hù)的數(shù)據(jù)資料 * * @param uuid---用戶(hù)唯一標(biāo)識(shí)碼 * @return ---返回按這個(gè)唯一標(biāo)識(shí)碼找到的用戶(hù)數(shù)據(jù) */ public UserModel getSingle(String uuid); } |
以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持服務(wù)器之家。
原文鏈接:http://blog.csdn.net/qq_26525215/article/details/51073546