using Kingdee.BOS.App.Data;
using Kingdee.BOS.Core.DynamicForm.PlugIn;
using Kingdee.BOS.Core.DynamicForm.PlugIn.Args;
using Kingdee.BOS.Orm.DataEntity;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace LQKJ.K3.MFG.PRD.App.ServicePlugIn
{
    [Kingdee.BOS.Util.HotUpdate]
    [Description("采购变更单记录同步数据服务插件")]
    public  class POChangeSyncdataService : AbstractOperationServicePlugIn
    {
        public override void EndOperationTransaction(EndOperationTransactionArgs e)
        {
            List<string> list = new List<string>();
            string id = base.BusinessInfo.GetForm().Id;
            string text = base.Context.UserId.ToString();
            string text2 = base.FormOperation.OperationName.ToString();
            string operation = base.FormOperation.Operation;
            DynamicObject[] dataEntitys = e.DataEntitys;
            HashSet<string> hsFID = new HashSet<string>();
            foreach (var item in dataEntitys)
            {
                var Entrys = item["POChangeEntry"] as DynamicObjectCollection;
                foreach (var entry in Entrys)//OrderFid
                {
                    if (!hsFID.Contains(entry["OrderFid"].ToString()))
                    {
                        hsFID.Add(entry["OrderFid"].ToString());
                    }
                }
            }
            foreach (var fid in hsFID)
            {
                //DynamicObject dynamicObject = dataEntitys[i];
                string text3 = fid;
                string item = string.Format("insert into LQKJ_t_IMSSync(FID,F_LQKJ_SYNCDATAID,F_LQKJ_SYNCBILL,F_LQKJ_SYNDDATETIME,FCREATORID,FMODIFIERID,FCREATEDATE,FMODIFYDATE,F_LQKJ_SYNCCHECK,F_LQKJ_Operationname,F_LQKJ_operationinnercode)\r\n              values(NEWID(),'{0}','{1}',null,'{2}','0',GETDATE(),GETDATE(),'0','{3}','{4}')", new object[]
                {
                    text3,
                    "PUR_PurchaseOrder",
                    text,
                    text2,
                    operation
                });
                list.Add(item);
            }
            DBUtils.ExecuteBatch(base.Context, list, list.Count);
            base.EndOperationTransaction(e);
        }
    }
}
