📄 editortabledata.pas
字号:
if(Not(OutputClientDataSet.State=dsEdit))or
(Not(OutputClientDataSet.State=dsInsert))then
OutputClientDataSet.Edit;
//Open IniFile
theIni:=TIniFile.Create(ExtractFilePath(Application.ExeName)+
'Data'+PathDelim+DMMain.ProgName+'_Settings.ini');
try
theOpenDialog:=TOpenDialog.Create(nil);
try
{$IFDEF MSWINDOWS}
//On Windows use native Win32 Open Dlg
theOpenDialog.UseNativeDialog:=True;
theOpenDialog.OnShow:=DMMain.OnOpenSaveDlgShow;
{$ENDIF}
theOpenDialog.Title:='Open a File ...';
theOpenDialog.DefaultExt:='';
theOpenDialog.Filter:='All files (*.*)|*.*';
theOpenDialog.Width:=600;
theOpenDialog.Height:=450;
//Get last dir
RecentOpenBlobFieldDir:=theIni.ReadString('RecentDirectories', 'RecentOpenBlobFieldDir', '');
if(DirectoryExists(RecentOpenBlobFieldDir))then
theOpenDialog.InitialDir:=RecentOpenBlobFieldDir
else
theOpenDialog.InitialDir:='';
if(theOpenDialog.Execute)then
begin
RecentOpenBlobFieldDir:=ExtractFilePath(theOpenDialog.Filename);
if(DBGrid.SelectedField.ClassNameIs('TBlobField'))or
(DBGrid.SelectedField.ClassParent.ClassNameIs('TBlobField'))then
begin
DBImage.DataField:='';
DBMemo.DataField:='';
//Memo Field
if(DBGrid.SelectedField.ClassNameIs('TMemoField'))then
begin
TMemoField(DBGrid.SelectedField).LoadFromFile(theOpenDialog.Filename);
DBMemo.DataField:=DBGrid.Columns[DBGrid.SelectedIndex].FieldName;
end
else
//Blob or Image Field
begin
TBlobField(DBGrid.SelectedField).LoadFromFile(theOpenDialog.Filename);
thePicture:=TPicture.Create;
try
try
//try to open as Image
thePicture.LoadFromFile(theOpenDialog.Filename);
DBImage.DataField:=DBGrid.Columns[DBGrid.SelectedIndex].FieldName;
BlobPageControl.ActivePage:=ImgSheet;
except
BlobPageControl.ActivePage:=BlobSheet;
TBlobField(DBGrid.SelectedField).LoadFromFile(theOpenDialog.Filename);
DBGridColEnter(self);
end;
finally
thePicture.Free;
end;
end;
end;
{if(DBGrid.SelectedField.ClassNameIs('TMemoField'))then
TMemoField(DBGrid.SelectedField).LoadFromFile(theOpenDialog.Filename)
else if(DBGrid.SelectedField.ClassNameIs('TGraphicField'))then
TGraphicField(DBGrid.SelectedField).LoadFromFile(theOpenDialog.Filename)
else if(DBGrid.SelectedField.ClassNameIs('TBlobField'))then
TBlobField(DBGrid.SelectedField).LoadFromFile(theOpenDialog.Filename);}
theIni.WriteString('RecentDirectories', 'RecentOpenBlobFieldDir', RecentOpenBlobFieldDir);
end;
finally
theOpenDialog.Free;
end;
finally
theIni.Free;
end;
end;
procedure TEditorTableDataForm.SpeedButton1Click(Sender: TObject);
var theSaveDialog: TSaveDialog;
RecentSaveBlobFieldDir, theFileName: string;
theIni: TIniFile;
begin
if(DBGrid.SelectedField=nil)then
Exit;
if(Not(OutputClientDataSet.Active))then
Exit;
//Read IniFile
theIni:=TIniFile.Create(ExtractFilePath(Application.ExeName)+
'Data'+PathDelim+DMMain.ProgName+'_Settings.ini');
try
theSaveDialog:=TSaveDialog.Create(nil);
try
{$IFDEF MSWINDOWS}
//On Windows use native Win32 Open Dlg
theSaveDialog.UseNativeDialog:=True;
theSaveDialog.OnShow:=DMMain.OnOpenSaveDlgShow;
{$ENDIF}
theSaveDialog.Title:='Save Field As ...';
theSaveDialog.Width:=600;
theSaveDialog.Height:=450;
theSaveDialog.DefaultExt:='';
RecentSaveBlobFieldDir:=theIni.ReadString('RecentDirectories', 'RecentSaveBlobFieldDir', '');
if(Not(DirectoryExists(RecentSaveBlobFieldDir)))then
RecentSaveBlobFieldDir:=ExtractFilePath(Application.ExeName)+
'Models'+PathDelim;
theSaveDialog.InitialDir:=RecentSaveBlobFieldDir;
{theSaveDialog.Position:=Point((Screen.Width-theSaveDialog.Width) div 2,
(Screen.Height-theSaveDialog.Height) div 2);}
theSaveDialog.Filter:='All Files (*.*)|*.*';
if(theSaveDialog.Execute)then
begin
theFileName:=theSaveDialog.Filename;
if(FileExists(theFileName))then
if(MessageDlg('The file ['+ExtractFileName(theFileName)+'] '+
'already exists. '#13#10+
'Do you want to overwrite this file?', mtInformation,
[mbYes, mbNo], 0)=mrNo)then
Exit;
RecentSaveBlobFieldDir:=ExtractFilePath(theSaveDialog.FileName);
if(DBGrid.SelectedField.ClassNameIs('TMemoField'))then
TMemoField(DBGrid.SelectedField).SaveToFile(theFileName)
else if(DBGrid.SelectedField.ClassNameIs('TGraphicField'))then
TGraphicField(DBGrid.SelectedField).SaveToFile(theFileName)
else if(DBGrid.SelectedField.ClassNameIs('TBlobField'))then
TBlobField(DBGrid.SelectedField).SaveToFile(theFileName);
theIni.WriteString('RecentDirectories', 'RecentSaveBlobFieldDir', RecentSaveBlobFieldDir);
end;
finally
theSaveDialog.Free;
end;
finally
theIni.Free;
end;
end;
procedure TEditorTableDataForm.DBGridDblClick(Sender: TObject);
begin
if(Not(OpenBlobBtn.Enabled))then
RightPnlMouseDown(Self, mbLeft, [], 0, 0);
end;
procedure TEditorTableDataForm.OpenSQLPnlBtnClick(Sender: TObject);
begin
OpenSQLPnlBtn.Enabled:=False;
SQLSplitter.Visible:=True;
SQLSplitter.Left:=300;
SQLPnl.Width:=200;
end;
procedure TEditorTableDataForm.OpenBlobBtnClick(Sender: TObject);
begin
//Hide Blob Pnl
OpenBlobBtn.Enabled:=False;
BlobSplitter.Visible:=False;
BlobPnl.Width:=0;
end;
procedure TEditorTableDataForm.LeftPnlMouseDown(Sender: TObject;
Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
begin
//Show Blob Pnl
if(Not(OpenSQLPnlBtn.Enabled))then
begin
OpenSQLPnlBtn.Enabled:=True;
SQLSplitter.Visible:=False;
SQLPnl.Width:=0;
end;
end;
procedure TEditorTableDataForm.RightPnlMouseDown(Sender: TObject;
Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
begin
//Show Blob Pnl
if(Not(OpenBlobBtn.Enabled))then
begin
OpenBlobBtn.Enabled:=True;
BlobSplitter.Visible:=True;
BlobSplitter.Left:=300;
BlobPnl.Width:=240;
RightPnl.Left:=Width-10;
end;
end;
procedure TEditorTableDataForm.ClearSQLBtnClick(Sender: TObject);
begin
SQLMemo.Clear;
end;
procedure TEditorTableDataForm.LoadSQLBtnClick(Sender: TObject);
begin
//
end;
procedure TEditorTableDataForm.SaveSQLBtnClick(Sender: TObject);
begin
//
end;
procedure TEditorTableDataForm.ExecSQLBtnClick(Sender: TObject);
var i, Output: integer;
begin
//when not connected to DB, connect now
if(DMDB.CurrentDBConn=nil)then
begin
GetDBConnSBtnClick(self);
if(DMDB.CurrentDBConn=nil)then
Exit;
end
else
begin
DMDB.OutputQry.Close;
DMDB.OutputClientDataSet.Close;
DBGrid.DataSource:=DMDB.OutputDataSrc;
end;
//Trim all lines
for i:=0 to SQLMemo.Lines.Count-1 do
SQLMemo.Lines[i]:=Trim(SQLMemo.Lines[i]);
//Delete all rows from top which contain ''
while(SQLMemo.Lines.Count>1)and(SQLMemo.Lines[0]='')do
SQLMemo.Lines.Delete(0);
//if there is no sql statement, exit
if(SQLMemo.Text='')then
Exit;
Output:=1;
if((CompareText(Copy(SQLMemo.Lines[0], 1, 6), 'update')=0)
or(CompareText(Copy(SQLMemo.Lines[0], 1, 6), 'insert')=0)
or(CompareText(Copy(SQLMemo.Lines[0], 1, 6), 'delete')=0)
or(CompareText(Copy(SQLMemo.Lines[0], 1, 4), 'drop')=0)
or(CompareText(Copy(SQLMemo.Lines[0], 1, 5), 'alter')=0)
or(CompareText(Copy(SQLMemo.Lines[0], 1, 6), 'create')=0)
or(CompareText(Copy(SQLMemo.Lines[0], 1, 3), 'set')=0)
or(CompareText(Copy(SQLMemo.Lines[0], 1, 4), 'save')=0)
or(CompareText(Copy(SQLMemo.Lines[0], 1, 4), 'load')=0)
or(CompareText(Copy(SQLMemo.Lines[0], 1, 4), 'move')=0)
or(CompareText(Copy(SQLMemo.Lines[0], 1, 1), '<')=0)
or(CompareText(Copy(SQLMemo.Lines[0], 1, 1), '/')=0))then
Output:=0;
DMDB.OutputQry.SQL.Text:=SQLMemo.Text;
if(Output=0)then
begin
DMDB.OutputQry.ExecSQL(True);
DMGUI.SetStatusCaption('Query executed successfully.');
end
else if(Output=1)then
begin
DMDB.OutputQry.Open;
DMDB.OutputClientDataSet.Open;
DMGUI.SetStatusCaption('Query opened.');
end;
end;
procedure TEditorTableDataForm.SQLMemoDragDrop(Sender, Source: TObject; X,
Y: Integer);
var theTable: TEERTable;
theModel: TEERModel;
i, j, k, destTblNr, joinCount: integer;
theTableList: TList;
theTableAliases: TStringList;
s: string;
begin
if(Source<>nil)then
if(Source.ClassnameIs('TEERTable'))then
begin
s:='';
theTable:=TEERTable(Source);
theModel:=TEERModel(TEERTable(Source).Parent);
theTableList:=TList.Create;
theTableAliases:=TStringList.Create;
try
//Get all selected
for i:=0 to theModel.ComponentCount-1 do
if(theModel.Components[i].ClassName='TEERTable')then
if(TEERTable(theModel.Components[i]).Selected)then
theTableList.Add(theModel.Components[i]);
if(theTableList.Count=0)then
theTableList.Add(theTable);
for i:=0 to theTableList.Count-1 do
begin
j:=1;
while(theTableAliases.IndexOf(Copy(TEERTable(theTableList[i]).ObjName, 1, j))<>-1)and
(j<10)do
inc(j);
theTableAliases.Add(Copy(TEERTable(theTableList[i]).ObjName, 1, j));
end;
s:='SELECT * FROM ';
// list tables
for i:=0 to theTableList.Count-1 do
begin
s:=s+TEERTable(theTableList[i]).ObjName+' '+theTableAliases[i];
if(i<theTableList.Count-1)then
s:=s+', ';
end;
//make joins
if(theTableList.Count>1)then
begin
s:=s+#13#10+'WHERE ';
joinCount:=0;
for i:=0 to theTableList.Count-1 do
begin
for j:=0 to TEERTable(theTableList[i]).RelStart.Count-1 do
begin
destTblNr:=theTableList.IndexOf(TEERRel(TEERTable(theTableList[i]).RelStart[j]).DestTbl);
if(destTblNr<>-1)then
begin
for k:=0 to TEERRel(TEERTable(theTableList[i]).RelStart[j]).FKFields.Count-1 do
begin
if(joinCount>0)then
s:=s+' and ';
s:=s+theTableAliases[destTblNr]+'.'+
TEERRel(TEERTable(theTableList[i]).RelStart[j]).FKFields.ValueFromIndex[k]+'='+
theTableAliases[i]+'.'+
TEERRel(TEERTable(theTableList[i]).RelStart[j]).FKFields.Names[k];
inc(joinCount);
end;
end;
end;
end;
end;
finally
theTableList.Free;
theTableAliases.Free;
end;
SQLMemo.Text:=s;
end;
end;
procedure TEditorTableDataForm.SQLMemoDragOver(Sender, Source: TObject; X,
Y: Integer; State: TDragState; var Accept: Boolean);
begin
Accept:=False;
if(Source<>nil)then
if(Source.ClassnameIs('TEERTable'))then
Accept:=True;
end;
procedure TEditorTableDataForm.GetDBConn2SBtnClick(Sender: TObject);
begin
if(ActiveMDIChild<>nil)then
begin
if(ActiveMDIChild.Classname='TEERForm')then
begin
DMDB.GetDBConnButtonClick(Sender, TEERForm(TForm(Application.MainForm).ActiveMDIChild).EERModel.DefQueryDBConn);
if(DMDB.CurrentDBConn<>nil)then
TEERForm(ActiveMDIChild).EERModel.DefQueryDBConn:=DMDB.CurrentDBConn.Name;
end;
end
else
DMDB.GetDBConnButtonClick(Sender);
end;
end.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -