1. 程式人生 > >員工管理系統 ---------C 語言

員工管理系統 ---------C 語言

本系統有小部分程式碼借鑑了以下這位朋友的程式碼,並加以改進,大部分程式碼,都是自己編寫的.

注意:因為我模組分的比較多,程式碼不太好貼上,我只把部分程式碼貼上進來,供給各位參考.

簡介

這個是我自己用C語言編寫的員工資訊管理系統,算是我這一點時間來對所學習C語言的一個總結的作品.程式碼量還是蠻大的.功能比較豐富,包含了三個端,員工端,部門經理端,超級管理員端. 員工端可以申請請假/加薪/轉正(如果是試用期)/檢視自己本月應得工資等操作.部門管理員可以對員工的申請進行稽核等操作.管理員可以設定公司組織機構等操作.

本系統對於正在學習以及剛學習完C語言,希望鞏固一下語法知識的朋友,具有比較高的借鑑意義.比如陣列/函式指標的使用/對檔案的寫入和讀取/結構體的設計/列舉等語法的善用/游標的控制/介面的美化(本系統並沒有做具體的美化,但是提供了幾個美化的函式,比如設定顏色的函式Color(),以及控制游標的函式controlcursor()等函式,你可以自己去美化);

注意,本系統是使用VS2015編寫的.所以如果用VC來執行的話,需要自己修改部分語法.

管理員密碼在admin.txt檔案中 員工和部門經理密碼在初始都是123456

圖片: 整個系統的框架圖,其中有小部分功能沒有做,有心的人可以自己加

// main()主檔案以及algorithm.h演算法模組程式碼


#include "Login.h"
#include "file.h"
#include "Menu.h"
int main()
{
	//載入資料
	Load();
	//登入模組
	int nRet = Login();
	switch (nRet)
	{
	case 0:
		EXIT();
	case 1:
		g_nLevel = e_admin; //登入成功,則許可權為管理員;
while (MainMenu_1())//管理員主介面 ; break; case 2: //部門經理主介面 g_nLevel = e_manager; while (MainMenu_3())//部門經理主介面 ; break; case 3: g_nLevel = e_worker; while (MainMenu_2())//員工主介面 ; } return 0; } // algorithm.h演算法模組 #include "algorithm.h" //列印部門職位 static void PrintPost(char *pName); static
bool SortbyNum(S_WORKER*, S_WORKER*);//工號 static bool SortbyName(S_WORKER*, S_WORKER*);//姓名 static bool SortbySala(S_WORKER*, S_WORKER*);//基本工資 static bool SortbyPost(S_WORKER*, S_WORKER*);//部門 static void ModifyPsw_1();//員工修改密碼 static void ModifyPsw_2();//部門經理修改密碼 static void ModifyPsw_3();//超級管理員修改密碼 void Delete_dpt(); void Delete_post(); void Delete_manager(); void Delete_Request();//刪除員工節點 void Delete_worker();//釋放員工連結串列堆記憶體 //void setColor(unsigned short backColor = 0, unsigned short textColor = 7); void setColor(char c1 = '0', char c2 = '7'); void AddSnode_Worker(S_WORKER * pworker) { PWORKER pnode = (PWORKER)malloc(sizeof(SWORKER)); pnode->s_data = *pworker; pnode->s_pNext = g_worker_head; g_worker_head = pnode; } void AddSnode_Manager(S_DADMIN *pdata) { PDADMIN pnode = (PDADMIN)malloc(sizeof(S_NODE_DEPARTMENT_ADMIN)); pnode->data = *pdata; pnode->pnext = g_dptManger_head; g_dptManger_head = pnode; } unsigned short GetMonth()//獲取當前月份 { time_t timer; time(&timer); tm *ptime = localtime(&timer); asctime(ptime); //printf("%d", time->tm_mon+1); return ptime->tm_mon; } time_t GetNowTime()//獲取當前時間 { time_t timer; time(&timer); return timer; } int Confirm_Number() { int n = 0; do { printf("請選擇:"); int nRet = scanf("%d", &n); if (!nRet) { printf("只能輸入數字哦!\n"); rewind(stdin); continue; } else break; } while (true); return n; } void Print_Worker(S_WORKER *pworker) { if (g_worker_head == NULL) { printf("無資訊可列印"); return; } system("cls"); printf("工號 姓名 性別 職務 所屬部門 狀態1 實際工資 加班 請假 處分 狀態2 員工請求\n");//狀態1為是否正式工,2為是否請假/休假/離職 PWORKER pNode = g_worker_head; printf("_________________________________________________________________________________________________________\n"); if (pworker) { if (g_nLevel == e_manager) { if (strcmp(pworker->ss_Dpt, gp_manager->ss_Department) == 0) printf("%-8s%-10s%-8s%-12s%-12s%-12s%-9.0f%-6d%-6d%-6d%-12s%-15s\n", pworker->ss_Number, pworker->ss_Name, pworker->b_sex ? "男" : "女", pworker->ss_Post, pworker->ss_Dpt, pworker->b_test ? "正式工" : "試用期", pworker->s_Sala.f_real, pworker->cOverDays, pworker->cLeaveDays, pworker->cPunish, pState[pworker->State], pRequest[pworker->e_request]); else printf("您無權檢視該員工資訊!"); } if(g_nLevel==e_admin || g_nLevel==e_worker) printf("%-8s%-10s%-8s%-12s%-12s%-12s%-9.0f%-6d%-6d%-6d%-12s%-13s\n", pworker->ss_Number, pworker->ss_Name, pworker->b_sex ? "男" : "女", pworker->ss_Post, pworker->ss_Dpt, pworker->b_test ? "正式工" : "試用期", pworker->s_Sala.f_real, pworker->cOverDays, pworker->cLeaveDays, pworker->cPunish, pState[pworker->State], pRequest[pworker->e_request]); return; } while (pNode) { if (g_nLevel == e_manager && strcmp(pNode->s_data.ss_Dpt, gp_manager->ss_Department) == 0) {//如果是部門主管,則只能檢視自己所屬部門的員工. printf("%-8s%-10s%-8s%-12s%-12s%-12s%-9.0f%-6d%-6d%-6d%-12s%-13s\n", pNode->s_data.ss_Number, pNode->s_data.ss_Name, pNode->s_data.b_sex ? "男" : "女", pNode->s_data.ss_Post, pNode->s_data.ss_Dpt, pNode->s_data.b_test ? "正式工" : "試用期", pNode->s_data.s_Sala.f_real, pNode->s_data.cOverDays, pNode->s_data.cLeaveDays, pNode->s_data.cPunish, pState[pNode->s_data.State], pRequest[pNode->s_data.e_request]); } if(g_nLevel==e_admin) { printf("%-8s%-10s%-8s%-12s%-12s%-12s%-9.0f%-6d%-6d%-6d%-12s%-13s\n", pNode->s_data.ss_Number, pNode->s_data.ss_Name, pNode->s_data.b_sex ? "男" : "女", pNode->s_data.ss_Post, pNode->s_data.ss_Dpt, pNode->s_data.b_test ? "正式工" : "試用期", pNode->s_data.s_Sala.f_real, pNode->s_data.cOverDays, pNode->s_data.cLeaveDays, pNode->s_data.cPunish, pState[pNode->s_data.State], pRequest[pNode->s_data.e_request]); } pNode = pNode->s_pNext; } } //輸入引數為只打印指定的職位資訊.否則為全部列印 void Print_post(char *pName) { if (!g_post_head) { printf("當前無職位資訊!"); system("pause"); return; } puts("職位名稱 基本工資 試用期工資 所屬部門"); PPOST pnode = g_post_head; if (!pName) { while (pnode) { printf("%-15s%-15.0f%-10.0f%12s\n", pnode->data.ss_postName, pnode->data.f_baseSala, pnode->data.f_TestSala, pnode->data.ss_dptName); pnode = pnode->pnext; } } else { bool flag = false; while (pnode) { if (strcmp(pName, pnode->data.ss_dptName) == 0) { flag = true; printf("%-10s%-10f%-10f%10s\n", pnode->data.ss_postName, pnode->data.f_baseSala, pnode->data.f_TestSala, pnode->data.ss_dptName); } pnode = pnode->pnext; } if (!flag) { printf("未找到該職位資訊!"); } } } ///////////////////////////////////////////////////////////////////////////////////////////////////////// ////////////////////以下程式碼為組織的增刪改查///////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////////////////////////// void PrintDpt(S_DPT * pdata) { // system("cls"); if (pdata) { printf("%-10s%-15s%-10s%-10s\n", pdata->ss_dptNum, pdata->ss_dptName, pdata->ss_dpt_manager, pdata->ss_dpt_manager_num); printf("----------------------------------------------------------\n"); return; } if (!g_dpt_head) { puts("當前無部門資訊,請新增!"); return; } PDPT pnode = g_dpt_head; printf("部門編號 部門名稱 部門主管 主管編號 其他\n"); while (pnode) { printf("%-10s%-15s%-10s%-10s\n",pnode->data.ss_dptNum,pnode->data.ss_dptName, pnode->data.ss_dpt_manager, pnode->data.ss_dpt_manager_num); //printf("\n"); //printf("\t+++此部門包含職位:"); //PrintPost(pnode->data.ss_dptName);//根據部門編號,列印職位 //printf("\n"); printf("----------------------------------------------------------\n"); //printf("\n\n"); pnode = pnode->pnext; } } bool CheckDpt(char* pchar, int nindex, S_DPT** ppdata) //找到返回true,否則返回false { if (!g_dpt_head) return false; PDPT pnode = g_dpt_head; while (pnode) { if (nindex == 1) { if (strcmp(pchar, pnode->data.ss_dptNum) == 0) { if (ppdata) //如果ppdata不是NULL,就返回被找到的資料地址 *ppdata = &pnode->data; return true; } } if(nindex == 2) { if (strcmp(pchar, pnode->data.ss_dptName) == 0) { if (ppdata) //如果ppdata不是NULL,就返回被找到的資料地址 *ppdata = &pnode->data; return true; } } if (nindex == 3) { if (strcmp(pchar, pnode->data.ss_dpt_manager_num) == 0) { if (ppdata) //如果ppdata不是NULL,就返回被找到的資料地址 *ppdata = &pnode->data; return true; } } pnode = pnode->pnext; } return false; } bool CheckPostName(char * pName, S_POST ** ppdata) { if (g_post_head == NULL) return false; PPOST pnode = g_post_head; while (pnode) { if(strcmp(pnode->data.ss_postName, pName) == 0) { if (ppdata) *ppdata = &pnode->data; return true; } pnode = pnode->pnext; } return false; } bool CheckWorker(char *pNum, S_WORKER **ppworker) { if (!g_worker_head) return false; PWORKER pnode = g_worker_head; while (pnode) { if (strcmp(pNum, pnode->s_data.ss_Number) == 0) { if (ppworker) *ppworker = &pnode->s_data; return true; } pnode = pnode->s_pNext; } return false; } bool CheckDManager(char *pNum, S_DADMIN **ppManager) { if (!g_dptManger_head) return false; PDADMIN pnode = g_dptManger_head; while (pnode) { if (strcmp(pNum, pnode->data.ss_Num) == 0) { if (ppManager) *ppManager = &pnode->data; return true; } pnode = pnode->pnext; } return false; } int Delete_Manager() { char sNum[15]; while (1) { system("cls"); printf("請輸入要刪除的工號:"); scanf_s("%s", sNum, sizeof(sNum)); if (strlen(sNum) == 0) { printf("長度不能長於14個字元\n"); system("pause"); continue; } S_DADMIN *pManager=NULL; if (!CheckDManager(sNum, &pManager)) { printf("未找到該主管工號,請重新輸入.\n"); system("pause"); continue; } Print_DptManager(pManager); printf("確定要刪除此主管資訊嗎?(y/n):"); if (!goOn()) { puts("您取消了當前的刪除操作"); Sleep(2000); return 0; } PDADMIN pnode = g_dptManger_head,p1=NULL; if (strcmp(pnode->data.ss_Num, sNum) == 0) { g_dptManger_head = g_dptManger_head->pnext; free(pnode); break; } p1 = pnode; while (pnode) { if (strcmp(pnode->data.ss_Num, sNum) == 0) { p1->pnext = pnode->pnext; free(pnode); break; } p1 = pnode; pnode = pnode->pnext; } break; } S_DPT *pDpt =