二开案例.单据插件.切换单据类型
【应用场景】
通过插件的方式,切换任意单据类型。
【案例演示】
采购订单,通过插件的方式切换单据类型。
【实现步骤】
<1>编写单据插件,代码如下。
using Kingdee.BOS.Core.Bill; using Kingdee.BOS.Core.Bill.PlugIn; using Kingdee.BOS.Core.DynamicForm; using Kingdee.BOS.Core.DynamicForm.PlugIn.Args; using Kingdee.BOS.Core.Metadata.FieldElement; using Kingdee.BOS.Orm.DataEntity; using Kingdee.BOS.Util; using System; using System.Collections.Generic; using System.ComponentModel; using System.Linq; using System.Reflection; namespace Jac.XkDemo.BOS.Business.PlugIn { /// <summary> /// 【单据插件】切换单据类型 /// </summary> [Description("【单据插件】切换单据类型"), HotUpdate] public class ChangeBillTypeAfterMainOrgChangedBillPlugIn : AbstractBillPlugIn { public override void BarItemClick(BarItemClickEventArgs e) { base.BarItemClick(e); if (e.BarItemKey.EqualsIgnoreCase("test")) { // 获取下一个单据类型 var billTypeField = this.View.BillBusinessInfo.GetBillTypeField(); var enumList = billTypeField.BuildEnumList(); var currentBillTypeValue = ((DynamicObject)this.Model.GetValue(billTypeField))[0].ToString(); var index = 0; for (; index < enumList.Count; ++index) { if (currentBillTypeValue == enumList[index].Value) { break; } } var nextIndex = index >= enumList.Count - 1 ? 0 : index + 1; var nextBillTypeValue = enumList[nextIndex].Value; var nextBillType = billTypeField.BillTypeInfo.First(o => o["Id"].ToString() == nextBillTypeValue); var nextLayoutId = nextBillType["LayoutSolution_Id"].ToString(); // 切换单据类型并刷新视图 BillTypeChanged1(nextBillTypeValue, nextLayoutId); //BillTypeChanged2(billTypeField, nextBillTypeValue); } } #region 方案1 /// <summary> /// 切换单据类型(通过ShowForm刷新视图) /// </summary> /// <param name="billTypeId"></param> /// <param name="layoutId"></param> private void BillTypeChanged1(string billTypeId, string layoutId) { var para = new BillShowParameter(); this.CopyCustomeParameter(para); para.OpenStyle.ShowType = ShowType.InCurrentForm; para.FormId = this.View.OpenParameter.FormId; para.DefaultBillTypeId = billTypeId; para.LayoutId = layoutId; para.Status = this.View.OpenParameter.Status; para.PKey = null; para.ParentPageId = this.View.OpenParameter.ParentPageId; // PageId必须确保一致 para.PageId = this.View.PageId; // 本view标记为已经失效,需要重新构建 this.View.OpenParameter.IsOutOfTime = true; this.View.ShowForm(para); } /// <summary> /// 复制用户定制的属性 /// </summary> /// <param name="para"></param> private void CopyCustomeParameter(BillShowParameter para) { Type openParamType = this.View.OpenParameter.GetType(); var properties = openParamType.GetProperties(); var IsnotCustomerPropertyKeys = new List<string>() { "pk", "billType" }; // 复制定制参数 var customerParams = this.View.OpenParameter.GetCustomParameters(); if (customerParams != null && customerParams.Count > 0) { foreach (var item in customerParams) { if (IsnotCustomerPropertyKeys.Contains(item.Key)) continue; if (item.Value == null) continue; if (!(item.Value is string)) continue; // 只复制字符串参数 var prop = properties.FirstOrDefault(p => p.Name.EqualsIgnoreCase(item.Key)); if (prop != null) continue; para.CustomParams[item.Key] = Convert.ToString(item.Value); } } } #endregion #region 方案2 /// <summary> /// 切换单据类型(调用标准产品未公开方法) /// </summary> /// <param name="billTypeField"></param> /// <param name="value"></param> private void BillTypeChanged2(BillTypeField billTypeField, object value) { // private void BillTypeChanged(BillTypeField billTypeField, object value) var method = this.View.GetType().GetMethods(BindingFlags.Instance | BindingFlags.NonPublic).FirstOrDefault(o => o.Name == "BillTypeChanged" && o.GetParameters().Length == 2); if (method == null) { return; } method.Invoke(this.View, new[] { billTypeField, value }); } #endregion } }
<2>拷贝插件组件到应用站点的WebSite\Bin目录下,重启IIS。
<3>BOSIDE扩展采购订单,菜单集合新增菜单项,注册表单插件,保存元数据,开发完毕。
【功能验证】
<1>登录业务站点,打开采购订单新增界面,点击菜单test,即可按当前单据类型的下拉列表,自动切换到下一个单据类型。
---------------------------------------------------------------------------------------------------------
【金蝶云星空BOS二次开发案例演示】https://vip.kingdee.com/article/94751030918525696
二开案例.单据插件.切换单据类型
【应用场景】通过插件的方式,切换任意单据类型。【案例演示】采购订单,通过插件的方式切换单据类型。【实现步骤】<1>编写单据插件,代码...
点击下载文档
本文2024-09-23 04:00:20发表“云星空知识”栏目。
本文链接:https://wenku.my7c.com/article/kingdee-k3cloud-162494.html
您需要登录后才可以发表评论, 登录登录 或者 注册
最新文档
热门文章