/// <summary>
        ///累加日计划面积
        /// </summary>
        /// <param name="e"></param>
        public override void EndOperationTransaction(EndOperationTransactionArgs e)
        {
            base.EndOperationTransaction(e);
            IViewService Services = ServiceHelper.GetService <IViewService>();

            if (selectedRows != null && selectedRows.Count() != 0)
            {
                IMetaDataService metadataService = Kingdee.BOS.App.ServiceHelper.GetService <IMetaDataService>();
                string           SoureFormId     = "SZXY_FHJTRSCJH";
                //获取单据元数据
                FormMetadata BilMetada = metadataService.Load(Context, SoureFormId) as FormMetadata;

                foreach (DynamicObject dy in selectedRows)
                {
                    string  Id       = Convert.ToString(dy["Id"]);
                    decimal Area     = 0;
                    string  RJHFid   = string.Empty;
                    string  RJHRowId = string.Empty;
                    RJHFid   = Convert.ToString(dy["F_SZXY_FIDH"]);
                    Area     = Convert.ToDecimal(dy["F_SZXY_ProdArea"]);
                    RJHRowId = Convert.ToString(dy["F_SZXY_FEntryIDH"]);


                    if (Area > 0 && !RJHFid.IsNullOrEmptyOrWhiteSpace() && Convert.ToInt32(RJHFid) > 0 && Convert.ToInt32(RJHRowId) > 0)
                    {
                        //单据头反写复合日计划实际完成面积

                        string sql1 = $"/*dialect*/update SZXY_t_LSJTRSCJHEntry  set F_SZXY_ProdArea=F_SZXY_ProdArea-{Area} " +
                                      $"  where Fid={RJHFid}" +
                                      $" and FEntryID={RJHRowId} ";
                        DBServiceHelper.Execute(Context, sql1);
                    }
                }
            }
        }
Пример #2
0
        /// <summary>
        /// 提交
        /// </summary>
        /// <param name="ctx"></param>
        /// <param name="FormID"></param>
        /// <param name="ids"></param>
        /// <returns></returns>
        public IOperationResult SubmitBill(Context ctx, string FormID, object[] ids)
        {
            IMetaDataService metaService  = ServiceHelper.GetService <IMetaDataService>(); //元数据服务
            FormMetadata     Meta         = metaService.Load(ctx, FormID) as FormMetadata; //获取元数据
            OperateOption    submitOption = OperateOption.Create();
            IOperationResult submitResult = BusinessDataServiceHelper.Submit(ctx, Meta.BusinessInfo, ids, "Submit", submitOption);

            return(submitResult);

            //IMetaDataService metaService = ServiceHelper.GetService<IMetaDataService>();
            //FormMetadata targetBillMeta = metaService.Load(ctx, FormID) as FormMetadata;
            //// 构建保存操作参数:设置操作选项值,忽略交互提示
            //OperateOption submitOption = OperateOption.Create();
            //// 忽略全部需要交互性质的提示,直接保存;
            ////saveOption.SetIgnoreWarning(true);              // 忽略交互提示
            ////saveOption.SetInteractionFlag(this.Option.GetInteractionFlag());        // 如果有交互,传入用户选择的交互结果
            //// using Kingdee.BOS.Core.Interaction;
            ////saveOption.SetIgnoreInteractionFlag(this.Option.GetIgnoreInteractionFlag());
            ////// 如下代码,强制要求忽略交互提示(演示案例不需要,注释掉)
            //submitOption.SetIgnoreWarning(true);
            ////// using Kingdee.BOS.Core.Interaction;
            //submitOption.SetIgnoreInteractionFlag(true);
            //// 调用保存服务,自动保存
            //ISubmitService submitService = ServiceHelper.GetService<ISubmitService>();
            //IOperationResult submitResult = submitService.Submit(ctx, targetBillMeta.BusinessInfo, ids, "Submit", submitOption);
            //return submitResult;
        }
Пример #3
0
        /// <summary>
        ///累加日计划面积
        /// </summary>
        /// <param name="e"></param>
        public override void EndOperationTransaction(EndOperationTransactionArgs e)
        {
            base.EndOperationTransaction(e);
            IViewService Services = ServiceHelper.GetService <IViewService>();

            if (selectedRows != null && selectedRows.Count() != 0)
            {
                IMetaDataService metadataService = Kingdee.BOS.App.ServiceHelper.GetService <IMetaDataService>();
                string           SoureFormId     = "SZXY_FHJTRSCJH";
                //获取单据元数据
                FormMetadata BilMetada = metadataService.Load(Context, SoureFormId) as FormMetadata;

                foreach (DynamicObject dy in selectedRows)
                {
                    string Id       = Convert.ToString(dy["Id"]);
                    string RJHFid   = string.Empty;
                    string RJHRowId = string.Empty;

                    if (dy["SZXY_XYFHEntry"] is DynamicObjectCollection Entrys)
                    {
                        foreach (var item in Entrys.Where(op => !Convert.ToString(op["F_SZXY_PlasticNo"]).IsNullOrEmptyOrWhiteSpace()))
                        {
                            string LyNo = Convert.ToString(item["F_SZXY_PlasticNo"]);
                            //改写流转状态
                            string UpdateStateSql = string.Format("/*dialect*/update SZXY_t_XYLYEntry set  F_SZXY_CirculationState={0}   where F_SZXY_PlasticNo='{1}' ", 0, LyNo);
                            int    res            = DBServiceHelper.Execute(Context, UpdateStateSql);
                        }
                    }
                }
            }
        }
Пример #4
0
        /// <summary>
        /// 禁用单据
        /// </summary>
        /// <param name="ctx"></param>
        /// <param name="FormID">单据标识</param>
        /// <param name="ids">禁用单据内码集合</param>
        /// <param name="pkId">表主键列</param>
        /// <param name="tableName">表名</param>
        /// <param name="fieldName">禁用状态列</param>
        /// <param name="fieldValue">禁用值</param>
        /// <returns></returns>
        public void SetState(Context ctx, string FormID, object[] ids, string pkId, string tableName, string fieldName, string fieldValue)
        {
            IMetaDataService metaService = ServiceHelper.GetService <IMetaDataService>(); //元数据服务
            FormMetadata     Meta        = metaService.Load(ctx, FormID) as FormMetadata; //获取元数据
            OperateOption    AuditOption = OperateOption.Create();

            BusinessDataServiceHelper.SetState(ctx, tableName, fieldName, fieldValue, pkId, ids);
        }
Пример #5
0
        /// <summary>
        /// 另一种保存服务
        /// </summary>
        /// <param name="ctx"></param>
        /// <param name="FormID"></param>
        /// <param name="dyObject"></param>
        /// <returns></returns>
        public IOperationResult BatchSaveBill(Context ctx, string FormID, DynamicObject[] dyObject)
        {
            IMetaDataService metaService = ServiceHelper.GetService <IMetaDataService>(); //元数据服务
            FormMetadata     Meta        = metaService.Load(ctx, FormID) as FormMetadata; //获取元数据
            OperateOption    SaveOption  = OperateOption.Create();
            IOperationResult SaveResult  = BusinessDataServiceHelper.Save(ctx, Meta.BusinessInfo, dyObject, SaveOption, "Save");

            return(SaveResult);
        }
Пример #6
0
        public DynamicObject GetBasicObject(Context ctx, string formID, long ObjectID)
        {
            IMetaDataService metaService = ServiceHelper.GetService <IMetaDataService>(); //元数据服务
            IViewService     view        = ServiceHelper.GetService <IViewService>();     //界面服务
            FormMetadata     Meta        = metaService.Load(ctx, formID) as FormMetadata; //获取基础资料元数据
            DynamicObject    BasicObject = view.LoadSingle(ctx, ObjectID, Meta.BusinessInfo.GetDynamicObjectType());

            return(BasicObject);
        }
Пример #7
0
        public IOperationResult AuditBill(Context ctx, string FormID, object[] ids)
        {
            IMetaDataService metaService = ServiceHelper.GetService <IMetaDataService>(); //元数据服务
            FormMetadata     Meta        = metaService.Load(ctx, FormID) as FormMetadata; //获取元数据
            OperateOption    AuditOption = OperateOption.Create();
            IOperationResult AuditResult = BusinessDataServiceHelper.Audit(ctx, Meta.BusinessInfo, ids, AuditOption);

            return(AuditResult);
        }
Пример #8
0
        /// <summary>
        /// 暂存单据
        /// </summary>
        /// <param name="ctx"></param>
        /// <param name="FormID"></param>
        /// <param name="dyObject"></param>
        /// <returns></returns>
        public IOperationResult DraftBill(Context ctx, string FormID, DynamicObject[] dyObject)
        {
            IMetaDataService metaService = ServiceHelper.GetService <IMetaDataService>(); //元数据服务
            FormMetadata     Meta        = metaService.Load(ctx, FormID) as FormMetadata; //获取元数据
            OperateOption    DraftOption = OperateOption.Create();
            IOperationResult DraftResult = BusinessDataServiceHelper.Draft(ctx, Meta.BusinessInfo, dyObject, DraftOption, "Draft");

            return(DraftResult);
        }
Пример #9
0
        public override void DataChanged(DataChangedEventArgs e)
        {
            base.DataChanged(e);
            string        key = e.Field.Key.ToUpperInvariant();
            DynamicObject BasicObject;

            //判断实收数量是否改变
            if ((key == "FREALQTY" && Convert.ToInt32(e.NewValue) > 0) || (key == "FSTOCKDEPTID" && Convert.ToInt32(e.NewValue) > 0))
            {
                //获取单据组织
                DynamicObject stockOrg = this.Model.GetValue("FSTOCKORGID") as DynamicObject;
                long          orgId    = Convert.ToInt64(stockOrg["Id"]);
                //获取单据部门(需要判断是否为工厂)
                DynamicObject stockDept   = this.Model.GetValue("FSTOCKDEPTID") as DynamicObject;
                long          stockDeptId = Convert.ToInt64(stockDept["Id"]);
                //sql 执行sql查询对应组织工厂成品库
                string sql    = string.Format(@" select t1.fstockId from t_bd_stock t1 
                                           inner join t_bd_stock_l t2 on t1.fstockid = t2.fstockid
                                           where t2.fname like '%工厂成品库%' and fuseorgid={0}", orgId);
                long   result = DBUtils.ExecuteScalar <long>(base.Context, sql, -1, null);
                if (result != -1 && result != 0)
                {
                    IMetaDataService metaService = ServiceHelper.GetService <IMetaDataService>();              //元数据服务
                    IViewService     view        = ServiceHelper.GetService <IViewService>();                  //界面服务
                    FormMetadata     Meta        = metaService.Load(base.Context, "BD_STOCK") as FormMetadata; //获取基础资料元数据
                    BasicObject = view.LoadSingle(base.Context, result, Meta.BusinessInfo.GetDynamicObjectType());
                    //sql2 执行sql查询 界面是否为工厂
                    string sql2 = string.Format(@" select t.fdeptid from t_bd_department_l t where t.fname like '%工厂%' ");
                    DynamicObjectCollection result2 = DBUtils.ExecuteDynamicObject(this.Context, sql2);
                    //遍历工厂
                    foreach (DynamicObject stock in result2)
                    {
                        if (stock["FDeptId"].Equals(stockDeptId))
                        {
                            int row = this.Model.GetEntryRowCount("FInStockEntry");
                            for (int i = 0; i < row; i++)
                            {
                                this.Model.SetValue("FStockId", BasicObject, i);
                            }
                            break;
                        }
                        if (!stock["FDeptId"].Equals(stockDeptId))
                        {
                            int row = this.Model.GetEntryRowCount("FInStockEntry");
                            for (int i = 0; i < row; i++)
                            {
                                this.Model.SetValue("FStockId", null, i);
                            }
                        }
                    }
                }
            }
        }
Пример #10
0
        public BusinessInfo GetDemensionMetaData(string formId)
        {
            BusinessInfo     businessInfo;
            IMetaDataService service = ServiceHelper.GetService <IMetaDataService>();

            if (!this.dicDimensionMetaData.TryGetValue(formId, out businessInfo))
            {
                FormMetadata metadata = service.Load(base.Context, formId, true) as FormMetadata;
                businessInfo = metadata.BusinessInfo;
                this.dicDimensionMetaData.Add(formId, businessInfo);
            }
            return(businessInfo);
        }
Пример #11
0
        public static string GetExpandFieldSql(Context context, string tableName, string billFormFiedName)
        {
            IMetaDataService service = ServiceHelper.GetService <IMetaDataService>();

            string[] strArray = GetBillFormId(context, tableName, billFormFiedName);
            if (strArray.Length == 0)
            {
                return(string.Empty);
            }
            List <OutAcctgSeqConfig> source  = new OutInStockIndexService().GetAcctgIndexData(context, 0L, 0L, string.Format(" FBILLFROMID in ('{0}')", string.Join("','", strArray)));
            StringBuilder            builder = new StringBuilder();

            string[] strArray2 = strArray;
            for (int j = 0; j < strArray2.Length; j++)
            {
                Func <OutAcctgSeqConfig, bool> predicate = null;
                string       item = strArray2[j];
                FormMetadata mete = (FormMetadata)service.Load(context, item, true);
                if (predicate == null)
                {
                    predicate = i => i.BillFromId.ToUpper() == item.ToUpper();
                }
                OutAcctgSeqConfig config = source.FirstOrDefault <OutAcctgSeqConfig>(predicate);
                if (config != null)
                {
                    config.Initialization(mete, null);
                    Field extQtyField = null;
                    foreach (string str in qtyFieldNames)
                    {
                        extQtyField = mete.BusinessInfo.GetField(str);
                        if (extQtyField != null)
                        {
                            break;
                        }
                    }
                    if (extQtyField != null)
                    {
                        Field field    = mete.BusinessInfo.GetField(config.QtyField);
                        Field matField = mete.BusinessInfo.GetField(config.MaterialField);
                        if (!string.IsNullOrEmpty(builder.ToString()))
                        {
                            builder.AppendLine(" union all ");
                        }
                        builder.AppendLine(GetBills(tableName, matField, field, extQtyField, billFormFiedName, item));
                    }
                }
            }
            return(builder.ToString());
        }
Пример #12
0
        /// <summary>
        /// 提交进入工作流
        /// </summary>
        /// <param name="ctx"></param>
        /// <param name="FormID"></param>
        /// <param name="ids"></param>
        /// <returns></returns>
        public IOperationResult SubmitWorkFlowBill(Context ctx, string FormID, string billId)
        {
            IMetaDataService metaService = ServiceHelper.GetService <IMetaDataService>(); //元数据服务
            FormMetadata     Meta        = metaService.Load(ctx, FormID) as FormMetadata; //获取元数据
            // 首先判断单据是否已经有未完成的工作流
            IProcInstService procInstService = Kingdee.BOS.Workflow.Contracts.ServiceFactory.GetProcInstService(ctx);
            bool             isExist         = procInstService.CheckUnCompletePrcInstExsit(ctx, FormID, billId);

            if (isExist)
            {
                throw new KDBusinessException("AutoSubmit-001", "该单据已经启动了流程,不允许重复提交!");
            }
            // 读取单据的工作流配置模板
            IWorkflowTemplateService wfTemplateService  = Kingdee.BOS.Workflow.Contracts.ServiceFactory.GetWorkflowTemplateService(ctx);
            List <FindPrcResult>     findProcResultList = wfTemplateService.GetPrcListByFormID(
                FormID, new string[] { billId }, ctx);

            if (findProcResultList == null || findProcResultList.Count == 0)
            {
                throw new KDBusinessException("AutoSubmit-002", "查找单据适用的流程模板失败,不允许提交工作流!");
            }

            // 设置提交参数:忽略操作过程中的警告,避免与用户交互
            OperateOption submitOption = OperateOption.Create();

            submitOption.SetIgnoreWarning(true);
            IOperationResult submitResult = null;

            FindPrcResult findProcResult = findProcResultList[0];

            if (findProcResult.Result == TemplateResultType.Error)
            {
                throw new KDBusinessException("AutoSubmit-003", "单据不符合流程启动条件,不允许提交工作流!");
            }
            else if (findProcResult.Result != TemplateResultType.Normal)
            {    // 本单无适用的流程图,直接走传统审批
                ISubmitService submitService = ServiceHelper.GetService <ISubmitService>();
                submitResult = submitService.Submit(ctx, Meta.BusinessInfo,
                                                    new object[] { billId }, "Submit", submitOption);
            }
            else
            {    // 走工作流
                IBOSWorkflowService wfService = Kingdee.BOS.Workflow.Contracts.ServiceFactory.GetBOSWorkflowService(ctx);
                submitResult = wfService.ListSubmit(ctx, Meta.BusinessInfo,
                                                    0, new object[] { billId }, findProcResultList, submitOption);
            }
            return(submitResult);
        }
        /// <summary>
        ///累加日计划面积
        /// </summary>
        /// <param name="e"></param>
        public override void EndOperationTransaction(EndOperationTransactionArgs e)
        {
            base.EndOperationTransaction(e);

            if (selectedRows != null && selectedRows.Count() != 0)
            {
                IMetaDataService metadataService = Kingdee.BOS.App.ServiceHelper.GetService <IMetaDataService>();

                //获取单据元数据
                FormMetadata BilMetada = metadataService.Load(Context, "SZXY_LYJTRSCJH") as FormMetadata;

                foreach (DynamicObject dy in selectedRows)
                {
                    string Id     = Convert.ToString(dy["Id"]);
                    string FormId = "SZXY_LYJTRSCJH";
                    if (dy["SZXY_XYLYEntry"] is DynamicObjectCollection entry)
                    {
                        decimal Area     = 0;
                        string  RJHFid   = string.Empty;
                        string  RJHRowId = string.Empty;
                        foreach (var item in entry.Where(m => !Convert.ToString(m["F_SZXY_PlasticNo"]).IsNullOrEmptyOrWhiteSpace()))
                        {
                            RJHFid   = Convert.ToString(item["F_SZXY_FID"]);
                            Area     = Convert.ToDecimal(item["F_SZXY_Area"]);
                            RJHRowId = Convert.ToString(item["F_SZXY_FEntryID"]);

                            if (Area != 0 && !RJHFid.IsNullOrEmptyOrWhiteSpace())
                            {
                                DynamicObject RJHObejct = Utils.LoadFIDBillObject(this.Context, FormId, RJHFid);
                                if (RJHObejct["SZXY_LYJTRSCJHEntry"] is DynamicObjectCollection SoureEntry)
                                {
                                    var Row = from row in SoureEntry
                                              where Convert.ToString(row["id"]).EqualsIgnoreCase(RJHRowId)
                                              select row;
                                    foreach (DynamicObject SoureRow in SoureEntry.Where(p => Convert.ToString(p["id"]).EqualsIgnoreCase(RJHRowId)))
                                    {
                                        Area += Convert.ToDecimal(SoureRow["F_SZXY_ProductionArea"]);
                                        SoureRow["F_SZXY_ProductionArea"] = Area;
                                    }
                                }
                                var saveResult = BusinessDataServiceHelper.Save(Context, BilMetada.BusinessInfo, RJHObejct);
                            }
                        }
                    }
                }
            }
        }
        public override void EndOperationTransaction(EndOperationTransactionArgs e)
        {
            base.EndOperationTransaction(e);

            if (selectedRows != null && selectedRows.Count() != 0)
            {
                IMetaDataService metadataService = Kingdee.BOS.App.ServiceHelper.GetService <IMetaDataService>();
                string           SoureFormId     = "SZXY_FHJTRSCJH";
                //获取单据元数据
                FormMetadata BilMetada = metadataService.Load(Context, SoureFormId) as FormMetadata;

                foreach (DynamicObject dy in selectedRows)
                {
                    string  Id       = Convert.ToString(dy["Id"]);
                    decimal Area     = 0;
                    string  RJHFid   = string.Empty;
                    string  RJHRowId = string.Empty;
                    RJHFid   = Convert.ToString(dy["F_SZXY_FIDH"]);
                    Area     = Convert.ToDecimal(dy["F_SZXY_InArea"]);
                    RJHRowId = Convert.ToString(dy["F_SZXY_FEntryIDH"]);
                    string F_SZXY_MotherVolume = Convert.ToString(dy["F_SZXY_MotherVolume"]);
                    string F_SZXY_ligature     = Convert.ToString(dy["F_SZXY_ligature"]);


                    if (Area != 0 && !RJHFid.IsNullOrEmptyOrWhiteSpace())
                    {
                        DynamicObject RJHObejct = Utils.LoadFIDBillObject(this.Context, SoureFormId, RJHFid);
                        if (RJHObejct["SZXY_FHJTRSCJHEntry"] is DynamicObjectCollection SoureEntry)
                        {
                            //var Row = from row in SoureEntry
                            //          where Convert.ToString(row["id"]).EqualsIgnoreCase(RJHRowId)
                            //          select row;
                            foreach (DynamicObject SoureRow in SoureEntry.Where(p => Convert.ToString(p["id"]).EqualsIgnoreCase(RJHRowId)))
                            {
                                decimal ResArea = Convert.ToDecimal(SoureRow["F_SZXY_ProductionArea"]) - Area;
                                SoureRow["F_SZXY_ProductionArea"] = ResArea;
                            }
                        }
                        var saveResult = BusinessDataServiceHelper.Save(Context, BilMetada.BusinessInfo, RJHObejct);
                    }
                }
            }
        }
Пример #15
0
        /// <summary>
        ///累加日计划面积
        /// </summary>
        /// <param name="e"></param>
        public override void EndOperationTransaction(EndOperationTransactionArgs e)
        {
            base.EndOperationTransaction(e);
            IViewService Services = ServiceHelper.GetService <IViewService>();

            if (selectedRows != null && selectedRows.Count() != 0)
            {
                IMetaDataService metadataService = Kingdee.BOS.App.ServiceHelper.GetService <IMetaDataService>();
                string           SoureFormId     = "SZXY_FHJTRSCJH";
                //获取单据元数据
                FormMetadata BilMetada = metadataService.Load(Context, SoureFormId) as FormMetadata;

                foreach (DynamicObject dy in selectedRows)
                {
                    string  Id   = Convert.ToString(dy["Id"]);
                    decimal Area = 0;

                    string RJHRowId = string.Empty;
                    //Area = Convert.ToDecimal(dy["F_SZXY_AREA"]);
                    //RJHRowId = Convert.ToString(dy["F_SZXY_RJHEntryID"]);


                    if (dy["SZXY_SFDEntry"] is DynamicObjectCollection Entry)
                    {
                        foreach (var item in Entry)
                        {
                            Area = Convert.ToDecimal(item["F_SZXY_AREA"]);
                            //反写日计划实际完成面积
                            RJHRowId = Convert.ToString(item["F_SZXY_RJHEntryID"]);
                            if (!RJHRowId.IsNullOrEmptyOrWhiteSpace() && Convert.ToInt32(RJHRowId) > 0)
                            {
                                string sql1 = $"/*dialect*/update SZXY_t_SFJTRSCJHEntry  set F_SZXY_ProductionArea=F_SZXY_ProductionArea-{Area} " +
                                              $" where FEntryID={RJHRowId} ";
                                DBServiceHelper.Execute(Context, sql1);
                            }
                        }
                    }
                }
            }
        }
Пример #16
0
        //操作初始化时确认操作执行参数

        public override void BeginOperationTransaction(BeginOperationTransactionArgs e)
        {
            base.BeginOperationTransaction(e);
            string strSql = string.Format(@"/*dialect*/select A.FSTOCKSTATUSID from t_BD_StockStatus A inner join t_Bd_Stockstatus_l B on A.FSTOCKSTATUSID = B.FSTOCKSTATUSID where B.FNAME = '不参与核算'");
            long   result = DBUtils.ExecuteScalar <long>(base.Context, strSql, -1, null);

            DynamicObject[] entitys = e.DataEntitys;
            if (result > 0)
            {
                IMetaDataService metaService = ServiceHelper.GetService <IMetaDataService>();                    //元数据服务
                IViewService     view        = ServiceHelper.GetService <IViewService>();                        //界面服务
                FormMetadata     Meta        = metaService.Load(base.Context, "BD_StockStatus") as FormMetadata; //获取基础资料元数据
                BasicObject = view.LoadSingle(base.Context, result, Meta.BusinessInfo.GetDynamicObjectType());   //不参与核算的库存状态ID
            }
            foreach (DynamicObject entity in entitys)
            {//FSTOCKSTATUSID库存状态  编码  07040000 07040004
                if (entity != null)
                {
                    DynamicObjectCollection entityInfo = entity["TransferDirectEntry"] as DynamicObjectCollection;
                    for (int i = 0; i < entityInfo.Count; i++)
                    {
                        DynamicObject material = entityInfo[i]["MATERIALID"] as DynamicObject;

                        if (material["Number"].Equals("07040000") || material["Number"].Equals("07040004"))
                        {
                            if (BasicObject != null)
                            {
                                //string updateStr = string.Format(@"/*dialect*/Update T_STK_MISCELLANEOUSENTRY set FSTOCKSTATUSID = {0} where fentryid = {1}", result, Convert.ToInt64(entityInfo[i]["Id"]));
                                //DBUtils.Execute(base.Context, updateStr);
                                entityInfo[i]["SrcStockStatusId"]     = BasicObject;
                                entityInfo[i]["SrcStockStatusId_Id"]  = result;
                                entityInfo[i]["DestStockStatusId"]    = BasicObject;
                                entityInfo[i]["DestStockStatusId_Id"] = result;
                            }
                        }
                    }
                }
            }
        }
        /// <summary>
        /// 尝试删除下游单据,返回删除结果
        /// </summary>
        /// <param name="tableNumber">下游单据表格编码</param>
        /// <param name="entityIds">下游单据体内码</param>
        /// <returns></returns>
        private IOperationResult DeleteTargetBill(
            string tableNumber, HashSet <long> entityIds)
        {
            IBusinessFlowService bfService   = ServiceHelper.GetService <IBusinessFlowService>();
            TableDefine          tableDefine = bfService.LoadTableDefine(this.Context, tableNumber);

            // 读取下游单据的元数据
            IMetaDataService metaService = ServiceHelper.GetService <IMetaDataService>();
            FormMetadata     meta        = metaService.Load(
                this.Context, tableDefine.FormId) as FormMetadata;

            // 根据下游单据体的内码,读取单据内码
            HashSet <long> billIds = this.LoadTargetBillIds(meta.BusinessInfo, tableDefine.EntityKey, entityIds);

            object[] pkValues = (from p in billIds select(object) p).ToArray();
            // 调用删除服务,删除单据
            IDeleteService   deleteService = ServiceHelper.GetService <IDeleteService>();
            IOperationResult deleteResult  = deleteService.Delete(this.Context, meta.BusinessInfo,
                                                                  pkValues, this.Option);

            return(deleteResult);
        }
Пример #18
0
        /// <summary>
        /// 保存
        /// </summary>
        /// <param name="ctx"></param>
        /// <param name="FormID">业务对象标识</param>
        /// <param name="dyObject">保存业务对象集合</param>
        /// <returns></returns>
        public IOperationResult SaveBill(Context ctx, string FormID, DynamicObject[] dyObject)
        {
            IMetaDataService metaService    = ServiceHelper.GetService <IMetaDataService>();
            FormMetadata     targetBillMeta = metaService.Load(ctx, FormID) as FormMetadata;
            // 构建保存操作参数:设置操作选项值,忽略交互提示
            OperateOption saveOption = OperateOption.Create();

            // 忽略全部需要交互性质的提示,直接保存;
            //saveOption.SetIgnoreWarning(true);              // 忽略交互提示
            //saveOption.SetInteractionFlag(this.Option.GetInteractionFlag());        // 如果有交互,传入用户选择的交互结果
            // using Kingdee.BOS.Core.Interaction;
            //saveOption.SetIgnoreInteractionFlag(this.Option.GetIgnoreInteractionFlag());
            //// 如下代码,强制要求忽略交互提示(演示案例不需要,注释掉)
            saveOption.SetIgnoreWarning(true);
            //// using Kingdee.BOS.Core.Interaction;
            saveOption.SetIgnoreInteractionFlag(true);
            // 调用保存服务,自动保存
            ISaveService     saveService  = ServiceHelper.GetService <ISaveService>();
            IOperationResult saveResult   = saveService.Save(ctx, targetBillMeta.BusinessInfo, dyObject, saveOption, "Save");
            ISubmitService   save1Service = ServiceHelper.GetService <ISubmitService>();


            return(saveResult);
        }
Пример #19
0
        public override void AfterConvert(AfterConvertEventArgs e)
        {
            base.AfterConvert(e);
            ExtendedDataEntity[] array       = e.Result.FindByEntityKey("FBillHead");
            IMetaDataService     metaService = ServiceHelper.GetService <IMetaDataService>();
            FormMetadata         bomMeta     = metaService.Load(this.Context, "ENG_BOM", true) as FormMetadata;
            IViewService         viewService = ServiceHelper.GetService <IViewService>();

            foreach (ExtendedDataEntity item in array)
            {
                long orgId = Convert.ToInt64(item["SaleOrgId_Id"]);
                //long orgId = 100005;
                DynamicObjectCollection orderEntry = item["SaleOrderEntry"] as DynamicObjectCollection;
                if (orderEntry != null && orderEntry.Count() > 0)
                {
                    foreach (DynamicObject order in orderEntry)
                    {
                        long   materialId   = Convert.ToInt64(order["MaterialId_Id"]);
                        long   AuxPropId_Id = Convert.ToInt64(order["AuxPropId_Id"]);
                        string strSql       = string.Format(@"/*dialect*/select FMASTERID from T_BD_MATERIAL where FMATERIALID = {0}", materialId);
                        long   masterid     = DBUtils.ExecuteScalar <long>(this.Context, strSql, 0, null);
                        if (masterid != 0)
                        {
                            //1上下文,2物料masterid,3辅助属性内码id,
                            long bomId = BOMServiceHelper.GetDefaultBomKey(this.Context, masterid, orgId, AuxPropId_Id, Enums.Enu_BOMUse.TYBOM) > 0? BOMServiceHelper.GetDefaultBomKey(this.Context, masterid, orgId, AuxPropId_Id, Enums.Enu_BOMUse.TYBOM):0;
                            if (bomId > 0)
                            {
                                DynamicObject bomObject = viewService.LoadSingle(this.Context, bomId, bomMeta.BusinessInfo.GetDynamicObjectType());
                                order["BomId"]    = bomObject;
                                order["BomId_Id"] = bomId;
                            }
                        }
                    }
                }
            }
        }
Пример #20
0
        /// <summary>
        /// 审核结束自动下推(应付单下推付款申请单)
        /// </summary>
        /// <param name="e"></param>
        public override void AfterExecuteOperationTransaction(AfterExecuteOperationTransaction e)
        {
            base.AfterExecuteOperationTransaction(e);
            try
            {
                string sql = string.Empty;
                if (e.DataEntitys != null && e.DataEntitys.Count <DynamicObject>() > 0)
                {
                    foreach (DynamicObject item in e.DataEntitys)
                    {
                        //收款单id
                        string Fid  = item["Id"].ToString();
                        string sql2 = "";
                        //收款单源单明细
                        DynamicObjectCollection RECEIVEBILLSRCENTRYList = item["RECEIVEBILLSRCENTRY"] as DynamicObjectCollection;
                        foreach (var entry in RECEIVEBILLSRCENTRYList)
                        {
                            //销售订单明细内码
                            string FORDERENTRYID = entry["FSRCORDERENTRYID"].ToString();
                            //本次收款金额
                            decimal FREALRECAMOUNT = Convert.ToDecimal(entry["REALRECAMOUNT"].ToString());
                            if (!string.IsNullOrEmpty(FORDERENTRYID))
                            {
                                //查询采购订单
                                sql = string.Format(@"select a.FBILLNO,b.FENTRYID as 采购订单明细内码 ,f.F_YBG_BUSINESSMODEL as 业务模式  from  t_PUR_POOrder a  
                                                       inner join   t_PUR_POOrderEntry b on a.fID=b.FID 
                                                       inner join T_PUR_POORDERENTRY_LK c on c.FENTRYID=b.FENTRYID 
                                                       left join T_SAL_ORDERENTRY d on d.FENTRYID=c.FSID
                                                       left  join T_SAL_ORDER f on f.FID=d.FID 
                                                       where  FSID='{0}'", FORDERENTRYID);
                                DataSet   ds = DBServiceHelper.ExecuteDataSet(this.Context, sql);
                                DataTable dt = ds.Tables[0];
                                if (dt.Rows.Count > 0)
                                {
                                    for (int i = 0; i < dt.Rows.Count; i++)
                                    {
                                        string F_YBG_BUSINESSMODEL = dt.Rows[i]["采购订单明细内码"].ToString();
                                        if (F_YBG_BUSINESSMODEL == "01" || F_YBG_BUSINESSMODEL == "04") //挂靠的采用自动生成付款申请单
                                        {
                                            string POFENTRYID = dt.Rows[i]["采购订单明细内码"].ToString();
                                            if (string.IsNullOrEmpty(sql2))
                                            {
                                                sql2 += "  FPAYABLEENTRYID='" + POFENTRYID + "' ";
                                            }
                                            else
                                            {
                                                sql2 += "  or  FPAYABLEENTRYID='" + POFENTRYID + "' ";
                                            }
                                        }
                                    }
                                }
                            }
                        }
                        if (!string.IsNullOrEmpty(sql2))
                        {
                            #region  应付单下推付款申请单
                            string           srcFormId  = "AP_Payable";  //应付单
                            string           destFormId = "CN_PAYAPPLY"; //付款申请单
                            IMetaDataService mService   = Kingdee.BOS.App.ServiceHelper.GetService <IMetaDataService>();
                            IViewService     vService   = Kingdee.BOS.App.ServiceHelper.GetService <IViewService>();
                            FormMetadata     destmeta   = mService.Load(this.Context, destFormId) as FormMetadata;
                            //转换规则的唯一标识
                            string ruleKey = "AP_PayableToPayApply";
                            //var rules = ConvertServiceHelper.GetConvertRules(Context, srcFormId, destFormId);
                            //var rule = rules.FirstOrDefault(t => t.IsDefault);
                            ConvertRuleElement     rule    = GetDefaultConvertRule(Context, srcFormId, destFormId, ruleKey);
                            List <ListSelectedRow> lstRows = new List <ListSelectedRow>();
                            string  strsql = "select a.FID , a.FENTRYID  from T_AP_PAYABLEPLAN  a left join T_AP_PAYABLE b on a.FID=b.FID   where b.FDOCUMENTSTATUS='C' and  (" + sql2 + ") ";
                            DataSet ds2    = DBServiceHelper.ExecuteDataSet(Context, strsql);
                            if (ds2.Tables[0].Rows.Count > 0)
                            {
                                HashSet <string> hasset = new HashSet <string>();
                                for (int j = 0; j < ds2.Tables[0].Rows.Count; j++)
                                {
                                    hasset.Add(ds2.Tables[0].Rows[j]["FID"].ToString());
                                    long entryId = Convert.ToInt64(ds2.Tables[0].Rows[j]["FENTRYID"]);
                                    //源单单据标识
                                    ListSelectedRow row = new ListSelectedRow(ds2.Tables[0].Rows[j]["FID"].ToString(), entryId.ToString(), 0, "AP_Payable");
                                    //源单单据体标识
                                    row.EntryEntityKey = "FEntityPlan";
                                    lstRows.Add(row);
                                }

                                PushArgs        pargs      = new PushArgs(rule, lstRows.ToArray());
                                IConvertService cvtService = Kingdee.BOS.App.ServiceHelper.GetService <IConvertService>();
                                OperateOption   option     = OperateOption.Create();
                                option.SetIgnoreWarning(true);
                                option.SetVariableValue("ignoreTransaction", false);
                                option.SetIgnoreInteractionFlag(true);
                                #region 提交审核
                                //OperateOption option2 = OperateOption.Create();
                                //option2.SetIgnoreWarning(true);
                                //option2.SetVariableValue("ignoreTransaction", true);
                                //foreach (var hid in hasset)
                                //{
                                //    //如果应付单没有提交先提交审核
                                //    IMetaDataService BomService = Kingdee.BOS.App.ServiceHelper.GetService<IMetaDataService>();
                                //    //应付单元素包
                                //    FormMetadata APMeta = BomService.Load(Context, "AP_Payable") as FormMetadata;
                                //    IViewService APVService = Kingdee.BOS.App.ServiceHelper.GetService<IViewService>();
                                //    //应付单数据包
                                //    DynamicObject APmd = APVService.LoadSingle(Context, hid, APMeta.BusinessInfo.GetDynamicObjectType());

                                //    DynamicObject[] dy = new DynamicObject[] { APmd };

                                //    object[] items = dy.Select(p => p["Id"]).ToArray();

                                //    ISubmitService submitService = Kingdee.BOS.App.ServiceHelper.GetService<ISubmitService>();
                                //    IOperationResult submitresult = submitService.Submit(Context, APMeta.BusinessInfo, items, "Submit", option2);

                                //    IAuditService auditService = Kingdee.BOS.App.ServiceHelper.GetService<IAuditService>();
                                //    IOperationResult auditresult = auditService.Audit(Context, APMeta.BusinessInfo, items, option2);
                                //}
                                #endregion

                                ConvertOperationResult cvtResult = cvtService.Push(Context, pargs, option, false);
                                if (cvtResult.IsSuccess)
                                {
                                    DynamicObject[] dylist = (from p in cvtResult.TargetDataEntities select p.DataEntity).ToArray();
                                    //修改应收单里面数据
                                    for (int K = 0; K < dylist.Length; K++)
                                    {
                                        //付款原因
                                        dylist[K]["F_YBG_Remarks"] = "供应商付款";
                                        //明细信息
                                        DynamicObjectCollection RECEIVEBILLENTRYList = dylist[K]["FPAYAPPLYENTRY"] as DynamicObjectCollection;
                                        foreach (var Entry in RECEIVEBILLENTRYList)
                                        {
                                            //结算方式
                                            BaseDataField FSETTLETYPEID = destmeta.BusinessInfo.GetField("FSETTLETYPEID") as BaseDataField;
                                            Entry["FSETTLETYPEID_Id"] = 4;
                                            Entry["FSETTLETYPEID"]    = vService.LoadSingle(Context, 4, FSETTLETYPEID.RefFormDynamicObjectType);
                                        }
                                    }
                                    //保存
                                    ISaveService     saveService = Kingdee.BOS.App.ServiceHelper.GetService <ISaveService>();
                                    IOperationResult saveresult  = saveService.Save(Context, destmeta.BusinessInfo, dylist, option);
                                    bool             reult       = CheckResult(saveresult, out string mssg);
                                    if (!reult)
                                    {
                                        throw new Exception("收款款单审核成功,生成付款申请单失败:");
                                    }
                                    else
                                    {
                                        //纪录核销的纪录
                                        OperateResultCollection operateResults = saveresult.OperateResult;
                                        string fnmber = operateResults[0].Number;
                                        string fid    = operateResults[0].PKValue.ToString();
                                    }
                                }
                            }
                            else
                            {
                                throw new KDException("", "应付单不存在或者未审核,下推付款申请单失败");
                            }
                            #endregion
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                throw new KDException("", "应付单下推付款申请单失败:" + ex.ToString());
            }
        }
        /// <summary>
        /// 主单据体的字段携带完毕,与源单的关联关系创建好之后,触发此事件
        /// </summary>
        /// <param name="e"></param>
        //public override void OnAfterCreateLink(CreateLinkEventArgs e)
        //{
        //    base.OnAfterCreateLink(e);
        //    //源单  销售订单明细
        //    Entity srcFirstEntity = e.SourceBusinessInfo.GetEntity("FSaleOrderEntry");

        //    //目标单  直接调拨单明细
        //    Entity mainEntity = e.TargetBusinessInfo.GetEntity("FBillEntry");

        //    // 目标单关联子单据体
        //    Entity linkEntity = null;
        //    Form form = e.TargetBusinessInfo.GetForm();
        //    if (form.LinkSet != null
        //        && form.LinkSet.LinkEntitys != null
        //        && form.LinkSet.LinkEntitys.Count != 0)
        //    {
        //        linkEntity = e.TargetBusinessInfo.GetEntity(
        //            form.LinkSet.LinkEntitys[0].Key);
        //    }

        //    if (linkEntity == null)
        //    {
        //        return;
        //    }
        //    // 获取生成的全部下游单据
        //    ExtendedDataEntity[] billDataEntitys = e.TargetExtendedDataEntities.FindByEntityKey("FBillHead");

        //    // 对下游单据,逐张单据进行处理
        //    foreach (var item in billDataEntitys)
        //    {
        //        DynamicObjectCollection directEntry = item["TransferDirectEntry"] as DynamicObjectCollection;
        //        //合并之后的分录  为了不遍历每次增加
        //        DynamicObject entryEnd = directEntry[0] as DynamicObject;
        //        //获取目标单组织 sql中使用
        //        DynamicObject org = item["StockOrgId"] as DynamicObject;
        //        long orgId=Convert.ToInt64(org["Id"]);
        //        decimal slamount = 0;//塑料箱总数
        //        decimal pmamount = 0;//泡沫箱总数
        //        for (int i=0;i< directEntry.Count; i++)
        //        {
        //            //目标单分录
        //            DynamicObject entry= directEntry[i] as DynamicObject;
        //            //目标单物料
        //            DynamicObject material = entry["MaterialId"] as DynamicObject;
        //            //目标单调拨数量
        //            decimal qty= Convert.ToDecimal(entry["QTY"]);
        //            //物料获取装箱数
        //            decimal packQty= Convert.ToDecimal(material["FPACKQTY"]);
        //            //物料获取箱套类型
        //            DynamicObjectCollection materialBase = material["MaterialBase"] as DynamicObjectCollection;
        //            foreach (DynamicObject colourAll in materialBase)
        //            {
        //                string colour = Convert.ToString(colourAll["FBOXCOLOUR"]);
        //                if (colour.Equals("1"))//塑料箱
        //                {
        //                    decimal slxAmount = Math.Ceiling(qty / packQty);
        //                    slamount = slamount + slxAmount;
        //                }
        //                if (colour.Equals("2"))//泡沫箱
        //                {
        //                    decimal pmxAmount = Math.Ceiling(qty / packQty);
        //                    pmamount = pmamount + pmxAmount;
        //                }
        //            }

        //        }
        //        //新增分录  判断两种箱套数量是否为空
        //        if (slamount != 0)
        //        {
        //            // 目标单添加新行,并接受源单字段值
        //            DynamicObject newRow = new DynamicObject(mainEntity.DynamicObjectType);
        //            directEntry.Add(newRow);
        //            //根据组织查询对应 箱套
        //            string sql = string.Format(@"select fmaterialid from t_bd_material where fnumber='07040000' and fuseorgid={0}", orgId);
        //            long result = DBUtils.ExecuteScalar<long>(base.Context, sql, -1, null);
        //            //调入货主类型 string
        //            string ownerType = Convert.ToString(item["OwnerTypeIdHead"]);
        //            //调出货主类型 string
        //            string ownerOutType = Convert.ToString(item["OwnerTypeOutIdHead"]);
        //            //调入货主 DynamicObject
        //            DynamicObject owner = item["OwnerIdHead"] as DynamicObject;
        //            //调出货主 DynamicObject
        //            DynamicObject ownerOut = item["OwnerOutIdHead"] as DynamicObject;
        //            //调入保管者类型
        //            string keeperType = item["OwnerTypeIdHead"] as string;
        //            //调出保管者类型
        //            string keeperOutType = entryEnd["KeeperTypeId"] as string;
        //            //调入保管者
        //            DynamicObject keeper = entryEnd["KeeperId"] as DynamicObject;
        //            //调出保管者
        //            DynamicObject keeperOut = entryEnd["KeeperOutId"] as DynamicObject;
        //            //调拨数量基本单位  BaseQty
        //            decimal baseQty = Convert.ToDecimal( entryEnd["BaseQty"]);

        //            //组织基础资料对象
        //            if (result !=0 && result != -1)
        //            {
        //                IMetaDataService metaService = ServiceHelper.GetService<IMetaDataService>();//元数据服务
        //                IViewService view = ServiceHelper.GetService<IViewService>();//界面服务
        //                FormMetadata Meta = metaService.Load(base.Context, "BD_MATERIAL") as FormMetadata;//获取基础资料元数据
        //                DynamicObject BasicObject = view.LoadSingle(base.Context, result, Meta.BusinessInfo.GetDynamicObjectType());
        //                //物料ID
        //                long materialId = Convert.ToInt64(BasicObject["Id"]);
        //                // 填写字段值
        //                DynamicObjectCollection materialStock = BasicObject["MaterialStock"] as DynamicObjectCollection;
        //                DynamicObjectCollection materialBase = BasicObject["MaterialBase"] as DynamicObjectCollection;

        //                //基本单位
        //                foreach(DynamicObject base2 in materialBase)
        //                {
        //                    DynamicObject baseUnit = base2["BaseUnitId"] as DynamicObject;
        //                    newRow["BaseUnitId"] =baseUnit;
        //                }
        //                //单位  物料
        //                foreach (DynamicObject base1 in materialStock)
        //                {
        //                    DynamicObject unit = base1["StoreUnitID"] as DynamicObject;
        //                    long unitId = Convert.ToInt64(unit["Id"]);
        //                    newRow["MaterialId"] = BasicObject;
        //                    newRow["MaterialId_Id"] = materialId;
        //                    newRow["QTY"] = slamount;
        //                    newRow["UnitId"] = unit;
        //                    newRow["UnitId_Id"] = unitId;
        //                    newRow["Seq"] = directEntry.Count;



        //                    //调入货主
        //                    newRow["OwnerId"] = owner;
        //                    //调入货主类型
        //                    newRow["OwnerTypeId"] = ownerType;
        //                    //调处货主
        //                    newRow["FOwnerOutId"] = ownerOut;
        //                    //调出货主类型
        //                    newRow["OwnerTypeOutId"] = ownerOutType;
        //                    //调入保管者类型
        //                    newRow["KeeperTypeId"] = keeperOutType;
        //                    //调出保管者类型
        //                    newRow["KeeperTypeOutId"] = keeperOutType;
        //                    //调入保管者
        //                    newRow["KeeperId"] = owner;
        //                    //调出保管者
        //                    newRow["KeeperOutId"] = ownerOut;
        //                    //调出数量(基本单位)
        //                    newRow["BaseQty"] = baseQty;
        //                }

        //            }

        //        }



        //        if(pmamount != 0)
        //        {
        //            // 目标单添加新行
        //            DynamicObject newRow = new DynamicObject(entryEnd.DynamicObjectType);
        //            directEntry.Add(newRow);
        //            //根据组织查询对应 箱套
        //            string sql = string.Format(@"select fmaterialid from t_bd_material where fnumber='07040004' and fuseorgid={0}", orgId);
        //            long result = DBUtils.ExecuteScalar<long>(base.Context, sql, -1, null);
        //            //组织基础资料对象
        //            if (result != 0 && result != -1)
        //            {
        //                IMetaDataService metaService = ServiceHelper.GetService<IMetaDataService>();//元数据服务
        //                IViewService view = ServiceHelper.GetService<IViewService>();//界面服务
        //                FormMetadata Meta = metaService.Load(base.Context, "BD_MATERIAL") as FormMetadata;//获取基础资料元数据
        //                DynamicObject BasicObject = view.LoadSingle(base.Context, result, Meta.BusinessInfo.GetDynamicObjectType());
        //                //物料ID
        //                long materialId = Convert.ToInt64(BasicObject["Id"]);
        //                // 填写字段值
        //                DynamicObjectCollection materialStock =  BasicObject["MaterialStock"] as DynamicObjectCollection;
        //                foreach(DynamicObject base1 in materialStock)
        //                {
        //                    DynamicObject unit = base1["StoreUnitID"] as DynamicObject;
        //                    long unitId = Convert.ToInt64(unit["Id"]);
        //                    newRow["MaterialId"] = BasicObject;
        //                    newRow["MaterialId_Id"] = materialId;
        //                    newRow["QTY"] = pmamount;
        //                    newRow["UnitId"] = unit;
        //                    newRow["UnitId_Id"] = unitId;
        //                    newRow["Seq"] = directEntry.Count;
        //                }


        //            }

        //        }


        //        // TODO: 逐个填写其他字段值,示例代码略

        //    }
        //}
        public override void AfterConvert(AfterConvertEventArgs e)
        {
            base.AfterConvert(e);
            // 获取生成的全部下游单据
            ExtendedDataEntity[] billDataEntitys = e.Result.FindByEntityKey("FBillHead");
            Entity mainEntity     = e.TargetBusinessInfo.GetEntity("FBillEntry");
            Entity srcFirstEntity = e.SourceBusinessInfo.GetEntity("FSaleOrderEntry");

            // 对下游单据,逐张单据进行处理
            foreach (var item in billDataEntitys)
            {
                DynamicObjectCollection directEntry = item["TransferDirectEntry"] as DynamicObjectCollection;
                //合并之后的分录  为了不遍历每次增加
                DynamicObject entryEnd = directEntry[0] as DynamicObject;
                //获取目标单组织 sql中使用
                DynamicObject org      = item["StockOrgId"] as DynamicObject;
                long          orgId    = Convert.ToInt64(org["Id"]);
                decimal       slamount = 0; //塑料箱总数
                decimal       pmamount = 0; //泡沫箱总数
                for (int i = 0; i < directEntry.Count; i++)
                {
                    //目标单分录
                    DynamicObject entry = directEntry[i] as DynamicObject;
                    //目标单物料
                    DynamicObject material = entry["MaterialId"] as DynamicObject;
                    //目标单调拨数量
                    decimal qty = Convert.ToDecimal(entry["QTY"]);
                    //物料获取装箱数
                    decimal packQty = Convert.ToDecimal(material["FPACKQTY"]);
                    //物料获取箱套类型
                    DynamicObjectCollection materialBase = material["MaterialBase"] as DynamicObjectCollection;
                    foreach (DynamicObject colourAll in materialBase)
                    {
                        string colour = Convert.ToString(colourAll["FBOXCOLOUR"]);
                        if (colour.Equals("1"))//塑料箱
                        {
                            decimal slxAmount = Math.Ceiling(qty / packQty);
                            slamount = slamount + slxAmount;
                        }
                        if (colour.Equals("2"))//泡沫箱
                        {
                            decimal pmxAmount = Math.Ceiling(qty / packQty);
                            pmamount = pmamount + pmxAmount;
                        }
                    }
                }
                //新增分录  判断两种箱套数量是否为空
                if (slamount != 0)
                {
                    // 目标单添加新行,并接受源单字段值
                    DynamicObject newRow = new DynamicObject(mainEntity.DynamicObjectType);
                    directEntry.Add(newRow);
                    //根据组织查询对应 箱套
                    string sql    = string.Format(@"select fmaterialid from t_bd_material where fnumber='07040000' and fuseorgid={0}", orgId);
                    long   result = DBUtils.ExecuteScalar <long>(base.Context, sql, -1, null);
                    //调入货主类型 string
                    string ownerType = Convert.ToString(item["OwnerTypeIdHead"]);
                    //调出货主类型 string
                    string ownerOutType = Convert.ToString(item["OwnerTypeOutIdHead"]);
                    //调入货主 DynamicObject
                    DynamicObject owner = entryEnd["OwnerId"] as DynamicObject;
                    //调出货主 DynamicObject
                    DynamicObject ownerOut = entryEnd["FOwnerOutId"] as DynamicObject;
                    //调入保管者
                    DynamicObject keeper = entryEnd["KeeperId"] as DynamicObject;
                    //调出保管者
                    DynamicObject keeperOut = entryEnd["KeeperOutId"] as DynamicObject;
                    //调入保管者类型
                    string keeperType = entryEnd["OwnerTypeId"] as string;
                    //调出保管者类型
                    string keeperOutType = entryEnd["KeeperTypeId"] as string;

                    ////调拨数量基本单位  BaseQty
                    //decimal baseQty = Convert.ToDecimal(entryEnd["BaseQty"]);

                    //组织基础资料对象
                    if (result != 0 && result != -1)
                    {
                        IMetaDataService metaService = ServiceHelper.GetService <IMetaDataService>();                 //元数据服务
                        IViewService     view        = ServiceHelper.GetService <IViewService>();                     //界面服务
                        FormMetadata     Meta        = metaService.Load(base.Context, "BD_MATERIAL") as FormMetadata; //获取基础资料元数据
                        DynamicObject    BasicObject = view.LoadSingle(base.Context, result, Meta.BusinessInfo.GetDynamicObjectType());
                        //物料ID
                        long materialId = Convert.ToInt64(BasicObject["Id"]);
                        // 填写字段值
                        DynamicObjectCollection materialStock = BasicObject["MaterialStock"] as DynamicObjectCollection;
                        DynamicObjectCollection materialBase  = BasicObject["MaterialBase"] as DynamicObjectCollection;

                        ////基本单位
                        //foreach (DynamicObject base2 in materialBase)
                        //{
                        //    DynamicObject baseUnit = base2["BaseUnitId"] as DynamicObject;
                        //    newRow["BaseUnitId"] = baseUnit;
                        //}
                        //单位  物料
                        foreach (DynamicObject base1 in materialStock)
                        {
                            DynamicObject unit   = base1["StoreUnitID"] as DynamicObject;
                            long          unitId = Convert.ToInt64(unit["Id"]);
                            newRow["MaterialId"]     = BasicObject;
                            newRow["MaterialId_Id"]  = materialId;
                            newRow["QTY"]            = slamount;
                            newRow["UnitId"]         = unit;
                            newRow["UnitId_Id"]      = unitId;
                            newRow["Seq"]            = directEntry.Count;
                            newRow["DestMaterialId"] = BasicObject;
                            newRow["BaseUnitId"]     = unit;
                            newRow["BaseUnitId_Id"]  = unitId;
                            //BaseUnitId

                            //调入货主
                            newRow["OwnerId"] = owner;
                            //调入货主类型
                            newRow["OwnerTypeId"] = ownerType;
                            //调处货主
                            newRow["FOwnerOutId"] = ownerOut;
                            //调出货主类型
                            newRow["OwnerTypeOutId"] = ownerOutType;
                            //调入保管者类型
                            newRow["KeeperTypeId"] = keeperOutType;
                            //调出保管者类型
                            newRow["KeeperTypeOutId"] = keeperOutType;
                            //调入保管者
                            newRow["KeeperId"] = owner;
                            //调出保管者
                            newRow["KeeperOutId"] = ownerOut;
                            //调出数量(基本单位)
                            newRow["BaseQty"] = slamount;
                        }
                    }
                }



                if (pmamount != 0)
                {
                    // 目标单添加新行
                    DynamicObject newRow = new DynamicObject(entryEnd.DynamicObjectType);
                    directEntry.Add(newRow);
                    //根据组织查询对应 箱套
                    string sql    = string.Format(@"select fmaterialid from t_bd_material where fnumber='07040004' and fuseorgid={0}", orgId);
                    long   result = DBUtils.ExecuteScalar <long>(base.Context, sql, -1, null);
                    //组织基础资料对象
                    if (result != 0 && result != -1)
                    {
                        IMetaDataService metaService = ServiceHelper.GetService <IMetaDataService>();                 //元数据服务
                        IViewService     view        = ServiceHelper.GetService <IViewService>();                     //界面服务
                        FormMetadata     Meta        = metaService.Load(base.Context, "BD_MATERIAL") as FormMetadata; //获取基础资料元数据
                        DynamicObject    BasicObject = view.LoadSingle(base.Context, result, Meta.BusinessInfo.GetDynamicObjectType());
                        //物料ID
                        long materialId = Convert.ToInt64(BasicObject["Id"]);
                        // 填写字段值
                        DynamicObjectCollection materialStock = BasicObject["MaterialStock"] as DynamicObjectCollection;
                        foreach (DynamicObject base1 in materialStock)
                        {
                            DynamicObject unit   = base1["StoreUnitID"] as DynamicObject;
                            long          unitId = Convert.ToInt64(unit["Id"]);
                            newRow["MaterialId"]     = BasicObject;
                            newRow["MaterialId_Id"]  = materialId;
                            newRow["QTY"]            = pmamount;
                            newRow["UnitId"]         = unit;
                            newRow["UnitId_Id"]      = unitId;
                            newRow["Seq"]            = directEntry.Count;
                            newRow["DestMaterialId"] = BasicObject;
                            //调出数量(基本单位)
                            newRow["BaseQty"] = pmamount;
                        }
                    }
                }
            }
        }
Пример #22
0
        /// <summary>
        /// 自动下推并保存
        /// </summary>
        /// <param name="sourceFormId">源单FormId</param>
        /// <param name="targetFormId">目标单FormId</param>
        /// <param name="sourceBillIds">源单内码</param>
        private IOperationResult DoPush(string sourceFormId, string targetFormId, long targetOrgId, List <long> sourceBillIds)
        {
            IOperationResult result = new OperationResult();

            result.IsSuccess = false;
            // 获取源单与目标单的转换规则
            IConvertService convertService = Kingdee.BOS.App.ServiceHelper.GetService <IConvertService>();
            var             rules          = convertService.GetConvertRules(this.Context, sourceFormId, targetFormId);

            if (rules == null || rules.Count == 0)
            {
                throw new KDBusinessException("", string.Format("未找到{0}到{1}之间,启用的转换规则,无法自动下推!", sourceFormId, targetFormId));
            }
            // 取勾选了默认选项的规则
            var rule = rules.FirstOrDefault(t => t.IsDefault);

            //var rule = rules.
            // 如果无默认规则,则取第一个
            if (rule == null)
            {
                rule = rules[0];
            }
            // 开始构建下推参数:
            // 待下推的源单数据行
            List <ListSelectedRow> srcSelectedRows = new List <ListSelectedRow>();

            foreach (var billId in sourceBillIds)
            {// 把待下推的源单内码,逐个创建ListSelectedRow对象,添加到集合中
                srcSelectedRows.Add(new ListSelectedRow(billId.ToString(), string.Empty, 0, sourceFormId));
                // 特别说明:上述代码,是整单下推;
                // 如果需要指定待下推的单据体行,请参照下句代码,在ListSelectedRow中,指定EntryEntityKey以及EntryId
                //srcSelectedRows.Add(new ListSelectedRow(billId.ToString(), entityId, 0, sourceFormId) { EntryEntityKey = "FEntity" });
            }

            // 指定目标单单据类型:情况比较复杂,没有合适的案例做参照,示例代码暂略,直接留空,会下推到默认的单据类型
            string targetBillTypeId = string.Empty;
            // 指定目标单据主业务组织:情况更加复杂,需要涉及到业务委托关系,缺少合适案例,示例代码暂略
            // 建议在转换规则中,配置好主业务组织字段的映射关系:运行时,由系统根据映射关系,自动从上游单据取主业务组织,避免由插件指定
            //long targetOrgId = 0;
            // 自定义参数字典:把一些自定义参数,传递到转换插件中;转换插件再根据这些参数,进行特定处理
            Dictionary <string, object> custParams = new Dictionary <string, object>();
            // 组装下推参数对象
            PushArgs pushArgs = new PushArgs(rule, srcSelectedRows.ToArray())
            {
                TargetBillTypeId = targetBillTypeId,
                TargetOrgId      = targetOrgId,
                CustomParams     = custParams
            };
            // 调用下推服务,生成下游单据数据包
            ConvertOperationResult operationResult = convertService.Push(this.Context, pushArgs, OperateOption.Create());

            // 开始处理下推结果:
            // 获取下推生成的下游单据数据包
            DynamicObject[] targetBillObjs = (from p in operationResult.TargetDataEntities select p.DataEntity).ToArray();
            if (targetBillObjs.Length == 0)
            {
                // 未下推成功目标单,抛出错误,中断审核
                throw new KDBusinessException("", string.Format("由{0}自动下推{1},没有成功生成数据包,自动下推失败!", sourceFormId, targetFormId));
            }
            // 对下游单据数据包,进行适当的修订,以避免关键字段为空,自动保存失败
            // 示例代码略
            // 读取目标单据元数据
            IMetaDataService metaService = Kingdee.BOS.App.ServiceHelper.GetService <IMetaDataService>();
            var targetBillMeta           = metaService.Load(this.Context, targetFormId) as FormMetadata;
            // 构建保存操作参数:设置操作选项值,忽略交互提示
            OperateOption saveOption = OperateOption.Create();

            // 忽略全部需要交互性质的提示,直接保存;
            saveOption.SetIgnoreWarning(true);                               // 忽略交互提示
            saveOption.SetInteractionFlag(this.Option.GetInteractionFlag()); // 如果有交互,传入用户选择的交互结果
            // using Kingdee.BOS.Core.Interaction;
            saveOption.SetIgnoreInteractionFlag(this.Option.GetIgnoreInteractionFlag());
            // 调用保存服务,自动保存
            ISaveService saveService = Kingdee.BOS.App.ServiceHelper.GetService <ISaveService>();
            var          saveResult  = saveService.Save(this.Context, targetBillMeta.BusinessInfo, targetBillObjs, saveOption, "Save");

            // 判断自动保存结果:只有操作成功,才会继续
            if (saveResult.SuccessDataEnity != null)
            {
                var submitRet = AppServiceContext.SubmitService.Submit(this.Context, targetBillMeta.BusinessInfo, saveResult.SuccessDataEnity.Select(o => o["Id"]).ToArray(), "Submit", saveOption);
                result.MergeResult(submitRet);
                if (submitRet.SuccessDataEnity != null)
                {
                    var auditResult = AppServiceContext.SetStatusService.SetBillStatus(this.Context, targetBillMeta.BusinessInfo,
                                                                                       submitRet.SuccessDataEnity.Select(o => new KeyValuePair <object, object>(o["Id"], 0)).ToList(),
                                                                                       new List <object> {
                        "1", ""
                    },
                                                                                       "Audit", saveOption);

                    result.MergeResult(auditResult);
                }
            }
            if (this.CheckOpResult(saveResult, saveOption))
            {
                return(result);
            }
            return(result);
        }
Пример #23
0
        //根据组织确定其是否是分公司销售,保存前根据物料判断 并且新增行计算箱套数量添加到分录中
        public override void BeforeSave(BeforeSaveEventArgs e)
        {
            base.BeforeSave(e);

            //1.获取单据头销售组织
            DynamicObject saleOrg = this.Model.GetValue("FSALEORGID") as DynamicObject;
            //2.获取单据头客户
            DynamicObject customer = this.Model.GetValue("FCUSTOMERID") as DynamicObject;

            //4.定义泡沫箱,塑料箱总数
            decimal slx = 0;
            decimal pmx = 0;

            //客户和销售组织不为空
            if (saleOrg != null && customer != null)
            {
                long useOrgId   = Convert.ToInt64(saleOrg["Id"]);
                long customerId = Convert.ToInt64(customer["Id"]);
                //3.通过sql查询该组织下对应所有子客户
                string sql = string.Format(@"select t1.FcustId 
                                           from t_bd_customer t1
                                           where t1.FPRIMARYGROUP=105322  and FUSEORGID = {0}", useOrgId);
                DynamicObjectCollection allCusto = DBUtils.ExecuteDynamicObject(base.Context, sql);
                foreach (DynamicObject custo in allCusto)
                {
                    //4.如果是子客户,则需要获取分录计算
                    long custoId = Convert.ToInt64(custo["FCUSTID"]);
                    if (custoId == customerId)
                    {
                        DynamicObject           billObj = this.Model.DataObject;
                        DynamicObjectCollection entrys  = billObj["SAL_OUTSTOCKENTRY"] as DynamicObjectCollection;
                        for (int i = 0; i < entrys.Count; i++)
                        {
                            //获取每一个分录
                            DynamicObject entry = entrys[i] as DynamicObject;
                            //塑料箱数量
                            decimal slxAmount = Convert.ToDecimal(entry["FSLXQTY"]);
                            if (slxAmount != 0)
                            {
                                slx = slx + slxAmount;
                            }
                            //泡沫箱数量
                            decimal pmxAmount = Convert.ToDecimal(entry["FPMXQTY"]);
                            if (pmxAmount != 0)
                            {
                                pmx = pmx + pmxAmount;
                            }
                        }
                        //this.View.Model.CreateNewEntryRow("FEntity");//新增
                        //根据组织查询对应 箱套
                        if (slx != 0)
                        {
                            string sql2   = string.Format(@"select FMATERIALID from t_bd_material where fnumber='07040000' and fuseorgid={0}", useOrgId);
                            long   result = DBUtils.ExecuteScalar <long>(base.Context, sql2, -1, null);
                            if (result != 0 && result != -1)
                            {
                                IMetaDataService metaService = ServiceHelper.GetService <IMetaDataService>();                 //元数据服务
                                IViewService     view        = ServiceHelper.GetService <IViewService>();                     //界面服务
                                FormMetadata     Meta        = metaService.Load(base.Context, "BD_MATERIAL") as FormMetadata; //获取基础资料元数据
                                DynamicObject    BasicObject = view.LoadSingle(base.Context, result, Meta.BusinessInfo.GetDynamicObjectType());
                                // 填写字段值
                                DynamicObjectCollection materialStock = BasicObject["MaterialStock"] as DynamicObjectCollection;
                                DynamicObjectCollection materialBase  = BasicObject["MaterialBase"] as DynamicObjectCollection;
                                foreach (DynamicObject base1 in materialStock)
                                {
                                    long          materialId = Convert.ToInt64(BasicObject["Id"]);
                                    DynamicObject unit       = base1["StoreUnitID"] as DynamicObject;
                                    long          unitId     = Convert.ToInt64(unit["Id"]);
                                    this.Model.BatchCreateNewEntryRow("FEntity", 1);
                                    //之前一行
                                    DynamicObject before = entrys[entrys.Count - 2] as DynamicObject;
                                    //新增分录行
                                    DynamicObject end     = entrys[entrys.Count - 1] as DynamicObject;
                                    DynamicObject stock   = before["StockID"] as DynamicObject;
                                    long          stockID = Convert.ToInt64(stock["Id"]);

                                    end["MaterialID"]    = BasicObject;
                                    end["MaterialID_Id"] = materialId;
                                    end["UnitID"]        = unit;
                                    end["UnitID_Id"]     = unitId;
                                    end["RealQty"]       = slx;
                                    end["StockID"]       = stock;
                                    end["StockID_Id"]    = stockID;
                                    end["BaseUnitQty"]   = slx;

                                    //this.Model.SetValue("MaterialID", BasicObject, entrys.Count);
                                    //this.Model.SetValue("UnitID", unitId, entrys.Count);
                                    //this.Model.SetValue("RealQty", slx, entrys.Count);
                                }
                            }
                        }

                        if (pmx != 0)
                        {
                            string sql2   = string.Format(@"select FMATERIALID from t_bd_material where fnumber='07040004' and fuseorgid={0}", useOrgId);
                            long   result = DBUtils.ExecuteScalar <long>(base.Context, sql2, -1, null);
                            if (result != 0 && result != -1)
                            {
                                IMetaDataService metaService = ServiceHelper.GetService <IMetaDataService>();                 //元数据服务
                                IViewService     view        = ServiceHelper.GetService <IViewService>();                     //界面服务
                                FormMetadata     Meta        = metaService.Load(base.Context, "BD_MATERIAL") as FormMetadata; //获取基础资料元数据
                                DynamicObject    BasicObject = view.LoadSingle(base.Context, result, Meta.BusinessInfo.GetDynamicObjectType());
                                // 填写字段值
                                DynamicObjectCollection materialStock = BasicObject["MaterialStock"] as DynamicObjectCollection;
                                DynamicObjectCollection materialBase  = BasicObject["MaterialBase"] as DynamicObjectCollection;
                                foreach (DynamicObject base1 in materialStock)
                                {
                                    long          materialId = Convert.ToInt64(BasicObject["Id"]);
                                    DynamicObject unit       = base1["StoreUnitID"] as DynamicObject;
                                    long          unitId     = Convert.ToInt64(unit["Id"]);
                                    this.Model.BatchCreateNewEntryRow("FEntity", 1);
                                    //之前一行
                                    DynamicObject before = entrys[entrys.Count - 2] as DynamicObject;
                                    //新增分录行
                                    DynamicObject end     = entrys[entrys.Count - 1] as DynamicObject;
                                    DynamicObject stock   = before["StockID"] as DynamicObject;
                                    long          stockID = Convert.ToInt64(stock["Id"]);

                                    end["MaterialID"]    = BasicObject;
                                    end["MaterialID_Id"] = materialId;
                                    end["UnitID"]        = unit;
                                    end["UnitID_Id"]     = unitId;
                                    end["RealQty"]       = slx;
                                    end["StockID"]       = stock;
                                    end["StockID_Id"]    = stockID;
                                    end["BaseUnitQty"]   = slx;

                                    //this.Model.SetValue("MaterialID", BasicObject, entrys.Count);
                                    //this.Model.SetValue("UnitID", unitId, entrys.Count);
                                    //this.Model.SetValue("RealQty", slx, entrys.Count);
                                }
                            }
                        }
                    }
                }
                //新增分录行
            }
        }
Пример #24
0
        public override void DataChanged(DataChangedEventArgs e)
        {
            base.DataChanged(e);
            string key = e.Field.Key.ToUpperInvariant();

            #region 对数量监听,实现仓库携带。
            if (key == "FQTY" && e.NewValue != null)
            {
                string        transType = this.Model.GetValue("FAllocateType") as string;
                DynamicObject org       = this.Model.GetValue("FStockOrgId") as DynamicObject;
                string        orgId     = Convert.ToString(org["Id"]);
                DynamicObject line      = this.Model.GetValue("FLINE") as DynamicObject;
                DynamicObject salDept   = this.Model.GetValue("FSALEDEPTID") as DynamicObject;

                string sql0 = string.Format(@"select FdeptId from T_BD_DEPARTMENT_L where fname like '%分销站%' ");
                DynamicObjectCollection result1 = DBUtils.ExecuteDynamicObject(this.Context, sql0);

                DynamicObject destStock = this.Model.GetValue("FDESTSTOCKID") as DynamicObject;

                if (result1 != null)
                {    //调拨类型
                    if (transType != null && transType == "0")
                    {
                        //线路为空
                        if (line == null)
                        {
                            if (salDept != null)
                            {
                                string deptId = Convert.ToString(salDept["Id"]);
                                foreach (DynamicObject item in result1)
                                {
                                    if (Convert.ToString(item["FdeptId"]) == deptId)
                                    {
                                        string           sql1        = string.Format(@"select fstockid, fnumber
                                  from t_bd_stock
                                    where fdept = {0}
                                     and fstockid not in
                                       (select flinestock
                                          from t_tl_line
                                         where fdept = {0}
                                        union
                                        select freturnstock from t_tl_line where fdept = {0})", deptId);
                                        long             result      = DBUtils.ExecuteScalar <long>(base.Context, sql1, -1, null);
                                        IMetaDataService metaService = ServiceHelper.GetService <IMetaDataService>();                                   //元数据服务
                                        IViewService     view        = ServiceHelper.GetService <IViewService>();                                       //界面服务
                                        FormMetadata     Meta        = metaService.Load(base.Context, "BD_STOCK") as FormMetadata;                      //获取基础资料元数据
                                        DynamicObject    BasicObject = view.LoadSingle(base.Context, result, Meta.BusinessInfo.GetDynamicObjectType()); //不参与核算的库存状态ID

                                        string        sql2         = string.Format(@"
                                           select t1.fstockId from t_bd_stock t1 
                                            inner join t_bd_stock_l t2 on t1.fstockid = t2.fstockid
                                            where t2.fname='工厂成品库' and t1.Fuseorgid={0}
                                        ", orgId);
                                        long          result2      = DBUtils.ExecuteScalar <long>(base.Context, sql2, -1, null);
                                        DynamicObject BasicObject1 = view.LoadSingle(base.Context, result2, Meta.BusinessInfo.GetDynamicObjectType());

                                        //箱套类型
                                        int row = this.Model.GetEntryRowCount("FBillEntry");
                                        for (int i = 0; i < row; i++)
                                        {
                                            DynamicObject material = this.Model.GetValue("FMaterialId", i) as DynamicObject;
                                            if (material != null)
                                            {
                                                if (material["Number"].Equals("07040000") || material["Number"].Equals("07040004"))
                                                {
                                                    this.Model.SetValue("FDestStockId", BasicObject1, i);
                                                    this.Model.SetValue("FSRCSTOCKID", BasicObject, i);
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
            #endregion


            #region 对调拨类型监听,删除仓库
            if ((key == "FALLOCATETYPE" && e.NewValue != null) || (key == "FSALEDEPTID" && e.NewValue != null))
            {
                DynamicObject org     = this.Model.GetValue("FStockOrgId") as DynamicObject;
                string        orgId   = Convert.ToString(org["Id"]);
                DynamicObject line    = this.Model.GetValue("FLINE") as DynamicObject;
                DynamicObject salDept = this.Model.GetValue("FSALEDEPTID") as DynamicObject;

                string sql0 = string.Format(@"select FdeptId from T_BD_DEPARTMENT_L where fname like '%分销站%' ");
                DynamicObjectCollection result1 = DBUtils.ExecuteDynamicObject(this.Context, sql0);
                string transType = this.Model.GetValue("FAllocateType") as string;
                //if (transType != null && transType != "0")
                //{
                //    int row = this.Model.GetEntryRowCount("FBillEntry");
                //    for (int i = 0; i < row; i++)
                //    {
                //        //DynamicObject stockId = this.Model.GetValue("FSTOCKID") as DynamicObject;
                //        this.Model.SetValue("FDestStockId", null, i);
                //        this.Model.SetValue("FSRCSTOCKID", null, i);
                //    }

                //}

                if (transType != null && transType == "0")
                {
                    //线路为空
                    if (line == null)
                    {
                        if (salDept != null)
                        {
                            string deptId = Convert.ToString(salDept["Id"]);
                            foreach (DynamicObject item in result1)
                            {
                                if (Convert.ToString(item["FdeptId"]) == deptId)
                                {
                                    string           sql1        = string.Format(@"select fstockid, fnumber
                                  from t_bd_stock
                                    where fdept = {0}
                                     and fstockid not in
                                       (select flinestock
                                          from t_tl_line
                                         where fdept = {0}
                                        union
                                        select freturnstock from t_tl_line where fdept = {0})", deptId);
                                    long             result      = DBUtils.ExecuteScalar <long>(base.Context, sql1, -1, null);
                                    IMetaDataService metaService = ServiceHelper.GetService <IMetaDataService>();                                   //元数据服务
                                    IViewService     view        = ServiceHelper.GetService <IViewService>();                                       //界面服务
                                    FormMetadata     Meta        = metaService.Load(base.Context, "BD_STOCK") as FormMetadata;                      //获取基础资料元数据
                                    DynamicObject    BasicObject = view.LoadSingle(base.Context, result, Meta.BusinessInfo.GetDynamicObjectType()); //不参与核算的库存状态ID

                                    string        sql2         = string.Format(@"
                                           select t1.fstockId from t_bd_stock t1 
                                            inner join t_bd_stock_l t2 on t1.fstockid = t2.fstockid
                                            where t2.fname='工厂成品库' and t1.Fuseorgid={0}
                                        ", orgId);
                                    long          result2      = DBUtils.ExecuteScalar <long>(base.Context, sql2, -1, null);
                                    DynamicObject BasicObject1 = view.LoadSingle(base.Context, result2, Meta.BusinessInfo.GetDynamicObjectType());

                                    //箱套类型
                                    int row = this.Model.GetEntryRowCount("FBillEntry");
                                    for (int i = 0; i < row; i++)
                                    {
                                        DynamicObject material = this.Model.GetValue("FMaterialId", i) as DynamicObject;
                                        if (material != null)
                                        {
                                            if (material["Number"].Equals("07040000") || material["Number"].Equals("07040004"))
                                            {
                                                this.Model.SetValue("FDestStockId", BasicObject1, i);
                                                this.Model.SetValue("FSRCSTOCKID", BasicObject, i);
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
            #endregion

            #region 对线路的监听
            if (key == "FLINE" && e.NewValue == null)
            {
                DynamicObject org     = this.Model.GetValue("FStockOrgId") as DynamicObject;
                string        orgId   = Convert.ToString(org["Id"]);
                DynamicObject line    = this.Model.GetValue("FLINE") as DynamicObject;
                DynamicObject salDept = this.Model.GetValue("FSALEDEPTID") as DynamicObject;

                string sql0 = string.Format(@"select FdeptId from T_BD_DEPARTMENT_L where fname like '%分销站%' ");
                DynamicObjectCollection result1 = DBUtils.ExecuteDynamicObject(this.Context, sql0);
                string transType = this.Model.GetValue("FAllocateType") as string;
                if (transType != null && transType == "0")
                {
                    if (salDept != null)
                    {
                        string deptId = Convert.ToString(salDept["Id"]);
                        foreach (DynamicObject item in result1)
                        {
                            if (Convert.ToString(item["FdeptId"]) == deptId)
                            {
                                string           sql1        = string.Format(@"select fstockid, fnumber
                                  from t_bd_stock
                                    where fdept = {0}
                                     and fstockid not in
                                       (select flinestock
                                          from t_tl_line
                                         where fdept = {0}
                                        union
                                        select freturnstock from t_tl_line where fdept = {0})", deptId);
                                long             result      = DBUtils.ExecuteScalar <long>(base.Context, sql1, -1, null);
                                IMetaDataService metaService = ServiceHelper.GetService <IMetaDataService>();                                   //元数据服务
                                IViewService     view        = ServiceHelper.GetService <IViewService>();                                       //界面服务
                                FormMetadata     Meta        = metaService.Load(base.Context, "BD_STOCK") as FormMetadata;                      //获取基础资料元数据
                                DynamicObject    BasicObject = view.LoadSingle(base.Context, result, Meta.BusinessInfo.GetDynamicObjectType()); //不参与核算的库存状态ID

                                string        sql2         = string.Format(@"
                                           select t1.fstockId from t_bd_stock t1 
                                            inner join t_bd_stock_l t2 on t1.fstockid = t2.fstockid
                                            where t2.fname='工厂成品库' and t1.Fuseorgid={0}
                                        ", orgId);
                                long          result2      = DBUtils.ExecuteScalar <long>(base.Context, sql2, -1, null);
                                DynamicObject BasicObject1 = view.LoadSingle(base.Context, result2, Meta.BusinessInfo.GetDynamicObjectType());

                                //箱套类型
                                int row = this.Model.GetEntryRowCount("FBillEntry");
                                for (int i = 0; i < row; i++)
                                {
                                    DynamicObject material = this.Model.GetValue("FMaterialId", i) as DynamicObject;
                                    if (material != null)
                                    {
                                        if (material["Number"].Equals("07040000") || material["Number"].Equals("07040004"))
                                        {
                                            this.Model.SetValue("FDestStockId", BasicObject1, i);
                                            this.Model.SetValue("FSRCSTOCKID", BasicObject, i);
                                        }
                                    }
                                }
                            }
                        }
                    }
                }


                #endregion
            }
        }
        /// <summary>
        ///累加日计划面积
        /// </summary>
        /// <param name="e"></param>
        public override void EndOperationTransaction(EndOperationTransactionArgs e)
        {
            base.EndOperationTransaction(e);
            IViewService Services = ServiceHelper.GetService <IViewService>();

            if (selectedRows != null && selectedRows.Count() != 0)
            {
                IMetaDataService metadataService = Kingdee.BOS.App.ServiceHelper.GetService <IMetaDataService>();
                string           SoureFormId     = "SZXY_FHJTRSCJH";
                //获取单据元数据
                FormMetadata BilMetada = metadataService.Load(Context, SoureFormId) as FormMetadata;

                foreach (DynamicObject dy in selectedRows)
                {
                    string  Id       = Convert.ToString(dy["Id"]);
                    decimal Area     = 0;
                    string  RJHFid   = string.Empty;
                    string  RJHRowId = string.Empty;
                    RJHFid   = Convert.ToString(dy["F_SZXY_FIDH"]);
                    Area     = Convert.ToDecimal(dy["F_SZXY_InArea"]);
                    RJHRowId = Convert.ToString(dy["F_SZXY_FEntryIDH"]);
                    DynamicObject F_SZXY_MotherVolume = dy["F_SZXY_MotherVolume"] as  DynamicObject;
                    DynamicObject F_SZXY_ligature     = dy["F_SZXY_ligature"] as DynamicObject;


                    if (Area != 0 && !RJHFid.IsNullOrEmptyOrWhiteSpace() && Convert.ToInt32(RJHFid) > 0 && Convert.ToInt32(RJHRowId) > 0)
                    {
                        //单据头反写复合日计划实际完成面积

                        //DynamicObject RJHObejct = Utils.LoadFIDBillObject(this.Context, SoureFormId, RJHFid);
                        //if (RJHObejct["SZXY_FHJTRSCJHEntry"] is DynamicObjectCollection SoureEntry)
                        //{
                        //var Row = from row in SoureEntry
                        //          where Convert.ToString(row["id"]).EqualsIgnoreCase(RJHRowId)
                        //          select row;
                        //foreach (DynamicObject SoureRow in SoureEntry.Where(p => Convert.ToString(p["id"]).EqualsIgnoreCase(RJHRowId)))
                        //{
                        string MotherVolume = "";
                        string ligature     = "";
                        if (F_SZXY_MotherVolume != null)
                        {
                            MotherVolume = F_SZXY_MotherVolume["Id"].ToString();
                        }
                        if (F_SZXY_ligature != null)
                        {
                            ligature = F_SZXY_ligature["Id"].ToString();
                        }

                        string sql1 = $"/*dialect*/update SZXY_t_FHJTRSCJHEntry  set F_SZXY_ProductionArea=F_SZXY_ProductionArea+{Area}," +
                                      $" F_SZXY_WIRED='{ligature}', F_SZXY_MVolume='{MotherVolume}'" +
                                      $"  where Fid={RJHFid}" +
                                      $" and FEntryID={RJHRowId} ";
                        DBServiceHelper.Execute(Context, sql1);
                        //}

                        //}
                        //var saveResult = BusinessDataServiceHelper.Save(Context, BilMetada.BusinessInfo, RJHObejct);
                    }
                }
            }
        }