ReportInteractInfo.pas 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. unit ReportInteractInfo;
  2. interface
  3. uses
  4. Classes, ScFileArchiver, XmlDoc, XmlIntf;
  5. Type
  6. TInteractInfo = class
  7. private
  8. FTemplateFile: string;
  9. FInteractFlag: Integer;
  10. FInteractSubFlag: Integer;
  11. FMemoryStream: TMemoryStream;
  12. FAudits: TStringList;
  13. FSql: string;
  14. procedure LoadReportTemplate;
  15. procedure LoadAuditor(AXmlNode: IXMLNode);
  16. procedure LoadSql(AXmlNode: IXMLNode);
  17. procedure LoadInteractInfo(AXmlNode: IXMLNode);
  18. procedure LoadXmlFromStream;
  19. public
  20. constructor Create(const AFileName: string);
  21. destructor Destroy; override;
  22. property Audits: TStringList read FAudits;
  23. property Sql: string read FSql;
  24. end;
  25. implementation
  26. uses
  27. UtilMethods;
  28. { TInteractInfo }
  29. constructor TInteractInfo.Create(const AFileName: string);
  30. begin
  31. FTemplateFile := AFileName;
  32. FAudits := TStringList.Create;
  33. LoadReportTemplate;
  34. LoadXmlFromStream;
  35. end;
  36. destructor TInteractInfo.Destroy;
  37. begin
  38. FMemoryStream.Free;
  39. inherited;
  40. end;
  41. procedure TInteractInfo.LoadAuditor(AXmlNode: IXMLNode);
  42. var
  43. vAudits: IXMLNodeList;
  44. vAudit: IXMLNode;
  45. i: Integer;
  46. begin
  47. if AXmlNode = nil then Exit;
  48. vAudits := AXmlNode.ChildNodes;
  49. for i := 0 to vAudits.Count - 1 do
  50. begin
  51. vAudit := AXmlNode.ChildNodes.Nodes[i];
  52. if vAudit.HasAttribute('职位') then
  53. FAudits.Add(vAudit.Attributes['职位']);
  54. end;
  55. end;
  56. procedure TInteractInfo.LoadInteractInfo(AXmlNode: IXMLNode);
  57. var
  58. XmlNode: IXMLNode;
  59. begin
  60. XmlNode := AXmlNode.ChildNodes.FindNode('附加信息');
  61. LoadAuditor(XmlNode.ChildNodes.FindNode('审核意见'));
  62. LoadSql(XmlNode.ChildNodes.FindNode('查询语句'));
  63. end;
  64. procedure TInteractInfo.LoadReportTemplate;
  65. var
  66. vArchiver: TReportArchiver;
  67. begin
  68. vArchiver := TReportArchiver.Create;
  69. vArchiver.FileName := FTemplateFile;
  70. FMemoryStream := vArchiver.Extract;
  71. end;
  72. procedure TInteractInfo.LoadSql(AXmlNode: IXMLNode);
  73. begin
  74. if AXmlNode = nil then Exit;
  75. if AXmlNode.HasAttribute('Sql语句') then
  76. FSql := AXmlNode.Attributes['Sql语句'];
  77. end;
  78. procedure TInteractInfo.LoadXmlFromStream;
  79. var
  80. FXmlDocument: IXMLDocument;
  81. begin
  82. FXmlDocument := TXMLDocument.Create(nil) as IXMLDocument;
  83. try
  84. FXmlDocument.Options := [doNodeAutoCreate,doNodeAutoIndent,doAutoPrefix,doNamespaceDecl];
  85. if not Assigned(FMemoryStream) then Exit;
  86. FXmlDocument.LoadFromStream(FMemoryStream);
  87. LoadInteractInfo(FXmlDocument.DocumentElement);
  88. finally
  89. FXmlDocument := nil;
  90. end;
  91. end;
  92. end.