1 Star 0 Fork 0

翟毅鑫/命令行界面-企业员工管理系统

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
StaffManagementSystem.java 41.96 KB
一键复制 编辑 原始数据 按行查看 历史
翟毅鑫 提交于 2024-01-24 12:14 . first-commit
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924
package java_code.cloud_database;
import java.sql.*;
import java.util.Scanner;
import java.util.ArrayList;
import java.text.ParseException;
import java.text.SimpleDateFormat;
public class StaffManagementSystem {
static final String JDBC_DRIVER = "com.huawei.opengauss.jdbc.Driver";
static final String DB_URL = "jdbc:opengauss://110.41.126.115:8000/CQU_DB2021?ApplicationName=app1";
static final String USER = "db_user2021_230";
static final String PASS = "db_user@123";
static Connection conn = null;
static Statement stmt = null;
static Scanner in = null;
static String userID = null;
public static void main(String[] args) {
try {
Class.forName(JDBC_DRIVER);
System.out.println("连接数据库中...");
conn = DriverManager.getConnection(DB_URL, USER, PASS);
stmt = conn.createStatement();
System.out.println("成功连接数据库。");
} catch (SQLException se) {
System.out.println("连接数据库失败!");
System.out.println("报错信息:" + se);
return;
} catch (Exception e) {
System.out.println("程序运行失败!");
System.out.println("报错信息:" + e);
return;
}
in = new Scanner(System.in);
System.out.println("欢迎来到企业员工管理系统");
LogIn();
boolean exit = false;
while (!exit) {
Boolean isAdmin = null;
try {
String sql = "SELECT administrator FROM staff_member WHERE ID_card_number = " + userID;
ResultSet rs = stmt.executeQuery(sql);
rs.next();
isAdmin = rs.getBoolean("administrator");
} catch (SQLException se) {
System.out.println("报错信息:" + se);
return;
}
System.out.println("请选择您想要执行的操作:");
if (isAdmin) {
System.out.println("(p)人员信息 (d)部门信息 (r)批假 (e)退出");
String cmd = in.nextLine();
switch (cmd) {
case "p":
StaffInfo();
break;
case "d":
DeptInfo();
break;
case "r":
RecessInfo();
break;
case "e":
exit = true;
break;
default:
System.out.println("没有该选项!");
break;
}
} else {
System.out.println("(p)个人信息 (r)请假 (e)退出");
String cmd = in.nextLine();
switch (cmd) {
case "p":
Self();
break;
case "r":
Recess();
break;
case "e":
exit = true;
break;
default:
System.out.println("没有该选项!");
break;
}
}
}
in.close();
try {
if (stmt != null) stmt.close();
} catch (SQLException se2) {
}
try {
if (conn != null) conn.close();
} catch (SQLException se) {
System.out.println("关闭数据库连接失败!");
System.out.println("报错信息:" + se);
}
System.out.println("已退出");
}
public static Integer InputInt() {
Integer num = null;
boolean valid = false;
while (!valid) {
String s = in.nextLine();
try {
num = Integer.parseInt(s);
valid = true;
} catch (NumberFormatException ne) {
System.out.println("格式错误!");
System.out.println("请输入整数:");
}
}
return num;
}
public static Date InputDate() {
java.sql.Date date = null;
boolean valid = false;
SimpleDateFormat sdf = new SimpleDateFormat("yyyy年MM月dd日");
while (!valid)
try {
System.out.println("请输入年份:");
String yyyy = in.nextLine();
System.out.println("请输入月份:");
String MM = in.nextLine();
System.out.println("请输入日期:");
String dd = in.nextLine();
java.util.Date parse = null;
parse = sdf.parse(yyyy + "年" + MM + "月" + dd + "日");
date = new java.sql.Date(parse.getTime());
valid = true;
} catch (ParseException pe) {
System.out.println("格式错误!");
System.out.println("报错信息:" + pe);
}
return date;
}
public static Double InputDouble() {
Double d = null;
Boolean valid = false;
while (!valid)
try {
String s = in.nextLine();
d = Double.parseDouble(s);
valid = true;
} catch (NumberFormatException ne) {
System.out.println("格式错误!");
System.out.println("请输入浮点数:");
}
return d;
}
public static Boolean InputBoolean() {
Boolean b = null;
Boolean valid = false;
while (!valid)
try {
String s = in.nextLine();
switch (s) {
case "true":
valid = true;
break;
case "false":
valid = true;
break;
default:
System.out.println("格式错误!");
System.out.println("请输入true或者false:");
}
b = Boolean.parseBoolean(s);
} catch (NumberFormatException ne) {
}
return b;
}
public static String InputGender() {
String s = null;
Boolean valid = false;
while (!valid) {
s = in.nextLine();
switch (s) {
case "M":
valid = true;
break;
case "F":
valid = true;
break;
default:
System.out.println("格式错误!");
System.out.println("请输入M或者F:");
}
}
return s;
}
public static void LogIn() {
System.out.println("请先登录您的账号");
boolean back = false;
ResultSet rs = null;
while (!back) {
System.out.println("请输入身份证号:");
String ID = in.nextLine();
System.out.println("请输入密码:");
String passWord = in.nextLine();
boolean exist = false;
boolean match = false;
try {
String sql = "SELECT ID_card_number FROM staff_member WHERE ID_card_number = " + ID;
rs = stmt.executeQuery(sql);
exist = rs.next();
} catch (SQLException se) {
}
if (!exist) {
System.out.println("账号不存在!");
continue;
}
try {
String sql = "SELECT ID_card_number,name FROM staff_member WHERE ID_card_number = " + ID + "AND password = " + passWord;
rs = stmt.executeQuery(sql);
match = rs.next();
} catch (SQLException se) {
}
if (match)
back = true;
else
System.out.println("密码错误!");
}
String userName = "unknown";
try {
userID = rs.getString("ID_card_number");
userName = rs.getString("name");
System.out.println("登录成功");
System.out.println("您好! " + userName + " :)");
} catch (SQLException se) {
}
}
public static void StaffInfo() {
boolean back = false;
ArrayList<String> ID_card_number = new ArrayList<String>();
try {
while (!back) {
String sql = "SELECT ID_card_number,dept_name,supervisor_ID,name FROM staff_member ORDER BY name";
ResultSet rs = stmt.executeQuery(sql);
System.out.println(" 身份证号, 姓名,部门, 上司");
int count = 0;
ID_card_number.clear();
while (rs.next()) {
ID_card_number.add(rs.getString("ID_card_number"));
count++;
System.out.println("(" + count + ")" + rs.getString("ID_card_number") + ", " + rs.getString("name") + ", " + rs.getString("dept_name") + ", " + rs.getString("supervisor_ID"));
}
rs.close();
System.out.println("请选择您想要执行的操作:");
System.out.println("(c)查看员工信息 (n)新增员工 (b)返回");
String cmd = in.nextLine();
switch (cmd) {
case "c":
System.out.println("请输入数字以选择您要查看的员工:");
int num = InputInt();
if (num <= 0 || count < num)
System.out.println("没有该选项!");
else
StaffUpdate(ID_card_number.get(num - 1));
break;
case "n":
NewStaff();
break;
case "b":
back = true;
break;
default:
System.out.println("没有该选项!");
}
}
} catch (SQLException se) {
System.out.println("报错信息:" + se);
}
}
public static void StaffUpdate(String ID_card_number) {
Boolean back = false;
try {
while (!back) {
String sql = "SELECT * FROM staff_member WHERE ID_card_number = '" + ID_card_number + "'";
ResultSet rs = stmt.executeQuery(sql);
rs.next();
System.out.println("(1)*身份证号:" + rs.getString(1));
System.out.println("(2)*部门:" + rs.getString(2));
System.out.println("(3)o上级的身份证号:" + rs.getString(3));
System.out.println("(4)*姓名:" + rs.getString(4));
System.out.println("(5)*性别:" + rs.getString(5));
System.out.println("(6)*出生日期:" + rs.getDate(6));
System.out.println("(7)*就职日期:" + rs.getDate(7));
System.out.println("(8)*职位:" + rs.getString(8));
System.out.println("(9)*工资:" + rs.getString(9));
System.out.println("(10)*密码:" + rs.getString(10));
System.out.println("(11)*是否是管理员:" + rs.getBoolean(11));
System.out.println("(12)o居住地:" + rs.getString(12));
System.out.println("(13)o电话号码:" + rs.getString(13));
System.out.println("(14)o电子邮件地址:" + rs.getString(14));
System.out.println("请选择您想要执行的操作:");
System.out.println("(1)*身份证号 (2)*部门 (3)o上级 (4)*姓名 (5)*性别 (6)*出生日期 (7)*就职日期 (8)*职位 (9)*工资 (10)*密码");
System.out.println("(11)*是否是管理员 (12)o居住地 (13)o电话号码 (14)o电子邮件地址 (d)删除该员工 (b)返回");
String cmd = null;
cmd = in.nextLine();
switch (cmd) {
case "1":
System.out.println("请输入身份证号:");
cmd = in.nextLine();
stmt.executeUpdate("UPDATE staff_member SET ID_card_number = '" + cmd + "' WHERE ID_card_number = '" + ID_card_number + "'");
if (ID_card_number.equals(userID))
userID = cmd;
ID_card_number = cmd;
System.out.println("修改成功");
break;
case "2":
System.out.println("请输入部门名:");
cmd = in.nextLine();
stmt.executeUpdate("UPDATE staff_member SET dept_name = '" + cmd + "' WHERE ID_card_number = '" + ID_card_number + "'");
System.out.println("修改成功");
break;
case "3":
System.out.println("请输入上级身份证号:");
cmd = in.nextLine();
if (!cmd.equals("null"))
cmd = "'" + cmd + "'";
stmt.executeUpdate("UPDATE staff_member SET supervisor_ID = " + cmd + " WHERE ID_card_number = '" + ID_card_number + "'");
System.out.println("修改成功");
break;
case "4":
System.out.println("请输入姓名:");
cmd = in.nextLine();
stmt.executeUpdate("UPDATE staff_member SET name = '" + cmd + "' WHERE ID_card_number = '" + ID_card_number + "'");
System.out.println("修改成功");
break;
case "5":
System.out.println("请输入性别(M/F):");
stmt.executeUpdate("UPDATE staff_member SET gender = '" + InputGender() + "' WHERE ID_card_number = '" + ID_card_number + "'");
System.out.println("修改成功");
break;
case "6":
System.out.println("请输入出生日期:");
stmt.executeUpdate("UPDATE staff_member SET birth_date = '" + InputDate() + "' WHERE ID_card_number = '" + ID_card_number + "'");
System.out.println("修改成功");
break;
case "7":
System.out.println("请输入就职日期:");
stmt.executeUpdate("UPDATE staff_member SET joining_date = '" + InputDate() + "' WHERE ID_card_number = '" + ID_card_number + "'");
System.out.println("修改成功");
break;
case "8":
System.out.println("请输入职务:");
cmd = in.nextLine();
stmt.executeUpdate("UPDATE staff_member SET duty = '" + cmd + "' WHERE ID_card_number = '" + ID_card_number + "'");
System.out.println("修改成功");
break;
case "9":
System.out.println("请输入工资:");
stmt.executeUpdate("UPDATE staff_member SET salary = " + InputDouble() + " WHERE ID_card_number = '" + ID_card_number + "'");
System.out.println("修改成功");
break;
case "10":
System.out.println("请输入密码:");
cmd = in.nextLine();
stmt.executeUpdate("UPDATE staff_member SET password = '" + cmd + "' WHERE ID_card_number = '" + ID_card_number + "'");
System.out.println("修改成功");
break;
case "11":
System.out.println("是否是管理员(true/false):");
stmt.executeUpdate("UPDATE staff_member SET administrator = " + InputBoolean() + " WHERE ID_card_number = '" + ID_card_number + "'");
System.out.println("修改成功");
break;
case "12":
System.out.println("请输入居住地:");
cmd = in.nextLine();
if (!cmd.equals("null"))
cmd = "'" + cmd + "'";
stmt.executeUpdate("UPDATE staff_member SET residence_address = " + cmd + " WHERE ID_card_number = '" + ID_card_number + "'");
System.out.println("修改成功");
break;
case "13":
System.out.println("请输入电话号码:");
cmd = in.nextLine();
if (!cmd.equals("null"))
cmd = "'" + cmd + "'";
stmt.executeUpdate("UPDATE staff_member SET phone_number = " + cmd + " WHERE ID_card_number = '" + ID_card_number + "'");
System.out.println("修改成功");
break;
case "14":
System.out.println("请输入电子邮件地址:");
cmd = in.nextLine();
if (!cmd.equals("null"))
cmd = "'" + cmd + "'";
stmt.executeUpdate("UPDATE staff_member SET email_address = " + cmd + " WHERE ID_card_number = '" + ID_card_number + "'");
System.out.println("修改成功");
break;
case "d":
if (!ID_card_number.equals(userID)) {
stmt.execute("DELETE FROM staff_member WHERE ID_card_number = " + ID_card_number);
System.out.println("删除成功");
back = true;
} else
System.out.println("不允许删除自己!");
break;
case "b":
back = true;
break;
default:
System.out.println("没有该选项!");
}
}
} catch (SQLException se) {
System.out.println("报错信息:" + se);
}
}
public static void NewStaff() {
String ID_card_number = null;
String dept_name = null;
String supervisor_ID = null;
String name = null;
String gender = null;
Date birth_date = null;
Date joining_date = null;
String duty = null;
Double salary = null;
String password = null;
Boolean administrator = null;
String residence_address = null;
String phone_number = null;
String email_address = null;
Boolean back = false;
while (!back) {
System.out.println("(1)*身份证号:" + ID_card_number);
System.out.println("(2)*部门:" + dept_name);
System.out.println("(3)o上级的身份证号:" + supervisor_ID);
System.out.println("(4)*姓名:" + name);
System.out.println("(5)*性别:" + gender);
System.out.println("(6)*出生日期:" + birth_date);
System.out.println("(7)*就职日期:" + joining_date);
System.out.println("(8)*职位:" + duty);
System.out.println("(9)*工资:" + salary);
System.out.println("(10)*初始密码:" + password);
System.out.println("(11)*是否是管理员:" + administrator);
System.out.println("(12)o居住地:" + residence_address);
System.out.println("(13)o电话号码:" + phone_number);
System.out.println("(14)o电子邮件地址:" + email_address);
System.out.println("请选择您想要执行的操作:");
System.out.println("(1)*身份证号 (2)*部门 (3)o上级 (4)*姓名 (5)*性别 (6)*出生日期 (7)*就职日期 (8)*职位 (9)*工资 (10)*初始密码");
System.out.println("(11)*是否是管理员 (12)o居住地 (13)o电话号码 (14)o电子邮件地址 (a)确认 (c)取消");
try {
String cmd = null;
cmd = in.nextLine();
switch (cmd) {
case "1":
System.out.println("请输入身份证号:");
cmd = in.nextLine();
ID_card_number = cmd;
break;
case "2":
System.out.println("请输入部门名:");
cmd = in.nextLine();
dept_name = cmd;
break;
case "3":
System.out.println("请输入上级身份证号:");
cmd = in.nextLine();
supervisor_ID = cmd;
break;
case "4":
System.out.println("请输入姓名:");
cmd = in.nextLine();
name = cmd;
break;
case "5":
System.out.println("请输入性别(M/F):");
gender = InputGender();
break;
case "6":
System.out.println("请输入出生日期:");
birth_date = InputDate();
break;
case "7":
System.out.println("请输入就职日期:");
joining_date = InputDate();
break;
case "8":
System.out.println("请输入职务:");
cmd = in.nextLine();
duty = cmd;
break;
case "9":
System.out.println("请输入工资:");
salary = InputDouble();
break;
case "10":
System.out.println("请输入初始密码:");
cmd = in.nextLine();
password = cmd;
break;
case "11":
System.out.println("是否是管理员(true/false):");
administrator = InputBoolean();
break;
case "12":
System.out.println("请输入居住地:");
cmd = in.nextLine();
residence_address = cmd;
break;
case "13":
System.out.println("请输入电话号码:");
cmd = in.nextLine();
phone_number = cmd;
break;
case "14":
System.out.println("请输入电子邮件地址:");
cmd = in.nextLine();
email_address = cmd;
break;
case "a":
String _supervisor_ID_ = null;
String _residence_address_ = null;
String _phone_number_ = null;
String _email_address_ = null;
if (supervisor_ID != null && !supervisor_ID.equals("null")) {
_supervisor_ID_ = "'" + supervisor_ID + "'";
}
if (residence_address != null && !residence_address.equals("null")) {
_residence_address_ = "'" + residence_address + "'";
}
if (phone_number != null && !phone_number.equals("null")) ;
{
_phone_number_ = "'" + phone_number + "'";
}
if (email_address != null && !phone_number.equals("null")) ;
{
_email_address_ = "'" + email_address + "'";
}
stmt.execute("INSERT INTO staff_member VALUES('" + ID_card_number + "','" + dept_name + "'," + _supervisor_ID_ + ",'" + name + "','" + gender + "','" + birth_date + "','" + joining_date + "','" + duty + "'," + salary + ",'" + password + "'," + administrator + "," + _residence_address_ + "," + _phone_number_ + "," + _email_address_ + ")");
System.out.println("新增成功");
;
back = true;
break;
case "c":
back = true;
break;
default:
System.out.println("没有该选项!");
break;
}
} catch (SQLException se) {
System.out.println("报错信息:" + se);
} catch (Exception e) {
System.out.println("报错信息:" + e);
}
}
}
public static void DeptInfo() {
try {
Boolean back = false;
ArrayList<String> dept_name = new ArrayList<String>();
while (!back) {
String sql = "SELECT dept_name,location FROM department";
ResultSet rs = stmt.executeQuery(sql);
System.out.println(" 部门名, 地址");
int count = 0;
dept_name.clear();
while (rs.next()) {
dept_name.add(rs.getString("dept_name"));
count++;
System.out.println("(" + count + ")" + rs.getString("dept_name") + ", " + rs.getString("location"));
}
rs.close();
System.out.println("请选择您想要执行的操作:");
System.out.println("(c)查看账本 (n)新增部门 (d)删除部门 (b)返回");
String cmd = in.nextLine();
switch (cmd) {
case "c":
System.out.println("请输入数字以选择您所要查看的部门:");
int num = InputInt();
if (num <= 0 || count < num)
System.out.println("没有该选项!");
else
IncomeExpense(dept_name.get(num - 1));
break;
case "n":
NewDept();
break;
case "d":
System.out.println("请输入数字以选择您所要删除的部门:");
num = InputInt();
if (num <= 0 || count < num)
System.out.println("没有该选项!");
else
stmt.execute("DELETE FROM department WHERE dept_name = '" + dept_name.get(num - 1) + "'");
break;
case "b":
back = true;
break;
default:
System.out.println("没有该选项!");
}
}
} catch (SQLException se) {
System.out.println("报错信息:" + se);
}
}
public static void NewDept() {
try {
boolean back = false;
String dept_name = null;
String location = null;
while (!back) {
System.out.println("部门名:" + dept_name);
System.out.println("地址:" + location);
System.out.println("请选择您想要执行的操作:");
System.out.println("(1)*部门名 (2)*地址 (a)确认 (c)取消");
String cmd = in.nextLine();
switch (cmd) {
case "1":
System.out.println("请输入部门名:");
cmd = in.nextLine();
dept_name = cmd;
break;
case "2":
System.out.println("请输入部门地址:");
cmd = in.nextLine();
location = cmd;
break;
case "a":
stmt.execute("INSERT INTO department VALUES('" + dept_name + "','" + location + "')");
System.out.println("新增成功");
back = true;
break;
case "c":
back = true;
break;
default:
}
}
} catch (SQLException se) {
System.out.println("报错信息:" + se);
}
}
public static void IncomeExpense(String dept_name) {
try {
boolean back = false;
boolean onlyin = false;
boolean onlyex = false;
Date begin = Date.valueOf("2000-01-01");
Date stop = Date.valueOf("2100-12-31");
while (!back) {
String cond = "dept_name = '" + dept_name + "' AND income_expense_time >= '" + begin + "' AND income_expense_time <= '" + stop + "'";
if (onlyin)
cond += " AND income_expense >= 0 ";
else if (onlyex)
cond += " AND income_expense < 0 ";
String sql = "SELECT income_expense_time,income_expense FROM income_expense_record WHERE " + cond + "ORDER BY income_expense_time";
ResultSet rs = stmt.executeQuery(sql);
System.out.println(begin + "~" + stop + "之间的记录:");
System.out.println(" 时间, 金额");
int count = 0;
double sum = 0;
while (rs.next()) {
count++;
System.out.println("(" + count + ")" + rs.getDate("income_expense_time") + ", " + rs.getDouble("income_expense"));
sum += rs.getDouble("income_expense");
}
System.out.println("总金额:" + sum);
rs.close();
System.out.println("请选择您想要执行的操作:");
System.out.println("(+)只显示收入 (-)只显示支出 (*)收入支出都显示 ");
System.out.println("([)起始日期 (])截止日期");
System.out.println("(n)新增记录 (d)删除这些记录 (b)返回");
String cmd = in.nextLine();
switch (cmd) {
case "+":
onlyin = true;
onlyex = false;
break;
case "-":
onlyin = false;
onlyex = true;
break;
case "*":
onlyin = false;
onlyex = false;
break;
case "[":
begin = InputDate();
break;
case "]":
stop = InputDate();
break;
case "n":
System.out.println("请输入时间:");
Date date = InputDate();
System.out.println("请输入金额:");
Double doub = InputDouble();
try {
stmt.execute("INSERT INTO income_expense_record VALUES('" + dept_name + "','" + date + "'," + doub + ")");
System.out.println("新增成功");
} catch (SQLException se) {
System.out.println("新增失败!");
System.out.println("报错信息:" + se);
}
break;
case "d":
try {
stmt.execute("DELETE FROM income_expense_record WHERE " + cond);
System.out.println("删除成功");
begin = Date.valueOf("2000-01-01");
stop = Date.valueOf("2100-12-31");
} catch (SQLException se) {
System.out.println("删除失败!");
System.out.println("报错信息:" + se);
}
break;
case "b":
back = true;
break;
default:
System.out.println("没有该选项!");
}
}
} catch (SQLException se) {
System.out.println("报错信息:" + se);
}
}
public static void RecessInfo() {
try {
boolean back = false;
ArrayList<String> ID_card_number = new ArrayList<String>();
ArrayList<Date> start_time = new ArrayList<Date>();
while (!back) {
String sql = "SELECT * FROM recess_record NATURAL JOIN staff_member ORDER BY start_time ";
ResultSet rs = stmt.executeQuery(sql);
ID_card_number.clear();
start_time.clear();
System.out.println(" 员工,请假时间");
int count = 0;
while (rs.next()) {
ID_card_number.add(rs.getString("ID_card_number"));
start_time.add(rs.getDate("start_time"));
count++;
System.out.print("(" + count + ")" + rs.getString("name") + ", " + rs.getDate("start_time") + "~" + rs.getDate("end_time"));
if (rs.getBoolean("checked") == false)
System.out.println(" *");
else
System.out.println("");
}
System.out.println("请选择您想要执行的操作:");
System.out.println("(c)查看 (b)返回");
String cmd = in.nextLine();
switch (cmd) {
case "c":
System.out.println("请输入数字以选择您要查看的记录:");
int num = InputInt();
if (num <= 0 || count < num)
System.out.println("没有该选项!");
else
RecessAdmit(ID_card_number.get(num - 1), start_time.get(num - 1));
break;
case "b":
back = true;
break;
default:
System.out.println("没有该选项!");
}
}
} catch (SQLException se) {
System.out.println("报错信息:" + se);
}
}
public static void RecessAdmit(String ID_card_number, Date start_time) {
try {
stmt.execute("UPDATE recess_record SET checked = true WHERE ID_card_number = '" + ID_card_number + "' AND start_time = '" + start_time + "'");
boolean back = false;
while (!back) {
String sql = "SELECT * FROM recess_record NATURAL JOIN staff_member WHERE ID_card_number = '" + ID_card_number + "' AND start_time = '" + start_time + "'";
ResultSet rs = stmt.executeQuery(sql);
rs.next();
System.out.println("员工:" + rs.getString("name"));
System.out.println("请假时间:" + rs.getDate("start_time") + "~" + rs.getDate("end_time"));
System.out.println("请假原因:" + rs.getString("reason"));
System.out.println("是否批准:" + rs.getBoolean("admitted"));
System.out.println("请选择您想要执行的操作:");
System.out.println("(y)批准 (n)驳回 (b)返回");
String cmd = in.nextLine();
switch (cmd) {
case "y":
stmt.execute("UPDATE recess_record SET admitted = true WHERE ID_card_number = '" + ID_card_number + "' AND start_time = '" + start_time + "'");
break;
case "n":
stmt.execute("UPDATE recess_record SET admitted = false WHERE ID_card_number = '" + ID_card_number + "' AND start_time = '" + start_time + "'");
break;
case "b":
back = true;
break;
default:
System.out.println("没有该选项!");
}
}
} catch (SQLException se) {
System.out.println("报错信息:" + se);
}
}
public static void Self() {
Boolean back = false;
try {
while (!back) {
String sql = "SELECT * FROM staff_member WHERE ID_card_number = '" + userID + "'";
ResultSet rs = stmt.executeQuery(sql);
rs.next();
System.out.println("身份证号:" + rs.getString(1));
System.out.println("部门:" + rs.getString(2));
System.out.println("上级的身份证号:" + rs.getString(3));
System.out.println("姓名:" + rs.getString(4));
System.out.println("性别:" + rs.getString(5));
System.out.println("出生日期:" + rs.getDate(6));
System.out.println("就职日期:" + rs.getDate(7));
System.out.println("职位:" + rs.getString(8));
System.out.println("工资:" + rs.getString(9));
System.out.println("密码:" + rs.getString(10));
System.out.println("居住地:" + rs.getString(12));
System.out.println("电话号码:" + rs.getString(13));
System.out.println("email地址:" + rs.getString(14));
System.out.println("请选择您想要执行的操作:");
System.out.println("(w)修改密码 (r)修改居住地 (p)修改电话号码 (e)修改email地址 (b)返回");
String cmd = in.nextLine();
switch (cmd) {
case "w":
System.out.println("请输入密码:");
cmd = in.nextLine();
stmt.executeUpdate("UPDATE staff_member SET password = '" + cmd + "' WHERE ID_card_number = '" + userID + "'");
System.out.println("修改成功");
break;
case "r":
System.out.println("请输入居住地:");
cmd = in.nextLine();
stmt.executeUpdate("UPDATE staff_member SET residence_address = '" + cmd + "' WHERE ID_card_number = '" + userID + "'");
System.out.println("修改成功");
break;
case "p":
System.out.println("请输入电话号码:");
cmd = in.nextLine();
stmt.executeUpdate("UPDATE staff_member SET phone_number = '" + cmd + "' WHERE ID_card_number = '" + userID + "'");
System.out.println("修改成功");
break;
case "e":
System.out.println("请输入email地址:");
cmd = in.nextLine();
stmt.executeUpdate("UPDATE staff_member SET email_address = '" + cmd + "' WHERE ID_card_number = '" + userID + "'");
System.out.println("修改成功");
break;
case "b":
back = true;
break;
default:
System.out.println("没有该选项!");
}
}
} catch (SQLException se) {
System.out.println("报错信息:" + se);
}
}
public static void Recess() {
try {
boolean back = false;
while (!back) {
String sql = "SELECT * FROM recess_record WHERE ID_card_number = '" + userID + "' ORDER BY start_time ";
ResultSet rs = stmt.executeQuery(sql);
System.out.println(" 请假时间,是否被批准");
int count = 0;
while (rs.next()) {
count++;
System.out.print("(" + count + ")" + rs.getDate("start_time") + "~" + rs.getDate("end_time") + ",");
if (rs.getBoolean("admitted"))
System.out.println("已被批准");
else
System.out.println("未被批准");
}
System.out.println("请选择您想要执行的操作:");
System.out.println("(n)新增申请 (b)返回");
String cmd = in.nextLine();
switch (cmd) {
case "n":
System.out.println("请输入起始时间:");
Date start_time = InputDate();
System.out.println("请输入结束时间:");
Date end_time = InputDate();
System.out.println("请输入请假原因:");
String reason = in.nextLine();
stmt.execute("INSERT INTO recess_record VALUES('" + userID + "','" + start_time + "','" + end_time + "'," + false + ",'" + reason + "'," + null + ")");
break;
case "b":
back = true;
break;
default:
System.out.println("没有该选项!");
}
}
} catch (SQLException se) {
System.out.println("报错信息:" + se);
}
}
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/zhai-yixin/command-line-management-system.git
git@gitee.com:zhai-yixin/command-line-management-system.git
zhai-yixin
command-line-management-system
命令行界面-企业员工管理系统
main

搜索帮助