/// <summary> /// 替换字符串里的$函数$和%%变量,结果不带"" /// 表达式结果如果为null,则用string.Empty代替 /// </summary> /// <param name="expression"></param> /// <param name="entity"></param> /// <returns></returns> public static string ReplaceExpression(string expression, object entity) { try { Match m = s_regexExpression.Match(expression); while (m.Success) { string ownExpression = m.Groups[1].Value; object result = EntityScript.CalculateExpression(ownExpression, entity); string replaceString = string.Empty; if (result != null) { replaceString = result.ToString(); } expression = expression.Replace(m.Groups[0].Value, replaceString); m = s_regexExpression.Match(expression); } } catch (Exception ex) { throw new ArgumentException("expression of " + expression + " format is invalid!", ex); } return(expression); }
///// <summary> ///// 在显示当前位置数据前发生 ///// </summary> //public event EventHandler CurrentDisplaying; /// <summary> /// 显示当前位置实体类数据 /// </summary> public virtual void DisplayCurrent() { foreach (IDataControl dc in this.DataControls) { // if in tab control, the data control may be invisible //if (!dc.Visible) // continue; switch (dc.ControlType) { case DataControlType.Unbound: break; case DataControlType.Normal: { if (string.IsNullOrEmpty(dc.PropertyName)) { continue; } if (this.CurrentItem == null) { dc.SelectedDataValue = null; } else { try { dc.SelectedDataValue = EntityScript.GetPropertyValue(this.CurrentItem, dc.Navigator, dc.PropertyName); } catch (Exception ex) { throw new ArgumentException(string.Format("DataControl of {0} is Invalid!", dc.Name), ex); } } } break; case DataControlType.Expression: if (string.IsNullOrEmpty(dc.PropertyName)) { continue; } if (dc.PropertyName.Contains("%")) { dc.SelectedDataValue = EntityScript.CalculateExpression(dc.PropertyName, this.CurrentItem); } else { } break; default: throw new ArgumentException(string.Format("DataControl of {0} is Invalid!", dc.Name)); } } }