-
Notifications
You must be signed in to change notification settings - Fork 0
/
CQuizFillIn.cs
287 lines (222 loc) · 14.7 KB
/
CQuizFillIn.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
using System;
using System.Data;
using System.Windows.Forms;
using System.Collections;
using System.Text.RegularExpressions;
namespace BrowserApp
{
/// <summary>
/// Summary description for CQuizFillIn.
/// </summary>
public class CQuizFillIn : CQuiz
{
public CQuizFillIn(ref DataGridView dataGridCurrent, ref DataTable dTableCurrent) : base(ref dataGridCurrent, ref dTableCurrent)
{
//
// TODO: Add constructor logic here
//
sCurrentJsQuizType = "FillIn";
InitializeGrid(ref dataGridCurrent, ref dTableCurrent);
}
/// <summary>
///
/// </summary>
public override void InitializeGrid(ref DataGridView dataGridCurrent, ref DataTable dTableCurrent)
{
RemoveClickEvent(dataGridCurrent);
dTableCurrent = new DataTable ("DataTable" + GetQuizType());
dataGridCurrent.Columns.Clear();
dataGridCurrent.RowTemplate.Height = 52;
//dataGridCurrent.TableStyles.Clear();
// Add a GridTableStyle and set the MappingName
// to the name of the DataTable.
DataGridTableStyle dgdtblStyle = new DataGridTableStyle();
dgdtblStyle.RowHeadersVisible = false;
dgdtblStyle.MappingName = dTableCurrent.TableName;
dgdtblStyle.AllowSorting = false;
dataGridCurrent.RowHeadersVisible = false;
for (int i = 0; i < 2; i++) {
dTableCurrent.Columns.Add("Column" + (i+1).ToString(), System.Type.GetType("System.String"));
}
DataGridViewTextBoxColumn gtbc1 = new DataGridViewTextBoxColumn();
gtbc1.HeaderText = "Phrase (use '<input0>, <input1>, etc' to denote multiple Fill-In boxes)";
gtbc1.DefaultCellStyle.WrapMode = DataGridViewTriState.True;
gtbc1.SortMode = DataGridViewColumnSortMode.NotSortable;
gtbc1.DataPropertyName = "Column1";
//gtbc1.ValueType = typeof(string);
gtbc1.Width = 600;
gtbc1.DefaultCellStyle.NullValue = "<type phrase here>";
dataGridCurrent.Columns.Add(gtbc1);
// Add a GridColumnStyle and set the MappingName
// to the name of a DataColumn in the DataTable.
// Set the HeaderText and Width properties.
//ExtendedDataGridMultiLineTextBoxColumn tbc1 = new ExtendedDataGridMultiLineTextBoxColumn();
//tbc1.MappingName = "Column1";
//tbc1.TextBox.Multiline = true;
//tbc1.MinimumHeight = 52;
//tbc1.HeaderText = "Phrase (use '<input0>, <input1>, etc' to denote multiple Fill-In boxes)";
//tbc1.Width = 600;
//tbc1.NullText = "<type phrase here>";
//dgdtblStyle.GridColumnStyles.Add(tbc1);
DataGridViewTextBoxColumn gtbc2 = new DataGridViewTextBoxColumn();
gtbc2.HeaderText = "Answer (use semicolon \";\" to deliminate)";
gtbc2.DataPropertyName = "Column2";
gtbc2.Width = 300;
gtbc2.SortMode = DataGridViewColumnSortMode.NotSortable;
gtbc2.DefaultCellStyle.NullValue = "<type answer here>";
dataGridCurrent.Columns.Add(gtbc2);
//DataGridTextBoxColumn tbc2 = new DataGridTextBoxColumn();
//tbc2.MappingName = "Column2";
//tbc2.HeaderText = "Answer (use semicolon \";\" to deliminate)";
//tbc2.Width = 230;
//tbc2.NullText = "<type answer here>";
//dgdtblStyle.GridColumnStyles.Add(tbc2);
foreach (DataGridViewColumn column in dataGridCurrent.Columns)
{
dataGridCurrent.Columns[column.Name].SortMode = DataGridViewColumnSortMode.NotSortable;
}
// Add the DataGridTableStyle instance to the GridTableStylesCollection.
//dataGridCurrent.TableStyles.Add(dgdtblStyle);
dataGridCurrent.DataSource = dTableCurrent;
dataGridCurrent.Visible = true;
}
/// <summary>
///
/// </summary>
public override void FillGridWithJavascriptData(ref DataGridView dataGridCurrent, ref DataTable dTableCurrent, string sJavascriptData, TabControl tabData)
{
int iAnswerCount = 0;
string sNumQuestions = GetLastMatchedString(sJavascriptData, "numQues=", ";");
for (int i = 0; (sNumQuestions.Length > 0) && (i < Convert.ToInt32(sNumQuestions)); i++) {
string sInputCount = GetLastMatchedString(sJavascriptData, "OrigQuestions[" + i.ToString() + "][0]=", ";");
string sNextQuestion = GetLastMatchedString(sJavascriptData, "OrigQuestions[" + i.ToString() + "][1]=\"", "\"");
//Should Convert sNextQuestion's <inputX> to <input> here in the future so user doesn't have to type number X
string sNextAnswer = "";
for (int j = 0; j < Convert.ToInt32(sInputCount); j++) {
sNextAnswer = sNextAnswer + GetLastMatchedString(sJavascriptData, "OrigAnswers[" + iAnswerCount.ToString() + "]=\"", "\"") + ";";
iAnswerCount++;
}
DataRow drNewData = dTableCurrent.NewRow();
// Format for %'s in Netscape 6 - %25's from javascript file must become %'s
sNextQuestion = sNextQuestion.Replace("%25", "%");
sNextAnswer = sNextAnswer.Replace("%25", "%");
// Format for %'s in Netscape 6 - %25's from javascript file must become %'s
drNewData["Column1"] = sNextQuestion;
drNewData["Column2"] = sNextAnswer;
dTableCurrent.Rows.Add(drNewData);
}
string sChoices = GetLastMatchedString(sJavascriptData, "PossibleAnswers=\"", "\"");
// Format for textbox - <br>, <br/>, <br />, <br /> all become \n
sChoices = sChoices.Replace("<br>", "\r\n");
sChoices = sChoices.Replace("<br/>", "\r\n");
sChoices = sChoices.Replace("<br />", "\r\n");
sChoices = sChoices.Replace("<br />", "\r\n");
string sArrangement = GetLastMatchedString(sJavascriptData, "bOnePerPage=", ";");
string sColumns = GetLastMatchedString(sJavascriptData, "iResultsWidth=", ";");
string sRows = GetLastMatchedString(sJavascriptData, "iResultsHeight=", ";");
string sShowQuestionNumbers = GetLastMatchedString(sJavascriptData, "bShowQuestionNumbers=", ";");
string sPageWidth = GetLastMatchedString(sJavascriptData, "iTotalPageWidth=", ";");
string sTypeQuiz = GetLastMatchedString(sJavascriptData, "bTypeQuiz=", ";");
Control.ControlCollection ocTabPageJsOptions = tabData.Controls.Find("tabPageJsOptionsFi", false)[0].Controls;
((TextBox)ocTabPageJsOptions.Find("textBoxFiResultsCols", false)[0]).Text = sColumns;
((TextBox)ocTabPageJsOptions.Find("textBoxFiResultsRows", false)[0]).Text = sRows;
((RadioButton)ocTabPageJsOptions.Find("radioButtonFiQuestionAll", false)[0]).Checked = sArrangement.Equals("true");
((RadioButton)ocTabPageJsOptions.Find("radioButtonFiQuestionOne", false)[0]).Checked = sArrangement.Equals("false");
((TextBox)ocTabPageJsOptions.Find("textBoxJsOptionsFiChoices", false)[0]).Text = sChoices;
((TextBox)ocTabPageJsOptions.Find("textBoxFiPageWidth", false)[0]).Text = sPageWidth;
((CheckBox)ocTabPageJsOptions.Find("checkBoxFiShowNumbers", false)[0]).Checked = sShowQuestionNumbers.Equals("true");
((CheckBox)ocTabPageJsOptions.Find("checkBoxFiTypeQuiz", false)[0]).Checked = sTypeQuiz.Equals("true");
}
/// <summary>
///
/// </summary>
public override string ParseGridAndCreateJavascriptData(DataGridView dataGridCurrent, string sJsDataTemplate, Form cMainForm, TabControl tabData)
{
AcceptChanges(dataGridCurrent);
string sReturnJavascript = sJsDataTemplate;
if (dataGridCurrent.DataSource != null) {
int iQuestionsCount = 0;
int iAnswersCount = 0;
string sMatchingInputCountLine = "\r\nOrigQuestions[NNN][0]=III;";
string sMatchingQuestionsLine = "\r\nOrigQuestions[NNN][1]=\"QQQ\";";
string sMatchingAnswersLine = "\r\nOrigAnswers[NNN]=\"AAA\";";
string sQuestionLines = "";
string sAnswerLines = "";
CurrencyManager cm = (CurrencyManager)cMainForm.BindingContext[dataGridCurrent.DataSource];
for (int row = 0; row < cm.Count; row++) {
string sQuestion = dataGridCurrent[0,row].Value.ToString();
string sAnswer = dataGridCurrent[1,row].Value.ToString();
if ((sQuestion.Length > 0) && (sAnswer.Length > 0)) {
int iLastInput = sQuestion.LastIndexOf("<input");
string sInputCount = GetLastMatchedString(sQuestion.Substring(iLastInput), "<input", ">");
int iNumInputs = Convert.ToInt32(sInputCount) + 1;
string sTempInputCountLine = sMatchingInputCountLine;
sTempInputCountLine = sTempInputCountLine.Replace("NNN", row.ToString());
sTempInputCountLine = sTempInputCountLine.Replace("III", iNumInputs.ToString());
string sTempQuestionsLine = sMatchingQuestionsLine;
sTempQuestionsLine = sTempQuestionsLine.Replace("NNN", row.ToString());
sQuestion = sQuestion.Replace("\"", """);
sTempQuestionsLine = sTempQuestionsLine.Replace("QQQ", sQuestion);
sQuestionLines = sQuestionLines + sTempInputCountLine + sTempQuestionsLine;
sAnswer = sAnswer.Replace("\"", """);
string[] asIndividual = sAnswer.Split(new char[]{';'});
for (int j = 0; j < iNumInputs; j++) {
string sTempAnswersLine = sMatchingAnswersLine;
sTempAnswersLine = sTempAnswersLine.Replace("NNN", iAnswersCount.ToString());
sTempAnswersLine = sTempAnswersLine.Replace("AAA", asIndividual[j]);
sAnswerLines = sAnswerLines + sTempAnswersLine;
iAnswersCount++;
}
iQuestionsCount++;
}
}
string sNewSizeVars = "numQues=" + iQuestionsCount + ";";
sReturnJavascript = Regex.Replace(sReturnJavascript,
"//SIZEVARSBEGIN(.*)//SIZEVARSEND",
"//SIZEVARSBEGIN\r\n" + sNewSizeVars + "\r\n//SIZEVARSEND",
RegexOptions.Singleline);
// Format for %'s in Netscape 6 - %25's from javascript file must become %'s
sQuestionLines = sQuestionLines.Replace("%", "%25");
sAnswerLines = sAnswerLines.Replace("%", "%25");
// Format for %'s in Netscape 6 - %25's from javascript file must become %'s
sReturnJavascript = Regex.Replace(sReturnJavascript,
"//QUESTIONSBEGIN(.*)//QUESTIONSEND",
"//QUESTIONSBEGIN" + sQuestionLines + "\r\n//QUESTIONSEND",
RegexOptions.Singleline);
sReturnJavascript = Regex.Replace(sReturnJavascript,
"//ANSWERSBEGIN(.*)//ANSWERSEND",
"//ANSWERSBEGIN" + sAnswerLines + "\r\n//ANSWERSEND",
RegexOptions.Singleline);
Control.ControlCollection ocTabPageJsOptions = tabData.Controls.Find("tabPageJsOptionsFi", false)[0].Controls;
string sNumCols = ((TextBox)ocTabPageJsOptions.Find("textBoxFiResultsCols", false)[0]).Text;
string sNumRows = ((TextBox)ocTabPageJsOptions.Find("textBoxFiResultsRows", false)[0]).Text;
//string sOnePerPage = !((RadioButton)ocTabPageJsOptions.Find("radioButtonFiQuestionAll", false)[0]).Checked ? "false" : "true";
string sOnePerPage = ((RadioButton)ocTabPageJsOptions.Find("radioButtonFiQuestionOne", false)[0]).Checked ? "true" : "false";
string sChoices = ((TextBox)ocTabPageJsOptions.Find("textBoxJsOptionsFiChoices", false)[0]).Text;
string sPageWidth = ((TextBox)ocTabPageJsOptions.Find("textBoxFiPageWidth", false)[0]).Text;
string sShowQuestionNumbers = ((CheckBox)ocTabPageJsOptions.Find("checkBoxFiShowNumbers", false)[0]).Checked ? "true" : "false";
string sTypeQuiz = ((CheckBox)ocTabPageJsOptions.Find("checkBoxFiTypeQuiz", false)[0]).Checked ? "true" : "false";
/*
//Not really set up yet so maybe need to change movenexts
string sTypeQuiz = ((CheckBox)ieTabPage.Current).Checked ? "true" : "false";
*/
// Format for textbox - <br>, <br/>, <br /> all become \r\n
sChoices = sChoices.Replace("\r\n", "<br />");
sChoices = sChoices.Replace("\"", """);
string sMatchingChoicesLine = "\r\nPossibleAnswers=\"PPP\";";
sMatchingChoicesLine = sMatchingChoicesLine.Replace("PPP", sChoices);
sReturnJavascript = Regex.Replace(sReturnJavascript,
"//CHOICESBEGIN(.*)//CHOICESEND",
"//CHOICESBEGIN" + sMatchingChoicesLine + "\r\n//CHOICESEND",
RegexOptions.Singleline);
sReturnJavascript += "\r\nbOnePerPage=" + sOnePerPage + ";\r\n";
sReturnJavascript += "\r\niResultsWidth=" + sNumCols + ";\r\n";
sReturnJavascript += "\r\niResultsHeight=" + sNumRows + ";\r\n";
sReturnJavascript += "\r\nbShowQuestionNumbers=" + sShowQuestionNumbers + ";\r\n";
sReturnJavascript += "\r\niTotalPageWidth=" + sPageWidth + ";\r\n";
sReturnJavascript += "\r\nbTypeQuiz=" + sTypeQuiz + ";\r\n";
}
return (sReturnJavascript);
}
}
}