fix(legacy): complete hosted module cleanup
This commit is contained in:
@@ -4126,7 +4126,7 @@ namespace Lskj.Control.Model
|
||||
// 添加内容
|
||||
if (i == 0)
|
||||
{
|
||||
string guid = ERPInfo.Instance.PageControl.SelectedTabPage.Tag + "";
|
||||
string guid = ERPInfo.Instance.CurrentModulePage.Tag + "";
|
||||
DllModule model = ERPInfo.Instance.ModuleForms[guid];
|
||||
cell.SetCellValue(model.Name);
|
||||
}
|
||||
|
||||
@@ -1228,7 +1228,7 @@ namespace Lskj.Control.Model
|
||||
paramList[12],
|
||||
paramList[13]//固定添加行数据json字符串
|
||||
};
|
||||
XtraTabPage xtraTab = ERPInfo.Instance.PageControl != null ? ERPInfo.Instance.PageControl.SelectedTabPage : null;
|
||||
XtraTabPage xtraTab = ERPInfo.Instance.CurrentModulePage != null ? ERPInfo.Instance.CurrentModulePage : null;
|
||||
DllModule module = new DllModule
|
||||
{
|
||||
DllName = ReplaceDllFileName(dllName),
|
||||
@@ -1240,12 +1240,12 @@ namespace Lskj.Control.Model
|
||||
{
|
||||
if (SystemInfo.Instance.SoftOpenMode)
|
||||
{
|
||||
foreach (XtraTabPage tablepage in ERPInfo.Instance.PageControl.TabPages)
|
||||
foreach (XtraTabPage tablepage in ERPInfo.Instance.ModulePages)
|
||||
{
|
||||
if (tablepage.Text == model.MenuName)
|
||||
{
|
||||
MessageUtil.Show("已设置不能打开多个相同模块!");
|
||||
ERPInfo.Instance.PageControl.SelectedTabPage = tablepage;
|
||||
ERPInfo.Instance.CurrentModulePage = tablepage;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -1408,8 +1408,8 @@ namespace Lskj.Control.Model
|
||||
{
|
||||
tp.Disposed += new EventHandler(OnTp_Disposed);
|
||||
}
|
||||
ERPInfo.Instance.PageControl.TabPages.Add(tp);
|
||||
ERPInfo.Instance.PageControl.SelectedTabPage = tp;
|
||||
ERPInfo.Instance.AddModulePage(tp);
|
||||
ERPInfo.Instance.CurrentModulePage = tp;
|
||||
if (isPrivateDll)
|
||||
{
|
||||
StaticControl.DogVerifyModuleForms.Add(tp);
|
||||
|
||||
@@ -15,11 +15,25 @@ namespace Lskj.Control.Model
|
||||
public static class StaticBandedControl
|
||||
{
|
||||
public static void ReleaseModuleReferences(WinFormsControl moduleRoot, XtraTabPage modulePage, string moduleCode)
|
||||
{
|
||||
List<WinFormsControl> moduleControls = CollectModuleControls(moduleRoot, modulePage);
|
||||
ReleaseModuleReferences(moduleControls, modulePage, moduleCode);
|
||||
}
|
||||
|
||||
internal static void ReleaseModuleReferences(
|
||||
IEnumerable<WinFormsControl> moduleControls,
|
||||
XtraTabPage modulePage,
|
||||
string moduleCode)
|
||||
{
|
||||
try
|
||||
{
|
||||
List<BandedGridView> bandedViews = CollectBandedGridViews(moduleRoot);
|
||||
List<GridView> targetViews = CollectTargetGridViews(moduleRoot);
|
||||
List<WinFormsControl> controls = new List<WinFormsControl>();
|
||||
if (moduleControls != null)
|
||||
foreach (WinFormsControl control in moduleControls)
|
||||
if (control != null && !ContainsControl(controls, control))
|
||||
controls.Add(control);
|
||||
List<BandedGridView> bandedViews = CollectBandedGridViews(controls);
|
||||
List<GridView> targetViews = CollectTargetGridViews(controls);
|
||||
foreach (BandedGridView view in bandedViews)
|
||||
BandedGridDragGrid.DisposeRegistrations(
|
||||
BandedGridViewDragGridDic,
|
||||
@@ -32,14 +46,10 @@ namespace Lskj.Control.Model
|
||||
BandedTargetViewDragGridDic,
|
||||
null,
|
||||
view);
|
||||
if (SourceDragBandedGridView != null &&
|
||||
(bandedViews.Contains(SourceDragBandedGridView) ||
|
||||
(SourceDragBandedGridView.GridControl != null && SourceDragBandedGridView.GridControl.IsDisposed)))
|
||||
if (ContainsBandedGridView(bandedViews, SourceDragBandedGridView))
|
||||
SourceDragBandedGridView = null;
|
||||
RemoveConditionPanels(moduleCode);
|
||||
while (modulePage != null && DogVerifyModuleForms.Remove(modulePage))
|
||||
{
|
||||
}
|
||||
RemoveConditionPanels(moduleCode, controls);
|
||||
RemoveProtectedReferences(controls, modulePage);
|
||||
}
|
||||
catch (Exception exception)
|
||||
{
|
||||
@@ -47,36 +57,116 @@ namespace Lskj.Control.Model
|
||||
}
|
||||
}
|
||||
|
||||
private static List<BandedGridView> CollectBandedGridViews(WinFormsControl root)
|
||||
private static List<WinFormsControl> CollectModuleControls(
|
||||
WinFormsControl moduleRoot,
|
||||
XtraTabPage modulePage)
|
||||
{
|
||||
List<WinFormsControl> result = new List<WinFormsControl>();
|
||||
AddModuleControls(result, moduleRoot);
|
||||
if (!ReferenceEquals(moduleRoot, modulePage))
|
||||
AddModuleControls(result, modulePage);
|
||||
return result;
|
||||
}
|
||||
|
||||
private static void AddModuleControls(
|
||||
List<WinFormsControl> target,
|
||||
WinFormsControl root)
|
||||
{
|
||||
if (root == null)
|
||||
return;
|
||||
foreach (WinFormsControl control in EnumerateControls(root))
|
||||
if (!ContainsControl(target, control))
|
||||
target.Add(control);
|
||||
}
|
||||
|
||||
private static List<BandedGridView> CollectBandedGridViews(
|
||||
IEnumerable<WinFormsControl> controls)
|
||||
{
|
||||
List<BandedGridView> result = new List<BandedGridView>();
|
||||
if (root == null)
|
||||
if (controls == null)
|
||||
return result;
|
||||
foreach (WinFormsControl control in EnumerateControls(root))
|
||||
foreach (WinFormsControl control in controls)
|
||||
{
|
||||
DevExpress.XtraGrid.GridControl grid = control as DevExpress.XtraGrid.GridControl;
|
||||
BandedGridView view = grid == null ? null : grid.MainView as BandedGridView;
|
||||
if (view != null && !result.Contains(view))
|
||||
result.Add(view);
|
||||
if (grid == null)
|
||||
continue;
|
||||
try
|
||||
{
|
||||
AddBandedGridView(result, grid.MainView as BandedGridView);
|
||||
foreach (DevExpress.XtraGrid.Views.Base.BaseView baseView in grid.ViewCollection)
|
||||
AddBandedGridView(result, baseView as BandedGridView);
|
||||
}
|
||||
catch (Exception exception)
|
||||
{
|
||||
System.Diagnostics.Debug.WriteLine("读取旧 Banded 表格视图失败:" + exception);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
private static List<GridView> CollectTargetGridViews(WinFormsControl root)
|
||||
private static void AddBandedGridView(
|
||||
List<BandedGridView> target,
|
||||
BandedGridView view)
|
||||
{
|
||||
if (view != null && !ContainsBandedGridView(target, view))
|
||||
target.Add(view);
|
||||
}
|
||||
|
||||
private static bool ContainsBandedGridView(
|
||||
IEnumerable<BandedGridView> gridViews,
|
||||
BandedGridView value)
|
||||
{
|
||||
if (gridViews == null || value == null)
|
||||
return false;
|
||||
foreach (BandedGridView gridView in gridViews)
|
||||
if (ReferenceEquals(gridView, value))
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
private static List<GridView> CollectTargetGridViews(
|
||||
IEnumerable<WinFormsControl> controls)
|
||||
{
|
||||
List<GridView> result = new List<GridView>();
|
||||
if (root == null)
|
||||
if (controls == null)
|
||||
return result;
|
||||
foreach (WinFormsControl control in EnumerateControls(root))
|
||||
foreach (WinFormsControl control in controls)
|
||||
{
|
||||
DevExpress.XtraGrid.GridControl grid = control as DevExpress.XtraGrid.GridControl;
|
||||
GridView view = grid == null ? null : grid.MainView as GridView;
|
||||
if (view != null && !result.Contains(view))
|
||||
result.Add(view);
|
||||
if (grid == null)
|
||||
continue;
|
||||
try
|
||||
{
|
||||
AddGridView(result, grid.MainView as GridView);
|
||||
foreach (DevExpress.XtraGrid.Views.Base.BaseView baseView in grid.ViewCollection)
|
||||
AddGridView(result, baseView as GridView);
|
||||
}
|
||||
catch (Exception exception)
|
||||
{
|
||||
System.Diagnostics.Debug.WriteLine("读取旧 Banded 目标表格视图失败:" + exception);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
private static void AddGridView(List<GridView> target, GridView view)
|
||||
{
|
||||
if (view != null && !ContainsGridView(target, view))
|
||||
target.Add(view);
|
||||
}
|
||||
|
||||
private static bool ContainsGridView(
|
||||
IEnumerable<GridView> gridViews,
|
||||
GridView value)
|
||||
{
|
||||
if (gridViews == null || value == null)
|
||||
return false;
|
||||
foreach (GridView gridView in gridViews)
|
||||
if (ReferenceEquals(gridView, value))
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
private static IEnumerable<WinFormsControl> EnumerateControls(WinFormsControl root)
|
||||
{
|
||||
yield return root;
|
||||
@@ -85,16 +175,67 @@ namespace Lskj.Control.Model
|
||||
yield return nested;
|
||||
}
|
||||
|
||||
private static void RemoveConditionPanels(string moduleCode)
|
||||
private static void RemoveConditionPanels(
|
||||
string moduleCode,
|
||||
IEnumerable<WinFormsControl> moduleControls)
|
||||
{
|
||||
foreach (string key in ConditionsPanelDic.Keys.ToList())
|
||||
{
|
||||
ModuleConditionsPanelEx panel;
|
||||
if (string.Equals(key, moduleCode, StringComparison.OrdinalIgnoreCase) ||
|
||||
!ConditionsPanelDic.TryGetValue(key, out panel) || panel == null || panel.IsDisposed)
|
||||
if (!ConditionsPanelDic.TryGetValue(key, out panel) || panel == null || panel.IsDisposed)
|
||||
{
|
||||
ConditionsPanelDic.Remove(key);
|
||||
continue;
|
||||
}
|
||||
|
||||
if (string.Equals(key, moduleCode, StringComparison.OrdinalIgnoreCase) &&
|
||||
IsConditionPanelOwnedByModule(panel, moduleControls))
|
||||
ConditionsPanelDic.Remove(key);
|
||||
}
|
||||
}
|
||||
|
||||
private static bool IsConditionPanelOwnedByModule(
|
||||
ModuleConditionsPanelEx panel,
|
||||
IEnumerable<WinFormsControl> moduleControls)
|
||||
{
|
||||
if (panel == null)
|
||||
return false;
|
||||
if (ContainsControl(moduleControls, panel) || ContainsControl(moduleControls, panel.Owner))
|
||||
return true;
|
||||
|
||||
MyControl parentControl = panel.ParentControlObj;
|
||||
return parentControl != null &&
|
||||
parentControl.MainGridEx != null &&
|
||||
ContainsControl(moduleControls, parentControl.MainGridEx);
|
||||
}
|
||||
|
||||
private static void RemoveProtectedReferences(
|
||||
IEnumerable<WinFormsControl> moduleControls,
|
||||
XtraTabPage modulePage)
|
||||
{
|
||||
while (modulePage != null && DogVerifyModuleForms.Remove(modulePage))
|
||||
{
|
||||
}
|
||||
foreach (XtraTabPage item in DogVerifyModuleForms.ToList())
|
||||
if (item == null || item.IsDisposed || ContainsControl(moduleControls, item))
|
||||
DogVerifyModuleForms.Remove(item);
|
||||
foreach (IForm item in DogVerifyNoPageForms.ToList())
|
||||
if (item == null || item.SubForm == null || item.SubForm.IsDisposed ||
|
||||
ContainsControl(moduleControls, item.SubForm))
|
||||
DogVerifyNoPageForms.Remove(item);
|
||||
}
|
||||
|
||||
private static bool ContainsControl(
|
||||
IEnumerable<WinFormsControl> moduleControls,
|
||||
WinFormsControl value)
|
||||
{
|
||||
if (moduleControls == null || value == null)
|
||||
return false;
|
||||
foreach (WinFormsControl control in moduleControls)
|
||||
if (ReferenceEquals(control, value))
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
/// <summary>
|
||||
/// 记录当前U盾权限窗口
|
||||
/// </summary>
|
||||
|
||||
Reference in New Issue
Block a user