Account.cpp 14 KB

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