feat: 完善个人设置及表格功能

This commit is contained in:
cyf
2026-08-31 18:03:47 +08:00
parent 769aa52241
commit c1d10f22f5
11 changed files with 1033 additions and 88 deletions
@@ -122,6 +122,8 @@ namespace Lskj.Control
this.bandedGridView.PopupMenuShowing += new DevExpress.XtraGrid.Views.Grid.PopupMenuShowingEventHandler(this.OnGridViewPopupMenuShowing);
this.bandedGridView.Click += new EventHandler(OnBandedGridView_Click);
this.bandedGridView.DoubleClick += new EventHandler(OnBandedGridViewDoubleClick);
// 多表头的操作列使用 BandedGridView,复用基类的禁编按钮点击处理。
this.bandedGridView.MouseDown += GridView_MouseDown;
this.bandedGridView.CustomDrawGroupRow += new RowObjectCustomDrawEventHandler(OnGridCustomDrawGroupRow);
this.bandedGridView.LeftCoordChanged += OnBandedLeftCoordChanged;
this.SetGridRowHeightAndFont();
@@ -133,6 +135,236 @@ namespace Lskj.Control
this.bandedGridView.ShowingEditor += GridView_ShowingEditor;
}
/// <summary>
/// 多表头创建或重建操作列。
/// 操作列不参与业务列配置,只挂到空白一级表头的最右侧。
/// </summary>
protected override void TryInitRightMenuBtnEdit(bool rebuild)
{
if (!this.gridColumnsInitialized || this.Model == null ||
(this.CustomColumKey ?? string.Empty).Contains("BaseLeftGridView_"))
{
return;
}
BandedGridColumn oldColumn = this.bandedGridView.Columns["RightMenuBtnEdit"];
bool showButtonColumn = this.rightMenuButtonTable != null &&
this.rightMenuButtonTable.Rows.Cast<DataRow>().Any(row =>
(row.Table.Columns.Contains("IcoName") &&
!string.IsNullOrWhiteSpace(row["IcoName"] + "")) ||
(row.Table.Columns.Contains("showtoolbar") &&
"1".Equals(row["showtoolbar"] + "")));
if (!showButtonColumn)
{
if (oldColumn != null)
{
this.RemoveRightMenuButtonColumn(oldColumn);
}
return;
}
if (oldColumn != null)
{
if (!rebuild)
{
return;
}
this.RemoveRightMenuButtonColumn(oldColumn);
}
this.InitRightMenuBtnEdit(this.rightMenuButtonTable);
DataTable dataSource = this.GridControl == null ? null : this.GridControl.DataSource as DataTable;
if (dataSource != null && !dataSource.Columns.Contains("RightMenuBtnEdit"))
{
dataSource.Columns.Add("RightMenuBtnEdit");
}
}
/// <summary>
/// 删除旧操作列,同时保持空白一级表头下其他列的现有宽度。
/// </summary>
private void RemoveRightMenuButtonColumn(BandedGridColumn oldColumn)
{
GridBand ownerBand = oldColumn.OwnerBand;
int oldColumnWidth = oldColumn.Width;
int originalBandWidth = ownerBand == null ? 0 : ownerBand.Width;
Dictionary<BandedGridColumn, int> originalColumnWidths = ownerBand == null
? new Dictionary<BandedGridColumn, int>()
: ownerBand.Columns.Cast<BandedGridColumn>()
.Where(column => column != oldColumn)
.ToDictionary(column => column, column => column.Width);
this.bandedGridView.BeginUpdate();
try
{
this.bandedGridView.Columns.Remove(oldColumn);
if (ownerBand == null)
{
return;
}
if (ownerBand.Columns.Count == 0)
{
this.bandedGridView.Bands.Remove(ownerBand);
}
else
{
ownerBand.Width = Math.Max(0, originalBandWidth - oldColumnWidth);
foreach (KeyValuePair<BandedGridColumn, int> item in originalColumnWidths)
{
item.Key.Width = item.Value;
}
}
}
finally
{
this.bandedGridView.EndUpdate();
}
}
/// <summary>
/// 创建多表头操作列,并将其放到空白一级表头的最右侧。
/// </summary>
protected override void InitRightMenuBtnEdit(DataTable rightMenuTab)
{
if (rightMenuTab == null)
{
return;
}
BandedGridColumn gridColumn = new BandedGridColumn();
gridColumn.FieldName = "RightMenuBtnEdit";
gridColumn.Name = "RightMenuBtnEdit";
gridColumn.Caption = "操作列";
gridColumn.Visible = true;
gridColumn.OptionsColumn.AllowEdit = true;
RepositoryItemButtonEdit itemButtonEdit = new RepositoryItemButtonEdit();
itemButtonEdit.Buttons.Clear();
itemButtonEdit.AppearanceDisabled.Options.UseTextOptions = true;
itemButtonEdit.AppearanceDisabled.TextOptions.HAlignment = HorzAlignment.Center;
itemButtonEdit.TextEditStyle = TextEditStyles.HideTextEditor;
itemButtonEdit.ButtonsStyle = BorderStyles.UltraFlat;
itemButtonEdit.BorderStyle = BorderStyles.NoBorder;
itemButtonEdit.ButtonClick += new ButtonPressedEventHandler(OnItemButtonEdit_ButtonClick);
int columnWidth = 0;
if (rightMenuTab.Columns.Contains("IcoName"))
{
DataRow[] rightMenuButtons = rightMenuTab.Select()
.Where(n => !string.IsNullOrEmpty(n["IcoName"] + ""))
.ToArray();
int pictureWidth = 30;
foreach (DataRow rightMenu in rightMenuButtons)
{
GridRightMenuModel menuModel = new GridRightMenuModel(rightMenu);
if (string.IsNullOrWhiteSpace(menuModel.MenuName))
{
continue;
}
EditorButton editorButton = new EditorButton();
editorButton.Appearance.BackColor = Color.Transparent;
if (!string.IsNullOrEmpty(menuModel.IcoName))
{
try
{
Image image = GetRightMenuButtonImage(menuModel.IcoName);
if (image != null && image.Width > 30)
{
pictureWidth = image.Width;
}
editorButton.Image = image;
}
catch (Exception)
{
}
}
editorButton.ToolTip = menuModel.MenuName;
editorButton.Kind = ButtonPredefines.Glyph;
editorButton.Width = pictureWidth;
editorButton.Tag = menuModel;
itemButtonEdit.Buttons.Add(editorButton);
}
columnWidth = rightMenuButtons.Length * pictureWidth;
}
if (rightMenuTab.Columns.Contains("showtoolbar"))
{
DataRow[] rightMenuTextButtons = rightMenuTab.Select()
.Where(n => "1".Equals(n["showtoolbar"] + ""))
.ToArray();
foreach (DataRow rightMenu in rightMenuTextButtons)
{
GridRightMenuModel menuModel = new GridRightMenuModel(rightMenu);
if (string.IsNullOrWhiteSpace(menuModel.MenuName))
{
continue;
}
EditorButton editorButton = new EditorButton();
editorButton.Caption = menuModel.MenuName + "";
editorButton.ToolTip = menuModel.MenuName;
editorButton.Kind = ButtonPredefines.Glyph;
editorButton.Width = this.CalculateTextWidth(editorButton.Caption, editorButton.Appearance.Font);
editorButton.Tag = menuModel;
editorButton.Appearance.BackColor = Color.FromArgb(240, 240, 240);
editorButton.Appearance.BorderColor = Color.FromArgb(180, 180, 180);
editorButton.Appearance.ForeColor = Color.FromArgb(50, 50, 50);
editorButton.Appearance.Options.UseBackColor = true;
editorButton.Appearance.Options.UseBorderColor = true;
editorButton.Appearance.Options.UseForeColor = true;
itemButtonEdit.Buttons.Add(editorButton);
columnWidth += editorButton.Width;
}
}
gridColumn.ColumnEdit = itemButtonEdit;
gridColumn.MaxWidth = columnWidth;
gridColumn.MinWidth = columnWidth;
gridColumn.Width = columnWidth;
GridBand emptyBand = this.bandedGridView.Bands.Cast<GridBand>()
.FirstOrDefault(x => string.IsNullOrEmpty(x.Caption));
if (emptyBand == null)
{
emptyBand = new GridBand();
emptyBand.Caption = "";
emptyBand.AppearanceHeader.Options.UseFont = true;
emptyBand.AppearanceHeader.Font = new Font("宋体", 9, FontStyle.Bold);
emptyBand.AppearanceHeader.Options.UseTextOptions = true;
emptyBand.AppearanceHeader.TextOptions.HAlignment = HorzAlignment.Center;
this.bandedGridView.Bands.Add(emptyBand);
}
int originalBandWidth = emptyBand.Width;
Dictionary<BandedGridColumn, int> originalColumnWidths = emptyBand.Columns
.Cast<BandedGridColumn>()
.ToDictionary(column => column, column => column.Width);
this.bandedGridView.BeginUpdate();
try
{
emptyBand.Columns.Add(gridColumn);
this.bandedGridView.Columns.Add(gridColumn);
gridColumn.ColVIndex = emptyBand.Columns.Count - 1;
// DevExpress 默认保持 Band 总宽度,新增列时会压缩同一 Band 下的原列。
// 恢复原列宽,并单独为操作列扩展一级表头宽度。
emptyBand.Width = originalBandWidth + columnWidth;
foreach (KeyValuePair<BandedGridColumn, int> item in originalColumnWidths)
{
item.Key.Width = item.Value;
}
gridColumn.Width = columnWidth;
}
finally
{
this.bandedGridView.EndUpdate();
}
this.bandedGridView.OptionsBehavior.EditorShowMode = EditorShowMode.MouseDown;
}
/// <summary>
@@ -574,6 +806,7 @@ namespace Lskj.Control
protected void AddBandColumns(DataTable table, bool readOnly = true)
{
if (table == null) return;
this.gridColumnsInitialized = false;
this.InitGridColumsTab = table;
this.mControlList.Clear();
List<String> bandFieldstr = new List<String>();
@@ -844,6 +1077,8 @@ namespace Lskj.Control
// 加载数据源
//BindDataSource();
this.SetCustomColumns();//加载多表头自定义列
this.gridColumnsInitialized = true;
this.TryInitRightMenuBtnEdit(false);
//多表头冻结
foreach (BandedGridColumn item in FrozenColumns)
+7 -1
View File
@@ -178,6 +178,12 @@ namespace Lskj.Control
foreach (GridColumn col in gridView.Columns)
{
if (col.FieldName.Equals("RightMenuBtnEdit", StringComparison.OrdinalIgnoreCase))
{
// 操作列仅用于界面按钮,不应进入导出结果。
hasBoolean = true;
continue;
}
if ((col.ColumnEdit != null && col.ColumnEdit.GetType() == typeof(RepositoryItemCheckEdit)) ||
(col.ColumnType != null && col.ColumnType.Name.ToLower() == "boolean"))
{
@@ -209,7 +215,7 @@ namespace Lskj.Control
foreach (BandedGridColumn col in gridView.Columns)
{
GridColumnModel gridModel = col.Tag as GridColumnModel;
if (col.Visible)
if (col.Visible && !col.FieldName.Equals("RightMenuBtnEdit", StringComparison.OrdinalIgnoreCase))
{
BandedGridColumn newCol = new BandedGridColumn();
newCol.Tag = col.Tag;
+21 -21
View File
@@ -184,8 +184,8 @@ namespace Lskj.Control
/// <summary>
/// 外部设置的右键菜单数据,用于创建每行操作列。
/// </summary>
private DataTable rightMenuButtonTable;
private bool gridColumnsInitialized;
protected DataTable rightMenuButtonTable;
protected bool gridColumnsInitialized;
/// <summary>
/// 新版模块选择框缓存。同一关联模块的单选和多选界面分别复用。
@@ -5649,8 +5649,8 @@ namespace Lskj.Control
/// </summary>
internal void SetRightMenuButtonTable(DataTable table)
{
// 树表格和多表头表格原来不在此处创建操作列,维持原有行为
if (this is TreeGridControlEx || this is BandedGridControlEx)
// 树表格仍由原有逻辑处理,不创建操作列
if (this is TreeGridControlEx)
{
return;
}
@@ -5659,7 +5659,7 @@ namespace Lskj.Control
this.TryInitRightMenuBtnEdit(true);
}
private void TryInitRightMenuBtnEdit(bool rebuild)
protected virtual void TryInitRightMenuBtnEdit(bool rebuild)
{
if (!this.gridColumnsInitialized || this.Model == null ||
this.CustomColumKey.Contains("BaseLeftGridView_"))
@@ -5689,7 +5689,7 @@ namespace Lskj.Control
}
}
private void InitRightMenuBtnEdit(DataTable rightMenuTab)
protected virtual void InitRightMenuBtnEdit(DataTable rightMenuTab)
{
GridColumn gridColumn = new GridColumn();
gridColumn.FieldName = "RightMenuBtnEdit";
@@ -9771,7 +9771,7 @@ namespace Lskj.Control
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void OnItemButtonEdit_ButtonClick(object sender, ButtonPressedEventArgs e)
protected void OnItemButtonEdit_ButtonClick(object sender, ButtonPressedEventArgs e)
{
EditorButton editorButton = e.Button as EditorButton;
GridRightMenuModel menuModel = editorButton.Tag as GridRightMenuModel;
@@ -9779,8 +9779,8 @@ namespace Lskj.Control
if (toolStripMenuItem != null)
{
bool allowClick = true;
int[] mSelectRows = this.gridView.GetSelectedRows();
DataRow mSelectRow = this.gridView.GetDataRow(mSelectRows[0]);
int[] mSelectRows = this.GridView.GetSelectedRows();
DataRow mSelectRow = this.GridView.GetDataRow(mSelectRows[0]);
if (menuModel != null)
{
if (menuModel.PrivilegeOper.Length > 1 && !menuModel.PrivilegeOper.Contains(ERPInfo.Instance.UserName + ","))
@@ -9797,13 +9797,13 @@ namespace Lskj.Control
if (this.gridViewRightMenu.ControlObj != null)
cond = this.gridViewRightMenu.ControlObj.ReplaceParentControlValue(menuModel.MenuCond);
cond = ReplaceHelper.ReplaceRowParam(mSelectRow, menuModel.MenuCond);
if (this.gridView != null)
if (this.GridView != null)
{
GridCell[] cells = this.gridView.GetSelectedCells();
GridCell[] cells = this.GridView.GetSelectedCells();
if (cells != null && cells.Length > 0 && cond.Contains("{COLUMN_"))
{
GridCell cell = cells[0];
DataRow focusedRow = this.gridView.GetFocusedDataRow();
DataRow focusedRow = this.GridView.GetFocusedDataRow();
string colValue = focusedRow == null || !focusedRow.Table.Columns.Contains(cell.Column.Name) ? "" : focusedRow[cell.Column.Name] + "";
cond = cond.ReplaceColumnParam(cell.Column.Name, cell.Column.Caption, colValue);
}
@@ -11113,7 +11113,7 @@ namespace Lskj.Control
return Math.Max(textWidth + padding, 40);
}
private Image GetRightMenuButtonImage(string imageName)
protected Image GetRightMenuButtonImage(string imageName)
{
if (string.IsNullOrWhiteSpace(imageName))
{
@@ -11177,7 +11177,7 @@ namespace Lskj.Control
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void GridView_MouseDown(object sender, MouseEventArgs e)
protected void GridView_MouseDown(object sender, MouseEventArgs e)
{
if (e.Button != MouseButtons.Left) return;
@@ -11190,7 +11190,7 @@ namespace Lskj.Control
RepositoryItemButtonEdit repo = hitInfo.Column.ColumnEdit as RepositoryItemButtonEdit;
if (!hitInfo.Column.FieldName.Equals("RightMenuBtnEdit")) return;
int rowHandle = hitInfo.RowHandle;
this.gridView.SelectRowHandler(rowHandle);
view.SelectRowHandler(rowHandle);
int buttonIndex = this.GetClickedButtonIndex(repo, view, rowHandle, hitInfo.Column, e.Location, hitInfo.Column.Width);
if (buttonIndex != -1)
@@ -11207,7 +11207,7 @@ namespace Lskj.Control
/// 执行点击的右键按钮
/// </summary>
/// <param name="editorButton"></param>
private void RightButtonClick(EditorButton editorButton)
protected void RightButtonClick(EditorButton editorButton)
{
GridRightMenuModel menuModel = editorButton.Tag as GridRightMenuModel;
@@ -11215,8 +11215,8 @@ namespace Lskj.Control
if (toolStripMenuItem != null)
{
bool allowClick = true;
int[] mSelectRows = this.gridView.GetSelectedRows();
DataRow mSelectRow = this.gridView.GetDataRow(mSelectRows[0]);
int[] mSelectRows = this.GridView.GetSelectedRows();
DataRow mSelectRow = this.GridView.GetDataRow(mSelectRows[0]);
if (menuModel != null)
{
if (menuModel.PrivilegeOper.Length > 1 && !menuModel.PrivilegeOper.Contains(ERPInfo.Instance.UserName + ","))
@@ -11233,13 +11233,13 @@ namespace Lskj.Control
if (this.gridViewRightMenu.ControlObj != null)
cond = this.gridViewRightMenu.ControlObj.ReplaceParentControlValue(menuModel.MenuCond);
cond = ReplaceHelper.ReplaceRowParam(mSelectRow, menuModel.MenuCond);
if (this.gridView != null)
if (this.GridView != null)
{
GridCell[] cells = this.gridView.GetSelectedCells();
GridCell[] cells = this.GridView.GetSelectedCells();
if (cells != null && cells.Length > 0 && cond.Contains("{COLUMN_"))
{
GridCell cell = cells[0];
DataRow focusedRow = this.gridView.GetFocusedDataRow();
DataRow focusedRow = this.GridView.GetFocusedDataRow();
string colValue = focusedRow == null || !focusedRow.Table.Columns.Contains(cell.Column.Name) ? "" : focusedRow[cell.Column.Name] + "";
cond = cond.ReplaceColumnParam(cell.Column.Name, cell.Column.Caption, colValue);
}
@@ -622,6 +622,8 @@ namespace Lskj.Control.Model
}
GridColumnModel model = col.Tag as GridColumnModel;
// 操作列是运行时创建的界面列,不参与个性化保存。
if (model == null) continue;
DataRow a = customTable.Rows.Cast<DataRow>().FirstOrDefault(x => col.Name.Equals(x["fieldName"] + "", StringComparison.OrdinalIgnoreCase));
string tempSql = a == null ? string.Format(@"insert into {8}(formkey,fieldname,username,orderid,isvisible,operatorid,operatorName,operatedate,fieldWidth,IfFixColumn,FieldText {11}) values('{0}','{1}','{2}','{3}','{4}','{5}','{6}',getdate(),'{7}','{9}','{10}' {12});",
key, col.FieldName, col.Caption, col.VisibleIndex, Convert.ToInt32(col.Visible), ERPInfo.Instance.UserId, ERPInfo.Instance.UserName, col.Width, ResourceKeys.SettingTableName, col.OwnerBand != null ? col.OwnerBand.Fixed == DevExpress.XtraGrid.Columns.FixedStyle.Left ? 1 : 0 : 0, model.FieldText, saveFieldName, fieldValue) : string.Format(@"update {6} set orderid='{0}',fieldWidth='{1}',isvisible={2},IfFixColumn='{7}' {8} where formkey='{3}' and fieldname='{4}' and operatorid='{5}';",
@@ -1146,6 +1148,8 @@ namespace Lskj.Control.Model
gridControl.gridViewRightMenu = rightMenu;
rightMenu.InitRightMenus(gridControl, table, model, control, menu);
rightMenu.SetRightCallback(handler);
// 右键菜单创建完成后再生成多表头操作列,确保按钮数据完整。
gridControl.SetRightMenuButtonTable(table);
}
/// <summary>
/// <para>说明:设置图标右键菜单</para>
@@ -358,6 +358,11 @@ namespace Lskj.Control
tcButtom.OnDetailRightCallback += OnGridViewRightCallBack;
}
if (this.SysModel.RefreshTheInterface)
{
}
this.tcButtom.Model = this.Model;
this.tcButtom.DrgaParentPrimaryKey = this.SysModel.ParmaryKey;
this.tcButtom.IsDragDetail = this.IsDragDetail;
@@ -387,6 +392,11 @@ namespace Lskj.Control
tcButtom.OnDetailRightCallback += OnGridViewRightCallBack;
}
if (this.SysModel.RefreshTheInterface)
{
}
this.tcButtom.Model = this.Model;
this.tcButtom.DrgaParentPrimaryKey = this.SysModel.ParmaryKey;
this.tcButtom.IsDragDetail = this.IsDragDetail;
+10
View File
@@ -142,6 +142,13 @@ namespace Lskj.Control
/// </summary>
public event EventHandler BillDetailRightGridCallBack;
/// <summary>
/// 新版左右结构下,左侧或者右侧的表格数据改变后,刷新主表数据(主表刷新后会刷新当前明细或者全部明细)
/// </summary>
/// <param name="sender">The sender.</param>
public event EventHandler OnDataChangeExecution;
/// <summary>
/// 明细页签与主模块对应关系
/// </summary>
@@ -181,6 +188,9 @@ namespace Lskj.Control
/// 页签名(判断是否有重复的左右结构)
/// </summary>
public string DetaiName = string.Empty;
public TabControlEx()
{
InitializeComponent();