Account.cpp 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540
  1. // Account.cpp : implementation file
  2. //
  3. #include "stdafx.h"
  4. #include "ylgl.h"
  5. #include "Account.h"
  6. #include "MyMdi.H"
  7. #include "SetLeftBar.h"
  8. #ifdef _DEBUG
  9. #define new DEBUG_NEW
  10. #undef THIS_FILE
  11. static char THIS_FILE[] = __FILE__;
  12. #endif
  13. /////////////////////////////////////////////////////////////////////////////
  14. // Account IDC_EDIT2
  15. IMPLEMENT_DYNCREATE(Account, MyFormView)
  16. Account::Account()
  17. : MyFormView(Account::IDD)
  18. {
  19. //{{AFX_DATA_INIT(Account)
  20. m_account = _T("");
  21. m_psw = _T("");
  22. m_psw2 = _T("");
  23. m_discount = "9.0";
  24. m_bAddNew = 1;
  25. m_discount2 = _T("9.0");
  26. //}}AFX_DATA_INIT
  27. }
  28. Account::~Account()
  29. {
  30. }
  31. void Account::DoDataExchange(CDataExchange* pDX)
  32. {
  33. MyFormView::DoDataExchange(pDX);
  34. //{{AFX_DATA_MAP(Account)
  35. DDX_Control(pDX, IDC_SPIN1, m_spin1);
  36. DDX_Control(pDX, IDC_COMBOname, m_comboname);
  37. DDX_Control(pDX, IDC_LIST2, m_List1);
  38. DDX_Control(pDX, IDC_STATIC1, m_static1);
  39. DDX_Text(pDX, IDC_EDITaccount, m_account);
  40. DDX_Text(pDX, IDC_EDITpsw, m_psw);
  41. DDX_Text(pDX, IDC_EDITpsw2, m_psw2);
  42. DDX_Text(pDX, IDC_EDIT2, m_discount);
  43. DDX_Text(pDX, IDC_EDIT3, m_discount2);
  44. //}}AFX_DATA_MAP
  45. }
  46. BEGIN_MESSAGE_MAP(Account, MyFormView)
  47. //{{AFX_MSG_MAP(Account)
  48. ON_BN_CLICKED(IDC_BUTsave, OnBUTsave)
  49. ON_BN_CLICKED(IDC_BUTdel, OnBUTdel)
  50. ON_BN_CLICKED(IDC_BUTclose, OnBUTclose)
  51. ON_NOTIFY(NM_CLICK, IDC_LIST2, OnClickList2)
  52. ON_BN_CLICKED(IDC_BUTadd, OnBUTadd)
  53. ON_BN_CLICKED(IDC_BUTbm1, OnBUTbm1)
  54. ON_BN_CLICKED(IDC_BUTbm6, OnBUTbm6)
  55. ON_BN_CLICKED(IDC_BUTbm2, OnBUTbm2)
  56. ON_BN_CLICKED(IDC_BUTbm3, OnBUTbm3)
  57. ON_BN_CLICKED(IDC_BUTbm4, OnBUTbm4)
  58. ON_BN_CLICKED(IDC_BUTbm5, OnBUTbm5)
  59. ON_BN_CLICKED(IDC_BUTleftbar, OnBUTleftbar)
  60. ON_BN_CLICKED(IDC_CHECK27, OnCheck27)
  61. //}}AFX_MSG_MAP
  62. END_MESSAGE_MAP()
  63. /////////////////////////////////////////////////////////////////////////////
  64. // Account diagnostics
  65. #ifdef _DEBUG
  66. void Account::AssertValid() const
  67. {
  68. MyFormView::AssertValid();
  69. }
  70. void Account::Dump(CDumpContext& dc) const
  71. {
  72. MyFormView::Dump(dc);
  73. }
  74. #endif //_DEBUG
  75. /////////////////////////////////////////////////////////////////////////////
  76. // Account message handlers
  77. void Account::OnInitialUpdate()
  78. {
  79. //AfxMessageBox("用户管理");
  80. MyFormView::OnInitialUpdate();
  81. // TODO: Add your specialized code here and/or call the base class
  82. CMyMdi Mdi;
  83. Mdi.SetSubView((CWnd*)GetParent(), (CWnd*)this);
  84. #ifdef LKAY_VERSION
  85. GetDlgItem(IDC_CHECK54)->ShowWindow(SW_SHOW);
  86. #endif
  87. #ifdef LYFZ_VERSION
  88. GetDlgItem(IDC_CHECK54)->SetWindowText("明日安排");
  89. GetDlgItem(IDC_CHECK54)->ShowWindow(SW_SHOW);
  90. #endif
  91. #ifdef BASIC_VERSION
  92. GetDlgItem(IDC_BUTleftbar)->ShowWindow(0);
  93. #ifdef BASIC_ADDDRESS
  94. GetDlgItem(IDC_STATIC2)->ShowWindow(1);
  95. GetDlgItem(IDC_CHECK40)->ShowWindow(1);
  96. GetDlgItem(IDC_CHECK41)->ShowWindow(1);
  97. GetDlgItem(IDC_CHECK42)->ShowWindow(1);
  98. GetDlgItem(IDC_CHECK43)->ShowWindow(1);
  99. GetDlgItem(IDC_CHECK44)->ShowWindow(1);
  100. #endif
  101. #endif
  102. #ifdef ENTERPRISE_VERSION
  103. GetDlgItem(IDC_CHECK29)->ShowWindow(1);
  104. #endif
  105. // Here we create the outbar control using the splitter as its parent
  106. // and setting its id to the first pane.
  107. CRect rc2;
  108. GetWindowRect(rc2);
  109. ::MoveWindow(m_hWnd, g_rc.left, g_rc.top, g_rc.Width(), g_rc.Height(), TRUE);
  110. EnumChildWindows(m_hWnd, (WNDENUMPROC)EnumChildProc, 0);
  111. m_comboname.GetWindowRect(rc2);
  112. ScreenToClient(rc2);
  113. rc2.bottom += 200;
  114. m_comboname.MoveWindow(rc2);
  115. m_spin1.SetRange(0, 10);
  116. m_static1.SetFont(&g_titlefont);
  117. m_List1.SetHeadings("账号, 60;姓名, 60;部门,60");
  118. m_List1.LoadColumnInfo(112);
  119. // Jeff初始化,向服务器获取用户信息;
  120. g_sendhead.bsql = 0;
  121. g_sendhead.code[0] = 23;
  122. g_sendhead.tabcount = 1;
  123. g_pMainWnd->ProcessChatMessageRequest2(5);
  124. if (g_bSendOK == 0) return;
  125. DataToArray(&m_List1array);
  126. m_List1arrayBak.SetSize(m_List1array.GetSize());
  127. for (int i = 0; i < m_List1array.GetSize(); i++)
  128. {
  129. m_List1arrayBak.ElementAt(i).Add(m_List1array.ElementAt(i).ElementAt(0)); // Jeff.账号;
  130. m_List1arrayBak.ElementAt(i).Add(m_List1array.ElementAt(i).ElementAt(1)); // Jeff.性名;
  131. m_List1arrayBak.ElementAt(i).Add(m_List1array.ElementAt(i).ElementAt(8)); // Jeff.部门;
  132. }
  133. // Jeff:这里需要做个小处理,不添加已有账号的姓名到下拉框中;
  134. #if 0// OldEdition;
  135. for( i=0; i<g_userarray.GetSize(); i++)
  136. m_comboname.AddString (g_userarray.ElementAt (i).ElementAt (1));
  137. #else
  138. for (i = 0; i < g_userarray.GetSize(); i++)
  139. m_strNameArray.Add(g_userarray.ElementAt(i).ElementAt(1));
  140. for (i = 0; i < m_List1array.GetSize(); i++)
  141. {
  142. for (int j = 0; j < m_strNameArray.GetSize(); j++)
  143. if (m_List1array.ElementAt(i).ElementAt(1) == m_strNameArray.ElementAt(j))
  144. {
  145. m_strNameArray.RemoveAt(j);
  146. }
  147. }
  148. CommboboxReLoad();
  149. #endif
  150. FillGrid();
  151. }
  152. void Account::CommboboxReLoad()
  153. {
  154. m_comboname.ResetContent();
  155. for (int i = 0; i < m_strNameArray.GetSize(); i++)
  156. m_comboname.AddString(m_strNameArray.ElementAt(i));
  157. }
  158. void Account::FillGrid()
  159. {
  160. m_List1.DeleteAllItems2();
  161. int ii = 0;
  162. //m_List1.m_arLabels.SetSize( m_List1arrayBak.GetSize (), 1 ); // Jeff:old
  163. m_List1.m_arLabels.SetSize(m_List1array.GetSize(), 1);
  164. int count = 0;
  165. for (ii = 0; ii < m_List1.m_arLabels.GetSize(); ii++)
  166. {
  167. m_List1.m_arLabels.ElementAt(count++).Copy(m_List1arrayBak.ElementAt(ii));
  168. //m_List1.m_arLabels.ElementAt(count++).Copy(m_List1array.ElementAt(ii));
  169. }
  170. m_List1.m_arLabels.SetSize(count, 1);
  171. ii = count;
  172. m_List1.m_LabelCount = ii;
  173. m_List1.SetItemCountEx(ii);
  174. UpdateData();
  175. //Invalidate();
  176. }
  177. void Account::OnBUTclose()
  178. {
  179. // TODO: Add your control notification handler code here
  180. GetParent()->SendMessage(WM_CLOSE);
  181. }
  182. void Account::ClearCtrl()
  183. {
  184. m_account = _T("");
  185. m_psw = _T("");
  186. m_psw2 = _T("");
  187. m_comboname.SetCurSel(-1);
  188. UpdateData(false);
  189. for (int i = 0; i < 60; i++)
  190. {
  191. ((CButton*)GetDlgItem(IDC_CHECK1 + i))->SetCheck(0);
  192. }
  193. }
  194. void Account::OnClickList2(NMHDR* pNMHDR, LRESULT* pResult)
  195. {
  196. // TODO: Add your control notification handler code here
  197. ListSelChange();
  198. *pResult = 0;
  199. }
  200. void Account::ListSelChange()
  201. {
  202. #if 1 // Jeff 在选择列表时,启用删除按钮;
  203. GetDlgItem(IDC_BUTdel)->EnableWindow();
  204. #endif
  205. POSITION pos;
  206. pos = m_List1.GetFirstSelectedItemPosition();
  207. if (pos == NULL)
  208. {
  209. OnBUTadd();
  210. return;
  211. }
  212. GetDlgItem(IDC_BUTleftbar)->EnableWindow(1);
  213. m_bAddNew = 0;
  214. GetDlgItem(IDC_EDITaccount)->EnableWindow(0);
  215. GetDlgItem(IDC_COMBOname)->EnableWindow(0);
  216. GetDlgItem(IDC_EDITpsw)->EnableWindow(0);
  217. GetDlgItem(IDC_EDITpsw2)->EnableWindow(0);
  218. int iItem = m_List1.GetNextSelectedItem(pos);
  219. CString account = m_List1.GetItemText(iItem, 0);
  220. for (int ii = 0; ii < m_List1array.GetSize(); ii++)
  221. {
  222. if (m_List1array.ElementAt(ii).ElementAt(0) == account)
  223. {
  224. CString name, rights;
  225. m_account = m_List1array.ElementAt(ii).ElementAt(0);
  226. name = m_List1array.ElementAt(ii).ElementAt(1);
  227. m_psw = m_psw2 = m_List1array.ElementAt(ii).ElementAt(2);
  228. rights = m_List1array.ElementAt(ii).ElementAt(3);
  229. m_discount.Format("%0.1f", atof(m_List1array.ElementAt(ii).ElementAt(5)));
  230. m_discount2.Format("%0.1f", atof(m_List1array.ElementAt(ii).ElementAt(6)));
  231. UpdateData(false);
  232. //int nIndex =0 ;
  233. int pos = m_comboname.FindString(0, name);
  234. if (pos != -1)
  235. m_comboname.SetCurSel(pos);
  236. else
  237. {
  238. m_comboname.InsertString(0, name);
  239. m_comboname.SetCurSel(0);
  240. }
  241. SetRights(rights);
  242. return;
  243. }
  244. }
  245. }
  246. void Account::OnBUTadd() // 添加新账号按钮; 添加时禁用删除按钮;
  247. {
  248. // TODO: Add your control notification handler code here
  249. CommboboxReLoad();
  250. m_bAddNew = 1;
  251. GetDlgItem(IDC_EDITaccount)->EnableWindow(1);
  252. GetDlgItem(IDC_COMBOname)->EnableWindow(1);
  253. GetDlgItem(IDC_EDITpsw)->EnableWindow(1);
  254. GetDlgItem(IDC_EDITpsw2)->EnableWindow(1);
  255. ClearCtrl();
  256. GetDlgItem(IDC_BUTleftbar)->EnableWindow(0);
  257. #if 1 // Jeff添加时禁用删除按钮;
  258. GetDlgItem(IDC_BUTdel)->EnableWindow(0);
  259. #endif
  260. }
  261. void Account::OnBUTsave() // 保存按钮;
  262. {
  263. // TODO: Add your control notification handler code here
  264. UpdateData();
  265. CString name;
  266. CString rights = GetRights();
  267. CString sql;
  268. if (m_bAddNew)
  269. {
  270. if (m_account.IsEmpty())
  271. {
  272. AfxMessageBox("资料不全!", MB_ICONINFORMATION); return;
  273. }
  274. int pos = m_comboname.GetCurSel();
  275. if (pos == -1)
  276. {
  277. AfxMessageBox("资料不全!", MB_ICONINFORMATION); return;
  278. }
  279. m_comboname.GetLBText(pos, name);
  280. if (m_psw != m_psw2)
  281. {
  282. AfxMessageBox("密码不一至!", MB_ICONINFORMATION); return;
  283. }
  284. if (IsExist(m_account, name))
  285. {
  286. AfxMessageBox("已有此账号或姓名,请重新输入!", MB_ICONINFORMATION);
  287. return;
  288. }
  289. sql.Format("insert into [user](account,name,psw,rights,discount,discount2) values('%s','%s','%s','%s','%0.1f','%0.1f')", m_account, name, m_psw, rights, atof(m_discount), atof(m_discount2));
  290. sql += USER_REF;
  291. g_sendhead.bsql = 1;
  292. g_pMainWnd->ProcessChatMessageRequest2(sql);
  293. if (g_bSendOK == 0)
  294. return;
  295. #if 1 // Jeff添加成功后,要删除m_strNameArray里的存根;
  296. for (int i(0); i < m_strNameArray.GetSize(); i++)
  297. {
  298. if (name == m_strNameArray.ElementAt(i))
  299. {
  300. //AfxMessageBox("ssssss");
  301. m_strNameArray.RemoveAt(i);
  302. break;
  303. }
  304. }
  305. ClearCtrl();
  306. CommboboxReLoad();
  307. #endif
  308. GetData();
  309. }
  310. else//修改
  311. {
  312. sql.Format("update [user] set [rights]='%s',[discount]='%0.1f',[discount2]='%0.1f' where [account]='%s' ", rights, atof(m_discount), atof(m_discount2), m_account);
  313. sql += USER_REF;
  314. g_sendhead.bsql = 1;
  315. g_pMainWnd->ProcessChatMessageRequest2(sql); if (g_bSendOK == 0)return;
  316. GetData();
  317. }
  318. }
  319. void Account::OnBUTdel() // 删除按钮;
  320. {
  321. // TODO: Add your control notification handler code here
  322. POSITION pos;
  323. pos = m_List1.GetFirstSelectedItemPosition();
  324. if (pos == NULL)
  325. {
  326. return;
  327. }
  328. if (AfxMessageBox("确认删除吗?", MB_YESNO | MB_ICONINFORMATION) != IDYES)return;
  329. int iItem = m_List1.GetNextSelectedItem(pos);
  330. CString account = m_List1.GetItemText(iItem, 0);
  331. if (account == "admin")
  332. {
  333. AfxMessageBox("管理员不能删除");
  334. return;
  335. }
  336. CString sql;
  337. sql.Format("delete from [user] where [account]='%s' ", account);
  338. sql += USER_REF;
  339. g_sendhead.bsql = 1;
  340. g_pMainWnd->ProcessChatMessageRequest2(sql);
  341. if (g_bSendOK == 0)
  342. return;
  343. #if 1 // Jeff 删除时要清空文本框;
  344. CString strName = m_List1.GetItemText(iItem, 1);
  345. //BOOL bNameInArray = FALSE;
  346. ClearCtrl();
  347. //for ( int i(0); i < m_strNameArray.GetSize(); i++)
  348. //{
  349. // if ( name == m_strNameArray.ElementAt(i))
  350. // {
  351. // bNameInArray = TRUE;
  352. // break;
  353. // }
  354. // }
  355. //if ( !bNameInArray )
  356. // {
  357. m_strNameArray.Add(strName);
  358. //}
  359. CommboboxReLoad();
  360. #endif
  361. GetData();
  362. }
  363. void Account::GetData()
  364. {
  365. g_sendhead.bsql = 0;
  366. g_sendhead.code[0] = 23;
  367. g_sendhead.tabcount = 1;
  368. g_pMainWnd->ProcessChatMessageRequest2(23);
  369. DataToArray(&m_List1array);
  370. // Jeff add:在getdata里处理;
  371. m_List1arrayBak.RemoveAll();
  372. m_List1arrayBak.SetSize(m_List1array.GetSize());
  373. for (int i = 0; i < m_List1array.GetSize(); i++)
  374. {
  375. m_List1arrayBak.ElementAt(i).Add(m_List1array.ElementAt(i).ElementAt(0));
  376. m_List1arrayBak.ElementAt(i).Add(m_List1array.ElementAt(i).ElementAt(1));
  377. m_List1arrayBak.ElementAt(i).Add(m_List1array.ElementAt(i).ElementAt(8));
  378. }
  379. //
  380. FillGrid();
  381. }
  382. BOOL Account::IsExist(CString account, CString name)
  383. {
  384. for (int i = 0; i < m_List1array.GetSize(); i++)
  385. {
  386. if (account == m_List1array.ElementAt(i).ElementAt(0))return 1;
  387. if (name == m_List1array.ElementAt(i).ElementAt(1))return 1;
  388. }
  389. return 0;
  390. }
  391. CString Account::GetRights()//50
  392. {
  393. CString ret, temp;
  394. for (int i = 0; i < 60; i++)
  395. {
  396. temp.Format("%d", ((CButton*)GetDlgItem(IDC_CHECK1 + i))->GetCheck());
  397. ret += temp;
  398. }
  399. return ret;
  400. }
  401. void Account::SetRights(CString rights)
  402. {
  403. for (int i = 0; i < rights.GetLength(); i++)
  404. {
  405. if (i >= 60)break;
  406. ((CButton*)GetDlgItem(IDC_CHECK1 + i))->SetCheck(rights.GetAt(i) == '1');
  407. }
  408. for (i = rights.GetLength(); i < 60; i++)
  409. {
  410. ((CButton*)GetDlgItem(IDC_CHECK1 + i))->SetCheck(0);
  411. }
  412. }
  413. void Account::OnBUTbm6()
  414. {
  415. // TODO: Add your control notification handler code here
  416. POSITION pos;
  417. pos = m_List1.GetFirstSelectedItemPosition();
  418. if (pos)
  419. {
  420. int iItem = m_List1.GetNextSelectedItem(pos);
  421. CString account = m_List1.GetItemText(iItem, 0);
  422. if (account == "admin")
  423. {
  424. SetRights("000000000000000000000000000000000000000000000000010000000000");
  425. return;
  426. }
  427. }
  428. SetRights("000000000000000000000000000000000000000000000000000000000000");
  429. }
  430. void Account::OnBUTbm1()
  431. {
  432. // TODO: Add your control notification handler code here
  433. ((CButton*)GetDlgItem(IDC_CHECK1 + 0))->SetCheck(1);
  434. ((CButton*)GetDlgItem(IDC_CHECK1 + 15))->SetCheck(1);
  435. }
  436. void Account::OnBUTbm2()
  437. {
  438. // TODO: Add your control notification handler code here
  439. ((CButton*)GetDlgItem(IDC_CHECK1 + 4))->SetCheck(1);
  440. ((CButton*)GetDlgItem(IDC_CHECK1 + 5))->SetCheck(1);
  441. ((CButton*)GetDlgItem(IDC_CHECK1 + 8))->SetCheck(1);
  442. ((CButton*)GetDlgItem(IDC_CHECK1 + 15))->SetCheck(1);
  443. }
  444. void Account::OnBUTbm3()
  445. {
  446. // TODO: Add your control notification handler code here
  447. ((CButton*)GetDlgItem(IDC_CHECK1 + 5))->SetCheck(1);
  448. ((CButton*)GetDlgItem(IDC_CHECK1 + 6))->SetCheck(1);
  449. ((CButton*)GetDlgItem(IDC_CHECK1 + 7))->SetCheck(1);
  450. ((CButton*)GetDlgItem(IDC_CHECK1 + 8))->SetCheck(1);
  451. ((CButton*)GetDlgItem(IDC_CHECK1 + 9))->SetCheck(1);
  452. ((CButton*)GetDlgItem(IDC_CHECK1 + 10))->SetCheck(1);
  453. ((CButton*)GetDlgItem(IDC_CHECK1 + 11))->SetCheck(1);
  454. ((CButton*)GetDlgItem(IDC_CHECK1 + 12))->SetCheck(1);
  455. }
  456. void Account::OnBUTbm4()
  457. {
  458. // TODO: Add your control notification handler code here
  459. ((CButton*)GetDlgItem(IDC_CHECK1 + 16))->SetCheck(1);
  460. ((CButton*)GetDlgItem(IDC_CHECK1 + 17))->SetCheck(1);
  461. ((CButton*)GetDlgItem(IDC_CHECK1 + 18))->SetCheck(1);
  462. ((CButton*)GetDlgItem(IDC_CHECK1 + 19))->SetCheck(1);
  463. ((CButton*)GetDlgItem(IDC_CHECK1 + 20))->SetCheck(1);
  464. ((CButton*)GetDlgItem(IDC_CHECK1 + 21))->SetCheck(1);
  465. ((CButton*)GetDlgItem(IDC_CHECK1 + 22))->SetCheck(1);
  466. }
  467. void Account::OnBUTbm5()
  468. {
  469. // TODO: Add your control notification handler code here
  470. SetRights("111111111111111111111111111111111111111111111111111111111111");
  471. }
  472. void Account::OnBUTleftbar() // 界面设置
  473. {
  474. // TODO: Add your control notification handler code here
  475. SetLeftBar dlg;
  476. dlg.m_account = m_account;
  477. dlg.DoModal();
  478. }
  479. void Account::OnCheck27()
  480. {
  481. // TODO: Add your control notification handler code here
  482. // if(((CButton*)GetDlgItem(IDC_CHECK27))->GetCheck())
  483. // {
  484. // }
  485. }