Files
lserp_cs_6.0/插件库/Lskj.PubCodeDesign/CodeDesignModuleGridEx.cs
T
2026-07-16 16:05:38 +08:00

111 lines
3.7 KiB
C#

using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Reflection;
using System.Windows.Forms;
using Lskj.Control;
namespace Lskj.PubCodeDesign
{
internal class CodeDesignModuleGridEx : ModuleGridEx
{
protected override void OnCreateControl()
{
base.OnCreateControl();
HideTopToolPanel();
}
public void HideTopToolPanel()
{
CollapseChildControl(this, "pl_top");
HideChildControl(this, "pl_top_right");
HideChildControl(this, "ddbOper");
HideChildControl(this, "ddbPrint");
HideChildControl(this, "btnRefresh");
}
public void AddNewLogic()
{
this.ExternallyTriggeredAdd();
}
public void EnsureHiddenSaveColumns(IEnumerable<string> fieldNames)
{
DataTable gridColumns = GetGridColumns();
if (gridColumns == null || fieldNames == null) return;
foreach (string fieldName in fieldNames.Where(n => !string.IsNullOrWhiteSpace(n)))
{
EnsureHiddenGridColumn(gridColumns, fieldName);
}
}
private DataTable GetGridColumns()
{
FieldInfo field = typeof(ModuleGridEx).GetField("_gridColumns", BindingFlags.Instance | BindingFlags.NonPublic);
return field == null ? null : field.GetValue(this) as DataTable;
}
private static void EnsureHiddenGridColumn(DataTable gridColumns, string fieldName)
{
if (gridColumns.Rows.Cast<DataRow>().Any(n => string.Equals(n["fieldname"] + "", fieldName, StringComparison.OrdinalIgnoreCase)))
{
return;
}
DataRow row = gridColumns.NewRow();
SetColumnValue(row, "fieldname", fieldName);
SetColumnValue(row, "username", fieldName);
SetColumnValue(row, "sysname", fieldName);
SetColumnValue(row, "width", 0);
SetColumnValue(row, "visible", 0);
SetColumnValue(row, "fieldtype", 1);
SetColumnValue(row, "fieldTypeId", 1);
SetColumnValue(row, "nullable", 1);
SetColumnValue(row, "edited", 1);
SetColumnValue(row, "sortid", 9999);
gridColumns.Rows.Add(row);
}
private static void SetColumnValue(DataRow row, string columnName, object value)
{
if (row == null || row.Table == null || !row.Table.Columns.Contains(columnName)) return;
row[columnName] = value ?? DBNull.Value;
}
private static void CollapseChildControl(System.Windows.Forms.Control parent, string controlName)
{
if (parent == null || string.IsNullOrWhiteSpace(controlName)) return;
foreach (System.Windows.Forms.Control child in parent.Controls)
{
if (string.Equals(child.Name, controlName, StringComparison.OrdinalIgnoreCase))
{
child.Visible = false;
child.Height = 0;
child.Margin = Padding.Empty;
}
CollapseChildControl(child, controlName);
}
}
private static void HideChildControl(System.Windows.Forms.Control parent, string controlName)
{
if (parent == null || string.IsNullOrWhiteSpace(controlName)) return;
foreach (System.Windows.Forms.Control child in parent.Controls)
{
if (string.Equals(child.Name, controlName, StringComparison.OrdinalIgnoreCase))
{
child.Visible = false;
}
HideChildControl(child, controlName);
}
}
}
}