二开案例.单据插件.固定列仓位赋值给弹出窗仓位
【应用场景】
将固定列仓位字段的值,赋值给弹出窗仓位字段。
【案例演示】
销售出库单,固定列仓位赋值给弹出窗仓位。
【实现步骤】
<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")
{
//字符
if (obj[refPropertyName] != null && !obj[refPropertyName].ToString().IsNullOrEmpty())
{
sbFilter.AppendFormat(" and {0} = N'{1}'", flexItem["FFlexNumber"],
obj[refPropertyName].ToString().Replace("'", "''"));
}
else
{
//特殊处理,以后调KSQL函数
sbFilter.AppendLine(" and (" + flexItem["FFlexNumber"] + " = '' ");
sbFilter.AppendLine(" or " + flexItem["FFlexNumber"] + " = ' ') ");
}
}
else if (customDataType == "3" || customDataType == "6")
{
//日期/日期时间
if (obj[refPropertyName] == null || obj[refPropertyName].ToString() == "")
{
sbFilter.AppendLine(" and " + flexItem["FFlexNumber"] + " is null ");
}
else
{
sbFilter.AppendLine(" and " + flexItem["FFlexNumber"] + " = {ts'" + obj[refPropertyName] + "'} ");
}
}
else if (customDataType == "4")
{
//布尔
if (obj[refPropertyName] != null && obj[refPropertyName].ToString().EqualsIgnoreCase("false"))
{
sbFilter.AppendLine(" and " + flexItem["FFlexNumber"] + " = 0 ");
}
else
{
sbFilter.AppendLine(" and " + flexItem["FFlexNumber"] + " = 1 ");
}
}
else
{
//字符
sbFilter.AppendLine(" and 1=1 ");
}
}
}
#endregion
}
return sbFilter.ToString();
}
/// <summary>
/// 获取维度数据集
/// </summary>
/// <param name="ctx"></param>
/// <param name="flexDataFormId">维度表单Id</param>
/// <param name="filter">根据维度数据包生成的过滤条件</param>
/// <returns></returns>
private static long GetFlexDataIdByFilter(Context ctx, string flexDataFormId, string filter)
{
var sb = new StringBuilder();
if (flexDataFormId == FormIdConst.BD_FLEXITEMDETAILV)
{
// 取所有科目核算类型信息
sb.AppendFormat("/*dialect*/ Select FID from T_BD_FLEXITEMDETAILV where 1=1 ");
}
else if (flexDataFormId == FormIdConst.BD_FLEXSITEMDETAILV)
{
// 取所有物料辅助属性值信息
sb.AppendFormat("/*dialect*/ Select FID from T_BD_FLEXSITEMDETAILV where 1=1 ");
}
else if (flexDataFormId == FormIdConst.BD_FLEXVALUESDETAIL)
{
// 取所有仓位辅助属性值信息
sb.AppendFormat("/*dialect*/ Select FID from T_BAS_FLEXVALUESDETAIL where 1=1 ");
}
else if (flexDataFormId == FormIdConst.HR_JS_FlexGradeItemDetail)
{
// 取所有的职等维度数据
sb.AppendFormat("/*dialect*/ Select FID from T_JS_FlexGradeItemDetail where 1=1 ");
}
sb.AppendLine(filter);
sb.AppendFormat(" Order By FID");
return DBUtils.ExecuteScalar<long>(ctx, sb.ToString(), 0);
}
/// <summary>
/// 获取维度数据内码
/// </summary>
/// <param name="ctx"></param>
/// <param name="flexData">维度数据</param>
/// <param name="flexDataFormId">维度表单Id</param>
/// <param name="isAutoSave">当维度数据不存在时,是否自动保存</param>
/// <returns></returns>
public static long GetFlexDataId(Context ctx, DynamicObject flexData, string flexDataFormId, bool isAutoSave = false)
{
long pkId = -1;
var flexItems = GetInUseFlexItemInfo(ctx, flexDataFormId);
if (flexItems.IsEmpty() || flexData == null)
{
return pkId;
}
var filter = GetFlexDataFilter(flexData, flexItems);
if (string.IsNullOrWhiteSpace(filter))
{
return pkId;
}
pkId = GetFlexDataIdByFilter(ctx, flexDataFormId, filter);
if (pkId == 0 && isAutoSave)
{
var obj = SaveFlexObject(ctx, flexData);
pkId = Convert.ToInt64(obj[0]);
}
return pkId;
}
/// <summary>
/// 保存维度数据
/// </summary>
/// <param name="ctx"></param>
/// <param name="flexData">维度数据</param>
/// <returns></returns>
public static DynamicObject SaveFlexObject(Context ctx, DynamicObject flexData)
{
var seqReader = new SequenceReader(ctx);
var businessDataService = new BusinessDataService();
seqReader.AutoSetPrimaryKey(new[] { flexData }, flexData.DynamicObjectType);
return businessDataService.Save(ctx, new[] { flexData })[0];
}
}
}
<2>拷贝插件组件到应用站点的WebSite\Bin目录下,重启IIS。
<3>BOSIDE扩展销售出库单,明细信息新增仓位字段,注册表单插件,保存元数据,开发完毕。
【功能验证】
<1>登录业务站点,打开销售出库单编辑界面,固定列仓位录入数据完成后,就会自动赋值给弹出窗仓位,如下图。
---------------------------------------------------------------------------------------------------------
【仓位知识】
<1>仓库已设置的仓位信息:
<2>仓库数据包中的仓位信息:
<3>仓位数据包中的仓位值集信息:
<4>相关表格:
/*仓库*/
SELECT * FROM T_BD_STOCK
/*仓库的仓位值集*/
SELECT * FROM T_BD_STOCKFLEXITEM
/*仓位值集*/
SELECT * FROM T_BAS_FLEXVALUES
SELECT * FROM T_BAS_FLEXVALUESENTRY
/*仓位值*/
SELECT * FROM T_BAS_FLEXVALUESDETAIL
---------------------------------------------------------------------------------------------------------
【金蝶云星空BOS二次开发案例演示】https://vip.kingdee.com/article/94751030918525696
二开案例.单据插件.固定列仓位赋值给弹出窗仓位
本文2024-09-23 04:07:52发表“云星空知识”栏目。
本文链接:https://wenku.my7c.com/article/kingdee-k3cloud-163330.html