优化模块资源释放与异步预加载

This commit is contained in:
2026-09-03 14:16:48 +08:00
parent a263522b47
commit fddab16bd2
35 changed files with 1553 additions and 977 deletions
+244 -148
View File
@@ -204,6 +204,8 @@ namespace Lskj.PubBillConcise
/// 单据来源控件集合
/// </summary>
public Dictionary<DataRow, BillModuleModel> BillModuleModelDic = new Dictionary<DataRow, BillModuleModel>();
private volatile bool _moduleDisposed;
private readonly object _billModuleModelSync = new object();
/// <summary>
/// 主表动态生成的日期列
/// </summary>
@@ -232,6 +234,36 @@ namespace Lskj.PubBillConcise
public BillModule()
{
InitializeComponent();
this.Disposed += BillModule_Disposed;
}
private void BillModule_Disposed(object sender, EventArgs e)
{
_moduleDisposed = true;
// The preloading graph keeps delegates pointing at this module.
// Remove this owner from the cache as soon as the visual root is
// disposed so later lookups cannot resurrect a closed module.
try
{
if (SysModel != null && SysModel.DataCaches != null)
SysModel.DataCaches.RemoveCache(this);
}
catch
{
// Disposal must remain best-effort.
}
lock (_billModuleModelSync)
{
BillModuleModelDic.Clear();
}
DateColumnList.Clear();
RemoveRowitem.Clear();
ToWithdrawRows.Clear();
ChangeColorRow.Clear();
SysModel = null;
BillModel = null;
ControlObj = null;
}
#region
@@ -250,6 +282,8 @@ namespace Lskj.PubBillConcise
try
{
this.SysModel = Model;// 单据动态链接库参数,入口参数
if (this.SysModel != null && this.SysModel.DataCaches == null)
this.SysModel.DataCaches = new Dictionary<object, Hashtable>();
this._isInitFinish = false;// 是否为初始化创建
this.ssc_main.Visible = false; //获取或设置一个值,该值指示是否显示该控件及其所有子控件。
//this.ProcessExists = (Lskj.Data.Caches.CacheSYSConfig.Instance().JudgeProcessExists() && SystemInfo.Instance.isExecload);
@@ -263,8 +297,13 @@ namespace Lskj.PubBillConcise
}
Dictionary<object, Hashtable> dataCaches = Model != null ? Model.DataCaches : null;
dataCaches.GetValue(this, "DataCaches", out bool _);//等待缓存数据加载完成
if (dataCaches != null)
dataCaches.GetValue(this, "DataCaches", out bool _);//等待缓存数据加载完成
if (this.IsDisposed || Model == null)
return;
this.InitializeSetting();//初始化系统配置
if (this.IsDisposed || this.BillModel == null)
return;
this.InitializeControl();//初始化控件
this.InitlizeSpiltLocation();
@@ -302,31 +341,62 @@ namespace Lskj.PubBillConcise
finally
{
this._isInitFinish = true;
this.ssc_main.Visible = true;
if (this.BillModel.MainVerticalScroll || this.BillModel.MainHorizontalScrolling)
if (!this.IsDisposed && !this.Disposing)
{
this.pl_main_center_master.AutoScroll = true;
this.pl_main_center_master.VerticalScroll.Visible = this.BillModel.MainVerticalScroll;//隐藏纵向滚动条
this.pl_main_center_master.HorizontalScroll.Visible = this.BillModel.MainHorizontalScrolling;//隐藏横向滚动条
this.ssc_main.Visible = true;
if (this.BillModel != null &&
(this.BillModel.MainVerticalScroll || this.BillModel.MainHorizontalScrolling))
{
this.pl_main_center_master.AutoScroll = true;
this.pl_main_center_master.VerticalScroll.Visible = this.BillModel.MainVerticalScroll;//隐藏纵向滚动条
this.pl_main_center_master.HorizontalScroll.Visible = this.BillModel.MainHorizontalScrolling;//隐藏横向滚动条
}
}
}
}
private static void AttachCachedTask<T>(
Dictionary<object, Hashtable> cachesDic,
object cacheOwner,
string cacheKey,
object control,
string controlKey)
{
if (cachesDic == null || cacheOwner == null || control == null ||
cachesDic.GetTask<T>(control, controlKey) != null)
{
return;
}
Task<T> task = cachesDic.GetTask<T>(cacheOwner, cacheKey);
if (task != null)
{
cachesDic.AddTask(control, controlKey, task);
}
}
/// <summary>
/// 获取数据源缓存
/// </summary>
/// <param name="cachesDic"></param>
public void GetDataCaches(Dictionary<object, Hashtable> cachesDic)
{
if (cachesDic == null)
return;
//获取通用数据
Task<ModuleModel> sysModelTask = cachesDic.GetTask<ModuleModel>(this, "SysModel");
Task<DataRow> systemDllRowTask = cachesDic.GetTask<DataRow>(this, "SystemDllRow");
Task<DynamicModel> dynamicModelTask = cachesDic.GetTask<DynamicModel>(this, "DynamicModel");
if (dynamicModelTask == null)
return;
Task<bool> getDataCachesTask = cachesDic.AddTask(this, "DataCaches", new Task<bool>(() =>
{
DynamicBillModel dynamicModel = (DynamicBillModel)dynamicModelTask.Result;
if (dynamicModel == null)
return false;
#region InitializeSetting初始化系统配置
Task<DataRow> billInfoRowTask = cachesDic.AddTask(this, "BillInfo", new Task<DataRow>(() =>
{
@@ -342,6 +412,8 @@ namespace Lskj.PubBillConcise
return model;
}));
BillModel billModel = billModelTask.Result;
if (billModel == null)
return false;
if (billModel != null)
{
Task<string> masterPreFixTask = cachesDic.AddTask(this, "MasterPreFix", new Task<string>(() =>
@@ -358,18 +430,25 @@ namespace Lskj.PubBillConcise
DataRow dataRow = BaseImpl.GetMenuConfigTab(dynamicModel.ModuleId);
if (dataRow != null)
{
billModel.BillSourceIds = dataRow.Table.Columns.Contains("BillSourceIds") ? (dataRow["BillSourceIds"] + "").Trim(',') : string.Empty;
billModel.BillFlag = dataRow.Table.Columns.Contains("BillFlag") && !string.IsNullOrEmpty(dataRow["BillFlag"] + "") ? Convert.ToInt32(dataRow["BillFlag"] + "") : -1;
if (billModel != null)
{
billModel.BillSourceIds = dataRow.Table.Columns.Contains("BillSourceIds") ? (dataRow["BillSourceIds"] + "").Trim(',') : string.Empty;
billModel.BillFlag = dataRow.Table.Columns.Contains("BillFlag") && !string.IsNullOrEmpty(dataRow["BillFlag"] + "") ? Convert.ToInt32(dataRow["BillFlag"] + "") : -1;
}
//billModel
}
return dataRow;//获取菜单其他配置
}));
#region GetPrintOtherParam获取打印其他参数
if (string.IsNullOrEmpty(billModel.PrintSql) && billModel.PrintSql.Contains("<<"))
if (!string.IsNullOrEmpty(billModel.PrintSql) &&
billModel.PrintSql.Contains("<<"))
{
string[] strs = billModel.PrintSql.Split(new[] { ">>" }, 2, StringSplitOptions.None);
_mainPrintSql = strs[1];
_printModeCond = strs[0].Replace("<<", "");
int printEnd = billModel.PrintSql.IndexOf(">>", StringComparison.Ordinal);
if (printEnd > 1 && printEnd + 2 < billModel.PrintSql.Length)
{
_printModeCond = billModel.PrintSql.Substring(2, printEnd - 2);
_mainPrintSql = billModel.PrintSql.Substring(printEnd + 2);
}
}
if (!string.IsNullOrEmpty(_printModeCond) && _printModeCond.IndexOf(';') > 0)
{
@@ -435,15 +514,8 @@ namespace Lskj.PubBillConcise
{
return BaseModuleImpl.GetControlLocation(billModel.FormKey, dynamicModel.ModuleCode);
}));
Task<MyControl> controlObjTask = cachesDic.AddTask(this, "ControlObj", new Task<MyControl>(() =>
{
MyControl myControl = new MyControl() { Model = dynamicModel };
myControl.OtherParams = dynamicModel.OtherParams();
cachesDic.AddTask(myControl, "DynamicModel", dynamicModelTask);
cachesDic.AddTask(myControl, "ControlsTable", controlLocationTask);
myControl.GetControlDataCaches(cachesDic);
return myControl;//主表控件
}));
// MyControl 持有 WinForms Timer。后台预加载只取得控件配置数据,
// MyControl 及其实际编辑控件统一在真正的 UI 线程创建。
Task<DataTable> addGroupDataTask = cachesDic.AddTask(this, "AddGroupData", new Task<DataTable>(() =>
{
return BaseModuleImpl.GetAddGroupData(billModel.FormKey);//获取主信息分组数据
@@ -500,14 +572,21 @@ namespace Lskj.PubBillConcise
}));
cachesDic.AddTask(tb_buttom, "DynamicModel", dynamicModelTask);
cachesDic.AddTask(tb_buttom, "Details", detailTask);
tb_buttom.GetDataCaches(cachesDic);
// TabControlEx.GetDataCaches 会创建 Grid、ModuleGrid、浏览器等
// WinForms/DevExpress 控件。这里只预取来源数据,实际控件在
// InitializeBillSource 的 UI 线程阶段创建。
Task<bool> initSourcesTask = cachesDic.AddTask(this, "InitSourcesTask", new Task<bool>(() =>
{
if (_moduleDisposed)
return false;
Hashtable htTable = sourcesTask.Result;
DataTable masterTable = htTable["master"] as DataTable;
DataTable detailTable = htTable["detail"] as DataTable;
if (masterTable == null)
return false;
for (int i = 0; i < masterTable.Rows.Count; i++)
{
if (_moduleDisposed)
return false;
DataRow sourceModelRow = masterTable.Rows[i];
BillModuleModel billModuleModel = new BillModuleModel();
BillSourceModel model = new BillSourceModel(sourceModelRow);
@@ -516,137 +595,78 @@ namespace Lskj.PubBillConcise
{
return BaseModuleImpl.GetCustomQueryFields(model.FormKey);
}));
#region
GridControlEx gridControl = null;
TreeViewEx treeView = null;
// 后台阶段只加载数据,不构造任何 WinForms/DevExpress
// 对象。缓存以 BillModuleModel 为所有者,UI 创建实际控件
// 后再把需要的任务绑定到该控件。
if (model.SourceType == 1)
{
// 来源为树类型
treeView = new TreeViewEx();
billModuleModel.SourceControl = treeView;
Task<DataTable> bindTreeTableTask = cachesDic.AddTask(treeView, "BindTreeTable", new Task<DataTable>(() =>
cachesDic.AddTask(billModuleModel, "BindTreeTable", new Task<DataTable>(() =>
{
return BaseImpl.GetDataTableResult(model.SourceSql);
}));
}
else if (model.SourceType == 5)
{
model.ChangeSourceType(2);//单据来源显示条数
}
else if (model.SourceType == 3 || model.SourceType == 4)
{
gridControl = new TreeGridControlEx();
billModuleModel.SourceControl = gridControl;
Task<DataTable> sourceColumnsTask = cachesDic.AddTask(gridControl, "SourceColumns", new Task<DataTable>(() =>
{
return BillImpl.GetSourceColumns(model.Id);
}));
Task<DataTable> sourceGridRowColorsTask = cachesDic.AddTask(gridControl, "BaseGridRowColors", new Task<DataTable>(() =>
{
return BaseModuleImpl.GetBaseGridRowColors("BILLSOURCE_" + model.FormKey);
}));
Task<DataTable> sourceGridRightMenusTask = cachesDic.AddTask(gridControl, "BaseGridRightMenus", new Task<DataTable>(() =>
{
return BaseModuleImpl.GetBaseGridRightMenus("BILLSOURCE_" + model.FormKey);
}));
}
else
{
// 来源为表格类型
gridControl = new GridControlEx();
billModuleModel.SourceControl = gridControl;
Task<DataTable> sourceColumnsTask = cachesDic.AddTask(gridControl, "SourceColumns", new Task<DataTable>(() =>
{
return BillImpl.GetSourceColumns(model.Id);
}));
//创建表格列
cachesDic.AddTask(gridControl, "DynamicModel", dynamicModelTask);
gridControl.GetDataCaches(cachesDic, GridCustomColumnStruct.BillSourceGridView + model.FormKey);
Task<DataTable> sourceGridRowColorsTask = cachesDic.AddTask(gridControl, "BaseGridRowColors", new Task<DataTable>(() =>
{
return BaseModuleImpl.GetBaseGridRowColors("BILLSOURCE_" + model.FormKey);
}));
Task<DataTable> sourceGridRightMenusTask = cachesDic.AddTask(gridControl, "BaseGridRightMenus", new Task<DataTable>(() =>
{
return BaseModuleImpl.GetBaseGridRightMenus("BILLSOURCE_" + model.FormKey);
}));
}
#endregion
#region
GridControlEx gridDetail = new GridControlEx();
if (model.sourceDetailType.Equals("1"))
{
//明细为树表格
gridDetail = new TreeGridControlEx();
billModuleModel.SourceDetailControl = gridDetail;
//创建表格列
cachesDic.AddTask(gridDetail, "DynamicModel", dynamicModelTask);
gridDetail.GetDataCaches(cachesDic, GridCustomColumnStruct.BillSourceDetailGridView + model.FormKey);
Task<DataTable> detailGridRowColorsTask = cachesDic.AddTask(gridDetail, "BaseGridRowColors", new Task<DataTable>(() =>
{
return BaseModuleImpl.GetBaseGridRowColors("SOURCEDETAIL_" + model.FormKey);
}));
Task<DataTable> detailGridRightMenusTask = cachesDic.AddTask(gridDetail, "BaseGridRightMenus", new Task<DataTable>(() =>
{
return BaseModuleImpl.GetBaseGridRightMenus("BILLSOURCEDT_" + model.FormKey);
}));
if (model.SourceType == 5)
model.ChangeSourceType(2);//单据来源显示条数
cachesDic.AddTask(billModuleModel, "SourceColumns", new Task<DataTable>(() =>
{
return BillImpl.GetSourceColumns(model.Id);
}));
cachesDic.AddTask(billModuleModel, "SourceCustomColumnByDatabase", new Task<DataTable>(() =>
{
return GridExtend.GetCustomColumnByDatabase(
GridCustomColumnStruct.BillSourceGridView + model.FormKey);
}));
cachesDic.AddTask(billModuleModel, "SourceBaseGridRowColors", new Task<DataTable>(() =>
{
return BaseModuleImpl.GetBaseGridRowColors("BILLSOURCE_" + model.FormKey);
}));
cachesDic.AddTask(billModuleModel, "SourceBaseGridRightMenus", new Task<DataTable>(() =>
{
return BaseModuleImpl.GetBaseGridRightMenus("BILLSOURCE_" + model.FormKey);
}));
}
else
if (string.IsNullOrWhiteSpace(model.DetailModeCode))
{
gridDetail = new GridControlEx();
billModuleModel.SourceDetailControl = gridDetail;
//创建表格列
cachesDic.AddTask(gridDetail, "DynamicModel", dynamicModelTask);
gridDetail.GetDataCaches(cachesDic, GridCustomColumnStruct.BillSourceDetailGridView + model.FormKey);
Task<DataTable> detailGridRowColorsTask = cachesDic.AddTask(gridDetail, "BaseGridRowColors", new Task<DataTable>(() =>
cachesDic.AddTask(billModuleModel, "SourceDetailCustomColumnByDatabase", new Task<DataTable>(() =>
{
return GridExtend.GetCustomColumnByDatabase(
GridCustomColumnStruct.BillSourceDetailGridView + model.FormKey);
}));
cachesDic.AddTask(billModuleModel, "SourceDetailBaseGridRowColors", new Task<DataTable>(() =>
{
return BaseModuleImpl.GetBaseGridRowColors("SOURCEDETAIL_" + model.FormKey);
}));
Task<DataTable> detailGridRightMenusTask = cachesDic.AddTask(gridDetail, "BaseGridRightMenus", new Task<DataTable>(() =>
cachesDic.AddTask(billModuleModel, "SourceDetailBaseGridRightMenus", new Task<DataTable>(() =>
{
return BaseModuleImpl.GetBaseGridRightMenus("BILLSOURCEDT_" + model.FormKey);
}));
//明细的明细(明细分成左右2个)
if (!string.IsNullOrEmpty(model.SourceDetailsDetailsSql))
{
GridControlEx gridDetail_Details = new GridControlEx();
billModuleModel.SourceDetailDetailControl = gridDetail_Details;
//创建只读列
Task<DataTable> detailDetailsTask = cachesDic.AddTask(gridDetail_Details, "DetailDetails", new Task<DataTable>(() =>
cachesDic.AddTask(billModuleModel, "DetailDetails", new Task<DataTable>(() =>
{
return BaseModuleImpl.getDetail_Details(model.FormKey);
}));
//创建表格列
cachesDic.AddTask(gridDetail_Details, "DynamicModel", dynamicModelTask);
gridDetail_Details.GetDataCaches(cachesDic);
Task<DataTable> detailDetailsGridRightMenusTask = cachesDic.AddTask(gridDetail_Details, "BaseGridRightMenus", new Task<DataTable>(() =>
cachesDic.AddTask(billModuleModel, "SourceDetailDetailsCustomColumnByDatabase", new Task<DataTable>(() =>
{
return GridExtend.GetCustomColumnByDatabase(string.Empty);
}));
cachesDic.AddTask(billModuleModel, "SourceDetailDetailsBaseGridRightMenus", new Task<DataTable>(() =>
{
return BaseModuleImpl.GetBaseGridRightMenus("BILLSOURCEDTX_" + model.FormKey);
}));
}
}
#endregion
BillModuleModelDic.Add(sourceModelRow, billModuleModel);
#region
Task<MyControl> searchControlTask = cachesDic.AddTask(sourceModelRow, "SearchControl", new Task<MyControl>(() =>
lock (_billModuleModelSync)
{
DataTable controls = customQueryFieldsTask.Result;
MyControl searchControl = null;
if (model.SourceType != 1 || (controls != null && controls.Rows.Count > 0))
{
// 创建自定义条件
string searchSql = model.SourceType == 1 ? Regex.Replace(model.DetailSql, "{speciesno}", "", RegexOptions.IgnoreCase) : model.SourceSql;
searchControl = new MyControl(searchSql, gridControl == null ? gridDetail : gridControl, treeView);
searchControl.Model = dynamicModel;
searchControl.OtherParams = dynamicModel.OtherParams();
cachesDic.AddTask(searchControl, "DynamicModel", dynamicModelTask);
cachesDic.AddTask(searchControl, "ControlsTable", customQueryFieldsTask);
searchControl.GetSearchDataCaches(cachesDic);
}
return searchControl;
}));
#endregion
if (_moduleDisposed)
return false;
BillModuleModelDic[sourceModelRow] = billModuleModel;
}
}
return true;
}));
@@ -715,6 +735,10 @@ namespace Lskj.PubBillConcise
private void InitializeSetting()
{
Dictionary<object, Hashtable> dataCaches = SysModel != null ? SysModel.DataCaches : null;
if (this.SysModel == null)
return;
if (dataCaches == null)
dataCaches = new Dictionary<object, Hashtable>();
if (!dataCaches.GetValue(this, "BillInfo", out DataRow modelRow))
{
modelRow = BillImpl.GetBillInfo(this.SysModel.ModuleCode);//获取单个模块信息
@@ -1040,6 +1064,10 @@ namespace Lskj.PubBillConcise
private void InitializeBillInfo()
{
Dictionary<object, Hashtable> dataCaches = SysModel != null ? SysModel.DataCaches : null;
if (this.BillModel == null || this.SysModel == null)
return;
if (dataCaches == null)
dataCaches = new Dictionary<object, Hashtable>();
if (!dataCaches.GetValue(this, "ControlLocation", out DataTable controls))
{
controls = BaseModuleImpl.GetControlLocation(this.BillModel.FormKey, this.SysModel.ModuleCode);
@@ -1653,6 +1681,18 @@ namespace Lskj.PubBillConcise
this.xtc_left_container.TabPages.Clear();
Dictionary<object, Hashtable> dataCaches = SysModel != null ? SysModel.DataCaches : null;
if (this.BillModel == null || this.SysModel == null)
return;
if (dataCaches == null)
dataCaches = new Dictionary<object, Hashtable>();
if (tb_buttom != null && dataCaches != null &&
dataCaches.GetTask<DynamicModel>(tb_buttom, "DynamicModel") != null &&
dataCaches.GetTask<List<GridDetailModel>>(tb_buttom, "Details") != null)
{
// TabControlEx.GetDataCaches 会创建来源明细页中的控件,必须在
// 当前 WinForms UI 线程执行;其内部的数据任务仍可并行准备。
tb_buttom.GetDataCaches(dataCaches);
}
if (!dataCaches.GetValue(this, "Details", out List<GridDetailModel> attachModels))
{
attachModels = GetAttachTabs();
@@ -1666,8 +1706,13 @@ namespace Lskj.PubBillConcise
}
htTable = BillImpl.GetSources(this.SysModel.ModuleCode, SourceIds);//获取单据来源
}
if (htTable == null)
return;
DataTable masterTable = htTable["master"] as DataTable;
DataTable detailTable = htTable["detail"] as DataTable;
if (masterTable == null)
return;
DataTable detailTable = htTable["detail"] as DataTable ?? new DataTable();
/*
* 1. ,()+,.
@@ -1700,7 +1745,13 @@ namespace Lskj.PubBillConcise
for (int i = 0; i < masterTable.Rows.Count; i++)
{
DataRow sourceModelRow = masterTable.Rows[i];
BillModuleModel billModuleModel = BillModuleModelDic.ContainsKey(sourceModelRow) ? BillModuleModelDic[sourceModelRow] : new BillModuleModel();
BillModuleModel billModuleModel;
lock (_billModuleModelSync)
{
BillModuleModelDic.TryGetValue(sourceModelRow, out billModuleModel);
}
if (billModuleModel == null)
billModuleModel = new BillModuleModel();
BillSourceModel model = billModuleModel.SourceModel != null ? billModuleModel.SourceModel : new BillSourceModel(sourceModelRow);
object sourceControl = billModuleModel.SourceControl != null ? billModuleModel.SourceControl : null;
object sourceDetailControl = billModuleModel.SourceDetailControl != null ? billModuleModel.SourceDetailControl : null;
@@ -1743,7 +1794,7 @@ namespace Lskj.PubBillConcise
treeView.Dock = DockStyle.Fill;
treeView.TreeNodeKeyField = model.SourceKeyField;
treeView.TreeNodeTextField = model.SourceResult;
if (!dataCaches.GetValue(treeView, "BindTreeTable", out DataTable bindTreeTable))
if (!dataCaches.GetValue(billModuleModel, "BindTreeTable", out DataTable bindTreeTable))
{
bindTreeTable = BaseImpl.GetDataTableResult(model.SourceSql);
}
@@ -1765,15 +1816,15 @@ namespace Lskj.PubBillConcise
gridControl.BorderStyle = System.Windows.Forms.BorderStyle.None;
gridControl.Model = this.SysModel;
if (!dataCaches.GetValue(gridControl, "SourceColumns", out DataTable dtSourceColumns))
if (!dataCaches.GetValue(billModuleModel, "SourceColumns", out DataTable dtSourceColumns))
{
dtSourceColumns = BillImpl.GetSourceColumns(model.Id);
}
if (!dataCaches.GetValue(gridControl, "BaseGridRowColors", out DataTable dtBaseGridRowColors))
if (!dataCaches.GetValue(billModuleModel, "SourceBaseGridRowColors", out DataTable dtBaseGridRowColors))
{
dtBaseGridRowColors = BaseModuleImpl.GetBaseGridRowColors("BILLSOURCE_" + model.FormKey);
}
if (!dataCaches.GetValue(gridControl, "BaseGridRightMenus", out DataTable dtBaseGridRightMenus))
if (!dataCaches.GetValue(billModuleModel, "SourceBaseGridRightMenus", out DataTable dtBaseGridRightMenus))
{
dtBaseGridRightMenus = BaseModuleImpl.GetBaseGridRightMenus("BILLSOURCE_" + model.FormKey);
}
@@ -1783,6 +1834,9 @@ namespace Lskj.PubBillConcise
//父节点编号
if (!string.IsNullOrWhiteSpace(model.SourceParentFieldName)) (gridControl as TreeGridControlEx).TreeListObj.ParentFieldName = model.SourceParentFieldName;
AttachCachedTask<DataTable>(dataCaches, billModuleModel,
"SourceCustomColumnByDatabase", gridControl,
"CustomColumnByDatabase");
gridControl.SetReadOnlyColumns(dtSourceColumns, GridCustomColumnStruct.BillSourceGridView + model.FormKey);
gridControl.SetGridRowColors(dtBaseGridRowColors);
//gridControl.SetGridRightMenus(dtBaseGridRightMenus, this.SysModel, OnGridControlRightCallback);
@@ -1829,18 +1883,21 @@ namespace Lskj.PubBillConcise
{
gridControl.GridView.OptionsView.ShowAutoFilterRow = true;
}
if (!dataCaches.GetValue(gridControl, "SourceColumns", out DataTable dtSourceColumns))
if (!dataCaches.GetValue(billModuleModel, "SourceColumns", out DataTable dtSourceColumns))
{
dtSourceColumns = BillImpl.GetSourceColumns(model.Id);
}
if (!dataCaches.GetValue(gridControl, "BaseGridRowColors", out DataTable dtBaseGridRowColors))
if (!dataCaches.GetValue(billModuleModel, "SourceBaseGridRowColors", out DataTable dtBaseGridRowColors))
{
dtBaseGridRowColors = BaseModuleImpl.GetBaseGridRowColors("BILLSOURCE_" + model.FormKey);
}
if (!dataCaches.GetValue(gridControl, "BaseGridRightMenus", out DataTable dtBaseGridRightMenus))
if (!dataCaches.GetValue(billModuleModel, "SourceBaseGridRightMenus", out DataTable dtBaseGridRightMenus))
{
dtBaseGridRightMenus = BaseModuleImpl.GetBaseGridRightMenus("BILLSOURCE_" + model.FormKey);
}
AttachCachedTask<DataTable>(dataCaches, billModuleModel,
"SourceCustomColumnByDatabase", gridControl,
"CustomColumnByDatabase");
gridControl.SetReadOnlyColumns(dtSourceColumns, GridCustomColumnStruct.BillSourceGridView + model.FormKey);
gridControl.SetGridRowColors(dtBaseGridRowColors);
gridControl.SetGridRightMenus(dtBaseGridRightMenus, this.SysModel, OnGridControlRightCallback);
@@ -1893,8 +1950,9 @@ namespace Lskj.PubBillConcise
DataRow[] detailColumns = detailTable.Select("sourceId=" + model.Id);
//明细为表格
GridControlEx gridDetail = new GridControlEx();
// 明细控件由下面的分支按实际类型创建,避免先构造一个
// 随即被替换、且无法进入父容器 Dispose 链的临时 GridControlEx。
GridControlEx gridDetail = null;
if (model.sourceDetailType.Equals("1"))
@@ -1903,12 +1961,15 @@ namespace Lskj.PubBillConcise
gridDetail = sourceDetailControl != null ? (TreeGridControlEx)sourceDetailControl : new TreeGridControlEx();
gridDetail.Model = this.SysModel;
gridDetail.Dock = DockStyle.Fill;
AttachCachedTask<DataTable>(dataCaches, billModuleModel,
"SourceDetailCustomColumnByDatabase", gridDetail,
"CustomColumnByDatabase");
gridDetail.SetReadOnlyColumns(detailColumns == null || detailColumns.Length == 0 ? new DataTable() : detailColumns.CopyToDataTable(), GridCustomColumnStruct.BillSourceDetailGridView + model.FormKey);
if (!dataCaches.GetValue(gridDetail, "BaseGridRowColors", out DataTable dtBaseGridRowColors))
if (!dataCaches.GetValue(billModuleModel, "SourceDetailBaseGridRowColors", out DataTable dtBaseGridRowColors))
{
dtBaseGridRowColors = BaseModuleImpl.GetBaseGridRowColors("SOURCEDETAIL_" + model.FormKey);
}
if (!dataCaches.GetValue(gridDetail, "BaseGridRightMenus", out DataTable dtBaseGridRightMenus))
if (!dataCaches.GetValue(billModuleModel, "SourceDetailBaseGridRightMenus", out DataTable dtBaseGridRightMenus))
{
dtBaseGridRightMenus = BaseModuleImpl.GetBaseGridRightMenus("BILLSOURCEDT_" + model.FormKey);
}
@@ -1940,17 +2001,20 @@ namespace Lskj.PubBillConcise
gridDetail = sourceDetailControl != null ? (GridControlEx)sourceDetailControl : new GridControlEx();
gridDetail.Model = this.SysModel;
gridDetail.Dock = DockStyle.Fill;
AttachCachedTask<DataTable>(dataCaches, billModuleModel,
"SourceDetailCustomColumnByDatabase", gridDetail,
"CustomColumnByDatabase");
gridDetail.SetReadOnlyColumns(detailColumns == null || detailColumns.Length == 0 ? new DataTable() : detailColumns.CopyToDataTable(), GridCustomColumnStruct.BillSourceDetailGridView + model.FormKey);
if (model.DetailedLoadFilter)
{
gridDetail.GridView.OptionsView.ShowAutoFilterRow = true;
}
if (!dataCaches.GetValue(gridDetail, "BaseGridRowColors", out DataTable dtBaseGridRowColors))
if (!dataCaches.GetValue(billModuleModel, "SourceDetailBaseGridRowColors", out DataTable dtBaseGridRowColors))
{
dtBaseGridRowColors = BaseModuleImpl.GetBaseGridRowColors("SOURCEDETAIL_" + model.FormKey);
}
if (!dataCaches.GetValue(gridDetail, "BaseGridRightMenus", out DataTable dtBaseGridRightMenus))
if (!dataCaches.GetValue(billModuleModel, "SourceDetailBaseGridRightMenus", out DataTable dtBaseGridRightMenus))
{
dtBaseGridRightMenus = BaseModuleImpl.GetBaseGridRightMenus("BILLSOURCEDT_" + model.FormKey);
}
@@ -1966,14 +2030,17 @@ namespace Lskj.PubBillConcise
GridControlEx gridDetail_Details = sourceDetailDetailControl != null ? (GridControlEx)sourceDetailDetailControl : new GridControlEx();
gridDetail_Details.Model = this.SysModel;
gridDetail_Details.Dock = DockStyle.Fill;
AttachCachedTask<DataTable>(dataCaches, billModuleModel,
"SourceDetailDetailsCustomColumnByDatabase", gridDetail_Details,
"CustomColumnByDatabase");
//创建只读列
if (!dataCaches.GetValue(gridDetail_Details, "Detail_Details", out DataTable dataTable))
if (!dataCaches.GetValue(billModuleModel, "DetailDetails", out DataTable dataTable))
{
dataTable = BaseModuleImpl.getDetail_Details(model.FormKey);
}
gridDetail_Details.SetReadOnlyColumns(dataTable);
//设置右键
if (!dataCaches.GetValue(gridDetail_Details, "BaseGridRightMenus", out DataTable dttBaseGridRightMenus))
if (!dataCaches.GetValue(billModuleModel, "SourceDetailDetailsBaseGridRightMenus", out DataTable dttBaseGridRightMenus))
{
dttBaseGridRightMenus = BaseModuleImpl.GetBaseGridRightMenus("BILLSOURCEDTX_" + model.FormKey);
}
@@ -2092,9 +2159,23 @@ namespace Lskj.PubBillConcise
string searchSql = model.SourceType == 1 ? Regex.Replace(model.DetailSql, "{speciesno}", "", RegexOptions.IgnoreCase) : model.SourceSql;
//searchSql = ReplaceHelper.ReplaceParam(searchSql);
PanelControl searchPanel = new PanelControl();
if (!dataCaches.GetValue(sourceModelRow, "SearchControl", out MyControl searchControl))
MyControl searchControl = new MyControl(
searchSql,
gridControl == null ? gridDetail : gridControl,
treeView)
{
searchControl = new MyControl(searchSql, gridControl == null ? gridDetail : gridControl, treeView);
Model = this.SysModel,
OtherParams = this.SysModel.OtherParams()
};
if (dataCaches != null)
{
dataCaches.AddTask(searchControl, "DynamicModel",
new Task<DynamicModel>(() => this.SysModel));
dataCaches.AddTask(searchControl, "ControlsTable",
new Task<DataTable>(() => controls));
// 查询条件模型和默认值可以后台准备,编辑控件由
// InitSearchControl 在当前 UI 线程创建。
searchControl.GetSearchDataCaches(dataCaches);
}
searchControl.OnSearchBeforeCallBack += new SearchEventHandler(OnSearchBefore);
searchControl.OnSearchAfterCallBack += new EventHandler(OnSearchAfterd);
@@ -2132,6 +2213,21 @@ namespace Lskj.PubBillConcise
}
// Keep the actual UI-owned controls on the per-source record.
// This preserves reuse on a later source rebuild and gives
// disposal/debugging code an exact ownership list without
// traversing the visual tree.
billModuleModel.SourceModel = model;
billModuleModel.SourceControl = treeView ?? (object)gridControl;
billModuleModel.SourceDetailControl = gridDetail;
billModuleModel.SourceDetailDetailControl =
unionModel.GridDetailDetailControlObj;
lock (_billModuleModelSync)
{
if (!_moduleDisposed)
BillModuleModelDic[sourceModelRow] = billModuleModel;
}
unionModel.ModelObj = model;
@@ -3215,7 +3311,7 @@ namespace Lskj.PubBillConcise
if (pageControl.Tag is GridDetailModel detailModel && (detailModel.Orderid + "").Equals(movepage))
{
this.tb_buttom.TabControlObj.SelectedTabPage = xtraTabPage;
StaticControl.BomUnionPage = xtraTabPage;
StaticControl.SetBomUnionPage(xtraTabPage);
if (xtraTabPage.Tag is GridControlEx)
{
DataRow dataRow = this.gcMain.GetViewFocusedDataRow();
@@ -5157,7 +5253,7 @@ namespace Lskj.PubBillConcise
menu.ApplyBefore += new CommonToolApplyEventHandler(OnMenuApplyBefore);
menu.DynamicLinkAfter += new CommonToolAfterDynamicLinkEventHandler(OnDynamicLinkAfter);
StaticControl.RightMenuGridView = gcMain.GridView;
StaticControl.RightMenuMyControl = ControlObj;
StaticControl.SetRightMenuMyControl(ControlObj);
menu.Apply(menuRow);
if (!menu.issuccess)
{
@@ -9269,4 +9365,4 @@ namespace Lskj.PubBillConcise
}
}
}
}
}