Exemplo n.º 1
0
 /// <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;
 }
Exemplo n.º 2
0
 public static string ParseHtml(object obj)
 {
     try
     {
         return(ParseHtml(Wf_ConvertHelper.ToString(obj)));
     }
     catch { return(""); }
 }
Exemplo n.º 3
0
 public static DateTime ToDateTime(object input)
 {
     try
     {
         return(ToDateTime(Wf_ConvertHelper.ToString(input)));
     }
     catch { return(DateTime.MinValue); }
 }
Exemplo n.º 4
0
 /// <summary>
 /// 将字符串分割,返回int[]数组
 /// </summary>
 /// <param name="input">字符串</param>
 /// <returns>int[]</returns>
 public static int[] SplitRetInt(string input)
 {
     string[] strs = Split(input);
     int[]    ids  = new int[strs.Length];
     for (int i = 0; i < ids.Length; i++)
     {
         ids[i] = Wf_ConvertHelper.ToInt32(strs[i]);
     }
     return(ids);
 }
Exemplo n.º 5
0
 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); }
 }
Exemplo n.º 6
0
        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);
            }
        }
Exemplo n.º 7
0
        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);
            }
        }
Exemplo n.º 8
0
        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);
            }
        }
Exemplo n.º 9
0
        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);
            }
        }
Exemplo n.º 10
0
        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, @"&nbsp;", " ", System.Text.RegularExpressions.RegexOptions.Compiled | System.Text.RegularExpressions.RegexOptions.IgnoreCase | System.Text.RegularExpressions.RegexOptions.Singleline);
                return(html);
            }
            catch { return(""); }
        }
Exemplo n.º 11
0
 /// <summary>
 /// 判断字符串是否为null或""(清楚首尾空格)
 /// </summary>
 /// <param name="input">object</param>
 /// <returns>为空或""返回true,否则flase</returns>
 public static bool IsNullOrEmptyByTrim(object input)
 {
     return(IsNullOrEmptyByTrim(Wf_ConvertHelper.ToString(input)));
 }
Exemplo n.º 12
0
 public static string GetUpLoadImagePath(object imagesPath, bool findSmallImg)
 {
     return(GetUpLoadImagePath(Wf_ConvertHelper.ToString(imagesPath), findSmallImg));
 }
Exemplo n.º 13
0
 /// <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);
 }
Exemplo n.º 14
0
        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));
            }
        }
Exemplo n.º 15
0
        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 { }
        }