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

public class D150516046321d5dbfc4d4e88380f736e51150e: H3.SmartForm.SmartFormController
{
    public D150516046321d5dbfc4d4e88380f736e51150e(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)
    {

        //=========================================================================判断现有库存数量大于出库数量================================================================================================================
        //p判断现有库存数量大于出库数量
        //库存单的构建schema
        H3.DataModel.BizObjectSchema schema = this.Request.Engine.BizObjectManager.GetPublishedSchema("D150516Schrygddhktx2lwxq4squp2zl2");
        //获取到领取单子表的数组对象
        H3.DataModel.BizObject[] childBo = (H3.DataModel.BizObject[]) this.Request.BizObject["D150516receive"];
        //获取到领取单的对象信息
        // H3.DataModel.BizObject targetBo50e = H3.DataModel.BizObject.Load(this.Request.UserContext.UserId, this.Engine, "D150516046321d5dbfc4d4e88380f736e51150e", this.Request.BizObjectId, false);
        foreach(H3.DataModel.BizObject child in childBo)
        {
            string sql = "select objectid,coding,address from i_D150516Schrygddhktx2lwxq4squp2zl2 where coding = '" + child["coding"] + "' and address='" + this.Request.BizObject["joinOffice"] + "'";
            System.Data.DataTable table = this.Engine.Query.QueryTable(sql, null);
            if(table != null && table.Rows.Count > 0 && table.Rows[0]["coding"] + string.Empty == child["coding"] + string.Empty && table.Rows[0]["address"] + string.Empty == this.Request.BizObject["joinOffice"] + string.Empty)
            {
                //new 一个库存单的对象
                H3.DataModel.BizObject targetBo = new H3.DataModel.BizObject(this.Engine, schema, this.Request.UserContext.UserId);
                foreach(System.Data.DataRow row in table.Rows)
                {
                    targetBo = H3.DataModel.BizObject.Load(this.Request.UserContext.UserId, this.Engine, "D150516Schrygddhktx2lwxq4squp2zl2", row["objectid"] + string.Empty, false);
                    if((int) Convert.ToInt32(targetBo["inventoryMains"]) >= (int) Convert.ToInt32(child["number"]))
                    {

                    } else
                    {
                        response.Errors.Add("物资编号为:" + child["coding"] + "现有数量不足!!!" + "还剩下" + (int) Convert.ToInt32(targetBo["inventoryMains"]));
                    }
                }
            } else
            {
                response.Errors.Add("此仓库没有物资编号为:" + child["coding"]);
            }
        }
        base.OnSubmit(actionName, postValue, response);

    }
    //=========================================================================流程结束后的业务规则对库存数量进行================================================================================================================

    //和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)
        {

            //获取到领取单子表的数组对象
            H3.DataModel.BizObject[] childBo = (H3.DataModel.BizObject[]) this.Request.BizObject["D150516receive"];
            //获取到领取单的对象信息
            // H3.DataModel.BizObject targetBoe = H3.DataModel.BizObject.Load(this.Request.UserContext.UserId, this.Engine, "D150516046321d5dbfc4d4e88380f736e51150e", this.Request.BizObjectId, false);
            foreach(H3.DataModel.BizObject child in childBo)
            {
                //库存单的构建schema
                H3.DataModel.BizObjectSchema schema = this.Request.Engine.BizObjectManager.GetPublishedSchema("D150516Schrygddhktx2lwxq4squp2zl2");
                //new 一个库存单的对象
                H3.DataModel.BizObject targetBo = new H3.DataModel.BizObject(this.Engine, schema, this.Request.UserContext.UserId);
                string sqlselect = "select * from i_D150516Schrygddhktx2lwxq4squp2zl2 where coding = '" + child["coding"] + "' and address='" + this.Request.BizObject["joinOffice"] + "'";
                System.Data.DataTable table = this.Engine.Query.QueryTable(sqlselect, null);
                if(table != null && table.Rows.Count > 0 && table.Rows[0]["coding"] + string.Empty == child["coding"] + string.Empty && table.Rows[0]["address"] + string.Empty == this.Request.BizObject["joinOffice"] + string.Empty)
                {
                    if(childBo != null && childBo.Length > 0)
                    {
                        //获取到库存单的load对象信息
                        targetBo = H3.DataModel.BizObject.Load(this.Request.UserContext.UserId, this.Engine, "D150516Schrygddhktx2lwxq4squp2zl2", table.Rows[0]["objectid"] + string.Empty, false);
                        //数量减少
                        targetBo["inventoryMains"] = double.Parse(targetBo["inventoryMains"] + string.Empty) - double.Parse(child["number"] + string.Empty);
                        targetBo.Update();


                        //更新库存
                        // string sql = "UPDATE i_D150516Schrygddhktx2lwxq4squp2zl2 a JOIN i_D150516receive b ON a.coding = b.coding and a.address='" + this.Request.BizObject["joinOffice"] + "'   SET a.inventoryMains = a.inventoryMains - b.number where " +
                        //     " b.parentobjectid = '" + this.Request.BizObjectId + "'";
                        // this.Engine.Query.QueryTable(sql, null);


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

 

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