职工信息管理系统java源代码

合集下载

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课程设计代码

员工管理系统java课程设计代码

员工管理系统Java课程设计代码一、需求分析在公司中,员工管理是一个至关重要的环节。

为了提高管理效率,我们需要一个员工管理系统。

本系统可以实现员工信息的录入、查询、修改和删除等功能,同时能够根据不同的需求输出相应的报表。

本文将介绍员工管理系统的Java课程设计代码实现。

二、系统架构1. 数据库设计我们将使用MySQL数据库存储员工信息。

数据库中将包含一个employee表,用于存储员工的基本信息,如员工号、姓名、性别、职位、入职日期等字段。

2. 后台逻辑后台逻辑部分将采用Java语言进行编码。

我们将使用JDBC连接数据库,实现数据的增删改查操作。

同时,我们将采用面向对象的编程思想,设计Employee类来表示员工信息,EmployeeDAO类用于实现数据库操作。

3. 前端界面前端界面将采用简单的控制台界面。

用户可以通过控制台界面输入操作指令,实现员工信息的录入、查询、修改和删除操作。

三、功能实现1. 员工信息录入用户可以输入员工的基本信息,程序将会将信息保存到数据库中。

2. 员工信息查询用户可以通过员工号或者姓名进行查询,程序将会从数据库中检索相应的员工信息,并输出到控制台。

3. 员工信息修改用户可以输入员工号和需要修改的信息,程序将会更新数据库中对应员工的信息。

4. 员工信息删除用户可以输入员工号,程序将会从数据库中删除对应员工的信息。

5. 输出报表系统提供了不同的报表输出选项,如按照职位统计员工人数、按照性别统计员工平均工资等。

四、代码示例public class Employee {private int empId;private String empName;private String gender;private String position;private Date hireDate;// 省略getter和setter方法}public class EmployeeDAO {public void addEmployee(Employee emp) {// 实现员工信息添加逻辑}public Employee findEmployeeById(int empId) {// 实现根据员工号查询员工信息逻辑}public void updateEmployee(Employee emp) {// 实现员工信息更新逻辑}public void deleteEmployee(int empId) {// 实现员工信息删除逻辑}}// 程序入口public class Main {public static void main(String[] args) {// 主程序逻辑,包括界面交互和调用DAO方法}}五、总结通过本文的介绍,我们可以看到员工管理系统的Java课程设计代码实现是一个比较完整的系统,涵盖了从数据库设计到后台逻辑再到前端界面的全方位内容。

简单的JAVA员工信息管理系统源码

简单的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源代码

(完整版)职工信息管理系统java源代码
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");
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员工管理系统排序代码(原创版)目录1.Java 员工管理系统简介2.排序代码的作用和原理3.员工信息排序的实现方法4.代码示例及解析5.总结正文一、Java 员工管理系统简介Java 员工管理系统是一款基于 Java 语言开发的软件,用于实现对企业员工信息的管理、查询、添加、删除和修改等功能。

该系统具有良好的用户界面,易于操作,能够满足企业对员工信息管理的需求。

二、排序代码的作用和原理在员工管理系统中,排序代码的作用是对员工信息进行排序,以便于企业进行员工信息的查找、筛选和分析。

排序代码的原理是通过比较员工信息的某一字段,将员工信息按照该字段的值进行升序或降序排列。

三、员工信息排序的实现方法在 Java 员工管理系统中,员工信息排序的实现方法主要包括以下两种:1.采用 Java 内置的 Arrays.sort() 方法对员工信息数组进行排序。

该方法可以对数组中的元素进行原地排序,不需要创建新的数组,但排序后的数组是从原始数组中复制得到的。

2.采用 Java 的 Collections 框架中的 Collections.sort() 方法对员工信息列表进行排序。

该方法同样可以对列表中的元素进行原地排序,不需要创建新的列表,但排序后的列表是从原始列表中复制得到的。

四、代码示例及解析以下是一个简单的 Java 员工管理系统排序代码示例:```javaimport java.util.ArrayList;import java.util.Collections;import java.util.List;public class EmployeeSort {public static void main(String[] args) {List<Employee> employeeList = new ArrayList<>();employeeList.add(new Employee("张三", 25));employeeList.add(new Employee("李四", 30));employeeList.add(new Employee("王五", 28));System.out.println("排序前:");printEmployeeList(employeeList);Collections.sort(employeeList);System.out.println("排序后:");printEmployeeList(employeeList);}public static void printEmployeeList(List<Employee> employeeList) {for (Employee employee : employeeList) {System.out.println(employee);}}}class Employee {private String name;private int age;public Employee(String name, int age) { = name;this.age = age;}@Overridepublic String toString() {return "Employee{" +"name="" + name + """ +", age=" + age +"}";}}```代码解析:1.首先,我们创建了一个 Employee 类,用于存储员工信息。

最终的职工信息管理系统源代码(精)

最终的职工信息管理系统源代码(精)

#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实现简单员⼯管理系统本⽂实例为⼤家分享了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;}}运⾏⽰例:以上就是本⽂的全部内容,希望对⼤家的学习有所帮助,也希望⼤家多多⽀持。

java职工信息管理系统源代码(精)

java职工信息管理系统源代码(精)

java职工信息管理系统源代码(精)源代码packageleon2;importjava.ql.某;publicclaemployee{publicStringnum;publicStringname;publicStringe某;publicStringage;publicStringedu;publicStringla;publicStringad d;publicStringtel;publicvoidinit(String某1,String某2,String某3,String某4,String某5,String某6,String某7,String某8{num=某1;name=某2;e某=某3;age=某4;edu=某5;la=某6;add=某7;tel=某8;} publicvoidload(Stringf{try{Cla.forName(\;Stringurl=\;StringuerName=\;Stringpaword=\;Connectionconn=DriverManager.getConnection(url,uerName,pawor d;if(conn!=nullSytem.out.println(\已成功地与SQLServer2005数据库建立连接!\;Statementtmt=conn.createStatement(;tmt.e某ecuteUpdate(f;tmt.cloe(;}catch(E某ceptione{e.printStackTrace(;}}}packageleon2;importjava.awt.某;importjava.awt.event.某;importjava.ql.某;publicclaleon2_1{taticFramef;CardLayoutmyCard;Panelp1;Panelp2;Panelp3;Panelp4 ;Panelp5;Panelp6;Panelp7;Panelp8;publictaticvoidmain(String[]arg{leon2_1tet=newleon2_1(;tet.go1(;tet.go2(;tet.go3(;tet.go4(;t et.go5(;tet.go6(;tet.go7(;tet.go8(;}publicvoidgo1({f=newFrame(\呵呵!!!\myCard=newCardLayout(;f.etLayout(myCard;p1=newPanel(;Butto nb1,b2,b3;LabelL1;Te某tFieldte1;finalTe某tFieldte2;p1.etLayout(newGridBagLayout(;GridBagContraintc=newGridBagContraint(;Panelp1_1=newPanel(;p1_1.etLayout(newGridBagLayout(;GridBagContraint某=newGridBagContraint(;b1=newButton(\请输入用户名\b1.etBackground(Color.CYAN;某.inet=newInet(50,50,50,50;某.grid某=0;某.gridy=0;某.gridwidth=1;某.gridheight=1;p1_1.add(b1,某;b2=newButton(\请输入密码\b2.etBackground(Color.CYAN;某.grid 某=0;某.gridy=5;某.gridwidth=1;某.gridheight=1;p1_1.add(b2,某;te1=newTe某tField(15;c.inet=newInet(40,0,40,0;某.grid某=5;某.gridy=0;某.gridwidth=1;某.gridheight=1;p1_1.add(te1,某;te2=newTe某tField(15;某.grid某=5;某.gridy=5;某.gridwidth=1;某.gridheight=1;p1_1.add(te2,某;L1=newLabel(\欢迎进入职工管理系统某某某某某某某某某某某某某某\L1.etBackground(Color.CYAN;c.grid某=0;c.gridy=0;c.gridwidth=0;c.gridheight=1;p1.add(L1,c;b3=newButton(\登录\b3.etBackground(Color.CYAN;c.grid某=0;c.gridy=10;c.gridwidth=5;c.gridheight=5;p1.add(b3,c;c.grid某=0;c.gridy=20;c.gridwidth=5;c.gridheight=5;p1.add(p1_1,c;p1.etBackground(Color.green;f.add(p1,\myCard.how(f,\f.etSize (600,600;f.etViible(true;f.addWindowLitener(newWindowAdapter({ publicvoidwindowCloing(WindowEvente{Sytem.e某it(0;}};b3.addMoueLitener(newMoueAdapter({publicvoidmoueClicked(Moue Evente{String某=te2.getTe某t(;inty=Integer.pareInt(某;if(y==106 myCard.how(f,\}};}publicvoidgo2({p2=newPanel(;Buttonb1,b2,b3,b4,b5,b6;LabelL1;p2.etLayout(newGridBagLayout(;GridBagContraintc=newGridBagContraint(;c.inet=newInet(50,0,8 ,0;b1=newButton(\职工信息录入\b1.etBackground(Color.CYAN;c.grid 某=1;c.gridy=50;c.gridwidth=5;c.gridheight=50;p2.add(b1,c;b2=newButton(\职工信息浏览\b2.etBackground(Color.CYAN;c.grid 某=1;c.gridy=100;c.gridwidth=5;c.gridheight=50;p2.add(b2,c;b3=newButton(\职工信息查询\b3.etBackground(Color.CYAN;c.grid 某=1;c.gridy=150;c.gridwidth=5;c.gridheight=50;p2.add(b3,c;b4=newButton(\职工信息排序\b4.etBackground(Color.CYAN;c.grid 某=1;c.gridy=200;c.gridwidth=5;c.gridheight=50;p2.add(b4,c;b5=newButton(\职工信息修改\b5.etBackground(Color.CYAN;c.grid 某=1;c.gridy=250;c.gridwidth=5;c.gridheight=50;p2.add(b5,c;b6=newButton(\职工信息删除\b6.etBackground(Color.CYAN;c.grid 某=1;c.gridy=300;c.gridwidth=5;c.gridheight=50;p2.add(b6,c;L1=newLabel(\欢迎进入职工管理系统某某某某某某某某某某\L1.etBackground(Color.CYAN;c.grid某=1;c.gridy=0;c.gridwidth=5;c.gridheight=10;p2.add(L1,c;p2.etBackground(Color.green;f.add(p2,\b1.addMoueLitener(newMoueAdapter({publicvoidmoueClicked(Moue Evente{myCard.how(f,\}};b2.addMoueLitener(newMoueAdapter({publicvoidmoueClicked(Moue Evente{myCard.how(f,\}};b3.addMoueLitener(newMoueAdapter({publicvoidmoueClicked(Moue Evente{myCard.how(f,\}};b4.addMoueLitener(newMoueAdapter({publicvoidmoueClicked(Moue Evente{myCard.how(f,\}};b5.addMoueLitener(newMoueAdapter({publicvoidmoueClicked(Moue Evente{myCard.how(f,\}};b6.addMoueLitener(newMoueAdapter({publicvoidmoueClicked(Moue Evente{myCard.how(f,\}};}publicvoidgo3({p3=newPanel(;p3.etLayout(newGridBagLayout(;GridBagContraintc=newGridBagContraint(;Buttonb1,b2,b3,b4,b5, b6,b7,b8,b9,b10;finalTe某tFieldte1,te2,te3,te4,te5,te6,te7,te8;LabelL1;c.inet=newInet(60,50,0,0;L1=newLabel(\请输入下面信息某某某某某某某某某某某某某某某某\ L1.etBackground(Color.CYAN;c.grid某=0;c.gridy=0;c.gridwidth=0;c.gridheight=1;p3.add(L1,c;b1=newButton(\工号\b1.etBackground(Color.CYAN;c.grid某=0;c.gridy=10;c.gridwidth=1;c.gridheight=1;p3.add(b1,c;b2=newButton(\姓名\b2.etBackground(Color.CYAN;c.grid某=35;c.gridy=10;c.gridwidth=1;c.gridheight=1;p3.add(b2,c;b3=newButton(\性别\b3.etBackground(Color.CYAN;c.grid某=0;c.gridy=30;c.gridwidth=1;c.gridheight=1;p3.add(b3,c;b4=newButton(\年龄\b4.etBackground(Color.CYAN;c.grid某=35;c.gridy=30;c.gridwidth=1;c.gridheight=1;p3.add(b4,c;b5=newButton(\学历\b5.etBackground(Color.CYAN;c.grid某=0;c.gridy=50;c.gridwidth=1;c.gridheight=1;p3.add(b5,c;b6=newButton(\工资\b6.etBackground(Color.CYAN;c.grid某=35;c.gridy=50;c.gridwidth=1;c.gridheight=1;p3.add(b6,c;b7=newButton(\住址\b7.etBackground(Color.CYAN;c.grid某=0;c.gridy=70;c.gridwidth=1;c.gridheight=1;p3.add(b7,c;b8=newButton(\电话\b8.etBackground(Color.CYAN;c.grid某=35;c.gridy=70;c.gridwidth=1;c.gridheight=1;p3.add(b8,c;b9=newButton(\提交\b9.etBackground(Color.CYAN;c.grid某=10;c.gridy=100;c.gridwidth=1;c.gridheight=1;p3.add(b9,c;b10=newButton(\返回\b10.etBackground(Color.CYAN;c.grid某=35;c.gridy=100;c.gridwidth=1;c.gridheight=1;p3.add(b10,c;te1=ne wTe某tField(10;c.grid某=10;c.gridy=10;c.gridwidth=1;c.gridheight=1;p3.add(te1,c;te2=newTe某tField(10;c.grid某=37;c.gridy=10;c.gridwidth=1;c.gridheight=1;p3.add(te2,c;te3=new Te某tField(10;c.grid某=10;c.gridy=30;c.gridwidth=1;c.gridheight=1;p3.add(te3,c;te4=new Te某tField(10;c.grid某=37;c.gridy=30;c.gridwidth=1;c.gridheight=1;p3.add(te4,c;te5=new Te某tField(10;c.grid某=10;c.gridy=50;c.gridwidth=1;c.gridheight=1;p3.add(te5,c;te6=new Te某tField(10;c.grid某=37;c.gridy=50;c.gridwidth=1;c.gridheight=1;p3.add(te6,c;te7=new Te某tField(10;c.grid某=10;c.gridy=70;c.gridwidth=1;c.gridheight=1;p3.add(te7,c;te8=new Te某tField(10;c.grid某=37;c.gridy=70;c.gridwidth=1;c.gridheight=1;p3.add(te8,c;p3.etBackground(Color.green;f.add(p3,\b9.addMoueLitener(newMoueAdapter({publicvoidmoueClicked(Moue Evente{employeee1=newemployee(;e1.init(te1.getTe某t(,te2.getTe某t(,te3.getTe某t(,te4.getTe某t(,te5.getTe某t(,te6.getTe某t(,te7.getTe某t(,te8.getTe某t(;String某=\Stringy=\Stringz=\Stringw=\Stringql=\ql=ql+某+e1.num+y+z+某++y+z+某+e1.e某+y+z+某+e1.age+y+z+某++y+z+某++y+z+某+e1.add+y+z+某+e1.tel+y+w;e1.load(ql;te1.etTe某t(\te2.etTe某t(\te3.etTe某t(\te4.etTe某t(\te5.etTe某t(\te6.etTe某t(\te7.etTe某t(\te8.etTe某t(\}};eEvente{myCard.how(f,\}};}publicvoidgo4({p4=newPanel(;p4.etLayout(newGridBagLayout(;GridBagContraintc=newGridBagContraint(;Buttonb1,b2;LabelL1;f inalTe某tAreata;c.inet=newInet(60,0,0,0;L1=newLabel(\欢迎进入信息浏览界面某某某某某某某某某某某某某某某某\L1.etBackground(Color.CYAN;c.grid某=0;c.gridy=0;c.gridwidth=0;c.gridheight=1;p4.add(L1,c;b1=newButton(\浏览\b1.etBackground(Color.CYAN;c.grid某=0;c.gridy=10;c.gridwidth=1;c.gridheight=1;p4.add(b1,c;b2=newButton(\返回\b2.etBackground(Color.CYAN;c.grid某=0;c.gridy=20;c.gridwidth=1;c.gridheight=1;p4.add(b2,c;ta=newTe某tArea(15,50;c.grid某=0;c.gridy=11;c.gridwidth=1;c.gridheight=1;p4.add(ta,c;p4.etBackground(Color.green;f.add(p4,\Evente{try{Cla.forName(\Stringurl=\StringuerName=\Stringpaword=\Connectionconn=DriverManager.getConnection(url,uerName,pawor d;Statementtmt=conn.createStatement(;ReultSetr=tmt.e某ecuteQuery(\employee[]em=newemployee[10];inti=0;while(r.ne某t({ =+em[j].num+\em[j].edu+\}ta.etTe某t(;r.cloe(;tmt.cloe(;}catch(E某ceptione1{e1.printStackTrace(;}}};b2.addMoueLitener(newMoueAdapter({publicvoidmoueClicked(Moue Evente{ta.etTe某t(\myCard.how(f,\}};}publicvoidgo5({p5=newPanel(;p5.etLayout(newGridBagLayout(;GridBagContraintc=newGridBagContraint(;c.inet=newInet(40,0,0 ,0;Panelp5_2=newPanel(;p5_2.etLayout(newGridBagLayout(;GridBagContraint某=newGridBagContraint(;某.inet=newInet(30,60,0,80;Buttonb1,b2,b3,b4;finalTe某tFieldt1;finalTe某tFieldt2;finalTe某tAreata;LabelL1;b1=newButton(\查询名称\b1.etBackground(Color.CYAN;某.grid某=0;某.gridy=0;某.gridwidth=2;某.gridheight=1;p5_2.add(b1,某;b2=newButton(\查询范围\b2.etBackground(Color.CYAN;某.grid某=0;某.gridy=5;某.gridwidth=2;某.gridheight=1;p5_2.add(b2,某;b3=newButton(\查询\b3.etBackground(Color.CYAN;某.grid某=0;某.gridy=10;某.gridwidth=2;某.gridheight=1;p5_2.add(b3,某;b4=newButton(\返回\b4.etBackground(Color.CYAN;某.grid某=20;某.gridy=10;某.gridwidth=1;某.gridheight=1;p5_2.add(b4,某;t1=newTe某tField(10;某.grid某=20;某.gridy=0;某.gridwidth=1;某.gridheight=1;p5_2.add(t1,某;t2=newTe某tField(10;某.grid某=20;某.gridy=5;某.gridwidth=1;某.gridheight=1;p5_2.add(t2,某;L1=newLabel(\欢迎进入职工信息查询界面某某某某某某某某某某某\ L1.etBackground(Color.CYAN;c.grid某=0;c.gridy=0;c.gridwidth=0;c.gridheight=1;p5.add(L1,c;c.grid某=0;c.gridy=5;c.gridwidth=1;c.gridheight=1;p5.add(p5_2,c;ta=newTe某tArea(10,65;c.grid某=0;c.gridy=10;c.gridwidth=1;c.gridheight=1;p5.add(ta,c;p5.etBackground(Color.green;f.add(p5,\b4.addMoueLitener(newMoueAdapter({publicvoidmoueClicked(Moue Evente{t1.etTe某t(\t2.etTe某t(\ta.etTe某t(\myCard.how(f,\}};b3.addMoueLitener(newMoueAdapter({publicvoidmoueClicked(Moue Evente{try{Cla.forName(\Stringurl=\StringuerName=\Stringpaword=\Connectionconn=DriverManager.getConnection(url,uerName,pawor d;Statementtmt=conn.createStatement(;Stringql=\Stringql1=t1.getT e某t(;Stringql2=t2.getTe某t(;ql=ql+ql1+\ReultSetr=tmt.e某ecuteQuery(ql;employee[]em=newemployee[10];inti=0;while(r.ne某t({employeeem1=newemployee(;em1.num=r.getString(\工号\=r.getString(\姓名\em1.e某=r.getString(\性别\ =+\em[j].edu+\}ta.etTe某t(;r.cloe(;tmt.cloe(;}catch(E某ceptione1{e1.printStackTrace(;}}};}publicvoidgo6({p6=newPanel(;p6.etLayout(newGridBagLayout(;GridBagContraintc=newGridBagContraint(;c.inet=newInet(60,0,3 0,0;Panelp6_1=newPanel(;p6_1.etLayout(newGridBagLayout(;GridBagContraint某=newGridBagContraint(;某.inet=newInet(0,40,0,40;LabelL1;Buttonb1,b2,b3;finalTe某tAreata;b1=newButton(\按年龄排序\某.grid某=0;某.gridy=0;某.gridwidth=1;某.gridheight=1;p6_1.add(b1,某;b2=newButton(\按工资排序\某.grid某=10;某.gridy=0;某.gridwidth=1;某.gridheight=1;p6_1.add(b2,某;b3=newButton(\返回\某.grid某=15;某.gridy=0;某.gridwidth=1;某.gridheight=1;p6_1.add(b3,某;L1=newLabel(\欢迎进入职工信息查询界面某某某某某某某某某某某\ L1.etBackground(Color.CYAN;c.grid某=0;c.gridy=0;c.gridwidth=1;c.gridheight=1;p6.add(L1,c;c.grid某=0;c.gridy=5;c.gridwidth=1;c.gridheight=1;p6.add(p6_1,c;ta=newTe某tArea(10,65;c.grid某=0;c.gridy=10;c.gridwidth=1;c.gridheight=1;p6.add(ta,c;p6.etBackground(Color.green;f.add(p6,\b1.addMoueLitener(newMoueAdapter({publicvoidmoueClicked(Moue Evente{try{Cla.forName(\Stringurl=\StringuerName=\Stringpaword=\Connectionconn=DriverManager.getConnection(url,uerName,pawor d;Statementtmt=conn.createStatement(;ReultSetr=tmt.e某ecuteQuery(\employee[]em=newemployee[10];inti=0;while(r.ne某t({ employeeem1=newemployee(;em1.num=r.getString(\工号\=r.getString(\姓名\em1.e某=r.getString(\性别\em1.age=r.getString(\年龄\=r.getString(\学历\=r.getString(\工资\em1.add=r.getString(\住址\employeezz;int某,y;for(intf=1;ffor(intk=f+1;k{某=Integer.pareInt(em[f].age;y=Integer.pareInt(em[k].age;if(某>y{z z=em[f];em[f]=em[k];em[k]=zz;}}=+\em[j].edu+\}ta.etTe某t(;r.cloe(;tmt.cloe(;}catch(E某ceptione1{e1.printStackTrace(;}}};b2.addMoueLitener(newMoueAdapter({publicvoidmoueClicked(Moue Evente{try{Cla.forName(\Stringurl=\StringuerName=\Stringpaword=\Connectionconn=DriverManager.getConnection(url,uerName,pawor d;Statementtmt=conn.createStatement(;ReultSetr=tmt.e某ecuteQuery(\employee[]em=newemployee[10];inti=0;while(r.ne某t({ employeeem1=newemployee(;employeezz;int某,y;for(intf=1;ffor(intk=f+1;k{某=Integer.pareInt(em[f].la;y=Integer.pareInt(em[k].la;if(某>y{zz= em[f];em[f]=em[k];em[k]=zz;}}=+\em[j].edu+\}ta.etTe某t(;r.cloe(;tmt.cloe(;}catch(E某ceptione1{e1.printStackTrace(;}}};b3.addMoueLitener(newMoueAdapter({publicvoidmoueClicked(Moue Evente{ta.etTe某t(\myCard.how(f,\}};}publicvoidgo7({p7=newPanel(;p7.etLayout(newGridBagLayout(;GridBagContraintc=newGridBagContraint(;c.inet=newInet(40,0,5 0,0;Panelp7_1=newPanel(;p7_1.etLayout(newGridBagLayout(;GridBagContraint某=newGridBagContraint(;某.inet=newInet(30,60,0,80;LabelL1;Buttonb1,b2,b3,b4,b5,b6,b7;finalTe某tFieldt1;finalTe某tFieldt2;finalTe某tFieldt3;b1=newButton(\信息编号\b1.etBackground(Color.CYAN;某.grid某=0;某.gridy=0;某.gridwidth=1;某.gridheight=1;p7_1.add(b1,某;b2=newButton(\修改名称\b2.etBackground(Color.CYAN;某.grid某=0;某.gridy=5;某.gridwidth=1;某.gridheight=1;p7_1.add(b2,某;b3=newButton(\修改值\b3.etBackground(Color.CYAN;某.grid某=0;某.gridy=10;某.gridwidth=1;某.gridheight=1;p7_1.add(b3,某;b4=newButton(\修改\b4.etBackground(Color.CYAN;某.grid某=0;某.gridy=15;某.gridwidth=1;某.gridheight=1;p7_1.add(b4,某;b5=newButton(\返回\b5.etBackground(Color.CYAN;某.grid某=10;某.gridy=15;某.gridwidth=1;某.gridheight=1;p7_1.add(b5,某;b6=newButton(\查询\b6.etBackground(Color.CYAN;某.grid某=0;某.gridy=20;某.gridwidth=1;某.gridheight=1;p7_1.add(b6,某;b7=newButton(\继续\b7.etBackground(Color.CYAN;某.grid某=10;某.gridy=20;某.gridwidth=1;某.gridheight=1;p7_1.add(b7,某;t1=newTe某tField(16;某.grid某=10;某.gridy=0;某.gridwidth=1;某.gridheight=1;p7_1.add(t1,某;t2=newTe某tField(16;某.grid某=10;某.gridy=5;某.gridwidth=1;某.gridheight=1;p7_1.add(t2,某;t3=newTe某tField(16;某.grid某=10;某.gridy=10;某.gridwidth=1;某.gridheight=1;p7_1.add(t3,某;L1=newLabel(\欢迎进入职工信息修改界面某某某某某某某某某某某\ L1.etBackground(Color.CYAN;c.grid某=0;c.gridy=0;c.gridwidth=1;c.gridheight=1;p7.add(L1,c;c.grid某=0;c.gridy=10;c.gridwidth=1;c.gridheight=1;p7.add(p7_1,c;p7.etBackground(Color.green;f.add(p7,\b4.addMoueLitener(newMoueAdapter({publicvoidmoueClicked(Moue Evente{employeee1=newemployee(;Stringql;ql=\工号='\+t1.getTe某t(+\Sytem.out.println(ql;e1.load(ql;t1.etTe某t(\t2.etTe某t(\t3.etTe某t(\}};b5.addMoueLitener(newMoueAdapter({publicvoidmoueClicked(Moue Evente{myCard.how(f,\}};b6.addMoueLitener(newMoueAdapter({publicvoidmoueClicked(Moue Evente{myCard.how(f,\}};b7.addMoueLitener(newMoueAdapter({publicvoidmoueClicked(Moue Evente{t1.etTe某t(\t2.etTe某t(\t3.etTe某t(\}};}publicvoidgo8({p8=newPanel(;p8.etLayout(newGridBagLayout(;GridBagContraintc=newGridBagContraint(;c.inet=newInet(10,0,7 0,0;Panelp8_1=newPanel(;p8_1.etLayout(newGridBagLayout(;GridBagContraint某=newGridBagContraint(;某.inet=newInet(80,60,0,80;Buttonb1,b2,b3;LabelL1;finalTe某tFieldt1;b1=newButton(\工号\b1.etBackground(Color.CYAN;某.grid 某=0;某.gridy=0;某.gridwidth=1;某.gridheight=1;p8_1.add(b1,某;b2=newButton(\删除\b2.etBackground(Color.CYAN;某.grid某=0;某.gridy=10;某.gridwidth=1;某.gridheight=1;p8_1.add(b2,某;b3=newButton(\返回\b3.etBackground(Color.CYAN;某.grid某=10;某.gridy=10;某.gridwidth=1;某.gridheight=1;p8_1.add(b3,某;t1=newTe某tField(11;t1.etBackground(Color.CYAN;某.grid某=10;某.gridy=0;某.gridwidth=1;某.gridheight=1;p8_1.add(t1,某;L1=newLabel(\欢迎进入职工信息删除界面某某某某某某某某某某某\ L1.etBackground(Color.CYAN;c.grid某=0;c.gridy=0;c.gridwidth=1;c.gridheight=1;p8.add(L1,c;c.grid某=0;c.gridy=5;c.gridwidth=1;c.gridheight=1;p8.add(p8_1,c;p8.etBackground(Color.green;f.add(p8,\b2.addMoueLitener(newMoueAdapter({publicvoidmoueClicked(Moue Evente{employeee1=newemployee(;Stringql;ql=\工号=\Sytem.out.println(ql;e1.load(ql;}};b3.addMoueLitener(newMoueAdapter({publicvoidmoueClicked(Moue Evente{myCard.how(f,\}};}}。

职工信息管理系统java源代码

职工信息管理系统java源代码

职工信息管理系统j a v a源代码Document number:NOCG-YUNOO-BUYTT-UU986-1986UTpackage exercise;import .*;class staffInfo 入职工信息★★★┃");"┃★★★ 2.预览职工信息★★★┃");"┃★★★ 3.查找职工信息★★★┃");"┃★★★ 4.删除职工信息★★★┃");"┃★★★ 5.读取已存数据★★★┃");"┃★★★ 6.安全退出系统★★★┃");"┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛");" 请输入您需要的功能代号(1--6):");choice=());switch(choice){case 1:creat(staffOne);break;case 2:output(staffOne);break;case 3:search(staffOne);break;case 4:delete(staffOne);break;case 5:read(staffOne);break;case 6:save(staffOne);break;}}while(choice!=0);}void creat(staffInfo staffOne[]) throws IOException{final BufferedReader buf=new BufferedReader(new InputStreamReader);"请输入职工信息(以0结束)\n");"姓名:");staffOne[i].name=(); "0")!=0) um=();"性别:");staffOne[i].sex=();"年龄:");staffOne[i].age=();"学历:");staffOne[i].record=();"职位:");staffOne[i].position=();"工资:");staffOne[i].wanges=();"电话:");staffOne[i].tel=();"住址:");staffOne[i].addr=();i++;"请输入下一个职工信息:");staffOne[i].name=();}}void output(staffInfo staffOne[]) throws IOExceptionum+"\t"+staffOne[j].sex+"\t"+staffOne[j].age+"\t"+staffOne[j]. record+"\t"+staffOne[j].position+"\t\t"+staffOne[j].wanges+"\t "+staffOne[j].tel+"\t"+staffOne[j].addr+"\n");"-------------------------------------------------------------------------------------------------");}else"没有职工信息!");}}void search(staffInfo staffOne[]) throws IOException{final BufferedReader buf=new BufferedReader(new InputStreamReader);"请输入您要查找的职工工号:");recordkey=();boolean flg=true;for(int j=0;j<i;j++){if(staffOne[j].num))um+"\t"+staffOne[j].sex+"\t"+staffOne[j].age+"\t"+staffOne[j]. record+"\t"+staffOne[j].position+"\t\t"+staffOne[j].wanges+"\t "+staffOne[j].tel+"\t"+staffOne[j].addr+"\n");flg=false;}}if(flg)"对不起,查无此人!");}void delete(staffInfo staffOne[]) throws IOException{final BufferedReader buf=new BufferedReader(new InputStreamReader);"请输入您要删除的职工工号:");recordkey=();boolean flg=true;for(int j=0;j<i;j++){"输入的工号为:"+recordkey);if(staffOne[j].num)){for(int k=j;k<=i-1;k++) ame=staffOne[k+1].name ; staffOne[k].num=staffOne[k+1].num ;staffOne[k].sex=staffOne[k+1].sex;staffOne[k].age=staffOne[k+1].age ;staffOne[k].record=staffOne[k+1].record ;staffOne[k].position=staffOne[k+1].position ; staffOne[k].wanges=staffOne[k+1].wanges ;staffOne[k].tel=staffOne[k+1].tel ;staffOne[k].addr=staffOne[k+1].addr ;}i--;ame+"\n");( staffOne[k].num+"\n");( staffOne[k].sex+"\n" );( staffOne[k].age+"\n");( staffOne[k].record+"\n");( staffOne[k].position+"\n") ;( staffOne[k].wanges+"\n");( staffOne[k].tel+"\n");( staffOne[k].addr+"\n");}();"系统已经安全退出!感谢您的使用!");(0);}void read(staffInfo staffOne[]) throws IOException{final FileReader fr=new FileReader(filename);final BufferedReader bfr=new BufferedReader(fr);if((recordkey=())!=null)i=(recordkey);for(int j=0;j<i;j++){staffOne[j].name=();staffOne[j].num=();staffOne[j].sex=();staffOne[j].age=();staffOne[j].record=();staffOne[j].position=() ;staffOne[j].wanges=();staffOne[j].tel=();staffOne[j].addr=();}();"\n数据已经成功读取!");}}。

企业人事管理系统java源代码

企业人事管理系统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();}}。

人力资源管理系统应用开发纯java实现的java源代码和存在问题

人力资源管理系统应用开发纯java实现的java源代码和存在问题
PATH:增加新安装jdk的路径为C:\ProgramData\Oracle\Java\javapath;
结果:正常编译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源代码

职工信息管理系统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数据已经成功读取";}}。

java管理系统设计代码

java管理系统设计代码

在Java中设计一个管理系统通常涉及多个类和接口,下面是一个简单的例子,展示了如何设计一个基本的“员工”管理系统。

首先,我们定义一个`Employee`类,它包含员工的基本信息:```javapublic class Employee {private String name;private int id;private String department;public Employee(String name, int id, String department) { = name;this.id = id;this.department = department;}public String getName() {return name;}public int getId() {return id;}public String getDepartment() {return department;}// getter and setter methods...}```然后,我们定义一个`EmployeeManager`类,用于管理`Employee`对象:```javaimport java.util.ArrayList;import java.util.List;public class EmployeeManager {private List<Employee> employees;public EmployeeManager() {this.employees = new ArrayList<>();}public void addEmployee(Employee employee) {this.employees.add(employee);}public void removeEmployee(int id) {this.employees.removeIf(e -> e.getId() == id);}public Employee findEmployee(int id) {return this.employees.stream().filter(e -> e.getId() == id).findFirst().orElse(null);}public void printAllEmployees() {for (Employee e : this.employees) {System.out.println("Name: " + e.getName() + ", ID: " + e.getId() + ", Department: " + e.getDepartment());}}}```最后,我们在`main`方法中测试这个系统:```javapublic class Main {public static void main(String[] args) {EmployeeManager manager = new EmployeeManager();manager.addEmployee(new Employee("John Doe", 1, "IT"));manager.addEmployee(new Employee("Jane Doe", 2, "HR"));manager.addEmployee(new Employee("Alex Johnson", 3, "Sales"));manager.printAllEmployees(); // Prints all employeesmanager.removeEmployee(2); // Removes employee with ID 2manager.printAllEmployees(); // Prints allremaining employees}}```这只是一个非常基础的例子,实际的系统可能需要包含更多的功能,例如更新员工信息,搜索员工等。

Information java员工信息管理代码

Information java员工信息管理代码
Information.java import java.util.*; public class Information {
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("正在执行根据编号查找一个员工

《数据库应用》课程设计——人事管理系统(java源代码)

《数据库应用》课程设计——人事管理系统(java源代码)

《数据库应用》课程设计——人事管理系统(java源代码)//用户登陆类package classsource;import java.awt.*;import java.awt.event.*;import javax.swing.*;import java.sql.*;public class Land extends JFrame{JFrame jf ;JTextField textName=new JTextField(); JPasswordField textage=new JPasswordField(); JLabel label = new JLabel("员工管理系统");JLabel labelName=new JLabel("用户名:");JLabel labelage=new JLabel("密码:");JButton buttonEnter=new JButton("登录");JButton buttoncancel=new JButton("清空");public Land(){jf=this;setTitle("登录");Font f = new Font("新宋体",Font.PLAIN,12); Container con = getContentPane();con.setLayout(null);label.setBounds(95,10,110,20);label.setFont(new Font("新宋体",Font.PLAIN,14));con.add(label);labelName.setBounds(45,40,55,20);labelName.setFont(f);con.add(labelName);textName.setBounds(95,40,120,20);con.add(textName);labelage.setBounds(45,70,45,20);con.add(labelage);labelage.setFont(f);textage.setBounds(95,70,120,20);con.add(textage);buttonEnter.setBounds(90,110,60,20);buttonEnter.setFont(f);con.add(buttonEnter);//登陆的鼠标监听buttonEnter.addMouseListener(new MouseAdapter(){public void mouseClicked(MouseEvent me){if(textName.getText().equals("")){new JOptionPane().showMessageDialog(null,"用户名不能为空!"); }else if(textage.getText().equals("")){new JOptionPane().showMessageDialog(null,"密码不能为空!"); }else{String sql="select * from UserInformation where User_Name = '" + textName.getText() + "' and Password = '" + textage.getText()+ "'";System.out.println(sql);Judge(sql);}}});buttoncancel.setBounds(155,110,60,20);buttoncancel.setFont(f);con.add(buttoncancel);//清空按钮的鼠标监听方法buttoncancel.addMouseListener(new MouseAdapter(){public void mouseClicked(MouseEvent me){textName.setText("");textage.setText("");}});setResizable(false);Image img=Toolkit.getDefaultToolkit().getImage("image\\main.gif");setIconImage(img);Toolkit t = Toolkit.getDefaultToolkit();int w = t.getScreenSize().width;int h = t.getScreenSize().height;setBounds(w/2-150,h/2-90,300,180);setVisible(true);}private void Judge(String sqlString) {if (Database.joinDB()) {if (Database.query(sqlString))try{if(Database.rs.isBeforeFirst()) {System.out.println("密码正确");jf.setVisible(false);.close();new Main();}else {System.out.println("错误");new JOptionPane().showMessageDialog(null,"用户名或密码错误!","",JOptionPane.ERROR_MESSAGE);}}catch(Exception ex) {System.out.println(ex.getMessage());}}else{System.out.println("连接数据库不成功");}}public static void main(String args[]){new Land();}}//主函数类,可以独立运行package classsource;import java.awt.*;import java.awt.event.*;import javax.swing.*;import java.sql.*;public class Main extends JFrame implements Runnable{ Thread t=new Thread(this);JDesktopPane deskpane = new JDesktopPane();JPanel p = new JPanel();Label lp1=new Label("欢迎使用员工管理系统 !"); ImageIcon icon1=new ImageIcon("imagetjsc.gif"); ImageIcon icon2=new ImageIcon("imagecxdl.gif"); ImageIcon icon3=new ImageIcon("imagexgmm.gif"); ImageIcon icon4=new ImageIcon("imagetcxt.gif"); ImageIcon icon5=new ImageIcon("imagejj.gif"); ImageIcon icon6=new ImageIcon("imagehelp.gif"); ImageIcon icon7=new ImageIcon("imagecx.gif"); ImageIcon icon8=new ImageIcon("imagegl.gif");ImageIcon icon9=new ImageIcon("imagext.gif");ImageIcon icon10=new ImageIcon("imagexxgl.gif");ImageIcon icon11=new ImageIcon("imagexxcx.gif");ImageIcon icon12=new ImageIcon("imagebz.gif");ImageIcon icon13=new ImageIcon("imagegy.gif");ImageIcon icon14=new ImageIcon("imageglxx.gif");ImageIcon icon15=new ImageIcon("imagecxxx.gif");//完--------------------------------------------------------------------------------public Main(){setTitle("员工管理系统");Container con = getContentPane();con.setLayout(new BorderLayout());con.add(deskpane,BorderLayout.CENTER);Font f =new Font("新宋体",Font.PLAIN,12);JMenuBar mb = new JMenuBar();JMenu systemM = new JMenu("系统管理");systemM.setFont(f);JMenu manageM = new JMenu("信息管理");manageM.setFont(f);JMenu employeeMM = new JMenu("员工信息管理");employeeMM.setFont(f);JMenu selectM = new JMenu("信息查询");selectM.setFont(f);JMenu employeeSM =new JMenu("员工信息查询"); employeeSM.setFont(f);JMenu helpM = new JMenu("帮助");helpM.setFont(f);JMenu aboutM=new JMenu("关于");aboutM.setFont(f);JMenuItem password = new JMenuItem("密码修改"); password.setFont(f);JMenuItem land = new JMenuItem("重新登陆");land.setFont(f);JMenuItem addDelete = new JMenuItem("添加/删除用户"); addDelete.setFont(f);JMenuItem exit = new JMenuItem("退出系统");exit.setFont(f);systemM.add(password);systemM.add(land);systemM.add(addDelete);systemM.add(exit);//为系统管理菜单加事件password.addActionListener(new ActionListener(){ public void actionPerformed(ActionEvent e){System.out.println("AmendPassword");deskpane.add(new AmendPassword());}});land.addActionListener(new ActionListener(){public void actionPerformed(ActionEvent e){System.out.println("Land");setVisible(false);new Land();}});addDelete.addActionListener(new ActionListener(){ public void actionPerformed(ActionEvent e){ deskpane.add(new AddDeleteUser());}});exit.addActionListener(new ActionListener(){public void actionPerformed(ActionEvent e){//new JOptionPane().showMessageDialog(setVisible(false);}});JMenuItem departmentM = new JMenuItem("部门信息管理"); departmentM.setFont(f);JMenuItem employeeM = new JMenuItem("基本信息管理"); employeeM.setFont(f);JMenuItem trainM = new JMenuItem("培训信息管理");trainM.setFont(f);JMenuItem encouragementPunishM = new JMenuItem("奖罚信息管理"); encouragementPunishM.setFont(f);JMenuItem wageM =new JMenuItem("薪资信息管理");wageM.setFont(f);employeeMM.add(trainM);employeeMM.add(employeeM);employeeMM.add(encouragementPunishM);employeeMM.add(wageM);manageM.add(employeeMM);manageM.add(departmentM);//为管理菜单加事件departmentM.addActionListener(new ActionListener(){public void actionPerformed(ActionEvent e){System.out.println("Departmentmanage");deskpane.add(new Departmentmanage());}});employeeM.addActionListener(new ActionListener(){public void actionPerformed(ActionEvent e){System.out.println("Employeemanage");deskpane.add(new Employeemanage());}});trainM.addActionListener(new ActionListener(){public void actionPerformed(ActionEvent e){System.out.println("Trainmanage");deskpane.add(new Trainmanage());}});encouragementPunishM.addActionListener(new ActionListener(){ public void actionPerformed(ActionEvent e){System.out.println("EncouragementPunish");deskpane.add(new EncouragementPunish());}});wageM.addActionListener(new ActionListener(){public void actionPerformed(ActionEvent e){System.out.println("WageManage");deskpane.add(new WageManage());}});JMenuItem departmentS = new JMenuItem("部门信息查询"); departmentS.setFont(f);JMenuItem employeeS = new JMenuItem("基本信息查询"); employeeS.setFont(f);JMenuItem trainS = new JMenuItem("培训信息查询");trainS.setFont(f);JMenuItem encouragementPunishS = new JMenuItem("奖罚信息查询"); encouragementPunishS.setFont(f);JMenuItem wageS =new JMenuItem("薪资信息查询");wageS.setFont(f);employeeSM.add(trainS);employeeSM.add(employeeS);employeeSM.add(encouragementPunishS);employeeSM.add(wageS);selectM.add(employeeSM);selectM.add(departmentS);//为查询菜单加事件departmentS.addActionListener(new ActionListener(){public void actionPerformed(ActionEvent e){System.out.println("DIQ");deskpane.add(new DIQ());}});employeeS.addActionListener(new ActionListener(){public void actionPerformed(ActionEvent e){System.out.println("BIQ");deskpane.add(new BIQ());}});trainS.addActionListener(new ActionListener(){public void actionPerformed(ActionEvent e){System.out.println("TIQ");deskpane.add(new TIQ());}});encouragementPunishS.addActionListener(new ActionListener(){ public void actionPerformed(ActionEvent e){System.out.println("EPIQ");deskpane.add(new EPIQ());}});wageS.addActionListener(new ActionListener(){public void actionPerformed(ActionEvent e){System.out.println("SIQ");deskpane.add(new SIQ());}});JMenuItem help = new JMenuItem("帮助");help.setFont(f);JMenuItem about =new JMenuItem("关于");about.setFont(f);helpM.add(help);aboutM.add(about);//为帮助菜单加事件about.addActionListener(new ActionListener(){public void actionPerformed(ActionEvent e){deskpane.add(new About());}});mb.add(systemM);mb.add(manageM);mb.add(selectM);mb.add(helpM);mb.add(aboutM);setJMenuBar(mb);Image img=Toolkit.getDefaultToolkit().getImage("imagemain.gif"); setIconImage(img);systemM.setIcon(icon9);manageM.setIcon(icon8);selectM.setIcon(icon7);helpM.setIcon(icon6);addDelete.setIcon(icon1);land.setIcon(icon2);password.setIcon(icon3);exit.setIcon(icon4);employeeMM.setIcon(icon5);employeeSM.setIcon(icon5);departmentM.setIcon(icon10);departmentS.setIcon(icon11);help.setIcon(icon6);aboutM.setIcon(icon13);about.setIcon(icon13);employeeM.setIcon(icon14);trainM.setIcon(icon14); encouragementPunishM.setIcon(icon14); wageM.setIcon(icon14);employeeS.setIcon(icon15);trainS.setIcon(icon15); encouragementPunishS.setIcon(icon15); wageS.setIcon(icon15);JToolBar jToolBar1 = new JToolBar(); jToolBar1.setLayout(new GridLayout(9,1)); JButton jButton1 = new JButton();jButton1.setToolTipText("员工基本信息管理"); JButton jButton2 = new JButton();jButton2.setToolTipText("员工基本信息查询"); JButton jButton3 = new JButton();jButton3.setToolTipText("修改密码");JButton jButton5 = new JButton();jButton5.setToolTipText("计算器");JButton jButton6 = new JButton();jButton6.setToolTipText("退出系统");jToolBar1.setMaximumSize(new java.awt.Dimension(600, 50)); jToolBar1.setMinimumSize(new java.awt.Dimension(600, 50)); //添加工具栏中按钮的方法jButton1.setIcon(new ImageIcon("image1.png"));jButton1.addActionListener(new ActionListener(){public void actionPerformed(ActionEvent e){System.out.println("Employeemanage");deskpane.add(new Employeemanage());}});jToolBar1.add(jButton1);jButton2.setIcon(new ImageIcon("image2.png"));jButton2.addActionListener(new ActionListener(){public void actionPerformed(ActionEvent e){deskpane.add(new BIQ());}});jToolBar1.add(jButton2);jButton3.setIcon(new ImageIcon("image3.png"));jButton3.addActionListener(new ActionListener(){public void actionPerformed(ActionEvent e){deskpane.add(new AmendPassword());}});jToolBar1.add(jButton3);jButton5.setIcon(new ImageIcon("image5.png"));jButton5.addActionListener(new ActionListener(){public void actionPerformed(ActionEvent e){System.out.println("Calculator");deskpane.add(new Calculator());}});jToolBar1.add(jButton5);jButton6.setIcon(new javax.swing.ImageIcon("image6.png")); jButton6.addActionListener(new ActionListener(){public void actionPerformed(ActionEvent e){System.exit(0);}});jToolBar1.add(jButton6);jToolBar1.setBounds(0, 0, 30, 600);jToolBar1.setEnabled(false);con.add(jToolBar1,BorderLayout.WEST);p.setLayout(new BorderLayout());p.add(lp1,BorderLayout.EAST);t.start();con.add(p,BorderLayout.SOUTH);Toolkit t = Toolkit.getDefaultToolkit();int width = t.getScreenSize().width - 200; int height = t.getScreenSize().height - 100; setSize(width,height);setLocation(150,100);setVisible(true);setResizable(false);}//线程的方法public void run(){System.out.println("线程启动了!");Toolkit t = Toolkit.getDefaultToolkit();int x=t.getScreenSize().width;System.out.println("x=" + x);lp1.setForeground(Color.red);while(true){if(x<-600){x=t.getScreenSize().width;}lp1.setBounds(x,0,700,20);x-=10;try{Thread.sleep(100);}catch(Exception e){} }}public static void main(String[] args){new Main();}}//数据库联接类package classsource;import java.sql.*;public class Database {public static Connection cn;public static Statement st;public static ResultSet rs;public static boolean joinDB() {boolean joinFlag;try {joinFlag = true;Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");cn =DriverManager.getConnection("jdbc:odbc:EmployeeInformationMS","sa"," ");cn.setCatalog("EmployeeInformationMS");System.out.println("数据库连接成功");st = cn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_READ_ONLY);return joinFlag;} catch (SQLException sqlEx) {System.out.println(sqlEx.getMessage());joinFlag = false;return joinFlag;} catch (ClassNotFoundException notfoundEX) { System.out.println(notfoundEX.getMessage());joinFlag = false;return joinFlag;}}public static boolean executeSQL(String sqlString) { boolean executeFlag;try {st.execute(sqlString);executeFlag = true;} catch (Exception e) {executeFlag = false;System.out.println("sql exception:" + e.getMessage()); }return executeFlag;}public static boolean query(String sqlString) {try {rs = null;//System.out.println(sqlString);rs = st.executeQuery(sqlString);} catch (Exception Ex) {System.out.println("sql exception:" + Ex);return false;}return true;}}//添加删除用户类package classsource;import java.awt.event.*;import java.awt.*;import javax.swing.*;import java.sql.*;public class AddDeleteUser extends javax.swing.JInternalFrame { private JButton butACancel,butDCancel,butDelete,butOk;private JComboBox cbUserName;private JLabel jLabel1,jLabel2,jLabel3,jLabel4,jLabel5;private JPasswordField pas1,pas2,pas3;private JTextField txtname;public AddDeleteUser() {initComponents();this.setVisible(true);this.setClosable(true);this.setSize(268,350);}private void initComponents() { jLabel1 = new JLabel();jLabel2 = new JLabel();jLabel3 = new JLabel();txtname = new JTextField();pas1 = new JPasswordField();pas2 = new JPasswordField(); butOk = new JButton();butACancel = new JButton();jLabel4 = new JLabel(); cbUserName = new JComboBox(); jLabel5 = new JLabel();pas3 = new JPasswordField(); butDelete = new JButton(); butDCancel = new JButton(); getContentPane().setLayout(null); jLabel1.setText("新用户名:"); getContentPane().add(jLabel1); jLabel1.setBounds(30, 30, 70, 20); jLabel2.setText("输入密码:");getContentPane().add(jLabel2);jLabel2.setBounds(30, 60, 70, 18); jLabel3.setText("确认密码:"); getContentPane().add(jLabel3);jLabel3.setBounds(30, 90, 60, 18); getContentPane().add(txtname); txtname.setBounds(100, 30, 130, 24); getContentPane().add(pas1);pas1.setBounds(100, 60, 130, 24); getContentPane().add(pas2);pas2.setBounds(100, 90, 130, 24); butOk.setText("添加");getContentPane().add(butOk);butOk.setBounds(80, 130, 70, 27); butACancel.setText("清空"); getContentPane().add(butACancel); butACancel.setBounds(160, 130, 70, 27); jLabel4.setText("已有用户名:"); getContentPane().add(jLabel4);jLabel4.setBounds(30, 180, 80, 18); getContentPane().add(cbUserName); cbUserName.setBounds(100, 180, 130, 24); jLabel5.setText("密码:"); getContentPane().add(jLabel5);jLabel5.setBounds(30, 210, 60, 18);getContentPane().add(pas3);pas3.setBounds(100, 216, 130, 24);butDelete.setText("删除");getContentPane().add(butDelete);butDelete.setBounds(79, 260, 70, 27);butDCancel.setText("清空");getContentPane().add(butDCancel);butDCancel.setBounds(160, 260, 70, 27);//将所有用用户名读出来Database.joinDB();String sql="select * from UserInformation";try{if(Database.query(sql)){while(Database.rs.next()){String name=Database.rs.getString("User_Name");cbUserName.addItem(name);}}}catch(Exception e){}//为添加和取消按钮加事件----------------------------------------- butOk.addActionListener(new ActionListener(){public void actionPerformed(ActionEvent e){if(txtname.getText().equals("")){new JOptionPane().showMessageDialog(null,"用户名不能为空!");}else if(pas1.getText().equals("")){new JOptionPane().showMessageDialog(null,"密码不能为空!");}else if(pas1.getText().equals(pas2.getText())){String sql="insert UserInformation values('"+ txtname.getText() +"','"+ pas1.getText() +"','B')";try{if(Database.executeSQL(sql)){new JOptionPane().showMessageDialog(null,"添加成功!");cbUserName.addItem(txtname.getText());}}catch(Exception ea){}}}});butACancel.addActionListener(new ActionListener(){public void actionPerformed(ActionEvent e){txtname.setText("");pas1.setText("");pas2.setText("");}});//为删除和取消按钮加事件--------------------------------------- butDelete.addActionListener(new ActionListener(){public void actionPerformed(ActionEvent e){String name="" + cbUserName.getSelectedItem();String sql="select * from UserInformation where User_Name='"+ name +"'";try{if(Database.query(sql)){Database.rs.next();String pas=pas3.getText();String password=Database.rs.getString("Password");System.out.println(password);if(pas.equals(password)){String sdelete="delete from UserInformation where User_Name='"+ name +"'";if(Database.executeSQL(sdelete)){new JOptionPane().showMessageDialog(null,"删除成功!");pas3.setText("");cbUserName.removeAllItems();String sql1="select * from UserInformation";if(Database.query(sql1)){while(Database.rs.next()){Stringname1=Database.rs.getString("User_Name"); cbUserName.addItem(name1);}}}}else{new JOptionPane().showMessageDialog(null,"密码不正确!");}}}catch(Exception el){System.out.println(el);}}});butDCancel.addActionListener(new ActionListener(){ public void actionPerformed(ActionEvent e){pas3.setText("");}});}}//修改密码类package classsource;import java.awt.*;import java.awt.event.*;import javax.swing.*;import java.sql.*;public class AmendPassword extends JInternalFrame { JLabel lbe1=new JLabel("修改密码");JPanel p=new JPanel();public AmendPassword(){setTitle("修改密码");p.add(lbe1);AmendPanel panel=new AmendPanel();Container contentPane=getContentPane(); contentPane.add(p,"North");contentPane.add(panel,"Center");setBounds(100, 100, 280, 260);this.setClosable(true);setVisible(true);}}class AmendPanel extends JPanel {JButton b1,b2;JLabel lbe2,lbe3,lbe4,lbe5; JPasswordField pas1,pas2,pas3; JComboBox tf;public AmendPanel(){lbe2=new JLabel("用户名:");lbe3=new JLabel("输入旧密码:"); lbe4=new JLabel("输入新密码:"); lbe5=new JLabel("确定新密码:"); tf=new JComboBox();pas1=new JPasswordField();pas2=new JPasswordField();pas3=new JPasswordField();b1=new JButton("确定");b2=new JButton("清空");add(lbe2);lbe2.setBounds(16,10,90,25); this.add(tf);tf.setBounds(100,10,120,25); add(lbe3);lbe3.setBounds(16,45,90,25);add(pas1);pas1.setBounds(100,45,120,25);add(lbe4);lbe4.setBounds(16,80,80,25);add(pas2);pas2.setBounds(100,80,120,25);add(lbe5);lbe5.setBounds(16,115,80,25);add(pas3);pas3.setBounds(100,115,120,25);add(b1);b1.setBounds(100,160,60,30);add(b2);b2.setBounds(160,160,60,30);setLayout(null);//将所有用用户名读出来Database.joinDB();String sql="select * from UserInformation";try{if(Database.query(sql)){while(Database.rs.next()){String name=Database.rs.getString("User_Name"); tf.addItem(name);}}}catch(Exception e){}//为确定取消按钮加事件b1.addActionListener(new ActionListener(){public void actionPerformed(ActionEvent e){String name="" + tf.getSelectedItem();System.out.println(name);String sql="select * from UserInformation where User_Name='"+ name +"'";System.out.println(sql);try{if(Database.query(sql)){Database.rs.next();String ps1=pas1.getText();String password=Database.rs.getString("Password");if(ps1.equals(password)){if(pas2.getText().equals(pas3.getText())){String supdate="update UserInformation set Password='"+pas3.getText()+"' where User_Name='"+ name +"'";Database.executeSQL(supdate);new JOptionPane().showMessageDialog(null,"密码更改成功!");}else{new JOptionPane().showMessageDialog(null,"两次密码不同!");}}else{new JOptionPane().showMessageDialog(null,"旧密码不正确!");}}}catch(Exception el){System.out.println(el);}}});b2.addActionListener(new ActionListener(){public void actionPerformed(ActionEvent e){pas1.setText("");pas2.setText("");pas3.setText("");}});}}//关于类package classsource;import java.awt.*;import java.awt.event.*;import javax.swing.*;public class About extends JInternalFrame {JLabel label = new JLabel("运行环境:Windows");JLabel labe2 = new JLabel("开发语言:JAVA");JLabel labe3 = new JLabel("数据库类型:SqlServer2000"); public About(){setTitle("关于");Container con=getContentPane();con.setLayout(new GridLayout(4,1));con.add(label);con.add(labe2);con.add(labe3);con.setBackground(Color.white);setResizable(false);setSize(380,220);setVisible(true);setClosable(true);}}//员工信息查询类package classsource;import java.awt.*;import javax.swing.*;import javax.swing.table.*;import java.awt.event.*;import java.util.*;import javax.swing.JScrollPane.*;import java.sql.*;public class BIQ extends JInternalFrame{JLabel lbl1=new JLabel("基本信息查询");JLabel lbl2=new JLabel("员工编号:");JLabel lbl3=new JLabel("员工姓名:");JTextField btxtid=new JTextField(10);JTextField btxtname=new JTextField(10);JButton btn1=new JButton("查询");JTable table;DefaultTableModel dtm;String columns[] = {"员工编号","员工姓名"," 性别 ","出生日期","婚姻状况","政治面貌"," 学历 ","进入公司时间","转正时间"," 部门 "," 职务 ","员工状态"," 备注"};public BIQ(){setTitle("基本信息查询");dtm = new DefaultTableModel();table = new JTable(dtm);JScrollPane sl = new JScrollPane();sl.getViewport().add(table);dtm.setColumnCount(5);dtm.setColumnIdentifiers(columns); getContentPane().setLayout(null);lbl1.setBounds(240,10,300,30);lbl1.setFont(new Font("宋体",Font.BOLD,24)); getContentPane().add(lbl1);Font f=new Font("宋体",Font.PLAIN,12);lbl2.setBounds(10,60,80,25);lbl2.setFont(f);getContentPane().add(lbl2);btxtid.setBounds(80,60,80,23);btxtid.setFont(f);getContentPane().add(btxtid);lbl3.setBounds(10,90,80,25);lbl3.setFont(f);getContentPane().add(lbl3);btxtname.setBounds(80,90,80,23);btxtname.setFont(f);getContentPane().add(btxtname);btn1.setBounds(90,130,60,25);btn1.setFont(f);getContentPane().add(btn1);sl.setBounds(180,60,500,370);getContentPane().add(sl);//设置边框btxtid.setBorder(BorderFactory.createLineBorder(Color.black));btxtname.setBorder(BorderFactory.createLineBorder(Color.black));btn1.setBorder(BorderFactory.createRaisedBevelBorder());sl.setBorder(BorderFactory.createLineBorder(Color.black));//----连接数据库--------------------------------------------------------------------------Database.joinDB();String sql="select * from EmployeeInformation";if(Database.query(sql)){System.out.println(sql);try{while(Database.rs.next()){String eNumber=(""+Database.rs.getInt("E_Number"));System.out.println(eNumber);String eName=Database.rs.getString("E_Name");System.out.println(eName);String eSex=Database.rs.getString("E_Sex");System.out.println(eSex);String eBornDate=Database.rs.getString("E_BornDate");System.out.println(eBornDate);String eMarriage=Database.rs.getString("E_Marriage");System.out.println(eMarriage);StringePoliticsVisage=Database.rs.getString("E_PoliticsVisage"); System.out.println(ePoliticsVisage);String eSchoolAge=Database.rs.getString("E_SchoolAge"); System.out.println(eSchoolAge);String eEnterDate=Database.rs.getString("E_EnterDate"); System.out.println(eEnterDate);String eInDueFormDate=Database.rs.getString("E_InDueFormDate"); System.out.println(eInDueFormDate);String eDepartment=Database.rs.getString("E_Department"); System.out.println(eDepartment);String eHeadship=Database.rs.getString("E_Headship");System.out.println(eHeadship);String eEstate=Database.rs.getString("E_Estate");System.out.println(eEstate);String eRemark=Database.rs.getString("E_Remark");System.out.println(eRemark);Vector v=new Vector();v.add(eNumber);v.add(eName);v.add(eSex);v.add(eBornDate);v.add(eMarriage);v.add(ePoliticsVisage);v.add(eSchoolAge);v.add(eEnterDate);v.add(eInDueFormDate);v.add(eDepartment);v.add(eHeadship);v.add(eEstate);v.add(eRemark);dtm.addRow(v);}}catch(Exception eBIQ){System.out.println("初始化数据失败!");}}//为查询按钮加事件btn1.addActionListener(new ActionListener(){ public void actionPerformed(ActionEvent eBIQ){ System.out.println("按钮事件");String esql;int rc=dtm.getRowCount();for(int i=0;i<rc;i++){dtm.removeRow(0);}if(btxtid.getText().equals("")&&btxtname.getText().equals("")){ esql="select * from EmployeeInformation";}else if(btxtname.getText().equals("")){esql="select * from EmployeeInformation where E_Number = '" + btxtid.getText() +"'";}else{esql="select * from EmployeeInformation where E_Number = '" + btxtid.getText() +"' or E_Name like '%"+ btxtname.getText() +"%'";}System.out.println(esql);if(Database.query(esql)){try{while(Database.rs.next()){String eNumber=(""+Database.rs.getInt("E_Number"));System.out.println(eNumber);String eName=Database.rs.getString("E_Name");System.out.println(eName);。

职工信息管理系统代码

职工信息管理系统代码

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. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。

package exercise;import java.io.*;class staffInfo //职工类{public String name;public String num;public String sex;public String age;public String record;public String position;public String wanges;public String tel;public String addr;}public class StaffInfomation //实现部分{public static void main(final String[] args) throws IOException {staffInfo staffOne[]=new staffInfo[100];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 String recordkey;public int i=0;//i用来存放职工的人数public String filename="Infomation.txt";BufferedReader buf=new BufferedReader(new InputStreamReader(System.in));void caidan(staffInfo staffOne[]) throws IOException{final BufferedReader buf=new BufferedReader(new InputStreamReader(System.in)); //此处是JAVA语言中输入数据的基本格式,功能有如C中的scanf函数int choice;do{System.out.println("┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓");System.out.println("┃★★★★★★★★职工管理系统主菜单界面★★★★★★★★┃");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("┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛");System.out.print(" 请输入您需要的功能代号(1--6):");choice=Integer.parseInt(buf.readLine());switch(choice){case 1:creat(staffOne);break;case 2:output(staffOne);break;case 3:search(staffOne);break;case 4:delete(staffOne);break;case 5:read(staffOne);break;case 6:save(staffOne);break;}}while(choice!=0);}void creat(staffInfo staffOne[]) throws IOException{final BufferedReader buf=new BufferedReader(newInputStreamReader(System.in));System.out.print("请输入职工信息(以0结束)\n");System.out.print("姓名:");staffOne[i].name=buf.readLine(); //用数组staffOne[i]来暂存职工的相关信息while(staffOne[i]pareTo("0")!=0) //用compareTo方法确定判定是否应该写入新信息{System.out.print("工号:");staffOne[i].num=buf.readLine();System.out.print("性别:");staffOne[i].sex=buf.readLine();System.out.print("年龄:");staffOne[i].age=buf.readLine();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();i++;System.out.println("请输入下一个职工信息:");staffOne[i].name=buf.readLine();}}void output(staffInfo staffOne[]) throws IOException //这里是实现“输出(预览)职工信息”output的模块{for(int j=0;j<i;j++){if(i!=0){System.out.println("------------------------------------------------------------------------------------------------");System.out.println(" *职工信息表* ");System.out.println("-------------------------------------------------------------------------------------------------");System.out.println("姓名\t工号\t\t性别\t年龄\t学历\t职位\t\t工资\t电话号码 \t\t住址");System.out.println("-------------------------------------------------------------------------------------------------");System.out.print(staffOne[j].name+"\t"+staffOne[j].num+"\t"+staff One[j].sex+"\t"+staffOne[j].age+"\t"+staffOne[j].record+"\t"+staf fOne[j].position+"\t\t"+staffOne[j].wanges+"\t"+staffOne[j].tel+" \t"+staffOne[j].addr+"\n");System.out.println("-------------------------------------------------------------------------------------------------");}else System.out.println("没有职工信息!");}}void search(staffInfo staffOne[]) throws IOException{final BufferedReader buf=new BufferedReader(new InputStreamReader(System.in));System.out.print("请输入您要查找的职工工号:");recordkey=buf.readLine();boolean flg=true;for(int j=0;j<i;j++){if(recordkey.equals(staffOne[j].num)) //equals是字符串比较函数相等返回true{System.out.println("-------------------------------------------------------------------------------------");System.out.println(" *职工信息表* ");System.out.println("--------------------------------------------------------------------------------------");System.out.println("姓名\t工号\t\t性别\t年龄\t学历\t职位 \t\t 工资\t电话号码 \t\t住址");System.out.println("--------------------------------------------------------------------------------------");System.out.println(staffOne[j].name+"\t"+staffOne[j].num+"\t"+sta ffOne[j].sex+"\t"+staffOne[j].age+"\t"+staffOne[j].record+"\t"+st affOne[j].position+"\t\t"+staffOne[j].wanges+"\t"+staffOne[j].tel +"\t"+staffOne[j].addr+"\n");flg=false;}}if(flg)System.out.println("对不起,查无此人!");}void delete(staffInfo staffOne[]) throws IOException{final BufferedReader buf=new BufferedReader(new InputStreamReader(System.in));System.out.print("请输入您要删除的职工工号:");recordkey=buf.readLine();boolean flg=true;for(int j=0;j<i;j++){System.out.println("输入的工号为:"+recordkey);if(recordkey.equals(staffOne[j].num)){for(int k=j;k<=i-1;k++) //利用顺序表的删除算法,删除值之后,再把后面的值往前移位,从而实现删除{staffOne[k].name=staffOne[k+1].name ;staffOne[k].num=staffOne[k+1].num ;staffOne[k].sex=staffOne[k+1].sex;staffOne[k].age=staffOne[k+1].age ;staffOne[k].record=staffOne[k+1].record ;staffOne[k].position=staffOne[k+1].position ;staffOne[k].wanges=staffOne[k+1].wanges ;staffOne[k].tel=staffOne[k+1].tel ;staffOne[k].addr=staffOne[k+1].addr ;}i--;//职工人数减一flg=false;}}if(flg)System.out.println("对不起,查无此人!。

相关文档
最新文档