Utility常用功能类 MD5 ClientIP JS弹窗消息

UTILITY
Utility

  1 None.gif using  System;
  2 None.gif using  System.Collections.Generic;
  3 None.gif using  System.Text;
  4 None.gif using  Microsoft.Practices.EnterpriseLibrary.Logging;
  5 None.gif using  System.Security.Cryptography;
  6 None.gif using  System.Web;
  7 None.gif using  System.Collections;
  8 None.gif using  System.Text.RegularExpressions;
  9 None.gif using  Dart.PowerTCP.SecureMail;
 10 None.gif using  System.Net.Sockets;
 11 None.gif using  System.IO;
 12 None.gif using  System.Data.SqlClient;
 13 None.gif using  System.Data;
 14 None.gif using  System.Collections.Specialized;
 15 None.gif
 16 None.gif namespace  ChinaValue.CommonV2008
 17 ExpandedBlockStart.gifContractedBlock.gif dot.gif {
 18ExpandedSubBlockStart.gifContractedSubBlock.gif    /**//// <summary>
 19InBlock.gif    /// 常用功能类
 20ExpandedSubBlockEnd.gif    /// </summary>

 21InBlock.gif    public class Utility
 22ExpandedSubBlockStart.gifContractedSubBlock.gif    dot.gif{
 23ExpandedSubBlockStart.gifContractedSubBlock.gif        /**//// <summary>
 24InBlock.gif        /// 检测非法Post字符
 25InBlock.gif        /// </summary>
 26InBlock.gif        /// <param name="content"></param>
 27ExpandedSubBlockEnd.gif        /// <returns></returns>

 28InBlock.gif        public static Boolean ValidatePostContent(String content)
 29ExpandedSubBlockStart.gifContractedSubBlock.gif        dot.gif{
 30InBlock.gif            Regex regexBadString = new Regex(@"<\s*?(/form)|(form)|(iframe)|(frame)|(meta)|(script).+?>", RegexOptions.Compiled | RegexOptions.IgnoreCase | RegexOptions.Singleline);
 31InBlock.gif            return !regexBadString.Match(content).Success;
 32ExpandedSubBlockEnd.gif        }

 33InBlock.gif
 34ExpandedSubBlockStart.gifContractedSubBlock.gif        /**//// <summary>
 35InBlock.gif        /// 写错误日志
 36InBlock.gif        /// </summary>
 37InBlock.gif        /// <param name="strInformation"></param>
 38ExpandedSubBlockEnd.gif        /// <param name="strTitle"></param>

 39InBlock.gif        public static void LogInfo(String strTitle, String strInformation)
 40ExpandedSubBlockStart.gifContractedSubBlock.gif        dot.gif{
 41InBlock.gif            LogEntry logEntry = new LogEntry();
 42InBlock.gif            logEntry.Title = strTitle;
 43InBlock.gif            logEntry.Message = strInformation;
 44InBlock.gif            logEntry.Categories.Add("General");
 45InBlock.gif            logEntry.TimeStamp = DateTime.Now;
 46InBlock.gif            Logger.Write(logEntry);
 47ExpandedSubBlockEnd.gif        }

 48InBlock.gif
 49ExpandedSubBlockStart.gifContractedSubBlock.gif        /**//// <summary>
 50InBlock.gif        /// 写指定路径的日志
 51InBlock.gif        /// </summary>
 52InBlock.gif        /// <param name="logUrl">日志路径,物理地址</param>
 53InBlock.gif        /// <param name="title"></param>
 54ExpandedSubBlockEnd.gif        /// <param name="information"></param>

 55InBlock.gif        public static void LogInfo(String logUrl, String title, String information)
 56ExpandedSubBlockStart.gifContractedSubBlock.gif        dot.gif{
 57InBlock.gif            using (FileStream fs = new FileStream(logUrl, FileMode.Append, FileAccess.Write))
 58ExpandedSubBlockStart.gifContractedSubBlock.gif            dot.gif{
 59InBlock.gif                StreamWriter sw = new StreamWriter(fs, System.Text.Encoding.Default);
 60InBlock.gif                sw.WriteLine(information);
 61InBlock.gif                sw.Flush();
 62InBlock.gif                sw.Close();
 63InBlock.gif                fs.Close();
 64ExpandedSubBlockEnd.gif            }

 65ExpandedSubBlockEnd.gif        }

 66InBlock.gif
 67ExpandedSubBlockStart.gifContractedSubBlock.gif        /**//// <summary>
 68InBlock.gif        /// MD5加密
 69InBlock.gif        /// </summary>
 70InBlock.gif        /// <param name="toCryString"></param>
 71ExpandedSubBlockEnd.gif        /// <returns></returns>

 72InBlock.gif        public static String MD5(String toCryString)
 73ExpandedSubBlockStart.gifContractedSubBlock.gif        dot.gif{
 74InBlock.gif            MD5CryptoServiceProvider hashmd5;
 75InBlock.gif            hashmd5 = new MD5CryptoServiceProvider();
 76InBlock.gif            return BitConverter.ToString(hashmd5.ComputeHash(Encoding.Default.GetBytes(toCryString))).Replace("-""").ToLower();
 77ExpandedSubBlockEnd.gif        }

 78InBlock.gif
 79ExpandedSubBlockStart.gifContractedSubBlock.gif        /**//// <summary>
 80InBlock.gif        /// 获取客户端的IP地址
 81InBlock.gif        /// </summary>
 82ExpandedSubBlockEnd.gif        /// <returns></returns>

 83InBlock.gif        public static String ClientIP()
 84ExpandedSubBlockStart.gifContractedSubBlock.gif        dot.gif{
 85InBlock.gif            //判断是否通过代理服务器上网
 86InBlock.gif            if (HttpContext.Current.Request.ServerVariables["HTTP_X_FORWARDED_FOR"!= null)
 87ExpandedSubBlockStart.gifContractedSubBlock.gif            dot.gif{
 88InBlock.gif                return HttpContext.Current.Request.ServerVariables["HTTP_X_FORWARDED_FOR"].ToString();  //真实的IP
 89ExpandedSubBlockEnd.gif            }

 90InBlock.gif            else
 91ExpandedSubBlockStart.gifContractedSubBlock.gif            dot.gif{
 92InBlock.gif                return HttpContext.Current.Request.ServerVariables["REMOTE_ADDR"].ToString();
 93ExpandedSubBlockEnd.gif            }

 94ExpandedSubBlockEnd.gif        }

 95InBlock.gif
 96ExpandedSubBlockStart.gifContractedSubBlock.gif        /**//// <summary>
 97InBlock.gif        /// 在客户端弹出一个消息框(Page)
 98InBlock.gif        /// </summary>
 99ExpandedSubBlockEnd.gif        /// <param name="strMsg">待显示的信息</param>

100InBlock.gif        public static void ShowClientMessegeBox(System.Web.UI.Page pageFor, String strMessage)
101ExpandedSubBlockStart.gifContractedSubBlock.gif        dot.gif{
102InBlock.gif            System.Text.StringBuilder strBuilder = new System.Text.StringBuilder("<script>alert(\"");
103InBlock.gif            strBuilder.Append(strMessage.Replace("\r\n""\\r\\n"));
104InBlock.gif            strBuilder.Append("\")</script>");
105InBlock.gif            pageFor.ClientScript.RegisterStartupScript(pageFor.GetType(), "alertBox", strBuilder.ToString());
106ExpandedSubBlockEnd.gif        }

107InBlock.gif
108ExpandedSubBlockStart.gifContractedSubBlock.gif        /**//// <summary>
109InBlock.gif        /// 在客户端弹出一个消息框(UserControl)
110InBlock.gif        /// </summary>
111ExpandedSubBlockEnd.gif        /// <param name="strMsg">待显示的信息</param>

112InBlock.gif        public static void ShowClientMessegeBox(System.Web.UI.UserControl ucFor, String strMessage)
113ExpandedSubBlockStart.gifContractedSubBlock.gif        dot.gif{
114InBlock.gif            System.Text.StringBuilder strBuilder = new System.Text.StringBuilder("<script>alert(\"");
115InBlock.gif            strBuilder.Append(strMessage.Replace("\r\n""\\r\\n"));
116InBlock.gif            strBuilder.Append("\")</script>");
117InBlock.gif            ucFor.Page.ClientScript.RegisterStartupScript(ucFor.GetType(), "alertBox", strBuilder.ToString());
118ExpandedSubBlockEnd.gif        }

119InBlock.gif
120ExpandedSubBlockStart.gifContractedSubBlock.gif        /**//// <summary>
121InBlock.gif        /// 在客户端跳转页面
122InBlock.gif        /// </summary>
123ExpandedSubBlockEnd.gif        /// <param name="Url"></param>

124InBlock.gif        public static void RedirectAtClient(String redirectUrl)
125ExpandedSubBlockStart.gifContractedSubBlock.gif        dot.gif{
126InBlock.gif            HttpContext.Current.Response.Write("<script language=\"javascript\" type=\"text/javascript\">");
127InBlock.gif            HttpContext.Current.Response.Write("location.href='" + redirectUrl + "';");
128InBlock.gif            HttpContext.Current.Response.Write("</script>");
129InBlock.gif            HttpContext.Current.Response.End();
130ExpandedSubBlockEnd.gif        }

131InBlock.gif
132ExpandedSubBlockStart.gifContractedSubBlock.gif        /**//// <summary>
133InBlock.gif        /// 在客户端弹出消息框并跳转
134InBlock.gif        /// </summary>
135InBlock.gif        /// <param name="pageFor"></param>
136InBlock.gif        /// <param name="message">待显示的信息</param>
137ExpandedSubBlockEnd.gif        /// <param name="redirectUrl">待跳转的地址</param>

138InBlock.gif        public static void ShowClientMessegeBoxAndRedirect(String message, String redirectUrl)
139ExpandedSubBlockStart.gifContractedSubBlock.gif        dot.gif{
140InBlock.gif            HttpContext.Current.Response.Write("<script language=\"javascript\" type=\"text/javascript\">");
141InBlock.gif            HttpContext.Current.Response.Write("alert('" + message + "');");
142InBlock.gif            HttpContext.Current.Response.Write("location.href='" + redirectUrl + "';");
143InBlock.gif            HttpContext.Current.Response.Write("</script>");
144InBlock.gif            HttpContext.Current.Response.End();
145ExpandedSubBlockEnd.gif        }

146InBlock.gif
147ExpandedSubBlockStart.gifContractedSubBlock.gif        /**//// <summary>
148InBlock.gif        /// 在客户端弹出消息框并关闭窗口
149InBlock.gif        /// </summary>
150ExpandedSubBlockEnd.gif        /// <param name="message">待显示的信息</param>

151InBlock.gif        public static void ShowClientMessegeBoxAndClose(String message)
152ExpandedSubBlockStart.gifContractedSubBlock.gif        dot.gif{
153InBlock.gif            HttpContext.Current.Response.Write("<script language=\"javascript\" type=\"text/javascript\">");
154InBlock.gif            HttpContext.Current.Response.Write("alert('" + message + "');");
155InBlock.gif            HttpContext.Current.Response.Write("window.close();");
156InBlock.gif            HttpContext.Current.Response.Write("</script>");
157InBlock.gif            HttpContext.Current.Response.End();
158ExpandedSubBlockEnd.gif        }

159InBlock.gif
160InBlock.gif
161ExpandedSubBlockStart.gifContractedSubBlock.gif        /**//// <summary>
162InBlock.gif        /// 在客户端弹出消息框并父窗口跳转
163InBlock.gif        /// </summary>
164ExpandedSubBlockEnd.gif        /// <param name="message">待显示的信息</param>

165InBlock.gif        public static void ShowClientMessegeBoxAndRedirectAtParent(String message, String redirectUrl)
166ExpandedSubBlockStart.gifContractedSubBlock.gif        dot.gif{
167InBlock.gif            HttpContext.Current.Response.Write("<script language=\"javascript\" type=\"text/javascript\">");
168InBlock.gif            HttpContext.Current.Response.Write("alert('" + message + "');");
169InBlock.gif            HttpContext.Current.Response.Write("window.parent.location.href='" + redirectUrl + "';");
170InBlock.gif            HttpContext.Current.Response.Write("</script>");
171InBlock.gif            HttpContext.Current.Response.End();
172ExpandedSubBlockEnd.gif        }

173InBlock.gif
174ExpandedSubBlockStart.gifContractedSubBlock.gif        /**//// <summary>
175InBlock.gif        /// 在客户端关闭新开窗口并刷新Opener
176InBlock.gif        /// </summary>
177InBlock.gif        /// <param name="pageFor"></param>
178InBlock.gif        /// <param name="message">待显示的信息</param>
179ExpandedSubBlockEnd.gif        /// <param name="redirectUrl">待跳转的地址</param>

180InBlock.gif        public static void CloseAndRefreshOpener()
181ExpandedSubBlockStart.gifContractedSubBlock.gif        dot.gif{
182InBlock.gif            HttpContext.Current.Response.Write("<script language=\"javascript\" type=\"text/javascript\">");
183InBlock.gif            HttpContext.Current.Response.Write("window.opener.location.href=window.opener.location.href;");
184InBlock.gif            HttpContext.Current.Response.Write("window.focus();");
185InBlock.gif            HttpContext.Current.Response.Write("window.opener=null;");
186InBlock.gif            HttpContext.Current.Response.Write("window.close();");
187InBlock.gif            HttpContext.Current.Response.Write("</script>");
188InBlock.gif            HttpContext.Current.Response.End();
189ExpandedSubBlockEnd.gif        }

190InBlock.gif
191ExpandedSubBlockStart.gifContractedSubBlock.gif        /**//// <summary>
192InBlock.gif        /// 在客户端刷新Opener
193InBlock.gif        /// </summary>
194InBlock.gif        /// <param name="pageFor"></param>
195InBlock.gif        /// <param name="message">待显示的信息</param>
196ExpandedSubBlockEnd.gif        /// <param name="redirectUrl">待跳转的地址</param>

197InBlock.gif        public static void RefreshOpener()
198ExpandedSubBlockStart.gifContractedSubBlock.gif        dot.gif{
199InBlock.gif            HttpContext.Current.Response.Write("<script language=\"javascript\" type=\"text/javascript\">");
200InBlock.gif            HttpContext.Current.Response.Write("window.opener.location.href=window.opener.location.href;");
201InBlock.gif            HttpContext.Current.Response.Write("window.focus();");
202InBlock.gif            HttpContext.Current.Response.Write("</script>");
203ExpandedSubBlockEnd.gif        }

204InBlock.gif
205ExpandedSubBlockStart.gifContractedSubBlock.gif        /**//// <summary>
206InBlock.gif        /// 替换瘦文本框中的空格、大于号、小于号以及软回车,自动转换Email、HTTP地址
207InBlock.gif        /// </summary>
208InBlock.gif        /// <param name="content"></param>
209ExpandedSubBlockEnd.gif        /// <returns></returns>

210InBlock.gif        public static String EncodeTextBox(String content)
211ExpandedSubBlockStart.gifContractedSubBlock.gif        dot.gif{
212InBlock.gif            StringBuilder sbContent = new StringBuilder(content);
213InBlock.gif
214InBlock.gif            sbContent = sbContent.Replace("<""&lt;");//处理小于号   
215InBlock.gif            sbContent = sbContent.Replace(">""&gt;");//处理大于号   
216InBlock.gif            sbContent = sbContent.Replace("\"""&quot;");//处理双引号
217InBlock.gif
218InBlock.gif            //替换URL
219InBlock.gif            Regex regUrl = new Regex(@"(http:\/\/[\w.]+(\/?\w+)+[.a-zA-Z0-9\?=]+)", RegexOptions.IgnoreCase | RegexOptions.Compiled);
220InBlock.gif            sbContent = new StringBuilder(regUrl.Replace(sbContent.ToString(), "<a href=\"$0\" target=\"_blank\">$0</a>"));
221InBlock.gif
222InBlock.gif            //替换Email
223InBlock.gif            Regex regEmail = new Regex(@"([a-zA-Z_0-9.-]+\@[a-zA-Z_0-9.-]+\.\w+)", RegexOptions.IgnoreCase | RegexOptions.Compiled);
224InBlock.gif            sbContent = new StringBuilder(regEmail.Replace(sbContent.ToString(), "<a href=\"mailto:$0\">$0</a>"));
225InBlock.gif
226InBlock.gif            sbContent = sbContent.Replace("\n""<br />");//处理换行   
227InBlock.gif            sbContent = sbContent.Replace("  ""&nbsp;&nbsp;");//处理空格   
228InBlock.gif
229InBlock.gif            return sbContent.ToString();
230ExpandedSubBlockEnd.gif        }

231InBlock.gif
232ExpandedSubBlockStart.gifContractedSubBlock.gif        /**//// <summary>
233InBlock.gif        /// 与EncodeTextBox方法作用相反
234InBlock.gif        /// </summary>
235InBlock.gif        /// <param name="content"></param>
236ExpandedSubBlockEnd.gif        /// <returns></returns>

237InBlock.gif        public static String DecodeTextBox(String content)
238ExpandedSubBlockStart.gifContractedSubBlock.gif        dot.gif{
239InBlock.gif            StringBuilder sbContent = new StringBuilder(Utility.DropHtmlTags(content)); //去掉html标签
240InBlock.gif
241InBlock.gif            sbContent = sbContent.Replace("&quot;""\"");//处理双引号
242InBlock.gif            sbContent = sbContent.Replace("&nbsp;&nbsp;""  ");//处理空格   
243InBlock.gif            sbContent = sbContent.Replace("&lt;""<");//处理小于号   
244InBlock.gif            sbContent = sbContent.Replace("&gt;"">");//处理大于号   
245InBlock.gif            sbContent = sbContent.Replace("<br />""\n");//处理换行   
246InBlock.gif
247InBlock.gif            return sbContent.ToString();
248ExpandedSubBlockEnd.gif        }

249InBlock.gif
250ExpandedSubBlockStart.gifContractedSubBlock.gif        /**//// <summary>
251InBlock.gif        /// 对字符串进行Base64编码
252InBlock.gif        /// </summary>
253InBlock.gif        /// <param name="content"></param>
254ExpandedSubBlockEnd.gif        /// <returns></returns>

255InBlock.gif        public static String EncodeBase64(String content)
256ExpandedSubBlockStart.gifContractedSubBlock.gif        dot.gif{
257InBlock.gif            String encode = "";
258InBlock.gif            Byte[] bytes = Encoding.Default.GetBytes(content);
259InBlock.gif
260InBlock.gif            try
261ExpandedSubBlockStart.gifContractedSubBlock.gif            dot.gif{
262InBlock.gif                encode = Convert.ToBase64String(bytes);
263ExpandedSubBlockEnd.gif            }

264InBlock.gif            catch
265ExpandedSubBlockStart.gifContractedSubBlock.gif            dot.gif{
266InBlock.gif                encode = content;
267ExpandedSubBlockEnd.gif            }

268InBlock.gif
269InBlock.gif            return encode;
270ExpandedSubBlockEnd.gif        }

271InBlock.gif
272ExpandedSubBlockStart.gifContractedSubBlock.gif        /**//// <summary>
273InBlock.gif        /// 对字符串进行Base64解码
274InBlock.gif        /// </summary>
275InBlock.gif        /// <param name="content"></param>
276ExpandedSubBlockEnd.gif        /// <returns></returns>

277InBlock.gif        public static String DecodeBase64(String content)
278ExpandedSubBlockStart.gifContractedSubBlock.gif        dot.gif{
279InBlock.gif            String decode = "";
280InBlock.gif            Byte[] bytes = Convert.FromBase64String(content);
281InBlock.gif
282InBlock.gif            try
283ExpandedSubBlockStart.gifContractedSubBlock.gif            dot.gif{
284InBlock.gif                decode = Encoding.Default.GetString(bytes);
285ExpandedSubBlockEnd.gif            }

286InBlock.gif            catch
287ExpandedSubBlockStart.gifContractedSubBlock.gif            dot.gif{
288InBlock.gif                decode = content;
289ExpandedSubBlockEnd.gif            }

290InBlock.gif
291InBlock.gif            return decode;
292ExpandedSubBlockEnd.gif        }

293InBlock.gif
294ExpandedSubBlockStart.gifContractedSubBlock.gif        /**//// <summary>
295InBlock.gif        /// DES加密
296InBlock.gif        /// </summary>
297InBlock.gif        /// <param name="pToEncrypt">要加密的字符串</param>
298InBlock.gif        /// <param name="sKey">密钥</param>
299ExpandedSubBlockEnd.gif        /// <returns></returns>

300InBlock.gif        public static String EncodeDES(String pToEncrypt, String sKey)
301ExpandedSubBlockStart.gifContractedSubBlock.gif        dot.gif{
302InBlock.gif            DESCryptoServiceProvider des = new DESCryptoServiceProvider();
303InBlock.gif
304InBlock.gif            //把字符串放到byte数组中
305InBlock.gif            Byte[] inputByteArray = Encoding.Default.GetBytes(pToEncrypt);
306InBlock.gif
307InBlock.gif            //建立加密对象的密钥和偏移量  
308InBlock.gif            //原文使用ASCIIEncoding.ASCII方法的GetBytes方法  
309InBlock.gif            //使得输入密码必须输入英文文本  
310InBlock.gif            des.Key = ASCIIEncoding.ASCII.GetBytes(sKey);
311InBlock.gif            des.IV = ASCIIEncoding.ASCII.GetBytes(sKey);
312InBlock.gif            MemoryStream ms = new MemoryStream();
313InBlock.gif            CryptoStream cs = new CryptoStream(ms, des.CreateEncryptor(), CryptoStreamMode.Write);
314InBlock.gif
315InBlock.gif            //Write  the  byte  array  into  the  crypto  stream  
316InBlock.gif            //(It  will  end  up  in  the  memory  stream)  
317InBlock.gif            cs.Write(inputByteArray, 0, inputByteArray.Length);
318InBlock.gif            cs.FlushFinalBlock();
319InBlock.gif
320InBlock.gif            //Get  the  data  back  from  the  memory  stream,  and  into  a  string  
321InBlock.gif            StringBuilder ret = new StringBuilder();
322InBlock.gif            foreach (Byte b in ms.ToArray())
323ExpandedSubBlockStart.gifContractedSubBlock.gif            dot.gif{
324InBlock.gif                //Format  as  hex  
325InBlock.gif                ret.AppendFormat("{0:X2}", b);
326ExpandedSubBlockEnd.gif            }

327InBlock.gif
328InBlock.gif            ret.ToString();
329InBlock.gif
330InBlock.gif            return ret.ToString();
331ExpandedSubBlockEnd.gif        }

332InBlock.gif
333ExpandedSubBlockStart.gifContractedSubBlock.gif        /**//// <summary>
334InBlock.gif        /// DES解密
335InBlock.gif        /// </summary>
336InBlock.gif        /// <param name="pToDecrypt">要解密的字符串</param>
337InBlock.gif        /// <param name="sKey">密钥</param>
338ExpandedSubBlockEnd.gif        /// <returns></returns>

339InBlock.gif        public static String DecodeDES(String pToDecrypt, String sKey)
340ExpandedSubBlockStart.gifContractedSubBlock.gif        dot.gif{
341InBlock.gif            DESCryptoServiceProvider des = new DESCryptoServiceProvider();
342InBlock.gif
343InBlock.gif            Byte[] inputByteArray = new Byte[pToDecrypt.Length / 2];
344InBlock.gif
345InBlock.gif            for (Int32 x = 0; x < pToDecrypt.Length / 2; x++)
346ExpandedSubBlockStart.gifContractedSubBlock.gif            dot.gif{
347InBlock.gif                Int32 i = (Convert.ToInt32(pToDecrypt.Substring(x * 22), 16));
348InBlock.gif                inputByteArray[x] = (Byte)i;
349ExpandedSubBlockEnd.gif            }

350InBlock.gif
351InBlock.gif            //建立加密对象的密钥和偏移量,此值重要,不能修改  
352InBlock.gif            des.Key = ASCIIEncoding.ASCII.GetBytes(sKey);
353InBlock.gif            des.IV = ASCIIEncoding.ASCII.GetBytes(sKey);
354InBlock.gif            MemoryStream ms = new MemoryStream();
355InBlock.gif            CryptoStream cs = new CryptoStream(ms, des.CreateDecryptor(), CryptoStreamMode.Write);
356InBlock.gif
357InBlock.gif            //Flush  the  data  through  the  crypto  stream  into  the  memory  stream  
358InBlock.gif            cs.Write(inputByteArray, 0, inputByteArray.Length);
359InBlock.gif            cs.FlushFinalBlock();
360InBlock.gif
361InBlock.gif            //Get  the  decrypted  data  back  from  the  memory  stream  
362InBlock.gif            return Encoding.Default.GetString(ms.ToArray());
363ExpandedSubBlockEnd.gif        }

364InBlock.gif
365ExpandedSubBlockStart.gifContractedSubBlock.gif        /**//// <summary>
366InBlock.gif        /// DES与Base64组合加密
367InBlock.gif        /// </summary>
368InBlock.gif        /// <param name="data"></param>
369InBlock.gif        /// <param name="key"></param>
370ExpandedSubBlockEnd.gif        /// <returns></returns>

371InBlock.gif        public static String EncodeDESAndBase64(String data, String key)
372ExpandedSubBlockStart.gifContractedSubBlock.gif        dot.gif{
373InBlock.gif            Byte[] byKey = Encoding.Default.GetBytes(key);
374InBlock.gif            Byte[] byIV = Encoding.Default.GetBytes(key);
375InBlock.gif
376InBlock.gif            DESCryptoServiceProvider cryptoProvider = new DESCryptoServiceProvider();
377InBlock.gif            Int32 i = cryptoProvider.KeySize;
378InBlock.gif            MemoryStream ms = new MemoryStream();
379InBlock.gif            CryptoStream cst = new CryptoStream(ms, cryptoProvider.CreateEncryptor(byKey, byIV), CryptoStreamMode.Write);
380InBlock.gif
381InBlock.gif            StreamWriter sw = new StreamWriter(cst);
382InBlock.gif            cst.Write(System.Text.Encoding.Default.GetBytes(data), 0, System.Text.Encoding.Default.GetByteCount(data));
383InBlock.gif            sw.Flush();
384InBlock.gif            cst.FlushFinalBlock();
385InBlock.gif            sw.Flush();
386InBlock.gif
387InBlock.gif            return Convert.ToBase64String(ms.GetBuffer(), 0, (Int32)ms.Length);
388ExpandedSubBlockEnd.gif        }

389InBlock.gif
390ExpandedSubBlockStart.gifContractedSubBlock.gif        /**//// <summary>
391InBlock.gif        /// DES与Base64组合解密
392InBlock.gif        /// </summary>
393InBlock.gif        /// <param name="data"></param>
394InBlock.gif        /// <param name="key"></param>
395ExpandedSubBlockEnd.gif        /// <returns></returns>

396InBlock.gif        public static String DecodeDESAndBase64(String data, String key)
397ExpandedSubBlockStart.gifContractedSubBlock.gif        dot.gif{
398InBlock.gif            //把密钥转成二进制数组
399InBlock.gif            Byte[] byKey = Encoding.Default.GetBytes(key);
400InBlock.gif            Byte[] byIV = Encoding.Default.GetBytes(key);
401InBlock.gif
402InBlock.gif            Byte[] byEnc;
403InBlock.gif
404InBlock.gif            try
405ExpandedSubBlockStart.gifContractedSubBlock.gif            dot.gif{
406InBlock.gif                //base64解码
407InBlock.gif                byEnc = Convert.FromBase64String(data);
408ExpandedSubBlockEnd.gif            }

409InBlock.gif            catch
410ExpandedSubBlockStart.gifContractedSubBlock.gif            dot.gif{
411InBlock.gif                return null;
412ExpandedSubBlockEnd.gif            }

413InBlock.gif
414InBlock.gif            DESCryptoServiceProvider cryptoProvider = new DESCryptoServiceProvider();
415InBlock.gif            MemoryStream ms = new MemoryStream(byEnc);
416InBlock.gif            CryptoStream cst = new CryptoStream(ms, cryptoProvider.CreateDecryptor(byKey, byIV), CryptoStreamMode.Read);
417InBlock.gif            StreamReader sr = new StreamReader(cst);
418InBlock.gif            Byte[] tmp = new Byte[ms.Length];
419InBlock.gif            cst.Read(tmp, 0, tmp.Length);
420InBlock.gif            String result = System.Text.Encoding.Default.GetString(tmp);
421InBlock.gif
422InBlock.gif            return result;
423ExpandedSubBlockEnd.gif        }

424InBlock.gif
425ExpandedSubBlockStart.gifContractedSubBlock.gif        /**//// <summary>
426InBlock.gif        /// 数组转换为ArrayList
427InBlock.gif        /// </summary>
428InBlock.gif        /// <param name="array">待转换的数组</param>
429ExpandedSubBlockEnd.gif        /// <returns></returns>

430InBlock.gif        public static ArrayList ArrayToArrayList(String[] array)
431ExpandedSubBlockStart.gifContractedSubBlock.gif        dot.gif{
432InBlock.gif            ArrayList arrayList = new ArrayList();
433InBlock.gif
434InBlock.gif            for (Int32 i = 0; i < array.Length; i++)
435ExpandedSubBlockStart.gifContractedSubBlock.gif            dot.gif{
436InBlock.gif                arrayList.Add(array[i]);
437ExpandedSubBlockEnd.gif            }

438InBlock.gif
439InBlock.gif            return arrayList;
440ExpandedSubBlockEnd.gif        }

441InBlock.gif
442ExpandedSubBlockStart.gifContractedSubBlock.gif        /**//// <summary>
443InBlock.gif        /// 数组转换为ArrayList
444InBlock.gif        /// </summary>
445InBlock.gif        /// <param name="array">待转换的数组</param>
446ExpandedSubBlockEnd.gif        /// <returns></returns>

447InBlock.gif        public static ArrayList ArrayToArrayList(Char[] array)
448ExpandedSubBlockStart.gifContractedSubBlock.gif        dot.gif{
449InBlock.gif            ArrayList arrayList = new ArrayList();
450InBlock.gif
451InBlock.gif            for (Int32 i = 0; i < array.Length; i++)
452ExpandedSubBlockStart.gifContractedSubBlock.gif            dot.gif{
453InBlock.gif                arrayList.Add(array[i]);
454ExpandedSubBlockEnd.gif            }

455InBlock.gif
456InBlock.gif            return arrayList;
457ExpandedSubBlockEnd.gif        }

458InBlock.gif
459ExpandedSubBlockStart.gifContractedSubBlock.gif        /**//// <summary>
460InBlock.gif        /// 截断字符串,截断结果的长度将不会超过制定的最大长度
461InBlock.gif        /// </summary>
462InBlock.gif        /// <param name="strContent"></param>
463InBlock.gif        /// <param name="intMaxLength"></param>
464ExpandedSubBlockEnd.gif        /// <returns></returns>

465InBlock.gif        public static String CompressString(String strContent, Int32 intMaxLength)
466ExpandedSubBlockStart.gifContractedSubBlock.gif        dot.gif{
467InBlock.gif            return CompressString(strContent, intMaxLength, true);
468ExpandedSubBlockEnd.gif        }

469InBlock.gif
470ExpandedSubBlockStart.gifContractedSubBlock.gif        /**//// <summary>
471InBlock.gif        /// 截断字符串,截断结果的长度将不会超过制定的最大长度,并且可以指定是否添加省略号
472InBlock.gif        /// </summary>
473InBlock.gif        /// <param name="strContent"></param>
474InBlock.gif        /// <param name="intMaxLength"></param>
475InBlock.gif        /// <param name="appendSuffix"></param>
476ExpandedSubBlockEnd.gif        /// <returns></returns>

477InBlock.gif        public static String CompressString(String strContent, Int32 intMaxLength, Boolean appendSuffix)
478ExpandedSubBlockStart.gifContractedSubBlock.gif        dot.gif{
479InBlock.gif            if (String.IsNullOrEmpty(strContent))
480ExpandedSubBlockStart.gifContractedSubBlock.gif            dot.gif{
481InBlock.gif                return String.Empty;
482ExpandedSubBlockEnd.gif            }

483InBlock.gif            else
484ExpandedSubBlockStart.gifContractedSubBlock.gif            dot.gif{
485InBlock.gif                int intUnicodeLength = 0;
486InBlock.gif                int intCharCount = 0;
487InBlock.gif                for (Int32 i = 0; i < strContent.Length && intUnicodeLength < intMaxLength; i++)
488ExpandedSubBlockStart.gifContractedSubBlock.gif                dot.gif{
489InBlock.gif                    if (strContent[i] > 255)
490InBlock.gif                        intUnicodeLength += 2;
491InBlock.gif                    else
492InBlock.gif                        intUnicodeLength++;
493InBlock.gif
494InBlock.gif                    intCharCount++;
495ExpandedSubBlockEnd.gif                }

496InBlock.gif
497InBlock.gif                if (intUnicodeLength >= intMaxLength)
498ExpandedSubBlockStart.gifContractedSubBlock.gif                dot.gif{
499InBlock.gif                    if (appendSuffix)
500ExpandedSubBlockStart.gifContractedSubBlock.gif                    dot.gif{
501InBlock.gif                        return strContent.Substring(0, intCharCount) + "";
502ExpandedSubBlockEnd.gif                    }

503InBlock.gif                    else
504ExpandedSubBlockStart.gifContractedSubBlock.gif                    dot.gif{
505InBlock.gif                        return strContent.Substring(0, intCharCount);
506ExpandedSubBlockEnd.gif                    }

507ExpandedSubBlockEnd.gif                }

508InBlock.gif                else
509ExpandedSubBlockStart.gifContractedSubBlock.gif                dot.gif{
510InBlock.gif                    return strContent;
511ExpandedSubBlockEnd.gif                }

512ExpandedSubBlockEnd.gif            }

513ExpandedSubBlockEnd.gif        }

514InBlock.gif
515ExpandedSubBlockStart.gifContractedSubBlock.gif        /**//// <summary>
516InBlock.gif        /// 去掉字符串中的所有空格
517InBlock.gif        /// </summary>
518InBlock.gif        /// <param name="HtmlText"></param>
519ExpandedSubBlockEnd.gif        /// <returns></returns>

520InBlock.gif        public static String DropBlanks(string HtmlText)
521ExpandedSubBlockStart.gifContractedSubBlock.gif        dot.gif{
522InBlock.gif            if (!String.IsNullOrEmpty(HtmlText))
523ExpandedSubBlockStart.gifContractedSubBlock.gif            dot.gif{
524InBlock.gif                System.Text.RegularExpressions.Regex reg = new System.Text.RegularExpressions.Regex(@"[\s| ]", System.Text.RegularExpressions.RegexOptions.Singleline | System.Text.RegularExpressions.RegexOptions.Compiled);
525InBlock.gif                return reg.Replace(HtmlText, string.Empty).Replace("&nbsp;"" ");
526ExpandedSubBlockEnd.gif            }

527InBlock.gif            else
528ExpandedSubBlockStart.gifContractedSubBlock.gif            dot.gif{
529InBlock.gif                return String.Empty;
530ExpandedSubBlockEnd.gif            }

531ExpandedSubBlockEnd.gif        }

532InBlock.gif
533ExpandedSubBlockStart.gifContractedSubBlock.gif        /**//// <summary>
534InBlock.gif        /// 去除Html"标签"
535InBlock.gif        /// </summary>
536InBlock.gif        /// <param name="HtmlText"></param>
537ExpandedSubBlockEnd.gif        /// <returns></returns>

538InBlock.gif        public static String DropHtmlTags(string HtmlText)
539ExpandedSubBlockStart.gifContractedSubBlock.gif        dot.gif{
540InBlock.gif            if (string.IsNullOrEmpty(HtmlText))
541ExpandedSubBlockStart.gifContractedSubBlock.gif            dot.gif{
542InBlock.gif                return String.Empty;
543ExpandedSubBlockEnd.gif            }

544InBlock.gif            else
545ExpandedSubBlockStart.gifContractedSubBlock.gif            dot.gif{
546InBlock.gif                System.Text.RegularExpressions.Regex reg = new System.Text.RegularExpressions.Regex(@"<.*?>", System.Text.RegularExpressions.RegexOptions.Singleline | System.Text.RegularExpressions.RegexOptions.Compiled);
547InBlock.gif                return reg.Replace(HtmlText, string.Empty);
548ExpandedSubBlockEnd.gif            }

549ExpandedSubBlockEnd.gif        }

550InBlock.gif
551ExpandedSubBlockStart.gifContractedSubBlock.gif        /**//// <summary>
552InBlock.gif        /// 发送邮件(账户友好名称为:“价值中国网”)
553InBlock.gif        /// </summary>
554InBlock.gif        /// <param name="userID">邮件发送目的用户ID</param>
555InBlock.gif        /// <param name="subject">邮件主题</param>
556InBlock.gif        /// <param name="body">邮件内容</param>
557ExpandedSubBlockEnd.gif        /// <returns></returns>

558InBlock.gif        public static Boolean SendMail(Int32 userID, String subject, String body)
559ExpandedSubBlockStart.gifContractedSubBlock.gif        dot.gif{
560InBlock.gif            SqlParameter[] para = new SqlParameter[1];
561InBlock.gif            para[0= new SqlParameter("@ID", SqlDbType.Int, 4);
562InBlock.gif            para[0].Value = userID;
563InBlock.gif
564InBlock.gif            String sqlStr = "SELECT Email FROM huiyuan WHERE [ID] = @ID";
565InBlock.gif
566InBlock.gif            Object objEmail = SqlHelper.ExecuteScalar(WebConfig.ConnStrWWW, CommandType.Text, sqlStr, para);
567InBlock.gif
568InBlock.gif            if (objEmail != null)
569ExpandedSubBlockStart.gifContractedSubBlock.gif            dot.gif{
570InBlock.gif                return SendMail("价值中国网", objEmail.ToString(), subject, body);
571ExpandedSubBlockEnd.gif            }

572InBlock.gif
573InBlock.gif            return false;
574ExpandedSubBlockEnd.gif        }

575InBlock.gif
576ExpandedSubBlockStart.gifContractedSubBlock.gif        /**//// <summary>
577InBlock.gif        /// 发送邮件(账户友好名称为:“价值中国网”)
578InBlock.gif        /// </summary>
579InBlock.gif        /// <param name="toEmail">邮件发送目的Email</param>
580InBlock.gif        /// <param name="subject">邮件主题</param>
581InBlock.gif        /// <param name="body">邮件内容</param>
582ExpandedSubBlockEnd.gif        /// <returns></returns>

583InBlock.gif        public static Boolean SendMail(String toEmail, String subject, String body)
584ExpandedSubBlockStart.gifContractedSubBlock.gif        dot.gif{
585InBlock.gif            return SendMail("价值中国网", toEmail, subject, body);
586ExpandedSubBlockEnd.gif        }

587InBlock.gif
588ExpandedSubBlockStart.gifContractedSubBlock.gif        /**//// <summary>
589InBlock.gif        /// 发送邮件
590InBlock.gif        /// </summary>
591InBlock.gif        /// <param name="fromFriendlyName">收件人看到的友好名称</param>
592InBlock.gif        /// <param name="toEmail">邮件发送目的Email</param>
593InBlock.gif        /// <param name="subject">邮件主题</param>
594InBlock.gif        /// <param name="body">邮件内容</param>
595ExpandedSubBlockEnd.gif        /// <returns></returns>

596InBlock.gif        public static Boolean SendMail(String fromFriendlyName, String toEmail, String subject, String body)
597ExpandedSubBlockStart.gifContractedSubBlock.gif        dot.gif{
598InBlock.gif            return SendMail(fromFriendlyName, WebConfig.SMTPMailAccount, toEmail, subject, body);
599ExpandedSubBlockEnd.gif        }

600InBlock.gif
601ExpandedSubBlockStart.gifContractedSubBlock.gif        /**//// <summary>
602InBlock.gif        /// 发送邮件
603InBlock.gif        /// </summary>
604InBlock.gif        /// <param name="fromFriendlyName">收件人看到的友好名称</param>
605InBlock.gif        /// <param name="fromFriendlyMail">收件人看到的友好Email</param>
606InBlock.gif        /// <param name="toEmail">邮件发送目的Email</param>
607InBlock.gif        /// <param name="subject">邮件主题</param>
608InBlock.gif        /// <param name="body">邮件内容</param>
609ExpandedSubBlockEnd.gif        /// <returns></returns>

610InBlock.gif        public static Boolean SendMail(String fromFriendlyName, String fromFriendlyMail, String toEmail, String subject, String body)
611ExpandedSubBlockStart.gifContractedSubBlock.gif        dot.gif{
612InBlock.gif            Boolean sendResult = false;
613InBlock.gif
614InBlock.gif            String fromTrueUser = WebConfig.SMTPMailAccount.Substring(0, WebConfig.SMTPMailAccount.IndexOf('@'));
615InBlock.gif            String fromTrueDomain = WebConfig.SMTPMailAccount.Substring(WebConfig.SMTPMailAccount.IndexOf('@'+ 1, WebConfig.SMTPMailAccount.Length - fromTrueUser.Length - 1);
616InBlock.gif
617InBlock.gif            String fromUser = fromFriendlyMail.Substring(0, fromFriendlyMail.IndexOf('@'));
618InBlock.gif            String fromDomain = fromFriendlyMail.Substring(fromFriendlyMail.IndexOf('@'+ 1, fromFriendlyMail.Length - fromUser.Length - 1);
619InBlock.gif
620InBlock.gif            Smtp smtpServer = new Smtp();
621InBlock.gif            smtpServer.UseAuthentication = true;
622InBlock.gif            smtpServer.Server = WebConfig.SMTPServerAddress;
623InBlock.gif            smtpServer.Username = WebConfig.SMTPUserName;
624InBlock.gif            smtpServer.Password = WebConfig.SMTPPassword;
625InBlock.gif            smtpServer.MailFrom = new MailAddress(fromFriendlyName, fromTrueUser, fromTrueDomain);
626InBlock.gif
627InBlock.gif            StringBuilder sbMailBody = new StringBuilder();
628InBlock.gif            sbMailBody.Append("<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\"><html xmlns=\"http://www.w3.org/1999/xhtml\"><head><meta http-equiv=\"Content-Type\" content=\"text/html; charset=gb2312\" /><body>");
629InBlock.gif            sbMailBody.Append(body);
630InBlock.gif            sbMailBody.Append("</body></html>");
631InBlock.gif
632InBlock.gif            MessageStream msgStream = new MessageStream();
633InBlock.gif            msgStream.Type = "text/html";
634InBlock.gif            msgStream.From.Domain = fromDomain;
635InBlock.gif            msgStream.From.User = fromUser;
636InBlock.gif            msgStream.From.Friendly = fromFriendlyName;
637InBlock.gif            msgStream.To.Add(new MailAddress(toEmail));
638InBlock.gif
639InBlock.gif            msgStream.Charset = "gb2312";
640InBlock.gif            //以下各种时间格式都会造成用户收到的邮件时间不准,暂时没有好的解决办法
641InBlock.gif            //msgStream.Date = DateTime.Now.ToString("r") + " +0800";
642InBlock.gif            //msgStream.Date = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
643InBlock.gif            //msgStream.Date = DateTime.Now.ToString("g");
644InBlock.gif            //msgStream.Date = DateTime.Now.ToString();
645InBlock.gif            msgStream.Mailer = "www.chinavalue.net";
646InBlock.gif
647InBlock.gif            msgStream.Subject = subject;
648InBlock.gif            msgStream.Text = sbMailBody.ToString();
649InBlock.gif
650InBlock.gif            try
651ExpandedSubBlockStart.gifContractedSubBlock.gif            dot.gif{
652InBlock.gif                smtpServer.Send(msgStream);
653InBlock.gif                smtpServer.Close();
654InBlock.gif
655InBlock.gif                sendResult = true;
656ExpandedSubBlockEnd.gif            }

657InBlock.gif            catch (ProtocolException exProtocol)
658ExpandedSubBlockStart.gifContractedSubBlock.gif            dot.gif{
659InBlock.gif                //TODO: Log exception
660InBlock.gif                Utility.LogInfo("ChinaValue.Info.Common.SendMail Error", exProtocol.ToString());
661ExpandedSubBlockEnd.gif            }

662InBlock.gif            catch (SocketException exSocket)
663ExpandedSubBlockStart.gifContractedSubBlock.gif            dot.gif{
664InBlock.gif                //TODO: Log exception
665InBlock.gif                Utility.LogInfo("ChinaValue.Info.Common.SendMail Error", exSocket.ToString());
666ExpandedSubBlockEnd.gif            }

667InBlock.gif            catch (IOException exIO)
668ExpandedSubBlockStart.gifContractedSubBlock.gif            dot.gif{
669InBlock.gif                //TODO: Log IOException
670InBlock.gif                Utility.LogInfo("ChinaValue.Info.Common.SendMail Error", exIO.ToString());
671ExpandedSubBlockEnd.gif            }

672InBlock.gif            catch (ArgumentException exArg)
673ExpandedSubBlockStart.gifContractedSubBlock.gif            dot.gif{
674InBlock.gif                //TODO: Log Argument Exception
675InBlock.gif                Utility.LogInfo("ChinaValue.Info.Common.SendMail Error", exArg.ToString());
676ExpandedSubBlockEnd.gif            }

677InBlock.gif
678InBlock.gif            return sendResult;
679ExpandedSubBlockEnd.gif        }

680InBlock.gif
681ExpandedSubBlockStart.gifContractedSubBlock.gif        /**//// <summary>
682InBlock.gif        /// 发送站内信息
683InBlock.gif        /// </summary>
684InBlock.gif        /// <param name="intFromUserId">发送用户的ID</param>
685InBlock.gif        /// <param name="intToUserId">接收用户的ID</param>
686InBlock.gif        /// <param name="msgSubject">消息标题</param>
687InBlock.gif        /// <param name="msgBody">消息内容</param>
688ExpandedSubBlockEnd.gif        /// <returns></returns>

689InBlock.gif        public static Boolean SendMessage(Int32 fromUserID, Int32 toUserID, String msgSubject, String msgBody)
690ExpandedSubBlockStart.gifContractedSubBlock.gif        dot.gif{
691InBlock.gif            return SendMessage(fromUserID, toUserID, msgSubject, msgBody, String.Empty);
692ExpandedSubBlockEnd.gif        }

693InBlock.gif
694ExpandedSubBlockStart.gifContractedSubBlock.gif        /**//// <summary>
695InBlock.gif        /// 发送系统消息
696InBlock.gif        /// </summary>
697InBlock.gif        /// <param name="toUserID">接收用户的ID</param>
698InBlock.gif        /// <param name="msgSubject">消息标题</param>
699InBlock.gif        /// <param name="msgBody">消息内容</param>
700ExpandedSubBlockEnd.gif        /// <returns></returns>

701InBlock.gif        public static Boolean SendMessage(Int32 toUserID, String msgSubject, String msgBody)
702ExpandedSubBlockStart.gifContractedSubBlock.gif        dot.gif{
703InBlock.gif            return SendMessage(0, toUserID, msgSubject, msgBody, "价值中国");
704ExpandedSubBlockEnd.gif        }

705InBlock.gif
706ExpandedSubBlockStart.gifContractedSubBlock.gif        /**//// <summary>
707InBlock.gif        /// 发送站内信息
708InBlock.gif        /// </summary>
709InBlock.gif        /// <param name="fromUserID">发送用户的ID</param>
710InBlock.gif        /// <param name="toUserID">接收用户的ID</param>
711InBlock.gif        /// <param name="msgSubject">消息标题</param>
712InBlock.gif        /// <param name="msgBody">消息内容</param>
713InBlock.gif        /// <param name="systemUserName">系统消息的发送者姓名</param>
714ExpandedSubBlockEnd.gif        /// <returns></returns>

715InBlock.gif        public static Boolean SendMessage(Int32 fromUserID, Int32 toUserID, String msgSubject, String msgBody, String systemUserName)
716ExpandedSubBlockStart.gifContractedSubBlock.gif        dot.gif{
717InBlock.gif            SqlParameter[] para = new SqlParameter[5];
718InBlock.gif            para[0= new SqlParameter("@title", SqlDbType.NText);
719InBlock.gif            para[0].Value = msgSubject;
720InBlock.gif            para[1= new SqlParameter("@content", SqlDbType.NText);
721InBlock.gif            para[1].Value = msgBody;
722InBlock.gif            para[2= new SqlParameter("@toUserID", SqlDbType.Int, 4);
723InBlock.gif            para[2].Value = toUserID;
724InBlock.gif            para[3= new SqlParameter("@fromUserID", SqlDbType.Int, 4);
725InBlock.gif            para[3].Value = fromUserID;
726InBlock.gif            para[4= new SqlParameter("@systemUserName", SqlDbType.NVarChar, 20);
727InBlock.gif            para[4].Value = systemUserName;
728InBlock.gif
729InBlock.gif            if (SqlHelper.ExecuteNonQuery(WebConfig.DBConnectionString, CommandType.StoredProcedure, "pr_Message_Send", para) > 0)
730ExpandedSubBlockStart.gifContractedSubBlock.gif            dot.gif{
731InBlock.gif                return true;
732ExpandedSubBlockEnd.gif            }

733InBlock.gif
734InBlock.gif            return false;
735ExpandedSubBlockEnd.gif        }

736InBlock.gif
737ExpandedSubBlockStart.gifContractedSubBlock.gif        /**//// <summary>
738InBlock.gif        /// 发送站内消息 + Email
739InBlock.gif        /// </summary>
740InBlock.gif        /// <param name="toUserID">收件人ID</param>
741InBlock.gif        /// <param name="subject">消息主题</param>
742InBlock.gif        /// <param name="body">消息内容</param>
743ExpandedSubBlockEnd.gif        /// <returns></returns>

744InBlock.gif        public static Boolean SendMailAndMessage(Int32 toUserID, String subject, String body)
745ExpandedSubBlockStart.gifContractedSubBlock.gif        dot.gif{
746InBlock.gif            return SendMail(toUserID, subject, body) & SendMessage(toUserID, subject, body);
747ExpandedSubBlockEnd.gif        }

748InBlock.gif
749ExpandedSubBlockStart.gifContractedSubBlock.gif        /**//// <summary>
750InBlock.gif        /// 清除Word冗余格式
751InBlock.gif        /// </summary>
752InBlock.gif        /// <param name="str"></param>
753ExpandedSubBlockEnd.gif        /// <returns></returns>

754InBlock.gif        public static string CleanWordStyle(String str)
755ExpandedSubBlockStart.gifContractedSubBlock.gif        dot.gif{
756InBlock.gif            StringCollection sc = new StringCollection();
757InBlock.gif
758InBlock.gif            // get rid of unnecessary tag spans (comments and title)
759InBlock.gif            sc.Add(@"<!--(\w|\W)+?-->");
760InBlock.gif            sc.Add(@"<title>(\w|\W)+?</title>");
761InBlock.gif
762InBlock.gif            // Get rid of classes and styles
763InBlock.gif            sc.Add(@"\s?class=\w+");
764InBlock.gif            sc.Add(@"\s+style='[^']+'");
765InBlock.gif
766InBlock.gif            // Get rid of unnecessary tags
767InBlock.gif            sc.Add(
768InBlock.gif            @"<(meta|link|/?o:|/?style|/?st\d|/?head|/?html|body|/?body|/?span|!\[)[^>]*?>");
769InBlock.gif
770InBlock.gif            // Get rid of empty paragraph tags
771InBlock.gif            sc.Add(@"(<[^>]+>)+&nbsp;(</\w+>)+");
772InBlock.gif
773InBlock.gif            // remove bizarre v: element attached to <img> tag
774InBlock.gif            sc.Add(@"\s+v:\w+=""[^""]+""");
775InBlock.gif
776InBlock.gif            // remove extra lines
777InBlock.gif            sc.Add(@"(\n\r){2,}");
778InBlock.gif
779InBlock.gif            // remove font tags
780InBlock.gif            sc.Add(@"</?font.*?>");
781InBlock.gif
782InBlock.gif            // remove font tags
783InBlock.gif            sc.Add(@"</?b\W+.*?>");
784InBlock.gif
785InBlock.gif            // remove font tags
786InBlock.gif            sc.Add(@"<\?xml.*?>");
787InBlock.gif
788InBlock.gif            foreach (String s in sc)
789ExpandedSubBlockStart.gifContractedSubBlock.gif            dot.gif{
790InBlock.gif                str = Regex.Replace(str, s, "", RegexOptions.IgnoreCase | RegexOptions.Multiline);
791ExpandedSubBlockEnd.gif            }

792InBlock.gif
793InBlock.gif            String pattern = @"<p.*?>";
794InBlock.gif            Regex reg = new Regex(pattern, RegexOptions.IgnoreCase | RegexOptions.Multiline);
795InBlock.gif            str = reg.Replace(str, "<p>");
796InBlock.gif
797InBlock.gif            pattern = @"<div.*?>";
798InBlock.gif            reg = new Regex(pattern, RegexOptions.IgnoreCase | RegexOptions.Multiline);
799InBlock.gif            str = reg.Replace(str, "<div>");
800InBlock.gif
801InBlock.gif            return str;
802ExpandedSubBlockEnd.gif        }

803InBlock.gif
804ExpandedSubBlockStart.gifContractedSubBlock.gif        /**//// <summary>
805InBlock.gif        /// 检测操作是否已进行,用于限制规定时间内只能进行一次的操作
806InBlock.gif        /// </summary>
807InBlock.gif        /// <param name="key">用户监测的Cookie、Session键</param>
808InBlock.gif        /// <param name="expireTime">下次操作的间隔时间(分钟)</param>
809InBlock.gif        /// <param name="userSession">是否启用Session(默认只用Cookie)</param>
810ExpandedSubBlockEnd.gif        /// <returns></returns>

811InBlock.gif        public static Boolean OperationDone(String key, Int32 expireTime, Boolean userSession)
812ExpandedSubBlockStart.gifContractedSubBlock.gif        dot.gif{
813InBlock.gif            if (!String.IsNullOrEmpty(CVCookie.Read(key)))  //Cookie最省服务器资源,Cookie存在的情况下,直接返回-1,不再继续
814ExpandedSubBlockStart.gifContractedSubBlock.gif            dot.gif{
815InBlock.gif                return true;
816ExpandedSubBlockEnd.gif            }

817InBlock.gif
818InBlock.gif            if (userSession)
819ExpandedSubBlockStart.gifContractedSubBlock.gif            dot.gif{
820InBlock.gif                if (HttpContext.Current.Session[key] != null)
821ExpandedSubBlockStart.gifContractedSubBlock.gif                dot.gif{
822InBlock.gif                    if (!String.IsNullOrEmpty(HttpContext.Current.Session[key].ToString()))
823ExpandedSubBlockStart.gifContractedSubBlock.gif                    dot.gif{
824InBlock.gif                        return true;
825ExpandedSubBlockEnd.gif                    }

826ExpandedSubBlockEnd.gif                }

827ExpandedSubBlockEnd.gif            }

828InBlock.gif
829InBlock.gif            //Cookie、Session的默认值
830InBlock.gif            String defaultValue = "1";
831InBlock.gif
832InBlock.gif            CVCookie.Set(key, defaultValue, expireTime * 60);  //expireTime秒内只能操作一次
833InBlock.gif
834InBlock.gif            if (userSession)
835ExpandedSubBlockStart.gifContractedSubBlock.gif            dot.gif{
836InBlock.gif                HttpContext.Current.Session.Timeout = expireTime;
837InBlock.gif                HttpContext.Current.Session[key] = defaultValue;  //用Session可以避免Cookie被删除
838ExpandedSubBlockEnd.gif            }

839InBlock.gif
840InBlock.gif            return false;
841ExpandedSubBlockEnd.gif        }

842InBlock.gif
843ExpandedSubBlockStart.gifContractedSubBlock.gif        /**//// <summary>
844InBlock.gif        /// 检测操作是否已进行,用于限制规定时间内只能进行一次的操作(Cookie、Session并用)
845InBlock.gif        /// </summary>
846InBlock.gif        /// <param name="key">用户监测的Cookie、Session键</param>
847InBlock.gif        /// <param name="expireTime">下次操作的间隔时间(秒)</param>
848ExpandedSubBlockEnd.gif        /// <returns></returns>

849InBlock.gif        public static Boolean OperationDone(String key, Int32 expireTime)
850ExpandedSubBlockStart.gifContractedSubBlock.gif        dot.gif{
851InBlock.gif            return OperationDone(key, expireTime, true);
852ExpandedSubBlockEnd.gif        }

853ExpandedSubBlockEnd.gif    }

854ExpandedBlockEnd.gif}

转载于:https://www.cnblogs.com/guolichun/archive/2008/04/24/1169544.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值