-
Notifications
You must be signed in to change notification settings - Fork 0
/
LoadFm.pas
226 lines (185 loc) · 5.24 KB
/
LoadFm.pas
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
unit LoadFm;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, Grids, ValEdit, Spin, StdCtrls, ExtCtrls, TabFunctions, OutputPlus;
type
TOpenTabFm = class(TForm)
Button1: TButton;
Button2: TButton;
StringGrid1: TStringGrid;
SepG: TRadioGroup;
Edit1: TEdit;
ValueList: TValueListEditor;
Label1: TLabel;
SpinEdit1: TSpinEdit;
Label2: TLabel;
procedure ValueListKeyUp(Sender: TObject; var Key: Word;
Shift: TShiftState);
procedure SepGClick(Sender: TObject);
procedure FormShow(Sender: TObject);
procedure RefreshRes;
procedure FormCreate(Sender: TObject);
procedure FormDestroy(Sender: TObject);
procedure Edit1Change(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure OpenTable(SG:TStringGrid);
procedure Button1Click(Sender: TObject);
procedure SpinEdit1Change(Sender: TObject);
procedure StringGrid1DrawCell(Sender: TObject; ACol, ARow: Integer;
Rect: TRect; State: TGridDrawState);
private
{ Private declarations }
public
isLeftTab :Boolean;
FileToLoad :String;
{ Public declarations }
end;
var
OpenTabFm: TOpenTabFm;
S: TStringList;
implementation
uses LocFm, MainForm;
{$R *.dfm}
procedure TOpenTabFm.ValueListKeyUp(Sender: TObject; var Key: Word;
Shift: TShiftState);
begin
RefreshRes;
end;
procedure TOpenTabFm.SepGClick(Sender: TObject);
begin
Edit1.Visible := SepG.ItemIndex = 2;
RefreshRes;
end;
procedure TOpenTabFm.FormShow(Sender: TObject);
var I :integer;
begin
for I := 1 To 4 Do
case isLeftTab of
true:
begin
ValueList.Keys[I] := LocForm.StringGrid1.Cells[I-1,0];
StringGrid1.Cells[I-1,0] := LocForm.StringGrid1.Cells[I-1,0];
end;
false:
begin
ValueList.Keys[I] := LocForm.StringGrid2.Cells[I-1,0];
StringGrid1.Cells[I-1,0] := LocForm.StringGrid2.Cells[I-1,0];
end;
end;
SetCurrentDir(Form1.MyDir);
if Pos('xls', AnsiLowerCase(ExtractFileExt(FileToLoad))) > 0 then
begin
Form1.XlsToTXT(FileToLoad);
FileToLoad := 'Data\Temp.txt';
SepG.ItemIndex :=1;
end;
S.LoadFromFile(FileToLoad);
RefreshRes;
end;
procedure ClearGrid(StringGrid: TStringGrid);
var i, j: Integer;
begin
with StringGrid do
begin
for i:=1 to RowCount-1 do
for j:=0 to ColCount-1 do
Cells[j, i]:='';
StringGrid.RowCount := 2;
end;
end;
procedure TOpenTabFm.RefreshRes;
var i, j, CoordType : integer;
Sep : Char;
begin
try
ClearGrid(StringGrid1);
for i:= SpinEdit1.Value-1 to S.count-1 do
Begin
if i<0 then
continue;
if i > 3 + (SpinEdit1.Value-1) then exit;
with StringGrid1 do
RowCount := 5;
if StringGrid1.RowCount > 1 then
StringGrid1.FixedRows := 1;
sep:=' ';
case SepG.ItemIndex of
0: sep:=' ';
1: sep:=#$9;
2: if Edit1.Text<> '' then sep := Edit1.Text[1];
3: sep:=';';
4: sep:=',';
end;
StringGrid1.Cells[0,i+1-(SpinEdit1.Value-1)] := GetCols(s[i], StrToInt(ValueList.Cells[1,1])-1, 1, sep, false);
StringGrid1.Cells[1,i+1-(SpinEdit1.Value-1)] := GetCols(s[i], StrToInt(ValueList.Cells[1,2])-1, 1, sep, true);
StringGrid1.Cells[2,i+1-(SpinEdit1.Value-1)] := GetCols(s[i], StrToInt(ValueList.Cells[1,3])-1, 1, sep, true);
StringGrid1.Cells[3,i+1-(SpinEdit1.Value-1)] := GetCols(s[i], StrToInt(ValueList.Cells[1,4])-1, 1, sep, true);
end;
except
end;
end;
procedure TOpenTabFm.FormCreate(Sender: TObject);
begin
S := TStringList.Create;
end;
procedure TOpenTabFm.FormDestroy(Sender: TObject);
begin
S.Free
end;
procedure TOpenTabFm.Edit1Change(Sender: TObject);
begin
SepG.ItemIndex := 2;
end;
procedure TOpenTabFm.Button2Click(Sender: TObject);
begin
close;
end;
procedure TOpenTabFm.OpenTable(SG:TStringGrid);
var i, j, CoordType : integer;
Sep : Char;
begin
try
ClearGrid(SG);
for i:= SpinEdit1.Value-1 to S.count-1 do
Begin
if i<0 then
continue;
with SG do
RowCount := i + 2 - (SpinEdit1.Value-1);
if SG.RowCount > 1 then
SG.FixedRows := 1;
sep:=' ';
case SepG.ItemIndex of
0: sep:=' ';
1: sep:=#$9;
2: if Edit1.Text<> '' then sep := Edit1.Text[1];
3: sep:=';';
4: sep:=',';
end;
SG.Cells[0,i+1-(SpinEdit1.Value-1)] := GetCols(s[i], StrToInt(ValueList.Cells[1,1])-1, 1, sep, false);
SG.Cells[1,i+1-(SpinEdit1.Value-1)] := GetCols(s[i], StrToInt(ValueList.Cells[1,2])-1, 1, sep, true);
SG.Cells[2,i+1-(SpinEdit1.Value-1)] := GetCols(s[i], StrToInt(ValueList.Cells[1,3])-1, 1, sep, true);
SG.Cells[3,i+1-(SpinEdit1.Value-1)] := GetCols(s[i], StrToInt(ValueList.Cells[1,4])-1, 1, sep, true);
end;
except
end;
end;
procedure TOpenTabFm.Button1Click(Sender: TObject);
begin
case isLeftTab of
true: OpenTable(LocForm.StringGrid1);
false: OpenTable(LocForm.StringGrid2);
end;
close;
end;
procedure TOpenTabFm.SpinEdit1Change(Sender: TObject);
begin
RefreshRes;
end;
procedure TOpenTabFm.StringGrid1DrawCell(Sender: TObject; ACol,
ARow: Integer; Rect: TRect; State: TGridDrawState);
begin
DrawCellPlus(StringGrid1, ACol, ARow, Rect, State, 1);
end;
end.