--- h6-udlÃ¥nssystemDlg.cpp 2006/08/30 21:57:57 9 +++ h6-udlÃ¥nssystemDlg.cpp 2006/09/11 14:02:08 53 @@ -1,13 +1,20 @@ -// 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 @@ -76,6 +83,7 @@ BOOL Ch6udlnssystemDlg::OnInitDialog() { CDialog::OnInitDialog(); + CWaitCursor wait; // Add "About..." menu item to system menu. @@ -106,10 +114,39 @@ m_tabs.Init(); m_tabs.SetCurSel(0); + ConfigFile config; + try { + config.Read(); + } catch(...) { + MessageBox("Could not open config file"); + OnOK(); + return true; + } - DatabaseLayer *dbl = new DatabaseLayer; - CommonStorage::Instance()->setDBLayer(dbl); + 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 @@ -167,7 +204,8 @@ void Ch6udlnssystemDlg::OnHelpAbout() { - MessageBox("DA6H :: Udlånssystem\r\nLavet af:\r\nKevin, Hedin & Torben"); + CAboutDlg about; + about.DoModal(); } void Ch6udlnssystemDlg::OnFileExit()