Exemplo n.º 1
0
 /// <summary>
 /// 将变量绑定值
 /// </summary>
 /// <param name="values">将变量绑定值</param>
 public virtual void BindValue(IDictionary <string, Object> values)
 {
     if (null != values && values.Count > 0 && !string.IsNullOrEmpty(Var))
     {
         RealText = string.Format("[%{0}%]", Var);
         string          str   = @"\[#?%?(p{0,}/?\w){1,}%?#?\]";//@"\[#?%?(([\u4E00-\u9FFF]){0,}/?\w){1,}%?#?\]";
         Regex           regex = new Regex(str);
         MatchCollection mc    = regex.Matches(RealText);
         if (null != mc && mc.Count > 0)
         {
             foreach (Match m in mc)
             {
                 string key = m.Value.Remove(0, 1);
                 key = key.Remove(key.Length - 1, 1);
                 if (values.ContainsKey(key))
                 {
                     string newStr = values[key] as string;
                     if (string.IsNullOrEmpty(newStr))
                     {
                         newStr = " ";
                     }
                     RealText = RealText.Replace(m.Value, newStr);
                 }
             }
         }
     }
 }
Exemplo n.º 2
0
 public void BindValue(IDictionary <string, Object> values)
 {
     if (null != values && values.Count > 0)
     {
         RealText = Text;
         string          str   = @"\[#?%?(p{0,}/?\w){1,}%?#?\]";//@"\[#?%?(([\u4E00-\u9FFF]){0,}/?\w){1,}%?#?\]";
         Regex           regex = new Regex(str);
         MatchCollection mc    = regex.Matches(RealText);
         if (null != mc && mc.Count > 0)
         {
             foreach (Match m in mc)
             {
                 string key = m.Value.Remove(0, 1);
                 key = key.Remove(key.Length - 1, 1);
                 if (values.ContainsKey(key))
                 {
                     object value  = values[key];
                     string newStr = " ";
                     if (null != value)
                     {
                         newStr = value.ToString();
                     }
                     RealText = RealText.Replace(m.Value, newStr);
                 }
             }
         }
     }
 }
Exemplo n.º 3
0
 /// <summary>
 /// 字段绑定值
 /// </summary>
 /// <param name="values"></param>
 public override void BindValue(IDictionary <string, object> values)
 {
     if (null != values && values.Count > 0)
     {
         RealText = Text;
         string          str   = @"\[#?%?(p{0,}/?\w){1,}%?#?\]";
         Regex           regex = new Regex(str);
         MatchCollection mc    = regex.Matches(RealText);
         if (null != mc && mc.Count > 0)
         {
             foreach (Match m in mc)
             {
                 string key = m.Value.Remove(0, 1);
                 key = key.Remove(key.Length - 1, 1);
                 if (values.ContainsKey(key))
                 {
                     string newStr = string.Empty;
                     object o      = values[key];
                     if (null != o)
                     {
                         if (string.IsNullOrEmpty(StrFormate))
                         {
                             newStr = o.ToString();
                         }
                         else
                         {
                             newStr = FormateToString(o);
                         }
                     }
                     if (newStr == string.Empty)
                     {
                         newStr = " ";
                     }
                     RealText = RealText.Replace(m.Value, newStr);
                 }
             }
         }
     }
 }