Personnel.cpp 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439
  1. // Personnel.cpp: 实现文件
  2. //
  3. #include "pch.h"
  4. #include "ZGKJ.h"
  5. #include "afxdialogex.h"
  6. #include "Personnel.h"
  7. #include "AddDep.h"
  8. #include "AddPost.h"
  9. // Personnel 对话框
  10. IMPLEMENT_DYNAMIC(Personnel, CDialogEx)
  11. Personnel::Personnel(CWnd* pParent /*=nullptr*/)
  12. : CDialogEx(IDD_PERSONNEL, pParent)
  13. , awatiName(_T(""))
  14. , awatiPhone(_T(""))
  15. , depName(_T(""))
  16. , postName(_T(""))
  17. {
  18. //pParent = new Personnel;
  19. }
  20. Personnel::~Personnel()
  21. {
  22. }
  23. void Personnel::DoDataExchange(CDataExchange* pDX)
  24. {
  25. CDialogEx::DoDataExchange(pDX);
  26. DDX_Control(pDX, IDC_LIST_DEPARMENT, ListDeparment);
  27. DDX_Control(pDX, IDC_LIST_AWATI, ListAwati);
  28. DDX_Control(pDX, IDC_LIST3_STAFF, ListStaff);
  29. DDX_Control(pDX, IDC_COMBO_DEP, DepName);
  30. DDX_Control(pDX, IDC_LIST_POST, ListPost);
  31. DDX_Control(pDX, IDC_COMBO2_POST, PostName);
  32. DDX_Text(pDX, IDC_PER_NAME, awatiName);
  33. DDX_Text(pDX, IDC_PER_PHONE, awatiPhone);
  34. DDX_CBString(pDX, IDC_COMBO_DEP, depName);
  35. DDX_CBString(pDX, IDC_COMBO2_POST, postName);
  36. }
  37. BEGIN_MESSAGE_MAP(Personnel, CDialogEx)
  38. ON_WM_LBUTTONDOWN()
  39. ON_WM_LBUTTONDOWN()
  40. ON_NOTIFY(NM_CLICK, IDC_LIST_AWATI, &Personnel::OnNMClickListAwati)
  41. ON_BN_CLICKED(IDC_ADD_DEP, &Personnel::OnBnClickedAddDep)
  42. ON_BN_CLICKED(IDC_PER_DELETE, &Personnel::OnBnClickedPerDelete)
  43. ON_BN_CLICKED(IDC_ENTRY, &Personnel::OnBnClickedEntry)
  44. ON_BN_CLICKED(IDC_ADD_POST, &Personnel::OnBnClickedAddPost)
  45. ON_BN_CLICKED(IDC_DIMISSION, &Personnel::OnBnClickedDimission)
  46. ON_WM_TIMER()
  47. END_MESSAGE_MAP()
  48. BOOL Personnel::OnInitDialog()
  49. {
  50. CDialogEx::OnInitDialog();
  51. // TODO: 在此添加额外的初始化
  52. InitListDeparment();
  53. LoadDepartement();
  54. InitListAwati();
  55. LoadAwatiForReview();
  56. InitList3Staff();
  57. LoadSaff();
  58. InitListPost();
  59. LoadPost();
  60. SetTimer(1, 120000, NULL);
  61. return TRUE; // return TRUE unless you set the focus to a control
  62. // 异常: OCX 属性页应返回 FALSE
  63. }
  64. // Personnel 消息处理程序
  65. void Personnel::InitListDeparment()
  66. {
  67. // TODO: 在此处添加实现代码.
  68. ListDeparment.SetExtendedStyle(LVS_EX_FULLROWSELECT | LVS_EX_GRIDLINES);
  69. ListDeparment.InsertColumn(0, _T("部门ID"), LVCFMT_LEFT, 70);
  70. ListDeparment.InsertColumn(1, _T("部门名称"), LVCFMT_LEFT, 90);
  71. }
  72. void Personnel::InitList3Staff()
  73. {
  74. ListStaff.SetExtendedStyle(LVS_EX_FULLROWSELECT | LVS_EX_GRIDLINES| WS_CHILD | WS_VISIBLE | WS_BORDER | LVS_REPORT | LVS_EDITLABELS);
  75. //ListStaff.InsertColumn(0, _T("员工ID"), LVCFMT_LEFT, 60);
  76. ListStaff.InsertColumn(0, _T("员工姓名"), LVCFMT_LEFT, 100);
  77. ListStaff.InsertColumn(1, _T("员工电话"), LVCFMT_LEFT, 150);
  78. ListStaff.InsertColumn(2, _T("部门"), LVCFMT_LEFT, 105);
  79. ListStaff.InsertColumn(3, _T("职务"), LVCFMT_LEFT, 105);
  80. }
  81. void Personnel::InitListPost()
  82. {
  83. ListPost.SetExtendedStyle(LVS_EX_FULLROWSELECT | LVS_EX_GRIDLINES);
  84. ListPost.InsertColumn(0, _T("职务ID"), LVCFMT_LEFT, 70);
  85. ListPost.InsertColumn(1, _T("职务名称"), LVCFMT_LEFT, 90);
  86. }
  87. void Personnel::InitListAwati()
  88. {
  89. // TODO: 在此处添加实现代码.
  90. ListAwati.SetExtendedStyle(LVS_EX_FULLROWSELECT | LVS_EX_GRIDLINES);
  91. ListAwati.InsertColumn(0, _T("待审核人姓名"), LVCFMT_LEFT, 130);
  92. ListAwati.InsertColumn(1, _T("待审核人电话"), LVCFMT_LEFT, 160);
  93. }
  94. void Personnel::LoadAwatiForReview()
  95. {
  96. ListAwati.DeleteAllItems();
  97. char* strSql = "SELECT name,phone FROM tb_wait_for_review;";
  98. if (!theApp.sql->ExecutiveCommand(strSql))
  99. {
  100. int i = 0;
  101. MYSQL_RES* res = theApp.sql->GetResultSet();
  102. while (theApp.sql->row = mysql_fetch_row(res))
  103. {
  104. CString str,str2;
  105. str = theApp.MyAtoT(theApp.sql->row[0]);
  106. str2 = theApp.MyAtoT(theApp.sql->row[1]);
  107. ListAwati.InsertItem(i, str);
  108. ListAwati.SetItemText(i, 1, str2);
  109. i++;
  110. }
  111. }
  112. else
  113. {
  114. AfxMessageBox(theApp.MyAtoT(theApp.sql->GetErrorInformation()), MB_OK | MB_ICONERROR);
  115. }
  116. return;
  117. }
  118. void Personnel::LoadDepartement()
  119. {
  120. //"INSERT INTO tb_department (department_id,department_name)VALUES (%d,'%s')", depID, depName);
  121. ListDeparment.DeleteAllItems();
  122. DepName.ResetContent();
  123. char* strSql = "SELECT department_id,department_name FROM tb_department;";
  124. if (!theApp.sql->ExecutiveCommand(strSql))
  125. {
  126. int i = 0;
  127. MYSQL_RES* res = theApp.sql->GetResultSet();
  128. while (theApp.sql->row = mysql_fetch_row(res))
  129. {
  130. CString str, str2;
  131. str = theApp.MyAtoT(theApp.sql->row[0]);
  132. str2 = theApp.MyAtoT(theApp.sql->row[1]);
  133. ListDeparment.InsertItem(i, str);
  134. ListDeparment.SetItemText(i, 1, str2);
  135. DepName.AddString(str2);
  136. i++;
  137. }
  138. }
  139. else
  140. {
  141. AfxMessageBox(theApp.MyAtoT(theApp.sql->GetErrorInformation()), MB_OK | MB_ICONERROR);
  142. }
  143. return;
  144. }
  145. void Personnel::LoadPost()
  146. {
  147. ListPost.DeleteAllItems();
  148. PostName.ResetContent();
  149. char* strSql = "SELECT post_id,post_name FROM tb_post;";
  150. //char* strSql = "SELECT department_id,department_name FROM tb_department;";
  151. if (!theApp.sql->ExecutiveCommand(strSql))
  152. {
  153. int i = 0;
  154. MYSQL_RES* res = theApp.sql->GetResultSet();
  155. while (theApp.sql->row = mysql_fetch_row(res))
  156. {
  157. CString str, str2;
  158. str = theApp.MyAtoT(theApp.sql->row[0]);
  159. str2 = theApp.MyAtoT(theApp.sql->row[1]);
  160. ListPost.InsertItem(i, str);
  161. ListPost.SetItemText(i, 1, str2);
  162. PostName.AddString(str2);
  163. i++;
  164. }
  165. }
  166. else
  167. {
  168. AfxMessageBox(theApp.MyAtoT(theApp.sql->GetErrorInformation()), MB_OK | MB_ICONERROR);
  169. }
  170. return;
  171. }
  172. void Personnel::LoadSaff()
  173. {
  174. ListStaff.DeleteAllItems();
  175. int i = 0;
  176. //char deparment[STR_NUM], post[STR_NUM];
  177. CString Phone, Name, Department, Post;
  178. char order[STR_NUM];
  179. sprintf_s(order, STR_NUM - 1, "SELECT tb_staff.name,tb_staff.phone,tb_department.department_name,tb_post.post_name FROM tb_staff INNER JOIN tb_department INNER JOIN tb_post ON tb_staff.department_id =tb_department.department_id AND tb_staff.post_id=tb_post.post_id;");
  180. if (!theApp.sql->ExecutiveCommand(order))
  181. {
  182. MYSQL_RES* res = theApp.sql->GetResultSet();
  183. while (theApp.sql->row = mysql_fetch_row(res))
  184. {
  185. Phone = theApp.MyAtoT(theApp.sql->row[0]);
  186. Name = theApp.MyAtoT(theApp.sql->row[1]);
  187. Department = theApp.MyAtoT(theApp.sql->row[2]);
  188. Post = theApp.MyAtoT(theApp.sql->row[3]);
  189. ListStaff.InsertItem(i, Phone);
  190. ListStaff.SetItemText(i, 1, Name);
  191. ListStaff.SetItemText(i, 2, Department);
  192. ListStaff.SetItemText(i, 3, Post);
  193. i++;
  194. }
  195. }
  196. else
  197. {
  198. AfxMessageBox(theApp.MyAtoT(theApp.sql->GetErrorInformation()), MB_OK | MB_ICONERROR);
  199. }
  200. return;
  201. }
  202. void Personnel::OnNMClickListAwati(NMHDR* pNMHDR, LRESULT* pResult)
  203. {
  204. LPNMITEMACTIVATE pNMItemActivate = reinterpret_cast<LPNMITEMACTIVATE>(pNMHDR);
  205. // TODO: 在此添加控件通知处理程序代码
  206. POSITION pos = ListAwati.GetFirstSelectedItemPosition();
  207. int i = ListAwati.GetNextSelectedItem(pos);
  208. CString str,str2;
  209. str = ListAwati.GetItemText(i, 0);
  210. str2 = ListAwati.GetItemText(i, 1);
  211. SetDlgItemText(IDC_PER_NAME,str);
  212. SetDlgItemText(IDC_PER_PHONE, str2);
  213. *pResult = 0;
  214. }
  215. void Personnel::OnBnClickedAddDep()
  216. {
  217. // TODO: 在此添加控件通知处理程序代码
  218. AddDep adddep;
  219. if(adddep.DoModal()==IDOK)
  220. {
  221. LoadDepartement();
  222. }
  223. }
  224. void Personnel::OnBnClickedPerDelete()
  225. {
  226. // TODO: 在此添加控件通知处理程序代码
  227. CString name, phone, str;
  228. char order[STR_NUM], * str1, * str2;
  229. GetDlgItemText(IDC_PER_NAME, name);
  230. GetDlgItemText(IDC_PER_PHONE, phone);
  231. str.Format(_T("确认删除待入职人员:%s 吗?"), name);
  232. str1 = CZGKJApp::MyTtoA(name);
  233. str2 = CZGKJApp::MyTtoA(phone);
  234. sprintf_s(order, STR_NUM - 1, "DELETE FROM tb_wait_for_review WHERE name = '%s' AND phone = '%s' ", str1, str2);
  235. if (AfxMessageBox(str, MB_YESNO) == IDNO)
  236. {
  237. return;
  238. }
  239. else if (!theApp.sql->ExecutiveCommand(order))
  240. {
  241. str.Format(_T("%s 已删除成功!"), name);
  242. AfxMessageBox(str);
  243. LoadAwatiForReview();
  244. return;
  245. }
  246. else
  247. {
  248. AfxMessageBox(theApp.MyAtoT(theApp.sql->GetErrorInformation()), MB_OK | MB_ICONERROR);
  249. }
  250. }
  251. void Personnel::OnBnClickedEntry()
  252. {
  253. UpdateData(TRUE);
  254. if (depName.IsEmpty() || postName.IsEmpty())
  255. {
  256. AfxMessageBox(_T("必须指定待入职人员部门和职务!"));
  257. return;
  258. }
  259. char pass[STR_NUM];
  260. char key[STR_NUM];
  261. char order[STR_NUM];
  262. int key1;
  263. int depID;
  264. int postID;
  265. char* phone = CZGKJApp::MyTtoA(awatiPhone);
  266. char* name = CZGKJApp::MyTtoA(awatiName);
  267. sprintf_s(order, STR_NUM - 1, "SELECT pass, secret_key FROM tb_wait_for_review WHERE phone = '%s'", phone);
  268. if (!theApp.sql->ExecutiveCommand(order))
  269. {
  270. //if(theApp.sql.)
  271. MYSQL_RES* res = theApp.sql->GetResultSet();
  272. if (res->row_count == 0)
  273. {
  274. AfxMessageBox(_T("无此用户注册信息!"));
  275. return;
  276. }
  277. theApp.sql->row = mysql_fetch_row(res);
  278. strcpy_s(pass, STR_NUM, theApp.sql->row[0]);
  279. strcpy_s(key, STR_NUM, theApp.sql->row[1]);
  280. key1 = atoi(key);
  281. }
  282. else
  283. {
  284. AfxMessageBox(theApp.MyAtoT(theApp.sql->GetErrorInformation()));
  285. return;
  286. }
  287. sprintf_s(order, STR_NUM, "SELECT department_id FROM tb_department WHERE department_name = '%s';",CZGKJApp::MyTtoA(depName));
  288. if (!theApp.sql->ExecutiveCommand(order))
  289. {
  290. MYSQL_RES* res = theApp.sql->GetResultSet();
  291. theApp.sql->row = mysql_fetch_row(res);
  292. depID = atoi(theApp.sql->row[0]);
  293. }
  294. else
  295. {
  296. AfxMessageBox(theApp.MyAtoT(theApp.sql->GetErrorInformation()), MB_OK | MB_ICONERROR);
  297. return;
  298. }
  299. sprintf_s(order, STR_NUM, "SELECT post_id FROM tb_post WHERE post_name = '%s';", CZGKJApp::MyTtoA(postName));
  300. if (!theApp.sql->ExecutiveCommand(order))
  301. {
  302. MYSQL_RES* res = theApp.sql->GetResultSet();
  303. theApp.sql->row = mysql_fetch_row(res);
  304. postID = atoi(theApp.sql->row[0]);
  305. }
  306. else
  307. {
  308. AfxMessageBox(theApp.MyAtoT(theApp.sql->GetErrorInformation()));
  309. return;
  310. }
  311. sprintf_s(order, STR_NUM, "INSERT INTO tb_staff (phone,name,department_id,password,secret_key,post_id)VALUES ('%s','%s',%d,'%s',%d,%d)",phone, name, depID, pass, key1,postID);
  312. if (!theApp.sql->ExecutiveCommand(order))
  313. {
  314. sprintf_s(order, STR_NUM - 1, "DELETE FROM tb_wait_for_review WHERE name = '%s' AND phone = '%s' ", name, phone);
  315. theApp.sql->ExecutiveCommand(order);
  316. AfxMessageBox(awatiName + _T("入职成功!"));
  317. LoadAwatiForReview();
  318. LoadSaff();
  319. }
  320. else
  321. {
  322. AfxMessageBox(theApp.MyAtoT(theApp.sql->GetErrorInformation()), MB_OK | MB_ICONERROR);
  323. return;
  324. }
  325. SetDlgItemText(IDC_PER_NAME,_T(""));
  326. SetDlgItemText(IDC_PER_PHONE, _T(""));
  327. SetDlgItemText(IDC_COMBO_DEP, _T(""));
  328. SetDlgItemText(IDC_COMBO2_POST, _T(""));
  329. return;
  330. }
  331. void Personnel::OnBnClickedAddPost()
  332. {
  333. // TODO: 在此添加控件通知处理程序代码
  334. AddPost addPost;
  335. if(addPost.DoModal()==IDOK)
  336. {
  337. LoadPost();
  338. }
  339. }
  340. void Personnel::OnBnClickedDimission()
  341. {
  342. // TODO: 在此添加控件通知处理程序代码
  343. CString phone, name,str;
  344. int i = ListStaff.GetSelectionMark();
  345. if (i < 0)
  346. {
  347. AfxMessageBox(_T("请选中要离职的人员"));
  348. return;
  349. }
  350. name = ListStaff.GetItemText(i, 0);
  351. phone = ListStaff.GetItemText(i, 1);
  352. str.Format(_T("请确认 %s 离职手续已办理完毕!"), name);
  353. ;
  354. if (AfxMessageBox(str, MB_YESNO) == IDNO)
  355. {
  356. return;
  357. }
  358. char order[STR_NUM];
  359. sprintf_s(order, STR_NUM, "DELETE FROM tb_staff WHERE phone = '%s'", CZGKJApp::MyTtoA(phone));
  360. if (theApp.sql->ExecutiveCommand(order))
  361. {
  362. AfxMessageBox(theApp.MyAtoT(theApp.sql->GetErrorInformation()), MB_OK | MB_ICONERROR);
  363. }
  364. LoadSaff();
  365. return;
  366. }
  367. void Personnel::OnTimer(UINT_PTR nIDEvent)
  368. {
  369. // TODO: 在此添加消息处理程序代码和/或调用默认值
  370. char order[STR_NUM] = "SELECT 1";
  371. if (nIDEvent == 1)
  372. {
  373. if (theApp.sql->ExecutiveCommand(order))
  374. {
  375. AfxMessageBox(theApp.MyAtoT(theApp.sql->GetErrorInformation()), MB_OK | MB_ICONERROR);
  376. }
  377. MYSQL_RES* res = theApp.sql->GetResultSet();
  378. }
  379. CDialogEx::OnTimer(nIDEvent);
  380. }