@@ -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
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 }
@@ -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
52111procedure TMainForm.btnNewClick (Sender: TObject);
53112begin
54113 DataModule1.mdLayouts.Append
55114end ;
56115
57116procedure TMainForm.btnDesignClick (Sender: TObject);
58117begin
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;
67124end ;
68125
69126procedure TMainForm.btnPreviewClick (Sender: TObject);
70127begin
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;
80134end ;
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
90138end .
0 commit comments