TTMSFNCPlanner: Guidance with Adding Items.

Hi,

I'm still struggling with the TTMSFNCPlanner component.

I have the Planner component connected to TTMSFNCPlannerDatabaseAdapter, connected to a DataSource, connected to a table.

I want to add an appointment (item) to the Day view.

Here is a screenshot of the test application with a custom dialog open:

https://www.stevegill.com.au/images/TTMSFNCPlanner.png

There are no data-aware controls used in the dialog. Here is the code for adding an item:


So what do I need to add in this code block:

      if AppointmentDialog.ShowModal = mrOk then
      begin

      end;

Thanks.

Steve

Hi,


To save an item in the database from a custom editor, you need to use the following code:



var
  st, et: TDateTime;
  it: TTMSFNCPlannerItem;
begin
  st := Now;
  et := Now + 1;


  it := TMSFNCPlanner1.AddItem(st, et);
  it.DataString := 'Data1;Data2;Data3';
  TMSFNCPlannerDatabaseAdapter1.InsertItem(it);


As you have additional data in your dialog that needs to be saved as well you need to have an event attached to the OnItemToFields and OnFieldsToItem, and store the data inside the DataString property. You could also write a custom class that saves the data to the DataObject instead if you are using data other than strings or you wish to not have to convert to values while saving.



procedure TForm79.TMSFNCPlannerDatabaseAdapter1FieldsToItem(Sender: TObject;
  AFields: TFields; AItem: TTMSFNCPlannerItem);
var
  s: string;
begin
  //Data1
  s := AFields.FieldByName('Data1').AsString;
  //Data2
  s := s + ';' +AFields.FieldByName('Data2').AsString;
  //Data3
  s := s + ';' +AFields.FieldByName('Data3').AsString;


  AItem.DataString := s;
end;


procedure TForm79.TMSFNCPlannerDatabaseAdapter1ItemToFields(Sender: TObject;
  AItem: TTMSFNCPlannerItem; AFields: TFields);
var
  sl: TStringList;
begin
  sl := TStringList.Create;
  try
    TTMSFNCUtils.Split(';', AItem.DataString, sl);
    //Data1
    AFields.FieldByName('Data1').AsString := sl[0];
    //Data2
    AFields.FieldByName('Data2').AsString := sl[1];
    //Data3
    AFields.FieldByName('Data3').AsString := sl[2];
  finally
    sl.Free;
  end;
end;

Thanks Pieter, that worked!

= Steve