-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFrmPreview.cs
More file actions
92 lines (91 loc) · 4.26 KB
/
FrmPreview.cs
File metadata and controls
92 lines (91 loc) · 4.26 KB
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
using Xceed.Words.NET;
namespace QuestionPaperMaker
{
public partial class FrmPreview : DevExpress.XtraEditors.XtraForm
{
public FrmPreview(string documentPath, List<string> arguments)
{
InitializeComponent();
DocX document = DocX.Load(documentPath);
bool questions1Bool = false;
bool questions2Bool = false;
bool questions3Bool = false;
bool questions4Bool = false;
var questions1List = new List<string>();
var questions2List = new List<string>();
var questions3List = new List<string>();
var questions4List = new List<string>();
foreach (var paragraph in document.Paragraphs)
{
if (paragraph.Text == "1-ci sual*")
{
questions1Bool = true;
continue;
}
if (paragraph.Text == "2-ci sual**")
{
questions2Bool = true;
continue;
}
if (paragraph.Text == "3-cü sual***")
{
questions3Bool = true;
continue;
}
if (paragraph.Text == "4-cü sual****")
{
questions4Bool = true;
continue;
}
if (questions4Bool)
{
questions4List.Add(paragraph.Text);
continue;
}
if (questions3Bool)
{
questions3List.Add(paragraph.Text);
continue;
}
if (questions2Bool)
{
questions2List.Add(paragraph.Text);
continue;
}
if (questions1Bool)
{
questions1List.Add(paragraph.Text);
continue;
}
}
var faculty = arguments[0];
var group = arguments[1];
var subject = arguments[2];
var teacher = arguments[3];
var yearAndSemester = arguments[4];
var paperCount = Convert.ToInt32(arguments[5]);
for (int i = 0; i < paperCount; i++)
{
richEditControl.Document.AppendDocumentContent("QuestionPaperTemplate.docx");
if (i != paperCount - 1)
richEditControl.Document.AppendRtfText("{\\rtf1\\ansi \\page}");
richEditControl.Document.ReplaceAll("[PaperCount]", (i + 1).ToString(), DevExpress.XtraRichEdit.API.Native.SearchOptions.None);
richEditControl.Document.ReplaceAll("[Faculty]", faculty, DevExpress.XtraRichEdit.API.Native.SearchOptions.None);
richEditControl.Document.ReplaceAll("[Group]", group, DevExpress.XtraRichEdit.API.Native.SearchOptions.None);
richEditControl.Document.ReplaceAll("[Subject]", subject, DevExpress.XtraRichEdit.API.Native.SearchOptions.None);
richEditControl.Document.ReplaceAll("[Teacher]", teacher, DevExpress.XtraRichEdit.API.Native.SearchOptions.None);
richEditControl.Document.ReplaceAll("[YearAndSemester]", yearAndSemester, DevExpress.XtraRichEdit.API.Native.SearchOptions.None);
var random = new Random();
Func<List<string>, string> getRandomQuestion = (questionsList) =>
{
int randomIndex = random.Next(0, questionsList.Count);
return questionsList[randomIndex];
};
richEditControl.Document.ReplaceAll("[Question1]", getRandomQuestion(questions1List), DevExpress.XtraRichEdit.API.Native.SearchOptions.None);
richEditControl.Document.ReplaceAll("[Question2]", getRandomQuestion(questions2List), DevExpress.XtraRichEdit.API.Native.SearchOptions.None);
richEditControl.Document.ReplaceAll("[Question3]", getRandomQuestion(questions3List), DevExpress.XtraRichEdit.API.Native.SearchOptions.None);
richEditControl.Document.ReplaceAll("[Question4]", getRandomQuestion(questions4List), DevExpress.XtraRichEdit.API.Native.SearchOptions.None);
}
}
}
}