📄 webfunction.cs
字号:
/// <summary>
/// 执行指定Sql语句
/// </summary>
/// <param name="sqlstr">传入的Sql语句</param>
public static DataView dataView(string sqlstr)
{
OleDbDataAdapter da = new OleDbDataAdapter();
DataView dv = new DataView();
DataSet ds = new DataSet();
try
{
openConnection();
comm.CommandType = CommandType.Text;
comm.CommandText = sqlstr;
da.SelectCommand = comm;
da.Fill(ds);
dv = ds.Tables[0].DefaultView;
}
catch (Exception e)
{
throw new Exception(e.Message);
}
finally
{
closeConnection();
}
return dv;
}
/// <summary>
/// 执行指定Sql语句,开始记录位置,和返回记录数
/// </summary>
/// <param name="sqlstr">传入的Sql语句</param>
/// <param name="StartIndex">开始记录位置</param>
/// <param name="pageSize">返回记录数</param>
public static DataView dataView(string sqlstr, int StartIndex, int pageSize)
{
OleDbDataAdapter da = new OleDbDataAdapter();
DataView dv = new DataView();
DataSet ds = new DataSet();
try
{
openConnection();
comm.CommandType = CommandType.Text;
comm.CommandText = sqlstr;
da.SelectCommand = comm;
da.Fill(ds, StartIndex, pageSize, "pagelist");
dv = ds.Tables["pagelist"].DefaultView;
}
catch (Exception e)
{
throw new Exception(e.Message);
}
finally
{
closeConnection();
}
return dv;
}
public static string cutTitle(string str, int len)
{
int intLen = str.Length;
int start = 0;
int end = intLen;
int single = 0;
char[] chars = str.ToCharArray();
for (int i = 0; i < chars.Length; i++)
{
if (Convert.ToInt32(chars[i]) > 255)
{
start += 2;
}
else
{
start += 1;
single++;
}
if (start >= len)
{
if (end % 2 == 0)
{
if (single % 2 == 0)
{
end = i + 1;
}
else
{
end = i;
}
}
else
{
end = i + 1;
}
break;
}
}
string temp = str.Substring(0, end);
if (str.Length > end)
{
return temp + "...";
}
else
{
return temp;
}
}
/// <summary>
/// 验证是否正确
/// </summary>
/// <param name="userName">传入sql语句</param>
/// <returns>布尔值</returns>
public static bool chkExist(string sqlstr)
{
int isExit = 0;
try
{
openConnection();
comm.CommandType = CommandType.Text;
comm.CommandText = sqlstr;
isExit = Convert.ToInt32(comm.ExecuteScalar());
}
catch (Exception e)
{
throw new Exception(e.Message);
}
finally
{
closeConnection();
}
if (isExit > 0)
{
return true;
}
else
{
return false;
}
}
public static string safeForm(string str)
{
str = str.Trim();
str = str.Replace("'", "''");
return str;
}
public static string alertChk(string str, int how)
{
switch (how)
{
case 1:
return "<script>alert('" + str + "');window.location.href='Default.aspx'</script>";
case 2:
return "<script>alert('" + str + "');window.close()</script>";
default:
return "<script>alert('" + str + "');history.go(-1)</script>";
}
}
/// <summary>
/// 替换html中的特殊字符
/// </summary>
/// <param name="theString">需要进行替换的文本。</param>
/// <returns>替换完的文本。</returns>
public static string HtmlEncode(string theString)
{
theString = theString.Replace(">", ">");
theString = theString.Replace("<", "<");
theString = theString.Replace(" ", " ");
theString = theString.Replace(" ", " ");
theString = theString.Replace("\"", """);
theString = theString.Replace("\'", "'");
theString = theString.Replace("\n", "<br/> ");
return theString;
}
/// <summary>
/// 恢复html中的特殊字符
/// </summary>
/// <param name="theString">需要恢复的文本。</param>
/// <returns>恢复好的文本。</returns>
public static string HtmlDiscode(string theString)
{
theString = theString.Replace(">", ">");
theString = theString.Replace("<", "<");
theString = theString.Replace(" ", " ");
theString = theString.Replace(" ", " ");
theString = theString.Replace(""", "\"");
theString = theString.Replace("'", "\'");
theString = theString.Replace("<br/> ", "\n");
return theString;
}
public static string DealHtml(string str)
{
str = Regex.Replace(str, @"\<(img)[^>]*>|<\/(img)>", "", RegexOptions.IgnoreCase);
str = Regex.Replace(str, @"\<(table|tbody|tr|td|th|)[^>]*>|<\/(table|tbody|tr|td|th|)>", "", RegexOptions.IgnoreCase);
str = Regex.Replace(str, @"\<(div|blockquote|fieldset|legend)[^>]*>|<\/(div|blockquote|fieldset|legend)>", "", RegexOptions.IgnoreCase);
str = Regex.Replace(str, @"\<(font|i|u|h[1-9]|s)[^>]*>|<\/(font|i|u|h[1-9]|s)>", "", RegexOptions.IgnoreCase);
str = Regex.Replace(str, @"\<(style|strong)[^>]*>|<\/(style|strong)>", "", RegexOptions.IgnoreCase);
str = Regex.Replace(str, @"\<a[^>]*>|<\/a>", "", RegexOptions.IgnoreCase);
str = Regex.Replace(str, @"\<(meta|iframe|frame|span|tbody|layer)[^>]*>|<\/(iframe|frame|meta|span|tbody|layer)>", "", RegexOptions.IgnoreCase);
str = Regex.Replace(str, @"\<a[^>]*", "", RegexOptions.IgnoreCase);
return str;
}
public static string PageList(int size, string funClick, int countNum, int currentPage)
{
int pageCount = 0;
int stepNum = 3;
int pageRoot = 1;
string pageStr = "";
int pageSize = size;
if (countNum % pageSize == 0)
{
pageCount = countNum / pageSize;
}
else
{
pageCount = countNum / pageSize + 1;
}
pageStr = "<div id='pager'>分页:" + currentPage.ToString() + "/" + pageCount.ToString() + "页";
if (currentPage - stepNum > 1)
{
pageRoot = currentPage - stepNum;
}
int pageFoot = pageCount;
if (currentPage + stepNum < pageCount)
{
pageFoot = currentPage + stepNum;
}
if (pageRoot == 1)
{
if (currentPage == 1)
{
pageStr += "<font color=888888 face=webdings>9</font></a>";
pageStr += "<font color=888888 face=webdings>7</font></a> ";
}
else
{
pageStr += "<a href='#page.1' onclick='" + funClick + "(1)' title='首页'><font face=webdings>9</font></a>";
pageStr += "<a href='#page." + Convert.ToString(currentPage - 1) + "' onclick='" + funClick + "(" + Convert.ToString(currentPage - 1) + ")' title='上页'><font face=webdings>7</font></a> ";
}
}
else
{
pageStr += "<a href='#page.1' onclick='" + funClick + "(1)' title='首页'><font face=webdings>9</font></a>";
pageStr += "<a href='#page." + Convert.ToString(currentPage - 1) + "' onclick='" + funClick + "(" + Convert.ToString(currentPage - 1) + ")' title='上页'><font face=webdings>7</font></a>...";
}
for (int i = pageRoot; i <= pageFoot; i++)
{
if (i == currentPage)
{
pageStr += "<font color='red'>[" + i.ToString() + "]</font> ";
}
else
{
pageStr += "<a href='#page." + i.ToString() + "' onclick='" + funClick + "(" + i.ToString() + ")'>[" + i.ToString() + "]</a> ";
}
if (i == pageCount)
break;
}
if (pageFoot == pageCount)
{
if (pageCount == currentPage)
{
pageStr += "<font color=888888 face=webdings>8</font></a>";
pageStr += "<font color=888888 face=webdings>:</font></a>";
}
else
{
pageStr += "<a href='#page." + Convert.ToString(currentPage + 1) + "' onclick='" + funClick + "(" + Convert.ToString(currentPage + 1) + ")' title='下页'><font face=webdings>8</font></a>";
pageStr += "<a href='#page." + pageCount.ToString() + "' onclick='" + funClick + "(" + pageCount.ToString() + ")' title='尾页'><font face=webdings>:</font></a>";
}
}
else
{
pageStr += "... <a href='#page." + Convert.ToString(currentPage + 1) + "' onclick='" + funClick + "(" + Convert.ToString(currentPage + 1) + ")' title='下页'><font face=webdings>8</font></a>";
pageStr += "<a href='#page." + pageCount.ToString() + "' onclick='" + funClick + "(" + pageCount.ToString() + ")' title='尾页'><font face=webdings>:</font></a>";
}
pageStr += "</div>";
return pageStr;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -