예제 #1
0
 public static bool JsonToStructure(string jsonString, BizStructure structure, out string errorMessage)
 {
     try
     {
         JObject jobject = Newtonsoft.Json.Linq.JObject.Parse(jsonString);
         if (jobject == null)
         {
             errorMessage = "传入的数据位空";
             return(false);
         }
         return(JObjectToStructure(jobject, structure, out errorMessage));
     }
     catch (Exception ex)
     {
         errorMessage = ex.ToString();
         return(false);
     }
 }
예제 #2
0
 static private void ConvertUnitCodeToIds(List <KeyValuePair <BizStructure, string> > changedProperties, Dictionary <string, string> unitCodeIdTable)
 {
     foreach (KeyValuePair <BizStructure, string> pair in changedProperties)
     {
         BizStructure obj  = pair.Key;
         string       name = pair.Value;
         ItemSchema   p    = obj.Schema.GetItem(name);
         object       v    = obj[p.Name];
         if (v == null)
         {
             continue;
         }
         if (p.DataType == BizDataType.Unit)
         {
             if (!unitCodeIdTable.ContainsKey((string)v))
             {
                 obj[p.Name] = null;
             }
             else
             {
                 obj[p.Name] = unitCodeIdTable[(string)v];
             }
         }
         else if (p.DataType == BizDataType.UnitArray)
         {
             string[] vs = (string[])v;
             for (int i = 0; i < vs.Length; i++)
             {
                 string _v = vs[i];
                 if (string.IsNullOrEmpty(_v) || !unitCodeIdTable.ContainsKey(_v))
                 {
                     vs[i] = null;
                 }
                 else
                 {
                     vs[i] = unitCodeIdTable[_v];
                 }
             }
             obj[p.Name] = vs;
         }
     }
 }
예제 #3
0
        public static bool JsonToStructures(string[] jsonStrings, BizStructure[] structures, out string errorMessage)
        {
            structures   = null;
            errorMessage = null;
            if (jsonStrings == null)
            {
                return(true);
            }
            List <BizStructure> ss = new List <BizStructure>();

            foreach (string s in jsonStrings)
            {
                BizStructure structure = null;
                if (!JsonToStructure(s, structure, out errorMessage))
                {
                    return(false);
                }
                ss.Add(structure);
            }
            structures = ss.ToArray();
            return(true);
        }
예제 #4
0
        public static bool JsonToListResult(string json, out ListResult result, out string errorMessage)
        {
            errorMessage = null;
            result       = null;
            try
            {
                JObject jobject = Newtonsoft.Json.Linq.JObject.Parse(json);
                if (jobject == null)
                {
                    errorMessage = "传入的数据位空";
                    return(false);
                }
                int    resultCode = (int)ErrorCode.GeneralFailed;
                string message    = null;
                H3.BizBus.BizStructure[]     structures = null;
                H3.BizBus.BizStructureSchema schema     = null;
                int count = -1;

                foreach (KeyValuePair <string, JToken> keyValuePair in jobject)
                {
                    if (string.Compare(keyValuePair.Key, "schema", true) == 0)
                    {
                        if (keyValuePair.Value == null)
                        {
                        }
                        else if (!(keyValuePair.Value is JObject))
                        {
                            errorMessage = "传入的数据格式不正确";
                        }
                        else
                        {
                            if (!JObjectToSchema((JObject)keyValuePair.Value, out schema, out errorMessage))
                            {
                                return(false);
                            }
                        }
                    }
                }
                if (schema == null)
                {
                    errorMessage = "传入的数据没有包含Schema属性";
                    return(false);
                }

                foreach (KeyValuePair <string, JToken> keyValuePair in jobject)
                {
                    if (string.Compare(keyValuePair.Key, "code", true) == 0)
                    {
                        string s = keyValuePair.Value == null ? null : keyValuePair.Value.ToString();
                        int.TryParse(s, out resultCode);
                    }
                    else if (string.Compare(keyValuePair.Key, "count", true) == 0)
                    {
                        string s = keyValuePair.Value == null ? null : keyValuePair.Value.ToString();
                        int.TryParse(s, out count);
                    }
                    else if (string.Compare(keyValuePair.Key, "message", true) == 0)
                    {
                        message = keyValuePair.Value == null ? null : keyValuePair.Value.ToString();
                    }
                    else if (string.Compare(keyValuePair.Key, "data", true) == 0)
                    {
                        if (keyValuePair.Value == null)
                        {
                        }
                        else if (!(keyValuePair.Value is JArray))
                        {
                            errorMessage = "传入的数据格式不正确";
                        }
                        else
                        {
                            structures = new BizStructure[keyValuePair.Value.Count()];
                            int i = 0;
                            foreach (JObject o in keyValuePair.Value)
                            {
                                structures[i] = new BizStructure(schema);
                                if (!JObjectToStructure(o, structures[i], out errorMessage))
                                {
                                    return(false);
                                }
                                i++;
                            }
                        }
                    }
                }
                result = new ListResult(resultCode, message, structures, count);
                return(true);
            }
            catch (Exception ex)
            {
                errorMessage = ex.ToString();
                return(false);
            }
        }
예제 #5
0
        public static string StructureToJson(BizStructure structure)
        {
            if (structure == null)
            {
                return(null);
            }
            System.Text.StringBuilder jsonString = new System.Text.StringBuilder();
            BizStructureSchema        schema     = structure.Schema;

            ItemSchema[] properties = schema.Items;
            jsonString.Append("{");
            foreach (ItemSchema p in properties)
            {
                object v = structure[p.Name];
                if (v == null)
                {
                    continue;
                }

                jsonString.Append("\"" + p.Name + "\":");
                if (p.DataType == BizDataType.UnitArray)
                {
                    string[] ids = (string[])v;
                    jsonString.Append("[");
                    if (ids.Length > 0)
                    {
                        foreach (string code in ids)
                        {
                            jsonString.Append("\"" + code + "\",");
                        }
                        jsonString.Remove(jsonString.Length - 1, 1);
                    }
                    jsonString.Append("],");
                }
                else if (p.DataType == BizDataType.BizStructure)
                {
                    jsonString.Append(StructureToJson((BizStructure)v) + ",");
                }
                else if (p.DataType == BizDataType.BizStructureArray)
                {
                    BizStructure[] children = (BizStructure[])v;
                    jsonString.Append("[");
                    foreach (BizStructure child in children)
                    {
                        jsonString.Append(StructureToJson(child) + ",");
                    }
                    if (jsonString[jsonString.Length - 1] == ',')
                    {
                        jsonString.Remove(jsonString.Length - 1, 1);
                    }
                    jsonString.Append("],");
                }
                else
                {
                    jsonString.Append("\"" + v.ToString() + "\",");
                }
            }
            if (jsonString[jsonString.Length - 1] == ',')
            {
                jsonString.Remove(jsonString.Length - 1, 1);
            }
            jsonString.Append("}");
            return(jsonString.ToString());
        }
예제 #6
0
        private static bool JObjectToStructure(JObject jobject, BizStructure obj, out string errorMessage)
        {
            errorMessage = null;

            // 赋值进去
            foreach (KeyValuePair <string, JToken> keyValuePair in jobject)
            {
                ItemSchema property = obj.Schema.GetItem(keyValuePair.Key);
                if (keyValuePair.Value == null)
                {
                    continue;
                }
                else if (property == null)
                {
                    continue;
                }
                else if (property.DataType == BizDataType.BizStructure)
                {
                    BizStructure childObject = null;
                    if (keyValuePair.Value.ToString() != "")
                    {
                        if (!(keyValuePair.Value is JObject))
                        {
                            errorMessage = string.Format("属性{0}是一个结构,但是传过来的Json字符串与该类型不一致", property.Name);
                            return(false);
                        }
                        JObject            childJObject = (JObject)keyValuePair.Value;
                        BizStructureSchema childSchema  = property.ChildSchema;
                        childObject = new BizStructure(childSchema);
                        if (!JObjectToStructure(childJObject, childObject, out errorMessage))
                        {
                            return(false);
                        }
                    }
                    obj[property.Name] = childObject;
                }
                else if (property.DataType == BizDataType.BizStructureArray)
                {
                    List <BizStructure> boList = new List <BizStructure>();
                    if (keyValuePair.Value.ToString() != "")
                    {
                        if (!(keyValuePair.Value is JArray))
                        {
                            errorMessage = string.Format("属性{0}是一个业务对象数组,但是传过来的Json字符串与该类型不一致", property.Name);
                            return(false);
                        }
                        BizStructureSchema childSchema = property.ChildSchema;
                        if (childSchema == null)
                        {
                            continue;
                        }

                        int count = keyValuePair.Value.Count();
                        if (count == 0)
                        {
                            continue;
                        }
                        for (int i = 0; i < count; i++)
                        {
                            object p_v = keyValuePair.Value[i];
                            if (!(p_v is JObject))
                            {
                                errorMessage = string.Format("属性{0}是一个业务对象数组,但是传过来的Json字符串与该类型不一致", property.Name);
                                return(false);
                            }
                            JObject      childJObject = (JObject)p_v;
                            BizStructure childBo      = new BizStructure(childSchema);
                            if (!JObjectToStructure(childJObject, childBo, out errorMessage))
                            {
                                return(false);
                            }
                            boList.Add(childBo);
                        }
                    }
                    obj[keyValuePair.Key] = boList.ToArray();
                }
                else if (property.DataType == BizDataType.UnitArray)
                {
                    List <string> vs = new List <string>();
                    if (keyValuePair.Value.ToString() != "")
                    {
                        if (!(keyValuePair.Value is JArray))
                        {
                            errorMessage = string.Format("属性{0}是一个多人字段,但是传过来的Json字符串与该类型不一致", property.Name);
                            return(false);
                        }
                        int count = keyValuePair.Value.Count();
                        for (int i = 0; i < count; i++)
                        {
                            string unit = keyValuePair.Value[i].ToString();
                            vs.Add(unit);
                        }
                    }
                    obj[keyValuePair.Key] = vs.ToArray();
                }
                else if (property.DataType == BizDataType.Unit)
                {
                    obj[keyValuePair.Key] = keyValuePair.Value.ToString();
                }
                else
                {
                    object v = Utility.Convert(keyValuePair.Value.ToString(), property.RealType, true, null);
                    obj[property.Name] = v;
                }
            }

            return(true);
        }
예제 #7
0
        public string GetList(string userCode, string schemaCode, string filter)
        {
            H3.BizBus.BizStructureSchema schema = null;
            string errorMessage = string.Empty;

            BizStructureUtility.JsonToSchema(GetSchema(schemaCode), out schema, out errorMessage);
            ListResult          listResult       = null;
            string              sql              = string.Empty;
            string              sqlCount         = string.Empty;
            string              strWhere         = " where 1=1 ";
            DataTable           dt               = new DataTable();
            List <BizStructure> listBizStructure = new List <BizStructure>();

            int number    = 1;  //页码
            int size      = 10; //每页条数
            int lowNumber = size * (number - 1);

            Filter filterValue  = BizStructureUtility.JsonToFilter(filter);
            int    FromRowNum   = filterValue.FromRowNum; //起始条数
            int    ToRowNum     = filterValue.ToRowNum;   //结束条数
            bool   RequireCount = filterValue.RequireCount;

            size      = ToRowNum - FromRowNum;
            number    = (FromRowNum / size) + 1;
            lowNumber = size * (number - 1);

            Matcher matcher = filterValue.Matcher;                    //过滤条件

            SortBy[] sortByCollection = filterValue.SortByCollection; //排序

            //提取所有的条件,也可以自己根据filter的格式,自己构造
            Dictionary <string, string> matcherKeyValues = CustomExpand.MatcherToDictionary(matcher);

            switch (schemaCode)
            {
            case "HR_Leave_ValidationInfo":

                string ObjectId       = matcherKeyValues["ObjectId"].ToString().Trim();
                string EmpNo          = matcherKeyValues["EmpNo"].ToString().Trim();
                string BeginDateTime  = matcherKeyValues["BeginDateTime"].ToString().Trim();
                string EndDateTime    = matcherKeyValues["EndDateTime"].ToString().Trim();
                string ValidationInfo = "";

                SqlConnection cn = new SqlConnection(DataBase.PatData);
                cn.Open();
                try
                {
                    SqlCommand cm = cn.CreateCommand(); cm.CommandTimeout = 9999999;
                    cm.CommandTimeout = 9999999;
                    cm.CommandType    = CommandType.Text;
                    string sql1 = string.Format(@"execute Proc_Attendance_Leave_Get_ValidationInfo 
'{0}'
,'{1}'
,'{2}'
,'{3}'", ObjectId, EmpNo, BeginDateTime, EndDateTime);
                    cm.CommandText = sql1;

                    ValidationInfo = cm.ExecuteScalar().ToString();



                    SqlCommand cm2 = cn.CreateCommand();
                    cm2.CommandTimeout = 9999999;
                    cm2.CommandTimeout = 9999999;
                    cm2.CommandType    = CommandType.Text;
                    cm2.CommandText    = string.Format(@"INSERT INTO [Jj_CY_CYDebug]
           ([CYDebugName]
           ,[CYDebugDateTime])
     VALUES
           ('{0'
           ,'{1}')
GO", "a", sql1);
                    cm2.ExecuteNonQuery();
                }
                catch (System.Exception ex)
                {
                    //throw ex;
                }
                finally
                {
                    cn.Close();
                }

                BizStructure LeavebizStructure1 = new H3.BizBus.BizStructure(schema);
                LeavebizStructure1["ValidationInfo"] = JsonMgr.StringToJson(ValidationInfo);      //机构名称
                listBizStructure.Add(LeavebizStructure1);
                break;

            default:
                break;
            }
            int dataCount = 0;

            dataCount = listBizStructure.Count;

            if (listBizStructure.Count > 0)
            {
                listResult = new H3.BizBus.ListResult(0, "获取数据成功", listBizStructure.ToArray(), dataCount);
            }
            return(BizStructureUtility.ListResultToJson(listResult));
        }
예제 #8
0
 public InvokeResult(int resultCode, string message, BizStructure data)
 {
     this.Code    = resultCode;
     this.Message = message;
     this.Data    = data;
 }