二开案例.单据插件.固定列仓位赋值给弹出窗仓位

【应用场景】
将固定列仓位字段的值,赋值给弹出窗仓位字段。
【案例演示】
销售出库单,固定列仓位赋值给弹出窗仓位。

【实现步骤】
<1>编写单据插件,代码如下。
using Kingdee.BOS;
using Kingdee.BOS.App.Core;
using Kingdee.BOS.App.Data;
using Kingdee.BOS.Core;
using Kingdee.BOS.Core.Bill.PlugIn;
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.Text;
namespace Jac.XkDemo.BOS.Business.PlugIn
{
/// <summary>
/// 【单据插件】固定列仓位赋值给弹出窗仓位
/// https://vip.kingdee.com/article/324639289705128448
/// </summary>
[Description("【单据插件】固定列仓位赋值给弹出窗仓位"), HotUpdate]
public class FixColumnFlexFieldSetValueToPopupBoxBillPlugIn : AbstractBillPlugIn
{
public override void DataChanged(DataChangedEventArgs e)
{
base.DataChanged(e);
var fixColumnFlexFieldKey = "F_Jac_Flex"; // 固定列仓位字段标识
var popupBoxFlexFieldKey = "FStockLocID"; // 弹出窗仓位字段标识
var fixColumnFlexField = (RelatedFlexGroupField)this.View.BillBusinessInfo.GetField(fixColumnFlexFieldKey);
var popupBoxFlexField = (RelatedFlexGroupField)this.View.BillBusinessInfo.GetField(popupBoxFlexFieldKey);
if (e.Field.Key.EqualsIgnoreCase(fixColumnFlexFieldKey))
{
// 根据仓库,获取该仓库启用的仓位集合
var stockIdObj = this.Model.GetValue("FStockID", e.Row) as DynamicObject;
if (stockIdObj == null)
{
return;
}
var stockFlexItems = stockIdObj["StockFlexItem"] as DynamicObjectCollection;
if (stockFlexItems == null || stockFlexItems.Count == 0)
{
return;
}
// 获取固定列仓位值
var flexValue = this.Model.GetValue(fixColumnFlexFieldKey, e.Row) as DynamicObject;
if (flexValue == null)
{
return;
}
var allFlexHasValue = stockFlexItems.All(flexItem => flexValue["F" + flexItem["FlexId_Id"]] != null);
if (allFlexHasValue)
{
// 当固定列仓位的所有维度都完成录入后,赋值给弹出窗仓位
var flexDataId = FlexUtils.GetFlexDataId(Context, flexValue, fixColumnFlexField.RelatedBDFlexItemLinkField);
if (flexDataId > 0)
{
var rowObj = this.Model.GetEntityDataObject(fixColumnFlexField.Entity, e.Row);
flexValue[0] = flexDataId;
rowObj[fixColumnFlexField.RefIDDynamicProperty] = flexDataId;
rowObj[popupBoxFlexField.RefIDDynamicProperty] = flexDataId;
this.Model.SetValue(popupBoxFlexFieldKey, flexValue, e.Row);
this.View.UpdateView(popupBoxFlexFieldKey, e.Row);
return;
}
}
// 当固定列仓位的维度数据录入不完整时,清除弹出窗仓位字段值
this.Model.SetValue(popupBoxFlexFieldKey, null, e.Row);
this.View.UpdateView(popupBoxFlexFieldKey, e.Row);
}
}
}
/// <summary>
/// 弹性域操作帮助类
/// </summary>
public class FlexUtils
{
/// <summary>
/// 获取维度字段所启用的维度信息
/// </summary>
/// <param name="ctx"></param>
/// <param name="flexDataFormId">维度表单Id</param>
/// <returns></returns>
private static List<DynamicObject> GetInUseFlexItemInfo(Context ctx, string flexDataFormId)
{
var sb = new StringBuilder();
if (flexDataFormId == FormIdConst.BD_FLEXITEMDETAILV)
{
#region 科目--核算类型
//取科目所启用维度信息
sb.AppendLine(" Select FID, FValueType,FFlexNumber,FCustomDataType from T_BD_FLEXITEMPROPERTY ");
sb.AppendLine(" where FDocumentStatus = 'C' ");
//sb.AppendLine(" and FForbidStatus = 'A' ");
#endregion
}
else if (flexDataFormId == FormIdConst.BD_FLEXSITEMDETAILV)
{
#region 物料--辅助属性
//取物料所启用辅助属性信息
sb.AppendLine(" Select FID, FValueType,FFlexNumber,FCustomDataType from T_BD_FLEXAUXPROPERTY ");
sb.AppendLine(" where FDocumentStatus = 'C' order by FNUMBER ");
//sb.AppendLine(" and FForbidStatus = 'A' "); 禁用的也要(保存时要匹配禁用字段数据重复,如颜色、尺码、地区,地区禁用后,实际数据只录入了颜色尺码匹配时仍然应该有地区字段)
#endregion
}
else if (flexDataFormId == FormIdConst.BD_FLEXVALUESDETAIL)
{
#region 仓位--辅助属性
//取所有仓位辅助属性值信息
sb.AppendLine(" Select FID, 3 as FValueType, FFlexNumber,'' as FCustomDataType from T_BAS_FLEXVALUES ");
sb.AppendLine(" where FDocumentStatus = 'C' ");
//sb.AppendLine(" and FForbidStatus = 'A' ");
#endregion
}
else if (flexDataFormId == FormIdConst.HR_JS_FlexGradeItemDetail)
{
#region 职等维度属性
//取所有职等维度值信息
sb.AppendLine(@" Select FID, 0 as FValueType, concat('FG',tochar(FID)) as FFlexNumber,'' as FCustomDataType from T_JS_FlexGradeItem ");
sb.AppendLine(" where FDocumentStatus = 'C' ");
//sb.AppendLine(" and FForbidStatus = 'A' ");
#endregion
}
var objs = DBUtils.ExecuteDynamicObject(ctx, sb.ToString());
return objs.ToList();
}
/// <summary>
/// 字段组合过滤条件
/// </summary>
/// <param name="obj">维度数据包</param>
/// <param name="flexItems">已启用的维度集合</param>
/// <returns>根据维度数据包生成的过滤条件</returns>
private static string GetFlexDataFilter(DynamicObject obj, List<DynamicObject> flexItems)
{
var sbFilter = new StringBuilder();
foreach (var flexItem in flexItems)
{
#region 过滤条件
var propertyName = flexItem["FFlexNumber"].ToString().Substring(1);
if (!string.IsNullOrEmpty(propertyName))
{
if (!obj.DynamicObjectType.Properties.ContainsKey(propertyName))
{
var strMessage = string.Format("维度定义已经发生了变更,无法继续操作。\r\n请【保存】或【暂存】并关闭当前单据,再重新打开。\r\n属性名:{0}。", propertyName);
throw new Exception(strMessage);
}
var refPropertyName = "";
var objValue = "";
if (Convert.ToInt32(flexItem["FValueType"]) == 0 || Convert.ToInt32(flexItem["FValueType"]) == 3)
{
//基础资料/值集资料
refPropertyName = propertyName + "_Id";
if (obj[refPropertyName] != null && !obj[refPropertyName].ToString().IsNullOrEmpty())
{
objValue = obj[refPropertyName].ToString();
}
else
{
objValue = "0";
}
sbFilter.AppendLine(" and " + flexItem["FFlexNumber"] + " = " + objValue + " ");
}
else if (Convert.ToInt32(flexItem["FValueType"]) == 1)
{
//辅助资料
refPropertyName = propertyName + "_Id";
if (obj[refPropertyName] != null && !obj[refPropertyName].ToString().IsNullOrEmpty())
{
sbFilter.AppendLine(" and " + flexItem["FFlexNumber"] + " = N'" + obj[refPropertyName] + "' ");
}
else
{
//特殊处理,以后调KSQL函数
sbFilter.AppendLine(" and (" + flexItem["FFlexNumber"] + " = '' ");
sbFilter.AppendLine(" or " + flexItem["FFlexNumber"] + " = ' ') ");
}
}
else
{
//自定义(仓位属性暂不支持)
refPropertyName = propertyName;
var customDataType = flexItem["FCustomDataType"].ToString();
if (customDataType == "1" || customDataType == "5")
{
//整数/数字
if (obj[refPropertyName] != null && !obj[refPropertyName].ToString().IsNullOrEmpty())
{
objValue = obj[refPropertyName].ToString();
}
else
{
objValue = "0";
}
sbFilter.AppendLine(" and " + flexItem["FFlexNumber"] + " = " + objValue + " ");
}
else if (customDataType == "2")
{
//字符
二开案例.单据插件.固定列仓位赋值给弹出窗仓位
声明:除非特别标注,否则均为本站原创文章,转载时请以链接形式注明文章出处。如若本站内容侵犯了原著者的合法权益,可联系本站删除。



