tvplanit: Add datastore method DeleteResource.

git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@8351 8e941d3f-bd1b-0410-a28a-d453659cc2b4
This commit is contained in:
wp_xxyyzz
2022-07-16 16:38:36 +00:00
parent 6b91b30c26
commit beb0481d33
5 changed files with 51 additions and 5 deletions

View File

@ -23,7 +23,7 @@ object Form1: TForm1
AnchorSideLeft.Control = Panel1
Left = 4
Height = 23
Top = 5
Top = 4
Width = 208
DataStore = VpIniDatastore1
Style = csDropDownList
@ -61,6 +61,19 @@ object Form1: TForm1
OnClick = BtnEditResClick
TabOrder = 2
end
object BtnDeleteRes: TButton
AnchorSideLeft.Control = BtnEditRes
AnchorSideLeft.Side = asrBottom
Left = 416
Height = 25
Top = 4
Width = 107
AutoSize = True
BorderSpacing.Left = 4
Caption = 'Delete resource'
OnClick = BtnDeleteResClick
TabOrder = 3
end
end
object PageControl1: TPageControl
Left = 0

View File

@ -17,6 +17,7 @@ type
TForm1 = class(TForm)
BtnNewRes: TButton;
BtnEditRes: TButton;
BtnDeleteRes: TButton;
PageControl1: TPageControl;
Panel1: TPanel;
Panel2: TPanel;
@ -36,6 +37,7 @@ type
VpResourceEditDialog1: TVpResourceEditDialog;
VpTaskList1: TVpTaskList;
VpWeekView1: TVpWeekView;
procedure BtnDeleteResClick(Sender: TObject);
procedure BtnNewResClick(Sender: TObject);
procedure BtnEditResClick(Sender: TObject);
procedure FormCreate(Sender: TObject);
@ -65,6 +67,22 @@ begin
VpResourceEditDialog1.AddNewResource;
end;
procedure TForm1.BtnDeleteResClick(Sender: TObject);
var
res: TVpResource;
begin
res := VpControlLink1.Datastore.Resource;
if res = nil then
exit;
if MessageDlg('Do you really want to delete the resource "' + res.Description + '"?',
mtConfirmation, [mbYes, mbNo], 0) <> mrYes
then
exit;
VpControlLink1.Datastore.DeleteResource(res);
end;
// Edits the currently selected resource
procedure TForm1.BtnEditResClick(Sender: TObject);
begin

View File

@ -4,11 +4,12 @@ object MainForm: TMainForm
Top = 134
Width = 959
Caption = 'Turbo Power VisualPlanIt Demo'
ClientHeight = 596
ClientHeight = 576
ClientWidth = 959
Menu = MainMenu1
OnCloseQuery = FormCloseQuery
OnCreate = FormCreate
LCLVersion = '2.3.0.0'
object Panel1: TPanel
Left = 125
Height = 596
@ -58,7 +59,7 @@ object MainForm: TMainForm
Height = 548
Top = 48
Width = 834
PageIndex = 4
PageIndex = 0
Align = alClient
TabOrder = 1
TabStop = True

View File

@ -363,7 +363,7 @@ begin
if MessageDlg(Format(RSConfirmDeleteRes, [res.Description]), mtConfirmation, [mbYes, mbNo], 0) = mrYes then
begin
VpControlLink1.Datastore.PurgeResource(res);
VpControlLink1.Datastore.DeleteResource(res);
UpdateOtherResourcesList;
end;
end;

View File

@ -305,6 +305,8 @@ type
procedure UpdateGroupEvents; virtual;
procedure DeleteResource(Res: TVpResource);
property Connected : boolean read FConnected write SetConnected;
property Loading : Boolean read FLoading write FLoading;
property Resource: TVpResource read FResource write SetResource;
@ -518,6 +520,18 @@ begin
inherited;
end;
procedure TVpCustomDataStore.DeleteResource(Res: TVpResource);
begin
if Res = nil then
exit;
if Res = FResource then
FResource := nil;
Res.Deleted := true;
PurgeResource(Res);
end;
{=====}
procedure TVpCustomDataStore.DeregisterAllWatchers;
@ -1186,7 +1200,7 @@ begin
for I := 0 to pred(DataStore.Resources.Count) do begin
Res := DataStore.Resources.Items[I];
if Res = nil then
if (Res = nil) or Res.Deleted then
Continue;
if Res.Description <> '' then
Items.Add(Res.Description);