二开案例.单据插件.数据表格的单元格的输入焦点设置
【应用场景】通过插件控制数据表格的单元格的输入焦点。
【案例演示】采购订单,明细信息单据体,录入完当前行物料后,焦点自动跳转到下一行的物料编码单元格上。
【实现步骤】
<1>编写单据插件,如下图所示。
using Kingdee.BOS.Core.Bill.PlugIn;
using Kingdee.BOS.Core.DynamicForm;
using Kingdee.BOS.Core.DynamicForm.PlugIn.Args;
using Kingdee.BOS.Core.DynamicForm.PlugIn.ControlModel;
using Kingdee.BOS.JSON;
using Kingdee.BOS.Util;
using System.Collections.Generic;
using System.ComponentModel;
using System.Reflection;
namespace Jac.XkDemo.BOS.Business.PlugIn
{
/// <summary>
/// 【单据插件】数据表格的单元格的输入焦点设置
/// </summary>
[Description("【单据插件】数据表格的单元格的输入焦点设置"), HotUpdate]
public class EntryGirdCellSetFoucsBillPlugIn : AbstractBillPlugIn
{
public override void EntryBarItemClick(BarItemClickEventArgs e)
{
base.EntryBarItemClick(e);
if (e.BarItemKey.EqualsIgnoreCase("tbGetEntryCurrentRowIndex"))
{
this.View.ShowMessage("当前选中行:" + (this.Model.GetEntryCurrentRowIndex("FPOOrderEntry") + 1));
}
}
/// <summary>
/// 捕获物料编码的值更新事件
/// </summary>
/// <param name="e"></param>
public override void DataChanged(DataChangedEventArgs e)
{
base.DataChanged(e);
if (e.Field.Key.EqualsIgnoreCase("FMaterialId"))
{
// 物料编码赋值成功后,输入焦点下移
if (e.NewValue != null)
{
var currentRowIndex = this.Model.GetEntryCurrentRowIndex(e.Field.EntityKey);
if (currentRowIndex < 0)
{
// 焦点行异常,不予处理
return;
}
var newFocusRowIndex = currentRowIndex + 1;
if (newFocusRowIndex > this.Model.GetEntryRowCount(e.Field.EntityKey) - 1)
{
// 新行尚未创建,没法设置焦点了
return;
}
SetFocus(this.View, e.Field.EntityKey, e.Field.Key, newFocusRowIndex);
//SetFocusRowIndex(this.View, e.Field.EntityKey, e.Field.Key, newFocusRowIndex);
}
}
}
/// <summary>
/// 设置焦点行(方式一)
/// </summary>
/// <param name="view"></param>
/// <param name="entryKey"></param>
/// <param name="rowIndex"></param>
/// <param name="fieldKey"></param>
private void SetFocus(IDynamicFormView view, string entryKey, string fieldKey, int rowIndex)
{
var grid = view.GetControl<EntryGrid>(entryKey);
var data = new JSONObject();
data["colKey"] = fieldKey.ToUpper();
grid.InvokeControlMethod("Focus", data);
grid.SetFocusRowIndex(rowIndex);
}
/// <summary>
/// 设置焦点行(方式二)
/// </summary>
/// <param name="view"></param>
/// <param name="entryKey"></param>
/// <param name="fieldKey"></param>
/// <param name="rowIndex"></param>
private void SetFocusRowIndex(IDynamicFormView view, string entryKey, string fieldKey, int rowIndex)
{
var grid = view.GetControl<EntryGrid>(entryKey);
var entry = new Dictionary<string, object>();
entry["row"] = rowIndex;
entry["fieldKey"] = fieldKey.ToUpper();
var formState = (IDynamicFormState)GetPropertyValue(grid, "FormState");
formState.AddSelectedRows(entryKey, entry);
formState.SetControlProperty(entryKey, "FocusRowIndex", rowIndex);
}
/// <summary>
/// 反射获取对象实例的某个变量值
/// </summary>
/// <param name="obj"></param>
/// <param name="propertyName"></param>
/// <returns></returns>
private object GetPropertyValue(object obj, string propertyName)
{
var property = obj.GetType().GetProperty(propertyName, BindingFlags.NonPublic | BindingFlags.Instance);
if (property != null)
{
return property.GetValue(obj, null);
}
return null;
}
}
}
<2>拷贝插件组件到应用站点的WebSite\Bin目录下,重启IIS。
<3>登录BOSIDE,扩展采购订单,注册表单插件,添加分录菜单,保存元数据,开发完毕。
现在可以登录业务站点,打开采购订单,验证一下插件的控制效果啦。
【金蝶云星空BOS二次开发案例演示】https://vip.kingdee.com/article/94751030918525696
二开案例.单据插件.数据表格的单元格的输入焦点设置
本文2024-09-23 04:21:20发表“云星空知识”栏目。
本文链接:https://wenku.my7c.com/article/kingdee-k3cloud-164769.html