This repository has been archived by the owner on Oct 16, 2023. It is now read-only.
/
CustomizeExportControllerWin.cs
78 lines (73 loc) · 3.14 KB
/
CustomizeExportControllerWin.cs
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
using System;
using System.ComponentModel;
using System.Collections.Generic;
using System.Diagnostics;
using System.Text;
using DevExpress.ExpressApp;
using DevExpress.ExpressApp.Actions;
using DevExpress.Persistent.Base;
using DevExpress.ExpressApp.Win.SystemModule;
using DevExpress.ExpressApp.Win.Editors;
using DevExpress.ExpressApp.Win;
using System.Windows.Forms;
using System.IO;
using CustomizeExportAction.Module.Controllers;
using DevExpress.XtraGrid.Views.Grid;
namespace CustomizeExportAction.Module.Win.Controllers {
public partial class CustomizeExportControllerWin : CustomizeExportController {
private WinExportController winExportController;
protected override void OnActivated() {
base.OnActivated();
winExportController = Frame.GetController<WinExportController>();
winExportController.Exported += new EventHandler<DevExpress.ExpressApp.SystemModule.CustomExportEventArgs>(winExportController_Exported);
}
void winExportController_Exported(object sender, DevExpress.ExpressApp.SystemModule.CustomExportEventArgs e) {
if (e.Stream is FileStream) {
string fileName = ((FileStream)e.Stream).Name;
if (File.Exists(fileName)) {
e.Stream.Close();
if (WinApplication.Messaging.GetUserChoice("Open the exported file?",
GetMessageBoxCaption(), MessageBoxButtons.YesNo) == DialogResult.Yes)
Process.Start(fileName);
}
}
}
protected override void CustomExport(object sender, DevExpress.ExpressApp.SystemModule.CustomExportEventArgs e) {
base.CustomExport(sender, e);
//Show a message before exporting a Grid List Editor
GridListEditor gridListEditor =
((DevExpress.ExpressApp.ListView)View).Editor as GridListEditor;
if (gridListEditor != null) {
GridView gridView = gridListEditor.GridView;
if (HasCollapsedGroups(gridView)) {
string message =
"There are collapsed groups in the grid. Expand all groups in the exported file?";
gridView.OptionsPrint.ExpandAllGroups =
WinApplication.Messaging.GetUserChoice(message, GetMessageBoxCaption(),
MessageBoxButtons.YesNo)
== DialogResult.Yes;
}
}
}
private bool HasCollapsedGroups(GridView gridView) {
if (gridView.GroupCount > 0) {
int rowHandle = -1;
while (gridView.IsValidRowHandle(rowHandle)) {
if (!gridView.GetRowExpanded(rowHandle))
return true;
rowHandle--;
}
}
return false;
}
private string GetMessageBoxCaption() {
return String.Format(
"{0} {1}", winExportController.ExportAction.Caption,
winExportController.ExportAction.SelectedItem);
}
protected override void OnDeactivated() {
winExportController.Exported -= new EventHandler<DevExpress.ExpressApp.SystemModule.CustomExportEventArgs>(winExportController_Exported);
base.OnDeactivated();
}
}
}