⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 left.ascx.cs

📁 本文介绍了在Visual Studio.net环境下开发一个教材库管理系统的过程。创建了一套行之有效的方案。文章介绍了管理系统的系统分析部分
💻 CS
字号:
namespace jiaocaiku.include
{
	using System;
	using System.Data;
	using System.Drawing;
	using System.Web;
	using System.Web.UI.WebControls;
	using System.Web.UI.HtmlControls;
	using System.Data.SqlClient;
	using System.Configuration;
	using System.IO;



	/// <summary>
	///		left 的摘要说明。
	/// </summary>
	public class left : System.Web.UI.UserControl
	{
		protected System.Web.UI.WebControls.TextBox username;
		protected System.Web.UI.WebControls.TextBox password;
		protected System.Web.UI.WebControls.Button delu;
		protected System.Web.UI.WebControls.Button delu_cancel;
		protected System.Web.UI.WebControls.Panel Panel1;
		protected System.Web.UI.WebControls.Panel Panel2;



		protected string sub;

		private void Page_Load(object sender, System.EventArgs e)
		{
			if(!Page.IsPostBack)
			{
				if (Session["username"]==null)
				{
					Panel1.Visible=true;
					Panel2.Visible=false;
				}

				else
				{
					Panel1.Visible=false;
					Panel2.Visible=true;
					

				}

Gethot();
			}


		}

		#region Web 窗体设计器生成的代码
		override protected void OnInit(EventArgs e)
		{
			//
			// CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。
			//
			InitializeComponent();
			base.OnInit(e);
		}
		
		/// <summary>
		///		设计器支持所需的方法 - 不要使用代码编辑器
		///		修改此方法的内容。
		/// </summary>
		private void InitializeComponent()
		{
			this.delu.Click += new System.EventHandler(this.delu_Click);
			this.delu_cancel.Click += new System.EventHandler(this.delu_cancel_Click);
			this.Load += new System.EventHandler(this.Page_Load);

		}
		#endregion

		private void delu_Click(object sender, System.EventArgs e)
		{
			SqlConnection conn= new SqlConnection(ConfigurationSettings.AppSettings["connstr"].ToString());
			string strsql="select * from teacher where teacherid='"+username.Text.ToString()+"'";
			strsql+=" and password='"+ password.Text.ToString() + "'";
			conn.Open();
			SqlCommand cmd=new SqlCommand(strsql,conn);
			SqlDataReader dr=cmd.ExecuteReader();
			
			if (dr.Read())
			{

				Session["username"]=dr["teacherid"].ToString();
				Response.Redirect("default.aspx");
			}
			else
			{
				Response.Write("<script>alert('用户名或密码错误!');</script>");

				//Response.Redirect("default.aspx");
			}
			conn.Close();

		}

		public string Gethot()
		{
			SqlConnection conn= new SqlConnection(ConfigurationSettings.AppSettings["connstr"].ToString());
			conn.Open();

			string Gethot=null;
		
			string strsql="select top 9 * from news order by ID desc";

			SqlCommand cmd=new SqlCommand(strsql,conn);
			SqlDataReader dr=cmd.ExecuteReader();

			while(dr.Read ())
			{
				sub=dr["Title"].ToString();
				if(sub.Length>30)
				{
					sub=sub.Remove(30,sub.Length-30)+"...";
				}
				
				Gethot+="<img src='images/icon2.gif'></img>"+" ";
				Gethot+="<a href='news_show.aspx?id="+dr["id"]+"' target=_blank>"+sub+"</a>"+"<br>";
				Gethot+="<br>";
				
			}
		
			dr.Close();
			conn.Close();
			return Gethot;
			
		}
		

		private void delu_cancel_Click(object sender, System.EventArgs e)
		{
			username.Text="";
				password.Text="";

		}
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -