--- h6-udlÃ¥nssystemDlg.cpp 2006/08/30 08:01:57 4 +++ h6-udlÃ¥nssystemDlg.cpp 2006/09/11 14:02:08 53 @@ -1,11 +1,21 @@ -// h6-udlånssystemDlg.cpp : implementation file -// +/* + * Developed by Torben H. Nielsen + */ + #include "stdafx.h" #include "h6-udlånssystem.h" #include "h6-udlånssystemDlg.h" #include ".\h6-udlånssystemdlg.h" +#include "ConfigFile.h" +#include "commonstorage.h" + +#include "databaselayer.h" +#include "microsoftdblayer.h" +#include "mysqllayer.h" +#include "postgreslayer.h" + #ifdef _DEBUG #define new DEBUG_NEW #endif @@ -64,6 +74,7 @@ ON_WM_QUERYDRAGICON() //}}AFX_MSG_MAP ON_COMMAND(ID_HELP_ABOUT, OnHelpAbout) + ON_COMMAND(ID_FILE_EXIT, OnFileExit) END_MESSAGE_MAP() @@ -72,6 +83,7 @@ BOOL Ch6udlnssystemDlg::OnInitDialog() { CDialog::OnInitDialog(); + CWaitCursor wait; // Add "About..." menu item to system menu. @@ -102,6 +114,40 @@ m_tabs.Init(); m_tabs.SetCurSel(0); + ConfigFile config; + try { + config.Read(); + } catch(...) { + MessageBox("Could not open config file"); + OnOK(); + return true; + } + + try { + DatabaseLayer *dbl = 0; + if (config.driver.MakeLower() == "mysql") + dbl = new MySQLLayer(config); + else if (config.driver.MakeLower() == "postgresql") + dbl = new PostgresLayer(config); + else if (config.driver.MakeLower() == "microsoftsql") + dbl = new MicrosoftDBLayer(config); + else { + CString tmp; + tmp.Format("Unsupported driver: %s", config.driver); + MessageBox(tmp); + OnOK(); + } + CommonStorage::Instance()->setDBLayer(dbl); + } catch (...) { + MessageBox(CString("Could not establish connection to the database server\r\n") + + "Please contact your network administrator"); + OnOK(); + } + + CString title = "H6-Udlånssystem - "; + title += config.driver; + SetWindowText(title); + // TODO: Add extra initialization here return TRUE; // return TRUE unless you set the focus to a control @@ -158,5 +204,12 @@ void Ch6udlnssystemDlg::OnHelpAbout() { - MessageBox("DA6H :: Udlånssystem\r\nLavet af:\r\nKevin, Hedin & Torben"); + CAboutDlg about; + about.DoModal(); +} + +void Ch6udlnssystemDlg::OnFileExit() +{ + // TODO: Add your command handler code here + OnOK(); }