using System;
using System.Collections.Generic;
using System.Text;
using System.IO;
using System.Web;
using System.Web.UI;
using System.Xml;
using System.Drawing;
using System.Configuration;
using System.Web.UI.WebControls;
using System.Text.RegularExpressions;
using System.Security.Cryptography;
namespace ClassLibrary
{
#region 字串控制類
/// <summary>
/// 字串控制類
/// </summary>
public static class ControlString
{
#region 提示訊息函數
#region 顯示提示訊息
/// <summary>
/// 顯示提示訊息
/// </summary>
/// <param name="str_Message">要顯示得資料</param>
/// <param name="page">頁面類</param>
public static void ShowMessageBox(string str_Message, Page page)
{
Type cstype = page.GetType();
ClientScriptManager cs = page.ClientScript;
cs.RegisterStartupScript(cstype, "", "alert('" + str_Message + "');", true);
}
#endregion
#region 顯示訊息並導向到目標頁面
/// <summary>
/// 顯示訊息並導向到目標頁面
/// </summary>
/// <param name="str_Message">顯示資料</param>
/// <param name="url">目標路徑</param>
/// <param name="page">頁面類</param>
public static void ShowMessageBoxRedirect(string str_Message, string url, Page page)
{
Type cstype = page.GetType();
ClientScriptManager cs = page.ClientScript;
cs.RegisterStartupScript(cstype, "", "alert('" + str_Message + "');window.location.href='" + url + "';", true);
}
#endregion
#region 顯示資訊並關閉本視窗
/// <summary>
/// 顯示資訊並關閉本視窗
/// </summary>
/// <param name="str_Message">顯示資料</param>
/// <param name="page">頁面類</param>
public static void ShowMessageBoxAndCloseWindow(string str_Message, Page page)
{
Type cstype = page.GetType();
ClientScriptManager cs = page.ClientScript;
cs.RegisterStartupScript(cstype, "", "alert('" + str_Message + "');window.close();", true);
}
#endregion
#region 顯示資訊視窗並後退一步
/// <summary>
/// 顯示資訊視窗並後退一步
/// </summary>
/// <param name="str_Message">顯示資料</param>
/// <param name="page">頁面類</param>
public static void ShowMessageBoxGoBack(string str_Message, Page page)
{
Type cstype = page.GetType();
ClientScriptManager cs = page.ClientScript;
cs.RegisterStartupScript(cstype, "", "alert('" + str_Message + "');window.history.go(-1);", true);
}
#endregion
#endregion
#region 擷取長度函數
#region 擷取指定長度字串
/// <summary>
/// 擷取指定長度字串
/// </summary>
/// <param name="Str">未經處理資料</param>
/// <param name="Count">擷取長度</param>
/// <returns>返回資料</returns>
public static string GetLimitStr(string Str, int Count)
{
if (Str.Length > Count)
Str = Str.Substring(0, Count);
return Str;
}
#endregion
#region 擷取前N個字串
/// <summary>
/// 擷取前N個字串
/// </summary>
/// <param name="Str">未經處理資料</param>
/// <param name="N">指定長度</param>
/// <returns>返回資料</returns>
public static string GetNstring(string Str, int N)
{
int intn = N;
if (intn < 1) { intn = 1; }
string tmpstr = Str;
Char[] cc = tmpstr.ToCharArray();
int intLen = tmpstr.Length;
int i;
for (i = 0; i < cc.Length; i++)
{
if (System.Convert.ToInt32(cc[i]) > 255 || (System.Convert.ToInt32(cc[i]) > 64 && System.Convert.ToInt32(cc[i]) < 91))
{
intLen++;
}
}
if (intLen > N)
{
tmpstr = tmpstr.Substring(0, tmpstr.Length - 1);
tmpstr = GetNstring(tmpstr, intn);
}
return tmpstr;
}
#endregion
#endregion
}
#endregion
}