source: trunk/Forms/FormExport.pas

Last change on this file was 227, checked in by chronos, 44 hours ago
  • Modified: Do not reference global Core object if possible.
File size: 3.6 KB
Line 
1unit FormExport;
2
3interface
4
5uses
6 Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, StdCtrls,
7 JobProgressView, FormEx, Acronym;
8
9type
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
34implementation
35
36{$R *.lfm}
37
38resourcestring
39 SExportedAcronyms = 'Exported %d acronyms';
40 SExporting = 'Exporting';
41
42{ TFormExport }
43
44procedure TFormExport.ButtonSaveToFileClick(Sender: TObject);
45begin
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;
52end;
53
54procedure TFormExport.JobExportCSV(Job: TJob);
55var
56 I: Integer;
57 J: Integer;
58begin
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;
72end;
73
74procedure TFormExport.JobExportMediaWiki(Job: TJob);
75var
76 I: Integer;
77 J: Integer;
78begin
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;
93end;
94
95procedure TFormExport.JobExportMediaWikiTable(Job: TJob);
96var
97 I: Integer;
98 J: Integer;
99begin
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;
117end;
118
119procedure TFormExport.ButtonProcessClick(Sender: TObject);
120begin
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]));
130end;
131
132end.
133
Note: See TracBrowser for help on using the repository browser.