@@ -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;
1314
1415type
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 }
@@ -48,43 +56,85 @@ implementation
4856
4957uses uData;
5058
59+ procedure TMainForm.LoadReportNameAndLayout ();
60+ begin
61+ if (DataModule1.mdLayouts.RecordCount = 0 ) and not (DataModule1.mdLayouts.State = dsInsert) then
62+ begin
63+ ShowMessage(' The database is empty' );
64+ Exit;
65+ end ;
66+ // Load the report name from the database
67+ dxReport1.ReportName := DataModule1.mdLayoutsName.AsString;
68+ // Load the report layout from the database
69+ dxReport1.Layout.Assign(DataModule1.mdLayoutsLayout);
70+ end ;
71+
72+ procedure TMainForm.SaveReportNameAndLayout ();
73+ begin
74+ // Start editing the active dataset record
75+ DataModule1.mdLayouts.Edit;
76+ // Save the report name
77+ DataModule1.mdLayoutsName.AsString := dxReport1.ReportName;
78+ // Save the report layout
79+ DataModule1.mdLayoutsLayout.Assign(dxReport1.Layout);
80+ // Finish editing and write a modified record
81+ DataModule1.mdLayouts.Post;
82+ end ;
83+
84+ // Handle the OnFormCreate event called when the application starts
85+ procedure TMainForm.FormCreate (Sender: TObject);
86+ begin
87+ LoadReportNameAndLayout;
88+ end ;
89+
90+ // Handle the OnLayoutChanged event called when a user saves a report layout in the Report Designer
91+ procedure TMainForm.dxReport1LayoutChanged (ASender: TdxReport);
92+ begin
93+ SaveReportNameAndLayout;
94+ end ;
5195
96+ // Handle the OnFocusedItemChanged event called when a user selects a different row
97+ // in the Grid Table View
98+ procedure TMainForm.gvLayoutsFocusedItemChanged (Sender: TcxCustomGridTableView;
99+ APrevFocusedItem, AFocusedItem: TcxCustomGridTableItem);
100+ begin
101+ LoadReportNameAndLayout;
102+ end ;
103+
104+ // Handle the OnEditValueChanged event called when a user edits the layout name
105+ // in the Grid Table View
106+ procedure TMainForm.gvLayoutsEditValueChanged (Sender: TcxCustomGridTableView;
107+ AItem: TcxCustomGridTableItem);
108+ begin
109+ LoadReportNameAndLayout;
110+ end ;
111+
112+ // To create a new report layout, create a new dataset record
52113procedure TMainForm.btnNewClick (Sender: TObject);
53114begin
54115 DataModule1.mdLayouts.Append
55116end ;
56117
57118procedure TMainForm.btnDesignClick (Sender: TObject);
58119begin
59- if (DataModule1.mdLayouts.RecordCount = 0 ) and not (DataModule1.mdLayouts.State = dsInsert) then
120+ if (dxReport1.ReportName = ' ' ) then
60121 begin
61- ShowMessage(' The database is empty ' );
122+ ShowMessage(' The report is not specified ' );
62123 Exit;
63124 end ;
64- dxReport1.ReportName := DataModule1.mdLayoutsName.AsString;
65- dxReport1.Layout.Assign(DataModule1.mdLayoutsLayout);
66125 dxReport1.ShowDesigner;
67126end ;
68127
69128procedure TMainForm.btnPreviewClick (Sender: TObject);
70129begin
71- if (DataModule1.mdLayoutsName.AsString = ' ' ) then
130+ if (dxReport1.ReportName = ' ' ) then
72131 begin
73132 ShowMessage(' The report is not specified' );
74133 Exit;
75134 end ;
76-
77- dxReport1.ReportName := DataModule1.mdLayoutsName.AsString;
78- dxReport1.Layout.Assign(DataModule1.mdLayoutsLayout);
79135 dxReport1.ShowViewer;
80136end ;
81137
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 ;
138+
89139
90140end .
0 commit comments