提交当前本机最新程序
This commit is contained in:
@@ -192,6 +192,30 @@ namespace Lskj.Control
|
||||
/// </summary>
|
||||
public Dictionary<GridColumnModel, Task<DataTable>> mControlSourceDic = new Dictionary<GridColumnModel, Task<DataTable>>();
|
||||
/// <summary>
|
||||
/// 字典搜索框数据源缓存,只用于弹出下拉框时临时绑定,避免表格滚动时控件持有大数据源。
|
||||
/// </summary>
|
||||
private Dictionary<string, DataTable> mSpecialReturnSourceDic = new Dictionary<string, DataTable>();
|
||||
/// <summary>
|
||||
/// 字典搜索框后台加载任务缓存。
|
||||
/// </summary>
|
||||
private Dictionary<string, Task<DataTable>> mSpecialReturnSourceTaskDic = new Dictionary<string, Task<DataTable>>();
|
||||
/// <summary>
|
||||
/// 字典搜索框显示文本缓存,表格显示时按单元格值快速转换为显示文本。
|
||||
/// </summary>
|
||||
private Dictionary<string, Dictionary<string, string>> mSpecialReturnDisplayDic = new Dictionary<string, Dictionary<string, string>>();
|
||||
/// <summary>
|
||||
/// 字典搜索框编辑器缓存,进入编辑状态时再替换为搜索框控件。
|
||||
/// </summary>
|
||||
private Dictionary<string, RepositoryItemGridLookUpEdit> mSpecialReturnEditDic = new Dictionary<string, RepositoryItemGridLookUpEdit>();
|
||||
/// <summary>
|
||||
/// 字典搜索框显示文本事件是否已绑定。
|
||||
/// </summary>
|
||||
private bool mSpecialReturnDisplayEventAttached = false;
|
||||
/// <summary>
|
||||
/// 字典搜索框编辑器替换事件是否已绑定。
|
||||
/// </summary>
|
||||
private bool mSpecialReturnEditEventAttached = false;
|
||||
/// <summary>
|
||||
/// 计算值
|
||||
/// </summary>
|
||||
public decimal customSum;
|
||||
@@ -995,7 +1019,7 @@ namespace Lskj.Control
|
||||
return;
|
||||
}
|
||||
|
||||
if (!string.IsNullOrEmpty(model.SqlSource) && !ControlType.IsNotLoadData(model.FieldType))
|
||||
if (!string.IsNullOrEmpty(model.SqlSource) && !ControlType.IsNotLoadData(model.FieldType) && !IsSpecialReturnBox(model.FieldType))
|
||||
{
|
||||
Task<DataTable> sourceTask = new Task<DataTable>(() =>
|
||||
{
|
||||
@@ -1191,6 +1215,12 @@ namespace Lskj.Control
|
||||
case ControlType.LabModuleAddRowsText:
|
||||
InitModuleReturnLine(column, model);
|
||||
break;
|
||||
case ControlType.DictionarySearchBoxToId:
|
||||
case ControlType.DictionarySearchBoxToText:
|
||||
case ControlType.DictionarySearchBoxToIdParam:
|
||||
case ControlType.DictionarySearchBoxToTextParam:
|
||||
InitSpecialReturn(column, model);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
@@ -1201,6 +1231,567 @@ namespace Lskj.Control
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 初始化字典搜索框。表格显示阶段使用文本编辑器,进入编辑状态时再切换为搜索框。
|
||||
/// </summary>
|
||||
private void InitSpecialReturn(GridColumn column, GridColumnModel model)
|
||||
{
|
||||
RepositoryItemGridLookUpEdit searchEdit = CreateSpecialReturnSearchEdit(model);
|
||||
RepositoryItemTextEdit textEdit = new RepositoryItemTextEdit();
|
||||
|
||||
gridControl.RepositoryItems.Add(textEdit);
|
||||
gridControl.RepositoryItems.Add(searchEdit);
|
||||
column.ColumnEdit = textEdit;
|
||||
|
||||
mSpecialReturnEditDic[model.FieldName] = searchEdit;
|
||||
this.mControlList.Add(model);
|
||||
StartSpecialReturnSourceTask(model);
|
||||
|
||||
if (!mSpecialReturnDisplayEventAttached)
|
||||
{
|
||||
this.gridView.CustomColumnDisplayText += GridView_CustomColumnDisplayText_SpecialReturn;
|
||||
mSpecialReturnDisplayEventAttached = true;
|
||||
}
|
||||
if (!mSpecialReturnEditEventAttached)
|
||||
{
|
||||
this.gridView.CustomRowCellEditForEditing += GridView_CustomRowCellEditForEditing_SpecialReturn;
|
||||
mSpecialReturnEditEventAttached = true;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 判断是否为字典搜索框类型。
|
||||
/// </summary>
|
||||
private static bool IsSpecialReturnBox(int fieldType)
|
||||
{
|
||||
return fieldType == ControlType.DictionarySearchBoxToId
|
||||
|| fieldType == ControlType.DictionarySearchBoxToText
|
||||
|| fieldType == ControlType.DictionarySearchBoxToIdParam
|
||||
|| fieldType == ControlType.DictionarySearchBoxToTextParam;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 判断字典搜索框是否保存显示文本。
|
||||
/// </summary>
|
||||
private static bool IsSpecialReturnTextBox(int fieldType)
|
||||
{
|
||||
return fieldType == ControlType.DictionarySearchBoxToText
|
||||
|| fieldType == ControlType.DictionarySearchBoxToTextParam;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 判断字典搜索框是否为带参数类型。
|
||||
/// </summary>
|
||||
private static bool IsSpecialReturnParamBox(int fieldType)
|
||||
{
|
||||
return fieldType == ControlType.DictionarySearchBoxToIdParam
|
||||
|| fieldType == ControlType.DictionarySearchBoxToTextParam;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 创建字典搜索框编辑器。
|
||||
/// </summary>
|
||||
private RepositoryItemGridLookUpEdit CreateSpecialReturnSearchEdit(GridColumnModel model)
|
||||
{
|
||||
RepositoryItemGridLookUpEdit searchEdit = new RepositoryItemGridLookUpEdit();
|
||||
if (model.FontSize > 0) searchEdit.View.Appearance.Row.Font = new Font("微软雅黑", model.FontSize);
|
||||
searchEdit.View.OptionsView.ShowIndicator = false;
|
||||
searchEdit.View.OptionsView.ColumnAutoWidth = false;
|
||||
searchEdit.PopupSizeable = true;
|
||||
searchEdit.PopupResizeMode = ResizeMode.Default;
|
||||
searchEdit.AllowFocused = true;
|
||||
searchEdit.ImmediatePopup = true;
|
||||
searchEdit.ShowFooter = false;
|
||||
searchEdit.NullText = "";
|
||||
searchEdit.TextEditStyle = TextEditStyles.Standard;
|
||||
searchEdit.PopupBorderStyle = PopupBorderStyles.Flat;
|
||||
searchEdit.AllowNullInput = DefaultBoolean.False;
|
||||
searchEdit.ShowPopupShadow = true;
|
||||
searchEdit.DisplayMember = model.TextMember;
|
||||
searchEdit.ValueMember = IsSpecialReturnTextBox(model.FieldType) ? model.TextMember : model.ValueMember;
|
||||
searchEdit.Tag = model;
|
||||
searchEdit.View.Tag = searchEdit;
|
||||
searchEdit.View.Appearance.HeaderPanel.TextOptions.HAlignment = HorzAlignment.Center;
|
||||
searchEdit.View.PopupMenuShowing += new PopupMenuShowingEventHandler(OnAutoSearchEditPopupMenuShowing);
|
||||
searchEdit.KeyDown += OnsearchEditKeyDown;
|
||||
searchEdit.QueryPopUp += SpecialReturnEdit_QueryPopUp;
|
||||
searchEdit.CloseUp += SpecialReturnEdit_CloseUp;
|
||||
searchEdit.Closed += SpecialReturnEdit_Closed;
|
||||
searchEdit.CustomDisplayText += SpecialReturnEdit_CustomDisplayText;
|
||||
searchEdit.EditValueChanging += gridLookUpEdit1_EditValueChanging;
|
||||
searchEdit.View.CustomDrawFilterPanel += OnCustomDrawFilterPanel;
|
||||
|
||||
GridColumn valueColumn = new GridColumn();
|
||||
valueColumn.Name = valueColumn.FieldName = model.ValueMember;
|
||||
valueColumn.Caption = "编码";
|
||||
valueColumn.Visible = model.ValueMember.Substring(0, 1) != "_";
|
||||
|
||||
GridColumn textColumn = new GridColumn();
|
||||
textColumn.Name = textColumn.FieldName = model.TextMember;
|
||||
textColumn.Caption = "名称";
|
||||
textColumn.Visible = model.TextMember.Substring(0, 1) != "_";
|
||||
|
||||
searchEdit.View.Columns.AddRange(new GridColumn[] { valueColumn, textColumn });
|
||||
return searchEdit;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 字典搜索框显示文本事件,表格滚动显示时只查字典,不绑定下拉框大数据源。
|
||||
/// </summary>
|
||||
private void GridView_CustomColumnDisplayText_SpecialReturn(object sender, CustomColumnDisplayTextEventArgs e)
|
||||
{
|
||||
try
|
||||
{
|
||||
GridColumnModel model = e.Column.Tag as GridColumnModel;
|
||||
if (model == null || !IsSpecialReturnBox(model.FieldType)) return;
|
||||
|
||||
string value = e.Value + "";
|
||||
if (string.IsNullOrWhiteSpace(value)) return;
|
||||
|
||||
string displayText = string.Empty;
|
||||
bool sourceReady = EnsureSpecialReturnSourceReady(model);
|
||||
if (TryGetSpecialReturnDisplayText(model, value, out displayText))
|
||||
{
|
||||
e.DisplayText = displayText;
|
||||
}
|
||||
else if (sourceReady)
|
||||
{
|
||||
e.DisplayText = string.Empty;
|
||||
}
|
||||
}
|
||||
catch
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 字典搜索框编辑器替换事件,只有进入编辑状态时才使用搜索框控件。
|
||||
/// </summary>
|
||||
private void GridView_CustomRowCellEditForEditing_SpecialReturn(object sender, CustomRowCellEditEventArgs e)
|
||||
{
|
||||
GridColumnModel model = e.Column.Tag as GridColumnModel;
|
||||
if (model == null || !IsSpecialReturnBox(model.FieldType)) return;
|
||||
if (mSpecialReturnEditDic.ContainsKey(model.FieldName))
|
||||
{
|
||||
RepositoryItemGridLookUpEdit searchEdit = mSpecialReturnEditDic[model.FieldName];
|
||||
BindSpecialReturnCurrentValue(searchEdit, model, this.gridView.GetRowCellValue(e.RowHandle, e.Column));
|
||||
e.RepositoryItem = searchEdit;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 字典搜索框编辑态显示文本事件,避免编辑器未绑定数据源时当前值显示为空。
|
||||
/// </summary>
|
||||
private void SpecialReturnEdit_CustomDisplayText(object sender, CustomDisplayTextEventArgs e)
|
||||
{
|
||||
RepositoryItemGridLookUpEdit edit = sender as RepositoryItemGridLookUpEdit;
|
||||
if (edit == null || e.Value == null) return;
|
||||
|
||||
GridColumnModel model = edit.Tag as GridColumnModel;
|
||||
if (model == null || !IsSpecialReturnBox(model.FieldType)) return;
|
||||
|
||||
string value = e.Value + "";
|
||||
if (string.IsNullOrWhiteSpace(value)) return;
|
||||
|
||||
string displayText = string.Empty;
|
||||
bool sourceReady = EnsureSpecialReturnSourceReady(model);
|
||||
if (TryGetSpecialReturnDisplayText(model, value, out displayText))
|
||||
{
|
||||
e.DisplayText = displayText;
|
||||
}
|
||||
else if (sourceReady)
|
||||
{
|
||||
e.DisplayText = string.Empty;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 字典搜索框弹出事件。普通类型使用缓存数据源,带参数类型按当前行条件重新查询。
|
||||
/// </summary>
|
||||
private void SpecialReturnEdit_QueryPopUp(object sender, CancelEventArgs e)
|
||||
{
|
||||
try
|
||||
{
|
||||
GridLookUpEdit edit = sender as GridLookUpEdit;
|
||||
if (edit == null) return;
|
||||
GridColumnModel model = edit.Properties.Tag as GridColumnModel;
|
||||
if (model == null) return;
|
||||
|
||||
CurrentOperColumnKey = Model.ModuleCode + "_" + model.FieldName;
|
||||
CurrentOperModel = model;
|
||||
|
||||
DataTable table = IsSpecialReturnParamBox(model.FieldType) ? GetSpecialReturnParamSourceTable(model) : GetSpecialReturnSourceTable(model);
|
||||
if (IsSpecialReturnParamBox(model.FieldType))
|
||||
{
|
||||
AddSpecialReturnManualData(model, table);
|
||||
}
|
||||
edit.Properties.DataSource = table;
|
||||
AddSpecialReturnViewColumns(edit.Properties, table, model);
|
||||
SetSpecialReturnPopupWidth(edit.Properties, table, model);
|
||||
CacheSpecialReturnDisplayValues(model, table);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
string Message = ErrorMessage.PromptErrorMessage(ex, Model.ModuleCode);
|
||||
MessageUtil.Show(Message, ex.Message);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 字典搜索框关闭选择事件,把本次选择结果补入显示字典。
|
||||
/// </summary>
|
||||
private void SpecialReturnEdit_CloseUp(object sender, CloseUpEventArgs e)
|
||||
{
|
||||
try
|
||||
{
|
||||
GridLookUpEdit edit = sender as GridLookUpEdit;
|
||||
if (edit == null) return;
|
||||
GridColumnModel model = edit.Properties.Tag as GridColumnModel;
|
||||
if (model == null || e.Value == null) return;
|
||||
|
||||
DataTable table = edit.Properties.DataSource as DataTable;
|
||||
if (table == null) return;
|
||||
|
||||
string value = e.Value + "";
|
||||
string valueMember = IsSpecialReturnTextBox(model.FieldType) ? model.TextMember : model.ValueMember;
|
||||
if (!table.Columns.Contains(valueMember) || !table.Columns.Contains(model.TextMember)) return;
|
||||
|
||||
DataRow row = table.Rows.Cast<DataRow>().FirstOrDefault(item => (item[valueMember] + "").Equals(value));
|
||||
if (row != null)
|
||||
{
|
||||
GetSpecialReturnDisplayDic(model)[value] = row[model.TextMember] + "";
|
||||
}
|
||||
|
||||
edit.EditValue = e.Value;
|
||||
GridColumn column = this.gridView.Columns[model.FieldName];
|
||||
if (column != null)
|
||||
{
|
||||
this.gridView.SetFocusedRowCellValue(column, e.Value);
|
||||
}
|
||||
this.gridView.PostEditor();
|
||||
this.gridView.UpdateCurrentRow();
|
||||
}
|
||||
catch
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 字典搜索框关闭后清空临时数据源,避免编辑器长期持有大量数据。
|
||||
/// </summary>
|
||||
private void SpecialReturnEdit_Closed(object sender, ClosedEventArgs e)
|
||||
{
|
||||
GridLookUpEdit edit = sender as GridLookUpEdit;
|
||||
if (edit != null)
|
||||
{
|
||||
edit.Properties.DataSource = null;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取字典搜索框初始化数据源,用于普通弹出和显示字典缓存。
|
||||
/// </summary>
|
||||
private DataTable GetSpecialReturnSourceTable(GridColumnModel model)
|
||||
{
|
||||
string key = model.FieldName;
|
||||
if (mSpecialReturnSourceDic.ContainsKey(key))
|
||||
{
|
||||
return mSpecialReturnSourceDic[key];
|
||||
}
|
||||
if (mSpecialReturnSourceTaskDic.ContainsKey(key))
|
||||
{
|
||||
DataTable taskTable = mSpecialReturnSourceTaskDic[key].Result;
|
||||
mSpecialReturnSourceDic[key] = taskTable;
|
||||
CacheSpecialReturnDisplayValues(model, taskTable);
|
||||
return taskTable;
|
||||
}
|
||||
|
||||
DataTable table = BaseImpl.GetDataTableResult(model.SqlSource);
|
||||
mSpecialReturnSourceDic[key] = table;
|
||||
CacheSpecialReturnDisplayValues(model, table);
|
||||
return table;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取带参数字典搜索框弹出数据源,逻辑与原带参数搜索框弹出查询保持一致。
|
||||
/// </summary>
|
||||
private DataTable GetSpecialReturnParamSourceTable(GridColumnModel model)
|
||||
{
|
||||
DataRow[] dataRows = this.GetViewFocusedDataRows();
|
||||
DataRow rowItem = dataRows.Count() > 0 ? dataRows[0] : this.gridView.GetFocusedDataRow();
|
||||
if (rowItem == null && this.ParentControl == null)
|
||||
{
|
||||
return GetSpecialReturnSourceTable(model);
|
||||
}
|
||||
|
||||
string sqlValue = model.SqlSource;
|
||||
if (this.ParentControl != null)
|
||||
sqlValue = this.ParentControl.ReplaceParentControlValue(sqlValue);
|
||||
|
||||
sqlValue = sqlValue.Replace("#", "");
|
||||
|
||||
if (rowItem != null)
|
||||
{
|
||||
sqlValue = ReplaceHelper.ReplaceRowParam(rowItem, sqlValue);
|
||||
}
|
||||
|
||||
return MainImpl.GetDataTableResult(sqlValue);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 带参数字典搜索框保存文本时,把手动新增的数据追加到本次弹出数据源。
|
||||
/// </summary>
|
||||
private void AddSpecialReturnManualData(GridColumnModel model, DataTable table)
|
||||
{
|
||||
if (model == null || table == null || !model.SearchBoxAddition || !IsSpecialReturnTextBox(model.FieldType)) return;
|
||||
if (!this.ManuallyAddData.ContainsKey(model.FieldName)) return;
|
||||
|
||||
List<DataRow> dataRows = this.ManuallyAddData[model.FieldName];
|
||||
foreach (DataRow row in dataRows)
|
||||
{
|
||||
DataRow newrow = table.NewRow();
|
||||
newrow.ItemArray = row.ItemArray;
|
||||
table.Rows.Add(newrow);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 后台加载字典搜索框数据源并建立显示字典。
|
||||
/// </summary>
|
||||
private void StartSpecialReturnSourceTask(GridColumnModel model)
|
||||
{
|
||||
if (model == null || string.IsNullOrWhiteSpace(model.SqlSource) || mSpecialReturnSourceTaskDic.ContainsKey(model.FieldName)) return;
|
||||
|
||||
Task<DataTable> sourceTask = new Task<DataTable>(() =>
|
||||
{
|
||||
return BaseImpl.GetDataTableResult(model.SqlSource);
|
||||
});
|
||||
sourceTask.ContinueWith(task =>
|
||||
{
|
||||
if (task.Status != TaskStatus.RanToCompletion || task.Result == null) return;
|
||||
if (this.IsDisposed || !this.IsHandleCreated) return;
|
||||
this.BeginInvoke(new MethodInvoker(delegate ()
|
||||
{
|
||||
if (this.IsDisposed) return;
|
||||
mSpecialReturnSourceDic[model.FieldName] = task.Result;
|
||||
CacheSpecialReturnDisplayValues(model, task.Result);
|
||||
gridView.Invalidate();
|
||||
}));
|
||||
});
|
||||
mSpecialReturnSourceTaskDic.Add(model.FieldName, sourceTask);
|
||||
sourceTask.Start(DataTableExtend.SchedulerUtil);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取字段对应的显示文本字典。
|
||||
/// </summary>
|
||||
private Dictionary<string, string> GetSpecialReturnDisplayDic(GridColumnModel model)
|
||||
{
|
||||
if (!mSpecialReturnDisplayDic.ContainsKey(model.FieldName))
|
||||
{
|
||||
mSpecialReturnDisplayDic[model.FieldName] = new Dictionary<string, string>();
|
||||
}
|
||||
return mSpecialReturnDisplayDic[model.FieldName];
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 确认字典搜索框数据源是否已加载;后台任务已完成但回调未执行时,在这里补建显示字典。
|
||||
/// </summary>
|
||||
private bool EnsureSpecialReturnSourceReady(GridColumnModel model)
|
||||
{
|
||||
if (model == null) return false;
|
||||
if (mSpecialReturnSourceDic.ContainsKey(model.FieldName)) return true;
|
||||
|
||||
Task<DataTable> sourceTask = null;
|
||||
if (!mSpecialReturnSourceTaskDic.TryGetValue(model.FieldName, out sourceTask)) return false;
|
||||
if (!sourceTask.IsCompleted) return false;
|
||||
|
||||
if (sourceTask.Status == TaskStatus.RanToCompletion && sourceTask.Result != null)
|
||||
{
|
||||
mSpecialReturnSourceDic[model.FieldName] = sourceTask.Result;
|
||||
CacheSpecialReturnDisplayValues(model, sourceTask.Result);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 把数据源中的值和显示文本缓存到字典中。
|
||||
/// </summary>
|
||||
private void CacheSpecialReturnDisplayValues(GridColumnModel model, DataTable table)
|
||||
{
|
||||
if (table == null || !table.Columns.Contains(model.ValueMember) || !table.Columns.Contains(model.TextMember)) return;
|
||||
|
||||
Dictionary<string, string> displayDic = GetSpecialReturnDisplayDic(model);
|
||||
foreach (DataRow row in table.Rows)
|
||||
{
|
||||
string value = IsSpecialReturnTextBox(model.FieldType) ? row[model.TextMember] + "" : row[model.ValueMember] + "";
|
||||
if (!string.IsNullOrWhiteSpace(value) && !displayDic.ContainsKey(value))
|
||||
{
|
||||
displayDic.Add(value, row[model.TextMember] + "");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 根据单元格保存值获取显示文本。
|
||||
/// </summary>
|
||||
private string GetSpecialReturnDisplayText(GridColumnModel model, string value)
|
||||
{
|
||||
Dictionary<string, string> displayDic = GetSpecialReturnDisplayDic(model);
|
||||
string[] values = value.Trim(',').Split(',');
|
||||
StringBuilder result = new StringBuilder();
|
||||
foreach (string item in values)
|
||||
{
|
||||
string key = (item + "").Trim();
|
||||
if (string.IsNullOrWhiteSpace(key)) continue;
|
||||
|
||||
string displayText = string.Empty;
|
||||
result.Append(displayDic.TryGetValue(key, out displayText) ? displayText : key);
|
||||
result.Append(",");
|
||||
}
|
||||
return result.ToString().TrimEnd(',');
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 严格按字典获取显示文本,字典中不存在时返回false。
|
||||
/// </summary>
|
||||
private bool TryGetSpecialReturnDisplayText(GridColumnModel model, string value, out string displayText)
|
||||
{
|
||||
displayText = string.Empty;
|
||||
Dictionary<string, string> displayDic = GetSpecialReturnDisplayDic(model);
|
||||
string[] values = value.Trim(',').Split(',');
|
||||
StringBuilder result = new StringBuilder();
|
||||
foreach (string item in values)
|
||||
{
|
||||
string key = (item + "").Trim();
|
||||
if (string.IsNullOrWhiteSpace(key)) continue;
|
||||
|
||||
string itemText = string.Empty;
|
||||
if (!displayDic.TryGetValue(key, out itemText)) return false;
|
||||
|
||||
result.Append(itemText);
|
||||
result.Append(",");
|
||||
}
|
||||
|
||||
displayText = result.ToString().TrimEnd(',');
|
||||
return !string.IsNullOrWhiteSpace(displayText);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 进入编辑态时只给当前有效值绑定一行临时数据,避免未弹出下拉框时显示为空。
|
||||
/// </summary>
|
||||
private void BindSpecialReturnCurrentValue(RepositoryItemGridLookUpEdit searchEdit, GridColumnModel model, object cellValue)
|
||||
{
|
||||
if (searchEdit == null || model == null || cellValue == null) return;
|
||||
|
||||
string value = cellValue + "";
|
||||
if (string.IsNullOrWhiteSpace(value)) return;
|
||||
|
||||
string displayText = string.Empty;
|
||||
bool sourceReady = EnsureSpecialReturnSourceReady(model);
|
||||
if (!TryGetSpecialReturnDisplayText(model, value, out displayText))
|
||||
{
|
||||
if (sourceReady)
|
||||
{
|
||||
searchEdit.DataSource = null;
|
||||
return;
|
||||
}
|
||||
displayText = value;
|
||||
}
|
||||
|
||||
DataTable table = new DataTable();
|
||||
if (!table.Columns.Contains(model.ValueMember)) table.Columns.Add(model.ValueMember);
|
||||
if (!table.Columns.Contains(model.TextMember)) table.Columns.Add(model.TextMember);
|
||||
|
||||
DataRow row = table.NewRow();
|
||||
row[model.ValueMember] = IsSpecialReturnTextBox(model.FieldType) ? displayText : value;
|
||||
row[model.TextMember] = displayText;
|
||||
table.Rows.Add(row);
|
||||
|
||||
searchEdit.DataSource = table;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 根据弹出数据源补充搜索框显示列。
|
||||
/// </summary>
|
||||
private void AddSpecialReturnViewColumns(RepositoryItemGridLookUpEdit searchEdit, DataTable table, GridColumnModel model)
|
||||
{
|
||||
if (searchEdit == null || table == null) return;
|
||||
|
||||
foreach (DataColumn dcol in table.Columns)
|
||||
{
|
||||
if (string.IsNullOrEmpty(dcol.ColumnName) || dcol.ColumnName.Substring(0, 1) == "_") continue;
|
||||
if (searchEdit.View.Columns.FirstOrDefault(item => item.FieldName == dcol.ColumnName) != null) continue;
|
||||
|
||||
GridColumn otherColumn = new GridColumn();
|
||||
otherColumn.Name = otherColumn.FieldName = otherColumn.Caption = dcol.ColumnName;
|
||||
otherColumn.Visible = true;
|
||||
searchEdit.View.Columns.Add(otherColumn);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 设置字典搜索框弹出宽度,规则与普通自动搜索框保持一致。
|
||||
/// </summary>
|
||||
private void SetSpecialReturnPopupWidth(RepositoryItemGridLookUpEdit searchEdit, DataTable table, GridColumnModel model)
|
||||
{
|
||||
if (searchEdit == null || table == null || model == null) return;
|
||||
|
||||
int popWidth = 0;
|
||||
string[] columnsWidth = !string.IsNullOrWhiteSpace(model.LookUpFieldsWidth) ? model.LookUpFieldsWidth.Trim().TrimEnd(',').Split(',') : null;
|
||||
if (columnsWidth != null && columnsWidth.Length > 0)
|
||||
{
|
||||
int columnWidthIndex = 0;
|
||||
foreach (DataColumn dcol in table.Columns)
|
||||
{
|
||||
if (!string.IsNullOrEmpty(dcol.ColumnName) && dcol.ColumnName.Substring(0, 1) != "_")
|
||||
{
|
||||
GridColumn gCol = searchEdit.View.Columns.FirstOrDefault(x => x.FieldName == dcol.ColumnName);
|
||||
if (gCol != null)
|
||||
{
|
||||
int width = 0;
|
||||
if (columnWidthIndex < columnsWidth.Length)
|
||||
{
|
||||
string widthStr = columnsWidth[columnWidthIndex];
|
||||
width = int.TryParse(widthStr, out width) ? width : GraphicsText.GetTextWidth(gCol.Caption);
|
||||
}
|
||||
else
|
||||
{
|
||||
width = GraphicsText.GetTextWidth(gCol.Caption);
|
||||
int maxWidth = CalcMaxColumnWidth(table, gCol.Name);
|
||||
width = width > maxWidth ? width : maxWidth;
|
||||
}
|
||||
gCol.Width = width;
|
||||
popWidth += gCol.Width;
|
||||
}
|
||||
}
|
||||
columnWidthIndex++;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
foreach (DataColumn dcol in table.Columns)
|
||||
{
|
||||
if (string.IsNullOrEmpty(dcol.ColumnName) || dcol.ColumnName.Substring(0, 1) == "_") continue;
|
||||
GridColumn gCol = searchEdit.View.Columns.FirstOrDefault(x => x.FieldName == dcol.ColumnName);
|
||||
if (gCol != null)
|
||||
{
|
||||
int columnWidth = GraphicsText.GetTextWidth(gCol.Caption);
|
||||
gCol.Width = CalcMaxColumnWidth(table, gCol.Name);
|
||||
gCol.Width = columnWidth > gCol.Width ? columnWidth : gCol.Width;
|
||||
popWidth += gCol.Width;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (model.LookUpWidth > 0)
|
||||
{
|
||||
popWidth = model.LookUpWidth + 5;
|
||||
}
|
||||
searchEdit.PopupFormSize = new Size(popWidth, searchEdit.PopupFormSize.Height);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/// <summary>
|
||||
@@ -1457,6 +2048,7 @@ namespace Lskj.Control
|
||||
{
|
||||
if (this.DisableFieldSources && item.isVislble) continue;
|
||||
if (ControlType.IsNotLoadData(item.FieldType)) continue;
|
||||
if (IsSpecialReturnBox(item.FieldType)) continue;
|
||||
if (UpdateColumnRefresh && !string.IsNullOrWhiteSpace(UpdateColumns) && !UpdateColumns.Split(',').Contains(item.FieldName)) continue;
|
||||
if (!string.IsNullOrWhiteSpace(item.SqlSource))
|
||||
{
|
||||
@@ -4573,6 +5165,11 @@ namespace Lskj.Control
|
||||
if (SystemInfo.Instance.DisableCellAutoFiltering && edit.Properties != null) edit.Properties.AutoComplete = false;//设置是否启用自动完成功能
|
||||
RepositoryItemGridLookUpEdit searchEdit = edit.Properties;
|
||||
DataTable dt = (searchEdit.DataSource as DataTable);
|
||||
GridColumnModel model = searchEdit.Tag as GridColumnModel;
|
||||
if (dt == null && model != null && IsSpecialReturnBox(model.FieldType))
|
||||
{
|
||||
return;
|
||||
}
|
||||
BeginInvoke(new MethodInvoker(delegate ()
|
||||
{
|
||||
FilterLookup(sender, e.NewValue + "");
|
||||
@@ -8165,6 +8762,8 @@ namespace Lskj.Control
|
||||
Tag = normalCol,
|
||||
OptionsColumn = { AllowEdit = normalCol.Edit, FixedWidth = true }
|
||||
};
|
||||
col.OptionsFilter.AutoFilterCondition = AutoFilterCondition.Contains;
|
||||
col.OptionsFilter.FilterPopupMode = FilterPopupMode.CheckedList;
|
||||
if (!normalCol.Edit)
|
||||
{
|
||||
col.AppearanceHeader.Options.UseForeColor = true;
|
||||
@@ -8213,6 +8812,7 @@ namespace Lskj.Control
|
||||
|
||||
BandedGridColumn subColumn = new BandedGridColumn
|
||||
{
|
||||
Name = dynamicFieldName,
|
||||
FieldName = dynamicFieldName,
|
||||
Caption = subCaption,
|
||||
Width = subField.Width,
|
||||
@@ -8222,6 +8822,8 @@ namespace Lskj.Control
|
||||
MaxWidth = subField.Width,
|
||||
OptionsColumn = { AllowEdit = subField.Edit, FixedWidth = true }
|
||||
};
|
||||
subColumn.OptionsFilter.AutoFilterCondition = AutoFilterCondition.Contains;
|
||||
subColumn.OptionsFilter.FilterPopupMode = FilterPopupMode.CheckedList;
|
||||
if (!subField.Edit)
|
||||
{
|
||||
subColumn.AppearanceHeader.Options.UseForeColor = true;
|
||||
@@ -8302,6 +8904,8 @@ namespace Lskj.Control
|
||||
Tag = normalCol,
|
||||
OptionsColumn = { AllowEdit = normalCol.Edit, FixedWidth = true }
|
||||
};
|
||||
col.OptionsFilter.AutoFilterCondition = DevExpress.XtraTreeList.Columns.AutoFilterCondition.Contains;
|
||||
col.OptionsFilter.FilterPopupMode = DevExpress.XtraTreeList.FilterPopupMode.CheckedList;
|
||||
if (!normalCol.Edit)
|
||||
{
|
||||
col.AppearanceHeader.Options.UseForeColor = true;
|
||||
@@ -8355,6 +8959,7 @@ namespace Lskj.Control
|
||||
|
||||
DevExpress.XtraTreeList.Columns.TreeListColumn subColumn = new DevExpress.XtraTreeList.Columns.TreeListColumn
|
||||
{
|
||||
Name = dynamicFieldName,
|
||||
FieldName = dynamicFieldName,
|
||||
Caption = subCaption,
|
||||
Width = subField.Width,
|
||||
@@ -8363,6 +8968,8 @@ namespace Lskj.Control
|
||||
MinWidth = subField.Width,
|
||||
OptionsColumn = { AllowEdit = subField.Edit, FixedWidth = true }
|
||||
};
|
||||
subColumn.OptionsFilter.AutoFilterCondition = DevExpress.XtraTreeList.Columns.AutoFilterCondition.Contains;
|
||||
subColumn.OptionsFilter.FilterPopupMode = DevExpress.XtraTreeList.FilterPopupMode.CheckedList;
|
||||
if (!subField.Edit)
|
||||
{
|
||||
subColumn.AppearanceHeader.Options.UseForeColor = true;
|
||||
@@ -9252,6 +9859,16 @@ namespace Lskj.Control
|
||||
{
|
||||
this.mLoading = false;
|
||||
mControlSourceDic.Clear();
|
||||
mSpecialReturnSourceDic.Clear();
|
||||
mSpecialReturnSourceTaskDic.Clear();
|
||||
mSpecialReturnDisplayDic.Clear();
|
||||
foreach (GridColumnModel model in mControlList)
|
||||
{
|
||||
if (IsSpecialReturnBox(model.FieldType))
|
||||
{
|
||||
StartSpecialReturnSourceTask(model);
|
||||
}
|
||||
}
|
||||
SetColumnsSource(UpdateColumnRefresh);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user