using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Collections;
using System.Security.Cryptography;
using System.Text;
using System.IO;
using System.Collections.Generic;
using System.Text.RegularExpressions;
/// <summary>
///commTools 的摘要说明
/// </summary>
namespace Intelligent.Common
{
public class commTools
{
public commTools()
{ }
//提示信息
public static void alert(TemplateControl target, string msg)
{
string scriptString = "alert('" + msg + "')";
target.Page.ClientScript.RegisterClientScriptBlock(typeof(TemplateControl), DateTime.Now.ToString().Replace(":", " "), scriptString, true);
}
//错误页面
public static void toErrorPage(string msg)
{
HttpContext.Current.Server.Transfer("~/Error.aspx?msg="+msg);
}
//获取对应参数的值,如果参数不合法则跳转到错误页面
public static string getQueryString(string key)
{
if (HttpContext.Current.Request.QueryString[key] != null)
{
string value = HttpContext.Current.Request.QueryString[key].ToString();
//可以根据key的不同,对值的类型和范围再进行判断和处理
return value;
}
else
toErrorPage("参数无效");
return null;
}
//根据某个值让RadioButtonList某项被选中
public static void setRadioButtonListByValue(RadioButtonList list, string value)
{
for (int i = ; i < list.Items.Count; i++)
{
if (list.Items[i].Value == value)
list.Items[i].Selected = true;
else
list.Items[i].Selected = false;
}
}
//根据某个值让DropDownList某项被选中
public static void setDropDownListByValue(DropDownList list, string value)
{
for (int i = ; i < list.Items.Count; i++)
{
if (list.Items[i].Value == value)
list.Items[i].Selected = true;
else
list.Items[i].Selected = false;
}
}
//根据传的集合,让CheckBoxList多项被选中
public static void SetCheckBoxListByList(CheckBoxList list,List<string> value)
{
for (int i = ; i < list.Items.Count; i++)
{
bool tag = false;
for (int j = ; j < value.Count; j++)
{
if (list.Items[i].Value == value[j])
{
tag = true;
break;
}
}
list.Items[i].Selected = tag;
}
}
//把一个字符串转换成对应的MD5
public static string toMD5(string str)
{
return System.Web.Security.FormsAuthentication.HashPasswordForStoringInConfigFile(str, "md5");
} private static Random m_rnd = new Random();
private static char getRandomChar()
{
int ret = m_rnd.Next();
while (ret < || (ret > && ret < ) || (ret > && ret < ))
{
ret = m_rnd.Next();
}
return (char)ret;
}
public static string getRandomString(int length)
{
StringBuilder sb = new StringBuilder(length);
for (int i = ; i < length; i++)
{
sb.Append(getRandomChar());
}
return sb.ToString();
} public static bool SendMail(string StrTo, string StrBody, string strSubject)
{
return false;
}
/// <summary>
/// 根据传进来的分割符,以及字符串将字符串分割
/// </summary>
/// <param name="str">需要分割的字符串</param>
/// <param name="spiltChar">分隔符</param>
/// <returns>返回分割好的字符串数组</returns>
public static string[] StringSpilt(string str, string spiltChar)
{
Regex regex = new Regex(spiltChar);
string[] strArr = regex.Split(str);
return strArr;
} /// <summary>
/// 去除字符串的末尾标志符
/// </summary>
/// <param name="str">字符串</param>
/// <param name="splitFlag">末尾标识符</param>
/// <returns>返回结果字符串</returns>
public static string RemoveLastSplitFlag(string str, string splitFlag)
{
int i = str.LastIndexOf(splitFlag);
if (i == -) //不存在末尾标志位
{
return str;
}
else
{
return str.Remove(i, splitFlag.Length);
} }

ASP.NET一些公共方法commTools的更多相关文章

  1. J2EE项目开发中常用到的公共方法

    在项目IDCM中涉及到多种工单,包括有:服务器|网络设备上下架工单.服务器|网络设备重启工单.服务器光纤网线更换工单.网络设备撤线布线工单.服务器|网络设备替换工单.服务器|网络设备RMA工单.通用原 ...

  2. php 图片上传的公共方法(按图片宽高缩放或原图)

    写的用于图片上传的公共方法类调用方法: $upload_name='pic';$type = 'logo_val';$file_name = 'logo_' . $user_id .create_st ...

  3. web开发过程中经常用到的一些公共方法及操作

    进化成为程序猿也有段岁月了,所谓的经验,广度还是依旧,只不过是对于某种功能有了多种实现方式的想法.每天依旧不厌其烦的敲打着代码,每一行代码的回车似乎都有一种似曾相识的感觉.于是乎:粘贴复制,再粘贴再复 ...

  4. iOS常用公共方法

      iOS常用公共方法 字数2917 阅读3070 评论45 喜欢236 1. 获取磁盘总空间大小 //磁盘总空间 + (CGFloat)diskOfAllSizeMBytes{ CGFloat si ...

  5. Angularjs调用公共方法与共享数据

    这个问题场景是在使用ionic开发页面的过程中发现,多个页面对应的多个controller如何去调用公共方法,比如给ionic引入了toast插件,如何将这个插件的调用变成公共方法或者设置成工具类,因 ...

  6. 64位Win7下运行ASP+Access网站的方法

    64位Win7下运行ASP+Access网站的方法 近日系统升级为WIN7 64位之后,突然发现原本运行正常的ASP+ACCESS网站无法正常连接数据库. 网上搜索多次,终于解决了问题,总结了几条经验 ...

  7. JQuery直接调用asp.net后台WebMethod方法

    利用JQuery的$.ajax()可以很方便的调用asp.net的后台方法.[WebMethod]   命名空间 1.无参数的方法调用, 注意:1.方法一定要静态方法,而且要有[WebMethod]的 ...

  8. ASP.NET MVC3升级到ASP.NET MVC4 的方法

    ASP.NET MVC3升级 ASP.NET MVC4 的方法: 1.先去掉引用的System.Web.Mvc.dll(MVC3版本),重新引入System.Web.Mvc.dll(MVC4版本) 2 ...

  9. 利用JQuery的$.ajax()可以很方便的调用asp.net的后台方法

    利用JQuery的$.ajax()可以很方便的调用asp.net的后台方法. 先来个简单的实例热热身吧. 1.无参数的方法调用 asp.net code: view plaincopy to clip ...

随机推荐

  1. P,V操作实例分析

    刚开始学习操作系统的时候,就听说PV操作,简单说说PV操作. ●  P(S): S=S-1 如果S≥0,则该进程继续执行:               S<0,进程暂停执行,放入信号量的等待队列 ...

  2. SQL SERVER 与ACCESS、EXCEL的数据转换

    --Excel导入到SQL的一个新思路: /*比如Excel有两列,A列和B列需要导入到SQL表中,反正我已经有几年不用DTS之类的工具了. 在Excel中的新的一列中,直接写公式 =CONCATEN ...

  3. logback 配置详解【讲解较全的博客网站】

    http://blog.csdn.net/haidage/article/category/812478 详解(一)http://blog.csdn.net/haidage/article/detai ...

  4. unity 播放过场动画

    public var url="file:///c:/sample.ogg"; //文件路径 function Start () { //拼凑一个url url="fil ...

  5. BZOJ4158 : [POI2007]Railway

    论文题. 随便取个关键点,求出最短路树. 求出所有关键点组成的虚树,将两端都在虚树上的边保留. 对剩下的边求出最小生成树即可得到一组可行解. #include<cstdio> #inclu ...

  6. MongoDB的安装与CRUD(JAVA)

    http://blogread.cn/it/article/4348?f=wb (MongoDB) 安装: 1)下载MongoDB数据库(这里使用Windows 32 bit版) http://dow ...

  7. eWebeditor编辑器上传图片路径错误解决方法[疑难杂症]【转,作者:unvs】

    做了一个多版本的网站,后台用的编辑器是eWebeditor,NET版,后面发现上传图片或者文件之后,路径错误无法显示,必须手工修改才行.. 为了更清楚的说明问题,我下面会说的比较详细,首先是网站文件框 ...

  8. 新机上岗 Core i7-4790 @ 3.60GHz 四核 / 16 GB ( 金士顿 DDR3 1866MHz ) / GeForce GTX 970 ( 4 GB / 七彩虹 )

    新机上岗 ==============================电脑型号 华硕 All Series 台式电脑操作系统 Windows 7 旗舰版 64位 SP1 ( DirectX 11 )  ...

  9. ajax无刷新获取php后台数据

    $.ajax({ url:"result.php", //data:{"page":i}, dataType:"json", beforeS ...

  10. Silic PHP大马Cookie欺骗漏洞

    $password="ebd9a3c106064a255aaee28b6eb4f21c"; if($_COOKIE['admin_silicpass'] != md5($passw ...