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

public class D1505165b8d9780f9e349ab90537f34db37d255: H3.SmartForm.SmartFormController
{
    public D1505165b8d9780f9e349ab90537f34db37d255(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)
    {
        string activitycode = this.Request.ActivityCode;
        //在付款出纳的流程上将入库和采购的付款状态更改
        if(actionName == "Submit" && activitycode == "Activity3")
        {
            //更新办公耗材采购单的状态
            string sql = "select * from i_D150516purchasingApplication where objectid='" + this.Request.BizObject["godown"] + "'";
            System.Data.DataTable  dt = this.Request.Engine.Query.QueryTable(sql, null);
            if(dt != null && dt.Rows.Count > 0)//中括号里面接数字取数组里面的值
            {
                H3.DataModel.BizObject accountBo = H3.DataModel.BizObject.Load(H3.Organization.User.SystemUserId, this.Request.Engine, "D150516purchasingApplication", dt.Rows[0]["objectid"] + string.Empty, false);
                accountBo["STOCK"] = true;
                accountBo.Update();  //更新对象
            }
        }
        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["D150516storageTime"];
            if(childBo != null && childBo.Length > 0)
            {
                //加一个list集合,将数据添加至集合中
                List < H3.DataModel.BizObject > childList = new List<H3.DataModel.BizObject>();
                //获取到入库单的对象信息
                H3.DataModel.BizObject targetBo2 = H3.DataModel.BizObject.Load(this.Request.UserContext.UserId, this.Engine, "D1505165b8d9780f9e349ab90537f34db37d255", this.Request.BizObjectId, false);

                // for(int i = 0; i < childBo.Length; i++)//正常循环都还是这样写的,和java差不多少,只是这里foreach比java方便不少
                // {
                //     H3.DataModel.BizObject child = childBo[i];
                // }

                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   childBoCodes = child["MaterialFactoryCodes"] + string.Empty;
                    //仓库
                    string   joinOffice = targetBo2["joinOffice"] + string.Empty;

                    //查询 编码和仓库
                    string sqlcoding = "select * from i_D150516Schrygddhktx2lwxq4squp2zl2 where coding = '" + child["MaterialFactoryCodes"] + "' and address='" + targetBo2["joinOffice"] + "'";
                    System.Data.DataTable  dt = this.Request.Engine.Query.QueryTable(sqlcoding, null);
                    //判断是否有此物资,有此物资则更新数量,无此物资则创建此物资
                    if(dt != null && dt.Rows.Count > 0 && dt.Rows[0]["coding"] + string.Empty == childBoCodes && dt.Rows[0]["address"] + string.Empty == joinOffice)//中括号里面接数字取数组里面的值
                    {
                        //获取到库存单的load对象信息
                        targetBo = H3.DataModel.BizObject.Load(this.Request.UserContext.UserId, this.Engine, "D150516Schrygddhktx2lwxq4squp2zl2", dt.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_D150516storageTime b ON a.coding = b.MaterialFactoryCodes and a.address='" + joinOffice + "' SET a.inventoryMains = a.inventoryMains + b.number where " +
                        //     " b.parentobjectid = '" + this.Request.BizObjectId + "'";
                        // this.Engine.Query.QueryTable(sql, null);
                    } else
                    {   //物资名称
                        targetBo["nameMaterial"] = child["materialName"] + string.Empty;
                        //规格型号
                        targetBo["specification"] = child["model"] + string.Empty;
                        //物资类别
                        targetBo["category"] = child["categoryName1"] + string.Empty;
                        //物资出厂码
                        targetBo["MaterialFactoryCode"] = child["coding"] + string.Empty;
                        //物资编码
                        targetBo["coding"] = child["MaterialFactoryCodes"] + string.Empty;
                        //供应商名称
                        targetBo["supplier"] = targetBo2["joinPersonnel"] + string.Empty;
                        //现有库存
                        targetBo["inventoryMains"] = child["number"] + string.Empty;
                        //计量单位
                        targetBo["measureUnit"] = child["measuringUnit"] + string.Empty;
                        //仓库
                        targetBo["address"] = targetBo2["joinOffice"] + string.Empty;
                        //库管
                        targetBo["principal"] = targetBo2["joinPersonnel02"] + string.Empty;
                        //设置业务对象数据为生效状态
                        targetBo.Status = H3.DataModel.BizObjectStatus.Effective;
                        //目标表单创建
                        targetBo.Create();
                    }

                }

            }
        }
        base.OnWorkflowInstanceStateChanged(oldState, newState);
    }
}
/* 控件接口说明:
 * 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 ActivityCode = $.SmartForm.ResponseContext.ActivityCode;
var that = this;
// 表单插件代码
$.extend( $.JForm, {
    // 加载事件
    OnLoad: function() {
    },

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

    // 提交校验
    OnValidate: function( actionControl ) {
        if( actionControl.Action == "Submit" && ActivityCode == "Activity2" ) {
            var payment2 = that.payment2.GetValue(); 
            if(!payment2) {
                $.IShowWarn( "错误", "还未完成付款!!!" );
            }
            return payment2;
        }
        return true;
    },

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

    // 提交后事件
    AfterSubmit: function( action, responseValue ) {
    }
});

 

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