1. 程式人生 > >c++專案 ——公司管理系統

c++專案 ——公司管理系統

這是關於C++的一個專案,這個專案是關於公司管理系統,使用到的比較特色的功能有,密碼隱藏,連線mysql的庫建立,裡面的連結返回,公司的升職降職,管理員的功能等。

資源如下:http://download.csdn.net/detail/xx5595480/9160309

程式碼如下:

//#include"my_main.h"
#include"my_company.h"
#include<stdio.h>
#include<time.h>
#include<iomanip>
#include<iostream>
#include<string.h>
#include<mysql/mysql.h>
#include<stdlib.h>
#include <list>
#include <climits>
#include<unistd.h>
using namespace std;

MYSQL* conn;
list<Employee*> Link;        //建立一個用於儲存Employee物件指標的list容器;

void Load_Menu();
void Main_Menu();
int login_account(int num,string pwd);
void conn_mysql();
void load();

void boss_fun(list<Employee*>::iterator p);
void man_fun(list<Employee*>::iterator p);
void manager_fun(list<Employee*>::iterator p);	


void view_all(list<Employee*>::iterator p);
void view_all(list<Employee*>::iterator p);
void add_manager(list<Employee*>::iterator p);
void del(list<Employee*>::iterator p);
void modify_salary(list<Employee*>::iterator p,list<Employee*>::iterator q);
void modify_mark(list<Employee*>::iterator p);
void update(list<Employee*>::iterator p);
void add_man(list<Employee*>::iterator p);
void show_depart(list<Employee*>::iterator p);	
void save_all();
void change_pwd(list<Employee*>::iterator p);
void show_personal(list<Employee*>::iterator p);
bool sort_any (const Employee *first,const Employee * second);	
bool sort_lead (const Employee *first,const Employee * second);
bool sort_depart (const Employee *first,const Employee * second);
bool sort_num (const Employee *first, const Employee * second);	
bool sort_name (const Employee *first,const Employee * second);		

int check=0;


void Employee::save_str(char *savestr)										//save information to mysql
{
	list<Employee*>::iterator l=Link.begin();  //建立容器Link1的迭代器 l;
	while(l != Link.end())
	{
		sprintf(savestr,"insert into Employee (number,name,password,position,salary,logtime,flag,remark,leader) values(%d,'%s','%s','%s',%f,'%s',%d,'%s','%s')",
			(*l)->number,(*l)->name.c_str(),(*l)->password.c_str(),(*l)->position.c_str(),
			(*l)->salary,(*l)->logtime.c_str(),(*l)->flag,(*l)->mark.c_str(),(*l)->leader.c_str());
		if(mysql_query(conn,savestr))    //傳送SQL語句,成功返回0;
		{
			fprintf(stderr,"%s\n",mysql_error(conn));
			exit(1);
		}
		l++;
	}
}
////////////////////////////////////////////////////
bool sort_lead (const Employee *first,const Employee * second)			//sort from little to greater by lead
{
	return (first->leader) < (second->leader)?true:false;
}
////////////////////////
bool sort_depart (const Employee *first,const Employee * second)				//sort from little to greater by depart
{
	return (first->flag) <(second->flag)?true:false;
}
////////////////////////////
bool sort_num (const Employee *first, const Employee * second)			//sort from little to greater by number
{
	return (first->number) < (second->number)?true:false;
}
//////////////////////////
bool sort_name (const Employee *first,const Employee * second)			//sort from little to greater by name
{
	return (first->name) < (second->name)?true:false;
}
////////////////////////////////////////////////////////
bool sort_any (const Employee *first,const Employee * second)			//sort from little to greater by depart
{
	bool res;
	if((first->flag) < (second->flag))
	{
		if((first->leader) < (second->leader))
		{
			if((first->number) < (second->number))
			{
				res = true;
			}
			else
			{
				res = false;
			}
		}
	} 
	else
	{
		res = false;
	}
	return res = true?true:false;
}
///////////////////////////////////////////////
void show_personal(list<Employee*>::iterator p)						//show saleman's  information 
{
	system("clear");
	cout<<"\033[34;1m您的個人資訊為:\033[0m"<<endl<<endl;
	
	cout<<"----------------------------------------------------------------------------------------------"<<endl;
	cout.width(10);	cout<<"工號 |";
	cout.width(19);	cout<<"姓名 |";
	cout.width(12);	cout<<"職位 |";
	cout.width(9);	cout<<"薪水 |";
	cout.width(9);	cout<<"等級 |";
	cout.width(19);	cout<<"REMARK |";
	cout.width(19);	cout<<"上級 |";
	cout.width(40);	cout<<"上次登入時間";
	cout<<endl;
	cout<<"----------------------------------------------------------------------------------------------"<<endl;
	(*p)->print();
	cin.ignore(1000,'\n');
	cin.get();
	
}
/////////////////////////////////////////////
void change_pwd(list<Employee*>::iterator p)					//change salesman's password 
{
	string pwd;
	string c_pwd;
	while(1)
	{
		cout<<"\n\033[34;1m請輸入新密碼:\033[0m";
		system("stty -echo");
		cin>>pwd;
		system("stty echo");
		cout<<"\n\033[34;1m請在輸入一次:\033[0m";
		system("stty -echo");
		cin>>c_pwd;
		system("stty echo");
		if(pwd == c_pwd)
		{
			(*p)->set_passwd(pwd);
			cout<<"\n\033[34;1m密碼修改成功!\033[0m"<<endl;
			cout<<"Input any key";
			cin.ignore(1000,'\n');
			cin.get();
			break;
		}		
	}
	save_all();
}
//////////////////////////////////////////////
void save_all()													//save all data to mysql
{
	list<Employee*>::iterator p=Link.begin();
	if(mysql_query(conn,"drop table Employee"))
	{
		cout<<"mysql error"<<endl;
		exit(1);
	}
	if(mysql_query(conn,"create table Employee(no int auto_increment not null primary key,number int not null,name varchar(20) not null,password varchar(20) not null default '1234',position varchar(20) not null,salary float not null,logtime timestamp default current_timestamp,flag tinyint not null,remark varchar(128),leader varchar(20))default charset=utf8"))
	{
		cout<<"\033[34;1m建立資料庫失敗!\033[0m"<<endl;
		exit(1);
	}

	char str[1024]="";
	while(p!=Link.end())
	{
		(*p)->save_str(str);
		if(mysql_query(conn,str))
		{
			cout<<"\033[34;1m新增資料失敗!\033[0m"<<endl;
			exit(1);
		}
		p++;
	}
}
/////////////////////////////////////////////
void show_depart(list<Employee*>::iterator p)					//view depart staff information
{
	string name;
	name = (*p)->get_name();
	p=Link.begin();
	system("clear");
	cout<<"---------------------------------------------------------------------------------------------------------"<<endl;
	cout.width(10);	cout<<"工號 |";
	cout.width(19);	cout<<"姓名 |";
	cout.width(12);	cout<<"職位 |";
	cout.width(9); 	cout<<"薪水 |";
	cout.width(9);	cout<<"等級 |";
	cout.width(19);	cout<<"REMARK |";
	cout.width(19);	cout<<"上級 |";
	cout.width(40);	cout<<"上次登入時間 |";
	cout<<endl;
	cout<<"---------------------------------------------------------------------------------------------------------"<<endl;
	while(p!=Link.end())
	{
		if( (((*p)->get_lead()) == name)  )
		{
			(*p)->print();
		}
		p++;
	}
	cin.ignore(1000,'\n');
	cin.get();
}
//////////////////////////////////////////
void add_man(list<Employee*>::iterator p)						//add sales man
{
	
	Employee* ptr =NULL;
	string name;	cout<<"\033[34;1m請輸入姓名:\033[0m";	cin>>name;
	string pwd = "www";						
	string pos;
	float d_salary =3000;
	int flag;
	string mark;	cout<<"Input remark:";		cin>>mark;
	string lead	=	(*p)->get_name();
	time_t t;	t=time(NULL);
	string g_t;
	char tt[1024]="";
	struct tm *tmper;
	tmper = localtime(&t);
	sprintf(tt,"%d-%d-%d %d:%d:%d",tmper->tm_year+1900,tmper->tm_mon+1,tmper->tm_mday,tmper->tm_hour,tmper->tm_min,tmper->tm_sec);
	g_t = tt;
	int wt;
	float sale;
	float m_fixed;

	Link.sort(sort_num);
	list<Employee*>::iterator q =Link.begin();

	q=Link.begin();
	int number = ((*q)->get_num());	
	while(q!=Link.end())
	{
		if( number < ((*q)->get_num()) )
		{
			break;
		}
		q++;
		number++;
	}

	switch((*p)->get_flag())
	{
		case 2:
			flag = 1;
			pos="銷售職員";
			ptr=new S_man(number,name,pwd,pos,d_salary,g_t,flag,mark,lead);
			cout<<"請輸入銷售額:";	cin>>sale;
			ptr->set_sales(sale);
			ptr->set_salary();
			m_fixed = (*p)->get_salary();
			(*p)->set_sales(sale);
			(*p)->set_fixed_salary(m_fixed);
			(*p)->set_salary();
			break;
		case 4:
			flag = 3;
			pos="技術職員";
			ptr=new T_man(number,name,pwd,pos,d_salary,g_t,flag,mark,lead);
			cout<<"\033[34;1m請輸入工作時間:\033[0m";	cin>>wt;
			ptr->set_worktime(wt);
			ptr->set_salary();
			break;
		default:
			break;
	}	

	Link.push_front(ptr);
	save_all();
	cout<<"\033[34;1m新增成功!\033[0m"<<endl;
	cin.ignore(1000,'\n');
	cin.get();
}
/////////////////////////////////////////////
void update(list<Employee*>::iterator p)					//view depart staff information
{
	int number;
	string name = (*p)->get_name();
	list<Employee*>::iterator q=Link.begin();
	cout<<"\033[34;1m請輸入工號:\033[0m";
	cin>>number;
	while(q!=Link.end())
	{
		if( number == (*q)->get_num() && name == (*q)->get_lead() )
		{
			break;
		}
		q++;
	}
	if(q==Link.end())
	{
		cout<<"\033[34;1m沒有該職員!\033[0m"<<endl;
		cin.ignore(1000,'\n');
		cin.get();
		return;
	}
	system("clear");
	system("tput cup 15 38");	cout<<"\t\t****************************************************"<<endl;
	system("tput cup 16 38");	cout<<"\t\t*      CHOOSE THE ITEM YOU WANT TO MODIFY          *"<<endl;
	system("tput cup 17 38");	cout<<"\t\t*--------------------------------------------------*"<<endl;
	system("tput cup 18 38");	cout<<"\t\t*               1.MODIFY SALARY                    *"<<endl;
	system("tput cup 19 38");	cout<<"\t\t*               2.MODIFY REMARK                    *"<<endl;
	system("tput cup 21 38");	cout<<"\t\t*               3.RETURN                           *"<<endl;
	system("tput cup 20 38");	cout<<"\t\t*               SELECT:                            *"<<endl;
	system("tput cup 21 38");	cout<<"\t\t****************************************************"<<endl;
	int select;
	cin.clear();
	cin.sync();
	system("tput cup 20 75");	cin>>select;
	switch(select)
	{
		case 1:
			modify_salary(q,p);
			break;
		case 2:
			modify_mark(q);
			break;
		case 3:
			return;
		default:
			break;
	}
}
////////////////////////////////////////////
void modify_mark(list<Employee*>::iterator p)				//modify remark
{
	string mark;
	cout<<"Input remark:";
	cin>>mark;
	(*p)->set_mark(mark);
	cout<<"\033[34;1m修改成功!\033[0m"<<endl;
	cin.ignore(1000,'\n');
	cin.get();
	save_all();
}
//////////////////////////////////////////////////////////////
void modify_salary(list<Employee*>::iterator p,list<Employee*>::iterator q)						//modify salary	
{
	int time;
	float sales;
	float fixed;
	float m_fixed;
	float s_fixed;
	switch((*p)->get_flag())
	{
		case 1:
			cout<<"\033[34;1m請輸入銷售額:\033[0m";	cin>>sales;
			s_fixed = (*p)->get_salary();
			(*p)->set_sales(sales);
			(*p)->set_salary();
			m_fixed = (*q)->get_salary();
			m_fixed = m_fixed - s_fixed/5;
			(*q)->set_fixed_salary(m_fixed);
			(*q)->set_sales(sales);
			(*q)->set_salary();
			break;
		case 2:
			cout<<"\033[34;1m請輸入修改後的薪水:\033[0m";	cin>>fixed;
			(*p)->set_fixed_salary(fixed);
			(*p)->set_salary();
			break;
		case 3:
			cout<<"\033[34;1m請輸入工作時間:\033[0m";	cin>>time;
			(*p)->set_worktime(time);
			(*p)->set_salary();
			break;
		case 4:
			cout<<"\033[34;1m請輸入修改後的薪水:\033[0m";	cin>>fixed;
			(*p)->set_fixed_salary(fixed);
			(*p)->set_salary();
			break;
		default:
			break;
	}
	cout<<"\033[34;1m修改成功!\033[0m"<<endl;
	cin.ignore(1000,'\n');
	cin.get();
	save_all();
}
//////////////刪除/////////////////////////
void del(list<Employee*>::iterator p)							//delete an Employee
{
	list<Employee*>::iterator q=Link.begin();
	int number;
	cout<<"\033[34;1m請輸入要刪除的工號\033[0m";
	cin>>number;
	float m_fixed;
	while(q!=Link.end())
	{
		if((number == (*q)->get_num()) && ((*p)->get_name() == (*q)->get_lead()) )
		{
			m_fixed = (*p)->get_salary();
			m_fixed = m_fixed - (*q)->get_salary()/5;
			(*p)->set_sales(0);
			(*p)->set_fixed_salary(m_fixed);
			(*p)->set_salary();		
			Link.erase(q);
			cout<<"\033[34;1m刪除成功!\033[0m"<<endl;
			cin.ignore(1000,'\n');
			cin.get();
			break;
		}
		q++;
	}

	if(q == Link.end())
	{
		cout<<"\033[34;1m沒有該員工!\033[0m"<<endl;
		cin.ignore(1000,'\n');
		cin.get();
		return;
	}
	save_all();
}
////////////////新增經理////////////////////////////
void add_manager(list<Employee*>::iterator p)								//add manager
{
	
	Employee* ptr =NULL;
	string name;	cout<<"\033[34;1m請輸入姓名:\033[0m";	cin>>name;
	string pwd = "123";						
	string pos;
	int flag;

	string mark;	cout<<"Input remark:";		cin>>mark;
	time_t t;	t=time(NULL);
	string g_t;
	char tt[1024]="";
	struct tm *tmper;
	tmper = localtime(&t);
	sprintf(tt,"%d-%d-%d %d:%d:%d",tmper->tm_year+1900,tmper->tm_mon+1,tmper->tm_mday,tmper->tm_hour,tmper->tm_min,tmper->tm_sec);
	g_t = tt;

	string lead = (*p)->get_name();
	float fixed;
	cout<<"\033[34;1m請輸入修改後的薪水:\033[0m";	cin>>fixed;
	
	Link.sort(sort_num);//對容器內的物件按從小到大的順序進行排序;
	list<Employee*>::iterator q =Link.begin();

	q=Link.begin();
	int number = ((*q)->get_num());	
	while(q!=Link.end())
	{
		if( number < ((*q)->get_num()) )
		{
			break;
		}
		q++;
		number++;
	}
	while(1)
	{
		cout<<"\n\033[34;1m您想要增加那個資訊:  1.銷售經理   2.技術經理\033[0m\n";
		int select;
		cin>>select;
		if(select == 1)
		{
			flag =2;
			pos = "\033[34;1m銷售經理\033[0m";
			ptr=new S_manager(number,name,pwd,pos,fixed,g_t,flag,mark,lead);
			ptr->set_fixed_salary(fixed);
			ptr->set_sales(0);
			ptr->set_salary();
			break;
		}
		else if(select == 2)
		{
			flag = 4;
			pos = "\033[34;1m技術經理\033[0m";
			ptr=new T_manager(number,name,pwd,pos,fixed,g_t,flag,mark,lead);
			break;
		}
	}
	Link.push_front(ptr);
	cout<<"\033[34;1m新增成功!\033[0m"<<endl;
	cin.ignore(1000,'\n');
	cin.get();
	save_all();

}
///////////////顯示所有的資訊/////////////////////////
void view_all(list<Employee*>::iterator p)								//view all information
{	
	while(1)
	{
		system("clear");
		system("tput cup 15 38");	cout<<"\t\t\033[34;1m****************************************************"<<endl;
		system("tput cup 16 38");	cout<<"\t\t*               顯 示 模 式 ?                      *"<<endl;
		system("tput cup 17 38");	cout<<"\t\t****************************************************"<<endl;
		system("tput cup 18 38");	cout<<"\t\t*               1.工號                             *"<<endl;
		system("tput cup 19 38");	cout<<"\t\t*               2.姓名                             *"<<endl;
		system("tput cup 20 38");	cout<<"\t\t*               3.部門                             *"<<endl;
		system("tput cup 21 38");	cout<<"\t\t*               4.領導                             *"<<endl;
		system("tput cup 22 38");	cout<<"\t\t*               5.所有                             *"<<endl;
		system("tput cup 23 38");	cout<<"\t\t*               選 擇 :                           *"<<endl;
		system("tput cup 24 38");	cout<<"\t\t****************************************************\033[0m"<<endl;
		system("tput cup 23 73");string select;
		cin>>select;
		if(select == "1")
		{
			Link.sort(sort_num);
			break;
		}
		else if(select == "2")
		{
			Link.sort(sort_name);
			break;
		}
		else if(select == "3")
		{
			Link.sort(sort_depart);
			break;
		}
		else if(select == "4")
		{
			Link.sort(sort_lead);
			break;
		}
		else if(select == "5")
		{
			Link.sort(sort_any);
			break;
		}
	}
	system("clear");
	p=Link.begin();
}
////////////////經理介面////////////////////////////
void manager_fun(list<Employee*>::iterator p)					
{
	while(1)
	{

		system("clear");
		cout<<"\t\t\n\n\n";
		system("tput cup 15 38");	cout<<"\t\t\033[34;1m****************************************************"<<endl;
		system("tput cup 16 38");	cout<<"\t\t*             歡 迎 來 到 經 理 界 面               *"<<endl;
		system("tput cup 17 38");	cout<<"\t\t****************************************************"<<endl;
		system("tput cup 18 38");	cout<<"\t\t*            請 選 擇 :                           *"<<endl;
		system("tput cup 19 38");	cout<<"\t\t****************************************************"<<endl;
		system("tput cup 20 38");	cout<<"\t\t*            1.檢視個人資訊                         *"<<endl;
		system("tput cup 21 38");	cout<<"\t\t*            2.檢視部門員工資訊                     *"<<endl;
		system("tput cup 22 38");	cout<<"\t\t*            3.增加員工                            *"<<endl;
		system("tput cup 23 38");	cout<<"\t\t*            4.修改員工資訊                         *"<<endl;
		system("tput cup 24 38");	cout<<"\t\t*            5.刪除員工資訊                         *"<<endl;
		system("tput cup 25 38");	cout<<"\t\t*            6.修改密碼                             *"<<endl;
		system("tput cup 26 38");	cout<<"\t\t*            7.返回                                 *"<<endl;
		system("tput cup 27 38");	cout<<"\t\t*            8.退出                                *"<<endl;
		system("tput cup 28 38");	cout<<"\t\t*            選 擇 :                               *"<<endl;
		system("tput cup 29 38");	cout<<"\t\t****************************************************\033[0m"<<endl;
		int select;
		cin.clear();
		cin.sync();
		system("tput cup 28 69");	cin>>select;
		switch(select)
		{
			case 1:
				show_personal(p);			//show information of sale manager
				break;
			case 2:
				show_depart(p);				//show depart information
				break;
			case 3:
				add_man(p);
				break;
			case 4:
				update(p);
				break;
			case 5:
				del(p);
				break;
			case 6:
				change_pwd(p);//change sales manager's password
				return;
				break;
			case 7:
				return;
			case 8:					//save all data
				system("clear");
				exit(0);
			default:
				break;
		}
	}
}
//////////////員工介面////////////////////////
void man_fun(list<Employee*>::iterator p)						
{
	while(1)
	{

		system("clear");
		cout<<"\t\t\n\n\n";
		system("tput cup 15 38");	cout<<"\t\t\033[34;1m****************************************************"<<endl;
		system("tput cup 16 38");	cout<<"\t\t*              歡 迎 來 到 員 工 界 面              *"<<endl;
		system("tput cup 17 38");	cout<<"\t\t****************************************************"<<endl;
		system("tput cup 18 38");	cout<<"\t\t*            請 選 擇 :                           *"<<endl;
		system("tput cup 19 38");	cout<<"\t\t****************************************************"<<endl;
		system("tput cup 20 38");	cout<<"\t\t*            1.檢視個人資訊                         *"<<endl;
		system("tput cup 21 38");	cout<<"\t\t*            2.修改密碼                             *"<<endl;
		system("tput cup 22 38");	cout<<"\t\t*            3.返回                                *"<<endl;
		system("tput cup 23 38");	cout<<"\t\t*            4.退出                                *"<<endl;
		system("tput cup 24 38");	cout<<"\t\t*            選 擇 :                              *"<<endl;
		system("tput cup 25 38");	cout<<"\t\t****************************************************\033[0m"<<endl;
		int select;
		cin.clear();
		cin.sync();
		system("tput cup 24 69");	cin>>select;
		switch(select)
		{
			case 1:
				show_personal(p);						//see information
				break;
			case 2:
				change_pwd(p);					//change password
				break;
			case 3:
				return;							//return to login
				break;
			case 4:								//exit program						
				system("clear");
				exit(1);
				break;
			default:
				break;
		}
	}
}
///////////////老闆管理介面/////////////////////////////////
void boss_fun(list<Employee*>::iterator p)	
{
	while(1)
	{
		system("clear");
		system("tput cup 15 38");	cout<<"\t\t\033[34;1m****************************************************"<<endl;
		system("tput cup 16 38");	cout<<"\t\t*               請 選 擇 您 要 操 作 的 選 項       *"<<endl;
		system("tput cup 17 38");	cout<<"\t\t****************************************************"<<endl;
		system("tput cup 18 38");	cout<<"\t\t*               1.增加經理                          *"<<endl;
		system("tput cup 19 38");	cout<<"\t\t*               2.檢視所有的員工資訊                *"<<endl;
		system("tput cup 20 38");	cout<<"\t\t*               3、刪除一個員工                     *"<<endl;
		system("tput cup 21 38");	cout<<"\t\t*               4、修改密碼                         *"<<endl;
		system("tput cup 22 38");	cout<<"\t\t*               5、返回:                            *"<<endl;
		system("tput cup 23 38");	cout<<"\t\t*               6、退出                             *"<<endl;
		system("tput cup 24 38");	cout<<"\t\t*               選 擇 :                            *"<<endl;
		system("tput cup 25 38");	cout<<"\t\t****************************************************\033[0m"<<endl;
		int select;
		cin.clear();
		cin.sync();
		system("tput cup 24 75");	cin>>select;
		switch(select)
		{
			case 1:
				add_manager(p);
				break;
			case 2:
				view_all(p);
				break;
			case 3:
				del(p);
				break;
			case 4:
				change_pwd(p);
				break;
			case 5:
				return;
				break;
			case 6:
				system("clear");
				exit(0);
				break;
			default:
				break;
		}
	}
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
void Load_Menu()
{
	list<Employee*>::iterator p=Link.begin();
	load();
	for(int i=0;i<4;i++)
	{
		system("clear");
		putchar(10);
		putchar(10);
		putchar(10);
		putchar(10);
		putchar(10);
		putchar(10);
		putchar(10);
		putchar(10);
		putchar(10);
		putchar(10);
		putchar(10);
		putchar(10);
		putchar(10);
		switch(i)
		{
			case 0:
			cout<<"\t\t\t\t\t\033[34;1m玩命載入中\033[0m\t\t"<<endl;
			break;
			case 1:
			cout<<"\t\t\t\t\t\033[34;1m玩命載入中..........\033[0m\t\t"<<endl;
			break;
			case 2:
			cout<<"\t\t\t\t\t\033[34;1m玩命載入中....................\033[0m\t\t"<<endl;
			break;
			case 3:
			cout<<"\t\t\t\t\t\033[34;1m玩命載入中..............................\033[0m\t\t"<<endl;
			break;
		}
		putchar(10);
		putchar(10);
		putchar(10);
		putchar(10);
		cout<<"\t\t\t\t\t\033[34;1m小提示:\033[0m"<<endl;
		cout<<"\t\t\t\t\t\t\033[34;1m  您上次登入系統的時間為:"<<endl;
		//cout<<(*p)->get_logt()<<endl;
		sleep(1);
	}
		putchar(10);
		putchar(10);
		putchar(10);
		putchar(10);
	//cout<<"載入成功!"<<endl;
	cout<<"\t\t\t\t\t\t\033[34;1m啟動成功!\033[0m"<<endl;
	//cout<<"載入成功!"<<endl;
	for(int i=0;i<2;i++){sleep(1);}
	system("clear");
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
void Main_Menu()
{
	while(1)
	{	
		Load_Menu();
		system("clear");
		system("tput cup 15 38");	cout<<"\t\t\033[34;1m*****************************************************"<<endl;
		system("tput cup 16 38");	cout<<"\t\t*         歡 迎 使 用 公 司 管 理 系 統 v1.0        *"<<endl;
		system("tput cup 17 38");	cout<<"\t\t*****************************************************"<<endl;
		system("tput cup 18 38");	cout<<"\t\t*                   請 登 錄 :                     *"<<endl;
		system("tput cup 19 38");	cout<<"\t\t*---------------------------------------------------*"<<endl;
		system("tput cup 20 38");	cout<<"\t\t*            帳號:                                 *"<<endl;
		system("tput cup 21 38");	cout<<"\t\t*            密碼:                                 *"<<endl;
		system("tput cup 22 38");	cout<<"\t\t*****************************************************\033[0m"<<endl;
	int l_num;
	string l_pwd;
	cin.clear();
	cin.sync();
	system("tput cup 20 67");	
	cin>>l_num;
	cin.clear();
	cin.sync();
	system("stty -echo");
	system("tput cup 21 67");	
	cin>>l_pwd;
	system("stty echo");
	login_account(l_num,l_pwd);
	}
}
///////////////登入賬戶///////////////////
int login_account(int num,string pwd)
{
	list<Employee*>::iterator p=Link.begin();
	cout<<"賬號為:"<<(*p)->get_num()<<endl;
	cout<<"密碼為:"<<(*p)->get_pwd()<<endl;
	while(p!=Link.end())
	{
		if(((*p)->get_num())==num)
		{
			if(((*p)->get_pwd())==pwd)
			{
				check=0;
				break;
			}
			else{
				cout<<"\033[34;1m您輸入密碼錯誤!請重新輸入!\033[0m"<<endl;
				cin.ignore(1000,'\n');
				cin.get();
				check++;
				if(check>=3)
				{
					cout<<"\033[34;1m錯誤次數太多!\033[0m"<<endl;
					cin.get();
					exit(0);
				}
				return 0;
			}	
		}
		p++;
	}
	if(p==Link.end())
	{
		cout<<"\033[34;1m沒有該帳號!\033[0m"<<endl;
		cin.ignore(1000,'\n');
		cin.get();
		return 0;
	}
	switch((*p)->get_flag())
	{
		case 0:
			boss_fun(p);
			break;
		case 1:
			man_fun(p);
			break;
		case 2:
			manager_fun(p);
			break;
		case 3:
			man_fun(p);
			break;
		case 4:
			manager_fun(p);
			break;
		default:
			break;
	}
	return 0;
}
/////////////////////////////////
/////////////*連結資料庫*/////////////////
void connect_mysql()
{
	conn=mysql_init(NULL);
	const char *server="localhost";
	const char *user="root";
	const char *paswd="512330";
	const char *database="company";
	if(!mysql_real_connect(conn,server,user,paswd,database,0,NULL,0))
	{
		cout<<"\033[34;1m載入資料庫失敗!\033[0m"<<endl;
		exit(1);
	}
	mysql_set_character_set(conn,"utf8");
}
/////////////*載入資料庫資訊*/////////////
void load()
{
	MYSQL_RES* res;
	MYSQL_ROW row;
	Employee* p=NULL;
    int number;        //編號
	string name;       //姓名
	string pwd;   //密碼
	string position;    //職位
	float salary;      //薪水
	string logtime;    //登入時間
	int flag;          //旗子
	string mark;       
	string leader;     //直接領導
	float sales;
	float m_sales;
	float fixed;
	int worktime;
	connect_mysql();
	if(mysql_query(conn,"select*from Employee"))//開啟"Employee"表;
	{
		cout<<mysql_error(conn)<<endl;
		exit(1);
	}
	res=mysql_use_result(conn);
	while((row=mysql_fetch_row(res))!=NULL)//將"Employee"表中的資料分別存入各個相應的變數中;
	{
		flag=atoi(row[7]);
		//cout<<"\033[34;1m載入成功!\033[0m"<<endl;

		switch(flag)//分別將已取出來的"Employee"表中的資料放入各個相應的類中;
		{
			case 0:
				number=atoi(row[1]);
				name=row[2];
				pwd=row[3];
				position=row[4];
				salary=atof(row[5]);
				logtime=row[6];
				flag=atoi(row[7]);
				mark=row[8];
				leader=row[9];
				p=new Boss(number,name,pwd,position,salary,logtime,flag,mark,leader);
				Link.push_front(p);
				delete p;
				p=NULL;
				cout<<"\033[34;1m載入成功!\033[0m"<<endl;
				break;
			case 1:
				number=atoi(row[1]);
				name=row[2];
				pwd=row[3];
				position=row[4];
				salary=atof(row[5]);
				logtime=row[6];
				flag=atoi(row[7]);
				mark=row[8];
				leader=row[9];
				p=new S_man(number,name,pwd,position,salary,logtime,flag,mark,leader);
				Link.push_front(p);
				delete p;
				p=NULL;
				break;
			case 2:
				while((row=mysql_fetch_row(res))!=NULL)//將"Employee"表中的資料分別存入各個相應的變數中;
				{
					number=atoi(row[1]);
					name=row[2];
					pwd=row[3];
					position=row[4];
					salary=atof(row[5]);
					logtime=row[6];
					flag=atoi(row[7]);
					mark=row[8];
					leader=row[9];
				}
				p=new S_manager(number,name,pwd,position,salary,logtime,flag,mark,leader);
				Link.push_front(p);
				delete p;
				p=NULL;
				break;
			case 3:
				while((row=mysql_fetch_row(res))!=NULL)//將"Employee"表中的資料分別存入各個相應的變數中;
				{
					number=atoi(row[1]);
					name=row[2];
					pwd=row[3];
					position=row[4];
					salary=atof(row[5]);
					logtime=row[6];
					flag=atoi(row[7]);
					mark=row[8];
					leader=row[9];
				}
				p=new T_man(number,name,pwd,position,salary,logtime,flag,mark,leader);
				Link.push_front(p);
				delete p;
				p=NULL;
				break;
			case 4:
				while((row=mysql_fetch_row(res))!=NULL)//將"Employee"表中的資料分別存入各個相應的變數中;
				{
					number=atoi(row[1]);
					name=row[2];
					pwd=row[3];
					position=row[4];
					salary=atof(row[5]);
					logtime=row[6];
					flag=atoi(row[7]);
					mark=row[8];
					leader=row[9];
				}
				p=new T_manager(number,name,pwd,position,salary,logtime,flag,mark,leader);
				Link.push_front(p);
				delete p;
				p=NULL;
				break;
			default:
				break;
		}
	}
}
int main()
{
	Main_Menu();	
	return 0;
}