public static string GetUpLoadImagePath(string imagesPath, bool findSmallImg) { if (Wf_StringHelper.IsNullOrEmptyByTrim(imagesPath)) { return(Wf_StringHelper.NotImage); } //增加直接从images文件夹找图片 string rootpath = imagesPath.StartsWith("/") ? "/" : "/UploadFiles/main/Images/"; string sitePath = string.Format("{0}{1}", System.Web.HttpContext.Current.Server.MapPath(rootpath), imagesPath); if (findSmallImg) { string smallpath = sitePath + ".gif"; if (System.IO.File.Exists(smallpath)) { return(rootpath + (imagesPath.StartsWith("/") ? imagesPath.Remove(0, 1) : imagesPath) + ".gif"); } } if (System.IO.File.Exists(sitePath)) { return(rootpath + (imagesPath.StartsWith("/") ? imagesPath.Remove(0, 1) : imagesPath)); } else { return(Wf_StringHelper.NotImage); } }
/// <summary> /// 按照固定的某宽/某高等比例缩放图片 /// </summary> /// <param name="Path"></param> /// <param name="Limitwidth">最大宽度</param> /// <param name="Limitheight">最大高度</param> /// <param name="OutWidth">输出宽度</param> /// <param name="OutHeight">输出高度</param> public static void GetImageThumbnailSize(string Path, int Limitwidth, int Limitheight, out int OutWidth, out int OutHeight) { if (!Wf_StringHelper.IsNullOrEmptyByTrim(Path)) { //获取图片 string filepath = System.Web.HttpContext.Current.Server.MapPath("/") + (Path.IndexOf('/') == 0 ? Path.Remove(0, 1) : Path); Image image = Image.FromFile(filepath); if (image != null) { if (Limitwidth > 0 && image.Width >= Limitwidth) //指定高度进行缩放 { OutWidth = Limitwidth; OutHeight = Wf_ConvertHelper.ToInt32(Limitwidth * image.Height / image.Width); } else if (Limitheight > 0 && image.Height >= Limitheight) //指定宽度进行缩放 { OutHeight = Limitheight; OutWidth = Wf_ConvertHelper.ToInt32(Limitheight * image.Width / image.Height); } else { OutWidth = image.Width; OutHeight = image.Height; } return; } } OutWidth = 200; OutHeight = 200; }
public static string Replace(string input, string pattern, string replacement) { if (Wf_StringHelper.IsNullOrEmptyByTrim(input)) { return(""); } return(System.Text.RegularExpressions.Regex.Replace(input, pattern, replacement, System.Text.RegularExpressions.RegexOptions.Compiled | System.Text.RegularExpressions.RegexOptions.IgnoreCase | System.Text.RegularExpressions.RegexOptions.Singleline)); }
public static string CheckStr(object input, string format) { string result = Wf_RegexHelper.ParseHtmlBQ(input); if (!Wf_StringHelper.IsNullOrEmptyByTrim(result)) { return(string.Format(format, result)); } return(""); }
public static string ParesHtmlLineTab(string html) { try { if (Wf_StringHelper.IsNullOrEmptyByTrim(html)) { return(""); } return(System.Text.RegularExpressions.Regex.Replace(html, "\t|\r|\n|\r\n", "", System.Text.RegularExpressions.RegexOptions.Compiled)); } catch { return(""); } }
public static string RemoveHtmlViewState(string html) { try { if (Wf_StringHelper.IsNullOrEmptyByTrim(html)) { return(""); } return(System.Text.RegularExpressions.Regex.Replace(html, "<div><input type=\"hidden\" name=\"__VIEWSTATE\" id=\"__VIEWSTATE\" .*? /></div>", "", System.Text.RegularExpressions.RegexOptions.Compiled)); } catch { return(""); } }
public static string ToString(object input, string defaultValue, bool sqlSafeFilter) { if (input == null || Wf_StringHelper.IsNullOrEmptyByTrim(input.ToString())) { return(defaultValue); } if (sqlSafeFilter) { return(Wf_RegexHelper.SqlKeyWordsFilter(input.ToString())); } return(input.ToString()); }
public static int GetHtmlPageCount(string html) { if (Wf_StringHelper.IsNullOrEmptyByTrim(html)) { return(0); } try { Regex regex = new Regex("<span class=\"toprand-page-numpage\">.*?</span>"); MatchCollection matchs = regex.Matches(html); string count = new Regex(@"^\+?[1-9]\d*$").Match(matchs[matchs.Count - 1].Value).Value; return(Wf_ConvertHelper.ToInt32(count)); } catch { return(0); } }
public static DateTime ToDateTime(string input) { if (Wf_StringHelper.IsNullOrEmptyByTrim(input)) { return(DateTime.Parse("1900-01-01")); } try { return(System.Convert.ToDateTime(input)); } catch (Exception) { return(DateTime.MinValue); } }
public static bool ToBoolean(object input, bool defaultValue) { if (Wf_StringHelper.IsNullOrEmptyByTrim(input)) { return(defaultValue); } try { return(System.Convert.ToBoolean(input)); } catch (Exception) { 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 Guid ToGUID(object input, Guid defaultValue) { if (Wf_StringHelper.IsNullOrEmptyByTrim(input)) { return(defaultValue); } Guid g = Guid.Empty; if (Guid.TryParse(input.ToString(), out g)) { return(new Guid(input.ToString())); } 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(""); } }
public static string ReplaceHtmlStyle(string html) { if (Wf_StringHelper.IsNullOrEmptyByTrim(html)) { return(""); } try { Regex regex = new Regex("<link.*? />"); MatchCollection matchs = regex.Matches(html); foreach (Match match in matchs) { string link = new Regex("href=\"(.*?..css\")").Match(match.Value).Value.Replace("href=\"", "").Replace("\"", ""); Wf_FileReadOrWrite file = new Wf_FileReadOrWrite(); string css = file.FileRead(link.Remove(0, 1)); css = css.Replace("../images", "/skins/images"); html = html.Replace(match.Value, string.Format("<style type=\"text/css\">{0}</style>", css)); } return(html); } catch { return(""); } }
/// <summary> /// 去除Html标签 /// </summary> /// <param name="html"><p>abcdefg</p></param> /// <returns>abcdefg</returns> public static string ParseHtml(string input) { if (Wf_StringHelper.IsNullOrEmptyByTrim(input)) { return(""); } try { string html = Wf_RegexHelper.ParseToHtml(input); //替换换行 空格 html = System.Text.RegularExpressions.Regex.Replace(html, "<!--.*?-->", "", System.Text.RegularExpressions.RegexOptions.Compiled); html = System.Text.RegularExpressions.Regex.Replace(html, "<style.*?>.*?</style>", "", System.Text.RegularExpressions.RegexOptions.Compiled | System.Text.RegularExpressions.RegexOptions.IgnoreCase | System.Text.RegularExpressions.RegexOptions.Singleline); html = System.Text.RegularExpressions.Regex.Replace(html, "<script.*?>.*?</script>", "", System.Text.RegularExpressions.RegexOptions.Compiled | System.Text.RegularExpressions.RegexOptions.IgnoreCase | System.Text.RegularExpressions.RegexOptions.Singleline); html = System.Text.RegularExpressions.Regex.Replace(html, "<head>.*?</head>", "", System.Text.RegularExpressions.RegexOptions.Compiled | System.Text.RegularExpressions.RegexOptions.IgnoreCase | System.Text.RegularExpressions.RegexOptions.Singleline); html = System.Text.RegularExpressions.Regex.Replace(html, "<option.*?>.*?</option>", "", System.Text.RegularExpressions.RegexOptions.Compiled | System.Text.RegularExpressions.RegexOptions.IgnoreCase | System.Text.RegularExpressions.RegexOptions.Singleline); 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); return(html); } catch (Exception) { return(input); } }
public static object MappingControlObject(object obj, HtmlForm form, ContentPlaceHolder cph, bool SqlKeyWordsFilter) { try { if (obj == null) { return(obj); } 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; if (Wf_StringHelper.IsNullOrEmptyByTrim(txt.Text)) { continue; } pi.SetValue(obj, ChangeType(txt.Text, pi.PropertyType, SqlKeyWordsFilter), null); } else if (ctrl is Label) { Label lbl = ctrl as Label; if (Wf_StringHelper.IsNullOrEmptyByTrim(lbl.Text)) { continue; } pi.SetValue(obj, ChangeType(lbl.Text, pi.PropertyType, SqlKeyWordsFilter), null); } else if (ctrl is Literal) { Literal lit = ctrl as Literal; if (Wf_StringHelper.IsNullOrEmptyByTrim(lit.Text)) { continue; } pi.SetValue(obj, ChangeType(lit.Text, pi.PropertyType, SqlKeyWordsFilter), null); } else if (ctrl is HiddenField) { HiddenField hid = ctrl as HiddenField; if (Wf_StringHelper.IsNullOrEmptyByTrim(hid.Value)) { continue; } pi.SetValue(obj, ChangeType(hid.Value, pi.PropertyType, SqlKeyWordsFilter), null); } else if (ctrl is DropDownList) { DropDownList ddl = ctrl as DropDownList; if (Wf_StringHelper.IsNullOrEmptyByTrim(ddl.SelectedValue)) { continue; } pi.SetValue(obj, ChangeType(ddl.SelectedValue, pi.PropertyType, SqlKeyWordsFilter), null); } else if (ctrl is RadioButtonList) { RadioButtonList rdo = ctrl as RadioButtonList; string value = ""; foreach (ListItem item in rdo.Items) { if (item.Selected) { value += Wf_StringHelper.IsNullOrEmptyByTrim(value) ? item.Value : "," + item.Value; } } if (Wf_StringHelper.IsNullOrEmptyByTrim(value)) { continue; } pi.SetValue(obj, ChangeType(value, pi.PropertyType, SqlKeyWordsFilter), null); } else if (ctrl is CheckBoxList) { CheckBoxList chk = ctrl as CheckBoxList; string value = ""; foreach (ListItem item in chk.Items) { if (item.Selected) { value += Wf_StringHelper.IsNullOrEmptyByTrim(value) ? item.Value : "," + item.Value; } } if (Wf_StringHelper.IsNullOrEmptyByTrim(value)) { continue; } pi.SetValue(obj, ChangeType(value, pi.PropertyType, SqlKeyWordsFilter), null); } continue; } return(obj); } catch (Exception) { return(null); } }