ZGKJDlg.cpp 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200
  1. 
  2. // ZGKJDlg.cpp: 实现文件
  3. //
  4. #include "pch.h"
  5. #include "framework.h"
  6. #include "ZGKJ.h"
  7. #include "ZGKJDlg.h"
  8. #include "afxdialogex.h"
  9. #include "RegisterDlg.h"
  10. #include "SupportStaff.h"
  11. #ifdef _DEBUG
  12. #define new DEBUG_NEW
  13. #endif
  14. // CZGKJDlg 对话框
  15. CZGKJDlg::CZGKJDlg(CWnd* pParent /*=nullptr*/)
  16. : CDialogEx(IDD_ZGKJ_DIALOG, pParent)
  17. , Port(_T(""))
  18. , Password(_T(""))
  19. , Phone(_T(""))
  20. {
  21. m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
  22. }
  23. void CZGKJDlg::DoDataExchange(CDataExchange* pDX)
  24. {
  25. CDialogEx::DoDataExchange(pDX);
  26. DDX_Text(pDX, IDC_PORT, Port);
  27. DDX_Text(pDX, IDC_PORT, Port);
  28. DDX_Text(pDX, IDC_USER_PASSWORD, Password);
  29. DDX_Text(pDX, IDC_USER_ID, Phone);
  30. }
  31. BEGIN_MESSAGE_MAP(CZGKJDlg, CDialogEx)
  32. ON_WM_PAINT()
  33. ON_WM_QUERYDRAGICON()
  34. ON_BN_CLICKED(IDC_REGISTER, &CZGKJDlg::OnBnClickedRegister)
  35. ON_BN_CLICKED(IDC_LINK, &CZGKJDlg::OnBnClickedLink)
  36. ON_BN_CLICKED(IDC_LOGIN, &CZGKJDlg::OnBnClickedLogin)
  37. END_MESSAGE_MAP()
  38. // CZGKJDlg 消息处理程序
  39. BOOL CZGKJDlg::OnInitDialog()
  40. {
  41. CDialogEx::OnInitDialog();
  42. // 设置此对话框的图标。 当应用程序主窗口不是对话框时,框架将自动
  43. // 执行此操作
  44. SetIcon(m_hIcon, TRUE); // 设置大图标
  45. SetIcon(m_hIcon, FALSE); // 设置小图标
  46. // TODO: 在此添加额外的初始化代码
  47. GetDlgItem(IDC_LOGIN)->EnableWindow(FALSE);
  48. GetDlgItem(IDC_REGISTER)->EnableWindow(FALSE);
  49. GetDlgItem(IDC_IPADDRESS1)->SetWindowText(_T("118.24.178.150"));
  50. GetDlgItem(IDC_PORT)->SetWindowText(_T("3306"));
  51. return TRUE; // 除非将焦点设置到控件,否则返回 TRUE
  52. }
  53. // 如果向对话框添加最小化按钮,则需要下面的代码
  54. // 来绘制该图标。 对于使用文档/视图模型的 MFC 应用程序,
  55. // 这将由框架自动完成。
  56. void CZGKJDlg::OnPaint()
  57. {
  58. if (IsIconic())
  59. {
  60. CPaintDC dc(this); // 用于绘制的设备上下文
  61. SendMessage(WM_ICONERASEBKGND, reinterpret_cast<WPARAM>(dc.GetSafeHdc()), 0);
  62. // 使图标在工作区矩形中居中
  63. int cxIcon = GetSystemMetrics(SM_CXICON);
  64. int cyIcon = GetSystemMetrics(SM_CYICON);
  65. CRect rect;
  66. GetClientRect(&rect);
  67. int x = (rect.Width() - cxIcon + 1) / 2;
  68. int y = (rect.Height() - cyIcon + 1) / 2;
  69. // 绘制图标
  70. dc.DrawIcon(x, y, m_hIcon);
  71. }
  72. else
  73. {
  74. CDialogEx::OnPaint();
  75. }
  76. }
  77. //当用户拖动最小化窗口时系统调用此函数取得光标
  78. //显示。
  79. HCURSOR CZGKJDlg::OnQueryDragIcon()
  80. {
  81. return static_cast<HCURSOR>(m_hIcon);
  82. }
  83. CString CZGKJDlg::Decode(char* pass, int secretkey)
  84. {
  85. //CString pass2;
  86. int a = strlen(pass);
  87. for (int i = 0; i < strlen(pass); i++)
  88. {
  89. pass[i] ^= secretkey;
  90. }
  91. pass[a] = '\0';
  92. //pass2.Format(_T("%s"), pass);
  93. return CString(pass);
  94. }
  95. void CZGKJDlg::OnBnClickedRegister()
  96. {
  97. // TODO: 在此添加控件通知处理程序代码
  98. RegisterDlg regDlg;
  99. regDlg.DoModal();
  100. return;
  101. }
  102. void CZGKJDlg::OnBnClickedLink()
  103. {
  104. // TODO: 在此添加控件通知处理程序代码
  105. GetDlgItem(IDC_IPADDRESS1)->GetWindowText(IPAddress);
  106. GetDlgItemText(IDC_PORT, Port);
  107. DBINFO DatabasesInfo;
  108. DatabasesInfo.server_address = CZGKJApp::MyTtoA(IPAddress);
  109. DatabasesInfo.server_port = CZGKJApp::MyTtoI(Port);
  110. DatabasesInfo.database_name = "zgkj";
  111. DatabasesInfo.user_name = "htl";
  112. DatabasesInfo.password = "fl961511";
  113. theApp.sql = HtlMysql::GetInstance();
  114. if (!theApp.sql->Connect(DatabasesInfo))
  115. {
  116. const char* e = theApp.sql->GetErrorInformation();
  117. CString error = CZGKJApp::MyAtoT(e);
  118. AfxMessageBox(error, MB_OK | MB_ICONERROR);
  119. return;
  120. }
  121. GetDlgItem(IDC_LOGIN)->EnableWindow(TRUE);
  122. GetDlgItem(IDC_REGISTER)->EnableWindow(TRUE);
  123. return;
  124. }
  125. void CZGKJDlg::OnBnClickedLogin()
  126. {
  127. // TODO: 在此添加控件通知处理程序代码
  128. UpdateData(TRUE);
  129. CString str;
  130. CString sqlPass;
  131. const char* phone = CZGKJApp::MyTtoA(Phone);
  132. char order[STR_NUM];
  133. sprintf_s(order, STR_NUM, "SELECT phone,password,secret_key,department_id FROM tb_staff WHERE phone='%s' ", phone);
  134. if (!theApp.sql->ExecutiveCommand(order))
  135. {
  136. MYSQL_RES* res = theApp.sql->GetResultSet();
  137. if (res->row_count == 0)
  138. {
  139. AfxMessageBox(_T("请核对账号和密码!"));
  140. return;
  141. }
  142. char* tempPhone;
  143. char* tempPass;
  144. int tempSecretKey;
  145. theApp.sql->row = mysql_fetch_row(res);
  146. tempPhone = theApp.sql->row[0];
  147. tempPass = theApp.sql->row[1];
  148. tempSecretKey = atoi(theApp.sql->row[2]);
  149. theApp.Department_ID = atoi(theApp.sql->row[3]);
  150. theApp.Phone = theApp.MyAtoT(tempPhone);
  151. sqlPass = Decode(tempPass, tempSecretKey);
  152. if (!(Phone == CZGKJApp::MyAtoT(tempPhone) && Password == sqlPass))
  153. {
  154. AfxMessageBox(_T("请核对账号和密码!"));
  155. return;
  156. }
  157. }
  158. else
  159. {
  160. AfxMessageBox(theApp.MyAtoT(theApp.sql->GetErrorInformation()), MB_OK | MB_ICONERROR);
  161. return;
  162. }
  163. EndDialog(IDC_LOGIN);
  164. }