📄 eerexportimportdm.pas
字号:
theIndex.IndexKind:=ik_UNIQUE_INDEX
else
theIndex.IndexKind:=ik_INDEX;
theIndex.Pos:=theTbl.Indices.Count;
theTbl.Indices.Add(theIndex);
for k:=0 to theDoc.Model.Entity_Groups[i].Key_Group_Groups.Key_Group[j].Key_Group_Member_Groups.Count-1 do
begin
for l:=0 to theTbl.Columns.Count-1 do
if(theDoc.Model.Entity_Groups[i].Key_Group_Groups.Key_Group[j].Key_Group_Member_Groups.Key_Group_Member[k].Key_Group_MemberProps.Key_Group_Member_Column=
TEERColumn(theTbl.Columns[l]).tmp)then
begin
theIndex.Columns.Add(IntToStr(TEERColumn(theTbl.Columns[l]).Obj_id));
break;
end;
end;
end;
theTbl.RefreshStrechedImg:=True;
end;
//Get Relations
for i:=0 to theDoc.Model.Relationship_Groups.Count-1 do
begin
inc(NewRelCounter);
theRel:=TEERRel.Create(theModel, 'Rel_'+FormatFloat('00', NewRelCounter));
theRel.Obj_id:=DMMain.GetNextGlobalID;
theRel.ObjName:=theDoc.Model.Relationship_Groups.Relationship[i].RelationshipProps.Name;
if(Trim(theRel.ObjName)='')then
theRel.ObjName:=theDoc.Model.Relationship_Groups.Relationship[i].Name;
if(Trim(theRel.ObjName)='')then
theRel.ObjName:=theRel.Name;
theRel.Comments:=theDoc.Model.Relationship_Groups.Relationship[i].RelationshipProps.Note;
if(theDoc.Model.Relationship_Groups.Relationship[i].RelationshipProps.Type_=2)then
theRel.RelKind:=rk_1n
else
theRel.RelKind:=rk_1nNonId;
//SrcTable
for j:=0 to theModel.ComponentCount-1 do
if(theModel.Components[j].ClassNameIs('TEERTable'))then
if(TEERTable(theModel.Components[j]).tmp=
theDoc.Model.Relationship_Groups.Relationship[i].RelationshipProps.Relationship_Parent_Entity)then
begin
theRel.SrcTbl:=TEERTable(theModel.Components[j]);
break;
end;
//DestTable
for j:=0 to theModel.ComponentCount-1 do
if(theModel.Components[j].ClassNameIs('TEERTable'))then
if(TEERTable(theModel.Components[j]).tmp=
theDoc.Model.Relationship_Groups.Relationship[i].RelationshipProps.Relationship_Child_Entity)then
begin
theRel.DestTbl:=TEERTable(theModel.Components[j]);
break;
end;
//Add relation to Tables
theRel.SrcTbl.RelStart.Add(theRel);
theRel.DestTbl.RelEnd.Add(theRel);
//Display at the right pos and size
theRel.SrcTbl.RefreshRelations;
theRel.DestTbl.RefreshRelations;
end;
except
on x: Exception do
begin
ShowMessage('An Error occurred while reading Tables from XML File:'+#13#10#13#10+
'Error: '+x.Message);
end;
end;
finally
end;
theModel.ModelHasChanged;
theModel.Refresh;
DMEER.RefreshPalettes;
finally
theSubstList.Free;
end;
finally
theIniFile.Free;
end;
{$ENDIF}
end;
procedure TDMEERExportImport.ExportMDBXMLFile(theModel: TEERModel; fname: string);
var theFile: Textfile;
theDBInfo: TMemIniFile;
theDatatypeMappings, theInserts: TStringList;
i, j, k: integer;
theObjList: TList;
physicalDatatypeName, s: string;
begin
AssignFile(theFile, fname);
Rewrite(theFile);
try
theDatatypeMappings:=TStringList.Create;
theInserts:=TStringList.Create;
try
theDBInfo:=TMemIniFile.Create(DMMain.SettingsPath+'DBDesigner4_DatabaseInfo.ini');
try
theDBInfo.ReadSectionValues(theModel.DatabaseType+'_MDB_DatatypeSubst', theDatatypeMappings);
finally
theDBInfo.Free;
end;
WriteLn(theFile, '<?xml version="1.0" encoding="ISO-8859-1" ?>');
WriteLn(theFile, '<!--'+ExtractFileName(fname)+#13#10+
'Generated '+FormatDateTime('yyyy-mm-dd hh:nn', Now)+#13#10+
'-->');
WriteLn(theFile, '<database>');
WriteLn(theFile, '<name>'+theModel.GetModelName+'</name>');
WriteLn(theFile, '<create>1</create>');
theObjList:=TList.Create;
try
theModel.GetEERObjectList([EERTable], theObjList);
theModel.SortEERObjectListByObjName(theObjList);
for i:=0 to theObjList.Count-1 do
begin
WriteLn(theFile, '<table>');
WriteLn(theFile, '<name>'+TEERTable(theObjList[i]).ObjName+'</name>');
WriteLn(theFile, '<declaration>');
//Columns
for j:=0 to TEERTable(theObjList[i]).Columns.Count-1 do
begin
WriteLn(theFile, '<field>');
WriteLn(theFile, '<name>'+TEERColumn(TEERTable(theObjList[i]).Columns[j]).ColName+'</name>');
//Datatype mapped
physicalDatatypeName:=TEERDatatype(theModel.GetDataType(TEERColumn(TEERTable(theObjList[i]).Columns[j]).iddatatype)).GetPhysicalTypeName;
//if there is a ( in the physicalDatatypeName, truncate physicalDatatypeName
if(Pos('(', physicalDatatypeName)>0)then
physicalDatatypeName:=Copy(physicalDatatypeName, 1, Pos('(', physicalDatatypeName)-1);
WriteLn(theFile, '<type>'+theDatatypeMappings.Values[physicalDatatypeName]+'</type>');
//Default Value
WriteLn(theFile, '<default>'+TEERColumn(TEERTable(theObjList[i]).Columns[j]).DefaultValue+'</default>');
WriteLn(theFile, '<notnull>'+IntToStr(Ord(TEERColumn(TEERTable(theObjList[i]).Columns[j]).NotNull=True))+'</notnull>');
WriteLn(theFile, '</field>');
end;
//Indices
for j:=0 to TEERTable(theObjList[i]).Indices.Count-1 do
begin
WriteLn(theFile, '<index>');
WriteLn(theFile, '<name>'+TEERIndex(TEERTable(theObjList[i]).Indices[j]).IndexName+'</name>');
if(TEERIndex(TEERTable(theObjList[i]).Indices[j]).IndexKind=ik_PRIMARY)or
(TEERIndex(TEERTable(theObjList[i]).Indices[j]).IndexKind=ik_UNIQUE_INDEX)then
WriteLn(theFile, '<unique>1</unique>')
else
WriteLn(theFile, '<unique>0</unique>');
WriteLn(theFile, '<field>');
//Index fields
for k:=0 to TEERIndex(TEERTable(theObjList[i]).Indices[j]).Columns.Count-1 do
WriteLn(theFile, '<name>'+TEERColumn(TEERTable(theObjList[i]).GetColumnByID(StrToInt(TEERIndex(TEERTable(theObjList[i]).Indices[j]).Columns[k]))).ColName+'</name>');
WriteLn(theFile, '</field>');
WriteLn(theFile, '</index>');
end;
WriteLn(theFile, '</declaration>');
WriteLn(theFile, '<initialization>');
//put all lines from insert to one line for theInserts
theInserts.Clear;
s:='';
for j:=0 to TEERTable(theObjList[i]).StandardInserts.Count-1 do
begin
s:=s+TEERTable(theObjList[i]).StandardInserts[j];
if(Copy(Trim(s), Length(Trim(s)), 1)=';')then
begin
theInserts.Add(Copy(Trim(s), 1, Length(Trim(s))-1));
s:='';
end;
end;
for j:=0 to theInserts.Count-1 do
begin
//Invalid Select statement
if(DMMain.GetSubStringCountInString(theInserts[j], '(')<2)then
Continue;
WriteLn(theFile, '<insert>');
for k:=0 to TEERTable(theObjList[i]).Columns.Count-1 do
begin
s:=DMMain.GetValueFromSQLInsert(TEERColumn(TEERTable(theObjList[i]).Columns[k]).ColName, theInserts[j]);
if(s<>'NOTININSERT')then
begin
WriteLn(theFile, '<field>');
WriteLn(theFile, '<name>'+TEERColumn(TEERTable(theObjList[i]).Columns[k]).ColName+'</name>');
WriteLn(theFile, '<value>'+s+'</value>');
WriteLn(theFile, '</field>');
end;
end;
WriteLn(theFile, '</insert>');
end;
WriteLn(theFile, '</initialization>');
WriteLn(theFile, '</table>');
end;
finally
theObjList.Free;
end;
WriteLn(theFile, '</database>');
finally
theDatatypeMappings.Free;
theInserts.Free;
end;
finally
CloseFile(theFile)
end;
DMGUI.SetStatusCaption(DMMain.GetTranslatedMessage('The model was successfully saved to %s.', 198, fname));
end;
end.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -