📄 department.cpp
字号:
#include "stdafx.h"
#include "SalaryManagement.h"
#include "Department.h"
#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif
/*
*注释
*此类的对象要使用的时候先InitDepartment()
*/
//////////////////////////////////////////////////////////////////////
void CDepartment::InitDepartment(){ //初始化部门类的对象
CString SQL; //保存用来查询的SQL语句
SQL="select * from Department where 部门='"+this->GetDepartmentName()+"'"; //要查询的SQL语句
database.GetRecordset(SQL); //得到查询的记录集
if(database.m_pRecordset->adoEOF==0){ //用数据库里的数据初始化 部门类的对象
try{
m_manager.SetEmployeeName((LPCTSTR)(_bstr_t)(database.m_pRecordset->GetCollect("经理"))); //得到部门的经理
m_employeenumber=database.m_pRecordset->GetCollect("职工数").intVal; //得到职员数
}
catch(_com_error e){ //如果数据库中没有经理就会出错
m_manager.SetEmployeeName(""); //没有经理
}
}
SQL="select * from zNext"; //得到年份
database.GetRecordset(SQL);
if(database.m_pRecordset->adoEOF==0){ //从zNext表中获得信息
m_year=(LPCTSTR)(_bstr_t)database.m_pRecordset->GetCollect("年");
m_month=(LPCTSTR)(_bstr_t)database.m_pRecordset->GetCollect("月");
m_s_rate=database.m_pRecordset->GetCollect("职员提成率").intVal;
m_m_rate=database.m_pRecordset->GetCollect("经理提成率").intVal;
m_t_rate=database.m_pRecordset->GetCollect("奖金率").intVal;
}
}
//得到部门的信息
CEmployee CDepartment::GetManager(){ //得到部门经理
return m_manager;
}
CString CDepartment::GetDepartmentName(){ //得到部门的名字
return m_departname;
}
int CDepartment::GetEmployeeNumber(){ //得到部门的职员数
return m_employeenumber;
}
//
void CDepartment::UpdateEmployeeNumber(int number){ //更新部门的职员数
m_employeenumber=number; //先更新当前部门对象中的数据
CString SQL; //建立进行查询的SQL语句
char temp[10]; //用来保存职工数的字符串格式的
sprintf(temp,"%d",number);
SQL="update Department set 职工数=";
SQL+=temp;
SQL+=" where 部门='"+m_departname+"'";
database.ExecuteSQL(SQL);
}
void CDepartment::GetDepartmentEmployee(){ //得到部门中所有职员的信息
InitDepartment(); //得到最新的部门信息
CString SQL; //建立进行查询的SQL语句
int temp; //用来数字向字符串转换
char convert[10]; //用来数字向字符串进行转换
if(m_departname=="A部门")
SQL="select * from ADepartEmployee"; //得到A部门的职员信息
else if(m_departname=="B部门")
SQL="select * from BDepartEmployee"; //得到B部门的职员信息
else if(m_departname=="C部门")
SQL="select * from CDepartEmployee"; //得到C部门的职员信息
database.GetRecordset(SQL); //执行SQL语句
DeleteDepartmentEmployee(); //先delete掉以前的职员类对象的数组
m_employee=new CEmployee[m_employeenumber]; //建立了一个职员的数组
int i=0;
while(i<m_employeenumber&&database.m_pRecordset->adoEOF==0){ //从数据库得到这些职员的信息
(m_employee+i)->SetEmployeeID((LPCTSTR)(_bstr_t)(database.m_pRecordset->GetCollect("职员号"))); //得到职员号
(m_employee+i)->SetEmployeeName((LPCTSTR)(_bstr_t)(database.m_pRecordset->GetCollect("姓名"))); //得到姓名
(m_employee+i)->SetEmployeePosition((LPCTSTR)(_bstr_t)(database.m_pRecordset->GetCollect("职位"))); //得到职位
(m_employee+i)->SetEmployeeDepartment((LPCTSTR)(_bstr_t)(database.m_pRecordset->GetCollect("所在部门"))); //得到所在部门
temp=database.m_pRecordset->GetCollect("基本工资").intVal; //基本工资
sprintf(convert,"%d",temp); //把数字转化为字符串
(m_employee+i)->SetEmployeeBasis((CString)convert);
(m_employee+i)->AddEmployeeSalary(temp); //累加总工资
temp=database.m_pRecordset->GetCollect("扣除").intVal; //扣除
sprintf(convert,"%d",temp); //把数字转化为字符串
(m_employee+i)->SetEmployeeDeduct((CString)convert);
(m_employee+i)->AddEmployeeSalary((-1)*temp); //累加总工资
i++;
database.m_pRecordset->MoveNext();
}
}
void CDepartment::GetEmployeeSellamount(){ //得到职员的销售额
InitDepartment(); //得到最新的部门信息
CString SQL; //用来查询的SQL语句
SQL="select * from "+DEPART+"Year"+m_year;
database.GetRecordset(SQL);
m_departsellamount=0; //先把部门的销售额初始化为0
int i=0;
int temp; //暂时来存放销售额
int total; //total里是一个职员的全部销售额
int bonus; //保存奖金
char cbonus[10];
while(i<m_employeenumber&&database.m_pRecordset->adoEOF==0){ //从数据库得到这些销售额的信息
temp=database.m_pRecordset->GetCollect((_bstr_t)m_month).intVal; //数据库中得到
(m_employee+i)->SetEmployeeSellamount(temp); //个人的销售额
//根据个人的销售额来得到月奖金
bonus=temp*m_s_rate/100;
sprintf(cbonus,"%d",bonus);
(m_employee+i)->SetEmployeeBonus(cbonus);
(m_employee+i)->AddEmployeeSalary(bonus); //累加总工资
m_departsellamount+=temp; //累加本月的部门销售额
total=0;
total=database.m_pRecordset->GetCollect("一月").intVal;
total+=database.m_pRecordset->GetCollect("二月").intVal;
total+=database.m_pRecordset->GetCollect("三月").intVal;
total+=database.m_pRecordset->GetCollect("四月").intVal;
total+=database.m_pRecordset->GetCollect("五月").intVal;
total+=database.m_pRecordset->GetCollect("六月").intVal;
total+=database.m_pRecordset->GetCollect("七月").intVal;
total+=database.m_pRecordset->GetCollect("八月").intVal;
total+=database.m_pRecordset->GetCollect("九月").intVal;
total+=database.m_pRecordset->GetCollect("十月").intVal;
total+=database.m_pRecordset->GetCollect("十一月").intVal;
total+=database.m_pRecordset->GetCollect("十二月").intVal;
(m_employee+i)->SetEmployeeAward(total*m_t_rate/100);
i++;
database.m_pRecordset->MoveNext();
}
}
void CDepartment::DeleteDepartmentEmployee(){ //废除现在得到的职员信息
if(m_employeenumber) //如果有职员的话
delete[] m_employee; //释放堆中的空间
}
void CDepartment::Create_Table(CString year){ //创建年销售量的表
CString SQL; //建立要执行的SQL语句
SQL="create table "+DEPART+"Year"+year+" (职员号 text,姓名 text,一月 int,二月 int,三月 int,四月 int,五月 int,六月 int,七月 int,八月 int,九月 int,十月 int,十一月 int,十二月 int,全年 int)";
database.ExecuteSQL(SQL); //创建了年销售量的表
int i=0;
while(i<m_employeenumber){ //对表中的数据进行初始化
SQL="insert into "+DEPART+"Year"+year+" (职员号,姓名,一月,二月,三月,四月,五月,六月,七月,八月,九月,十月,十一月,十二月,全年) ";
SQL+="values ('"+(m_employee+i)->GetEmployeeID()+"','"+(m_employee+i)->GetEmployeeName()+"',0,0,0,0,0,0,0,0,0,0,0,0,0)";
i++;
database.ExecuteSQL(SQL);
}
}
//时间
CString CDepartment::GetYear(){ //得到要加入的年
return m_year;
}
CString CDepartment::GetMonth(){ //得到要加入的月
return m_month;
}
void CDepartment::SetDate(CString year,CString month){ //设置时间
m_year=year;
m_month=month;
}
CDepartment::CDepartment(CString DepartName){ //重载构造函数
m_departname=DepartName; //给部门的名称赋值
//用来判断是哪个部门
if(m_departname=="A部门")
DEPART="A";
else if(m_departname=="B部门")
DEPART="B";
else if(m_departname=="C部门")
DEPART="C";
}
CDepartment::~CDepartment(){
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -