ASP.NET一些公共方法commTools
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的更多相关文章
- J2EE项目开发中常用到的公共方法
在项目IDCM中涉及到多种工单,包括有:服务器|网络设备上下架工单.服务器|网络设备重启工单.服务器光纤网线更换工单.网络设备撤线布线工单.服务器|网络设备替换工单.服务器|网络设备RMA工单.通用原 ...
- php 图片上传的公共方法(按图片宽高缩放或原图)
写的用于图片上传的公共方法类调用方法: $upload_name='pic';$type = 'logo_val';$file_name = 'logo_' . $user_id .create_st ...
- web开发过程中经常用到的一些公共方法及操作
进化成为程序猿也有段岁月了,所谓的经验,广度还是依旧,只不过是对于某种功能有了多种实现方式的想法.每天依旧不厌其烦的敲打着代码,每一行代码的回车似乎都有一种似曾相识的感觉.于是乎:粘贴复制,再粘贴再复 ...
- iOS常用公共方法
iOS常用公共方法 字数2917 阅读3070 评论45 喜欢236 1. 获取磁盘总空间大小 //磁盘总空间 + (CGFloat)diskOfAllSizeMBytes{ CGFloat si ...
- Angularjs调用公共方法与共享数据
这个问题场景是在使用ionic开发页面的过程中发现,多个页面对应的多个controller如何去调用公共方法,比如给ionic引入了toast插件,如何将这个插件的调用变成公共方法或者设置成工具类,因 ...
- 64位Win7下运行ASP+Access网站的方法
64位Win7下运行ASP+Access网站的方法 近日系统升级为WIN7 64位之后,突然发现原本运行正常的ASP+ACCESS网站无法正常连接数据库. 网上搜索多次,终于解决了问题,总结了几条经验 ...
- JQuery直接调用asp.net后台WebMethod方法
利用JQuery的$.ajax()可以很方便的调用asp.net的后台方法.[WebMethod] 命名空间 1.无参数的方法调用, 注意:1.方法一定要静态方法,而且要有[WebMethod]的 ...
- ASP.NET MVC3升级到ASP.NET MVC4 的方法
ASP.NET MVC3升级 ASP.NET MVC4 的方法: 1.先去掉引用的System.Web.Mvc.dll(MVC3版本),重新引入System.Web.Mvc.dll(MVC4版本) 2 ...
- 利用JQuery的$.ajax()可以很方便的调用asp.net的后台方法
利用JQuery的$.ajax()可以很方便的调用asp.net的后台方法. 先来个简单的实例热热身吧. 1.无参数的方法调用 asp.net code: view plaincopy to clip ...
随机推荐
- python reduce()函数
reduce()函数 reduce()函数也是Python内置的一个高阶函数.reduce()函数接收的参数和 map()类似,一个函数 f,一个list,但行为和 map()不同,reduce()传 ...
- jquery概要--基础01
jquery对象,DOM对象 var $cr = $('#cr'); var cr = $cr[0]; /var cr = $cr.get(0); var cr = document ...
- 阿里云ECS(云服务器)之产品简介
参考阿里产品文档:https://docs.aliyun.com/?spm=5176.100054.3.1.ywnrMX#/pub/ecs/product-introduction/concept
- POJ2778 DNA Sequence(AC自动机+矩阵快速幂)
题目给m个病毒串,问不包含病毒串的长度n的DNA片段有几个. 感觉这题好神,看了好久的题解. 所有病毒串构造一个AC自动机,这个AC自动机可以看作一张有向图,图上的每个顶点就是Trie树上的结点,每个 ...
- 【转载】Linux下makefile详解--跟我一起写 Makefile
概述 —— 什么是makefile?或许很多Winodws的程序员都不知道这个东西,因为那些Windows的IDE都为你做了这个工作,但我觉得要作一个好的和professional的程序员,makef ...
- CC150 - 11.3
Question: Given a sorted array of n integers that has been rotated an unknown number of times, write ...
- Qt resizeEvent 控件居中设置
在Qt中我们有时需要让一个控件在窗口居中或是在父控件中居中,而且在窗口拉伸时仍然保持正中央的位置.这里介绍一种方法,用到了主窗口的响应函数resizeEvent(QResizeEvent* event ...
- zabbix配置文件详解
Zabbix之配置文件详解 zabbix配置文件种类: zabbix_server配置文件zabbix_server.conf zabbix_proxy配置文件zabbix_proxy.conf ...
- c#委托事件及其讲解
一定要标明出处,波哥的文章.所有文章都值得一看.这篇是摘抄的大白话之C#事件讲解.委托 http://www.cnblogs.com/wudiwushen/archive/2010/04/20/170 ...
- [转]通过继承ConfigurationSection,在web.config中增加自定义配置
本文转自:http://www.blue1000.com/bkhtml/2008-02/55810.htm 前几天写了一篇使用IConfigurationSectionHandler在web.conf ...