public static DateTime ToDateTime(object input) { try { return(ToDateTime(Wf_ConvertHelper.ToString(input))); } catch { return(DateTime.MinValue); } }
public static string ParseHtml(object obj) { try { return(ParseHtml(Wf_ConvertHelper.ToString(obj))); } catch { return(""); } }
public static int ToInt32(object input, int defaultValue) { string temp = Wf_ConvertHelper.ToString(input); if (string.IsNullOrEmpty(temp)) { return(defaultValue); } if (Wf_RegexHelper.IsInt(temp)) { return(System.Convert.ToInt32(input)); } else { return(defaultValue); } }
public static short ToInt16(object input, short defaultValue) { string temp = Wf_ConvertHelper.ToString(input); if (Wf_StringHelper.IsNullOrEmptyByTrim(temp)) { return(defaultValue); } if (Wf_RegexHelper.IsInt(temp)) { return(System.Convert.ToInt16(temp)); } else { return(defaultValue); } }
public static decimal ToDecimal(object input, decimal defaultValue) { string temp = Wf_ConvertHelper.ToString(input); if (Wf_StringHelper.IsNullOrEmptyByTrim(input)) { return(defaultValue); } if (Wf_RegexHelper.IsNumeric(temp)) { return(System.Convert.ToDecimal(input)); } else { return(defaultValue); } }
public static float ToFloat(object input, float defaultValue) { string temp = Wf_ConvertHelper.ToString(input); if (Wf_StringHelper.IsNullOrEmptyByTrim(input)) { return(defaultValue); } if (Wf_RegexHelper.IsNumeric(temp)) { return(System.Convert.ToSingle(input)); } else { return(defaultValue); } }
public static string ParseHtmlBQ(object temp) { string html = Wf_ConvertHelper.ToString(temp); if (Wf_StringHelper.IsNullOrEmptyByTrim(html)) { return(""); } try { html = Wf_RegexHelper.ParseToHtml(html); //替换换行 空格 html = System.Text.RegularExpressions.Regex.Replace(html, "<!--.*?-->", "", System.Text.RegularExpressions.RegexOptions.Compiled); html = System.Text.RegularExpressions.Regex.Replace(html, "((<[a-z!].*?>)|(</.+?>))", "", System.Text.RegularExpressions.RegexOptions.Compiled | System.Text.RegularExpressions.RegexOptions.IgnoreCase | System.Text.RegularExpressions.RegexOptions.Singleline); html = System.Text.RegularExpressions.Regex.Replace(html, @"\s+", " ", System.Text.RegularExpressions.RegexOptions.Compiled | System.Text.RegularExpressions.RegexOptions.IgnoreCase | System.Text.RegularExpressions.RegexOptions.Singleline); html = System.Text.RegularExpressions.Regex.Replace(html, @" ", " ", System.Text.RegularExpressions.RegexOptions.Compiled | System.Text.RegularExpressions.RegexOptions.IgnoreCase | System.Text.RegularExpressions.RegexOptions.Singleline); return(html); } catch { return(""); } }
/// <summary> /// 判断字符串是否为null或""(清楚首尾空格) /// </summary> /// <param name="input">object</param> /// <returns>为空或""返回true,否则flase</returns> public static bool IsNullOrEmptyByTrim(object input) { return(IsNullOrEmptyByTrim(Wf_ConvertHelper.ToString(input))); }
public static string GetUpLoadImagePath(object imagesPath, bool findSmallImg) { return(GetUpLoadImagePath(Wf_ConvertHelper.ToString(imagesPath), findSmallImg)); }
/// <summary> /// 判断字符是否为英文或数字 /// </summary> /// <param name="ch">字符</param> /// <returns>是英文或数组则返回true,否则返回false</returns> public static bool IsEnglishOrInteger(char ch) { return(System.Text.RegularExpressions.Regex.Match(Wf_ConvertHelper.ToString(ch), englishCharAndDigit, System.Text.RegularExpressions.RegexOptions.Compiled).Success); }
private static object ChangeType(object value, Type type, bool SqlKeyWordsFilter) { string tempValue = SqlKeyWordsFilter == true? Wf_RegexHelper.ParseHtmlBQ(Wf_RegexHelper.SqlKeyWordsFilter(Wf_ConvertHelper.ToString(value))) : Wf_ConvertHelper.ToString(value); if (type.IsGenericType && type.GetGenericTypeDefinition().Equals(typeof(Nullable <>))) { System.ComponentModel.NullableConverter nullableConverter = new System.ComponentModel.NullableConverter(type); return(Convert.ChangeType(tempValue, nullableConverter.UnderlyingType)); } else { return(Convert.ChangeType(tempValue, type)); } }
public static void MappingControlShow(object obj, HtmlForm form, ContentPlaceHolder cph) { try { if (obj == null) { return; } List <PropertyInfo> pilist = obj.GetType().GetProperties().ToList(); Control baseControl = cph == null ? (Control)form : (Control)cph; foreach (PropertyInfo pi in pilist) { Control ctrl = baseControl.FindControl("txt" + pi.Name); ctrl = ctrl == null?baseControl.FindControl("lbl" + pi.Name) : ctrl; ctrl = ctrl == null?baseControl.FindControl("lit" + pi.Name) : ctrl; ctrl = ctrl == null?baseControl.FindControl("hid" + pi.Name) : ctrl; ctrl = ctrl == null?baseControl.FindControl("ddl" + pi.Name) : ctrl; ctrl = ctrl == null?baseControl.FindControl("rdo" + pi.Name) : ctrl; ctrl = ctrl == null?baseControl.FindControl("chk" + pi.Name) : ctrl; if (ctrl == null) { continue; } else if (ctrl is TextBox) { TextBox txt = ctrl as TextBox; txt.Text = Wf_ConvertHelper.ToString(pi.GetValue(obj, null)); } else if (ctrl is Label) { Label lbl = ctrl as Label; lbl.Text = Wf_ConvertHelper.ToString(pi.GetValue(obj, null)); } else if (ctrl is Literal) { Literal lit = ctrl as Literal; lit.Text = Wf_ConvertHelper.ToString(pi.GetValue(obj, null)); } else if (ctrl is HiddenField) { HiddenField hid = ctrl as HiddenField; hid.Value = Wf_ConvertHelper.ToString(pi.GetValue(obj, null)); } else if (ctrl is DropDownList) { DropDownList ddl = ctrl as DropDownList; foreach (ListItem item in ddl.Items) { object value = pi.GetValue(obj, null); if (item.Value == Wf_ConvertHelper.ToString(value)) { ddl.SelectedValue = item.Value; } } } else if (ctrl is RadioButtonList) { RadioButtonList rdo = ctrl as RadioButtonList; object value = pi.GetValue(obj, null); string[] arr = Wf_ConvertHelper.ToString(value, "").Split(','); foreach (ListItem item in rdo.Items) { if (arr.Contains(item.Value)) { item.Selected = true; } } } else if (ctrl is CheckBoxList) { CheckBoxList chk = ctrl as CheckBoxList; object value = pi.GetValue(obj, null); string[] arr = Wf_ConvertHelper.ToString(value, "").Split(','); foreach (ListItem item in chk.Items) { if (arr.Contains(item.Value)) { item.Selected = true; } } } continue; } } catch { } }