//这是在物料上的基本信息里面加了个基础资料字段,跟辅助属性上的字段是一样的;
using System;
using Kingdee.BOS.Core.Bill.PlugIn;
using Kingdee.BOS.Core.DynamicForm.PlugIn.Args;
using Kingdee.BOS.Orm.DataEntity;
using System.ComponentModel;
using Kingdee.BOS.App.Data;
using Kingdee.BOS.Core.Metadata.FieldElement;
using Kingdee.BOS.Model.DynamicForm;
using Kingdee.BOS.Web.DynamicForm;
using Kingdee.BOS.ServiceHelper;
namespace ZJX.T_PLN_PLANORDER.Business.PlugIn
{
[Kingdee.BOS.Util.HotUpdate]
[Description("选择物料后更新辅助属性")]
public class MOBill_FZSX : AbstractBillPlugIn
{
public override void DataChanged(DataChangedEventArgs e)
{
base.DataChanged(e);
if (e.Field.Key == "FMaterialId")
{
DynamicObject matObj = this.View.Model.GetValue("FMaterialId", e.Row) as DynamicObject; //获取当前行物料数据包
if (matObj != null)
{
long FMATERIALID = Convert.ToInt64(matObj["ID"]); //获取物料ID
string matNum1 = Convert.ToString(matObj["Number"]); //#物料编码,字符串类型
if (matNum1.StartsWith("4TM")) //这里是判断个别的物料编码不执行;
{
return;
}
string sql = string.Format(@"/*dialect*/SELECT T.FMATERIALID AS HJMATERIALID,ISNULL(T.F_ora_Base1,0) F_ora_Base1 FROM t_BD_Material T INNER JOIN t_BD_MaterialAuxPty TA ON T.FMATERIALID = TA.FMATERIALID WHERE TA.FISENABLE = 1 AND TA.FAUXPROPERTYID = 100006 AND T.FMATERIALID={0};", FMATERIALID); //貌似可以简单写,不用INNER JOIN t_BD_Material
DynamicObjectCollection Dyobjs = DBUtils.ExecuteDynamicObject(this.Context, sql);
string sql2 = string.Format(@"/*dialect*/SELECT T.FMATERIALID AS HJMATERIALID,ISNULL(T.F_ora_Base6,0) F_ora_Base6 FROM t_BD_Material T INNER JOIN t_BD_MaterialAuxPty TA ON T.FMATERIALID = TA.FMATERIALID WHERE TA.FISENABLE = 1 AND TA.FAUXPROPERTYID = 100003 AND T.FMATERIALID={0};", FMATERIALID);
DynamicObjectCollection Dyobjs2 = DBUtils.ExecuteDynamicObject(this.Context, sql2);
if (Dyobjs.Count == 0 && Dyobjs2.Count == 0)
{
this.View.Model.SetValue("$$FAUXPROPID__FF100003", "", e.Row);
this.View.Model.SetValue("$$FAUXPROPID__FF100006", "", e.Row);
return;
}
#region 操作Model逐个维度进行赋值
{
// 获取维度关联字段
var flexField = (RelatedFlexGroupField)this.View.BillBusinessInfo.GetField("FAuxPropId");
// 获取维度关联字段的某个维度
var field = (BaseDataField)flexField.RelateFlexBusinessInfo.GetField("FF100006");
var field1 = (BaseDataField)flexField.RelateFlexBusinessInfo.GetField("FF100003");
// 设置物料的属性
if (Dyobjs[0]["F_ora_Base1"] == "" || Dyobjs[0]["F_ora_Base1"] == null || Dyobjs[0]["F_ora_Base1"].ToString() == "0")
{
//var dynamicObj = BusinessDataServiceHelper.LoadSingle(this.Context, "", field.RefFormDynamicObjectType);
((DynamicFormModel)this.Model).SetFlexValue(flexField, "$$FAUXPROPID__FF100003", "", e.Row);
}
else
{
var dynamicObj = BusinessDataServiceHelper.LoadSingle(this.Context, Dyobjs[0]["F_ora_Base1"], field.RefFormDynamicObjectType);
((DynamicFormModel)this.Model).SetFlexValue(flexField, "$$FAUXPROPID__FF100003", dynamicObj, e.Row);
}
if (Dyobjs2[0]["F_ora_Base6"] == "" || Dyobjs2[0]["F_ora_Base6"] == null || Dyobjs2[0]["F_ora_Base6"].ToString() == "0")
{
((DynamicFormModel)this.Model).SetFlexValue(flexField, "$$FAUXPROPID__FF100006", "", e.Row);
}
else
{
var dynamicObj2 = BusinessDataServiceHelper.LoadSingle(this.Context, Dyobjs2[0]["F_ora_Base6"], field1.RefFormDynamicObjectType);
((DynamicFormModel)this.Model).SetFlexValue(flexField, "$$FAUXPROPID__FF100006", dynamicObj2, e.Row);
}
}
#endregion
}
}
}
}
}
推荐阅读