表单.二开案例.自定义表单操作(显示下推界面得到选择的转换规则)
【场景】实现一个表单操作,实现大部分表单、列表通用的逻辑,避免通过写表单插件、挂表单插件等频繁逻辑
【案例】自定义一个表单操作,实现打开下推界面(整单计算),显示下推界面得到选择的转换规则
<1>表单层操作代码案例
```chsarp
using Kingdee.BOS.BusinessEntity.ConvertTracker;
using Kingdee.BOS.Core;
using Kingdee.BOS.Core.DynamicForm;
using Kingdee.BOS.Core.List;
using Kingdee.BOS.Core.List.PlugIn.Args;
using Kingdee.BOS.Core.Metadata.ConvertElement.ServiceArgs;
using Kingdee.BOS.ServiceHelper;
using System;
using System.Collections.Generic;
using System.Linq;
namespace DynamicFormPlugIn.Operation
{
[System.ComponentModel.Description("自定义操作")]
public class CustomOperate_ShowPush : AbstractDynamicFormOperation
{
public override IFormOperation GetNewInstance()
{
return new CustomOperate_ShowPush();
}
/// <summary>
/// 创建操作结果
/// </summary>
/// <returns></returns>
protected override IOperationResult CreateOperationResult()
{
return base.CreateOperationResult();
}
/// <summary>
/// 验权
/// </summary>
/// <param name="result"></param>
/// <returns></returns>
protected override bool DoAuthPermission(IOperationResult result)
{
return base.DoAuthPermission(result);
}
/*
* Execute是操作实现的核心
* 包括创建操作结果-》验权-》表单插件操作前事件-》操作执行-》表单插件操作后事件
* 如无需要不建议重写此方法;
* 但是特别的:目前表单插件事件操作后事件仅支持同步触发,不支持在打开窗体异步回调的处理
* 可参考本案例实现,返回空结果,自行调用操作后事件
public override bool Execute()
{
return base.Execute();
}
*/
/// <summary>
/// 操作实现的核心
/// </summary>
/// <returns></returns>
protected override IOperationResult ExecuteOperation()
{
var selectedPkVal = GetPkIds();
if (selectedPkVal == null || selectedPkVal.Count <= 0)
return null;
/*
* 实现单据列表默认整单下推
*/
//<0>构造选中行,全部使用单据头实体
string formId = this.View.BillBusinessInfo.GetForm().Id;
List<ListSelectedRow> selectedRows = new List<ListSelectedRow>();
for (int i = 0; i < selectedPkVal.Count; ++i)
{
var pk = selectedPkVal[i];
var row = new ListSelectedRow(pk, string.Empty, i, formId);
selectedRows.Add(row);
}
GetConvertBusinessFlowsArgs getFlowArgs = new GetConvertBusinessFlowsArgs()
{
FormId = formId,
EntityKey = string.Empty,
Operation = FormOperationEnum.Push,
SelectedRows = selectedRows.ToArray(),
};
var getFlowResult = ConvertServiceHelper.GetConvertBusinessFlows(this.View.Context, getFlowArgs);
Dictionary<string, object> convertOpData = new Dictionary<string, object>();
convertOpData["SrcBillTypeId"] = getFlowResult.SrcBillTypeId;
convertOpData["SrcMainOrgId"] = getFlowResult.SrcMainOrgId;
convertOpData["Bills"] = getFlowResult.Bills;
convertOpData["ReplaceRelations"] = new List<ReplaceRelation>();//第三方下推关系
convertOpData["OptionalTargetOrgIds"] = new Dictionary<string, List<long>>();//插件限定的可选组织内码
convertOpData["SelectedRows"] = selectedRows; //选择的上游单据数据包,可以被插件修改
convertOpData["ThisViewSelectedRows"] = selectedPkVal; //原始数据,没有被插件修改
string sessionName = FormConst.ConvParamKey_BillsSessionName;
// 把可下推的单据放在交换区,供子页面取用
this.View.Session[sessionName] = convertOpData;
//打开单据转换操作界面,返回目标单Id
DynamicFormShowParameter param = new DynamicFormShowParameter();
param.FormId = FormIdConst.BOS_ConvertOpForm;
param.ParentPageId = this.View.PageId;
param.CustomComplexParams.Add("OperationNumber", FormOperationEnum.Push);
this.View.ShowForm(param, new Action<FormResult>((res) =>
{
//操作框返回结果
OpFormReturnInfo retInfo = res.ReturnData as OpFormReturnInfo;
if (retInfo == null) return;
//异步回调的操作后事件案例
//DynamicFormViewPlugInProxy proxy = this.View.GetService<DynamicFormViewPlugInProxy>();
//AfterDoOperationEventArgs adoArgs = new AfterDoOperationEventArgs(this.FormOperation);
//proxy.FireAfterDoOperation(adoArgs);
//todo 调用后续的服务层下推操作,显示下游单据数据
//ConvertServiceHelper.Push(this.View.Context, pushArgs, this.Option)
}));
return null;
}
private List<string> GetPkIds()
{
if (this.ListView != null)
{
return this.ListView.SelectedRowsInfo.GetPrimaryKeyValues().ToList();
}
if (this.BillView != null)
{
var billPk = this.BillView.Model.GetPKValue();
if (billPk == null)
return null;
var billId = billPk.ToString();
return new List<string> { billId };
}
return null;
}
}
}
```
<2>注册表单层操作脚本
```sql
declare @opId int;
set @opId = 1000099;
IF NOT EXISTS(SELECT 1 FROM T_MDL_FORMOPERATIONTYPE WHERE FID = @opId)
BEGIN
--<0>表单操作
INSERT INTO T_MDL_FORMOPERATIONTYPE(FID,FOPERATION,FISCONFIRM,FRESOURCE,FENABLEDSTATE,FOPERELEIDS,FSERVICECLASS,FDESIGNERCLASS,
FTOPCLASSIDS,FISSUPPORTWF,FSERVICEINVOKECLASS,FSERVICECLASSEXT,FWEBSERVICECLASS,FWEBDESIGNERCLASS,FAPPSCENARIOTYPE)
VALUES(@opId,'CustomOperate_ShowPush',0,null,'VIEW,EDIT',34,'DynamicFormPlugIn.Operation.CustomOperate_ShowPush, DynamicFormPlugIn',
'Kingdee.BOS.DomainModelDesigner.OperationDesigner.FormOperationDesigner', -1, 0,' ', null, NULL,null,1)
--<1>多语言描述
DELETE FROM T_MDL_FORMOPERATIONTYPE_L WHERE FID = @opId AND FLOCALEID = 2052;
INSERT INTO T_MDL_FORMOPERATIONTYPE_L(FPKID,FID,FLOCALEID,FNAME)
VALUES((SELECT ISNULL(MAX(FPKID), 0) + 1 FROM T_MDL_FORMOPERATIONTYPE_L WHERE FPKID < 100000),@opId,2052,'自定义操作_下推');
END;
```
<3>表单上绑定操作和菜单
![image.webp](/download/01005dbb544ab73b4b7685ee95071fbcadc7.webp)
【效果】实现了一个通用表单操作,大部分表单均可使用
![Image_20230119110025.webp](/download/010010a9ba3f8d944b4c91785280e2820471.webp)
表单.二开案例.自定义表单操作(显示下推界面得到选择的转换规则)
【场景】实现一个表单操作,实现大部分表单、列表通用的逻辑,避免通过写表单插件、挂表单插件等频繁逻辑【案例】自定义一个表单操作,实现...
点击下载文档
上一篇:根据单据的标识获取单据表名下一篇:单据转换.二开案例.选单时清空历史分录
本文2024-09-16 18:32:50发表“云星空知识”栏目。
本文链接:https://wenku.my7c.com/article/kingdee-k3cloud-22859.html
您需要登录后才可以发表评论, 登录登录 或者 注册
最新文档
热门文章