服裝管理系統

HW*發表於2020-12-20

entity實體(Clothes)

public class Clothes {
        /**
         *樣式
         */
        private String style;

        /**
         * 尺碼
         */
        private Integer size;

        /**
         * 顏色
         */
        private String colour;

        /**
         * 數量
         */
        private Integer quantity;
    /**Clothes初始化所有引數的構造器
     *  * @param style
     *  * @param size
     *  * @param colour
     *  * @param quantity
     */
    public Clothes(String style, Integer size,
                String colour, Integer quantity){
        this.style = style;
        this.size = size;
        this.colour = colour;
        this.quantity = quantity;
    }
    public String getStyle() {
        return style;
    }

    public void setStyle(String style) {
        this.style = style;
    }

    public Integer getSize() {
        return size;
    }

    public void setSize(Integer size) {
        this.size = size;
    }

    public String getColour() {
        return colour;
    }

    public void setColour(String colour) {
        this.colour = colour;
    }

    public Integer getQuantity() {
        return quantity;
    }

    public void setQuantity(Integer quantity) {
        this.quantity = quantity;
    }

    @Override
    public String toString() {
        return "Clothes{" +
                "style='" + style + '\'' +
                ", size=" + size +
                ", colour='" + colour + '\'' +
                ", quantity=" + quantity +
                '}';
    }
}

entity(User)

public class User {

    /**
     * id
     */
    private Integer id;


    /**
     * 使用者名稱
     */
    private String userName;


    /**
     * 密碼
     */
    private String password;

    /**
     * 密保問題
     */
    private String question;

    /**
     * 密保答案
     */
    private String answer;

    public User(Integer id) {
        this.id = id;
    }

    /**
     * 空參構造器
     */
    public User() {

    }

    /**
     *User初始化所有引數的構造器

     * @param userName
     * @param answer
     * @param answer
     * @param question
     */
    public User(Integer id,
                String userName, String answer,
                String password, String question) {

        this.userName = userName;
        this.answer = answer;
        this.password = password;
        this.question = question;
        this.id = id;
    }


    public String getUserName() {
        return userName;
    }

    public void setUserName(String userName) {
        this.userName = userName;
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    public String getQuestion() {
        return question;
    }

    public void setQuestion(String question) {
        this.question = question;
    }

    public String getAnswer() {
        return answer;
    }

    public void setAnswer(String answer) {
        this.answer = answer;
    }

    public Integer getId() {
        return id;
    }

    public void setId(Integer id) {
        this.id = id;
    }

    @Override
    public String toString() {
        return "User{" +"id='"+id+
                ", userName='" + userName + '\'' +
                ", password='" + password + '\'' +
                ", question='" + question + '\'' +
                ", answer='" + answer + '\'' +
                '}';
    }
}

Dao(Clothes)介面

import studio.lemon.clothessystem.entity.Clothes;

import java.io.IOException;
import java.util.List;

/**
 * @Author: Lemon
 * @Date: 2020/12/15 21:23
 */
public interface IClothesDao {
    /**
     * 增加服裝ClothesDao
     * @param clothes
     * @return boolean
     */
    boolean insertClothesDao(Clothes clothes);

    /**
     * 根據服裝型別style刪除服裝資訊
     * @param style
     * @return boolean
     */
    boolean deleteClothesDao(String style);
    /**
     * 根據使用者id更改服裝資訊
     * @param id
     * @return boolean
     */
    boolean updateClothesDao(Integer id);
    /**
     * 根據服裝型別style查詢服裝資訊ClothesDao
     * @param style
     * @return List<Clothes>
     */
    List<Clothes> selectClothesByIdDao(String style) ;
}
``

``

Dao(Clothes)實現

import studio.lemon.clothessystem.dao.IClothesDao;
import studio.lemon.clothessystem.entity.Clothes;
import java.io.*;
import java.util.ArrayList;
import java.util.List;

public class ClothesDaoImpl implements IClothesDao {
    /**
     * 增加服裝資訊ClothesDao
     * @param clothes
     * @return boolean
     */
    @Override
    public boolean insertClothesDao(Clothes clothes)  {
        BufferedWriter bufferedWriter = null;
        try {
            bufferedWriter = new BufferedWriter(new FileWriter("ClothesSystem\\Clothes.txt"));
            String returnString=String.format("%s,%s,%s,%s",clothes.getColour(),clothes.getQuantity(),clothes.getSize(),clothes.getStyle());
            bufferedWriter.write(returnString);
            bufferedWriter.newLine();
            bufferedWriter.close();
            return true;
        } catch (IOException e) {

            return false;
        }
    }


    /**
     * 根據服裝型別style刪除服裝資訊
     * @param style
     * @return boolean
     */
    @Override
    public boolean deleteClothesDao(String style) {
        BufferedReader bufferedReader = null;
        try {
            bufferedReader = new BufferedReader(new FileReader("ClothesSystem\\Clothes.txt"));
            List<Clothes> clothesList = new ArrayList<>();
            String string;
            while ((string = bufferedReader.readLine()) != null) {
                String[] dates = string.split(",");
                Clothes clothes = new Clothes(dates[0], Integer.parseInt(dates[1]), dates[2], Integer.parseInt(dates[3]));
                System.out.println(clothes);
                clothesList.add(clothes);
            }
            for (int i = 0; i <= clothesList.size() - 1; i++) {
                Clothes clothes = clothesList.get(i);
                if (clothes.getStyle().equals(style)) {
                    clothesList.remove(i);
                }
            }
            BufferedWriter bufferedWriter = new BufferedWriter(new FileWriter("ClothesSystem\\Clothes.txt"));
            for (int i = 0; i < clothesList.size(); i++) {
                Clothes clothes = clothesList.get(i);
                String returnString = String.format("%s,%s,%s,%s", clothes.getStyle(),clothes.getSize(),clothes.getQuantity(),clothes.getColour());
                bufferedWriter.write(returnString);
                bufferedWriter.newLine();
            }
            bufferedReader.close();
            bufferedWriter.close();
            return true;
        } catch (Exception e) {

            return false;
        }
    }
    /**
     * 根據使用者id更改服裝資訊
     * @param id
     * @return boolean
     */
    @Override
    public boolean updateClothesDao(Integer id) {
        BufferedReader bufferedReader = null;
        try {
            bufferedReader = new BufferedReader(new FileReader("ClothesSystem\\Clothes.txt"));
            List<Clothes> clothesList=new ArrayList<>();
            String string;
            while ((string = bufferedReader.readLine()) != null) {
                String[] dates=string.split(",");
                Clothes returnClothes=new Clothes(dates[0], Integer.parseInt(dates[1]), dates[2], Integer.parseInt(dates[3]));
                clothesList.add(returnClothes);
            }
            for (int i = 0; i <=clothesList.size()-1 ; i++) {
                Clothes clothes = clothesList.get(i);
                if (clothes.getStyle().equals(clothes.getStyle())){
                    clothesList.set(i,clothes);
                }
            }
            BufferedWriter bufferedWriter = new BufferedWriter(new FileWriter("ClothesSystem\\Clothes.txt"));
            for (int i = 0; i <clothesList.size() ; i++) {
                Clothes returnclothes=clothesList.get(i);
                String returnString=String.format("%s,%s,%s,%s",returnclothes.getColour(),returnclothes.getQuantity(),returnclothes.getSize(),returnclothes.getStyle() );
                bufferedWriter.write(returnString);
                bufferedWriter.newLine();
            }
            bufferedReader.close();
            bufferedWriter.close();
        return true;
        } catch (Exception e) {
            return false;
        }
    }
    /**
     * 根據服裝型別style查詢服裝資訊ClothesDao
     * @param style
     * @return List<Clothes>
     */
    @Override
    public List<Clothes> selectClothesByIdDao(String style)  {
        BufferedReader bufferedReader = null;
        try {
            bufferedReader = new BufferedReader(new FileReader("ClothesSystem\\Clothes.txt"));
            List<Clothes> clothesList = new ArrayList<>();
            String string;
            while ((string = bufferedReader.readLine()) != null) {
                String[] dates = string.split(",");
                if (dates[3]==style){
                    Clothes clothes = new Clothes(dates[0], Integer.parseInt(dates[1]), dates[2], Integer.parseInt(dates[3]));
                    clothesList.add(clothes);
                }
            }
            bufferedReader.close();
            return clothesList;
        } catch (Exception e) {
            return null;
        }
    }
}

Dao(User)介面

import studio.lemon.clothessystem.entity.User;
import java.io.IOException;
import java.util.List;
public interface IUserDao {

    /**
     * 增加使用者IUserDao
     * @param user
     * @return boolean
     */
    boolean insertUserDao(User user) ;

    /**
     * 根據使用者id刪除使用者IUserDao
     * @param id
     * @return boolean
     */
    boolean deleteUserDao(Integer id) ;

    /**
     * 根據使用者id更改使用者資訊IUserDao
     * @param id
     * @param user
     * @return boolean
     * @throws IOException
     */
    boolean updateUserDao(User user,Integer id) ;

    /**
     * 根據密保問題question查詢使用者資訊
     * @param question
     * @return List<User>
     */
    List<User> retrieveUserDao(String question);
}

Dao(User)實現

import studio.lemon.clothessystem.dao.IUserDao;
import studio.lemon.clothessystem.entity.User;
import java.io.*;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
public class UserDaoImpl implements IUserDao {
    /**
     * 增加使用者IUserDao
     * @param user
     * @return boolean
     */
    @Override
    public boolean insertUserDao(User user)  {
        BufferedWriter bufferedWriter = null;
        try {
            bufferedWriter = new BufferedWriter(new FileWriter("ClothesSystem\\User.txt",true));
            String returnString=String.format("%s,%s,%s,%s,%s",user.getId(),user.getUserName(),user.getPassword(),user.getQuestion(),user.getAnswer());
            bufferedWriter.write(returnString);
            bufferedWriter.newLine();
            bufferedWriter.close();
            return true;
        } catch (Exception e) {
            System.out.println("資料增加失敗");
            return false;
        }
    }
    /**
     * 根據使用者id刪除使用者IUserDao
     * @param id
     * @return boolean
     */
    @Override
    public boolean deleteUserDao(Integer id)  {
        BufferedReader bufferedReader = null;
        try {
            bufferedReader = new BufferedReader(new FileReader("ClothesSystem\\User.txt"));
            List<User> userList=new ArrayList<>();
            String string;
            while ((string=bufferedReader.readLine())!=null){
                String[] dates=string.split(",");
                User user=new User(Integer.parseInt(dates[0]),dates[1],dates[2],dates[3],dates[4]);
                System.out.println(user);
                userList.add(user);
            }
            for (int i = 0; i <=userList.size()-1 ; i++) {
                User user=userList.get(i);
                if (user.getId().equals(id)){
                    userList.remove(i);
                }
            }
            BufferedWriter bufferedWriter = new BufferedWriter(new FileWriter("ClothesSystem\\User.txt"));
            for (int i = 0; i <userList.size() ; i++) {
                User user=userList.get(i);
                String returnString=String.format("%s,%s,%s,%s,%s",user.getId(),user.getUserName(),user.getPassword(),user.getQuestion(),user.getAnswer());
                bufferedWriter.write(returnString);
                bufferedWriter.newLine();
            }
            bufferedWriter.close();
            return true;
        } catch (Exception e) {
            System.out.println("刪除失敗");
            return false;
        }
    }

    /**
     * 根據使用者id更改使用者資訊IUserDao
     * @param id
     * @return boolean
     */
    @Override
    public boolean updateUserDao(User user, Integer id)  {
        BufferedReader bufferedReader = null;
        try {
            bufferedReader = new BufferedReader(new FileReader("ClothesSystem\\User.txt"));
            List<User> userList=new ArrayList<>();
            String string;
            while ((string=bufferedReader.readLine())!=null){
                String[] dates=string.split(",");
                User returnUser=new User(Integer.parseInt(dates[0]),dates[1],dates[2],dates[3],dates[4]);
                userList.add(returnUser);
            }
            for (int i = 0; i <=userList.size()-1 ; i++) {
                User returnUser=userList.get(i);
                if (returnUser.getId().equals(id)){
                    userList.set(i,user);
                }
            }
            BufferedWriter bufferedWriter = new BufferedWriter(new FileWriter("ClothesSystem\\User.txt"));
            for (int i = 0; i <userList.size() ; i++) {
                User returnUser=userList.get(i);
                String returnString=String.format("%s,%s,%s,%s,%s",returnUser.getId(),returnUser.getUserName(),returnUser.getPassword(),returnUser.getQuestion(),returnUser.getAnswer());
                bufferedWriter.write(returnString);
                bufferedWriter.newLine();
            }
            bufferedReader.close();
            bufferedWriter.close();
            return true;
        } catch (Exception e) {
            System.out.println("更改失敗");
            return false;
        }
    }
    /**
     * 根據密保問題question查詢使用者資訊
     * @param question
     * @return List<User>
     */
    @Override
    public List<User> retrieveUserDao(String question)  {
        BufferedReader bufferedReader = null;
        try {
            bufferedReader = new BufferedReader(new FileReader("ClothesSystem\\User.txt"));
            List<User> userList=new ArrayList<>();
            String string;
            while ((string=bufferedReader.readLine())!=null){
                String[] dates=string.split(",");
                if (dates[4].equals(question)){
                    User user=new User(Integer.parseInt(dates[0]),dates[1],dates[2],dates[3],dates[4]);
                    userList.add(user);
                }
            }
            bufferedReader.close();
            return userList;
        } catch (Exception e) {
            System.out.println("資料查詢失敗");
            return null;
        }
    }
}

Service(Clothes)介面

import studio.lemon.clothessystem.entity.Clothes;

import java.io.IOException;
import java.util.List;
public interface IClothesService {
    /**
     * 增加服裝Clothesservice
     * @param clothes
     * @return booleanclothes
     */
    boolean insertClothesService(Clothes clothes);

    /**
     * 根據服裝型別style刪除服裝資訊
     * @param style
     * @return boolean
     */
    boolean deleteClothesService(String style);
    /**
     * 根據使用者id更改服裝資訊
     * @param id
     * @return boolean
     */
    boolean addClothesService(Integer id);
    /**
     * 根據服裝型別style查詢服裝資訊Clothesservice
     * @param style
     * @return List<Clothes>
     */
    List<Clothes> selectClothesByIdService(String style);
}

Service(Clothes)實現

import studio.lemon.clothessystem.dao.IClothesDao;
import studio.lemon.clothessystem.dao.impl.ClothesDaoImpl;
import studio.lemon.clothessystem.entity.Clothes;
import studio.lemon.clothessystem.service.IClothesService;

import java.io.IOException;
import java.util.List;

/**
 * @Author: Lemon
 * @Date: 2020/12/17 22:03
 */
public class ClothesServiceImpl implements IClothesService {
    /**
     * Clothes建立Dao物件
     */
    IClothesDao iClothesDao=new ClothesDaoImpl();


    /**
     * 增加服裝ClothesService
     * @param clothes
     * @return boolean
     */
    @Override
    public boolean insertClothesService( Clothes clothes) {
        List<Clothes> clothesList= iClothesDao.selectClothesByIdDao(String.valueOf(clothes.getStyle()));
       if (clothesList.size()==0){
          boolean judgment= iClothesDao.insertClothesDao(clothes);
           if (judgment){
               System.out.println("增加成功");
               return true;
           }
           return false;
       }
        return false;
    }
    /**
     * 根據服裝型別style刪除服裝資訊
     * @param style
     * @return boolean
     */
    @Override
    public boolean deleteClothesService(String style) {
      iClothesDao.deleteClothesDao(style);
        return true;
    }
    /**
     * 根據使用者id更改服裝資訊
     * @param id
     * @return boolean
     */
    @Override
    public boolean addClothesService(Integer id) {
   if (iClothesDao.updateClothesDao(id)){
       return true;
   }
        return false;
    }
    /**
     * 根據服裝型別style查詢服裝資訊ClothesService
     * @param style
     * @return List<Clothes>
     */
    @Override
    public List<Clothes> selectClothesByIdService(String style)  {
        List<Clothes> list=iClothesDao.selectClothesByIdDao("衛衣");
        for (int i = 0; i <list.size() ; i++) {
            System.out.println(list.get(i));
        }
        return null;
    }
}

Service(User)介面

import studio.lemon.clothessystem.entity.User;
import java.io.IOException;
public interface IUserService {

    /**
     * 增加使用者IUserservice
     * @param user
     * @return boolean
     */
    boolean insertUserService(User user);

    /**
     * 根據使用者id刪除使用者IUserservice
     * @param id
     * @return boolean
     */
    boolean deleteUserService(Integer id);

    /**
     * 根據使用者id更改使用者資訊IUseservice
     * @param id
     * @return boolean
     */
    boolean updateUserService(User user,Integer id);


    /**
     * 根據密保問題question找回使用者密碼password
     * @param question
     * @return boolean
     */
    boolean retrieveUserService(String question);
}

Service(User)實現

import studio.lemon.clothessystem.dao.IUserDao;
import studio.lemon.clothessystem.dao.impl.UserDaoImpl;
import studio.lemon.clothessystem.entity.User;
import studio.lemon.clothessystem.service.IUserService;

import java.io.IOException;
import java.util.List;
public class UserServiceImpl implements IUserService {
    /**
     * User建立Dao物件
     */
    IUserDao iUserDao=new UserDaoImpl();

    /**
     * 增加使用者IUserservice
     * @param user
     * @return boolean
     * @throws IOException
     */
    @Override
    public boolean insertUserService(User user)  {
        List<User> userList=iUserDao.retrieveUserDao(user.getQuestion());
        if (userList.size()==0){
            iUserDao.insertUserDao(user);
            System.out.println("使用者新增成功");
            return true;
        }
        System.out.println("使用者新增失敗");
        return false;
    }
    /**
     * 根據使用者id刪除使用者IUserservice
     * @param id
     * @return boolean
     * @throws IOException
     */
    @Override
    public boolean deleteUserService(Integer id)  {
        iUserDao.deleteUserDao(id);
        return false;
    }
    /**
     * 根據使用者id更改使用者資訊IUseservice
     * @param id
     * @return boolean
     * @throws IOException
     */
    @Override
    public boolean updateUserService(User user, Integer id)  {
        iUserDao.updateUserDao(user,id);
        return false;
    }
    /**
     * 根據密保問題question找回使用者密碼password
     * @param question
     * @return boolean
     * throws IOException
     */
    @Override
    public boolean retrieveUserService(String question)  {
        iUserDao.retrieveUserDao(question);
        return false;
    }
}

Contoller(Clother)

import studio.lemon.clothessystem.entity.Clothes;
import studio.lemon.clothessystem.service.IClothesService;
import studio.lemon.clothessystem.service.impi.ClothesServiceImpl;

import java.util.List;
public class ClothesController {
    IClothesService iClothesservice=new ClothesServiceImpl();


        /**
         * 增加服裝ClothesDao
         * @param clothes
         * @return boolean
         */
    public boolean insertClothesController(Clothes clothes) {
        return iClothesservice.insertClothesService(clothes);
    }

    /**
     * 根據服裝型別style刪除服裝資訊
     *
     * @param style
     * @return boolean
     */
    public boolean deleteClothesController(String style) {

        return iClothesservice.deleteClothesService(style);
    }

    /**
     * 根據使用者id更改服裝資訊
     * @param id
     * @return boolean
     */
    public boolean addClothesController(Integer id) {
        return iClothesservice.addClothesService(id);
    }

    /**
     * 根據服裝型別style查詢服裝資訊ClothesDao
     *
     * @param style
     * @return List<Clothes>
     */
   public List<Clothes> selectClothesController(String style) {
        return iClothesservice.selectClothesByIdService(style);
    }
    }

Contoller(User)

import studio.lemon.clothessystem.entity.User;
import studio.lemon.clothessystem.service.IUserService;
import studio.lemon.clothessystem.service.impi.UserServiceImpl;
public class UserController {
    IUserService iUserService=new UserServiceImpl();

    /**
     * 增加使用者IUserService
     * @param user
     * @return boolean
     */
   public boolean insertUserController(User user)  {
        return false;
    }
    /**
     * 根據使用者id刪除使用者IUserService
     * @param id
     * @return boolean
     */
     public boolean deleteUserController(Integer id)  {
        return false;
    }
    /**
     * 根據使用者id更改使用者資訊IUseService
     * @param id
     * @return boolean
     */
   public boolean updateUserController(User user, Integer id)  {
        return false;
    }
    /**
     * 根據密保問題question找回使用者密碼password
     * @param question
     * @return boolean
     */
   public boolean retrieveUserController(String question) {
        return false;
    }
}

Views(Clothers)

import studio.lemon.clothessystem.controller.ClothesController;
import studio.lemon.clothessystem.entity.Clothes;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.List;
public class ClothesViews {
    ClothesController clothesController=new ClothesController();
    public void insertClothes(){

        clothesController.insertClothesController(new Clothes("衛衣",2,"紅色",7));
    }
    /**
     * 服裝資訊刪除
     */

    public void deleteClothes() {
        System.out.println("歡迎進入服裝資訊刪除介面");
        System.out.println("請輸入您的賬號(id)");
        BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(System.in));
        try {
            int id = Integer.parseInt(bufferedReader.readLine());
            System.out.println(id);
            if (id < 5) {
                System.out.println("您沒有許可權");
            } else if (id > 5 && id < 10) {
                System.out.println("登陸成功" );
                System.out.println("您想刪除的服裝型別是:1、衛衣 2、帽子 3、雪地靴");

                String style = bufferedReader.readLine();
                int a=Integer.parseInt(style);
                if(a==1){
                    clothesController.deleteClothesController(style);
                    System.out.println("衛衣資訊刪除成功");
                }
                if(a==2){
                    clothesController.deleteClothesController(style);
                    System.out.println("帽子資訊刪除成功");
                }if(a==3){
                    clothesController.deleteClothesController(style);
                    System.out.println("雪地靴資訊刪除成功");
                }
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    /**
     * 更改服裝資訊
     */

    public void addClothes(){

        System.out.println("歡迎進入更改服裝資訊介面");
        System.out.println("請輸入您的賬號(id)");
        BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(System.in));
        try {
            int id = bufferedReader.read();
            if (id < 5) {
                System.out.println("您沒有許可權");
            } else if (id > 5 && id < 10) {
                System.out.println("登陸成功" +
                        "目前您只能更改衛衣的資訊");
                clothesController.addClothesController(id);
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    /**
     * 查詢服裝資訊
     */
    public void selectClothes(){
        System.out.println("您想查詢的資訊是");
        ClothesController clothesController=new ClothesController();
        System.out.println(clothesController.selectClothesController("1"));
    }
    }

View(User)

import studio.lemon.clothessystem.controller.UserController;
import studio.lemon.clothessystem.entity.User;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class UserVies {
    UserController userController=new  UserController();

    /**
     * 刪除使用者資訊
     */
    public void deleteUser() {
        System.out.println("歡迎進入使用者資訊刪除介面");
        BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(System.in));
        int id = 0;
        try {
            id = bufferedReader.read();
            userController.deleteUserController(id);
            System.out.println("您已刪除成功");
        } catch (IOException e) {
            e.printStackTrace();
        }
    }/**
     * 增加使用者IUserService
     */
public void insertUser(){
    System.out.println("歡迎進入使用者資訊增加介面,請輸入您的id");
    BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(System.in));
    int id = 0;
    try {
        id = bufferedReader.read();
        userController.insertUserController(new User(id));
    } catch (IOException e) {
        e.printStackTrace();
    }
}
public void updateUser(){
    System.out.println("歡迎進入使用者資訊更改介面");
    BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(System.in));
    int id = 0;
    try {
        id = bufferedReader.read();
        userController.updateUserController(new User(id),id);
        System.out.println("您已修改成功");
    } catch (IOException e) {
        e.printStackTrace();
    }
}
}

CView

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
public class CView {
    UserVies userVies=new UserVies();
    ClothesViews clothesViews=new ClothesViews();
    BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(System.in));
    String m;

    public void CL(){
        try {
        System.out.println("歡迎進入服裝管理系統,請先註冊");
        userVies.insertUser();
        System.out.println("你已註冊成功,可以檢視資訊");
        clothesViews.selectClothes();
        System.out.println("請問您是否要刪除服裝資訊     1 是   2否");
            m = bufferedReader.readLine();
        switch (Integer.parseInt(m)){
            case 1:
                if (m.equals("1")){
                clothesViews.deleteClothes();
                }
            case 2:
        System.out.println("請問您是否要增加服裝資訊   1 是   2 否");
                m = bufferedReader.readLine();
                if (m.equals("1")){
                    clothesViews.addClothes();
                    System.out.println("增加成功");
                }
                break;
            default:
                System.out.println("輸入指令異常");
                break;
        }
    } catch (IOException e) {
        e.printStackTrace();
    }
}
}

Utils Create

import java.io.IOException;
public class Create {
    public static void main(String[] args) throws IOException {
        CreateFileName createFileName=new CreateFileName();
        CreatePathName createPathName=new CreatePathName();
        createPathName.create("ClothesSystem");
        createFileName.create("ClothesSystem\\User.txt");
        createFileName.create("ClothesSystem\\Clothes.txt");
    }
}

Utils CreateFileName

import java.io.File;
import java.io.IOException;
public class CreateFileName {
    //建立檔案
    public boolean create(String filename) throws IOException {
        File file = new File(filename);
        file.createNewFile();
        if (file.exists()) {
            return false;
        }
        if (file.createNewFile()) {
            return true;
        } else {
            return false;
        }
    }
}

Utils

import java.io.File;
import java.io.IOException;
public class CreatePathName {

    //建立目錄
    public boolean create(String Filename) throws IOException {
        File file = new File(Filename);
        if (file.exists()) {
            return false;
        }
        if (!Filename.endsWith(File.separator)) {
            Filename = Filename + File.separator;
        }
        if (file.mkdir()) {
            return true;
        } else {
            return false;
        }
    }
}

相關文章