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;
using System.Web.Security;

namespace Samples
{
	/// <summary>
	/// WebForm1 的摘要说明。
	/// </summary>
	public class ValidPart : System.Web.UI.Page
	{
		protected System.Web.UI.WebControls.RadioButtonList RadioButtonList1;
		protected System.Web.UI.WebControls.Button AddItem;
		protected System.Web.UI.WebControls.Button SearchItem;
		protected System.Web.UI.WebControls.ListBox CatalogList1;
		protected System.Web.UI.WebControls.RequiredFieldValidator CatalogListRequiredFieldValidator1;
		protected System.Web.UI.WebControls.TextBox ItemName1;
		protected System.Web.UI.WebControls.RequiredFieldValidator ItemNameRequiredFieldValidator1;
		protected System.Web.UI.WebControls.TextBox ItemNum1;
		protected System.Web.UI.WebControls.RequiredFieldValidator ItemNumRequiredFieldValidator1;
		protected System.Web.UI.WebControls.CompareValidator ItemNumCompareValidator1;
		protected System.Web.UI.WebControls.ListBox CatalogList2;
		protected System.Web.UI.WebControls.RequiredFieldValidator CatalogListRequiredFieldValidator2;
		protected System.Web.UI.WebControls.TextBox ItemName2;
		protected System.Web.UI.WebControls.RequiredFieldValidator ItemNameRequiredFieldValidator2;
	
		private void Page_Load(object sender, System.EventArgs e)
		{
			// 在此处放置用户代码以初始化页面
		}

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

		}
		#endregion

		private void AddItem_Click(object sender, System.EventArgs e)
		{
			//验证对应控件
			CatalogListRequiredFieldValidator1.Validate();
			ItemNameRequiredFieldValidator1.Validate();
			ItemNumRequiredFieldValidator1.Validate();
			ItemNumCompareValidator1.Validate();
			
			//如果对应的各个验证控件验证通过，则执行提交按钮操作
			if (CatalogListRequiredFieldValidator1.IsValid && ItemNameRequiredFieldValidator1.IsValid && ItemNumRequiredFieldValidator1.IsValid && ItemNumCompareValidator1.IsValid) 
			{
				Response.Write("<script language=javascript>");
				Response.Write("window.alert('验证通过，保存成功！')");
				Response.Write("</script>");

				//这里放将填写的数据添加到数据库中

				//清除各控件值
				CatalogList1.ClearSelection();
				ItemName1.Text = String.Empty;
				ItemNum1.Text = String.Empty;
			}
		}

		private void SearchItem_Click(object sender, System.EventArgs e)
		{
			//验证对应控件
			CatalogListRequiredFieldValidator2.Validate();
			ItemNameRequiredFieldValidator2.Validate();
			
			//如果各个验证控件验证通过，则添加进程日志信息
			if (CatalogListRequiredFieldValidator2.IsValid && ItemNameRequiredFieldValidator2.IsValid) 
			{
				Response.Write("<script language=javascript>");
				Response.Write("window.alert('验证通过，检索成功！')");
				Response.Write("</script>");

				//这里放将填写的数据添加到数据库中

				//清除各控件值
				CatalogList2.ClearSelection();
				ItemName2.Text = String.Empty;
			}
		}
	}
}
