(完整版)职工信息管理系统java源代码
Java实现员工信息管理系统
Java实现员⼯信息管理系统在Java SE中,对IO流与集合的操作在应⽤中⽐较重要。
接下来,我以⼀个⼩型项⽬的形式,演⽰IO流、集合等知识点在实践中的运⽤。
该项⽬名称为“员⼯信息管理系统”(或“员⼯收录系统”),主要是通过输⼊员⼯的id、姓名信息,实现简单的增删改查功能。
该项⽬主要在DOS窗⼝的控制台或者Eclipse的控制台上进⾏操作。
操作界⾯如下:该项⽬的⽂件结构如下:Step 1:⼊⼝类SystemMain的代码为:package empsystem;import java.util.Scanner;/*** 主界⾯* ⼀个Scanner录⼊对象* Employ类* ⽂件路径* 查重SearchID* @author 李章勇**/public class SystemMain {private Scanner sc=new Scanner(System.in);public SystemMain() {showWelcome();}public void showWelcome(){System.out.println("----员⼯收录系统");System.out.println("1.增加员⼯功能");System.out.println("2.查看员⼯功能");System.out.println("3.修改员⼯功能");System.out.println("4.删除员⼯功能");System.out.println("5.退出系统");String choice=sc.nextLine();switch(choice){case "1":System.out.println("您选择了增加⽤户功能");//Addnew Add();break;case "2":System.out.println("您选择了查看⽤户功能");//Searchnew ShowEmp();break;case "3":System.out.println("您选择了修改⽤户功能");//Modifynew Modify();break;case "4":System.out.println("您选择了删除⽤户功能");//删除⽤户Deletenew Delete();break;case "5":System.out.println("您选择了退出系统");return;default:System.out.println("⽆此功能");break;}}}Step 2:写⽂件路径FilePath接⼝。
java 职工信息管理系统源代码
源代码package lesson2;import java。
sql。
*;public class employee{public String num;public String name;public String sex;public String age;public String edu;public String sla;public String add;public String tel;public void init(String x1,String x2,String x3,String x4,String x5,String x6,String x7,String x8){num=x1;name=x2;sex=x3;age=x4;edu=x5;sla=x6;add=x7;tel=x8;}public void load(String f){try{Class。
forName(”com.microsoft.sqlserver.jdbc。
SQLServerDriver”);String url=”jdbc:sqlserver://localhost:1433;DatabaseName=employee";String userName=”sa”;String password="xhw";Connection conn=DriverManager.getConnection (url,userName,password);if(conn!=null)System.out。
println(”已成功地与SQL Server 2005数据库建立连接!");Statement stmt=conn.createStatement();stmt.executeUpdate(f);stmt。
close();}catch(Exception e){e。
员工信息管理系统源码
business R(Q);
return Q;
}
admi gyx(admi Q)
{
admi R(Q);
return Q;
}
/////////////////////////////////主体+初始+登录
void fg();void main();void denglu();void began();void amend();void list();
file1<<A[i].name<<" "<<A[i].age<<" "<<A[i].card<<" "<<A[i].home<<
" "<<A[i].id<<" "<<A[i].time<<" "<<A[i].wage<<" "<<A[i].code<<endl;
file2<<B.jieshao<<" "<<B.gonggao<<endl;
int gnum;int snum;int xnum;
num(int gn,int sn,int xn);
num(){gnum=snum=xnum=0;}
};
num::num(int gn,int sn,int xn)
{
gnum=gn;snum=sn;xnum=xn;
}
简单的JAVA员工信息管理系统源码
据库连结 3.查问 4.增、 5 删 6 改 (操作数据库)import .*;public class EmpManageSys implements ActionListener { Connection con;Statement stmt;String sql;ResultSet rs;StringBuffer sb = new StringBuffer();JTextField jtf2 = new JTextField("张飞 ",10); JTextField jtf3 = new JTextField(10);JTextField jtf4 = new JTextField(10);JTextField jtf7 = new JTextField(10);JTextField jtf5 = new JTextField(10);JTextField jtf6 = new JTextField(10);JTextField jtf8 = new JTextField(10);JTextField jtf9 = new JTextField(10);JTextArea jta10 = new JTextArea(50, 40);public void actionPerformed(ActionEvent e) {String str = ();if ("查问 ".equals(str)) {quals(str)) {quals(str)) {quals(str)) {EmpManageSys() {createGUI();connectToDataBase();}public void searchEmp() {("");try {stmt = ();oLowerCase().trim() + "or id="+().toLowerCase().trim() + "or engName="+().toLowerCase().trim() + "or UNIT="+().toLowerCase().trim() + "or TEAM="+().toLowerCase().trim() + "or Phone="+().toLowerCase().trim() + "or region="+().toLowerCase().trim() + "or busStation="+().toLowerCase().trim();(sql);rs = ();ResultSetMetaData meta = ();int cols = ();while ()) {for (int i = 1; i <= cols; i++) {(" " + (i) + " =");(i));}("\n");());}} catch (SQLException e11){ ();}}public void addEmp() {try {stmt = ();sql = "update Mstar values(" + () + ()+()+()+()+()+()+()+")"; inti = ();if (() != null) && () != null)&&() != null) && () != null)){ (sql);("增添记录成功 " + i + "条"); } else {("带 * 号项为增添记录时不可以为空 ");}} catch (SQLException e1) {();}}public void deleteEmp() {searchEmp();try {stmt = ();sql = "delete from Mstar where chineseName=" +().toLowerCase().trim() + "or id="+().toLowerCase().trim() + "or engName="+().toLowerCase().trim() + "or UNIT="+().toLowerCase().trim() + "or TEAM="+().toLowerCase().trim() + "or Phone="+().toLowerCase().trim() + "or region="+().toLowerCase().trim() + "or busStation="+().toLowerCase().trim();(sql);int i = ();("撤掉操作成功 " + i + "条");} catch (SQLException e){ ();}}public void alterEmp(){ searchEmp();sql = "update Mstar set chineseName="+().toLowerCase().trim() + "and id="+().toLowerCase().trim() + "and engName="+().toLowerCase().trim() + "and UNIT="+().toLowerCase().trim() + "and TEAM="+().toLowerCase().trim() + "and Phone="+().toLowerCase().trim() + "and region="+().toLowerCase().trim() + "and busStation="+().toLowerCase().trim();int i = 0;try {(sql);i = ();} catch (SQLException e){ ();}("改正操作成功 " + i + "条");}public void createGUI() {JFrame jf = new JFrame("职工信息管理系统 "); (new GridLayout(2, 1));// (new GridLayout(10,2));JPanel jp00 = new JPanel(new GridLayout(5, 4)); JPanel jp1 = new JPanel();JButton jb11 = new JButton("查问 ");(this);JButton jb12 = new JButton("增添 ");(this);(jb11);(jb12);(jp1);JPanel jp11 = new JPanel();JButton jb111 = new JButton("改正 "); (this);JButton jb112 = new JButton("撤掉 "); (this);(jb111);(jb112);(jp11);JPanel jp2 = new JPanel();JLabel jl2 = new JLabel("中文名 * "); (jl2);(jtf2);(jp2);JPanel jp3 = new JPanel();JLabel jl3 = new JLabel("工号 ");(jl3);(jtf3);(jp3);JPanel jp4 = new JPanel();JLabel jl4 = new JLabel("EngName*"); (jl4);(jtf4);(jp4);JPanel jp5 = new JPanel();JLabel jl5 = new JLabel("UNIT ");(jl5);(jtf5);(jp5);JPanel jp6 = new JPanel();JLabel jl6 = new JLabel("TEAM* "); (jl6);(jtf6);(jp6);JPanel jp7 = new JPanel();JLabel jl7 = new JLabel("Phone* "); (jl7);(jtf7);(jp7);JPanel jp8 = new JPanel();JLabel jl8 = new JLabel("地区 ");(jl8);(jtf8);(jp8);JPanel jp9 = new JPanel();JLabel jl9 = new JLabel("公交站");(jl9);(jtf9);(jp9);(jp00);JPanel jp01 = new JPanel();("--用户使用手册 -- \n1、查问:选择一个字段,如 EngName 在文本框中输入相应内容,点击查问 \n2 、增添:在各个文本框中输入相应内容后,点击增添。
(完整版)职工信息管理系统java源代码
case 6:save(staffOne);break ;
}
}
while (choice!=0);
}
void creat(staffI nfo staffO ne[])
{
InputStreamReader(System. in));
System. out .print("请输入职工信息(以0结束)\n");
for(int j=0;j<100;j++)
staffOne[j]=new staffInfo();
final ways staffTwo= new ways(); staffTwo.caidan(staffOne); staffTwo.creat(staffOne);
staffTwo.output(staffOne); staffTwo.search(staffOne);
staffTwo.delete(staffOne);
}
}
class ways//方法类,主要实现职工信息的建立,显示,查找,删除,信息的保存与读取;这个类是整个程序的操作类。
public int i=0;//i用来存放职工的人数public String filename="Infomation.txt" BufferedReader buf =new
package exercise;
import java.io.*;
class staffInfo//职工类{
public
String
name;
public
String
num;
public
java实现人员信息管理系统
java实现⼈员信息管理系统本⽂实例为⼤家分享了java实现⼈员信息管理系统的具体代码,供⼤家参考,具体内容如下实现增删改查.java⼊门的练⼿⼩程序1.Person类package p1;public class Person {// Person属性private int num;private String name;private String sex;private int salary;public Person(int num, String name, String sex, int salary) {super();this.num = num; = name;this.sex = sex;this.salary = salary;}// 对Perosn操作的⽅法public int getNum() {return num;}public void setNum(int num) {this.num = num;}public String getName() {return name;}public void setName(String name) { = name;}public String getSex() {return sex;}public void setSex(String sex) {this.sex = sex;}public int getSalary() {return salary;}public void setSalary(int salary) {this.salary = salary;}}2.SysMenu类package p1;public class SysMenu {public static final String[] MENU = { "1.员⼯信息管理", "2.退出" };public static final String[] OPERATION_MENU = { "1.新增", "2.查看", "3.修改", "4.删除", "5.返回" };public static void showMenu(String[] Menu) {for (int i = 0; i < Menu.length; i++)System.out.print(Menu[i] + "\t\t");System.out.println();System.out.println("---------------------------------------");}}3.SysInfo类package p1;import java.util.ArrayList;import java.util.List;public class SysInfo {private static List informationList = new ArrayList();// 获取 informationListpublic static List getList() {return informationList;}}rmationService类package p1;import java.util.List;public class InformationService {private List informationList = SysInfo.getList();// 获取信息列表public List getList() {return informationList;}// 按编号查找信息public Person getPersonByNum(final int num) {if (num < 1) {System.out.println("编号错误");return null;}for (int i = 0; i < informationList.size(); i++) {Person p = (Person) informationList.get(i);if (p.getNum() == num) {System.out.println("查找成功");return p;}}System.out.println("查找失败");return null;}//查看单⼀Person信息public void showAPerson(Person p){System.out.println("编号\t\t姓名\t\t性别\t\t薪⽔");System.out.println(p.getNum()+ "\t\t" + p.getName() + "\t\t" + p.getSex() + "\t\t" + p.getSalary());}//show all Personpublic void showPerson() {System.out.println("编号\t\t姓名\t\t性别\t\t薪⽔");List ps = getList();for (int i = 0; i < ps.size(); i++) {Person p = (Person) ps.get(i);System.out.println(p.getNum() + "\t\t" + p.getName() + "\t\t" + p.getSex() + "\t\t" + p.getSalary()); }}// 按名字查找信息public Person getPersonByName(final String name) {if (name == null)return null;for (int i = 0; i < informationList.size(); i++) {Person p = (Person) informationList.get(i);if (p.getName().equals(name)) {return p;}}return null;}//检查对象是否存在public boolean CheckExitByNum(int num){for(int i=0;i<informationList.size();i++){Person p = (Person)informationList.get(i);if(p.getNum()==num)return true;}return false;}//save Personpublic void savePerson(Person p){p.setNum(getPersonMaxInt()+1);informationList.add(p);}// 查找最⼤编号public int getPersonMaxInt(){int max = 0;for(int i =0;i<informationList.size();i++){Person p =(Person)informationList.get(i);if(max < p.getNum())max = p.getNum();}return max;}}5.SysRun类package p1;import java.util.InputMismatchException;import java.util.List;import java.util.Scanner;public class SysRun {private List informationList = SysInfo.getList();private Scanner s = new Scanner(System.in);private InformationService is = new InformationService(); // 系统运⾏类public static void main(String[] args) {SysRun sys = new SysRun();sys.sysRun();}public void sysRun() {System.out.println("启动系统管理系统");boolean isExit = false;do {System.out.println("----------操作选项-------------");SysMenu.showMenu(SysMenu.MENU);// 获取⽤户输⼊int operNum = getCorrONum(SysMenu.MENU);// 管理操作isExit = doManageNum(operNum);} while (!isExit);System.out.println("系统退出.");}private boolean doManageNum(int operNum) {boolean isExit = false;switch (operNum) {case 1:is.showPerson();System.out.println("----------操作选项-------------");SysMenu.showMenu(SysMenu.OPERATION_MENU); // addPerson();//testSystem.out.println("输⼊功能选择:");int num = getVaildInt();doOperationNum(num);break;case 2:isExit = true;return isExit;}return isExit;}// doOperationNumprivate void doOperationNum(int OperationNum) {// 增,查,修,删,返回switch (OperationNum) {case 1:// addaddPerson();is.showPerson();break;case 2:// 查看viewPerson();break;case 3:updatePerson();break;case 4:deletePerson();is.showPerson();break;case 5:break;}}// 删除Personprivate void deletePerson() {int num;// Person p;boolean isOk = false;System.out.println("请输⼊要删除信息的编号:");do {num = getVaildInt();isOk = is.CheckExitByNum(num);if (isOk == true) {System.out.println("编号信息查找成功。
职工信息管理系统源代码
#include<stdio.h>#include<string.h>#include<stdlib.h>int N=2;struct worker /*定义一个职工信息的结构体*/{int num; /*定义一个职工信息的结构体*/char name[20]; /*定义一个职工信息的结构体*/char sex[10]; //用字符串存放职工的性别数据char birth[20]; //用字符串存放职工的出生年月数据char deta[20]; //用字符串存放职工的工作年月数据char education[20]; //用字符串存放职工的学历数据double salary; //用字符串存放职工的性别数据char work[30]; //用字符串存放职工的职务数据char addr[20]; //用字符串存放职工的地址数据char tel[20]; //用字符串存放职工的数据}worker[100]; //用结构体数组存放职工的所有信息void menu();void input();void save();void read();void display();void add();void search();void search_education();void search_num();void del();void modify();void main(){char s;system("color 3f");printf("\n\n");printf(" \t┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓\n");printf(" \t┃**********************************************************┃\n");printf(" \t┃***┏━━━━━━━━━━━━━━━━━━━━━━━━┓***┃\n");printf(" \t┃***┃************************************************┃***┃\n");printf(" \t┃***┃*** ****┃***┃\n");printf(" \t┃***┃*** 欢迎使用职工信息管理系统****┃***┃\n");printf(" \t┃***┃*** ****┃***┃\n");printf(" \t┃***┃*** ****┃***┃\n");printf(" \t┃***┃*** 制作人吴青伶****┃***┃\n");printf(" \t┃***┃*** ****┃***┃\n");printf(" \t┃***┃*** 2013.12.28 ****┃***┃\n");printf(" \t┃***┃*** ****┃***┃\n");printf(" \t┃***┃************************************************┃***┃\n");printf(" \t┃***┗━━━━━━━━━━━━━━━━━━━━━━━━┛***┃\n"); printf(" \t┃**********************************************************┃\n");printf(" \t┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛\n"); do{menu();printf("Do you want to continue?(y/n)");s=getchar();}while(s=='Y'||s=='y');}void menu()/*菜单函数*/{int b;printf("\t \n");printf("\t \n");printf("\t \n");printf("\t \n");printf("\t \n");printf("\t 请选择\n");printf("\t ------------------------------ \n");printf("\t || || \n");printf("\t || 1. 职工信息录入|| \n");printf("\t || 2. 职工信息浏览|| \n");printf("\t || 3. 职工信息添加|| \n");printf("\t || 4. 职工信息查询|| \n");printf("\t || 5. 职工信息删除|| \n");printf("\t || 6. 职工信息修改|| \n");printf("\t || 0. 退出|| \n");printf("\t ------------------------------- \n");printf("\n 输入你的选择项(0~6):\n");scanf("%d",&b);switch(b){case 1 : //职工信息录入、保存input();save();getchar();break;case 2 ://读入职工信息并显示read();display();getchar();break;case 3 : //添加职工信息add();getchar();break;case 4 : //查询职工信息search();getchar();break;case 5 : //读入职工信息并实现职工信息删除功能read();del();getchar();break;case 6 : //读入职工信息并修改职工信息read();modify();getchar();break;case 0 : exit(0);//退出default:break;}}void input() //录入职工信息{int i,flag,j;printf("输入职工个数(默认个数为2):");scanf("%d",&N);fflush(stdin);//清除缓存for(i=0;i<N;i++){loop:printf("职工号:");scanf("%d",&worker[i].num); fflush(stdin);flag=1;if(worker[N].num<0)printf("请输入正整数:\n");elsefor(j=0;j<i;j++){if(worker[i].num==worker[j].num){flag=0;printf(" 工号重复,请重新输入!\n");goto loop;}}printf("XX:");scanf("%s",worker[i].name); fflush(stdin);printf("性别:");scanf(" %s",worker[i].sex); fflush(stdin);printf("出生年月:");scanf("%d",&worker[i].birth); fflush(stdin);printf("工作年月:");scanf("%lf",&worker[i].deta); fflush(stdin);printf("请输入学历(中专=zz,大专=dz,本科=bk,研究生=yjs):\n");scanf("%s",worker[i].education);fflush(stdin);printf("工资:");scanf("%lf",worker[i].salary); fflush(stdin);printf("职务:");scanf("%s",worker[i].work); fflush(stdin);printf("住址:");scanf("%s",worker[i].addr); fflush(stdin);printf(":");scanf("%s",worker[i].tel); fflush(stdin);}printf("\n创建完毕!\n");}void save() //保存函数{FILE *fp;int i;if((fp=fopen("worker.txt","wb"))==NULL)//以只写方式打开一个二进制文件{printf("\ncannot open file\n");exit(0);}for(i=0;i<N;i++)fwrite(&worker[i],sizeof(struct worker),1,fp);//将存中的职工信息数据输出到磁盘文件中去(二进制)fclose(fp);}void read() //读入函数{FILE *fp;int i=0;if((fp=fopen("worker.txt","rb"))==NULL) //以只读方式为输出打开磁盘文件中的一个二进制文件{printf("\ncannot open file\n");exit(0);}do{fread(&worker[i],sizeof(struct worker),1,fp);//从worker.txt文件向存读入数据(二进制)i++;}while(!feof(fp));fclose(fp);N=i-1;}void display() //信息浏览函数{int i;for(i=0;i<N;i++){printf("职工号:%d\n",worker[i].num);printf("XX:%s\n",worker[i].name);printf("性别:%s\n",worker[i].sex);printf("出生年月:%d\n",worker[i].birth);printf("工作年月:%d\n",worker[i].deta);printf("学历:%s\n",worker[i].education);printf("工资:%lf\n",worker[i].salary);printf("职务:%d\n",worker[i].work);printf("住址:%s\n",worker[i].addr);printf(":%s\n",worker[i].tel);}}void add() //添加函数{FILE *fp;int i;struct worker p;double t;printf("\n请输入新增加职工的信息:\n");printf("请输入职工号:\n");scanf("%d",&p.num);for(i=0;i<N;i++){while(worker[i].num==p.num){printf(" 工号重复,请重新输入!\n");scanf("%d",&p.num);}}printf("请输入XX:\n");scanf("%s",);printf("请输入性别:\n");scanf("%s",p.sex);printf("请输入出生年月:\n");scanf("%d",&p.birth);printf("请输入工作年月:\n");scanf("%d",&p.deta);printf("请输入学历(中专=zz,大专=dz,本科=bk,研究生=yjs:):\n");scanf("%s",cation);printf("请输入工资:\n");scanf("%lf",&t);p.salary=t;printf("请输入职务:\n");scanf("%s",p.work);printf("请输入住址:\n");scanf("%s",p.addr);printf("请输入:\n");scanf("%s",p.tel);printf("\n添加完毕!\n");if((fp=fopen("worker.txt","ab"))==NULL)//以追加方式打开一个二进制文件尾部{printf("\ncannot open file\n");exit(0);}fwrite(&p,sizeof(struct worker),1,fp);fclose(fp);}void search() //查询函数{int c;do{puts("\nsearch by=>\n1.学历2.职工号3.取消并返回");printf("Which you needed?:\n");scanf("%d",&c);if(c>3||c<1){puts("\nchoice error!please again!");getchar();//此语句用于接受在执行上一句时最后输出的回车符}}while(c>3||c<1);{switch(c){case 1:search_education();break;case 2:search_num();break;case 3:menu();break;}}}void search_education() //按学历查询函数{int i,flag=0;char s[10];printf("\n请输入你要查询的学历:\n");scanf("%s",s);for(i=0;i<N;i++){if(strcmp(s,worker[i].education)==0){printf("职工号:%d\n",worker[i].num);printf("XX:%s\n",worker[i].name);printf("性别:%s\n",worker[i].sex);printf("出生年月:%d\n",worker[i].birth);printf("工作年月:%d\n",worker[i].deta);printf("学历(中专=zz,大专=dz,本科=bk,研究生=yjs):%s\n",worker[i].education);printf("工资:%lf\n",worker[i].salary);printf("职务:%lf\n",worker[i].work);printf("住址:%s\n",worker[i].addr);printf(":%s\n",worker[i].tel);flag++;}}if(flag==0)printf("\n对不起没有找到!\n");getchar();}void search_num() //按工号查询函数{int i,s,flag=0;printf("\n输入要查询的职工号!:\n");scanf("%d",&s);for(i=0;i<N;i++){if(s==worker[i].num){printf("职工号:%d\n",worker[i].num);printf("XX:%s\n",worker[i].name);printf("性别:%s\n",worker[i].sex);printf("出生年月:%d\n",worker[i].birth);printf("工作年月:%d\n",worker[i].deta);printf("学历(中专=zz,大专=dz,本科=bk,研究生=yjs):%s\n",worker[i].education);printf("工资:%lf\n",worker[i].salary);printf("职务:%lf\n",worker[i].work);printf("住址:%s\n",worker[i].addr);printf(":%s\n",worker[i].tel);flag++;}}if(flag==0)printf("\n对不起没有找到! please");getchar();}void del() //删除函数{int i,j;FILE *fp;char name[20];char c;if((fp=fopen("worker.txt","wb"))==NULL)//以只写方式打开一个二进制文件{printf("\ncannot open file\n");exit(0);}printf("请输入要删除的职工的XX:");scanf("%s",name);for(i=0;i<N;i++){if(strcmp(name,worker[i].name)==0)//判断输入的XX和原来的XX是否相同{printf("找到该职工,是否删除?(y/n) ") ;fflush(stdin);scanf("%c",&c);if(c =='Y'||c=='y'){for(j=i;j<N;j++)worker[j]=worker[j+1];printf("删除成功! \n");//break;}}}if(i>=N){printf("没有找到该职工!\n ");return;}else{N=N-1;for(i=0;i<N;i++)if(fwrite(&worker[i],sizeof(struct worker),1,fp)!=1){printf("\ncannot save file\n");getchar();}fclose(fp);}}void modify() //修改函数{struct worker p;FILE *fp;int i,n;double t;printf("\n输入要修改的职工号:\n");scanf("%d",&n);for(i=0;i<N;i++){if(n==worker[i].num){printf("找到该职工的信息(任意键继续)!");printf("\n请输入职工的信息!\n");printf("请输入XX:\n");scanf("%s",);printf("请输入性别:\n");scanf("%s",p.sex);printf("请输入:\n");scanf("%d",&p.birth);printf("请输入工作年月:\n");scanf("%lf",&p.deta);printf("请输入学历(中专=zz,大专=dz,本科=bk,研究生=yjs):\n");scanf("%s",cation);printf("请输入工资:\n");scanf("%lf",&t);p.salary=t;printf("请输入职务:\n");scanf("%s",p.work);printf("请输入住址:\n");scanf("%s",p.addr);printf("请输入:\n");scanf("%s",p.tel);p.num=n;if((fp=fopen("worker.txt","r+"))==NULL)//以读写的方式将修改的信息写入磁盘文件{printf("\ncannot open file\n");exit(0);}fseek(fp,i*sizeof(struct worker),0);//将位置指针移到i*sizeof(struct worker)个字节处fwrite(&p,sizeof(struct worker),1,fp);fclose(fp);printf("修改成功!\n");break;}}if(i>=N)printf("\n未找到该职工!\n");}- .- . 可修编.。
最终的职工信息管理系统源代码(精)
#include#include#include#includeint saveflag=0;//是否需要存盘的标志变量struct employee{char name[15];char num[10];char sex[4];char pozition[15];long salary;char xueli[20];char address[100];char marriage[10];int age;};typedef struct node{struct employee data;struct node *next;} Node,*Link;void add(Link l;//添加void disp(Link l;//浏览void del(Link l;//删除Node* Locate(Link l,char findmess[],char nameornum[];void Qur(Link l;//查询void Tongji(Link l;//统计void Sort(Link l;//排序void Modify(Link l;//修改void Save(Link l;//保存void printe(Node *p;//打印链表中的节点//工具函数void printstart(;void Wrong(;void Nofind(;void printc(;void menu({system("color 07";printf("\t\t★★★★★★★★★★★★★★★★★★★★★★★★★★\n"; printf("\t\t★★\n";printf("\t\t★欢迎进入职工信息管理系统★\n";printf("\t\t★★\n";printf("\t\t★ [1] 创建职工信息 [2] 删除职工信息★\n";printf("\t\t★ [3] 查询职工信息 [4] 修改职工信息★\n";printf("\t\t★ [5] 追加职工记录 [6] 统计职工信息★\n";printf("\t\t★ [7] 排序职工信息 [8] 保存职工信息★\n";printf("\t\t★ [9] 浏览职工信息 [0] 退出系统★\n";printf("\t\t★★\n";printf("\t\t★创造者:龙丹万莎廖杰红沈冠★\n";printf("\t\t★九天出品必属精品★\n";printf("\t\t★ (^o^ (*^__^* O(∩_∩O (≧▽≦★\n";printf("\t\t★★★★★★★★★★★★★★★★★★★★★★★★★★\n"; }void Disp(Link l{int count=0;Node *p;p=l->next;//l储存的是单链表头节点的指针,头节点无职工信息if(!p// p==NULL NULL在stdlib中定义为0{printf("\n====>提示:没有职工记录可以显示!\n";return ;}printf("\t\t\t\t显示结果\n";printstart(;printc(;printf("\n";while(p//逐条输出链表中储存的职工信息{printe(p;p=p->next;}printstart(;printf("\n";}void printstart({printf("------------------------------------------------------------------------------\n";}void Wrong({printf("\n===>提示:输入错误!\n";}void Nofind({printf("\n===>提示:没有找到该职工!\n";}void printc({printf("工号\t姓名\t性别\t年龄\t学历\t职称\t工资\t地址\t婚否\n";printstart(;}void printe(Node *p{printf("%s\t%s\t%s\t%d\t%s\t%s\t%ld\t%s\t%s\n",p->data.num,p->,p->data.sex,p->data.age,p->data.xueli,p->data.pozition,p->data.salary,p->data.address,p->data.marriage;}Node* Locate(Link l,char findmess[],char zcornum[]//该函数用于定位链表中符合要求的节点,并返回该指针{Node *r;if(strcmp(zcornum,"num"==0//按工号查询{r=l->next;while(r!=NULL{if(strcmp(r->data.num,findmess==0return r;r=r->next;}}else if(strcmp(zcornum,"pozition"==0//按职称查询{r=l->next;while(r!=NULL{if(strcmp(r->data.pozition,findmess==0return r;r=r->next;}}else if(strcmp(zcornum,"name"==0//按姓名查询{r=l->next;while(r!=NULL{if(strcmp(r->,findmess==0return r;r=r->next;}}return 0;//若未找到返回一个空指针}void Add(Link l//次函数中无节点时r指向list头有节点时 r指向list尾{Node *p,*r,*s;//实现添加操作的临时结构体指针变量char num[10];int flag=0;r=l;s=l->next;//链表无节点时 s=NULL 有节点时指向第一个职工节点while(r->next!=NULL//如果存在后继节点时 r指针后移一个r=r->next;//将指针移至链表末尾准备添加记录while(1{printf("请你输入工号(以‘0’返回上一级菜单:)";scanf("%s",num;if(strcmp(num,"0"==0//输0跳出s=l->next;//每次从第一个节点开始找看num是否重复while(s//工号重复时返回主菜单{if(strcmp(s->data.num,num==0{printf("====>提示:工号为%s的职工已经存在,若要修改请选择4!\n",num; flag=1;return ;}s=s->next;}p=(Node *malloc(sizeof(Node;//生成新节点pstrcpy(p->data.num,num;printf("请输入姓名:";scanf("%s",p->;getchar(;printf("请输入性别:";scanf("%s",p->data.sex;getchar(;printf("请输入年龄:";scanf("%d",&p->data.age;getchar(;printf("请输入学历:";scanf("%s",p->data.xueli;printf("请输入职称:";scanf("%s",p->data.pozition;getchar(;printf("请输入工资:";scanf("%ld",&p->data.salary;getchar(;printf("请输入地址:";scanf("%s",p->data.address;getchar(;printf("请输入婚否:";scanf("%s",p->data.marriage;getchar(;p->next=NULL;//表明这是链表的尾部节点r->next=p;//将新建的节点加入链表尾部中r=p;saveflag=1;}}void Del(Link l{int sel;Node *p,*r;//实现删除操作的临时结构体指针变量char findmess[20];if(!l->next//当list无后继节点时提示和返回del({printf("\n====>提示:没有记录可以删除!\n";return ;}printf("\n====>1 按工号删除\n====>2 按姓名删除\n";scanf("%d",&sel;if(sel==1{printf("请您输入要删除的工号:";scanf("%s",findmess;p=Locate(l,findmess,"num";if(p{r=l;while(r->next!=pr=r->next;//从第一个节点找起直到找到待删除的节点跳出循环r->next=p->next;free(p;printf("\n====>提示:该职工已经成功删除!\n";saveflag=1;}else Nofind(;}else if(sel==2{printf("请您输入要删除的姓名:";scanf("%s",findmess;p=Locate(l,findmess,"name";if(p{r=l;while(r->next!=pr=r->next;r->next=p->next;free(p;printf("\n====>提示:该职工已经成功删除!\n"; saveflag=1;}else Nofind(;}else Wrong(;}void Qur(Link l{int sel;char findmess[20];Node *p;//实现查询操作的临时结构体指针变量if(!l->next{printf("\n====>提示:没有资料可查询!\n";return ;}printf("\n====>1按工号查询\n====>2按职称查询\n====>3按姓名查询\n"; scanf("%d",&sel;if(sel==1{printf("请你输入要查找的工号:";scanf("%s",findmess;p=Locate(l,findmess,"num";if(p{printf("\t\t\t\t查找结果\n";printstart(;printc(;printe(p;printstart(;}else Nofind(;}else if(sel==2{printf("请您输入要查找的职称:";scanf("%s",findmess;p=Locate(l,findmess,"pozition";if(pprintf("\t\t\t\t查找结果\n"; printstart(;printc(;printe(p;printstart(;}else Nofind(;}else if(sel==3{printf("请您输入要查找的姓名:"; scanf("%s",findmess;p=Locate(l,findmess,"name";if(p{printf("\t\t\t\t查找结果\n"; printstart(;printc(;printe(p;printstart(;}else Nofind(;}else Wrong(;void Modefy(Link l{Node *p;char findmess[20];if(!l->next{printf("\n====>提示:没有资料可以修改!\n";return ;}printf("请您输入要修改的职工工号:";scanf("%s",findmess;p=Locate(l,findmess,"num";if(p{printf("请您输入新工号(原来是%s):",p->data.num; scanf("%s",p->data.num;printf("请您输入新姓名(原来是%s):",p->; scanf("%s",p->;printf("请您输入新性别(原来是%s):",p->data.sex; scanf("%s",p->data.sex;printf("请您输入新年龄(原来是%d):",p->data.age; scanf("%d",&p->data.age;printf("请您输入学历(原来是%s):",p->data.xueli; scanf("%s",p->data.xueli;printf("请您输入职称(原来是%s):",p->data.pozition;scanf("%s",p->data.pozition;printf("请您输入工资(原来是%ld):",p->data.salary;scanf("%ld",&p->data.salary;printf("请您输入地址(原来是%s):",p->data.address;scanf("%s",p->data.address;printf("请您输入婚否(原来是%s):",p->data.marriage;scanf("%s",p->data.marriage;printf("\n====>提示:资料修改成功!\n";}else Nofind(;}void Insert(Link l//按工号查询到要插入节点的位置然后在该工号之后插入一个新节点{Node *s,*r,*p;//p指向插入位置 p指新插入记录节点char ch,new_num[10],old_num[10];//前一个保存插入点位置之前的工号后一个保存输入的新记录的工号int flag=0;s=l->next;system("cls";Disp(l;while(1{printf("请您输入已存在的工号(以0返回上一级菜单:)";scanf("%s",old_num;if(strcmp(old_num,"0"==0return ;s=l->next;flag=0;while(s//查询该工号是否存在{if(strcmp(s->data.num,old_num==0{flag=1;break;}s=s->next;}if(flag==1//若工号存在则进行插入之前的新记录的输入操作break;else{getchar(;printf("\n====>%s不存在,是否重新再输入?(y/n):",old_num; scanf("%c",&ch;if(ch=='y'||ch=='Y'{continue;}else{return ;}}}//以下记录新节点类似addprintf("请您输入待插入的工号(以0返回上一级菜单:)"; scanf("%s",new_num;if(strcmp(new_num,"0"==0return ;s=l->next;//每次从第一个节点开始找看num是否重复while(s//工号重复时返回主菜单{if(strcmp(s->data.num,new_num==0{printf("====>提示:工号为%s的职工已经存在!\n",new_num; flag=1;return ;}s=s->next;}p=(Node *malloc(sizeof(Node;if(!p{printf("\n allocate memory failure";//申请空间失败return ;}strcpy(p->data.num,new_num;printf("请您输入姓名:";scanf("%s",p->;getchar(;printf("请您输入性别:";scanf("%s",p->data.sex;getchar(;printf("请您输入年龄:";scanf("%d",&p->data.age;getchar(;printf("请您输入学历:";scanf("%s",p->data.xueli;getchar(;printf("请您输入职称:";scanf("%s",p->data.pozition;getchar(;printf("请您输入工资:";scanf("%ld",&p->data.salary;getchar(;printf("请您输入地址:";scanf("%s",p->data.address;getchar(;printf("请您输入婚否:";scanf("%s",p->data.marriage;getchar(;p->next=NULL;//表明这是链表的结尾saveflag=1;//在主函数中有对该全局变量的判断若为1 则进行存盘操作r=l->next;//将指针赋值给r 因为l中的头节点的下一个节点才实际保存着记录while(1{if(strcmp(r->data.num,old_num==0//在链表中插入一个节点{p->next=r->next;r->next=p;break;}r=r->next;}//r作为查询指针从第一个节点找起直到找到后跳出循环Disp(l;printf("\n\n";}void Tongji(Link l{Node *p;int a=0,b=0,c=0;int deal;p=l;printf("请输入您想统计的项目\n";printf("====>1 对各工资段的人数进行统计\n";printf("====>2 对各年龄段的人数进行统计\n";scanf("%d",&deal;if(deal==1{while(1{if(p->data.salary>=5000 a++;else if(p->data.salary>=2000&&p->data.salary<5000 b++;else c++;p=p->next;if(p==NULLbreak;}system("cls";Disp(l;printf("====>工资大于等于5000的人数是:%d\n",a-1;printf("====>工资大于等于2000且小于5000的人数是:%d\n",b; printf("====>工资小于2000的人数是:%d\n",c;}else if(deal==2{while(1{if(p->data.age>=30 a++;else if(p->data.age>=18&&p->data.age<30 b++;else c++;p=p->next;if(p==NULLbreak;}system("cls";Disp(l;printf("====>年龄大于等于30的人数是:%d\n",a-1;printf("====>年龄大于等于18且小于30的人数是:%d\n",b; printf("====>年龄小于18的人数是:%d\n",c;}else Wrong(;}void Sort(Link l{Link ll;Node *p,*rr,*s;int i=0;int select;if(l->next==NULL{system("cls";printf("\n===>没有职工记录!\n";getchar(;return ;}ll=(Node*malloc(sizeof(Node;if(!ll{printf("\n allocate memory failure";return ;}ll->next=NULL;system("cls";Disp(l;p=l->next;printf("请选择排序方法:\n";printf("====>1 按年龄排序\n====>2 按工资排序\n";scanf("%d",&select;while(p{s=(Node*malloc(sizeof(Node;//新建节点用于保存从原链表中取出的节点信息if(!s//s=NULL{printf("\n allocate memory failure";return ;}s->data=p->data;//填数据域s->next=NULL;//指针域为空rr=ll;//rr链表于储存插入单个节点后保存排序的链表 ll是这个链表的头指针每次从头开始查找插入位置if(select==1{while(rr->next!=NULL&&rr->next->data.age>=p->data.age{rr=rr->next;//指针移至年龄比p所指节点的年龄小的节点位置}if(rr->next==NULL//若新链表ll中的所有节点的年龄都比p大则将p插入末尾rr->next=s;else//否则将该节点插入至第一个年龄比他小的前面{s->next=rr->next;rr->next=s;}p=p->next;//原链表的指针下移一个节点}else if(select==2{while(rr->next!=NULL&&rr->next->data.salary>=p->data.salary{rr=rr->next;}if(rr->next==NULLrr->next=s;else{s->next=rr->next;rr->next=s;}p=p->next;}else Wrong(;}l->next=ll->next;//ll中储存的是已排序的链表的头指针Disp(l;saveflag=1;printf("\n ====>排序完成!\n";}void Save(Link l{FILE*fp;Node *p;int flag=1,count=0;fp=fopen("employee.txt","wb";if(fp==NULL{printf("\n====>提示:重新打开文件时发生错误!\n"; return ;}p=l->next;//指向第一个记录节点while(p{if(fwrite(p,sizeof(Node,1,fp==1//将第一个记录节点值写入文件{p=p->next;//依次写第二个节点的值count++;//文件记录+1}else{flag=0;break;}}if(count>0{printf("\n====>提示:文件保存成功,(有%d条记录已经保存)\n",count; saveflag=0;}else{system("cls";printf("保存文件失败,0条记录被保存!\n";}fclose(fp;}void main({char zhanghao[10],mima[10];char answer1[10]= {"jiutian"},password1[10]= {"20121314"}; char answer2[10]= {"xiaolong"},password2[10]= {"1314520"}; int amg=0;int i,j;printf("请等待";for(i=0; i<15; i++{Sleep(300;printf(".";}printf("\n";while(1{if(amg{break;}printf("请输入用户名:\n";scanf("%s",zhanghao;getchar(;printf("请输入密码:\n";scanf("%s",mima;getchar(;if((strcmp(answer1,zhanghao==0&&strcmp(password1,mima==0||(strcmp(answer2,zhan ghao==0&&strcmp(password2,mima==0{system("cls";Link list;//定义链表FILE *fp;//文件指针int choose;//保存选择结果变量char ch;//保存y/nint count=0;//保存节点个数struct node *p,*r;//定义记录指针变量printf("\t\t\t\t职工信息管理系统\n\t\t\t\t\n";list=(struct node*malloc(sizeof(struct node;if(!list{printf("\n allocate memory failure";//申请空间失败return ;}list->next=NULL;r=list;fp=fopen("employee.txt","rb";if(fp==NULL{printf("\n=====>提示:文件还不存在,是否创建?(y/n)\n"; scanf("%c",&ch;if(ch=='y'||ch=='Y'fp=fopen("employee.txt","ab+";else exit(0;}printf("\n=====>提示:文件已打开,正在导入记录";for(j=0;j<7;j++{Sleep(300;printf(".";}while(!feof(fp//没有到文件尾时循环{p=(struct node*malloc(sizeof(struct node;if(!p{printf("memory malloc failure!\n";exit(0;}if(fread(p,sizeof(struct node,1,fp//读文件的已有内容放入节点中{p->next=NULL;r->next=p;r=p;//将该节点挂入链表中,r指向最后的节点count++;}}fclose(fp;printf("\n=====>提示:记录导入完毕,共导入%d条记录.\n",count; while(1{menu(;printf("\t\t====>请选择:";scanf("%d",&choose;if(choose==0{if(saveflag==1{getchar(;printf("\n====>提示:资料已经改动,是否将改动保存到文件中(y/n?\n"; scanf("%c",&ch;if(ch=='y'||ch=='Y'Save(list;}printf("\n====>提示:你已退出系统,再见!\n";amg=1;break;}switch(choose{case 1:Add(list; break; case 2:Del(list; break; case 3:Qur(list; break; case 4: Modefy(list; break; case 5: Insert(list; break; case 6: Tongji(list; break; case 7: Sort(list; break; case 8: Save(list; break;case 9:system("cls";Disp(list;break;default:Wrong(;getchar(;break;}}}else printf("您的账号或密码错误!请重新输入!\n"; }}。
人员信息管理系统源代码
#include<stdio.h>/*人员信息管理系统*/#include<string.h>#include<malloc.h>#include<stdlib.h>#define Max 10000typedef struct Node{int NO; // 编号char name[30]; // 姓名char sex[10]; // 性别int age; // 年龄char ZhiWu[30]; // 职务char Zhicheng[30]; //职称char ZZMM[30]; // 政治面貌char XueLi[30]; // 最高学历int OnTime; // 任职时间int CTime; // 来院时间char RenLB[30]; // 人员类别}Worker;Worker Q[Max];int top;int cnt = 0;int Insert() //输入人员信息{Worker *q;if( ( q = (Worker *)malloc( sizeof( Worker) ) ) == NULL )exit(0); printf( "请依次输入:编号,姓名,性别,年龄,职务,职称,政治面貌,最高学历,任职时间,来院时间,人员类别\n" );scanf( "%d %s %s %d %s %s %s %s %d %d %s", &(q->NO), q->name, q->sex, &(q->age), q->ZhiWu, q->Zhicheng, q->ZZMM, q->XueLi, &(q->OnTime), &(q->CTime), q->RenLB );Q[top++] = (*q);printf( "已加入\n" );return top;}int Delete() //按编号删除人员信息{int NO;int i, j, ok = 0;printf( "请依次输入: 编号\n" );scanf( "%d", &NO );for( i = 0; i < top; i++ ){if( Q[i].NO ==NO ){for( j = i+1; j < top; j++ ){Q[j-1] = Q[j];}top--;ok = 1;break;}}if( ok == 0 )printf( "无此人\n" );else printf( "已删除\n" );return top;}void Search() //搜索人员信息{int NO;char name[30];int i, ok = 0;Worker *q;printf( "请依次输入: 编号和姓名\n" );scanf( "%d %s", &NO, name );for( i = 0; i < top; i++ ){if( Q[i].NO ==NO && strcmp( Q[i].name, name ) == 0 ) {ok = 1;break;}}q = &(Q[i]);if( ok == 0 )printf( "无此人\n" );else{printf( "该人信息为:\n" );printf( "%d %s %s %d %s %s %s %s %d %d %s\n", (q->NO), q->name, q->sex, (q->age), q->ZhiWu, q->Zhicheng, q->ZZMM, q->XueLi,(q->OnTime), (q->CTime), q->RenLB );}}void Sort(Worker *Q) //按要求进行排序分类{int way,i,j,flag=1;Worker temp;printf( "输入按什么排序:1 --- 年龄; 2 ---- 来院时间\n" );scanf( "%d", &way );if( way == 1 ){for(i=1;i<top&&flag==1;i++){flag=0;for(j=0;j<top-i;j++){if(Q[j].age>Q[j+1].age){flag=1;temp=Q[j];Q[j]=Q[j+1];Q[j+1]=temp;}}for(i=0;i<cnt;i++)printf( "%d %s %s %d %s %s %s %s %d %d %s\n", (Q[i].NO),Q[i].name, Q[i].sex, (Q[i].age),Q[i].ZhiWu, Q[i].Zhicheng, Q[i].ZZMM, Q[i].XueLi, (Q[i].OnTime), (Q[i].CTime), Q[i].RenLB );}}else if( way == 2 ){for(i=1;i<top&&flag==1;i++){flag=0;for(j=0;j<top-i;j++){if(Q[j].CTime>Q[j+1].CTime){flag=1;temp=Q[j];Q[j]=Q[j+1];Q[j+1]=temp;}}for(i=0;i<cnt;i++)printf( "%d %s %s %d %s %s %s %s %d %d %s\n", (Q[i].NO),Q[i].name, Q[i].sex, (Q[i].age),Q[i].ZhiWu, Q[i].Zhicheng, Q[i].ZZMM, Q[i].XueLi, (Q[i].OnTime), (Q[i].CTime), Q[i].RenLB );}for(i=0;i<cnt;i++)printf( "%d %s %s %d %s %s %s %s %d %d %s\n", (Q[i].NO),Q[i].name, Q[i].sex, (Q[i].age),Q[i].ZhiWu, Q[i].Zhicheng, Q[i].ZZMM, Q[i].XueLi, (Q[i].OnTime), (Q[i].CTime), Q[i].RenLB );}}void COUNT_1() //统计在职人数{int i;for( i = 0; i < top; i++ ){if( strcmp( Q[i].RenLB, "退休人员" ) != 0 &&strcmp( Q[i].RenLB, "临时工" ) != 0 ){Worker *q;q = &(Q[i]);cnt++;printf( "%d %s %s %d %s %s %s %s %d %d %s\n", (q->NO), q->name, q->sex, (q->age), q->ZhiWu, q->Zhicheng, q->ZZMM, q->XueLi, (q->OnTime), (q->CTime), q->RenLB );}}printf( "共有%d 在职人数\n", cnt );}void COUNT_2() //统计党员人数{int i;for( i = 0; i < top; i++ ){if( strcmp( Q[i].ZZMM, "党员" ) == 0 ){Worker *q;q = &(Q[i]);cnt++;printf( "%d %s %s %d %s %s %s %s %d %d %s\n", (q->NO), q->name, q->sex, (q->age), q->ZhiWu, q->Zhicheng, q->ZZMM, q->XueLi, (q->OnTime), (q->CTime), q->RenLB );}}printf( "共有%d 党员\n", cnt );}void COUNT_3() // 统计女工人数{int i;for( i = 0; i < top; i++ ){if( strcmp( Q[i].sex, "女" ) == 0 ){Worker *q;q = &(Q[i]);cnt++;printf( "%d %s %s %d %s %s %s %s %d %d %s\n", (q->NO), q->name, q->sex, (q->age), q->ZhiWu, q->Zhicheng, q->ZZMM, q->XueLi, (q->OnTime), (q->CTime), q->RenLB );}}printf( "共有%d 女性员工\n", cnt );}void COUNT_4() //统计高学历人数{int i;for( i = 0; i < top; i++ ){if( strcmp( Q[i].XueLi, "研究生" ) == 0|| strcmp( Q[i].XueLi, "副教授" ) == 0|| strcmp( Q[i].XueLi, "教授" ) == 0|| strcmp( Q[i].XueLi, "院士" ) == 0|| strcmp( Q[i].XueLi, "博士" ) == 0|| strcmp( Q[i].XueLi, "博士后" ) == 0|| strcmp( Q[i].XueLi, "助理教授" ) == 0 ){Worker *q;q = &(Q[i]);cnt++;printf( "%d %s %s %d %s %s %s %s %d %d %s\n", (q->NO), q->name, q->sex, (q->age), q->ZhiWu, q->Zhicheng, q->ZZMM, q->XueLi, (q->OnTime), (q->CTime), q->RenLB );}printf( "共有%d 高学历员工\n", cnt );}void Count() //统计函数{int way;printf( "输入按什么统计:1 --- 在职人数; 2 --- 党员人数;3 --- 女工人数;4 --- 高学历高职称人数: \n" );printf( "输入统计关键字:" );scanf( "%d", &way );switch( way ){case 1: COUNT_1(); break;case 2: COUNT_2(); break;case 3: COUNT_3(); break;case 4: COUNT_4(); break;}}void Edit() // 编辑存储功能{}int main(){int way;top = 0;printf( "\n\n" );printf( "****************************************************************** **\n" );printf( " * 1:添加人员,输入人员相关信息*\n" );printf( " * 2: 删除人员,提供职工号*\n" );printf( " * 3: 查询提供编号和姓名*\n" );printf( " * 4: 统计提供相应方式对应输入*\n" );printf( " * 5: 排序,按程序要求提供相应的关键字*\n" );printf( " * 6: 编辑存储*\n" );printf( "****************************************************************** **\n" );while( 1 ){printf( "输入需要操作:way = " ); // 选择功能if( scanf( "%d", &way ) == EOF )break; // 以 ctrl + Z 结束输入switch(way){case 1: Insert(); break;case 2: Delete(); break;case 3: Search(); break;case 4: Count(); break;case 5: Sort(Q); break;case 6: Edit(); break;}}return 0;}。
职工信息管理系统源代码
#include <malloc.h>#include <stdio.h>#include <string.h>#include <stdlib.h>#define ALLMAX 100 //总共统计的职工的人数typedef struct Node{long int born_date,work_date,tele_num;charsex,name[ALLMAX],degree[ALLMAX],job[ALLMAX],address[ALLMAX];struct Node *next;}SLNode;typedef struct{long int born_date,work_date,tele_num;charname[ALLMAX],sex,degree[ALLMAX],job[ALLMAX],address[ALLMAX];}DataType;void ListInitiate(SLNode **head)//链表初始化{if((*head=(SLNode *)malloc(sizeof(SLNode)))==NULL) exit(1);//动态分配存储空间(*head)->next=NULL;}SLNode *ListInsert(SLNode *head,DataType x)//职工信息的插入姓名并按照升序排列{SLNode *p,*q,*s;p=head->next;if((q=(SLNode *)malloc(sizeof(SLNode)))==NULL) exit(1);//动态分配存储空间q->born_date=x.born_date;q->work_date=x.work_date;q->tele_num=x.tele_num;strcpy(q->name,);q->sex=x.sex;strcpy(q->degree,x.degree);strcpy(q->job,x.job);strcpy(q->address,x.address);if(head->next==NULL){//如果只有链表的头结点,没有其他的结点,直接插入在头结点后面head->next=q;head->next->next=NULL;}else{//链表非空for(;p;p=p->next){if(p->next!=NULL){if(strcmp(p->name,)<0&&strcmp(p->next->name,)>0){//位于两个结点之间s=p->next;p->next=q;q->next=s;break;}//else if(strcmp(p->name,)==0)break; //如果姓名相同则不插入信息}else if(strcmp(p->name,)<0&&p->next==NULL){//链表非空,并且在排序中是最后一个p->next=q;q->next=NULL;break;}if(strcmp(p->name,)>0){//位于链表头结点之后的位置s=head->next;head->next=q;q->next=s;break;}}}return head;}void ListDelete(SLNode *head)//职工信息的删除{SLNode *p,*s;char x[20];s=head;p=head->next;if(head->next==NULL){//链表为空,输出:名单中无职工信息,无须删除!printf("名单中无此职工信息,无须删除!\n");return;}printf("请输入要删除职工的姓名:\n"); //输入要删除的人的姓名scanf("%s",x);for(p;p;p=p->next){//在链表中从头到尾查找输入的人的姓名if(strcmp(p->name,x)==0){ //如果存在,则删除,否则输出:名单中无职工信息,无须删除!s->next=p->next;free(p);printf("删除成功!请继续操作!\n");break;}s=p;}if(p==NULL){//链表本身为空printf("名单中无此职工信息,无须删除!\n");}}void ListModify(SLNode *head)//职工信息的修改{DataType x;SLNode *p;p=head->next;if(p==NULL){//链表本身为空printf("职工名单无职工信息,无须修改!\n");return;}printf("请输入要修改的职工姓名:\n");scanf("%s",);for(;p;p=p->next){if(strcmp(,p->name)==0){//查找到了该职工的信息printf("依次写入该职工的新信息:\n");printf("请输入职工信息:\n姓名、性别、出生年月、工作年月、学历、职务、住址、电话\n");scanf("%s %c %d %d %s %s %s %d",p->name,&p->sex,&p->born_date,&p->work_ date,p->degree,p->job,p->address,&p->tele_num);printf("修改成功!请继续操作!\n");break;}}if(p==NULL)//如果链表为空printf("此职工不存在,无法修改其信息!\n");}void put(SLNode *head,FILE *fp)//职工信息的保存{SLNode *p;if((fp=fopen("Employee.txt","w"))==NULL){//printf("无法打开'Employee.txt'!\n");exit(0);}for(p=head->next;p;p=p->next){fprintf(fp,"%s %c %d %d %s %s %s %d\n",p->name,p->sex,p->born_date,p->work_ date,p->degree,p->job,p->address,p->tele_num);}if(fclose(fp)){printf("无法关闭'Employee.txt'!\n"); exit(0);}}void Listfind(SLNode head)//职工信息的查找{int i,j;SLNode *p;DataType x;if(head.next==NULL){//链表为空printf("名单中无职工信息,查询失败!\n");return;}//返回主菜单printf("\n");printf("\t*********************************\n");printf("\t*职工信息查询操作*\n");printf("\t**\n");printf("\t*0.退出查询系统,回到主菜单\t\t 1.对姓名进行查询\t*\n\t * 2.对出生年月进行查询\t\t 3.对学历进行查询\t*\n\t* 4.对工作年月进行查询\t\t 5.对职务进行查询\t*\n\t* 6.对住址进行查询\t\t 7.对电话进行查询\t*\n");printf("\t*********************************\n");while(1){printf("请输入您要选择的操作:");scanf("%d",&i);if(i==0)//输入0,退出查询系统,回到主菜单break;else if(i==1){//输入1,对姓名进行查询p=head.next;printf("请输入姓名:");scanf("%s",);j=0;for(p;p;p=p->next){if(strcmp(p->name,)==0){//如果存在这个人,那么j自加++j;printf("\n姓名、性别、出生年月、工作年月、学历、职务、住址、电话\n");printf("%s %c %d %d %s %s %s %d\n",p->name,p->sex,p->born_date,p->work_date ,p->degree,p->job,p->address,p->tele_num);}}if(j==0)//表示没有找到输入的信息printf("职工名单中不存在此人!\n");else printf("查询成功!继续操作!\n");}else if(i==2){//输入2,对出生年月进行查询p=head.next;printf("请输入出生年月:");scanf("%d",&x.born_date);j=0;for(p;p;p=p->next){if(p->born_date==x.born_date){//输入的出生年月在链表中存在++j;//如果存在这个人,那么j自加printf("\n姓名、性别、出生年月、工作年月、学历、职务、住址、电话\n");printf("%s %c %d %d %s %s %s %d\n",p->name,p->sex,p->born_date,p->work_date ,p->degree,p->job,p->address,p->tele_num);}}if(j==0)//表示没有找到输入的信息printf("职工名单中没有这个时间出生的!\n");else printf("查询成功!请继续操作!\n");}else if(i==4){//输入4,对工作年月进行查询p=head.next;printf("请输入工作年月:");scanf("%d",&x.work_date);j=0;for(p;p;p=p->next){if(p->work_date==x.work_date){++j;//如果存在这个人,那么j自加printf("\n姓名、性别、出生年月、工作年月、学历、职务、住址、电话\n");printf("%s %c %d %d %s %s %s %d\n",p->name,p->sex,p->born_date,p->work_date ,p->degree,p->job,p->address,p->tele_num);}}if(j==0)//表示没有找到输入的信息printf("职工名单中没有这个时间工作的!\n");else printf("查询成功!请继续操作!\n");}else if(i==3){//输入3,对学历进行查询p=head.next;printf("请输入学历:");scanf("%s",x.degree);j=0;for(p;p;p=p->next){if(strcmp(p->degree,x.degree)==0){++j;//如果存在这个人,那么j自加printf("\n姓名、性别、出生年月、工作年月、学历、职务、住址、电话\n");printf("%s %c %d %d %s %s %s %d\n",p->name,p->sex,p->born_date,p->work_date ,p->degree,p->job,p->address,p->tele_num);}}if(j==0)//表示没有找到输入的信息printf("职工名单中没有这种学历的!\n");else printf("查询成功!请继续操作!\n");}else if(i==5){//输入5,对职务进行查询p=head.next;printf("请输入职务:");scanf("%s",x.job);j=0;for(p;p;p=p->next){if(strcmp(p->job,x.job)==0){++j;//如果存在这个人,那么j自加printf("\n姓名、性别、出生年月、工作年月、学历、职务、住址、电话\n");printf("%s %c %d %d %s %s %s %d\n",p->name,p->sex,p->born_date,p->work_date ,p->degree,p->job,p->address,p->tele_num);}}if(j==0)//表示没有找到输入的信息printf("职工名单中没有这种职务的!\n");else printf("查询成功!请继续操作!\n");}else if(i==6){//输入6,对住址进行查询p=head.next;printf("请输入住址:");scanf("%s",x.address);j=0;for(p;p;p=p->next){if(strcmp(p->address,x.address)==0){++j;//如果存在这个人,那么j自加printf("\n姓名、性别、出生年月、工作年月、学历、职务、住址、电话\n");printf("%s %c %d %d %s %s %s %d\n",p->name,p->sex,p->born_date,p->work_date ,p->degree,p->job,p->address,p->tele_num);}}if(j==0)//表示没有找到输入的信息printf("职工名单中没有住这的!\n");else printf("查询成功!请继续操作!\n");}else if(i==7){//输入7,对电话号码进行查询p=head.next;printf("请输入电话:");scanf("%d",&x.tele_num);j=0;for(p;p;p=p->next){if(p->tele_num==x.tele_num){++j;//如果存在这个人,那么j自加printf("\n姓名、性别、出生年月、工作年月、学历、职务、住址、电话\n");printf("%s %c %d %d %s %s %s %d\n",p->name,p->sex,p->born_date,p->work_date ,p->degree,p->job,p->address,p->tele_num);}}if(j==0)//表示没有找到输入的信息printf("职工名单中没人用这个号码!\n");else printf("查询成功!请继续操作!\n");}else if(i!=0 && i!=1 && i!=2 && i!=3 && i!=4 && i!=5 && i!=6 && i!=7)//输入任意不是上述数字的,那么久显示输入错误printf("输入出错!请再次输入!\n");printf("\n");printf("\t*********************************\n");printf("\t*职工信息查询系统*\n");printf("\t**\n");printf("\t*0.退出查询系统,回到主菜单\t\t 1.对姓名进行查询\t*\n\t* 2.对出生年月进行查询\t\t 3.对学历进行查询\t*\n\t*4.对工作年月进行查询\t\t 5.对职务进行查询\t*\n\t* 6.对住址进行查询\t\t 7.对电话进行查询\t*\n");printf("\t*********************************\n");//printf("0.退出查询系统,回到主菜单\n1.对姓名进行查询\n2.对出生年月进行查询\n3.对工作年月进行查询\n4.对学历进行查询\n5.对职务进行查询\n6.对住址进行查询\n7.对电话号码进行查询\n");}}void print(SLNode *head)//职工信息的显示{SLNode *p;for(p=head->next;p!=NULL;p=p->next)//输出所有职工的信息printf("%s %c %d %d %s %s %s %d\n",p->name,p->sex,p->born_date,p->work_date ,p->degree,p->job,p->address,p->tele_num);}void printLink(SLNode *head)//职工信息的显示{printf("职工名单:\n姓名、性别、出生年月、工作年月、学历、职务、住址、电话\n");print(head);}void Listpaixu(SLNode *head)//职工信息的排序{int i,n=0,m,flag=1;SLNode *p,*q,*s;if(head->next==NULL){//职工链表为空printf("名单中无职工信息,无法排序!\n\n");return;}// printf("输入出错!请再次输入!\n\n");printf("\t\t~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~\n");printf("\t\t~.~ 职工信息排序操作~.~\n");printf("\t\t~.~ ~.~\n");printf("\t\t~.~\t0.退出排序系统,回到主菜单~.~\n\t\t~.~\t1.对性别进行排序~.~\n\t\t~.~\t2.对出生年月进行排序~.~\n\t\t~.~\t3.对工作年月进行排序~.~\n\t\t~.~\t4.对姓名进行排序~.~\n");printf("\t\t~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~\n");while(1){printf("请输入您要选择的操作:");scanf("%d",&i);if(i==0)//输入0,退出排序系统,回到主菜单break;else if(i==1){//输入1,对性别进行排序n=0,m,flag=1;for(p=head;NULL!=p;p=p->next)//统计职工人数n++;for(m=1;flag&&m<=n;m++){flag=0;for(q=head->next,p=head,s=p;q;s=p,p=q,q=q->next){if(p->sex>q->sex)//p为当前节点,p的性别>p的后继节点的性别{if(head==p)//p为头结点{head->next=q->next;head=q;q->next=p;//交换节点信息q=head->next;p=head;}else{p->next=q->next;q->next=p;s->next=q;p=q;q=p->next;}flag=1;}}}printf("排好序的信息如下:\n");printLink(head);//输出所有节点的信息return;}else if(i==2){//输入2,对出生年月进行排序n=0,m,flag=1;for(p=head;NULL!=p;p=p->next)//统计职工人数n++;for(m=1;flag&&m<=n;n++)//循环{flag=0;for(q=head->next,p=head,s=p;q;s=p,p=q,q=q->next){if(p->born_date>q->born_date)//对出生年月进行排序{if(head==p){head->next=q->next;head=q;q->next=p;q=head->next;p=head;}else{p->next=q->next;q->next=p;s->next=q;p=q;q=p->next;}flag=1;}}}printf("排好序的信息如下:\n");printLink(head);return;}else if(i==3){//输入3,按工作时间进行排序n=0,m,flag=1;for(p=head;NULL!=p;p=p->next)n++;for(m=1;flag&&m<=n;n++){flag=0;for(q=head->next,p=head,s=p;q;s=p,p=q,q=q->next){ if(p->work_date>q->work_date){if(head==p){head->next=q->next;head=q;q->next=p;q=head->next;p=head;}else{p->next=q->next;q->next=p;s->next=q;p=q;q=p->next;}flag=1;}}}printf("排好序的信息如下:\n");printLink(head);return;}else if(i==4){n=0,m,flag=1;for(p=head;NULL!=p;p=p->next)n++;for(m=1;flag&&m<=n;n++){flag=0;for(q=head->next,p=head,s=p;q;s=p,p=q,q=q->next){if(p->name[0]>q->name[0]){if(head==p){head->next=q->next;head=q;q->next=p;q=head->next;p=head;}else{p->next=q->next;q->next=p;s->next=q;p=q;q=p->next;}flag=1;}}}printf("排好序的信息如下:\n");printLink(head);return;}else if(i!=0&&i!=1&&i!=2&&i!=3&&i!=4)printf("输入出错!请再次输入!\n\n");printf("\t\t~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~\n");printf("\t\t~.~ 职工信息排序系统~.~\n");printf("\t\t~.~~.~\n");printf("\t\t~.~\t0.退出排序系统,回到主菜单~.~\n\t\t~.~\t1.对性别进行排序~.~\n\t\t~.~\t2.对出生年月进行排序~.~\n\t\t~.~\t3.对工作年月进行排序~.~\n\t\t~.~\t4.显示全部职工信息~.~\n");printf("\t\t~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~\n");//printf("0.退出排序系统,回到主菜单\n1.对性别进行排序\n2.对出生年月进行排序\n3.对工作年月进行排序\n");}}void main(){DataType x;SLNode *head;int i,n;FILE *fp;ListInitiate(&head);//初始化链表printf("\n");printf("*************************************************************** ****************\n");printf("************************ 欢迎使用职工管理系统***************************\n");printf("*************************************************************** ****************\n");printf("请输入要录入的职工人数n:");//输入要录入的职工人数scanf("%d",&n);if(n==0) goto aa;printf("请输入职工信息:\n姓名、性别、出生年月、工作年月、学历、职务、住址、电话\n");for(i=0;i<n;i++)//职工信息的输入{scanf("%s %c %d %d %s %s %s %d",,&x.sex,&x.born_date,&x.work_date,x. degree,x.job,x.address,&x.tele_num);head=ListInsert(head,x);}if((fp=fopen("Employeetxt","a"))==NULL){printf("\t无法打开'Employee.txt'!\n");exit(0);}put(head,fp);if(fclose(fp)){printf("\t无法关闭'Employee.txt'!\n"); exit(0);}printLink(head);aa: printf("\n");printf("\t★☆☆★☆☆★☆☆★★☆☆★☆☆★☆☆★★☆☆★☆☆★☆☆★☆☆★\n");printf("\t☆* 主菜单* ☆\n");printf("\t★********** ★\n");printf("\t☆☆\n");printf("\t★\t0.结束管理系统\t\t\t1.新增职工信息\t\t★\n\t☆\t2.删除职工信息\t\t\t3.查询职工信息\t\t☆\n\t★\t4.修改职工信息\t\t\t5.职工信息排序\t\t★\n");printf("\t☆☆\n");printf("\t★☆☆★☆☆★☆☆★★☆☆★☆☆★☆☆★★☆☆★☆☆★☆☆★☆☆★\n");while(1){printf("请输入您要选择的操作:");scanf("%d",&i);if(i==0)//输入0,结束系统{printf("\t\t您已经成功退出职工管理系统,谢谢使用!\n");break;}else if(i==1){//输入1,新增一名职工printf("请输入职工信息:\n姓名、性别、出生年月、工作年月、学历、职务、住址、电话\n");scanf("%s %c %d %d %s %s %s %d",,&x.sex,&x.born_date,&x.work_date,x. degree,x.job,x.address,&x.tele_num);head=ListInsert(head,x);printf("新增成功!请继续操作!\n");printLink(head);put(head,fp);//保存在文件中else if(i==2){//输入2,删除一名职工ListDelete(head);if((fp=fopen("Employee.txt","w"))==NULL){printf("无法打开'职工名单.txt'!\n");exit(0);}put(head,fp);//保存在文件中if(fclose(fp)){printf("无法关闭'Employee.txt'!\n"); exit(0);}}else if(i==3)//输入3,查找一名职工Listfind(*head);else if(i==4){//输入4,修改职工信息ListModify(head);if((fp=fopen("Employee.txt","w"))==NULL){printf("无法打开'Employee.txt'!\n");exit(0);}put(head,fp);//保存在文件中if(fclose(fp)){printf("无法关闭'Employee.txt'!\n"); exit(0);}}else if(i==5){//输入5,对职工信息进行排序SLNode *p=head;Listpaixu(p);}//如果出入的不是上述任何一种情况就输出:输入出错else printf("输入出错!请再次输入!\n");printf("\n");printf("\t★☆☆★☆☆★☆☆★★☆☆★☆☆★☆☆★★☆☆★☆☆★☆☆★☆☆★\n");printf("\t☆* 主菜单* ☆\n");printf("\t★********** ★\n");printf("\t☆☆\n");printf("\t★0.结束管理系统\t\t\t\t1.新增职工信息\t★\n\t☆ 2.删除职工信息\t\t\t\t3.查询职工信息\t☆\n\t★ 4.修改职工信息\t\t\t\t5.职工信息排序\t★\n");printf("\t☆☆\n");printf("\t★☆☆★☆☆★☆☆★★☆☆★☆☆★☆☆★★☆☆★☆☆★☆☆★☆☆★\n");//printf("0.结束系统\n1.新增一名职工\n2.删除一名职工\n3.查询职工信息\n4.修改职工信息\n5.对职工信息进行排序\n");}}。
职工信息管理系统源代码
#include <stdio.h>#include <string.h>#include <stdlib.h>#include<conio.h>struct Date /*日期*/{int year;int month;int day;};struct Info{char num[15]; /*职工号*/char name[15]; /*姓名*/char sex[10]; /*性别*/struct Date birthday; /*出生年月*/char education[10]; /*学历*/char duty[15]; /*职务*/double wage; /*工资*/char addr[30]; /*地址*/char phone[15]; /*电话*/};/*************************菜单选择函数******************************/ char menu(){char n; /*n记录选择的菜单*/int system(const char *string); /*清屏*/system("cls"); /*清屏*/puts("\t\t 欢迎使用职工信息管理系统");puts("\t\t*********************MENU*******************\n");puts("\t\t\t\t1. 职工信息录入功能\n");puts("\t\t\t\t2. 职工信息浏览功能\n");puts("\t\t\t\t3. 职工信息查询功能\n");puts("\t\t\t\t4. 职工信息修改功能\n");puts("\t\t\t\t5. 职工信息删除功能\n");puts("\t\t\t\t6. 退出\n");puts("\t\t********************************************\n");printf("选择你要使用的功能(1-6):[ ]\b\b");while(1){n=getchar();getchar();if(n<'1'||n>'6')printf("输入错误,请重新选择你要使用的功能(1-6):[ ]\b\b");elsebreak;}return n;}/****************************信息输入函数****************************/void append(){struct Info info;FILE * fp;char ch;char temp[10];if((fp=fopen("inform.txt","ab"))==NULL){printf("\t文件打开错误!");getch();exit(1);}do{printf("\t号码:");gets(info.num);printf("\t姓名:");gets();printf("\t性别:");gets(info.sex);printf("\t出生日期(yyyy/mm/dd):");scanf("%d/%d/%d",&info.birthday.year,&info.birthday.month,&info.birthday.day);getchar();printf("\t学历:");gets(cation);printf("\t职务:");gets(info.duty);printf("\t工资:");gets(temp); info.wage=atof(temp);printf("\t地址:");gets(info.addr);printf("\t电话:");gets(info.phone);fwrite(&info,sizeof(info),1,fp);printf("\t还有更多的吗?(Y/N):[ ]\b\b");ch=getchar();getchar();}while(ch=='Y'||ch=='y');fclose(fp);}void print1(){printf("%-10s%-10s%-10s%-12s%-10s%-10s%-15s%-30s%-15s%\n","号码","姓名","性别","出生日期","学历","职务","工资","地址","电话");}void print2(struct Info info){;printf("%-10s%-10s%-10s",info.num,,info.sex);printf("%-4d/%-2d/%-4d",info.birthday.year,info.birthday.month,info.birthday.day);printf("%-10s%-10s%-15.2lf",cation,info.duty,info.wage);printf("%-30s%-15s\n",info.addr,info.phone);}/***********************职工信息显示函数**************************/ void display(){struct Info info;FILE * fp;int total=0;if((fp=fopen("inform.txt","rb"))==NULL){printf("\t文件打开错误!");getch();exit(1);}while(fread(&info, sizeof(info),1,fp)==1){total++;if(total==1)print1();print2(info);if((total!=0)&&(total%10==0)){printf("\n\n\t按任意键继续。
Java实现简单员工管理系统
Java实现简单员⼯管理系统本⽂实例为⼤家分享了Java实现简单员⼯管理系统的具体代码,供⼤家参考,具体内容如下代码如下:import java.util.*;public class Demo {public static void main(String[] args) {EmpManage em = new EmpManage();while (true) {System.out.println("==================员⼯管理系统====================");System.out.println("==================0.加载原有信息==================");System.out.println("==================1.加⼊员⼯=====================");System.out.println("==================2.删除员⼯=====================");System.out.println("==================3.查询员⼯信息==================");System.out.println("==================4.修改员⼯薪⽔ ==================");System.out.println("==================5.薪⽔排序======================");System.out.println("==================6.平均⼯资、最低与最⾼⼯资=======");System.out.println("==================7.打印全体员⼯信息==============");System.out.println("==================8.退出系统=====================");System.out.print("请选择功能【0~8】:");Scanner reader = new Scanner(System.in);int x;x = reader.nextInt();switch (x) {case 0:Employee e1 = new Employee("2001","轩辕⼽",2002f);Employee f = new Employee("2002","季长风",4500f);Employee g = new Employee("2003","鱼幼薇",2560f);Employee h = new Employee("2004","李⼩龙",1604f);em.addEmp(e1);em.addEmp(f);em.addEmp(g);em.addEmp(h);System.out.println("加载完毕!");break;case 1:System.out.println("请输⼊要增加员⼯的信息(编号,姓名,薪⽔中间⽤空格隔开)");String a, b;float c;a = reader.next();b = reader.next();c = reader.nextFloat();Employee e = new Employee(a, b, c);em.addEmp(e);System.out.println("加⼊成功!");break;case 2:System.out.print("请输⼊要刪除員⼯的编号:");String y;y=reader.next();em.deleteEmp(y);System.out.println("删除成功!");break;case 3:System.out.print("请输⼊要查询員⼯的编号:");String z;z=reader.next();em.showinfo(z);break;case 4:System.out.print("请输⼊要修改員⼯的编号:");String w;w=reader.next();System.out.print("请输⼊要修改成的⼯资数⽬:");float v;v=reader.nextFloat();em.changesal(w, v);System.out.println("修改成功!");break;case 5:System.out.println("1.按薪⽔从⾼到低的顺序排序");System.out.println("2.按薪⽔从低到⾼的顺序排序");System.out.print("请选择功能【1~2】:");int t;t=reader.nextInt();if(t==1){em.sorthl();}if(t==2){em.sortlh();}break;case 6:em.hlsal();break;case 7:em.showAll();break;case 8:System.out.println("程序已经运⾏结束,下次见!");System.exit(0);break;default:System.out.print("数字范围只能在1~8之间!");}}}}//雇员管理类class EmpManage{private ArrayList al=null;//构造⽅法public EmpManage() {al=new ArrayList();}//加⼊员⼯⽅法public void addEmp(Employee e){al.add(e);}//刪除员⼯public void deleteEmp(String x){int i;for(i=0;i<al.size();i++){Employee temp=(Employee)al.get(i);if(temp.getEmNo().equals(x))break;}al.remove(i-1);}//根据员⼯号显⽰该员⼯的信息public void showinfo(String emNo){//遍历整个ArrayListfor(int i=0;i<al.size();i++){Employee em=(Employee)al.get(i);if(em.getEmNo().equals(emNo)){System.out.println("编号:"+em.getEmNo()+" "+"姓名:"+em.getName()+" "+"⼯资:"+em.getSal()); }}}//修改员⼯的薪⽔public void changesal(String x,float y){for(int i=0;i<al.size();i++){Employee em=(Employee) al.get(i);if(em.getEmNo().equals(x)){em.setSal(y);}}}//根据员⼯的薪⽔进⾏排序(从⾼到低) public void sorthl(){String a,b;float c;for(int i=0;i<al.size()-1;i++){Employee e=(Employee)al.get(i);for(int j=i+1;j<al.size();j++){Employee m=(Employee)al.get(j); if(e.getSal()<m.getSal()){a=e.getEmNo();e.setEmNo(m.getEmNo());m.setEmNo(a);b=e.getName();e.setName(m.getName());m.setName(b);c=e.getSal();e.setSal(m.getSal());m.setSal(c);}}}System.out.println("排序成功!");System.out.println("打印信息如下:"); showAll();}//根据员⼯的薪⽔进⾏排序(从低到⾼) public void sortlh(){String a,b;float c;for(int i=0;i<al.size()-1;i++){Employee e=(Employee)al.get(i);for(int j=i+1;j<al.size();j++){Employee m=(Employee)al.get(j); if(e.getSal()>m.getSal()){a=e.getEmNo();e.setEmNo(m.getEmNo());m.setEmNo(a);b=e.getName();e.setName(m.getName());m.setName(b);c=e.getSal();e.setSal(m.getSal());m.setSal(c);}}}System.out.println("排序成功!");System.out.println("打印信息如下:"); showAll();}//平均⼯资、最⾼与最低⼯资public void hlsal(){float x=0,h,l=0;for(int i=0;i<al.size();i++){Employee e=(Employee)al.get(i);x=x+e.getSal();}System.out.println("平均⼯资:"+x/al.size());Employee s=(Employee)al.get(0);h=s.getSal();l=s.getSal();for(int i=0;i<al.size();i++){Employee v=(Employee)al.get(i);if(v.getSal()>h)h=v.getSal();if(v.getSal()<l)l=v.getSal();}System.out.println("最⾼⼯资:"+h);System.out.println("最低⼯资:"+l);}//显⽰所有员⼯的信息public void showAll(){for(int i=0;i<al.size();i++){Employee em=(Employee)al.get(i);System.out.println("第"+(i+1)+"个员⼯: "+"编号:"+em.getEmNo()+" "+"姓名:"+em.getName()+" "+"⼯资:"+em.getSal()); }}}//员⼯类class Employee {private String emNo;private String name;private float sal;// 构造⽅法public Employee(String emNo, String name, float sal) {super();this.emNo = emNo; = name;this.sal = sal;}// 所有的getter和setter⽅法public String getEmNo() {return emNo;}public void setEmNo(String emNo) {this.emNo = emNo;}public String getName() {return name;}public void setName(String name) { = name;}public float getSal() {return sal;}public void setSal(float sal) {this.sal = sal;}}运⾏⽰例:以上就是本⽂的全部内容,希望对⼤家的学习有所帮助,也希望⼤家多多⽀持。
简单的员工信息管理系统源码
据库连接3.查询4.增、5删6改(操作数据库)import .*;import .*;import .*;import .*;public class EmpManageSys implements ActionListener { Connection con;Statement stmt;String sql;ResultSet rs;StringBuffer sb = new StringBuffer();JTextField jtf2 = new JTextField("张飞",10);JTextField jtf3 = new JTextField(10);JTextField jtf4 = new JTextField(10);JTextField jtf7 = new JTextField(10);JTextField jtf5 = new JTextField(10);JTextField jtf6 = new JTextField(10);JTextField jtf8 = new JTextField(10);JTextField jtf9 = new JTextField(10);JTextArea jta10 = new JTextArea(50, 40);public void actionPerformed(ActionEvent e) {String str = ();if ("查询".equals(str)) {quals(str)) {quals(str)) {quals(str)) {EmpManageSys() {createGUI();connectToDataBase();public Connection connectToDataBase() { con = ();(con);return con;}public void searchEmp() {("");try {stmt = ();oLowerCase().trim() + "or id="+ ().toLowerCase().trim() + "or engName=" + ().toLowerCase().trim() + "or UNIT="+ ().toLowerCase().trim() + "or TEAM="+ ().toLowerCase().trim() + "or Phone="+ ().toLowerCase().trim() + "or region="+ ().toLowerCase().trim() + "or busStation=" + ().toLowerCase().trim();(sql);rs = ();ResultSetMetaData meta = ();int cols = ();while ()) {for (int i = 1; i <= cols; i++) {(" " + (i) + " =");(i));}("\n");());}} catch (SQLException e11) {();}}public void addEmp() {try {stmt = ();sql = "update Mstar values(" + () + ()+ () + () + ()+ () + () + () + ")";int i = ();if (() != null) && () != null)&& () != null) && () != null)) {(sql);("添加记录成功" + i + "条");} else {("带*号项为添加记录时不能为空");}} catch (SQLException e1) {();}}public void deleteEmp() {searchEmp();try {stmt = ();sql = "delete from Mstar where chineseName=" + ().toLowerCase().trim() + "or id="+ ().toLowerCase().trim() + "or engName="+ ().toLowerCase().trim() + "or UNIT="+ ().toLowerCase().trim() + "or TEAM="+ ().toLowerCase().trim() + "or Phone="+ ().toLowerCase().trim() + "or region="+ ().toLowerCase().trim() + "or busStation=" + ().toLowerCase().trim();(sql);int i = ();("撤除操作成功" + i + "条");} catch (SQLException e) {();}}public void alterEmp() {searchEmp();sql = "update Mstar set chineseName="+ ().toLowerCase().trim() + "and id="+ ().toLowerCase().trim() + "and engName=" + ().toLowerCase().trim() + "and UNIT="+ ().toLowerCase().trim() + "and TEAM="+ ().toLowerCase().trim() + "and Phone="+ ().toLowerCase().trim() + "and region="+ ().toLowerCase().trim() + "and busStation="+ ().toLowerCase().trim();int i = 0;try {(sql);i = ();} catch (SQLException e) {();}("修改操作成功" + i + "条");}public void createGUI() {JFrame jf = new JFrame("员工信息管理系统"); (new GridLayout(2, 1));;public class JdbcUtil{//load driver from filestatic{try{String driverName ="";(driverName);}catch(Exception e){();}}//establish connectionpublic static Connection getConnection(){Connection con = null;try{String url ="jdbc:oracle:thinString usr = "openlab";String pwd = "open123";con = (url,usr,pwd);}catch(Exception e){();}return con;}//close resultSet,statement and connectionpublic static void close(ResultSet rs,Statement stmt,Connection con){try{if(rs!=null) ();}catch(Exception ex){ ();}try{if(stmt!=null) ();}catch(Exception ex){ ();}try{if(con!=null) ();}catch(Exception ex){ ();}}}。
企业人事管理系统java源代码
企业⼈事管理系统java源代码import java.awt.* ;import java.awt.event.*;import java.sql.*;import java.util.*;import javax.swing.*;import javax.swing.border.*;public class A extends JFrame{protected JPanel p = new JPanel();protected JPanel p1 = new JPanel();protected JPanel p2 = new JPanel();protected JPanel p3= new JPanel();JMenuBar M =new JMenuBar();JMenu m1 = new JMenu("基本信息模块");JMenu m2 = new JMenu("考勤考评信息模块");JMenu m3 = new JMenu("系统维护信息模块");JMenuItem mm1 = new JMenuItem("员⼯基本信息"); JMenuItem mm2 = new JMenuItem("员⼯家庭成员基本信息"); JMenuItem mm3 = new JMenuItem("员⼯培训信息"); JMenuItem mm4 = new JMenuItem("员⼯考勤信息"); JMenuItem mm5 = new JMenuItem("员⼯考评信息"); JMenuItem mm6 = new JMenuItem("普通管理员"); JMenuItem mm7 = new JMenuItem("⾼级管理员"); JMenuItem mm8 = new JMenuItem("退出");protected JLabel l1 = new JLabel("员⼯编号:");protected JLabel l2 = new JLabel("姓名:");protected JLabel l3 = new JLabel("性别:");protected JLabel l4 = new JLabel("年龄:");protected JLabel l5 = new JLabel("部门:");protected JTextField t1 = new JTextField(10);protected JTextField t2 = new JTextField(10);protected JTextField t3 = new JTextField(10);protected JTextField t4 = new JTextField(10);protected JTextField t5 = new JTextField(10);private JButton b1 = new JButton("查询");private JButton b2 = new JButton("插⼊");private JButton b3 = new JButton("修改");private JButton b4 = new JButton("删除");private JButton b5 = new JButton("清除");private JButton b6 = new JButton("下⼀条");private Connection c; // @jve:decl-index=0:private Statement s; // @jve:decl-index=0:private ResultSet r; // @jve:decl-index=0:{super("⼈事管理系统");getContentPane().add(p);setJMenuBar(M);M.add(m1);M.add(m2);M.add(m3);m1.add(mm1);m1.add(mm2);m1.add(mm3);m1.addSeparator();m1.add(mm8);m2.add(mm4);m2.add(mm5);m3.add(mm6);m3.add(mm7);p.add(p1,BorderLayout.NORTH);p.add(p2,BorderLayout.CENTER);p.add(p3,BorderLayout.SOUTH);p1.setLayout(new GridLayout(5,2,1,3));p1.add(l1);p1.add(t1);p1.add(l2);p1.add(t2);p1.add(l3);p1.add(t3);p1.add(l4);p1.add(t4);p1.add(l5);p1.add(t5);p2.add(b1);p1.add(b2);p2.add(b3);p1.add(b4);p2.add(b5);p3.add(b6);t1.setText("");t2.setText("");t3.setText("");t4.setText("");t5.setText("");setSize(350,300);setVisible(true);try{Class.forName("sun.jdbc.odbc.JdbcOdbcDrive");c=DriverManager.getConnection("jdbc:odbc:sd","sa",null);s=c.createStatement();r=s.executeQuery("select * from 员⼯基本信息表");}catch (SQLException e){JOptionPane.showMessageDialog(null ,e.getMessage(),"操作错误!",JOptionPane.ERROR_MESSAGE); System.exit(1);}catch(ClassNotFoundException e)JOptionPane.showMessageDialog(null ,e.getMessage(),"驱动程序找不到!",JOptionPane.ERROR_MESSAGE); System.exit(1);}addWindowListener( new WindowAdapter(){public void windowClosing(WindowEvent event){try {s.close();c.close();catch(SQLException e){JOptionPane.showMessageDialog(null,e.getMessage(),"不能关闭!",JOptionPane.ERROR_MESSAGE); System.exit(1);}}});b1.addActionListener(new ActionListener(){public void actionPerformed(ActionEvent event){try{r=s.executeQuery("select * from 员⼯基本信息表" + "where 员⼯编号='"+t1.getText()+"'");if(r.next()){t1.setText(r.getString(1));t2.setText(r.getString(2));t3.setText(r.getString(3));t4.setText(r.getString(4));t5.setText(r.getString(5));JOptionPane.showMessageDialog(null,"查询成功!","查询操作",JOptionPane.ERROR_MESSAGE);}else{t2.setText("");t3.setText("");t4.setText("");t5.setText("");JOptionPane.showMessageDialog(null,"查询失败!","查询操作",JOptionPane.ERROR_MESSAGE);}catch(NumberFormatException e){System.out.println(e);}catch(SQLException e){System.out.println(e);}});b2.addActionListener(new ActionListener(){public void actionPerformed(ActionEvent event){String v1,v2,v3,v4,v5;v1=t1.getText();v2=t2.getText();v3=t3.getText();v4=t4.getText();v5=t5.getText();if((!v1.equals( "" ))&&(!v2.equals(""))&&(!v3.equals(""))&&(!v4.equals(""))&&(!v5.equals (""))){try{int n1 = Integer.parseInt(v4);int r1 = s.executeUpdate("INSERT INTO 员⼯基本信息表"+ "values('"+v1+"','"+v2+"','"+v3+"',"+n1+",'"+v5+"')"); if(r1!=0){t1.setText("");t2.setText("");t3.setText("");t4.setText("");t5.setText("");JOptionPane.showMessageDialog(null,"插⼊成功!","插⼊操作",JOptionPane.ERROR_MESSAGE);}}catch (NumberFormatException e ){System.out.println(e);}catch (SQLException e){System.out.println(e);}}else{JOptionPane.showMessageDialog(null,"插⼊失败!","插⼊操作",JOptionPane.ERROR_MESSAGE);}}});b3.addActionListener(new ActionListener(){public void actionPerformed(ActionEvent event)try {int r1=s.executeUpdate("update 员⼯基本信息表set 姓名='"+t2.getText()+"'," +"性别='"+t3.getText()+"'," +"年龄="+Integer.parseInt(t4.getText())+"," +"部门='"+t5.getText()+"'"+"where 员⼯编号='"+t1.getText()+"'");if(r1!=0){JOptionPane.showMessageDialog(null,"修改成功!","修改操作",JOptionPane.ERROR_MESSAGE);}else{JOptionPane.showMessageDialog(null,"修改失败!","修改操作",JOptionPane.ERROR_MESSAGE);}} catch (NumberFormatException e ){System.out.println(e);}catch (SQLException e){System.out.println(e);}}});b4.addActionListener(new ActionListener(){public void actionPerformed(ActionEvent event){try{int r1=s.executeUpdate("delete from 员⼯基本信息表"+"where 员⼯编号='"+t1.getText()+"'");if(r1!=0){t1.setText("");t2.setText("");t3.setText("");t4.setText("");t5.setText("");JOptionPane.showMessageDialog(null,"删除成功!","删除操作",JOptionPane.ERROR_MESSAGE);}else{JOptionPane.showMessageDialog(null,"删除失败!","删除操作",JOptionPane.ERROR_MESSAGE);}} catch (NumberFormatException e ){System.out.println(e);}catch (SQLException e){System.out.println(e);}}});b5.addActionListener(new ActionListener(){public void actionPerformed(ActionEvent event){t1.setText("");t2.setText("");t3.setText("");t4.setText("");t5.setText("");}});b6.addActionListener(new ActionListener(){public void actionPerformed(ActionEvent event){try{if(r.next())t1.setText(r.getString(1));t2.setText(r.getString(2));t3.setText(r.getString(3));t4.setText(""+r.getInt(4));t5.setText(r.getString(5));}catch (NumberFormatException e ){System.out.println(e);} catch (SQLException e){System.out.println(e);}}});mm8.addActionListener(new ActionListener(){public void actionPerformed(ActionEvent event){System.exit(0);}});}public static void main(String args[]){new A();}}。
公司人员管理系统源代码
公司人员管理系统源代码#include#include#include#include//全局数据,对象double ManagerSalary; //经理固定月薪double SalesManagerSalary; //销售经理固定月薪double SalesManagerPercent; //销售经理提成%double SalesPercent; //销售人员提成%double WagePerHour; //技术人员小时工资int ID; //员工标识(要保证唯一)class Person //员工类{protected:int No; //编号char Name[20]; //姓名int Duty; //岗位double Earning; //收入Person *next;public:Person(char ID,char *Name,int Duty){this->Duty=Duty;strcpy(this->Name,Name);this->No=ID;}virtual void CalcSalary()=0;virtual void Output()=0;friend class Company;};class Manager:public Person //经理类{public:Manager(char ID,char *Name,int Duty):Person(ID,Name,Duty){}void CalcSalary(){Earning=ManagerSalary;}void Output(){CalcSalary();cout<<no<<"\t"<<name<<"\t经理\t"<<earning<<endl;}};class SalesManager:public Person //销售经理类{private:double Amount;public:SalesManager(char ID,char *Name,int Duty):Person(ID,Name,Duty){}void SetAmount(double s){Amount=s;}void CalcSalary(){Earning=SalesManagerSalary+Amount*SalesManagerPerce nt/100;}void Output(){CalcSalary();cout<<no<<"\t"<<name<<"\t销售经理\t"<<earning<<endl;}};class Technician:public Person //技术员类{private:double t;public:Technician(char ID,char *Name,int Duty,double T):Person(ID,Name,Duty){this->t=T;}double GetT(){return t;}void SetT(double T){this->t=T;}{Earning=WagePerHour*t;}void Output(){CalcSalary();cout<<no<<"\t"<<name<<"\t技术员\t"<<t<<"\t"<<earning<<endl;}};class Sales:public Person //销售员类{private:double Amount;public:Sales(char ID,char *Name,int Duty,double Amount):Person(ID,Name,Duty){this->Amount=Amount;}double GetAmount(){return Amount;}void SetAmount(double Amount){this->Amount=Amount;}{Earning=SalesPercent/100*Amount;}void Output(){CalcSalary();cout<<no<<"\t"<<name<<"\t销售员\t"<<amount<<"\t"<<earning<<endl;}};class Company //公司类{private:Person *Worker; //员工表void Clear(); //清除内存中数据public:Company(){Worker=0;Load();}~Company(){Person *p;p=Worker;while(p){p=p->next;delete Worker;Worker=p;}Worker=0;}void Add(); //增加人员void Delete(); //删除人员void Modify(); //修改人员void Query(); //查询人员void Set(); //基础数据设置void Save(); //数据存盘(包括基础数据,人员数据)void Load(); //数据装入(包括基础数据,人员数据)};void Company::Clear() //清除内存中人员数据(内部使用) {Person* p=Worker;while(p){Worker=p->next;delete p;p=Worker;}}void Company::Add(){Person *p; //新结点指针int Duty;char Name[20</no<<"\t"<<name<<"\t销售员\t"<<amount<<"\t"<<earning<<endl;</no<<"\t"<<name<<"\t技术员\t"<<t<<"\t"<<earning<<endl;</no<<"\t"<<name<<"\t销售经理\t"<<earning<<endl;</no<<"\t"<<name<<"\t经理\t"<<earning<<endl;];double Amount,T;cout<<"\n** 新增员工 **\n";//输入员工信息ID++;cout<<"输入岗位(1-经理2-销售经理3-销售员4-技术员):"; cin>>Duty;cout<<"输入姓名:"; cin>>Name;if(Duty==3){cout<<"本月销售额:"; cin>>Amount;}else if(Duty==4){cout<<"本月工作小时数(0-168):";cin>>T;}//创建新员工结点switch(Duty){case 1:p=new Manager(ID,Name,Duty); break; case 2:p=new SalesManager(ID,Name,Duty); break; case 3:p=new Sales(ID,Name,Duty,Amount); break; case 4:p=new Technician(ID,Name,Duty,T); break; }p->next=0;//员工结点加入链表if(Worker) //若已经存在结点{Person *p2;p2=Worker;while(p2->next) //查找尾结点{p2=p2->next;}p2->next=p; //连接}else //若不存在结点(表空){Worker=p; //连接}}void Company::Delete() //删除人员{int No;cout<<"\n** 删除员工 **\n";cout<<"ID:"; cin>>No;//查找要删除的结点Person *p1,*p2; p1=Worker;while(p1){if(p1->No==No)break;else{p2=p1;p1=p1->next;}}//删除结点if(p1!=NULL)//若找到结点,则删除{if(p1==Worker) //若要删除的结点是第一个结点{Worker=p1->next;delete p1;}else //若要删除的结点是后续结点{p2->next=p1->next;delete p1;}cout<<"找到并删除\n";}else //未找到结点cout<<"未找到!\n";}void Company::Modify(){int No,Duty;char Name[20];double Amount,T;cout<<"\n** 修改员工 **\n";cout<<"ID:"; cin>>No;//查找要修改的结点Person *p1,*p2; p1=Worker;while(p1){if(p1->No==No)break;else{p2=p1;p1=p1->next;}}//修改结点if(p1!=NULL)//若找到结点{p1->Output();cout<<"调整岗位(1-经理2-销售经理3-销售员4-技术员):";cin>>Duty;if(p1->Duty!=Duty) //若岗位发生变动{//修改其它数据cout<<"输入姓名:"; cin>>Name;if(Duty==3){cout<<"本月销售额:"; cin>>Amount;}else if(Duty==4){cout<<"本月工作小时数(0-168):";cin>>T;}//创建新员工结点Person *p3;switch(Duty){case 1:p3=new Manager(p1->No,Name,Duty); break;case 2:p3=new SalesManager(p1->No,Name,Duty); break;case 3:p3=new Sales(p1->No,Name,Duty,Amount); break;case 4:p3=new Technician(p1->No,Name,Duty,T); break;}//员工结点替换到链表p3->next=p1->next;if(p1==Worker) //若要替换的结点是第一个结点Worker=p3;else //若要删除的结点是后续结点p2->next=p3;//删除原来的员工结点delete p1;}else //若岗位没有变动{cout<<"输入姓名:"; cin>>p1->Name;if(Duty==3){cout<<"本月销售额:";cin>>Amount; ((Sales *)p1)->SetAmount(Amount);}else if(Duty==4){cout<<"本月工作小时数(0-168):";cin>>T; ((T echnician *)p1)->SetT(T);}}cout<<"修改成功!\n";}else //未找到结点cout<<"未找到!\n";}void Company::Query(){cout<<"\n** 查询人员本月销售信息 **\n";double sum=0; //销售额总和Person *p=Worker;while(p){if(p->Duty==3)sum+=((Sales *)p)->GetAmount();p=p->next;}p=Worker;double sum2=0; //工资总和while(p){if(p->Duty==2)((SalesManager *)p)->SetAmount(sum);p->Output();sum2+=p->Earning;p=p->next;}cout<<"本月盈利:"<<sum*0.20-sum2<<endl;cout<<"(按照20%利润计算)\n";}void Company::Set(){cout<<"\n** 设置基础数据 **\n";cout<<"经理固定月薪["<<managersalary<<"元]:"; cin>>ManagerSalary;cout<<"销售经理固定月薪["<<salesmanagersalary<<"元]:"; cin>>SalesManagerSalary;cout<<"销售经理提成["<<salesmanagerpercent<<"%]:";cin>>SalesManagerPercent;cout<<"销售人员提成["<<salespercent<<"%]:";cin>>SalesPercent;cout<<"技术人员小时工资["<<wageperhour<<"(元cin>>WagePerHour;cout<<"员工标识[>="<<id<<"]:";cin>>ID;}void Company::Save() //数据存盘(包括基础数据,人员数据),均采用文本文件{ofstream fPerson,fBase;char c;cout<<"\n保存人员和基础数据,是否继续?[Y/N]:"; cin>>c;if(toupper(c)!='Y')return;//保存人员编号、姓名、岗位fPerson.open("person.txt",ios::out);Person *p=Worker;while(p){fPerson<No<<"\t"<Name<<"\t"<Duty<<"\t";if(p->Duty==3)fPerson<<((Sales*)p)->GetAmount()<<"\t";else if(p->Duty==4)fPerson<<((Technician *)p)->GetT()<<"\t";fPerson<<endl;p=p->next;}fPerson.close();//保存基础数据fBase.open("base.txt",ios::out);fBase<<"经理固定月薪\t"<<managersalary<fBase<<"销售经理固定月薪\t"<<salesmanagersalary< fBase<<"销售经理提成%\t"<<salesmanagerpercent< fBase<<"销售人员提成%\t"<<salespercent<fBase<<"技术人员小时工资\t"<<wageperhour<fBase<<"ID\t"<<id<<endl;fPerson.close();cout<<"\n保存人员和基础数据已经完成...\n";}void Company::Load() //数据装入(包括基础数据,人员数据) {//基础数据装入ifstream fBase;char buf[80]; //buf用于保存数据文件中的注释字符串fBase.open("base.txt",ios::in);fBase>>buf>>ManagerSalary; //经理固定月薪fBase>>buf>>SalesManagerSalary; //销售经理固定月薪fBase>>buf>>SalesManagerPercent; //销售经理提成%fBase>>buf>>SalesPercent; //销售人员提成%fBase>>buf>>WagePerHour; //技术人员小时工资fBase>>buf>>ID; //员工标识fBase.close();//清除内存人员数据Clear();//人员数据数据装入ifstream fPerson;Person *p=Worker;int No; char Name[20]; int Duty;double Amount,T;fPerson.open("person.txt",ios::in);//读一条记录fPerson>>No>>Name>>Duty;if(Duty==3)fPerson>>Amount;else if(Duty==4)fPerson>>T;while(fPerson.good()){//创建员工结点switch(Duty){case 1:p=new Manager(No,Name,Duty); break;case 2:p=new SalesManager(No,Name,Duty); break;case 3:p=new Sales(No,Name,Duty,Amount); break;case 4:p=new Technician(No,Name,Duty,T); brea</id<<endl;</wageperhour<</salespercent<</salesmanagerpercent< </salesmanagersalary<</managersalary<</endl;</id<<"]:";</wageperhour<<"(元></salespercent<<"%]:";</salesmanagerpercent<<"%]:";</salesmanagersalary<<"元]:";></managersalary<<"元]:"; </sum*0.20-sum2<<endl;k;}p->next=0;//员工结点加入链表if(Worker) //若已经存在结点{Person *p2;p2=Worker;while(p2->next) //查找尾结点{p2=p2->next;}p2->next=p; //连接}else //若不存在结点(表空){Worker=p; //连接}//读下一条记录fPerson>>No>>Name>>Duty;if(Duty==3)fPerson>>Amount;else if(Duty==4)fPerson>>T;}fPerson.close();cout<<"\n人员和基础数据已经装入...\n";void main(){char c;Company a;do{cout<<"\n*** 公司人员管理系统 ***\n"; cout<<"1-增加人员\n";cout<<"2-删除人员\n";cout<<"3-修改人员\n";cout<<"4-查询本月经营信息\n"; cout<<"5-基础数据设置\n";cout<<"6-数据存盘\n";cout<<"7-数据装入\n";cout<<"8-退出\t请选择(1-8):";cin>>c;switch(c){case '1': a.Add(); break;case '2': a.Delete();break;case '3': a.Modify();break;case '4': a.Query(); break;case '5': a.Set(); break;case '6': a.Save(); break;case '7': a.Load(); break;}}while(c!='8');。
人力资源管理系统应用开发纯java实现的java源代码和存在问题
结果:正常编译main方法。
2、JDBC的驱动没有加载
问题:编译时报错:This is main()ng.ClassNotFoundException:
}
rs.close();
pstmt.close();
}
}
3、数据库连接程序DbConn.java
import java.sql.*;
public class DbConn{
private static Connection conn=null;
private static String url="jdbc:oracle:thin:@localhost:1521:orcl";
while (rs.next()) {
/*Vector curEmployee = new Vector();
curEmployee.addElement(rs.getInt("employee_id"));
curEmployee.addElement(rs.getString("first_name"));
oracle.jdbc.driver.OracleDriver
分析:是JDBC的驱动没有加载。因为已经安装了Oracle 11g,系统中应该有该文件,
所以在Windows环境下进行搜索,找到该文件:
D:\app\Administrator\product\11.2.0\dbhome_1\jdbc\lib\ojdbc6.jar
conn=DriverManager.getConnection(url,username,password);
职工信息管理系统java源代码
package exercise;.;class staffInfo入职工信息★★★┃";"┃★★★2.预览职工信息★★★┃";"┃★★★3.查找职工信息★★★┃";"┃★★★4.删除职工信息★★★┃";"┃★★★ 5.读取已存数据★★★┃";"┃★★★6.安全退出系统★★★┃";"┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛"; "请输入您需要的功能代号1--6:";choice=;switch choice{case1:creatstaffOne;break;case2:outputstaffOne;break;case3:searchstaffOne;break;case4:deletestaffOne;break;case5:readstaffOne;break;case6:savestaffOne;break;}}while choice=0;}void creatstaffInfostaffOne throws IOException{final BufferedReaderbuf=new BufferedReader new InputStreamReader;"请输入职工信息以0结束\n";"姓名:";staffOne =;"0"=0um=;"性别:";staffOne i.sex=;"年龄:";staffOne i.age=;"学历:";staffOne i.record=;"职位:";staffOne i.position=;"工资:";staffOne i.wanges=;"电话:";staffOne i.tel=;"住址:";staffOne i.addr=;i++;"请输入下一个职工信息:";staffOne =;}}void outputstaffInfostaffOne throws IOException um+"\t"+staffOnej.sex+"\t"+staffOnej.age+"\t" +staffOnej.record+"\t"+staffOnej.position+"\t\t"+staffOnej.wanges+"\t"+staffOnej.tel+"\t" +staffOnej.addr+"\n";"-------------------------------------------------------------------------------------------------";}"没有职工信息";}}void searchstaffInfostaffOne throws IOException{final BufferedReaderbuf=new BufferedReader new InputStreamReader;"请输入您要查找的职工工号:";recordkey=;boolean flg=true;forint j=0;j<i;j++{if staffOnej.numum+"\t"+staffOnej.sex+"\t"+staffOnej.age+"\t"+staffOnej.record+"\t"+st affOnej.position+"\t\t"+staffOnej.wanges+"\t"+staffOnej.tel+"\t"+staffOnej.addr+"\n";flg=false;}}if flg"对不起,查无此人";}void deletestaffInfostaffOne throws IOException{final BufferedReaderbuf=new BufferedReader new InputStreamReader;"请输入您要删除的职工工号:";recordkey=;boolean flg=true;forint j=0;j<i;j++{"输入的工号为:"+recordkey;if staffOnej.num{forint k=j;k<=i-1;k++ame=staffOnek+;staffOnek.num=staffOnek+1.num;staffOnek.sex=staffOnek+1.sex;staffOnek.age=staffOnek+1.age;staffOnek.record=staffOnek+1.record; staffOnek.position=staffOnek+1.position; staffOnek.wanges=staffOnek+1.wanges; staffOnek.tel=staffOnek+1.tel;staffOnek.addr=staffOnek+1.addr;}i--;ame+"\n";staffOnek.num+"\n";staffOnek.sex+"\n";staffOnek.age+"\n";staffOnek.record+"\n";staffOnek.position+"\n";staffOnek.wanges+"\n";staffOnek.tel+"\n";staffOnek.addr+"\n";};"系统已经安全退出感谢您的使用";0;}void readstaffInfostaffOne throws IOException{final FileReaderfr=new FileReader filename;final BufferedReaderbfr=new BufferedReaderfr;if recordkey==nulli=recordkey;forint j=0;j<i;j++{=;staffOnej.num=;staffOnej.sex=;staffOnej.age=;staffOnej.record=;staffOnej.position=;staffOnej.wanges=;staffOnej.tel=;staffOnej.addr=;};"\n数据已经成功读取";}}。
Information java员工信息管理代码
public static void main(String[] args){ Scanner in=new Scanner(System.in); System.out.println("--------请定义员工人数---------"); Person personArr[]=new Person[in.nextInt()]; Adson adsonPer=new Adson(); while(true){ System.out.println("请选择你要执行的功能"); System.out.println("1:添加一个员工"); System.out.println("2:根据编号查找一个员工"); System.out.println("3:根据编号更新员工的基本信息"); System.out.println("4:根据编号删除员工---"); System.out.println("5:根据编号输入员工的各项信息"); System.out.println("6:根据绩效进行排序"); System.out.println("8:退出系统"); String di=in.next(); if(di.equals("1")){ System.out.println("请输入员工的姓名"); String name=in.next(); System.out.println("请输入员工的年龄"); int age=in.nextInt(); adsonPer.create(name,age,personArr); }else if(di.equals("2")){ System.out.println("正在执行根据编号查找一个员工
职工管理系统源代码
#include<iostream>#include<string>#include<fstream>using namespace std;const N=50; // 定义系统可录入的员工最大数值long Enum[N];string Ename[N];char Esex[N];int Etime[N];string Etitle[N];int Edegree[50];float Epay[N];char Emarriage[N];class Employee{public:long Employeenum;string Employeename;char Employeesex;int Employeetime;string Employeetitle;int Employeedegree;float Employeepay;char Employeemarriage;static long EmployeeMaxNum;static float EmployeeBasePay;void NewInfo();void ShowInfo();void showall();void showtitle(string title);void showtimebehind(int time);void showtimebefore(int time);void showmarriage(char x);void shownum(long number);void RefreshInfo();void DeleteInfo();static int MaxNum();};class DBOperate{public:long Employeenum;string Employeename;char Employeesex;int Employeetime;string Employeetitle;int Employeedegree;float Employeepay;char Employeemarriage;static long EmployeeMaxNum;static float EmployeeBasePay;void WriteIn(int iflag);void ReadOut();void RefreshMaxNum(int iflag); //i=1 or -1 or 0};long Employee::EmployeeMaxNum = 1000;float Employee::EmployeeBasePay = 1500;int Employee::MaxNum(){ //返回系统已经存储的人数int MN = 0;ifstream myf;myf.open("EmployeeMaxNum.txt");myf>>MN;myf.close();return MN;}void Employee::NewInfo(){ //添加新成员函数Employee::Employeenum = EmployeeMaxNum + Employee::MaxNum()+1;cout<<"新员工姓名: ";cin>>Employee::Employeename;cout<<"新员工性别(F为女性,M为男性): ";cin>>Employee::Employeesex;cout<<"出生年月(如2010年3月:201003): ";cin>>Employee::Employeetime;cout<<"职工职称: ";cin>>Employee::Employeetitle;cout<<"新员工学历,请输入相应学历的序号: ";cout<<" [1:初中2:高中3:本科4:硕士5:博士] ";cin>>Employee::Employeedegree;cout<<"职工工资: ";cin>>Employee::Employeepay;cout<<"新员工婚姻状况(Y为已婚,N为未婚): ";cin>>Employee::Employeemarriage;DBOperate dbo;dbo.ReadOut();int MaxNum = Employee::MaxNum();Enum[MaxNum] = Employee::Employeenum;Ename[MaxNum] = Employee::Employeename;Esex[MaxNum] = Employee::Employeesex;Etime[MaxNum] = Employee::Employeetime;Etitle[MaxNum]= Employee::Employeetitle;Edegree[MaxNum] = Employee::Employeedegree;Epay[MaxNum] = Employee::Employeepay;Emarriage[MaxNum] = Employee::Employeemarriage;dbo.WriteIn(1);cout<<" 添加新成员成功!"<<endl;return;}void Employee::ShowInfo(){ //程序主体数据输出函数int choice1,time;char x;string title;Employee e;cout<<" 请选择查询方式:"<<endl;cout<<"★★★★★★★★★★★★★★★★★★★★★★★★★★★★★"<<endl;cout<<"* 输出全体职工信息列表--------------------------------- 1"<<endl;cout<<"* 输出某职称的职工信息列表----------------------------- 2"<<endl;cout<<"* 输出某年月以后出生的职工信息列表--------------------- 3"<<endl;cout<<"* 输出某年月以前出生的职工信息列表--------------------- 4"<<endl;cout<<"* 输出某婚姻状况的职工信息刘表------------------------- 5"<<endl;cout<<"★★★★★★★★★★★★★★★★★★★★★★★★★★★★★"<<endl;cin>>choice1;switch(choice1){case 1: showall();break;case 2: cout<<"请输入要查询的职工职称:";cin>>title;e.showtitle(title);break;case 3: cout<<"请输入要查询的出生日期,查询该日期后出生的职工(如2010年3月:201003):";cin>>time;e.showtimebehind(time);break;case 4: cout<<"请输入要查询的出生日期,查询该日期前出生的职工(如2010年3月:201003):";cin>>time;e.showtimebefore(time);break;case 5: cout<<"输入要查询职工的婚姻状况(Y为已婚,N为未婚):";cin>>x;e.showmarriage(x);break;default: cout<<"出错啦! "<<endl;break;}}void Employee::showall(){ //全体员工输出函数int i;for(i=0;i<Employee::MaxNum();i++){long number = Enum[i];shownum(number);}}void Employee::showtitle(string title){ //按职工职称输出函数int i;for(i=0;i<Employee::MaxNum();i++){if(Etitle[i]==title){long number = Enum[i];shownum(number);}else continue;}}void Employee::showtimebehind(int time){ //按员工年龄输出函数int i;for(i=0;i<Employee::MaxNum();i++){if(Etime[i]>=time){long number = Enum[i];shownum(number);}else continue;}}void Employee::showtimebefore(int time){ //按员工年龄输出函数int i;for(i=0;i<Employee::MaxNum();i++){if(Etime[i]<=time){long number = Enum[i];shownum(number);}else continue;}}void Employee::showmarriage(char x){ //按员工婚姻情况输出函数int i;for(i=0;i<Employee::MaxNum();i++){if(Emarriage[i]==x) {long number = Enum[i];shownum(number);}else continue;}}void Employee::shownum(long number){ //按员工编号输出函数int i;for(i=0;i<Employee::MaxNum();i++){if(Enum[i] == number){cout<<"∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞"<<endl;cout<<" 员工编号>"<<Enum[i]<<endl;cout<<" 姓名>"<<Ename[i]<<endl;cout<<" 性别>";if(Esex[i]=='F') cout<<"女"<<endl;else if(Esex[i]=='M') cout<<"男"<<endl;cout<<" 出生年月"<<Etime[i]<<endl;cout<<" 职称>"<<Etitle[i]<<endl;cout<<" 学历>";switch (Edegree[i]){case 1:cout<<" 初中"<<endl;break;case 2:cout<<" 高中"<<endl;break;case 3:cout<<" 本科"<<endl;break;case 4:cout<<" 硕士"<<endl;break;case 5:cout<<" 博士"<<endl;break;}cout<<" 额定工资>"<<Epay[i]<<"元"<<endl;cout<<" 婚姻情况>";if(Emarriage[i]=='Y') cout<<"已婚"<<endl;else if(Emarriage[i]=='N') cout<<"未婚"<<endl;cout<<"∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞"<<endl;}else continue;}}void Employee::RefreshInfo(){ //修改员工信息的函数int cNum = 1000;DBOperate dbo;dbo.ReadOut();void Employee::shownum(long number);cout<<"请输入您要修改的员工编号:>";cin>>cNum;int MN;MN = Employee::MaxNum();for(int i=0;i<MN;i++){ //遍历数据文件,查找要修改的员工数据if(Enum[i] == cNum){Employee::shownum(cNum);cout<<"请输入该员工的新信息: "<<endl;cout<<"新员工姓名: "; //录入员工的新的数据,员工号保持不变cin>>Employee::Employeename;Ename[i] = Employee::Employeename;cout<<"新员工性别: [F为女性,M为男性]: ";cin>>Employee::Employeesex;Esex[i] = Employee::Employeesex;cout<<"新员工出生年月: ";cin>>Employee::Employeetime;Etime[i] = Employee::Employeetime;cout<<"新员工的职称:";cin>>Employee::Employeetitle;Etitle[i]=Employee::Employeetitle;cout<<"新员工学历,请输入相应学历的序号:";cout<<" [1:初中2:高中3:本科4:硕士5:博士] ";cin>>Employee::Employeedegree;Edegree[i] = Employee::Employeedegree;cout<<"职工工资: ";cin>>Employee::Employeepay;Epay[i] = Employee::Employeepay;cout<<"新员工婚姻状况(Y为已婚,N为未婚): ";cin>>Employee::Employeemarriage;Emarriage[i] = Employee::Employeemarriage;break;}}dbo.WriteIn(0);}void Employee::DeleteInfo(){ //删除员工数据的函数char tmp;int cNum = 1000;DBOperate dbo;dbo.ReadOut();void Employee::shownum(long number);cout<<"请输入您要删除的员工编号>:";cin>>cNum;int MN;MN = Employee::MaxNum();for(int i=0;i<MN;i++){ //遍历数据文件,查找要删除的员工if(Enum[i] == cNum)Employee::shownum(cNum);}cout<<"确认要删除该员工信息?(Y为确认N为放弃):";cin>>tmp;if(tmp=='Y'){if(i==MN-1)dbo.WriteIn(-1);else{for(int j=i;j<MN-1;j++){ Enum[j] = Enum[j+1]; }dbo.WriteIn(-1);}cout<<" 删除操作成功! "<<endl;}}void DBOperate::WriteIn(int iflag){ //数据操作函数写入DBOperate::RefreshMaxNum(iflag);ofstream myf("Employee.txt");Employee e;int MN;MN = e.MaxNum();for(int i=0;i<MN;i++){myf<<Enum[i]<<'\n'<<Ename[i]<<'\n'<<Esex[i]<<'\n'<<Etime[i]<<'\n'<<Etitle[i]<<'\n'<<Edegree[i]<<'\n' <<Epay[i]<<'\n'<<Emarriage[i]<<'\n';}myf.close();return;}void DBOperate::ReadOut(){ //数据操作函数读出ifstream myf("Employee.txt");Employee e;int MN;MN = e.MaxNum();for(int i=0 ;i<MN;i++){myf>>DBOperate::Employeenum>>DBOperate::Employeename>>DBOperate::Employeese x>>DBOperate::Employeetime>>DBOperate::Employeetitle>>DBOperate::Employeedegree>>D BOperate::Employeepay>>DBOperate::Employeemarriage;Enum[i] = DBOperate::Employeenum;Ename[i] = DBOperate::Employeename;Esex[i] = DBOperate::Employeesex;Etime[i] = DBOperate::Employeetime;Etitle[i]=DBOperate::Employeetitle;Edegree[i] = DBOperate::Employeedegree;Epay[i] = DBOperate::Employeepay;Emarriage[i] = DBOperate::Employeemarriage;}myf.close();}void DBOperate::RefreshMaxNum(int iflag){ //更新系统中员工计数文件的函数int MaxNum = 0;ifstream myif("EmployeeMaxNum.txt");myif>>MaxNum;myif.close();MaxNum = MaxNum+iflag;ofstream myof("EmployeeMaxNum.txt");myof<<MaxNum;myof.close();}int main(){ //主函数int select = 0;while(select!=5){cout<<" ☆☆☆☆^-^天天好心情^-^☆☆☆☆"<<endl;cout<<" ▽▽▽▽▽《主菜单》▽▽▽▽▽▽"<<endl;cout<<" ⊙请选择功能⊙"<<endl;cout<<" ⊙㎜㎜㎜㎜㎜㎜㎜㎜㎜㎜㎜㎜㎜㎜⊙"<<endl;cout<<" ⊙①.新建并输入职工数据⊙"<<endl;cout<<" ⊙②.按条件输出职工数据⊙"<<endl;cout<<" ⊙③.修改指定职工的数据⊙"<<endl;cout<<" ⊙④.删除数据⊙"<<endl;cout<<" ⊙⑤.退出⊙"<<endl;cout<<" △△△△△△△△△△△△△△△△"<<endl;cout<<" -------▉计科1301 谭鑫▉------"<<endl;cout<<" 请选择您要服务的类别: " ;cin>>select;Employee e;DBOperate dbo;switch(select){case 1:e.NewInfo(); break;case 2:dbo.ReadOut();e.ShowInfo(); break;case 3:e.RefreshInfo(); break;case 4:e.DeleteInfo(); break;case 5: break;default:cout<<"命令错误!"<<endl;}if(select == 5)break;}exit(1);return 0;}。
职工信息管理系统代码
1、定义职工类:public class Employee implements java.io.Serializable {String number,name,discipling,grade,borth,sex;public Employee(){}public void setNumber(String number){this.number=number;}public String getNumber(){return number;}public void setName(String name){=name;}public String getName(){return name;}public void setDiscipling(String discipling){this.discipling=discipling;}public String getDisciping(){return discipling;}public void setGrade(String grade){this.grade=grade;}public String getGrade(){return grade;}public void setBorth(String borth){this.borth=borth;}public String getBorth(){return borth;}public void setSex(String sex){this.sex=sex;}public String getSex(){return sex;}}2、主程序:import java.awt.*;import java.awt.event.*;import javax.swing.*;import java.io.*;import java.util.Hashtable;public class EmployeeManager extends JFrame implements ActionListener {EmployeeSituation 基本信息录入=null;ModifySituation 基本信息修改=null;Inquest 基本信息查询=null;Delete 基本信息删除=null;JMenuBar bar;JMenu fileMenu;JMenuItem 录入,修改,查询,删除;Container con=null;Hashtable 基本信息=null;File file=null;CardLayout card=null;JLabel label=null;JPanel pCenter;public EmployeeManager(){录入=new JMenuItem("录入职工基本信息");修改=new JMenuItem("修改职工基本信息");查询=new JMenuItem("查询职工基本信息");删除=new JMenuItem("删除职工基本信息");bar=new JMenuBar();fileMenu=new JMenu("菜单选项");fileMenu.add(录入);fileMenu.add(修改);fileMenu.add(查询);fileMenu.add(删除);bar.add(fileMenu);setJMenuBar(bar);label=new JLabel("欢迎进入职工信息管理系统",JLabel.CENTER);label.setFont(new Font("SansSerif",Font.BOLD+Font.ITALIC,25));label.setForeground(Color.red);基本信息=new Hashtable();录入.addActionListener(this);修改.addActionListener(this);查询.addActionListener(this);删除.addActionListener(this);card=new CardLayout();con=getContentPane();pCenter=new JPanel();pCenter.setLayout(card);pCenter.setBackground(Color.yellow);file=new File("基本信息.txt");if(!file.exists()){try{FileOutputStream out=new FileOutputStream(file);ObjectOutputStream objectOut=new ObjectOutputStream(out);objectOut.writeObject(基本信息);objectOut.close();out.close();}catch(IOException e){}}基本信息录入=new EmployeeSituation(file);基本信息修改=new ModifySituation(file);基本信息查询=new Inquest(this,file);基本信息删除=new Delete(file);pCenter.add("欢迎语界面",label);pCenter.add("录入界面",基本信息录入);pCenter.add("修改界面",基本信息修改);pCenter.add("删除界面",基本信息删除);con.add(pCenter,BorderLayout.CENTER);con.validate();addWindowListener(new WindowAdapter(){public void windowClosing(WindowEvent e){System.exit(0);}});setVisible(true);setBounds(100,50,420,380);validate();}public void actionPerformed(ActionEvent e){if(e.getSource()==录入){card.show(pCenter,"录入界面");}else if(e.getSource()==修改){card.show(pCenter,"修改界面");}else if(e.getSource()==查询){基本信息查询.setVisible(true);}else if(e.getSource()==删除){card.show(pCenter,"删除界面");}}public static void main(String args[]){new EmployeeManager();}}3、实现职工信息的录入:import java.awt.*;import java.awt.event.*;import javax.swing.*;import java.io.*;import java.util.*;public class EmployeeSituation extends JPanel implements ActionListener {Hashtable 基本信息表=null;JTextField 职工号,姓名,工资;Choice 部门;JRadioButton 男,女;Employee 职工=null;ButtonGroup group=null;JButton 录入,重置;FileInputStream inOne=null;ObjectInputStream inTwo=null;FileOutputStream outOne=null;ObjectOutputStream outTwo=null;File file=null; public EmployeeSituation(File file){this.file=file;职工号=new JTextField(10);姓名=new JTextField(10);部门=new Choice();部门.add("请选择");部门.add("研发部");部门.add("销售部");部门.add("人事部");部门.add("安全部");工资=new JTextField(10);group=new ButtonGroup();男=new JRadioButton("男",true);女=new JRadioButton("女",false);group.add(男);group.add(女);录入=new JButton("录入");重置=new JButton("重置");录入.addActionListener(this);重置.addActionListener(this);Box box1=Box.createHorizontalBox();box1.add(new JLabel("职工号:",JLabel.CENTER));box1.add(职工号);Box box2=Box.createHorizontalBox();box2.add(new JLabel("姓名:",JLabel.CENTER));box2.add(姓名);Box box3=Box.createHorizontalBox();box3.add(new JLabel("性别:",JLabel.CENTER));box3.add(男);box3.add(女);Box box4=Box.createHorizontalBox();box4.add(new JLabel("部门:",JLabel.CENTER));box4.add(部门);Box box6=Box.createHorizontalBox();box6.add(new JLabel(" ",JLabel.CENTER));Box box5=Box.createHorizontalBox();box5.add(new JLabel("工资:",JLabel.CENTER));box5.add(工资);Box boxH=Box.createVerticalBox();boxH.add(box1);boxH.add(box2);boxH.add(box3);boxH.add(box5);boxH.add(box6);boxH.add(box4);boxH.add(Box.createVerticalGlue());JPanel pCenter=new JPanel();pCenter.add(boxH);pCenter.setBackground(Color.yellow);setLayout(new BorderLayout());add(pCenter,BorderLayout.CENTER);JPanel pSouth=new JPanel();pSouth.add(录入);pSouth.add(重置);pSouth.setBackground(Color.yellow);add(pSouth,BorderLayout.SOUTH);validate();}public void actionPerformed(ActionEvent e){if(e.getSource()==录入){String number="";number=职工号.getText();if(number.length()>0){try{inOne=new FileInputStream(file);inTwo=new ObjectInputStream(inOne);基本信息表=(Hashtable)inTwo.readObject();inOne.close();inTwo.close();}catch(Exception ee){}if(基本信息表.containsKey(number)){String warning="该职工基本信息已存在,请到修改页面修改!"; JOptionPane.showMessageDialog(this,warning,"警告",JOptionPane.WARNING_MESSAGE);}else{String m="基本信息将被录入!";int ok=JOptionPane.showConfirmDialog(this,m,"确认",JOptionPane.YES_NO_OPTION,RMATION_MESSAGE);if(ok==JOptionPane.YES_OPTION){String name=姓名.getText();String discipling=部门.getSelectedItem();String grade=工资.getText();String sex=null;if(男.isSelected()){sex=男.getText();}else{sex=女.getText();}职工=new Employee();职工.setNumber(number);职工.setName(name);职工.setDiscipling(discipling);职工.setGrade(grade);职工.setSex(sex);try{outOne=new FileOutputStream(file);outTwo=new ObjectOutputStream(outOne);基本信息表.put(number,职工);outTwo.writeObject(基本信息表);outTwo.close();outOne.close();职工号.setText(null);姓名.setText(null);工资.setText(null);}catch(Exception ee){System.out.println(ee);}}}}else{String warning="必须要输入职工号!";JOptionPane.showMessageDialog(this,warning,"警告",JOptionPane.WARNING_MESSAGE);}}if(e.getSource()==重置){职工号.setText(null);姓名.setText(null);部门.remove(部门.getSelectedIndex());工资.setText(null);}}}4、实现职工信息的修改:import java.awt.*;import java.awt.event.*;import javax.swing.*;import java.io.*;import java.util.*;public class ModifySituation extends JPanel implements ActionListener {Hashtable 基本信息表=null;JTextField 职工号,姓名,工资;Choice 部门;JRadioButton 男,女;ButtonGroup group=null;JButton 开始修改,录入修改,重置;FileInputStream inOne=null;ObjectInputStream inTwo=null;FileOutputStream outOne=null;ObjectOutputStream outTwo=null;File file=null;public ModifySituation(File file){this.file=file;职工号=new JTextField(10);姓名=new JTextField(10);部门=new Choice();部门.add("请选择");部门.add("研发部");部门.add("销售部");部门.add("人事部");部门.add("安全部");工资=new JTextField(10);group=new ButtonGroup();男=new JRadioButton("男",true);女=new JRadioButton("女",false);group.add(男);group.add(女);开始修改=new JButton("开始修改");录入修改=new JButton("录入修改");录入修改.setEnabled(false);重置=new JButton("重置");职工号.addActionListener(this);开始修改.addActionListener(this);录入修改.addActionListener(this);重置.addActionListener(this);Box box1=Box.createHorizontalBox();box1.add(new JLabel("输入要修改信息的职工号:",JLabel.CENTER));box1.add(职工号);box1.add(开始修改);Box box2=Box.createHorizontalBox();box2.add(new JLabel("姓名:",JLabel.CENTER));box2.add(姓名);Box box3=Box.createHorizontalBox();box3.add(new JLabel("性别:",JLabel.CENTER));box3.add(男);box3.add(女);Box box4=Box.createHorizontalBox();box4.add(new JLabel("部门:",JLabel.CENTER));box4.add(部门);Box box6=Box.createHorizontalBox();box6.add(new JLabel(" ",JLabel.CENTER));Box box5=Box.createHorizontalBox();box5.add(new JLabel("工资:",JLabel.CENTER));box5.add(工资);Box boxH=Box.createVerticalBox();boxH.add(box1);boxH.add(box2);boxH.add(box3);boxH.add(box5);boxH.add(box6);boxH.add(box4);boxH.add(Box.createVerticalGlue());JPanel pCenter=new JPanel();pCenter.add(boxH);pCenter.setBackground(Color.yellow);setLayout(new BorderLayout());add(pCenter,BorderLayout.CENTER);JPanel pSouth=new JPanel();pSouth.add(录入修改);pSouth.add(重置);pSouth.setBackground(Color.yellow);add(pSouth,BorderLayout.SOUTH);validate();}public void actionPerformed(ActionEvent e){if(e.getSource()==开始修改||e.getSource()==职工号){String number="";number=职工号.getText();if(number.length()>0){try {inOne=new FileInputStream(file);inTwo=new ObjectInputStream(inOne);基本信息表=(Hashtable)inTwo.readObject();inOne.close();inTwo.close();}catch(Exception ee){}if(基本信息表.containsKey(number)){录入修改.setEnabled(true);Employee stu=(Employee)基本信息表.get(number);姓名.setText(stu.getName());部门.getSelectedItem();工资.setText(stu.getGrade());if(stu.getSex().equals("男")){男.setSelected(true);}else{女.setSelected(true);}}else{录入修改.setEnabled(false);String warning="该职工号不存在!";JOptionPane.showMessageDialog(this,warning,"警告",JOptionPane.WARNING_MESSAGE);职工号.setText(null);姓名.setText(null);部门.remove(部门.getSelectedItem());工资.setText(null);}}else{录入修改.setEnabled(false);String warning="必须要输入职工号!";JOptionPane.showMessageDialog(this,warning,"警告",JOptionPane.WARNING_MESSAGE);职工号.setText(null);姓名.setText(null);部门.remove(部门.getSelectedItem());工资.setText(null);}}else if(e.getSource()==录入修改){String number="";number=职工号.getText();if(number.length()>0){try {inOne=new FileInputStream(file);inTwo=new ObjectInputStream(inOne);基本信息表=(Hashtable)inTwo.readObject();inOne.close();inTwo.close();}catch(Exception ee){}if(基本信息表.containsKey(number)){String question="该职工基本信息已存在,您想修改他(她)的基本信息吗?";JOptionPane.showMessageDialog(this,question,"警告",JOptionPane.QUESTION_MESSAGE);String m="基本信息将被修改!";int ok=JOptionPane.showConfirmDialog(this,m,"确认",JOptionPane.YES_NO_OPTION,RMATION_MESSAGE);if(ok==JOptionPane.YES_OPTION){String name=姓名.getText();String discipling=部门.getSelectedItem();String grade=工资.getText();String sex=null;if(男.isSelected()){sex=男.getText();}else{sex=女.getText();}Employee 职工=new Employee();职工.setNumber(number);职工.setName(name);职工.setDiscipling(discipling);职工.setGrade(grade);职工.setSex(sex);try{outOne=new FileOutputStream(file);outTwo=new ObjectOutputStream(outOne);基本信息表.put(number,职工);outTwo.writeObject(基本信息表);outTwo.close();outOne.close();职工号.setText(null);姓名.setText(null);部门.remove(部门.getSelectedItem());工资.setText(null);}catch(Exception ee){System.out.println(ee);}录入修改.setEnabled(false);}else if(ok==JOptionPane.NO_OPTION){录入修改.setEnabled(true);}}else{String warning="该职工号没有基本信息,不能修改!";JOptionPane.showMessageDialog(this,warning,"警告",JOptionPane.WARNING_MESSAGE);录入修改.setEnabled(false);}}else{String warning="必须要输入职工号!";JOptionPane.showMessageDialog(this,warning,"警告",JOptionPane.WARNING_MESSAGE);录入修改.setEnabled(false);}}if(e.getSource()==重置){职工号.setText(null);姓名.setText(null);部门.remove(部门.getSelectedItem());工资.setText(null);}}}5、实现职工信息的查询:import java.awt.*;import java.awt.event.*;import javax.swing.*;import java.io.*;import java.util.*;public class Inquest extends JDialog implements ActionListener {Hashtable 基本信息表=null;JTextField 职工号,姓名,部门,工资;JRadioButton 男,女;JButton 查询;ButtonGroup group=null;FileInputStream inOne=null;ObjectInputStream inTwo=null;File file=null;public Inquest(JFrame f,File file){super(f,"查询对话框",false);this.file=file;职工号=new JTextField(10);查询=new JButton("查询");职工号.addActionListener(this);查询.addActionListener(this);姓名=new JTextField(10);姓名.setEditable(false);部门=new JTextField(10);部门.setEditable(false);工资=new JTextField(10);工资.setEditable(false);男=new JRadioButton("男",false);女=new JRadioButton("女",false);group=new ButtonGroup();group.add(男);group.add(女);Box box1=Box.createHorizontalBox();box1.add(new JLabel("输入要查询的职工号:",JLabel.CENTER));box1.add(职工号);box1.add(查询);Box box2=Box.createHorizontalBox();box2.add(new JLabel("姓名:",JLabel.CENTER));box2.add(姓名);Box box3=Box.createHorizontalBox();box3.add(new JLabel("性别:",JLabel.CENTER));box3.add(男);box3.add(女);Box box4=Box.createHorizontalBox();box4.add(new JLabel("部门:",JLabel.CENTER));box4.add(部门);Box box5=Box.createHorizontalBox();box5.add(new JLabel("工资:",JLabel.CENTER));box5.add(工资);Box boxH=Box.createVerticalBox();boxH.add(box1);boxH.add(box2);boxH.add(box3);boxH.add(box5);boxH.add(box4);boxH.add(Box.createVerticalGlue());JPanel pCenter=new JPanel();pCenter.add(boxH);pCenter.setBackground(Color.green);Container con=getContentPane();con.add(pCenter,BorderLayout.CENTER);con.validate();setVisible(false);setBounds(100,200,360,270);addWindowListener(new WindowAdapter(){public void windowClosing(WindowEvent e){setVisible(false);} });}public void actionPerformed(ActionEvent e){姓名.setText(null);部门.setText(null);工资.setText(null);if(e.getSource()==查询||e.getSource()==职工号){String number="";number=职工号.getText();if(number.length()>0){try {inOne=new FileInputStream(file);inTwo=new ObjectInputStream(inOne);基本信息表=(Hashtable)inTwo.readObject();inOne.close();inTwo.close();}catch(Exception ee){}if(基本信息表.containsKey(number)){Employee stu=(Employee)基本信息表.get(number);姓名.setText(stu.getName());部门.setText(stu.getDisciping());工资.setText(stu.getGrade());if(stu.getSex().equals("男")){男.setSelected(true);}else{女.setSelected(true);} }else{String warning="该职工号不存在!";JOptionPane.showMessageDialog(this,warning,"警告",JOptionPane.WARNING_MESSAGE);}}else{String warning="必须要输入职工号!";JOptionPane.showMessageDialog(this,warning,"警告",JOptionPane.WARNING_MESSAGE);}}}6、实现职工信息的删除:import java.awt.*;import java.awt.event.*;import javax.swing.*;import java.io.*;import java.util.*;public class Delete extends JPanel implements ActionListener {Hashtable 基本信息表=null;JTextField 职工号,姓名,部门,工资;JRadioButton 男,女;JButton 删除;ButtonGroup group=null;FileInputStream inOne=null;ObjectInputStream inTwo=null;FileOutputStream outOne=null;ObjectOutputStream outTwo=null;File file=null;public Delete(File file){this.file=file;职工号=new JTextField(10);删除=new JButton("删除");职工号.addActionListener(this);删除.addActionListener(this);姓名=new JTextField(10);姓名.setEditable(false);部门=new JTextField(10);部门.setEditable(false);工资=new JTextField(10);工资.setEditable(false);男=new JRadioButton("男",false);女=new JRadioButton("女",false);group=new ButtonGroup();group.add(男);group.add(女);Box box1=Box.createHorizontalBox();box1.add(new JLabel("输入要删除的职工:",JLabel.CENTER));box1.add(职工号);box1.add(删除);Box box2=Box.createHorizontalBox();box2.add(new JLabel("姓名:",JLabel.CENTER));box2.add(姓名);Box box3=Box.createHorizontalBox();box3.add(new JLabel("性别:",JLabel.CENTER));box3.add(男);box3.add(女);Box box4=Box.createHorizontalBox();box4.add(new JLabel("部门:",JLabel.CENTER));box4.add(部门);Box box6=Box.createHorizontalBox();box6.add(new JLabel(" ",JLabel.CENTER));Box box5=Box.createHorizontalBox();box5.add(new JLabel("工资:",JLabel.CENTER));box5.add(工资);Box boxH=Box.createVerticalBox();boxH.add(box1);boxH.add(box2);boxH.add(box3);boxH.add(box5);boxH.add(box6);boxH.add(box4);boxH.add(Box.createVerticalGlue());JPanel pCenter=new JPanel();pCenter.add(boxH);pCenter.setBackground(Color.yellow);setLayout(new BorderLayout());add(pCenter,BorderLayout.CENTER);validate();}public void actionPerformed(ActionEvent e){if(e.getSource()==删除||e.getSource()==职工号){String number="";number=职工号.getText();if(number.length()>0){try{inOne=new FileInputStream(file);inTwo=new ObjectInputStream(inOne);基本信息表=(Hashtable)inTwo.readObject();inOne.close();inTwo.close();}catch(Exception ee){}if(基本信息表.containsKey(number)){Employee stu=(Employee)基本信息表.get(number);姓名.setText(stu.getName());部门.setText(stu.getDisciping());工资.setText(stu.getGrade());if(stu.getSex().equals("男")){男.setSelected(true);}else{女.setSelected(true);}String m="确定要删除该职工号及全部信息吗?";int ok=JOptionPane.showConfirmDialog(this,m,"确认",JOptionPane.YES_NO_OPTION,JOptionPane.QUESTION_MESSAGE);if(ok==JOptionPane.YES_OPTION){基本信息表.remove(number);try{outOne=new FileOutputStream(file);outTwo=new ObjectOutputStream(outOne);outTwo.writeObject(基本信息表);outTwo.close();outOne.close();职工号.setText(null);姓名.setText(null);部门.setText(null);工资.setText(null);}catch(Exception ee){System.out.println(ee);}}else if(ok==JOptionPane.NO_OPTION){职工号.setText(null);姓名.setText(null);部门.setText(null);工资.setText(null);}}else{String warning="该职工号不存在!";JOptionPane.showMessageDialog(this,warning,"警告",JOptionPane.WARNING_MESSAGE);}}else{String warning="必须要输入职工号!";JOptionPane.showMessageDialog(this,warning,"警告",JOptionPane.WARNING_MESSAGE);}}}}。
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
switch (choice){
case 1:creat(staffOne);break ;
case2:output(staffOne);break;
case3:search(staffOne);break;
case4:delete(staffOne);break;
package exercise;
import java.io.*;
class staffInfo//职工类{
public
String
name;
public
String
num;
public
String
sex;
public
String
age;
public
String
record
public
String
"1
1
Syste m.
);
out
.println(
"1
★★★
1.输入职工信息
★★★
1");
System.
out
.println(
"1
★
★ ★
2
■预览职
工信息
★★★
1);
Syste m.
out
.println(
"1
★
★ ★3.
查找职工信息
★ ★
★
1
);
System.
out
.println(
"1
★
★ ★4.
staffTwo.delete(staffOne);
}
}
class ways//方法类,主要实现职工信息的建立,显示,查找,删除,信息的保存与读取;这个类是整个程序的操作类。
public int i=0;//i用来存放职工的人数public String filename="Infomation.txt" BufferedReader buf =new
System. out .print("姓名:" );
staffOne[ i].name =buf.readLine();//用数组staffOne[i]来暂存职工的相
关信息
while (staffOne[ i].name .compareTo("0" )!=0) //用compareTo方法确定判定是否应该写入新信息
{
for(int j=0;j< i ;j++)
删除职工信息
★ ★
★
1");
System.
out
.println(
"1
★★★
5.读取已存数据
★★★
1");
System.
out
.println(
"1
★
★ ★
6
•安全退
出系统
★★★
1);
Syste m.
i
out
.println(
"1
System.
);
out
.print("
请输入您需要的功能代号
(1--6):" );
InputStreamReader(System. in));
void caidan(staffInfo staffOne[])
{
final BufferedReader
InputStreamReader(System. in));
throws IOException
buf= new BufferedReader(
{
System. out .print("工号:" );
staffOne[ i].num=buf.readLine();
System. out .print("性别:" );
staffOne[ i].sex =buf.readLine();
System. out .print("年龄:" );
staffOne[ i].age =buf.readLine();
case 5:read(staffOne);break ;
case 6:save(staffOne);break ;
}
}
while (choice!=0);
}
void creat(staffI nfo staffO ne[])
{
InputStreamReader(System. in));
System. out .print("请输入职工信息(以0结束)\n");
position
public
String
wanges
public
String
tel;
public
String
addr;
public class StaffInfomation//实现部分
{
public static void main( final String[] args){
staffInfo staffOne[]= new staffInfo[100];
i++;
System. out .println("请输入下一个职工信息:" );
staffOne[ i].name =buf.readLine();
}}
void output(staffInfo staffOne[]) throws IOException//这里是实现“输出(预览)职工信息”output的模块
for(int j=0;j<100;j++)
staffOne[j]=new staffInfo();
final ways staffTwo= new ways(); staffTwo.caidan(staffOne); staffTwo.creat(staffOne);
staffTwo.output(staffOne); staffTwo.search(staffOne);
//此处是JAVA语言中输入数据的基本格式,
能有如C中的scanf函数
int choice;
do{
System. out .println(
1 ");
.
out
.println(
"!★★★
★ ★★
★
★职工管理系统主菜单界
面^★ ★★ ★
★★
★1");
Syste m.
1
out
.println(
System. out .print("学历:" );
staffOne[ i].record =buf.readLine();
System. out .print("职位:" );
staffOne[ i].position =buf.readLine();
System. out .print("工资:" );
staffOne[ i].wanges =buf.readLine();
System. out .print("电话:" );
staffOne[ i].tel =buf.readLine();
System. out .print("住址:" );
staffOne[ i].addr =buf.readLine();