1 Commits
fu ... ishikawa

Author SHA1 Message Date
e1b74e4ad2 個人開発20261023 2026-10-23 16:25:33 +09:00
9 changed files with 293 additions and 7 deletions

7
.classpath Normal file
View File

@@ -0,0 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
<classpathentry kind="src" path="src"/>
<classpathentry kind="lib" path="実行例/em_oop.jar"/>
<classpathentry kind="output" path="bin"/>
</classpath>

1
.gitignore vendored Normal file
View File

@@ -0,0 +1 @@
/bin/

23
.project Normal file
View File

@@ -0,0 +1,23 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>development-empmanager</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.wst.validation.validationbuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.jdt.core.javanature</nature>
<nature>org.eclipse.wst.jsdt.core.jsNature</nature>
</natures>
</projectDescription>

7
.settings/.jsdtscope Normal file
View File

@@ -0,0 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="con" path="org.eclipse.wst.jsdt.launching.JRE_CONTAINER"/>
<classpathentry kind="con" path="org.eclipse.wst.jsdt.launching.baseBrowserLibrary"/>
<classpathentry kind="src" path=""/>
<classpathentry kind="output" path=""/>
</classpath>

View File

@@ -0,0 +1 @@
org.eclipse.wst.jsdt.launching.JRE_CONTAINER

View File

@@ -0,0 +1 @@
Global

View File

@@ -0,0 +1,72 @@
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 DPT_FILEPATH = "file/DepartmentData.csv";
public DepartmentAccess() {
super("file/DepartmentData.csv");
}
public List<BaseData> selectAll() throws FileNotFoundException {
List<String> csvList = this.readData();
List<BaseData> datalist = new ArrayList();
for(String line : csvList) {// 26
DepartmentData dpt = new DepartmentData();
String[] columns = line.split(",");
dpt.setIdDepartment(columns[0]);
dpt.setNmDepartment(columns[1]);
datalist.add(dpt);
}
return datalist;
}
public List<BaseData> selectById(String key) throws FileNotFoundException {
List<BaseData> allList = this.selectAll();
List<BaseData> selectList = new ArrayList();
for(BaseData dpt : allList) {
if (dpt.getPrimaryKeyValue().equals(key)) {
selectList.add(dpt);
}
}
return selectList;
}
public void insert(BaseData data) throws IOException {
this.addData(data);// 61
}// 62
public void update(BaseData updateData) throws IOException {
List<BaseData> updatedList = new ArrayList();
for(BaseData dpt : this.selectAll()) {
if (dpt.getPrimaryKeyValue().equals(updateData.getPrimaryKeyValue())) {// 72
updatedList.add(updateData);
} else {
updatedList.add(dpt);
}
}
this.updateData(updatedList);// 81
}// 83
public void delete(String key) throws IOException {
List<BaseData> deletedList = new ArrayList();// 88
for(BaseData employee : this.selectAll()) {// 91 93
if (!employee.getPrimaryKeyValue().equals(key)) {// 94
deletedList.add(employee);// 95
}
}
updateData(deletedList);
}
}

View File

@@ -0,0 +1,33 @@
package com.rhizome.example.data;
public class DepartmentData extends BaseData {
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;
}
public String toString() {
return this.getIdDepartment()
+ "\t" + this.getNmDepartment();
}
public String toCSV() {
return this.getIdDepartment()
+ "\t" + this.getNmDepartment();
}
public String getPrimaryKeyValue() {
return this.idDepartment;
}
}

View File

@@ -1,12 +1,16 @@
package com.rhizome.example.main; package com.rhizome.example.main;
import java.io.BufferedReader;
import java.io.FileNotFoundException; import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException; import java.io.IOException;
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 {
@@ -18,7 +22,9 @@ public class Main {
* @param args * @param args
*/ */
public static void main(String[] args) { public static void main(String[] args) {
System.out.println("システムを開始します"); System.out.println("システムを開始します");
//※1
while (true) { while (true) {
try { try {
new Main().start(); new Main().start();
@@ -36,28 +42,69 @@ 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:削除 0:終了"); System.out.println("1:検索 2:登録 3:更新 4:削除 9:データ切り替え 0:終了 (管理対象:Employee)");
String ope = sc.nextLine(); String ope = sc.nextLine(); //キーボードから読み取り
switch (ope) { switch (ope) {
case "1": //検索 case "1": //検索
empSelect(); System.out.println(" 1:全件検索 2:条件検索 それ以外:戻る");
break; String choose = sc.nextLine(); //キーボードから読み取り
if(choose.equals("1")) { //1の時
empSelect("all"); //引数all(文字列)を渡す
}else if(choose.equals("2")) { //2の時
empSelect(); //引数なし
}
break;
case "2": //登録 case "2": //登録
empInsert(); empInsert();
break; break;
case "3": //更新 case "3": //更新
empUpdate(); empUpdate();
break; break;
case "4": //削除 case "4": //削除
empDelete(); empDelete();
break;
case "9": //切り替え
dptloop:while(true) {
System.out.println("1:検索 2:登録 3:更新 4:削除 9:データ切り替え 0:終了 (管理対象:Department)");
String dope = sc.nextLine();
switch (dope) {
case "1": //検索
System.out.println(" 1:全件検索 2:条件検索 それ以外:戻る");
String dptchoose = sc.nextLine();
if(dptchoose.equals("1")) {
dptSelect("all"); //全検索
}else if(dptchoose.equals("2")) {
dptSelect(); //条件検索
}
break;
case "2": //登録
dptInsert();
break;
case "3": //更新
dptUpdate();
break;
case "4": //削除
dptDelete();
break;
case "9": //切り替え
break dptloop;
case "0": //終了
System.out.println("システムを終了します");
System.exit(0);
default:
System.out.println("指定の番号を入力してください");
continue; //※2戻る
}
}
break; break;
case "0": //修了 case "0": //修了
System.out.println("システムを終了します"); System.out.println("システムを終了します");
System.exit(0); System.exit(0);
default: default:
System.out.println("指定の番号を入力してください"); System.out.println("指定の番号を入力してください");
break; break;
} }
} }
@@ -84,6 +131,50 @@ public class Main {
System.out.println(employee.toString()); System.out.println(employee.toString());
} }
} }
//throwsで例外が起きたときにメインメソッドで処理できるようにする
public void empSelect(String str)throws FileNotFoundException { //allを受け取るメソッド
//try-catchで例外処理+try-with-resourcesでファイルを自動で閉じる
//csvファイルを読み込みreaderの変数へ代入
try (BufferedReader reader = new BufferedReader(new FileReader("file/EmployeeData.csv"))) {
String line; //変数定義
//ファイルから読み込んだ1行をlineに代入しnullじゃない間ループ
while((line = reader.readLine())!= null) {
System.out.println(line); //lineを出力
}
}catch(IOException e) { //エラーの受け取りと処理
System.out.println("ファイルの読み込み中にエラーが発生しました");
e.printStackTrace(); //エラーの内容を詳しく表示する処理
}
}
public void dptSelect() throws FileNotFoundException {
DepartmentAccess da = new DepartmentAccess();
List<BaseData> list;
String id = inputCheck("ID", true);
list = da.selectById(id);
if (list.size() == 0) {
System.out.println("入力された値で情報がみつかりませんでした");
}
for (BaseData department : list) {
System.out.println(department.toString());
}
}
public void dptSelect(String str) throws FileNotFoundException {
try (BufferedReader dptreader = new BufferedReader(new FileReader("file/DepartmentData.csv"))) {
String line;
while((line = dptreader.readLine())!= null) {
System.out.println(line);
}
}catch(IOException e) {
System.out.println("ファイルの読み込み中にエラーが発生しました");
e.printStackTrace();
}
}
/** /**
* 社員ファイルに情報を登録する * 社員ファイルに情報を登録する
@@ -113,6 +204,18 @@ public class Main {
ea.insert(employee); ea.insert(employee);
System.out.println("登録が完了しました"); System.out.println("登録が完了しました");
} }
public void dptInsert() throws IOException {
String depId = inputCheck("部署ID", true);
String depName = inputCheck("部署名", false);
DepartmentData dpt = new DepartmentData();
dpt.setIdDepartment(depId);
dpt.setNmDepartment(depName);
DepartmentAccess da = new DepartmentAccess();
da.insert(dpt);
System.out.println("登録が完了しました");
}
/** /**
* 社員ファイルの情報を更新する * 社員ファイルの情報を更新する
@@ -150,6 +253,25 @@ public class Main {
ea.update(employee); ea.update(employee);
System.out.println("更新が完了しました"); System.out.println("更新が完了しました");
} }
public void dptUpdate() throws IOException {
DepartmentAccess da = new DepartmentAccess();
String dptid = inputCheck("ID", true);
if (da.selectById(dptid).size() == 0) {
System.out.println("入力された値で情報がみつかりませんでした");
return;
}
String depId = inputCheck("部署ID", true);
String depName = inputCheck("部署名前", true);
DepartmentData dpt = new DepartmentData();
dpt.setIdDepartment(depId);
dpt.setNmDepartment(depName);
da.update(dpt);
System.out.println("更新が完了しました");
}
/** /**
* 社員ファイルの情報を削除する * 社員ファイルの情報を削除する
@@ -178,6 +300,25 @@ public class Main {
System.out.println("削除が完了しました"); System.out.println("削除が完了しました");
} }
public void dptDelete() throws IOException {
DepartmentAccess da = new DepartmentAccess();
String dptid = inputCheck("ID", true);
if (da.selectById(dptid).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;
}
da.delete(dptid);
System.out.println("削除が完了しました");
}
/** /**
* 入力値を判定し、返却する * 入力値を判定し、返却する
* *