private void CloneDoctorEventAction_Execute(object sender, PopupWindowShowActionExecuteEventArgs e) { Doctor doctor = FilterDoctorEventAction.SelectedItem.Data as Doctor; // Форма параметров CloneDoctorEventParameters parameters = (CloneDoctorEventParameters)e.PopupWindowViewCurrentObject; using (IObjectSpace os = Application.CreateObjectSpace()) { TimeIntervalCollection intervalCol = activeView.GetVisibleIntervals(); DateTime clonedWeekDateIn = intervalCol.Start; Dictionary <int, List <DoctorEvent> > clonedWeek = new Dictionary <int, List <DoctorEvent> >(); DateTime start = clonedWeekDateIn; int i = 1; // Копируем в буфер неделю, которую мы хотим скопировать while (start < clonedWeekDateIn.AddDays(7)) { clonedWeek[i] = new List <DoctorEvent>(os.GetObjects <DoctorEvent>( DoctorEvent.Fields.AssignedTo == os.GetObject(doctor) & DoctorEvent.Fields.StartOn >= start.Date & DoctorEvent.Fields.EndOn < start.Date.AddDays(1))); start = start.AddDays(1); i++; } int weekIndex = 0; start = clonedWeekDateIn.Date.AddDays(7); while (weekIndex < parameters.NextWeeksCount) { int dayIndex = 1; while (dayIndex <= 7) { foreach (DoctorEvent clonedEvent in clonedWeek[dayIndex]) { var newEvent = os.CreateObject <DoctorEvent>(); newEvent.AssignedTo = clonedEvent.AssignedTo; newEvent.Label = clonedEvent.Label; newEvent.StartOn = start.AddHours(clonedEvent.StartOn.Hour).AddMinutes(clonedEvent.StartOn.Minute); newEvent.EndOn = start.AddHours(clonedEvent.EndOn.Hour).AddMinutes(clonedEvent.EndOn.Minute); } dayIndex++; start = start.AddDays(1); } weekIndex++; } // Отключение аудита Session session = ((XPObjectSpace)os).Session; AuditTrailService.Instance.EndSessionAudit(session); os.CommitChanges(); } // Обновление списочного представления if (rootListView != null && rootListView.ObjectSpace != null && rootListView.CollectionSource != null) { rootListView.CollectionSource.Reload(); } }
private void CloneDoctorEventAction_CustomizePopupWindowParams(object sender, CustomizePopupWindowParamsEventArgs e) { CloneDoctorEventParameters parameters = new CloneDoctorEventParameters(); e.View = Application.CreateDetailView(ObjectSpaceInMemory.CreateNew(), parameters, true); }