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