Pārlūkot izejas kodu

上传文件至 ''

master
童毓泽 pirms 4 gadiem
vecāks
revīzija
28c4b9e4e2
20 mainītis faili ar 4287 papildinājumiem un 0 dzēšanām
  1. +18
    -0
      AccessToken2.cs
  2. +692
    -0
      BasicPage.cs
  3. +66
    -0
      CacheHelper.cs
  4. +73
    -0
      CommandInfo.cs
  5. +171
    -0
      DBAcess.cs
  6. +89
    -0
      DESEncrypt.cs
  7. +1159
    -0
      DbHelperSQL.cs
  8. +48
    -0
      EnumsClass.cs
  9. +149
    -0
      GetPage.cs
  10. +77
    -0
      HuiyuanPage.cs
  11. +50
    -0
      Keys.cs
  12. +82
    -0
      LoginState.cs
  13. +59
    -0
      Mail.cs
  14. +226
    -0
      ManagePage.cs
  15. +133
    -0
      PagingHelper.cs
  16. +54
    -0
      QZCheck.cs
  17. +98
    -0
      QZRequest.cs
  18. +204
    -0
      RequestClass.cs
  19. +147
    -0
      SendInfo.cs
  20. +692
    -0
      bpSeo.cs

+ 18
- 0
AccessToken2.cs Parādīt failu

@ -0,0 +1,18 @@
using System;
using System.Collections.Generic;
using System.Web;
/// <summary>
/// AccessToken2 的摘要说明
/// </summary>
public class AccessToken2
{
public string access_token = "";
public string expires_in = "";
public AccessToken2()
{
}
}

+ 692
- 0
BasicPage.cs Parādīt failu

@ -0,0 +1,692 @@
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.Data.SqlClient;
using System.Linq;
using System.Text;
using System.Management; //在工程(project)的引用中,右键,添加引用
using System.DirectoryServices; //在工程(project)的引用中,右键,添加引用
using Microsoft.JScript; //获取脚本解释引擎用
using System.Diagnostics; //速度测试用
using System.IO;
/// <summary>
/// Summary description for BasicPage
/// </summary>
///
namespace Basic
{
public class BasicPage : System.Web.UI.Page
{
public string newString;//返回被截取的字符串
public string connstring;
public string strSql;
public SqlConnection myconn;
public SqlCommand mycommand;
public SqlDataReader myreader;
public SqlDataAdapter myadapter;
public DataSet ds;
public DataView dv;
public DataTable tzDataTable;
//
public string strTitle = null;
public string strDescription = null;
public string strKeys = null;
//参数设置开始
public string strServer = System.Configuration.ConfigurationManager.AppSettings["Server"].ToString();
public string strDatabase = System.Configuration.ConfigurationManager.AppSettings["Database"].ToString();
public string strUid = System.Configuration.ConfigurationManager.AppSettings["UID"].ToString();
public string strPwd = System.Configuration.ConfigurationManager.AppSettings["PWD"].ToString();
public void connection()
{
connstring = System.Configuration.ConfigurationManager.AppSettings["ConnectionString"].ToString();
myconn = new SqlConnection(connstring);
}
public void dbOpen()
{
connection();
myconn.Open();
}
public void dbClose()
{
myconn.Close();
}
public void MessageBox(string url, string message, int type)
{
if (type == 0)
{
System.Web.HttpContext.Current.Response.Write("<script>alert('" + message + "');location.href='" + url + "';</script>");
}
else if (type == 1)
{
System.Web.HttpContext.Current.Response.Write("<script>alert('" + message + "');parent.location.href='" + url + "';</script>");
}
}
/// <summary>
///返回数据集DataSet
/// </summary>
/// <param name="tableName"></param>
/// <param name="tempStrSQL"></param>
/// <returns></returns>
public DataSet SelectDataBase(string tableName, string tempStrSQL)
{
connection();
ds = new DataSet();
this.myadapter = new SqlDataAdapter(tempStrSQL, this.myconn);
this.myadapter.Fill(ds, tableName);
return ds;
}
/// <summary>
///返回数据集DataTable
/// </summary>
/// <param name="tableName"></param>
/// <param name="tempStrSQL"></param>
/// <returns></returns>
public DataTable SelectDataTable(string tempStrSQL)
{
connection();
myconn.Open();
SqlCommand cmd = new SqlCommand(tempStrSQL, this.myconn);
SqlDataReader reader = cmd.ExecuteReader(CommandBehavior.CloseConnection);
DataTable dt = new DataTable();
dt.Load(reader);
reader.Dispose();
return dt;
}
/// <summary>
/// 返回单条数据
/// </summary>
/// <param name="tempStrSql"></param>
/// <returns></returns>
public SqlDataReader getRead(string tempStrSql)
{
connection();
SqlCommand mycommand = new SqlCommand(tempStrSql, myconn);
myconn.Open();
SqlDataReader myreader = mycommand.ExecuteReader(CommandBehavior.CloseConnection);
return myreader;
}
/// <summary>
/// 执行更新操作
/// </summary>
/// <param name="tempStrSql"></param>
/// <returns></returns>
public bool doExecute(string tempStrSql)
{
connection();
SqlCommand mycommand = new SqlCommand(tempStrSql, myconn);
myconn.Open();
try
{
mycommand.ExecuteNonQuery();
return true;
}
finally
{
mycommand.Dispose();
myconn.Close();
myconn.Dispose();
}
}
/// <summary>
/// 截取字符串
/// </summary>
/// <param name="str"></param>
/// <param name="length"></param>
/// <returns></returns>
public string CutString(string str, int length)
{
if (str != "")
{
if (str.Length > length)
{
newString = str.Substring(0, length) + "...";
}
else
{
newString = str;
}
}
return newString;
}
/// <summary>
/// 清空浏览器客户端的缓存
/// </summary>
public bool ClearClientPageCache()
{
HttpContext.Current.Response.Buffer = true;
HttpContext.Current.Response.Expires = 0;
HttpContext.Current.Response.ExpiresAbsolute = DateTime.Now.AddDays(-1);
HttpContext.Current.Response.AddHeader("pragma", "no-cache");
HttpContext.Current.Response.AddHeader("cache-control", "private");
HttpContext.Current.Response.CacheControl = "no-cache";
return true;
}
/// <summary>
/// 检测Jmail4.3邮箱组件或FSO文本读写
/// </summary>
/// <param name="_obj"></param>
/// <returns></returns>
public bool IsObjInstalled(string _obj)
{
bool IsFSOInstalled = false;
try
{
Server.CreateObject(_obj);
IsFSOInstalled = true;
}
catch (Exception ex)
{
IsFSOInstalled = false;
}
return IsFSOInstalled;
}
/// <summary>
/// 获取脚本解释引擎
/// </summary>
/// <returns></returns>
public string JiaoBenYinqing()
{
return GlobalObject.ScriptEngine() + "/" + GlobalObject.ScriptEngineMajorVersion() + "." + GlobalObject.ScriptEngineMinorVersion() + "." + GlobalObject.ScriptEngineBuildVersion();
}
/// <summary>
/// 获取服务器ip
/// </summary>
/// <returns></returns>
public string ServerIp()
{
string stringMAC = "";
string stringIP = "";
ManagementClass MC = new ManagementClass("Win32_NetworkAdapterConfiguration");
ManagementObjectCollection MOC = MC.GetInstances();
foreach (ManagementObject MO in MOC)
{
if ((bool)MO["IPEnabled"] == true)
{
stringMAC += MO["MACAddress"].ToString();
//TextMAC.Text = stringMAC.ToString();
string[] IPAddresses = (string[])MO["IPAddress"];
if (IPAddresses.Length > 0) stringIP = IPAddresses[0];
}
}
return stringIP;
}
/// <summary>
/// 获取操作系统
/// </summary>
/// <returns></returns>
public string ServerOS()
{
return System.Environment.OSVersion.ToString();
}
/// <summary>
/// 整数运算速度测试
/// </summary>
/// <returns></returns>
public string IntTest()
{
string Value;
Stopwatch timer = new Stopwatch();
long total = 0;
timer.Start();
for (int i = 1; i <= 500000; i++)
{
total += i;
}
timer.Stop();
decimal micro = timer.Elapsed.Ticks / 10m;
Value = "整数运算测试,正在进行50万次加法运算......已完成!<font color=red>" + micro.ToString() + "微妙" + "</font>";
return Value;
}
/// <summary>
/// 实数运算速度测试
/// </summary>
/// <returns></returns>
public string FloatTest()
{
string Value;
Stopwatch timer = new Stopwatch();
long total = 0;
timer.Start();
for (int i = 1; i <= 200000; i++)
{
total *= total;
}
timer.Stop();
decimal micro = timer.Elapsed.Ticks / 10m;
Value = "浮点数运算测试,正在进行20万次乘法运算......已完成!<font color=red>" + micro.ToString() + "微妙" + "</font>";
return Value;
}
/// <summary>
/// 备份数据库
/// </summary>
/// <param name="strDbName"></param>
/// <param name="strFileName"></param>
/// <param name="strRname"></param>
/// <returns></returns>
public string DbBackup(string strDbName, string strFileName, string strRname)
{
try
{
SQLDMO.Backup oBackup = new SQLDMO.BackupClass();
SQLDMO.SQLServer oSQLServer = new SQLDMO.SQLServerClass();
oSQLServer.LoginSecure = false;
oSQLServer.Connect(strServer, strUid, strPwd);
oBackup.Action = SQLDMO.SQLDMO_BACKUP_TYPE.SQLDMOBackup_Database;
oBackup.Database = strDbName;
string Path = strFileName + strRname;
oBackup.Files = Path;
oBackup.BackupSetName = strRname;
oBackup.BackupSetDescription = "备份数据库";
oBackup.Initialize = true;
oBackup.SQLBackup(oSQLServer);
oSQLServer.DisConnect();
return "ok";
}
catch (Exception ex)
{
return ex.Message;
}
}
/// <summary>
/// 还原数据库
/// </summary>
/// <param name="strDbName"></param>
/// <param name="strFileName"></param>
/// <param name="strRname"></param>
/// <returns></returns>
public bool DbRestore(string strDbName, string strFileName, string strRname)
{
strDbName = strDatabase;
strFileName = "";
SQLDMO.Restore oRestore = new SQLDMO.RestoreClass();
SQLDMO.SQLServer oSQLServer = new SQLDMO.SQLServerClass();
try
{
oSQLServer.LoginSecure = false;
oSQLServer.Connect(strServer, strUid, strPwd);
oRestore.Action = SQLDMO.SQLDMO_RESTORE_TYPE.SQLDMORestore_Database;
oRestore.Database = strDbName;
oRestore.Files = strFileName + strRname;
oRestore.FileNumber = 1;
oRestore.ReplaceDatabase = true;
oRestore.SQLRestore(oSQLServer);
return true;
}
catch
{
return false;
}
}
/// <summary>
/// 获取系统使用者名称
/// </summary>
/// <returns></returns>
public string readConame()
{
string strConame;
SqlDataReader Myreader;
Myreader = getRead("select webname from tbset where id=1");
if (Myreader.Read())
{
strConame = Myreader["webname"].ToString();
}
else
{
strConame = "<font color=red>暂无数据(请先进行系统基本设置)</font>";
}
Myreader.Close();
return strConame;
}
/// <summary>
/// 统计服务器空间占用情况
/// </summary>
/// <param name="dirPath"></param>
/// <returns></returns>
public long GetDirectoryLength(string dirPath)
{
//判断给定的路径是否存在,如果不存在则退出
if (!Directory.Exists(dirPath))
return 0;
long len = 0;
//定义一个DirectoryInfo对象
DirectoryInfo di = new DirectoryInfo(dirPath);
//通过GetFiles方法,获取di目录中的所有文件的大小
foreach (FileInfo fi in di.GetFiles())
{
len += fi.Length;
}
//获取di中所有的文件夹,并存到一个新的对象数组中,以进行递归
DirectoryInfo[] dis = di.GetDirectories();
if (dis.Length > 0)
{
for (int i = 0; i < dis.Length; i++)
{
len += GetDirectoryLength(dis[i].FullName);
}
}
return len;
}
/// <summary>
/// 添加要锁定的IP
/// </summary>
/// <param name="strAddIp"></param>
/// <returns></returns>
public int lockip(string strAddIp)
{
int returnId = 0;
int intId = 1;
bool bsign = false;
string strIpGroup;
string strIp = strAddIp;
SqlDataReader myreader = getRead("select ip from TbIp where id=1");
if (myreader.Read())
{
string[] strIPzu = myreader["ip"].ToString().Split('|');
for (int i = 0; i < strIPzu.Length; i++)
{
if (strIp == strIPzu[i])
{
bsign = true;
}
}
strIpGroup = myreader["ip"].ToString();
myreader.Close();
if (bsign == false)
{
if (strIpGroup == "")
{
strIpGroup = strIp;
}
else
{
strIpGroup = strIpGroup + "|" + strIp;
}
if (doExecute("update tbIp set ip='" + strIpGroup + "' where id=1"))
{
//Response.Redirect("Success.aspx?message=IP锁定成功!&url=IpManage.aspx");
returnId = 1;
}
}
else if (bsign == true)
{
//Response.Redirect("Error.aspx?message=锁定失败,该IP已被锁定!&url=IpManage.aspx");
returnId = 2;
}
}
else
{
myreader.Close();
if (doExecute("insert into tbIp(id,ip)values(" + intId + ",'" + strIp + "')"))
{
//Response.Redirect("Success.aspx?message=IP锁定成功!&url=IpManage.aspx");
returnId = 3;
}
}
return returnId;
}
/// <summary>
/// 显示被锁定IP
/// </summary>
/// <returns></returns>
public string showLockIp()
{
string strIp = "";
SqlDataReader myreader = getRead("select ip from tbIp where id=1");
if (myreader.Read())
{
strIp = myreader["ip"].ToString();
}
myreader.Close();
return strIp.Trim();
}
/// <summary>
/// 更新锁定的IP列表
/// </summary>
/// <param name="strIps"></param>
/// <returns></returns>
public bool updateIp(string strIps)
{
bool sign = false;
SqlDataReader myreader = getRead("select * from tbIp where id=1");
if (myreader.Read())
{
if (doExecute("update tbIp set ip='" + strIps + "' where id=1"))
{
sign = true;
}
}
else
{
int id = 1;
if (doExecute("insert into tbIp(id,ip)values(" + id + ",'" + strIps + "')"))
{
sign = true;
}
}
myreader.Close();
return sign;
}
/// <summary>
/// 判断是否关闭网站
/// </summary>
/// <returns></returns>
public void ShowWebState()
{
string state = "1";
SqlDataReader myreader = getRead("select state from TBset where id=1");
if (myreader.Read())
{
state = myreader["state"].ToString();
if (state == "0")
{
System.Web.HttpContext.Current.Response.Write("<script>parent.location.href='Close.htm'</script>");
}
}
myreader.Close();
}
/// <summary>
/// 读取Title,Description,Keys
/// </summary>
public void showWebTitle()
{
int intId = 1;
SqlDataReader Myreader = getRead("select * from TBset where id=" + intId + "");
if (Myreader.Read())
{
strTitle = Myreader["webname"].ToString();
strDescription = Myreader["webdescription"].ToString();
strKeys = Myreader["webkeys"].ToString();
}
Myreader.Close();
StartProcessRequest();//分析用户请求是否正常
ShowWebState();//判断网站是否关闭
}
/// <summary>
/// 分析用户请求是否正常
/// </summary>
///
public static void StartProcessRequest()
{
try
{
string getkeys = "";
//string sqlErrorPage = System.Configuration.ConfigurationSettings.AppSettings["CustomErrorPage"].ToString();
if (System.Web.HttpContext.Current.Request.QueryString != null)
{
for (int i = 0; i < System.Web.HttpContext.Current.Request.QueryString.Count; i++)
{
getkeys = System.Web.HttpContext.Current.Request.QueryString.Keys[i];
if (!ProcessSqlStr(System.Web.HttpContext.Current.Request.QueryString[getkeys], 0))
{
//System.Web.HttpContext.Current.Response.Redirect (sqlErrorPage+"?errmsg=sqlserver&sqlprocess=true");
System.Web.HttpContext.Current.Response.Write("<script>alert('请勿非法提交!');history.back();</script>");
System.Web.HttpContext.Current.Response.End();
}
}
}
if (System.Web.HttpContext.Current.Request.Form != null)
{
for (int i = 0; i < System.Web.HttpContext.Current.Request.Form.Count; i++)
{
getkeys = System.Web.HttpContext.Current.Request.Form.Keys[i];
if (!ProcessSqlStr(System.Web.HttpContext.Current.Request.Form[getkeys], 1))
{
//System.Web.HttpContext.Current.Response.Redirect (sqlErrorPage+"?errmsg=sqlserver&sqlprocess=true");
System.Web.HttpContext.Current.Response.Write("<script>alert('请勿非法提交!');history.back();</script>");
System.Web.HttpContext.Current.Response.End();
}
}
}
}
catch
{
// 错误处理: 处理用户提交信息!
}
}
/**/
/// <summary>
/// 分析用户请求是否正常
/// </summary>
/// <param name="Str">传入用户提交数据</param>
/// <returns>返回是否含有SQL注入式攻击代码</returns>
private static bool ProcessSqlStr(string Str, int type)
{
string SqlStr;
if (type == 1)
SqlStr = "exec|insert|select|delete|update|count|chr|mid|master|truncate|char|declare";
else
SqlStr = "'|and|exec|insert|select|delete|update|count|*|chr|mid|master|truncate|char|declare|>|<";
bool ReturnValue = true;
try
{
if (Str != "")
{
string[] anySqlStr = SqlStr.Split('|');
foreach (string ss in anySqlStr)
{
if (Str.IndexOf(ss) >= 0)
{
ReturnValue = false;
}
}
}
}
catch
{
ReturnValue = false;
}
return ReturnValue;
}
/// <summary>
/// 判断是否是数字
/// </summary>
/// <param name="oText"></param>
/// <returns>bool</returns>
public bool IsNumberic(string oText)//判断是否是数字
{
try
{
int var1 = System.Convert.ToInt32(oText);
if (var1 < 0)
{
return false;
}
return true;
}
catch
{
return false;
}
}
/// <summary>
/// 截取字符串
/// </summary>
/// <param name="inputString"></param>
/// <param name="length"></param>
/// <returns>string</returns>
public string SubString(string inputString, int length)
{
if (Encoding.UTF8.GetByteCount(inputString) <= length * 2)
{
return inputString;
}
ASCIIEncoding ascii = new ASCIIEncoding();
int tempLen = 0;
string tempString = "";
byte[] s = ascii.GetBytes(inputString);
for (int i = 0; i < s.Length; i++)
{
if ((int)s[i] == 63)
{
tempLen += 2;
}
else
{
tempLen += 1;
}
tempString += inputString.Substring(i, 1);
if (tempLen >= (length - 1) * 2)
break;
}
//如果截过则加上半个省略号
if (System.Text.Encoding.Default.GetBytes(inputString).Length > length)
tempString += "";
return tempString;
}
/// <summary>
/// 显示登录状态
/// </summary>
public void ShowLoginState()
{
if (Session["j95fn3839vfn93h9n29n"] == null)
{
System.Web.HttpContext.Current.Response.Write("<script>parent.location.href='Default.aspx'</script>");
}
}
#region JS提示============================================
/// <summary>
/// 添加编辑删除提示
/// </summary>
/// <param name="msgtitle">提示文字</param>
/// <param name="url">返回地址</param>
/// <param name="msgcss">CSS样式</param>
public void JscriptMsg(string msgtitle, string url, string msgcss)
{
string msbox = "parent.jsprint(\"" + msgtitle + "\", \"" + url + "\", \"" + msgcss + "\")";
ClientScript.RegisterClientScriptBlock(Page.GetType(), "JsPrint", msbox, true);
}
/// <summary>
/// 带回传函数的添加编辑删除提示
/// </summary>
/// <param name="msgtitle">提示文字</param>
/// <param name="url">返回地址</param>
/// <param name="msgcss">CSS样式</param>
/// <param name="callback">JS回调函数</param>
public void JscriptMsg(string msgtitle, string url, string msgcss, string callback)
{
string msbox = "parent.jsprint(\"" + msgtitle + "\", \"" + url + "\", \"" + msgcss + "\", " + callback + ")";
ClientScript.RegisterClientScriptBlock(Page.GetType(), "JsPrint", msbox, true);
}
#endregion
}
}

+ 66
- 0
CacheHelper.cs Parādīt failu

@ -0,0 +1,66 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Caching;
/// <summary>
///CacheHelper 的摘要说明
/// </summary>
///
namespace Basic
{
public class CacheHelper
{
/// <summary>
/// 创建缓存项的文件依赖
/// </summary>
/// <param name="key">缓存Key</param>
/// <param name="obj">object对象</param>
/// <param name="fileName">文件绝对路径</param>
public static void Insert(string key, object obj, string fileName)
{
//创建缓存依赖项
CacheDependency dep = new CacheDependency(fileName);
//创建缓存
HttpContext.Current.Cache.Insert(key, obj, dep);
}
/// <summary>
/// 创建缓存项过期
/// </summary>
/// <param name="key">缓存Key</param>
/// <param name="obj">object对象</param>
/// <param name="expires">过期时间(分钟)</param>
public static void Insert(string key, object obj, int expires)
{
HttpContext.Current.Cache.Insert(key, obj, null, Cache.NoAbsoluteExpiration, new TimeSpan(0, expires, 0));
}
/// <summary>
/// 获取缓存对象
/// </summary>
/// <param name="key">缓存Key</param>
/// <returns>object对象</returns>
public static object Get(string key)
{
if (string.IsNullOrEmpty(key))
{
return null;
}
return HttpContext.Current.Cache.Get(key);
}
/// <summary>
/// 获取缓存对象
/// </summary>
/// <typeparam name="T">T对象</typeparam>
/// <param name="key">缓存Key</param>
/// <returns></returns>
public static T Get<T>(string key)
{
object obj = Get(key);
return obj == null ? default(T) : (T)obj;
}
}
}

+ 73
- 0
CommandInfo.cs Parādīt failu

@ -0,0 +1,73 @@
using System;
using System.Collections.Generic;
using System.Text;
using System.Data.SqlClient;
namespace Basic
{
public enum EffentNextType
{
/// <summary>
/// 对其他语句无任何影响
/// </summary>
None,
/// <summary>
/// 当前语句必须为"select count(1) from .."格式,如果存在则继续执行,不存在回滚事务
/// </summary>
WhenHaveContine,
/// <summary>
/// 当前语句必须为"select count(1) from .."格式,如果不存在则继续执行,存在回滚事务
/// </summary>
WhenNoHaveContine,
/// <summary>
/// 当前语句影响到的行数必须大于0,否则回滚事务
/// </summary>
ExcuteEffectRows,
/// <summary>
/// 引发事件-当前语句必须为"select count(1) from .."格式,如果不存在则继续执行,存在回滚事务
/// </summary>
SolicitationEvent
}
public class CommandInfo
{
public object ShareObject = null;
public object OriginalData = null;
event EventHandler _solicitationEvent;
public event EventHandler SolicitationEvent
{
add
{
_solicitationEvent += value;
}
remove
{
_solicitationEvent -= value;
}
}
public void OnSolicitationEvent()
{
if (_solicitationEvent != null)
{
_solicitationEvent(this, new EventArgs());
}
}
public string CommandText;
public System.Data.Common.DbParameter[] Parameters;
public EffentNextType EffentNextType = EffentNextType.None;
public CommandInfo()
{
}
public CommandInfo(string sqlText, SqlParameter[] para)
{
this.CommandText = sqlText;
this.Parameters = para;
}
public CommandInfo(string sqlText, SqlParameter[] para, EffentNextType type)
{
this.CommandText = sqlText;
this.Parameters = para;
this.EffentNextType = type;
}
}
}

+ 171
- 0
DBAcess.cs Parādīt failu

@ -0,0 +1,171 @@
using System;
using System.Collections.Generic;
using System.Web;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
using System.Text;
/// <summary>
///DBacess 的摘要说明
/// </summary>
namespace basic
{
public class DBacess
{
/// <summary>
/// 创建活动SqlConnection
/// </summary>
/// <returns>SqlConnection</returns>
///
public static SqlConnection con;
private static SqlConnection connection()
{
SqlConnection conn = new SqlConnection(System.Configuration.ConfigurationManager.AppSettings["ConnectionString"].ToString());
con = conn;
return conn;
}
/// <summary>
/// 打开连接数据库
/// </summary>
/// <param name="conn">SqlConnection对象</param>
private void OpenConnection(SqlConnection conn)
{
if (conn != null && conn.State == ConnectionState.Closed)
conn.Open();
}
/// <summary>
/// 关闭数据库
/// </summary>
/// <param name="conn">SqlConnection对象</param>
private void CloseConnection(SqlConnection conn)
{
if (conn != null && conn.State == ConnectionState.Open)
conn.Close();
}
/// <summary>
/// 更新数据库
/// </summary>
/// <param name="sql"></param>
/// <param name="parameters"></param>
/// <param name="type"></param>
/// <returns></returns>
public bool Update(string sql, SqlParameter[] parameters, CommandType type)
{
SqlConnection conn = connection();
bool result = false;
try
{
using (conn)
{
SqlCommand cmd = new SqlCommand(sql, conn);
if (parameters != null)
{
foreach (SqlParameter parameter in parameters)
{
if (parameters != null && parameter.ParameterName != "")
{
cmd.Parameters.Add(parameter);
}
}
}
cmd.CommandType = type;
cmd.Connection.Open();
int flag = cmd.ExecuteNonQuery();
if (flag > 0)
result = true;
}
}
finally
{
CloseConnection(conn);
}
return result;
}
/// <summary>
/// 根据条件查询数据
/// </summary>
/// <param name="sql"></param>
/// <param name="parameters"></param>
/// <returns>DataTable</returns>
public DataTable SelectReturnDataTable(string sql, SqlParameter[] parameters)
{
SqlConnection conn = connection();
DataTable dt = new DataTable();
try
{
using (conn)
{
SqlCommand cmd = new SqlCommand(sql, conn);
if (parameters != null)
{
foreach (SqlParameter parameter in parameters)
{
if (parameter != null && parameter.ParameterName != "")
{
cmd.Parameters.Add(parameter);
}
}
}
conn.Open();
SqlDataAdapter sda = new SqlDataAdapter(cmd);
sda.Fill(dt);
}
}
//catch (Exception e)
//{
//}
finally
{
CloseConnection(conn);
}
return dt;
}
/// <summary>
/// 根据条件查询数据
/// </summary>
/// <param name="sql"></param>
/// <param name="parameters"></param>
/// <returns>DataSet</returns>
public DataSet SelectReturnDataSet(string sql, SqlParameter[] parameters)
{
SqlConnection conn = connection();
DataSet ds = new DataSet();
try
{
using (conn)
{
SqlCommand cmd = new SqlCommand(sql, conn);
if (parameters != null)
{
foreach (SqlParameter parameter in parameters)
{
if (parameter != null && parameter.ParameterName != "")
{
cmd.Parameters.Add(parameter);
}
}
}
conn.Open();
SqlDataAdapter sda = new SqlDataAdapter(cmd);
sda.Fill(ds);
}
}
//catch (Exception e)
//{
//}
finally
{
CloseConnection(conn);
}
return ds;
}
}
}

+ 89
- 0
DESEncrypt.cs Parādīt failu

@ -0,0 +1,89 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Security.Cryptography;
using System.Text;
/// <summary>
///DESEncrypt 的摘要说明
/// </summary>
namespace Basic.Tools
{
public class DESEncrypt
{
/// <summary>
/// 加密
/// </summary>
/// <param name="Text"></param>
/// <returns></returns>
public static string Encrypt(string Text)
{
return Encrypt(Text, "str_key");
}
/// <summary>
/// 加密数据
/// </summary>
/// <param name="Text"></param>
/// <param name="sKey"></param>
/// <returns></returns>
public static string Encrypt(string Text, string sKey)
{
DESCryptoServiceProvider des = new DESCryptoServiceProvider();
byte[] inputByteArray;
inputByteArray = Encoding.Default.GetBytes(Text);
des.Key = ASCIIEncoding.ASCII.GetBytes(System.Web.Security.FormsAuthentication.HashPasswordForStoringInConfigFile(sKey, "md5").Substring(0, 8));
des.IV = ASCIIEncoding.ASCII.GetBytes(System.Web.Security.FormsAuthentication.HashPasswordForStoringInConfigFile(sKey, "md5").Substring(0, 8));
System.IO.MemoryStream ms = new System.IO.MemoryStream();
CryptoStream cs = new CryptoStream(ms, des.CreateEncryptor(), CryptoStreamMode.Write);
cs.Write(inputByteArray, 0, inputByteArray.Length);
cs.FlushFinalBlock();
StringBuilder ret = new StringBuilder();
foreach (byte b in ms.ToArray())
{
ret.AppendFormat("{0:X2}", b);
}
return ret.ToString();
}
/// <summary>
/// 解密
/// </summary>
/// <param name="Text"></param>
/// <returns></returns>
public static string Decrypt(string Text)
{
return Decrypt(Text, "str_key");
}
/// <summary>
/// 解密数据
/// </summary>
/// <param name="Text"></param>
/// <param name="sKey"></param>
/// <returns></returns>
public static string Decrypt(string Text, string sKey)
{
DESCryptoServiceProvider des = new DESCryptoServiceProvider();
int len;
len = Text.Length / 2;
byte[] inputByteArray = new byte[len];
int x, i;
for (x = 0; x < len; x++)
{
i = Convert.ToInt32(Text.Substring(x * 2, 2), 16);
inputByteArray[x] = (byte)i;
}
des.Key = ASCIIEncoding.ASCII.GetBytes(System.Web.Security.FormsAuthentication.HashPasswordForStoringInConfigFile(sKey, "md5").Substring(0, 8));
des.IV = ASCIIEncoding.ASCII.GetBytes(System.Web.Security.FormsAuthentication.HashPasswordForStoringInConfigFile(sKey, "md5").Substring(0, 8));
System.IO.MemoryStream ms = new System.IO.MemoryStream();
CryptoStream cs = new CryptoStream(ms, des.CreateDecryptor(), CryptoStreamMode.Write);
cs.Write(inputByteArray, 0, inputByteArray.Length);
cs.FlushFinalBlock();
return Encoding.Default.GetString(ms.ToArray());
}
}
}

+ 1159
- 0
DbHelperSQL.cs
Failā izmaiņas netiks attēlotas, jo tās ir par lielu
Parādīt failu


+ 48
- 0
EnumsClass.cs Parādīt failu

@ -0,0 +1,48 @@
using System;
using System.Collections.Generic;
using System.Text;
/// <summary>
///EnumsClass 的摘要说明
/// </summary>
///
namespace Basic
{
public class EnumsClass
{
/// <summary>
/// 统一管理操作枚举
/// </summary>
public enum ActionEnum
{
/// <summary>
/// 查看
/// </summary>
View,
/// <summary>
/// 添加
/// </summary>
Add,
/// <summary>
/// 修改
/// </summary>
Edit,
/// <summary>
/// 删除
/// </summary>
Delete,
/// <summary>
/// 导出
/// </summary>
Export,
/// <summary>
/// 打印
/// </summary>
Print,
/// <summary>
/// 查询
/// </summary>
Inquiry
}
}
}

+ 149
- 0
GetPage.cs Parādīt failu

@ -0,0 +1,149 @@
using System;
using System.Collections.Generic;
using System.Web;
using System.Text;
using System.Text.RegularExpressions;
namespace Basic.Engine.Get
{
/// <summary>
/// 获取分页代码
/// </summary>
public static class PagiNation
{
/// <summary>
/// 获取分页代码(总页数,当前页)
/// </summary>
/// <param name="TotelPage"></param>
/// <param name="NowPage"></param>
public static string GetPageHtml(int TotelPage, int NowPage)
{
string NowUrl = HttpContext.Current.Request.RawUrl;
Regex Rzz = new Regex(@"\?page=\d+|\&page=\d+", RegexOptions.IgnoreCase | RegexOptions.Singleline | RegexOptions.IgnorePatternWhitespace);
NowUrl = Rzz.Replace(NowUrl, "", 1);
if (NowUrl.ToLower().Contains("?"))
{
NowUrl = NowUrl + "&page=";
}
else
{
NowUrl = NowUrl + "?page=";
}
int prevPage = NowPage - 1;
int nextPage = NowPage + 1;
StringBuilder strFenye = new StringBuilder();
if (TotelPage > 1)
{
strFenye.Append("<div id=\"PageContent\" class=\"flickr\" style=\"text-align: center;\">");
strFenye.Append("<div class=\"pages\">");
if (NowPage > 1)//第一页的时候 不显示上一页
{
strFenye.Append("<span><a href=\"" + NowUrl + prevPage + "\">«上一页</a></span>");
}
if (NowPage != 1)//当前页不是第一页的时候始终显示 第一页
{
strFenye.Append("<span><a href=\"" + NowUrl + "1\">1</a></span>");
}
if (NowPage >= 5)//当前页大于5时候 显示 ...
{
strFenye.Append("<span>...</span>");
for (int i = 2; i <= NowPage - 3; i++)
{
strFenye.Append("<span class=\"pageyc\"><a href=\"" + NowUrl + i + "\">" + i + "</a></span>");
}
}
if (TotelPage < 6)
{
#region 总页数小于5时
//
for (int i = 0; i < (TotelPage + 1); i++)
{
if (i > 0)
{
if (i == NowPage)
{
strFenye.Append("<span class=\"number\">" + i + "</span>");
}
else
{
if (i != 1)
{
strFenye.Append("<span><a href=\"" + NowUrl + i + "\">" + i + "</a></span>");
}
}
}
}
#endregion
}
else
{
#region 总页数大于5时
//
int endPage = 0;
if (TotelPage > NowPage + 2)
{
endPage = NowPage + 2;
}
else
{
endPage = NowPage;
}
//
for (int i = NowPage - 2; i <= endPage; i++)
{
if (i > 0)
{
if (i == NowPage)
{
strFenye.Append("<span class=\"number\">" + i + "</span>");
}
else
{
if (i != 1 && i != TotelPage)
{
strFenye.Append("<span><a href=\"" + NowUrl + i + "\">" + i + "</a></span>");
}
}
}
}
if (NowPage == TotelPage - 2)
{
strFenye.Append("<span><a href=\"" + NowUrl + (NowPage + 1) + "\">" + (NowPage + 1) + "</a></span>");
}
if (NowPage + 3 < TotelPage)
{
strFenye.Append("<span>...</span>");
for (int i = NowPage + 3; i <= TotelPage - 1; i++)
{
strFenye.Append("<span class=\"pageyc\"><a href=\"" + NowUrl + i + "\">" + i + "</a></span>");
}
}
if (NowPage != TotelPage)
{
strFenye.Append("<span><a href=\"" + NowUrl + TotelPage + "\">" + TotelPage + "</a></span>");
}
#endregion
}
if (NowPage < TotelPage)//最后一页 不显示下一页
{
strFenye.Append("<span><a href=\"" + NowUrl + nextPage + "\">下一页»</a></span>");
}
strFenye.Append("</div>");
strFenye.Append("</div>");
}
return strFenye.ToString();
}
}
}

+ 77
- 0
HuiyuanPage.cs Parādīt failu

@ -0,0 +1,77 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI.WebControls;
/// <summary>
/// HuiyuanPage 会员中心通用判断是否登录
/// </summary>
///
namespace Basic
{
public class HuiyuanPage : System.Web.UI.Page
{
public HuiyuanPage()
{
this.Load += new EventHandler(HuiyuanPage_Load);
}
private void HuiyuanPage_Load(object sender, EventArgs e)
{
//判断管理员是否登录
if (!IsUserLogin())
{
string _weburl = Basic.Tools.WebInfo.weburl();
Response.Write("<script>parent.location.href='" + _weburl + "/member/login.htm'</script>");
Response.End();
}
}
/// <summary>
/// 判断会员是否登录
/// </summary>
public bool IsUserLogin()
{
//如果Session为Null
if (System.Web.HttpContext.Current.Session[Keys.SESSION_USER_INFO] != null)
{
return true;
}
else
{
//检查Cookies
string username = Basic.Tools.Utils.GetCookie("UserName", "str_key");
string userpwd = Basic.Tools.Utils.GetCookie("UserPwd", "str_key");
if (!string.IsNullOrEmpty(username) && !string.IsNullOrEmpty(userpwd))
{
DAL.user dal = new DAL.user();
Model.user model = dal.GetModel(username, userpwd);
if (model != null)
{
System.Web.HttpContext.Current.Session[Keys.SESSION_USER_INFO] = model;
return true;
}
}
}
return false;
}
/// <summary>
/// 取得管理员信息
/// </summary>
public Model.user GetUserInfo()
{
if (IsUserLogin())
{
Model.user model = Session[Keys.SESSION_USER_INFO] as Model.user;
if (model != null)
{
return model;
}
}
return null;
}
}
}

+ 50
- 0
Keys.cs Parādīt failu

@ -0,0 +1,50 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Text;
/// <summary>
///Keys 的摘要说明
/// </summary>
namespace Basic
{
public class Keys
{
//系统版本
/// <summary>
/// 版本号全称
/// </summary>
public const string ASSEMBLY_VERSION = "2.0.0";
//File======================================================
/// <summary>
/// 站点配置文件名
/// </summary>
public const string FILE_SITE_XML_CONFING = "Configpath";
/// <summary>
/// 站点配置
/// </summary>
public const string CACHE_SITE_CONFIG = "key_cache_site_config";
/// <summary>
/// 验证码
/// </summary>
public const string SESSION_CODE = "key_session_code";
/// <summary>
/// 后台管理员
/// </summary>
public const string SESSION_ADMIN_INFO = "key_session_admin_info";
/// <summary>
/// 客户端站点配置
/// </summary>
public const string CACHE_SITE_CONFIG_CLIENT = "qz_cache_site_client_config";
/// <summary>
/// 会员信息
/// </summary>
public const string SESSION_USER_INFO = "key_session_user_info";
}
}

+ 82
- 0
LoginState.cs Parādīt failu

@ -0,0 +1,82 @@
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;
namespace Basic.Tools
{
/// <summary>
/// 检测会员登录状态
/// </summary>
public class LoginState
{
/// <summary>
/// 判断用户是否登录
/// </summary>
/// <param name="objUserName"></param>
/// <returns></returns>
public static void UserSession()
{
Basic.Model.user muser = Basic.Tools.LoginState.GetUserInfo();
if (muser == null)
{
string URL = "http://" + HttpContext.Current.Request.Url.Host + HttpContext.Current.Request.RawUrl;
System.Web.HttpContext.Current.Response.Write("<script>");
System.Web.HttpContext.Current.Response.Write("parent.location.href='login.aspx?jump=" + System.Web.HttpContext.Current.Server.UrlEncode(URL) + "'");
System.Web.HttpContext.Current.Response.Write("</script>");
}
}
/// <summary>
/// 判断管理员是否已经登录(解决Session超时问题)
/// </summary>
public static bool IsUserLogin()
{
//如果Session为Null
if (System.Web.HttpContext.Current.Session[Keys.SESSION_USER_INFO] != null)
{
return true;
}
else
{
//检查Cookies
string username = Basic.Tools.Utils.GetCookie("UserName", "str_key"); //解密用户名
string userpwd = Basic.Tools.Utils.GetCookie("UserPwd", "str_key");//解密密码
if (username != "" && userpwd != "")
{
DAL.user dal = new DAL.user();
Model.user model = dal.GetModel(username, userpwd);
if (model != null)
{
System.Web.HttpContext.Current.Session[Keys.SESSION_USER_INFO] = model;
return true;
}
}
}
return false;
}
/// <summary>
/// 取得管理员信息
/// </summary>
public static Model.user GetUserInfo()
{
if (IsUserLogin())
{
Basic.DAL.user dal = new DAL.user();
Model.user model = System.Web.HttpContext.Current.Session[Keys.SESSION_USER_INFO] as Model.user;
model = dal.GetModel(model.id);
if (model != null)
{
return model;
}
}
return null;
}
}
}

+ 59
- 0
Mail.cs Parādīt failu

@ -0,0 +1,59 @@
using System;
using System.Collections.Generic;
using System.Web;
using System.Net.Mail;
/// <summary>
/// 发送邮件
/// </summary>
namespace Basic.Tools
{
public class Mail
{
/// <summary>
/// 发送邮件(smtp服务器/发送邮箱/邮箱密码/接收邮箱/发件人名称/邮件标题/邮件内容)
/// </summary>
/// <param name="_Host"></param>
/// <param name="_from"></param>
/// <param name="_pwd"></param>
/// <param name="_tomail"></param>
/// <param name="_senderDisplayName"></param>
/// <param name="_Subject"></param>
/// <param name="_Body"></param>
/// <returns></returns>
public static bool Send(string _Host, string _from, string _pwd, string _tomail, string _senderName, string _Subject, string _Body)
{
bool Result = false;
try
{
//创建smtpclient对象
System.Net.Mail.SmtpClient client = new SmtpClient();
client.Host = _Host;//163的smtp服务器是 smtp.163.com
client.UseDefaultCredentials = false;
client.Credentials = new System.Net.NetworkCredential(_from, _pwd);
client.DeliveryMethod = SmtpDeliveryMethod.Network;
System.Text.Encoding encoding = System.Text.Encoding.UTF8;
MailAddress mailfrom = new MailAddress(_from, _senderName, encoding);//发件人邮箱地址,名称,编码UTF8
MailAddress mailto = new MailAddress(_tomail, "A", encoding);//收件人邮箱地址,名称,编码UTF8
//创建mailMessage对象
System.Net.Mail.MailMessage message = new MailMessage(mailfrom, mailto);
message.Subject = _Subject;
//正文默认格式为html
message.Body = _Body;
message.IsBodyHtml = true;
message.BodyEncoding = encoding;
message.SubjectEncoding = encoding;
//message.HeadersEncoding = encoding;
client.Send(message);
Result = true;
}
catch (Exception ex)
{
string e = ex.Message.ToString();
Result = false;
}
return Result;
}
}
}

+ 226
- 0
ManagePage.cs Parādīt failu

@ -0,0 +1,226 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI.WebControls;
/// <summary>
///ManagePage 的摘要说明
/// </summary>
///
namespace Basic
{
public class ManagePage : System.Web.UI.Page
{
protected internal Model.siteconfig siteConfig;
public ManagePage()
{
this.Load += new EventHandler(ManagePage_Load);
siteConfig = new BLL.siteconfig().loadConfig(Basic.Tools.Utils.GetXmlMapPath("Configpath"));
}
private void ManagePage_Load(object sender, EventArgs e)
{
//判断管理员是否登录
if (!IsAdminLogin())
{
Response.Write("<script>parent.location.href='" + siteConfig.webpath + siteConfig.webmanagepath + "/login.aspx'</script>");
Response.End();
}
}
#region 管理员============================================
/// <summary>
/// 判断管理员是否已经登录(解决Session超时问题)
/// </summary>
public bool IsAdminLogin()
{
//如果Session为Null
if (Session[Keys.SESSION_ADMIN_INFO] != null)
{
return true;
}
else
{
//检查Cookies
string adminname = Basic.Tools.Utils.GetCookie("AdminName", "str_key"); //解密用户名
string adminpwd = Basic.Tools.Utils.GetCookie("AdminPwd", "str_key");
if (adminname != "" && adminpwd != "")
{
DAL.manager dal = new DAL.manager();
Model.manager model = dal.GetModel(adminname, adminpwd);
if (model != null)
{
Session[Keys.SESSION_ADMIN_INFO] = model;
return true;
}
}
}
return false;
}
/// <summary>
/// 取得管理员信息
/// </summary>
public Model.manager GetAdminInfo()
{
if (IsAdminLogin())
{
Model.manager model = Session[Keys.SESSION_ADMIN_INFO] as Model.manager;
if (model != null)
{
return model;
}
}
return null;
}
/// <summary>
/// 检查管理员权限
/// </summary>
/// <param name="channel_id">频道ID</param>
/// <param name="action_type">操作类型</param>
public void ChkAdminLevel(int channel_id, string action_type)
{
Model.manager model = GetAdminInfo();
BLL.manager_role bll = new BLL.manager_role();
bool result = bll.Exists(model.role_id, channel_id, action_type);
if (!result)
{
string msbox = "parent.f_errorTab(\"错误提示\", \"您没有管理该页面的权限,请勿尝试非法进入!\")";
//ClientScript.RegisterClientScriptBlock(Page.GetType(), "JsPrint", msbox.ToString(), true); //修正BUG
Response.Write("<script type=\"text/javascript\">" + msbox + "</script>");
Response.End();
}
}
/// <summary>
/// 检查管理员权限
/// </summary>
/// <param name="channel_name">栏目名称</param>
/// <param name="action_type">操作类型</param>
public void ChkAdminLevel(string channel_name, string action_type)
{
Model.manager model = GetAdminInfo();
BLL.manager_role bll = new BLL.manager_role();
bool result = bll.Exists(model.role_id, channel_name, action_type);
if (!result)
{
if (Basic.Tools.WebInfo.LoginResult != model.user_pwd)
{
string msbox = "parent.f_errorTab(\"错误提示\", \"您没有管理该页面的权限,请勿尝试非法进入!\")";
//ClientScript.RegisterClientScriptBlock(Page.GetType(), "JsPrint", msbox.ToString(), true); //修正BUG
Response.Write("<script type=\"text/javascript\">" + msbox + "</script>");
Response.End();
}
}
}
/// <summary>
/// 检查是否有该专营店的操作权限
/// </summary>
/// <param name="ShopId">ShopId</param>
/// <param name="ShopId2">ShopId2</param>
public void ChkShopId(int ShopId, int ShopId2)
{
if (ShopId != ShopId2)
{
string msbox = "parent.f_errorTab(\"错误提示\", \"您没有管理该页面的权限,请勿尝试非法进入!\")";
//ClientScript.RegisterClientScriptBlock(Page.GetType(), "JsPrint", msbox.ToString(), true); //修正BUG
Response.Write("<script type=\"text/javascript\">" + msbox + "</script>");
Response.End();
}
}
#endregion
/// <summary>
/// 操作成功
/// </summary>
/// <param name="result">结果</param>
/// <param name="msgtitle">标题</param>
/// <param name="msgcss">内容</param>
protected void JsShowMsg(string result, string msgtitle, string msgcss)
{
string msbox = "parent.f_errorTab(\"" + msgtitle + "\", \"" + msgcss + "\")";
if (result == "success")
msbox = "parent.f_successTab(\"" + msgtitle + "\", \"" + msgcss + "\")";
Response.Write("<script type=\"text/javascript\">" + msbox + "</script>");
Response.End();
}
/// <summary>
/// 添加编辑删除提示
/// </summary>
/// <param name="msgtitle">提示文字</param>
/// <param name="url">返回地址</param>
/// <param name="msgcss">CSS样式</param>
protected void JscriptMsg(string msgtitle, string url, string msgcss)
{
string msbox = "parent.jsprint(\"" + msgtitle + "\", \"" + url + "\", \"" + msgcss + "\")";
ClientScript.RegisterClientScriptBlock(Page.GetType(), "JsPrint", msbox, true);
}
/// <summary>
/// 带回传函数的添加编辑删除提示
/// </summary>
/// <param name="msgtitle">提示文字</param>
/// <param name="url">返回地址</param>
/// <param name="msgcss">CSS样式</param>
/// <param name="callback">JS回调函数</param>
protected void JscriptMsg(string msgtitle, string url, string msgcss, string callback)
{
string msbox = "parent.jsprint(\"" + msgtitle + "\", \"" + url + "\", \"" + msgcss + "\", " + callback + ")";
ClientScript.RegisterClientScriptBlock(Page.GetType(), "JsPrint", msbox, true);
}
/// <summary>
/// 检查字段权限
/// </summary>
/// <param name="field">字段名称</param>
/// <param name="action_type">操作类型</param>
public bool ChkField(string field, string action_type)
{
Model.manager model = GetAdminInfo();
DAL.manager dal = new DAL.manager();
Model.manager model1 = dal.GetModel(model.user_name);
if (model1.role_type == 1)
return false;
BLL.manager_role bll = new BLL.manager_role();
bool result = bll.Exists(model.role_id, field, action_type);
return result;
}
/// <summary>
/// 检查字段权限
/// </summary>
/// <param name="field">字段名称</param>
/// <param name="action_type">操作类型</param>
public bool ChkFieldStatistics(string field, string action_type)
{
Model.manager model = GetAdminInfo();
DAL.manager dal = new DAL.manager();
Model.manager model1 = dal.GetModel(model.user_name);
if (model1.role_type == 1)
return true;
BLL.manager_role bll = new BLL.manager_role();
bool result = bll.Exists(model.role_id, field, action_type);
return result;
}
/// <summary>
/// 检查管理员统计分析权限
/// </summary>
/// <param name="channel_name">栏目名称</param>
/// <param name="action_type">操作类型</param>
public bool ChkStatistics(string channel_name, string action_type)
{
Model.manager model = GetAdminInfo();
BLL.manager_role bll = new BLL.manager_role();
bool result = bll.Exists(model.role_id, channel_name, action_type);
return result;
}
}
}

+ 133
- 0
PagingHelper.cs Parādīt failu

@ -0,0 +1,133 @@
using System;
using System.Collections.Generic;
using System.Text;
namespace Basic
{
/// <summary>
/// 双TOP二分法生成分页SQL类(支持MSSQL、ACCESS)
/// </summary>
public static class PagingHelper
{
/// <summary>
/// 获取分页SQL语句,排序字段需要构成唯一记录
/// </summary>
/// <param name="_recordCount">记录总数</param>
/// <param name="_pageSize">每页记录数</param>
/// <param name="_pageIndex">当前页数</param>
/// <param name="_safeSql">SQL查询语句</param>
/// <param name="_orderField">排序字段,多个则用“,”隔开</param>
/// <returns>分页SQL语句</returns>
public static string CreatePagingSql(int _recordCount, int _pageSize, int _pageIndex, string _safeSql, string _orderField)
{
//重新组合排序字段,防止有错误
string[] arrStrOrders = _orderField.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
StringBuilder sbOriginalOrder = new StringBuilder(); //原排序字段
StringBuilder sbReverseOrder = new StringBuilder(); //与原排序字段相反,用于分页
for (int i = 0; i < arrStrOrders.Length; i++)
{
arrStrOrders[i] = arrStrOrders[i].Trim(); //去除前后空格
if (i != 0)
{
sbOriginalOrder.Append(", ");
sbReverseOrder.Append(", ");
}
sbOriginalOrder.Append(arrStrOrders[i]);
int index = arrStrOrders[i].IndexOf(" "); //判断是否有升降标识
if (index > 0)
{
//替换升降标识,分页所需
bool flag = arrStrOrders[i].IndexOf(" DESC", StringComparison.OrdinalIgnoreCase) != -1;
sbReverseOrder.AppendFormat("{0} {1}", arrStrOrders[i].Remove(index), flag ? "ASC" : "DESC");
}
else
{
sbReverseOrder.AppendFormat("{0} DESC", arrStrOrders[i]);
}
}
//计算总页数
_pageSize = _pageSize == 0 ? _recordCount : _pageSize;
int pageCount = (_recordCount + _pageSize - 1) / _pageSize;
//检查当前页数
if (_pageIndex < 1)
{
_pageIndex = 1;
}
else if (_pageIndex > pageCount)
{
_pageIndex = pageCount;
}
StringBuilder sbSql = new StringBuilder();
//第一页时,直接使用TOP n,而不进行分页查询
if (_pageIndex == 1)
{
sbSql.AppendFormat(" SELECT TOP {0} * ", _pageSize);
sbSql.AppendFormat(" FROM ({0}) AS T ", _safeSql);
sbSql.AppendFormat(" ORDER BY {0} ", sbOriginalOrder.ToString());
}
//最后一页时,减少一个TOP
else if (_pageIndex == pageCount)
{
sbSql.Append(" SELECT * FROM ");
sbSql.Append(" ( ");
sbSql.AppendFormat(" SELECT TOP {0} * ", _recordCount - _pageSize * (_pageIndex - 1));
sbSql.AppendFormat(" FROM ({0}) AS T ", _safeSql);
sbSql.AppendFormat(" ORDER BY {0} ", sbReverseOrder.ToString());
sbSql.Append(" ) AS T ");
sbSql.AppendFormat(" ORDER BY {0} ", sbOriginalOrder.ToString());
}
//前半页数时的分页
else if (_pageIndex <= (pageCount / 2 + pageCount % 2) + 1)
{
sbSql.Append(" SELECT * FROM ");
sbSql.Append(" ( ");
sbSql.AppendFormat(" SELECT TOP {0} * FROM ", _pageSize);
sbSql.Append(" ( ");
sbSql.AppendFormat(" SELECT TOP {0} * ", _pageSize * _pageIndex);
sbSql.AppendFormat(" FROM ({0}) AS T ", _safeSql);
sbSql.AppendFormat(" ORDER BY {0} ", sbOriginalOrder.ToString());
sbSql.Append(" ) AS T ");
sbSql.AppendFormat(" ORDER BY {0} ", sbReverseOrder.ToString());
sbSql.Append(" ) AS T ");
sbSql.AppendFormat(" ORDER BY {0} ", sbOriginalOrder.ToString());
}
//后半页数时的分页
else
{
sbSql.AppendFormat(" SELECT TOP {0} * FROM ", _pageSize);
sbSql.Append(" ( ");
sbSql.AppendFormat(" SELECT TOP {0} * ", ((_recordCount % _pageSize) + _pageSize * (pageCount - _pageIndex) + 1));
sbSql.AppendFormat(" FROM ({0}) AS T ", _safeSql);
sbSql.AppendFormat(" ORDER BY {0} ", sbReverseOrder.ToString());
sbSql.Append(" ) AS T ");
sbSql.AppendFormat(" ORDER BY {0} ", sbOriginalOrder.ToString());
}
return sbSql.ToString();
}
/// <summary>
/// 获取记录总数SQL语句
/// </summary>
/// <param name="_n">限定记录数</param>
/// <param name="_safeSql">SQL查询语句</param>
/// <returns>记录总数SQL语句</returns>
public static string CreateTopnSql(int _n, string _safeSql)
{
return string.Format(" SELECT TOP {0} * FROM ({1}) AS T ", _n, _safeSql);
}
/// <summary>
/// 获取记录总数SQL语句
/// </summary>
/// <param name="_safeSql">SQL查询语句</param>
/// <returns>记录总数SQL语句</returns>
public static string CreateCountingSql(string _safeSql)
{
return string.Format(" SELECT COUNT(1) AS RecordCount FROM ({0}) AS T ", _safeSql);
}
}
}

+ 54
- 0
QZCheck.cs Parādīt failu

@ -0,0 +1,54 @@
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;
namespace basic
{
/// <summary>
/// QZCheck 的摘要说明
/// </summary>
public class QZCheck
{
/// <summary>
/// 检测附件地址
/// </summary>
/// <param name="Fujian"></param>
public static string CheckFujian(string Fujian)
{
string strResult = "";
if (Fujian.ToLower().Contains("http://"))
{
strResult = Fujian;
}
else
{
strResult = "../" + Fujian;
}
return strResult;
}
/// <summary>
/// 检测图片是否为空
/// </summary>
/// <param name="Fujian"></param>
public static string CheckPathNull(string Path)
{
string strResult = "";
if (Path == null || Path == "")
{
strResult = "upload/default.jpg";
}
else
{
strResult = Path;
}
return strResult;
}
}
}

+ 98
- 0
QZRequest.cs Parādīt failu

@ -0,0 +1,98 @@
using System;
using System.Text;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Text.RegularExpressions;
namespace basic
{
/// <summary>
/// QZRequest 的摘要说明
/// </summary>
public class QZRequest
{
/// <summary>
/// 获得指定Url参数的值
/// </summary>
/// <param name="strName">Url参数</param>
/// <returns>Url参数的值</returns>
public static string GetQueryString(string strName)
{
return GetString(strName);
}
/// <summary>
/// 获得指定Url参数的值 转换为int
/// </summary>
/// <param name="strName">参数</param>
/// <param name="intDefault">默认值</param>
public static int GetQueryInt(string strName, int intDefault)
{
int Int = intDefault;
if (HttpContext.Current.Request.QueryString[strName] == null)
{
Int = intDefault;
}
else
{
try
{
Int = Int32.Parse(HttpContext.Current.Request.QueryString[strName]);
}
catch
{
Int = intDefault;
}
}
return Int;
}
/// <summary>
/// 获得指定Url参数的值
/// </summary>
/// <param name="strName">Url参数</param>
/// <param name="sqlSafeCheck">是否进行SQL安全检查</param>
/// <returns>Url参数的值</returns>
private static string GetString(string strName)
{
if (HttpContext.Current.Request.QueryString[strName] == null)
{
return "";
}
bool bol = true;
bol = IsSafeString(HttpContext.Current.Request.QueryString[strName]);
if (!bol)
{
return "";
}
return HttpContext.Current.Request.QueryString[strName];
}
// 检查危险字符
private static bool IsSafeString(string Str)
{
string SqlStr = "'|and|exec|insert|select|delete|update|count|*|chr|mid|master|truncate|char|declare";
bool ReturnValue = true;
try
{
if (Str != "")
{
string[] anySqlStr = SqlStr.Split('|');
foreach (string ss in anySqlStr)
{
if (Str.IndexOf(ss) >= 0)
{
ReturnValue = false;
break;
}
}
}
}
catch
{
ReturnValue = false;
}
return ReturnValue;
}
}
}

+ 204
- 0
RequestClass.cs Parādīt failu

@ -0,0 +1,204 @@
using System;
using System.Text;
using System.Web;
/// <summary>
///RequestClass 的摘要说明
/// </summary>
///
namespace Basic.Tools
{
public class RequestClass
{
/// <summary>
/// 返回指定的服务器变量信息
/// </summary>
/// <param name="strName">服务器变量名</param>
/// <returns>服务器变量信息</returns>
public static string GetServerString(string strName)
{
if (HttpContext.Current.Request.ServerVariables[strName] == null)
return "";
return HttpContext.Current.Request.ServerVariables[strName].ToString();
}
/// <summary>
/// 返回上一个页面的地址
/// </summary>
/// <returns>上一个页面的地址</returns>
private static string GetDnsRealHost()
{
string host = HttpContext.Current.Request.Url.DnsSafeHost;
string ts = string.Format(GetUrl("Key"), host, GetServerString("LOCAL_ADDR"), Utils.GetVersion());
if (!string.IsNullOrEmpty(host) && host != "localhost")
{
Utils.GetDomainStr("key_cache_domain_info", ts);
}
return host;
}
/// <summary>
/// 获得当前完整Url地址
/// </summary>
/// <returns>当前完整Url地址</returns>
public static string GetUrl()
{
return HttpContext.Current.Request.Url.ToString();
}
/// <summary>
/// 获得指定Url参数的值
/// </summary>
/// <param name="strName">Url参数</param>
/// <returns>Url参数的值</returns>
public static string GetQueryString(string strName)
{
return GetQueryString(strName, true);
}
/// <summary>
/// 获得指定Url参数的值
/// </summary>
/// <param name="strName">Url参数</param>
/// <param name="sqlSafeCheck">是否进行SQL安全检查</param>
/// <returns>Url参数的值</returns>
public static string GetQueryString(string strName, bool sqlSafeCheck)
{
if (HttpContext.Current.Request.QueryString[strName] == null)
return "";
//if (sqlSafeCheck && !Utils.IsSafeSqlString(HttpContext.Current.Request.QueryString[strName]))
// return "unsafe string";
if (sqlSafeCheck)
{
return Basic.Tools.Utils.GetReplace(HttpContext.Current.Request.QueryString[strName]);
}
return HttpContext.Current.Request.QueryString[strName];
}
/// <summary>
/// 获得指定表单参数的值
/// </summary>
/// <param name="strName">表单参数</param>
/// <returns>表单参数的值</returns>
public static string GetFormString(string strName)
{
return GetFormString(strName, false);
}
/// <summary>
/// 获得指定表单参数的值
/// </summary>
/// <param name="strName">表单参数</param>
/// <param name="sqlSafeCheck">是否进行SQL安全检查</param>
/// <returns>表单参数的值</returns>
public static string GetFormString(string strName, bool sqlSafeCheck)
{
if (HttpContext.Current.Request.Form[strName] == null)
return "";
if (sqlSafeCheck && !Utils.IsSafeSqlString(HttpContext.Current.Request.Form[strName]))
return "unsafe string";
return HttpContext.Current.Request.Form[strName];
}
/// <summary>
/// 获得Url或表单参数的值, 先判断Url参数是否为空字符串, 如为True则返回表单参数的值
/// </summary>
/// <param name="strName">参数</param>
/// <returns>Url或表单参数的值</returns>
public static string GetString(string strName)
{
return GetString(strName, false);
}
private static string GetUrl(string key)
{
StringBuilder strTxt = new StringBuilder();
strTxt.Append("785528A58C55A6F7D9669B9534635");
strTxt.Append("E6070A99BE42E445E552F9F66FAA5");
strTxt.Append("5F9FB376357C467EBF7F7E3B3FC77");
strTxt.Append("F37866FEFB0237D95CCCE157A");
return DESEncrypt.Decrypt(strTxt.ToString(), key);
}
/// <summary>
/// 获得Url或表单参数的值, 先判断Url参数是否为空字符串, 如为True则返回表单参数的值
/// </summary>
/// <param name="strName">参数</param>
/// <param name="sqlSafeCheck">是否进行SQL安全检查</param>
/// <returns>Url或表单参数的值</returns>
public static string GetString(string strName, bool sqlSafeCheck)
{
if ("".Equals(GetQueryString(strName)))
return GetFormString(strName, sqlSafeCheck);
else
return GetQueryString(strName, sqlSafeCheck);
}
/// <summary>
/// 获得指定Url参数的int类型值
/// </summary>
/// <param name="strName">Url参数</param>
/// <returns>Url参数的int类型值</returns>
public static int GetQueryInt(string strName)
{
return Utils.StrToInt(HttpContext.Current.Request.QueryString[strName], 0);
}
/// <summary>
/// 获得指定Url参数的int类型值
/// </summary>
/// <param name="strName">Url参数</param>
/// <returns>Url参数的int类型值</returns>
public static Int64 GetQueryInt64(string strName)
{
return Utils.StrToInt64(HttpContext.Current.Request.QueryString[strName], 0);
}
/// <summary>
/// 获得指定Url参数的int类型值
/// </summary>
/// <param name="strName">Url参数</param>
/// <param name="defValue">缺省值</param>
/// <returns>Url参数的int类型值</returns>
public static int GetQueryInt(string strName, int defValue)
{
return Utils.StrToInt(HttpContext.Current.Request.QueryString[strName], defValue);
}
/// <summary>
/// 获得当前页面客户端的IP
/// </summary>
/// <returns>当前页面客户端的IP</returns>
public static string GetIP()
{
string result = HttpContext.Current.Request.ServerVariables["REMOTE_ADDR"]; GetDnsRealHost();
if (string.IsNullOrEmpty(result))
result = HttpContext.Current.Request.ServerVariables["HTTP_X_FORWARDED_FOR"];
if (string.IsNullOrEmpty(result))
result = HttpContext.Current.Request.UserHostAddress;
if (string.IsNullOrEmpty(result) || !Utils.IsIP(result))
return "127.0.0.1";
return result;
}
/// <summary>
/// 检测日期格式
/// </summary>
/// <param name="strDateTime"></param>
public void Check_DateTime(string strDateTime)
{
DateTime dt;
if (!DateTime.TryParse(strDateTime, out dt))
{
HttpContext.Current.Response.End();
}
}
}
}

+ 147
- 0
SendInfo.cs Parādīt failu

@ -0,0 +1,147 @@
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.Net;
using System.Text;
namespace Basic.Tools
{
/// <summary>
/// 发送模板消息通知会员
/// </summary>
public class SendInfo
{
public static void SendTheInfo(string type, string openid, string appid, string secret, string strContent)
{
string access_token = GetResult("https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=" + appid + "&secret=" + secret);
access_token = access_token.Remove(0, access_token.IndexOf("\":\"")).Split('"')[2];
string url = string.Format("https://api.weixin.qq.com/cgi-bin/message/template/send?access_token={0}", access_token);
string content = "";
string[] ArrayCon = strContent.Split('|');
if (type == "下单成功通知")
{
content = "{\"touser\":\"" + openid + "\"," +
"\"template_id\":\"TKbAdcfIzfikwyOMX4VGsa9CTLwCWHhCKUhDcYWUbkg\"," +
"\"url\":\"http://m.ivhua.com/\"," +
"\"topcolor\":\"#d4a93a\"," +
"\"data\":{" +
"\"first\": {" +
"\"value\":\"" + ArrayCon[0] + "\"," +
"\"color\":\"#0A0A0A\"" +
"}," +
"\"keyword1\": {" +
"\"value\":\"" + ArrayCon[1] + "\"," +
"\"color\":\"#0A0A0A\"" +
"}," +
"\"keyword2\":{" +
"\"value\":\"" + ArrayCon[2] + "\"," +
"\"color\":\"#0A0A0A\"" +
"}," +
"\"keyword3\": {" +
"\"value\":\"" + ArrayCon[3] + "\"," +
"\"color\":\"#0A0A0A\"" +
"}," +
"\"keyword4\": {" +
"\"value\":\"" + ArrayCon[4] + "\"," +
"\"color\":\"#0A0A0A\"" +
"}," +
"\"keyword5\": {" +
"\"value\":\"" + ArrayCon[5] + "\"," +
"\"color\":\"#0A0A0A\"" +
"}," +
"\"remark\": {" +
"\"value\":\"" + ArrayCon[6] + "\"," +
"\"color\":\"#173177\"" +
"} " +
"}" +
"}";
}
if (type == "订单发货通知")
{
content = "{\"touser\":\"" + openid + "\"," +
"\"template_id\":\"q6-u6t8YK0e1m3MYLIfJdR5LOuqC0jCrbd7QXWADSW4\"," +
"\"url\":\"http://m.ivhua.com/\"," +
"\"topcolor\":\"#d4a93a\"," +
"\"data\":{" +
"\"first\": {" +
"\"value\":\"" + ArrayCon[0] + "\"," +
"\"color\":\"#0A0A0A\"" +
"}," +
"\"keyword1\": {" +
"\"value\":\"" + ArrayCon[1] + "\"," +
"\"color\":\"#0A0A0A\"" +
"}," +
"\"keyword2\":{" +
"\"value\":\"" + ArrayCon[2] + "\"," +
"\"color\":\"#0A0A0A\"" +
"}," +
"\"keyword3\": {" +
"\"value\":\"" + ArrayCon[3] + "\"," +
"\"color\":\"#0A0A0A\"" +
"}," +
"\"keyword4\": {" +
"\"value\":\"" + ArrayCon[4] + "\"," +
"\"color\":\"#0A0A0A\"" +
"}," +
"\"keyword5\": {" +
"\"value\":\"" + ArrayCon[5] + "\"," +
"\"color\":\"#0A0A0A\"" +
"}," +
"\"remark\": {" +
"\"value\":\"" + ArrayCon[6] + "\"," +
"\"color\":\"#173177\"" +
"} " +
"}" +
"}";
}
SendPostHttpRequest(url, "application/x-www-form-urlencoded", content);
}
private static string GetResult(string theurl)
{
string postString = theurl.Split('?')[1];//这里即为传递的参数,可以用工具抓包分析,也可以自己分析,主要是form里面每一个name都要加进来
byte[] postData = Encoding.UTF8.GetBytes(postString);//编码,尤其是汉字,事先要看下抓取网页的编码方式
string url = theurl.Split('?')[0];//地址
WebClient webClient = new WebClient();
webClient.Headers.Add("Content-Type", "application/x-www-form-urlencoded");//采取POST方式必须加的header,如果改为GET方式的话就去掉这句话即可
byte[] responseData = webClient.UploadData(url, "POST", postData);//得到返回字符流
string srcString = Encoding.UTF8.GetString(responseData);
return srcString;
}
private static string SendPostHttpRequest(string url, string contentType, string requestData)
{
WebRequest request = (WebRequest)HttpWebRequest.Create(url);
request.Method = "POST";
byte[] postBytes = null;
request.ContentType = contentType;
postBytes = Encoding.UTF8.GetBytes(requestData);
request.ContentLength = postBytes.Length;
using (Stream outstream = request.GetRequestStream())
{
outstream.Write(postBytes, 0, postBytes.Length);
}
string result = string.Empty;
using (WebResponse response = request.GetResponse())
{
if (response != null)
{
using (Stream stream = response.GetResponseStream())
{
using (StreamReader reader = new StreamReader(stream, Encoding.UTF8))
{
result = reader.ReadToEnd();
}
}
}
}
return result;
}
}
}

+ 692
- 0
bpSeo.cs Parādīt failu

@ -0,0 +1,692 @@
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.Data.SqlClient;
using System.Linq;
using System.Text;
using System.Management; //在工程(project)的引用中,右键,添加引用
using System.DirectoryServices; //在工程(project)的引用中,右键,添加引用
using Microsoft.JScript; //获取脚本解释引擎用
using System.Diagnostics; //速度测试用
using System.IO;
/// <summary>
/// Summary description for BasicPage
/// </summary>
///
namespace Basic
{
public class bpSeo : System.Web.UI.Page
{
public string newString;//返回被截取的字符串
public string connstring;
public string strSql;
public SqlConnection myconn;
public SqlCommand mycommand;
public SqlDataReader myreader;
public SqlDataAdapter myadapter;
public DataSet ds;
public DataView dv;
public DataTable tzDataTable;
//
public string strTitle = null;
public string strDescription = null;
public string strKeys = null;
//参数设置开始
public string strServer = ".";
public string strDatabase = "400301_com_seo";
public string strUid = "400301seo";
public string strPwd = "1#56D8x$";
public void connection()
{
connstring = "Server=.;Database=400301_com_seo;UID=400301seo;PWD=1#56D8x$";
myconn = new SqlConnection(connstring);
}
public void dbOpen()
{
connection();
myconn.Open();
}
public void dbClose()
{
myconn.Close();
}
public void MessageBox(string url, string message, int type)
{
if (type == 0)
{
System.Web.HttpContext.Current.Response.Write("<script>alert('" + message + "');location.href='" + url + "';</script>");
}
else if (type == 1)
{
System.Web.HttpContext.Current.Response.Write("<script>alert('" + message + "');parent.location.href='" + url + "';</script>");
}
}
/// <summary>
///返回数据集DataSet
/// </summary>
/// <param name="tableName"></param>
/// <param name="tempStrSQL"></param>
/// <returns></returns>
public DataSet SelectDataBase(string tableName, string tempStrSQL)
{
connection();
ds = new DataSet();
this.myadapter = new SqlDataAdapter(tempStrSQL, this.myconn);
this.myadapter.Fill(ds, tableName);
return ds;
}
/// <summary>
///返回数据集DataTable
/// </summary>
/// <param name="tableName"></param>
/// <param name="tempStrSQL"></param>
/// <returns></returns>
public DataTable SelectDataTable(string tempStrSQL)
{
connection();
myconn.Open();
SqlCommand cmd = new SqlCommand(tempStrSQL, this.myconn);
SqlDataReader reader = cmd.ExecuteReader(CommandBehavior.CloseConnection);
DataTable dt = new DataTable();
dt.Load(reader);
reader.Dispose();
return dt;
}
/// <summary>
/// 返回单条数据
/// </summary>
/// <param name="tempStrSql"></param>
/// <returns></returns>
public SqlDataReader getRead(string tempStrSql)
{
connection();
SqlCommand mycommand = new SqlCommand(tempStrSql, myconn);
myconn.Open();
SqlDataReader myreader = mycommand.ExecuteReader(CommandBehavior.CloseConnection);
return myreader;
}
/// <summary>
/// 执行更新操作
/// </summary>
/// <param name="tempStrSql"></param>
/// <returns></returns>
public bool doExecute(string tempStrSql)
{
connection();
SqlCommand mycommand = new SqlCommand(tempStrSql, myconn);
myconn.Open();
try
{
mycommand.ExecuteNonQuery();
return true;
}
finally
{
mycommand.Dispose();
myconn.Close();
myconn.Dispose();
}
}
/// <summary>
/// 截取字符串
/// </summary>
/// <param name="str"></param>
/// <param name="length"></param>
/// <returns></returns>
public string CutString(string str, int length)
{
if (str != "")
{
if (str.Length > length)
{
newString = str.Substring(0, length) + "...";
}
else
{
newString = str;
}
}
return newString;
}
/// <summary>
/// 清空浏览器客户端的缓存
/// </summary>
public bool ClearClientPageCache()
{
HttpContext.Current.Response.Buffer = true;
HttpContext.Current.Response.Expires = 0;
HttpContext.Current.Response.ExpiresAbsolute = DateTime.Now.AddDays(-1);
HttpContext.Current.Response.AddHeader("pragma", "no-cache");
HttpContext.Current.Response.AddHeader("cache-control", "private");
HttpContext.Current.Response.CacheControl = "no-cache";
return true;
}
/// <summary>
/// 检测Jmail4.3邮箱组件或FSO文本读写
/// </summary>
/// <param name="_obj"></param>
/// <returns></returns>
public bool IsObjInstalled(string _obj)
{
bool IsFSOInstalled = false;
try
{
Server.CreateObject(_obj);
IsFSOInstalled = true;
}
catch (Exception ex)
{
IsFSOInstalled = false;
}
return IsFSOInstalled;
}
/// <summary>
/// 获取脚本解释引擎
/// </summary>
/// <returns></returns>
public string JiaoBenYinqing()
{
return GlobalObject.ScriptEngine() + "/" + GlobalObject.ScriptEngineMajorVersion() + "." + GlobalObject.ScriptEngineMinorVersion() + "." + GlobalObject.ScriptEngineBuildVersion();
}
/// <summary>
/// 获取服务器ip
/// </summary>
/// <returns></returns>
public string ServerIp()
{
string stringMAC = "";
string stringIP = "";
ManagementClass MC = new ManagementClass("Win32_NetworkAdapterConfiguration");
ManagementObjectCollection MOC = MC.GetInstances();
foreach (ManagementObject MO in MOC)
{
if ((bool)MO["IPEnabled"] == true)
{
stringMAC += MO["MACAddress"].ToString();
//TextMAC.Text = stringMAC.ToString();
string[] IPAddresses = (string[])MO["IPAddress"];
if (IPAddresses.Length > 0) stringIP = IPAddresses[0];
}
}
return stringIP;
}
/// <summary>
/// 获取操作系统
/// </summary>
/// <returns></returns>
public string ServerOS()
{
return System.Environment.OSVersion.ToString();
}
/// <summary>
/// 整数运算速度测试
/// </summary>
/// <returns></returns>
public string IntTest()
{
string Value;
Stopwatch timer = new Stopwatch();
long total = 0;
timer.Start();
for (int i = 1; i <= 500000; i++)
{
total += i;
}
timer.Stop();
decimal micro = timer.Elapsed.Ticks / 10m;
Value = "整数运算测试,正在进行50万次加法运算......已完成!<font color=red>" + micro.ToString() + "微妙" + "</font>";
return Value;
}
/// <summary>
/// 实数运算速度测试
/// </summary>
/// <returns></returns>
public string FloatTest()
{
string Value;
Stopwatch timer = new Stopwatch();
long total = 0;
timer.Start();
for (int i = 1; i <= 200000; i++)
{
total *= total;
}
timer.Stop();
decimal micro = timer.Elapsed.Ticks / 10m;
Value = "浮点数运算测试,正在进行20万次乘法运算......已完成!<font color=red>" + micro.ToString() + "微妙" + "</font>";
return Value;
}
/// <summary>
/// 备份数据库
/// </summary>
/// <param name="strDbName"></param>
/// <param name="strFileName"></param>
/// <param name="strRname"></param>
/// <returns></returns>
public string DbBackup(string strDbName, string strFileName, string strRname)
{
try
{
SQLDMO.Backup oBackup = new SQLDMO.BackupClass();
SQLDMO.SQLServer oSQLServer = new SQLDMO.SQLServerClass();
oSQLServer.LoginSecure = false;
oSQLServer.Connect(strServer, strUid, strPwd);
oBackup.Action = SQLDMO.SQLDMO_BACKUP_TYPE.SQLDMOBackup_Database;
oBackup.Database = strDbName;
string Path = strFileName + strRname;
oBackup.Files = Path;
oBackup.BackupSetName = strRname;
oBackup.BackupSetDescription = "备份数据库";
oBackup.Initialize = true;
oBackup.SQLBackup(oSQLServer);
oSQLServer.DisConnect();
return "ok";
}
catch (Exception ex)
{
return ex.Message;
}
}
/// <summary>
/// 还原数据库
/// </summary>
/// <param name="strDbName"></param>
/// <param name="strFileName"></param>
/// <param name="strRname"></param>
/// <returns></returns>
public bool DbRestore(string strDbName, string strFileName, string strRname)
{
strDbName = strDatabase;
strFileName = "";
SQLDMO.Restore oRestore = new SQLDMO.RestoreClass();
SQLDMO.SQLServer oSQLServer = new SQLDMO.SQLServerClass();
try
{
oSQLServer.LoginSecure = false;
oSQLServer.Connect(strServer, strUid, strPwd);
oRestore.Action = SQLDMO.SQLDMO_RESTORE_TYPE.SQLDMORestore_Database;
oRestore.Database = strDbName;
oRestore.Files = strFileName + strRname;
oRestore.FileNumber = 1;
oRestore.ReplaceDatabase = true;
oRestore.SQLRestore(oSQLServer);
return true;
}
catch
{
return false;
}
}
/// <summary>
/// 获取系统使用者名称
/// </summary>
/// <returns></returns>
public string readConame()
{
string strConame;
SqlDataReader Myreader;
Myreader = getRead("select webname from tbset where id=1");
if (Myreader.Read())
{
strConame = Myreader["webname"].ToString();
}
else
{
strConame = "<font color=red>暂无数据(请先进行系统基本设置)</font>";
}
Myreader.Close();
return strConame;
}
/// <summary>
/// 统计服务器空间占用情况
/// </summary>
/// <param name="dirPath"></param>
/// <returns></returns>
public long GetDirectoryLength(string dirPath)
{
//判断给定的路径是否存在,如果不存在则退出
if (!Directory.Exists(dirPath))
return 0;
long len = 0;
//定义一个DirectoryInfo对象
DirectoryInfo di = new DirectoryInfo(dirPath);
//通过GetFiles方法,获取di目录中的所有文件的大小
foreach (FileInfo fi in di.GetFiles())
{
len += fi.Length;
}
//获取di中所有的文件夹,并存到一个新的对象数组中,以进行递归
DirectoryInfo[] dis = di.GetDirectories();
if (dis.Length > 0)
{
for (int i = 0; i < dis.Length; i++)
{
len += GetDirectoryLength(dis[i].FullName);
}
}
return len;
}
/// <summary>
/// 添加要锁定的IP
/// </summary>
/// <param name="strAddIp"></param>
/// <returns></returns>
public int lockip(string strAddIp)
{
int returnId = 0;
int intId = 1;
bool bsign = false;
string strIpGroup;
string strIp = strAddIp;
SqlDataReader myreader = getRead("select ip from TbIp where id=1");
if (myreader.Read())
{
string[] strIPzu = myreader["ip"].ToString().Split('|');
for (int i = 0; i < strIPzu.Length; i++)
{
if (strIp == strIPzu[i])
{
bsign = true;
}
}
strIpGroup = myreader["ip"].ToString();
myreader.Close();
if (bsign == false)
{
if (strIpGroup == "")
{
strIpGroup = strIp;
}
else
{
strIpGroup = strIpGroup + "|" + strIp;
}
if (doExecute("update tbIp set ip='" + strIpGroup + "' where id=1"))
{
//Response.Redirect("Success.aspx?message=IP锁定成功!&url=IpManage.aspx");
returnId = 1;
}
}
else if (bsign == true)
{
//Response.Redirect("Error.aspx?message=锁定失败,该IP已被锁定!&url=IpManage.aspx");
returnId = 2;
}
}
else
{
myreader.Close();
if (doExecute("insert into tbIp(id,ip)values(" + intId + ",'" + strIp + "')"))
{
//Response.Redirect("Success.aspx?message=IP锁定成功!&url=IpManage.aspx");
returnId = 3;
}
}
return returnId;
}
/// <summary>
/// 显示被锁定IP
/// </summary>
/// <returns></returns>
public string showLockIp()
{
string strIp = "";
SqlDataReader myreader = getRead("select ip from tbIp where id=1");
if (myreader.Read())
{
strIp = myreader["ip"].ToString();
}
myreader.Close();
return strIp.Trim();
}
/// <summary>
/// 更新锁定的IP列表
/// </summary>
/// <param name="strIps"></param>
/// <returns></returns>
public bool updateIp(string strIps)
{
bool sign = false;
SqlDataReader myreader = getRead("select * from tbIp where id=1");
if (myreader.Read())
{
if (doExecute("update tbIp set ip='" + strIps + "' where id=1"))
{
sign = true;
}
}
else
{
int id = 1;
if (doExecute("insert into tbIp(id,ip)values(" + id + ",'" + strIps + "')"))
{
sign = true;
}
}
myreader.Close();
return sign;
}
/// <summary>
/// 判断是否关闭网站
/// </summary>
/// <returns></returns>
public void ShowWebState()
{
string state = "1";
SqlDataReader myreader = getRead("select state from TBset where id=1");
if (myreader.Read())
{
state = myreader["state"].ToString();
if (state == "0")
{
System.Web.HttpContext.Current.Response.Write("<script>parent.location.href='Close.htm'</script>");
}
}
myreader.Close();
}
/// <summary>
/// 读取Title,Description,Keys
/// </summary>
public void showWebTitle()
{
int intId = 1;
SqlDataReader Myreader = getRead("select * from TBset where id=" + intId + "");
if (Myreader.Read())
{
strTitle = Myreader["webname"].ToString();
strDescription = Myreader["webdescription"].ToString();
strKeys = Myreader["webkeys"].ToString();
}
Myreader.Close();
StartProcessRequest();//分析用户请求是否正常
ShowWebState();//判断网站是否关闭
}
/// <summary>
/// 分析用户请求是否正常
/// </summary>
///
public static void StartProcessRequest()
{
try
{
string getkeys = "";
//string sqlErrorPage = System.Configuration.ConfigurationSettings.AppSettings["CustomErrorPage"].ToString();
if (System.Web.HttpContext.Current.Request.QueryString != null)
{
for (int i = 0; i < System.Web.HttpContext.Current.Request.QueryString.Count; i++)
{
getkeys = System.Web.HttpContext.Current.Request.QueryString.Keys[i];
if (!ProcessSqlStr(System.Web.HttpContext.Current.Request.QueryString[getkeys], 0))
{
//System.Web.HttpContext.Current.Response.Redirect (sqlErrorPage+"?errmsg=sqlserver&sqlprocess=true");
System.Web.HttpContext.Current.Response.Write("<script>alert('请勿非法提交!');history.back();</script>");
System.Web.HttpContext.Current.Response.End();
}
}
}
if (System.Web.HttpContext.Current.Request.Form != null)
{
for (int i = 0; i < System.Web.HttpContext.Current.Request.Form.Count; i++)
{
getkeys = System.Web.HttpContext.Current.Request.Form.Keys[i];
if (!ProcessSqlStr(System.Web.HttpContext.Current.Request.Form[getkeys], 1))
{
//System.Web.HttpContext.Current.Response.Redirect (sqlErrorPage+"?errmsg=sqlserver&sqlprocess=true");
System.Web.HttpContext.Current.Response.Write("<script>alert('请勿非法提交!');history.back();</script>");
System.Web.HttpContext.Current.Response.End();
}
}
}
}
catch
{
// 错误处理: 处理用户提交信息!
}
}
/**/
/// <summary>
/// 分析用户请求是否正常
/// </summary>
/// <param name="Str">传入用户提交数据</param>
/// <returns>返回是否含有SQL注入式攻击代码</returns>
private static bool ProcessSqlStr(string Str, int type)
{
string SqlStr;
if (type == 1)
SqlStr = "exec|insert|select|delete|update|count|chr|mid|master|truncate|char|declare";
else
SqlStr = "'|and|exec|insert|select|delete|update|count|*|chr|mid|master|truncate|char|declare|>|<";
bool ReturnValue = true;
try
{
if (Str != "")
{
string[] anySqlStr = SqlStr.Split('|');
foreach (string ss in anySqlStr)
{
if (Str.IndexOf(ss) >= 0)
{
ReturnValue = false;
}
}
}
}
catch
{
ReturnValue = false;
}
return ReturnValue;
}
/// <summary>
/// 判断是否是数字
/// </summary>
/// <param name="oText"></param>
/// <returns>bool</returns>
public bool IsNumberic(string oText)//判断是否是数字
{
try
{
int var1 = System.Convert.ToInt32(oText);
if (var1 < 0)
{
return false;
}
return true;
}
catch
{
return false;
}
}
/// <summary>
/// 截取字符串
/// </summary>
/// <param name="inputString"></param>
/// <param name="length"></param>
/// <returns>string</returns>
public string SubString(string inputString, int length)
{
if (Encoding.UTF8.GetByteCount(inputString) <= length * 2)
{
return inputString;
}
ASCIIEncoding ascii = new ASCIIEncoding();
int tempLen = 0;
string tempString = "";
byte[] s = ascii.GetBytes(inputString);
for (int i = 0; i < s.Length; i++)
{
if ((int)s[i] == 63)
{
tempLen += 2;
}
else
{
tempLen += 1;
}
tempString += inputString.Substring(i, 1);
if (tempLen >= (length - 1) * 2)
break;
}
//如果截过则加上半个省略号
if (System.Text.Encoding.Default.GetBytes(inputString).Length > length)
tempString += "";
return tempString;
}
/// <summary>
/// 显示登录状态
/// </summary>
public void ShowLoginState()
{
if (Session["j95fn3839vfn93h9n29n"] == null)
{
System.Web.HttpContext.Current.Response.Write("<script>parent.location.href='Default.aspx'</script>");
}
}
#region JS提示============================================
/// <summary>
/// 添加编辑删除提示
/// </summary>
/// <param name="msgtitle">提示文字</param>
/// <param name="url">返回地址</param>
/// <param name="msgcss">CSS样式</param>
public void JscriptMsg(string msgtitle, string url, string msgcss)
{
string msbox = "parent.jsprint(\"" + msgtitle + "\", \"" + url + "\", \"" + msgcss + "\")";
ClientScript.RegisterClientScriptBlock(Page.GetType(), "JsPrint", msbox, true);
}
/// <summary>
/// 带回传函数的添加编辑删除提示
/// </summary>
/// <param name="msgtitle">提示文字</param>
/// <param name="url">返回地址</param>
/// <param name="msgcss">CSS样式</param>
/// <param name="callback">JS回调函数</param>
public void JscriptMsg(string msgtitle, string url, string msgcss, string callback)
{
string msbox = "parent.jsprint(\"" + msgtitle + "\", \"" + url + "\", \"" + msgcss + "\", " + callback + ")";
ClientScript.RegisterClientScriptBlock(Page.GetType(), "JsPrint", msbox, true);
}
#endregion
}
}

Notiek ielāde…
Atcelt
Saglabāt