feat: 优化主界面及控件功能

This commit is contained in:
cyf
2026-08-30 12:00:03 +08:00
parent 24653fbe6c
commit 641d3c232d
6 changed files with 300 additions and 40 deletions
+54 -1
View File
@@ -6530,6 +6530,8 @@ namespace Lskj.Control
this.gridView.RowCount > 0 &&
this.gridView.OptionsBehavior.Editable)
{
GridColumnModel model = column.Tag as GridColumnModel;
// 允许操作
int focusedRowHandle = this.gridView.FocusedRowHandle;
int totalRowCount = this.gridView.RowCount;
@@ -6544,7 +6546,58 @@ namespace Lskj.Control
int valueNum = 0;
object obj = this.gridView.GetFocusedRowCellValue(column);
if (!string.IsNullOrEmpty(obj + ""))
if (model != null && (ControlType.IsDate(model.FieldType) || model.FieldType == ControlType.LabShortDate))
{
DateTime dateValue;
if (!DateTime.TryParse(obj + "", out dateValue))
{
MessageUtil.Show("当前单元格不是有效日期,无法按日期生成。");
e.Handled = true;
return;
}
string dateFormat = DateFormat.Format(model.FieldType);
bool onlyYear = !string.IsNullOrEmpty(dateFormat)
&& dateFormat.IndexOf("y", StringComparison.OrdinalIgnoreCase) >= 0
&& dateFormat.IndexOf("M", StringComparison.Ordinal) < 0
&& dateFormat.IndexOf("d", StringComparison.OrdinalIgnoreCase) < 0;
bool onlyMonth = !string.IsNullOrEmpty(dateFormat)
&& dateFormat.IndexOf("M", StringComparison.Ordinal) >= 0
&& dateFormat.IndexOf("d", StringComparison.OrdinalIgnoreCase) < 0;
this.gridView.BeginUpdate();
this.gridView.BeginDataUpdate();
try
{
for (int i = focusedRowHandle; i < totalRowCount; i++)
{
gridView.SetRowCellValue(i, column, dateValue);
if (onlyYear)
{
dateValue = dateValue.AddYears(1);
}
else if (onlyMonth)
{
dateValue = dateValue.AddMonths(1);
}
else
{
dateValue = dateValue.AddDays(1);
}
}
}
finally
{
this.gridView.EndDataUpdate();
this.gridView.EndUpdate();
}
gridView.FocusedRowHandle = totalRowCount - 1;
e.Handled = true;
return;
}
else if (!string.IsNullOrEmpty(obj + ""))
{
//isExec = Int64.TryParse(obj + "", out value);
Regex regex = new Regex(@"\D", RegexOptions.RightToLeft);
+15 -19
View File
@@ -435,27 +435,23 @@ namespace Lskj.Control.Model
{
BaseUserControl baseControl = control as BaseUserControl;
baseControl.Location = model.Location;
System.Threading.SynchronizationContext.Current.Post(SetProperty, null);
void SetProperty(object state)
// 控件创建、属性设置和挂载必须保持在同一条 UI 线程上,避免 WPF 宿主下 Timer 先执行。
baseControl.Model = model;
baseControl.FontSize = model.FontSize;
baseControl.Name = "txt_" + model.FieldName;
baseControl.LabelText = model.LabelText;
baseControl.NullText = model.NullText;
//baseControl.EditText = model.DefaultValue;
//baseControl.Location = model.Location;
baseControl.Size = model.Size;
if (!model.ReadOnly && !string.IsNullOrWhiteSpace(model.ControlTitleColor))
{
//放到外面避免线程问题
baseControl.Model = model;
baseControl.FontSize = model.FontSize;
baseControl.Name = "txt_" + model.FieldName;
baseControl.LabelText = model.LabelText;
baseControl.NullText = model.NullText;
//baseControl.EditText = model.DefaultValue;
//baseControl.Location = model.Location;
baseControl.Size = model.Size;
if (!model.ReadOnly && !string.IsNullOrWhiteSpace(model.ControlTitleColor))
{
baseControl.ModifyDefaultColors(ColorTranslator.FromHtml(model.ControlTitleColor));
}
baseControl.ReadOnly = model.ReadOnly;
baseControl.Required = model.IsEmpty;
baseControl.Tag = model;
baseControl.TabIndex = model.TabOrder;
baseControl.ModifyDefaultColors(ColorTranslator.FromHtml(model.ControlTitleColor));
}
baseControl.ReadOnly = model.ReadOnly;
baseControl.Required = model.IsEmpty;
baseControl.Tag = model;
baseControl.TabIndex = model.TabOrder;
for (int i = 0; i < startLocktion.Count; i++)
{
+9 -8
View File
@@ -255,9 +255,10 @@ namespace Lskj.Control
/// <summary>
/// 设置当前页签内 ModuleGridEx 底部操作栏是否可交互。
/// 只处理左右结构右侧页签里直接承载的 ModuleGridEx,不影响普通页签和左侧表。
/// 左右结构中,右侧明细是否允许操作由左侧主表是否有数据决定,
/// 不能使用右侧明细查询结果判断,否则右侧为空时无法新增第一行。
/// </summary>
private void SetModuleGridBottomPanelEnabled(XtraTabPage tabPage, bool enabled)
private void SetModuleGridBottomPanelEnabled(XtraTabPage tabPage, GridControlEx leftGrid)
{
if (tabPage == null) return;
if (!_rightSideTabPages.Contains(tabPage)) return;
@@ -265,7 +266,7 @@ namespace Lskj.Control
ModuleGridEx moduleGrid = tabPage.Controls.OfType<ModuleGridEx>().FirstOrDefault();
if (moduleGrid != null && moduleGrid.ObjPanel != null)
{
moduleGrid.ObjPanel.Enabled = enabled;
moduleGrid.ObjPanel.Enabled = leftGrid != null && leftGrid.DataRowCount() > 0;
}
}
#endregion
@@ -286,7 +287,7 @@ namespace Lskj.Control
if (model == null)
{
BindTableToPage(tabPage, new DataTable());
SetModuleGridBottomPanelEnabled(tabPage, false);
SetModuleGridBottomPanelEnabled(tabPage, leftGrid);
return;
}
@@ -311,12 +312,12 @@ namespace Lskj.Control
sqlValue = ReplaceHelper.ReplaceWhereCond(sqlValue);
DataTable dt = MainImpl.GetDataTableResult(sqlValue);
BindTableToPage(tabPage, dt);
SetModuleGridBottomPanelEnabled(tabPage, dt != null && dt.Rows.Count > 0);
SetModuleGridBottomPanelEnabled(tabPage, leftGrid);
}
else
{
BindTableToPage(tabPage, new DataTable());
SetModuleGridBottomPanelEnabled(tabPage, false);
SetModuleGridBottomPanelEnabled(tabPage, leftGrid);
}
return;
}
@@ -335,7 +336,7 @@ namespace Lskj.Control
if (!visible)
{
BindTableToPage(tabPage, new DataTable());
SetModuleGridBottomPanelEnabled(tabPage, false);
SetModuleGridBottomPanelEnabled(tabPage, leftGrid);
return;
}
}
@@ -418,7 +419,7 @@ namespace Lskj.Control
DataTable table = MainImpl.GetDataTableResult(finalSql);
BindTableToPage(tabPage, table, finalSql);
SetModuleGridBottomPanelEnabled(tabPage, table != null && table.Rows.Count > 0);
SetModuleGridBottomPanelEnabled(tabPage, leftGrid);
tabPage.Text = $"{model.DetailName}({table.Rows.Count}条)";
tabPage.Appearance.Header.ForeColor = table.Rows.Count > 0 ? Color.Red : Color.FromArgb(0, 0, 0);
// 首次加载自动查询