/// <summary> /// Returns true if the provided SurveyQuestion objects are equal in terms of refVarName and the match fields. /// </summary> /// <param name="sq1"></param> /// <param name="sq2"></param> /// <returns></returns> public bool HarmonyMatch(SurveyQuestion sq1, SurveyQuestion sq2) { bool prepMatch = false, preiMatch = false, preaMatch = false, litqMatch = false, pstiMatch = false, pstpMatch = false, roMatch = false, nrMatch = false; bool tranMatch = false; if (!matchFields.Contains("PreP")) { prepMatch = true; } if (!matchFields.Contains("PreI")) { preiMatch = true; } if (!matchFields.Contains("PreA")) { preaMatch = true; } if (!matchFields.Contains("LitQ")) { litqMatch = true; } if (!matchFields.Contains("PstI")) { pstiMatch = true; } if (!matchFields.Contains("PstP")) { pstpMatch = true; } if (!matchFields.Contains("RespOptions")) { roMatch = true; } if (!matchFields.Contains("NRCodes")) { nrMatch = true; } if (!matchFields.Contains("Translation")) { tranMatch = true; } foreach (string s in matchFields) { if (s.Equals("PreP")) { prepMatch = (sq1.PreP == sq2.PreP); } if (s.Equals("PreI")) { preiMatch = (sq1.PreI == sq2.PreI); } if (s.Equals("PreA")) { preaMatch = (sq1.PreA == sq2.PreA); } if (s.Equals("LitQ")) { litqMatch = (sq1.LitQ == sq2.LitQ); } if (s.Equals("PstI")) { pstiMatch = (sq1.PstI == sq2.PstI); } if (s.Equals("PstP")) { pstpMatch = (sq1.PstP == sq2.PstP); } if (s.Equals("RespOptions")) { roMatch = (sq1.RespOptions == sq2.RespOptions); } if (s.Equals("NRCodes")) { nrMatch = (sq1.NRCodes == sq2.NRCodes); } if (s.Equals("Translation")) { tranMatch = (sq1.GetTranslationText(Lang) == sq2.GetTranslationText(Lang)); } } return(prepMatch && preiMatch && preaMatch && litqMatch && pstiMatch & pstpMatch && roMatch && nrMatch); }
/// <summary> /// Builds a table using the provided ReportSurvey data. /// </summary> /// <param name="s">Report survey</param> public DataTable MakeFinalTable(ReportSurvey s) { DataTable finalTable; DataRow newrow; string questionColumnName = GetQuestionColumnName(s); string varname; // (potentially) edited VarName field string questionFilter; // construct finalTable // finalTable will have fields for ID, Qnum, VarName, Question Text, and Labels by default // comments, translations, filters will be added if needed finalTable = new DataTable(); finalTable.Columns.Add("ID", Type.GetType("System.Int32")); finalTable.Columns.Add("SortBy", Type.GetType("System.String")); finalTable.Columns.Add("Qnum", Type.GetType("System.String")); finalTable.Columns.Add("AltQnum", Type.GetType("System.String")); finalTable.Columns.Add("VarName", Type.GetType("System.String")); finalTable.Columns.Add("refVarName", Type.GetType("System.String")); finalTable.Columns.Add(questionColumnName, Type.GetType("System.String")); finalTable.Columns.Add(questionColumnName + " AltQnum2", Type.GetType("System.String")); finalTable.Columns.Add(questionColumnName + " AltQnum3", Type.GetType("System.String")); finalTable.Columns.Add(questionColumnName + " VarLabel", Type.GetType("System.String")); finalTable.Columns.Add(questionColumnName + " Domain", Type.GetType("System.String")); finalTable.Columns.Add(questionColumnName + " Topic", Type.GetType("System.String")); finalTable.Columns.Add(questionColumnName + " Content", Type.GetType("System.String")); finalTable.Columns.Add(questionColumnName + " Product", Type.GetType("System.String")); finalTable.Columns.Add("CorrectedFlag", Type.GetType("System.Boolean")); finalTable.Columns.Add("TableFormat", Type.GetType("System.Boolean")); // comment column if (s.CommentFields != null && s.CommentFields.Count != 0) { finalTable.Columns.Add(questionColumnName + " Comments", Type.GetType("System.String")); } // translation column foreach (string lang in s.TransFields) { finalTable.Columns.Add(questionColumnName + " " + lang, Type.GetType("System.String")); } // filter columns if (s.FilterCol) { finalTable.Columns.Add(questionColumnName + " Filters", Type.GetType("System.String")); } // section bounds if (ShowSectionBounds) { finalTable.Columns.Add(questionColumnName + " FirstVarName", Type.GetType("System.String")); finalTable.Columns.Add(questionColumnName + " LastVarName", Type.GetType("System.String")); } // for each question, edit the fields according to the chosen options, // then add the fields to a new row in the final table. foreach (SurveyQuestion q in s.Questions) { // create a deep copy of just the wordings so that we can format them without affecting the original wordings SurveyQuestion wordings = q.DeepCopyWordings(); // insert Qnums before variable names if (QNInsertion) { s.InsertQnums(wordings, Numbering); s.InsertOddQnums(wordings, Numbering); } // insert Country codes into variable names if (CCInsertion) { s.InsertCountryCodes(wordings); } // remove long lists in response option column if (!ShowLongLists && Utilities.CountLines(q.RespOptions) >= 25) { wordings.RespOptions = "[center](Response options omitted)[/center]"; } // NRFormat if (NrFormat != ReadOutOptions.Neither && !string.IsNullOrEmpty(q.NRCodes)) { wordings.NRCodes = s.FormatNR(q.NRCodes, NrFormat); } // Semi-telephone format if (SemiTel) { q.FormatSemiTel(out string changedPreI, out string changedRespOptions); wordings.PreI = changedPreI; wordings.RespOptions = changedRespOptions; } // in-line routing if (InlineRouting && !String.IsNullOrEmpty(q.PstP)) { s.FormatRouting(wordings); } // routing format if (!wordings.VarName.FullVarName.StartsWith("Z")) { if (s.RoutingFormat == RoutingStyle.None) { wordings.PreP = ""; wordings.PstP = ""; } else if (s.RoutingFormat == RoutingStyle.Grey) { wordings.PreP = "<Font Color=#a6a6a6>" + wordings.PreP + "</Font>"; wordings.PstP = "<Font Color=#a6a6a6>" + wordings.PstP + "</Font>"; } } // subset tables if (SubsetTables) { if (SubsetTablesTranslation) { s.InsertTranslationTableTags(wordings); } else { if (q.TableFormat && q.Qnum.EndsWith("a")) { wordings.RespOptions = "[TBLROS]" + wordings.RespOptions; wordings.NRCodes += "[TBLROE]"; wordings.LitQ = "[LitQ]" + wordings.LitQ + "[/LitQ]"; } } } // edit VarName, but don't edit the SurveyQuestion's VarName field, since this would update the refVarName field as well varname = q.VarName.FullVarName; if (VarChangesCol && !string.IsNullOrEmpty(q.VarName.FullVarName) && !q.VarName.FullVarName.StartsWith("Z") && (q.PreviousNameList.Count > 0)) { varname += " (Prev. "; foreach (VariableName v in q.PreviousNameList) { varname += v.RefVarName + ", "; } varname = varname.Substring(0, varname.Length - 2) + ")"; } // corrected if (q.CorrectedFlag) { if (s.Corrected) { varname += "\r\n" + "[C]"; } else { varname += "\r\n" + "[A]"; } } // now we can add the fields to a DataRow to be inserted into the final table newrow = finalTable.NewRow(); newrow["ID"] = q.ID; newrow["SortBy"] = q.Qnum; newrow["Qnum"] = q.GetQnum(); newrow["VarName"] = varname; newrow["refVarName"] = q.VarName.RefVarName; // concatenate the question fields, and if this is varname BI104, attach the essential questions list newrow[questionColumnName] = wordings.GetQuestionText(s.StdFieldsChosen); if (q.VarName.RefVarName.Equals("BI104")) { newrow[questionColumnName] += "\r\n<strong>" + s.EssentialList + "</strong>"; } // labels (only show labels for non-headings) if (!q.VarName.FullVarName.StartsWith("Z") || !ShowQuestion) { newrow[questionColumnName + " AltQnum2"] = q.AltQnum2; newrow[questionColumnName + " AltQnum3"] = q.AltQnum3; newrow[questionColumnName + " VarLabel"] = q.VarName.VarLabel; newrow[questionColumnName + " Topic"] = q.VarName.Topic.LabelText; newrow[questionColumnName + " Content"] = q.VarName.Content.LabelText; newrow[questionColumnName + " Domain"] = q.VarName.Domain.LabelText; newrow[questionColumnName + " Product"] = q.VarName.Product.LabelText; } // comments try { foreach (QuestionComment c in q.Comments) { newrow[questionColumnName + " Comments"] += c.GetComments() + "\r\n\r\n"; } } catch { } // translations foreach (string lang in s.TransFields) { if (s.EnglishRouting) { newrow[questionColumnName + " " + lang] = wordings.GetEnglishRoutingTranslation(lang).Replace("<br>", "\r\n"); } else { newrow[questionColumnName + " " + lang] = wordings.GetTranslationText(lang).Replace("<br>", "\r\n"); } } // filters if (s.FilterCol) { newrow[questionColumnName + " Filters"] = q.Filters; } newrow["CorrectedFlag"] = q.CorrectedFlag; newrow["TableFormat"] = q.TableFormat; // section bounds if (ShowSectionBounds) { newrow[questionColumnName + " FirstVarName"] = s.GetSectionLowerBound(q); newrow[questionColumnName + " LastVarName"] = s.GetSectionUpperBound(q); } // now add a new row to the finalTable DataTable // the new row will be a susbet of columns in the rawTable, after the above modifications have been applied finalTable.Rows.Add(newrow); } // apply the question filters questionFilter = s.GetQuestionFilter(); if (!questionFilter.Equals("")) { try { finalTable = finalTable.Select(questionFilter).CopyToDataTable().Copy(); } catch (InvalidOperationException) { return(null);// filters resulted in 0 records } } // set the primary key to be the refVarName column // so that surveys from differing countries can still be matched up finalTable.PrimaryKey = new DataColumn[] { finalTable.Columns["refVarName"] }; // remove unneeded fields if (!ShowQuestion) { finalTable.Columns.Remove(questionColumnName); } // check enumeration and delete AltQnum if (Numbering == Enumeration.Qnum) { finalTable.Columns.Remove("AltQnum"); } if (Numbering == Enumeration.AltQnum) { finalTable.Columns.Remove("Qnum"); } if (!s.AltQnum2Col) { finalTable.Columns.Remove(questionColumnName + " AltQnum2"); } if (!s.AltQnum3Col) { finalTable.Columns.Remove(questionColumnName + " AltQnum3"); } if (!s.DomainLabelCol) { finalTable.Columns.Remove(questionColumnName + " Domain"); } if (!s.TopicLabelCol) { finalTable.Columns.Remove(questionColumnName + " Topic"); } if (!s.ContentLabelCol) { finalTable.Columns.Remove(questionColumnName + " Content"); } if (!s.VarLabelCol) { finalTable.Columns.Remove(questionColumnName + " VarLabel"); } if (!s.ProductLabelCol) { finalTable.Columns.Remove(questionColumnName + " Product"); } // these are no longer needed finalTable.Columns.Remove("CorrectedFlag"); finalTable.Columns.Remove("TableFormat"); finalTable.Columns.Remove("ID"); return(finalTable); }