1 Commits
fu ... kawara

Author SHA1 Message Date
4a9dad81f0 Department実装まで完了 2026-10-23 16:15:23 +09:00
7 changed files with 271 additions and 263 deletions

View File

@@ -6,18 +6,18 @@
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<name>org.eclipse.wst.validation.validationbuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.wst.validation.validationbuilder</name>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.wst.jsdt.core.jsNature</nature>
<nature>org.eclipse.jdt.core.javanature</nature>
<nature>org.eclipse.wst.jsdt.core.jsNature</nature>
</natures>
</projectDescription>

View File

@@ -1,3 +1,4 @@
09,代表取締役
10,役員
11,人事・総務部
12,経理部
1 10 09 役員 代表取締役
1 09 代表取締役
2 10 10 役員 役員
3 11 11 人事・総務部 人事・総務部
4 12 12 経理部 経理部

View File

@@ -8,3 +8,4 @@
10007,葉山稔,ハヤマミノル,mhayama@hoge.jp,hhh,14
10008,川上朱里,カワカミアカリ,kawakami@hoge.jp,iii,14
10009,杉井肇,スギイハジメ,sugi@hoge.jp,jjj,15
10010,瓦昂世,カワラコウセイ,kawara@hoge.jp,kkk,09
1 10000 山田龍也 ヤマダタツヤ yamada@hoge.jp aaa 10
8 10007 葉山稔 ハヤマミノル mhayama@hoge.jp hhh 14
9 10008 川上朱里 カワカミアカリ kawakami@hoge.jp iii 14
10 10009 杉井肇 スギイハジメ sugi@hoge.jp jjj 15
11 10010 瓦昂世 カワラコウセイ kawara@hoge.jp kkk 09

View File

@@ -9,33 +9,10 @@ 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";
private static final String DEPDATA_FILEPATH = "file/DepartmentData.csv";
public DepartmentAccess() {
super(DEPARTMENT_FILEPATH);
super(DEPDATA_FILEPATH);
}
public List<BaseData> DepSelectAll() 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.setNmDepartment(columns[1]);
allList.add(department);
}
return allList;
}
@Override
public List<BaseData> selectById(String key) throws FileNotFoundException {
//全件データ
@@ -49,10 +26,9 @@ public class DepartmentAccess extends BaseAccess{
String[] columns = line.split(",");
department.setIdDepartment(columns[0]);
department.setNmDepartment(columns[1]);
allList.add(department);
}
//IDでの抽出データ
List<BaseData> selectList = new ArrayList<>();
@@ -87,13 +63,11 @@ public class DepartmentAccess extends BaseAccess{
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);
@@ -120,11 +94,10 @@ public class DepartmentAccess extends BaseAccess{
List<String> csvList = readData();
for (String line : csvList) {
DepartmentData department= new DepartmentData();
DepartmentData department = new DepartmentData();
String[] columns = line.split(",");
department.setIdDepartment(columns[0]);
department.setNmDepartment(columns[1]);
allList.add(department);
}
@@ -138,4 +111,4 @@ public class DepartmentAccess extends BaseAccess{
updateData(deletedList);
}
}
}

View File

@@ -15,30 +15,7 @@ public class EmployeeAccess extends BaseAccess {
public EmployeeAccess() {
super(EMPDATA_FILEPATH);
}
public List<BaseData> empSelectAll() 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
public List<BaseData> selectById(String key) throws FileNotFoundException {
//全件データ
@@ -149,7 +126,5 @@ public class EmployeeAccess extends BaseAccess {
//ファイル上書き処理
updateData(deletedList);
}
}

View File

@@ -1,23 +1,43 @@
package com.rhizome.example.data;
public class DepartmentData extends BaseData{
/** 役職ID */
public class DepartmentData extends BaseData {
/** 部署ID */
private String idDepartment;
/** 役職名 */
/** 部署名 */
private String nmDepartment;
/**
* @return 部署ID
*/
public String getIdDepartment() {
return idDepartment;
}
/**
* @param idDepartment 部署ID
*/
public void setIdDepartment(String idDepartment) {
this.idDepartment = idDepartment;
}
/**
* @return 部署名
*/
public String getNmDepartment() {
return nmDepartment;
}
/**
* @param ndDepartment 部署名
*/
public void setNmDepartment(String nmDepartment) {
this.nmDepartment = nmDepartment;
}
/**
* {@inheritDoc}
*/
@Override
public String toString() {
return getIdDepartment() + "\t" + getNmDepartment();
@@ -28,9 +48,11 @@ public class DepartmentData extends BaseData{
public String toCSV() {
return getIdDepartment() + "," + getNmDepartment();
}
@Override
public String getPrimaryKeyValue() {
return getIdDepartment();
return idDepartment;
}
}

View File

@@ -1,6 +1,8 @@
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;
@@ -11,10 +13,9 @@ 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;
/**
* 処理開始位置
*
@@ -22,15 +23,15 @@ public class Main {
*/
public static void main(String[] args) {
System.out.println("システムを開始します");
Main main = new Main();
while (true) {
while (true) {
try {
main.start();
new Main().Start();
} catch (Exception e) {
System.out.println("予期せぬエラーが発生しました");
e.printStackTrace();
}
}
}
/**
@@ -38,81 +39,166 @@ public class Main {
* @throws IOException
*
*/
public void start() throws IOException {
public void Start() throws IOException {
System.out.println();
System.out.println("1:検索 2:登録 3:更新 4:削除 9:データ切り替え 0:終了 "
+ "(管理対象:"
+(employeeMode ? "Employee" : "Department")
+ ")");
System.out.println("1:検索 2:登録 3:更新 4:削除 9:データ切り替え 0:終了 (管理対象:Employee)");
String ope = sc.nextLine();
switch (ope) {
case "1": //検索
if(employeeMode) {
start1();
}else {
start2();
}
case "1": //検索 ←変えたとこ
empDivide();
break;
case "2": //登録
if(employeeMode) {
empInsert();
}else {
depInsert();
}
case "2": //登録
empInsert();
break;
case "3": //更新
if(employeeMode) {
empUpdate();
}else {
depUpdate();
}
case "3": //更新
empUpdate();
break;
case "4": //削除
if(employeeMode) {
empDelete();
}else {
depDelete();
}
case "4": //削除
empDelete();
break;
case "9": //データ切り替え
employeeMode = !employeeMode;
break;
case "0": //終了
case "9": //切り替え ←追加したとこ
Change();
break;
case "0": //終了
System.out.println("システムを終了します");
System.exit(0);
break;
default:
System.out.println("指定の番号を入力してください");
break;
}
}
//自分がつくったところ 部署のデータ
public void departmentStart() throws IOException {
System.out.println();
System.out.println("1:検索 2:登録 3:更新 4:削除 9:データ切り替え 0:終了 (管理対象:Department)");
String ope = sc.nextLine();
switch (ope) {
case "1": //検索 おかしい
depDivide();
break;
case "2": //登録 おけ
depInsert();
break;
case "3": //更新 おけ
depUpdate();
break;
case "4": //削除 おかしい
depDelete();
break;
case "9": //切り替え おけ
Change();
break;
case "0": //終了 おけ
System.out.println("システムを終了します");
System.exit(0);
break;
default:
System.out.println("指定の番号を入力してください");
break;
}
}
//自分がつくったところ データ切り替えるか確認するばしょ
public void Change() throws IOException {
System.out.println();
System.out.println("データを切り替えますか?");
System.out.println("1:部署データへ 2:社員データへ 0:終了");
String ope = sc.nextLine();
switch (ope) {
case "1": //部署データに切り替える おけ
departmentStart();
break;
case "2": //社員データに戻る おけ
Start();
break;
case "0": //終了
System.out.println("システムを終了します");
System.exit(0);
break;
default:
System.out.println("指定の番号を入力してください");
break;
}
}
//自分がつくったところ 全検索か条件検索か
public void empDivide() throws IOException {
System.out.println();
System.out.println("1:全検索 2:条件検索 それ以外:戻る");
String ope = sc.nextLine();
switch (ope) {
case "1": //全検索 おけ
empExportcsv();
break;
case "2": //条件検索 おけ
empSelect();
break;
default:
break;
}
}
//自分がつくったところ 部署 全検索か 条件検索か
public void depDivide() throws IOException {
System.out.println();
System.out.println("1:全検索 2:条件検索 それ以外:戻る");
String ope = sc.nextLine();
switch (ope) {
case "1": //全検索 おけ
depExportcsv();
break;
case "2": //条件検索 おけ
depSelect();
break;
default:
break;
}
}
//自分がつくったとこ csv指定して出力
public void empExportcsv() throws IOException {
try (BufferedReader reader = new BufferedReader(new FileReader("file/EmployeeData.csv"))) {
String line;
while ((line = reader.readLine()) != null) {
String formatted = line.replace(",", " ");
System.out.println(formatted);
}
}
}
//自分がつくったとこ 部署csv指定して出力
public void depExportcsv() throws IOException {
try (BufferedReader reader = new BufferedReader(new FileReader("file/DepartmentData.csv"))) {
String line;
while ((line = reader.readLine()) != null) {
String formatted = line.replace(",", " ");
System.out.println(formatted);
}
}
}
/**
* 社員ファイルから情報を検索する
*
* @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<BaseData> list;
@@ -122,7 +208,7 @@ public class Main {
//idに一致する社員データ取得
list = ea.selectById(id);
if (list.size() == 0) { //取得結果が0件の場合
if (list.size() == 0) { //取得結果が0件の場合
System.out.println("入力された値で情報がみつかりませんでした");
}
@@ -130,6 +216,29 @@ public class Main {
for (BaseData employee : list) {
System.out.println(employee.toString());
}
}
//自分がつくったところ 部署ファイルから情報検索
public void depSelect() throws FileNotFoundException {
DepartmentAccess da = new DepartmentAccess();
List<BaseData> list;
//IDの入力および入力チェック
String id = inputCheck("ID", true);
//idに一致する社員データ取得
list = da.selectById(id);
if (list.size() == 0) { //取得結果が0件の場合
System.out.println("入力された値で情報がみつかりませんでした");
}
//取得結果件数分、データをタブ区切りで出力する
for (BaseData department : list) {
System.out.println(department.toString());
}
}
/**
@@ -161,6 +270,23 @@ public class Main {
System.out.println("登録が完了しました");
}
//自分がつくったところ 部署ファイルに情報登録
public void depInsert() throws IOException {
//各項目の入力および入力チェック処理
String id = inputCheck("部署ID", true);
String name = inputCheck("部署名", false);
//部署データインスタンスを生成し、入力値を設定
DepartmentData department = new DepartmentData();
department.setIdDepartment(id);
department.setNmDepartment(name);
DepartmentAccess da = new DepartmentAccess();
//ファイルデータ追加処理
da.insert(department);
System.out.println("登録が完了しました");
}
/**
* 社員ファイルの情報を更新する
*
@@ -198,6 +324,29 @@ public class Main {
System.out.println("更新が完了しました");
}
//自分が作ったところ 部署データアップデート
public void depUpdate() throws IOException {
DepartmentAccess da = new DepartmentAccess();
//入力チェック
String id = inputCheck("部署ID", true);
//存在チェック
if (da.selectById(id).size() == 0) {
System.out.println("入力された値で情報がみつかりませんでした");
return;
}
//名前入力チェック
String name = inputCheck("部署名", false);
DepartmentData department = new DepartmentData();
department.setIdDepartment(id);
department.setNmDepartment(name);
//ファイルデータ更新処理
da.update(department);
System.out.println("更新が完了しました");
}
/**
* 社員ファイルの情報を削除する
*
@@ -213,7 +362,7 @@ public class Main {
System.out.println("入力された値で情報がみつかりませんでした");
return;
}
System.out.println("指定されたIDの情報を削除します? Y/y");
System.out.println("指定されたIDの情報を削除しますか? Y/y");
System.out.println("(Y/y以外の入力であればキャンセル)");
String yY = sc.nextLine();
if (!"y".equals(yY) && !"Y".equals(yY)) {
@@ -225,6 +374,30 @@ public class Main {
System.out.println("削除が完了しました");
}
//自分がつくったところ 部署データ削除
public void depDelete() throws IOException {
DepartmentAccess da = new DepartmentAccess();
//入力チェック
String id = inputCheck("部署ID", true);
//存在チェック
if (da.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;
}
//ファイルデータ削除処理
da.delete(id);
System.out.println("削除が完了しました");
}
/**
* 入力値を判定し、返却する
*
@@ -255,142 +428,5 @@ public class Main {
}
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());
}
}
}