]> git.saurik.com Git - wxWidgets.git/blame - demos/dbbrowse/doc.cpp
Added wxDbTable::SetOrderByColNums() function
[wxWidgets.git] / demos / dbbrowse / doc.cpp
Content-type: text/html ]> git.saurik.com Git - wxWidgets.git/blame - demos/dbbrowse/doc.cpp


500 - Internal Server Error

Malformed UTF-8 character (fatal) at /usr/lib/x86_64-linux-gnu/perl5/5.40/HTML/Entities.pm line 485, <$fd> line 752.
CommitLineData
c92b0f9a 1//----------------------------------------------------------------------------------------
b5ffecfc 2// Name: Doc.cpp
c92b0f9a 3// Purpose: Holds information for DBBrowser - (a do-it-yourself document)
b5ffecfc
GT
4// Author: Mark Johnson, mj10777@gmx.net
5// Modified by: 19990808.mj10777
6// BJO : Bart A.M. JOURQUIN
7// Created: 19990808
8// Copyright: (c) Mark Johnson
9// Licence: wxWindows license
c09d434d 10// RCS-ID: $Id$
c92b0f9a
MJ
11//----------------------------------------------------------------------------------------
12//-- all #ifdefs that the whole Project needs. -------------------------------------------
13//----------------------------------------------------------------------------------------
b5ffecfc 14#ifdef __GNUG__
b5ce269b
BJ
15#pragma implementation
16#pragma interface
b5ffecfc 17#endif
c92b0f9a 18//----------------------------------------------------------------------------------------
b5ffecfc
GT
19// For compilers that support precompilation, includes "wx/wx.h".
20#include "wx/wxprec.h"
c92b0f9a 21//----------------------------------------------------------------------------------------
b5ffecfc 22#ifdef __BORLANDC__
b5ce269b 23#pragma hdrstop
b5ffecfc 24#endif
c92b0f9a 25//----------------------------------------------------------------------------------------
b5ffecfc 26#ifndef WX_PRECOMP
b5ce269b 27#include "wx/wx.h"
b5ffecfc 28#endif
c92b0f9a
MJ
29//----------------------------------------------------------------------------------------
30//-- all #includes that every .cpp needs ----19990807.mj10777 ----------------
31//----------------------------------------------------------------------------------------
b5ffecfc 32#include "std.h" // sorgsam Pflegen !
c92b0f9a
MJ
33//----------------------------------------------------------------------------------------
34//-- Some Global Vars for all Files (extern in ?.h needed) -------------------------------
b5ffecfc 35// Global structure for holding ODBC connection information
e2f1cfb2 36wxDbConnectInf DbConnectInf;
c92b0f9a 37//----------------------------------------------------------------------------------------
b5ffecfc
GT
38wxConfigBase *p_ProgramCfg; // All Config and Path information
39wxLogTextCtrl *p_LogBook; // All Log messages
40wxString LogBuf; // String for all Logs
c92b0f9a 41//----------------------------------------------------------------------------------------
3fa0976a 42MainDoc::MainDoc()
b5ffecfc 43{
c92b0f9a
MJ
44 db_Br = NULL;
45 p_DSN = NULL;
46 i_DSN = 0;
47 p_Splitter = NULL;
48 p_MainFrame = NULL;
49 p_PgmCtrl = NULL; // Is not active
50 p_DBTree = NULL;
51 p_DBGrid = NULL;
52 p_LogWin = NULL;
53 p_TabArea = NULL;
54 p_PageArea = NULL;
55 i_TabNr = 0;
56 i_PageNr = 0;
57 s_BColour = "WHEAT";
58 ft_Doc = new wxFont(wxSystemSettings::GetSystemFont(wxSYS_SYSTEM_FONT));
b5ffecfc 59}
c92b0f9a 60//----------------------------------------------------------------------------------------
3fa0976a 61MainDoc::~MainDoc()
b5ffecfc 62{
c92b0f9a
MJ
63 // ----------------------------------------------------------
64 // -E-> The Tree Controls take to long to close : Why ??
65 // ----------------------------------------------------------
ca7408bd
MJ
66 delete ft_Doc;
67 ft_Doc = NULL;
c92b0f9a
MJ
68 p_TabArea->Show(FALSE); // Deactivate the Window
69 p_PageArea->Show(FALSE); // Deactivate the Window
70 p_PgmCtrl = NULL;
71 delete p_PgmCtrl;
72 delete [] p_DSN;
73 delete p_DBTree;
74 p_TabArea = NULL; delete p_TabArea;
75 p_PageArea = NULL; delete p_PageArea;
76 p_Splitter = NULL;
77 delete p_Splitter;
78 delete [] db_Br;
3fa0976a 79 // wxMessageBox("~MainDoc");
b5ffecfc 80}
c92b0f9a 81//----------------------------------------------------------------------------------------
3fa0976a 82bool MainDoc::OnNewDocument()
b5ffecfc 83{
897d36c2 84 wxStopWatch sw;
c92b0f9a
MJ
85 //---------------------------------------------------------------------------------------
86 if (!OnInitView())
c92b0f9a 87 return FALSE;
c92b0f9a
MJ
88 p_PgmCtrl->OnPopulate();
89 //---------------------------------------------------------------------------------------
3fa0976a 90 wxLogMessage(_("-I-> MainDoc::OnNewDocument() - End - Time needed : %ld ms"),sw.Time());
c92b0f9a 91 return TRUE;
b5ffecfc 92}
c92b0f9a 93//----------------------------------------------------------------------------------------
3fa0976a 94bool MainDoc::OnInitView()
b5ffecfc 95{
c92b0f9a 96 Sash = p_ProgramCfg->Read("/MainFrame/Sash", 200);
3fa0976a 97 // wxMessageBox("OnInitView() - Begin ","-I->MainDoc::OnInitView");
c92b0f9a
MJ
98 //---------------------------------------------------------------------------------------
99 // create "workplace" window
100 //---------------------------------------------------------------------------------------
101 p_TabArea = new wxTabbedWindow(); // Init the Pointer
102 p_TabArea->Create(p_Splitter, -1);
103 //---------------------------------------------------------------------------------------
104 p_PgmCtrl = new PgmCtrl(p_TabArea, TREE_CTRL_PGM,wxDefaultPosition, wxDefaultSize,
105 wxTR_HAS_BUTTONS | wxSUNKEN_BORDER);
106 p_PgmCtrl->i_TabArt = 0; // 0 = Tab ; 1 = Page
107 p_PgmCtrl->i_ViewNr = p_TabArea->GetTabCount()-1;
108 //---------------------------------------------------------------------------------------
109 wxBitmap *p_FolderClose = new wxBitmap("PgmCtrl"); //, wxBITMAP_TYPE_BMP_RESOURCE); // BJO20000115
110 //---------------------------------------------------------------------------------------
111 p_TabArea->AddTab(p_PgmCtrl,"PgmCtrl",p_FolderClose);
ca7408bd
MJ
112 delete p_FolderClose; // Memory leak
113 p_FolderClose = NULL;
c92b0f9a
MJ
114 //---------------------------------------------------------------------------------------
115 // now create "output" window
116 //---------------------------------------------------------------------------------------
117 p_PageArea = new wxPaggedWindow(); // Init the Pointer
118 p_PageArea->Create(p_Splitter, -1);
119 //---------------------------------------------------------------------------------------
120 p_LogWin = new wxTextCtrl(p_PageArea,-1,wxEmptyString,
121 wxDefaultPosition, wxDefaultSize,wxTE_MULTILINE );
897d36c2 122 p_LogWin->SetFont(* ft_Doc);
c92b0f9a
MJ
123 // Don't forget ! This is always : i_TabArt = 0 ; i_ViewNr = 1;
124 //---------------------------------------------------------------------------------------
125 p_LogBook = new wxLogTextCtrl(p_LogWin); // make p_LogWin the LogBook
126 p_LogBook->SetActiveTarget(p_LogBook);
127 p_LogBook->SetTimestamp( NULL );
128 //---------------------------------------------------------------------------------------
129 p_PageArea->AddTab(p_LogWin,_("LogBook"), "what is this?" );
130 i_TabNr = p_TabArea->GetTabCount()-1; // Add one when a new AddTab is done;
131 i_PageNr = p_PageArea->GetTabCount()-1; // Add one when a new AddTab is done;
132 //---------------------------------------------------------------------------------------
133 p_PgmCtrl->pDoc = this;
134 p_TabArea->SetActiveTab(i_PageNr);
135 //---------------------------------------------------------------------------------------
136 p_Splitter->Initialize(p_TabArea);
137 p_Splitter->SplitHorizontally(p_TabArea,p_PageArea,Sash);
138 //---------------------------------------------------------------------------------------
36ba4665
MJ
139 // if (!OnInitODBC())
140 // return FALSE;
141 OnInitODBC();
c92b0f9a 142 //---------------------------------------------------------------------------------------
3fa0976a 143 Temp0.Printf(_("-I-> MainDoc::OnInitView() - End - %d DSN's found"),i_DSN);
c92b0f9a
MJ
144 p_MainFrame->SetStatusText(Temp0, 0);
145 wxLogMessage(Temp0);
146 return TRUE;
b5ffecfc
GT
147}
148//----------------------------------------------------------------------------------------
3fa0976a 149bool MainDoc::OnInitODBC()
b5ffecfc 150{
c92b0f9a
MJ
151 char Dsn[SQL_MAX_DSN_LENGTH + 1];
152 char DsDesc[255]; // BJO20002501 instead of 512
153 Temp0 = "";
154 i_DSN = 0; // Counter
155 int i = 0;
156 //---------------------------------------------------------------------------------------
157 // Initialize the ODBC Environment for Database Operations
158
159 if (SQLAllocEnv(&DbConnectInf.Henv) != SQL_SUCCESS)
160 {
161 return FALSE;
162 }
163 //---------------------------------------------------------------------------------------
164 const char sep = 3; // separator character used in string between DSN ans DsDesc
165 wxStringList s_SortDSNList, s_SortDsDescList;
166 // BJO-20000127
167 // In order to have same sort result on both Dsn and DsDesc, create a 'keyed' string.
168 // The key will be removed after sorting
169 wxString KeyString;
170 //---------------------------------------------------------------------------------------
df991b9d 171 while(wxDbGetDataSource(DbConnectInf.Henv, Dsn, sizeof(Dsn), DsDesc, sizeof(DsDesc)))
c92b0f9a
MJ
172 {
173 i_DSN++; // How many Dsn have we ?
174 KeyString.Printf("%s%c%s",Dsn, sep, DsDesc);
175 s_SortDSNList.Add(Dsn);
176 s_SortDsDescList.Add(KeyString);
177 }
178 s_SortDSNList.Sort(); //BJO
179 s_SortDsDescList.Sort(); //BJO
180
181 char ** s_SortDSN = s_SortDSNList.ListToArray(); //BJO
182 char ** s_SortDsDesc = s_SortDsDescList.ListToArray(); //BJO
183 //---------------------------------------------------------------------------------------
184 // Allocate n ODBC-DSN objects to hold the information
185 p_DSN = new DSN[i_DSN]; //BJO
186 for (i=0;i<i_DSN;i++)
187 {
188 KeyString = s_SortDsDesc[i];
189 KeyString = KeyString.AfterFirst(sep);
190 strcpy(s_SortDsDesc[i],KeyString.c_str());
191 (p_DSN+i)->Dsn = s_SortDSN[i];
192 (p_DSN+i)->Drv = s_SortDsDesc[i];
193 (p_DSN+i)->Usr = "";
194 (p_DSN+i)->Pas = "";
195 Temp0.Printf("%02d) Dsn(%s) DsDesc(%s)",i,(p_DSN+i)->Dsn.c_str(),(p_DSN+i)->Drv.c_str());
196 wxLogMessage(Temp0);
197 }
198 i = 0;
199 //---------------------------------------------------------------------------------------
200 // Allocate n wxDatabase objects to hold the column information
201 db_Br = new BrowserDB[i_DSN];
202 for (i=0;i<i_DSN;i++)
203 {
204 (db_Br+i)->p_LogWindow = p_LogWin;
205 (db_Br+i)->ODBCSource = (p_DSN+i)->Dsn;
206 (db_Br+i)->UserName = (p_DSN+i)->Usr;
207 (db_Br+i)->Password = (p_DSN+i)->Pas;
208 (db_Br+i)->pDoc = this;
209 (db_Br+i)->i_Which = i;
210 }
30bb7c13 211 if (SQLFreeEnv(DbConnectInf.Henv) != SQL_SUCCESS) // BJO20000125 / MJ10777.20000309 : no &
c92b0f9a
MJ
212 {
213 // Error freeing environment handle
214 }
215 delete [] s_SortDSN;
216 delete [] s_SortDsDesc;
217 //---------------------------------------------------------------------------------------
218 if (!i_DSN)
219 {
220 wxMessageBox(_("No Dataset names found in ODBC!\n" \
221 " Program will exit!\n\n" \
222 " Ciao"),"-E-> Fatal situation");
223 return FALSE;
224 }
225 //---------------------------------------------------------------------------------------
226 return TRUE;
b5ffecfc
GT
227}
228//----------------------------------------------------------------------------------------
3fa0976a 229bool MainDoc::OnChosenDSN(int Which)
b5ffecfc 230{
c92b0f9a
MJ
231 // wxLogMessage("OnChosenDSN(%d) - Begin",Which);
232 //---------------------------------------------------------------------------------------
233 if (p_DBTree != NULL)
234 {
b5ffecfc 235 p_TabArea->Show(FALSE); // Deactivate the Window
c92b0f9a
MJ
236 p_TabArea->RemoveTab(p_DBTree->i_ViewNr);
237 p_TabArea->Show(TRUE); // Activate the Window
238 OnChosenTbl(77,"");
239 }
240 //-------------------------
241 p_TabArea->Show(FALSE); // Deactivate the Window
242 p_DBTree = new DBTree(p_TabArea, TREE_CTRL_DB,wxDefaultPosition, wxDefaultSize,
243 wxTR_HAS_BUTTONS | wxSUNKEN_BORDER);
244 p_TabArea->AddTab(p_DBTree,(p_DSN+Which)->Dsn," ? ");
245 p_DBTree->i_ViewNr = p_TabArea->GetTabCount()-1;
246 p_TabArea->Show(TRUE); // Deactivate the Window
247 p_DBTree->i_Which = Which;
248 p_DBTree->s_DSN = (p_DSN+Which)->Dsn;
249 p_DBTree->i_TabArt = 0;
250 p_DBTree->pDoc = this;
251 p_DBTree->OnPopulate();
252 p_TabArea->SetActiveTab(p_DBTree->i_ViewNr);
253 //---------------------------------------------------------------------------------------
254 // wxLogMessage("OnChosenDSN(%d) - End",Which);
255 return TRUE;
b5ffecfc
GT
256}
257//----------------------------------------------------------------------------------------
3fa0976a 258bool MainDoc::OnChosenTbl(int Tab,wxString Table)
b5ffecfc 259{
c92b0f9a
MJ
260 // wxLogMessage("OnChosenTbl(%d,%s)",Tab,Table.c_str());
261 //-------------------------
262 if (p_DBGrid != NULL)
263 {
264 if (p_DBGrid->i_TabArt == 0)
265 {
266 p_TabArea->Show(FALSE); // Deactivate the Window
267 p_TabArea->RemoveTab(p_DBGrid->i_ViewNr);
268 p_TabArea->Show(TRUE); // Activate the Window
269 }
270 if (p_DBGrid->i_TabArt == 1)
271 {
272 p_PageArea->Show(FALSE); // Deactivate the Window
273 p_PageArea->RemoveTab(p_DBGrid->i_ViewNr);
274 p_PageArea->Show(TRUE); // Activate the Window
275 }
276 p_DBGrid = NULL;
277 delete p_DBGrid;
278 }
279 if (Tab == 77) // Delete only
280 return TRUE;
281 //-------------------------
282 if (Tab == 0) // Tabview
283 {
284 p_TabArea->Show(FALSE); // Deactivate the Window
285 p_DBGrid = new DBGrid(p_TabArea,GRID_CTRL_DB,wxDefaultPosition, wxDefaultSize,
286 wxSUNKEN_BORDER);
287 p_TabArea->AddTab(p_DBGrid, Table, "");
288 p_DBGrid->i_ViewNr = p_TabArea->GetTabCount()-1;
289 p_DBGrid->pDoc = this;
290 p_DBGrid->db_Br = db_Br;
291 p_DBGrid->OnTableView(Table);
292 p_TabArea->SetActiveTab(p_DBGrid->i_ViewNr);
293 p_TabArea->Show(TRUE); // Activate the Window
294 }
295 if (Tab == 1) // Pageview
296 {
297 p_PageArea->Show(FALSE); // Deactivate the Window
298 p_DBGrid = new DBGrid(p_PageArea,GRID_CTRL_DB,wxDefaultPosition, wxDefaultSize,
299 wxSUNKEN_BORDER);
300 p_PageArea->AddTab(p_DBGrid, Table, "");
301 p_DBGrid->i_ViewNr = p_PageArea->GetTabCount()-1;
302 p_DBGrid->pDoc = this;
303 p_DBGrid->db_Br = db_Br;
304 p_DBGrid->i_Which = p_DBTree->i_Which;
305 p_PageArea->Show(TRUE); // Activate the Window
306 p_DBGrid->OnTableView(Table);
307 p_PageArea->SetActiveTab(p_DBGrid->i_ViewNr);
308 }
309 p_DBGrid->i_TabArt = Tab;
310 //--------------------------
311 return TRUE;;
b5ffecfc
GT
312}
313//----------------------------------------------------------------------------------------
3fa0976a 314void MainDoc::OnLeer(wxString Aufrufer)
b5ffecfc 315{
3fa0976a
MJ
316