diff --git a/.classpath b/.classpath
new file mode 100644
index 0000000..31d6a44
--- /dev/null
+++ b/.classpath
@@ -0,0 +1,7 @@
+
+
+
+
+
+
+
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..ae3c172
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1 @@
+/bin/
diff --git a/.project b/.project
new file mode 100644
index 0000000..a0dc2ef
--- /dev/null
+++ b/.project
@@ -0,0 +1,23 @@
+
+
+ development-empmanager
+
+
+
+
+
+ org.eclipse.jdt.core.javabuilder
+
+
+
+
+ org.eclipse.wst.validation.validationbuilder
+
+
+
+
+
+ org.eclipse.wst.jsdt.core.jsNature
+ org.eclipse.jdt.core.javanature
+
+
diff --git a/.settings/.jsdtscope b/.settings/.jsdtscope
new file mode 100644
index 0000000..cca691f
--- /dev/null
+++ b/.settings/.jsdtscope
@@ -0,0 +1,7 @@
+
+
+
+
+
+
+
diff --git a/.settings/org.eclipse.wst.jsdt.ui.superType.container b/.settings/org.eclipse.wst.jsdt.ui.superType.container
new file mode 100644
index 0000000..49c8cd4
--- /dev/null
+++ b/.settings/org.eclipse.wst.jsdt.ui.superType.container
@@ -0,0 +1 @@
+org.eclipse.wst.jsdt.launching.JRE_CONTAINER
\ No newline at end of file
diff --git a/.settings/org.eclipse.wst.jsdt.ui.superType.name b/.settings/org.eclipse.wst.jsdt.ui.superType.name
new file mode 100644
index 0000000..11006e2
--- /dev/null
+++ b/.settings/org.eclipse.wst.jsdt.ui.superType.name
@@ -0,0 +1 @@
+Global
\ No newline at end of file
diff --git a/src/com/rhizome/example/access/DepartmentAccess.java b/src/com/rhizome/example/access/DepartmentAccess.java
new file mode 100644
index 0000000..6f9c54a
--- /dev/null
+++ b/src/com/rhizome/example/access/DepartmentAccess.java
@@ -0,0 +1,141 @@
+package com.rhizome.example.access;
+
+import java.io.FileNotFoundException;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.List;
+
+import com.rhizome.example.data.BaseData;
+import com.rhizome.example.data.DepartmentData;
+
+public class DepartmentAccess extends BaseAccess{
+
+ private static final String DEPARTMENT_FILEPATH = "file/DepartmentData.csv";
+
+ public DepartmentAccess() {
+ super(DEPARTMENT_FILEPATH);
+ }
+
+ public List DepSelectAll() throws FileNotFoundException {
+ //全件データ
+ List allList = new ArrayList<>();
+
+ //取得用リスト(CSV形式)
+ List 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 selectById(String key) throws FileNotFoundException {
+ //全件データ
+ List allList = new ArrayList<>();
+
+ //取得用リスト(CSV形式)
+ List 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);
+ }
+
+ //IDでの抽出データ
+ List selectList = new ArrayList<>();
+
+ for (BaseData department : allList) {
+ if (department.getPrimaryKeyValue().equals(key)) {
+ selectList.add(department);
+ }
+ }
+
+ return selectList;
+ }
+
+ @Override
+ public void insert(BaseData data) throws IOException {
+ //CSVファイルに追記する
+ addData(data);
+ }
+
+ @Override
+ public void update(BaseData updateData) throws IOException {
+ //更新後データリスト
+ List updatedList = new ArrayList<>();
+
+ //全件取得し、更新データを反映する
+ List allList = new ArrayList<>();
+
+ //取得用リスト(CSV形式)
+ List 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);
+ }
+
+ for (BaseData department : allList) {
+
+ if(department.getPrimaryKeyValue().equals(updateData.getPrimaryKeyValue())) {
+ //指定されたデータとキーが一致するデータの場合、更新データを設定
+ updatedList.add(updateData);
+ } else {
+ //上記以外は取得したデータをそのまま設定
+ updatedList.add(department);
+ }
+ }
+ //ファイル上書き処理
+ updateData(updatedList);
+
+ }
+
+ @Override
+ public void delete(String key) throws IOException {
+ //全件から削除データを除いたリスト
+ List deletedList = new ArrayList<>();
+
+ //全件取得し、keyに該当するデータをリストから削除する
+ //全件データ
+ List allList = new ArrayList<>();
+
+ //取得用リスト(CSV形式)
+ List 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);
+ }
+
+ for (BaseData department : allList) {
+ if(!department.getPrimaryKeyValue().equals(key)) {
+ deletedList.add(department);
+ }
+ }
+ //ファイル上書き処理
+ updateData(deletedList);
+ }
+
+}
diff --git a/src/com/rhizome/example/access/EmployeeAccess.java b/src/com/rhizome/example/access/EmployeeAccess.java
index 4eb9e4b..45885bb 100644
--- a/src/com/rhizome/example/access/EmployeeAccess.java
+++ b/src/com/rhizome/example/access/EmployeeAccess.java
@@ -15,7 +15,30 @@ public class EmployeeAccess extends BaseAccess {
public EmployeeAccess() {
super(EMPDATA_FILEPATH);
}
+
+ public List empSelectAll() throws FileNotFoundException {
+ //全件データ
+ List allList = new ArrayList<>();
+ //取得用リスト(CSV形式)
+ List 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 selectById(String key) throws FileNotFoundException {
//全件データ
@@ -126,5 +149,7 @@ public class EmployeeAccess extends BaseAccess {
//ファイル上書き処理
updateData(deletedList);
}
+
+
}
diff --git a/src/com/rhizome/example/data/DepartmentData.java b/src/com/rhizome/example/data/DepartmentData.java
new file mode 100644
index 0000000..8bda936
--- /dev/null
+++ b/src/com/rhizome/example/data/DepartmentData.java
@@ -0,0 +1,36 @@
+package com.rhizome.example.data;
+
+public class DepartmentData extends BaseData{
+ /** 役職ID */
+ private String idDepartment;
+ /** 役職名 */
+ private String nmDepartment;
+ public String getIdDepartment() {
+ return idDepartment;
+ }
+ public void setIdDepartment(String idDepartment) {
+ this.idDepartment = idDepartment;
+ }
+ public String getNmDepartment() {
+ return nmDepartment;
+ }
+ public void setNmDepartment(String nmDepartment) {
+ this.nmDepartment = nmDepartment;
+ }
+
+ @Override
+ public String toString() {
+ return getIdDepartment() + "\t" + getNmDepartment();
+
+ }
+
+ @Override
+ public String toCSV() {
+ return getIdDepartment() + "," + getNmDepartment();
+ }
+
+ @Override
+ public String getPrimaryKeyValue() {
+ return getIdDepartment();
+ }
+}
diff --git a/src/com/rhizome/example/main/Main.java b/src/com/rhizome/example/main/Main.java
index a08fa53..ca028c9 100644
--- a/src/com/rhizome/example/main/Main.java
+++ b/src/com/rhizome/example/main/Main.java
@@ -5,13 +5,16 @@ import java.io.IOException;
import java.util.List;
import java.util.Scanner;
+import com.rhizome.example.access.DepartmentAccess;
import com.rhizome.example.access.EmployeeAccess;
import com.rhizome.example.data.BaseData;
+import com.rhizome.example.data.DepartmentData;
import com.rhizome.example.data.EmployeeData;
+
public class Main {
static Scanner sc = new Scanner(System.in);
-
+ private boolean employeeMode = true;
/**
* 処理開始位置
*
@@ -19,9 +22,12 @@ public class Main {
*/
public static void main(String[] args) {
System.out.println("システムを開始します");
+ Main main = new Main();
while (true) {
+
+
try {
- new Main().start();
+ main.start();
} catch (Exception e) {
System.out.println("予期せぬエラーが発生しました");
e.printStackTrace();
@@ -35,24 +41,52 @@ public class Main {
*
*/
public void start() throws IOException {
+
System.out.println();
- System.out.println("1:検索 2:登録 3:更新 4:削除 0:終了");
+ System.out.println("1:検索 2:登録 3:更新 4:削除 9:データ切り替え 0:終了 "
+ + "(管理対象:"
+ +(employeeMode ? "Employee" : "Department")
+ + ")");
+
String ope = sc.nextLine();
switch (ope) {
- case "1": //検索
- empSelect();
+ case "1": //検索
+ if(employeeMode) {
+ start1();
+ }else {
+ start2();
+ }
+
break;
case "2": //登録
- empInsert();
+ if(employeeMode) {
+ empInsert();
+ }else {
+ depInsert();
+ }
+
break;
case "3": //更新
- empUpdate();
+ if(employeeMode) {
+ empUpdate();
+ }else {
+ depUpdate();
+ }
+
break;
case "4": //削除
- empDelete();
+ if(employeeMode) {
+ empDelete();
+ }else {
+ depDelete();
+ }
+
break;
- case "0": //修了
+ case "9": //データ切り替え
+ employeeMode = !employeeMode;
+ break;
+ case "0": //終了
System.out.println("システムを終了します");
System.exit(0);
default:
@@ -66,6 +100,25 @@ public class Main {
*
* @throws FileNotFoundException
*/
+
+ public void start1() throws IOException {
+ System.out.println();
+ System.out.println("1:全検索 2:条件検索");
+ String ope = sc.nextLine();
+
+ switch (ope) {
+ case "1": //全検索
+ //全出力
+ empSelectAll();
+ break;
+ case "2": //条件検索
+ empSelect();
+ break;
+ default:
+ //戻る
+ break;
+ }
+ }
public void empSelect() throws FileNotFoundException {
EmployeeAccess ea = new EmployeeAccess();
List list;
@@ -208,4 +261,173 @@ public class Main {
}
return str;
}
+
+ public void empSelectAll() throws FileNotFoundException {
+
+ EmployeeAccess ea = new EmployeeAccess();
+
+ List 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 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("削除が完了しました");
+ }
+
+ /**
+ * 入力値を判定し、返却する
+ *
+ * @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;
+ }
+*/
+ public void DepSelectAll()throws FileNotFoundException{
+ DepartmentAccess da = new DepartmentAccess();
+
+ List list = da.DepSelectAll();
+
+ for (BaseData department : list) {
+ System.out.println(department.toString());
+ }
+
+ }
+
+
}