feat: 优化初始化缓存及控件功能
This commit is contained in:
@@ -211,17 +211,17 @@ namespace Lskj.Control
|
||||
g.SetGridViewDataSource(table);
|
||||
break;
|
||||
|
||||
/* ③ Tag 是面板/其它容器,递归找内部网格 ------------------------ */
|
||||
/* ③ 图表控件:需先于通用容器判断,避免绑定到图表内部隐藏网格 -- */
|
||||
case ChartControlEx chartEx:
|
||||
chartEx.CreateChart(table);
|
||||
break;
|
||||
|
||||
/* ④ Tag 是面板/其它容器,递归找内部网格 ------------------------ */
|
||||
case System.Windows.Forms.Control container when FindGridControlEx(container) is GridControlEx g2:
|
||||
g2.LastSearchSql = lastSql ?? g2.LastSearchSql;
|
||||
g2.SetGridViewDataSource(table);
|
||||
break;
|
||||
|
||||
/* ④ 图表控件 ---------------------------------------------------- */
|
||||
case ChartControlEx chartEx:
|
||||
chartEx.CreateChart(table);
|
||||
break;
|
||||
|
||||
/* ⑤ 其它控件无需绑定 ------------------------------------------- */
|
||||
default:
|
||||
break;
|
||||
@@ -501,6 +501,14 @@ namespace Lskj.Control
|
||||
|
||||
Dictionary<object, Hashtable> dataCaches = Model?.DataCaches;
|
||||
|
||||
// 普通 ModuleGridEx 明细使用同一个父模块主键,避免同步加载时每个明细重复查询。
|
||||
bool hasModuleGridDetail = Model != null && gridDetail.Any(model => IsModuleGridDetail(model, gridDetail, isGridmerge));
|
||||
string parentPrimaryKey = null;
|
||||
if (hasModuleGridDetail && !dataCaches.GetValue(this, "ParentPrimaryKey", out parentPrimaryKey))
|
||||
{
|
||||
parentPrimaryKey = BaseImpl.GetBasePrimaryKey(Model.ModuleCode);
|
||||
}
|
||||
|
||||
this.DetaiName = string.Empty;
|
||||
|
||||
foreach (GridDetailModel model in gridDetail)
|
||||
@@ -520,7 +528,7 @@ namespace Lskj.Control
|
||||
page.SizeChanged += OnPageSizeChanged;
|
||||
|
||||
// 2️⃣ 先生成“左侧”父明细控件
|
||||
System.Windows.Forms.Control leftCtrl = CreateDetailControl(page, model, dataCaches);
|
||||
System.Windows.Forms.Control leftCtrl = CreateDetailControl(page, model, dataCaches, true, null, hasModuleGridDetail, parentPrimaryKey);
|
||||
int position = int.TryParse(IniHelper.Read($"base_TabPageMain_{model.Id}"), out int value) ? value : 0; // 0 是转换失败时的默认值
|
||||
if (hasRight && isGridmerge)
|
||||
{
|
||||
@@ -559,7 +567,7 @@ namespace Lskj.Control
|
||||
foreach (var child in rightChildren.OrderBy(c => c.Orderid))
|
||||
{
|
||||
XtraTabPage childPage = new XtraTabPage { Text = child.DetailName };
|
||||
System.Windows.Forms.Control childCtrl = CreateDetailControl(childPage, child, dataCaches, true, leftControl);
|
||||
System.Windows.Forms.Control childCtrl = CreateDetailControl(childPage, child, dataCaches, true, leftControl, hasModuleGridDetail, parentPrimaryKey);
|
||||
childPage.Controls.Add(childCtrl);
|
||||
rightTab.TabPages.Add(childPage);
|
||||
_rightSideTabPages.Add(childPage);
|
||||
@@ -605,6 +613,21 @@ namespace Lskj.Control
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 判断明细配置是否会创建普通 ModuleGridEx 控件。
|
||||
/// </summary>
|
||||
private static bool IsModuleGridDetail(GridDetailModel model, List<GridDetailModel> gridDetail, bool isGridmerge)
|
||||
{
|
||||
if (model == null || model.IsChart || model.IsExcel || model.IsWebView || model.IsWebView2 || model.IsWebView3 ||
|
||||
model.IsSched || (model.IsAddPanel && isGridmerge) || model.IsDetailView)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
int sameDetailCount = gridDetail.Count(item => item.DetailName.Equals(model.DetailName));
|
||||
return !(model.IsReadOnly && sameDetailCount == 1) && !(sameDetailCount > 1 && isGridmerge);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -989,6 +1012,7 @@ namespace Lskj.Control
|
||||
this.isMrpDetail = true;
|
||||
gridEx.VisibleMrpSearchPanel = true;
|
||||
}
|
||||
gridEx.MrpClickMenus = rightDt;
|
||||
gridEx.VisibleOperPanel = !model.IsReadOnly;
|
||||
gridEx.InitializeControl(model.SystemModel, dyncModel);
|
||||
gridEx.GridControlObj.Tag = model;
|
||||
@@ -1106,7 +1130,7 @@ namespace Lskj.Control
|
||||
/// <param name="dataCaches"></param>
|
||||
/// <param name="isGridmerge"></param>
|
||||
/// <returns></returns>
|
||||
private System.Windows.Forms.Control CreateDetailControl(System.Windows.Forms.Control parentControl, GridDetailModel model, Dictionary<object, Hashtable> dataCaches, bool isGridmerge = true, GridControlEx leftGridControlEx =null)
|
||||
private System.Windows.Forms.Control CreateDetailControl(System.Windows.Forms.Control parentControl, GridDetailModel model, Dictionary<object, Hashtable> dataCaches, bool isGridmerge = true, GridControlEx leftGridControlEx = null, bool hasParentPrimaryKey = false, string parentPrimaryKey = null)
|
||||
{
|
||||
|
||||
GridDetailModel[] isMeage = _gridDetail.Cast<GridDetailModel>().Where(x => x.DetailName.Equals(model.DetailName)).ToArray();
|
||||
@@ -1441,8 +1465,11 @@ namespace Lskj.Control
|
||||
|
||||
if (Model != null)
|
||||
{
|
||||
if (!dataCaches.GetValue(gridEx, "ParentPrimaryKey", out string primaryKey))
|
||||
string primaryKey = parentPrimaryKey;
|
||||
if (!hasParentPrimaryKey && !dataCaches.GetValue(gridEx, "ParentPrimaryKey", out primaryKey))
|
||||
{
|
||||
primaryKey = BaseImpl.GetBasePrimaryKey(Model.ModuleCode);
|
||||
}
|
||||
model.SystemModel.ParmaryKey = primaryKey;
|
||||
}
|
||||
|
||||
@@ -1465,6 +1492,7 @@ namespace Lskj.Control
|
||||
isMrpDetail = true;
|
||||
gridEx.VisibleMrpSearchPanel = true;
|
||||
}
|
||||
gridEx.MrpClickMenus = rightDt;
|
||||
|
||||
gridEx.VisibleOperPanel = !model.IsReadOnly;
|
||||
if (model.HideBottomPanel|| model.Library.Equals("Lskj.Report.dll", StringComparison.OrdinalIgnoreCase))
|
||||
@@ -1600,6 +1628,15 @@ namespace Lskj.Control
|
||||
Task<List<GridDetailModel>> detailsTask = cachesDic.GetTask<List<GridDetailModel>>(this, "Details");
|
||||
DynamicModel dynamicModel = dynamicModelTask.Result;
|
||||
List<GridDetailModel> details = detailsTask.Result;
|
||||
// 所有子模块使用同一个父模块主键。优先复用外部主表的查询任务,其他入口只补查一次。
|
||||
Task<string> parentPrimaryKeyTask = cachesDic.GetTask<string>(this, "ParentPrimaryKey");
|
||||
if (parentPrimaryKeyTask == null)
|
||||
{
|
||||
parentPrimaryKeyTask = cachesDic.AddTask(this, "ParentPrimaryKey", new Task<string>(() =>
|
||||
{
|
||||
return BaseImpl.GetBasePrimaryKey(dynamicModel.ModuleCode);
|
||||
}));
|
||||
}
|
||||
string DetaiName = string.Empty;
|
||||
PageControlsDic.Clear();
|
||||
foreach (GridDetailModel model in details)
|
||||
@@ -1778,11 +1815,7 @@ namespace Lskj.Control
|
||||
}));
|
||||
if (dynamicModel != null)
|
||||
{
|
||||
Task<string> basePrimaryKeyTask = cachesDic.AddTask(gridEx, "ParentPrimaryKey", new Task<string>(() =>
|
||||
{
|
||||
string basePrimaryKey = BaseImpl.GetBasePrimaryKey(dynamicModel.ModuleCode);
|
||||
return basePrimaryKey;
|
||||
}));
|
||||
cachesDic.AddTask(gridEx, "ParentPrimaryKey", parentPrimaryKeyTask);
|
||||
}
|
||||
Task<DataTable> baseGridRightMenusTask = cachesDic.AddTask(gridEx, "UnionBaseGridRightMenus", new Task<DataTable>(() =>
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user