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