1 |
/*
|
2 |
* Developed by Torben H. Nielsen
|
3 |
*/
|
4 |
|
5 |
|
6 |
#include "stdafx.h"
|
7 |
#include "h6-udlånssystem.h"
|
8 |
#include "h6-udlånssystemDlg.h"
|
9 |
#include ".\h6-udlånssystemdlg.h"
|
10 |
|
11 |
#include "commonstorage.h"
|
12 |
#include "databaselayer.h"
|
13 |
#include "microsoftdblayer.h"
|
14 |
#include "mysqllayer.h"
|
15 |
|
16 |
#ifdef _DEBUG
|
17 |
#define new DEBUG_NEW
|
18 |
#endif
|
19 |
|
20 |
|
21 |
// CAboutDlg dialog used for App About
|
22 |
|
23 |
class CAboutDlg : public CDialog
|
24 |
{
|
25 |
public:
|
26 |
CAboutDlg();
|
27 |
|
28 |
// Dialog Data
|
29 |
enum { IDD = IDD_ABOUTBOX };
|
30 |
|
31 |
protected:
|
32 |
virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
|
33 |
|
34 |
// Implementation
|
35 |
protected:
|
36 |
DECLARE_MESSAGE_MAP()
|
37 |
};
|
38 |
|
39 |
CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
|
40 |
{
|
41 |
}
|
42 |
|
43 |
void CAboutDlg::DoDataExchange(CDataExchange* pDX)
|
44 |
{
|
45 |
CDialog::DoDataExchange(pDX);
|
46 |
}
|
47 |
|
48 |
BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
|
49 |
END_MESSAGE_MAP()
|
50 |
|
51 |
|
52 |
// Ch6udlnssystemDlg dialog
|
53 |
|
54 |
|
55 |
|
56 |
Ch6udlnssystemDlg::Ch6udlnssystemDlg(CWnd* pParent /*=NULL*/)
|
57 |
: CDialog(Ch6udlnssystemDlg::IDD, pParent)
|
58 |
{
|
59 |
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
|
60 |
}
|
61 |
|
62 |
void Ch6udlnssystemDlg::DoDataExchange(CDataExchange* pDX)
|
63 |
{
|
64 |
CDialog::DoDataExchange(pDX);
|
65 |
DDX_Control(pDX, IDC_TAB, m_tabs);
|
66 |
}
|
67 |
|
68 |
BEGIN_MESSAGE_MAP(Ch6udlnssystemDlg, CDialog)
|
69 |
ON_WM_SYSCOMMAND()
|
70 |
ON_WM_PAINT()
|
71 |
ON_WM_QUERYDRAGICON()
|
72 |
//}}AFX_MSG_MAP
|
73 |
ON_COMMAND(ID_HELP_ABOUT, OnHelpAbout)
|
74 |
ON_COMMAND(ID_FILE_EXIT, OnFileExit)
|
75 |
END_MESSAGE_MAP()
|
76 |
|
77 |
|
78 |
// Ch6udlnssystemDlg message handlers
|
79 |
|
80 |
BOOL Ch6udlnssystemDlg::OnInitDialog()
|
81 |
{
|
82 |
CDialog::OnInitDialog();
|
83 |
CWaitCursor wait;
|
84 |
|
85 |
// Add "About..." menu item to system menu.
|
86 |
|
87 |
// IDM_ABOUTBOX must be in the system command range.
|
88 |
ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
|
89 |
ASSERT(IDM_ABOUTBOX < 0xF000);
|
90 |
|
91 |
CMenu* pSysMenu = GetSystemMenu(FALSE);
|
92 |
if (pSysMenu != NULL)
|
93 |
{
|
94 |
CString strAboutMenu;
|
95 |
strAboutMenu.LoadString(IDS_ABOUTBOX);
|
96 |
if (!strAboutMenu.IsEmpty())
|
97 |
{
|
98 |
pSysMenu->AppendMenu(MF_SEPARATOR);
|
99 |
pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
|
100 |
}
|
101 |
}
|
102 |
|
103 |
// Set the icon for this dialog. The framework does this automatically
|
104 |
// when the application's main window is not a dialog
|
105 |
SetIcon(m_hIcon, TRUE); // Set big icon
|
106 |
SetIcon(m_hIcon, FALSE); // Set small icon
|
107 |
|
108 |
m_tabs.InsertItem(0,"Search");
|
109 |
m_tabs.InsertItem(1,"Result");
|
110 |
m_tabs.InsertItem(2,"Administration");
|
111 |
m_tabs.Init();
|
112 |
m_tabs.SetCurSel(0);
|
113 |
|
114 |
|
115 |
try {
|
116 |
//DatabaseLayer *dbl = new DatabaseLayer;
|
117 |
DatabaseLayer *dbl = new MySQLLayer;
|
118 |
CommonStorage::Instance()->setDBLayer(dbl);
|
119 |
} catch (...) {
|
120 |
MessageBox(CString("Could not establish connection to the database server\r\n") +
|
121 |
"Please contact your network administrator\r\n" +
|
122 |
"(This application shuts down automatically)");
|
123 |
OnOK();
|
124 |
}
|
125 |
|
126 |
|
127 |
// TODO: Add extra initialization here
|
128 |
|
129 |
return TRUE; // return TRUE unless you set the focus to a control
|
130 |
}
|
131 |
|
132 |
void Ch6udlnssystemDlg::OnSysCommand(UINT nID, LPARAM lParam)
|
133 |
{
|
134 |
if ((nID & 0xFFF0) == IDM_ABOUTBOX)
|
135 |
{
|
136 |
CAboutDlg dlgAbout;
|
137 |
dlgAbout.DoModal();
|
138 |
}
|
139 |
else
|
140 |
{
|
141 |
CDialog::OnSysCommand(nID, lParam);
|
142 |
}
|
143 |
}
|
144 |
|
145 |
// If you add a minimize button to your dialog, you will need the code below
|
146 |
// to draw the icon. For MFC applications using the document/view model,
|
147 |
// this is automatically done for you by the framework.
|
148 |
|
149 |
void Ch6udlnssystemDlg::OnPaint()
|
150 |
{
|
151 |
if (IsIconic())
|
152 |
{
|
153 |
CPaintDC dc(this); // device context for painting
|
154 |
|
155 |
SendMessage(WM_ICONERASEBKGND, reinterpret_cast<WPARAM>(dc.GetSafeHdc()), 0);
|
156 |
|
157 |
// Center icon in client rectangle
|
158 |
int cxIcon = GetSystemMetrics(SM_CXICON);
|
159 |
int cyIcon = GetSystemMetrics(SM_CYICON);
|
160 |
CRect rect;
|
161 |
GetClientRect(&rect);
|
162 |
int x = (rect.Width() - cxIcon + 1) / 2;
|
163 |
int y = (rect.Height() - cyIcon + 1) / 2;
|
164 |
|
165 |
// Draw the icon
|
166 |
dc.DrawIcon(x, y, m_hIcon);
|
167 |
}
|
168 |
else
|
169 |
{
|
170 |
CDialog::OnPaint();
|
171 |
}
|
172 |
}
|
173 |
|
174 |
// The system calls this function to obtain the cursor to display while the user drags
|
175 |
// the minimized window.
|
176 |
HCURSOR Ch6udlnssystemDlg::OnQueryDragIcon()
|
177 |
{
|
178 |
return static_cast<HCURSOR>(m_hIcon);
|
179 |
}
|
180 |
|
181 |
void Ch6udlnssystemDlg::OnHelpAbout()
|
182 |
{
|
183 |
CAboutDlg about;
|
184 |
about.DoModal();
|
185 |
}
|
186 |
|
187 |
void Ch6udlnssystemDlg::OnFileExit()
|
188 |
{
|
189 |
// TODO: Add your command handler code here
|
190 |
OnOK();
|
191 |
}
|