1、总结12C#常用的类C#常用的类/* * Title: 系统函数 * Description: 系统函数 * Copyright: Copyright (c) 2009* Version 1.0 */using System;using System.Data;using System.Configuration;using System.Web;using System.Web.Security;using System.Web.UI;using System.Web.UI.WebControls;using System.Web.UI.WebControls.WebParts;using
2、System.Web.UI.HtmlControls;using System.Text;using System.Text.RegularExpressions;using WBIS.Base.Fun;using System.IO;namespace WBIS.Base.Fun / / funSystem 系统处理类 / public class funSystem / / 取得大写中文字 / / 数字如1、2、3 / / public static string GetBigTWNum(string strCode) string strReData; switch (strCode)
3、case 1: strReData = 壹; break; case 2: strReData = 贰; break; case 3: strReData = 参; break; case 4: strReData = 肆; break; case 5: strReData = 伍; break; case 6: strReData = 陆; break; case 7: strReData = 柒; break; case 8: strReData = 捌; break; case 9: strReData = 玖; break; case 0: strReData = 零; break;
4、default: strReData = ; break; return strReData; / / 将阿拉伯数字转为国文数字 / / 阿拉伯数字(例:15) / 转换后的中文数字(例:十五) / Author:Peter 2006/8/17 public static string NumToChn(string strCode) if (strCode = null | strCode = ) return ; string strReData; if (strCode.Length = 1) switch (strCode) case 1: strReData = 一; break;
5、case 2: strReData = 二; break; case 3: strReData = 三; break; case 4: strReData = 四; break; case 5: strReData = 五; break; case 6: strReData = 六; break; case 7: strReData = 七; break; case 8: strReData = 八; break; case 9: strReData = 九; break; case 0: strReData = 零; break; default: strReData = ; break;
6、else if (strCode.Length = 2) if (strCode = 10) strReData = 十; else if (strCode = 20 | strCode = 30 | strCode = 40 | strCode = 50 | strCode = 60 | strCode = 90 | strCode = 70 | strCode = 80) strReData = NumToChn(strCode.Substring(0, 1) + 十; else if (Convert.ToInt16(strCode) 10) strReData = 十 + NumToC
7、hn(strCode.Substring(1, 1); else if (Convert.ToInt16(strCode) 20) strReData = NumToChn(strCode.Substring(0, 1) + 十 + NumToChn(strCode.Substring(1, 1); else strReData = ; else if (strCode.Length = 3) if (strCode = 100) strReData = 一百; else if (Convert.ToInt16(strCode) 100 & Convert.ToInt16(strCode) 2
8、00 & Convert.ToInt16(strCode) 300 & Convert.ToInt16(strCode) 400 & Convert.ToInt16(strCode) 500 & Convert.ToInt16(strCode) 600 & Convert.ToInt16(strCode) 700 & Convert.ToInt16(strCode) 800 & Convert.ToInt16(strCode) 900 & Convert.ToInt16(strCode) 110 & Convert.ToInt16(strCode) 110 & Convert.ToInt16(
9、strCode) 1000) strReData = NumToChn(strCode.Substring(0, 1) + 百 + NumToChn(strCode.Substring(1, 2); else strReData = ; else strReData = ; return strReData; / / 前缀补0 / / 要补零的字符串 / 设置补零后的字长 / 补零后的字符串 public static string AddPrefixZero(string strValue, int iLen) int i; i = strValue.Length; while (i iLe
10、n) strValue = 0 + strValue; i = strValue.Length; return strValue; / / 后缀补0 / / 要补零的字符串 / 设置补零后的字长 / 补零后的字符串 public static string AddSuffixZero(string strValue, int iLen) int i; i = strValue.Length; while (i iLen) strValue = strValue + 0; i = strValue.Length; return strValue; / / 前缀去0 / / 要去零的字符串 / 去
11、零后的字符串 / public static string RemovePrefixZero(string strValue) string outValue; for (int i = 0; i strValue.Length; i+) if (strValue.Substring(i, 1) != 0) outValue = strValue.Substring(i, (strValue.Length - i); return outValue; return ; / / 判断strNumber是否为数字,是数字返回True,不是数字返回False / / 要判断是否数字的字符串 / 数字
12、返回True,不是数字返回False public static bool IsNumeric(String strNumber) Regex NumberPattern = new Regex(0-9.-); return !NumberPattern.IsMatch(strNumber); / / 连接功能处理 / / 功能名称 / 功能编号 / Response对象 public static void linkFun(string funName, string funNo, ClientScriptManager clientScriptTmp) /判断是否有传入Http画面资料 i
13、f (clientScriptTmp = null) return; if (funNo.Length 3) return; /组成更改提示之javascript的语句 string alertMeg; alertMeg = parent.statusbar.openFun(; alertMeg += funName; alertMeg += , + funNo; alertMeg += ); /画面上显示提示 clientScriptTmp.RegisterStartupScript(clientScriptTmp.GetType(), alertMeg, alertMeg); / / 过滤
14、和其它非法输入 / / 需判断之参数 / clientScript对象 / / Ki 添加 2009/4/1 public static Boolean checkRule(string press, ClientScriptManager clientScriptTmp) string c; int j = 0; for (int i = 0; i press.Length; i+) c = press.Substring(i, 1).ToString(); if (c = ) | (c = ) | (c = ) | (c = -) | (c = .) | (c = /) funMessag
15、e.messageBox(您输入的有非法字符!, clientScriptTmp); j = 1; break; if (j = 1) return false; else return true; / / 转化为小数 / / / public static double strToDouble(string strNum) try return double.Parse(strNum.Trim().ToString(); catch (System.Exception ex) return 0; return 0; / / 格式化数字成三字一撇的形式 / / 传入的数值 / 保留的小数点 p
16、ublic static string FormatNum(string strValue, int iValue) string strRight, strLeft; string iLenDecimal; string a; a = strValue.ToString().Substring(0, 1); iLenDecimal = strValue; if (iLenDecimal.ToString().IndexOf(., 0) 0) strRight = iLenDecimal.ToString().Substring(iLenDecimal.ToString().IndexOf(.
17、, 0), iLenDecimal.ToString().Length - iLenDecimal.ToString().IndexOf(., 0); if (a = -) strLeft = iLenDecimal.ToString().Substring(1, iLenDecimal.ToString().IndexOf(., 0); else strLeft = iLenDecimal.ToString().Substring(0, iLenDecimal.ToString().IndexOf(., 0); else strRight = ; strLeft = iLenDecimal.
18、ToString(); int j = 1; int i = strLeft.ToString().Length; while (i 3) int iDecimal = funSystem.ToInt(iLenDecimal); iLenDecimal = Convert.ToString(Convert.ToInt32(iDecimal / 1000); /string striLenDecimal = Convert.ToString(iLenDecimal); i = Convert.ToString(iLenDecimal).Length; if (j = 1) strLeft = s
19、trLeft.ToString().Insert(strLeft.Length - (3 * j), ,); else strLeft = strLeft.ToString().Insert(strLeft.Length - 3 * j - (j - 1), ,); j+; if (strRight.Length = 0) for (int d = iValue; d 0; d-) strRight += 0; if (iValue != 0) return strLeft.ToString() + . + strRight.ToString(); else return strLeft.To
20、String(); if (iValue != 0) return strLeft.ToString() + . + funSystem.AddSuffixZero(strRight.Substring(1), iValue); else return strLeft.ToString(); / / 格式化数字成三字一撇的形式 / / / /public static string FormatNum(string str) / / string strA = new string2; / strA = str.Split(.); / string strB = new string2; /
21、strB = str.Split(-); / if (strA.Length = 2) / / str = strA0; / / else if (strB.Length = 2) / / str = strB1; / / Regex rg = new Regex(d3, RegexOptions.RightToLeft); / MatchCollection mc = rg.Matches(str); / if (str.Trim().Length % 3 = 0) / / for (int i = 0; i mc.Count - 1; i+) / / str = str.Insert(mci.Index, ,); / / / else / / for (int i = 0; i = 2) / / str = str + . + strA1; / / else if (strB.Length = 2) / / str = - + str; / / return str; / / / 格式化数字成三字一撇的形式 / / 传入数字(如:1000或是1000.12)
copyright@ 2008-2022 冰豆网网站版权所有
经营许可证编号:鄂ICP备2022015515号-1