diff --git a/插件库/Lskj.Control/GridControlEx.cs b/插件库/Lskj.Control/GridControlEx.cs index 11cec94..f61c7fc 100644 --- a/插件库/Lskj.Control/GridControlEx.cs +++ b/插件库/Lskj.Control/GridControlEx.cs @@ -390,6 +390,10 @@ namespace Lskj.Control /// 导出名不包含日期 /// public bool IgnoreTab = false; + /// + /// 创建动态分组列控件回调 + /// + public event EventHandler OnBuildGroupedColumnCallBack; public GridControlEx() { @@ -411,7 +415,7 @@ namespace Lskj.Control this.gridView.CellMerge += new CellMergeEventHandler(OnGridViewCellMerge); this.gridView.CustomSummaryCalculate += new CustomSummaryEventHandler(OnGridViewSummaryCalculate); this.gridView.OptionsNavigation.EnterMoveNextColumn = true; - this.gridView.OptionsBehavior.EditorShowMode = DevExpress.Utils.EditorShowMode.MouseDownFocused; + this.gridView.OptionsBehavior.EditorShowMode = EditorShowMode.MouseDownFocused; this.SetGridRowHeightAndFont(); this.gridView.ShowFilterPopupCheckedListBox += new FilterPopupCheckedListBoxEventHandler(OnShowFilterPopupCheckedListBox);//(修复筛选条件) //this.gridView.ValidateRow += OnGridView_ValidateRow; @@ -442,7 +446,6 @@ namespace Lskj.Control #endregion } - /// /// 保存前反写多表头数据源 /// @@ -4265,8 +4268,6 @@ namespace Lskj.Control hyperLinkEdit.LinkColor = System.Drawing.Color.Blue; hyperLinkEdit.NullText = ""; hyperLinkEdit.TextEditStyle = DevExpress.XtraEditors.Controls.TextEditStyles.DisableTextEditor; - // 设置超链接点击事件 - hyperLinkEdit.Click += HyperLinkEdit_Click; hyperLinkEdit.SingleClick = true; hyperLinkEdit.Tag = model; @@ -4292,8 +4293,6 @@ namespace Lskj.Control hyperLinkEdit.LinkColor = System.Drawing.Color.Blue; hyperLinkEdit.NullText = ""; hyperLinkEdit.TextEditStyle = DevExpress.XtraEditors.Controls.TextEditStyles.DisableTextEditor; - // 设置超链接点击事件 - hyperLinkEdit.Click += OnRightClick; hyperLinkEdit.SingleClick = true; hyperLinkEdit.Tag = model; @@ -4331,7 +4330,6 @@ namespace Lskj.Control { this.OnAfterLinkCilk(unionright, null);//直接调用新增行方法,添加关联数据 } - } } } @@ -7221,6 +7219,10 @@ namespace Lskj.Control dynamicHeaders); bandedGridControlEx.gridControl.DataSource = dynamicDataTable; + if (OnBuildGroupedColumnCallBack != null) + { + OnBuildGroupedColumnCallBack(bandedGridControlEx.BandedView, null); + } } @@ -8403,11 +8405,9 @@ namespace Lskj.Control } } - /// /// 清空url图片列缓存 /// - private void ClearImage() { GridColumnCollection gridColumns = this.GridView.Columns; @@ -8765,8 +8765,6 @@ namespace Lskj.Control } #endregion - - /// /// 新建汇总 /// diff --git a/插件库/Lskj.Control/TabControlEx.cs b/插件库/Lskj.Control/TabControlEx.cs index 377e693..e41a8ef 100644 --- a/插件库/Lskj.Control/TabControlEx.cs +++ b/插件库/Lskj.Control/TabControlEx.cs @@ -27,6 +27,7 @@ using Lskj.Business; using DevExpress.XtraGrid.Views.Grid; using System.Threading.Tasks; using System.Collections; +using DevExpress.XtraGrid.Views.BandedGrid; namespace Lskj.Control { @@ -177,7 +178,7 @@ namespace Lskj.Control case GridControlEx gridEx: gridEx.LastSearchSql = lastSql ?? gridEx.LastSearchSql; gridEx.SetGridViewDataSource(table); - + break; /* ② page.Tag 是某种 Control,且本身是 GridControlEx ----------- */ @@ -360,7 +361,7 @@ namespace Lskj.Control tabPage.Text = $"{model.DetailName}({gc.ParentControl.GridRowCount}条)"; tabPage.Appearance.Header.ForeColor = gc.ParentControl.GridRowCount > 0 ? Color.Red : Color.FromArgb(0, 0, 0); } - + // 行定位 / 按钮状态 if (tabPage.Controls.OfType().FirstOrDefault() is ModuleGridEx mod) { @@ -388,9 +389,14 @@ namespace Lskj.Control /// /// - public void InitTabPages(List gridDetail, - bool isGridmerge = true, bool isAddPages = false) + public void InitTabPages(List gridDetail, bool isGridmerge = true, bool isAddPages = false) { + if (ParentGridEx != null && ParentGridEx.CustomGroupBandEx != null) + { + ParentGridEx.CustomGroupBandEx.BandedView.LeftCoordChanged += OnBandedViewLeftCoordChanged; + ParentGridEx.CustomGroupBandEx.BandedView.ColumnWidthChanged += OnBandedViewColumnWidthChanged; + ParentGridEx.OnBuildGroupedColumnCallBack += OnBandedViewColumnWidthChanged; + } this._gridDetail = gridDetail; if (!isAddPages) this.xtc_container.TabPages.Clear(); @@ -417,7 +423,7 @@ namespace Lskj.Control // 2️⃣ 先生成“左侧”父明细控件 System.Windows.Forms.Control leftCtrl = CreateDetailControl(model, dataCaches); - int position = int.TryParse(IniHelper.Read($"base_TabPageMain_{model.Id}"),out int value) ? value : 0; // 0 是转换失败时的默认值 + int position = int.TryParse(IniHelper.Read($"base_TabPageMain_{model.Id}"), out int value) ? value : 0; // 0 是转换失败时的默认值 if (hasRight && isGridmerge) { /* ── 带右侧 Dock 的父明细 ───────────────────────────── */ @@ -425,7 +431,7 @@ namespace Lskj.Control { Dock = DockStyle.Fill, FixedPanel = SplitFixedPanel.Panel1, - SplitterPosition = position>0? position: Math.Max(350, this.xtc_container.Width / 2) + SplitterPosition = position > 0 ? position : Math.Max(350, this.xtc_container.Width / 2) }; split.Panel1.Controls.Add(leftCtrl); split.SplitterPositionChanged += OnSplitterPositionChanged; @@ -508,7 +514,7 @@ namespace Lskj.Control try { SplitContainerControl splitContainerControl = sender as SplitContainerControl; - GridDetailModel model=splitContainerControl.Panel1.Controls[0].Tag as GridDetailModel; + GridDetailModel model = splitContainerControl.Panel1.Controls[0].Tag as GridDetailModel; IniHelper.Write(string.Format("base_TabPageMain_{0}", model.Id), splitContainerControl.SplitterPosition + ""); } catch (Exception ex) @@ -828,6 +834,10 @@ namespace Lskj.Control : model.UnionParentField; gridEx.DetailKeyField = model.UnionValue; gridEx.GridControlObj.ParentControl = gridEx.SearchObj; + if (gridEx.GridControlObj.CustomGroupBandEx != null) + { + gridEx.GridControlObj.CustomGroupBandEx.BandedView.LeftCoordChanged += OnBandedViewLeftCoordChanged; + } gridEx.Tag = model; if (model.IsCheck == 1) { @@ -2392,4 +2402,97 @@ namespace Lskj.Control { Object moduleObject = tabPage.Controls.Cast().FirstOrDefault(); if (moduleObject is ModuleGridEx) - \ No newline at end of file + { + ModuleGridEx moduleGridEx = moduleObject as ModuleGridEx; + bool SaveResults = moduleGridEx.SaveWhenSwitching(); + if (!SaveResults) return false; + } + } + } + } + } + catch (Exception ex) + { + string Message = ErrorMessage.PromptErrorMessage(ex); + MessageUtil.Show(Message, ex.Message); + LogHelper.Instance.WriteError(ex); + return false; + } + return true; + } + /// + /// 控件注销时 + /// + /// + /// + private void OnTabControlExDisposed(object sender, EventArgs e) + { + PageControlsDic?.Clear(); + DetailTabPagesDic?.Clear(); + } + /// + /// 水平滚动条改变时 + /// + /// + /// + private void OnBandedViewLeftCoordChanged(object sender, EventArgs e) + { + BandedGridControlEx childBandView = null; + if (this.TabControlObj.SelectedTabPage != null && this.TabControlObj.SelectedTabPage.Controls.Count > 0) + { + foreach (System.Windows.Forms.Control item in this.TabControlObj.SelectedTabPage.Controls) + { + if (item is ModuleGridEx moduleGridEx && moduleGridEx.GridControlObj.CustomGroupBandEx != null) + { + childBandView = moduleGridEx.GridControlObj.CustomGroupBandEx; + break; + } + } + } + if (childBandView != null && ParentGridEx != null && ParentGridEx.CustomGroupBandEx != null) + { + if (sender == ParentGridEx.CustomGroupBandEx.BandedView) + { + childBandView.BandedView.LeftCoord = ParentGridEx.CustomGroupBandEx.BandedView.LeftCoord; + } + else if (sender == childBandView.BandedView) + { + ParentGridEx.CustomGroupBandEx.BandedView.LeftCoord = childBandView.BandedView.LeftCoord; + } + } + } + /// + /// 宽度改变事件处理,兼容BandedGridView和TreeList + /// + public void OnBandedViewColumnWidthChanged(object sender, EventArgs e) + { + BandedGridControlEx childBandView = null; + if (this.TabControlObj.SelectedTabPage != null && this.TabControlObj.SelectedTabPage.Controls.Count > 0) + { + foreach (System.Windows.Forms.Control item in this.TabControlObj.SelectedTabPage.Controls) + { + if (item is ModuleGridEx moduleGridEx && moduleGridEx.GridControlObj.CustomGroupBandEx != null) + { + childBandView = moduleGridEx.GridControlObj.CustomGroupBandEx; + break; + } + } + } + if (childBandView != null && ParentGridEx != null && ParentGridEx.CustomGroupBandEx != null) + { + int allWidth = 0; + // 如果sender为原有的BandedView类型 + if (sender == ParentGridEx.CustomGroupBandEx.BandedView) + { + foreach (GridBand gridBand in ParentGridEx.CustomGroupBandEx.BandedView.Bands) + { + if (gridBand.Caption.Equals("基本信息")) + { + allWidth += gridBand.Width; + break; + } + } + } + else + { + return; // 非 \ No newline at end of file