Old fashion design for PC-104
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

379 lines
10 KiB

4 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  1. //----------------------------------------------------------------------------
  2. // Laser Guard Ltd.
  3. // Copyright � 2000-2002. All Rights Reserved.
  4. // Version 1.0 01/01/2000
  5. // Last modification: 08/10/2003
  6. // PROJECT:
  7. // SUBSYSTEM:
  8. // FILE: AutorizationDlg.cpp
  9. // AUTHOR: Sergey Chizhevskiy
  10. // OVERVIEW
  11. // ~~~~~~~~
  12. // Source file of AutorizationDlg.cpp
  13. //----------------------------------------------------------------------------
  14. // AutorizationDlg.cpp : implementation file
  15. //
  16. #include "stdafx.h"
  17. #include "chicago.h"
  18. #include "AutorizationDlg.h"
  19. #include "..\..\LgLib\Version.h"
  20. #ifdef _DEBUG
  21. #define new DEBUG_NEW
  22. #undef THIS_FILE
  23. static char THIS_FILE[] = __FILE__;
  24. #endif
  25. /////////////////////////////////////////////////////////////////////////////
  26. // CAutorizationDlg dialog
  27. CAutorizationDlg::CAutorizationDlg(CWnd* pParent /*=NULL*/)
  28. : CDialog(CAutorizationDlg::IDD, pParent)
  29. {
  30. //{{AFX_DATA_INIT(CAutorizationDlg)
  31. m_GuardNew = _T("");
  32. m_GuardOld = _T("");
  33. m_SuperName = _T("");
  34. m_bSuperPresent = FALSE;
  35. m_SuperPassword = _T("");
  36. //}}AFX_DATA_INIT
  37. m_bSuper = FALSE;
  38. m_bGuardNew = FALSE;
  39. m_bGuardOld = FALSE;
  40. m_bEnable = TRUE;
  41. LGLOG( LOG_LEVEL_MEDIUM, LOG_TYPE_INFO, this, _T("CAutorizationDlg::CAutorizationDlg") );
  42. }
  43. void CAutorizationDlg::DoDataExchange(CDataExchange* pDX)
  44. {
  45. CDialog::DoDataExchange(pDX);
  46. //{{AFX_DATA_MAP(CAutorizationDlg)
  47. DDX_Control(pDX, IDC_STATIC_SUPER_PASSWORD, m_StaticSuperPassword);
  48. DDX_Control(pDX, IDC_STATIC_SUPER_NAME, m_StaticSuperName);
  49. DDX_Control(pDX, IDOK, m_ButtonOk);
  50. DDX_Control(pDX, IDCANCEL, m_ButtonCancel);
  51. DDX_Control(pDX, IDC_STATIC_SUPER, m_StaticSuper);
  52. DDX_Control(pDX, IDC_STATIC_GUARD_OLD, m_StaticGuardOld);
  53. DDX_Control(pDX, IDC_STATIC_GUARD_NEW, m_StaticGuardNew);
  54. DDX_Control(pDX, IDC_STATIC_GUARD, m_StaticGuard);
  55. DDX_Control(pDX, IDC_CHECK_SUPER_PRESENT, m_ButtonSuperPresent);
  56. DDX_Control(pDX, IDC_EDIT_SUPER_PASSWORD, m_EditSuperPassword);
  57. DDX_Control(pDX, IDC_EDIT_SUPER_NAME, m_EditSuperName);
  58. DDX_Control(pDX, IDC_EDIT_GUARD_OLD, m_EditGuardOld);
  59. DDX_Control(pDX, IDC_EDIT_GUARD_NEW, m_EditGuardNew);
  60. DDX_Text(pDX, IDC_EDIT_GUARD_NEW, m_GuardNew);
  61. DDX_Text(pDX, IDC_EDIT_GUARD_OLD, m_GuardOld);
  62. DDX_Text(pDX, IDC_EDIT_SUPER_NAME, m_SuperName);
  63. DDX_Check(pDX, IDC_CHECK_SUPER_PRESENT, m_bSuperPresent);
  64. DDX_Text(pDX, IDC_EDIT_SUPER_PASSWORD, m_SuperPassword);
  65. //}}AFX_DATA_MAP
  66. }
  67. BEGIN_MESSAGE_MAP(CAutorizationDlg, CDialog)
  68. //{{AFX_MSG_MAP(CAutorizationDlg)
  69. ON_WM_TIMER()
  70. ON_BN_CLICKED(IDC_CHECK_SUPER_PRESENT, OnCheckSuperPresent)
  71. //}}AFX_MSG_MAP
  72. END_MESSAGE_MAP()
  73. void CAutorizationDlg::OnTimer(UINT nIDEvent)
  74. {
  75. if( ::GetTickCount() >= m_dwStartTime )
  76. EndDialog( IDCANCEL );
  77. else
  78. CDialog::OnTimer(nIDEvent);
  79. }
  80. int CAutorizationDlg::DoModal()
  81. {
  82. m_dwStartTime = ::GetTickCount() + 60000UL;
  83. return CDialog::DoModal();
  84. }
  85. void CAutorizationDlg::SetSensorArray(CSensorArray *pSensorArray)
  86. {
  87. m_pSensorArray = pSensorArray;
  88. }
  89. //DEL void CAutorizationDlg::OnChangeEditSuperName()
  90. //DEL {
  91. //DEL CheckInputState();
  92. //DEL
  93. //DEL CString str;
  94. //DEL m_SuperName.GetWindowText( str );
  95. //DEL if( m_pSensorArray->CheckSuper( (LPSTR)(LPCTSTR)str ) )
  96. //DEL m_SuperPassword.SetFocus();
  97. //DEL }
  98. void CAutorizationDlg::CheckInputState()
  99. {
  100. /* CString strSuperName;
  101. CString strGuardName;
  102. CString strPassword;
  103. m_SuperName.GetWindowText( strSuperName );
  104. m_SuperPassword.GetWindowText( strPassword );
  105. m_GuardName.GetWindowText( strGuardName );
  106. BOOL bEnable = FALSE;
  107. if( m_pSensorArray->CheckSuperPassword( (LPSTR)(LPCTSTR)strSuperName, (LPSTR)(LPCTSTR)strPassword ) )
  108. bEnable = TRUE;
  109. if( m_pSensorArray->CheckGuard( (LPSTR)(LPCTSTR)strGuardName ) )
  110. bEnable = TRUE;
  111. m_Ok.EnableWindow( bEnable );
  112. */
  113. }
  114. //DEL void CAutorizationDlg::OnChangeEditSuperPassword()
  115. //DEL {
  116. //DEL CheckInputState();
  117. //DEL
  118. //DEL CString strName;
  119. //DEL CString strPassword;
  120. //DEL m_SuperName.GetWindowText( strName );
  121. //DEL m_SuperPassword.GetWindowText( strPassword );
  122. //DEL if( m_pSensorArray->CheckSuperPassword( (LPSTR)(LPCTSTR)strName, (LPSTR)(LPCTSTR)strPassword ) )
  123. //DEL m_Ok.SetFocus();
  124. //DEL }
  125. //DEL void CAutorizationDlg::OnChangeEditGuardName()
  126. //DEL {
  127. //DEL CheckInputState();
  128. //DEL
  129. //DEL CString strName;
  130. //DEL m_GuardName.GetWindowText( strName );
  131. //DEL if( m_pSensorArray->CheckGuard( (LPSTR)(LPCTSTR)strName ) )
  132. //DEL m_Ok.SetFocus();
  133. //DEL }
  134. BOOL CAutorizationDlg::OnInitDialog()
  135. {
  136. CDialog::OnInitDialog();
  137. m_EditGuardNew.EnableWindow( m_bGuardNew );
  138. m_EditGuardOld.EnableWindow( m_bGuardOld );
  139. if( !m_bGuardNew )
  140. {
  141. m_ButtonSuperPresent.SetCheck( TRUE );
  142. m_ButtonSuperPresent.EnableWindow( FALSE );
  143. }
  144. else
  145. m_ButtonSuperPresent.EnableWindow( m_bSuper );
  146. if( !m_bGuardOld )
  147. {
  148. m_EditSuperName.EnableWindow( m_ButtonSuperPresent.GetCheck() );
  149. m_EditSuperPassword.EnableWindow( m_ButtonSuperPresent.GetCheck() );
  150. }
  151. else
  152. {
  153. m_EditSuperName.EnableWindow( FALSE );
  154. m_EditSuperPassword.EnableWindow( FALSE );
  155. }
  156. m_EditGuardNew.SetWindowText( "" );
  157. m_EditGuardOld.SetWindowText( "" );
  158. m_EditSuperName.SetWindowText( "" );
  159. m_EditSuperPassword.SetWindowText( "" );
  160. Reposition();
  161. return TRUE;
  162. }
  163. void CAutorizationDlg::OnCheckSuperPresent()
  164. {
  165. m_EditSuperName.EnableWindow( m_ButtonSuperPresent.GetCheck() );
  166. m_EditSuperPassword.EnableWindow( m_ButtonSuperPresent.GetCheck() );
  167. }
  168. void CAutorizationDlg::OnOK()
  169. {
  170. /* if( m_bGuard )
  171. {
  172. CString strName;
  173. m_GuardName.GetWindowText( strName );
  174. if( m_pSensorArray->CheckGuard( (LPSTR)(LPCTSTR)strName ) )
  175. {
  176. if( strName != m_CurrentGuard )
  177. {
  178. CString str;
  179. str.Format( "guard \"%s\"", m_CurrentGuard = strName );
  180. m_pSensorArray->GetEventQueue()->PostEvent( LGS_EVENT_GUARD, 0, 0, 0, RGB(0xFF,0xFF,0xFF), (LPSTR)(LPCTSTR)str );
  181. }
  182. }
  183. }
  184. if( m_bSuper && m_SuperPresent.GetCheck() )
  185. {
  186. CString strName;
  187. CString strPassword;
  188. m_SuperName.GetWindowText( strName );
  189. m_SuperPassword.GetWindowText( strPassword );
  190. if( m_pSensorArray->CheckSuperPassword( (LPSTR)(LPCTSTR)strName, (LPSTR)(LPCTSTR)strPassword ) )
  191. {
  192. if( strName != m_CurrentSuper )
  193. {
  194. CString str;
  195. str.Format( "supervisor \"%s\"", m_CurrentSuper = strName );
  196. m_pSensorArray->GetEventQueue()->PostEvent( LGS_EVENT_GUARD, 0, 0, 0, RGB(0xFF,0xFF,0xFF), (LPSTR)(LPCTSTR)str );
  197. }
  198. }
  199. }
  200. */
  201. CDialog::OnOK();
  202. }
  203. int CAutorizationDlg::DoModal( BOOL bSuper, BOOL bNewGuard, BOOL bOldGuard )
  204. {
  205. if( m_bEnable ) m_bSuper = bSuper;
  206. else m_bSuper = FALSE;
  207. m_bGuardNew = bNewGuard;
  208. m_bGuardOld = bOldGuard;
  209. if( !m_bSuper && !m_bGuardNew )
  210. return IDOK;
  211. int iResult = DoModal();
  212. if( iResult==IDOK )
  213. {
  214. if( m_bSuper && m_bSuperPresent )
  215. {
  216. if( !m_pSensorArray->CheckSuperPassword( (LPSTR)(LPCTSTR)m_SuperName, (LPSTR)(LPCTSTR)m_SuperPassword ) )
  217. {
  218. m_ErrorString = "wrong supervisor autorization";
  219. return IDRETRY;
  220. }
  221. if( m_CurrentSuper != m_SuperName )
  222. {
  223. CString str;
  224. str.Format( "supervisor \"%s\"", m_CurrentSuper = m_SuperName );
  225. m_pSensorArray->GetEventQueue()->PostEvent( LGS_EVENT_GUARD, 0, 0, 0, RGB(0xFF,0xFF,0xFF), (LPSTR)(LPCTSTR)str );
  226. }
  227. }
  228. if( m_bGuardNew )
  229. {
  230. if( m_bGuardOld )
  231. {
  232. if( m_GuardOld != m_CurrentGuard )
  233. {
  234. m_ErrorString = "It needs to enter old system operator's logon";
  235. return IDRETRY;
  236. }
  237. }
  238. if( m_pSensorArray->CheckGuard( (LPSTR)(LPCTSTR)m_GuardNew ) )
  239. {
  240. if( m_GuardNew != m_CurrentGuard )
  241. {
  242. CString str;
  243. str.Format( "system operator \"%s\"", m_CurrentGuard = m_GuardNew );
  244. m_pSensorArray->GetEventQueue()->PostEvent( LGS_EVENT_GUARD, 0, 0, 0, RGB(0xFF,0xFF,0xFF), (LPSTR)(LPCTSTR)str );
  245. }
  246. }
  247. else
  248. {
  249. m_ErrorString = "wrong new system operator's logon";
  250. return IDRETRY;
  251. }
  252. }
  253. return iResult;
  254. }
  255. return iResult;
  256. }
  257. CString& CAutorizationDlg::GetErrorString()
  258. {
  259. return m_ErrorString;
  260. }
  261. void CAutorizationDlg::Reposition()
  262. {
  263. CRect r;
  264. m_StaticSuper.GetClientRect( &r );
  265. m_StaticSuper.MapWindowPoints( this, &r );
  266. CRect r0;
  267. m_StaticGuard.GetClientRect( &r0 );
  268. m_StaticGuard.MapWindowPoints( this, &r0 );
  269. CSize s( r.left - r0.left, r.top - r0.top );
  270. if( !m_bSuper )
  271. {
  272. m_StaticSuper.ShowWindow( SW_HIDE );
  273. m_StaticSuperName.ShowWindow( SW_HIDE );
  274. m_StaticSuperPassword.ShowWindow( SW_HIDE );
  275. m_EditSuperName.ShowWindow( SW_HIDE );
  276. m_EditSuperPassword.ShowWindow( SW_HIDE );
  277. m_ButtonSuperPresent.ShowWindow( SW_HIDE );
  278. r0.OffsetRect( s );
  279. m_StaticGuard.MoveWindow( r0 );
  280. m_StaticGuardNew.GetClientRect( &r0 );
  281. m_StaticGuardNew.MapWindowPoints( this, &r0 );
  282. r0.OffsetRect( s );
  283. m_StaticGuardNew.MoveWindow( r0 );
  284. m_StaticGuardOld.GetClientRect( &r0 );
  285. m_StaticGuardOld.MapWindowPoints( this, &r0 );
  286. r0.OffsetRect( s );
  287. m_StaticGuardOld.MoveWindow( r0 );
  288. m_EditGuardNew.GetClientRect( &r0 );
  289. m_EditGuardNew.MapWindowPoints( this, &r0 );
  290. r0.OffsetRect( s );
  291. m_EditGuardNew.MoveWindow( r0 );
  292. m_EditGuardOld.GetClientRect( &r0 );
  293. m_EditGuardOld.MapWindowPoints( this, &r0 );
  294. r0.OffsetRect( s );
  295. m_EditGuardOld.MoveWindow( r0 );
  296. }
  297. if( !m_bSuper || !m_bGuardNew )
  298. {
  299. m_ButtonOk.GetClientRect( &r0 );
  300. m_ButtonOk.MapWindowPoints( this, &r0 );
  301. r0.OffsetRect( s );
  302. m_ButtonOk.MoveWindow( r0 );
  303. m_ButtonCancel.GetClientRect( &r0 );
  304. m_ButtonCancel.MapWindowPoints( this, &r0 );
  305. r0.OffsetRect( s );
  306. m_ButtonCancel.MoveWindow( r0 );
  307. GetWindowRect( &r );
  308. r.DeflateRect( CSize( -s.cx / 2, -s.cy / 2 ) );
  309. MoveWindow( &r );
  310. }
  311. if( !m_bGuardNew )
  312. {
  313. m_StaticGuard.ShowWindow( SW_HIDE );
  314. m_StaticGuardNew.ShowWindow( SW_HIDE );
  315. m_StaticGuardOld.ShowWindow( SW_HIDE );
  316. m_EditGuardNew.ShowWindow( SW_HIDE );
  317. m_EditGuardOld.ShowWindow( SW_HIDE );
  318. m_ButtonSuperPresent.ShowWindow( SW_HIDE );
  319. }
  320. else
  321. if( !m_bGuardOld )
  322. {
  323. m_StaticGuardOld.ShowWindow( SW_HIDE );
  324. m_EditGuardOld.ShowWindow( SW_HIDE );
  325. }
  326. }
  327. void CAutorizationDlg::Enable(BOOL bEnable)
  328. {
  329. m_bEnable = bEnable;
  330. }