-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathfixlinkedvaluesfrm.pas
117 lines (99 loc) · 3.43 KB
/
fixlinkedvaluesfrm.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
unit FixLinkedValuesFrm;
{$mode delphi}
interface
uses
Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, Buttons,
StdCtrls, DBGrids, db;
type
{ TFixLinkedValuesForm }
TFixLinkedValuesForm = class(TForm)
SearchBtn: TButton;
SearchEdt: TEdit;
ReplaceAllValuesBtn: TButton;
SaveNewValueBtn: TButton;
CloseBtn: TBitBtn;
DBGrid1: TDBGrid;
WrongValueEdt: TEdit;
LinkedColumnEdt: TEdit;
LinkedTableEdt: TEdit;
procedure FormShow(Sender: TObject);
procedure ReplaceAllValuesBtnClick(Sender: TObject);
procedure SaveNewValueBtnClick(Sender: TObject);
procedure SearchBtnClick(Sender: TObject);
private
public
end;
var
FixLinkedValuesForm: TFixLinkedValuesForm;
implementation
uses MainFrm, datafrm;
{$R *.lfm}
{ TFixLinkedValuesForm }
procedure TFixLinkedValuesForm.FormShow(Sender: TObject);
var
I: integer;
Found: boolean;
begin
Found := false;
for I := 0 to MainForm.SharedSetupGrid.RowCount - 1 do
begin
If MainForm.SharedSetupGrid.Cells[1,I] = MainForm.CSVGridSelectedField.FieldName then
begin
LinkedTableEdt.Text := MainForm.SharedSetupGrid.Cells[3,I];
LinkedColumnEdt.Text := MainForm.SharedSetupGrid.Cells[4,I];
WrongValueEdt.Text := MainForm.CSVGridSelectedField.Text;
Dataform.FromQuery1.Close;
with Dataform.FromQuery1.SQL do
begin
Clear;
Add('select ' + MainForm.SharedSetupGrid.Cells[4,I] + ' from ' + MainForm.SharedSetupGrid.Cells[3,I]);
Add('order by ' + MainForm.SharedSetupGrid.Cells[4,I]);
end;
try
Dataform.FromQuery1.Open;
except
on E : Exception do
begin
ShowMessage(E.ClassName + ' ' + E.Message + ' Error in getting link table rows');
exit;
end;
end;
Found := true;
end;
end;
end;
procedure TFixLinkedValuesForm.ReplaceAllValuesBtnClick(Sender: TObject);
begin
if MessageDlg('Question', 'Do you want to replace all wrong values in column?', mtConfirmation,
[mbYes, mbNo],0) = mrYes
then
begin
Dataform.CSVDataset.First;
Dataform.CSVDataset.DisableControls;
while not Dataform.CSVDataset.EOF do
begin
if Dataform.CSVDataSet.FieldByName(MainForm.CSVGridSelectedField.FieldName).asString = WrongValueEdt.Text then
begin
Dataform.CSVDataSet.Edit;
Dataform.CSVDataSet.FieldByName(MainForm.CSVGridSelectedField.FieldName).asString := Dataform.FromQuery1.FieldByName(LinkedColumnEdt.Text).asString;
Dataform.CSVDataSet.Post;
end;
Dataform.CSVDataset.Next;
end;
Dataform.CSVDataset.EnableControls;
Close;
end;
end;
procedure TFixLinkedValuesForm.SaveNewValueBtnClick(Sender: TObject);
begin
Dataform.CSVDataSet.Edit;
Dataform.CSVDataSet.FieldByName(MainForm.CSVGridSelectedField.FieldName).asString := Dataform.FromQuery1.FieldByName(LinkedColumnEdt.Text).asString;
Dataform.CSVDataSet.Post;
Close;
end;
procedure TFixLinkedValuesForm.SearchBtnClick(Sender: TObject);
begin
//or using [loCaseInsensitive,loPartialKey] options
Dataform.FromQuery1.Locate(LinkedColumnEdt.Text, SearchEdt.Text, [loCaseInsensitive,loPartialKey]);
end;
end.