1 |
torben |
9 |
// UserEditDialog.cpp : implementation file
|
2 |
|
|
//
|
3 |
|
|
|
4 |
|
|
#include "stdafx.h"
|
5 |
|
|
#include "h6-udlånssystem.h"
|
6 |
|
|
#include "UserEditDialog.h"
|
7 |
|
|
#include ".\usereditdialog.h"
|
8 |
|
|
|
9 |
|
|
|
10 |
|
|
// UserEditDialog dialog
|
11 |
|
|
|
12 |
|
|
IMPLEMENT_DYNAMIC(UserEditDialog, CDialog)
|
13 |
|
|
UserEditDialog::UserEditDialog(CWnd* pParent /*=NULL*/)
|
14 |
|
|
: CDialog(UserEditDialog::IDD, pParent)
|
15 |
|
|
{
|
16 |
|
|
}
|
17 |
|
|
|
18 |
|
|
UserEditDialog::~UserEditDialog()
|
19 |
|
|
{
|
20 |
|
|
}
|
21 |
|
|
|
22 |
|
|
void UserEditDialog::DoDataExchange(CDataExchange* pDX)
|
23 |
|
|
{
|
24 |
|
|
CDialog::DoDataExchange(pDX);
|
25 |
|
|
}
|
26 |
|
|
|
27 |
|
|
|
28 |
|
|
BEGIN_MESSAGE_MAP(UserEditDialog, CDialog)
|
29 |
|
|
ON_BN_CLICKED(IDC_ADMIN, OnBnClickedAdmin)
|
30 |
|
|
ON_BN_CLICKED(IDOK, OnBnClickedOk)
|
31 |
|
|
END_MESSAGE_MAP()
|
32 |
|
|
|
33 |
|
|
|
34 |
|
|
// UserEditDialog message handlers
|
35 |
|
|
|
36 |
|
|
BOOL UserEditDialog::OnInitDialog()
|
37 |
|
|
{
|
38 |
|
|
CDialog::OnInitDialog();
|
39 |
|
|
|
40 |
|
|
((CEdit*)GetDlgItem(IDC_INITS))->SetLimitText(4);
|
41 |
|
|
|
42 |
|
|
if (m_currentPerson.inits != "") {
|
43 |
|
|
GetDlgItem(IDC_INITS)->SetWindowText(m_currentPerson.inits);
|
44 |
|
|
GetDlgItem(IDC_NAME)->SetWindowText(m_currentPerson.name);
|
45 |
|
|
if (m_currentPerson.isadmin == true) {
|
46 |
|
|
((CButton*)GetDlgItem(IDC_ADMIN))->SetCheck(true);
|
47 |
|
|
} else {
|
48 |
|
|
GetDlgItem(IDC_PASSWORD1)->EnableWindow(false);
|
49 |
|
|
GetDlgItem(IDC_PASSWORD2)->EnableWindow(false);
|
50 |
|
|
}
|
51 |
|
|
} else {
|
52 |
|
|
GetDlgItem(IDC_PASSWORD1)->EnableWindow(false);
|
53 |
|
|
GetDlgItem(IDC_PASSWORD2)->EnableWindow(false);
|
54 |
|
|
}
|
55 |
|
|
|
56 |
|
|
return TRUE; // return TRUE unless you set the focus to a control
|
57 |
|
|
// EXCEPTION: OCX Property Pages should return FALSE
|
58 |
|
|
}
|
59 |
|
|
|
60 |
|
|
void UserEditDialog::OnBnClickedAdmin()
|
61 |
|
|
{
|
62 |
|
|
if (((CButton*)GetDlgItem(IDC_ADMIN))->GetCheck() == true) {
|
63 |
|
|
GetDlgItem(IDC_PASSWORD1)->EnableWindow(true);
|
64 |
|
|
GetDlgItem(IDC_PASSWORD2)->EnableWindow(true);
|
65 |
|
|
} else { //not checked
|
66 |
|
|
GetDlgItem(IDC_PASSWORD1)->EnableWindow(false);
|
67 |
|
|
GetDlgItem(IDC_PASSWORD2)->EnableWindow(false);
|
68 |
|
|
}
|
69 |
|
|
}
|
70 |
|
|
|
71 |
|
|
void UserEditDialog::OnBnClickedOk()
|
72 |
|
|
{
|
73 |
|
|
CString inits,name,password1,password2;
|
74 |
|
|
bool isAdmin;
|
75 |
|
|
GetDlgItem(IDC_INITS)->GetWindowText(inits);
|
76 |
|
|
GetDlgItem(IDC_NAME)->GetWindowText(name);
|
77 |
|
|
GetDlgItem(IDC_PASSWORD1)->GetWindowText(password1);
|
78 |
|
|
GetDlgItem(IDC_PASSWORD2)->GetWindowText(password2);
|
79 |
|
|
|
80 |
|
|
isAdmin = ((CButton*)GetDlgItem(IDC_ADMIN))->GetCheck();
|
81 |
|
|
|
82 |
|
|
if (inits == "" || name == "") {
|
83 |
|
|
MessageBox("You must enter initials and name", "Edit User");
|
84 |
|
|
return;
|
85 |
|
|
}
|
86 |
|
|
|
87 |
|
|
if (isAdmin && (password1 != password2) ) {
|
88 |
|
|
MessageBox("You must enter the same password in the 2 password fields");
|
89 |
|
|
return;
|
90 |
|
|
}
|
91 |
|
|
|
92 |
|
|
m_currentPerson.inits = inits;
|
93 |
|
|
m_currentPerson.name = name;
|
94 |
|
|
m_currentPerson.isadmin = isAdmin;
|
95 |
|
|
if (password1 != "") {
|
96 |
|
|
m_currentPerson.pass = password1;
|
97 |
|
|
}
|
98 |
|
|
|
99 |
|
|
// TODO: Add your control notification handler code here
|
100 |
|
|
OnOK();
|
101 |
|
|
}
|