/* 控件接口说明:
 * 1. 读取控件: this.***,*号输入控件编码;
 * 2. 读取控件的值: this.***.GetValue();
 * 3. 设置控件的值: this.***.SetValue(???);
 * 4. 绑定控件值变化事件: this.***.BindChange(key,function(){}),key是定义唯一的方法名;
 * 5. 解除控件值变化事件: this.***.UnbindChange(key);
 * 6. CheckboxList、DropDownList、RadioButtonList: $.***.AddItem(value,text),$.***.ClearItems();
 */
/* 公共接口:
 * 1. ajax:$.SmartForm.PostForm(actionName,data,callBack,errorBack,async),
 *          actionName:提交的ActionName;data:提交后台的数据;callback:回调函数;errorBack:错误回调函数;async:是否异步;
 * 2. 打开表单:$.IShowForm(schemaCode, objectId, checkIsChange),
 *          schemaCode:表单编码;objectId;表单数据Id;checkIsChange:关闭时,是否感知变化;
 * 3. 定位接口:$.ILocation();
 */
var that = this;
// 表单插件代码
$.extend( $.JForm, {
    // 加载事件
    OnLoad: function() {
        // that.material2.SetVisible( false );
        // that.material.SetVisible( false );
        // that.material3.SetVisible( false );

        if( $.SmartForm.ResponseContext.ActivityCode == "Activity2" ) {
            // 添加一行子表空白行
            var controlManager = that.D150516Addthemerchants;//获取子表控件对象
            var controlManager1 = that.D150516shoppingList;
            controlManager1.ClearRows();//清除子表行
            var subObjectId = $.IGuid();  //创建行ID
            controlManager.AddRow( subObjectId, {
                "D150516Addthemerchants.names": "",
                "D150516Addthemerchants.SupplierCategory": "",
                "D150516Addthemerchants.Principal2": "",
                "D150516Addthemerchants.iphone": "",
                "D150516Addthemerchants.bankofdeposits": "",
                "D150516Addthemerchants.bankcards": "",
                "D150516Addthemerchants.address": "",
                "D150516Addthemerchants.site": "",
            })
        }

        // var controlManager1 = that.D150516paCategoryChildList;//获取子表控件对象
        // if( $.SmartForm.ResponseContext.ActivityCode == "Activity2" && controlManager1[ "nameMaterial" ] != null && controlManager1[ "nameMaterial" ] != "" && controlManager1[ "supplier" ] == null && controlManager1[ "supplier" ] == "" ) {
        //     var subObjectId = $.IGuid();  //创建行ID
        //     controlManager1.AddRow( subObjectId, {
        //         "D150516paCategoryChildList.supplier": "that.joinPersonnel.GetValue()",
        //     })
        // }
    },
    //前端默认显示
    // var currentRowId = this.D150516shoppingList.GetValue()[ 0 ].ObjectId; //第一行子表ID                   
    // this.D150516shoppingList.UpdateRow( currentRowId, {
    //     "D150516shoppingList.categoryName1": "45e6e9f2-809b-4a9f-8a16-d6b19d338be9",
    // });

    //动态绑定
    // that.F0000002.BindChange( "key", function() {

    //     //此处是回调函数,要将this换成上面定义的that
    //     //获取值
    //     var value1 = that.F0000002.GetValue();
    //     //设置值

    //     that.F0000003.SetValue( value1 );

    // });



    // 按钮事件
    OnLoadActions: function( actions ) {

    },

    // 提交校验
    OnValidate: function( actionControl ) {
        return true;
    },

    // 提交前事件
    BeforeSubmit: function( action, postValue ) {
    },

    // 提交后事件
    AfterSubmit: function( action, responseValue ) {
        // //弹窗窗口 (弃用)
        // if( action == "material" ) {
        //     debugger
        //     var schemaCode = "D1505160cf9bbea9c6944f4bf7d451c86982138";//SchemaCode表单编码参数,需要打开的窗口编码
        //     var objectId = ""; //BizObjectID不传时打开新增时的表单
        //     var params = { SeasonObjectiveID: "" };//传递到表单的参数 JSON对象格式
        //     var checkIsChange = false;//是否检查修改
        //     var showlist = false;//兼容移动端是否显示列表
        //     var showInModal = true;//是否弹出框中显示,如果为false,title height width OnShowCallback OnHiddenCallback 等属性不起作用
        //     $.IShowForm( schemaCode, objectId, params, checkIsChange, showlist, {
        //         showInModal: true, title: "新增物资规格类型", height: 400, width: 800, OnShowCallback: function( da ) {
        //             console.log( da )
        //         }, onHiddenCallback: function( data ) {
        //             //弹出对应得控件id值
        //             // alert( data.Data.F0000001 );
        //             // console.log( da )
        //         }

        //     }); //OnShowCallback 显示时事件   onHiddenCallback 隐藏时事件

        // }
        // //弹窗窗口(弃用)
        // if( action == "material2" ) {
        //     debugger
        //     var schemaCode = "D150516category3";//SchemaCode表单编码参数,需要打开的窗口编码
        //     var objectId = ""; //BizObjectID不传时打开新增时的表单
        //     var params = { SeasonObjectiveID: "" };//传递到表单的参数 JSON对象格式
        //     var checkIsChange = false;//是否检查修改
        //     var showlist = false;//兼容移动端是否显示列表
        //     var showInModal = true;//是否弹出框中显示,如果为false,title height width OnShowCallback OnHiddenCallback 等属性不起作用
        //     $.IShowForm( schemaCode, objectId, params, checkIsChange, showlist, {
        //         showInModal: true, title: "新增物资信息", height: 600, width: 1000, OnShowCallback: function( da ) {
        //             console.log( da )
        //         }, onHiddenCallback: function( data ) {
        //             // alert( data.Data.nameMaterial );
        //             // console.log( da )
        //         }

        //     }); //OnShowCallback 显示时事件   onHiddenCallback 隐藏时事件

        // }
        // //弹窗窗口(弃用)
        // if( action == "material3" ) {
        //     debugger
        //     var schemaCode = "D150516vendor";//SchemaCode表单编码参数,需要打开的窗口编码
        //     var objectId = ""; //BizObjectID不传时打开新增时的表单
        //     var params = { SeasonObjectiveID: "" };//传递到表单的参数 JSON对象格式
        //     var checkIsChange = false;//是否检查修改
        //     var showlist = false;//兼容移动端是否显示列表
        //     var showInModal = true;//是否弹出框中显示,如果为false,title height width OnShowCallback OnHiddenCallback 等属性不起作用
        //     $.IShowForm( schemaCode, objectId, params, checkIsChange, showlist, {
        //         showInModal: true, title: "新增供应商", height: 800, width: 1000, OnShowCallback: function( da ) {
        //             console.log( da )
        //         }, onHiddenCallback: function( data ) {
        //             // alert( data.Data.names );
        //             // console.log( da )
        //         }

        //     }); //OnShowCallback 显示时事件   onHiddenCallback 隐藏时事件

        // }

    }
});

 

using System;
using System.Collections.Generic;
using System.Text;
using H3;

public class D150516purchasingApplication: H3.SmartForm.SmartFormController
{

    public D150516purchasingApplication(H3.SmartForm.SmartFormRequest request): base(request)
    {
    }

    protected override void OnLoad(H3.SmartForm.LoadSmartFormResponse response)
    {
        base.OnLoad(response);
    }

    protected override void OnSubmit(string actionName, H3.SmartForm.SmartFormPostValue postValue, H3.SmartForm.SubmitSmartFormResponse response)
    {
        //=========================================================================都是需要创建的各种对象===============================================================================================================
        // //物资目录的构建schema
        H3.DataModel.BizObjectSchema schemaCategory3 = this.Request.Engine.BizObjectManager.GetPublishedSchema("D150516category3");
        // //获取到采购申请单采购清单的对象
        H3.DataModel.BizObject[] childBoList = (H3.DataModel.BizObject[]) this.Request.BizObject["D150516shoppingList"];
        //采购申请单的构建schema
        H3.DataModel.BizObjectSchema schemation = this.Request.Engine.BizObjectManager.GetPublishedSchema("D150516purchasingApplication");
        //获取到采购申请单的对象
        H3.DataModel.BizObject targetBoPA = H3.DataModel.BizObject.Load(this.Request.UserContext.UserId, this.Engine, "D150516purchasingApplication", this.Request.BizObjectId, false);
        //供应商的构建schema
        H3.DataModel.BizObjectSchema schemaVendor = this.Request.Engine.BizObjectManager.GetPublishedSchema("D150516vendor");
        //new供应商一个对象
        H3.DataModel.BizObject targetBoVendor = new H3.DataModel.BizObject(this.Engine, schemaVendor, this.Request.UserContext.UserId);
        //获取到采购申请单新增供应商子表的对象
        H3.DataModel.BizObject[] childBoAddthemerchants = (H3.DataModel.BizObject[]) this.Request.BizObject["D150516Addthemerchants"];
        //获取到采购申请单新增物资子表的对象
        H3.DataModel.BizObject[] childPaCategory = (H3.DataModel.BizObject[]) this.Request.BizObject["D150516paCategoryChildList"];
        H3.DataModel.BizObject childBoChild = new H3.DataModel.BizObject(this.Request.Engine, schemation.GetChildSchema("D150516paCategoryChildList"), this.Request.UserContext.UserId);



        //=========================================================================提交后Activity3更新供应商信息================================================================================================================
        //提交后新增供应商
        if(actionName == "Submit" && this.Request.ActivityCode == "Activity3")
        {
            if(childBoAddthemerchants != null && childBoAddthemerchants.Length > 0)
            {
                foreach(H3.DataModel.BizObject child in childBoAddthemerchants)
                {
                    //供应商名称
                    targetBoVendor["names"] = child["names"] + string.Empty;
                    //供应商类别 
                    targetBoVendor["SupplierCategory"] = child["SupplierCategory"] + string.Empty;
                    //供应商类别负责人
                    targetBoVendor["Principal2"] = child["Principal2"] + string.Empty;
                    //电话号码
                    targetBoVendor["iphone"] = child["iphone"] + string.Empty;
                    //开户行
                    targetBoVendor["bankofdeposit"] = child["bankofdeposits"] + string.Empty;
                    //银行账户
                    targetBoVendor["bankcard"] = child["bankcards"] + string.Empty;
                    //区域
                    targetBoVendor["address"] = child["address"] + string.Empty;
                    //地址
                    targetBoVendor["site"] = child["site"] + string.Empty;
                    //设置业务对象数据为生效状态
                    targetBoVendor.Status = H3.DataModel.BizObjectStatus.Effective;
                    //目标表单创建
                    targetBoVendor.Create();

                }

            }

        }

        //=========================================================================提交后Activity3更新本表单供应商信息================================================================================================================
        if(actionName == "Submit" && this.Request.ActivityCode == "Activity3")
        {
            //将新增的供应商名称放在本表单的供应商名称中
            this.Request.BizObject["joinPersonnel"] = targetBoVendor.ObjectId;
            //开户银行
            this.Request.BizObject["bankofdeposit"] = targetBoVendor["bankofdeposit"];
            //银行账户
            this.Request.BizObject["bankcard"] = targetBoVendor["bankcard"];
        }



        base.OnSubmit(actionName, postValue, response);

        //=========================================================================提交后Activity4新增目标表单物资信息================================================================================================================
        if(childPaCategory != null && childPaCategory.Length > 0)
        {

            foreach(H3.DataModel.BizObject child in childPaCategory)
            {
                //供应商名称主表赋值给子表
                if((child["nameMaterial"] + string.Empty != null || child["nameMaterial"] + string.Empty != "") && (child["supplier"] + string.Empty == null || child["supplier"] + string.Empty == "")
                    && (this.Request.BizObject["joinPersonnel"] + string.Empty != null || this.Request.BizObject["joinPersonnel"] + string.Empty != ""))
                {
                    child["supplier"] = this.Request.BizObject["joinPersonnel"] + string.Empty;
                }
            }
        }
        // 新增物资的方法,在审批供应商时加载出所有数据
        if(actionName == "Submit" && this.Request.ActivityCode == "Activity4")
        {
            if(childPaCategory != null && childPaCategory.Length > 0)
            {
                // 加一个list集合,将数据添加至集合中
                List < H3.DataModel.BizObject > list = new List<H3.DataModel.BizObject>();
                //判断子表数据是否为空,不为空则保存
                if(childBoList != null)
                {
                    //先将原来的子表数据存起来
                    list.AddRange(childBoList);
                }
                foreach(H3.DataModel.BizObject child in childPaCategory)
                {
                    //new物资目录一个对象
                    H3.DataModel.BizObject targetBoCategory3 = new H3.DataModel.BizObject(this.Engine, schemaCategory3, this.Request.UserContext.UserId);
                    //物资名称
                    targetBoCategory3["nameMaterial"] = child["nameMaterial"] + string.Empty;
                    //规格型号
                    targetBoCategory3["specification"] = child["specification"] + string.Empty;
                    //物资出厂码
                    targetBoCategory3["MaterialFactoryCode"] = child["F1"] + string.Empty;
                    //物资类别
                    targetBoCategory3["categoryName1"] = child["categoryName1"] + string.Empty;
                    //物资类别负责人
                    targetBoCategory3["principal"] = child["principal"] + string.Empty;
                    //供应商名称
                    targetBoCategory3["joinPersonnel"] = child["supplier"] + string.Empty;
                    //计量单位
                    targetBoCategory3["measurement"] = child["measuringUnit"] + string.Empty;
                    //设置业务对象数据为生效状态
                    targetBoCategory3.Status = H3.DataModel.BizObjectStatus.Effective;
                    //目标表单创建
                    targetBoCategory3.Create();
                    //=========================================================================提交后Activity4更新本表单物资信息================================================================================================================

                    string sqlchildBo = "select * from i_D150516category3 where  ObjectId='" + targetBoCategory3.ObjectId + "'";
                    System.Data.DataTable  dt = this.Request.Engine.Query.QueryTable(sqlchildBo, null);
                    foreach(System.Data.DataRow row in dt.Rows)
                    {
                        //new一个采购清单业务对象
                        H3.DataModel.BizObject childBoList1 = new H3.DataModel.BizObject(this.Request.Engine, schemation.GetChildSchema("D150516shoppingList"), H3.Organization.User.SystemUserId);

                        {
                            //数据添加采购清单
                            //规格型号
                            childBoList1["specifications"] = row["ObjectId"];
                            //物资名称
                            childBoList1["materialName"] = row["nameMaterial"];
                            //物资出厂码
                            childBoList1["MaterialFactoryCode"] = row["MaterialFactoryCode"];
                            //物资编码
                            childBoList1["MaterialFactoryCodes"] = row["SeqNo"];
                            //物资类别
                            childBoList1["categoryName1"] = row["categoryName1"];
                            //计量单位
                            childBoList1["measuringUnit"] = row["measurement"];
                            list.Add(childBoList1);
                        }
                        //将新的子表数据集合赋值到子表控件
                        targetBoPA["D150516shoppingList"] = list.ToArray();
                        //更新主表数据
                        targetBoPA.Update();

                    }
                }

            }
        }
    }

    //========================================================================结束后流程运行的业务规则=================================================================================================================

    //和OnLoad平级,为重写方法
    protected override void OnWorkflowInstanceStateChanged(H3.Workflow.Instance.WorkflowInstanceState oldState, H3.Workflow.Instance.WorkflowInstanceState newState)
    {
        //流程审批结束事件(先执行业务规则,在执行该方法)。
        if(oldState == H3.Workflow.Instance.WorkflowInstanceState.Running && newState == H3.Workflow.Instance.WorkflowInstanceState.Finished)
        {

            //=========================================================================自动创建入库单=================================================================================================================
            //办公耗材入库单的构建schema
            H3.DataModel.BizObjectSchema schema = this.Request.Engine.BizObjectManager.GetPublishedSchema("D1505165b8d9780f9e349ab90537f34db37d255");
            //new办公耗材入库单一个对象
            H3.DataModel.BizObject targetBo = new H3.DataModel.BizObject(this.Engine, schema, this.Request.UserContext.UserId);
            //获取到采购申请单采购清单的对象
            H3.DataModel.BizObject[] childBo2 = (H3.DataModel.BizObject[]) this.Request.BizObject["D150516shoppingList"];
            //获取到采购申请单的对象
            H3.DataModel.BizObject targetBo2 = H3.DataModel.BizObject.Load(this.Request.UserContext.UserId, this.Engine, "D150516purchasingApplication", this.Request.BizObjectId, false);


            //此方法是将本表单的采购清单数据信息放进入库单中
            if(childBo2 != null && childBo2.Length > 0)
            {
                //加一个list集合,将数据添加至集合中
                List < H3.DataModel.BizObject > childList = new List<H3.DataModel.BizObject>();

                foreach(H3.DataModel.BizObject child in childBo2)
                {
                    //获取到办公耗材入库单子表的业务对象
                    H3.DataModel.BizObject childBo = new H3.DataModel.BizObject(this.Request.Engine, schema.GetChildSchema("D150516storageTime"), this.Request.UserContext.UserId);
                    //办公耗材入库单的办公耗材采购申请单号对应采购申请单的办公耗材采购申请单号
                    targetBo["godown"] = this.Request.BizObjectId + string.Empty;
                    //采购人
                    targetBo["joinPersonnel01"] = targetBo2.CreatedBy + string.Empty;
                    //费用支付方式
                    targetBo["costbreakdown"] = targetBo2["costbreakdown"] + string.Empty;
                    //判断是否是个人是个人就更新付款状态
                    if(this.Request.BizObject["costbreakdown"] + string.Empty != null && this.Request.BizObject["costbreakdown"] + string.Empty == "个人")
                    {
                        targetBo["payment2"] = true;
                    }
                    //仓库
                    targetBo["joinOffice"] = targetBo2["joinOffice"] + string.Empty;
                    //库管
                    targetBo["joinPersonnel02"] = targetBo2["joinPersonnel02"] + string.Empty;
                    //申请日期
                    targetBo["purchaseTime"] = this.Request.BizObject["time"] + string.Empty;
                    //供应商
                    targetBo["joinPersonnel"] = targetBo2["joinPersonnel"] + string.Empty;
                    //临时供应商
                    targetBo["joinPersonnel1"] = targetBo2["joinPersonnel1"] + string.Empty;
                    //物料名称
                    childBo["materialName"] = child["materialName"] + string.Empty;
                    //规格型号
                    childBo["model"] = child["specifications"] + string.Empty;
                    //物资出厂码
                    childBo["coding"] = child["MaterialFactoryCode"] + string.Empty;
                    //物资编码
                    childBo["MaterialFactoryCodes"] = child["MaterialFactoryCodes"] + string.Empty;
                    //物资类别
                    childBo["categoryName1"] = child["categoryName1"] + string.Empty;
                    //计量单位
                    childBo["measuringUnit"] = child["measuringUnit"] + string.Empty;
                    //数量
                    childBo["number"] = child["number"] + string.Empty;
                    //单价
                    childBo["price"] = child["price"] + string.Empty;
                    //总价
                    childBo["totalPrices"] = child["totalPrice"] + string.Empty;
                    //总金额
                    targetBo["totalMoney"] = this.Request.BizObject["totalAmount"] + string.Empty;
                    //将数据添加到子表
                    childList.Add(childBo);
                }
                //存入子表数据 格式为H3.DataModel.BizObject[]
                targetBo["D150516storageTime"] = childList.ToArray();
                //状态改为进行中
                targetBo.Status = H3.DataModel.BizObjectStatus.Running;
                string instanceId = System.Guid.NewGuid().ToString();
                if(string.IsNullOrEmpty(targetBo.WorkflowInstanceId))
                    targetBo.WorkflowInstanceId = instanceId;
                //目标表单创建
                targetBo.Create();
                //对付款单进行流程操作,使其直接跳过发起人节点
                H3.Workflow.Instance.WorkflowInstance wfInstance = this.Engine.WorkflowInstanceManager.GetWorkflowInstance(targetBo.WorkflowInstanceId);
                if(wfInstance == null)
                {
                    //启动流程
                    string workItemID = string.Empty;
                    string errorMsg = string.Empty;
                    H3.Workflow.Template.WorkflowTemplate wfTemp = this.Engine.WorkflowTemplateManager.GetDefaultWorkflow(targetBo.Schema.SchemaCode);
                    this.Engine.Interactor.OriginateInstance(this.Request.UserContext.UserId, targetBo.Schema.SchemaCode,
                        wfTemp.WorkflowVersion, targetBo.ObjectId, targetBo.WorkflowInstanceId, H3.Workflow.WorkItem.AccessMethod.Web,
                        true, string.Empty, true, out workItemID, out errorMsg);
                }

            }
            //=========================================================================================================================================================================================



            //=========================================================================自动创建付款单=================================================================================================================
            //付款单的schema1
            H3.DataModel.BizObjectSchema schema1 = this.Request.Engine.BizObjectManager.GetPublishedSchema("D150516paymentOrder");
            //new付款单一个对象
            H3.DataModel.BizObject targetBoPay = new H3.DataModel.BizObject(this.Engine, schema1, this.Request.UserContext.UserId);

            //这是把本表单的信息填充到付款单中
            if(this.Request.BizObject["costbreakdown"] + string.Empty != null && this.Request.BizObject["costbreakdown"] + string.Empty == "个人")
            {
                targetBo2["payment"] = true;
                targetBo2.Update();
            } else
            {
                //采购人
                targetBoPay["Purchasingapplicant"] = targetBo2.CreatedBy + string.Empty;
                //办公耗材入库单的办公耗材采购申请单号对应采购申请单的办公耗材采购申请单号
                targetBoPay["consumables"] = this.Request.BizObjectId + string.Empty;
                //费用支付方式
                targetBoPay["F0000003"] = this.Request.BizObject["costbreakdown"] + string.Empty;
                //当选择临时供应商时所需要的赋值判断
                if(this.Request.BizObject["costbreakdown"] + string.Empty != null && this.Request.BizObject["costbreakdown"] + string.Empty == "临时供应商") 
                {

                    //临时商户名称
                    targetBoPay["supplier1"] = this.Request.BizObject["joinPersonnel1"] + string.Empty;
                    //临时开户行
                    targetBoPay["bankofdeposit2"] = this.Request.BizObject["bankofdeposit1"] + string.Empty;
                    //临时银行账号
                    targetBoPay["bankcard2"] = this.Request.BizObject["bankcard1"] + string.Empty;
                }

                //商户名称
                targetBoPay["supplier"] = this.Request.BizObject["joinPersonnel"] + string.Empty;

                //开户行
                targetBoPay["bankofdeposit1"] = this.Request.BizObject["bankofdeposit"] + string.Empty;
                //银行账号
                targetBoPay["bankcard1"] = this.Request.BizObject["bankcard"] + string.Empty;
                //总金额
                targetBoPay["paymentamount"] = this.Request.BizObject["totalAmount"] + string.Empty;
                //状态改为进行中
                targetBoPay.Status = H3.DataModel.BizObjectStatus.Running;
                string instanceId = System.Guid.NewGuid().ToString();
                if(string.IsNullOrEmpty(targetBoPay.WorkflowInstanceId))
                    targetBoPay.WorkflowInstanceId = instanceId;
                //目标表单创建
                targetBoPay.Create();
                //对付款单进行流程操作,使其直接跳过发起人节点
                H3.Workflow.Instance.WorkflowInstance wfInstance = this.Engine.WorkflowInstanceManager.GetWorkflowInstance(targetBoPay.WorkflowInstanceId);
                if(wfInstance == null)
                {
                    //启动流程
                    string workItemID = string.Empty;
                    string errorMsg = string.Empty;
                    H3.Workflow.Template.WorkflowTemplate wfTemp = this.Engine.WorkflowTemplateManager.GetDefaultWorkflow(targetBoPay.Schema.SchemaCode);
                    this.Engine.Interactor.OriginateInstance(this.Request.UserContext.UserId, targetBoPay.Schema.SchemaCode,
                        wfTemp.WorkflowVersion, targetBoPay.ObjectId, targetBoPay.WorkflowInstanceId, H3.Workflow.WorkItem.AccessMethod.Web,
                        true, string.Empty, true, out workItemID, out errorMsg);
                }//第七个参数 false/true 为是否提交流程操作
                // activationProcess("Activity4");
            }

            //==========================================================================================================================================================================================

        }
        base.OnWorkflowInstanceStateChanged(oldState, newState);
    }
}

 

posted on 2022-05-12 09:39  天涯何  阅读(58)  评论(0编辑  收藏  举报