Skip to content

Commit bffee08

Browse files
committed
draft
1 parent eb23b42 commit bffee08

10 files changed

Lines changed: 292 additions & 30 deletions

Delphi/StoreReportInDB.res

-123 KB
Binary file not shown.

Delphi/example.dat

24.5 KB
Binary file not shown.

Delphi/uMainForm.dfm

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ object MainForm: TMainForm
1111
Font.Height = -12
1212
Font.Name = 'Segoe UI'
1313
Font.Style = []
14+
OnCreate = FormCreate
1415
TextHeight = 15
1516
object dxLayoutControl1: TdxLayoutControl
1617
Left = 0
@@ -44,6 +45,8 @@ object MainForm: TMainForm
4445
Height = 133
4546
TabOrder = 3
4647
object gvLayouts: TcxGridDBTableView
48+
OnEditValueChanged = gvLayoutsEditValueChanged
49+
OnFocusedItemChanged = gvLayoutsFocusedItemChanged
4750
DataController.DataSource = DataModule1.dsLayouts
4851
OptionsData.CancelOnExit = False
4952
OptionsData.Deleting = False

Delphi/uMainForm.pas

Lines changed: 65 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@ interface
99
cxStyles, Data.DB, cxDBData, dxLayoutControlAdapters,
1010
dxLayoutContainer, dxReport, cxGridLevel, cxGridCustomTableView,
1111
cxGridTableView, cxGridDBTableView, cxClasses, cxGridCustomView, cxGrid,
12-
cxButtons, dxLayoutControl;
12+
cxButtons, dxLayoutControl, cxCustomData, cxFilter, cxData, cxDataStorage,
13+
cxEdit, cxNavigator, dxDateRanges, dxScrollbarAnnotations, uData;
1314

1415
type
1516
TMainForm = class(TForm)
@@ -29,11 +30,18 @@ TMainForm = class(TForm)
2930
liShowDesigner: TdxLayoutItem;
3031
liViewReport: TdxLayoutItem;
3132
liGrid: TdxLayoutItem;
33+
procedure FormCreate(Sender: TObject);
3234
procedure btnDesignClick(Sender: TObject);
3335
procedure btnPreviewClick(Sender: TObject);
3436
procedure btnNewClick(Sender: TObject);
3537
procedure dxReport1LayoutChanged(ASender: TdxReport);
38+
procedure gvLayoutsEditValueChanged(Sender: TcxCustomGridTableView; AItem:
39+
TcxCustomGridTableItem);
40+
procedure gvLayoutsFocusedItemChanged(Sender: TcxCustomGridTableView;
41+
APrevFocusedItem, AFocusedItem: TcxCustomGridTableItem);
3642
private
43+
procedure LoadReportNameAndLayout;
44+
procedure SaveReportNameAndLayout;
3745
{ Private declarations }
3846
public
3947
{ Public declarations }
@@ -46,45 +54,85 @@ implementation
4654

4755
{$R *.dfm}
4856

49-
uses uData;
57+
procedure TMainForm.LoadReportNameAndLayout();
58+
begin
59+
if (DataModule1.mdLayouts.RecordCount = 0) and not (DataModule1.mdLayouts.State = dsInsert) then
60+
begin
61+
ShowMessage('The database is empty');
62+
Exit;
63+
end;
64+
// Load the report name from the database
65+
dxReport1.ReportName := DataModule1.mdLayoutsName.AsString;
66+
// Load the report layout from the database
67+
dxReport1.Layout.Assign(DataModule1.mdLayoutsLayout);
68+
end;
69+
70+
procedure TMainForm.SaveReportNameAndLayout();
71+
begin
72+
// Start editing the active dataset record
73+
DataModule1.mdLayouts.Edit;
74+
// Save the report name
75+
DataModule1.mdLayoutsName.AsString := dxReport1.ReportName;
76+
// Save the report layout
77+
DataModule1.mdLayoutsLayout.Assign(dxReport1.Layout);
78+
// Finish editing and write a modified record
79+
DataModule1.mdLayouts.Post;
80+
end;
81+
82+
// Handle the OnFormCreate event called when the application starts
83+
procedure TMainForm.FormCreate(Sender: TObject);
84+
begin
85+
LoadReportNameAndLayout;
86+
end;
87+
88+
// Handle the OnLayoutChanged event called when a user saves a report layout in the Report Designer
89+
procedure TMainForm.dxReport1LayoutChanged(ASender: TdxReport);
90+
begin
91+
SaveReportNameAndLayout;
92+
end;
93+
94+
// Handle the OnFocusedItemChanged event called when a user selects a different row
95+
// in the Grid Table View
96+
procedure TMainForm.gvLayoutsFocusedItemChanged(Sender: TcxCustomGridTableView;
97+
APrevFocusedItem, AFocusedItem: TcxCustomGridTableItem);
98+
begin
99+
LoadReportNameAndLayout;
100+
end;
50101

102+
// Handle the OnEditValueChanged event called when a user edits the layout name
103+
// in the Grid Table View
104+
procedure TMainForm.gvLayoutsEditValueChanged(Sender: TcxCustomGridTableView;
105+
AItem: TcxCustomGridTableItem);
106+
begin
107+
LoadReportNameAndLayout;
108+
end;
51109

110+
// To create a new report layout, create a new dataset record
52111
procedure TMainForm.btnNewClick(Sender: TObject);
53112
begin
54113
DataModule1.mdLayouts.Append
55114
end;
56115

57116
procedure TMainForm.btnDesignClick(Sender: TObject);
58117
begin
59-
if (DataModule1.mdLayouts.RecordCount = 0) and not (DataModule1.mdLayouts.State = dsInsert) then
118+
if (dxReport1.ReportName = '') then
60119
begin
61-
ShowMessage('The database is empty');
120+
ShowMessage('The report is not specified');
62121
Exit;
63122
end;
64-
dxReport1.ReportName := DataModule1.mdLayoutsName.AsString;
65-
dxReport1.Layout.Assign(DataModule1.mdLayoutsLayout);
66123
dxReport1.ShowDesigner;
67124
end;
68125

69126
procedure TMainForm.btnPreviewClick(Sender: TObject);
70127
begin
71-
if (DataModule1.mdLayoutsName.AsString = '') then
128+
if (dxReport1.ReportName = '') then
72129
begin
73130
ShowMessage('The report is not specified');
74131
Exit;
75132
end;
76-
77-
dxReport1.ReportName := DataModule1.mdLayoutsName.AsString;
78-
dxReport1.Layout.Assign(DataModule1.mdLayoutsLayout);
79133
dxReport1.ShowViewer;
80134
end;
81135

82-
procedure TMainForm.dxReport1LayoutChanged(ASender: TdxReport);
83-
begin
84-
DataModule1.mdLayouts.Edit;
85-
DataModule1.mdLayoutsLayout.Assign(dxReport1.Layout);
86-
DataModule1.mdLayoutsName.AsString := dxReport1.ReportName;
87-
DataModule1.mdLayouts.Post;
88-
end;
136+
89137

90138
end.

0 commit comments

Comments
 (0)