//===========================================================================
// Smarclient FPMS Demo Project a sample project for SmartClient technology.
// Smarclient FPMS Demo is designed and implemented bases Microsoft Application Block tech.
// Author: SFPMS Team, Date 2004-11
// Vision 1.0
// Revison History
//=============================================================================
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using JSW.FPMS.Tool ;

namespace JSW.FPMS.Xiang.ShiTu
{
	/// <summary>
	/// clsXuQiuLuRuForm 的摘要说明。
	/// </summary>
	public class XuQiuLuRuForm : System.Windows.Forms.Form
	{
		#region 成员变量区域
		private JSW.FPMS.Xiang.KongZhi.clsXuQiuChaXunKongZhi chaXunShuJu ;
		private System.Windows.Forms.GroupBox GB_XinXiZu;
		private System.Windows.Forms.GroupBox GB_FanKuiZu;
		private System.Windows.Forms.Button BT_QueDing;
		private System.Windows.Forms.Button BT_QuXiao;

		System.Data.DataSet huoQuShuJu = null ;
		private System.Windows.Forms.Panel PT_XinXiZu;
		private System.Windows.Forms.Panel PT_FanKuiZu;

		//日期控件
		private RiQiForm mRiQiForm;
		private string mdangQianShuRuK="" ;

		//状态   0 乡级(只显示信息组)  1 县级信息组只读  2 调看 只显示信息组 且只读
		private int mzhuangTai = 0;

		/// <summary>
		/// 必需的设计器变量。
		/// </summary>
		private System.ComponentModel.Container components = null;
		#endregion

		#region 私有方法区域
		#region Windows 窗体设计器生成的代码
		/// <summary>
		/// 设计器支持所需的方法 - 不要使用代码编辑器修改
		/// 此方法的内容。
		/// </summary>
		private void InitializeComponent()
		{
			this.GB_XinXiZu = new System.Windows.Forms.GroupBox();
			this.PT_XinXiZu = new System.Windows.Forms.Panel();
			this.GB_FanKuiZu = new System.Windows.Forms.GroupBox();
			this.PT_FanKuiZu = new System.Windows.Forms.Panel();
			this.BT_QueDing = new System.Windows.Forms.Button();
			this.BT_QuXiao = new System.Windows.Forms.Button();
			this.GB_XinXiZu.SuspendLayout();
			this.GB_FanKuiZu.SuspendLayout();
			this.SuspendLayout();
			// 
			// GB_XinXiZu
			// 
			this.GB_XinXiZu.Controls.Add(this.PT_XinXiZu);
			this.GB_XinXiZu.Location = new System.Drawing.Point(0, 0);
			this.GB_XinXiZu.Name = "GB_XinXiZu";
			this.GB_XinXiZu.Size = new System.Drawing.Size(576, 264);
			this.GB_XinXiZu.TabIndex = 0;
			this.GB_XinXiZu.TabStop = false;
			this.GB_XinXiZu.Text = "信息组";
			// 
			// PT_XinXiZu
			// 
			this.PT_XinXiZu.AutoScroll = true;
			this.PT_XinXiZu.Dock = System.Windows.Forms.DockStyle.Fill;
			this.PT_XinXiZu.Location = new System.Drawing.Point(3, 17);
			this.PT_XinXiZu.Name = "PT_XinXiZu";
			this.PT_XinXiZu.Size = new System.Drawing.Size(570, 244);
			this.PT_XinXiZu.TabIndex = 0;
			// 
			// GB_FanKuiZu
			// 
			this.GB_FanKuiZu.Controls.Add(this.PT_FanKuiZu);
			this.GB_FanKuiZu.Location = new System.Drawing.Point(0, 264);
			this.GB_FanKuiZu.Name = "GB_FanKuiZu";
			this.GB_FanKuiZu.Size = new System.Drawing.Size(576, 184);
			this.GB_FanKuiZu.TabIndex = 1;
			this.GB_FanKuiZu.TabStop = false;
			this.GB_FanKuiZu.Text = "反馈组";
			// 
			// PT_FanKuiZu
			// 
			this.PT_FanKuiZu.Dock = System.Windows.Forms.DockStyle.Fill;
			this.PT_FanKuiZu.Location = new System.Drawing.Point(3, 17);
			this.PT_FanKuiZu.Name = "PT_FanKuiZu";
			this.PT_FanKuiZu.Size = new System.Drawing.Size(570, 164);
			this.PT_FanKuiZu.TabIndex = 0;
			// 
			// BT_QueDing
			// 
			this.BT_QueDing.Location = new System.Drawing.Point(384, 456);
			this.BT_QueDing.Name = "BT_QueDing";
			this.BT_QueDing.TabIndex = 2;
			this.BT_QueDing.Text = "确定";
			this.BT_QueDing.Click += new System.EventHandler(this.BT_QueDing_Click);
			// 
			// BT_QuXiao
			// 
			this.BT_QuXiao.DialogResult = System.Windows.Forms.DialogResult.Cancel;
			this.BT_QuXiao.Location = new System.Drawing.Point(472, 456);
			this.BT_QuXiao.Name = "BT_QuXiao";
			this.BT_QuXiao.TabIndex = 3;
			this.BT_QuXiao.Text = "取消";
			this.BT_QuXiao.Click += new System.EventHandler(this.BT_QuXiao_Click);
			// 
			// XuQiuLuRuForm
			// 
			this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
			this.ClientSize = new System.Drawing.Size(576, 485);
			this.Controls.Add(this.BT_QuXiao);
			this.Controls.Add(this.BT_QueDing);
			this.Controls.Add(this.GB_FanKuiZu);
			this.Controls.Add(this.GB_XinXiZu);
			this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.Fixed3D;
			this.MaximizeBox = false;
			this.MinimizeBox = false;
			this.Name = "XuQiuLuRuForm";
			this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
			this.Text = "需求录入";
			this.Closed += new System.EventHandler(this.XuQiuLuRuForm_Closed);
			this.GB_XinXiZu.ResumeLayout(false);
			this.GB_FanKuiZu.ResumeLayout(false);
			this.ResumeLayout(false);

		}
		#endregion

		/// <summary>
		/// 窗体关闭事件
		/// </summary>
		private void XuQiuLuRuForm_Closed(object sender, System.EventArgs e)
		{
			mRiQiForm=null;
		}

		/// <summary>
		/// 设置窗体尺寸
		/// </summary>
		private void SheZhiFormSize()
		{
			int xinXiDianShuLiang = 0;
			int fanKuiZuSHuLiang = 0;
			int buChang = 30;
			int touGao = 30 ;

			System.Data.DataRow[] xinXiZu = huoQuShuJu.Tables["PeiZhi"].Select("ShuJuZuKJM = 'XinXiZu'");
			System.Data.DataRow[] fanKuiZu = huoQuShuJu.Tables["PeiZhi"].Select("ShuJuZuKJM = 'FanKuiZu'");
			xinXiDianShuLiang = xinXiZu.Length ;
			fanKuiZuSHuLiang = fanKuiZu.Length ;

			if (xinXiDianShuLiang%2==0)
				xinXiDianShuLiang = (xinXiDianShuLiang/2) * buChang + touGao;
			else
				xinXiDianShuLiang = (xinXiDianShuLiang/2+1) * buChang + touGao;

			if (this.mzhuangTai==0)
			{
				if (xinXiDianShuLiang<180)
					this.GB_XinXiZu.Height = 180 ;
				else if (xinXiDianShuLiang>600)
					this.GB_XinXiZu.Height = 600 ;
				else 
					this.GB_XinXiZu.Height = xinXiDianShuLiang ;
			}
			else
			{
				if (xinXiDianShuLiang<180)
					this.GB_XinXiZu.Height = 180 ;
				else if (xinXiDianShuLiang>400)
					this.GB_XinXiZu.Height = 400 ;
				else 
					this.GB_XinXiZu.Height = xinXiDianShuLiang ;
			
			}

			if (fanKuiZuSHuLiang%2==0)
				fanKuiZuSHuLiang = (fanKuiZuSHuLiang/2) * buChang + touGao;
			else
				fanKuiZuSHuLiang = (fanKuiZuSHuLiang/2+1) * buChang + touGao;

			if (fanKuiZuSHuLiang<100)
				this.GB_FanKuiZu.Height = 100 ;
			else if (fanKuiZuSHuLiang<200)
				this.GB_FanKuiZu.Height = 200 ;
			else
				this.GB_FanKuiZu.Height = fanKuiZuSHuLiang ;

			this.GB_FanKuiZu.Top = this.GB_XinXiZu.Top + this.GB_XinXiZu.Height ;

			if (this.mzhuangTai==0)
				this.Height = this.GB_XinXiZu.Top + this.GB_XinXiZu.Height + 70 ;
			else
				this.Height = this.GB_FanKuiZu.Top + this.GB_FanKuiZu.Height + 70 ;

			this.BT_QueDing.Top = this.Height - 60 ;
			this.BT_QuXiao.Top  = this.Height - 60 ;
		}

		/// <summary>
		/// 初始化信息组控件
		/// </summary>
		private void ChuShiHuaXinXiZu (System.Data.DataSet huoQuShuJu)
		{
			System.Data.DataRow[] xinXiZu = huoQuShuJu.Tables["PeiZhi"].Select("ShuJuZuKJM = 'XinXiZu'");
			if (xinXiZu.Length==0) return ;
			//排序
			System.Collections.ArrayList list = new ArrayList() ;
			System.Collections.Hashtable table = new Hashtable() ;
			int paixu=0 ;
			for (int i=0;i<xinXiZu.Length ;i++)
			{
				paixu = int.Parse(xinXiZu[i]["XianShiShunXu"].ToString().Trim());
				
				if (!table.ContainsKey(paixu))
				{
					table.Add(paixu,xinXiZu[i]) ;
					list.Add (paixu) ;
				}
			}
			list.Sort();

			for (int i=0;i<list.Count ;i++)
			{
				ChangJianKJ(PT_XinXiZu,(System.Data.DataRow)table[(int)list[i]],i) ;							
			}
		}

		/// <summary>
		/// 初始化反馈组控件
		/// </summary>
		private void ChuShiHuaFanKuiZu (System.Data.DataSet huoQuShuJu)
		{
			System.Data.DataRow[] xinXiZu = huoQuShuJu.Tables["PeiZhi"].Select("ShuJuZuKJM = 'FanKuiZu'");
			if (xinXiZu.Length==0) return ;

			//排序
			System.Collections.ArrayList list = new ArrayList() ;
			System.Collections.Hashtable table = new Hashtable() ;
			int paixu=0 ;
			for (int i=0;i<xinXiZu.Length ;i++)
			{
				paixu = int.Parse(xinXiZu[i]["XianShiShunXu"].ToString().Trim());
				
				if (!table.ContainsKey(paixu))
				{
					table.Add(paixu,xinXiZu[i]) ;
					list.Add (paixu) ;
				}
			}
			list.Sort();

			for (int i=0;i<list.Count ;i++)
			{
				ChangJianKJ(PT_FanKuiZu,(System.Data.DataRow)table[(int)list[i]],i) ;							
			}
		}

		/// <summary>
		/// 创建控件
		/// </summary>
		private void ChangJianKJ(Control fuKongJian ,System.Data.DataRow shujuxiang,int buChang)
		{
			int hangZuoBiao = 0 ;
			int lieZuoBiao = 0 ;
			
			if ((buChang%2)==0)
			{
				hangZuoBiao = 30 ;
				lieZuoBiao = (buChang+1) * 15 ;
			}
			else
			{
				hangZuoBiao = 310 ;
				lieZuoBiao = buChang * 15 ;
			}

			//创建标题
			Label biaoTi = new Label() ;
			biaoTi.Name = "LB_" + shujuxiang["ShuJuXiangKJM"].ToString().Trim() ;
			biaoTi.Text = shujuxiang["ShuJuXiangMing"].ToString().Trim() ;
			biaoTi.Location = new System.Drawing.Point(hangZuoBiao, lieZuoBiao);
			biaoTi.Size = new System.Drawing.Size(90, 25);
			fuKongJian.Controls.Add(biaoTi) ;

			//创建输入框
			string kongJianLX = shujuxiang["ShuJuXiangMing"].ToString().Trim() ;
			switch (kongJianLX)
			{
				case "需求类别" :
					ChuangJianXuQiu(fuKongJian,shujuxiang,hangZuoBiao,lieZuoBiao)  ;
					break;
				case "信息点编号" :
					ChuangJianXinXiDian(fuKongJian,shujuxiang,hangZuoBiao,lieZuoBiao)  ;
					break;
				default :
					ChuangJianText(fuKongJian,shujuxiang,hangZuoBiao,lieZuoBiao)  ;
					break;
			}
		}
		
		/// <summary>
		/// 创建需求控件
		/// </summary>
		private void ChuangJianXuQiu(Control fuKongJian ,System.Data.DataRow shujuxiang,int hangZuoBiao,int lieZuoBiao )
		{
			//创建下拉框
			ComboBox shuRuKuang = new ComboBox() ;
			shuRuKuang.Name = "TB_" + shujuxiang["ShuJuXiangKJM"].ToString().Trim() ;
			shuRuKuang.Location = new System.Drawing.Point((hangZuoBiao+100) , lieZuoBiao);
			shuRuKuang.Size = new System.Drawing.Size(130, 25);
			shuRuKuang.KeyDown += new System.Windows.Forms.KeyEventHandler(coboBox_KeyDown);
			shuRuKuang.KeyPress += new System.Windows.Forms.KeyPressEventHandler(coboBox_KeyPress);

			for (int i=0;i<huoQuShuJu.Tables["XuQiuFenLei"].Rows.Count;i++)
			{
				shuRuKuang.Items.Add (huoQuShuJu.Tables["XuQiuFenLei"].Rows[i]["XuQiuDaMaMingXi"].ToString().Trim()) ;
			}
			shuRuKuang.SelectedIndex = 0 ;
			fuKongJian.Controls.Add(shuRuKuang) ;	
		}

		/// <summary>
		/// 创建信息点控件
		/// </summary>
		private void ChuangJianXinXiDian(Control fuKongJian ,System.Data.DataRow shujuxiang,int hangZuoBiao,int lieZuoBiao )
		{
			//创建下拉框
			ComboBox shuRuKuang = new ComboBox() ;
			shuRuKuang.Name = "TB_" + shujuxiang["ShuJuXiangKJM"].ToString().Trim() ;
			shuRuKuang.Location = new System.Drawing.Point((hangZuoBiao+100) , lieZuoBiao);
			shuRuKuang.Size = new System.Drawing.Size(130, 25);
			shuRuKuang.KeyDown += new System.Windows.Forms.KeyEventHandler(coboBox_KeyDown);
			shuRuKuang.KeyPress += new System.Windows.Forms.KeyPressEventHandler(coboBox_KeyPress);

			for (int i=0;i<huoQuShuJu.Tables["XinXiDian"].Rows.Count;i++)
			{
				shuRuKuang.Items.Add (huoQuShuJu.Tables["XinXiDian"].Rows[i]["XinXiDianXiJie"].ToString().Trim()) ;
			}
			shuRuKuang.SelectedIndex = 0 ;
			fuKongJian.Controls.Add(shuRuKuang) ;	
		}

		/// <summary>
		/// 创建TextBox控件
		/// </summary>
		private void ChuangJianText(Control fuKongJian ,System.Data.DataRow shujuxiang,int hangZuoBiao,int lieZuoBiao )
		{
			//创建输入框
			TextBox shuRuKuang = new TextBox() ;
			shuRuKuang.Name = "TB_" + shujuxiang["ShuJuXiangKJM"].ToString().Trim() ;
			shuRuKuang.MaxLength = int.Parse(shujuxiang["ZuiDaShuRuChangDu"].ToString().Trim()) ;
			shuRuKuang.Location = new System.Drawing.Point((hangZuoBiao+100) , lieZuoBiao);
			shuRuKuang.Size = new System.Drawing.Size(130, 25);

			if (shujuxiang["ZhiDu"].ToString().Trim()=="Y")
				shuRuKuang.ReadOnly = true ;

			if (shujuxiang["MoRenZhi"].ToString().Trim()!="")
				shuRuKuang.Text = shujuxiang["MoRenZhi"].ToString().Trim() ;

			//处理数据项类型
			string leiXing = shujuxiang["ShuJuXiangKJLX"].ToString().Trim() ;
			switch (leiXing)
			{
				case "日期数据类型":
					shuRuKuang.ReadOnly = true ;
					//创建按钮
					Button BT_RiQI = new Button() ;
					BT_RiQI.Name = "BT_" + shujuxiang["ShuJuXiangKJM"].ToString().Trim() ; 
					BT_RiQI.Text = "..." ;
					BT_RiQI.Size = new System.Drawing.Size(23, 23) ;
					BT_RiQI.Location = new System.Drawing.Point((hangZuoBiao+230), lieZuoBiao);
					BT_RiQI.Click += new System.EventHandler(this.BT_RiQi_Click);
					fuKongJian.Controls.Add(BT_RiQI) ;	
					break;
				case "浮点数据类型":
					shuRuKuang.KeyPress  += new System.Windows.Forms.KeyPressEventHandler(this.txtBox_KeyPress);
					shuRuKuang.ReadOnly = false ;
					break;
			}
			fuKongJian.Controls.Add(shuRuKuang) ;	
		}

		/// <summary>
		/// 取值
		/// </summary>
		/// <param name="kongjianm"></param>
		/// <returns></returns>
		private string QuZhi(string kongjianm)
		{
			string lzhi="";
			Control ctl=(HuoQuKJ(kongjianm));	
			if (ctl!=null)															
			{
				if(ctl.GetType().Equals(typeof(System.Windows.Forms.TextBox)))
					lzhi=((TextBox)ctl).Text; 

				if(ctl.GetType().Equals(typeof(System.Windows.Forms.ComboBox)))
					lzhi=((ComboBox)ctl).SelectedIndex.ToString() ; 
			}
			return lzhi ;
		}

		/// <summary>
		/// 赋值
		/// </summary>
		/// <param name="kongjianm"></param>
		/// <param name="zhi"></param>
		private void FuZhi(string kongjianm,string zhi)
		{
			Control ctl=(HuoQuKJ(kongjianm));	
			if (ctl!=null)															
			{
				if(ctl.GetType().Equals(typeof(System.Windows.Forms.TextBox)))
					((TextBox)ctl).Text = zhi ;
 
				if(ctl.GetType().Equals(typeof(System.Windows.Forms.ComboBox)))
				{
					((ComboBox)ctl).Text  = "" ; 
					((ComboBox)ctl).Text = zhi ; 
				}
			}
		}

		/// <summary>
		/// 确定事件
		/// </summary>
		private void BT_QueDing_Click(object sender, System.EventArgs e)
		{
			//获得控件数据
			if(KongJianQuZhi()) 
			{
				//提交数据请求
				this.chaXunShuJu.XuQiuTiJiao(this.huoQuShuJu); 
				this.Close(); 
			}
		}

		/// <summary>
		/// 取消按钮事件
		/// </summary>
		private void BT_QuXiao_Click(object sender, System.EventArgs e)
		{
			this.Close();
		}

		#region 动态事件区

		/// <summary>
		/// 键盘事件
		/// </summary>
		private void txtBox_KeyPress(object sender, System.Windows.Forms.KeyPressEventArgs e)
		{
			if(Char.IsLetter(e.KeyChar))
			{
				e.Handled = true;
			}
			return ;
		}
		
		/// <summary>
		/// 下拉框键盘事件
		/// </summary>
		private void coboBox_KeyPress(object sender, System.Windows.Forms.KeyPressEventArgs e)
		{
			e.Handled = true;
		}

		private void coboBox_KeyDown(object sender, System.Windows.Forms.KeyEventArgs e)
		{
			e.Handled = true;
		}
		#endregion

		#region 日期
		/// <summary>
		/// 返回选择日期
		/// </summary>
		private void MyCalendar_DateSelected(object sender, System.Windows.Forms.DateRangeEventArgs e)
		{
			//显示格式
			TextBox bianJiKuang = (TextBox)this.HuoQuKJ(mdangQianShuRuK) ;
			bianJiKuang.Text=e.Start.ToString("yyyy-MM-dd");
			mRiQiForm.Hide();
		}

		/// <summary>
		/// 日期按钮控件事件
		/// </summary>
		private void BT_RiQi_Click(object sender, System.EventArgs e)
		{
			//获取当前输入框
			string[] kongjianm = (((Button)sender).Name).Split('_') ;
			if (kongjianm.Length <2) return ;
			mdangQianShuRuK ="TB_" + kongjianm[1] ;
			TextBox bianJiKuang = (TextBox)this.HuoQuKJ(mdangQianShuRuK) ;
			
			this.mRiQiForm.MyCalendar.DateSelected += new System.Windows.Forms.DateRangeEventHandler(this.MyCalendar_DateSelected);
			System.Drawing.Point mPoint=((Button)sender).PointToScreen(((Button)sender).Location);
			mPoint.X= mPoint.X-((Button)sender).Location.X ;
			mPoint.Y= mPoint.Y-((Button)sender).Location.Y+20 ;
			mRiQiForm.Location =mPoint;
			if (bianJiKuang.Text!="")
			{
				try
				{   
					DateTime mdt=DateTime.Parse(bianJiKuang.Text);
					mRiQiForm.MyCalendar.SetDate(mdt);
				}
				catch
				{
					bianJiKuang.Text="";
					mRiQiForm.MyCalendar.SetDate(DateTime.Now.Date);
				}
			}
			else
			{
				mRiQiForm.MyCalendar.SetDate(DateTime.Now.Date);
			}
			mRiQiForm.ShowDialog();
		}

		#endregion
		#endregion

		#region 保护方法区域
		/// <summary>
		/// 清理所有正在使用的资源。
		/// </summary>
		protected override void Dispose( bool disposing )
		{
			if( disposing )
			{
				if(components != null)
				{
					components.Dispose();
				}
			}
			base.Dispose( disposing );
		}

		/// <summary>
		/// 初始化界面
		/// 创建控件，控件属性定义
		/// </summary>
		protected void ChuShiHua(System.Data.DataSet shuju)
		{
			//获取界面的描述
			huoQuShuJu = ChuangJianShuJuJi() ;
												 	 
			if (shuju!=null)
				this.DaoRuSHuJu(shuju) ;

			//创建控件  控件有两个数据组：信息组和反馈组   分类加载
			//信息组
			this.ChuShiHuaXinXiZu(huoQuShuJu) ;
			
			//反馈组(只在县级显示)
			this.ChuShiHuaFanKuiZu(huoQuShuJu);
		}

		/// <summary>
		/// 设置界面编辑状态
		/// </summary>
		protected void SheZhiZhuangTai()
		{
			if (this.mzhuangTai==0)
			{
				//乡级
				GB_FanKuiZu.Visible = false;
				GB_XinXiZu.Height = 450 ;
			}
			else if (this.mzhuangTai==1)
			{
				//县级
				GB_XinXiZu.Enabled = false ;
			}
			else if (this.mzhuangTai==2)
			{
				GB_FanKuiZu.Enabled = false ;
				GB_XinXiZu.Enabled = false ;
				this.KongJianFuZhi() ;

				this.BT_QueDing .Visible = false ;
				this.BT_QuXiao.Text = "关闭" ;
				this.Text = "调看需求信息";
			}
		}

		/// <summary>
		/// 给控件赋值
		/// </summary>
		protected void KongJianFuZhi()
		{
			string lieMing = "" ;
			string kongJianMing ="" ;
			string shuJuLeiXing = "" ;
			string zhi = "";
			
			if (huoQuShuJu.Tables["ShuJu"].Rows.Count==0) return ;
			for (int i=0;i<huoQuShuJu.Tables["ShuJu"].Columns.Count;i++)
			{
				lieMing = huoQuShuJu.Tables["ShuJu"].Columns[i].ColumnName ;
				kongJianMing = "TB_" + lieMing;
				zhi = huoQuShuJu.Tables["ShuJu"].Rows[0][i].ToString().Trim() ;
				
				//日期行数据处理
				System.Data.DataRow[] rwshuJuLeiXing = huoQuShuJu.Tables["PeiZhi"].Select("ShuJuXiangKJM='" + lieMing + "'") ;
				shuJuLeiXing = rwshuJuLeiXing[0]["ShuJuXiangKJLX"].ToString().Trim() ;
				if (shuJuLeiXing=="日期数据类型"&&zhi!="")
					zhi = Convert.ToDateTime(zhi).ToShortDateString() ;

				//信息点编号
				if (lieMing=="XinXiDianBianHao")
				{
					System.Data.DataRow[] xinXinD = huoQuShuJu.Tables["XinXiDian"].Select("XinXiDianBianHao='" + zhi + "'") ;
					if (xinXinD.Length>0)
						zhi = xinXinD[0]["XinXiDianXiJie"].ToString().Trim() ;
				}
				//需求类别 
				if (lieMing=="XuQiuLeiBie")
				{
					System.Data.DataRow[] xinXinD = huoQuShuJu.Tables["XuQiuFenLei"].Select("XuQiuDaMa='" + zhi + "'") ;
					if (xinXinD.Length>0)
						zhi = xinXinD[0]["XuQiuDaMaMingXi"].ToString().Trim() ;
				}

				FuZhi(kongJianMing,zhi) ;
			}
		}

		/// <summary>
		/// 从控件中取值
		/// </summary>
		protected bool KongJianQuZhi()
		{
			string lieMing = "" ;
			string kongJianMing ="" ;
			huoQuShuJu.Tables["ShuJu"].Rows.Clear() ;
			System.Data.DataRow xinHang = huoQuShuJu.Tables["ShuJu"].NewRow() ;
			System.Data.DataRow[] shuJuXiang ;

			//过滤数据项  信息点和反馈组是分开存储的。
			System.Collections.Hashtable table = new Hashtable() ;
			System.Data.DataRow[] guoLv ;
			if (this.mzhuangTai==1)
				guoLv = huoQuShuJu.Tables["PeiZhi"].Select("ShuJuZuKJM = 'FanKuiZu'");
			else
				guoLv = huoQuShuJu.Tables["PeiZhi"].Select("ShuJuZuKJM = 'XinXiZu'");
			for (int i=0;i<guoLv.Length;i++)
			{
				table.Add (guoLv[i]["ShuJuXiangKJM"].ToString().Trim(),"") ;
			}

			for (int i=0;i<huoQuShuJu.Tables["ShuJu"].Columns.Count;i++)
			{
				lieMing = huoQuShuJu.Tables["ShuJu"].Columns[i].ColumnName ;
				shuJuXiang = huoQuShuJu.Tables["PeiZhi"].Select("ShuJuXiangKJM='" + lieMing + "'") ; 

				if (table.ContainsKey (lieMing))
				{
					kongJianMing = "TB_" + lieMing;
					string zhi = QuZhi(kongJianMing) ;

					//XiTongShuJu  不能为空
					if (zhi==""&&shuJuXiang[0]["XiTongShuJu"].ToString().Trim()=="Y" )
					{
						MessageBox.Show (shuJuXiang[0]["ShuJuXiangMing"].ToString().Trim() + " 不能为空！");
						return false ;
					}
					//浮点书校验
					if (zhi!=""&&shuJuXiang[0]["ShuJuXiangKJLX"].ToString().Trim()=="浮点数据类型" )
					{
						try
						{
							float fuDianShu = Convert.ToSingle(zhi) ;
						}
						catch
						{
							MessageBox.Show (shuJuXiang[0]["ShuJuXiangMing"].ToString().Trim() + "必须为浮点数！");
							return false ;
						}
					}
					else if (zhi==""&&shuJuXiang[0]["ShuJuXiangKJLX"].ToString().Trim()=="浮点数据类型" )
						zhi="0";

					//需求类别
					if (shuJuXiang[0]["ShuJuXiangMing"].ToString().Trim()=="需求类别")
					{
						int suoYing = int.Parse(zhi);
						zhi = huoQuShuJu.Tables["XuQiuFenLei"].Rows[suoYing]["XuQiuDaMa"].ToString().Trim() ;
					}

					//信息点编号
					if (shuJuXiang[0]["ShuJuXiangMing"].ToString().Trim()=="信息点编号")
					{
						int suoYing = int.Parse(zhi);
						zhi = huoQuShuJu.Tables["XinXiDian"].Rows[suoYing]["XinXiDianBianHao"].ToString().Trim() ;
					}

					xinHang[lieMing] = zhi ;
				}
			}
			
			huoQuShuJu.Tables["ShuJu"].Rows.Add(xinHang) ;

			return true ;
		}


		#endregion

		#region 公共方法区域
		/// <summary>
		/// 构造函数
		/// </summary>
		/// 
		public XuQiuLuRuForm()
		{
			InitializeComponent();
		}

		/// <summary>
		/// 构造函数
		/// </summary>
		/// <param name="jiemianKongZhi">界面控制对象</param>
		/// <param name="zhuangtai">界面状态 </param>
		/// <param name="shuju">界面显示数据</param>
		public XuQiuLuRuForm(JSW.FPMS.Xiang.KongZhi.clsXuQiuChaXunKongZhi jiemianKongZhi,int zhuangtai,System.Data.DataSet shuju)
		{
			InitializeComponent();
			this.mzhuangTai = zhuangtai ;
			chaXunShuJu = jiemianKongZhi;
			this.ChuShiHua(shuju);
			mRiQiForm = new RiQiForm();
			this.SheZhiZhuangTai() ;
			this.SheZhiFormSize() ;
		}

		/// <summary>
		/// 获取控件;
		/// 通过名称查找到相应控件
		/// </summary>
		public Control HuoQuKJ(string kongjianmc)
		{	
			Control ctl=null;					 			
			foreach (Control frmctl in this.Controls)
			{				
				//得到groupbox
				if (typeof(System.Windows.Forms.GroupBox).Equals(frmctl.GetType())) 
				{
					foreach (Control grpctl in frmctl.Controls) 
					{	
						//得到Panel
						if (typeof(System.Windows.Forms.Panel).Equals(grpctl.GetType())) 
						{
							foreach (Control panctl in grpctl.Controls) 
							{
								if(panctl.Name.Equals(kongjianmc))
								{
									ctl=panctl;
									return panctl;
								}
							}
						}
					}
				}

				if(frmctl.Name.Equals(kongjianmc))
				{
					ctl=frmctl;
					return frmctl;}
			}
			
			return ctl;
		}
		
		#region 数据处理
		
		/// <summary>
		/// 构造界面数据集
		/// 包括两个DataTable： JieGou  界面元素描述 ； ShuJu 存放界面中得到的数据
		///   其中：JieGou的DataTable为从服务器端得到的配置dataTable ,
		///         ShuJu 的DataTable 列名为结构DataTable 中的ShuJuXiangKJM的值
		/// </summary>
		/// <returns></returns>
		public System.Data.DataSet ChuangJianShuJuJi()
		{
			System.Data.DataSet ret = new System.Data.DataSet() ;
			
			//JieGou
			System.Data.DataSet fuWuQiMiaoShu = chaXunShuJu.HuoDeShuJu(clsChangLiang.SHUJU_PEIZHIXINXI) ;
			ret.Tables.Add(fuWuQiMiaoShu.Tables["PeiZhi"].Copy()) ;
			
			//ShuJu
			System.Data.DataTable shuJuDatable = new System.Data.DataTable("ShuJu") ;
			System.Data.DataColumn xinlie ;
			for (int i=0;i<fuWuQiMiaoShu.Tables["PeiZhi"].Rows.Count;i++)
			{
				xinlie = new System.Data.DataColumn() ;
				xinlie.ColumnName = fuWuQiMiaoShu.Tables["PeiZhi"].Rows[i]["ShuJuXiangKJM"].ToString().Trim() ;
				
				shuJuDatable.Columns.Add(xinlie) ; 
			}

			ret.Tables.Add(shuJuDatable) ;

			fuWuQiMiaoShu = chaXunShuJu.HuoDeShuJu(clsChangLiang.SHUJU_JIBENSHUJU) ;
			ret.Tables.Add(fuWuQiMiaoShu.Tables["XinXiDian"].Copy()) ;
			ret.Tables.Add(fuWuQiMiaoShu.Tables["XuQiuFenLei"].Copy()) ;

			return ret ;
		}

		/// <summary>
		/// 将传入的数据导入到界面DataSet中
		/// </summary>
		public void DaoRuSHuJu(System.Data.DataSet shuju)
		{
			System.Collections.Hashtable table = new Hashtable() ;
			huoQuShuJu.Tables["ShuJu"].Rows.Clear() ;

			System.Data.DataRow xinHang = huoQuShuJu.Tables["ShuJu"].NewRow () ;
			string lieMing = "" ;
			for (int i=0;i<shuju.Tables [0].Columns.Count;i++)
				table.Add(shuju.Tables [0].Columns[i].ColumnName,"") ;

			for (int i=0;i<huoQuShuJu.Tables["ShuJu"].Columns.Count;i++)
			{
				lieMing = huoQuShuJu.Tables["ShuJu"].Columns[i].ColumnName ;
				if (table.ContainsKey(lieMing))
					xinHang[lieMing] = shuju.Tables[0].Rows[0][lieMing].ToString() ;
			}
			huoQuShuJu.Tables["ShuJu"].Rows.Add(xinHang) ;
		}

		#endregion

		#endregion
	}
}
