using System;
using System.Data;
using System.Data.SqlClient;
using Microsoft.VisualBasic;
using System.IO;
using System.Web;
using System.Data;
using System.Data.SqlClient;
using Microsoft.VisualBasic;
using System.IO;
using System.Web;
namespace Main.components
{
/// <summary>
/// baseFunc 的摘要说明。
/// </summary>
public class baseFunc
{
public baseFunc()
{
//
// TODO: 在此处添加构造函数逻辑
//
}
#region 字符串截取函数
/// <summary>
/// 字符串截取函数
/// </summary>
/// <param name="str"></param>
/// <param name="num"></param>
/// <returns></returns>
public static string CutString(string str,int num)
{
str=RemoveHTML(str);
if(str.Length>num)
{
str=str.Substring(0,num)+"..";
}
return str;
}
public static string CutStringYes(string str,int num)
{
if(str.Length>num)
{
str=str.Substring(0,num)+"..";
}
return str;
}
public static string CutStringNo(string str,int num)
{
if(str.Length>num)
{
str=str.Substring(0,num);
}
return str;
}
#endregion
{
/// <summary>
/// baseFunc 的摘要说明。
/// </summary>
public class baseFunc
{
public baseFunc()
{
//
// TODO: 在此处添加构造函数逻辑
//
}
#region 字符串截取函数
/// <summary>
/// 字符串截取函数
/// </summary>
/// <param name="str"></param>
/// <param name="num"></param>
/// <returns></returns>
public static string CutString(string str,int num)
{
str=RemoveHTML(str);
if(str.Length>num)
{
str=str.Substring(0,num)+"..";
}
return str;
}
public static string CutStringYes(string str,int num)
{
if(str.Length>num)
{
str=str.Substring(0,num)+"..";
}
return str;
}
public static string CutStringNo(string str,int num)
{
if(str.Length>num)
{
str=str.Substring(0,num);
}
return str;
}
#endregion
public static string RemoveHTML(string strHTML)
{
System.Text.RegularExpressions.Regex Regexp=new System.Text.RegularExpressions.Regex("<.+?>");
string strReturn=Regexp.Replace(strHTML,"");
return strReturn;
}
{
System.Text.RegularExpressions.Regex Regexp=new System.Text.RegularExpressions.Regex("<.+?>");
string strReturn=Regexp.Replace(strHTML,"");
return strReturn;
}
#region 弹出窗口
/// <summary>
/// 弹出窗口
/// </summary>
/// <param name="opener">控件名称</param>
/// <param name="PagePath">弹出页面的路径</param>
public static void OpenPopUp(System.Web.UI.WebControls.WebControl opener,string PagePath)
{
string clientScript;
clientScript = "window.open('" + PagePath + "')";
opener.Attributes.Add("onClick", clientScript);
}
/// <summary>
/// 弹出窗口
/// </summary>
/// <param name="opener">控件名称</param>
/// <param name="PagePath">弹出页面的路径</param>
public static void OpenPopUp(System.Web.UI.WebControls.WebControl opener,string PagePath)
{
string clientScript;
clientScript = "window.open('" + PagePath + "')";
opener.Attributes.Add("onClick", clientScript);
}
/// <param name="opener">控件名称</param>
/// <param name="PagePath">弹出页面的路径</param>
/// <param name="WindowName">窗口名字</param>
/// <param name="width">宽度</param>
/// <param name="height">高度</param>
public static void OpenPopUp(System.Web.UI.WebControls.WebControl opener,string PagePath,string WindowName,int width,int height)
{
string clientScript;
string windowAttribs;
windowAttribs="width=" + width.ToString() + "px,"+"height="+height.ToString()+"px,"+"left='+((screen.width -" + width.ToString() + ") / 4)+',"+"top='+ (screen.height - " + height.ToString() + ") / 4+' scrollbars=yes";
clientScript = "window.open('" + PagePath + "','" + WindowName + "','" + windowAttribs + "');return false;";
opener.Attributes.Add("onClick", clientScript);
}
#endregion
/// <param name="PagePath">弹出页面的路径</param>
/// <param name="WindowName">窗口名字</param>
/// <param name="width">宽度</param>
/// <param name="height">高度</param>
public static void OpenPopUp(System.Web.UI.WebControls.WebControl opener,string PagePath,string WindowName,int width,int height)
{
string clientScript;
string windowAttribs;
windowAttribs="width=" + width.ToString() + "px,"+"height="+height.ToString()+"px,"+"left='+((screen.width -" + width.ToString() + ") / 4)+',"+"top='+ (screen.height - " + height.ToString() + ") / 4+' scrollbars=yes";
clientScript = "window.open('" + PagePath + "','" + WindowName + "','" + windowAttribs + "');return false;";
opener.Attributes.Add("onClick", clientScript);
}
#endregion
#region 将DataReader 转为 DataTable
/// <summary>
/// 将DataReader 转为 DataTable
/// </summary>
/// <param name="DataReader">DataReader</param>
public static DataTable ConvertDataReaderToDataTable(SqlDataReader dataReader)
{
DataTable datatable = new DataTable();
DataTable schemaTable = dataReader.GetSchemaTable(); //描述 dataReader 的列元数据
//动态添加列
try
{
foreach(DataRow myRow in schemaTable.Rows)
{
DataColumn myDataColumn = new DataColumn();
myDataColumn.DataType = myRow.GetType();
myDataColumn.ColumnName = myRow[0].ToString();
datatable.Columns.Add(myDataColumn);
}
//添加数据
while(dataReader.Read())
{
DataRow myDataRow = datatable.NewRow();
for(int i=0;i<schemaTable.Rows.Count;i++)
{
myDataRow[i] = dataReader[i].ToString();
}
datatable.Rows.Add(myDataRow);
myDataRow = null;
}
schemaTable = null;
return datatable;
}
catch(Exception ex)
{
return datatable;
}
}
/// <summary>
/// 将DataReader 转为 DataTable
/// </summary>
/// <param name="DataReader">DataReader</param>
public static DataTable ConvertDataReaderToDataTable(SqlDataReader dataReader)
{
DataTable datatable = new DataTable();
DataTable schemaTable = dataReader.GetSchemaTable(); //描述 dataReader 的列元数据
//动态添加列
try
{
foreach(DataRow myRow in schemaTable.Rows)
{
DataColumn myDataColumn = new DataColumn();
myDataColumn.DataType = myRow.GetType();
myDataColumn.ColumnName = myRow[0].ToString();
datatable.Columns.Add(myDataColumn);
}
//添加数据
while(dataReader.Read())
{
DataRow myDataRow = datatable.NewRow();
for(int i=0;i<schemaTable.Rows.Count;i++)
{
myDataRow[i] = dataReader[i].ToString();
}
datatable.Rows.Add(myDataRow);
myDataRow = null;
}
schemaTable = null;
return datatable;
}
catch(Exception ex)
{
return datatable;
}
}
#endregion
#region 判断网址是h/w开头
public static string ReturnWebadd(string str)
{
string str2;
if(str!=null&&str.ToString()!="")
{
string str1=str.Substring(0,1).ToString();
if(str1=="w"||str1=="W")
{
str2=" http://"+str;
}
else
{
str2=str;
}
}
else
{
str2="";
}
return str2;
}
#endregion
public static string ReturnWebadd(string str)
{
string str2;
if(str!=null&&str.ToString()!="")
{
string str1=str.Substring(0,1).ToString();
if(str1=="w"||str1=="W")
{
str2=" http://"+str;
}
else
{
str2=str;
}
}
else
{
str2="";
}
return str2;
}
#endregion
#region 图片New的显示
/// <summary>
/// 图片New的显示
/// </summary>
/// <param name="str"></param>
/// <param name="num"></param>
/// <returns></returns>
public static string DispNew(DateTime StrDate)
{
string imgStr="";
//DateTime DateStr=new DateTime();
//DateTime DateStr=StrDate;
//DateTime TodayStr=DateTime.Now;
int CtoT=0;
TimeSpan dt = DateTime.Now.Date.Subtract(StrDate);
double subDay = dt.Days;
CtoT=Convert.ToInt32(subDay);
if(CtoT>=0 && CtoT<=7)
{
imgStr="<img src='../images/04.gif' border='0' width='23' height='11'>";
}
return imgStr;
//return "["+StrDate.ToString()+"]"+CtoT.ToString();
}
#endregion
#region 取得当前全部网址
/// <summary>
/// 图片New的显示
/// </summary>
/// <param name="str"></param>
/// <param name="num"></param>
/// <returns></returns>
public static string DispNew(DateTime StrDate)
{
string imgStr="";
//DateTime DateStr=new DateTime();
//DateTime DateStr=StrDate;
//DateTime TodayStr=DateTime.Now;
int CtoT=0;
TimeSpan dt = DateTime.Now.Date.Subtract(StrDate);
double subDay = dt.Days;
CtoT=Convert.ToInt32(subDay);
if(CtoT>=0 && CtoT<=7)
{
imgStr="<img src='../images/04.gif' border='0' width='23' height='11'>";
}
return imgStr;
//return "["+StrDate.ToString()+"]"+CtoT.ToString();
}
#endregion
#region 取得当前全部网址
public static string getURL()
{
string strTemp="";
if(HttpContext.Current.Request.ServerVariables["HTTPS"].ToString().ToLower()=="off")
{
strTemp="http://";
}
else
{
strTemp="https://";
}
strTemp = strTemp+HttpContext.Current.Request.ServerVariables["SERVER_NAME"];
if( Convert.ToInt32(HttpContext.Current.Request.ServerVariables["SERVER_PORT"])!= 80)
strTemp = strTemp+":"+HttpContext.Current.Request.ServerVariables["SERVER_PORT"];
strTemp = strTemp+HttpContext.Current.Request.ServerVariables["URL"];
if (HttpContext.Current.Request.QueryString.ToString().Trim()!= "")
strTemp = strTemp+"?"+HttpContext.Current.Request.QueryString.ToString().Trim();
string GetUrl = strTemp;
return GetUrl;
}
{
string strTemp="";
if(HttpContext.Current.Request.ServerVariables["HTTPS"].ToString().ToLower()=="off")
{
strTemp="http://";
}
else
{
strTemp="https://";
}
strTemp = strTemp+HttpContext.Current.Request.ServerVariables["SERVER_NAME"];
if( Convert.ToInt32(HttpContext.Current.Request.ServerVariables["SERVER_PORT"])!= 80)
strTemp = strTemp+":"+HttpContext.Current.Request.ServerVariables["SERVER_PORT"];
strTemp = strTemp+HttpContext.Current.Request.ServerVariables["URL"];
if (HttpContext.Current.Request.QueryString.ToString().Trim()!= "")
strTemp = strTemp+"?"+HttpContext.Current.Request.QueryString.ToString().Trim();
string GetUrl = strTemp;
return GetUrl;
}
#endregion
}
}
}
}