Quintiq file version 2.0
#parent: #root
Method OnOK () id:Method_DialogCreateEditPeriodSpec_OnOK
{
  #keys: '[139394.0.523469829]'
  Body:
  [*
    // On OK
    
    data := DataHolderDialogData.Data();
    isnew := isnull( data.WrappedInstance() );
    confirmation := true;
    isusedforplanning := RadioButtonGroupUseForPlanning.BoundValue() ="true";
    periodaligment := DateTimeSelectorPeriodAlignment.DateTime();
    timeunit := DropDownStringListTimeUnit.Text();
    nroftimeunit := ApplicationMacroPlanner.FormatStringToNumber( EditFieldNrOfTimeUnits.Text() );
    nrofhistoricalperiod := ApplicationMacroPlanner.FormatStringToNumber( EditFieldNrOfHistorialPeriods.Text() );
    nroffutureperiod := ApplicationMacroPlanner.FormatStringToNumber( EditFieldNrOfFuturePeriods.Text() );
    
    //may need to pop messagebox during create or edit
    if(  PeriodSpecification_MP::GetChangeOfPlanningPeriodsAtEdition(  data.MacroPlan(),
                                                                       data.WrappedInstance(),
                                                                       isusedforplanning,
                                                                       periodaligment,
                                                                       nroftimeunit,
                                                                       timeunit,
                                                                       nrofhistoricalperiod,
                                                                       nroffutureperiod, 
                                                                       isnew                                                                   
                                                                     ) )
    {
      confirmation := WebMessageBox::Warning( Translations::MP_PeriodSpecification_MP_ChangePlanningPeriodDefinition(),
                                              Translations::MP_Designer_YesNo(), true) =0;
    }     
    if ( confirmation )
    {
      if( isnew ) //new
      {
        periodspec := PeriodSpecification_MP::Create( EditFieldID.Text(),
                                                      MacroPlan,
                                                      timeunit,
                                                      nroftimeunit,
                                                      periodaligment,
                                                      nrofhistoricalperiod,
                                                      nroffutureperiod,
                                                      false, //isfromdb
                                                      isusedforplanning,
                                                      false //isdummyplanningperiod
                                                    );
        // Access the form, select new period spec
        DataHolderForm.Data().ListPeriodSpec().SelectByKey( periodspec.Key() );
      }
      else  //update
      {
        data.WrappedInstance().Update( EditFieldID.Text(),        // Read-only attribute wont be update during apply changes
                                       timeunit,
                                       nroftimeunit,
                                       periodaligment,
                                       nrofhistoricalperiod,
                                       nroffutureperiod,
                                       true, //synchronize
                                       false , //isfromdb
                                       isusedforplanning,
                                       true //iscleanupactuals
                                       );
      }
      this.Close();
    }
  *]
}
