From 54a149364662f8d0aa8f5a0ed8f874d94dd671da Mon Sep 17 00:00:00 2001 From: tdx Date: Mon, 24 Mar 2025 13:31:01 +0000 Subject: [PATCH] SVN r381 SVN-Revision: r381 --- .../Lskj.Control/TreeBandedGridControlEx.cs | 345 ++++++++---------- 1 file changed, 148 insertions(+), 197 deletions(-) diff --git a/插件库/Lskj.Control/TreeBandedGridControlEx.cs b/插件库/Lskj.Control/TreeBandedGridControlEx.cs index 9c1ac80..d9e4a4e 100644 --- a/插件库/Lskj.Control/TreeBandedGridControlEx.cs +++ b/插件库/Lskj.Control/TreeBandedGridControlEx.cs @@ -48,6 +48,10 @@ namespace Lskj.Control /// public partial class TreeBandedGridControlEx : TreeGridControlEx { + /// + /// 获取模块配置 + /// + public ModuleModel moduleModel; public TreeList TreeListObj { get { return gcMain; } } /// @@ -278,12 +282,6 @@ namespace Lskj.Control this.gcMain.Bands.Clear(); this.gcMain.Columns.Clear(); this.AddBandColumns(table); - - - - DataTable customTable = this.gcMain.GetCustomColumnByDatabase(this.CustomColumKey); - this.SetCustomColumns(customTable); - } @@ -301,6 +299,7 @@ namespace Lskj.Control protected void AddBandColumns(DataTable table, bool readOnly = true) { if (table == null) return; + this.InitGridColumsTab = table; this.mControlList.Clear(); List bandFieldstr = new List(); string bandFields = string.Empty; @@ -309,239 +308,135 @@ namespace Lskj.Control GridColumnModel model = new GridColumnModel(item); this.ColumnList.Add(model); } + Dictionary gridBandEmptyDic = new Dictionary(); TreeListBand gridBandEmpty = new TreeListBand(); - //this.bandedGridView.OptionsView.ColumnHeaderAutoHeight = DefaultBoolean.True; - // 添加Band 列 + GridColumnModel[] bandRows = this.ColumnList.Where(x => !string.IsNullOrEmpty(x.BandFields)).ToArray(); GridColumnModel[] AutobandRows = this.ColumnList.Where(x => x.FieldText.Contains("|")).ToArray(); GridColumnModel[] bandEmptyRows = null; - if (true)//this.moduleModel != null && this.moduleModel.BandSequentialMode + + if (this.moduleModel != null && this.moduleModel.TreeAutoMultiHeader==1) { - bandEmptyRows = AutobandRows.Length > 0 ? this.ColumnList.Where(x => !x.FieldText.Contains("|") && x.Width > 0).ToArray() : this.ColumnList.Where(x => bandRows.Select(n => n.BandFields.Equals(x.FieldName)).Count() == 0 && x.Width > 0).ToArray(); + bandEmptyRows = AutobandRows.Length > 0 + ? this.ColumnList.Where(x => !x.FieldText.Contains("|") && x.Width > 0).ToArray() + : this.ColumnList.Where(x => bandRows.Select(n => n.BandFields.Equals(x.FieldName)).Count() == 0 && x.Width > 0).ToArray(); + foreach (GridColumnModel columnModel in this.ColumnList) { - if (!string.IsNullOrEmpty(columnModel.BandFields)) + string bandTitle = !string.IsNullOrEmpty(columnModel.BandFields) + ? columnModel.BandTitle + : columnModel.FieldText.Contains("|") + ? columnModel.FieldText.Substring(0, columnModel.FieldText.LastIndexOf("|")) + : string.Empty; + + TreeListBand gridBand = null; + + if (!string.IsNullOrEmpty(bandTitle)) { - TreeListBand gridBand = new TreeListBand(); - gridBand.Caption = columnModel.BandTitle; + if (bandFieldstr.Contains(bandTitle)) continue; + bandFieldstr.Add(bandTitle); + + gridBand = new TreeListBand(); + gridBand.Caption = bandTitle.Replace("\\r\\n", " "); gridBand.AppearanceHeader.Options.UseFont = true; gridBand.AppearanceHeader.Font = new Font("宋体", 9, FontStyle.Bold); gridBand.AppearanceHeader.Options.UseTextOptions = true; gridBand.AppearanceHeader.TextOptions.HAlignment = HorzAlignment.Center; - if (columnModel.BandTitle.Contains("\\r\\n")) + + if (bandTitle.Contains("\\r\\n")) { - gridBand.AppearanceHeader.Options.UseTextOptions = true; gridBand.AppearanceHeader.TextOptions.WordWrap = WordWrap.Wrap; - gridBand.Caption = columnModel.BandTitle.Replace("\\r\\n", " "); gridBand.RowCount = 2; } + saveGridBands.Add(gridBand); - gcMain.Bands.AddRange(new TreeListBand[] { gridBand }); - gridBandEmpty = new TreeListBand();//切换时重置空列 + this.gcMain.Bands.Add(gridBand); + gridBandEmpty = new TreeListBand(); } - else if (columnModel.FieldText.Contains("|")) + else if ((AutobandRows.Length > 0 && !columnModel.FieldText.Contains("|") && columnModel.Width > 0) + || (AutobandRows.Length <= 0 && bandRows.Select(n => n.BandFields.Equals(columnModel.FieldName)).Count() == 0 && columnModel.Width > 0)) { - if (bandRows.Length == 0 && AutobandRows.Length > 0) - { - TreeListBand gridBand = new TreeListBand(); - int index = columnModel.FieldText.LastIndexOf("|"); - string bandTitle = columnModel.FieldText.Substring(0, index); - string bandField = columnModel.FieldText.Substring(index + 1, columnModel.FieldText.Length - index - 1); - if (bandFieldstr.Contains(bandTitle)) continue; - bandFieldstr.Add(bandTitle); - gridBand.Caption = bandTitle; - gridBand.AppearanceHeader.Options.UseFont = true; - gridBand.AppearanceHeader.Font = new Font("宋体", 9, FontStyle.Bold); - gridBand.AppearanceHeader.Options.UseTextOptions = true; - gridBand.AppearanceHeader.TextOptions.HAlignment = HorzAlignment.Center; - if (bandTitle.Contains("\\r\\n")) - { - gridBand.AppearanceHeader.Options.UseTextOptions = true; - gridBand.AppearanceHeader.TextOptions.WordWrap = WordWrap.Wrap; - gridBand.Caption = bandTitle.Replace("\\r\\n", " "); - gridBand.RowCount = 2; - } - //gridBand.RowCount = 10; - //gridBand.AppearanceHeader.TextOptions.WordWrap = WordWrap.Wrap; - saveGridBands.Add(gridBand); - gcMain.Bands.AddRange(new TreeListBand[] { gridBand }); - gridBandEmpty = new TreeListBand();//切换时重置空列 - } - } - else if ((AutobandRows.Length > 0 && !columnModel.FieldText.Contains("|") && columnModel.Width > 0) || (AutobandRows.Length <= 0 && bandRows.Select(n => n.BandFields.Equals(columnModel.FieldName)).Count() == 0 && columnModel.Width > 0)) - { - // 空白列 gridBandEmpty.Caption = ""; gridBandEmpty.AppearanceHeader.Options.UseFont = true; gridBandEmpty.AppearanceHeader.Font = new Font("宋体", 9, FontStyle.Bold); gridBandEmpty.AppearanceHeader.Options.UseTextOptions = true; gridBandEmpty.AppearanceHeader.TextOptions.HAlignment = HorzAlignment.Center; + if (!gcMain.Bands.Contains(gridBandEmpty)) - { gcMain.Bands.Add(gridBandEmpty); - } + gridBandEmptyDic.Add(this.ColumnList.IndexOf(columnModel), gridBandEmpty); } } } - else - { - foreach (GridColumnModel item in bandRows) - { - TreeListBand gridBand = new TreeListBand(); - gridBand.Caption = item.BandTitle; - gridBand.AppearanceHeader.Options.UseFont = true; - gridBand.AppearanceHeader.Font = new Font("宋体", 9, FontStyle.Bold); - gridBand.AppearanceHeader.Options.UseTextOptions = true; - gridBand.AppearanceHeader.TextOptions.HAlignment = HorzAlignment.Center; - if (item.BandTitle.Contains("\\r\\n")) - { - gridBand.AppearanceHeader.Options.UseTextOptions = true; - gridBand.AppearanceHeader.TextOptions.WordWrap = WordWrap.Wrap; - gridBand.Caption = item.BandTitle.Replace("\\r\\n", " "); - gridBand.RowCount = 2; - } - saveGridBands.Add(gridBand); - gcMain.Bands.AddRange(new TreeListBand[] { gridBand }); - bandFields += "|" + item.BandFields; - } - if (bandRows.Length == 0 && AutobandRows.Length > 0) - { - foreach (GridColumnModel item in AutobandRows) - { - TreeListBand gridBand = new TreeListBand(); - int index = item.FieldText.LastIndexOf("|"); - string bandTitle = item.FieldText.Substring(0, index); - string bandField = item.FieldText.Substring(index + 1, item.FieldText.Length - index - 1); - if (bandFieldstr.Contains(bandTitle)) continue; - bandFieldstr.Add(bandTitle); - gridBand.Caption = bandTitle; - gridBand.AppearanceHeader.Options.UseFont = true; - gridBand.AppearanceHeader.Font = new Font("宋体", 9, FontStyle.Bold); - gridBand.AppearanceHeader.Options.UseTextOptions = true; - gridBand.AppearanceHeader.TextOptions.HAlignment = HorzAlignment.Center; - if (bandTitle.Contains("\\r\\n")) - { - gridBand.AppearanceHeader.Options.UseTextOptions = true; - gridBand.AppearanceHeader.TextOptions.WordWrap = WordWrap.Wrap; - gridBand.Caption = bandTitle.Replace("\\r\\n", " "); - gridBand.RowCount = 2; - } - //gridBand.RowCount = 10; - //gridBand.AppearanceHeader.TextOptions.WordWrap = WordWrap.Wrap; - - saveGridBands.Add(gridBand); - gcMain.Bands.AddRange(new TreeListBand[] { gridBand }); - bandFields += "|" + bandField; - } - } - bandFields = bandFields + "|"; - // 检查是否包含空白列 - bandEmptyRows = AutobandRows.Length > 0 ? this.ColumnList.Where(x => !x.FieldText.Contains("|") && x.Width > 0).ToArray() : this.ColumnList.Where(x => !bandFields.Contains("|" + x.FieldName + "|") && x.Width > 0).ToArray(); - if (bandEmptyRows != null && bandEmptyRows.Length > 0) - { - // 空白列 - gridBandEmpty.Caption = ""; - gridBandEmpty.AppearanceHeader.Options.UseFont = true; - gridBandEmpty.AppearanceHeader.Font = new Font("宋体", 9, FontStyle.Bold); - gridBandEmpty.AppearanceHeader.Options.UseTextOptions = true; - gridBandEmpty.AppearanceHeader.TextOptions.HAlignment = HorzAlignment.Center; - gcMain.Bands.Insert(0, gridBandEmpty); - } - } // 创建列 for (int i = 0; i < this.ColumnList.Count; i++) { GridColumnModel model = this.ColumnList[i]; - //if (model.Width == 0 || !model.Visible) continue; int startIndex = model.FieldText.Contains("|") ? model.FieldText.LastIndexOf("|") : 0; - string FieldText = startIndex > 0 ? model.FieldText.Substring(startIndex + 1, model.FieldText.Length - startIndex - 1) : model.FieldText; + string FieldText = startIndex > 0 ? model.FieldText.Substring(startIndex + 1) : model.FieldText; + TreeListColumn gridColumn = new TreeListColumn(); + gridColumn.OptionsFilter.AutoFilterCondition = AutoFilterCondition.Contains; + string bandTitle = startIndex > 0 ? model.FieldText.Substring(0, startIndex) : HasBand(model.FieldName, bandRows); - if (!string.IsNullOrEmpty(bandTitle)) - { - // 绑定了多表头显示 - TreeListBand gridBand = this.gcMain.Bands.Cast().FirstOrDefault(x => x.Caption == bandTitle); - if (gridBand != null) - { - gridBand.Columns.Add(gridColumn); - if (saveGridBandColumn.ContainsKey(gridBand)) - { - saveGridBandColumn[gridBand] = saveGridBandColumn[gridBand] + model.FieldName + "^"; - } - else - { - saveGridBandColumn.Add(gridBand, model.FieldName + "^"); - } + TreeListBand gridBand = gcMain.Bands.Cast().FirstOrDefault(x => x.Caption == bandTitle); - } - gcMain.Columns.Add(gridColumn); - } - else + if (gridBand != null) { - // 未绑定多表头则直接显示 - if (bandEmptyRows != null && bandEmptyRows.Contains(model)) - { - if (true)//this.moduleModel != null && this.moduleModel.BandSequentialMode - { - gridBandEmptyDic[this.ColumnList.IndexOf(model)].Columns.Add(gridColumn); - } - else - { - gridBandEmpty.Columns.Add(gridColumn); - } - } - gcMain.Columns.Add(gridColumn); + gridBand.Columns.Add(gridColumn); + if (saveGridBandColumn.ContainsKey(gridBand)) + saveGridBandColumn[gridBand] += model.FieldName + "^"; + else + saveGridBandColumn.Add(gridBand, model.FieldName + "^"); } - //gridColumn.OptionsColumn.AllowMerge = model.CanMerge ? DefaultBoolean.True : DefaultBoolean.False; - //if (model != null && model.CanMerge) - // gcMain.OptionsView.AllowCellMerge = true;//若有合并列则设置表合并,合并后无法多选 + else if (bandEmptyRows != null && bandEmptyRows.Contains(model)) + { + if (this.moduleModel != null && this.moduleModel.BandSequentialMode) + gridBandEmptyDic[this.ColumnList.IndexOf(model)].Columns.Add(gridColumn); + else + gridBandEmpty.Columns.Add(gridColumn); + } + + gcMain.Columns.Add(gridColumn); gridColumn.FieldName = model.FieldName; - gridColumn.Name = model.FieldName; - gridColumn.VisibleIndex = i; gridColumn.Caption = FieldText; gridColumn.Width = model.Width; gridColumn.Visible = model.Visible; gridColumn.OptionsColumn.AllowEdit = !readOnly && model.Edit; gridColumn.Tag = model; - gridColumn.OptionsFilter.FilterPopupMode = FilterPopupMode.CheckedList; - gridColumn.AppearanceHeader.TextOptions.HAlignment = DevExpress.Utils.HorzAlignment.Center; - if (EnabledChangeColor) + gridColumn.AppearanceHeader.TextOptions.HAlignment = HorzAlignment.Center; + + if (model.DataAlignment > 0) { - if (!model.Edit) - { - gridColumn.AppearanceHeader.Options.UseForeColor = true; - gridColumn.AppearanceHeader.ForeColor = ColorTranslator.FromHtml(HeaderColor); - } - else if (model.CanNull) - { - gridColumn.AppearanceHeader.Options.UseForeColor = true; - gridColumn.AppearanceHeader.ForeColor = RequiredForceColor; - } + gridColumn.AppearanceCell.Options.UseTextOptions = true; + gridColumn.AppearanceCell.TextOptions.HAlignment = model.DataAlignment == 1 + ? HorzAlignment.Center + : HorzAlignment.Far; } - this.SetColumnFormat(gridColumn, model); - this.SetColumnSumming(gridColumn, model); - this.InitEditColumns(gridColumn, model); + SetColumnFormat(gridColumn, model); + SetColumnSumming(gridColumn, model); + InitEditColumns(gridColumn, model); + if (model.RepeatedVerification) + this.RepeatedVerificationNames.Add(model.FieldName); } - // 加载数据源 - //BindDataSource(); - DataTable customTable = this.gcMain.GetCustomColumnByDatabase(this.CustomColumKey); - this.SetCustomColumns(customTable); - // 延迟加载数据源 + SetCustomColumns(); this.mLoading = false; - this.mTimer.Tick += new EventHandler(mTimerTick); + this.mTimer.Tick += mTimerTick; this.mTimer.Start(); } + + /// /// 说明:是否为多表头 /// 创建人:龚宇超 @@ -1050,8 +945,12 @@ namespace Lskj.Control mutilLookUp.ValueMember = model.FieldType == ControlType.LabMultiSelectValue || model.FieldType == ControlType.LabMultiSelectValueParam ? model.ValueMember : model.TextMember; mutilLookUp.Tag = model; - RepositoryItemCheckedComboBoxEdit btnEdit = new RepositoryItemCheckedComboBoxEdit(); + btnEdit.Disposed += (s, e) => + { + mutilLookUp?.Dispose(); + mutilLookUp = null; + }; btnEdit.NullText = ""; btnEdit.PopupBorderStyle = PopupBorderStyles.Flat; btnEdit.AllowNullInput = DefaultBoolean.False; @@ -1449,8 +1348,6 @@ namespace Lskj.Control this.gcMain.Bands.Clear(); this.gcMain.Columns.Clear(); this.AddBandColumns(table, false); - DataTable customTable = this.gcMain.GetCustomColumnByDatabase(this.CustomColumKey); - this.SetCustomColumns(customTable); } /// /// 说明:设置编辑列 @@ -1730,51 +1627,101 @@ namespace Lskj.Control } } /// - /// 说明:设置树表格自定义列 - /// 创建人:王一帆 - /// 创建日期:2019-11-14 + /// 说明:设置自定义列(适配TreeList) + /// 创建人:龚宇超 + /// 创建日期:2018-02-01 /// 修改人: /// 修改日期: /// 修改备注: /// 版本:1.0 /// - protected override void SetCustomColumns(DataTable customTable, bool isInit = true) + /// + /// 设置自定义列(适配TreeList,精准修正OwnerBand不存在的问题) + /// + /// + /// 说明:设置自定义列(适配TreeList) + /// 创建人:龚宇超 + /// 创建日期:2018-02-01 + /// 修改人: + /// 修改日期: + /// 修改备注: + /// 版本:1.0 + /// + protected virtual void SetCustomColumns(bool isInit = true) { - Dictionary dataCaches = Model != null ? Model.DataCaches : null; - if (!dataCaches.GetValue(this, "HasExistsSettingTable", out bool hasExistsSettingTable)) + if (string.IsNullOrEmpty(this.CustomColumKey) || !BaseImpl.HasExistsTable(ResourceKeys.SettingTableName)) return; + if (!BaseImpl.HasExistsColumn(ResourceKeys.SettingTableName, "FieldText")) { - hasExistsSettingTable = BaseImpl.HasExistsTable(ResourceKeys.SettingTableName); + BaseImpl.ExecSqlValue("alter table " + ResourceKeys.SettingTableName + " add FieldText varchar(100)"); } - if (string.IsNullOrEmpty(this.CustomColumKey) || !hasExistsSettingTable) return; + + DataTable customTable = this.gcMain.GetCustomColumnByDatabase(this.CustomColumKey); if (customTable != null && customTable.Rows.Count > 0) { + int MaxIndex = customTable.Columns.Count; foreach (DataRow rowItem in customTable.Rows) { string fieldName = rowItem["fieldName"] + ""; + string FieldText = rowItem["FieldText"] + ""; int fieldWidth = Convert.ToInt32(rowItem["fieldWidth"]); int index = Convert.ToInt32(rowItem["orderid"]); bool visible = "1".Equals(rowItem["isVisible"] + "") && fieldWidth > 0; bool isFix = "True".Equals(rowItem["IfFixColumn"] + "", StringComparison.OrdinalIgnoreCase); GridColumnModel column = this.ColumnList.Find(x => x.FieldName == fieldName); - TreeListColumn gridColumn = this.gcMain.Columns.ColumnByName(fieldName); - if (column != null && gridColumn != null && gridColumn.Visible && gridColumn.Width > 0) + TreeListColumn treeColumn = this.gcMain.Columns[fieldName]; + + if (column != null && !string.IsNullOrEmpty(fieldName) && treeColumn != null && treeColumn.Visible && treeColumn.Width > 0) { - TreeListColumn colObj = this.gcMain.Columns[fieldName]; - colObj.VisibleIndex = index; - colObj.Width = fieldWidth; - colObj.Visible = visible; - colObj.Fixed = isFix ? FixedStyle.Left : FixedStyle.None; + TreeListBand treeBand = gcMain.Bands.Cast().FirstOrDefault(b => b.Columns.Contains(treeColumn)); + + if (index >= 0 && index <= this.gcMain.Columns.Count - 1) + { + this.gcMain.Columns.Remove(treeColumn); + TreeListColumn newColumn = this.gcMain.Columns.Insert(index); + + //重新设置列属性 + newColumn.FieldName = fieldName; + newColumn.Caption = FieldText; + newColumn.Width = fieldWidth; + newColumn.VisibleIndex = index; + newColumn.Visible = visible; + newColumn.Tag = column; + newColumn.OptionsColumn.AllowEdit = treeColumn.OptionsColumn.AllowEdit; + + if (treeBand != null) + { + treeBand.Columns.Add(newColumn); + treeBand.Fixed = isFix ? FixedStyle.Left : FixedStyle.None; + } + + if (FieldText.Contains("|") && isFix) + { + FixLeftItemClick(newColumn, new EventArgs()); + } + } + } + } + + foreach (TreeListColumn col in this.gcMain.Columns) + { + DataRow a = customTable.Rows.Cast().FirstOrDefault(x => col.Name.Equals(x["fieldName"] + "", StringComparison.OrdinalIgnoreCase)); + if (a == null) + { + bool visible = col.Visible; + col.VisibleIndex = MaxIndex; + MaxIndex += 1; + col.Visible = visible; } } } + if (!isInit) { - // 非初始化,假如未配置则初始化到系统配置 for (int i = 0; i < this.ColumnList.Count; i++) { GridColumnModel column = this.ColumnList[i]; - if (this.gcMain.Columns.ColumnByName(column.FieldName) != null) + if (this.gcMain.Columns[column.FieldName] != null) { TreeListColumn colObj = this.gcMain.Columns[column.FieldName]; colObj.VisibleIndex = i; @@ -1785,6 +1732,10 @@ namespace Lskj.Control } } + + + + /// /// 说明:监听树表格键盘事件 /// 创建人:王一帆