AttachmentInfoDm.pas 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. unit AttachmentInfoDm;
  2. interface
  3. uses
  4. SysUtils, Classes, sdDB, sdProvider, ADODB, Variants;
  5. type
  6. TAttachmentInfoData = class(TDataModule)
  7. sdpAttachmentInfo: TsdADOProvider;
  8. sddAttachmentInfo: TsdDataSet;
  9. private
  10. FProjectData: TObject;
  11. FMacAddr: string;
  12. function GetAttachmentInfoRec(AID: Integer): TsdDataRecord;
  13. public
  14. constructor Create(AProjectData: TObject);
  15. destructor Destroy; override;
  16. procedure Open(AConnection: TADOConnection);
  17. procedure Close;
  18. procedure Save;
  19. function GetAttachmentPath(AID: Integer): string;
  20. procedure SaveAttachmentPath(AID: Integer; APath: string);
  21. end;
  22. implementation
  23. uses UtilMethods, PHPWebDM;
  24. {$R *.dfm}
  25. { TAttachmentInfoData }
  26. procedure TAttachmentInfoData.Close;
  27. begin
  28. sddAttachmentInfo.Close;
  29. end;
  30. constructor TAttachmentInfoData.Create(AProjectData: TObject);
  31. begin
  32. inherited Create(nil);
  33. FProjectData := AProjectData;
  34. FMacAddr := GetMacAddr;
  35. end;
  36. destructor TAttachmentInfoData.Destroy;
  37. begin
  38. inherited;
  39. end;
  40. function TAttachmentInfoData.GetAttachmentInfoRec(AID: Integer): TsdDataRecord;
  41. begin
  42. Result := sddAttachmentInfo.Locate('ID;Mac', VarArrayOf([AID, FMacAddr]));
  43. end;
  44. function TAttachmentInfoData.GetAttachmentPath(AID: Integer): string;
  45. var
  46. Rec: TsdDataRecord;
  47. begin
  48. Result := '';
  49. Rec := GetAttachmentInfoRec(AID);
  50. if Assigned(Rec) then
  51. Result := Rec.ValueByName('Path').AsString;
  52. end;
  53. procedure TAttachmentInfoData.Open(AConnection: TADOConnection);
  54. begin
  55. sdpAttachmentInfo.Connection := AConnection;
  56. sddAttachmentInfo.Open;
  57. end;
  58. procedure TAttachmentInfoData.Save;
  59. begin
  60. sddAttachmentInfo.Save;
  61. end;
  62. procedure TAttachmentInfoData.SaveAttachmentPath(AID: Integer;
  63. APath: string);
  64. var
  65. Rec: TsdDataRecord;
  66. begin
  67. Rec := GetAttachmentInfoRec(AID);
  68. if not Assigned(Rec) then
  69. begin
  70. Rec := sddAttachmentInfo.Add;
  71. Rec.ValueByName('ID').AsInteger := AID;
  72. Rec.ValueByName('UserID').AsInteger := PHPWeb.UserID;
  73. Rec.ValueByName('Mac').AsString := FMacAddr;
  74. end;
  75. Rec.ValueByName('Path').AsString := APath;
  76. sddAttachmentInfo.Save;
  77. end;
  78. end.