Compare commits
2 Commits
ishikawa
...
a7162f1b2e
| Author | SHA1 | Date | |
|---|---|---|---|
| a7162f1b2e | |||
| e4cf7bed2e |
@@ -1,7 +0,0 @@
|
||||
<?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
1
.gitignore
vendored
@@ -1 +0,0 @@
|
||||
/bin/
|
||||
23
.project
23
.project
@@ -1,23 +0,0 @@
|
||||
<?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>
|
||||
@@ -1,7 +0,0 @@
|
||||
<?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>
|
||||
@@ -1 +0,0 @@
|
||||
org.eclipse.wst.jsdt.launching.JRE_CONTAINER
|
||||
@@ -1 +0,0 @@
|
||||
Global
|
||||
@@ -1,72 +0,0 @@
|
||||
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);
|
||||
}
|
||||
}
|
||||
@@ -1,33 +0,0 @@
|
||||
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;
|
||||
}
|
||||
}
|
||||
@@ -1,16 +1,12 @@
|
||||
package com.rhizome.example.main;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.FileReader;
|
||||
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 {
|
||||
@@ -22,9 +18,7 @@ public class Main {
|
||||
* @param args
|
||||
*/
|
||||
public static void main(String[] args) {
|
||||
|
||||
System.out.println("システムを開始します");
|
||||
//※1
|
||||
while (true) {
|
||||
try {
|
||||
new Main().start();
|
||||
@@ -42,19 +36,12 @@ public class Main {
|
||||
*/
|
||||
public void start() throws IOException {
|
||||
System.out.println();
|
||||
System.out.println("1:検索 2:登録 3:更新 4:削除 9:データ切り替え 0:終了 (管理対象:Employee)");
|
||||
String ope = sc.nextLine(); //キーボードから読み取り
|
||||
System.out.println("1:検索 2:登録 3:更新 4:削除 0:終了");
|
||||
String ope = sc.nextLine();
|
||||
|
||||
switch (ope) {
|
||||
case "1": //検索
|
||||
System.out.println(" 1:全件検索 2:条件検索 それ以外:戻る");
|
||||
String choose = sc.nextLine(); //キーボードから読み取り
|
||||
if(choose.equals("1")) { //1の時
|
||||
empSelect("all"); //引数all(文字列)を渡す
|
||||
|
||||
}else if(choose.equals("2")) { //2の時
|
||||
empSelect(); //引数なし
|
||||
}
|
||||
empSelect();
|
||||
break;
|
||||
case "2": //登録
|
||||
empInsert();
|
||||
@@ -65,40 +52,6 @@ public class Main {
|
||||
case "4": //削除
|
||||
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;
|
||||
case "0": //修了
|
||||
System.out.println("システムを終了します");
|
||||
System.exit(0);
|
||||
@@ -131,50 +84,6 @@ public class Main {
|
||||
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();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 社員ファイルに情報を登録する
|
||||
@@ -205,18 +114,6 @@ public class Main {
|
||||
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("登録が完了しました");
|
||||
}
|
||||
|
||||
/**
|
||||
* 社員ファイルの情報を更新する
|
||||
*
|
||||
@@ -254,25 +151,6 @@ public class Main {
|
||||
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("更新が完了しました");
|
||||
}
|
||||
|
||||
/**
|
||||
* 社員ファイルの情報を削除する
|
||||
*
|
||||
@@ -300,25 +178,6 @@ public class Main {
|
||||
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("削除が完了しました");
|
||||
}
|
||||
|
||||
/**
|
||||
* 入力値を判定し、返却する
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user