private void DoGetAllCacheItemString() { lock (GetAllItemStringLock) { //检查Item大小是否发生变化 DataSet ds = sqlHelperDao.GetDatasetBySql("select COUNT(1) as c, SUM(Id) as s from Item where IsActive = 1", null); long count = long.Parse(ds.Tables[0].Rows[0][0].ToString()); long sumId = long.Parse(ds.Tables[0].Rows[0][1].ToString()); if (count != cachedAllItemCount || sumId != cachedAllItemId) { IList <Item> thisAllItem = GetAllItem(); StringBuilder data = new StringBuilder("["); for (int i = 0; i < thisAllItem.Count; i++) { Item item = thisAllItem[i]; string desc = item.Desc1; desc = desc.Replace("'", ""); data.Append(TextBoxHelper.GenSingleData(desc, item.Code) + (i < (thisAllItem.Count - 1) ? "," : string.Empty)); } data.Append("]"); cachedAllItemString = data.ToString(); cachedAllItemCount = count; cachedAllItemId = sumId; } } }
public string GetItemData(string serviceMgr, string serviceMethod, string serviceParameter, string valueField, string descField, string imageUrlField, string inputValue) { ISession session = GetService <ISession>(serviceMgr); object obj = null; if (serviceParameter != null && serviceParameter != string.Empty) { string[] paras = serviceParameter.Split(TextBoxHelper.ParameterSeperator); Type[] parasType = new Type[paras.Length]; object[] parasValue = new object[paras.Length]; for (int i = 0; i < paras.Length; i++) { string para = paras[i]; string type = para.Split(TextBoxHelper.TypeValueSeperator)[0]; string value = para.Split(TextBoxHelper.TypeValueSeperator)[1]; if (type == "bool") { parasType[i] = typeof(bool); try { parasValue[i] = bool.Parse(value); } catch (FormatException ex) { parasValue[i] = null; } } else if (type == "string") { parasType[i] = typeof(string); parasValue[i] = value; } else if (type == "int") { parasType[i] = typeof(int); try { parasValue[i] = int.Parse(value); } catch (FormatException ex) { parasValue[i] = null; } } else if (type == "long") { parasType[i] = typeof(long); try { parasValue[i] = long.Parse(value); } catch (FormatException ex) { parasValue[i] = null; } } else if (type == "decimal") { parasType[i] = typeof(decimal); try { parasValue[i] = decimal.Parse(value); } catch (FormatException ex) { parasValue[i] = null; } } else if (type == "DateTime") { parasType[i] = typeof(DateTime); try { parasValue[i] = DateTime.Parse(value); } catch (FormatException ex) { parasValue[i] = null; } } else if (type == "double") { parasType[i] = typeof(double); try { parasValue[i] = double.Parse(value); } catch (FormatException ex) { parasValue[i] = null; } } else if (type == "float") { parasType[i] = typeof(float); try { parasValue[i] = float.Parse(value); } catch (FormatException ex) { parasValue[i] = null; } } else { throw new TechnicalException("Unsupport parameter type:" + type); } } MethodInfo methodInfo = session.GetType().GetMethod(serviceMethod, parasType); obj = methodInfo.Invoke(session, parasValue); } else { MethodInfo methodInfo = session.GetType().GetMethod(serviceMethod, new Type[0]); obj = methodInfo.Invoke(session, null); } if (obj is IList) { IList list = obj as IList; string desc = string.Empty; string value = string.Empty; string imageUrl = string.Empty; string data = "["; for (int i = 0; i < list.Count; i++) { desc = GetFieldValue("DescField", descField, list, i); desc = desc.Replace("'", ""); value = GetFieldValue("ValueField", valueField, list, i); if (imageUrlField == null) { data += TextBoxHelper.GenSingleData(desc, value) + (i < (list.Count - 1) ? "," : string.Empty); } else { imageUrl = GetFieldValue("ImageUrlField", imageUrlField, list, i); data += TextBoxHelper.GenSingleData(desc, value, imageUrl) + (i < (list.Count - 1) ? "," : string.Empty); } } data += "]"; return(Server.HtmlEncode(data)); } else if (obj == null) { //do nothing return(string.Empty); } else { throw new TechnicalException("Unsupported return Type, only IList is accecpt"); } }