Procedure

TfrmTemplateEditor.mnuImportTemplateClick

Module

fTemplateEditor

Last Modified

7/15/2014 3:26:44 PM

Visibility

Public/Published

Owner

TfrmTemplateEditor

Declaration

procedure mnuImportTemplateClick(Sender: TObject);

Calls Hierarchy


TfrmTemplateEditor.mnuImportTemplateClick
 ├WordImportActive
 ├GetXMLFromWord
 │ ├StartImportMessage
 │ │ └TfrmBase508Form.Create
 │ │   ├TfrmBase508Form.UpdateAccessibilityActions
 │ │   ├UnfocusableControlEnter
 │ │   └AdjustControls
 │ │     ├TfrmBase508Form.ModifyUnfocusableControl
 │ │     └..(rec)..
 │ ├BadTemplateName
 │ ├AddXMLData
 │ ├UpdateImportMessage
 │ ├AddBoiler
 │ ├AddFieldHeader
 │ │ └AddField
 │ ├AddField
 │ ├WordWrap
 │ ├AddXMLList
 │ │ └ListTemplateFields
 │ │   └GetTemplateField
 │ │     ├LoadTemplateFieldByIEN
 │ │     ├LoadTemplateField
 │ │     └TTemplateField.Create
 │ │       ├TemplateFieldCode2Field
 │ │       └TemplateDateCode2DateType
 │ ├FMNow
 │ ├WordImportError
 │ └StopImportMessage
 ├XMLImportError
 ├BuildTemplateFields
 │ └reset_broker
 ├CheckTemplateFields
 ├CanEditTemplateFields
 ├TfrmTemplateEditor.btnNewClick
 │ ├TfrmTemplateEditor.CanClone
 │ │ ├GetFirstPersonalNode
 │ │ │ └..(rec)..
 │ │ └TTemplate.CanModify
 │ │   ├TTemplate.ValidID
 │ │   └LockTemplate
 │ ├TfrmTemplateEditor.Clone
 │ │ ├TfrmTemplateEditor.CanClone...
 │ │ ├..(rec)..
 │ │ ├TTemplate.CanModify...
 │ │ ├TTemplate.Clone
 │ │ │ ├TTemplate.TrueClone
 │ │ │ │ ├TTemplate.GetChildren
 │ │ │ │ ├TTemplate.Create
 │ │ │ │ │ └TTemplate.ReminderDialogIEN
 │ │ │ │ ├TTemplate.SetBoilerplate
 │ │ │ │ │ ├TTemplate.CanModify...
 │ │ │ │ │ └TTemplate.ValidID
 │ │ │ │ ├TTemplate.GetBoilerplate
 │ │ │ │ │ └GetTemplateBoilerplate
 │ │ │ │ ├TTemplate.SetDescription
 │ │ │ │ │ ├TTemplate.CanModify...
 │ │ │ │ │ └TTemplate.ValidID
 │ │ │ │ └TTemplate.GetDescription
 │ │ │ │   └LoadTemplateDescription
 │ │ │ ├TTemplate.GetItems
 │ │ │ │ └ExpandTemplate
 │ │ │ │   ├TTemplate.GetChildren
 │ │ │ │   ├GetTemplateChildren
 │ │ │ │   ├AddTemplate
 │ │ │ │   │ ├TTemplate.Create...
 │ │ │ │   │ └TTemplate.AddChild
 │ │ │ │   │   └TTemplate.GetItems...
 │ │ │ │   └TTemplate.ItemIENs
 │ │ │ │     └TTemplate.GetItems...
 │ │ │ └TTemplate.BackupItems
 │ │ │   └TTemplate.ItemIENs...
 │ │ ├TTemplate.RemoveNode
 │ │ ├MarkDeleted
 │ │ │ ├TTemplate.ValidID
 │ │ │ ├TTemplate.SetFileLink
 │ │ │ │ └TTemplate.AssignFileLink
 │ │ │ │   ├TTemplate.CanModify...
 │ │ │ │   ├TTemplate.ValidID
 │ │ │ │   ├TTemplate.LinkType
 │ │ │ │   ├TTemplate.SetReminderDialog
 │ │ │ │   │ ├TTemplate.CanModify...
 │ │ │ │   │ ├TTemplate.ValidID
 │ │ │ │   │ ├TTemplate.ReminderDialogIEN
 │ │ │ │   │ ├TTemplate.LinkType
 │ │ │ │   │ └TTemplate.SetFileLink...
 │ │ │ │   ├TTemplate.GetItems...
 │ │ │ │   └..(rec)..
 │ │ │ ├TTemplate.GetItems...
 │ │ │ └..(rec)..
 │ │ ├TTemplate.AddNode
 │ │ ├TTemplate.GetItems...
 │ │ └TfrmTemplateEditor.ShowTemplateType
 │ ├TTemplate.CanModify...
 │ ├TTemplate.GetItems...
 │ ├TTemplate.CreateFromXML
 │ │ ├TTemplate.Create...
 │ │ ├TTemplate.SetBoilerplate...
 │ │ ├TTemplate.SetDescription...
 │ │ ├TTemplate.GetItems...
 │ │ ├..(rec)..
 │ │ └TTemplate.BackupItems...
 │ ├TTemplate.Create...
 │ ├TTemplate.BackupItems...
 │ └TfrmTemplateEditor.Resync
 │   ├TdmodShared.Resync
 │   │ ├InSyncNode
 │   │ ├GetID
 │   │ │ └..(rec)..
 │   │ ├TTemplate.RemoveNode
 │   │ ├BuildNodes
 │   │ │ ├TTemplate.AddNode
 │   │ │ ├TTemplate.GetItems...
 │   │ │ ├..(rec)..
 │   │ │ └TTemplate.GetChildren
 │   │ └GetNode
 │   │   └GetID...
 │   ├TfrmTemplateEditor.EnableNavControls
 │   │ └TfrmTemplateEditor.AllowMove
 │   │   ├TfrmTemplateEditor.IsTemplateLocked
 │   │   │ ├TTemplate.AutoLock
 │   │   │ │ └TTemplate.LinkType
 │   │   │ ├TTemplate.IsLocked
 │   │   │ │ └TTemplate.AutoLock...
 │   │   │ └..(rec)..
 │   │   └TTemplate.GetItems...
 │   └TfrmTemplateEditor.tvTreeChange
 │     ├TfrmTemplateEditor.ChangeTree
 │     ├TfrmTemplateEditor.IsTemplateLocked...
 │     ├TfrmTemplateEditor.EnableControls
 │     │ ├TfrmTemplateEditor.UpdateInsertsDialogs
 │     │ │ ├TfrmTemplateObjects.UpdateStatus
 │     │ │ └TfrmTemplateFields.UpdateStatus
 │     │ │   └TfrmTemplateFields.ValidInsert
 │     │ └TfrmTemplateEditor.EnableNavControls...
 │     └TfrmTemplateEditor.ShowInfo
 │       ├TfrmTemplateEditor.ShowTemplateType
 │       ├TfrmTemplateEditor.GetLinkType
 │       ├LoadServiceListWithSynonyms
 │       ├TTemplate.LinkName
 │       │ ├GetLinkName
 │       │ │ └ExternalName
 │       │ ├TTemplate.LinkIEN
 │       │ └TTemplate.LinkType
 │       ├TTemplate.LinkIEN
 │       ├TTemplate.GetDescription...
 │       ├TTemplate.IsLocked...
 │       ├TTemplate.AutoLock...
 │       ├TfrmTemplateEditor.IsTemplateLocked...
 │       ├TTemplate.GetChildren
 │       ├TTemplate.ReminderDialogIEN
 │       ├TdmodShared.InDialog
 │       │ └TTemplate.IsDialog
 │       ├TTemplate.GetBoilerplate...
 │       ├TfrmTemplateEditor.DisplayBoilerplate
 │       │ ├TfrmTemplateEditor.pnlBoilerplateResize
 │       │ ├TTemplate.GetBoilerplate...
 │       │ ├TTemplate.FullBoilerplate
 │       │ │ ├TTemplate.GetBoilerplate...
 │       │ │ ├TTemplate.ItemBoilerplate
 │       │ │ │ ├TTemplate.GetItems...
 │       │ │ │ ├TTemplate.GetTemplateType
 │       │ │ │ ├DlgText
 │       │ │ │ └TTemplate.DialogProperties
 │       │ │ │   ├TTemplate.GetBoilerplate...
 │       │ │ │   └TTemplate.DlgID
 │       │ │ ├DlgText
 │       │ │ └TTemplate.DialogProperties...
 │       │ ├TfrmTemplateEditor.UpdateInsertsDialogs...
 │       │ ├TfrmTemplateEditor.ShowBoilerPlate
 │       │ └TfrmTemplateEditor.ShowGroupBoilerplate
 │       ├TfrmTemplateEditor.ShowGroupBoilerplate
 │       └TfrmTemplateEditor.pnlBoilerplateResize
 ├ImportLoadedFields
 ├ClearFields
 ├TTemplate.UpdateImportedFieldNames
 │ ├TTemplate.GetBoilerplate...
 │ ├TTemplate.CanModify...
 │ ├TTemplate.GetItems...
 │ └..(rec)..
 └TfrmTemplateEditor.ShowInfo...

Calls

Name Declaration Comments
TfrmTemplateEditor.btnNewClick procedure btnNewClick(Sender: TObject); -
BuildTemplateFields function BuildTemplateFields(XMLString: TStrings): boolean; -
CanEditTemplateFields function CanEditTemplateFields: boolean; -
CheckTemplateFields procedure CheckTemplateFields(ResultString: TStrings); -
ClearFields procedure ClearFields; -
GetXMLFromWord function GetXMLFromWord(const AFileName: string; Data: TStrings): boolean; -
ImportLoadedFields function ImportLoadedFields(ResultSet: TStrings): boolean; -
TfrmTemplateEditor.ShowInfo procedure ShowInfo(Node: TTreeNode); -
TTemplate.UpdateImportedFieldNames procedure UpdateImportedFieldNames(List: TStrings); -
WordImportActive function WordImportActive: boolean; -
XMLImportError procedure XMLImportError(Result: HResult); -


Source

3533  procedure TfrmTemplateEditor.mnuImportTemplateClick(Sender: TObject);
3534  const
3535    Filter1 = 'Template Files|*.txml';
3536    WordFilter = '|Word Documents|*.doc;*.dot';
3537    Filter2 = '|XML Files|*.xml|All Files|*.*';
3538  
3539  var
3540    XMLDoc: IXMLDOMDocument;
3541    RootElement: IXMLDOMElement;
3542    ImportedTemplate: TTemplate;
3543    AppData, Flds, ResultSet: TStringList;
3544    tmp, j, p3: string;
3545    err, ok, changes, xmlerr: boolean;
3546    i: integer;
3547    choice: word;
3548  
3549    procedure ClearFields;
3550    begin
3551      Flds.Text := '';
3552      ResultSet.Text := '';
3553    end;
3554  
3555  begin
3556    tmp := Filter1;
3557    err := FALSE;
3558    if WordImportActive then
3559      tmp := tmp + WordFilter;
3560    tmp := tmp + Filter2;
3561    dlgImport.Filter := tmp;
3562    if btnNew.Enabled and dlgImport.Execute then
3563    begin
3564      tmp := ExtractFileExt(dlgImport.FileName);
3565      if (WordImportActive and ((CompareText(tmp, '.doc') = 0) or
3566        (CompareText(tmp, '.dot') = 0))) then
3567        AppData := TStringList.Create
3568      else
3569        AppData := nil;
3570      try
3571        try
3572          XMLDoc := CoDOMDocument.Create;
3573        except
3574          InfoBox(Format(NoIE5, ['Import']), NoIE5Header, MB_OK);
3575          exit;
3576        end;
3577        try
3578          if assigned(AppData) then
3579          begin
3580            try
3581              ok := GetXMLFromWord(dlgImport.FileName, AppData);
3582            except
3583              ok := FALSE;
3584              err := TRUE;
3585            end;
3586          end
3587          else
3588            ok := TRUE;
3589          if ok and assigned(XMLDoc) then
3590          begin
3591            XMLDoc.preserveWhiteSpace := TRUE;
3592            if assigned(AppData) then
3593              XMLDoc.LoadXML(AppData.Text)
3594            else
3595              XMLDoc.Load(dlgImport.FileName);
3596            RootElement := XMLDoc.DocumentElement;
3597            if not assigned(RootElement) then
3598              XMLImportError(0);
3599            try
3600              if (RootElement.tagName <> XMLHeader) then
3601                XMLImportError(0)
3602              else
3603              begin
3604                ImportedTemplate := nil;
3605                FXMLTemplateElement := FindXMLElement(RootElement, XMLTemplateTag);
3606                if assigned(FXMLTemplateElement) then
3607                begin
3608                  FXMLFieldElement := FindXMLElement(RootElement, XMLTemplateFieldsTag);
3609                  if (assigned(FXMLFieldElement)) then
3610                  begin
3611                    Flds := TStringList.Create;
3612                    ResultSet := TStringList.Create;
3613                    try
3614                      Flds.Text := FXMLFieldElement.Get_XML;
3615                      choice := IDOK;
3616                      changes := FALSE;
3617                      Application.ProcessMessages;
3618                      if not BuildTemplateFields(Flds) then //Calls RPC to transfer all field XML
3619                        choice := IDCANCEL; //for processing
3620                      Flds.Text := '';
3621                      Application.ProcessMessages;
3622                      if choice = IDOK then
3623                        CheckTemplateFields(Flds);
3624                      if Flds.Count > 0 then
3625                      begin
3626                        for i := 1 to Flds.Count do
3627                        begin
3628                          j := piece(Flds[i - 1], U, 2);
3629                          if (j = '0') or (j = '2') then
3630                          begin
3631                            p3 := piece(Flds[i - 1], U, 3);
3632                            if p3 = 'XML FORMAT ERROR' then
3633                              choice := IDCANCEL;
3634                            changes := TRUE;
3635                            if j = '2' then begin
3636                              j := Flds[i - 1];
3637                              SetPiece(j, U, 2, '1');
3638                              Flds[i - 1] := j
3639                            end;
3640                          end;
3641                        end;
3642                      end
3643                      else
3644                        choice := IDCANCEL;
3645                      if choice <> IDOK then
3646                        InfoBox(iMessage2 + iMessage3, 'Error', MB_OK or MB_ICONERROR)
3647                      else
3648                        if (not CanEditTemplateFields) and
3649                          changes {(there is at least one new field)} then
3650                        begin
3651                          choice := InfoBox(iMessage, 'Warning', MB_OKCANCEL or MB_ICONWARNING);
3652                          Flds.Text := '';
3653                        end;
3654                      if choice <> IDCANCEL then
3655                      begin
3656                        FImportingFromXML := TRUE;
3657                        try
3658                          btnNewClick(Self);
3659                          ImportedTemplate := TTemplate(FBtnNewNode.Data);
3660                        finally
3661                          FImportingFromXML := FALSE;
3662                        end; {try}
3663                        Application.ProcessMessages;
3664                        if assigned(ImportedTemplate) and (Flds.Count > 0) then
3665                          if not ImportLoadedFields(ResultSet) then begin
3666                            InfoBox(iMessage2 + iMessage3, 'Error', MB_OK or MB_ICONERROR);
3667                            ClearFields;
3668                            choice := IDCANCEL;
3669                          end; //if
3670                        if Flds.Count = 0 then
3671                          choice := IDCANCEL;
3672                      end {if choice <> mrCancel}
3673                      else
3674                        ClearFields;
3675  
3676                      xmlerr := FALSE;
3677                      if (Flds.Count > 0) and
3678                        (ResultSet.Count > 0) and
3679                        (Flds.Count = ResultSet.Count) then
3680                        for i := 0 to Flds.Count - 1 do begin
3681                          if piece(ResultSet[i], U, 2) = '0' then begin
3682                            j := piece(Flds[i], U, 1) + U + '0' + U + piece(ResultSet[i], U, 3);
3683                            Flds[i] := j;
3684                          end
3685                        end
3686                      else
3687                        xmlerr := TRUE;
3688  
3689                      if xmlerr and (choice <> IDCANCEL) then begin
3690                        InfoBox(iMessage2, 'Warning', MB_OK or MB_ICONWARNING);
3691                        ClearFields;
3692                      end;
3693  
3694                      i := 0;
3695                      while (i < Flds.Count) do begin
3696                        if Piece(Flds[i], U, 2) <> '0' then
3697                          Flds.Delete(i)
3698                        else
3699                          inc(i);
3700                      end; //while
3701                      if (Flds.Count > 0) then
3702                      begin
3703                        if assigned(frmTemplateFields) then
3704                          FreeAndNil(frmTemplateFields);
3705                        ImportedTemplate.UpdateImportedFieldNames(Flds);
3706                        if not assigned(AppData) then
3707                        begin
3708                          for i := 0 to Flds.Count - 1 do
3709                            Flds[i] := '  Field "' + Piece(Flds[i], U, 1) + '" has been renamed to "' +
3710                              Piece(Flds[i], U, 3) + '"';
3711                          if Flds.Count = 1 then
3712                            tmp := 'A template field has'
3713                          else
3714                            tmp := IntToStr(Flds.Count) + ' template fields have';
3715                          Flds.Insert(0, tmp + ' been imported with the same name as');
3716                          Flds.Insert(1, 'existing template fields, but with different field definitions.');
3717                          Flds.Insert(2, 'These imported template fields have been renamed as follows:');
3718                          Flds.Insert(3, '');
3719                          InfoBox(Flds.Text, 'Information', MB_OK or MB_ICONINFORMATION);
3720                        end;
3721                      end;
3722                    finally
3723                      Flds.Free;
3724                      ResultSet.Free;
3725                    end;
3726                  end
3727                  else {There are no fields to consider...}
3728                  begin
3729                    FImportingFromXML := TRUE;
3730                    try
3731                      btnNewClick(Self);
3732                      ImportedTemplate := TTemplate(FBtnNewNode.Data);
3733                    finally
3734                      FImportingFromXML := FALSE;
3735                    end; {try}
3736                  end;
3737                end;
3738                if assigned(ImportedTemplate) then
3739                  ShowInfo(FBtnNewNode);
3740              end;
3741            finally
3742              RootElement := nil;
3743            end;
3744          end;
3745        finally
3746          XMLDoc := nil;
3747        end;
3748      finally
3749        if assigned(AppData) then
3750        begin
3751          AppData.Free;
3752          if err then
3753            InfoBox('An error occured while Importing Word Document.  Make sure Word is closed and try again.', 'Import Error', MB_OK);
3754        end;
3755      end;
3756    end;
3757  end;