private void detach_ActionTypes(ActionType entity)
 {
     this.SendPropertyChanging("ActionTypes");
     entity.RbActionShedule = null;
 }
 private void detach_ActionTypes(ActionType entity)
 {
     this.SendPropertyChanging("ActionTypes");
     entity.QuotaType = null;
 }
 private void attach_ActionTypes(ActionType entity)
 {
     this.SendPropertyChanging("ActionTypes");
     entity.RbService = this;
 }
        private static void verifyStationarPeriods(IBackgroundContext context, List<Event> allEvents, VistaMedDataContext dataContext, ActionType moveActType)
        {
            var stationarEvents = from e in allEvents
                                  where e.EventType.RbMedicalAidType != null
                                  && e.EventType.RbMedicalAidType.Name != null
                                  && e.EventType.RbMedicalAidType.Name.ToLower().Contains("стационар")
                                  && !e.EventType.RbMedicalAidType.Name.ToLower().Contains("дневной")
                                  select e;

            var moveActions = from e in stationarEvents
                              from c in e.Actions
                              where !c.Deleted && c.ActionType == moveActType
                              select c;

            var errors = new List<string>();

            foreach (var moveAction in moveActions.TakeWhile(x => !context.CancellationPending))
            {
                var dateRange = new DateRange(moveAction.BegDate, moveAction.EndDate);

                var client = moveAction.Event.Client;
                var clientActions = (from e in allEvents where e.Client == client && e != moveAction.Event select e).ToList();

                var theEvents = (from a in clientActions let dr = new DateRange(a.SetDate, a.ExecDate)
                                   where dr.Intersects(dateRange)
                                   && (dr.EndDate != dateRange.StartDate)
                                   && (dr.EndDate != dateRange.EndDate)
                                   select a).ToList();

                if (theEvents.Any())
                {
                    errors.Add(string.Format(@"СТАЦИОНАР.ТАЛОН '{0}'", moveAction.Event));
                    errors.Add(string.Format(@"  ДВИЖЕНИЕ '{0}'", moveAction));
                    foreach (var theEvent in theEvents)
                    {
                        errors.Add(string.Format(@"    Пересечение периодов '{0}'", theEvent));
                    }
                }
            }

            if (errors.Count > 0 && !context.CancellationPending)
            {
                context.ReportError(@"""{0}""", "ПЕРЕСЕЧЕНИЕ ПЕРИОДОВ");
                errors.ForEach(x => context.ReportProgress(@"    -> {0}", x));
            }
        }
 private void detach_ActionTypes(ActionType entity)
 {
     this.SendPropertyChanging("ActionTypes");
     entity.Organisation = null;
 }
        private static void verifyStationarBedProfile(IBackgroundContext context, 
            List<Event> allEvents, 
            VistaMedDataContext dataContext, ActionType moveActType,
            ActionPropertyType bedPropType, string eventKindName)
        {
            var eventTypes = from c in dataContext.VistaMed.EventTypes
                             where c.RbMedicalAidType != null
                                   && c.RbMedicalAidType.Name == eventKindName
                             select c;

            var stationarEvents = from e in allEvents
                                  where eventTypes.Contains(e.EventType)
                                  select e;

            // мероприятия "Движение"
            var moveActions = from e in stationarEvents
                              from c in e.Actions
                              where !c.Deleted && c.ActionType == moveActType
                              select new {Event = e, Action = c};

            // выборка свойств "койка"
            var actProp = from c in moveActions
                          from p in c.Action.ActionProperties
                          where p.ActionPropertyType == bedPropType && !p.Deleted
                          select new { Event = c.Event, Action = c.Action, BedProp = p };

            // выборка значений "койка"
            var actBed = (from c in actProp
                          join bedTypedProp in dataContext.VistaMed.ActionPropertyHospitalBeds on c.BedProp.Id equals bedTypedProp.Id
                          select new { c.Event, c.Action, Bed = bedTypedProp.OrgStructureHospitalBed }).ToList();

            Func<RbHospitalBedProfile, bool> comparator;
            if(eventKindName.Contains("Дневной"))
                comparator = x => x.Name.Contains(" ДС");
            else
                comparator = x => !x.Name.Contains(" ДС");

            var wrongBeds = from c in actBed
                           where c.Bed.RbHospitalBedProfile != null && !comparator(c.Bed.RbHospitalBedProfile)
                           select c;

            var errors = new List<string>();

            foreach (var wrongBed in wrongBeds)
            {
                errors.Add(string.Format(@"{0}. Неверный тип койки {1}", wrongBed.Event,
                    wrongBed.Bed.RbHospitalBedProfile.Name));
            }

            if (errors.Count > 0)
            {
                context.ReportError(@"""{0}""", eventKindName);
                errors.ForEach(x => context.ReportProgress(@"    -> {0}", x));
            }
        }
        private static void verifyStationarMovePerson(IBackgroundContext context, List<Action> allActions, 
            VistaMedDataContext dataContext, ActionType moveActType)
        {
            var badMoveActions = (from c in allActions
                                  where c.ActionType == moveActType
                                        && c.Person_SetPersonId != c.Event.Person_ExecPersonId
                                  select c).ToList();

            var errors = new List<string>();

            foreach (var badAction in badMoveActions)
            {
                errors.Add(string.Format(@"{0}. Исполнитель в мероприятии ""{1}"" а в талоне ""{2}""", badAction.Event,
                    badAction.Person_PersonId == null ? "не задан" : badAction.Person_PersonId.FIO,
                    badAction.Event.Person_ExecPersonId == null ? "не задан" : badAction.Event.Person_ExecPersonId.FIO));
            }

            if (errors.Count > 0)
            {
                context.ReportError(@"СТАЦИОНАР: МЕРОПРИЯТИЯ ДВИЖЕНИЯ С НЕВЕРНЫМ ИСПОЛНИТЕЛЕМ");
                errors.ForEach(x => context.ReportProgress(@"    -> {0}", x));
            }
        }
 private void detach_ActionTypes_PrescribedTypeId(ActionType entity)
 {
     this.SendPropertyChanging("ActionTypes_PrescribedTypeId");
     entity.ActionType_PrescribedTypeId = null;
 }
 private void detach_ActionTypes_GroupId(ActionType entity)
 {
     this.SendPropertyChanging("ActionTypes_GroupId");
     entity.ActionType_GroupId = null;
 }
 private void attach_ActionTypes_ModifyPersonId(ActionType entity)
 {
     this.SendPropertyChanging("ActionTypes_ModifyPersonId");
     entity.Person_ModifyPersonId = this;
 }
 private void attach_ActionTypes_DefaultExecPersonId(ActionType entity)
 {
     this.SendPropertyChanging("ActionTypes_DefaultExecPersonId");
     entity.Person_DefaultExecPersonId = this;
 }
 private void detach_ActionTypes_CreatePersonId(ActionType entity)
 {
     this.SendPropertyChanging("ActionTypes_CreatePersonId");
     entity.Person_CreatePersonId = null;
 }