职员管理系统
侧边栏壁纸
  • 累计撰写 28 篇文章
  • 累计收到 3 条评论

职员管理系统

admin
2022-06-22 / 0 评论 / 65 阅读 / 正在检测是否收录...

main.cpp的内容

#include"add.h"
#include<iostream>
#include<string>
#include<algorithm>
#include<fstream>
#include<stdlib.h>
using namespace std;
void CreatAdmin();
int main()
{
    char Choice;
    string UserName,PassWord;
    string InputUserName,InputPassWord;
    ifstream fin("admin.dat",ios::in);
    if(!fin)
    {
        cout<<"还未创建admin用户,请创建";
        CreatAdmin();
        fin.close();
    }
    fin.close();
    fin.open("admin.dat",ios::in);
    fin>>UserName;
    fin>>PassWord;
    cout<<"请输入admin用户名"<<endl;
    cin>>InputUserName;
    cout<<"请输入admin密码"<<endl;
    cin>>InputPassWord;
    if(UserName==InputUserName && InputPassWord==PassWord)
    {
        system("cls");
        cout<<"已进入系统!"<<endl;
        PrintWlecome(UserName);
        cin>>Choice;
        while (1)
        {
            JusticeUsersChoice(Choice);
            system("color 04");
            cout<<"请选择操作\n1.存入信息\n2.删除信息\n3.查找信息\n4.遍历信息\n5.修改信息"<<endl;
            cin>>Choice;
        }
        

    }
    else{
        cout<<"用户名或者密码不正确"<<endl;
        exit(0);
    }
    system("pause");


}
void CreatAdmin()
{
    string UserName,PassWord;
    ofstream fout("admin.dat",ios::out|ios::binary);
    cout<<"请输入admin用户名"<<endl;
    cin>>UserName;
    cout<<"请输入admin密码"<<endl;
    cin>>PassWord;
    fout<<UserName<<" "<<PassWord;
    fout.close();
    system("cls");
    
}

add.h的内容

#include<iostream>
#include<fstream>
#include<ctime>
#include<Windows.h>
using namespace std;
void GetUserInput();
void PrintWlecome(string UserName);
void GetUserInput();
void JusticeUsersChoice(char Choice);
void PointReadFile();
void ThroughAll();
void ReviseData();
bool DeletInfo();
void LogWrite();
class Person
{
private:
    string name;
    string id;
    string numbers;
    string address;
    char sex;
    string age;
    double salary;
    string diploma;

public:
    void Set_value(string name1,string id1,string number,string address1,char sex1,double salary1,string age1,string diploma1)
    {
        name=name1;
        id=id1;
        numbers=number;
        address=address1;
        sex=sex1;
        salary=salary1;
        diploma=diploma1;
        age=age1;

    }
    friend ofstream &operator<<(ofstream &fout,Person &a)
    {
        fout<<a.id<<" "<<a.name<<" "<<a.numbers<<" "<<a.address<<" "<<a.sex<<" "<<a.age<<" "<<a.salary<<" "<<a.diploma<<endl;
        return fout;
    }
    void print()
    {
        cout<<id<<"\t"<<name<<"\t"<<numbers<<"\t"<<address<<"\t"<<sex<<"\t"<<age<<"\t"<<salary<<"\t"<<diploma<<endl;
    }
    int Write()
    {
        ofstream fout("num.dat",ios::app);
        if(!fout)
        {
            cout<<"打开文件num.dat失败"<<endl;

        }
        fout<<id<<" "<<name<<" "<<numbers<<" "<<address<<" "<<sex<<" "<<age<<" "<<salary<<" "<<diploma<<endl;
        fout.close();
        return 0;
    }
    friend ostream &operator<<(ostream &out,Person &a)
    {  
        
        out<<a.id<<" "<<a.name<<" "<<a.numbers<<" "<<a.address<<" "<<a.sex<<" "<<a.age<<" "<<a.salary<<" "<<a.diploma<<endl;
        return out;
    }
    friend ifstream &operator>>(ifstream &fin,Person &people)
    {
        fin>>people.id;
        fin>>people.name;
        fin>>people.address;
        fin>>people.sex;
        fin>>people.age;
        fin>>people.salary;
        fin>>people.diploma;
        return fin;
    }

};
void LogWrite(Person people,string operate)
{
    SYSTEMTIME systime={0};
    GetSystemTime(&systime);
    ofstream fout("log.txt",ios::app);
    fout<<people<<"\t"<<operate<<" "<<systime.wYear<<":"<<systime.wMonth<<":"<<systime.wDay<<":"<<systime.wHour+8<<":"<<systime.wMinute<<":"<<systime.wSecond<<endl;


}
void PrintWlecome(string UserName)
{
    system("color 04");
    SYSTEMTIME systime={0};
    GetSystemTime(&systime);
    cout<<"尊敬的 "<<UserName<<" 欢迎进入进入本系统!"<<endl;
    cout<<"系统当前时间:"<<systime.wYear<<":"<<systime.wMonth<<":"<<systime.wDay<<":"<<systime.wHour+8<<":"<<systime.wMinute<<":"<<systime.wSecond<<endl;
    cout<<"请选择操作\n1.存入信息\n2.删除信息\n3.查找信息\n4.遍历信息\n5.修改信息"<<endl;
}
void GetUserInput()
{
    string name1;
    string id1;
    string number1;
    string address1;
    char sex1;
    string age1;
    double salary1;
    string diploma1;
    Person people;
    cout<<"请输入\nid 名字 number 地址 性别(m/f) 年龄 薪水 学历(中间有空格)"<<endl;
    cin>>id1>>name1>>number1>>address1>>sex1>>age1>>salary1>>diploma1;
    people.Set_value(name1,id1,number1,address1,sex1,salary1,age1,diploma1);
    people.print();
    people.Write();
    LogWrite(people,"输入");

}
void JusticeUsersChoice(char Choice)
{
    if(Choice=='1')
        {
            GetUserInput();

        }
        else if(Choice=='2')
        {
            DeletInfo();
        }
         else if(Choice=='3')
        {
            PointReadFile();
        }
         else if(Choice=='4')
        {
            ThroughAll();
        }
        else if(Choice=='5')
        {
            ReviseData();
        }
        else{
            cout<<"好歹也要选择一个嘛"<<endl;
        }
}
void PointReadFile()
{   
    bool point=0;
    char Choice;
    string FoundName;
    string Diploma;
    string name1;
    string id1;
    string number1;
    string address1;
    char sex1;
    string age1;
    double salary1;
    string diploma1;
    Person people;
    ifstream fin("num.dat",ios::in);
    cout<<"请输入序号\n1.查询id\n2.学历"<<endl;
    cin>>Choice;
    if(Choice=='1')
    {
        cout<<"请输入id"<<endl;
        cin>>FoundName;
    }
    else
    {
        cout<<"请输入学历"<<endl;
        cin>>Diploma;
    }
    if(!fin)
    {
        cout<<"打开文件num.dat失败"<<endl;
    }
    while(1)
    {
    fin>>id1;
    fin>>name1;
    fin>>number1;
    fin>>address1;
    fin>>sex1;
    fin>>age1;
    fin>>salary1;
    fin>>diploma1;
    people.Set_value(name1,id1,number1,address1,sex1,salary1,age1,diploma1);
    if(FoundName==id1)
    {
        break;
    }
    else if(Diploma==diploma1&&!fin.eof())
    {
        cout<<"id 名字 number 地址 性别 年龄 薪水 学历"<<endl;
        cout<<people;
        LogWrite(people,"查找");
        point=1;
    }
    if(fin.eof())
    {
        if(!point)
        {
            cout<<"查无此人"<<endl;
        }
        
        break;
    }
    }
    if(FoundName==id1)
    {
        cout<<people;
        LogWrite(people,"查找");
    } 
    
}
bool DeletInfo()
{
    string FoundId;
    string name1;
    string id1;
    string number1;
    string address1;
    char sex1;
    string age1;
    double salary1;
    string diploma1;
    Person people;
    int point=1;
    bool HasFound=0;
    ofstream fout("mid.dat",ios::app);
    ifstream fin("num.dat",ios::in);
    cout<<"输入你想查找的id"<<endl;
    cin>>FoundId;
    while (point)
    {

    fin>>id1;
    fin>>name1;
    fin>>number1;
    fin>>address1;
    fin>>sex1;
    fin>>age1;
    fin>>salary1;
    fin>>diploma1;
    people.Set_value(name1,id1,number1,address1,sex1,salary1,age1,diploma1);
    point=!fin.eof();  
    if(point!=1)
    {
        break;
    }
    if(FoundId!=id1)
    {
        fout<<people;
    }
    else
    { 
    HasFound=1;
    LogWrite(people,"删除");  
    }
   
    }
    if(HasFound==0)
    {
        cout<<"没有这个职工,请输入正确的职工号"<<endl;
    }
    else
    {   
        point=1;
        fin.clear();
        fin.close();
        fout.close();
        fout.open("num.dat");
        fin.open("mid.dat");
        while(point)
        {
            fin>>id1;
            fin>>name1;
            fin>>number1;
            fin>>address1;
            fin>>sex1;
            fin>>age1;
            fin>>salary1;
            fin>>diploma1;
            people.Set_value(name1,id1,number1,address1,sex1,salary1,age1,diploma1);
            point=!fin.eof();  
            if(point)
            {
                fout<<people;
            }
        }
        fin.clear();
        fin.close();
        fout.close();
        if(remove("mid.dat"))
        {
            cout<<"删除中介文件错误"<<endl;
        }
        cout<<"删除完成"<<endl;
    }

    return 0;
}
void ReviseData()
{   
    string FoundId;
    string name1;
    string id1;
    string number1;
    string address1;
    char sex1;
    string age1;
    double salary1;
    string diploma1;
    Person people;
    int point=1;
    bool HasFound=0;
    ofstream fout("mid.dat",ios::app);
    ifstream fin("num.dat",ios::in);
    cout<<"输入你想查找的id"<<endl;
    cin>>FoundId;
    while (point)
    {

    fin>>id1;
    fin>>name1;
    fin>>number1;
    fin>>address1;
    fin>>sex1;
    fin>>age1;
    fin>>salary1;
    fin>>diploma1;
    people.Set_value(name1,id1,number1,address1,sex1,salary1,age1,diploma1);
    point=!fin.eof();  
    if(point!=1)
    {
        break;
    }
    if(FoundId!=id1)
    {
        fout<<people;
    }
    else
    { 
    HasFound=1;  
    cout<<"请输入id 名字 number 地址 性别(m/f) 年龄 薪水 学历(中间有空格)"<<endl;
    cin>>id1>>name1>>number1>>address1>>sex1>>age1>>salary1>>diploma1;
    people.Set_value(name1,id1,number1,address1,sex1,salary1,age1,diploma1);
    fout<<people;
    LogWrite(people,"修改");
    }
   
    }
    if(HasFound==0)
    {
        cout<<"没有这个职工,请输入正确的职工号"<<endl;
    }
    else
    {   
        point=1;
        fin.clear();
        fin.close();
        fout.close();
        fout.open("num.dat");
        fin.open("mid.dat");
        while(point)
        {
            fin>>id1;
            fin>>name1;
            fin>>number1;
            fin>>address1;
            fin>>sex1;
            fin>>age1;
            fin>>salary1;
            fin>>diploma1;
            people.Set_value(name1,id1,number1,address1,sex1,salary1,age1,diploma1);
            point=!fin.eof();  
            if(point)
            {
                fout<<people;
            }
        }
        fin.clear();
        fin.close();
        fout.close();
        if(remove("mid.dat"))
        {
            cout<<"删除中介文件错误"<<endl;
        }
        cout<<"修改完成"<<endl;
    }

    
    
}
void ThroughAll()
{   
    // string name1;
    // string id1;
    // string number1;
    // string address1;
    // char sex1;
    // string age1;
    // double salary1;
    // string diploma1;
    ifstream fin("num.dat",ios::in);
    Person people;
    int point=1;
    while(point)
    {
    // fin>>id1;
    // fin>>name1;
    // fin>>number1;
    // fin>>address1;
    // fin>>sex1;
    // fin>>age1;
    // fin>>salary1;
    // fin>>diploma1;
    fin>>people;
    point=!fin.eof();
    // people.Set_value(name1,id1,number1,address1,sex1,salary1,age1,diploma1);
    if(point!=1)
    {
        break;
    }
    cout<<people;    
    }

}
0

评论 (0)

取消