no message

This commit is contained in:
2026-10-22 17:09:26 +09:00
parent 19425cd977
commit e4cf7bed2e
74 changed files with 43788 additions and 9 deletions

View File

@@ -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<BaseData> list;
@@ -208,4 +261,142 @@ 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());
}
}
}