public static string ListResultToJson(ListResult result) { if (result == null) { return(null); } StringBuilder builder = new StringBuilder(); if (result.Data != null && result.Data.Length != 0) { foreach (BizStructure s in result.Data) { builder.Append(StructureToJson(s) + ", "); } } if (builder.Length > 0) { builder.Remove(builder.Length - 2, 2); } return("{\"Code\":\"" + result.Code + "\", \"Message\":\"" + result.Message + "\", \"Schema\":" + SchemaToJson(result.Schema) + ", \"Count\":" + result.Count + ", \"Data\":[" + builder.ToString() + "]}"); }
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); } }
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)); }