admin.aspx.cs
来自「数字图书馆网站」· CS 代码 · 共 516 行 · 第 1/2 页
CS
516 行
using System;
using System.Configuration;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
namespace DigitalLibrary
{
/// <summary>
/// Summary description for Admin_aspx.
/// </summary>
public class Admin : System.Web.UI.Page
{
protected System.Data.SqlClient.SqlDataAdapter sqlDataAdapter1;
protected System.Data.SqlClient.SqlConnection sqlConnection1;
protected System.Web.UI.HtmlControls.HtmlGenericControl Div1;
protected System.Web.UI.WebControls.Label lblMessage;
protected System.Web.UI.WebControls.Label lblTitle;
protected System.Web.UI.WebControls.Image imgImage;
protected System.Web.UI.WebControls.DataGrid dgArticles;
protected System.Data.SqlClient.SqlCommand cmdPrevious;
protected System.Data.SqlClient.SqlCommand cmdNext;
protected System.Web.UI.WebControls.Button btnPrevious;
protected System.Web.UI.WebControls.Button btnNext;
protected System.Data.SqlClient.SqlCommand sqlSelectCommand1;
protected DigitalLibrary.articlesList articlesList1;
protected System.Data.SqlClient.SqlDataAdapter sqlDataAdapter2;
protected System.Data.SqlClient.SqlCommand sqlSelectCommand2;
protected System.Data.SqlClient.SqlCommand sqlInsertCommand1;
private int dgCurrentPage;
private static int totalcount;
protected System.Web.UI.WebControls.Label lblCache;
protected System.Data.SqlClient.SqlCommand sqlSelectCommand3;
protected System.Data.SqlClient.SqlConnection sqlConnection2;
protected System.Web.UI.WebControls.Button btnBack;
protected DigitalLibrary.Abstract cusAbstract;
private void Page_Load(object sender, System.EventArgs e)
{
// Put user code to initialize the page here
if (!Page.IsPostBack)
{
cmdNext.Parameters["@articleid"].Value = "";
dgCurrentPage = 0;
this.sqlDataAdapter1.Fill(this.articlesList1.Articles);
this.dgArticles.DataSource=this.articlesList1.Articles;
this.dgArticles.DataBind();
this.lblCache.Text = "显示表中的数据";
Session["CurrentTable"] = this.articlesList1.Articles;
Cache["MyCache"] = this.articlesList1.Articles;
totalcount = this.articlesList1.Articles.Rows.Count;
ViewState["dgCurrentPage"] = dgCurrentPage;
if (this.dgArticles.Items.Count > 0)
{
ViewState[dgCurrentPage.ToString()] = this.dgArticles.Items[0].Cells[0].Text;
}
btnPrevious.Enabled = false;
if (dgArticles.Items.Count <= dgArticles.PageSize)
btnNext.Enabled = false;
}
}
#region Web Form Designer generated code
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: This call is required by the ASP.NET Web Form Designer.
//
InitializeComponent();
base.OnInit(e);
}
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.sqlDataAdapter1 = new System.Data.SqlClient.SqlDataAdapter();
this.sqlSelectCommand3 = new System.Data.SqlClient.SqlCommand();
this.sqlConnection2 = new System.Data.SqlClient.SqlConnection();
this.sqlSelectCommand1 = new System.Data.SqlClient.SqlCommand();
this.sqlConnection1 = new System.Data.SqlClient.SqlConnection();
this.cmdPrevious = new System.Data.SqlClient.SqlCommand();
this.cmdNext = new System.Data.SqlClient.SqlCommand();
this.articlesList1 = new DigitalLibrary.articlesList();
this.sqlDataAdapter2 = new System.Data.SqlClient.SqlDataAdapter();
this.sqlInsertCommand1 = new System.Data.SqlClient.SqlCommand();
this.sqlSelectCommand2 = new System.Data.SqlClient.SqlCommand();
((System.ComponentModel.ISupportInitialize)(this.articlesList1)).BeginInit();
this.btnBack.Click += new System.EventHandler(this.btnBack_Click);
this.btnNext.Click += new System.EventHandler(this.btnNext_Click);
this.dgArticles.CancelCommand += new System.Web.UI.WebControls.DataGridCommandEventHandler(this.dgArticles_CancelCommand);
this.dgArticles.PreRender += new System.EventHandler(this.dgArticles_PreRender);
this.dgArticles.EditCommand += new System.Web.UI.WebControls.DataGridCommandEventHandler(this.dgArticles_EditCommand);
this.dgArticles.UpdateCommand += new System.Web.UI.WebControls.DataGridCommandEventHandler(this.dgArticles_UpdateCommand);
this.dgArticles.ItemDataBound += new System.Web.UI.WebControls.DataGridItemEventHandler(this.ArticlesDG_ItemDataBound);
this.btnPrevious.Click += new System.EventHandler(this.btnPrevious_Click);
//
// sqlDataAdapter1
//
this.sqlDataAdapter1.SelectCommand = this.sqlSelectCommand3;
this.sqlDataAdapter1.TableMappings.AddRange(new System.Data.Common.DataTableMapping[] {
new System.Data.Common.DataTableMapping("Table", "Articles", new System.Data.Common.DataColumnMapping[] {
new System.Data.Common.DataColumnMapping("ArticleID", "ArticleID"),
new System.Data.Common.DataColumnMapping("FileName", "FileName"),
new System.Data.Common.DataColumnMapping("Abstract", "Abstract"),
new System.Data.Common.DataColumnMapping("Rating", "Rating"),
new System.Data.Common.DataColumnMapping("Status", "Status"),
new System.Data.Common.DataColumnMapping("PostedBy", "PostedBy"),
new System.Data.Common.DataColumnMapping("Category", "Category"),
new System.Data.Common.DataColumnMapping("Price", "Price"),
new System.Data.Common.DataColumnMapping("CategoryID", "CategoryID")})});
//
// sqlSelectCommand3
//
this.sqlSelectCommand3.CommandText = @"SELECT Articles.ArticleID, Articles.FileName, 'Abstract ' + LTRIM(STR(Articles.ArticleID)) AS Abstract, Articles.Rating, Articles.Status, Articles.PostedBy, Category.Category, PayableArticles.Price, Category.CategoryID FROM Articles LEFT OUTER JOIN Category ON Articles.CategoryID = Category.CategoryID LEFT OUTER JOIN PayableArticles ON Articles.ArticleID = PayableArticles.ArticleID ORDER BY Articles.ArticleID";
this.sqlSelectCommand3.Connection = this.sqlConnection2;
//
// sqlConnection2
//
this.sqlConnection2.ConnectionString =ConfigurationSettings.AppSettings["DatabaseConnection"];
//
// sqlSelectCommand1
//
this.sqlSelectCommand1.CommandText = @"SELECT Articles.ArticleID, Articles.FileName, 'Abstract ' + LTRIM(STR(Articles.ArticleID)) AS Abstract, Articles.Rating, Articles.Status, Articles.PostedBy, Category.Category, PayableArticles.Price FROM Articles LEFT OUTER JOIN Category ON Articles.CategoryID = Category.CategoryID LEFT OUTER JOIN PayableArticles ON Articles.ArticleID = PayableArticles.ArticleID ORDER BY Articles.ArticleID";
this.sqlSelectCommand1.Connection = this.sqlConnection1;
//
// sqlConnection1
//
this.sqlConnection1.ConnectionString =ConfigurationSettings.AppSettings["DatabaseConnection"];
//
// cmdPrevious
//
this.cmdPrevious.CommandText = @"SELECT TOP 2 Articles.ArticleID, Articles.FileName, 'Abstract ' + LTRIM(STR(Articles.ArticleID)) AS Abstract, Articles.Rating, Articles.Status, Articles.PostedBy, Category.Category, PayableArticles.Price FROM Articles LEFT OUTER JOIN Category ON Articles.CategoryID = Category.CategoryID LEFT OUTER JOIN PayableArticles ON Articles.ArticleID = PayableArticles.ArticleID WHERE (Articles.ArticleID >= @articleid) ORDER BY Articles.ArticleID";
this.cmdPrevious.Connection = this.sqlConnection1;
this.cmdPrevious.Parameters.Add(new System.Data.SqlClient.SqlParameter("@articleid", System.Data.SqlDbType.Int, 4, "ArticleID"));
//
// cmdNext
//
this.cmdNext.CommandText = @"SELECT TOP 2 Articles.ArticleID, Articles.FileName, 'Abstract ' + LTRIM(STR(Articles.ArticleID)) AS Abstract, Articles.Rating, Articles.Status, Articles.PostedBy, Category.Category, PayableArticles.Price FROM Articles LEFT OUTER JOIN Category ON Articles.CategoryID = Category.CategoryID LEFT OUTER JOIN PayableArticles ON Articles.ArticleID = PayableArticles.ArticleID WHERE (Articles.ArticleID > @articleid) ORDER BY Articles.ArticleID";
this.cmdNext.Connection = this.sqlConnection1;
this.cmdNext.Parameters.Add(new System.Data.SqlClient.SqlParameter("@articleid", System.Data.SqlDbType.Int, 4, "ArticleID"));
//
// articlesList1
//
this.articlesList1.DataSetName = "articlesList";
this.articlesList1.Locale = new System.Globalization.CultureInfo("en-US");
//
// sqlDataAdapter2
//
this.sqlDataAdapter2.InsertCommand = this.sqlInsertCommand1;
this.sqlDataAdapter2.SelectCommand = this.sqlSelectCommand2;
this.sqlDataAdapter2.TableMappings.AddRange(new System.Data.Common.DataTableMapping[] {
new System.Data.Common.DataTableMapping("Table", "Category", new System.Data.Common.DataColumnMapping[] {
new System.Data.Common.DataColumnMapping("Category", "Category"),
new System.Data.Common.DataColumnMapping("CategoryID", "CategoryID")})});
//
// sqlInsertCommand1
//
this.sqlInsertCommand1.CommandText = "INSERT INTO Category(Category, CategoryID) VALUES (@Category, @CategoryID); SELEC" +
"T Category, CategoryID FROM Category";
this.sqlInsertCommand1.Connection = this.sqlConnection1;
this.sqlInsertCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Category", System.Data.SqlDbType.VarChar, 50, "Category"));
this.sqlInsertCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@CategoryID", System.Data.SqlDbType.Int, 4, "CategoryID"));
//
// sqlSelectCommand2
//
this.sqlSelectCommand2.CommandText = "SELECT Category, CategoryID FROM Category";
this.sqlSelectCommand2.Connection = this.sqlConnection1;
this.Load += new System.EventHandler(this.Page_Load);
((System.ComponentModel.ISupportInitialize)(this.articlesList1)).EndInit();
}
#endregion
protected void ShowAbstract(object sender, System.EventArgs e)
{
string strAbstract = sender.GetType().GetProperty("Text").GetValue(sender,null).ToString();
int AbstractID = Convert.ToInt32(strAbstract.Split(' ').GetValue(1));
SqlConnection myConnection = new SqlConnection(ConfigurationSettings.AppSettings["DatabaseConnection"]);
SqlDataAdapter myAdapter = new SqlDataAdapter("SELECT Abstract FROM Articles WHERE ArticleID = "+AbstractID,myConnection);
DataSet myDataSet = new DataSet();
myAdapter.Fill(myDataSet,"Abstracts");
myConnection.Close();
this.cusAbstract.AbstractText=myDataSet.Tables["Abstracts"].Rows[0][0].ToString();
this.cusAbstract.Visible=true;
}
private void ArticlesDG_ItemDataBound(object sender, System.Web.UI.WebControls.DataGridItemEventArgs e)
{
if (e.Item.ItemType == System.Web.UI.WebControls.ListItemType.Item || e.Item.ItemType == System.Web.UI.WebControls.ListItemType.AlternatingItem)
{
HyperLink hlFileName = (HyperLink)e.Item.Cells[1].Controls[1];
hlFileName.NavigateUrl = ConfigurationSettings.AppSettings["AttachmentsURL"]+hlFileName.Text;
hlFileName.Target="_blank";
}
}
private void btnPrevious_Click(object sender, System.EventArgs e)
{
btnNext.Enabled = true;
dgCurrentPage = Convert.ToInt32(ViewState["dgCurrentPage"]);
dgCurrentPage -= 1;
if (dgCurrentPage >= 0)
{
cmdPrevious.Parameters["@articleid"].Value = ViewState[dgCurrentPage.ToString()].ToString();
SqlDataAdapter myAdapter = new SqlDataAdapter(cmdPrevious);
myAdapter.Fill(this.articlesList1,"Articles");
dgArticles.DataSource = this.articlesList1;
dgArticles.DataMember = "Articles";
dgArticles.DataBind();
Session["CurrentTable"] = this.articlesList1.Articles;
Cache["MyCache"] = this.articlesList1.Articles;
this.lblCache.Text = "Data displayed from Table";
ViewState["dgCurrentPage"] = dgCurrentPage;
ViewState[dgCurrentPage.ToString()] = this.dgArticles.Items[0].Cells[0].Text;
if (dgCurrentPage==0)
btnPrevious.Enabled = false;
}
}
private void btnNext_Click(object sender, System.EventArgs e)
{
dgCurrentPage = Convert.ToInt32(ViewState["dgCurrentPage"]);
dgCurrentPage += 1;
cmdNext.Parameters["@articleid"].Value = dgArticles.Items[dgArticles.PageSize-1].Cells[0].Text;
SqlDataAdapter myAdapter = new SqlDataAdapter(cmdNext);
myAdapter.Fill(this.articlesList1,"Articles");
dgArticles.DataSource = this.articlesList1;
dgArticles.DataMember = "Articles";
dgArticles.DataBind();
Session["CurrentTable"] = this.articlesList1.Articles;
Cache["MyCache"] = this.articlesList1.Articles;
this.lblCache.Text = "Data displayed from Table";
ViewState["dgCurrentPage"] = dgCurrentPage;
if (this.dgArticles.Items.Count > 0)
{
ViewState[dgCurrentPage.ToString()] = this.dgArticles.Items[0].Cells[0].Text;
}
btnPrevious.Enabled = true;
if (dgArticles.Items.Count < dgArticles.PageSize)
btnNext.Enabled = false;
if ((dgArticles.Items.Count == dgArticles.PageSize) && ((dgCurrentPage == (totalcount/dgArticles.PageSize)-1)))
btnNext.Enabled = false;
}
private void dgArticles_EditCommand(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e)
{
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?