Exemplo n.º 1
0
        /// <summary>
        /// Parses XML from the web survey
        /// </summary>
        /// <param name="result">The parsed results in dictionary format</param>
        private List<WebFieldData> ParseXML(SurveyAnswerResponse result)
        {
            List<WebFieldData> surveyResponses = new List<WebFieldData>();

            foreach (Epi.Web.Common.DTO.SurveyAnswerDTO surveyAnswer in result.SurveyResponseList)
            {
                WebFieldData wfData = new WebFieldData();

                System.Xml.XmlDocument doc = new System.Xml.XmlDocument();
                doc.LoadXml(surveyAnswer.XML);

                foreach (XmlElement docElement in doc.ChildNodes)
                {
                    if (docElement.Name.ToLower().Equals("surveyresponse"))
                    {
                        foreach (XmlElement surveyElement in docElement.ChildNodes)
                        {
                            if (surveyElement.Name.ToLower().Equals("page") && surveyElement.Attributes.Count > 0 && surveyElement.Attributes[0].Name.ToLower().Equals("pageid"))
                            {
                                foreach (XmlElement pageElement in surveyElement.ChildNodes)
                                {
                                    if (pageElement.Name.ToLower().Equals("responsedetail"))
                                    {
                                        string fieldName = string.Empty;
                                        if (pageElement.Attributes.Count > 0)
                                        {
                                            fieldName = pageElement.Attributes[0].Value;
                                        }
                                        object fieldValue = pageElement.InnerText;

                                        wfData = new WebFieldData();
                                        wfData.RecordGUID = surveyAnswer.ResponseId;
                                        wfData.Page = Convert.ToInt32(surveyElement.Attributes[0].Value);
                                        wfData.FieldName = fieldName;
                                        wfData.FieldValue = fieldValue;
                                        wfData.Status = surveyAnswer.Status;
                                        if (wfData.Status == 3)
                                        {
                                            surveyResponses.Add(wfData);
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }

            return surveyResponses;
        }
Exemplo n.º 2
0
        private QueryParameter GetQueryParameterForField(WebFieldData fieldData, Page sourcePage)
        {
            Field dataField = destinationView.Fields[fieldData.FieldName];
            if (!(
                dataField is GroupField ||
                dataField is RelatedViewField ||
                dataField is UniqueKeyField ||
                dataField is RecStatusField ||
                dataField is GlobalRecordIdField ||
                dataField is ImageField ||
                fieldData.FieldValue == null ||
                string.IsNullOrEmpty(fieldData.FieldValue.ToString())
                ))
            {
                String fieldName = ((Epi.INamedObject)dataField).Name;
                 try
                    {
                switch (dataField.FieldType)
                {
                    case MetaFieldType.Date:
                    case MetaFieldType.DateTime:
                    case MetaFieldType.Time:
                        return new QueryParameter("@" + fieldName, DbType.DateTime, Convert.ToDateTime(fieldData.FieldValue));
                    case MetaFieldType.Checkbox:
                        return new QueryParameter("@" + fieldName, DbType.Boolean, Convert.ToBoolean(fieldData.FieldValue));
                    case MetaFieldType.CommentLegal:
                    case MetaFieldType.LegalValues:
                    case MetaFieldType.Codes:
                    case MetaFieldType.Text:
                    case MetaFieldType.TextUppercase:
                    case MetaFieldType.PhoneNumber:
                    case MetaFieldType.UniqueRowId:
                    case MetaFieldType.ForeignKey:
                    case MetaFieldType.GlobalRecordId:
                        if (fieldData.FieldValue.ToString().Length > 255)
                        {
                            fieldData.FieldValue = fieldData.FieldValue.ToString().Substring(0, 255);
                            AddStatusMessage("The field data for " + fieldData.FieldName + " in record " + fieldData.RecordGUID + " has been truncated because it exceeds 255 characters.");
                        }
                        return new QueryParameter("@" + fieldName, DbType.String, fieldData.FieldValue);
                    case MetaFieldType.Multiline:
                        return new QueryParameter("@" + fieldName, DbType.String, fieldData.FieldValue);
                    case MetaFieldType.Number:
                    case MetaFieldType.YesNo:
                    case MetaFieldType.RecStatus:
                        return new QueryParameter("@" + fieldName, DbType.Single, fieldData.FieldValue);
                    case MetaFieldType.Option:
                        return new QueryParameter("@" + fieldName, DbType.Int16, fieldData.FieldValue);
                    case MetaFieldType.Image:
                        this.BeginInvoke(new SetStatusDelegate(AddWarningMessage), "The data for " + fieldName + " was not imported. This field type is not supported.");
                        break;
                    default:
                        throw new ApplicationException("Not a supported field type");
                }
                    }
                 catch (Exception ex)
                     {

                     this.BeginInvoke(new SetStatusDelegate(AddWarningMessage), "Record GUID:" + fieldData.RecordGUID + "  Field Name:" + fieldName + "  Field Type:" + dataField.FieldType + "  Field Value:" + fieldData.FieldValue + "  Error Message :" + ex.Message);
                     // Logger.Log("Record GUID:" + fieldData.RecordGUID + "  Field Name:" + fieldName + "  Field Type:" + dataField.FieldType + "  Field Value:" + fieldData.FieldValue + "  Error Message :" + ex.Message);
                     return null;
                     }
            }

            return null;
        }
Exemplo n.º 3
0
        /// <summary>
        /// Parses XML from the web survey
        /// </summary>
        /// <param name="result">The parsed results in dictionary format</param>
        private int ParseXMLForProgressBar(SurveyAnswerResponse result)
        {
            int count = 0;

            foreach (Epi.Web.Common.DTO.SurveyAnswerDTO surveyAnswer in result.SurveyResponseList)
            {
                WebFieldData wfData = new WebFieldData();

                System.Xml.XmlDocument doc = new System.Xml.XmlDocument();
                doc.LoadXml(surveyAnswer.XML);

                foreach (XmlElement docElement in doc.ChildNodes)
                {
                    if (docElement.Name.ToLower().Equals("surveyresponse"))
                    {
                        foreach (XmlElement surveyElement in docElement.ChildNodes)
                        {
                            if (surveyElement.Name.ToLower().Equals("page") && surveyElement.Attributes.Count > 0 && surveyElement.Attributes[0].Name.ToLower().Equals("pagenumber"))
                            {
                                foreach (XmlElement pageElement in surveyElement.ChildNodes)
                                {
                                    if (pageElement.Name.ToLower().Equals("responsedetail"))
                                    {
                                        if (wfData.Status == 3)
                                        {
                                            count++;
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }

            return count;
        }
Exemplo n.º 4
0
        private void AddSurveyAnswerResult(Dictionary<string, Dictionary<string, WebFieldData>> result, SurveyManagerService.SurveyAnswerDTO surveyAnswer)
        {
            result.Add(surveyAnswer.ResponseId, new Dictionary<string, WebFieldData>(StringComparer.OrdinalIgnoreCase));
            System.Xml.XmlDocument doc = new System.Xml.XmlDocument();
            doc.LoadXml(surveyAnswer.XML);

            foreach (XmlNode docElement in doc.SelectNodes("//ResponseDetail"))
            {
                string fieldName = docElement.Attributes.GetNamedItem("QuestionName").Value;
                object fieldValue = FormatWebFieldData(fieldName, docElement.InnerText);

                WebFieldData wfData = new WebFieldData();
                wfData.RecordGUID = surveyAnswer.ResponseId;
                wfData.FieldName = fieldName;
                wfData.FieldValue = fieldValue;
                wfData.Status = surveyAnswer.Status;

                if (result[surveyAnswer.ResponseId].Keys.Contains(wfData.FieldName) == false)
                {
                    result[surveyAnswer.ResponseId].Add(wfData.FieldName, wfData);
                }
            }
        }