private void Form1_Load(object sender, EventArgs e) { this.txtComments.Text = @"far apart,far away,faraway,asg,after,all-star,all-stars,away from,before,day,days,final,finals,packetization,packetize,packet,playoff,superplayoff,tie,tb,tiebreaker"; this.txtQuestionInput.Text = @""; this.txtLogoFile.Text = @""; //this.txtTemplateInput.Text = @"C:\Users\mbentley\AppData\Local\Temp\QEMS2\130960503249323562.csv"; this.txtOutputDir.Text = Path.Combine(Path.GetTempPath(), "QEMS2"); this.txtSetName.Text = ""; this.opVHSL.Checked = true; this.setType = QuestionSet.SetType.VHSL; this.chkWriterNames.Checked = true; this.txtQuestionInput.Text = @"C:\Users\mbentley\Downloads\packet2 (13) (1).csv"; }
private void opNasat_CheckedChanged(object sender, EventArgs e) { this.setType = QuestionSet.SetType.Nasat; }
private void opVHSL_CheckedChanged(object sender, EventArgs e) { this.setType = QuestionSet.SetType.VHSL; }
/// <summary> /// For the given CSV of the packets, generates the RTF documents /// </summary> /// <param name="file">CSV of the packets. e.g. a file that is named something like 131384202599968092.csv</param> /// <param name="outputDir">Output directory to place the RTF files</param> /// <param name="includeScoresheet">If true, add a scoresheet to the first page</param> /// <param name="convertToDocx">If true, convert the RTF files to .docx files</param> /// <param name="setType">What question set type to produce</param> /// <param name="logo">Logo file to add to top of documents</param> /// <param name="includeComments">If true, include comments below questions</param> /// <param name="commentFilters">If non-empty, only include comments that match at least one of these terms</param> /// <param name="includeWriterNames">If true, include writer names under questions</param> /// <param name="setName">Name of the question set</param> /// <param name="font">Name of the font to use</param> public static void GenerateRtf( string file, string outputDir, bool includeScoresheet, bool convertToDocx, QuestionSet.SetType setType, string logo, bool includeComments, List <string> commentFilters, bool includeWriterNames, bool includeCategories, string setName, string font) { Directory.CreateDirectory(outputDir); string bitmapText = string.Empty; if (!string.IsNullOrEmpty(logo)) { Bitmap bitmap = LoadImage(logo); bitmapText = GetEmbedImageString(bitmap); } int round = 1; foreach (string line in File.ReadAllLines(file).Skip(1)) { string outputRtf = Path.Combine(outputDir, string.Format("Round {0}.rtf", round.ToString("D2"))); string rtfLine = EscapeRTF(line); List <string> cols = QuestionSet.ReadCSVLine(rtfLine); StringBuilder builder = new StringBuilder(); if (includeScoresheet) { // Load the scoresheet rtf to place at the top of the document string scoresheetRtf = File.ReadAllText(@"2017NSCScoresheet.rtf"); // Set the round number to the proper value scoresheetRtf = scoresheetRtf.Replace("CHANGE ME", round.ToString("D2")); scoresheetRtf = AddFontToScoresheet(scoresheetRtf, font); builder.Append(scoresheetRtf); } else { builder.Append(@"{\rtf1\ansi\ansicpg1252\deff0\deflang1033\margl720\margr720\margt720\margb720"); } string formattedRound = round.ToString("D2"); if (setType == QuestionSet.SetType.NSC || setType == QuestionSet.SetType.Nasat) { builder.Append(GetNscOrNasatText(cols, includeWriterNames, includeCategories, includeComments, commentFilters, setName, formattedRound, bitmapText, font)); } else if (setType == QuestionSet.SetType.VHSL) { builder.Append(GetVhslText(cols, includeWriterNames, includeCategories, includeComments, commentFilters, setName, formattedRound, bitmapText, font)); } builder.Append("}"); File.WriteAllText(outputRtf, builder.ToString()); round++; } ConvertToDocx(outputDir); }