Function

SaveAllTemplates

Module

uTemplates

Last Modified

7/15/2014 3:26:44 PM

Scope

Interfaced

Declaration

function SaveAllTemplates: boolean;

Calls Hierarchy


SaveAllTemplates
 ├SaveTemplate
 │ ├TTemplate.Changed
 │ │ ├TTemplate.ValidID
 │ │ └TTemplate.ItemIENs
 │ │   └TTemplate.GetItems
 │ │     └ExpandTemplate
 │ │       ├TTemplate.GetChildren
 │ │       ├GetTemplateChildren
 │ │       ├AddTemplate
 │ │       │ ├TTemplate.Create
 │ │       │ │ └TTemplate.ReminderDialogIEN
 │ │       │ └TTemplate.AddChild
 │ │       │   └TTemplate.GetItems...
 │ │       └TTemplate.ItemIENs...
 │ ├TTemplate.Unlock
 │ │ ├TTemplate.ValidID
 │ │ └UnlockTemplate
 │ ├TTemplate.GetBoilerplate
 │ │ └GetTemplateBoilerplate
 │ ├TTemplate.ReminderDialogIEN
 │ ├TTemplate.GetDescription
 │ │ └LoadTemplateDescription
 │ ├UpdateTemplate
 │ │ └UpdateTIURec
 │ ├DisplayErrors
 │ └TTemplate.ClearBackup
 │   └TTemplate.ItemIENs...
 ├TTemplate.ItemIENs...
 ├TTemplate.GetItems...
 ├UpdateChildren
 ├TTemplate.Unlock...
 ├DeleteTemplates
 └DisplayErrors

Called-By Hierarchy


                      SaveAllTemplates
    TfrmTemplateEditor.btnApplyClick┤ 
TfrmTemplateEditor.mnuRefreshClick┘ │ 
       TfrmTemplateEditor.btnOKClick┤ 
   TfrmTemplateEditor.FormCloseQuery┘ 

Calls

Name Declaration Comments
DeleteTemplates procedure DeleteTemplates(DelList: TStrings); -
DisplayErrors procedure DisplayErrors(Errors: TStringList; SingleError: string = ''); -
TTemplate.GetItems function GetItems: TList; -
TTemplate.ItemIENs function ItemIENs: string; -
SaveTemplate procedure SaveTemplate(Template: TTemplate; Idx: integer; ErrorList: TStrings = nil); -
TTemplate.Unlock procedure Unlock; -
UpdateChildren procedure UpdateChildren(ID: string; Children: TStrings); -

Called-By

Name Declaration Comments
TfrmTemplateEditor.btnApplyClick procedure btnApplyClick(Sender: TObject); -
TfrmTemplateEditor.btnOKClick procedure btnOKClick(Sender: TObject); -
TfrmTemplateEditor.FormCloseQuery procedure FormCloseQuery(Sender: TObject; var CanClose: Boolean); -


Source

931   function SaveAllTemplates: boolean;
932   var
933     i, k: integer;
934     New: TTemplate;
935     Errors: TStringList;
936     First, ChildErr: boolean;
937   
938   begin
939     Errors := TStringList.Create;
940     try
941       if(assigned(Templates)) then
942       begin
943         if(not assigned(TempSL)) then
944           TempSL := TStringList.Create;
945         for i := 0 to Templates.Count-1 do
946           SaveTemplate(TTemplate(Templates.Objects[i]), i, Errors);
947         First := TRUE;
948         if(Errors.Count > 0) then
949           Errors.Insert(0,'Errors Encountered Saving Templates:');
950         for i := 0 to Templates.Count-1 do
951         begin
952           New := TTemplate(Templates.Objects[i]);
953           with New.FBkup do
954           if(SavedItemIENs and (BItemIENs <> New.ItemIENs)) then
955           begin
956             TempSL.Clear;
957             for k := 0 to New.Items.Count-1 do
958               TempSL.Add(TTemplate(New.Items[k]).FID);
959             UpdateChildren(New.ID, TempSL);
960             ChildErr := FALSE;
961             for k := 0 to RPCBrokerV.Results.Count-1 do
962             begin
963               if(RPCBrokerV.Results[k] <> IntToStr(k+1)) then
964               begin
965                 if(First) then
966                 begin
967                   Errors.Add('Errors Encountered Saving Children:');
968                   First := FALSE;
969                 end;
970                 Errors.Add(New.ID+' Item #'+IntToStr(k+1)+'('+
971                        TTemplate(New.Items[k]).FID+')'+'='+RPCBrokerV.Results[k]);
972                 ChildErr := TRUE;
973               end;
974             end;
975             if(not ChildErr) then
976               BItemIENs := New.ItemIENs;
977           end;
978           New.Unlock;
979         end;
980         if(assigned(Deleted)) and (Deleted.Count > 0) then
981         begin
982           DeleteTemplates(Deleted);
983           Deleted.Clear;
984         end;
985         if(Errors.Count > 0) then
986           DisplayErrors(Errors);
987       end;
988     finally
989       Result := (Errors.Count = 0);
990       Errors.Free;
991     end;
992   end;