Ejemplo n.º 1
0
 public string GetValue(int index)
 {
     if (PK.Equals(FirstPart, StringComparison.OrdinalIgnoreCase))
     {
         //取相关的主键
         BillNoHelper billno = new BillNoHelper();
         if (!string.IsNullOrEmpty(SecondPart) && !string.IsNullOrEmpty(ThirdPart))
         {
             //表名与列名
             long phid = billno.GetBillId(SecondPart, ThirdPart);
             return(Convert.ToString(phid));
         }
     }
     if (BPK.Equals(FirstPart, StringComparison.OrdinalIgnoreCase))
     {
         //取相关业务主键
         if (!string.IsNullOrEmpty(SecondPart))
         {
             BillNoHelper billno = new BillNoHelper(SecondPart);
             var          id     = billno.GetBillNo();
             var          obj    = id.BillNoList;
             if (obj != null && obj.Count > 0)
             {
                 return(obj[0]);
             }
         }
     }
     throw new AddinException("无法解析出业务参数[" + Name + "]");
 }
Ejemplo n.º 2
0
        /// <summary>
        /// 用主键值来填充phid列
        /// </summary>
        /// <param name="jsonStr"></param>
        /// <returns></returns>
        public static string FillJsonStringWithPhid(string jsonStr)
        {
            string json = jsonStr;

            if (string.IsNullOrEmpty(jsonStr))
            {
                return(string.Empty);
            }

            JObject xmlobj = JsonConvert.DeserializeObject(jsonStr) as JObject;

            if (xmlobj == null)
            {
                return(json);
            }

            JToken jt = xmlobj["tablename"];

            if (jt == null)
            {
                return(json);
            }
            //更新的表名
            string tname = jt.ToString();

            //不处理直接返回
            if (string.IsNullOrEmpty(tname))
            {
                return(json);
            }

            JToken data = xmlobj["data"];

            if (data == null)
            {
                return(json);
            }

            string root  = "table";//grid传上来的数据
            JToken token = data["table"];

            if (token == null)
            {
                root = "form"; //form传上来的数据
            }

            JToken newRows = data[root]["newRow"];

            if (newRows == null)
            {
                goto rtn;
            }

            BillNoHelper billno = new BillNoHelper();

            if (newRows is JArray)
            {
                var array = newRows as JArray;

                //取得PHID,根据步长取得
                var pks = billno.GetBillId(tname, "phid", array.Count);

                for (int i = 0; i < array.Count; i++)
                {
                    JToken row = (array[i]["row"] == null) ? array[i] : array[i]["row"];
                    row["phid"] = pks.BillIdList[i];
                }
            }
            else
            {
                JToken row = (newRows["row"] == null) ? newRows : newRows["row"];
                row["phid"] = billno.GetBillId(tname, "phid"); //主键
            }

rtn:
            string newJson = JsonConvert.SerializeObject(data);

            //返回已经填充好的json字符串
            return(newJson);
        }