Browse Source

报表,可批量导入报表模板

MaiXinRong 9 years ago
parent
commit
f7ed377f71
3 changed files with 56 additions and 19 deletions
  1. 10 10
      Forms/ReportsFrm.dfm
  2. 24 9
      Forms/ReportsFrm.pas
  3. 22 0
      Units/UtilMethods.pas

+ 10 - 10
Forms/ReportsFrm.dfm

@@ -82,23 +82,23 @@ object ReportsForm: TReportsForm
   end
   object pnlReports: TPanel
     Left = 0
-    Top = 81
+    Top = 76
     Width = 1107
-    Height = 425
+    Height = 430
     Align = alClient
     BevelOuter = bvNone
     TabOrder = 6
     object sprReportPreview: TSplitter
       Left = 211
       Top = 0
-      Height = 425
+      Height = 430
       AutoSnap = False
     end
     object pnlReportsList: TPanel
       Left = 0
       Top = 0
       Width = 211
-      Height = 425
+      Height = 430
       Align = alLeft
       BevelOuter = bvNone
       TabOrder = 0
@@ -106,7 +106,7 @@ object ReportsForm: TReportsForm
         Left = 0
         Top = 35
         Width = 211
-        Height = 390
+        Height = 395
         Align = alClient
         Font.Charset = DEFAULT_CHARSET
         Font.Color = clWindowText
@@ -193,7 +193,7 @@ object ReportsForm: TReportsForm
       Left = 214
       Top = 0
       Width = 893
-      Height = 425
+      Height = 430
       HorzScrollBar.Increment = 48
       HorzScrollBar.Tracking = True
       VertScrollBar.Increment = 32
@@ -216,7 +216,7 @@ object ReportsForm: TReportsForm
     Font.Charset = DEFAULT_CHARSET
     Font.Color = clWindowText
     Font.Height = -12
-    Font.Name = #24494#36719#38597#40657
+    Font.Name = #23435#20307
     Font.Style = []
     Bars = <
       item
@@ -313,7 +313,7 @@ object ReportsForm: TReportsForm
         Caption = #33539#22260#36755#20986
         DockedDockingStyle = dsTop
         DockedLeft = 0
-        DockedTop = 52
+        DockedTop = 47
         DockingStyle = dsTop
         FloatLeft = 602
         FloatTop = 414
@@ -343,7 +343,7 @@ object ReportsForm: TReportsForm
         Caption = #25253#34920#36873#39033
         DockedDockingStyle = dsTop
         DockedLeft = 308
-        DockedTop = 52
+        DockedTop = 47
         DockingStyle = dsTop
         FloatLeft = 484
         FloatTop = 279
@@ -388,7 +388,7 @@ object ReportsForm: TReportsForm
     DockControlHeights = (
       0
       0
-      81
+      76
       0)
     object xlbPrint: TdxBarLargeButton
       Caption = #25171#21360

+ 24 - 9
Forms/ReportsFrm.pas

@@ -651,25 +651,40 @@ begin
 end;
 
 procedure TReportsForm.tbImportSrtClick(Sender: TObject);
-var
-  sFileName, sNewFileName: string;
-  vTemplateNode: TTemplateNode;
-begin
-  if SelectFile(sFileName, '.srt') then
+
+  procedure ImportReportTemplate(const AFileName: string);
+  var
+    sNewFileName: string;
+    vTemplateNode: TTemplateNode;
   begin
-    sNewFileName := GetReportTemplatePath + ExtractFileName(sFileName);
+    sNewFileName := GetReportTemplatePath + ExtractFileName(AFileName);
     if not FileExists(sNewFileName) then
     begin
-      CopyFile(PChar(sFileName), PChar(sNewFileName), True);
+      CopyFile(PChar(AFileName), PChar(sNewFileName), True);
       vTemplateNode := ReportTemplateManager.AddReportTemplate(sNewFileName);
       AddReportTemplate(vTemplateNode);
     end
     else
-      if QuestMessage('已存在报表模板' + ExtractFileName(sFileName) + ',是否覆盖原模板?', Handle) then
-        CopyFile(PChar(sFileName), PChar(sNewFileName), False)
+      if QuestMessage('已存在报表模板' + ExtractFileName(AFileName) + ',是否覆盖原模板?', Handle) then
+        CopyFile(PChar(AFileName), PChar(sNewFileName), False)
       else
         Exit;
   end;
+
+var
+  sgsFiles: TStrings;
+  iFile: Integer;
+begin
+  sgsFiles := TStringList.Create;
+  try
+    if SelectFiles(sgsFiles, '.srt') then
+    begin
+      for iFile := 0 to sgsFiles.Count - 1 do
+        ImportReportTemplate(sgsFiles.Strings[iFile]);
+    end;
+  finally
+    sgsFiles.Free;
+  end;
 end;
 
 procedure TReportsForm.tbDeleteSrtClick(Sender: TObject);

+ 22 - 0
Units/UtilMethods.pas

@@ -42,6 +42,7 @@ type
   {Select & Save File Choose}
   function GetFilter(AExt: string): string;
   function SelectFile(var AFileName: string; const AExt: string): Boolean;
+  function SelectFiles(AFiles: TStrings; const AExt: string): Boolean;
   function SaveFile(var FileName: string; const AExt: string): Boolean;
   function SelectOutputDirectory(const ATitle: string; var ADirectory: string;
     AParentHandle: THandle = 0; AHasNewFolderBtn: Boolean = True): Boolean;
@@ -296,6 +297,27 @@ begin
   end;
 end;
 
+function SelectFiles(AFiles: TStrings; const AExt: string): Boolean;
+var
+  odFile: TOpenDialog;
+begin
+  odFile := TOpenDialog.Create(nil);
+  try
+    odFile.Options := odFile.Options + [ofAllowMultiSelect];
+    odFile.Filter := GetFilter(AExt);
+    if odFile.Execute then
+    begin
+      Application.ProcessMessages;
+      AFiles.Assign(odFile.Files);
+      Result := True;
+    end
+    else
+      Result := False;
+  finally
+    odFile.Free;
+  end;
+end;
+
 function SaveFile(var FileName: string; const AExt: string): Boolean;
 var
   sdFile: TSaveDialog;