From bd12cc49b5fd9a9a6f18ce90d204cec2176996f4 Mon Sep 17 00:00:00 2001
From: lazhen <17772815105@139.com>
Date: 星期四, 25 七月 2024 16:48:42 +0800
Subject: [PATCH] 批量不可用事件新建bug

---
 Calendars/BL/Type_LibCal_LeadingParticipation/Method_UpdateCalendarWhenChanged.qbl |    2 
 Calendars/BL/Type_LibCal_Subscription/Method_CopyOccurrences#486.qbl               |    2 
 _Main/BL/Type_LibCal_Subscription/Method_CopyOccurrences#486.qbl                   |   33 +++++++++++
 Calendars/BL/Type_LibCal_LeadingParticipation/Method_Update.qbl                    |    2 
 _Main/BL/Type_LibCal_Event/StaticMethod_CreateUpdateFromUI0.qbl                    |   94 +++++++++++++++++++++++++++++++
 Calendars/BL/Type_LibCal_Subscription/Method_CopyOccurrences.qbl                   |    2 
 Calendars/BL/Type_LibCal_Event/Method_UpdateRecurrencePattern.qbl                  |    2 
 Calendars/BL/Type_LibCal_LeadingParticipation/Method_SetSubscribers.qbl            |    2 
 Calendars/BL/Type_LibCal_Participation/Attribute_EndTime.qbl                       |    1 
 _Main/BL/Type_LibCal_Event/StaticMethod_CreateUpdateFromUI.qbl                     |   21 ++++--
 _Main/BL/Type_LibCal_Subscription/_ROOT_Type_LibCal_Subscription.qbl               |    6 ++
 Calendars/BL/Type_LibCal_Participation/Method_UpdateRecurrencePeriod.qbl           |    2 
 12 files changed, 154 insertions(+), 15 deletions(-)

diff --git a/Calendars/BL/Type_LibCal_Event/Method_UpdateRecurrencePattern.qbl b/Calendars/BL/Type_LibCal_Event/Method_UpdateRecurrencePattern.qbl
index d6a1681..b7ff364 100644
--- a/Calendars/BL/Type_LibCal_Event/Method_UpdateRecurrencePattern.qbl
+++ b/Calendars/BL/Type_LibCal_Event/Method_UpdateRecurrencePattern.qbl
@@ -74,5 +74,5 @@
     // Directly update the relation from the Participations to the RecurrencePattern.
     Transaction::Transaction().Propagate( relation( LibCal_Participation, RecurrencePattern ) );
   *]
-  InterfaceProperties { Accessibility: 'Module' }
+  InterfaceProperties { Accessibility: 'Extensible' }
 }
diff --git a/Calendars/BL/Type_LibCal_LeadingParticipation/Method_SetSubscribers.qbl b/Calendars/BL/Type_LibCal_LeadingParticipation/Method_SetSubscribers.qbl
index 4071c7b..5ca83a8 100644
--- a/Calendars/BL/Type_LibCal_LeadingParticipation/Method_SetSubscribers.qbl
+++ b/Calendars/BL/Type_LibCal_LeadingParticipation/Method_SetSubscribers.qbl
@@ -11,5 +11,5 @@
     
     this.SetSubscribers( subscribers_i, useLeadingPeriod );
   *]
-  InterfaceProperties { Accessibility: 'Module' }
+  InterfaceProperties { Accessibility: 'Extensible' }
 }
diff --git a/Calendars/BL/Type_LibCal_LeadingParticipation/Method_Update.qbl b/Calendars/BL/Type_LibCal_LeadingParticipation/Method_Update.qbl
index ebecee3..4b6137d 100644
--- a/Calendars/BL/Type_LibCal_LeadingParticipation/Method_Update.qbl
+++ b/Calendars/BL/Type_LibCal_LeadingParticipation/Method_Update.qbl
@@ -36,5 +36,5 @@
       subscription.EndDate(   endDate_i   );
     }
   *]
-  InterfaceProperties { Accessibility: 'Module' }
+  InterfaceProperties { Accessibility: 'Extensible' }
 }
diff --git a/Calendars/BL/Type_LibCal_LeadingParticipation/Method_UpdateCalendarWhenChanged.qbl b/Calendars/BL/Type_LibCal_LeadingParticipation/Method_UpdateCalendarWhenChanged.qbl
index ec75609..d62346e 100644
--- a/Calendars/BL/Type_LibCal_LeadingParticipation/Method_UpdateCalendarWhenChanged.qbl
+++ b/Calendars/BL/Type_LibCal_LeadingParticipation/Method_UpdateCalendarWhenChanged.qbl
@@ -9,5 +9,5 @@
     onlyWhenChanged := true;
     this.UpdateCalendar( onlyWhenChanged );
   *]
-  InterfaceProperties { Accessibility: 'Module' }
+  InterfaceProperties { Accessibility: 'Extensible' }
 }
diff --git a/Calendars/BL/Type_LibCal_Participation/Attribute_EndTime.qbl b/Calendars/BL/Type_LibCal_Participation/Attribute_EndTime.qbl
index 845cbc7..1b2a5c7 100644
--- a/Calendars/BL/Type_LibCal_Participation/Attribute_EndTime.qbl
+++ b/Calendars/BL/Type_LibCal_Participation/Attribute_EndTime.qbl
@@ -5,5 +5,4 @@
   #keys: '3[131094.0.1190114209][131094.0.1190114208][131094.0.1190114210]'
   Description: 'EndTime of the event. Is only relevant for non-recurring events.'
   ValueType: DateTime
-  InterfaceProperties { Accessibility: 'Module' }
 }
diff --git a/Calendars/BL/Type_LibCal_Participation/Method_UpdateRecurrencePeriod.qbl b/Calendars/BL/Type_LibCal_Participation/Method_UpdateRecurrencePeriod.qbl
index 603dca4..ce015ce 100644
--- a/Calendars/BL/Type_LibCal_Participation/Method_UpdateRecurrencePeriod.qbl
+++ b/Calendars/BL/Type_LibCal_Participation/Method_UpdateRecurrencePeriod.qbl
@@ -50,5 +50,5 @@
     // this.CalcIsRecurring(); is not good enough here, explicit propagation is required.
     Transaction::Transaction().Propagate( attribute( LibCal_Participation, IsRecurring ) );
   *]
-  InterfaceProperties { Accessibility: 'Module' }
+  InterfaceProperties { Accessibility: 'Extensible' }
 }
diff --git "a/Calendars/BL/Type_LibCal_Subscription/Method_CopyOccurrences\043486.qbl" "b/Calendars/BL/Type_LibCal_Subscription/Method_CopyOccurrences\043486.qbl"
index 12a9e5e..909a395 100644
--- "a/Calendars/BL/Type_LibCal_Subscription/Method_CopyOccurrences\043486.qbl"
+++ "b/Calendars/BL/Type_LibCal_Subscription/Method_CopyOccurrences\043486.qbl"
@@ -31,5 +31,5 @@
       }
     }
   *]
-  InterfaceProperties { Accessibility: 'Module' }
+  InterfaceProperties { Accessibility: 'Extensible' }
 }
diff --git a/Calendars/BL/Type_LibCal_Subscription/Method_CopyOccurrences.qbl b/Calendars/BL/Type_LibCal_Subscription/Method_CopyOccurrences.qbl
index 5a597dd..baaaa38 100644
--- a/Calendars/BL/Type_LibCal_Subscription/Method_CopyOccurrences.qbl
+++ b/Calendars/BL/Type_LibCal_Subscription/Method_CopyOccurrences.qbl
@@ -28,5 +28,5 @@
       }            
     }
   *]
-  InterfaceProperties { Accessibility: 'Module' }
+  InterfaceProperties { Accessibility: 'Extensible' }
 }
diff --git a/_Main/BL/Type_LibCal_Event/StaticMethod_CreateUpdateFromUI.qbl b/_Main/BL/Type_LibCal_Event/StaticMethod_CreateUpdateFromUI.qbl
index 5660545..df18866 100644
--- a/_Main/BL/Type_LibCal_Event/StaticMethod_CreateUpdateFromUI.qbl
+++ b/_Main/BL/Type_LibCal_Event/StaticMethod_CreateUpdateFromUI.qbl
@@ -47,22 +47,30 @@
     
     //鍙湁閫氳繃鎵归噺鍒涘缓鐣岄潰涓斿凡鏈夊悓鍚嶄簨浠惰繘鍏ヤ笅闈㈡搷浣�
     if( ismultiple and not isnull( event ) ){
+      event.IsMultiple( true );
       lp        := event.LeadingParticipation();
       timezone  := lp.Calendar().GetTimeZone();
       starttime := startDate_i.DateTime( timezone ).AddAsPeriod( timezone, startTimeOfDay_i );
       endtime   := endDate_i.DateTime( timezone ).AddAsPeriod( timezone, endTimeOfDay_i );
+      etis      := selectset( lp, Subscription.ExplicitTimeInterval, eti, true );
     //  startDate := starttime.Date( timezone );
     //  endDate   := endtime.Date( timezone ) - ifexpr( endtime = endtime.StartOfDay( timezone ), 1, 0 );
-      lp.AddSubscribers( subscribers_i, true );;
       leadingETI := selectobject( lp, ExplicitTimeInterval, eti, eti.Start() = starttime and eti.End() = endtime );
+    
       if( isnull( leadingETI ) ){
         leadingETI := lp.CreateTimeInterval( starttime, endtime, event.Capacity() );
       }
-    //  info( '-----------------------2-----------------', lp.ExplicitTimeInterval( relsize ) );
+      lp.AddSubscribers( subscribers_i, true );
+    
       if( not isnull( leadingETI ) ){
         traverse( lp, Subscription, subscription, subscribers_i.Find( subscription.Calendar() ) >= 0 ){
-          traverse( subscription, ExplicitTimeInterval, eti, not ( eti.Start() = starttime and eti.End() = endtime ) ){
+    
+          traverse( subscription, ExplicitTimeInterval, eti, etis.Find( eti ) < 0 ){
             eti.Delete();
+          }
+          subscribingETI := subscription.CreateTimeInterval( starttime, endtime, event.Capacity() );
+          if( not isnull( subscribingETI ) ){
+            subscribingETI.LeadingETI( relset, leadingETI );
           }
         }
       }
@@ -73,14 +81,13 @@
                                       patternType_i, patternDaily_IsEveryWeekday_i, patternWeekly_Weekdays_i, 
                                       patternMonthly_IsDay_i, patternMonthly_Day_i, patternMonthly_WeekOfMonth_i, patternMonthly_DayOfWeek_i,
                                       patternYearly_IsDate_i, patternYearly_Month_i, patternYearly_Day_i, patternYearly_WeekOfMonth_i, patternYearly_DayOfWeek_i,
-                                      periodType_i, periodStartDate_i, nrOfOccurrences_i, periodEndDate_i, subscribers_i );
+                                      periodType_i, periodStartDate_i, nrOfOccurrences_i, periodEndDate_i, subscribers_i, ismultiple );
     }
+    
     if( not isnull( event ) ){
       event.EventType( relset, eventtype_i );
     }
-    if( ismultiple ){
-      event.IsMultiple( ismultiple );
-    }
+    
     return event;
   *]
 }
diff --git a/_Main/BL/Type_LibCal_Event/StaticMethod_CreateUpdateFromUI0.qbl b/_Main/BL/Type_LibCal_Event/StaticMethod_CreateUpdateFromUI0.qbl
new file mode 100644
index 0000000..a7e3fbe
--- /dev/null
+++ b/_Main/BL/Type_LibCal_Event/StaticMethod_CreateUpdateFromUI0.qbl
@@ -0,0 +1,94 @@
+Quintiq file version 2.0
+#parent: #root
+StaticMethod CreateUpdateFromUI (
+  LibCal_Calendar owner_i,
+  LibCal_LeadingParticipation participation_i,
+  String subject_i,
+  String description_i,
+  String type_i,
+  Real capacity_i,
+  LibCal_EventCategory category_i,
+  Boolean isDefault_i,
+  Date startDate_i,
+  Duration startTimeOfDay_i,
+  Date endDate_i,
+  Duration endTimeOfDay_i,
+  Boolean isAllDay_i,
+  Boolean isRecurring_i,
+  Number recurrenceInterval_i,
+  String patternType_i,
+  Boolean patternDaily_IsEveryWeekday_i,
+  String patternWeekly_Weekdays_i,
+  Boolean patternMonthly_IsDay_i,
+  Number patternMonthly_Day_i,
+  String patternMonthly_WeekOfMonth_i,
+  String patternMonthly_DayOfWeek_i,
+  Boolean patternYearly_IsDate_i,
+  Number patternYearly_Month_i,
+  Number patternYearly_Day_i,
+  String patternYearly_WeekOfMonth_i,
+  String patternYearly_DayOfWeek_i,
+  String periodType_i,
+  Date periodStartDate_i,
+  Number nrOfOccurrences_i,
+  Date periodEndDate_i,
+  LibCal_Calendars subscribers_i,
+  Boolean is_multiple
+) as LibCal_Event
+{
+  Description: 'Create and/or update an Event and its LeadingParticipation, based on information from the UI.'
+  TextBody:
+  [*
+    event    := null( LibCal_Event );
+    leadPart := participation_i;
+    timezone := owner_i.GetTimeZone();
+    
+    if( isnull( leadPart ) )
+    {
+      // Create a new Event. This also creates a new LeadingParticipation.
+      event    := LibCal_Event::Create( owner_i, "", Date::Today( timezone ), 1 );
+      leadPart := event.LeadingParticipation();
+    }
+    else
+    {
+      // Get the event of the participation.
+      event := leadPart.Event();
+    }
+    
+    if( is_multiple ){
+      event.IsMultiple( is_multiple );
+    }
+    
+    // Update the event...
+    duration := endDate_i.Add( timezone, endTimeOfDay_i ) - startDate_i.Add( timezone, startTimeOfDay_i );
+    isFromUI := true;
+    event.Update( subject_i, description_i, type_i, capacity_i, isDefault_i, startTimeOfDay_i, endTimeOfDay_i, duration, isAllDay_i, isFromUI );
+    
+    // Changing the category is a different kind of change, with no impact on the event itself.
+    event.EventCategory( relset, category_i );
+    
+    // ...and its recurrence pattern.
+    event.UpdateRecurrencePattern( isRecurring_i, patternType_i, recurrenceInterval_i,
+                                   patternDaily_IsEveryWeekday_i,
+                                   patternWeekly_Weekdays_i,
+                                   patternMonthly_IsDay_i, patternMonthly_Day_i,  patternMonthly_WeekOfMonth_i, patternMonthly_DayOfWeek_i,
+                                   patternYearly_IsDate_i, patternYearly_Month_i, patternYearly_Day_i, patternYearly_WeekOfMonth_i, patternYearly_DayOfWeek_i );
+    
+    // Update the participation...
+    leadPart.Update( startDate_i, endDate_i );
+    
+    // ...and its recurrence period.
+    leadPart.UpdateRecurrencePeriod( isRecurring_i, periodType_i, periodStartDate_i, nrOfOccurrences_i, periodEndDate_i );
+    
+    // Effectuate the changes.
+    leadPart.UpdateCalendarWhenChanged();
+    
+    // Set the subscribers. Must be done *after* UpdateCalendar.
+    leadPart.SetSubscribers( subscribers_i );
+    
+    // Call a post-processing method that can be extended to implement additional logic.
+    event.OnCreateUpdateFromUI();
+    
+    return event;
+  *]
+}
diff --git "a/_Main/BL/Type_LibCal_Subscription/Method_CopyOccurrences\043486.qbl" "b/_Main/BL/Type_LibCal_Subscription/Method_CopyOccurrences\043486.qbl"
new file mode 100644
index 0000000..fd50beb
--- /dev/null
+++ "b/_Main/BL/Type_LibCal_Subscription/Method_CopyOccurrences\043486.qbl"
@@ -0,0 +1,33 @@
+Quintiq file version 2.0
+#parent: #root
+Method CopyOccurrences #extension
+{
+  TextBody:
+  [*
+    timezone := this.Calendar().GetTimeZone();
+    
+    if( this.IsRecurring() and not this.LeadingParticipation().Event().IsMultiple() )
+    {
+      // If the participation ends at the start of a day, this is the start of the next day.
+      // In that case, one day should be subtracted in order to not take the next day into account. 
+      endDate := this.LeadingParticipation().RecurrencePeriod().EndDate()
+               - ifexpr( this.LeadingParticipation().EndTime() = this.LeadingParticipation().EndTime().StartOfDay( timezone ), 1, 0 );
+    
+      this.CopyOccurrences( this.LeadingParticipation().RecurrencePeriod().StartDate(), endDate );
+    }
+    else
+    {
+      // In case of a non-recurring event, there is only one occurrence (i.e. ExplicitTimeInterval),
+      // with an arbitrary Start and End. The Start and End of this occurrence must be used in order to have it copied to the subscription.
+      leadingETI := select( this.LeadingParticipation(), ExplicitTimeInterval, eti, true, true );
+    
+      if( not isnull( leadingETI ) )
+      {
+        endDate := leadingETI.End().Date( timezone )
+                 - ifexpr( leadingETI.End() = leadingETI.End().StartOfDay( timezone ), 1, 0 );
+        
+        this.CopyOccurrences( leadingETI.Start().Date( timezone ), endDate );
+      }
+    }
+  *]
+}
diff --git a/_Main/BL/Type_LibCal_Subscription/_ROOT_Type_LibCal_Subscription.qbl b/_Main/BL/Type_LibCal_Subscription/_ROOT_Type_LibCal_Subscription.qbl
new file mode 100644
index 0000000..ba6ae5b
--- /dev/null
+++ b/_Main/BL/Type_LibCal_Subscription/_ROOT_Type_LibCal_Subscription.qbl
@@ -0,0 +1,6 @@
+Quintiq file version 2.0
+#root
+#parent: #DomainModel
+TypeSpecialization LibCal_Subscription #extension
+{
+}

--
Gitblit v1.9.3