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 System.Web.UI.HtmlControls;
using System.IO;
using System.Collections.Generic;
using System.Text;
using System.Text.RegularExpressions;
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockStart.gif)
/**//// <summary>
///
/// Date: 08.7.16
/// Description: Class that has commonly used static methods
/// </summary>
public static class ToolBox
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockStart.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/ContractedBlock.gif)
{
![](https://www.cnblogs.com/Images/OutliningIndicators/ContractedSubBlock.gif)
"FindGridViewColumnIndex"#region "FindGridViewColumnIndex"
public static int FindGridViewColumnIndex(GridView pGridView, string pAccessibleHeaderText)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
for (int index = 0; index < pGridView.Columns.Count; index++)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
if (String.Compare(pGridView.Columns[index].AccessibleHeaderText, pAccessibleHeaderText, true) == 0)
return index;
}
return -1;
}
#endregion
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/ContractedSubBlock.gif)
"ConvertTrueAndFalseToYesAndNo"#region "ConvertTrueAndFalseToYesAndNo"
public static string ConvertTrueAndFalseToYesAndNo(bool pTrueAndFalse)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
if (pTrueAndFalse)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
return "Yes";
}
else
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
return "No";
}
}
#endregion
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/ContractedSubBlock.gif)
"GetMoneyFormatting"#region "GetMoneyFormatting"
public static string GetMoneyFormatting(object pMoney)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
return string.Format("{0:C}", pMoney);
}
#endregion
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/ContractedSubBlock.gif)
"GetDateFormatting"#region "GetDateFormatting"
public static string GetDateFormatting(object pDate)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
return string.Format("{0:d}", pDate);
}
#endregion
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/ContractedSubBlock.gif)
"ReloadCurrentPage"#region "ReloadCurrentPage"
public static void ReloadCurrentPage()
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
HttpContext.Current.Response.Redirect(HttpContext.Current.Request.Url.ToString());
}
#endregion
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/ContractedSubBlock.gif)
"FindGridViewButtonControl"#region "FindGridViewButtonControl"
private static IButtonControl FindGridViewButtonControl(GridViewRowEventArgs pGridViewRowEventArgs, ControlCollection pControlCollection, string pCommandName)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
foreach (Control c in pControlCollection)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
if (c is IButtonControl)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
if ((c as IButtonControl).CommandName == pCommandName)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
return c as IButtonControl;
}
else
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
if (c.HasControls())
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
IButtonControl ibc = FindGridViewButtonControl(pGridViewRowEventArgs, c.Controls, pCommandName);
if (ibc != null)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
return ibc;
}
}
}
}
else
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
if (c.HasControls())
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
IButtonControl ibc = FindGridViewButtonControl(pGridViewRowEventArgs, c.Controls, pCommandName);
if (ibc != null)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
return ibc;
}
}
}
}
return null;
}
#endregion
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/ContractedSubBlock.gif)
"FindGridViewButtonControl"#region "FindGridViewButtonControl"
public static IButtonControl FindGridViewButtonControl(GridViewRowEventArgs pGridViewRowEventArgs, GridViewButtonControlType pGridViewButtonControlType)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
return FindGridViewButtonControl(pGridViewRowEventArgs, pGridViewRowEventArgs.Row.Controls, pGridViewButtonControlType.ToString());
}
#endregion
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/ContractedSubBlock.gif)
"Properties"#region "Properties"
public enum GridViewButtonControlType
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
Edit,
Delete
}
#endregion
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/ContractedSubBlock.gif)
"ReloadTemplateCaches"#region "ReloadTemplateCaches"
public static void ReloadTemplateCaches()
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
DirectoryInfo di = new DirectoryInfo(HttpContext.Current.Server.MapPath("~") + "\\" + ConfigurationManager.AppSettings["TemplateFolder"]);
IEnumerable<FileInfo> fis = GetFilesRecursively(di);
if (fis != null)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
foreach (FileInfo fi in fis)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
string t = ReadFileText(fi.FullName);
if (t != null)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
HttpContext.Current.Cache.Remove(fi.Name);
HttpContext.Current.Cache.Insert(fi.Name, t);
}
}
}
}
#endregion
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/ContractedSubBlock.gif)
"ReloadTemplateCache"#region "ReloadTemplateCache"
public static void ReloadTemplateCache(string pFileName)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
FileInfo fi = new FileInfo(HttpContext.Current.Server.MapPath("~") + "\\" + ConfigurationManager.AppSettings["TemplateFolder"] + "\\" + pFileName);
string t = ReadFileText(fi.FullName);
if (t != null)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
HttpContext.Current.Cache.Remove(fi.Name);
HttpContext.Current.Cache.Insert(fi.Name, t);
}
}
#endregion
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/ContractedSubBlock.gif)
"GetTemplateCache"#region "GetTemplateCache"
public static string GetTemplateCache(string pFileName)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
try
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
return Convert.ToString(HttpContext.Current.Cache[pFileName]);
}
catch
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
return null;
}
}
#endregion
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/ContractedSubBlock.gif)
"TemplateCacheDoesExist"#region "TemplateCacheDoesExist"
public static bool TemplateCacheDoesExist(string pFileName)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
if (HttpContext.Current.Cache[pFileName] == null)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
return false;
}
else
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
return true;
}
}
#endregion
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/ContractedSubBlock.gif)
"ReplaceTemplateContent"#region "ReplaceTemplateContent"
public static string ReplaceTemplateContent(string pTagName, string pReplaceWith, string pTarget)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
return RelaceMatch("<" + ConfigurationManager.AppSettings["TemplateSeparator"] + ">" + pTagName + "</" + ConfigurationManager.AppSettings["TemplateSeparator"] + ">", pReplaceWith, pTarget);
}
#endregion
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/ContractedSubBlock.gif)
"ReplaceMatches"#region "ReplaceMatches"
public static List<string> ReplaceMatches(string pFindPattern, string pReplacePattern, string pTarget)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
List<string> l = new List<string>();
Regex r = new Regex(pFindPattern);
MatchCollection mc = r.Matches(pTarget);
foreach (Match m in mc)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
l.Add(Regex.Replace(m.Value, pFindPattern, pReplacePattern));
}
return l;
}
#endregion
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/ContractedSubBlock.gif)
"RelaceMatch"#region "RelaceMatch"
public static string RelaceMatch(string pFindPattern, string pReplacePattern, string pTarget)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
return Regex.Replace(pTarget, pFindPattern, pReplacePattern);
}
#endregion
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/ContractedSubBlock.gif)
"FindMatches"#region "FindMatches"
public static List<string> FindMatches(string pFindPattern, string pTarget)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
List<string> l = new List<string>();
Regex r = new Regex(pFindPattern);
MatchCollection mc = r.Matches(pTarget);
foreach (Match m in mc)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
l.Add(m.Value);
}
return l;
}
#endregion
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/ContractedSubBlock.gif)
"FindMatch"#region "FindMatch"
public static string FindMatch(string pFindPattern, string pTarget)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
Regex r = new Regex(pFindPattern);
Match m = r.Match(pTarget);
return m.Value;
}
#endregion
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/ContractedSubBlock.gif)
"ReadFileText"#region "ReadFileText"
public static string ReadFileText(string pPath)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
try
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
return File.ReadAllText(pPath);
}
catch
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
return null;
}
}
#endregion
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/ContractedSubBlock.gif)
"GetFilesRecursively"#region "GetFilesRecursively"
public static IEnumerable<FileInfo> GetFilesRecursively(DirectoryInfo pDirectoryInfo)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
return GetFilesRecursively(pDirectoryInfo, "*.*");
}
#endregion
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/ContractedSubBlock.gif)
"GetFilesRecursively"#region "GetFilesRecursively"
public static IEnumerable<FileInfo> GetFilesRecursively(DirectoryInfo pDirectoryInfo, string pSearchPattern)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
try
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
return TryGetFilesRecursively(pDirectoryInfo, pSearchPattern);
}
catch
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
return null;
}
}
#endregion
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/ContractedSubBlock.gif)
"TryGetFilesRecursively"#region "TryGetFilesRecursively"
private static IEnumerable<FileInfo> TryGetFilesRecursively(DirectoryInfo pDirectoryInfo, string pSearchPattern)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
foreach (DirectoryInfo di in pDirectoryInfo.GetDirectories())
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
foreach (FileInfo fi in GetFilesRecursively(di, pSearchPattern))
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
yield return fi;
}
}
foreach (FileInfo fi in pDirectoryInfo.GetFiles(pSearchPattern))
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
yield return fi;
}
}
#endregion
}
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
posted @
2008-07-26 02:52
N/A2011
阅读(
301)
评论()
编辑
收藏
举报