ec_controltimer.pas 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. unit ec_controltimer;
  2. {$mode objfpc}{$H+}
  3. interface
  4. uses
  5. Classes, SysUtils, Forms, Controls, Graphics, Dialogs, ExtCtrls, Buttons,
  6. StdCtrls, Spin, ec_base;
  7. type
  8. { TECControlTimerFrame }
  9. TECControlTimerFrame = class(TECBaseFrame)
  10. MinutesLabel: TLabel;
  11. SecondsLabel: TLabel;
  12. MinutesSpinEdit: TSpinEdit;
  13. SecondsSpinEdit: TSpinEdit;
  14. TimeGroupBox: TGroupBox;
  15. OperationRadioGroup: TRadioGroup;
  16. procedure OperationRadioGroupSelectionChanged(Sender: TObject);
  17. private
  18. procedure InitialSetup;
  19. public
  20. procedure InitNew; override;
  21. procedure InitExisting; override;
  22. procedure MakeResultingCommand; override;
  23. end;
  24. var
  25. ECControlTimerFrame: TECControlTimerFrame;
  26. implementation
  27. {$R *.lfm}
  28. uses
  29. fpjson, constants;
  30. resourcestring
  31. rsStartTimer = 'Start';
  32. rsStopTimer = 'Stop';
  33. { TECControlTimerFrame }
  34. procedure TECControlTimerFrame.OperationRadioGroupSelectionChanged(
  35. Sender: TObject);
  36. begin
  37. TimeGroupBox.Visible := OperationRadioGroup.ItemIndex = 0;
  38. end;
  39. procedure TECControlTimerFrame.InitialSetup;
  40. begin
  41. with OperationRadioGroup.Items do begin
  42. BeginUpdate;
  43. Clear;
  44. Add(rsStartTimer);
  45. Add(rsStopTimer);
  46. EndUpdate;
  47. end;
  48. end;
  49. procedure TECControlTimerFrame.InitNew;
  50. begin
  51. InitialSetup;
  52. MinutesSpinEdit.Value := 0;
  53. SecondsSpinEdit.Value := 0;
  54. OperationRadioGroup.ItemIndex := 0;
  55. end;
  56. procedure TECControlTimerFrame.InitExisting;
  57. var
  58. Params: TJSONArray;
  59. Operation: Integer = 0;
  60. Time: Integer = 0;
  61. begin
  62. InitialSetup;
  63. Params := GetFirstParams;
  64. if (Params.Count >= 1) and (Params[0].JSONType = jtNumber) then
  65. Operation := Params.Integers[0];
  66. if (Params.Count >= 2) and (Params[1].JSONType = jtNumber) then
  67. Time := Params.Integers[1];
  68. OperationRadioGroup.ItemIndex := Operation;
  69. MinutesSpinEdit.Value := Time div 60;
  70. SecondsSpinEdit.Value := Time mod 60;
  71. end;
  72. procedure TECControlTimerFrame.MakeResultingCommand;
  73. begin
  74. ResultingCommand := SingleLineResultingCommand(
  75. CONTROL_TIMER_EC_CODE,
  76. TJSONArray.Create([
  77. OperationRadioGroup.ItemIndex,
  78. MinutesSpinEdit.Value * 60 + SecondsSpinEdit.Value
  79. ])
  80. );
  81. end;
  82. end.