fix: 收敛旧模块资源释放与诊断
This commit is contained in:
@@ -32,8 +32,10 @@ namespace Lskj.Control.Model
|
||||
/// <summary>
|
||||
/// 查询控件、添加修改界面控件管理类
|
||||
/// </summary>
|
||||
public class MyControl
|
||||
public class MyControl : IDisposable
|
||||
{
|
||||
private const long UserSearchCooldownTicks =
|
||||
TimeSpan.TicksPerMillisecond * 350;
|
||||
private string _searchSql;
|
||||
private DataTable _controls;
|
||||
private DataTable _schemes;
|
||||
@@ -46,8 +48,12 @@ namespace Lskj.Control.Model
|
||||
private GridControlEx _gridLeft;
|
||||
private TreeViewEx _tvLeft;
|
||||
private MyControl _leftSearch;
|
||||
private DropDownButton _dropDown = new DropDownButton();
|
||||
private PopupMenu _popupMenu = new PopupMenu();
|
||||
private DropDownButton _dropDown;
|
||||
private PopupMenu _popupMenu;
|
||||
private bool mDisposed;
|
||||
private bool mUserSearchInProgress;
|
||||
private long mLastUserSearchCompletedTicks;
|
||||
private int mAcceptedUserSearchCount;
|
||||
/// <summary>
|
||||
/// 计算字段
|
||||
/// </summary>
|
||||
@@ -112,6 +118,10 @@ namespace Lskj.Control.Model
|
||||
/// </summary>
|
||||
/// <value>The button object.</value>
|
||||
public SimpleButton ButtonObj { get { return _button; } }
|
||||
public int AcceptedUserSearchCount
|
||||
{
|
||||
get { return mAcceptedUserSearchCount; }
|
||||
}
|
||||
/// <summary>
|
||||
/// 条件数据源刷新按钮
|
||||
/// </summary>
|
||||
@@ -1024,6 +1034,10 @@ namespace Lskj.Control.Model
|
||||
// 创建模版搜索
|
||||
if (_schemes != null && ModuleId > 0 && _schemes.Rows.Count > 0)
|
||||
{
|
||||
if (_popupMenu == null)
|
||||
{
|
||||
_popupMenu = new PopupMenu();
|
||||
}
|
||||
_dropDown = new DropDownButton();
|
||||
_dropDown.DropDownArrowStyle = DropDownArrowStyle.Show;
|
||||
_dropDown.DropDownControl = this._popupMenu;
|
||||
@@ -1204,6 +1218,10 @@ namespace Lskj.Control.Model
|
||||
// 创建模版搜索
|
||||
if (_schemes != null && ModuleId > 0 && _schemes.Rows.Count > 0)
|
||||
{
|
||||
if (_popupMenu == null)
|
||||
{
|
||||
_popupMenu = new PopupMenu();
|
||||
}
|
||||
_dropDown = new DropDownButton();
|
||||
_dropDown.DropDownArrowStyle = DropDownArrowStyle.Show;
|
||||
_dropDown.DropDownControl = this._popupMenu;
|
||||
@@ -1736,8 +1754,14 @@ namespace Lskj.Control.Model
|
||||
WaitForm.HideForm();
|
||||
mControlSourceDic.Clear();
|
||||
if (this.OnDataSourceBindCallBack != null) this.OnDataSourceBindCallBack(this, null);
|
||||
this.mTimer.Stop();
|
||||
this.mTimer.Dispose();
|
||||
Timer timer = this.mTimer;
|
||||
this.mTimer = null;
|
||||
if (timer != null)
|
||||
{
|
||||
timer.Tick -= mTimerTick;
|
||||
timer.Stop();
|
||||
timer.Dispose();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -6091,6 +6115,61 @@ namespace Lskj.Control.Model
|
||||
}
|
||||
}
|
||||
|
||||
private bool TryBeginUserSearch()
|
||||
{
|
||||
if (mDisposed || mUserSearchInProgress)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
long now = DateTime.UtcNow.Ticks;
|
||||
if (mLastUserSearchCompletedTicks > 0 &&
|
||||
now - mLastUserSearchCompletedTicks < UserSearchCooldownTicks)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
mUserSearchInProgress = true;
|
||||
mAcceptedUserSearchCount++;
|
||||
return true;
|
||||
}
|
||||
|
||||
private void EndUserSearch()
|
||||
{
|
||||
mUserSearchInProgress = false;
|
||||
mLastUserSearchCompletedTicks = DateTime.UtcNow.Ticks;
|
||||
}
|
||||
|
||||
private bool ExecuteUserSearch(object sender, EventArgs e)
|
||||
{
|
||||
if (!TryBeginUserSearch())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
SearchArgs args = new SearchArgs();
|
||||
if (OnSearchBeforeCallBack != null)
|
||||
{
|
||||
OnSearchBeforeCallBack(sender, args);
|
||||
}
|
||||
if (args.Continue)
|
||||
{
|
||||
this.SearchGrid(false);
|
||||
}
|
||||
if (OnSearchAfterCallBack != null)
|
||||
{
|
||||
OnSearchAfterCallBack(sender, e);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
finally
|
||||
{
|
||||
EndUserSearch();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// <para>说明:</para>
|
||||
/// <para>创建人:龚宇超</para>
|
||||
@@ -6115,18 +6194,8 @@ namespace Lskj.Control.Model
|
||||
{
|
||||
if (baseControl.Model.IsSearchControl)
|
||||
{
|
||||
// 搜索控件回车直接搜索
|
||||
SearchArgs args = new SearchArgs();
|
||||
// 查询之前
|
||||
if (OnSearchBeforeCallBack != null)
|
||||
OnSearchBeforeCallBack(sender, args);
|
||||
|
||||
if (args.Continue) this.SearchGrid(false);
|
||||
|
||||
// 查询之后
|
||||
if (OnSearchAfterCallBack != null) OnSearchAfterCallBack(sender, e);
|
||||
|
||||
if (baseControl.Model.ScanAfterEmpty)
|
||||
if (ExecuteUserSearch(sender, e) &&
|
||||
baseControl.Model.ScanAfterEmpty)
|
||||
{
|
||||
baseControl.EditText = string.Empty;
|
||||
}
|
||||
@@ -6225,14 +6294,7 @@ namespace Lskj.Control.Model
|
||||
{
|
||||
if (baseControl.Model.IsSearchControl)
|
||||
{
|
||||
// 搜索控件回车直接搜索
|
||||
SearchArgs args = new SearchArgs();
|
||||
// 查询之前
|
||||
if (OnSearchBeforeCallBack != null)
|
||||
OnSearchBeforeCallBack(sender, args);
|
||||
if (args.Continue) this.SearchGrid(false);
|
||||
// 查询之后
|
||||
if (OnSearchAfterCallBack != null) OnSearchAfterCallBack(sender, e);
|
||||
ExecuteUserSearch(sender, e);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -6249,45 +6311,57 @@ namespace Lskj.Control.Model
|
||||
/// <param name="e">The <see cref="EventArgs"/> instance containing the event data.</param>
|
||||
protected void OnSimpleButtonClick(object sender, EventArgs e)
|
||||
{
|
||||
if (!TryBeginUserSearch())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
if (Model != null)
|
||||
try
|
||||
{
|
||||
bool allowBefore = ApiHelper.IsExecEventApi(Interface.Api.OperateEvent.BeforeSearchBtnClick, Model.ModuleCode, 0);
|
||||
//查询前调用Api接口
|
||||
if (allowBefore)
|
||||
if (Model != null)
|
||||
{
|
||||
DataRow dataRow = this.GetAllControlValueRow();
|
||||
ApiHelper apiHelper = new ApiHelper(Model.ModuleCode, 0, dataRow);
|
||||
apiHelper.OnEvent(Interface.Api.OperateEvent.BeforeSearchBtnClick, Interface.Api.ActionType.None);
|
||||
if (apiHelper.apiHandlerModels.Count > 0)
|
||||
bool allowBefore = ApiHelper.IsExecEventApi(Interface.Api.OperateEvent.BeforeSearchBtnClick, Model.ModuleCode, 0);
|
||||
//查询前调用Api接口
|
||||
if (allowBefore)
|
||||
{
|
||||
Hashtable hashtable = apiHelper.apiHandlerModels[apiHelper.apiHandlerModels.Count - 1].resultPmsHashtables[0];
|
||||
if (hashtable.ContainsKey("result"))
|
||||
DataRow dataRow = this.GetAllControlValueRow();
|
||||
ApiHelper apiHelper = new ApiHelper(Model.ModuleCode, 0, dataRow);
|
||||
apiHelper.OnEvent(Interface.Api.OperateEvent.BeforeSearchBtnClick, Interface.Api.ActionType.None);
|
||||
if (apiHelper.apiHandlerModels.Count > 0)
|
||||
{
|
||||
string jsonResult = hashtable["result"] + "";
|
||||
DataTable dataTable = JsonConvert.DeserializeObject<DataTable>(jsonResult);
|
||||
this._mainGridEx.SetGridViewDataSource(dataTable);
|
||||
return;
|
||||
Hashtable hashtable = apiHelper.apiHandlerModels[apiHelper.apiHandlerModels.Count - 1].resultPmsHashtables[0];
|
||||
if (hashtable.ContainsKey("result"))
|
||||
{
|
||||
string jsonResult = hashtable["result"] + "";
|
||||
DataTable dataTable = JsonConvert.DeserializeObject<DataTable>(jsonResult);
|
||||
this._mainGridEx.SetGridViewDataSource(dataTable);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
MessageUtil.Show(ex.Message);
|
||||
}
|
||||
SearchArgs args = new SearchArgs();
|
||||
// 查询之前
|
||||
if (OnSearchBeforeCallBack != null)
|
||||
OnSearchBeforeCallBack(sender, args);
|
||||
|
||||
if (args.Continue) this.SearchGrid(false);
|
||||
|
||||
// 查询之后
|
||||
if (OnSearchAfterCallBack != null) OnSearchAfterCallBack(sender, e);
|
||||
}
|
||||
catch (Exception ex)
|
||||
finally
|
||||
{
|
||||
MessageUtil.Show(ex.Message);
|
||||
EndUserSearch();
|
||||
}
|
||||
SearchArgs args = new SearchArgs();
|
||||
// 查询之前
|
||||
if (OnSearchBeforeCallBack != null)
|
||||
OnSearchBeforeCallBack(sender, args);
|
||||
|
||||
if (args.Continue) this.SearchGrid(false);
|
||||
|
||||
// 查询之后
|
||||
if (OnSearchAfterCallBack != null) OnSearchAfterCallBack(sender, e);
|
||||
}
|
||||
|
||||
|
||||
@@ -6322,15 +6396,7 @@ namespace Lskj.Control.Model
|
||||
/// <param name="e">The <see cref="EventArgs"/> instance containing the event data.</param>
|
||||
protected void OnFixButtonClick(object sender, EventArgs e)
|
||||
{
|
||||
SearchArgs args = new SearchArgs();
|
||||
// 查询之前
|
||||
if (OnSearchBeforeCallBack != null)
|
||||
OnSearchBeforeCallBack(sender, args);
|
||||
|
||||
if (args.Continue) this.SearchGrid(false);
|
||||
|
||||
// 查询之后
|
||||
if (OnSearchAfterCallBack != null) OnSearchAfterCallBack(sender, e);
|
||||
ExecuteUserSearch(sender, e);
|
||||
}
|
||||
/// <summary>
|
||||
/// <para>说明:高级搜索按钮鼠标离开时</para>
|
||||
@@ -6716,6 +6782,154 @@ namespace Lskj.Control.Model
|
||||
}
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
Dispose(true);
|
||||
GC.SuppressFinalize(this);
|
||||
}
|
||||
|
||||
protected virtual void Dispose(bool disposing)
|
||||
{
|
||||
if (!disposing || mDisposed)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
mDisposed = true;
|
||||
mUserSearchInProgress = false;
|
||||
|
||||
Timer timer = mTimer;
|
||||
mTimer = null;
|
||||
if (timer != null)
|
||||
{
|
||||
try
|
||||
{
|
||||
timer.Tick -= mTimerTick;
|
||||
timer.Stop();
|
||||
timer.Dispose();
|
||||
}
|
||||
catch
|
||||
{
|
||||
// A completed delayed-load timer may already be disposed.
|
||||
}
|
||||
}
|
||||
|
||||
if (_button != null)
|
||||
{
|
||||
_button.Click -= OnSimpleButtonClick;
|
||||
_button.Tag = null;
|
||||
}
|
||||
if (_fixButton != null)
|
||||
{
|
||||
_fixButton.Click -= OnFixButtonClick;
|
||||
}
|
||||
if (_refreshButton != null)
|
||||
{
|
||||
_refreshButton.Click -= OnRefreshButtonClick;
|
||||
_refreshButton.Tag = null;
|
||||
}
|
||||
if (btnCondSearch != null)
|
||||
{
|
||||
btnCondSearch.Click -= OnBtnCondSearchClick;
|
||||
btnCondSearch.Tag = null;
|
||||
}
|
||||
if (_dropDown != null)
|
||||
{
|
||||
_dropDown.Leave -= OnDropDownLeave;
|
||||
_dropDown.DropDownControl = null;
|
||||
}
|
||||
foreach (SimpleButton button in mrpBtnDic.Values.Distinct())
|
||||
{
|
||||
if (button != null)
|
||||
{
|
||||
button.Click -= OnModuleClick;
|
||||
button.Tag = null;
|
||||
}
|
||||
}
|
||||
|
||||
BarManager searchSchemeManager =
|
||||
_popupMenu == null ? null : _popupMenu.Manager;
|
||||
if (_popupMenu != null)
|
||||
{
|
||||
_popupMenu.Manager = null;
|
||||
_popupMenu.ItemLinks.Clear();
|
||||
_popupMenu.Dispose();
|
||||
}
|
||||
if (searchSchemeManager != null)
|
||||
{
|
||||
searchSchemeManager.Dispose();
|
||||
}
|
||||
|
||||
if (_mainGridEx != null &&
|
||||
ReferenceEquals(_mainGridEx.ParentControl, this))
|
||||
{
|
||||
_mainGridEx.ParentControl = null;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
if (Model != null && Model.DataCaches != null)
|
||||
{
|
||||
Model.DataCaches.Remove(this);
|
||||
}
|
||||
}
|
||||
catch
|
||||
{
|
||||
// Cache cleanup must not interrupt module disposal.
|
||||
}
|
||||
|
||||
preSearchVerification = null;
|
||||
OnSearchBeforeCallBack = null;
|
||||
OnSearchAfterCallBack = null;
|
||||
OnAddCallBack = null;
|
||||
ClearDetails = null;
|
||||
OnLastQueryTriggered = null;
|
||||
OnSourceRefrshCallBack = null;
|
||||
OnDataSourceBindCallBack = null;
|
||||
OnDataFileRefrshCallBack = null;
|
||||
OpenDocumentSource = null;
|
||||
|
||||
_calcControls.Clear();
|
||||
_models.Clear();
|
||||
mControlList.Clear();
|
||||
mExtendedReturnSearchControls.Clear();
|
||||
mExtendedReturnPendingChanges.Clear();
|
||||
mControlSourceDic.Clear();
|
||||
mCacheDictionary.Clear();
|
||||
DetailSelection.Clear();
|
||||
changeLabelAutoGridLooks.Clear();
|
||||
mrpBtnDic.Clear();
|
||||
ModuleResultDic.Clear();
|
||||
ParaContrlsDic.Clear();
|
||||
|
||||
_controls = null;
|
||||
_schemes = null;
|
||||
_fixField = null;
|
||||
_fixKey = null;
|
||||
_button = null;
|
||||
_fixButton = null;
|
||||
_refreshButton = null;
|
||||
_dropDown = null;
|
||||
_popupMenu = null;
|
||||
btnCondSearch = null;
|
||||
_gridControl = null;
|
||||
_mainGridEx = null;
|
||||
_gridLeft = null;
|
||||
_tvLeft = null;
|
||||
_leftSearch = null;
|
||||
_parentPanel = null;
|
||||
CurrentData = null;
|
||||
SystemModel = null;
|
||||
SaveCondTab = null;
|
||||
mrpDyncModel = null;
|
||||
Model = null;
|
||||
popUpDyncModel = null;
|
||||
rightItemLinks = null;
|
||||
SpecialLeftTable = null;
|
||||
beforeData = null;
|
||||
OtherParams = null;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user