问题描述:

请设计一个职工信息管理程序,以方便人事部门对本单位职工的管理,该程序应该具有以下功

能:

(1)能从键盘输入职工的信息 。

(2)给定职工号,显示职工的信息。

(3)给定工作部门,显示该部门的职工信息。

(4)给定职工号,修改职工的信息。

(5)给定职工号,删除职工信息。

题目要求:

(1)按照分析、设计、编码、调试、测试的软件过程完成这个应用程序。

(2)职工信息应该包含职工号、姓名、工作部门、职称、入厂时间、工资。

(3)为程序设计windows 窗口,在该窗口上以按钮的形式为用户提供“菜单”,通过点击各个功

能项对应的按钮完成操作。

输入要求:

(1)用户可以根据需求,选定相应的操作项目。进入每个操作后,通过窗口的文本框,从键盘输

入相应的信息。程序根据用户输入的信息完成相应的处理,实现要求的功能。

(2)能对输入的数据进行简单的校验,例如,入厂时间必须是合法的日期格式,职工号是唯一的

(一个职工号对应一个职工的职工信息)。

输出要求:

(1)应用程序运行后,要在屏幕上显示一个按钮形式的“菜单”。

(2)要求用户输入数据时,给出清晰、明确的提示信息,包括输入的数据内容、格式以及结束方

式等。

(3)在程序完成处理后,要清楚地给出程序的处理结果。例如,在给定职工号删除职工信息时,

如果该职工不存在,要提示没能删除,如果删除成功要提示删除成功。

实现要求:

(1)在程序中使用链表存储职工信息。

(2)采用模块化程序设计的方法,将程序中的各项功能用函数实现。

提示:

(1)使用结构体表示职工信息,一个结点保存一条职工信息。

扩展功能:

(1)提供一些统计功能。例如统计每个部门的人数,统计平均工资、统计各职称的人数。

(2)职工信息从文件读入。

(3)将职工信息保存到文件中。

代码如下:

  1. #include <windows.h>
  2. #include<string.h>
  3. #include<stdio.h>
  4. #include"resource.h"
  5. LRESULT WINAPI WinProc(HWND hWnd,UINT Msg,WPARAM wParam,LPARAM lParam);//函数声明
  6. /* 基本功能 */
  7. void initWorker();
  8. void addWorker();
  9. void showAllInfo();
  10. void clearText();
  11. void clearCache();
  12. void deleteWorker();
  13. void searchWorker();
  14. void modifyWorker();
  15. void searchDepartmentWorker();
  16. void showFormat(struct worker *p);
  17. void saveLocalFile();
  18. void readLocalFile();
  19. void statisticsInfo();
  20.  
  21. struct inputhwnd
  22. {
  23. int x1;
  24. int x2;
  25. int x3;
  26. int x4;
  27. int menu_name;
  28. }hwndArray[]= {{, , , ,NUM_INPUT},{, , , ,NAME_INPUT},{, , , ,DEPART_INPUT},
  29. {, , , ,JOBTITLE_INPUT},{, , , ,YEAR_INPUT},{, , , ,WAGE_INPUT},
  30. {, , , ,MONTH_INPUT},{, , , ,DATE_INPUT},{, , , ,BIGTEXTBOX}};
  31. /* 按钮 结构体 */
  32. struct inputhwndbutton
  33. {
  34. char buttonName[];
  35. int x1;
  36. int x2;
  37. int x3;
  38. int x4;
  39. int buttonNum;
  40. }buttonArray[]={{"添加职工",,,,,ADD_BUTTON},{"按职工号查询",,,,,SEARCHNUM_BUTTON},{"修改信息",,,,,MODIFY_BUTTON},
  41. {"删除职工",,,,,DELETE_BUTTON},{"显示所有职工信息",,,,,SHOWINFO_BUTTON},{"按部门查询",,,,,SEARCHDEPART_BUTTON},
  42. {"清空显示",,,,,CLEARTEXT_BUTTON},{"版权声明",,,,,COPYRIGHT_BUTTON},{"退出程序",,,,,EXIT_BUTTON},
  43. {"保存到本地",,,,,SAVELOCALFILE_BUTTON},{"从本地读",,,,,READLOCALFILE_BUTTON},{"统计",,,,,STATISTICS_BUTTON}};
  44. /* 矩形框 结构体 */
  45. struct showrect
  46. {
  47. char rectName[];
  48. int top;
  49. int right;
  50. int bottom;
  51. int left;
  52. }rectArray[]={{"[ 职工信息输入框 ]",,,,},{"职工号:",,,,},{"姓名:",,,,},
  53. {"工作部门:",,,,},{"职称:",,,,},{"入厂时间:",,,,},
  54. {"工资:",,,,},{"年",,,,},{"月",,,,},{"日",,,,}};
  55. RECT rect[];
  56. HDC hDC;
  57. HWND hWnd;
  58. PAINTSTRUCT paint;
  59. static char str_num[],str_name[],str_depart[],str_jobTitle[],str_year[],str_month[],str_date[],str_wage[],str_showAll[];
  60. char title[]={"职工号\t\t姓名\t\t工作部门\t\t\t职称\t\t入厂时间\t\t工资\r\n\r\n"};
  61. struct worker
  62. {
  63. long num; //职工号
  64. char name[]; //姓名
  65. char department[];//工作部门
  66. char jobTitle[]; //职称
  67. int year;
  68. int month;
  69. int date;
  70. long wage; //工资
  71. worker *next;
  72. };
  73. struct worker *headp;
  74. void initWorker()
  75. {
  76. headp = new worker;
  77. headp->next=NULL;
  78. }
  79. int WINAPI WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance,LPSTR lpCmdLine,int nShowCmd)
  80. {
  81. char *cName = "myWindow";//定义个字符指针表示窗口类的名字
  82. WNDCLASS wc;//定义变量
  83. MSG Msg;
  84. wc.cbClsExtra = ;
  85. wc.cbWndExtra = ;
  86. wc.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH);;//设置窗口背景为白色
  87. wc.hCursor = NULL;//窗口的光标不设置
  88. wc.hIcon = NULL;
  89. wc.hInstance = hInstance;//当前程序的句柄,hInstance是由主函数传递
  90. wc.lpfnWndProc = WinProc;//窗口处理过程的窗口函数。
  91. wc.lpszClassName =(LPSTR)cName;//窗口类的名字。
  92. wc.lpszMenuName = NULL;//目录名,不设置
  93. wc.style = CS_HREDRAW | CS_VREDRAW; //窗口类的风格
  94. RegisterClass(&wc);//在系统中注册窗口
  95. hWnd = CreateWindow(cName,TEXT("职工管理程序"),WS_OVERLAPPEDWINDOW,, , , ,NULL, NULL, hInstance, NULL) ;
  96. ShowWindow(hWnd,nShowCmd);//显示窗口
  97. UpdateWindow(hWnd);//更新窗口
  98. initWorker();
  99. while(GetMessage(&Msg,NULL,,))
  100. {
  101. TranslateMessage(&Msg);//翻译消息
  102. DispatchMessage(&Msg);//分派消息
  103. }
  104. return Msg.message;//程序结束后返回消息
  105. }
  106. LRESULT WINAPI WinProc(HWND hWnd,UINT Msg,WPARAM wParam,LPARAM lParam)
  107. {//处理消息过程
  108. static HWND btnHwnd;
  109. static HWND inputHwnd[];
  110. static HWND hwndbutton[];
  111. switch(Msg)//对消息进行判断
  112. {
  113. case WM_PAINT:
  114. hDC=BeginPaint(hWnd,&paint);//获取设备上下文
  115. for(int i =;i<;i++)
  116. {
  117. rect[i].top = rectArray[i].top;
  118. rect[i].right = rectArray[i].right;
  119. rect[i].bottom = rectArray[i].bottom;
  120. rect[i].left = rectArray[i].left;
  121. DrawText(hDC,rectArray[i].rectName,-,&rect[i],DT_SINGLELINE|DT_LEFT|DT_VCENTER);
  122. }
  123. EndPaint(hWnd,&paint);
  124. return ;
  125. case WM_CREATE: //响应窗口的创建事件
  126. //gg(((LPCREATESTRUCT) lParam) -> hInstance);
  127. for(int i = ;i<;i++)
  128. {
  129. inputHwnd[i]=CreateWindow(TEXT("edit"),NULL,WS_CHILD |WS_VISIBLE|WS_BORDER|ES_LEFT|ES_MULTILINE,hwndArray[i].x1,hwndArray[i].x2,hwndArray[i].x3,hwndArray[i].x4,hWnd,(HMENU)hwndArray[i].menu_name,((LPCREATESTRUCT) lParam)->hInstance,NULL);
  130. }
  131. for(int i = ;i<;i++)
  132. {
  133. hwndbutton[i]=CreateWindow(TEXT("BUTTON"),buttonArray[i].buttonName,WS_CHILD|WS_VISIBLE,buttonArray[i].x1,buttonArray[i].x2,buttonArray[i].x3,buttonArray[i].x4,hWnd,(HMENU)buttonArray[i].buttonNum,((LPCREATESTRUCT) lParam) -> hInstance,NULL);
  134. }
  135. return ;
  136. case WM_COMMAND://响应命令
  137. {
  138. switch(LOWORD(wParam))
  139. {
  140. case ADD_BUTTON:
  141. {
  142. clearCache();
  143. addWorker();
  144. return ;
  145. }
  146. case SEARCHNUM_BUTTON:
  147. {
  148. clearCache();
  149. searchWorker();
  150. return ;
  151. }
  152. case MODIFY_BUTTON:
  153. {
  154. clearCache();
  155. modifyWorker();
  156. return ;
  157. }
  158. case DELETE_BUTTON:
  159. {
  160. clearCache();
  161. deleteWorker();
  162. return ;
  163. }
  164. case SHOWINFO_BUTTON:
  165. {
  166. clearCache();
  167. showAllInfo();
  168. return ;
  169. }
  170. case SEARCHDEPART_BUTTON:
  171. {
  172. clearCache();
  173. searchDepartmentWorker();
  174. return ;
  175. }
  176. case CLEARTEXT_BUTTON:
  177. {
  178. clearCache();
  179. clearText();
  180. return ;
  181. }
  182. case COPYRIGHT_BUTTON:
  183. {
  184. MessageBox(NULL,TEXT("本程序归属CCSoft所有,并保留一切权力,任何\n个人或者单位必须经过CCSoft的个人授权、不限\n于书面形式。如有侵权行为,必当追究。"),TEXT("版权声明"),MB_OK);
  185. return ;
  186. }
  187. case EXIT_BUTTON:
  188. {
  189. PostQuitMessage();//退出消息队列
  190. return ;//返回0,结束函数
  191. }
  192. /* 扩展功能:保存在本地 */
  193. case SAVELOCALFILE_BUTTON:
  194. {
  195. clearCache();
  196. saveLocalFile();
  197. return ;
  198. }
  199. /* 扩展功能:写在本地 */
  200.  
  201. /**fun()[];*/
  202. case READLOCALFILE_BUTTON:
  203. {
  204. clearCache();
  205. readLocalFile();
  206. /* 用函数指针的方式 */
  207. /*fun()[3]*/
  208. return ;
  209. }
  210. /* 扩展功能:简单的统计 */
  211. case STATISTICS_BUTTON:
  212. {
  213. clearCache();
  214. statisticsInfo();
  215. return ;
  216. }
  217. }
  218. return ;
  219. }
  220. case WM_DESTROY://如果是点击关闭窗口时的消息
  221. PostQuitMessage();//退出消息队列
  222. return ;//返回0,结束函数
  223. }
  224. //如果是其余的消息,调用默认消息处理函数,将消息该函数处理并将返回值返回
  225. return DefWindowProc(hWnd,Msg,wParam,lParam);
  226. }
  227. void clearText()
  228. {
  229.  
  230. SetDlgItemText(hWnd,NUM_INPUT,str_num);
  231. SetDlgItemText(hWnd,NAME_INPUT,str_name);
  232. SetDlgItemText(hWnd,DEPART_INPUT,str_depart);
  233. SetDlgItemText(hWnd,JOBTITLE_INPUT,str_jobTitle);
  234. SetDlgItemText(hWnd,YEAR_INPUT,str_year);
  235. SetDlgItemText(hWnd,MONTH_INPUT,str_month);
  236. SetDlgItemText(hWnd,DATE_INPUT,str_date);
  237. SetDlgItemText(hWnd,WAGE_INPUT,str_wage);
  238. SetDlgItemText(hWnd,BIGTEXTBOX,str_showAll);
  239. }
  240. void gg( HINSTANCE hInstance)
  241. {
  242.  
  243. }
  244.  
  245. void clearCache()
  246. {
  247. ZeroMemory(str_num,sizeof(str_num));
  248. ZeroMemory(str_name,sizeof(str_name));
  249. ZeroMemory(str_depart,sizeof(str_depart));
  250. ZeroMemory(str_jobTitle,sizeof(str_jobTitle));
  251. ZeroMemory(str_year,sizeof(str_year));
  252. ZeroMemory(str_month,sizeof(str_month));
  253. ZeroMemory(str_date,sizeof(str_date));
  254. ZeroMemory(str_wage,sizeof(str_wage));
  255. ZeroMemory(str_showAll,sizeof(str_showAll));
  256. }
  257. void addWorker()
  258. {
  259. char str_temp[];
  260. ZeroMemory(str_temp,sizeof(str_temp));
  261. struct worker *newworker;
  262. struct worker *assistp,*followp;
  263. followp=headp;
  264. assistp=headp->next;
  265. newworker = new worker;
  266. GetDlgItemText(hWnd,NUM_INPUT,str_num,sizeof(str_num)/sizeof(char));
  267. newworker->num = atol(str_num);
  268. if(newworker->num == || newworker->num<)
  269. {
  270. MessageBox(NULL,TEXT("保存失败!输入职工号不合法!请检查输入信息"),TEXT("系统提示"),MB_OK);
  271. delete newworker;
  272. }
  273. else
  274. {
  275. while(assistp!=NULL && assistp->num!=newworker->num)
  276. {
  277. assistp=assistp->next;
  278. followp=followp->next;
  279. }
  280. if(assistp==NULL)
  281. {
  282. GetDlgItemText(hWnd,NAME_INPUT,newworker->name,sizeof(str_num)/sizeof(char));
  283. GetDlgItemText(hWnd,DEPART_INPUT,newworker->department,sizeof(str_num)/sizeof(char));
  284. GetDlgItemText(hWnd,JOBTITLE_INPUT,newworker->jobTitle,sizeof(str_num)/sizeof(char));
  285. GetDlgItemText(hWnd,YEAR_INPUT,str_year,sizeof(str_num)/sizeof(char));
  286. GetDlgItemText(hWnd,MONTH_INPUT,str_month,sizeof(str_num)/sizeof(char));
  287. GetDlgItemText(hWnd,DATE_INPUT,str_date,sizeof(str_num)/sizeof(char));
  288. GetDlgItemText(hWnd,WAGE_INPUT,str_wage,sizeof(str_num)/sizeof(char));
  289. newworker->wage=atoi(str_wage);
  290. newworker->year=atoi(str_year);
  291. newworker->month=atoi(str_month);
  292. newworker->date=atoi(str_date);
  293. newworker->next = NULL;
  294. if(newworker->year< || newworker->year> || newworker->month< || newworker->month > || newworker->date < ||newworker->date>)
  295. {
  296. MessageBox(NULL,TEXT("保存失败!您输入的日期不合法,请检查职工信息,并重试!"),("系统提示"),MB_OK);
  297. delete newworker;
  298. }
  299. else if(newworker->wage< | newworker->wage > )
  300. {
  301. MessageBox(NULL,TEXT("保存失败!您输入的工资不合法,请检查职工信息,并重试!"),TEXT("系统提示"),MB_OK);
  302. delete newworker;
  303. }
  304. else
  305. {
  306. /* 理清楚概念不要挂错了地方。 */
  307. followp->next=newworker;//将指向首节点的指针,向右移动
  308. followp=followp->next;
  309. MessageBox(NULL,TEXT("保存成功!"),TEXT("系统提示"),MB_OK);
  310. }
  311. }
  312. else
  313. {
  314. strcat(str_temp,"保存失败!职工号为");
  315. ltoa(newworker->num,str_num,);
  316. strcat(str_temp,str_num);
  317. strcat(str_temp,"的职工已存在,请勿重复保存!");
  318. MessageBox(NULL,str_temp,"系统提示",MB_OK);
  319. delete newworker;
  320. }
  321. }
  322. }
  323. void showAllInfo()
  324. {
  325. int flag = ;
  326. worker *searchp;
  327. searchp=headp->next;
  328. if(searchp==NULL)
  329. {
  330. MessageBox(NULL,TEXT("请先输入职工信息!"),TEXT("系统提示"),MB_OK);
  331. }
  332. strcat(str_showAll,title);
  333. while(searchp!=NULL)
  334. {
  335. flag = ;
  336. showFormat(searchp);
  337. searchp=searchp->next;
  338. }
  339. if(flag==)
  340. {
  341. SetDlgItemText(hWnd,,str_showAll);
  342. }
  343. }
  344. /* 函数名:showFormat(struct worker *p)
  345. * 用来统一文本输出格式
  346. 为什么当初用那种显示方式 主要是因为简单,但是对于用户来说 可能影响了用户的使用体验。
  347. */
  348. void showFormat(struct worker *p)
  349. {
  350. ltoa(p->num,str_num,);
  351. strcat(str_showAll,str_num);
  352. /* 该判断 用来对齐 字符串 */
  353. if(strlen(str_num)<)
  354. {
  355. //MessageBox(NULL,TEXT("测试判断"),TEXT("提示"),MB_OK);
  356. strcat(str_showAll,"\t");
  357. }
  358. strcat(str_showAll,"\t");
  359. strcat(str_showAll,p->name);
  360. strcat(str_showAll,"\t\t");
  361. strcat(str_showAll,p->department);
  362. if(strlen(p->department)<)
  363. {
  364. strcat(str_showAll,"\t\t\t");
  365. }
  366. else
  367. {
  368. strcat(str_showAll,"\t\t");
  369. }
  370. //strcat(str_showAll,"\t");
  371. strcat(str_showAll,p->jobTitle);
  372. strcat(str_showAll,"\t\t");
  373. ltoa(p->year,str_year,);
  374. strcat(str_showAll,str_year);
  375. strcat(str_showAll,"年");
  376. ltoa(p->month,str_month,);
  377. strcat(str_showAll,str_month);
  378. strcat(str_showAll,"月");
  379. ltoa(p->date,str_date,);
  380. strcat(str_showAll,str_date);
  381. strcat(str_showAll,"日");
  382. strcat(str_showAll,"\t");
  383. ltoa(p->wage,str_wage,);
  384. strcat(str_showAll,str_wage);
  385. strcat(str_showAll,"\r\n");
  386. strcat(str_showAll,"\r\n");
  387. }
  388. void deleteWorker()
  389. {
  390. char str_temp[];
  391. ZeroMemory(str_temp,sizeof(str_temp));
  392. long s;
  393. worker *deletep,*shadowp;
  394. shadowp=headp;
  395. deletep=headp->next;
  396. GetDlgItemText(hWnd,NUM_INPUT,str_num,sizeof(str_num)/sizeof(char));
  397. s=atol(str_num);
  398. if(s== || s<)
  399. {
  400. MessageBox(NULL,TEXT("请输入正确的职工号再删除!"),TEXT("系统提示"),MB_OK);
  401. }
  402. else
  403. {
  404. while(deletep!=NULL && deletep->num!=s)
  405. {
  406. deletep=deletep->next;
  407. shadowp=shadowp->next;
  408. }
  409. if(deletep!=NULL)
  410. {
  411. if(deletep->next==NULL)
  412. {
  413. shadowp->next =NULL;
  414. delete deletep;;
  415. MessageBox(NULL,TEXT("删除成功"),TEXT("系统提示"),MB_OK);
  416. }
  417. else
  418. {
  419. shadowp->next=deletep->next;
  420. delete deletep;
  421. MessageBox(NULL,TEXT("删除成功"),TEXT("系统提示"),MB_OK);
  422. }
  423. }
  424. else
  425. {
  426. strcat(str_temp,"职工号为:");
  427. strcat(str_temp,str_num);
  428. strcat(str_temp,"的职工不存在,无法删除!");
  429. MessageBox(NULL,str_temp,TEXT("系统提示"),MB_OK);
  430. }
  431. }
  432. }
  433. void searchWorker()
  434. {
  435. long s;
  436. char str_temp[];
  437. ZeroMemory(str_temp,sizeof(str_temp));
  438. struct worker *assistp;
  439. assistp=headp->next;
  440. GetDlgItemText(hWnd,NUM_INPUT,str_num,sizeof(str_num)/sizeof(char));
  441. s=atol(str_num);
  442. if(s== || s<)
  443. {
  444. MessageBox(NULL,TEXT("请输入正确的职工号!"),TEXT("系统提示"),MB_OK);
  445. }
  446. else
  447. {
  448. /* long s = atol(str1); 直接用!=进行比较 没毛病 */
  449.  
  450. while(assistp!=NULL && assistp->num!=s)
  451. {
  452. assistp=assistp->next;
  453. }
  454. if(assistp!=NULL)
  455. {
  456. strcat(str_showAll,title);
  457. showFormat(assistp);
  458. SetDlgItemText(hWnd,,str_showAll);
  459. }
  460. else
  461. {
  462. strcat(str_temp,"职工号为:");
  463. strcat(str_temp,str_num);
  464. strcat(str_temp,"的职工不存在!");
  465. MessageBox(NULL,str_temp,TEXT("系统提示"),MB_OK);
  466. }
  467. }
  468.  
  469. }
  470. void modifyWorker()
  471. {
  472. struct worker *assistp;
  473. assistp=headp->next;
  474. char str_temp[];
  475. long s;
  476. GetDlgItemText(hWnd,NUM_INPUT,str_num,sizeof(str_num)/sizeof(char));
  477. s=atol(str_num);
  478. if(s== || s<)
  479. {
  480. MessageBox(NULL,TEXT("请输入正确的职工号!"),TEXT("系统提示"),MB_OK);
  481. }
  482. else
  483. {
  484. while(assistp!=NULL && assistp->num!=s)
  485. {
  486. assistp=assistp->next;
  487. }
  488. if(assistp!=NULL)
  489. {
  490. GetDlgItemText(hWnd,NAME_INPUT,assistp->name,sizeof(str_num)/sizeof(char));
  491. GetDlgItemText(hWnd,DEPART_INPUT,assistp->department,sizeof(str_num)/sizeof(char));
  492. GetDlgItemText(hWnd,JOBTITLE_INPUT,assistp->jobTitle,sizeof(str_num)/sizeof(char));
  493. //GetDlgItemText(hWnd,5,newworker->date,sizeof(str1)/sizeof(char));
  494. GetDlgItemText(hWnd,YEAR_INPUT,str_year,sizeof(str_num)/sizeof(char));
  495. GetDlgItemText(hWnd,WAGE_INPUT,str_wage,sizeof(str_num)/sizeof(char));
  496. GetDlgItemText(hWnd,MONTH_INPUT,str_month,sizeof(str_num)/sizeof(char));
  497. GetDlgItemText(hWnd,DATE_INPUT,str_date,sizeof(str_num)/sizeof(char));
  498. assistp->wage = atoi(str_wage);
  499. assistp->year = atoi(str_month);
  500. assistp->month = atoi(str_month);
  501. assistp->date = atoi(str_date);
  502. MessageBox(NULL,TEXT("修改成功!"),TEXT("系统提示"),MB_OK);
  503. }
  504. else
  505. {
  506. strcat(str_temp,"职工号为:");
  507. strcat(str_temp,str_num);
  508. strcat(str_temp,"的职工不存在,无法修改其信息!");
  509. MessageBox(NULL,str_temp,TEXT("系统提示"),MB_OK);
  510. }
  511. }
  512. assistp=headp->next;
  513. }
  514.  
  515. void searchDepartmentWorker()
  516. {
  517. int flag= ;
  518. worker *searchp;
  519. searchp=headp->next;
  520. GetDlgItemText(hWnd,DEPART_INPUT,str_depart,sizeof(str_num)/sizeof(char));
  521. if(str_depart=="\0")
  522. {
  523. MessageBox(NULL,TEXT("请输入正确的部门!"),TEXT("系统提示"),MB_OK);
  524. }
  525. else
  526. {
  527. strcat(str_showAll,title);
  528. while(searchp!=NULL)
  529. {
  530. if(strcmp((searchp->department),str_depart)==)
  531. {
  532. flag =;
  533. showFormat(searchp);
  534. /* 如果 和比对的 字符串 相等的话 , 向前移动一个在进行比较 */
  535. searchp=searchp->next;
  536.  
  537. }
  538. else
  539. {
  540. /* 如果 和比对的 字符串 不相等的话 , 向前移动一个在进行比较 */
  541. /* 注意这个不能漏,必定出错。 */
  542. searchp=searchp->next;
  543. }
  544. }
  545. SetDlgItemText(hWnd,,str_showAll);
  546. //searchp=headp->next;
  547. if(flag == )
  548. {
  549. MessageBox(NULL,TEXT("没有找到该部门的职工!"),TEXT("系统提示"),MB_OK);
  550. }
  551. }
  552. }
  553.  
  554. /* 扩展功能 */
  555. void saveLocalFile()
  556. {
  557. int flag = ;
  558. FILE *fp;
  559. fp=fopen("C:\\workerDatabase.txt","w");
  560. if(fp==NULL)
  561. {
  562. MessageBox(NULL,TEXT("无法保存在本地!"),TEXT("系统警告"),MB_OK);
  563. exit();
  564. }
  565. worker *searchp;
  566. searchp=headp->next;
  567. if(searchp==NULL)
  568. {
  569. MessageBox(NULL,TEXT("职工信息为空!请先录入职工信息!"),TEXT("系统警告"),MB_OK);
  570. exit();
  571. }
  572. while(searchp!=NULL)
  573. {
  574. fprintf(fp,"%ld %s %s %s %d %d %d %ld\n",searchp->num,searchp->name,searchp->department,searchp->jobTitle,searchp->year,searchp->month,searchp->date,searchp->wage);
  575. searchp=searchp->next;
  576. flag = ;
  577. }
  578. fclose(fp);
  579. if(flag == )
  580. {
  581. MessageBox(NULL,TEXT("写入本地成功!"),TEXT("系统提示"),MB_OK);
  582. }
  583. else
  584. {
  585. MessageBox(NULL,TEXT("写入本地失败!"),TEXT("系统提示"),MB_OK);
  586. }
  587. }
  588. void readLocalFile()
  589. {
  590. FILE *p;
  591. int flag = ;
  592. struct worker *newworker;//用来保存读入的新职员
  593. struct worker *followp;//用来移动指针
  594. followp=headp;
  595. worker *shadowp;//定义一个影子指针 用来指向 倒数第二个节点。因为从文本读入的时候最后一行是空行,要丢弃。
  596. if((p=fopen("C:\\workerDatabase.txt","r"))==NULL)
  597. {
  598. MessageBox(NULL,TEXT("打开本地数据文件失败!"),TEXT("系统警告"),MB_OK);
  599. exit();
  600. }
  601. while(!feof(p))
  602. {
  603. newworker = (struct worker*)malloc(sizeof(struct worker ));
  604. fscanf(p,"%ld %s %s %s %d %d %d %ld",&newworker->num,newworker->name,newworker->department,newworker->jobTitle,&newworker->year,&newworker->month,&newworker->date,&newworker->wage);
  605. newworker->next = NULL;
  606. followp->next = newworker;
  607. shadowp = followp;
  608. followp = newworker;
  609. /* 在这里-842156451是用来标记一个未赋值的变量。利用这一点,来判断读取是否成功*/
  610. if(newworker->wage != -)
  611. {
  612. flag = ;
  613. }
  614. }
  615. /* 删除最后一个节点*/
  616. delete newworker;
  617. followp = shadowp;
  618. shadowp->next = NULL;
  619. if(flag == )
  620. {
  621.  
  622. MessageBox(NULL,TEXT("从本地读取到程序成功!"),TEXT("系统提示"),MB_OK);
  623. }
  624. else
  625. {
  626. MessageBox(NULL,TEXT("从本地读取到程序失败"),TEXT("系统提示"),MB_OK);
  627. }
  628.  
  629. fclose(p);
  630. }
  631. void statisticsInfo()
  632. {
  633. char temp1[],temp2[];
  634. int NumOfPeoCount=;
  635. double sumWage = ;
  636. double averageWage=;
  637. worker *searchp;
  638. searchp=headp->next;
  639. if(headp->next==NULL)
  640. {
  641. MessageBox(NULL,TEXT("请先输入职工信息!"),TEXT("系统提示"),MB_OK);
  642. }
  643. else
  644. {
  645. while(searchp!=NULL)
  646. {
  647. NumOfPeoCount++;
  648. sumWage += searchp->wage;
  649. searchp=searchp->next;
  650. }
  651. averageWage = sumWage/(double)NumOfPeoCount;
  652. ltoa(NumOfPeoCount,temp1,);
  653. ltoa(averageWage,temp2,);
  654. strcat(str_showAll,"总计有:");
  655. strcat(str_showAll,temp1);
  656. strcat(str_showAll,"人\t");
  657. strcat(str_showAll,"平均工资为:");
  658. strcat(str_showAll,temp2);
  659. strcat(str_showAll,"\t\n");
  660. SetDlgItemText(hWnd,,str_showAll);
  661. }
  662. }

resource.h头文件如下:

  1. /* INPUT NUMBER */
  2. #define NUM_INPUT 1
  3. #define NAME_INPUT 2
  4. #define DEPART_INPUT 3
  5. #define JOBTITLE_INPUT 4
  6. #define YEAR_INPUT 5
  7. #define WAGE_INPUT 6
  8. #define MONTH_INPUT 7
  9. #define DATE_INPUT 8
  10. #define BIGTEXTBOX 10
  11. /* BUTTON NUMBER */
  12. #define ADD_BUTTON 13
  13. #define SEARCHNUM_BUTTON 14
  14. #define MODIFY_BUTTON 15
  15. #define DELETE_BUTTON 16
  16. #define SHOWINFO_BUTTON 17
  17. #define SEARCHDEPART_BUTTON 18
  18. #define CLEARTEXT_BUTTON 19
  19. #define COPYRIGHT_BUTTON 20
  20. #define EXIT_BUTTON 21
  21. #define SAVELOCALFILE_BUTTON 100
  22. #define READLOCALFILE_BUTTON 101
  23. #define STATISTICS_BUTTON 111

C语言课程设计 Win32应用程序的更多相关文章

  1. C语言课程设计

    目录 实现目的 游戏玩法介绍 实现流程与作品架构 任务列表及贡献度 总结感想 作品源码与仓库地址(附页) 资料引用与出处(附页) 实现目的 2048,作为一款极其经典的游戏,从发行到现在,已经有了极多 ...

  2. 学生管理系统-火车订票系统 c语言课程设计

    概要: C 语言课程设计一---学生管理系统 使使用 C 语言实现学生管理系统.系统实现对学生的基本信息和考试成绩的 管理.采用终端命令界面,作为系统的输入输出界面.采用文件作为信息存储介质. 功能描 ...

  3. C语言课程设计—图书管理系统

    这是本人大一第二学期初C语言课程设计的作品,嘿嘿,本来以为已经找不到原稿了,今天无意中居然在QQ网络硬盘中找到了当初的teta版,公布于此,以作纪念. C源码例如以下: #include<std ...

  4. Java语言课程设计——博客作业教学数据分析系统(201521123107 张翔)

    #Java语言课程设计--博客作业教学数据分析系统(个人博客) 1.团队课程设计博客链接 [博客作业教学数据分析系统(From:网络五条狗)](http://www.cnblogs.com/fanta ...

  5. C语言课程设计(成绩管理系统)

    C语言课程设计(成绩管理系统) 翻到了大学写的C语言课程设计,缅怀一下 内容: 增加学生成绩 查询学生成绩 删除 按照学生成绩进行排序 等 #include <stdio.h> #incl ...

  6. C语言课程设计大整数运算

    该大整数运算系统用于对有符号的位数不超过500位的大整数进行加.减.乘.除四则运算和计算N(0<=N<=10000)的阶乘.注意事项 :    1.操作期间,进行四则运算时若大整数为正数请 ...

  7. 大一C语言课程设计——班级档案管理系统

    记录我在大一第二学期期末做的C语言课程毕业设计 1. 班级档案管理系统运用到的主要结构体 typedef struct birthday //出生日期{int year;int month;int d ...

  8. C语言课程设计——电影院订票系统

    1. 课题简介 大家都爱看电影,现请参考一个熟悉电影票预订系统,实现C语言版的订票系统.了解订票如何实现的.系统主要有2类用户:管理员用户和顾客用户. 管理员用户登录系统后,实现电影放映厅信息管理和电 ...

  9. 第一次 C语言课程设计

    小学生测验 最近比较忙,就拿前几天做的课设项目水一水. 内容 面向小学1~2年级学生,随机选择两个整数和加减法形成算式要求学生解答. 功能要求: (1)电脑随机出10道题,每题10分,程序结束时显示学 ...

随机推荐

  1. Android服务开发经验——优雅地活着

    大多数的Android应用开发都会将注意力集中在界面功能上,只有少数应用会需要一个Service,尤其是一个长期运行的Service,去进行后台联网.环境检测.媒体播放等功能.Android环境下的S ...

  2. WebActivator的实现原理详解

    WebActivator的实现原理详解 文章内容 上篇文章,我们分析如何动态注册HttpModule的实现,本篇我们来分析一下通过上篇代码原理实现的WebActivator类库,WebActivato ...

  3. 在线试听功能(前端直接略过吧,适合javaEE后台开发的)

    应用场景:录音试听,MP3试听... 比如为客户提供录音功能时.客户希望录音完成试听录音,然后下载等功能.直接上代码:关键是取得录音的在服务器的地址,如:url='http://localhost:8 ...

  4. Java中的嵌套类和内部类

    以前看<Java编程思想>的时候,看到过嵌套类跟内部类的区别,不过后来就把它们的概念给忘了吧.昨天在看<数据结构与算法分析(Java语言版)>的时候,又遇到了这个概念,当时就很 ...

  5. c#二进制、十进制、16进制之间的转换

    //十进制转二进制 Console.WriteLine(Convert.ToString(69, 2)); //十进制转八进制 Console.WriteLine(Convert.ToString(6 ...

  6. Memcached缓存入门篇

    Asp.Net中使用Couchbase——Memcached缓存入门篇 前言 本文的主要目的就是简单的进行使用Memcached.这是Memchahed的官网http://memcached.org/ ...

  7. Microsoft Push Notification Service(MPNS)的最佳体验

    如何获得 Microsoft Push Notification Service(MPNS)的最佳体验 有很多同学抱怨MPNS的各种问题,其中包括服务超时.返回各种错误代码不知如何处理等等..今天我用 ...

  8. Html Agility Pack解析HTML页

    文章来源:Html Agility Pack解析HTML页 现在,在不少应用场合中都希望做到数据抓取,特别是基于网页部分的抓取.其实网页抓取的过程实际上是通过编程的方法,去抓取不同网站网页后,再进行分 ...

  9. C#程序调用cmd.exe执行命令

    代码部分 using System.Diagnostics; public class CmdHelper { private static string CmdPath = @"C:\Wi ...

  10. MSSQL数据库迁移到Oracle

    MSSQL数据库迁移到Oracle 最近要把一个MSSQL数据库迁移到Oracle上面,打算借助PowerDesigner这个软件来实现;今天简单研究一下这个软件的运用;把一步简单的操作步骤记录下来: ...