采购价目表更新自定义字段【自定义文本1=定制件全称,自定义文本2=指定规格】

栏目:云星空知识作者:金蝶来源:金蝶云社区发布:2024-09-16浏览:1

采购价目表更新自定义字段【自定义文本1=定制件全称,自定义文本2=指定规格】

using Kingdee.BOS.Core.DynamicForm.PlugIn;
using Kingdee.BOS.Core.DynamicForm.PlugIn.Args;
using Kingdee.BOS.Orm.DataEntity;
using Kingdee.BOS.ServiceHelper;
using Kingdee.BOS.Util;
using Kingdee.K3.Core.MFG.EntityHelper;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;

namespace HANS.SupplierSupplyRatio
{
    [Description("采购价目表更新自定义字段【自定义文本1=定制件全称,自定义文本2=指定规格】"), HotUpdate]
    public class PriceListUpdateDZJFullName : AbstractOperationServicePlugIn
    {
        private IEnumerable<DynamicObject> selectedRows = null;
        public override void OnPreparePropertys(PreparePropertysEventArgs e)
        {
            base.OnPreparePropertys(e);
            e.FieldKeys.Add("FAuxPropId");
        }

        public override void BeforeExecuteOperationTransaction(BeforeExecuteOperationTransaction e)
        {
            base.BeforeExecuteOperationTransaction(e);
            selectedRows = e.SelectedRows.Select(s => s.DataEntity);
        }

        public override void AfterExecuteOperationTransaction(AfterExecuteOperationTransaction e)
        {
            base.AfterExecuteOperationTransaction(e);
            if (!selectedRows.IsEmpty())
            {
                //定制件全称
               var listFIdForDZJ = selectedRows.SelectMany(p => p.GetDynamicValue<DynamicObjectCollection>("PriceListEntry"))
                                    .Where(q => (q.GetDynamicValue<long>("AuxPropId_Id") > 0) && (q.GetDynamicValue<DynamicObject>("AuxPropId").GetDynamicValue<long>("F100001_Id") > 0))
                                    .Select(x => x.GetDynamicValue<long>("Id")).Distinct().ToList();

                //指定规格
                var listFIdForZDGG = selectedRows.SelectMany(p => p.GetDynamicValue<DynamicObjectCollection>("PriceListEntry"))
                                    .Where(q => (q.GetDynamicValue<long>("AuxPropId_Id") > 0) && (!q.GetDynamicValue<DynamicObject>("AuxPropId").GetDynamicValue<string>("F100501").EqualsIgnoreCase(" ")))
                                    .Select(x => x.GetDynamicValue<long>("Id")).Distinct().ToList();

                if (!listFIdForDZJ.IsEmpty())
                {
                    var tmpSql = string.Format(@"Merge into t_PUR_PriceListEntry x Using 
                                                    (
                                                        /*定制件全称*/
	                                                    select  (c.fname) as F_HANS_DZJ_FullName, T.FEntryId
	                                                    from t_PUR_PriceListEntry t   
	                                                    inner join T_BD_FLEXSITEMDETAILV a on a.FId=T.FAUXPROPID
	                                                    inner join HANS_T_DINGZJ_l c on c.fid=a.ff100001
                                                        where t.FEntryId in({0}) and t.FAUXPROPID>0 and c.fname<>' '
                                                    ) y ON (x.FEntryId = y.FEntryId)                    
                                                    When Matched Then Update Set x.FDEFTEXTO = y.F_HANS_DZJ_FullName,x.FDEFTEXTT=' ' 
                                                ", string.Join(",", listFIdForDZJ.ToArray()));
                    //定制件全称
                    DBServiceHelper.Execute(this.Context, tmpSql);
                }

                if (!listFIdForZDGG.IsEmpty())
                {
                    var tmpSql = string.Format(@"Merge into t_PUR_PriceListEntry x Using 
                                                    (
	                                                    /*指定规格*/
                                                        select  a.ff100501 as F_HANS_ZDGG, t.FEntryId
	                                                    from t_PUR_PriceListEntry t  
	                                                    inner join T_BD_FLEXSITEMDETAILV a on a.FId=T.FAUXPROPID
                                                        where t.FEntryId in({0}) and t.FAUXPROPID>0  and a.ff100501<>' '
                                                    ) y ON (x.FEntryId = y.FEntryId)                    
                                                    When Matched Then Update Set x.FDEFTEXTT = y.F_HANS_ZDGG,x.FDEFTEXTO=' ' 
                                                ", string.Join(",", listFIdForZDGG.ToArray()));
                    //指定规格
                    DBServiceHelper.Execute(this.Context, tmpSql);
                }

                //处理 正常的物料(非 定制件,指定规格)
                var listIds = selectedRows.SelectMany(p => p.GetDynamicValue<DynamicObjectCollection>("PriceListEntry")
                              .Where(x => (x.GetDynamicValue<long>("AuxPropId_Id") == 0))
                              .Select(x => x.GetDynamicValue<long>("Id"))).Distinct().ToList();

                //排除 定制件全称
                if (!listFIdForDZJ.IsEmpty())
                    listIds = listIds.Where(p => listFIdForDZJ.All(x => x != p)).Distinct().ToList();

                //排除 指定规格
                if (!listFIdForZDGG.IsEmpty())
                    listIds = listIds.Where(p => listFIdForZDGG.All(x => x != p)).Distinct().ToList();

                if (!listIds.IsEmpty())
                {
                    var tmpNormalSql = string.Format("update t_PUR_PriceListEntry set FDEFTEXTT=' ',FDEFTEXTO=' ' where FEntryId in ({0})", string.Join(",", listIds.ToArray()));
                    DBServiceHelper.Execute(this.Context, tmpNormalSql);
                }
            }
        }

    }
}


采购价目表更新自定义字段【自定义文本1=定制件全称,自定义文本2=指定规格】

using Kingdee.BOS.Core.DynamicForm.PlugIn;using Kingdee.BOS.Core.DynamicForm.PlugIn.Args;using Kingdee.BOS.Orm.DataEntity;using Ki...
点击下载文档
确认删除?
回到顶部
客服QQ
  • 客服QQ点击这里给我发消息