|
|
- 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
-
-
- }
- }
|