/* ==============================================================================
* 功能描述:OpenListByRowDoubleClickFormPlugIn
* 创 建 者:迷路的绵羊
* 创建日期:2024/1/12 10:56:13
* CLR Version :4.0.30319.42000
* 未经允许不可复制传播使用
* ==============================================================================*/
using Kingdee.BOS.Core.Bill;
using Kingdee.BOS.Core.DynamicForm;
using Kingdee.BOS.Core.DynamicForm.PlugIn;
using Kingdee.BOS.Core.DynamicForm.PlugIn.Args;
using Kingdee.BOS.Core.List;
using Kingdee.BOS.Core.Metadata;
using Kingdee.BOS.Core.Permission;
using Kingdee.BOS.ServiceHelper;
using Kingdee.BOS.Util;
using Kingdee.BOS.Web.Report.SQLReport;
using System;
using System.ComponentModel;
using System.Data;
using System.Reflection;
namespace Kingdee_YD.BusinessPlugIn
{
/// <summary>
/// 质检上传直接账表双击数据行打开新窗体
/// </summary>
[Description("质检上传直接账表双击数据行打开新窗体"), HotUpdate]
public class OpenListByRowDoubleClickFormPlugIn : AbstractDynamicFormPlugIn
{
public override void EntityRowDoubleClick(EntityRowClickEventArgs e)
{
base.EntityRowDoubleClick(e);
var view = this.View as SQLReportView;
if (view == null)
{
return;
}
string RowColKeyValue = null;
if (e.ColKey.Equals("采购订单编号", StringComparison.OrdinalIgnoreCase))
{
RowColKeyValue="采购订单编号";
}
else if (e.ColKey.Equals("源单编号", StringComparison.OrdinalIgnoreCase))
{
RowColKeyValue = "源单编号";
}
else if (e.ColKey.Equals("出库单据编号", StringComparison.OrdinalIgnoreCase))
{
RowColKeyValue = "出库单据编号";
}
else if (e.ColKey.Equals("生产订单编号", StringComparison.OrdinalIgnoreCase))
{
RowColKeyValue = "生产订单编号";
}
else if (e.ColKey.Equals("采购申请单据编号", StringComparison.OrdinalIgnoreCase))
{
RowColKeyValue = "采购申请单据编号";
}
else if (e.ColKey.Equals("采购订单编号", StringComparison.OrdinalIgnoreCase))
{
RowColKeyValue = "采购订单编号";
}
else if (e.ColKey.Equals("采购入库单据编号", StringComparison.OrdinalIgnoreCase))
{
RowColKeyValue = "采购入库单据编号";
}
if (RowColKeyValue!=null)
{
//var currentRowValue = GetCurrentRowValue(view, RowColKeyValue);
// 版本PT-146850 [7.5.1.202008]后用此方法
var currentRowValue = view.GetCurrentRowValue(RowColKeyValue);
if (currentRowValue == null)
{
return;
}
var billNo = currentRowValue.ToString();
// 使用单据视图打开
ShowBillForm(billNo, RowColKeyValue);
}
}
/// <summary>
/// 使用单据视图打开
/// </summary>
/// <param name="billNo">单据编号</param>
private void ShowBillForm(string billNo,string billName)
{
var sql = string.Format("SELECT FID FROM T_PUR_POORDER WHERE FBILLNO='{0}'", billNo);
var pkId = DBServiceHelper.ExecuteScalar<long>(this.Context, sql, 0);
var param = new BillShowParameter();
switch (billName)
{
case "生产订单编号":
sql = string.Format("SELECT FID FROM T_PRD_MO WHERE FBILLNO='{0}'", billNo);
pkId = DBServiceHelper.ExecuteScalar<long>(this.Context, sql, 0);
if (pkId <= 0)
{
return;
}
param.FormId = "PRD_MO"; // 业务对象标识
break;
case "源单编号":
sql = string.Format("SELECT FID FROM T_SAL_ORDER WHERE FBILLNO='{0}'", billNo);
pkId = DBServiceHelper.ExecuteScalar<long>(this.Context, sql, 0);
if (pkId <= 0)
{
return;
}
param.FormId = "SAL_SaleOrder"; // 业务对象标识
break;
case "出库单据编号":
sql = string.Format("SELECT FID FROM T_SAL_OUTSTOCK WHERE FBILLNO='{0}'", billNo);
pkId = DBServiceHelper.ExecuteScalar<long>(this.Context, sql, 0);
if (pkId <= 0)
{
return;
}
param.FormId = "SAL_OUTSTOCK"; // 业务对象标识
break;
case "采购申请单据编号":
sql = string.Format("SELECT FID FROM T_PUR_Requisition WHERE FBILLNO='{0}'", billNo);
pkId = DBServiceHelper.ExecuteScalar<long>(this.Context, sql, 0);
if (pkId <= 0)
{
return;
}
param.FormId = "PUR_Requisition"; // 业务对象标识
break;
case "采购订单编号":
sql = string.Format("SELECT FID FROM T_PUR_POORDER WHERE FBILLNO='{0}'", billNo);
pkId = DBServiceHelper.ExecuteScalar<long>(this.Context, sql, 0);
if (pkId <= 0)
{
return;
}
param.FormId = "PUR_PurchaseOrder"; // 业务对象标识
break;
case "采购入库单据编号":
sql = string.Format("SELECT FID FROM t_STK_InStock WHERE FBILLNO='{0}'", billNo);
pkId = DBServiceHelper.ExecuteScalar<long>(this.Context, sql, 0);
if (pkId <= 0)
{
return;
}
param.FormId = "STK_InStock"; // 业务对象标识
break;
}
param.PKey = pkId.ToString(); // 单据内码
param.Status = OperationStatus.VIEW; // 查看模式打开
//param.Status = OperationStatus.EDIT; // 编辑模式打开
this.View.ShowForm(param);
}
/// <summary>
/// 使用列表视图打开
/// </summary>
/// <param name="billNo">单据编号</param>
private void ShowListForm(string billNo)
{
var param = new ListShowParameter();
param.FormId = "PUR_PurchaseOrder"; // 业务对象标识
param.PermissionItemId = PermissionConst.View; // 验证当前用户查看权限
param.OpenStyle.ShowType = ShowType.MainNewTabPage; // 主控台开新页签
param.ListFilterParameter.Filter = string.Format("FBillNo='{0}'", billNo); // 查看指定单据
this.View.ShowForm(param);
}
/// <summary>
/// 获取当前选中行指定列的数据
/// </summary>
/// <param name="view"></param>
/// <param name="columnName"></param>
/// <returns></returns>
private object GetCurrentRowValue(IDynamicFormView view, string columnName)
{
var currentPageData = GetValue(view, "currentPageData") as DataTable;
if (currentPageData == null)
{
return null;
}
if (!currentPageData.Columns.Contains(columnName))
{
return null;
}
if (view.OpenParameter.GetCustomParameter("FLIST_selectedRows") == null)
{
return null;
}
var curRow = view.OpenParameter.GetCustomParameter("FLIST_selectedRows").ToString();
// 反射获取当前账表数据包
var rows = currentPageData.Select(string.Format("{0}={1}", "FIDENTITYID", curRow));
if (rows.Length > 0)
{
return rows[0][columnName];
}
return null;
}
/// <summary>
/// 反射获取当前视图的某个值
/// </summary>
/// <param name="obj"></param>
/// <param name="propertyName"></param>
/// <returns></returns>
private object GetValue(object obj, string propertyName)
{
var field = typeof(SQLReportView).GetField(propertyName, BindingFlags.NonPublic | BindingFlags.Instance);
if (field != null)
{
return field.GetValue(obj);
}
return null;
}
}
}
推荐阅读