#include <iostream>
#include<string>
#include<stdlib.h>
#include<graphics.h>
#include<fstream>
#include <Windows.h>
const int Width = 800, Lengh = 1200;
using namespace std;
int N = 0;
const int Num = 100;
int Num_t = 0, Num_s = 0, Num_m = 0, Num_sm = 0;
class Employee
{
public:
Employee()
{
num = totalnum++;
salary = 0;
name = "";
post = "";
}
string getname()
{
return this->name;
}
int getno()
{
return this->num;
}
string getpost()
{
return this->post;
}
double getsalary()
{
return this->salary;
}
virtual void pay() = 0; //计算月薪 纯虚函数 基类变为抽象类
~Employee() {};
protected:
string name; //姓名
int num; //编号
string post; //部门
double salary; //月薪
static int totalnum; //静态数据成员
};
class Technician :public Employee //兼职技术人员
{
private:
double hourlyrate; //每小时酬金
double workhours; //当月工作小时数
public:
Technician() {};
Technician(string n, double h)
{
name = n;
hourlyrate = 100; //每小时酬金固定为100
workhours = h;
post = "兼职技术人员";
}
void pay()
{
salary = hourlyrate * workhours; //计算月薪,按小时计算
}
};
class Saleman :virtual public Employee //销售员
{
protected:
double commrate; //按销售额提取酬金的百分比
double sales; //当月销售额
public:
Saleman() {};
Saleman(string n, double s)
{
commrate = 0.04; //销售提成比例为4%
name = n;
sales = s;
post = "销售员";
}
void pay() //计算销售员的月薪函数
{
salary = sales * commrate; //计算月薪=本月销售额*销售提成比例
}
};
class Manager :virtual public Employee //经理
{
protected:
double monthlypay; //固定月薪
public:
Manager() {};
Manager(string n)
{
name = n;
post = "经理";
monthlypay = 8000;
}
void pay()
{
salary = monthlypay;
}
};
class Salemanager :public Manager, public Saleman //销售经理
{
public:
Salemanager() {};
Salemanager(string n, double s):Manager(n),Saleman(n,s)
{
monthlypay = 5000; //固定工资5000
commrate = 0.005; //销售提成比例0.5%
post = "销售经理";
}
void pay()
{
salary = monthlypay + commrate * sales; //月薪=固定月薪+销售提成
}
};
Technician t[Num];
Saleman s[Num];
Manager m[Num];
Salemanager sm[Num];
struct FileImag
{
char FileNum[20];
char FileName[20];
char FileSalary[20];
char FilePost[20];
}Image[100],ima;
void InitFile();
int Initnum();
void SetMenu();
void Show();
void ShowDraw();
void Add();
void AddManager();
void AddTechnician();
void AddSaleman();
void AddSalemanager();
void SaveManager();
void SaveSalemanager();
void SaveSaleman();
void SaveTechnician();
void Delete();
void Deletefile(string);
void Modify();
void ModifyFile(string);
void SaveAfterModify();
void Find();
int Employee::totalnum = Initnum()+1; //找到文件中已有的数据的最大值,保证每次添加编号有序
int main()
{
InitFile();
SetMenu();
return 0;
}
void InitFile()
{
N = 0;
FILE* fp = fopen("date.dat", "r"); //打开用户文件,只读
if (fp != NULL)
{
while (!feof(fp))
{
fscanf(fp, "%s %s %s %s\n", &Image[N].FileNum, &Image[N].FileName, &Image[N].FilePost, &Image[N].FileSalary);
N++;
}
if (fclose(fp))
{
printf("关闭文件失败!");
}
fp = NULL;
}
}
int Initnum()
{
InitFile();
if (N == 0)
{
return 9999;
}
else
{
int max = atoi(Image[0].FileNum);
for (int i = 0; i < N; i++)
{
if (atoi(Image[i].FileNum) > max)
max = atoi(Image[i].FileNum);
}
return max;
}
}
void SetMenu()
{
InitFile();
//创建窗口 确定窗口大小
initgraph(Lengh, Width);
setfillcolor(WHITE);
//设置背景
IMAGE img;
loadimage(&img, "./picture.jpg", Lengh, Width);
putimage(0, 0, &img);
//大标题
char MainTitle[] = { "小型公司的工资管理系统" };
//设置字体为抗锯齿效果
LOGFONT f;//字体变量
gettextstyle(&f);
f.lfHeight = 48;
strcpy(f.lfFaceName, "楷体");
f.lfQuality = ANTIALIASED_QUALITY;//打磨字体 使字体变得更加光滑
settextstyle(&f);
outtextxy(230, 100, MainTitle);
char text0[] = "显示职工工资信息";
char text1[] = "添加职工工资信息";
char text2[] = "删除职工工资信息";
char text3[] = "修改职工工资信息";
char text4[] = "查找职工工资信息";
char text5[] = "退出程序";
//设置7个矩形框
fillrectangle(330, 205, 660, 250);
fillrectangle(330, 265, 660, 310);
fillrectangle(330, 325, 660, 370);
fillrectangle(330, 385, 660, 430);
fillrectangle(330, 445, 660, 490);
fillrectangle(330, 505, 660, 550);
//设置字体
setbkmode(TRANSPARENT);
settextcolor(RGB(66, 75, 150));
settextstyle(40, 0, "楷体");
//书写内容
outtextxy(340, 210, text0);
outtextxy(340, 270, text1);
outtextxy(340, 330, text2);
outtextxy(340, 390, text3);
outtextxy(340, 450, text4);
outtextxy(340, 510, text5);
//鼠标操作,根据鼠标点击的不同位置跳转到不同函数
MOUSEMSG m1;
while (1)
{
m1 = GetMouseMsg();//获取鼠标操作
if (m1.x >= 330 && m1.x <= 660 && m1.y >= 205 && m1.y <= 250)
{
if (m1.uMsg == WM_LBUTTONDOWN) //右键单击一次触发
{
//显示职工工资信息
Show();
}
}
else if (m1.x >= 330 && m1.x <= 660 && m1.y >= 265 && m1.y <= 310)
{
if (m1.uMsg == WM_LBUTTONDOWN) //右键单击一次触发
{
//添加职工工资信息
Add();
}
}
else if (m1.x >= 330 && m1.x <= 660 && m1.y >= 325 && m1.y <= 370)
{
if (m1.uMsg == WM_LBUTTONDOWN)
{
//删除职工工资信息
Delete();
}
}
else if (m1.x >= 330 && m1.x <= 660 && m1.y >= 385 && m1.y <= 430)
{
if (m1.uMsg == WM_LBUTTONDOWN)
{
//修改职工工资信息
Modify();
}
}
else if (m1.x >= 330 && m1.x <= 660 && m1.y >= 445 && m1.y <= 490)
{
if (m1.uMsg == WM_LBUTTONDOWN)
{
//查询职工工资信息
Find();
}
}
else if (m1.x >= 330 && m1.x <= 660 && m1.y >= 505 && m1.y <= 550)
{
if (m1.uMsg == WM_LBUTTONDOWN)
{
//退出程序
exit(0);
}
}
}
getchar();
//关闭窗口
closegraph();
}
void ShowDraw()
{
//获取窗口句柄
HWND hnd = GetHWnd();
//设置窗口标题
SetWindowText(hnd, "显示职工工资信息");
//图片绘制
IMAGE img;
loadimage(&img, "./picture3.jpg", Lengh, Width);
putimage(0, 0, &img);
//大标题
char MainTitle[] = { "职工薪资情况" };
//设置字体为抗锯齿效果
LOGFONT f;//字体变量
gettextstyle(&f);
f.lfHeight = 48;
strcpy(f.lfFaceName, "楷体");
f.lfQuality = ANTIALIASED_QUALITY;//打磨字体 使字体变得更加光滑
settextstyle(&f);
outtextxy(600, 50, MainTitle);
char text1[] = "职工编号";
char text2[] = "职工姓名";
char text3[] = "职工职位";
char text4[] = "职工薪资";
char text5[] = "上一页";
char text6[] = "返回";
char text7[] = "下一页";
setlinecolor(BLACK);
//绘制表格
fillrectangle(330, 100, 1150, 700);
fillrectangle(400, 720, 550, 760);
fillrectangle(650, 720, 800, 760);
fillrectangle(900, 720, 1050, 760);
line(330, 150, 1150, 150);
line(330, 200, 1150, 200);
line(330, 250, 1150, 250);
line(330, 300, 1150, 300);
line(330, 350, 1150, 350);
line(330, 400, 1150, 400);
line(330, 450, 1150, 450);
line(330, 500, 1150, 500);
line(330, 550, 1150, 550);
line(330, 600, 1150, 600);
line(330, 650, 1150, 650);
line(330, 700, 1150, 700);
line(530, 100, 530, 700);
line(730, 100, 730, 700);
line(930, 100, 930, 700);
//设置字体
setbkmode(TRANSPARENT);
settextcolor(RGB(66, 75, 150));
settextstyle(24, 0, "楷体");
outtextxy(340, 120, text1);
outtextxy(540, 120, text2);
outtextxy(740, 120, text3);
outtextxy(940, 120, text4);
outtextxy(435, 730, text5);
outtextxy(700, 730, text6);
outtextxy(935, 730, text7);
}
void Show()
{
ShowDraw();
int i = 1,k=155,j,page=1;
bool fill = false;
while (i <= N && i<=11)
{
setb