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