public bool SetInstanceData(string InstanceID, string WorkitemID, string bizObjectSchemaCode, string childSchemaCode, string detObjectID, DataTable dt, ref decimal amt)
    {
        BizObjectSchema schema = Engine.BizObjectManager.GetPublishedSchema(bizObjectSchemaCode);
        BizObject       bo     = new BizObject(Engine, schema, "");

        //BizObjectID
        bo.ObjectID = detObjectID;
        bo.Load(); // Load 是装载数据
        //设置主表字段的值
        int i = 0;

        if (bo[childSchemaCode] != null)
        {
            foreach (var v in (OThinker.H3.DataModel.BizObject[])bo[childSchemaCode])
            {
                i++;
            }
        }
        BizObjectSchema childSchema = schema.GetProperty(childSchemaCode).ChildSchema;

        BizObject[] bizObjects = new BizObject[i + dt.Rows.Count];
        int         j          = 0;

        if (bo[childSchemaCode] != null)
        {
            foreach (var v in (OThinker.H3.DataModel.BizObject[])bo[childSchemaCode])
            {
                bizObjects[j] = new BizObject(this.Engine, childSchema, this.UserValidator.UserID);
                bizObjects[j] = v;
                j++;
            }
        }



        foreach (DataRow dr in dt.Rows)
        {
            bizObjects[i] = new BizObject(this.Engine, childSchema, this.UserValidator.UserID);
            foreach (string item in childSchema.GetPropertyNames())
            {
                if (dt.Columns.Contains(item))
                {
                    if ("DKJE" == item)
                    {
                        amt = amt + Convert.ToDecimal(dr["DKJE"].ToString());
                    }
                    if ("LXJE" == item)
                    {
                        amt = amt + Convert.ToDecimal(dr["LXJE"].ToString());
                    }
                    bizObjects[i][item] = dr[item].ToString();
                }
            }
            i++;
        }

        bo[childSchemaCode] = bizObjects;

        return(bo.Update());
    }
        public JsonResult GetDataModelData(string DataModelCode, string QueryCode, string SortBy, int ShowCount, string BoundFiledList, string LinkFormat)
        {
            ActionResult result = new ActionResult(true);

            if (string.IsNullOrEmpty(BoundFiledList))
            {
                result.Message = "未设置绑定数据";
                return(Json(result, JsonRequestBehavior.AllowGet));
            }
            BizObjectSchema schema = Engine.BizObjectManager.GetPublishedSchema(DataModelCode);

            DataModel.BizQuery query = Engine.BizObjectManager.GetBizQuery(QueryCode);
            if (schema != null && query != null)
            {
                OThinker.H3.BizBus.Filter.Filter filter = GetFilter(schema, "GetList", query);
                filter.FromRowNum = 1;
                filter.ToRowNum   = ShowCount;
                if (ShowCount <= 0)
                {
                    filter.ToRowNum = 5;
                }
                //SORTBY是正常的语法 Column1,Column2 DESC
                if (string.IsNullOrEmpty(SortBy))
                {
                    SortBy = schema.GetPropertyNames()[0] + " DESC";
                }
                string[] arrSortKey = SortBy.Split(',');
                List <OThinker.H3.BizBus.Filter.SortBy> list = new List <OThinker.H3.BizBus.Filter.SortBy>();
                foreach (string str in arrSortKey)
                {
                    if (string.IsNullOrEmpty(str))
                    {
                        continue;
                    }
                    string   str2  = str.Trim();
                    string[] ssarr = str2.Split(' ');
                    if (ssarr.Length == 0 || string.IsNullOrEmpty(ssarr[0]))
                    {
                        continue;
                    }
                    string sortitem = ssarr[0];
                    OThinker.H3.BizBus.Filter.SortDirection sd = OThinker.H3.BizBus.Filter.SortDirection.Ascending;
                    for (var k = 1; k < ssarr.Length; k++)
                    {
                        if (string.IsNullOrEmpty(ssarr[k]))
                        {
                            continue;
                        }
                        if (ssarr[k].ToLower() == "asc")
                        {
                            break;
                        }
                        if (ssarr[k].ToLower() == "desc")
                        {
                            sd = OThinker.H3.BizBus.Filter.SortDirection.Descending;
                            break;
                        }
                    }
                    filter.AddSortBy(sortitem, sd);
                }
                DataModel.BizObject[] objs = schema.GetList(
                    this.Engine.Organization,
                    this.Engine.MetadataRepository,
                    this.Engine.BizObjectManager,
                    this.UserValidator.UserID,
                    "GetList",
                    filter);
                // 开始绑定数据源
                DataTable tablesource = DataModel.BizObjectUtility.ToTable(schema, objs);

                List <object> tr = new List <object>();
                foreach (DataRow dr in tablesource.Rows)
                {
                    List <object> td = new List <object>();
                    foreach (string field in BoundFiledList.Split(','))
                    {
                        string[] arrFields = field.Split('|');
                        string   column    = arrFields[0];
                        int      len       = 0;
                        int.TryParse(arrFields[1], out len);
                        string format = arrFields[2];
                        if (!tablesource.Columns.Contains(column))
                        {
                            continue;
                        }
                        string fv = dr[column].ToString();
                        //格式化
                        if (!string.IsNullOrEmpty(format))
                        {
                            if (format.StartsWith("{0:"))
                            {   //{0:****}格式
                                if (tablesource.Columns[column].DataType == typeof(Decimal))
                                {
                                    fv = String.Format(format, Convert.ToDecimal(dr[column]));
                                }
                                if (tablesource.Columns[column].DataType == typeof(DateTime))
                                {
                                    fv = String.Format(format, Convert.ToDateTime(dr[column]));
                                }
                            }
                            else
                            {//****格式
                                if (tablesource.Columns[column].DataType == typeof(Decimal))
                                {
                                    fv = Convert.ToDecimal(dr[column]).ToString(format);
                                }
                                if (tablesource.Columns[column].DataType == typeof(DateTime))
                                {
                                    fv = Convert.ToDateTime(dr[column]).ToString(format);
                                }
                            }
                        }
                        //截取长度
                        if (len > 0 && fv.Length > len)
                        {
                            fv = fv.Substring(0, len);
                        }
                        string datalink = "";
                        //匹配链接参数
                        if (!string.IsNullOrEmpty(LinkFormat))
                        {
                            string[] paras    = LinkFormat.Split('{');
                            string   currlink = LinkFormat;
                            //如果包含有{}, pcol就是要找的替换格式字段
                            for (var p = 1; p < paras.Length; p++)
                            {
                                string pcol = paras[p].Split('}')[0];
                                if (tablesource.Columns.Contains(pcol))
                                {
                                    currlink = currlink.Replace("{" + pcol + "}", Convert.ToString(dr[pcol]));
                                }
                                else
                                {
                                    currlink = currlink.Replace("{" + pcol + "}", "");
                                }
                            }
                            //datalink = "href=\"" + currlink + "\"  target=\"_blank\"";
                            datalink = currlink;
                        }
                        var newRow = new
                        {
                            Text = fv,
                            Href = string.IsNullOrEmpty(datalink) ? "#" : datalink
                        };
                        td.Add(newRow);
                    }
                    tr.Add(td);
                }
                result.Extend = tr;
            }
            return(Json(result, JsonRequestBehavior.AllowGet));
        }