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. PHP 5.4 中经 htmlspecialchars 转义后的中文字符串为空,DeDeCMS在PHP5.4下编辑器中文不显示问题

    在加入 发布招聘功能的时候,出现问题了,就是修改招聘信息的时候.编辑器内容不显示,只显示英文,中文不显示,以前记得开发此功能没这问题啊!然后各种原因找不出,没办法,从编辑器函数入手,一步一步查,查到 ...

  2. spark streaming中使用flume数据源

    有两种方式,一种是sparkstreaming中的driver起监听,flume来推数据:另一种是sparkstreaming按照时间策略轮训的向flume拉数据. 最开始我以为只有第一种方法,但是尼 ...

  3. 字符串截取函数substr和substring的不同及其相关说明

    1.substr 方法 功能:用于返回一个从指定位置开始的指定长度的子字符串,从“母字符串”的“指定位置”开始提取“指定长度”的“子字符串”. 语法:stringObject.substr(start ...

  4. Redis作为多个Windows服务运行配置方法

    1.首先下载微软官方推荐的版本redis-2.8.12 2.开始配置,首先复制两份redis.conf并且重命名为redis6379.conf  redis6380.conf 里面的配置节点相应的更改 ...

  5. 20145315 《Java程序设计》实验五实验报告

    20145315 <Java程序设计>实验五实验报告 实验五 Java网络编程 我负责服务器部分,王嘉澜负责客户端部分:http://www.cnblogs.com/SJZGM10/p/5 ...

  6. 从一个action地址获取信息

    get方法 String url_str ="http://127.0.0.1:8400/lxyyProduct/getProductUserNeedUpdate.action?ts=&qu ...

  7. POJ 2342 Label:树形dp

    Anniversary party Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 6955   Accepted: 4003 ...

  8. HDU 4604 Deque(最长上升子序)

    题目链接 本来就对N*log(N)算法不大会....然后各种跪了,求出最长不下降+最长不上升-最少相同元素.求相同元素,用二分求上界搞的.代码里4个二分.... #include <cstdio ...

  9. COJ574 数字序列

    试题描述   霸中智力测试机构的一项工作就是按照一定的规则删除一个序列的数字,得到一个确定的数列.陈思同学很渴望成为霸中智力测试机构的主管,但是他在这个工作上做的并不好,俗话说熟能生巧,他打算做很多练 ...

  10. 一个简单的SqlServer游标使用

    declare @id int ) declare c_department cursor for select id,name from department open c_department f ...