private static object GetValue(ScopedElementCollection additionalElements, TableColumn tableColumn) { if (tableColumn.DataType == DataType.Boolean) { return(PollUtils.ToBool(GetDcElementContent(additionalElements, tableColumn.AttributeName), false)); } if (tableColumn.DataType == DataType.DateTime) { return(PollUtils.ToDateTime(GetDcElementContent(additionalElements, tableColumn.AttributeName))); } if (tableColumn.DataType == DataType.Decimal) { return(PollUtils.ToDecimal(GetDcElementContent(additionalElements, tableColumn.AttributeName), 0)); } if (tableColumn.DataType == DataType.Integer) { return(PollUtils.ToInt(GetDcElementContent(additionalElements, tableColumn.AttributeName), 0)); } if (tableColumn.DataType == DataType.Text) { return(Decrypt(GetDcElementContent(additionalElements, tableColumn.AttributeName))); } return(GetDcElementContent(additionalElements, tableColumn.AttributeName)); }
public static NameValueCollection ImportFields(int siteId, int pollId, string styleDirectoryPath, bool isHistoric) { var titleAttributeNameDict = new NameValueCollection(); if (!Directory.Exists(styleDirectoryPath)) { return(titleAttributeNameDict); } var filePaths = Directory.GetFiles(styleDirectoryPath); foreach (var filePath in filePaths) { var feed = AtomFeed.Load(new FileStream(filePath, FileMode.Open)); var title = GetDcElementContent(feed.AdditionalElements, nameof(FieldInfo.Title)); if (isHistoric) { var attributeName = GetDcElementContent(feed.AdditionalElements, "AttributeName"); title = GetDcElementContent(feed.AdditionalElements, "DisplayName"); titleAttributeNameDict[title] = attributeName; } var fieldType = GetDcElementContent(feed.AdditionalElements, nameof(FieldInfo.FieldType)); if (isHistoric) { fieldType = GetDcElementContent(feed.AdditionalElements, "InputType"); } var taxis = PollUtils.ToInt(GetDcElementContent(feed.AdditionalElements, "Taxis"), 0); var fieldInfo = new FieldInfo { PollId = pollId, Taxis = taxis, Title = title, FieldType = fieldType }; var fieldItems = new List <FieldItemInfo>(); foreach (AtomEntry entry in feed.Entries) { var itemValue = GetDcElementContent(entry.AdditionalElements, "ItemValue"); var isSelected = PollUtils.ToBool(GetDcElementContent(entry.AdditionalElements, "IsSelected"), false); fieldItems.Add(new FieldItemInfo { PollId = pollId, FieldId = 0, Value = itemValue, IsSelected = isSelected }); } if (fieldItems.Count > 0) { fieldInfo.Items = fieldItems; } if (FieldManager.Repository.IsTitleExists(pollId, title)) { FieldManager.Repository.Delete(pollId, title); } FieldManager.Repository.Insert(siteId, fieldInfo); } return(titleAttributeNameDict); }