-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathformDictionaries.pas
191 lines (172 loc) · 5.64 KB
/
formDictionaries.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
unit formDictionaries;
interface
uses
Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
Vcl.Controls, Vcl.Forms, Vcl.Dialogs, ClassSimpleForm, RzButton, Vcl.ExtCtrls,
RzPanel, dxGDIPlusClasses, cxGraphics, cxControls, cxLookAndFeels,
cxLookAndFeelPainters, cxStyles, cxCustomData, cxFilter, cxData,
cxDataStorage, cxEdit, cxNavigator, Data.DB, cxDBData, cxGridLevel,
cxGridCustomTableView, cxGridTableView, cxGridDBTableView, cxClasses,
cxGridCustomView, cxGrid, Vcl.ComCtrls, dxtree, dxdbtree;
type
TfrmDictionaries = class(TSimpleForm)
GridUserTypes: TcxGrid;
cxGridDBTableView1: TcxGridDBTableView;
cxGridDBColumn1: TcxGridDBColumn;
cxGridLevel1: TcxGridLevel;
pnlEdit: TRzPanel;
btnAdd: TRzBitBtn;
btnEdit: TRzBitBtn;
btnDel: TRzBitBtn;
cxStyleRepository1: TcxStyleRepository;
cxStyle1: TcxStyle;
GridProfs: TcxGrid;
cxGridDBTableView2: TcxGridDBTableView;
cxGridDBColumn2: TcxGridDBColumn;
cxGridLevel2: TcxGridLevel;
GridMaterials: TcxGrid;
cxGridDBTableView3: TcxGridDBTableView;
cxGridDBColumn3: TcxGridDBColumn;
cxGridLevel3: TcxGridLevel;
GridServices: TcxGrid;
cxGridDBTableView4: TcxGridDBTableView;
cxGridDBColumn4: TcxGridDBColumn;
cxGridLevel4: TcxGridLevel;
tvMaterials: TdxDBTreeView;
procedure GridUserTypesEnter(Sender: TObject);
procedure btnAddClick(Sender: TObject);
procedure FormShow(Sender: TObject);
procedure btnEditClick(Sender: TObject);
procedure btnDelClick(Sender: TObject);
procedure tvMaterialsEnter(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
frmDictionaries: TfrmDictionaries;
implementation
{$R *.dfm}
uses
DM_Main, ClassSimpleSprForm, ClassSimpleSprTypeForm, IBX.IBQuery, System.UITypes;
procedure TfrmDictionaries.btnAddClick(Sender: TObject);
var
data: TDataSet;
frm: TfrmSimpleSpr;
s: string;
parent, type_id, service_id, subtype_id: integer;
begin
data := TcxGridDBTableView(TcxGrid(pnlEdit.Tag).ActiveView).DataController.DataSet;
s := TcxGridDBTableView(TcxGrid(pnlEdit.Tag).ActiveView).Columns[0].Caption;
try
try
frm := TfrmSimpleSpr.Create(Self, s + ' [äîáàâëåíèå]');
frm.DS.DataSet := data;
if data = DM.DicMaterials then
begin
parent := DM.DicMaterials.FieldByName('parent').AsInteger;
type_id := DM.DicMaterials.FieldByName('type_id').AsInteger;
service_id := DM.DicMaterials.FieldByName('service_id').AsInteger;
subtype_id := DM.DicMaterials.FieldByName('subtype_id').AsInteger;
end;
data.Append;
if data = DM.DicMaterials then
begin
DM.DicMaterials.FieldByName('parent').AsInteger := parent;
DM.DicMaterials.FieldByName('type_id').AsInteger := type_id;
DM.DicMaterials.FieldByName('service_id').AsInteger := service_id;
DM.DicMaterials.FieldByName('subtype_id').AsInteger := subtype_id;
end;
frm.ShowModal;
if frm.ModalResult = mrOk then
begin
data.Post;
TIBQuery(data).ApplyUpdates;
if TIBQuery(data).Transaction.InTransaction then
TIBQuery(data).Transaction.CommitRetaining;
end
else
begin
data.Cancel;
TIBQuery(data).RevertRecord;
if TIBQuery(data).Transaction.InTransaction then
TIBQuery(data).Transaction.RollbackRetaining;
end;
except
data.Cancel;
TIBQuery(data).RevertRecord;
if TIBQuery(data).Transaction.InTransaction then
TIBQuery(data).Transaction.RollbackRetaining;
end;
finally
FreeAndNil(frm);
end;
end;
procedure TfrmDictionaries.btnDelClick(Sender: TObject);
var
data: TDataSet;
s: string;
begin
data := TcxGridDBTableView(TcxGrid(pnlEdit.Tag).ActiveView).DataController.DataSet;
s := TcxGridDBTableView(TcxGrid(pnlEdit.Tag).ActiveView).Columns[0].Caption;
if Application.MessageBox('Âû äåéñòâèòåëüíî õîòèòå óäàëèòü òåêóùóþ çàïèñü?', 'Ïîäòâåðæäåíèå',
MB_ICONQUESTION + MB_YESNO) <> mrYes then
Exit;
data.Delete;
TIBQuery(data).ApplyUpdates;
if TIBQuery(data).Transaction.InTransaction then
TIBQuery(data).Transaction.CommitRetaining;
end;
procedure TfrmDictionaries.btnEditClick(Sender: TObject);
var
data: TDataSet;
frm: TfrmSimpleSpr;
s: string;
begin
data := TcxGridDBTableView(TcxGrid(pnlEdit.Tag).ActiveView).DataController.DataSet;
s := TcxGridDBTableView(TcxGrid(pnlEdit.Tag).ActiveView).Columns[0].Caption;
try
try
frm := TfrmSimpleSpr.Create(Self, s + ' [èçìåíåíèå]');
frm.DS.DataSet := data;
data.Edit;
frm.ShowModal;
if frm.ModalResult = mrOk then
begin
data.Post;
TIBQuery(data).ApplyUpdates;
if TIBQuery(data).Transaction.InTransaction then
TIBQuery(data).Transaction.CommitRetaining;
end
else
begin
data.Cancel;
TIBQuery(data).RevertRecord;
if TIBQuery(data).Transaction.InTransaction then
TIBQuery(data).Transaction.RollbackRetaining;
end;
except
data.Cancel;
TIBQuery(data).RevertRecord;
if TIBQuery(data).Transaction.InTransaction then
TIBQuery(data).Transaction.RollbackRetaining;
end;
finally
FreeAndNil(frm);
end;
end;
procedure TfrmDictionaries.FormShow(Sender: TObject);
begin
GridUserTypes.SetFocus;
end;
procedure TfrmDictionaries.GridUserTypesEnter(Sender: TObject);
begin
pnlEdit.Left := TcxGrid(Sender).Left;
pnlEdit.Tag := Integer(TcxGrid(Sender));
end;
procedure TfrmDictionaries.tvMaterialsEnter(Sender: TObject);
begin
GridUserTypesEnter(GridMaterials);
end;
end.