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

//----------------------------------------------------------------------------
// Laser Guard Ltd.
// Copyright © 2000-2002. All Rights Reserved.
// Version 1.0 01/01/2000
// Last modification: 08/10/2003
// PROJECT:
// SUBSYSTEM:
// FILE: AutorizationDlg.cpp
// AUTHOR: Sergey Chizhevskiy
// OVERVIEW
// ~~~~~~~~
// Source file of AutorizationDlg.cpp
//----------------------------------------------------------------------------
// AutorizationDlg.cpp : implementation file
//
#include "stdafx.h"
#include "chicago.h"
#include "AutorizationDlg.h"
#include "..\..\LgLib\Version.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CAutorizationDlg dialog
CAutorizationDlg::CAutorizationDlg(CWnd* pParent /*=NULL*/)
: CDialog(CAutorizationDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CAutorizationDlg)
m_GuardNew = _T("");
m_GuardOld = _T("");
m_SuperName = _T("");
m_bSuperPresent = FALSE;
m_SuperPassword = _T("");
//}}AFX_DATA_INIT
m_bSuper = FALSE;
m_bGuardNew = FALSE;
m_bGuardOld = FALSE;
m_bEnable = TRUE;
LGLOG( LOG_LEVEL_MEDIUM, LOG_TYPE_INFO, this, _T("CAutorizationDlg::CAutorizationDlg") );
}
void CAutorizationDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CAutorizationDlg)
DDX_Control(pDX, IDC_STATIC_SUPER_PASSWORD, m_StaticSuperPassword);
DDX_Control(pDX, IDC_STATIC_SUPER_NAME, m_StaticSuperName);
DDX_Control(pDX, IDOK, m_ButtonOk);
DDX_Control(pDX, IDCANCEL, m_ButtonCancel);
DDX_Control(pDX, IDC_STATIC_SUPER, m_StaticSuper);
DDX_Control(pDX, IDC_STATIC_GUARD_OLD, m_StaticGuardOld);
DDX_Control(pDX, IDC_STATIC_GUARD_NEW, m_StaticGuardNew);
DDX_Control(pDX, IDC_STATIC_GUARD, m_StaticGuard);
DDX_Control(pDX, IDC_CHECK_SUPER_PRESENT, m_ButtonSuperPresent);
DDX_Control(pDX, IDC_EDIT_SUPER_PASSWORD, m_EditSuperPassword);
DDX_Control(pDX, IDC_EDIT_SUPER_NAME, m_EditSuperName);
DDX_Control(pDX, IDC_EDIT_GUARD_OLD, m_EditGuardOld);
DDX_Control(pDX, IDC_EDIT_GUARD_NEW, m_EditGuardNew);
DDX_Text(pDX, IDC_EDIT_GUARD_NEW, m_GuardNew);
DDX_Text(pDX, IDC_EDIT_GUARD_OLD, m_GuardOld);
DDX_Text(pDX, IDC_EDIT_SUPER_NAME, m_SuperName);
DDX_Check(pDX, IDC_CHECK_SUPER_PRESENT, m_bSuperPresent);
DDX_Text(pDX, IDC_EDIT_SUPER_PASSWORD, m_SuperPassword);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CAutorizationDlg, CDialog)
//{{AFX_MSG_MAP(CAutorizationDlg)
ON_WM_TIMER()
ON_BN_CLICKED(IDC_CHECK_SUPER_PRESENT, OnCheckSuperPresent)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
void CAutorizationDlg::OnTimer(UINT nIDEvent)
{
if( ::GetTickCount() >= m_dwStartTime )
EndDialog( IDCANCEL );
else
CDialog::OnTimer(nIDEvent);
}
int CAutorizationDlg::DoModal()
{
m_dwStartTime = ::GetTickCount() + 60000UL;
return CDialog::DoModal();
}
void CAutorizationDlg::SetSensorArray(CSensorArray *pSensorArray)
{
m_pSensorArray = pSensorArray;
}
//DEL void CAutorizationDlg::OnChangeEditSuperName()
//DEL {
//DEL CheckInputState();
//DEL
//DEL CString str;
//DEL m_SuperName.GetWindowText( str );
//DEL if( m_pSensorArray->CheckSuper( (LPSTR)(LPCTSTR)str ) )
//DEL m_SuperPassword.SetFocus();
//DEL }
void CAutorizationDlg::CheckInputState()
{
/* CString strSuperName;
CString strGuardName;
CString strPassword;
m_SuperName.GetWindowText( strSuperName );
m_SuperPassword.GetWindowText( strPassword );
m_GuardName.GetWindowText( strGuardName );
BOOL bEnable = FALSE;
if( m_pSensorArray->CheckSuperPassword( (LPSTR)(LPCTSTR)strSuperName, (LPSTR)(LPCTSTR)strPassword ) )
bEnable = TRUE;
if( m_pSensorArray->CheckGuard( (LPSTR)(LPCTSTR)strGuardName ) )
bEnable = TRUE;
m_Ok.EnableWindow( bEnable );
*/
}
//DEL void CAutorizationDlg::OnChangeEditSuperPassword()
//DEL {
//DEL CheckInputState();
//DEL
//DEL CString strName;
//DEL CString strPassword;
//DEL m_SuperName.GetWindowText( strName );
//DEL m_SuperPassword.GetWindowText( strPassword );
//DEL if( m_pSensorArray->CheckSuperPassword( (LPSTR)(LPCTSTR)strName, (LPSTR)(LPCTSTR)strPassword ) )
//DEL m_Ok.SetFocus();
//DEL }
//DEL void CAutorizationDlg::OnChangeEditGuardName()
//DEL {
//DEL CheckInputState();
//DEL
//DEL CString strName;
//DEL m_GuardName.GetWindowText( strName );
//DEL if( m_pSensorArray->CheckGuard( (LPSTR)(LPCTSTR)strName ) )
//DEL m_Ok.SetFocus();
//DEL }
BOOL CAutorizationDlg::OnInitDialog()
{
CDialog::OnInitDialog();
m_EditGuardNew.EnableWindow( m_bGuardNew );
m_EditGuardOld.EnableWindow( m_bGuardOld );
if( !m_bGuardNew )
{
m_ButtonSuperPresent.SetCheck( TRUE );
m_ButtonSuperPresent.EnableWindow( FALSE );
}
else
m_ButtonSuperPresent.EnableWindow( m_bSuper );
if( !m_bGuardOld )
{
m_EditSuperName.EnableWindow( m_ButtonSuperPresent.GetCheck() );
m_EditSuperPassword.EnableWindow( m_ButtonSuperPresent.GetCheck() );
}
else
{
m_EditSuperName.EnableWindow( FALSE );
m_EditSuperPassword.EnableWindow( FALSE );
}
m_EditGuardNew.SetWindowText( "" );
m_EditGuardOld.SetWindowText( "" );
m_EditSuperName.SetWindowText( "" );
m_EditSuperPassword.SetWindowText( "" );
Reposition();
return TRUE;
}
void CAutorizationDlg::OnCheckSuperPresent()
{
m_EditSuperName.EnableWindow( m_ButtonSuperPresent.GetCheck() );
m_EditSuperPassword.EnableWindow( m_ButtonSuperPresent.GetCheck() );
}
void CAutorizationDlg::OnOK()
{
/* if( m_bGuard )
{
CString strName;
m_GuardName.GetWindowText( strName );
if( m_pSensorArray->CheckGuard( (LPSTR)(LPCTSTR)strName ) )
{
if( strName != m_CurrentGuard )
{
CString str;
str.Format( "guard \"%s\"", m_CurrentGuard = strName );
m_pSensorArray->GetEventQueue()->PostEvent( LGS_EVENT_GUARD, 0, 0, 0, RGB(0xFF,0xFF,0xFF), (LPSTR)(LPCTSTR)str );
}
}
}
if( m_bSuper && m_SuperPresent.GetCheck() )
{
CString strName;
CString strPassword;
m_SuperName.GetWindowText( strName );
m_SuperPassword.GetWindowText( strPassword );
if( m_pSensorArray->CheckSuperPassword( (LPSTR)(LPCTSTR)strName, (LPSTR)(LPCTSTR)strPassword ) )
{
if( strName != m_CurrentSuper )
{
CString str;
str.Format( "supervisor \"%s\"", m_CurrentSuper = strName );
m_pSensorArray->GetEventQueue()->PostEvent( LGS_EVENT_GUARD, 0, 0, 0, RGB(0xFF,0xFF,0xFF), (LPSTR)(LPCTSTR)str );
}
}
}
*/
CDialog::OnOK();
}
int CAutorizationDlg::DoModal( BOOL bSuper, BOOL bNewGuard, BOOL bOldGuard )
{
if( m_bEnable ) m_bSuper = bSuper;
else m_bSuper = FALSE;
m_bGuardNew = bNewGuard;
m_bGuardOld = bOldGuard;
if( !m_bSuper && !m_bGuardNew )
return IDOK;
int iResult = DoModal();
if( iResult==IDOK )
{
if( m_bSuper && m_bSuperPresent )
{
if( !m_pSensorArray->CheckSuperPassword( (LPSTR)(LPCTSTR)m_SuperName, (LPSTR)(LPCTSTR)m_SuperPassword ) )
{
m_ErrorString = "wrong supervisor autorization";
return IDRETRY;
}
if( m_CurrentSuper != m_SuperName )
{
CString str;
str.Format( "supervisor \"%s\"", m_CurrentSuper = m_SuperName );
m_pSensorArray->GetEventQueue()->PostEvent( LGS_EVENT_GUARD, 0, 0, 0, RGB(0xFF,0xFF,0xFF), (LPSTR)(LPCTSTR)str );
}
}
if( m_bGuardNew )
{
if( m_bGuardOld )
{
if( m_GuardOld != m_CurrentGuard )
{
m_ErrorString = "It needs to enter old system operator's logon";
return IDRETRY;
}
}
if( m_pSensorArray->CheckGuard( (LPSTR)(LPCTSTR)m_GuardNew ) )
{
if( m_GuardNew != m_CurrentGuard )
{
CString str;
str.Format( "system operator \"%s\"", m_CurrentGuard = m_GuardNew );
m_pSensorArray->GetEventQueue()->PostEvent( LGS_EVENT_GUARD, 0, 0, 0, RGB(0xFF,0xFF,0xFF), (LPSTR)(LPCTSTR)str );
}
}
else
{
m_ErrorString = "wrong new system operator's logon";
return IDRETRY;
}
}
return iResult;
}
return iResult;
}
CString& CAutorizationDlg::GetErrorString()
{
return m_ErrorString;
}
void CAutorizationDlg::Reposition()
{
CRect r;
m_StaticSuper.GetClientRect( &r );
m_StaticSuper.MapWindowPoints( this, &r );
CRect r0;
m_StaticGuard.GetClientRect( &r0 );
m_StaticGuard.MapWindowPoints( this, &r0 );
CSize s( r.left - r0.left, r.top - r0.top );
if( !m_bSuper )
{
m_StaticSuper.ShowWindow( SW_HIDE );
m_StaticSuperName.ShowWindow( SW_HIDE );
m_StaticSuperPassword.ShowWindow( SW_HIDE );
m_EditSuperName.ShowWindow( SW_HIDE );
m_EditSuperPassword.ShowWindow( SW_HIDE );
m_ButtonSuperPresent.ShowWindow( SW_HIDE );
r0.OffsetRect( s );
m_StaticGuard.MoveWindow( r0 );
m_StaticGuardNew.GetClientRect( &r0 );
m_StaticGuardNew.MapWindowPoints( this, &r0 );
r0.OffsetRect( s );
m_StaticGuardNew.MoveWindow( r0 );
m_StaticGuardOld.GetClientRect( &r0 );
m_StaticGuardOld.MapWindowPoints( this, &r0 );
r0.OffsetRect( s );
m_StaticGuardOld.MoveWindow( r0 );
m_EditGuardNew.GetClientRect( &r0 );
m_EditGuardNew.MapWindowPoints( this, &r0 );
r0.OffsetRect( s );
m_EditGuardNew.MoveWindow( r0 );
m_EditGuardOld.GetClientRect( &r0 );
m_EditGuardOld.MapWindowPoints( this, &r0 );
r0.OffsetRect( s );
m_EditGuardOld.MoveWindow( r0 );
}
if( !m_bSuper || !m_bGuardNew )
{
m_ButtonOk.GetClientRect( &r0 );
m_ButtonOk.MapWindowPoints( this, &r0 );
r0.OffsetRect( s );
m_ButtonOk.MoveWindow( r0 );
m_ButtonCancel.GetClientRect( &r0 );
m_ButtonCancel.MapWindowPoints( this, &r0 );
r0.OffsetRect( s );
m_ButtonCancel.MoveWindow( r0 );
GetWindowRect( &r );
r.DeflateRect( CSize( -s.cx / 2, -s.cy / 2 ) );
MoveWindow( &r );
}
if( !m_bGuardNew )
{
m_StaticGuard.ShowWindow( SW_HIDE );
m_StaticGuardNew.ShowWindow( SW_HIDE );
m_StaticGuardOld.ShowWindow( SW_HIDE );
m_EditGuardNew.ShowWindow( SW_HIDE );
m_EditGuardOld.ShowWindow( SW_HIDE );
m_ButtonSuperPresent.ShowWindow( SW_HIDE );
}
else
if( !m_bGuardOld )
{
m_StaticGuardOld.ShowWindow( SW_HIDE );
m_EditGuardOld.ShowWindow( SW_HIDE );
}
}
void CAutorizationDlg::Enable(BOOL bEnable)
{
m_bEnable = bEnable;
}