tpPricePartSettingFrm.pas 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. unit tpPricePartSettingFrm;
  2. interface
  3. uses
  4. Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  5. Dialogs, ExtCtrls, StdCtrls, ComCtrls;
  6. const
  7. sPegIgnoreHint = '各桩号间可能存在重叠,可通过该项设置多少m重叠忽略不计' + #13#10 +
  8. '如果要求重叠桩号划分为1个标段,可设置为0。';
  9. type
  10. TPricePartInfo = class
  11. private
  12. FPartPrice: Double;
  13. FMinLength: Integer;
  14. FMinStep: Integer;
  15. public
  16. constructor Create;
  17. property PartPrice: Double read FPartPrice write FPartPrice;
  18. property MinLength: Integer read FMinLength write FMinLength;
  19. property MinStep: Integer read FMinStep write FMinStep;
  20. end;
  21. TtpPricePartSettingForm = class(TForm)
  22. lePartTotalPrice: TLabeledEdit;
  23. lblFormat: TLabel;
  24. btnOk: TButton;
  25. btnCancel: TButton;
  26. leMinLength: TLabeledEdit;
  27. udMinLength: TUpDown;
  28. leMinStep: TLabeledEdit;
  29. udMinStep: TUpDown;
  30. procedure btnOkClick(Sender: TObject);
  31. procedure lePartTotalPriceChange(Sender: TObject);
  32. procedure lePartTotalPriceKeyPress(Sender: TObject; var Key: Char);
  33. private
  34. function GetPartPrice: Double;
  35. function GetMinLength: Integer;
  36. function GetMinStep: Integer;
  37. public
  38. constructor Create(AInfo: TPricePartInfo);
  39. destructor Destroy; override;
  40. property PartPrice: Double read GetPartPrice;
  41. property MinLength: Integer read GetMinLength;
  42. property MinStep: Integer read GetMinStep;
  43. end;
  44. function PricePartSetting(AInfo: TPricePartInfo): Boolean;
  45. implementation
  46. uses
  47. UtilMethods;
  48. function PricePartSetting(AInfo: TPricePartInfo): Boolean;
  49. var
  50. SettingForm: TtpPricePartSettingForm;
  51. begin
  52. SettingForm := TtpPricePartSettingForm.Create(AInfo);
  53. try
  54. Result := SettingForm.ShowModal = mrOk;
  55. if Result then
  56. begin
  57. AInfo.PartPrice := SettingForm.PartPrice;
  58. AInfo.MinLength := SettingForm.MinLength;
  59. AInfo.MinStep := SettingForm.MinStep;
  60. end;
  61. finally
  62. SettingForm.Free;
  63. end;
  64. end;
  65. {$R *.dfm}
  66. { TtpPricePartSettingForm }
  67. constructor TtpPricePartSettingForm.Create(AInfo: TPricePartInfo);
  68. begin
  69. inherited Create(nil);
  70. if AInfo.PartPrice > 0 then
  71. lePartTotalPrice.Text := FloatToStr(AInfo.PartPrice)
  72. else
  73. lePartTotalPrice.Text := '';
  74. udMinLength.Position := AInfo.MinLength;
  75. udMinStep.Position := AInfo.MinStep;
  76. SetWindowLong(lePartTotalPrice.Handle, GWL_STYLE, GetWindowLong(lePartTotalPrice.Handle, GWL_STYLE) or ES_RIGHT);
  77. SetWindowLong(leMinLength.Handle, GWL_STYLE, GetWindowLong(leMinLength.Handle, GWL_STYLE) or ES_RIGHT);
  78. SetWindowLong(leMinStep.Handle, GWL_STYLE, GetWindowLong(leMinStep.Handle, GWL_STYLE) or ES_RIGHT);
  79. end;
  80. destructor TtpPricePartSettingForm.Destroy;
  81. begin
  82. inherited;
  83. end;
  84. function TtpPricePartSettingForm.GetPartPrice: Double;
  85. begin
  86. Result := StrToFloatDef(lePartTotalPrice.Text, 0);
  87. end;
  88. procedure TtpPricePartSettingForm.btnOkClick(Sender: TObject);
  89. begin
  90. if PartPrice <= 0 then
  91. TipMessage('单标段目标金额应大于0。')
  92. else
  93. ModalResult := mrOk;
  94. end;
  95. procedure TtpPricePartSettingForm.lePartTotalPriceChange(Sender: TObject);
  96. begin
  97. lblFormat.Visible := PartPrice > 0;
  98. lblFormat.Caption := FormatFloat('##,###,###,###.##', PartPrice);
  99. end;
  100. procedure TtpPricePartSettingForm.lePartTotalPriceKeyPress(Sender: TObject;
  101. var Key: Char);
  102. begin
  103. if not (Key in ['0'..'9', '.', #8, #13]) then
  104. Key := #0;
  105. end;
  106. function TtpPricePartSettingForm.GetMinLength: Integer;
  107. begin
  108. Result := udMinLength.Position;
  109. end;
  110. function TtpPricePartSettingForm.GetMinStep: Integer;
  111. begin
  112. Result := udMinStep.Position;
  113. end;
  114. { TPricePartInfo }
  115. constructor TPricePartInfo.Create;
  116. begin
  117. FPartPrice := 0;
  118. FMinLength := 5;
  119. FMinStep := 100;
  120. end;
  121. end.