tpPegGclGatherDm.pas 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. unit tpPegGclGatherDm;
  2. interface
  3. uses
  4. SysUtils, Classes, tpGatherGcl, sdDB, sdProvider;
  5. type
  6. TtpPegGclGatherData = class(TDataModule)
  7. smpGclGather: TsdMemoryProvider;
  8. sddGclGather: TsdDataSet;
  9. sdvGclGather: TsdDataView;
  10. smpGclRela: TsdMemoryProvider;
  11. sddGclRela: TsdDataSet;
  12. sdvGclRela: TsdDataView;
  13. procedure sdvGclGatherCurrentChanged(ARecord: TsdDataRecord);
  14. procedure sdvGclRelaFilterRecord(ARecord: TsdDataRecord;
  15. var Allow: Boolean);
  16. private
  17. public
  18. procedure LoadGclGatherData(AGcls: TtpGatherGclList);
  19. end;
  20. implementation
  21. uses tpGatherTree;
  22. {$R *.dfm}
  23. { TtpPegGclGatherData }
  24. procedure TtpPegGclGatherData.LoadGclGatherData(AGcls: TtpGatherGclList);
  25. procedure BeforeLoad;
  26. begin
  27. sddGclGather.Active := True;
  28. sddGclGather.DisableControls;
  29. sddGclGather.BeginUpdate;
  30. sddGclGather.DeleteAll;
  31. sddGclRela.Active := True;
  32. sddGclRela.DisableControls;
  33. sddGclRela.BeginUpdate;
  34. sddGclRela.DeleteAll;
  35. sdvGclRela.Filtered := False;
  36. end;
  37. procedure AfterLoad;
  38. begin
  39. sddGclGather.EndUpdate;
  40. sddGclGather.EnableControls;
  41. sddGclRela.EndUpdate;
  42. sddGclRela.EnableControls;
  43. sdvGclGather.LocateInControl(sdvGclGather.Records[0]);
  44. sdvGclRela.Filtered := True;
  45. end;
  46. procedure LoadGclRela(AGcl: TtpGatherGcl);
  47. var
  48. iRela: Integer;
  49. vRela: TtpGatherGclRela;
  50. Rec: TsdDataRecord;
  51. begin
  52. for iRela := 0 to AGcl.RelaCount - 1 do
  53. begin
  54. vRela := AGcl.Rela[iRela];
  55. Rec := sddGclRela.Add;
  56. Rec.ValueByName('DetailGclID').AsInteger := vRela.RelaGcl.ID;
  57. Rec.ValueByName('GclID').AsInteger := AGcl.ID;
  58. Rec.ValueByName('PegXmjID').AsInteger := vRela.RelaPegXmj.ID;
  59. Rec.ValueByName('PegXmjCode').AsString := vRela.RelaPegXmj.Code;
  60. Rec.ValueByName('PegXmjName').AsString := vRela.RelaPegXmj.Name;
  61. Rec.ValueByName('PegXmjUnits').AsString := vRela.RelaPegXmj.Units;
  62. Rec.ValueByName('Quantity').AsFloat := vRela.RelaGcl.Quantity;
  63. Rec.ValueByName('TotalPrice').AsFloat := vRela.RelaPegXmj.TotalPrice;
  64. end;
  65. end;
  66. procedure LoadGclNode(AGcl: TtpGatherGcl);
  67. var
  68. Rec: TsdDataRecord;
  69. begin
  70. Rec := sddGclGather.Add;
  71. Rec.ValueByName('ID').AsInteger := AGcl.ID;
  72. Rec.ValueByname('IndexCode').AsString := AGcl.IndexCode;
  73. Rec.ValueByname('B_Code').AsString := AGcl.B_Code;
  74. Rec.ValueByName('Name').AsString := AGcl.Name;
  75. Rec.ValueByName('Units').AsString := AGcl.Units;
  76. Rec.ValueByName('Price').AsFloat := AGcl.Price;
  77. Rec.ValueByName('Quantity').AsFloat := AGcl.Quantity;
  78. Rec.ValueByName('TotalPrice').AsFloat := AGcl.TotalPrice;
  79. LoadGclRela(AGcl);
  80. end;
  81. var
  82. iGcl: Integer;
  83. begin
  84. BeforeLoad;
  85. try
  86. for iGcl := 0 to AGcls.GclCount - 1 do
  87. LoadGclNode(AGcls.Gcl[iGcl]);
  88. finally
  89. AfterLoad;
  90. end;
  91. end;
  92. procedure TtpPegGclGatherData.sdvGclGatherCurrentChanged(
  93. ARecord: TsdDataRecord);
  94. begin
  95. sdvGclRela.RefreshFilter;
  96. end;
  97. procedure TtpPegGclGatherData.sdvGclRelaFilterRecord(
  98. ARecord: TsdDataRecord; var Allow: Boolean);
  99. begin
  100. if Assigned(sdvGclGather.Current) then
  101. Allow := ARecord.ValueByName('GclID').AsInteger = sdvGclGather.Current.ValueByName('ID').AsInteger
  102. else
  103. Allow := False;
  104. end;
  105. end.