forked from sanelson/dbdesigner-fork
/
EERSynchronisation.pas
231 lines (194 loc) · 6.91 KB
/
EERSynchronisation.pas
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
unit EERSynchronisation;
//----------------------------------------------------------------------------------------------------------------------
//
// This file is part of fabFORCE DBDesigner4.
// Copyright (C) 2002 Michael G. Zinner, www.fabFORCE.net
//
// DBDesigner4 is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2 of the License, or
// (at your option) any later version.
//
// DBDesigner4 is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License
// along with DBDesigner4; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
//
//----------------------------------------------------------------------------------------------------------------------
//
// Unit EERSynchronisation.pas
// ---------------------------
// Version 1.1, 20.03.2003, Mike
// Description
// Contains a visual interface for the DB Syncronisation functions
//
// Changes:
// Version 1.1, 20.03.2003, Mike
// rename the form, the file and the window caption from
// syncronisatin to synchronisation
// Version 1.0, 13.03.2003, Mike
// initial version
//
//----------------------------------------------------------------------------------------------------------------------
interface
uses
SysUtils, Types, Classes, LResources, Graphics, Controls, Forms, Dialogs,
StdCtrls, ExtCtrls, Buttons, EERModel, ComCtrls;
type
TEERSynchronisationForm = class(TForm)
StatusPnl: TPanel;
ConnectionSBtn: TSpeedButton;
StatusLbl: TLabel;
ProgressGroupBox: TGroupBox;
ProgressMemo: TMemo;
BottomPnl: TPanel;
SubmitBtn: TSpeedButton;
CancelBtn: TSpeedButton;
Bevel1: TBevel;
TopPnl: TPanel;
DBConnEd: TEdit;
Label1: TLabel;
GetDBConnSBtn: TSpeedButton;
GroupBox1: TGroupBox;
Bevel2: TBevel;
ChangeDBRBtn: TRadioButton;
ChangeModelRBtn: TRadioButton;
KeepExistingTabelsCBox: TCheckBox;
StdInsertsCBox: TCheckBox;
SyncStdInsertsCBox: TCheckBox;
LeftPnl: TPanel;
Panel2: TPanel;
procedure FormCreate(Sender: TObject);
procedure FormClose(Sender: TObject; var Action: TCloseAction);
procedure FormDestroy(Sender: TObject);
procedure FormShow(Sender: TObject);
function SetData(theModel: TEERModel): Boolean;
procedure GetDBConnSBtnClick(Sender: TObject);
procedure CancelBtnClick(Sender: TObject);
procedure SubmitBtnClick(Sender: TObject);
procedure FormKeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
procedure FormResize(Sender: TObject);
private
{ Private-Deklarationen }
public
{ Public-Deklarationen }
EERModel: TEERModel;
end;
var
EERSynchronisationForm: TEERSynchronisationForm;
implementation
uses MainDM, EERDM, DBDM, DBEERDM;
// {$R *.xfm}
{$mode delphi}{$H+}
procedure TEERSynchronisationForm.FormCreate(Sender: TObject);
begin
DMMain.InitForm(self);
end;
procedure TEERSynchronisationForm.FormClose(Sender: TObject;
var Action: TCloseAction);
begin
//
end;
procedure TEERSynchronisationForm.FormDestroy(Sender: TObject);
begin
//
end;
procedure TEERSynchronisationForm.FormShow(Sender: TObject);
begin
{Left:=(Screen.Width-Width) div 2;
Top:=(Screen.Height-Height) div 2;}
end;
function TEERSynchronisationForm.SetData(theModel: TEERModel): Boolean;
begin
EERModel:=theModel;
GetDBConnSBtnClick(self);
//When not connected, close
SetData:=(DMDB.CurrentDBConn<>nil);
end;
procedure TEERSynchronisationForm.GetDBConnSBtnClick(Sender: TObject);
var SelDBConn: TDBConn;
theTables: TStringList;
begin
DBConnEd.Text:='';
if(Sender.ClassNameIs('TSpeedButton'))then
DMDB.DisconnectFromDB;
StatusLbl.Caption:=DMMain.GetTranslatedMessage('Not connected to a Database', 27);
ConnectionSBtn.Enabled:=False;
SubmitBtn.Enabled:=False;
//do until a successful connection is established or the user selects abort
while(1=1)do
begin
//Let the User choose connection if there is no open connection
if(DMDB.CurrentDBConn=nil)or(EERModel.DefSyncDBConn<>DMDB.CurrentDBConn.Name)then
SelDBConn:=DMDB.GetUserSelectedDBConn(EERModel.DefSyncDBConn)
else
SelDBConn:=DMDB.CurrentDBConn;
if(SelDBConn<>nil)then
begin
//Try to connect to the DB
try
DMDB.ConnectToDB(SelDBConn);
except
on x: Exception do
begin
MessageDlg(DMMain.GetTranslatedMessage('Connection to database failed.'+#13#10#13#10+'%s', 121,
x.Message), mtError, [mbOK], 0);
continue;
end;
end;
ConnectionSBtn.Enabled:=True;
SubmitBtn.Enabled:=True;
DBConnEd.Text:=DMDB.CurrentDBConn.Name;
StatusLbl.Caption:=DMMain.GetTranslatedMessage('Connected to Database %s', 28,
DMDB.CurrentDBConn.Params.Values['User_Name']+'@'+
DMDB.CurrentDBConn.Params.Values['Database']);
ProgressMemo.Lines.Add(DMMain.GetTranslatedMessage('Connected to Database %s', 28,
DMDB.CurrentDBConn.Params.Values['User_Name']+'@'+
DMDB.CurrentDBConn.Params.Values['Database']));
theTables:=TStringList.Create;
try
DMDB.GetDBTables(theTables);
//Ignore DBDesigner4 table
if(theTables.IndexOf('DBDesigner4')<>-1)then
theTables.Delete(theTables.IndexOf('DBDesigner4'));
ProgressMemo.Lines.Add(DMMain.GetTranslatedMessage('%s Table(s) in Database, '+
'%s Table(s) in Model.', 221,
IntToStr(theTables.Count), IntToStr(EERModel.GetEERObjectCount([EERTable])))+#13#10+
'-------------------------------------');
finally
theTables.Free;
end;
break;
end
else
break;
end;
end;
procedure TEERSynchronisationForm.CancelBtnClick(Sender: TObject);
begin
ModalResult:=mrAbort;
end;
procedure TEERSynchronisationForm.SubmitBtnClick(Sender: TObject);
begin
EERModel.DefSyncDBConn:=DMDB.CurrentDBConn.Name;
DMDBEER.EERMySQLSyncDB(EERModel, DMDB.CurrentDBConn, ProgressMemo.Lines, KeepExistingTabelsCBox.Checked, StdInsertsCBox.Checked, SyncStdInsertsCBox.Checked);
end;
procedure TEERSynchronisationForm.FormKeyDown(Sender: TObject;
var Key: Word; Shift: TShiftState);
begin
if(Key=Key_F1)then
DMMain.ShowHelp('db', 'dbsync');
end;
procedure TEERSynchronisationForm.FormResize(Sender: TObject);
begin
ProgressMemo.Width:=ProgressGroupBox.Width-34;
ProgressMemo.Height:=ProgressGroupBox.Height-37;
end;
end.
initialization
{$I EERSynchronisation.lrs}
end.