Ejemplo n.º 1
0
        public IEnumerable <DocumentRequisite> Read(ComponentsModel packageModel)
        {
            foreach (var model in packageModel.DocumentRequisites)
            {
                var entity = PackageHandlerUtils.CreateEntity <DocumentRequisite>(model);

                var fieldReq = model.Card.Requisites
                               .FirstOrDefault(r => r.Code == FieldReqName);
                if (fieldReq != null)
                {
                    entity.Field = fieldReq.DecodedText;
                }

                var sectionReq = model.Card.Requisites
                                 .FirstOrDefault(r => r.Code == SectionReqName);
                if (sectionReq != null)
                {
                    entity.Section = RequisiteHandlerUtils.GetRequisiteSection(sectionReq.ValueLocalizeID);
                }

                var typeReq = model.Card.Requisites
                              .FirstOrDefault(r => r.Code == TypeReqName);
                if (typeReq != null)
                {
                    entity.Type = RequisiteHandlerUtils.GetRequisiteType(typeReq.ValueLocalizeID);
                }

                var formatReq = model.Card.Requisites
                                .FirstOrDefault(r => r.Code == FormatReqName);
                if (formatReq != null)
                {
                    entity.Format = RequisiteHandlerUtils.GetRequisiteFormat(formatReq.ValueLocalizeID);
                }

                var lengthReq = model.Card.Requisites
                                .FirstOrDefault(r => r.Code == LengthReqName);
                if (!string.IsNullOrEmpty(lengthReq?.Value))
                {
                    entity.Length = int.Parse(lengthReq.Value);
                }

                var precissionReq = model.Card.Requisites
                                    .FirstOrDefault(r => r.Code == PrecissionReqName);
                if (!string.IsNullOrEmpty(precissionReq?.Value))
                {
                    entity.Precission = int.Parse(precissionReq.Value);
                }

                var referenceTypeReq = model.Card.Requisites
                                       .FirstOrDefault(r => r.Code == ReferenceTypeReqName);
                if (referenceTypeReq != null)
                {
                    entity.ReferenceType = referenceTypeReq.Value;
                }

                var referenceViewReq = model.Card.Requisites
                                       .FirstOrDefault(r => r.Code == ReferenceViewReqName);
                if (referenceViewReq != null)
                {
                    entity.ReferenceView = referenceViewReq.Value;
                }

                var pickValuesReq = model.Card.Requisites
                                    .FirstOrDefault(r => r.Code == PickValuesReqName);
                if (!string.IsNullOrEmpty(pickValuesReq?.DecodedText))
                {
                    var pickValues = pickValuesReq.DecodedText.Split(';');
                    foreach (var pickValue in pickValues)
                    {
                        var pickValueParts = pickValue.Split('=', '|');
                        var reqPickValue   = new RequisitePickValue
                        {
                            Id    = pickValueParts[0][0],
                            Value = pickValueParts[1]
                        };
                        entity.PickValues.Add(reqPickValue);
                    }
                }

                var isStoredReq = model.Card.Requisites
                                  .FirstOrDefault(r => r.Code == IsStoredReqName);
                if (isStoredReq != null)
                {
                    entity.IsStored = isStoredReq.ValueLocalizeID == Stored;
                }

                var isGeneratedReq = model.Card.Requisites
                                     .FirstOrDefault(r => r.Code == IsGeneratedReqName);
                if (isGeneratedReq != null)
                {
                    entity.IsGenerated = isGeneratedReq.ValueLocalizeID == Generated;
                }

                yield return(entity);
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Прочитать реквизиты карточки.
        /// </summary>
        /// <param name="model">Модель.</param>
        /// <param name="entity">Сущность.</param>
        private static void ReadCardRequisites(ComponentModel model, DocumentCardType entity)
        {
            if (model.DetailDataSets?.DetailDataSet1 == null)
            {
                return;
            }

            foreach (var row in model.DetailDataSets.DetailDataSet1.Rows)
            {
                var cardRequisite = new CardRequisite();

                var numberReq = row.Requisites
                                .FirstOrDefault(r => r.Code == ReqNumberReqName);
                if (!string.IsNullOrEmpty(numberReq?.Value))
                {
                    cardRequisite.Number = int.Parse(numberReq.Value);
                }

                var sectionReq = row.Requisites
                                 .FirstOrDefault(r => r.Code == ReqSectionReqName);
                if (sectionReq != null)
                {
                    cardRequisite.Section = RequisiteHandlerUtils.GetRequisiteSection(sectionReq.ValueLocalizeID);
                }

                var nameReq = row.Requisites
                              .FirstOrDefault(r => r.Code == ReqNameReqName);
                if (nameReq != null)
                {
                    cardRequisite.Name = nameReq.Value;
                }

                var isRequiredReq = row.Requisites
                                    .FirstOrDefault(r => r.Code == ReqIsRequiredReqName);
                if (isRequiredReq != null)
                {
                    cardRequisite.IsRequired = isRequiredReq.ValueLocalizeID == YesValue;
                }

                var isLeadingReq = row.Requisites
                                   .FirstOrDefault(r => r.Code == ReqIsLeadingReqName);
                if (isLeadingReq != null)
                {
                    cardRequisite.IsLeading = isLeadingReq.ValueLocalizeID == YesValue;
                }

                var changeEventReq = row.Requisites
                                     .FirstOrDefault(r => r.Code == ReqChangeEventReqName);
                if (!string.IsNullOrEmpty(changeEventReq?.DecodedText))
                {
                    var @event = new Event
                    {
                        EventType       = EventType.Change,
                        CalculationText = changeEventReq.DecodedText
                    };
                    cardRequisite.Events.Add(@event);
                }

                var selectEventReq = row.Requisites
                                     .FirstOrDefault(r => r.Code == ReqSelectEventsReqName);
                if (!string.IsNullOrEmpty(selectEventReq?.DecodedText))
                {
                    var events = EventTextParser.Parse(selectEventReq.DecodedText);
                    foreach (var @event in events)
                    {
                        if (@event.EventType == EventType.Unknown)
                        {
                            @event.EventType = EventType.Select;
                        }
                        cardRequisite.Events.Add(@event);
                    }
                }

                entity.Requisites.Add(cardRequisite);
            }
        }