using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
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 TheClient
	
{
	
	/// <summary>
	///WebForm1的摘要说明.
	/// </summary>
	public class WebForm1 : System.Web.UI.Page
	{
		protected System.Web.UI.WebControls.DataGrid DataGrid1;
		protected System.Web.UI.WebControls.Label Label1;
		protected System.Web.UI.WebControls.DropDownList DropDownList1;
		protected System.Web.UI.WebControls.Button RunSql;
		protected System.Web.UI.WebControls.Button Populate;
		protected System.Web.UI.WebControls.Label messages;
		private localhost.dbService mydbService = new localhost.dbService();
		public WebForm1()
		{
			Page.Init += new System.EventHandler(Page_Init);
		}

		private void Page_Load(object sender, System.EventArgs e)
		{
			// 在此处放置页面初始化代码
		}

		private void Page_Init(object sender, EventArgs e)
		{
			//
			// CODEGEN: 该调用是 ASP.NET Web 服务设计器所必需的
			//
			InitializeComponent();
		}

		#region Web Form Designer generated code
		/// <summary>
		/// 设计器支持所需的方法 - 不要使用代码编辑器修改
		/// 此方法的内容
		/// </summary>
		private void InitializeComponent()
		{    
			this.Populate.Click += new System.EventHandler(this.Populate_Click);
			this.RunSql.Click += new System.EventHandler(this.RunSql_Click);
			this.Load += new System.EventHandler(this.Page_Load);

		}
		#endregion

		private void Populate_Click(object sender, System.EventArgs e)
		{
			DataSet ds = new DataSet();
			String s =  DropDownList1.SelectedItem.ToString();
			ds = mydbService.Populate(s);
			DataGrid1.DataSource=ds;
			DataGrid1.DataBind();
		
		}

		private void RunSql_Click(object sender, System.EventArgs e)
		{
		   
			string s;
			String ret;
			s = "Delete from pub_info where pub_id = '9999'";
			ret=mydbService.RunSQL(s);
			messages.Text= ret;

			//插入一个随机数
			Random r = new Random();

			s = " insert into pub_info(pub_id,pr_info) values("; 
			s = s + " '9999','" + r.Next(1000).ToString() + "')";
			ret = mydbService.RunSQL(s);
			messages.Text= ret;
		    
			//刷新DataGrid来显示更新的数据
			DataSet ds = new DataSet();
			s = "Select * from pub_info where pub_id = '9999'";
			ds = mydbService.Populate(s);
			DataGrid1.DataSource=ds;
			DataGrid1.DataBind();

		}
	}
}
