DlgConfig.cpp 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255
  1. // DlgConfig.cpp : 实现文件
  2. //
  3. #include "stdafx.h"
  4. #include "lyfzAttendance.h"
  5. #include "DlgConfig.h"
  6. // CDlgConfig 对话框
  7. IMPLEMENT_DYNAMIC(CDlgConfig, CDialog)
  8. CDlgConfig::CDlgConfig(CWnd* pParent /*=NULL*/)
  9. : CDialog(CDlgConfig::IDD, pParent)
  10. , m_radio(0)
  11. , m_strDBService(_T(""))
  12. , m_dwDBServicePort(0)
  13. , m_strDBAccount(_T(""))
  14. , m_strDBPassword(_T(""))
  15. , m_strDBName(_T(""))
  16. , m_lMachineNumber(0)
  17. , m_strMachineIP(_T(""))
  18. , m_nMachinePort(0)
  19. , m_nMachinePassword(0)
  20. , m_nMachineTimeout(0)
  21. , m_nProtocolType(0)
  22. , m_lpCfg(NULL)
  23. {
  24. }
  25. CDlgConfig::~CDlgConfig()
  26. {
  27. m_lpCfg = NULL;
  28. }
  29. void CDlgConfig::DoDataExchange(CDataExchange* pDX)
  30. {
  31. CDialog::DoDataExchange(pDX);
  32. DDX_Text(pDX, IDC_DBService, m_strDBService);
  33. DDX_Text(pDX, IDC_DBServicePort, m_dwDBServicePort);
  34. DDX_Text(pDX, IDC_DBAccount, m_strDBAccount);
  35. DDX_Text(pDX, IDC_DBPassword, m_strDBPassword);
  36. DDX_Text(pDX, IDC_DBName, m_strDBName);
  37. DDX_Text(pDX, IDC_ManchineNo, m_lMachineNumber);
  38. DDX_Text(pDX, IDC_ManchineIP, m_strMachineIP);
  39. DDX_Text(pDX, IDC_ManchinePort, m_nMachinePort);
  40. DDX_Text(pDX, IDC_ManchinePassword, m_nMachinePassword);
  41. DDX_Text(pDX, IDC_ManchineTimeout, m_nMachineTimeout);
  42. DDX_Control(pDX, IDC_MACHINETYPE_COMBO, m_TypeCombox);
  43. }
  44. BEGIN_MESSAGE_MAP(CDlgConfig, CDialog)
  45. ON_BN_CLICKED(IDOK, &CDlgConfig::OnBnClickedOk)
  46. ON_BN_CLICKED(IDCANCEL, &CDlgConfig::OnBnClickedCancel)
  47. ON_BN_CLICKED(IDC_Radio_USB, &CDlgConfig::OnBnClickedRadioUsb)
  48. ON_BN_CLICKED(IDC_Radio_Net, &CDlgConfig::OnBnClickedRadioNet)
  49. ON_BN_CLICKED(IDC_CHECKUDP, &CDlgConfig::OnBnClickedCheckudp)
  50. END_MESSAGE_MAP()
  51. BOOL CDlgConfig::OnInitDialog()
  52. {
  53. CDialog::OnInitDialog();
  54. // TODO: 在此添加额外的初始化
  55. if(m_lpCfg == NULL)
  56. return FALSE;
  57. m_TypeCombox.AddString(_T("奥芯U200"));
  58. m_TypeCombox.AddString(_T("鑫澳康FK6xx"));
  59. m_strDBService.Format(_T("%s"),g_szDBServer);
  60. m_dwDBServicePort = g_dwDBServerPort;
  61. m_strDBAccount.Format(_T("%s"), g_szDBAccount);
  62. m_strDBPassword.Format(_T("%s"), g_szDBPassWord);
  63. m_strDBName.Format(_T("%s"), g_szDBName);
  64. m_lMachineNumber = m_lpCfg->lMachineNumber;
  65. m_strMachineIP.Format(_T("%s"), m_lpCfg->szIpAddress);
  66. m_nMachinePort = m_lpCfg->lPort;
  67. m_nMachinePassword = m_lpCfg->lNetPassword;
  68. m_nMachineTimeout = m_lpCfg->lTimeOut;
  69. m_nProtocolType = m_lpCfg->lProtocolType;
  70. int nMachineType = m_lpCfg->nMachineType;
  71. m_TypeCombox.SetCurSel(nMachineType);
  72. if ( m_nProtocolType == 0 )//TCP
  73. ((CButton*)GetDlgItem(IDC_CHECKUDP))->SetCheck(FALSE);
  74. else
  75. ((CButton*)GetDlgItem(IDC_CHECKUDP))->SetCheck(TRUE);
  76. if ( m_lpCfg->nType == TYPE_USB)
  77. {
  78. m_radio = 0;
  79. // 禁用网络设置;
  80. ((CButton*)GetDlgItem(IDC_Radio_USB))->SetCheck(TRUE);
  81. ((CButton*)GetDlgItem(IDC_Radio_Net))->SetCheck(FALSE);
  82. GetDlgItem(IDC_CHECKUDP)->EnableWindow(FALSE);
  83. GetDlgItem(IDC_ManchineIP)->EnableWindow(FALSE);
  84. GetDlgItem(IDC_ManchinePassword)->EnableWindow(FALSE);
  85. GetDlgItem(IDC_ManchinePort)->EnableWindow(FALSE);
  86. GetDlgItem(IDC_ManchineTimeout)->EnableWindow(FALSE);
  87. }
  88. else
  89. {
  90. m_radio = 1;
  91. ((CButton*)GetDlgItem(IDC_Radio_USB))->SetCheck(FALSE);
  92. ((CButton*)GetDlgItem(IDC_Radio_Net))->SetCheck(TRUE);
  93. GetDlgItem(IDC_CHECKUDP)->EnableWindow(TRUE);
  94. GetDlgItem(IDC_ManchineIP)->EnableWindow(TRUE);
  95. GetDlgItem(IDC_ManchinePassword)->EnableWindow(TRUE);
  96. GetDlgItem(IDC_ManchinePort)->EnableWindow(TRUE);
  97. GetDlgItem(IDC_ManchineTimeout)->EnableWindow(TRUE);
  98. }
  99. UpdateData(0);
  100. return TRUE; // return TRUE unless you set the focus to a control
  101. }
  102. // CDlgConfig 消息处理程序
  103. void CDlgConfig::OnBnClickedOk()
  104. {
  105. // TODO: 在此添加控件通知处理程序代码
  106. UpdateData();
  107. // 1.
  108. wsprintf(g_szDBServer, _T("%s"), m_strDBService);
  109. wsprintf(g_szDBAccount, _T("%s"), m_strDBAccount);
  110. wsprintf(g_szDBPassWord, _T("%s"), m_strDBPassword);
  111. wsprintf(g_szDBName, _T("%s"), m_strDBName);
  112. g_dwDBServerPort = m_dwDBServicePort;
  113. // 2.
  114. m_lpCfg->lPort = m_nMachinePort;
  115. m_lpCfg->lTimeOut = m_nMachineTimeout;
  116. m_lpCfg->lNetPassword = m_nMachinePassword;
  117. m_lpCfg->lMachineNumber = m_lMachineNumber;
  118. wcscpy(m_lpCfg->szIpAddress, CT2CW(m_strMachineIP));
  119. m_lpCfg->nMachineType = m_TypeCombox.GetCurSel();
  120. switch(m_lpCfg->nMachineType)
  121. {
  122. case 0:
  123. m_lpCfg->lLicense = 0;
  124. break;
  125. case 1:
  126. m_lpCfg->lLicense = g_lLicense;
  127. }
  128. //--------------------------------------
  129. // 3.
  130. WCHAR szFile[MAX_PATH + 1] = {0};
  131. // 1.
  132. CString str;
  133. wsprintf(szFile, _T("%s\\lyfzServiceInfo.ini"),g_ModulePath);
  134. WritePrivateProfileString(_T("ServerInfo"), _T("dbServer"), g_szDBServer, szFile);
  135. if ( g_dwDBServerPort != 0 )
  136. {
  137. str.Format(_T("%ld"),g_dwDBServerPort);
  138. WritePrivateProfileString(_T("ServerInfo"), _T("dbServerPort"), str, szFile);
  139. }
  140. else
  141. {
  142. WritePrivateProfileString(_T("ServerInfo"), _T("dbServerPort"), _T(""), szFile);
  143. }
  144. WritePrivateProfileString(_T("ServerInfo"), _T("dbAccount"), g_szDBAccount, szFile);
  145. WritePrivateProfileString(_T("ServerInfo"), _T("dbPassWord"), g_szDBPassWord, szFile);
  146. WritePrivateProfileString(_T("ServerInfo"), _T("dbName"), g_szDBName, szFile);
  147. // 2.
  148. wsprintf(szFile, _T("%s\\GC0307.ini"), g_ModulePath);
  149. // 1.公共信息;
  150. str.Format(_T("%ld"), m_lpCfg->nMachineType);
  151. WritePrivateProfileString(_T("CommonInfo"), _T("MachineType"), str, szFile);
  152. str.Format(_T("%ld"), m_lpCfg->nType);
  153. WritePrivateProfileString(_T("CommonInfo"), _T("ConnectType"), str, szFile);
  154. str.Format(_T("%ld"), m_lpCfg->lMachineNumber);
  155. WritePrivateProfileString(_T("CommonInfo"), _T("MachineNumber"), str, szFile);
  156. str.Format(_T("%ld"), m_lpCfg->lLicense);
  157. WritePrivateProfileString(_T("CommonInfo"), _T("License"), str, szFile);
  158. // 2.网络信息;
  159. WritePrivateProfileString(_T("NetInfo"), _T("IP"), m_lpCfg->szIpAddress, szFile);
  160. str.Format(_T("%ld"), m_lpCfg->lPort);
  161. WritePrivateProfileString(_T("NetInfo"), _T("Port"), str, szFile);
  162. str.Format(_T("%ld"), m_lpCfg->lTimeOut);
  163. WritePrivateProfileString(_T("NetInfo"), _T("TimeOut"), str, szFile);
  164. str.Format(_T("%ld"), m_lpCfg->lProtocolType);
  165. WritePrivateProfileString(_T("NetInfo"), _T("ProtocolType"), str, szFile);
  166. str.Format(_T("%ld"), m_lpCfg->lNetPassword);
  167. WritePrivateProfileString(_T("NetInfo"), _T("NetPassword"), str, szFile);
  168. OnOK();
  169. }
  170. void CDlgConfig::OnBnClickedCancel()
  171. {
  172. // TODO: 在此添加控件通知处理程序代码
  173. OnCancel();
  174. }
  175. void CDlgConfig::OnBnClickedRadioUsb()
  176. {
  177. // TODO: 在此添加控件通知处理程序代码
  178. m_radio = 0;
  179. ((CButton*)GetDlgItem(IDC_Radio_USB))->SetCheck(TRUE);
  180. ((CButton*)GetDlgItem(IDC_Radio_Net))->SetCheck(FALSE);
  181. m_lpCfg->nType = TYPE_USB;
  182. GetDlgItem(IDC_CHECKUDP)->EnableWindow(FALSE);
  183. GetDlgItem(IDC_ManchineIP)->EnableWindow(FALSE);
  184. GetDlgItem(IDC_ManchinePassword)->EnableWindow(FALSE);
  185. GetDlgItem(IDC_ManchinePort)->EnableWindow(FALSE);
  186. GetDlgItem(IDC_ManchineTimeout)->EnableWindow(FALSE);
  187. }
  188. void CDlgConfig::OnBnClickedRadioNet()
  189. {
  190. // TODO: 在此添加控件通知处理程序代码
  191. m_radio = 1;
  192. m_lpCfg->nType = TYPE_TCP;
  193. ((CButton*)GetDlgItem(IDC_Radio_USB))->SetCheck(FALSE);
  194. ((CButton*)GetDlgItem(IDC_Radio_Net))->SetCheck(TRUE);
  195. GetDlgItem(IDC_CHECKUDP)->EnableWindow(TRUE);
  196. GetDlgItem(IDC_ManchineIP)->EnableWindow(TRUE);
  197. GetDlgItem(IDC_ManchinePassword)->EnableWindow(TRUE);
  198. GetDlgItem(IDC_ManchinePort)->EnableWindow(TRUE);
  199. GetDlgItem(IDC_ManchineTimeout)->EnableWindow(TRUE);
  200. }
  201. void CDlgConfig::OnBnClickedCheckudp()
  202. {
  203. // TODO: 在此添加控件通知处理程序代码
  204. if(((CButton*)GetDlgItem(IDC_CHECKUDP))->GetCheck())
  205. m_nProtocolType = 1;
  206. else
  207. m_nProtocolType = 0;
  208. m_lpCfg->lProtocolType = m_nProtocolType;
  209. }