-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathMasterDetailHelper.cs
More file actions
146 lines (128 loc) · 4.84 KB
/
MasterDetailHelper.cs
File metadata and controls
146 lines (128 loc) · 4.84 KB
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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
using System;
using System.Collections.Generic;
using System.Text;
using DevExpress.XtraGrid.Views.Base;
using DevExpress.XtraGrid;
using DevExpress.XtraGrid.Columns;
using DevExpress.XtraEditors.Repository;
using DevExpress.XtraEditors;
using System.Collections;
using DevExpress.XtraGrid.Views.Card;
using DevExpress.XtraGrid.Views.Grid;
using DevExpress.XtraGrid.Views.Layout;
using DevExpress.XtraGrid.Views.Base.ViewInfo;
using System.Drawing;
using System.Windows.Forms;
using DevExpress.XtraGrid.Views.Grid.ViewInfo;
using DevExpress.Utils.Win;
using DevExpress.XtraEditors.Popup;
namespace WindowsApplication3 {
public enum ViewType { Grid, Layout, Card }
public class MasterDetailHelper {
ColumnView view, detailView;
ViewType viewType;
GridControl detailGrid;
public MasterDetailHelper(ColumnView view, ViewType viewType) {
this.view = view;
this.viewType = viewType;
}
public GridControl DetailGrid {
get {
if(detailGrid == null) {
detailGrid = CreateGrid();
detailGrid.MainView = DetailView;
}
return detailGrid;
}
}
public ColumnView DetailView {
get {
if(detailView == null)
detailView = CreateView();
return detailView;
}
}
public ViewType ViewType {
get { return viewType; }
set {
if(viewType != value) {
viewType = value;
detailView = null;
DetailGrid.MainView = DetailView;
}
}
}
public void CreateDetail() {
SetColumnEdit(CreateColumn());
}
private GridControl CreateGrid() {
GridControl grid = new GridControl();
grid.Dock = System.Windows.Forms.DockStyle.Fill;
return grid;
}
private ColumnView CreateView() {
if(viewType == ViewType.Card)
detailView = new CardView(DetailGrid);
else if(viewType == ViewType.Grid) {
detailView = new GridView(DetailGrid);
((GridView)detailView).OptionsView.ShowGroupPanel = false;
}
else
detailView = new LayoutView(DetailGrid);
return detailView;
}
private GridColumn CreateColumn() {
GridColumn column = view.Columns.AddField("Detail");
column.Visible = true;
column.VisibleIndex = view.Columns.Count;
return column;
}
private void SetColumnEdit(GridColumn column) {
column.ColumnEdit = CreateItem();
}
private RepositoryItemPopupContainerEdit CreateItem() {
RepositoryItemPopupContainerEdit item = new RepositoryItemPopupContainerEdit();
item.PopupControl = CreatePopupControl();
item.ShowPopupCloseButton = item.ShowPopupShadow = false;
item.PopupSizeable = false;
item.TextEditStyle = DevExpress.XtraEditors.Controls.TextEditStyles.HideTextEditor;
item.QueryPopUp += OnPopup;
item.CloseUp += OnCloseUp;
view.GridControl.RepositoryItems.Add(item);
return item;
}
private PopupContainerControl CreatePopupControl() {
PopupContainerControl popupControl = new PopupContainerControl();
popupControl.Controls.Add(DetailGrid);
return popupControl;
}
void OnPopup(object sender, EventArgs e) {
DetailGrid.BeginUpdate();
try {
DetailGrid.DataSource = null;
DetailGrid.DataSource = GetDetailData();
}
finally {
DetailGrid.EndUpdate();
}
PopupContainerEdit edit = sender as PopupContainerEdit;
if(edit.Properties.PopupControl.Parent == null)
edit.Properties.PopupControl.Parent = edit.FindForm();
DetailGrid.ForceInitialize();
edit.Properties.PopupFormSize = CalcDetailViewSize();
}
private IList GetDetailData() {
return view.DataController.GetDetailList(view.FocusedRowHandle, 0);
}
private System.Drawing.Size CalcDetailViewSize() {
ColumnViewInfo viewInfo = DetailView.GetViewInfo() as ColumnViewInfo;
Rectangle rect = new Rectangle(0, 0, view.GridControl.ClientSize.Width, DetailView.DetailHeight);
rect.Height = viewInfo.CalcRealViewHeight(rect, true) + 5;
return rect.Size;
}
void OnCloseUp(object sender, DevExpress.XtraEditors.Controls.CloseUpEventArgs e) {
DetailView.PostEditor();
detailView.UpdateCurrentRow();
}
}
}