二开案例.表单插件.跨账套执行Sql账表

【应用场景】跨账套执行Sql账表
【案例演示】A账套新建直接SQL账表,运行时前往B账套获取数据。

【实现步骤】
<1>编写表单插件,代码如下。
using Kingdee.BOS.Core.DynamicForm.PlugIn;
using Kingdee.BOS.ServiceHelper;
using Kingdee.BOS.Util;
using System;
using System.ComponentModel;
using System.Reflection;
namespace Jac.XkDemo.BOS.Business.PlugIn
{
/// <summary>
/// 【表单插件】跨账套执行Sql账表
/// </summary>
[Description("【表单插件】跨账套执行Sql账表"), HotUpdate]
public class CrossDbSqlReportFormPlugIn : AbstractDynamicFormPlugIn
{
public override void OnLoad(EventArgs e)
{
base.OnLoad(e);
// 通过目标账套的数据中心内码获取访问目标账套的上下文(查管理中心数据库的T_BAS_DATACENTER表可获取)
var context = DataCenterService.GetDataCenterContextByID("5f6010a6071016");
// 设置访问目标账套的用户内码(查询目标账套的T_SEC_USER表可获取)
context.UserId = 103678;
context.CurrentOrganizationInfo = this.View.Context.CurrentOrganizationInfo;
context.CurrentOrganizationInfo.ID = 1;
context.ConsolePageId = this.Context.ConsolePageId;
//
SetValue(this.View.OpenParameter, "Context", context);
SetValue(this.View, "Context", context);
SetValue(this.View.Model, "Context", context);
}
private static void SetValue(object obj, string propertyName, object value)
{
var property = obj.GetType().GetProperty(propertyName, BindingFlags.Instance | BindingFlags.Public);
if (property != null)
{
var setterMethod = property.GetSetMethod(true);
if (setterMethod != null)
{
二开案例.表单插件.跨账套执行Sql账表
声明:除非特别标注,否则均为本站原创文章,转载时请以链接形式注明文章出处。如若本站内容侵犯了原著者的合法权益,可联系本站删除。



