editlearningformunit.pas 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. unit editlearningformunit;
  2. {$mode objfpc}{$H+}
  3. interface
  4. uses
  5. Classes, SysUtils, Forms, Controls, Graphics, Dialogs, StdCtrls, Spin,
  6. ButtonPanel, database, LCLTranslator;
  7. type
  8. { TEditLearningForm }
  9. TEditLearningForm = class(TForm)
  10. ResultButtonPanel: TButtonPanel;
  11. NoteEdit: TEdit;
  12. NoteLabel: TLabel;
  13. SkillComboBox: TComboBox;
  14. SkillLabel: TLabel;
  15. LevelLabel: TLabel;
  16. LevelSpinEdit: TSpinEdit;
  17. procedure CancelButtonClick(Sender: TObject);
  18. procedure LevelSpinEditChange(Sender: TObject);
  19. procedure NoteEditChange(Sender: TObject);
  20. procedure OKButtonClick(Sender: TObject);
  21. procedure SkillComboBoxChange(Sender: TObject);
  22. procedure FillItems;
  23. private
  24. ResultWasAccepted: Boolean;
  25. Db: TDatabase;
  26. public
  27. SelectedSkillId: Integer;
  28. SelectedLevel: Integer;
  29. SelectedNote: String;
  30. function ShowLearningEdit(ADb: TDatabase; ASkillLevel: Integer = 1; ASkillId: Integer = 1; ANote: String = ''): Boolean;
  31. end;
  32. var
  33. EditLearningForm: TEditLearningForm;
  34. implementation
  35. {$R *.lfm}
  36. { TEditLearningForm }
  37. procedure TEditLearningForm.SkillComboBoxChange(Sender: TObject);
  38. begin
  39. SelectedSkillId := SkillComboBox.ItemIndex + 1;
  40. end;
  41. procedure TEditLearningForm.FillItems;
  42. var
  43. SkillNames: TStringList;
  44. begin
  45. if Db = nil then begin
  46. SkillComboBox.Items.Clear;
  47. Exit
  48. end;
  49. SkillNames := Db.GetNames(Db.Skills);
  50. try
  51. SkillComboBox.Items.Assign(SkillNames);
  52. finally
  53. SkillNames.Free;
  54. end;
  55. end;
  56. function TEditLearningForm.ShowLearningEdit(ADb: TDatabase;
  57. ASkillLevel: Integer = 1; ASkillId: Integer = 1; ANote: String = ''): Boolean;
  58. begin
  59. ResultWasAccepted := False;
  60. Db := ADb;
  61. LevelSpinEdit.Value := ASkillLevel;
  62. SelectedLevel := ASkillLevel;
  63. FillItems;
  64. SkillComboBox.ItemIndex := ASkillId - 1;
  65. SelectedSkillId := ASkillId;
  66. NoteEdit.Text := ANote;
  67. SelectedNote := ANote;
  68. ShowModal;
  69. ShowLearningEdit := ResultWasAccepted
  70. end;
  71. procedure TEditLearningForm.OKButtonClick(Sender: TObject);
  72. begin
  73. ResultWasAccepted := True;
  74. Close
  75. end;
  76. procedure TEditLearningForm.CancelButtonClick(Sender: TObject);
  77. begin
  78. ResultWasAccepted := False;
  79. Close
  80. end;
  81. procedure TEditLearningForm.LevelSpinEditChange(Sender: TObject);
  82. begin
  83. SelectedLevel := LevelSpinEdit.Value;
  84. end;
  85. procedure TEditLearningForm.NoteEditChange(Sender: TObject);
  86. begin
  87. SelectedNote := NoteEdit.Text;
  88. end;
  89. end.