公共类
using System;
using System.Data;
using System.Data.SqlClient;
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.Drawing;
using System.Drawing.Imaging;
using System.Web.Caching;
using System.IO;
using System.Collections;
using System.Text.RegularExpressions;
namespace MyITJob
{
public class Class1 : Code.DbHelper
{
SqlConnection conn;
SqlCommand comm = new SqlCommand();
StreamReader sr;
StreamWriter sw;
#region 打开数据库
/// <summary>
/// 打开数据库
/// </summary>
public void OpenConnection() {
CheckConnection();
}
public bool CheckConnection() {
if (conn.State == ConnectionState.Closed) {
try {
conn.ConnectionString = ConfigurationManager.ConnectionStrings["0745Job"].ConnectionString;
comm.Connection = conn;
conn.Open();
} catch {
return false;
}
}
return true;
}
#endregion
#region 关闭数据库
/// <summary>
/// 关闭当前数据库
/// </summary>
public void MyCloseConn() {
if (conn.State == ConnectionState.Open) {
conn.Close();
conn.Dispose();
comm.Dispose();
}
}
#endregion
#region 返回指定的sql语句的DataSet记录集(多用于绑定数据)
/// <summary>
/// 返回指定的sql语句的DataSet记录集(多用于绑定数据)
/// </summary>
/// <param name="sql"></param>
/// <returns></returns>
public DataSet MyDataSet(string sql, string tablename) {
DataSet ds = new DataSet();
string sqlstr = ConfigurationManager.ConnectionStrings["0745Job"].ToString();
conn = new SqlConnection(sqlstr);
SqlDataAdapter da = new SqlDataAdapter(sql, conn);
da.Fill(ds, tablename);
da.Dispose();
conn.Close();
conn.Dispose();
return ds;
}
#endregion
#region 返回指定的sql语句的DataSet记录集,是否开启缓存(多用于绑定数据)
/// <summary>
/// 返回指定的sql语句的DataSet记录集,是否开启缓存(多用于绑定数据)
/// </summary>
/// <param name="sql">SQL语句</param>
/// <param name="tablename">缓存表名,若开启缓存,则表名在程序结构中不得重复出现</param>
/// <param name="Sure">若开启缓存,则表名在程序结构中不得重复出现</param>
/// <returns></returns>
public DataSet MyDataSet(string sql, string tablename, bool Sure) {
DataSet CacheDataSet = new DataSet();
DataSet ds = new DataSet();
if (Sure) {
CacheDataSet = (DataSet)Cache[tablename];
if (CacheDataSet == null) {
string sqlstr = ConfigurationManager.ConnectionStrings["0745Job"].ToString();
conn = new SqlConnection(sqlstr);
SqlDataAdapter da = new SqlDataAdapter(sql, conn);
da.Fill(ds, tablename);
da.Dispose();
conn.Close();
conn.Dispose();
// 将结果集存到缓存中去。
CacheDataSet = ds;
Cache.Insert(tablename, ds, null, DateTime.Now.AddMinutes(1), Cache.NoSlidingExpiration);
} else {
ds = (DataSet)Cache[tablename];
}
} else {
return MyDataSet(sql, tablename);
}
return CacheDataSet;
}
#endregion
#region 删除所有缓存资源
/// <summary>
/// 删除所有缓存资源
/// </summary>
public static void RemoveAllCache() {
Cache _cache = HttpRuntime.Cache;
IDictionaryEnumerator CacheEnum = _cache.GetEnumerator();
ArrayList _aList = new ArrayList();
while (CacheEnum.MoveNext()) {
_aList.Add(CacheEnum.Key);
}
foreach (string tempcache in _aList) {
_cache.Remove(tempcache);
}
}
#endregion
#region 执行SQL语句从而影响数据表内容(多用于添加、修改、删除语句)
/// <summary>
/// 执行SQL语句从而影响数据表内容(多用于添加、修改、删除语句)
/// </summary>
/// <param name="sql"></param>
public void MysqlExecute(string sql) {
try {
string sqlstr = ConfigurationManager.ConnectionStrings["0745Job"].ToString();
conn = new SqlConnection(sqlstr);
conn.Open();
comm = new SqlCommand(sql, conn);
comm.ExecuteNonQuery();
} catch (Exception e) {
throw new Exception(e.Message);
} finally {
MyCloseConn();
}
}
#endregion
#region 返回DataReader(多用于查询语句)
/// <summary>
/// 返回DataReader(多用于查询语句)
/// </summary>
/// <param name="sql"></param>
/// <returns></returns>
public SqlDataReader MyDataReader(string sql) {
try {
string sqlstr = ConfigurationManager.ConnectionStrings["0745Job"].ToString();
conn = new SqlConnection(sqlstr);
conn.Open();
SqlCommand comm = new SqlCommand(sql, conn);
SqlDataReader dr = comm.ExecuteReader(CommandBehavior.CloseConnection);
return dr;
} catch (Exception e) {
throw new Exception(e.Message);
}
}
#endregion
#region 加密Cookie
public string FormatCookie(string name) {
string ip = HttpContext.Current.Request.ServerVariables["REMOTE_ADDR"];
string agent = HttpContext.Current.Request.UserAgent;
string key = HttpContext.Current.Application["sitekey"].ToString();
string c_key = FormsAuthentication.HashPasswordForStoringInConfigFile(ip + agent + key + name, "MD5");
return c_key;
}
#endregion
#region 院校机构登陆,存入Cookie
public void SlCookie(string name) {
HttpCookie slCookie = new HttpCookie("slname");
slCookie["name"] = MyFormatstr(Server.UrlEncode(name));
slCookie["key"] = FormatCookie(name);
slCookie.Expires = DateTime.Now.AddMinutes(30);
Response.Cookies.Add(slCookie);
}
#endregion
#region 个人用户登录,存入Cookie
public void UserCookie(string name) {
HttpCookie userCookie = new HttpCookie("User");
if (HttpContext.Current.Request.Cookies["User"] != null) {
userCookie.Expires = DateTime.Now.AddDays(-1);
HttpContext.Current.Response.Cookies.Add(userCookie);
}
userCookie["name"] = MyFormatstr(Server.UrlEncode(name));
userCookie["key"] = FormatCookie(name);
userCookie.Expires = DateTime.Now.AddMinutes(30);
HttpContext.Current.Response.Cookies.Add(userCookie);
}
#endregion
#region 企业用户登录,存入Cookie
public void qyCookie(string name) {
HttpCookie qyCookie = new HttpCookie("qyUser");
if (HttpContext.Current.Request.Cookies["qyUser"] != null) {
qyCookie.Expires = DateTime.Now.AddHours(-1);
HttpContext.Current.Response.Cookies.Add(qyCookie);
}
qyCookie["name"] = MyFormatstr(Server.UrlEncode(name));
qyCookie["key"] = FormatCookie(name);
qyCookie.Expires = DateTime.Now.AddMinutes(30);
HttpContext.Current.Response.Cookies.Add(qyCookie);
}
#endregion
#region 管理员用户登录,存入Cookie
public void AdminCookie(string name) {
HttpCookie AdminCookie = new HttpCookie("AdminUser");
AdminCookie["name"] = MyFormatstr(name);
AdminCookie["key"] = FormatCookie(name);
AdminCookie.Expires = DateTime.Now.AddMinutes(30);
Response.Cookies.Add(AdminCookie);
}
#endregion
#region 判断院校机构是否登录
/// <summary>
/// 判断院校机构是否登录
/// </summary>
public void MySlLogin() {
if(Request.Cookies["slname"] == null || (Request.Cookies["slname"].Values["key"] != FormatCookie(Server.UrlDecode(Request.Cookies["slname"].Values["name"])))) {
Response.Redirect("Default.aspx");
}
}
#endregion
#region 判断个人用户是否登录
/// <summary>
/// 判断个人用户是否登录
/// </summary>
public void MyUserLogin() {
if (Request.Cookies["User"] == null || (Request.Cookies["User"].Values["key"] != FormatCookie(Server.UrlDecode(Request.Cookies["User"].Values["name"])))) {
Response.Redirect("../Default.aspx", true);
}
}
#endregion
#region 判断企业用户是否登录
/// <summary>
/// 判断企业用户是否登录
/// </summary>
public void MyqyLogin() {
if (Request.Cookies["qyUser"] == null || (Request.Cookies["qyUser"].Values["key"] != FormatCookie(Server.UrlDecode(Request.Cookies["qyUser"].Values["name"])))) {
//Response.Write("<script>alert('登录超时,请重新登录!');window.location='../Default.aspx'</script>");
Response.Redirect("../Default.aspx", true);
}
}
#endregion
#region 判断管理员是否登录
/// <summary>
/// 判断管理员是否登录
/// </summary>
public void AdminLogin() {
if (Request.Cookies["AdminUser"] == null || (Request.Cookies["AdminUser"].Values["key"] != FormatCookie(Request.Cookies["AdminUser"].Values["name"]))) {
Response.Redirect("Admin_Login.aspx");
}
}
#endregion
#region 获取HTML的参数
/// <summary>
/// 获取HTML的参数
/// </summary>
/// <param name="s"></param>
/// <returns></returns>
public string q(string s) {
if (Request.QueryString[s] != null) {
return MyFormatstr(Request.QueryString[s].ToString());
}
return string.Empty;
}
#endregion
#region 定义文章标题字段长度
/// <summary>
/// 定义文章标题字段长度
/// </summary>
/// <param name="str">需要定义的文字内容</param>
/// <param name="maxstr">最大显示长度</param>
/// <param name="laststr">实际显示长度</param>
/// <returns>返回字符串 + "..."</returns>
public string FormatLeft(string str, int maxstr, int laststr) {
if (str.Length > maxstr) {
return str.Substring(0, laststr) + "...";
} else {
return str;
}
}
#endregion
#region 定义文章标题字段长度2
/// <summary>
/// 定义文章标题字段长度,无...符号
/// </summary>
/// <param name="str">需要定义的文字内容</param>
/// <param name="maxstr">最大显示长度</param>
/// <param name="laststr">实际显示长度</param>
/// <returns>返回字符串 + "..."</returns>
public string FormatLeft2(string str, int maxstr, int laststr) {
if (str.Length > maxstr) {
return str.Substring(0, laststr);
} else {
return str;
}
}
#endregion
#region 格式化文本(防止SQL注入)
/// <summary>
/// 格式化文本(防止SQL注入)
/// </summary>
/// <param name="str"></param>
/// <returns></returns>
public string MyFormatstr(string html) {
System.Text.RegularExpressions.Regex regex1 = new System.Text.RegularExpressions.Regex(@"<script[\s\S]+</script *>", System.Text.RegularExpressions.RegexOptions.IgnoreCase);
System.Text.RegularExpressions.Regex regex2 = new System.Text.RegularExpressions.Regex(@" href *= *[\s\S]*script *:", System.Text.RegularExpressions.RegexOptions.IgnoreCase);
System.Text.RegularExpressions.Regex regex3 = new System.Text.RegularExpressions.Regex(@" on[\s\S]*=", System.Text.RegularExpressions.RegexOptions.IgnoreCase);
System.Text.RegularExpressions.Regex regex4 = new System.Text.RegularExpressions.Regex(@"<iframe[\s\S]+</iframe *>", System.Text.RegularExpressions.RegexOptions.IgnoreCase);
System.Text.RegularExpressions.Regex regex5 = new System.Text.RegularExpressions.Regex(@"<frameset[\s\S]+</frameset *>", System.Text.RegularExpressions.RegexOptions.IgnoreCase);
//System.Text.RegularExpressions.Regex regex6 = new System.Text.RegularExpressions.Regex(@"\<img[^\>]+\>", System.Text.RegularExpressions.RegexOptions.IgnoreCase);
//System.Text.RegularExpressions.Regex regex7 = new System.Text.RegularExpressions.Regex(@"</p>", System.Text.RegularExpressions.RegexOptions.IgnoreCase);
//System.Text.RegularExpressions.Regex regex8 = new System.Text.RegularExpressions.Regex(@"<p>", System.Text.RegularExpressions.RegexOptions.IgnoreCase);
//System.Text.RegularExpressions.Regex regex9 = new System.Text.RegularExpressions.Regex(@"<[^>]*>", System.Text.RegularExpressions.RegexOptions.IgnoreCase);
System.Text.RegularExpressions.Regex regex10 = new System.Text.RegularExpressions.Regex(@"select", System.Text.RegularExpressions.RegexOptions.IgnoreCase);
System.Text.RegularExpressions.Regex regex11 = new System.Text.RegularExpressions.Regex(@"update", System.Text.RegularExpressions.RegexOptions.IgnoreCase);
System.Text.RegularExpressions.Regex regex12 = new System.Text.RegularExpressions.Regex(@"delete", System.Text.RegularExpressions.RegexOptions.IgnoreCase);
html = regex1.Replace(html, ""); //过滤<script></script>标记
html = regex2.Replace(html, ""); //过滤href=javascript: (<A>) 属性
html = regex3.Replace(html, " _disibledevent="); //过滤其它控件的on...事件
html = regex4.Replace(html, ""); //过滤iframe
html = regex5.Replace(html, ""); //过滤frameset
//html = regex6.Replace(html, ""); //过滤frameset
//html = regex7.Replace(html, ""); //过滤frameset
//html = regex8.Replace(html, ""); //过滤frameset
//html = regex9.Replace(html, "");
html = regex10.Replace(html, "s_elect");
html = regex11.Replace(html, "u_pudate");
html = regex12.Replace(html, "d_elete");
html = html.Replace("'", "’");
html = html.Replace(" ", " ");
//html = html.Replace("</strong>", "");
//html = html.Replace("<strong>", "");
return html;
}
#endregion
#region 格式化文本(输出内容)
/// <summary>
/// 格式化文本(输出内容)
/// </summary>
/// <param name="str"></param>
/// <returns></returns>
public string MyFormatDestr(string str) {
str = str.Replace(" ", " ");
str = str.Replace("\"", """);
str = str.Replace("\'", "'");
str = str.Replace("\n", "<br/> ");
str = str.Replace("\r\n", "<br/> ");
return str;
}
#endregion
#region 输出文本时不带html标签格式
public string MyFormatnoHtml(string str) {
//str = str.Replace("<p>", "");
Regex regex1 = new Regex(@"<p>",RegexOptions.IgnoreCase);
Regex regex2 = new Regex(@"</p>", RegexOptions.IgnoreCase);
Regex regex3 = new Regex(@"<br />", RegexOptions.IgnoreCase);
str = regex1.Replace(str, "");
str = regex2.Replace(str, "");
str = regex3.Replace(str, "");
return str;
}
#endregion
#region ListBox树形结构函数
public string Tab = "├";
public void MyListTree(int pid, string tbname, System.Web.UI.WebControls.ListBox mListBox) {
DataSet ds = new DataSet();
string sqlstr = ConfigurationManager.ConnectionStrings["0745Job"].ToString();
conn = new SqlConnection(sqlstr);
SqlDataAdapter da = new SqlDataAdapter("select * from " + tbname + " where Pid=" + pid + " order by OrderID desc, id asc", conn);
da.Fill(ds, "DDLtb");
for (int i = 0; i < ds.Tables["DDLtb"].Rows.Count; i++) {
mListBox.Items.Add(new ListItem(Tab + ds.Tables["DDLtb"].Rows[i][2].ToString(), ds.Tables["DDLtb"].Rows[i][0].ToString()));
Tab += "─┴";
MyListTree(int.Parse(ds.Tables["DDLtb"].Rows[i][0].ToString()), tbname, mListBox);
Tab = Tab.Substring(0, Tab.Length - 2);
}
}
#endregion
#region DropDownList树形结构函数
public string Tab1 = "";
public void MyListDDLTree(int pid, string tbname, System.Web.UI.WebControls.DropDownList mDDL) {
DataSet ds = new DataSet();
string sqlstr = ConfigurationManager.ConnectionStrings["0745Job"].ToString();
conn = new SqlConnection(sqlstr);
SqlDataAdapter da = new SqlDataAdapter("select * from " + tbname + " where Pid=" + pid, conn);
da.Fill(ds, "DDLtb1");
for (int i = 0; i < ds.Tables["DDLtb1"].Rows.Count; i++) {
mDDL.Items.Add(new ListItem(Tab1 + ds.Tables["DDLtb1"].Rows[i][2].ToString(), ds.Tables["DDLtb1"].Rows[i][0].ToString()));
Tab1 += Server.HtmlDecode(" ");
MyListDDLTree(int.Parse(ds.Tables["DDLtb1"].Rows[i][0].ToString()), tbname, mDDL);
Tab1 = Tab1.Substring(0, Tab1.Length - 8);
}
}
#endregion
#region TreeView树形结构
public void BindFreeViewhs(string sqlstr, System.Web.UI.WebControls.TreeView mTreeView) {
string Connstr = ConfigurationManager.ConnectionStrings["0745Job"].ToString();
conn = new SqlConnection(Connstr);
SqlDataAdapter da = new SqlDataAdapter(sqlstr, conn);
DataSet ds = new DataSet();
da.Fill(ds);
this.ViewState["ds"] = ds;
AddTree(0, (TreeNode)null, mTreeView);
}
//递归添加树的节点
public void AddTree(int pid, TreeNode pnode, System.Web.UI.WebControls.TreeView mTreeView) {
DataSet ds = (DataSet)this.ViewState["ds"];
DataView dvtree = new DataView(ds.Tables[0]);
//过滤pid,得到当前的所有子节点
dvtree.RowFilter = "[pid] = " + pid;
foreach (DataRowView row in dvtree) {
TreeNode node = new TreeNode();
if (pnode == null) { //添加根节点
node.Text = row["Article_Class_Name"].ToString();
mTreeView.Nodes.Add(node);
// 默认不展开节点
node.Expanded = false;
AddTree(Int32.Parse(row["id"].ToString()), node, mTreeView); //再次递归
} else { //添加当前节点的子节点
node.Text = row["Article_Class_Name"].ToString();
pnode.ChildNodes.Add(node);
// 默认不展开节点
node.Expanded = false;
AddTree(Int32.Parse(row["id"].ToString()), node, mTreeView); //再次递归
}
node.NavigateUrl = "/newsallid.aspx?pid=" + row["id"].ToString();
}
}
#endregion
#region 写入JS头设置文件
public void WriteJs(string JsUrl, string sAdZone) {
//用来读取ZoneSetting的值
string[] Arraydr;
//读取JS模板文件
string tempmappath = Server.MapPath(JsUrl);
if (File.Exists(tempmappath)) {
sr = new StreamReader(tempmappath);
string ssr = sr.ReadToEnd();
sr.Close();
//创建文件夹
//Directory.CreateDirectory(Server.MapPath("../AD/" + DateTime.Now.ToString("yyyyMM")));
//创建文件,根据ID(sAdZone)值读取ZoneType的值,并写入读取的JS模板
DataRow dr = MyDataSet("select * from [AdZone] where [id]='" + sAdZone + "'", "ZoneJsName").Tables[0].Rows[0];
sw = new StreamWriter(Server.MapPath("../AD/" + dr["ZoneJsName"].ToString()), false, System.Text.Encoding.GetEncoding("UTF-8"));
sw.WriteLine(ssr);
switch (Convert.ToInt32(dr["ZoneType"])) {
case 1:
sw.WriteLine("var ZoneAD_" + dr["id"].ToString() + " = new BannerZoneAD(" + "\"ZoneAD_" + dr["id"].ToString() + "\"" + ");");
sw.WriteLine("ZoneAD_" + dr["id"].ToString() + ".ZoneID = " + dr["id"] + ";");
sw.WriteLine("ZoneAD_" + dr["id"].ToString() + ".ZoneWidth = " + dr["ZoneWidth"] + ";");
sw.WriteLine("ZoneAD_" + dr["id"].ToString() + ".ZoneHeight = " + dr["ZoneHeight"] + ";");
sw.WriteLine("ZoneAD_" + dr["id"].ToString() + ".ShowType = " + dr["ShowType"] + ";");
sw.WriteLine("");
ForWriteJS(dr["id"].ToString());
break;
case 2:
sw.WriteLine("var ZoneAD_" + dr["id"] + " = new PopZoneAD(" + "\"ZoneAD_" + dr["id"] + "\"" + ");");
sw.WriteLine("ZoneAD_" + dr["id"] + ".ZoneID = " + dr["id"] + ";");
sw.WriteLine("ZoneAD_" + dr["id"] + ".ZoneWidth = " + dr["ZoneWidth"] + ";");
sw.WriteLine("ZoneAD_" + dr["id"] + ".ZoneHeight = " + dr["ZoneHeight"] + ";");
sw.WriteLine("ZoneAD_" + dr["id"] + ".ShowType = " + dr["ShowType"] + ";");
Arraydr = dr["ZoneSetting"].ToString().Split(',');
sw.WriteLine("ZoneAD_" + dr["id"] + ".PopType = " + Arraydr[0].ToString() + ";");
sw.WriteLine("ZoneAD_" + dr["id"] + ".Left = " + Arraydr[1].ToString() + ";");
sw.WriteLine("ZoneAD_" + dr["id"] + ".Top = " + Arraydr[2].ToString() + ";");
sw.WriteLine("ZoneAD_" + dr["id"] + ".CookieHour = 0;");
sw.WriteLine("");
ForWriteJS(dr["id"].ToString());
break;
case 3:
sw.WriteLine("var ZoneAD_" + dr["id"] + " = new MoveZoneAD(" + "\"ZoneAD_" + dr["id"] + "\"" + ");");
sw.WriteLine("ZoneAD_" + dr["id"] + ".ZoneID = " + dr["id"] + ";");
sw.WriteLine("ZoneAD_" + dr["id"] + ".ZoneWidth = " + dr["ZoneWidth"] + ";");
sw.WriteLine("ZoneAD_" + dr["id"] + ".ZoneHeight = " + dr["ZoneHeight"] + ";");
sw.WriteLine("ZoneAD_" + dr["id"] + ".ShowType = " + dr["ShowType"] + ";");
Arraydr = dr["ZoneSetting"].ToString().Split(',');
sw.WriteLine("ZoneAD_" + dr["id"] + ".Left = " + Arraydr[0].ToString() + ";");
sw.WriteLine("ZoneAD_" + dr["id"] + ".Top = " + Arraydr[1].ToString() + ";");
sw.WriteLine("ZoneAD_" + dr["id"] + ".Delta = " + Arraydr[2].ToString() + ";");
sw.WriteLine("");
ForWriteJS(dr["id"].ToString());
break;
case 4:
sw.WriteLine("var ZoneAD_" + dr["id"] + " = new FixedZoneAD(" + "\"ZoneAD_" + dr["id"] + "\"" + ");");
sw.WriteLine("ZoneAD_" + dr["id"] + ".ZoneID = " + dr["id"] + ";");
sw.WriteLine("ZoneAD_" + dr["id"] + ".ZoneWidth = " + dr["ZoneWidth"] + ";");
sw.WriteLine("ZoneAD_" + dr["id"] + ".ZoneHeight = " + dr["ZoneHeight"] + ";");
sw.WriteLine("ZoneAD_" + dr["id"] + ".ShowType = " + dr["ShowType"] + ";");
Arraydr = dr["ZoneSetting"].ToString().Split(',');
sw.WriteLine("ZoneAD_" + dr["id"] + ".Left = " + Arraydr[0].ToString() + ";");
sw.WriteLine("ZoneAD_" + dr["id"] + ".Top = " + Arraydr[1].ToString() + ";");
sw.WriteLine("");
ForWriteJS(dr["id"].ToString());
break;
case 5:
sw.WriteLine("var ZoneAD_" + dr["id"] + " = new FloatZoneAD(" + "\"ZoneAD_" + dr["id"] + "\"" + ");");
sw.WriteLine("ZoneAD_" + dr["id"] + ".ZoneID = " + dr["id"] + ";");
sw.WriteLine("ZoneAD_" + dr["id"] + ".ZoneWidth = " + dr["ZoneWidth"] + ";");
sw.WriteLine("ZoneAD_" + dr["id"] + ".ZoneHeight = " + dr["ZoneHeight"] + ";");
sw.WriteLine("ZoneAD_" + dr["id"] + ".ShowType = " + dr["ShowType"] + ";");
Arraydr = dr["ZoneSetting"].ToString().Split(',');
sw.WriteLine("ZoneAD_" + dr["id"] + ".FloatType = " + Arraydr[0].ToString() + ";");
sw.WriteLine("ZoneAD_" + dr["id"] + ".Left = " + Arraydr[1].ToString() + ";");
sw.WriteLine("ZoneAD_" + dr["id"] + ".Top = " + Arraydr[2].ToString() + ";");
sw.WriteLine("");
ForWriteJS(dr["id"].ToString());
break;
case 6:
sw.WriteLine("var ZoneAD_" + dr["id"].ToString() + " = new CodeZoneAD(" + "\"ZoneAD_" + dr["id"].ToString() + "\"" + ");");
sw.WriteLine("ZoneAD_" + dr["id"].ToString() + ".ZoneID = " + dr["id"] + ";");
sw.WriteLine("ZoneAD_" + dr["id"].ToString() + ".ZoneWidth = " + dr["ZoneWidth"] + ";");
sw.WriteLine("ZoneAD_" + dr["id"].ToString() + ".ZoneHeight = " + dr["ZoneHeight"] + ";");
sw.WriteLine("ZoneAD_" + dr["id"].ToString() + ".ShowType = " + dr["ShowType"] + ";");
sw.WriteLine("");
ForWriteJS(dr["id"].ToString());
break;
}
sw.WriteLine("ZoneAD_" + dr["id"] + ".Show();");
sw.Flush();
sw.Close();
} else {
Response.Write("<script>alert('未找到JS模板,请联系管理员');window.location='../Default.aspx'</script>");
}
}
#endregion
#region 取得数据集的总数,用以循环打印结果JS内容
public void ForWriteJS(string sAdZone) {
//取得数据集的总数,用以循环打印结果
DataTable dt = MyDataSet("select * from [Advertisement] where [ZoneID]='" + sAdZone + "' and Passed='√'", "ZoneJsName").Tables[0];
for (int j = 0; j < dt.Rows.Count; j++) {
sw.WriteLine("var objAD = new ObjectAD();");
sw.WriteLine("objAD.ADID = " + dt.Rows[j]["id"] + ";");
sw.WriteLine("objAD.ADType = " + dt.Rows[j]["ADType"] + ";");
sw.WriteLine("objAD.ADName = " + "\"" + dt.Rows[j]["ADName"] + "\"" + ";");
sw.WriteLine("objAD.ImgUrl = " + "\"" + dt.Rows[j]["ImgUrl"] + "\"" + ";");
sw.WriteLine("objAD.ImgWidth = " + dt.Rows[j]["ImgWidth"] + ";");
sw.WriteLine("objAD.ImgHeight = " + dt.Rows[j]["ImgHeight"] + ";");
sw.WriteLine("objAD.FlashWmode = " + dt.Rows[j]["FlashWmode"] + ";");
sw.WriteLine("objAD.ADIntro = " + "\"" + dt.Rows[j]["ADIntro"] + "\"" + ";");
sw.WriteLine("objAD.LinkUrl = " + "\"" + dt.Rows[j]["LinkUrl"] + "\"" + ";");
sw.WriteLine("objAD.LinkTarget = " + dt.Rows[j]["LinkTarget"] + ";");
sw.WriteLine("objAD.LinkAlt = " + "\"" + dt.Rows[j]["LinkAlt"] + "\"" + ";");
sw.WriteLine("objAD.Priority = " + dt.Rows[j]["Priority"] + ";");
sw.WriteLine("objAD.CountView = " + dt.Rows[j]["Views"] + ";");
sw.WriteLine("objAD.CountClick = " + dt.Rows[j]["Clicks"] + ";");
sw.WriteLine("objAD.InstallDir = " + "\"" + Application["PageTitle"].ToString() + "\"" + ";");
sw.WriteLine("objAD.ADDIR = " + "\"" + "AD" + "\"" + ";");
sw.WriteLine("ZoneAD_" + dt.Rows[j]["ZoneID"] + ".AddAD(objAD);");
sw.WriteLine("");
}
}
#endregion
#region 弹出JS窗口提示框
/// <summary>
/// 弹出JS窗口提示框
/// </summary>
/// <param name="message">提示消息</param>
/// <param name="url">URL地址,可选参数,为空则只弹出对话框,而不刷新页面</param>
public void JsWindows(string message, string url) {
if (url == "") {
HttpContext.Current.Response.Write("<script>alert('" + message + "')</script>");
} else {
HttpContext.Current.Response.Write("<script>alert('" + message + "');window.location='" + url + "'</script>");
}
}
#endregion
#region 弹出JS对话框并关闭当前页
public void JsWindowsAndClose(string message) {
Response.Write("<script>alert('" + message + "');window.close();</script>");
}
#endregion
#region 返回MD5加密数据
public string md5(string str) {
return FormsAuthentication.HashPasswordForStoringInConfigFile(str, "MD5");
}
#endregion
#region 越权操作提示框
/// <summary>
/// 越权操作提示框
/// </summary>
public void NoPurview() {
Response.Write("<script>alert('无权限,请确认您具备该权限。');window.location='Admin_Manage.aspx'</script>");
}
#endregion
}
}