DeVexpress XTRAREPORT 보고서 설계를 직렬화하려면 어떻게해야합니까?
-
10-07-2019 - |
문제
보고서 설계를 직렬화해야합니다. 이것이 시나리오입니다.
이 앱에는 기본 보고서가 있습니다. Corp와 같은 사전 정의 된 열과 디자인 세트가 포함 된 "판매 보고서"라고 가정 해 봅시다. 헤더에 로고. 사용자는 예를 들어 사무실 주소가있는 바닥 글 또는 페이지 번호와 같은 레이아웃 추가를 변경할 수 있어야합니다. 이를 위해서는 보고서를 편집해야합니다. 디자이너를 입력하고 필요한 것을 추가/변경하십시오. 이 변경된 보고서 레이아웃은 해당 사용자의 데이터베이스에 저장되도록 직렬화되어야하므로 다음에 사용자는 해당 디자인을 사용하여 해당 보고서를 열어줍니다.
말이된다?
해결책
다음은 내가 수행하는 방법의 단순화 된 버전입니다.
XtraReport customReport;
customReport = new MyXtraReport();
byte[] layout = LoadCustomLayoutFromDB();
if (layout != null) {
using (System.IO.MemoryStream memoryStream = new System.IO.MemoryStream(layout)) {
customReport.LoadLayout(memoryStream);
}
}
using (XRDesignFormEx designer = new XRDesignFormEx()) {
MySaveCommandHandler customCommands = new MySaveCommandHandler(designer.DesignPanel);
designer.DesignPanel.AddCommandHandler(customCommands);
designer.OpenReport(customReport);
designer.ShowDialog(this);
if (customCommands.ChangesSaved)
SaveCustomLayoutToDB(customCommands.Layout);
}
MySaveCommandhandler 클래스 내부 :
public virtual void HandleCommand(ReportCommand command, object[] args, ref bool handled) {
if (command != ReportCommand.SaveFileAs && command != ReportCommand.SaveFileAs)
return;
using (System.IO.MemoryStream memoryStream = new System.IO.MemoryStream()) {
panel.Report.SaveLayout(memoryStream);
this.layout = memoryStream.ToArray();
changesSaved = true;
}
panel.ReportState = ReportState.Saved;
handled = true;
}
다른 팁
나는 당신이 찾고있는 것이 Savelayout 방법이라고 생각합니다.
보고서 저장
YourReport report = new YourReport();
// Save the layout to a file.
report.SaveLayout(@"C:\YourReport.repx");
보고서로드
YourReport report = new YourReport();
// Load the layout
report.LoadLayout(@"C:\YourReport.repx");
편집하다:
여기에 링크 보고서 정의를 저장하는 방법을 설명하는 DeVexpress 지원 사이트에.
Save 및 LoadLayout Override를 사용하여 스트림에 저장/로드 할 수 있습니다. 디자이너의 경우 명령 핸들러를 추가하여 저장 명령을 가로 채 릴 수 있습니다.
이 기사는 필요한 것을 다루어야합니다.
방법 : 최종 사용자 디자이너의 명령을 재정의합니다 (사용자 정의 저장)
그리고 완전성을 위해 : 모든 방법 목록
편집 : 고정 링크
제휴하지 않습니다 StackOverflow