Java-standalone bookstore Management System (Series 1)

Source: Internet
Author: User

Java-standalone bookstore Management System (Series 1)
Bookstore management system:

Project exercise objectives:
1. Basic Analysis of Java applications
2. Cultivate the basic idea of Object-Oriented Programming
3. Integrated Application of Java Basic Design Patterns
4. master the basic design of layers and interfaces
5. Build a reasonable Java application package structure
6. Apply the knowledge learned by JSE comprehensively
7. Rational Use of the Collection framework in applications
8. Use common swing components in applications
9. Basic implementation mechanism of the Presentation Layer
10. Basic operations on IO streams and files
11. cultivate good Java programming habits
12. cultivate the ability to debug Java programs and the ability to correct errors

Project Functional requirements:
1. Users can register, modify, delete, and query basic information.
2. You can add, delete, modify, and query basic information of a book.
3. You can enter the purchase order. One Purchase Order contains multiple specific purchase information. The purchased books must already exist in the book management. You can modify the inventory of the corresponding books at the same time.
4. Fill in the sales form. A sales form contains multiple specific sales information. The sold books must already exist in the book management, and the sales quantity cannot exceed the current inventory quantity; modify the inventory of books corresponding to the inventory at the same time of sales.
5. You can view the inventory details and search for the inventory values of specific books according to the conditions.
6. Simplify permissions and implement fixed permission control. Users are divided into persons with different operation permissions by module. A Special admin user can perform all the operations.

Basic Project Design:
★Architecture Design
Overall framework and module division
Modules: User, book, purchase, sales and inventory modules

★System Function Structure Design
Specific function sub-modules of each function module

★Database Design
Project framework implementation: modules, layers, subcontracting, and application Construction

1、user management (user.txt)

Description: The type indicates the user type.
1 -- indicates admin. All operations can be performed.
2 -- indicates the person who can operate the book Module
3 -- indicates the personnel who can operate the purchase Module
4 -- indicates the person who can operate the sales Module
5 -- indicates the person who can operate the inventory module

2XX library management (book.txt)

3rd Goods Import Management (inmain.txt)

4、import inventory management (indetail.txt)

5、sales management (outmain.txt)

6、sales License Management (outdetail.txt)

7. Inventory Management (stock.txt)

Project subcontracting

Level 1: By Module
User Module (user ),
Books ),
Incoming (in ),
Sales (out ),
Inventory (store)

Layer 2: divided by Layer 3 mode
Presentation layer (ui), logic layer (business), and data layer (dao)
Usually add a Value Object layer (vo)

Layer 3: divided by Layer
Depending on the specific situation, for example, you need to create sub-packages in the form of iron triangle in business and dao, while the ui and vo do not need to drag sub-packages ).

Project hierarchy:

Not complete. Please stay tuned to this series (2)

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's public Data Reading and Writing class * @ author Chen haoxiang ** @ version 1.0 */public class FileIoUtil {Public FileIoUtil () {}/ *** read all data from the database and return ** @ param fileName (file name corresponding to the data table) * @ param ee (passed generic type !) * @ Return all table records! * // @ SuppressWarnings ("unchecked") // Pressure Warning public static
  
   
List
   
    
ReadFormFile (String fileName, E ee) {List
    
     
List = new ArrayList
     
      
(); 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
      
        ) 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 shutdown failed") ;}} return list ;} /*** write a list set to the data file fileName ** @ param list (the data set to be stored) * @ param fileName (the name of the file to which the data is written) */public static void write2file (List
       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 ("failed to close the database! ");}}}}}
      
     
    
   
  

Encapsulated user data:

Cn. hncu. bookStore. user. vo;
UserModel. java

Package cn. hncu. bookStore. user. vo;/*** @ author Chen haoxiang * @ version 1.0 *** value object used to save user information * 1. serializable * 2. Private all variable members, add setter-getters Method * 3. Write equals and hashCode Methods ---- use the unique ID code of the primary key (uuid) * 4. Use the toString Method * 5, empty parameter Construction Method */public class UserModel {private String uuid; // Unique User ID code private String name; // user name private int type; // user type private String pwd; // User Password public UserModel () {}/*** function: Obtain uuid-Unique User ID code ** @ return uuid-Unique User ID Code */public String getUuid () {return uuid;}/*** function: set uuid-Unique User ID * @ param uuid-Unique User ID-String parameter */public void setUuid (String uuid) {this. uuid = uuid;}/*** function: Obtain the user's username * @ return --- name-username */public String getName () {return name;}/*** function: set the user name ** @ param name -- the user name set by the user, String-type parameter */public void setName (String name) {this. name = name;}/*** function: obtains the user type: * 1 -- indicates admin. You can perform all operations * 2 -- represents a person who can operate the book module * 3 -- represents a person who can operate the purchase module * 4 -- represents a person who can operate the sales module * 5 -- represents a person who can operate the inventory. module staff * @ return user type */public int getType () {return type;}/*** function: Set the user type: * 1 -- indicates admin, you can perform all operations. For example, "2" indicates the person who can operate the book module. For example, "3" indicates the person who can operate the purchase module. For example, "4" indicates the person who can operate the sales module. For example, "5" indicates the person who can perform the operation -- person who can operate the inventory module * @ param type -- User type-int type parameter */public void setType (int type) {this. type = type;}/*** function: Obtain the user's password * @ return String type, user's password */public String getPwd () {r Eturn pwd;}/*** function: Set the user's password * @ param pwd -- String 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 does not have anything, it only inherits the UserModel, but it must be written. This is a java writing specification that everyone complies!

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 the user module */public interface UserDao {/*** function: create a user ** @ param userModel --- user data to be created * @ return --- true indicates that the creation is successful, and false indicates that the creation fails */public boolean create (UserModel user ); /*** function: delete a user ** @ param uuid --- unique ID code of the user. Each user will not be the same * @ return --- true indicates that the deletion is successful, false indicates deletion failed */public boolean delete (String uuid);/*** function: modify user data ** @ param user --- user data parameter name to be modified * @ return returns true-indicates that the modification is successful, return false-indicates that the modification failed */public boolean update (UserModel user);/*** function: Get all user data ** @ return --- A UserModel set, that is, user data */public List
  
   
GetAll ();/*** function: searches based on certain search conditions and returns user data that meets the search conditions. ** @ Param uqm --- encapsulated Search Condition * @ return --- user data set meeting search conditions */public List
   
    
GetbyCondition (UserQueryModel uqm);/*** function: obtain the user data ** @ param uuid --- Unique User ID code * @ return --- return the user data found by the unique ID code */public UserModel getSingle (String uuid );}
   
  

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.