first commit
This commit is contained in:
71
App_Code/DbManager.cs
Normal file
71
App_Code/DbManager.cs
Normal file
@@ -0,0 +1,71 @@
|
||||
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;
|
||||
|
||||
/// <summary>
|
||||
/// DbManager 的摘要说明
|
||||
/// </summary>
|
||||
public class DbManager
|
||||
{
|
||||
private static string strConn = "Server=localhost\\SQLEXPRESS;Database=bbs;Integrated Security=True";
|
||||
private static SqlConnection conn;
|
||||
public DbManager()
|
||||
{
|
||||
//
|
||||
// TODO: 在此处添加构造函数逻辑
|
||||
//
|
||||
}
|
||||
|
||||
public static SqlCommand getCommand()
|
||||
{
|
||||
openConnection();
|
||||
SqlCommand comm = new SqlCommand();
|
||||
comm.Connection = conn;
|
||||
return comm;
|
||||
}
|
||||
public static SqlCommand getCommand(string sql)
|
||||
{
|
||||
openConnection();
|
||||
SqlCommand comm = new SqlCommand(sql, conn);
|
||||
return comm;
|
||||
}
|
||||
public static DataSet getDataSet(string sql, string dbName)
|
||||
{
|
||||
openConnection();
|
||||
DataSet myDataSet = new DataSet();
|
||||
SqlDataAdapter da = new SqlDataAdapter(sql, conn);
|
||||
da.Fill(myDataSet, dbName);
|
||||
return myDataSet;
|
||||
}
|
||||
public static SqlDataReader getReader(string sql)
|
||||
{
|
||||
SqlCommand myComm = getCommand(sql);
|
||||
return myComm.ExecuteReader();
|
||||
}
|
||||
public static int getNonQuery(string sql)
|
||||
{
|
||||
SqlCommand comm = getCommand();
|
||||
comm.CommandText = sql;
|
||||
return comm.ExecuteNonQuery();
|
||||
}
|
||||
public static void closeConnection()
|
||||
{
|
||||
if(conn.State==ConnectionState.Open)
|
||||
conn.Close();
|
||||
}
|
||||
public static void openConnection()
|
||||
{
|
||||
if (conn == null)
|
||||
conn = new SqlConnection(strConn);
|
||||
if (conn.State == ConnectionState.Closed)
|
||||
conn.Open();
|
||||
}
|
||||
|
||||
}
|
||||
36
App_Code/function.cs
Normal file
36
App_Code/function.cs
Normal file
@@ -0,0 +1,36 @@
|
||||
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;
|
||||
|
||||
/// <summary>
|
||||
/// function 的摘要说明
|
||||
/// </summary>
|
||||
public class function
|
||||
{
|
||||
public function()
|
||||
{
|
||||
//
|
||||
// TODO: 在此处添加构造函数逻辑
|
||||
//
|
||||
}
|
||||
public static string redirect(string url, string message)
|
||||
{
|
||||
string str = "";
|
||||
if (message != null && message != "")
|
||||
{
|
||||
str = "<div id='warning'>" + message + "</div>";
|
||||
str += "<script>setTimeout(function(){location.href='" + url + "'},1000)</script>";
|
||||
}
|
||||
else
|
||||
{
|
||||
str = "<script>self.location.href='" + url + "'</script>";
|
||||
}
|
||||
return str;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user