fix: 收敛旧模块资源释放与诊断

This commit is contained in:
2026-08-15 10:13:08 +08:00
parent 222ae3c08a
commit c49015d390
60 changed files with 4218 additions and 409 deletions
-17
View File
@@ -45,7 +45,6 @@
this.pl_main = new DevExpress.XtraEditors.PanelControl();
this.pl_main_center = new DevExpress.XtraEditors.PanelControl();
this.pl_main_center_detail = new DevExpress.XtraEditors.PanelControl();
this.gcMain = new Lskj.Control.GridControlEx();
this.pl_main_center_master = new DevExpress.XtraEditors.XtraScrollableControl();
this.pl_treeview_detault_search = new DevExpress.XtraEditors.PanelControl();
this.panelControl4 = new DevExpress.XtraEditors.PanelControl();
@@ -102,7 +101,6 @@
((System.ComponentModel.ISupportInitialize)(this.pl_main_center)).BeginInit();
this.pl_main_center.SuspendLayout();
((System.ComponentModel.ISupportInitialize)(this.pl_main_center_detail)).BeginInit();
this.pl_main_center_detail.SuspendLayout();
this.pl_main_center_master.SuspendLayout();
((System.ComponentModel.ISupportInitialize)(this.pl_treeview_detault_search)).BeginInit();
this.pl_treeview_detault_search.SuspendLayout();
@@ -279,26 +277,12 @@
this.pl_main_center_detail.Appearance.BackColor = System.Drawing.Color.Transparent;
this.pl_main_center_detail.Appearance.Options.UseBackColor = true;
this.pl_main_center_detail.BorderStyle = DevExpress.XtraEditors.Controls.BorderStyles.NoBorder;
this.pl_main_center_detail.Controls.Add(this.gcMain);
this.pl_main_center_detail.Dock = System.Windows.Forms.DockStyle.Fill;
this.pl_main_center_detail.Location = new System.Drawing.Point(0, 164);
this.pl_main_center_detail.Name = "pl_main_center_detail";
this.pl_main_center_detail.Size = new System.Drawing.Size(1211, 202);
this.pl_main_center_detail.TabIndex = 5;
//
// gcMain
//
this.gcMain.AdapterObj = null;
this.gcMain.BackColor = System.Drawing.Color.Transparent;
this.gcMain.Dock = System.Windows.Forms.DockStyle.Fill;
this.gcMain.Location = new System.Drawing.Point(0, 0);
this.gcMain.Margin = new System.Windows.Forms.Padding(5);
this.gcMain.Name = "gcMain";
this.gcMain.SiftEnumObj = Lskj.Control.GridControlEx.HeaderSiftEnum.Sum;
this.gcMain.Size = new System.Drawing.Size(1211, 202);
this.gcMain.SysModel = null;
this.gcMain.TabIndex = 0;
//
// pl_main_center_master
//
this.pl_main_center_master.AutoScroll = false;
@@ -854,7 +838,6 @@
((System.ComponentModel.ISupportInitialize)(this.pl_main_center)).EndInit();
this.pl_main_center.ResumeLayout(false);
((System.ComponentModel.ISupportInitialize)(this.pl_main_center_detail)).EndInit();
this.pl_main_center_detail.ResumeLayout(false);
this.pl_main_center_master.ResumeLayout(false);
((System.ComponentModel.ISupportInitialize)(this.pl_treeview_detault_search)).EndInit();
this.pl_treeview_detault_search.ResumeLayout(false);
+151
View File
@@ -26,6 +26,7 @@ using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient;
using System.Diagnostics;
using System.Drawing;
using System.IO;
using System.Linq;
@@ -89,6 +90,7 @@ namespace Lskj.PubBill
/// </summary>
private DataTable _detailColumns;
private bool IsCopying = false;
private bool _moduleResourcesReleased;
protected DataRow BillRowItem;
@@ -260,6 +262,155 @@ namespace Lskj.PubBill
InitializeComponent();
}
/// <summary>
/// Releases runtime objects created by the bill module. Cleanup is
/// idempotent and best-effort so it cannot change the close result.
/// </summary>
public void ReleaseModuleResources()
{
if (_moduleResourcesReleased)
return;
_moduleResourcesReleased = true;
TryRelease(() => PrintUtil.OnAfterPrint -= new EventHandler(OnReportPrintAfter), "打印回调");
TryRelease(ReleaseModuleEvents, "模块事件");
TryRelease(ReleaseModuleDataSources, "模块数据源");
TryRelease(ReleaseRuntimeCollections, "运行时集合");
BillRowItem = null;
ControlObj = null;
BillModel = null;
SysModel = null;
SumGridColumn = null;
ScanCodeTextEdit = null;
InitialSelectionTab = null;
_imageEdit = null;
_waterMark = null;
_itemImport = null;
_itemImportUpdate = null;
}
private void ReleaseModuleEvents()
{
if (ScanCodeTextEdit != null)
ScanCodeTextEdit.KeyDown -= Text_KeyDown;
if (gcMain != null)
{
gcMain.OnAfterLinkCilk -= OnAfterLinkCilkCall;
gcMain.OnAllAfterParseCallBack -= OnAllAfterParseCallBack;
if (gcMain.GridControl != null)
gcMain.GridControl.DataSourceChanged -= OnGcMainDataSourceChanged;
if (gcMain.GridView != null)
{
gcMain.GridView.KeyDown -= OnToWithdraw;
gcMain.GridView.ShowingEditor -= OnGridViewShowingEditor;
gcMain.GridView.MouseDown -= GridView_MouseDown;
gcMain.GridView.FocusedRowChanged -= GridView_FocusedRowChanged;
gcMain.GridView.InitNewRow -= OnGridViewInitNewRow;
gcMain.GridView.CellValueChanged -= OnGridViewCellValueChanged;
gcMain.GridView.RowCellClick -= OngcMainRowCellClick;
}
}
if (tb_buttom != null)
{
tb_buttom.OnDetailSaveGridCallBack -= Tab_OnDetailSaveGridCallBack;
tb_buttom.BillDetailRightGridCallBack -= Tab_OnDetailSaveGridCallBack;
tb_buttom.OnRightCallback -= OnButtomRightCallBack;
if (tb_buttom.TabControlObj != null)
tb_buttom.TabControlObj.SelectedPageChanged -= TabControlObj_SelectedPageChanged;
}
}
private void ReleaseModuleDataSources()
{
foreach (System.Windows.Forms.Control control in EnumerateChildControls(this).ToList())
{
GridControlEx grid = control as GridControlEx;
if (grid != null)
{
TreeGridControlEx treeGrid = grid as TreeGridControlEx;
if (treeGrid != null && treeGrid.TreeListObj != null)
treeGrid.TreeListObj.DataSource = null;
if (grid.GridControl != null)
grid.GridControl.DataSource = null;
}
XtraTabPage tabPage = control as XtraTabPage;
if (tabPage != null)
tabPage.Tag = null;
}
if (_imageEdit != null && _imageEdit.TextEdit != null)
_imageEdit.TextEdit.Image = null;
if (cb_input != null)
cb_input.Properties.Items.Clear();
if (cb_templete != null)
cb_templete.Properties.Items.Clear();
}
private static IEnumerable<System.Windows.Forms.Control> EnumerateChildControls(
System.Windows.Forms.Control root)
{
if (root == null)
yield break;
yield return root;
foreach (System.Windows.Forms.Control child in root.Controls)
foreach (System.Windows.Forms.Control nested in EnumerateChildControls(child))
yield return nested;
}
private void ReleaseRuntimeCollections()
{
foreach (BillModuleModel model in BillModuleModelDic.Values.ToList())
{
if (model == null)
continue;
model.SourceControl = null;
model.SourceDetailControl = null;
model.SourceDetailDetailControl = null;
model.SourceModel = null;
}
BillModuleModelDic.Clear();
pageNumKey.Clear();
foreach (Dictionary<int, DataRow> rows in ToWithdrawRows)
if (rows != null)
rows.Clear();
ToWithdrawRows.Clear();
ChangeColorRow.Clear();
DateColumnList.Clear();
itemCommonList.Clear();
ColorHandles.Clear();
if (DetailMappingField != null)
DetailMappingField.Clear();
if (_printSaveParams != null)
_printSaveParams.Clear();
if (_detailColumns != null)
{
_detailColumns.Dispose();
_detailColumns = null;
}
if (SaveCondTab != null)
{
SaveCondTab.Dispose();
SaveCondTab = null;
}
}
private static void TryRelease(Action release, string operation)
{
try
{
release();
}
catch (Exception exception)
{
Debug.WriteLine("释放单据模块资源失败[" + operation + "]" + exception);
}
}
#region
/// <summary>
/// <para>说明:窗口加载</para>
+17 -1
View File
@@ -209,5 +209,21 @@ namespace Lskj.PubBill
}
}
protected override void OnFormClosed(FormClosedEventArgs e)
{
base.OnFormClosed(e);
this.FormClosing -= OnClose;
this.Activated -= FrmMain_Activated;
try
{
if (billModule1 != null)
billModule1.ReleaseModuleResources();
}
catch (Exception ex)
{
System.Diagnostics.Debug.WriteLine("释放单据窗口资源失败:" + ex);
}
}
}
}
}