Compare commits
2 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 507bb0797a | |||
| 126e77eec0 |
6
.project
6
.project
@@ -6,18 +6,18 @@
|
|||||||
</projects>
|
</projects>
|
||||||
<buildSpec>
|
<buildSpec>
|
||||||
<buildCommand>
|
<buildCommand>
|
||||||
<name>org.eclipse.wst.validation.validationbuilder</name>
|
<name>org.eclipse.jdt.core.javabuilder</name>
|
||||||
<arguments>
|
<arguments>
|
||||||
</arguments>
|
</arguments>
|
||||||
</buildCommand>
|
</buildCommand>
|
||||||
<buildCommand>
|
<buildCommand>
|
||||||
<name>org.eclipse.jdt.core.javabuilder</name>
|
<name>org.eclipse.wst.validation.validationbuilder</name>
|
||||||
<arguments>
|
<arguments>
|
||||||
</arguments>
|
</arguments>
|
||||||
</buildCommand>
|
</buildCommand>
|
||||||
</buildSpec>
|
</buildSpec>
|
||||||
<natures>
|
<natures>
|
||||||
<nature>org.eclipse.jdt.core.javanature</nature>
|
|
||||||
<nature>org.eclipse.wst.jsdt.core.jsNature</nature>
|
<nature>org.eclipse.wst.jsdt.core.jsNature</nature>
|
||||||
|
<nature>org.eclipse.jdt.core.javanature</nature>
|
||||||
</natures>
|
</natures>
|
||||||
</projectDescription>
|
</projectDescription>
|
||||||
|
|||||||
@@ -108,12 +108,4 @@ public abstract class BaseAccess {
|
|||||||
* @throws IOException
|
* @throws IOException
|
||||||
*/
|
*/
|
||||||
public abstract void delete(String key) throws IOException;
|
public abstract void delete(String key) throws IOException;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public List<BaseData> selectByidDepartment(String key) throws FileNotFoundException {
|
|
||||||
// TODO 自動生成されたメソッド・スタブ
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -16,27 +16,43 @@ public class DepartmentAccess extends BaseAccess{
|
|||||||
super(DEPARTMENT_FILEPATH);
|
super(DEPARTMENT_FILEPATH);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
public List<BaseData> DepSelectAll() throws FileNotFoundException {
|
||||||
//条件検索用メソッド
|
|
||||||
public List<BaseData> selectByidDepartment(String key) throws FileNotFoundException {
|
|
||||||
//全件データ
|
//全件データ
|
||||||
List<BaseData> allList = new ArrayList<>();
|
List<BaseData> allList = new ArrayList<>();
|
||||||
|
|
||||||
//取得用リスト(CSV形式)
|
//取得用リスト(CSV形式)
|
||||||
List<String> csvList = readData();
|
List<String> csvList = readData();
|
||||||
|
|
||||||
|
for (String line : csvList) {
|
||||||
|
DepartmentData department = new DepartmentData();
|
||||||
|
String[] columns = line.split(",");
|
||||||
|
department.setIdDepartment(columns[0]);
|
||||||
|
department.setNmDepartment(columns[1]);
|
||||||
|
|
||||||
|
|
||||||
|
allList.add(department);
|
||||||
|
}
|
||||||
|
return allList;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<BaseData> selectById(String key) throws FileNotFoundException {
|
||||||
|
//全件データ
|
||||||
|
List<BaseData> allList = new ArrayList<>();
|
||||||
|
|
||||||
|
//取得用リスト(CSV形式)
|
||||||
|
List<String> csvList = readData();
|
||||||
|
|
||||||
for (String line : csvList) {
|
for (String line : csvList) {
|
||||||
DepartmentData department = new DepartmentData();
|
DepartmentData department = new DepartmentData();
|
||||||
String[] columns = line.split(",");
|
String[] columns = line.split(",");
|
||||||
department.setIdDepartment(columns[0]);
|
department.setIdDepartment(columns[0]);
|
||||||
department.setNameDepartment(columns[1]);
|
department.setNmDepartment(columns[1]);
|
||||||
|
|
||||||
|
|
||||||
allList.add(department);
|
allList.add(department);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
//IDでの抽出データ
|
//IDでの抽出データ
|
||||||
List<BaseData> selectList = new ArrayList<>();
|
List<BaseData> selectList = new ArrayList<>();
|
||||||
|
|
||||||
@@ -47,34 +63,8 @@ public class DepartmentAccess extends BaseAccess{
|
|||||||
}
|
}
|
||||||
|
|
||||||
return selectList;
|
return selectList;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//全件検索用メソッド
|
|
||||||
public List<BaseData> selectByallDepartment(String key) throws FileNotFoundException {
|
|
||||||
//全件データ
|
|
||||||
List<BaseData> allList = new ArrayList<>();
|
|
||||||
|
|
||||||
//取得用リスト(CSV形式)
|
|
||||||
List<String> csvList = readData();
|
|
||||||
|
|
||||||
|
|
||||||
for (String line : csvList) {
|
|
||||||
DepartmentData department = new DepartmentData();
|
|
||||||
String[] columns = line.split(",");
|
|
||||||
department.setIdDepartment(columns[0]);
|
|
||||||
department.setNameDepartment(columns[1]);
|
|
||||||
|
|
||||||
|
|
||||||
allList.add(department);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
return allList;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void insert(BaseData data) throws IOException {
|
public void insert(BaseData data) throws IOException {
|
||||||
//CSVファイルに追記する
|
//CSVファイルに追記する
|
||||||
@@ -96,13 +86,14 @@ public class DepartmentAccess extends BaseAccess{
|
|||||||
DepartmentData department = new DepartmentData();
|
DepartmentData department = new DepartmentData();
|
||||||
String[] columns = line.split(",");
|
String[] columns = line.split(",");
|
||||||
department.setIdDepartment(columns[0]);
|
department.setIdDepartment(columns[0]);
|
||||||
department.setNameDepartment(columns[1]);
|
department.setNmDepartment(columns[1]);
|
||||||
|
|
||||||
|
|
||||||
allList.add(department);
|
allList.add(department);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (BaseData department : allList) {
|
for (BaseData department : allList) {
|
||||||
|
|
||||||
if(department.getPrimaryKeyValue().equals(updateData.getPrimaryKeyValue())) {
|
if(department.getPrimaryKeyValue().equals(updateData.getPrimaryKeyValue())) {
|
||||||
//指定されたデータとキーが一致するデータの場合、更新データを設定
|
//指定されたデータとキーが一致するデータの場合、更新データを設定
|
||||||
updatedList.add(updateData);
|
updatedList.add(updateData);
|
||||||
@@ -129,10 +120,10 @@ public class DepartmentAccess extends BaseAccess{
|
|||||||
List<String> csvList = readData();
|
List<String> csvList = readData();
|
||||||
|
|
||||||
for (String line : csvList) {
|
for (String line : csvList) {
|
||||||
DepartmentData department = new DepartmentData();
|
DepartmentData department= new DepartmentData();
|
||||||
String[] columns = line.split(",");
|
String[] columns = line.split(",");
|
||||||
department.setIdDepartment(columns[0]);
|
department.setIdDepartment(columns[0]);
|
||||||
department.setNameDepartment(columns[1]);
|
department.setNmDepartment(columns[1]);
|
||||||
|
|
||||||
|
|
||||||
allList.add(department);
|
allList.add(department);
|
||||||
@@ -147,13 +138,4 @@ public class DepartmentAccess extends BaseAccess{
|
|||||||
updateData(deletedList);
|
updateData(deletedList);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public List<BaseData> selectById(String key) throws FileNotFoundException {
|
|
||||||
// TODO 自動生成されたメソッド・スタブ
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -16,15 +16,36 @@ public class EmployeeAccess extends BaseAccess {
|
|||||||
super(EMPDATA_FILEPATH);
|
super(EMPDATA_FILEPATH);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
public List<BaseData> empSelectAll() throws FileNotFoundException {
|
||||||
//条件検索用メソッド
|
|
||||||
public List<BaseData> selectById(String key) throws FileNotFoundException {
|
|
||||||
//全件データ
|
//全件データ
|
||||||
List<BaseData> allList = new ArrayList<>();
|
List<BaseData> allList = new ArrayList<>();
|
||||||
|
|
||||||
//取得用リスト(CSV形式)
|
//取得用リスト(CSV形式)
|
||||||
List<String> csvList = readData();
|
List<String> csvList = readData();
|
||||||
|
|
||||||
|
for (String line : csvList) {
|
||||||
|
EmployeeData employee = new EmployeeData();
|
||||||
|
String[] columns = line.split(",");
|
||||||
|
employee.setIdEmployee(columns[0]);
|
||||||
|
employee.setNmEmployee(columns[1]);
|
||||||
|
employee.setKnEmployee(columns[2]);
|
||||||
|
employee.setMailAddress(columns[3]);
|
||||||
|
employee.setPassword(columns[4]);
|
||||||
|
employee.setIdDepartment(columns[5]);
|
||||||
|
|
||||||
|
allList.add(employee);
|
||||||
|
}
|
||||||
|
return allList;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<BaseData> selectById(String key) throws FileNotFoundException {
|
||||||
|
//全件データ
|
||||||
|
List<BaseData> allList = new ArrayList<>();
|
||||||
|
|
||||||
|
//取得用リスト(CSV形式)
|
||||||
|
List<String> csvList = readData();
|
||||||
|
|
||||||
for (String line : csvList) {
|
for (String line : csvList) {
|
||||||
EmployeeData employee = new EmployeeData();
|
EmployeeData employee = new EmployeeData();
|
||||||
@@ -49,36 +70,8 @@ public class EmployeeAccess extends BaseAccess {
|
|||||||
}
|
}
|
||||||
|
|
||||||
return selectList;
|
return selectList;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//全件検索用メソッド
|
|
||||||
public List<BaseData> selectByall(String key) throws FileNotFoundException {
|
|
||||||
//全件データ
|
|
||||||
List<BaseData> allList = new ArrayList<>();
|
|
||||||
|
|
||||||
//取得用リスト(CSV形式)
|
|
||||||
List<String> csvList = readData();
|
|
||||||
|
|
||||||
|
|
||||||
for (String line : csvList) {
|
|
||||||
EmployeeData employee = new EmployeeData();
|
|
||||||
String[] columns = line.split(",");
|
|
||||||
employee.setIdEmployee(columns[0]);
|
|
||||||
employee.setNmEmployee(columns[1]);
|
|
||||||
employee.setKnEmployee(columns[2]);
|
|
||||||
employee.setMailAddress(columns[3]);
|
|
||||||
employee.setPassword(columns[4]);
|
|
||||||
employee.setIdDepartment(columns[5]);
|
|
||||||
|
|
||||||
allList.add(employee);
|
|
||||||
}
|
|
||||||
|
|
||||||
return allList;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void insert(BaseData data) throws IOException {
|
public void insert(BaseData data) throws IOException {
|
||||||
//CSVファイルに追記する
|
//CSVファイルに追記する
|
||||||
@@ -157,4 +150,6 @@ public class EmployeeAccess extends BaseAccess {
|
|||||||
updateData(deletedList);
|
updateData(deletedList);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -19,5 +19,4 @@ public abstract class BaseData {
|
|||||||
*/
|
*/
|
||||||
public abstract String getPrimaryKeyValue();
|
public abstract String getPrimaryKeyValue();
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,53 +1,36 @@
|
|||||||
package com.rhizome.example.data;
|
package com.rhizome.example.data;
|
||||||
|
|
||||||
public class DepartmentData extends BaseData{
|
public class DepartmentData extends BaseData{
|
||||||
/** 部署ID */
|
/** 役職ID */
|
||||||
private String idDepartment;
|
private String idDepartment;
|
||||||
/** 部署名 */
|
/** 役職名 */
|
||||||
private String nameDepartment;
|
private String nmDepartment;
|
||||||
|
|
||||||
/**
|
|
||||||
* @return 部署ID
|
|
||||||
*/
|
|
||||||
public String getIdDepartment() {
|
public String getIdDepartment() {
|
||||||
return idDepartment;
|
return idDepartment;
|
||||||
}
|
}
|
||||||
/**
|
|
||||||
* @param idDepartment 部署ID
|
|
||||||
*/
|
|
||||||
public void setIdDepartment(String idDepartment) {
|
public void setIdDepartment(String idDepartment) {
|
||||||
this.idDepartment = idDepartment;
|
this.idDepartment = idDepartment;
|
||||||
}
|
}
|
||||||
|
public String getNmDepartment() {
|
||||||
/**
|
return nmDepartment;
|
||||||
* @return 部署名
|
|
||||||
*/
|
|
||||||
public String getNameDepartment() {
|
|
||||||
return nameDepartment;
|
|
||||||
}
|
}
|
||||||
/**
|
public void setNmDepartment(String nmDepartment) {
|
||||||
* @param nameDepartment 部署名
|
this.nmDepartment = nmDepartment;
|
||||||
*/
|
|
||||||
public void setNameDepartment(String nameDepartment) {
|
|
||||||
this.nameDepartment = nameDepartment;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
// TODO 自動生成されたメソッド・スタブ
|
return getIdDepartment() + "\t" + getNmDepartment();
|
||||||
return getIdDepartment() + "\t" + getNameDepartment();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toCSV() {
|
public String toCSV() {
|
||||||
// TODO 自動生成されたメソッド・スタブ
|
return getIdDepartment() + "," + getNmDepartment();
|
||||||
return getIdDepartment() + "," + getNameDepartment();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getPrimaryKeyValue() {
|
public String getPrimaryKeyValue() {
|
||||||
// TODO 自動生成されたメソッド・スタブ
|
return getIdDepartment();
|
||||||
return idDepartment;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,234 +0,0 @@
|
|||||||
package com.rhizome.example.main;
|
|
||||||
|
|
||||||
import java.io.FileNotFoundException;
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Scanner;
|
|
||||||
|
|
||||||
import com.rhizome.example.access.DepartmentAccess;
|
|
||||||
import com.rhizome.example.data.BaseData;
|
|
||||||
import com.rhizome.example.data.DepartmentData;
|
|
||||||
|
|
||||||
|
|
||||||
public class DepartmentMain {
|
|
||||||
static Scanner sc = new Scanner(System.in);
|
|
||||||
|
|
||||||
public static void main(String[] args) {
|
|
||||||
System.out.println("システムを開始します");
|
|
||||||
while (true) {
|
|
||||||
try {
|
|
||||||
new DepartmentMain ().dpData();
|
|
||||||
} catch (Exception e) {
|
|
||||||
System.out.println("予期せぬエラーが発生しました");
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 処理選択を行う
|
|
||||||
* @throws IOException
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
public void dpData() throws IOException {
|
|
||||||
System.out.println();
|
|
||||||
System.out.println("1:検索 2:登録 3:更新 4:削除 9:データ切り替え 0:終了");
|
|
||||||
String ope = sc.nextLine();
|
|
||||||
DepartmentMain dp = new DepartmentMain();
|
|
||||||
|
|
||||||
switch (ope) {
|
|
||||||
case "1": //検索
|
|
||||||
dpSelect();
|
|
||||||
break;
|
|
||||||
case "2": //登録
|
|
||||||
dpInsert();
|
|
||||||
break;
|
|
||||||
case "3": //更新
|
|
||||||
dpUpdate();
|
|
||||||
break;
|
|
||||||
case "4": //削除
|
|
||||||
dpDelete();
|
|
||||||
break;
|
|
||||||
case "0": //修了
|
|
||||||
System.out.println("システムを終了します");
|
|
||||||
System.exit(0);
|
|
||||||
case "9":
|
|
||||||
dp.dpData();
|
|
||||||
default:
|
|
||||||
System.out.println("指定の番号を入力してください");
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 社員ファイルから情報を検索する
|
|
||||||
*
|
|
||||||
* @throws FileNotFoundException
|
|
||||||
*/
|
|
||||||
public void dpSelect() throws FileNotFoundException {
|
|
||||||
System.out.println();
|
|
||||||
System.out.println("1:全件検索 2:条件検索");
|
|
||||||
String search = sc.nextLine();
|
|
||||||
|
|
||||||
switch(search) {
|
|
||||||
case "1": //全件検索
|
|
||||||
//DepartmentData.csvファイルに記載されている情報が一覧で表示
|
|
||||||
DepartmentAccess all = new DepartmentAccess();
|
|
||||||
List<BaseData> allList = new ArrayList<>();
|
|
||||||
allList = all.selectByallDepartment(search);
|
|
||||||
|
|
||||||
for (BaseData department : allList) {
|
|
||||||
System.out.println(department.toString());
|
|
||||||
}
|
|
||||||
|
|
||||||
break;
|
|
||||||
|
|
||||||
|
|
||||||
case "2": //条件検索
|
|
||||||
//IDの入力および入力チェック
|
|
||||||
DepartmentAccess ea = new DepartmentAccess();
|
|
||||||
List<BaseData> list;
|
|
||||||
|
|
||||||
//IDの入力および入力チェック
|
|
||||||
String id = inputCheck("ID", true);
|
|
||||||
//idに一致する社員データ取得
|
|
||||||
list = ea.selectByidDepartment(id);
|
|
||||||
|
|
||||||
if (list.size() == 0) { //取得結果が0件の場合
|
|
||||||
System.out.println("入力された値で情報がみつかりませんでした");
|
|
||||||
}
|
|
||||||
//取得結果件数分、データをタブ区切りで出力する
|
|
||||||
for (BaseData department : list) {
|
|
||||||
System.out.println(department.toString());
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
|
|
||||||
default: //1.2以外なら戻る
|
|
||||||
try {
|
|
||||||
dpData();
|
|
||||||
} catch (IOException e) {
|
|
||||||
// TODO 自動生成された catch ブロック
|
|
||||||
e.printStackTrace();
|
|
||||||
} //メインメニューへ戻る
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 社員ファイルに情報を登録する
|
|
||||||
*
|
|
||||||
* @throws IOException
|
|
||||||
*/
|
|
||||||
public void dpInsert() throws IOException {
|
|
||||||
//各項目の入力および入力チェック処理
|
|
||||||
String id = inputCheck("部署ID", true);
|
|
||||||
String name = inputCheck("部署名", false);
|
|
||||||
|
|
||||||
|
|
||||||
//社員データインスタンスを生成し、入力値を設定
|
|
||||||
DepartmentData department = new DepartmentData();
|
|
||||||
department.setIdDepartment(id);
|
|
||||||
department.setNameDepartment(name);
|
|
||||||
|
|
||||||
DepartmentAccess ea = new DepartmentAccess();
|
|
||||||
//ファイルデータ追加処理
|
|
||||||
ea.insert(department);
|
|
||||||
System.out.println("登録が完了しました");
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 社員ファイルの情報を更新する
|
|
||||||
*
|
|
||||||
* @throws IOException
|
|
||||||
*/
|
|
||||||
public void dpUpdate() throws IOException {
|
|
||||||
DepartmentAccess ea = new DepartmentAccess();
|
|
||||||
|
|
||||||
//IDの入力および入力チェック
|
|
||||||
String id = inputCheck("ID", true);
|
|
||||||
//IDの存在チェック
|
|
||||||
if (ea.selectById(id).size() == 0) {
|
|
||||||
System.out.println("入力された値で情報がみつかりませんでした");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
//各項目の入力および入力チェック処理
|
|
||||||
String name = inputCheck("部署名", false);
|
|
||||||
|
|
||||||
|
|
||||||
//社員データインスタンスを生成し、入力値を設定
|
|
||||||
DepartmentData department = new DepartmentData();
|
|
||||||
department.setIdDepartment(id);
|
|
||||||
department.setNameDepartment(name);
|
|
||||||
|
|
||||||
|
|
||||||
//ファイルデータ更新処理
|
|
||||||
ea.update(department);
|
|
||||||
System.out.println("更新が完了しました");
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 社員ファイルの情報を削除する
|
|
||||||
*
|
|
||||||
* @throws IOException
|
|
||||||
*/
|
|
||||||
public void dpDelete() throws IOException {
|
|
||||||
DepartmentAccess ea = new DepartmentAccess();
|
|
||||||
|
|
||||||
//IDの入力および入力チェック
|
|
||||||
String id = inputCheck("ID", true);
|
|
||||||
//IDの存在チェック
|
|
||||||
if (ea.selectById(id).size() == 0) {
|
|
||||||
System.out.println("入力された値で情報がみつかりませんでした");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
System.out.println("指定されたIDの情報を削除します? Y/y");
|
|
||||||
System.out.println("(Y/y以外の入力であればキャンセル)");
|
|
||||||
String yY = sc.nextLine();
|
|
||||||
if (!"y".equals(yY) && !"Y".equals(yY)) {
|
|
||||||
System.out.println("削除をキャンセルしました");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
//ファイルデータ削除処理
|
|
||||||
ea.delete(id);
|
|
||||||
System.out.println("削除が完了しました");
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 入力値を判定し、返却する
|
|
||||||
*
|
|
||||||
* @param titleName 入力項目名
|
|
||||||
* @param flg 数値チェック可否フラグ
|
|
||||||
* @return チェック済み入力値
|
|
||||||
*/
|
|
||||||
public static String inputCheck(String titleName, boolean flg) {
|
|
||||||
String str = null;
|
|
||||||
while (true) {
|
|
||||||
System.out.println(titleName + "を入力してください");
|
|
||||||
str = sc.nextLine();
|
|
||||||
if (str.trim().length() == 0) {
|
|
||||||
System.out.println(titleName + "は入力必須です。");
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
if (flg) {
|
|
||||||
if (str.trim().length() > 0) {
|
|
||||||
try {
|
|
||||||
Integer.parseInt(str);
|
|
||||||
} catch (NumberFormatException e) {
|
|
||||||
System.out.println(titleName + "は数値入力です");
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
return str;
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -2,18 +2,19 @@ package com.rhizome.example.main;
|
|||||||
|
|
||||||
import java.io.FileNotFoundException;
|
import java.io.FileNotFoundException;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Scanner;
|
import java.util.Scanner;
|
||||||
|
|
||||||
|
import com.rhizome.example.access.DepartmentAccess;
|
||||||
import com.rhizome.example.access.EmployeeAccess;
|
import com.rhizome.example.access.EmployeeAccess;
|
||||||
import com.rhizome.example.data.BaseData;
|
import com.rhizome.example.data.BaseData;
|
||||||
|
import com.rhizome.example.data.DepartmentData;
|
||||||
import com.rhizome.example.data.EmployeeData;
|
import com.rhizome.example.data.EmployeeData;
|
||||||
|
|
||||||
|
|
||||||
public class Main {
|
public class Main {
|
||||||
static Scanner sc = new Scanner(System.in);
|
static Scanner sc = new Scanner(System.in);
|
||||||
|
private boolean employeeMode = true;
|
||||||
/**
|
/**
|
||||||
* 処理開始位置
|
* 処理開始位置
|
||||||
*
|
*
|
||||||
@@ -21,9 +22,10 @@ public class Main {
|
|||||||
*/
|
*/
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
System.out.println("システムを開始します");
|
System.out.println("システムを開始します");
|
||||||
|
Main main = new Main();
|
||||||
while (true) {
|
while (true) {
|
||||||
try {
|
try {
|
||||||
new Main().start();
|
main.start();
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
System.out.println("予期せぬエラーが発生しました");
|
System.out.println("予期せぬエラーが発生しました");
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
@@ -37,63 +39,81 @@ public class Main {
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public void start() throws IOException {
|
public void start() throws IOException {
|
||||||
|
|
||||||
System.out.println();
|
System.out.println();
|
||||||
System.out.println("1:検索 2:登録 3:更新 4:削除 9:データ切り替え 0:終了");
|
System.out.println("1:検索 2:登録 3:更新 4:削除 9:データ切り替え 0:終了 "
|
||||||
|
+ "(管理対象:"
|
||||||
|
+(employeeMode ? "Employee" : "Department")
|
||||||
|
+ ")");
|
||||||
|
|
||||||
String ope = sc.nextLine();
|
String ope = sc.nextLine();
|
||||||
DepartmentMain dp = new DepartmentMain();
|
|
||||||
|
|
||||||
switch (ope) {
|
switch (ope) {
|
||||||
case "1": //検索
|
case "1": //検索
|
||||||
empSelect();
|
if(employeeMode) {
|
||||||
|
start1();
|
||||||
|
}else {
|
||||||
|
start2();
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
case "2": //登録
|
case "2": //登録
|
||||||
|
if(employeeMode) {
|
||||||
empInsert();
|
empInsert();
|
||||||
|
}else {
|
||||||
|
depInsert();
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
case "3": //更新
|
case "3": //更新
|
||||||
|
if(employeeMode) {
|
||||||
empUpdate();
|
empUpdate();
|
||||||
|
}else {
|
||||||
|
depUpdate();
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
case "4": //削除
|
case "4": //削除
|
||||||
|
if(employeeMode) {
|
||||||
empDelete();
|
empDelete();
|
||||||
|
}else {
|
||||||
|
depDelete();
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
case "0": //修了
|
case "9": //データ切り替え
|
||||||
|
employeeMode = !employeeMode;
|
||||||
|
break;
|
||||||
|
case "0": //終了
|
||||||
System.out.println("システムを終了します");
|
System.out.println("システムを終了します");
|
||||||
System.exit(0);
|
System.exit(0);
|
||||||
case "9":
|
|
||||||
dp.dpData();
|
|
||||||
break;
|
|
||||||
default:
|
default:
|
||||||
System.out.println("指定の番号を入力してください");
|
System.out.println("指定の番号を入力してください");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 社員ファイルから情報を検索する
|
* 社員ファイルから情報を検索する
|
||||||
*
|
*
|
||||||
* @throws FileNotFoundException
|
* @throws FileNotFoundException
|
||||||
*/
|
*/
|
||||||
public void empSelect() throws FileNotFoundException {
|
|
||||||
|
public void start1() throws IOException {
|
||||||
System.out.println();
|
System.out.println();
|
||||||
System.out.println("1:全件検索 2:条件検索");
|
System.out.println("1:全検索 2:条件検索");
|
||||||
String search = sc.nextLine();
|
String ope = sc.nextLine();
|
||||||
|
|
||||||
switch(search) {
|
|
||||||
case "1": //全件検索
|
|
||||||
//EmployeeData.csvファイルに記載されている情報が一覧で表示
|
|
||||||
EmployeeAccess all = new EmployeeAccess();
|
|
||||||
List<BaseData> allList = new ArrayList<>();
|
|
||||||
allList = all.selectByall(search);
|
|
||||||
|
|
||||||
for (BaseData employee : allList) {
|
|
||||||
System.out.println(employee.toString());
|
|
||||||
}
|
|
||||||
|
|
||||||
|
switch (ope) {
|
||||||
|
case "1": //全検索
|
||||||
|
//全出力
|
||||||
|
empSelectAll();
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
|
||||||
case "2": //条件検索
|
case "2": //条件検索
|
||||||
//IDの入力および入力チェック
|
empSelect();
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
//戻る
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
public void empSelect() throws FileNotFoundException {
|
||||||
EmployeeAccess ea = new EmployeeAccess();
|
EmployeeAccess ea = new EmployeeAccess();
|
||||||
List<BaseData> list;
|
List<BaseData> list;
|
||||||
|
|
||||||
@@ -105,25 +125,13 @@ public class Main {
|
|||||||
if (list.size() == 0) { //取得結果が0件の場合
|
if (list.size() == 0) { //取得結果が0件の場合
|
||||||
System.out.println("入力された値で情報がみつかりませんでした");
|
System.out.println("入力された値で情報がみつかりませんでした");
|
||||||
}
|
}
|
||||||
|
|
||||||
//取得結果件数分、データをタブ区切りで出力する
|
//取得結果件数分、データをタブ区切りで出力する
|
||||||
for (BaseData employee : list) {
|
for (BaseData employee : list) {
|
||||||
System.out.println(employee.toString());
|
System.out.println(employee.toString());
|
||||||
}
|
}
|
||||||
break;
|
|
||||||
|
|
||||||
default: //1.2以外なら戻る
|
|
||||||
try {
|
|
||||||
start();
|
|
||||||
} catch (IOException e) {
|
|
||||||
// TODO 自動生成された catch ブロック
|
|
||||||
e.printStackTrace();
|
|
||||||
} //メインメニューへ戻る
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 社員ファイルに情報を登録する
|
* 社員ファイルに情報を登録する
|
||||||
*
|
*
|
||||||
@@ -248,6 +256,141 @@ public class Main {
|
|||||||
return str;
|
return str;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void empSelectAll() throws FileNotFoundException {
|
||||||
|
|
||||||
|
EmployeeAccess ea = new EmployeeAccess();
|
||||||
|
|
||||||
|
List<BaseData> list = ea.empSelectAll();
|
||||||
|
|
||||||
|
for (BaseData employee : list) {
|
||||||
|
System.out.println(employee.toString());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
//Department
|
||||||
|
public void start2() throws IOException {
|
||||||
|
System.out.println();
|
||||||
|
System.out.println("1:全検索 2:条件検索");
|
||||||
|
String ope = sc.nextLine();
|
||||||
|
|
||||||
|
switch (ope) {
|
||||||
|
case "1": //全検索
|
||||||
|
//全出力
|
||||||
|
DepSelectAll();
|
||||||
|
break;
|
||||||
|
case "2": //条件検索
|
||||||
|
depSelect();
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
//戻る
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
public void depSelect() throws FileNotFoundException {
|
||||||
|
DepartmentAccess ea = new DepartmentAccess();
|
||||||
|
List<BaseData> list;
|
||||||
|
|
||||||
|
//IDの入力および入力チェック
|
||||||
|
String id = inputCheck("ID", true);
|
||||||
|
//idに一致する社員データ取得
|
||||||
|
list = ea.selectById(id);
|
||||||
|
|
||||||
|
if (list.size() == 0) { //取得結果が0件の場合
|
||||||
|
System.out.println("入力された値で情報がみつかりませんでした");
|
||||||
|
}
|
||||||
|
|
||||||
|
//取得結果件数分、データをタブ区切りで出力する
|
||||||
|
for (BaseData department : list) {
|
||||||
|
System.out.println(department.toString());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 社員ファイルに情報を登録する
|
||||||
|
*
|
||||||
|
* @throws IOException
|
||||||
|
*/
|
||||||
|
public void depInsert() throws IOException {
|
||||||
|
//各項目の入力および入力チェック処理
|
||||||
|
String depId = inputCheck("部署ID", true);
|
||||||
|
String depNm = inputCheck("部署名",false);
|
||||||
|
|
||||||
|
//社員データインスタンスを生成し、入力値を設定
|
||||||
|
DepartmentData department = new DepartmentData();
|
||||||
|
department.setIdDepartment(depId);
|
||||||
|
department.setNmDepartment(depNm);
|
||||||
|
|
||||||
|
DepartmentAccess ea = new DepartmentAccess();
|
||||||
|
//ファイルデータ追加処理
|
||||||
|
ea.insert(department);
|
||||||
|
System.out.println("登録が完了しました");
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 社員ファイルの情報を更新する
|
||||||
|
*
|
||||||
|
* @throws IOException
|
||||||
|
*/
|
||||||
|
public void depUpdate() throws IOException {
|
||||||
|
DepartmentAccess ea = new DepartmentAccess();
|
||||||
|
|
||||||
|
//IDの入力および入力チェック
|
||||||
|
String id = inputCheck("ID", true);
|
||||||
|
//IDの存在チェック
|
||||||
|
if (ea.selectById(id).size() == 0) {
|
||||||
|
System.out.println("入力された値で情報がみつかりませんでした");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
//各項目の入力および入力チェック処理
|
||||||
|
String depId = inputCheck("部署ID", true);
|
||||||
|
String depNm = inputCheck("部署名", false);
|
||||||
|
|
||||||
|
//社員データインスタンスを生成し、入力値を設定
|
||||||
|
DepartmentData department = new DepartmentData();
|
||||||
|
department.setIdDepartment(depId);
|
||||||
|
department.setNmDepartment(depNm);
|
||||||
|
//ファイルデータ更新処理
|
||||||
|
ea.update(department);
|
||||||
|
System.out.println("更新が完了しました");
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 社員ファイルの情報を削除する
|
||||||
|
*
|
||||||
|
* @throws IOException
|
||||||
|
*/
|
||||||
|
public void depDelete() throws IOException {
|
||||||
|
DepartmentAccess ea = new DepartmentAccess();
|
||||||
|
|
||||||
|
//IDの入力および入力チェック
|
||||||
|
String id = inputCheck("ID", true);
|
||||||
|
//IDの存在チェック
|
||||||
|
if (ea.selectById(id).size() == 0) {
|
||||||
|
System.out.println("入力された値で情報がみつかりませんでした");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
System.out.println("指定されたIDの情報を削除します? Y/y");
|
||||||
|
System.out.println("(Y/y以外の入力であればキャンセル)");
|
||||||
|
String yY = sc.nextLine();
|
||||||
|
if (!"y".equals(yY) && !"Y".equals(yY)) {
|
||||||
|
System.out.println("削除をキャンセルしました");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
//ファイルデータ削除処理
|
||||||
|
ea.delete(id);
|
||||||
|
System.out.println("削除が完了しました");
|
||||||
|
}
|
||||||
|
|
||||||
|
public void DepSelectAll()throws FileNotFoundException{
|
||||||
|
DepartmentAccess da = new DepartmentAccess();
|
||||||
|
|
||||||
|
List<BaseData> list = da.DepSelectAll();
|
||||||
|
|
||||||
|
for (BaseData department : list) {
|
||||||
|
System.out.println(department.toString());
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user