using System;
using System.Collections;
using System.ComponentModel;
using System.Drawing;
using System.Windows.Forms;
using System.Data;
namespace JXC_MIS.UserTier.NewForm
{
	public class frmItemStore : JXC_MIS.UserTier.BaseForm.frmTreeWindows
	{
		private System.Windows.Forms.ComboBox cbo_FilterName;
		private System.Windows.Forms.Label label1;
		private System.Windows.Forms.ComboBox cbo_FliterValue;
		private System.Windows.Forms.CheckBox chk_AllSelect;
		private System.ComponentModel.IContainer components = null;
		private System.Windows.Forms.DataGridTableStyle dataGridTableStyle2;
		private System.Windows.Forms.DataGridTableStyle dataGridTableStyle3;
		private System.Windows.Forms.DataGridTableStyle dataGridTableStyle4;
		private System.Windows.Forms.DataGridTableStyle dataGridTableStyle5;
		private System.Windows.Forms.DataGridTableStyle dataGridTableStyle6;
		private System.Windows.Forms.DataGridTableStyle dataGridTableStyle7;
		private System.Windows.Forms.DataGridTableStyle dataGridTableStyle1;
		private System.Data.DataTable dt =new System.Data.DataTable();
		private System.Windows.Forms.Button cmd_Insert;
		private System.Windows.Forms.ContextMenu Menu_Right;
		private System.Windows.Forms.MenuItem menuItem1;
		private System.Windows.Forms.DataGridTableStyle 列一;
		private System.Windows.Forms.DataGridBoolColumn dataGridBoolColumn1;
		private System.Windows.Forms.DataGridTextBoxColumn dataGridTextBoxColumn1;
		private System.Windows.Forms.Button cmd_OK;
		private System.Data.DataSet dst = new System.Data.DataSet();

		public frmItemStore()
		{
			// 该调用是 Windows 窗体设计器所必需的。
			InitializeComponent();

			// TODO: 在 InitializeComponent 调用后添加任何初始化
		}
		/// <summary>
		/// 
		/// </summary>
		public System.Data.DataTable GetDataTable
		{ 
			get {return dt;} 
		} 
		/// <summary>
		/// 清理所有正在使用的资源。
		/// </summary>
		protected override void Dispose( bool disposing )
		{
			if( disposing )
			{
				if (components != null) 
				{
					components.Dispose();
				}
			}
			base.Dispose( disposing );
		}

		#region 设计器生成的代码
		/// <summary>
		/// 设计器支持所需的方法 - 不要使用代码编辑器修改
		/// 此方法的内容。
		/// </summary>
		private void InitializeComponent()
		{
			System.Resources.ResourceManager resources = new System.Resources.ResourceManager(typeof(frmItemStore));
			this.cbo_FilterName = new System.Windows.Forms.ComboBox();
			this.label1 = new System.Windows.Forms.Label();
			this.cbo_FliterValue = new System.Windows.Forms.ComboBox();
			this.chk_AllSelect = new System.Windows.Forms.CheckBox();
			this.dataGridTableStyle1 = new System.Windows.Forms.DataGridTableStyle();
			this.dataGridTableStyle2 = new System.Windows.Forms.DataGridTableStyle();
			this.dataGridTableStyle3 = new System.Windows.Forms.DataGridTableStyle();
			this.dataGridTableStyle4 = new System.Windows.Forms.DataGridTableStyle();
			this.dataGridTableStyle5 = new System.Windows.Forms.DataGridTableStyle();
			this.dataGridTableStyle6 = new System.Windows.Forms.DataGridTableStyle();
			this.dataGridTableStyle7 = new System.Windows.Forms.DataGridTableStyle();
			this.cmd_Insert = new System.Windows.Forms.Button();
			this.Menu_Right = new System.Windows.Forms.ContextMenu();
			this.menuItem1 = new System.Windows.Forms.MenuItem();
			this.列一 = new System.Windows.Forms.DataGridTableStyle();
			this.dataGridBoolColumn1 = new System.Windows.Forms.DataGridBoolColumn();
			this.dataGridTextBoxColumn1 = new System.Windows.Forms.DataGridTextBoxColumn();
			this.cmd_OK = new System.Windows.Forms.Button();
			((System.ComponentModel.ISupportInitialize)(this.grd_Bottom)).BeginInit();
			((System.ComponentModel.ISupportInitialize)(this.grd_Top)).BeginInit();
			this.SuspendLayout();
			// 
			// cbo_SetupName
			// 
			this.cbo_SetupName.Location = new System.Drawing.Point(492, 12);
			this.cbo_SetupName.Name = "cbo_SetupName";
			this.cbo_SetupName.Size = new System.Drawing.Size(48, 20);
			this.cbo_SetupName.Visible = true;
			// 
			// sbr_StatusBar
			// 
			this.sbr_StatusBar.Location = new System.Drawing.Point(0, 506);
			this.sbr_StatusBar.Name = "sbr_StatusBar";
			this.sbr_StatusBar.Size = new System.Drawing.Size(762, 25);
			// 
			// tbr_Toolbar
			// 
			this.tbr_Toolbar.Name = "tbr_Toolbar";
			this.tbr_Toolbar.Size = new System.Drawing.Size(762, 41);
			// 
			// panel1
			// 
			this.panel1.Name = "panel1";
			this.panel1.Size = new System.Drawing.Size(762, 465);
			// 
			// spt_H
			// 
			this.spt_H.Location = new System.Drawing.Point(3, 234);
			this.spt_H.Name = "spt_H";
			this.spt_H.Size = new System.Drawing.Size(759, 3);
			// 
			// grd_Bottom
			// 
			this.grd_Bottom.CaptionText = "被选列表";
			this.grd_Bottom.ContextMenu = this.Menu_Right;
			this.grd_Bottom.Location = new System.Drawing.Point(3, 237);
			this.grd_Bottom.Name = "grd_Bottom";
			this.grd_Bottom.Size = new System.Drawing.Size(761, 150);
			this.grd_Bottom.TabIndex = 5;
			this.grd_Bottom.TableStyles.AddRange(new System.Windows.Forms.DataGridTableStyle[] {
																								   this.dataGridTableStyle1,
																								   this.dataGridTableStyle2,
																								   this.dataGridTableStyle3,
																								   this.dataGridTableStyle4,
																								   this.dataGridTableStyle5,
																								   this.dataGridTableStyle6,
																								   this.dataGridTableStyle7,
																								   this.dataGridTableStyle1,
																								   this.dataGridTableStyle2,
																								   this.dataGridTableStyle3,
																								   this.dataGridTableStyle4,
																								   this.dataGridTableStyle5,
																								   this.dataGridTableStyle6,
																								   this.dataGridTableStyle7});
			// 
			// grd_Top
			// 
			this.grd_Top.CaptionBackColor = System.Drawing.Color.LightGray;
			this.grd_Top.CaptionText = "库存查询列表";
			this.grd_Top.Location = new System.Drawing.Point(3, 0);
			this.grd_Top.Name = "grd_Top";
			this.grd_Top.PreferredRowHeight = 16;
			this.grd_Top.ReadOnly = true;
			this.grd_Top.RowHeaderWidth = 25;
			this.grd_Top.Size = new System.Drawing.Size(759, 234);
			this.grd_Top.TableStyles.AddRange(new System.Windows.Forms.DataGridTableStyle[] {
																								this.列一});
			this.grd_Top.DoubleClick += new System.EventHandler(this.grd_Top_DoubleClick);
			this.grd_Top.Navigate += new System.Windows.Forms.NavigateEventHandler(this.grd_Top_Navigate);
			// 
			// spt_V
			// 
			this.spt_V.Location = new System.Drawing.Point(0, 0);
			this.spt_V.Name = "spt_V";
			this.spt_V.Size = new System.Drawing.Size(3, 465);
			// 
			// tv_Tree
			// 
			this.tv_Tree.Name = "tv_Tree";
			this.tv_Tree.Size = new System.Drawing.Size(0, 465);
			// 
			// pnl_Filter
			// 
			this.pnl_Filter.Name = "pnl_Filter";
			// 
			// cmd_Cancel
			// 
			this.cmd_Cancel.Name = "cmd_Cancel";
			// 
			// cmd_ExeQuery
			// 
			this.cmd_ExeQuery.Name = "cmd_ExeQuery";
			// 
			// grd_Filter
			// 
			this.grd_Filter.Name = "grd_Filter";
			// 
			// cbo_FilterName
			// 
			this.cbo_FilterName.Items.AddRange(new object[] {
																"国标型号",
																"国标代码"});
			this.cbo_FilterName.Location = new System.Drawing.Point(316, 12);
			this.cbo_FilterName.Name = "cbo_FilterName";
			this.cbo_FilterName.Size = new System.Drawing.Size(84, 20);
			this.cbo_FilterName.TabIndex = 14;
			this.cbo_FilterName.Text = "国标型号";
			// 
			// label1
			// 
			this.label1.Location = new System.Drawing.Point(252, 20);
			this.label1.Name = "label1";
			this.label1.Size = new System.Drawing.Size(246, 23);
			this.label1.TabIndex = 15;
			this.label1.Text = "查询内容：                值：";
			// 
			// cbo_FliterValue
			// 
			this.cbo_FliterValue.Items.AddRange(new object[] {
																 "<全部>"});
			this.cbo_FliterValue.Location = new System.Drawing.Point(436, 16);
			this.cbo_FliterValue.Name = "cbo_FliterValue";
			this.cbo_FliterValue.Size = new System.Drawing.Size(170, 20);
			this.cbo_FliterValue.TabIndex = 16;
			this.cbo_FliterValue.Text = "<全部>";
			this.cbo_FliterValue.KeyPress += new System.Windows.Forms.KeyPressEventHandler(this.cbo_FliterValue_KeyPress);
			// 
			// chk_AllSelect
			// 
			this.chk_AllSelect.Location = new System.Drawing.Point(614, 16);
			this.chk_AllSelect.Name = "chk_AllSelect";
			this.chk_AllSelect.Size = new System.Drawing.Size(50, 24);
			this.chk_AllSelect.TabIndex = 17;
			this.chk_AllSelect.Text = "全选";
			this.chk_AllSelect.CheckedChanged += new System.EventHandler(this.chk_AllSelect_CheckedChanged);
			// 
			// dataGridTableStyle1
			// 
			this.dataGridTableStyle1.DataGrid = this.grd_Bottom;
			this.dataGridTableStyle1.HeaderForeColor = System.Drawing.SystemColors.ControlText;
			this.dataGridTableStyle1.MappingName = "";
			// 
			// dataGridTableStyle2
			// 
			this.dataGridTableStyle2.DataGrid = this.grd_Bottom;
			this.dataGridTableStyle2.HeaderForeColor = System.Drawing.SystemColors.ControlText;
			this.dataGridTableStyle2.MappingName = "";
			// 
			// dataGridTableStyle3
			// 
			this.dataGridTableStyle3.DataGrid = this.grd_Bottom;
			this.dataGridTableStyle3.HeaderForeColor = System.Drawing.SystemColors.ControlText;
			this.dataGridTableStyle3.MappingName = "";
			// 
			// dataGridTableStyle4
			// 
			this.dataGridTableStyle4.DataGrid = this.grd_Bottom;
			this.dataGridTableStyle4.HeaderForeColor = System.Drawing.SystemColors.ControlText;
			this.dataGridTableStyle4.MappingName = "";
			// 
			// dataGridTableStyle5
			// 
			this.dataGridTableStyle5.DataGrid = this.grd_Bottom;
			this.dataGridTableStyle5.HeaderForeColor = System.Drawing.SystemColors.ControlText;
			this.dataGridTableStyle5.MappingName = "";
			// 
			// dataGridTableStyle6
			// 
			this.dataGridTableStyle6.DataGrid = this.grd_Bottom;
			this.dataGridTableStyle6.HeaderForeColor = System.Drawing.SystemColors.ControlText;
			this.dataGridTableStyle6.MappingName = "";
			// 
			// dataGridTableStyle7
			// 
			this.dataGridTableStyle7.DataGrid = this.grd_Bottom;
			this.dataGridTableStyle7.HeaderForeColor = System.Drawing.SystemColors.ControlText;
			this.dataGridTableStyle7.MappingName = "";
			// 
			// cmd_Insert
			// 
			this.cmd_Insert.Location = new System.Drawing.Point(660, 18);
			this.cmd_Insert.Name = "cmd_Insert";
			this.cmd_Insert.Size = new System.Drawing.Size(42, 23);
			this.cmd_Insert.TabIndex = 18;
			this.cmd_Insert.Text = "加入";
			this.cmd_Insert.Click += new System.EventHandler(this.cmd_Insert_Click);
			// 
			// Menu_Right
			// 
			this.Menu_Right.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
																					   this.menuItem1});
			// 
			// menuItem1
			// 
			this.menuItem1.Index = 0;
			this.menuItem1.Text = "生成销售单";
			// 
			// 列一
			// 
			this.列一.DataGrid = this.grd_Top;
			this.列一.GridColumnStyles.AddRange(new System.Windows.Forms.DataGridColumnStyle[] {
																								 this.dataGridBoolColumn1,
																								 this.dataGridTextBoxColumn1});
			this.列一.HeaderForeColor = System.Drawing.SystemColors.ControlText;
			this.列一.MappingName = "";
			// 
			// dataGridBoolColumn1
			// 
			this.dataGridBoolColumn1.FalseValue = false;
			this.dataGridBoolColumn1.MappingName = "";
			this.dataGridBoolColumn1.NullValue = ((object)(resources.GetObject("dataGridBoolColumn1.NullValue")));
			this.dataGridBoolColumn1.TrueValue = true;
			this.dataGridBoolColumn1.Width = 75;
			// 
			// dataGridTextBoxColumn1
			// 
			this.dataGridTextBoxColumn1.Format = "";
			this.dataGridTextBoxColumn1.FormatInfo = null;
			this.dataGridTextBoxColumn1.MappingName = "";
			this.dataGridTextBoxColumn1.Width = 75;
			// 
			// cmd_OK
			// 
			this.cmd_OK.Location = new System.Drawing.Point(706, 14);
			this.cmd_OK.Name = "cmd_OK";
			this.cmd_OK.Size = new System.Drawing.Size(56, 23);
			this.cmd_OK.TabIndex = 19;
			this.cmd_OK.Text = "确定";
			this.cmd_OK.Click += new System.EventHandler(this.cmd_OK_Click);
			// 
			// frmItemStore
			// 
			this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
			this.ClientSize = new System.Drawing.Size(762, 531);
			this.Controls.Add(this.cmd_OK);
			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 = "frmItemStore";
			this.Text = "库存参照";
			this.Load += new System.EventHandler(this.frmItemStore_Load);
			this.Controls.SetChildIndex(this.pnl_Filter, 0);
			this.Controls.SetChildIndex(this.tbr_Toolbar, 0);
			this.Controls.SetChildIndex(this.sbr_StatusBar, 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.panel1, 0);
			this.Controls.SetChildIndex(this.chk_AllSelect, 0);
			this.Controls.SetChildIndex(this.cmd_Insert, 0);
			this.Controls.SetChildIndex(this.cmd_OK, 0);
			((System.ComponentModel.ISupportInitialize)(this.grd_Bottom)).EndInit();
			((System.ComponentModel.ISupportInitialize)(this.grd_Top)).EndInit();
			this.ResumeLayout(false);

		}
		#endregion


		private void frmItemStore_Load(object sender, System.EventArgs e)
		{
			tv_Tree.Width =140;
			spt_H.Visible =true;
			spt_H.BringToFront() ;
			this.ShowResize();
			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;
			this.InitTreeData("SELECT fcCode, fcName, fnGrade FROM I_ProductLevel");

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

		}

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

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

			}
		}

		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());
				int cs=dt.Columns.Count;
				for (int intColIndex=0;intColIndex<cs;intColIndex++)
					{
						dt.Rows[dt.Rows.Count-1][intColIndex]=this.grd_Top[grd_Top.CurrentCell.RowNumber ,intColIndex];
					}
				dt.Rows[dt.Rows.Count-1][0]=dt.Rows.Count.ToString();
				grd_Bottom.DataSource=dt;

			}

            
		}


		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];
						}
						dt.Rows[dt.Rows.Count-1][0]=dt.Rows.Count.ToString();

					}

				}
					grd_Bottom.DataSource=dt;
		}

		protected override void tv_Tree_Click(object sender, EventArgs e)
		{
			TreeNode tn = new TreeNode();
			tn = tv_Tree.SelectedNode;
			if (tn != null)
			{
				cbo_FliterValue.Text =tn.Tag.ToString() ;
				ShowData(cbo_FliterValue.Text);
			}

		}


		protected override void tbr_Toolbar_ButtonClick(object sender, ToolBarButtonClickEventArgs e)
		{
			base.tbr_Toolbar_ButtonClick (sender, e);
//			switch (e.Button.Tag.ToString())
//			{
//				case "新增":
//					break;
//				case "修改":
//					//					if (grd_Bottom[grd_Bottom.CurrentCell.RowNumber ,0]==null){return;}
//					try
//					{
//					}
//					catch
//					{}
//
//					//					RecordModify();
//					break;
//				case "放弃":
//					////					RecordCancel();
//					break;
//				case "预览":
//
//					break;
//				case "打印":
//					//					ReceiptPrint();
//					break;
//				case "刷新":
//					//					InitData(cbo_SetupName.Text);
//					break;
//				case "查询":
//					//					ReceiptFind();
////					pnl_Filter.Visible =true;
//					break;
//				case "退出":
//					this.Close();
//					break;
//
//				default:
// 
//					break;
//			}

		}

		private void cmd_OK_Click(object sender, System.EventArgs e)
		{
		  this.Close();
		}

		private void grd_Top_Navigate(object sender, System.Windows.Forms.NavigateEventArgs ne)
		{
		
		}



	




	}



}

