tpPegGclGatherDm.pas 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  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. Rec.ValueByName('DrawingCode').AsString := vRela.RelaPegXmj.DrawingCode;
  65. end;
  66. end;
  67. procedure LoadGclNode(AGcl: TtpGatherGcl);
  68. var
  69. Rec: TsdDataRecord;
  70. begin
  71. Rec := sddGclGather.Add;
  72. Rec.ValueByName('ID').AsInteger := AGcl.ID;
  73. Rec.ValueByname('IndexCode').AsString := AGcl.IndexCode;
  74. Rec.ValueByname('B_Code').AsString := AGcl.B_Code;
  75. Rec.ValueByName('Name').AsString := AGcl.Name;
  76. Rec.ValueByName('Units').AsString := AGcl.Units;
  77. Rec.ValueByName('Price').AsFloat := AGcl.Price;
  78. Rec.ValueByName('Quantity').AsFloat := AGcl.Quantity;
  79. Rec.ValueByName('TotalPrice').AsFloat := AGcl.TotalPrice;
  80. LoadGclRela(AGcl);
  81. end;
  82. var
  83. iGcl: Integer;
  84. begin
  85. BeforeLoad;
  86. try
  87. for iGcl := 0 to AGcls.GclCount - 1 do
  88. LoadGclNode(AGcls.Gcl[iGcl]);
  89. finally
  90. AfterLoad;
  91. end;
  92. end;
  93. procedure TtpPegGclGatherData.sdvGclGatherCurrentChanged(
  94. ARecord: TsdDataRecord);
  95. begin
  96. sdvGclRela.RefreshFilter;
  97. end;
  98. procedure TtpPegGclGatherData.sdvGclRelaFilterRecord(
  99. ARecord: TsdDataRecord; var Allow: Boolean);
  100. begin
  101. if Assigned(sdvGclGather.Current) then
  102. Allow := ARecord.ValueByName('GclID').AsInteger = sdvGclGather.Current.ValueByName('ID').AsInteger
  103. else
  104. Allow := False;
  105. end;
  106. end.