using System;
using System.Collections;
using System.ComponentModel;
using System.Drawing;
using System.Windows.Forms;

namespace JXC_MIS.UserTier.NewForm
{
	public class frmStoreQuery : JXC_MIS.UserTier.BaseForm.frmTreeFormBase
	{
		private System.Windows.Forms.ComboBox cbo_FliterValue;
		private System.Windows.Forms.Button cmd_Insert;
		private System.Windows.Forms.CheckBox chk_AllSelect;
		private System.Windows.Forms.ComboBox cbo_FilterName;
		private System.Windows.Forms.Label label1;
		private System.ComponentModel.IContainer components = null;
		private System.Data.DataTable dt =new System.Data.DataTable();
		private System.Data.DataSet dst = new System.Data.DataSet();
		public frmStoreQuery()
		{
			// 该调用是 Windows 窗体设计器所必需的。
			InitializeComponent();

			// TODO: 在 InitializeComponent 调用后添加任何初始化
		}

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

		#region 设计器生成的代码
		/// <summary>
		/// 设计器支持所需的方法 - 不要使用代码编辑器修改
		/// 此方法的内容。
		/// </summary>
		private void InitializeComponent()
		{
			this.cbo_FliterValue = new System.Windows.Forms.ComboBox();
			this.cmd_Insert = new System.Windows.Forms.Button();
			this.chk_AllSelect = new System.Windows.Forms.CheckBox();
			this.cbo_FilterName = new System.Windows.Forms.ComboBox();
			this.label1 = new System.Windows.Forms.Label();
			((System.ComponentModel.ISupportInitialize)(this.grd_Top)).BeginInit();
			((System.ComponentModel.ISupportInitialize)(this.grd_Bottom)).BeginInit();
			this.SuspendLayout();
			// 
			// t_new
			// 
			this.t_new.Visible = false;
			// 
			// sbr_StatusBar
			// 
			this.sbr_StatusBar.Name = "sbr_StatusBar";
			this.sbr_StatusBar.Size = new System.Drawing.Size(716, 25);
			// 
			// t_Modify
			// 
			this.t_Modify.Visible = false;
			// 
			// t_Save
			// 
			this.t_Save.Visible = false;
			// 
			// cbo_SetupName
			// 
			this.cbo_SetupName.Location = new System.Drawing.Point(464, 12);
			this.cbo_SetupName.Name = "cbo_SetupName";
			// 
			// panel1
			// 
			this.panel1.Name = "panel1";
			this.panel1.Size = new System.Drawing.Size(716, 345);
			// 
			// tv_Tree
			// 
			this.tv_Tree.Name = "tv_Tree";
			this.tv_Tree.Size = new System.Drawing.Size(140, 345);
			// 
			// t_Cancel
			// 
			this.t_Cancel.Visible = false;
			// 
			// tbr_Toolbar
			// 
			this.tbr_Toolbar.Name = "tbr_Toolbar";
			this.tbr_Toolbar.Size = new System.Drawing.Size(716, 41);
			// 
			// spt_V
			// 
			this.spt_V.Location = new System.Drawing.Point(140, 0);
			this.spt_V.Name = "spt_V";
			// 
			// spt_H
			// 
			this.spt_H.Location = new System.Drawing.Point(146, 148);
			this.spt_H.Name = "spt_H";
			this.spt_H.Size = new System.Drawing.Size(570, 6);
			// 
			// grd_Top
			// 
			this.grd_Top.Location = new System.Drawing.Point(146, 0);
			this.grd_Top.Name = "grd_Top";
			this.grd_Top.Size = new System.Drawing.Size(570, 148);
			this.grd_Top.DoubleClick += new System.EventHandler(this.grd_Top_DoubleClick);
			// 
			// grd_Bottom
			// 
			this.grd_Bottom.Location = new System.Drawing.Point(146, 154);
			this.grd_Bottom.Name = "grd_Bottom";
			this.grd_Bottom.Size = new System.Drawing.Size(572, 191);
			// 
			// cbo_FliterValue
			// 
			this.cbo_FliterValue.Items.AddRange(new object[] {
																 "<全部>"});
			this.cbo_FliterValue.Location = new System.Drawing.Point(426, 10);
			this.cbo_FliterValue.Name = "cbo_FliterValue";
			this.cbo_FliterValue.Size = new System.Drawing.Size(210, 20);
			this.cbo_FliterValue.TabIndex = 21;
			this.cbo_FliterValue.Text = "<全部>";
			this.cbo_FliterValue.KeyPress += new System.Windows.Forms.KeyPressEventHandler(this.cbo_FliterValue_KeyPress);
			// 
			// cmd_Insert
			// 
			this.cmd_Insert.Location = new System.Drawing.Point(690, 10);
			this.cmd_Insert.Name = "cmd_Insert";
			this.cmd_Insert.Size = new System.Drawing.Size(62, 23);
			this.cmd_Insert.TabIndex = 23;
			this.cmd_Insert.Text = "加入";
			this.cmd_Insert.Click += new System.EventHandler(this.cmd_Insert_Click);
			// 
			// chk_AllSelect
			// 
			this.chk_AllSelect.Location = new System.Drawing.Point(646, 10);
			this.chk_AllSelect.Name = "chk_AllSelect";
			this.chk_AllSelect.TabIndex = 22;
			this.chk_AllSelect.Text = "全选";
			this.chk_AllSelect.Click += new System.EventHandler(this.chk_AllSelect_CheckedChanged);
			// 
			// cbo_FilterName
			// 
			this.cbo_FilterName.Items.AddRange(new object[] {
																"国标型号",
																"国标代码"});
			this.cbo_FilterName.Location = new System.Drawing.Point(306, 10);
			this.cbo_FilterName.Name = "cbo_FilterName";
			this.cbo_FilterName.Size = new System.Drawing.Size(84, 20);
			this.cbo_FilterName.TabIndex = 19;
			this.cbo_FilterName.Text = "国标型号";
			// 
			// label1
			// 
			this.label1.Location = new System.Drawing.Point(242, 14);
			this.label1.Name = "label1";
			this.label1.Size = new System.Drawing.Size(246, 23);
			this.label1.TabIndex = 20;
			this.label1.Text = "查询内容：                值：";
			// 
			// frmStoreQuery
			// 
			this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
			this.ClientSize = new System.Drawing.Size(716, 411);
			this.Controls.Add(this.cmd_Insert);
			this.Controls.Add(this.chk_AllSelect);
			this.Controls.Add(this.cbo_FliterValue);
			this.Controls.Add(this.cbo_FilterName);
			this.Controls.Add(this.label1);
			this.Name = "frmStoreQuery";
			this.Load += new System.EventHandler(this.frmStoreQuery_Load);
			this.Controls.SetChildIndex(this.tbr_Toolbar, 0);
			this.Controls.SetChildIndex(this.sbr_StatusBar, 0);
			this.Controls.SetChildIndex(this.panel1, 0);
			this.Controls.SetChildIndex(this.cbo_SetupName, 0);
			this.Controls.SetChildIndex(this.label1, 0);
			this.Controls.SetChildIndex(this.cbo_FilterName, 0);
			this.Controls.SetChildIndex(this.cbo_FliterValue, 0);
			this.Controls.SetChildIndex(this.chk_AllSelect, 0);
			this.Controls.SetChildIndex(this.cmd_Insert, 0);
			((System.ComponentModel.ISupportInitialize)(this.grd_Top)).EndInit();
			((System.ComponentModel.ISupportInitialize)(this.grd_Bottom)).EndInit();
			this.ResumeLayout(false);

		}
		#endregion

		private void frmStoreQuery_Load(object sender, System.EventArgs e)
		{
			this.Text ="库存查询";
			ShowData("刘金山");
			int	cs=dst.Tables[0].Columns.Count;

			for (int intRowIndex=0;intRowIndex<cs;intRowIndex++)
			{
				dt.Columns.Add(dst.Tables[0].Columns[intRowIndex].Caption);
			}	
			grd_Bottom.DataSource=dt;
		}

		private  void ShowData(string p_Filter)
		{
			int rs;
			if (p_Filter=="<全部>") { p_Filter="";} 
			else { p_Filter=cbo_FliterValue.Text;}
			dst= newADO.GetDataSet("ljs_KC_ProLibStore '"+p_Filter +"'");
			this.grd_Top.DataSource=dst.Tables[0] ;
			rs=dst.Tables[0].Rows.Count+1;
			//添加行号
			for (int r=1;r<rs;r++)
			{
				this.grd_Top[r-1,grd_Top.CurrentCell.ColumnNumber]=r.ToString();
			}

		}

		private void cbo_FliterValue_KeyPress(object sender, System.Windows.Forms.KeyPressEventArgs e)
		{
			//			string sFilterValue;

			if (e.KeyChar == (char)13) 
			{	
				ShowData(cbo_FliterValue.Text);

				////				if (cbo_FliterValue.Text=="<全部>") { sFilterValue="";} else { sFilterValue=cbo_FliterValue.Text;}
				////				System.Data.DataSet dst = new System.Data.DataSet();
				////				dst= newADO.GetDataSet("ljs_KC_ProLibStore '"+sFilterValue +"'");
				////				this.grd_Top.DataSource=dst.Tables[0] ;
				////				rs=dst.Tables[0].Rows.Count+1;
				////				cs=dst.Tables[0].Columns.Count;
				////				for (int r=1;r<rs;r++)
				////				{
				////				  this.grd_Top[r-1,grd_Top.CurrentCell.ColumnNumber]=r.ToString();
				////				
				////				}
				////				grd_Top.TableStyles.Count ;
				////					for (int intRowIndex=0;intRowIndex<cs;intRowIndex++)
				////					{
				//////						dt.Rows.Add(dt.NewRow());
				////						dt.Columns.Add(dst.Tables[0].Columns[intRowIndex].Caption);
				////					}	
				////		                grd_Bottom.DataSource=dt;
			}
		}

		private void grd_Top_DoubleClick(object sender, System.EventArgs e)
		{
			//"√";
			int rs=0;
			if (this.grd_Top[grd_Top.CurrentCell.RowNumber ,0].ToString() =="√")
			{
				rs=grd_Top.CurrentCell.RowNumber+1;
				this.grd_Top[grd_Top.CurrentCell.RowNumber ,0]=rs.ToString();
			}
			else
			{
				this.grd_Top[grd_Top.CurrentCell.RowNumber ,0]="√";
				dt.Rows.Add(dt.NewRow());
				for (int intColIndex=0;intColIndex<dt.Columns.Count-1;intColIndex++)
				{
					dt.Rows[dt.Rows.Count-1][intColIndex]=this.grd_Top[grd_Top.CurrentCell.RowNumber ,intColIndex];
				}
				grd_Bottom.DataSource=dt;

			}

            
		}

		private void frmItemStore_Load(object sender, System.EventArgs e)
		{

			

		}

		private void chk_AllSelect_CheckedChanged(object sender, System.EventArgs e)
		{
			int rs=dst.Tables[0].Rows.Count;
			if (chk_AllSelect.Checked==true)
			{
				//添加行号
				for (int r=0;r<rs;r++)
				{
					this.grd_Top[r ,0]="√";
				}
			}
			else
			{
				//添加行号
				for (int r=1;r<rs+1;r++)
				{
					this.grd_Top[r-1,0]=r.ToString();
				}
			
			}
		}

		private void cmd_Insert_Click(object sender, System.EventArgs e)
		{
			int rs=dst.Tables[0].Rows.Count;
			int cs=dt.Columns.Count;
			//添加行号
			for (int r=0;r<rs;r++)
			{
				if (this.grd_Top[r ,0].ToString()=="√")
				{
					dt.Rows.Add(dt.NewRow());
					for (int intColIndex=0;intColIndex<cs;intColIndex++)
					{
						dt.Rows[dt.Rows.Count-1][intColIndex]=this.grd_Top[r ,intColIndex];
					}
				}

			}
			grd_Bottom.DataSource=dt;
		}

          
		//		private void InitDataGrid()
		//		{
		//			DataTable dt =new DataTable();
		//			int intRowIndex;
		//			int intColIndex;
		//			for (intRowIndex=0;intRowIndex<9;intRowIndex++)
		//			{
		//				dt.Rows.Add(dt.NewRow());
		//				dt.Columns.Add();
		//			}	
		//
		//			for (intRowIndex=0;intRowIndex<9;intRowIndex++)
		//			{				
		//				for (intColIndex=0;intColIndex<9;intColIndex++)
		//				{
		//					dt.Rows[intRowIndex][intColIndex]=intRowIndex.ToString()+"行"+intColIndex.ToString()+"列";
		//				}
		//			}	
		//
		//			
		//			this.dataGrid1.DataSource=dt;
		//		}





















	}
}

