WaitList to DBPlanner with MoveToPlanner

Hello,


I try to build a new planner form with 1 TPlannerWaitList wich contains Items based on a DB table.
For each item in TPlannerWaitList, I have a KeyField ( a guid) already setted.

On my TDBPlanner, I create OnDragDrop event inwhich I write this :

procedure TFrmPlanning.PlannerDBDragDrop(Sender, Source: TObject;
  X, Y: Integer);
var
  newItem                : TPlannerItem;
  rv                     : integer;
begin
  inherited;
  if (source is tplannerwaitlist) then
  begin
      newItem := (Source as TPlannerwaitlist).MoveToPlanner(PlannerDB, (Source as TPlannerWaitlist).ItemIndex, X, Y);
 end;
end; 

That's working fine bu my problem is that MoveToPlanner Create a new Item => create a new record inside my table...
Or I doesn't want to create a new record but only update my current record (the origin record of my waitlist's item transferred to my planner) with infos configured in my TDBWeekSource (RessourceId, StartTime, EndTime,...)

Where can I configure or what can I implement to do this?

Thanks a lot ! 

MoveToPlanner will indeed create a new PlannerItem in the TDBPlanner and thus also a new record. So, you will not be able to use the MoveToPlanner() method.

I would assume there is some DB field you use to differentiate between PlannerItems in the DBPlanner & PlannerItems in the PlannerWaitList.
In your drag & drop operation, you'd then need to:
1) change the value of the DB field to indicate the PlannerItem should be displayed in the DBPlanner and possibly update other DB fields like StartTime/EndTime.
2) Call DBPlanner.Refresh so it reloads all PlannerItems and thus also the one for which the drag & drop just switched the DB field to be loaded in the DBPlanner.
3) Either refresh the PlannerWaitList or programmatically remove the item from the list.

Hello Bruno,


thanks for you smart answer ! Indeed I can do with this procedure. I call you back later with my results ;)

Dear Bruno,


I have a question about fields update on DragDrop event
In my code just below, I comment my call to "MoveToPlanner method" to replace it by a custom private procedure wich update my DB context before doing refresh of TPlanner and TWaitList like you suggest.
But I need to passed to my procedure 4 values => Items ID := ok But where I can find my resourceId / startTime and EndTime?

Thanks a lot
Nicolas Lemielle


procedure TFrmPlanning.PlannerDBDragDrop(Sender, Source: TObject;
  X, Y: Integer);
var
  newItem                : TPlannerItem;
  StartTime : TDateTime;
  EndTime : TDateTime;
  ResourceId : integer;
begin
  inherited;
  if (source is tplannerwaitlist) then
  begin
      StartTime := ??;
      EndTime := ??;
      ResourceId := ??;
      PlanThisFolder((Source as TPlannerwaitlist).Items[(Source as TPlannerWaitlist).ItemIndex].ID, StartTime, EndTime, ResourceId);


      //newItem := (Source as TPlannerwaitlist).MoveToPlanner(PlannerDB, (Source as TPlannerWaitlist).ItemIndex, X, Y);

You can convert the mouse X,Y coordinate to a position value & timeslot with:


cell: tpoint;
cell := Planner.XYToCell(X,Y);

Depending on the orientation, cell.X or cell.Y will be your position index and when you use DBxxxSource.ResourceMap, you can lookup the resource ID this way.
With the index along the time axis, you can get the start & end time of the timeslot with Planner.CellToAbsTime(t, starttime, endtime) where t will be either cell.X or cell.Y depending on Planner orientation.

It runs perfectly thanks !!