Exemplo n.º 1
0
        private void CreateDoctorEventAction_CustomizePopupWindowParams(object sender, CustomizePopupWindowParamsEventArgs e)
        {
            IObjectSpace                objectSpace = Application.CreateObjectSpace();
            TimeIntervalCollection      intervalCol = activeView.GetVisibleIntervals();
            CreateDoctorEventParameters parameters  = new CreateDoctorEventParameters(intervalCol.Start);

            e.View = Application.CreateDetailView(objectSpace, parameters, true);
        }
Exemplo n.º 2
0
        private void CreateDoctorEventAction_Execute(object sender, PopupWindowShowActionExecuteEventArgs e)
        {
            Doctor doctor = FilterDoctorEventAction.SelectedItem.Data as Doctor;
            // Форма параметров
            CreateDoctorEventParameters parameters = (CreateDoctorEventParameters)e.PopupWindowViewCurrentObject;

            using (IObjectSpace os = Application.CreateObjectSpace())
            {
                DateTime start = parameters.DateIn;
                DateTime end   = parameters.DateIn.AddDays(7 * parameters.WeeksCount);

                while (start < end)
                {
                    if ((start.DayOfWeek == DayOfWeek.Monday && parameters.Monday) ||
                        (start.DayOfWeek == DayOfWeek.Tuesday && parameters.Tuesday) ||
                        (start.DayOfWeek == DayOfWeek.Wednesday && parameters.Wednesday) ||
                        (start.DayOfWeek == DayOfWeek.Thursday && parameters.Thursday) ||
                        (start.DayOfWeek == DayOfWeek.Friday && parameters.Friday) ||
                        (start.DayOfWeek == DayOfWeek.Saturday && parameters.Saturday) ||
                        (start.DayOfWeek == DayOfWeek.Sunday && parameters.Sunday))
                    {
                        DateTime timeStart = start.AddHours(parameters.TimeIn.Hour).AddMinutes(parameters.TimeIn.Minute);
                        DateTime timeEnd   = start.AddHours(parameters.TimeOut.Hour).AddMinutes(parameters.TimeOut.Minute);

                        List <DoctorEvent> oldEvents         = new List <DoctorEvent>();
                        GroupOperator      oldEventsCriteria = new GroupOperator();
                        // Удаляем пересекающееся старое расписание
                        if (timeStart == timeStart.Date && timeEnd == timeEnd.Date)
                        {
                            // Если указано пустое расписание, то удаляем старое расписание полностью за день
                            oldEventsCriteria.Operands.Add(DoctorEvent.Fields.AssignedTo == os.GetObject(doctor) &
                                                           new FunctionOperator(FunctionOperatorType.GetDate, DoctorEvent.Fields.StartOn) >= timeStart.Date &
                                                           new FunctionOperator(FunctionOperatorType.GetDate, DoctorEvent.Fields.EndOn) < timeStart.Date.AddDays(1));
                        }
                        else
                        {
                            // Ищем пересекающиеся с указанным временем расписания
                            oldEventsCriteria.Operands.Add(DoctorEvent.Fields.AssignedTo == os.GetObject(doctor) & (
                                                               DoctorEvent.Fields.StartOn <timeStart& DoctorEvent.Fields.EndOn> timeStart |
                                                               DoctorEvent.Fields.StartOn >= timeStart & DoctorEvent.Fields.EndOn <= timeEnd |
                                                               DoctorEvent.Fields.StartOn <timeEnd& DoctorEvent.Fields.EndOn> timeEnd));
                        }

                        oldEvents.AddRange(os.GetObjects <DoctorEvent>(oldEventsCriteria));
                        os.Delete(oldEvents);

                        // Цикл по времени
                        while (timeStart < timeEnd)
                        {
                            var doctorEvent = os.CreateObject <DoctorEvent>();
                            doctorEvent.AssignedTo = os.GetObject(doctor);
                            doctorEvent.StartOn    = timeStart;
                            doctorEvent.EndOn      = timeStart.Add(parameters.Norm);
                            doctorEvent.Label      = parameters.Label;
                            timeStart = timeStart.Add(parameters.Norm);
                        }
                    }
                    start = start.AddDays(1);
                }

                // Отключение аудита
                Session session = ((XPObjectSpace)os).Session;
                AuditTrailService.Instance.EndSessionAudit(session);
                os.CommitChanges();
            }

            // Обновление списочного представления
            if (rootListView != null && rootListView.ObjectSpace != null && rootListView.CollectionSource != null)
            {
                rootListView.CollectionSource.Reload();
            }
        }