protected override void SetPageSessionContext() { base.SetPageSessionContext(); var sessionContainer = new HttpSessionStateContainer("id", new SessionStateItemCollection(), new HttpStaticObjectsCollection(), 10, true, HttpCookieMode.AutoDetect, SessionStateMode.InProc, false); var sessionState = typeof(HttpSessionState).GetConstructor( BindingFlags.NonPublic | BindingFlags.Instance, null, CallingConventions.Standard, new[] { typeof(HttpSessionStateContainer) }, null) .Invoke(new object[] { sessionContainer }) as HttpSessionState; ShimUserControl.AllInstances.SessionGet = (p) => { return(sessionState); }; _surveyReportInstance = new SurveyReport(); _shimSurveyReport = new ShimSurveyReport(_surveyReportInstance); _surveyReportPrivateObject = new PrivateObject(_surveyReportInstance); InitializeAllControls(_surveyReportInstance); var shimEcnSession = new ShimECNSession(); ShimECNSession.CurrentSession = () => shimEcnSession; ECNSession.CurrentSession().CurrentUser = new User() { UserID = 10 }; _viewState = GetPropertyOrField <StateBag>("ViewState"); }
public void NoSurveyTakers() { List <Survey> lstSurveys = new List <Survey>(); SurveyReport report = new SurveyReport(lstSurveys); Assert.IsTrue(report.SurveyTakers == 0); }
// GET: Survey/SurveyReport public ActionResult SurveyReport() { try { string strSurveyAsJsonObjects = string.Empty; var dataFile = Server.MapPath(_datastore); if (System.IO.File.Exists(dataFile)) { strSurveyAsJsonObjects = System.IO.File.ReadAllText(@dataFile); //Format the list of Json objects to an array of json objects strSurveyAsJsonObjects = strSurveyAsJsonObjects.TrimEnd(','); strSurveyAsJsonObjects = "[" + strSurveyAsJsonObjects + "]"; List <Survey> surveys = JsonConvert.DeserializeObject <List <Survey> >(strSurveyAsJsonObjects); SurveyReport report = new SurveyReport(surveys); return(View(report)); } } catch (Exception e) { ViewBag.Error = e?.Message + ":" + e?.InnerException?.Message; } //If I am here, return an empty report return(View(new SurveyReport(new List <Survey>()))); }
private void RunSurveyReport() { int result; // get the survey data for all chosen surveys PopulateSurveys(); SurveyReport survReport = new SurveyReport(SR) { SurveyCompare = compare }; // bind status label to survey report's status property lblStatus.DataBindings.Clear(); lblStatus.DataBindings.Add(new Binding("Text", survReport, "ReportStatus")); result = survReport.GenerateReport(); switch (result) { case 1: MessageBox.Show("One or more surveys contain no records."); // TODO if a backup was chosen, show a form for selecting a different survey code from that date break; default: break; } // output report to Word/PDF survReport.OutputReportTableXML(); }
public void SingleSurveyMultiQuestionReportTable() { SurveyReport SR = new SurveyReport(); ReportSurvey s = new ReportSurvey("Test"); SR.AddSurvey(s); for (int i = 0; i < 10; i++) { SurveyQuestion sq = new SurveyQuestion(); sq.VarName.FullVarName = "AA" + i.ToString("000"); sq.Qnum = i.ToString("000"); sq.PreP = "Test PreP" + i; sq.LitQ = "Test LitQ" + i; for (int j = 1; j <= i; j++) { sq.RespOptions += j + " Response Option " + j; } s.AddQuestion(sq); } int result = SR.GenerateReport(); Assert.IsTrue(result == 0); Assert.IsTrue(SR.ReportTable.Rows.Count == 10); }
public void SingleVarNameSingleTranslation() { SurveyReport SR = new SurveyReport(); ReportSurvey s = new ReportSurvey("TT1"); SurveyQuestion q = new SurveyQuestion("AA000", "001"); q.Translations.Add(new Translation() { Language = "TestLang", TranslationText = "Translation Text" }); s.AddQuestion(q); s.TransFields.Add("TestLang"); SR.AddSurvey(s); SR.GenerateReport(); DataTable dt = SR.ReportTable; bool hasQnumCol = dt.Columns[0].ColumnName.Equals("Qnum"); bool hasVarNameCol = dt.Columns[1].ColumnName.Equals("VarName"); bool hasQuestionCol = dt.Columns[2].ColumnName.Equals(s.SurveyCode); bool hasTranslationCol = dt.Columns[3].ColumnName.Equals(s.SurveyCode + " " + s.TransFields[0]); bool hasRows = dt.Rows.Count == s.Questions.Count; bool hasAllColumns = hasQnumCol && hasVarNameCol && hasQuestionCol && hasTranslationCol; Assert.IsTrue(hasAllColumns && hasRows); }
public void SingleVarNameVarLabel() { SurveyReport SR = new SurveyReport(); ReportSurvey s = new ReportSurvey("TT1"); SurveyQuestion q = new SurveyQuestion("AA000", "001"); s.AddQuestion(q); s.VarLabelCol = true; SR.AddSurvey(s); SR.GenerateReport(); DataTable dt = SR.ReportTable; bool hasQnumCol = dt.Columns[0].ColumnName.Equals("Qnum"); bool hasVarNameCol = dt.Columns[1].ColumnName.Equals("VarName"); bool hasQuestionCol = dt.Columns[2].ColumnName.Equals(s.SurveyCode); bool hasVarLabelCol = dt.Columns[3].ColumnName.Equals(s.SurveyCode + " VarLabel"); bool hasRows = dt.Rows.Count == s.Questions.Count; bool hasAllColumns = hasQnumCol && hasVarNameCol && hasQuestionCol && hasVarLabelCol; Assert.IsTrue(hasAllColumns && hasRows); }
public void SurveyReport_Class_All_Properties_Getter_Settter_Test() { // Arrange var surveyReport = new SurveyReport(); // Assert surveyReport.Master.ShouldBeNull(); }
public void SurveyReport_Class_Invalid_Property_MasterNotPresent_Access_Using_Reflexion_Doesnt_Throw_Exception_Test() { // Arrange const string propertyNameMaster = "MasterNotPresent"; var surveyReport = new SurveyReport(); // Act , Assert Should.NotThrow(action: () => surveyReport.GetType().GetProperty(propertyNameMaster)); }
private void OutputReport(DataTable dt, string customFileName, string customLocation = "\\\\psychfile\\psych$\\psych-lab-gfong\\SMG\\Access\\Reports\\ISR\\") { SurveyReport SR = new SurveyReport(); SR.Surveys.Add(new ReportSurvey(CurrentTiming.SurveyCode)); SR.FileName = customLocation; SR.ReportTable = dt; SR.OutputReportTableXML(customFileName); }
private void OutputReport(DataTable dt, string customFileName) { SurveyReport SR = new SurveyReport(); SR.Surveys.Add(new ReportSurvey("Survey Timing Method 3 Comparison")); SR.FileName = "\\\\psychfile\\psych$\\psych-lab-gfong\\SMG\\Access\\Reports\\ISR\\"; SR.ReportTable = dt; SR.OutputReportTableXML(customFileName); }
public async Task <FileStreamResult> ExportReportToPdf(SurveyReport surveyReport) { if (!Directory.Exists("wwwroot")) { Directory.CreateDirectory("wwwroot"); } var path = Path.Combine(_hostingEnvironment.WebRootPath, "reports"); if (!Directory.Exists(path)) { Directory.CreateDirectory(path); } var fullFileLocation = Path.Combine(path, surveyReport.Id + ".pdf"); if (File.Exists(fullFileLocation)) { File.Delete(fullFileLocation); } var globalSettings = new GlobalSettings { ColorMode = ColorMode.Color, Orientation = Orientation.Portrait, PaperSize = PaperKind.A4, Margins = new MarginSettings { Top = 10 }, DocumentTitle = surveyReport.SurveyTitle, Out = fullFileLocation }; var objectSettings = new ObjectSettings { PagesCount = true, HtmlContent = generateHtmlReport(surveyReport), WebSettings = { DefaultEncoding = "utf-8", UserStyleSheet = Path.Combine(Directory.GetCurrentDirectory(), "assets", "styles.css") }, HeaderSettings = { FontName = "Arial", FontSize = 9, Right = "Page [page] of [toPage]", Line = true }, FooterSettings = { FontName = "Arial", FontSize = 9, Line = true, Center = "Raport Created: " + DateTime.Now } }; var pdf = new HtmlToPdfDocument() { GlobalSettings = globalSettings, Objects = { objectSettings } }; _converter.Convert(pdf); return(new FileStreamResult(File.Open(fullFileLocation, FileMode.Open), "application/pdf") { FileDownloadName = "report.pdf" }); }
public void SurveyReportAddCurrentSurvey() { SurveyReport SR = new SurveyReport(); ReportSurvey RS = new ReportSurvey("6E2"); SR.AddSurvey(RS); Assert.IsTrue(SR.Surveys[0].ID == 1); Assert.IsTrue(SR.Surveys[0].Primary); Assert.IsTrue(SR.Surveys[0].Qnum); }
public void OneSurveyTaker() { Survey survey = new Survey(); List <Survey> lstSurveys = new List <Survey>(); lstSurveys.Add(survey); SurveyReport report = new SurveyReport(lstSurveys); Assert.IsTrue(report.SurveyTakers == 1); Assert.IsTrue(report.PositiveProductFeedback == 0); Assert.IsTrue(report.NegativeProductFeedback == 0); }
private void DoCompareReport(ReportSurvey s1, ReportSurvey s2, string filename, bool hideIdentical) { SurveyReport SR = new SurveyReport(); SR.FileName = "\\\\psychfile\\psych$\\psych-lab-gfong\\SMG\\Access\\Reports\\ISR\\"; string customFileName = filename; SR.AddSurvey(s1); SR.AddSurvey(s2); SR.ShowQuestion = false; SR.SurveyCompare.HideIdenticalQuestions = hideIdentical; SR.SurveyCompare.ReInsertDeletions = true; SR.GenerateReport(); SR.OutputReportTableXML(customFileName); }
// add 3 surveys, then remove the first added survey. The 2nd of the remaining surveys should be primary public void SurveyReportAdd3CurrentSurveysRemove2() { SurveyReport SR = new SurveyReport(); ReportSurvey RS = new ReportSurvey("6E2"); ReportSurvey RS2 = new ReportSurvey("6E1"); ReportSurvey RS3 = new ReportSurvey("6E2.5-ES"); SR.AddSurvey(RS); SR.AddSurvey(RS2); SR.AddSurvey(RS3); SR.RemoveSurvey(RS); Assert.IsTrue(SR.Surveys[0].ID == 1); Assert.IsFalse(SR.Surveys[0].Primary); Assert.IsTrue(SR.Surveys[1].Primary); Assert.IsTrue(SR.Surveys[0].Qnum); }
private void cmdGenerate_Click(object sender, EventArgs e) { SurveyReport SO = new SurveyReport(); ReportSurvey source = new ReportSurvey(DBAction.GetSurveyInfo(cboSurvey.GetItemText(cboSurvey.SelectedItem))); SO.Surveys.Add(source); SO.Surveys[0].Qnum = true; foreach (ReportSurvey rs in SO.Surveys) { rs.VarLabelCol = true; rs.TopicLabelCol = true; rs.ContentLabelCol = true; } SO.ShowAllQnums = true; SO.ShowAllVarNames = true; SO.ShowQuestion = false; SO.GenerateReport(); }
private void exportToolStripMenuItem1_Click(object sender, EventArgs e) { // check which are checked bool q = questionToolStripMenuItem.Checked; bool t = translationsToolStripMenuItem1.Checked; SurveyReport sr = new SurveyReport(); sr.AddSurvey(new ReportSurvey(CurrentSurvey.SurveyCode)); sr.Surveys[0].AddQuestion(CurrentQuestion); if (t) { sr.Surveys[0].Questions[0].Translations.AddRange(DBAction.GetQuestionTranslations(sr.Surveys[0].Questions[0].ID)); sr.Surveys[0].TransFields.AddRange(DBAction.GetLanguages(CurrentSurvey)); } sr.FileName = "\\\\psychfile\\psych$\\psych-lab-gfong\\SMG\\Access\\Reports\\ISR\\" + "Survey Entry Export - " + DateTime.Today.ToString("d").Replace("-", ""); sr.GenerateReport(); sr.OutputReportTableXML(); // TODO export items if each type is checked }
public void SingleSurveySingleQuestionReportTable() { SurveyReport SR = new SurveyReport(); ReportSurvey s = new ReportSurvey("Test"); SR.AddSurvey(s); SurveyQuestion sq = new SurveyQuestion(); sq.VarName.FullVarName = "AA000"; sq.Qnum = "000"; sq.PreP = "Test PreP"; sq.LitQ = "Test LitQ"; sq.RespOptions = "1 Yes"; s.AddQuestion(sq); int result = SR.GenerateReport(); Assert.IsTrue(result == 0); Assert.IsTrue(SR.ReportTable.Rows.Count == 1); }
public async Task <int> CreateAsync(int surveyId, string surveyTitle, string surveyDescription) { var surveyReport = new SurveyReport(surveyId, surveyTitle, surveyDescription); await _surveyReportRepository.AddAsync(surveyReport); var survey = await _surveyRepository.GetByIdWithQuestionsAsync(surveyId); foreach (var question in survey.Questions) { var questionReport = new QuestionReport(question.Content, question.Select, 0, question.QuestionPosition); surveyReport.AddQuestionReport(questionReport); await _questionReportRepository.AddAsync(questionReport); foreach (var fieldData in question.FieldData) { switch (questionReport.Select) { case "short-answer": case "long-answer": { var dataSet = new DataSet(); questionReport.AddDataSet(dataSet); await _dataSetRepository.AddAsync(dataSet); await _questionReportRepository.UpdateAsync(questionReport); foreach (var label in questionReport.Labels) { dataSet.AddData("0"); await _dataSetRepository.UpdateAsync(dataSet); } } break; case "dropdown-menu": { foreach (var choiceOption in fieldData.ChoiceOptions) { questionReport.AddLabel(choiceOption.ViewValue); } var dataSet = new DataSet(); questionReport.AddDataSet(dataSet); await _dataSetRepository.AddAsync(dataSet); await _questionReportRepository.UpdateAsync(questionReport); foreach (var label in questionReport.Labels) { dataSet.AddData("0"); await _dataSetRepository.UpdateAsync(dataSet); } } break; case "linear-scale": { for (var i = 1; i <= fieldData.MaxValue; i++) { questionReport.AddLabel(i.ToString()); } var dataSet = new DataSet(question.Content); questionReport.AddDataSet(dataSet); await _dataSetRepository.AddAsync(dataSet); await _questionReportRepository.UpdateAsync(questionReport); foreach (var label in questionReport.Labels) { dataSet.AddData("0"); await _dataSetRepository.UpdateAsync(dataSet); } } break; case "multiple-grid": case "single-grid": { foreach (var row in fieldData.Rows) { questionReport.AddLabel(row.Input); } foreach (var choiceOption in fieldData.ChoiceOptions) { var dataSet = new DataSet(choiceOption.ViewValue); questionReport.AddDataSet(dataSet); await _dataSetRepository.AddAsync(dataSet); await _questionReportRepository.UpdateAsync(questionReport); foreach (var row in fieldData.Rows) { dataSet.AddData("0"); await _dataSetRepository.UpdateAsync(dataSet); } } } break; case "single-choice": case "multiple-choice": { foreach (var choiceOption in fieldData.ChoiceOptions) { questionReport.AddLabel(choiceOption.ViewValue); } var dataSet = new DataSet(question.Content); questionReport.AddDataSet(dataSet); await _dataSetRepository.AddAsync(dataSet); await _questionReportRepository.UpdateAsync(questionReport); foreach (var label in questionReport.Labels) { dataSet.AddData("0"); await _dataSetRepository.UpdateAsync(dataSet); } } break; } } } return(surveyReport.Id); }
public async Task <ActionResult> SurveyResult(SurveyReport test) { var data = await SurveyQuetionRepository.Instance.Read(1); return(View(data)); }
public async Task AddAsync(SurveyReport surveyReport) { await _context.AddAsync(surveyReport); await _context.SaveChangesAsync(); }
private string generateHtmlReport(SurveyReport surveyReport) { var sb = new StringBuilder(); sb.Append(@" <html> <head> <style> .header{ text-align:center; padding-top:50px; } .question{ width:100%; margin-top:50px; position:relative; page-break-inside: avoid; } .question h2{ width:700px; } .odp{ position:absolute; right:0; top:0; } .textAnswerHead{ width:100%; height:20px; background-color:#c2e697; position:relative; } .textAnswer{ background-color:#8bc34a; padding:10px; } .columnChart{ width:100%; height:300px; position:relative; } .singleColumn{ position:absolute; bottom:0; left:0; width:50px; height:50%; background-color:#8bc34a; text-align:center; } .colLabel{ position:absolute; text-align:center; bottom:-20px; white-space: nowrap; } .repTable{ border:1px solid; width:100%; height:300px; border-collapse: collapse; } .repTable th{ border:1px solid; } </style> </head> <body> <div class='header'><h1>" + surveyReport.SurveyTitle + @"</h1>" + "Liczba odpowiedzi: " + surveyReport.AnswersNumber + @"</div> "); foreach (var questionReport in surveyReport.QuestionsReports) { sb.Append(@"<div class='question'> <h2>" + questionReport.Content + @"</h2><span class='odp'>Liczba odpowiedzi: " + questionReport.AnswersNumber + @"</span>"); switch (questionReport.Select) { case "short-answer": case "long-answer": foreach (var reportDataSet in questionReport.DataSets) { foreach (var data in reportDataSet._data) { if (data != "") { sb.Append(@"<div class='textAnswerHead'></div>"); sb.Append(@"<div class='textAnswer'>" + data + @"</div>"); } } } break; case "single-choice": case "multiple-choice": case "linear-scale": case "dropdown-menu": var array = new int[questionReport.Labels.Count]; foreach (var reportDataSet in questionReport.DataSets) { for (int i = 0; i < reportDataSet._data.Count; i++) { if (reportDataSet._data[i] == "1") { array[i]++; } } } sb.Append(@"<div class='columnChart'>"); for (int i = 0; i < questionReport.Labels.Count; i++) { sb.Append(@" <div class='singleColumn' style='left:" + 100 * (1 + i) / (questionReport.Labels.Count + 2) + @"%;height:" + 100 * array[i] / array.Max() + @"%'> <span class='colLabel'>" + array[i] + " x " + questionReport.Labels.ElementAt(i) + @"</span> </div>"); } sb.Append(@"</div> "); break; case "single-grid": case "multiple-grid": Dictionary <string, int[]> dictionary = new Dictionary <string, int[]>(); foreach (var reportDataSet in questionReport.DataSets) { if (dictionary.ContainsKey(reportDataSet.Label)) { for (int i = 0; i < reportDataSet._data.Count; i++) { if (reportDataSet._data[i] == "1") { dictionary[reportDataSet.Label][i] += 1; } } } else { int[] ints = reportDataSet._data.Select(int.Parse).ToArray(); dictionary.Add(reportDataSet.Label, ints); } } sb.Append(@"<table class='repTable'>"); sb.Append(@"<tr style='background-color:#8bc34a'><th></th>"); foreach (var entry in dictionary) { sb.Append(@"<th>" + entry.Key + @"</th>"); } sb.Append(@"</tr>"); for (int i = 0; i < questionReport.Labels.Count; i++) { sb.Append(@"<tr><th style='background-color:#8bc34a'>" + questionReport.Labels.ElementAt(i) + @"</th>"); for (int j = 0; j < dictionary.Count; j++) { sb.Append(@"<th style='background-color:#c2e697'>" + dictionary.ElementAt(j).Value[i] + @"</th>"); } sb.Append(@"</tr>"); } sb.Append(@"</table>"); break; } sb.Append(@"</div>"); } sb.Append(@" </body> </html>"); return(sb.ToString()); }
public async Task DeleteAsync(SurveyReport surveyReport) { _context.Remove(surveyReport); await _context.SaveChangesAsync(); }
public async Task <FileStreamResult> ExportReportToTxt(SurveyReport surveyReport) { if (!Directory.Exists("wwwroot")) { Directory.CreateDirectory("wwwroot"); } var path = Path.Combine(_hostingEnvironment.WebRootPath, "reports"); if (!Directory.Exists(path)) { Directory.CreateDirectory(path); } var fullFileLocation = Path.Combine(path, surveyReport.Id + ".txt"); if (File.Exists(fullFileLocation)) { File.Delete(fullFileLocation); } string surveyReportTxt = "Nazwa ankiety: " + surveyReport.SurveyTitle + Environment.NewLine + "Utworzona: " + surveyReport.CreatedAt + Environment.NewLine + "Odpowiedzi: " + surveyReport.AnswersNumber + Environment.NewLine + "Pytania:" + Environment.NewLine; foreach (var questionReport in surveyReport.QuestionsReports) { surveyReportTxt += Environment.NewLine + "-" + questionReport.Content + Environment.NewLine + "-ilość odpowiedzi: " + questionReport.AnswersNumber + Environment.NewLine; switch (questionReport.Select) { case "short-answer": case "long-answer": foreach (var reportDataSet in questionReport.DataSets) { foreach (var data in reportDataSet._data) { if (data != "") { surveyReportTxt += "--" + data + Environment.NewLine; } } } break; case "single-choice": case "multiple-choice": case "dropdown-menu": case "linear-scale": var array = new int[questionReport.Labels.Count]; foreach (var reportDataSet in questionReport.DataSets) { for (int i = 0; i < reportDataSet._data.Count; i++) { if (reportDataSet._data[i] == "1") { array[i]++; } } } for (int i = 0; i < questionReport.Labels.Count; i++) { surveyReportTxt += "--" + questionReport.Labels.ElementAt(i) + ": liczba odpowiedzi: " + array[i] + Environment.NewLine; } break; case "single-grid": case "multiple-grid": Dictionary <string, int[]> dictionary = new Dictionary <string, int[]>(); foreach (var reportDataSet in questionReport.DataSets) { if (dictionary.ContainsKey(reportDataSet.Label)) { for (int i = 0; i < reportDataSet._data.Count; i++) { if (reportDataSet._data[i] == "1") { dictionary[reportDataSet.Label][i] += 1; } } } else { int[] ints = reportDataSet._data.Select(int.Parse).ToArray(); dictionary.Add(reportDataSet.Label, ints); } } for (int i = 0; i < questionReport.Labels.Count; i++) { surveyReportTxt += "--" + questionReport.Labels.ElementAt(i) + ": "; foreach (var entry in dictionary) { surveyReportTxt += entry.Key + "x" + entry.Value[i] + " "; } surveyReportTxt += Environment.NewLine; } break; } } using (FileStream fs = File.Create(fullFileLocation)) { Byte[] info = new UTF8Encoding(true).GetBytes(surveyReportTxt); fs.Write(info, 0, info.Length); } return(new FileStreamResult(File.Open(fullFileLocation, FileMode.Open), "application/octet-stream") { FileDownloadName = "report.txt" }); }
public async Task <FileStreamResult> ExportReportToExcel(SurveyReport surveyReport) { if (!Directory.Exists("wwwroot")) { Directory.CreateDirectory("wwwroot"); } var path = Path.Combine(_hostingEnvironment.WebRootPath, "reports"); if (!Directory.Exists(path)) { Directory.CreateDirectory(path); } var fullFileLocation = Path.Combine(path, surveyReport.Id + ".xlsx"); if (File.Exists(fullFileLocation)) { File.Delete(fullFileLocation); } FileInfo fileInfo = new FileInfo(fullFileLocation); using (ExcelPackage package = new ExcelPackage(fileInfo)) { var worksheet = package.Workbook.Worksheets.Add("Ankieta"); worksheet.Cells.AutoFitColumns(); worksheet.Cells.Style.HorizontalAlignment = ExcelHorizontalAlignment.Center; worksheet.Cells[1, 1].Value = "Nazwa ankiety"; worksheet.Cells[1, 2].Value = surveyReport.SurveyTitle; worksheet.Cells[2, 1].Value = "Ilość odpowiedzi"; worksheet.Cells[2, 2].Value = surveyReport.AnswersNumber; worksheet.Cells[3, 1].Value = "Utworzona"; worksheet.Cells[3, 2].Value = "" + surveyReport.CreatedAt; foreach (var questionReport in surveyReport.QuestionsReports) { worksheet = package.Workbook.Worksheets.Add(questionReport.Content); worksheet.Cells.AutoFitColumns(); worksheet.Cells.Style.HorizontalAlignment = ExcelHorizontalAlignment.Center; worksheet.Cells[1, 1].Value = "Ilość odpowiedzi"; worksheet.Cells[1, 2].Value = questionReport.AnswersNumber; switch (questionReport.Select) { case "short-answer": case "long-answer": for (int i = 0; i < questionReport.DataSets.Count; i++) { for (int j = 0; j < questionReport.DataSets.ElementAt(i)._data.Count; j++) { if (questionReport.DataSets.ElementAt(i)._data[j] == "") { continue; } worksheet.Cells[3 + i, 1].Value = questionReport.DataSets.ElementAt(i)._data[j]; } } break; case "single-choice": case "multiple-choice": case "dropdown-menu": case "linear-scale": var array = new int[questionReport.Labels.Count]; foreach (var reportDataSet in questionReport.DataSets) { for (int i = 0; i < reportDataSet._data.Count; i++) { if (reportDataSet._data[i] == "1") { array[i]++; } } } for (int i = 0; i < questionReport.Labels.Count; i++) { worksheet.Cells[3, i + 1].Value = questionReport.Labels.ElementAt(i); worksheet.Cells[4, i + 1].Value = array[i]; } break; case "single-grid": case "multiple-grid": Dictionary <string, int[]> dictionary = new Dictionary <string, int[]>(); foreach (var reportDataSet in questionReport.DataSets) { if (dictionary.ContainsKey(reportDataSet.Label)) { for (int i = 0; i < reportDataSet._data.Count; i++) { if (reportDataSet._data[i] == "1") { dictionary[reportDataSet.Label][i] += 1; } } } else { int[] ints = reportDataSet._data.Select(int.Parse).ToArray(); dictionary.Add(reportDataSet.Label, ints); } } for (int i = 0; i < dictionary.Count; i++) { worksheet.Cells[3, i + 2].Value = dictionary.ElementAt(i).Key; } for (int i = 0; i < questionReport.Labels.Count; i++) { worksheet.Cells[4 + i, 1].Value = questionReport.Labels.ElementAt(i); for (int j = 0; j < dictionary.Count; j++) { worksheet.Cells[4 + i, 2 + j].Value = dictionary.ElementAt(j).Value[i]; } } break; } } package.Save(); } return(new FileStreamResult(File.Open(fullFileLocation, FileMode.Open), "application/octet-stream") { FileDownloadName = "report.xlsx" }); }
private void RunWebReport(bool withTranslation = false) { string mode; bool englishRouting; mode = SR.Surveys[0].Mode.ModeAbbrev; SR.QNInsertion = true; SR.LayoutOptions.FileFormat = FileFormats.PDF; SR.LayoutOptions.ToC = TableOfContents.PageNums; SR.Web = true; SR.LayoutOptions.CoverPage = true; SR.VarChangesCol = true; SR.ExcludeTempChanges = true; SR.VarChangesApp = true; SR.Details = ""; SR.ShowLongLists = true; switch (mode) { case "F2F": case "mail": case "semi-tel": SR.NrFormat = ReadOutOptions.DontReadOut; break; } if (withTranslation) { foreach (ReportSurvey rs in SR.Surveys) { rs.TransFields = DBAction.GetLanguages(rs); } } // get the survey data for all chosen surveys PopulateSurveys(); int result; SurveyReport survReport = new SurveyReport(SR) { SurveyCompare = compare }; // bind status label to survey report's status property lblStatus.DataBindings.Clear(); lblStatus.DataBindings.Add(new Binding("Text", survReport, "ReportStatus")); result = survReport.GenerateReport(); switch (result) { case 1: MessageBox.Show("One or more surveys contain no records."); // TODO if a backup was chosen, show a form for selecting a different survey code from that date break; default: break; } // output report to Word/PDF survReport.OutputReportTableXML(); }
private void RunStandardReport(bool withTranslation = false) { string mode; bool englishRouting; mode = SR.Surveys[0].Mode.ModeAbbrev; if (SR.Surveys.Count == 1) { englishRouting = SR.Surveys[0].EnglishRouting; SR.Surveys[0].Qnum = true; } else { int primeID = 0; if (SR.Surveys.Count >= 3) { primeID = 1; } else { primeID = 2; } SR.SetPrimary(primeID); SR.Surveys[0].Qnum = true; SR.CompareWordings = true; compare.ShowDeletedQuestions = true; compare.ShowDeletedFields = true; compare.ReInsertDeletions = true; compare.Highlight = true; } if (withTranslation) { foreach (ReportSurvey rs in SR.Surveys) { rs.TransFields = DBAction.GetLanguages(rs); } } switch (mode) { case "F2F": case "mail": case "semi-tel": SR.QNInsertion = true; SR.NrFormat = ReadOutOptions.DontReadOut; break; case "CATI": case "web": case "tel": case "CAPI": SR.QNInsertion = false; SR.NrFormat = ReadOutOptions.Neither; break; } SR.LayoutOptions.BlankColumn = true; SR.VarChangesCol = true; SR.ExcludeTempChanges = true; SR.Details = ""; // get the survey data for all chosen surveys PopulateSurveys(); int result; SurveyReport survReport = new SurveyReport(SR) { SurveyCompare = compare }; // bind status label to survey report's status property lblStatus.DataBindings.Clear(); lblStatus.DataBindings.Add(new Binding("Text", survReport, "ReportStatus")); result = survReport.GenerateReport(); switch (result) { case 1: MessageBox.Show("One or more surveys contain no records."); // TODO if a backup was chosen, show a form for selecting a different survey code from that date break; default: break; } // output report to Word/PDF survReport.OutputReportTableXML(); }