1 | unit FormExport;
|
---|
2 |
|
---|
3 | interface
|
---|
4 |
|
---|
5 | uses
|
---|
6 | Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, StdCtrls,
|
---|
7 | JobProgressView, FormEx, Acronym;
|
---|
8 |
|
---|
9 | type
|
---|
10 |
|
---|
11 | { TFormExport }
|
---|
12 |
|
---|
13 | TFormExport = class(TFormEx)
|
---|
14 | ButtonProcess: TButton;
|
---|
15 | ButtonSaveToFile: TButton;
|
---|
16 | ComboBoxDataFormat: TComboBox;
|
---|
17 | JobProgressView1: TJobProgressView;
|
---|
18 | Label1: TLabel;
|
---|
19 | Memo1: TMemo;
|
---|
20 | SaveDialog1: TSaveDialog;
|
---|
21 | procedure ButtonProcessClick(Sender: TObject);
|
---|
22 | procedure ButtonSaveToFileClick(Sender: TObject);
|
---|
23 | private
|
---|
24 | ItemCount: Integer;
|
---|
25 | Content: string;
|
---|
26 | procedure JobExportCSV(Job: TJob);
|
---|
27 | procedure JobExportMediaWiki(Job: TJob);
|
---|
28 | procedure JobExportMediaWikiTable(Job: TJob);
|
---|
29 | public
|
---|
30 | AcronymDb: TAcronymDb;
|
---|
31 | end;
|
---|
32 |
|
---|
33 |
|
---|
34 | implementation
|
---|
35 |
|
---|
36 | {$R *.lfm}
|
---|
37 |
|
---|
38 | resourcestring
|
---|
39 | SExportedAcronyms = 'Exported %d acronyms';
|
---|
40 | SExporting = 'Exporting';
|
---|
41 |
|
---|
42 | { TFormExport }
|
---|
43 |
|
---|
44 | procedure TFormExport.ButtonSaveToFileClick(Sender: TObject);
|
---|
45 | begin
|
---|
46 | if ComboBoxDataFormat.ItemIndex = 0 then SaveDialog1.DefaultExt := '.csv';
|
---|
47 | if ComboBoxDataFormat.ItemIndex = 1 then SaveDialog1.DefaultExt := '.txt';
|
---|
48 | if ComboBoxDataFormat.ItemIndex = 2 then SaveDialog1.DefaultExt := '.txt';
|
---|
49 | if SaveDialog1.Execute then begin
|
---|
50 | Memo1.Lines.SaveToFile(SaveDialog1.FileName);
|
---|
51 | end;
|
---|
52 | end;
|
---|
53 |
|
---|
54 | procedure TFormExport.JobExportCSV(Job: TJob);
|
---|
55 | var
|
---|
56 | I: Integer;
|
---|
57 | J: Integer;
|
---|
58 | begin
|
---|
59 | Job.Progress.Max := AcronymDb.Acronyms.Count;
|
---|
60 | ItemCount := 0;
|
---|
61 | Content := '';
|
---|
62 | for I := 0 to AcronymDb.Acronyms.Count - 1 do
|
---|
63 | with AcronymDb.Acronyms[I] do begin
|
---|
64 | for J := 0 to Meanings.Count - 1 do
|
---|
65 | with Meanings[J] do begin
|
---|
66 | Content := Content + '"' + Acronym.Name + '","' + Name + '","' + Description + '","' + Categories.GetString + '"' + LineEnding;
|
---|
67 | Inc(ItemCount);
|
---|
68 | end;
|
---|
69 | Job.Progress.Increment;
|
---|
70 | if Job.Terminate then Break;
|
---|
71 | end;
|
---|
72 | end;
|
---|
73 |
|
---|
74 | procedure TFormExport.JobExportMediaWiki(Job: TJob);
|
---|
75 | var
|
---|
76 | I: Integer;
|
---|
77 | J: Integer;
|
---|
78 | begin
|
---|
79 | Job.Progress.Max := AcronymDb.Acronyms.Count;
|
---|
80 | ItemCount := 0;
|
---|
81 | Content := '';
|
---|
82 | for I := 0 to AcronymDb.Acronyms.Count - 1 do
|
---|
83 | with AcronymDb.Acronyms[I] do begin
|
---|
84 | Content := Content + '; ' + Name + LineEnding;
|
---|
85 | for J := 0 to Meanings.Count - 1 do
|
---|
86 | with Meanings[J] do begin
|
---|
87 | Content := Content + ': ' + Name + LineEnding;
|
---|
88 | Inc(ItemCount);
|
---|
89 | end;
|
---|
90 | Job.Progress.Increment;
|
---|
91 | if Job.Terminate then Break;
|
---|
92 | end;
|
---|
93 | end;
|
---|
94 |
|
---|
95 | procedure TFormExport.JobExportMediaWikiTable(Job: TJob);
|
---|
96 | var
|
---|
97 | I: Integer;
|
---|
98 | J: Integer;
|
---|
99 | begin
|
---|
100 | Job.Progress.Max := AcronymDb.Acronyms.Count;
|
---|
101 | ItemCount := 0;
|
---|
102 | Content := '{| class="wikitable sortable"' + LineEnding +
|
---|
103 | '! Name !! Meaning !! Description !! Categories' + LineEnding;
|
---|
104 | for I := 0 to AcronymDb.Acronyms.Count - 1 do
|
---|
105 | with AcronymDb.Acronyms[I] do begin
|
---|
106 | for J := 0 to Meanings.Count - 1 do
|
---|
107 | with Meanings[J] do begin
|
---|
108 | Content := Content + '|-' + LineEnding +
|
---|
109 | '| ' + Acronym.Name + LineEnding + '| ' + Name + LineEnding +
|
---|
110 | '| ' + Description + LineEnding + '| ' + Categories.GetString + LineEnding;
|
---|
111 | Inc(ItemCount);
|
---|
112 | end;
|
---|
113 | Job.Progress.Increment;
|
---|
114 | if Job.Terminate then Break;
|
---|
115 | end;
|
---|
116 | Content := Content + '|}' + LineEnding;
|
---|
117 | end;
|
---|
118 |
|
---|
119 | procedure TFormExport.ButtonProcessClick(Sender: TObject);
|
---|
120 | begin
|
---|
121 | if ComboBoxDataFormat.ItemIndex = 0 then
|
---|
122 | JobProgressView1.AddJob(SExporting, JobExportCSV);
|
---|
123 | if ComboBoxDataFormat.ItemIndex = 1 then
|
---|
124 | JobProgressView1.AddJob(SExporting, JobExportMediaWiki);
|
---|
125 | if ComboBoxDataFormat.ItemIndex = 2 then
|
---|
126 | JobProgressView1.AddJob(SExporting, JobExportMediaWikiTable);
|
---|
127 | JobProgressView1.Start;
|
---|
128 | Memo1.Lines.Text := Content;
|
---|
129 | ShowMessage(Format(SExportedAcronyms, [ItemCount]));
|
---|
130 | end;
|
---|
131 |
|
---|
132 | end.
|
---|
133 |
|
---|