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

📄 companyadmin.aspx.cs

📁 ASP.NET编写的眼镜行分销系统的程序.
💻 CS
字号:
using System;
using System.Data;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;
namespace NewGlassBook
{
	public class CompanyAdmin :MyPage
	{
		protected SuperDataGrid dgShow;
		protected System.Web.UI.WebControls.LinkButton DeleteLink;		
		protected System.Web.UI.WebControls.DropDownList condition;
		protected NewGlassBook.MyTextBox conditionValue;
		protected NewGlassBook.MyButton dbtn_search;
		protected System.Web.UI.WebControls.Label lblWarning;
		string strSql;//SQL语句
		Record r;//访问数据库
		private void Page_Load(object sender, System.EventArgs e)
		{
			if(!Page.IsPostBack)
			{
				strSql="select * from company a,store b where a.storecode=b.storecode and a.id not like 'f%'";
				Session["strSql"]=strSql;
				dgShowOpen();
			}

		}
		protected string OpenWin(object obj)
		{
			if (!Convert.IsDBNull(obj))
			{
				return "window.open(\"CompanyEdit.aspx?id=" + obj.ToString() + "\", \"\",\"width=260,height=400,top=100,left=200\");return false;";
			}
			return "";
		}		
		public void dgShow_Change(Object sender, DataGridPageChangedEventArgs e) 
		{
			dgShow.CurrentPageIndex = e.NewPageIndex;//指定DataGrid的当前页面
			dgShowOpen();//将指定了页码的datagrid再次绑定
		}
		private void dgShowOpen()
		{
			r=new Record();
			DataSet ds=r.GetData("company",Session["strSql"].ToString());
			DataView dv=ds.Tables["company"].DefaultView;
			dgShow.DataSource=dv;
			dgShow.PagerStyle.Mode=PagerMode.NumericPages;
			dgShow.DataBind();			
		}
		
		
		protected void dgShow_Delete(Object sender,DataGridCommandEventArgs e)
		{
			string item = e.Item.Cells[0].Text;//取得该行的Id
			string strSql="delete from company where ID='"+item+"'";//生成删除用的Sql语句
			r=new Record();//创建Record类的对象
			if(r.ExecuteQuery(strSql)==1)//调用Record的ExecuteQuery方法执行Sql语句
			{
				dgShowOpen();//将删除数据后的DataGrid再次绑定		
			}
			else
			{
				lblWarning.Text=r.ErrMsg;
			}			
		}
		#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.dbtn_search.Click += new System.EventHandler(this.dbtn_search_Click);
			this.dgShow.PageIndexChanged += new System.Web.UI.WebControls.DataGridPageChangedEventHandler(this.dgShow_Change);
			this.dgShow.DeleteCommand += new System.Web.UI.WebControls.DataGridCommandEventHandler(this.dgShow_Delete);
			this.dgShow.ItemDataBound += new System.Web.UI.WebControls.DataGridItemEventHandler(this.dgShow_ItemDataBound);
			this.Load += new System.EventHandler(this.Page_Load);

		}
		#endregion

		private void dgShow_ItemDataBound(object sender, System.Web.UI.WebControls.DataGridItemEventArgs e)
		{
			if(e.Item.FindControl("DeleteLink")!= null)
			{ 
				((LinkButton) e.Item.FindControl("DeleteLink")).Attributes.Add("onClick", "return confirm('您确实要删除当前记录吗?');");//添加确认对话框

			}
		}

		private void dbtn_search_Click(object sender, System.EventArgs e)
		{
			//根据查询条件查询公司信息,并在DataGrid中显示出来
			string strValue,strCondition;
			strValue=conditionValue.Text;//查询条件
			strCondition=condition.SelectedItem.Value.ToString();
			strSql="select * from company a,store b where a.storecode=b.storecode";
			strSql=strSql+" and "+strCondition+" like '%"+strValue+"%' and a.id not like 'f%'";
			Session["strSql"]=strSql;
			dgShow.CurrentPageIndex=0;
			dgShowOpen();			
		}	
	}
}

⌨️ 快捷键说明

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