Bookstore management system:
Project Exercise Objectives:
1. Basic analysis of Java applications
2. Cultivate the basic ideas of object-oriented programming
3. Comprehensive application of basic Java design patterns
4. Master the basic design of layering and interfaces
5. Build a reasonable Java application package structure
6. Knowledge learned by comprehensive application of JSE
7. Use collection framework rationally in application
8. Comprehensive use of common components of swing in applications
9. Basic performance layer implementation mechanism
10. Basic operations of IO streams and files
11. Develop good Java programming habits
12. Cultivate the ability to debug Java programs and cultivate the ability to correct errors
Project functional requirements:
1. Can operate user registration, modify basic information, delete and query.
2. Can add, delete, modify and query the basic information of the book.
3. You can fill out the purchase form. A purchase form contains multiple specific purchase information. The purchased books must be already available in the book management; while purchasing, modifying the inventory volume of the corresponding books in the inventory.
4. You can fill out the sales form. A sales form contains multiple specific sales information. The books sold must be already in the book management, and the sales quantity cannot exceed the current inventory quantity; while selling, modify the inventory volume of the corresponding books in the inventory.
5. You can view the inventory details and find the inventory value of specific books according to the conditions.
6. Simplify the permissions and implement fixed permission control. The user is divided into personnel with different operating permissions according to the module, and a special admin user can operate all functions.
Basic project design:
★ Overall framework of architecture design, module division: 5 modules: user, book, purchase, sales and inventory
★ System functional structure design specific functional submodules of each functional module
★ Database design project framework implementation: module, layer, subcontract, and build applications
1. User Management (User.txt)
Note: The type is int type, which is used to represent the type of the operator.
1 - Denoted as admin, all operations can be performed
2--Denoted as a person who can operate the book module
3 - Expressed as a person who can operate the purchase module
4 - Expressed as a person who can operate sales modules
5 - Expressed as a person who can operate inventory modules
2. Book Management (Book.txt)
3. Purchase Management (InMain.txt)
4. Purchase details management (InDetail.txt)
5. Sales Management (OutMain.txt)
6. Sales Detail Management (OutDetail.txt)
7. Inventory Management (Stock.txt)
Project subcontract
The first layer: user module (user) according to the module
Books (books),
Purchase (in),
Sales (out),
Inventory (store)
The second layer: according to the three-layer mode, it is divided into presentation layer (ui), logic layer (business) and data layer (dao)
Usually, a value object layer (vo) needs to be added
The third layer: Depend on the specific situation according to the division within the layer. For example, the sub-packages must be built in the form of an iron triangle, while the ui and vo do not need to be divided into the sub-packages).
Project stratification ideas:
Not perfected, please continue to pay attention to this series (II)
The following is part of the code: (a public class in util)
cn.hncu.bookStore.util
FileIoUtil.java:
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;/** * User public data read and write class* @author Chen Haoxiang* * @version 1.0 */public class FileIoUtil { public FileIoUtil() { } /** * Read all data from the database and return it* * @param fileName(file name corresponding to the data table) * @param ee(type of the passed generic!) * @return Records of all tables! */ @SuppressWarnings("unchecked")//Press warning 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, "The data table does not exist!"); 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("Database close failed"); } } } return list; } /** * Write a list collection into the data file fileName * * @param list (the data collection that needs to be stored) * @param fileName (the file name to which file is written) */ 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("Database close failed!"); } } } } } } } }}Encapsulated user data:
cn.hncu.bookStore.user.vo;
UserModel.java
package cn.hncu.bookStore.user.vo;/** * @author Chen Haoxiang* @version 1.0 * * <br/> * Value object used to save user information<br/> * 1. Serialize<br/> * 2. Privatize all variable members and supplement setter-getters method<br/> * 3. Write equals and hashCode method---Use the primary key (uuid) unique identification code<br/> * 4. toString method<br/> * 5. Empty parameter construction method<br/> */public class UserModel { private String uuid;//user unique identification code private String name;//user name private int type;//user type private String pwd;//User password public UserModel() { } /** * Function: Get uuid-user unique identification code* * @return Return uuid-user unique identification code*/ public String getUuid() { return uuid; } /** * Function: Set uuid-user unique identification code* @param uuid-user unique identification code-String parameter*/ public void setUuid(String uuid) { this.uuid = uuid; } /** * Function: Get the user's username* @return---name-user name*/ public String getName() { return name; } /** * Function: Get the user's username* @return--name-user name*/ public String getName() { return name; } /** * Function: Set the user name* * @param name--user name set by the user, String type parameter*/ public void setName(String name) { this.name = name; } /** * Function: Get the user type: * 1― represents admin, and all operations can be performed* 2― represents the person who can operate the book module* 3― represents the person who can operate the purchase module* 4― represents the person who can operate the sales module* 5― represents the person who can operate the inventory module* @return User type*/ public int getType() { return type; } /** * Function: Set the user type: * 1― represents the person who can operate the book module* 2― represents the person who can operate the book module* 3―Denoted as a person who can operate the purchase module* 4―Denoted as a person who can operate the sales module* 5―Denoted as a person who can operate the inventory module* @param type-user's type-int type parameter*/ public void setType(int type) { this.type = type; } /** *Function: Get the user's password* @return String type, user's password*/ public String getPwd() { return pwd; } /** *Function: Set the user's password* @param pwd--String type parameter*/ 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 + "]"; }} Encapsulated user query data:
cn.hncu.bookStore.user.vo;
UserQueryModel.java
package cn.hncu.bookStore.user.vo;public class UserQueryModel extends UserModel{ }Although this class has nothing, it just inherits the UserModel, it still has to be written. This is the Java writing specification that everyone abides by!
User Dao (data layer): (interface)
cn.hncu.bookStore.user.dao.dao;
UserDao.java
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 Chen Haoxiang* * @version 1.0 * Data layer interface of user module*/public interface UserDao { /** * Function: Create a user* * @param userModel---user data to be created* @return--true means creation successful, false means creation failed*/ public boolean create(UserModel user); /** * Function: Delete a user* * @param uuid---User's unique identification code, each user will not be the same* @return---true means the deletion is successful, false means the deletion fails*/ public boolean delete(String uuid); /** * Function: Modify user data* * @param user---User data parameter name that needs to be modified* @return Return true- indicates that the modification is successful, return false- indicates that the modification has failed*/ public boolean update(UserModel user); /** * Function: Get all user data* * @return---A UserModel collection, that is, the user's data*/ public List<UserModel> getAll(); /** * Function: Search according to certain search conditions, * <br/> * Return user data that meets the search conditions. * * @param uqm---encapsulated search conditions* @return----User data set that meets the search conditions*/ public List<UserModel> getbyCondition(UserQueryModel uqm); /** * Function: Get a certain user data* * @param uuid---User unique identification code* @return ---Return the user data found according to this unique identification code*/ public UserModel getSingle(String uuid);}The above is all the content of this article. I hope it will be helpful to everyone's learning and I hope everyone will support Wulin.com more.