/* * Developed by Torben H. Nielsen */ #include "stdafx.h" #include "h6-udlånssystem.h" #include "UserEditDialog.h" #include ".\usereditdialog.h" // UserEditDialog dialog IMPLEMENT_DYNAMIC(UserEditDialog, CDialog) UserEditDialog::UserEditDialog(CWnd* pParent /*=NULL*/) : CDialog(UserEditDialog::IDD, pParent) { } UserEditDialog::~UserEditDialog() { } void UserEditDialog::DoDataExchange(CDataExchange* pDX) { CDialog::DoDataExchange(pDX); } BEGIN_MESSAGE_MAP(UserEditDialog, CDialog) ON_BN_CLICKED(IDC_ADMIN, OnBnClickedAdmin) ON_BN_CLICKED(IDOK, OnBnClickedOk) END_MESSAGE_MAP() // UserEditDialog message handlers BOOL UserEditDialog::OnInitDialog() { CDialog::OnInitDialog(); ((CEdit*)GetDlgItem(IDC_INITS))->SetLimitText(4); if (m_currentPerson.inits != "") { GetDlgItem(IDC_INITS)->SetWindowText(m_currentPerson.inits); GetDlgItem(IDC_NAME)->SetWindowText(m_currentPerson.name); if (m_currentPerson.isadmin == true) { ((CButton*)GetDlgItem(IDC_ADMIN))->SetCheck(true); } else { GetDlgItem(IDC_PASSWORD1)->EnableWindow(false); GetDlgItem(IDC_PASSWORD2)->EnableWindow(false); } } else { GetDlgItem(IDC_PASSWORD1)->EnableWindow(false); GetDlgItem(IDC_PASSWORD2)->EnableWindow(false); } return TRUE; // return TRUE unless you set the focus to a control // EXCEPTION: OCX Property Pages should return FALSE } void UserEditDialog::OnBnClickedAdmin() { if (((CButton*)GetDlgItem(IDC_ADMIN))->GetCheck() == true) { GetDlgItem(IDC_PASSWORD1)->EnableWindow(true); GetDlgItem(IDC_PASSWORD2)->EnableWindow(true); } else { //not checked GetDlgItem(IDC_PASSWORD1)->EnableWindow(false); GetDlgItem(IDC_PASSWORD2)->EnableWindow(false); } } void UserEditDialog::OnBnClickedOk() { CString inits,name,password1,password2; bool isAdmin; GetDlgItem(IDC_INITS)->GetWindowText(inits); GetDlgItem(IDC_NAME)->GetWindowText(name); GetDlgItem(IDC_PASSWORD1)->GetWindowText(password1); GetDlgItem(IDC_PASSWORD2)->GetWindowText(password2); isAdmin = ((CButton*)GetDlgItem(IDC_ADMIN))->GetCheck(); if (inits == "" || name == "") { MessageBox("You must enter initials and name", "Edit User"); return; } if (isAdmin && (password1 != password2) ) { MessageBox("You must enter the same password in the 2 password fields"); return; } m_currentPerson.inits = inits; m_currentPerson.name = name; m_currentPerson.isadmin = isAdmin; if (password1 != "") { m_currentPerson.pass = password1; } // TODO: Add your control notification handler code here OnOK(); }