/// <summary> /// 保存列表控件的布局信息 /// </summary> /// <param name="control">控件</param> /// <param name="attr">授权属性</param> private void StoreLayout(Control control, AuthorizationAttribute attr) { // 表格控件 if (control is GridControl) { foreach (BaseView view in ((GridControl)control).Views) { using (MemoryStream stream = new MemoryStream()) { view.SaveLayoutToStream(stream); Layout layout = new Layout(Thread.CurrentPrincipal.Identity.Name, ConbinPath(attr.AuthorizationUri, view.Name)); layout.Data = stream.ToArray(); LayoutService.StoreLayout(layout); // 保存布局 } } } // 列表控件 if (control is TreeList) { using (MemoryStream stream = new MemoryStream()) { TreeList list = (TreeList)control; list.SaveLayoutToStream(stream); Layout layout = new Layout(Thread.CurrentPrincipal.Identity.Name, ConbinPath(attr.AuthorizationUri, list.Name)); layout.Data = stream.ToArray(); LayoutService.StoreLayout(layout); // 保存布局 } } // 递归处理所有的列表控件 foreach (Control ctrl in control.Controls) { StoreLayout(ctrl, attr); } }
/// <summary> /// 恢复列表控件的布局信息 /// </summary> /// <param name="control">控件</param> /// <param name="attr">授权属性</param> private void ResotreLayout(Control control, AuthorizationAttribute attr) { // 表格控件 if (control is GridControl) { GridControl grid = (GridControl)control; foreach (BaseView view in grid.Views) { Layout layout = LayoutService.RestoreLayout(Thread.CurrentPrincipal.Identity.Name, ConbinPath(attr.AuthorizationUri, view.Name)); if (layout != null) view.RestoreLayoutFromStream(new MemoryStream(layout.Data)); } } // 列表控件 if (control is TreeList) { TreeList list = (TreeList)control; Layout layout = LayoutService.RestoreLayout(Thread.CurrentPrincipal.Identity.Name, ConbinPath(attr.AuthorizationUri, list.Name)); list.RestoreLayoutFromStream(new MemoryStream(layout.Data)); } // 递归处理所有的列表控件 foreach (Control ctrl in control.Controls) ResotreLayout(ctrl, attr); }