using System;
using System.Collections;
using System.ComponentModel;
using System.Drawing;
using System.Windows.Forms;
using ljs;
using JXC_MIS.MyClass;
using JXC_MIS.DataTier;
using JXC_MIS.UserTier.CommonForm  ;
using JXC_MIS.Interface;

namespace JXC_MIS.UserTier.NewForm
{
	public class frmReadyGoods : JXC_MIS.UserTier.BaseForm.frmTreeFlexGrid 
	{
		private System.ComponentModel.IContainer components = null;
		private System.Windows.Forms.MenuItem m_RecordBatch;
		private System.Windows.Forms.MenuItem mnu_DetailColWidth;
		private System.Windows.Forms.Button cmd_Start;
		private System.Windows.Forms.Button cmd_Save;
		private System.Windows.Forms.Button cmd_CancelReady;
		protected System.Windows.Forms.Button btnDown;

		private System.Data.DataSet dst = new System.Data.DataSet();
		protected ClsDataBase newDB=new ClsDataBase() ;
		protected ClsReceiptAttrib newR_Attrib=new ClsReceiptAttrib();
//		protected ClsReceiptMethod newR_Method=new ClsReceiptMethod();
		protected ClsCellAttrib newCellAttrib=new ClsCellAttrib();
		protected string m_RefertoReturnCols  ;		       //参照返回列值
		protected string m_RefertoInputCols  ;			       //目标列对应列
		protected string m_MouseEnterPlace  ;			       //鼠标单击时所在位置 ,主表位置"Master"	明细表位置 "Detail"
		private IReferto  m_IRefertoForm;
		private ToolTip nToolTip=new ToolTip();  //控件提示
		private string m_ColExpress;                   //计算列表达式
		private string m_ShowFormat;                    //显示格式
		string MasterSql="";
		string DetailSql="";
		string sReceiptNO="";
		protected TextBox TxtTemp=new TextBox() ;
		protected System.Windows.Forms.ComboBox CboReceiptNo;
		private System.Windows.Forms.Label label1;
		private System.Windows.Forms.ComboBox cbo_Operator;
		private string  m_OtherFilter;   //参照其他过滤条件
		/// <summary>
		/// 参照其他过滤条件
		/// </summary>
		public string OtherFilter
		{ 
			get {return m_OtherFilter;} 
			set { m_OtherFilter=value;} 
		} 
		public struct Cell
		{
		    public string Tag;
			public string Text;
		}
		Cell ActiveCell=new Cell();

		public frmReadyGoods()
		{
			// 该调用是 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()
		{
			System.Resources.ResourceManager resources = new System.Resources.ResourceManager(typeof(frmReadyGoods));
			this.m_RecordBatch = new System.Windows.Forms.MenuItem();
			this.mnu_DetailColWidth = new System.Windows.Forms.MenuItem();
			this.cmd_Start = new System.Windows.Forms.Button();
			this.cmd_Save = new System.Windows.Forms.Button();
			this.cmd_CancelReady = new System.Windows.Forms.Button();
			this.btnDown = new System.Windows.Forms.Button();
			this.CboReceiptNo = new System.Windows.Forms.ComboBox();
			this.label1 = new System.Windows.Forms.Label();
			this.cbo_Operator = new System.Windows.Forms.ComboBox();
			this.panel1.SuspendLayout();
			this.SuspendLayout();
			// 
			// panel1
			// 
			this.panel1.Controls.Add(this.btnDown);
			this.panel1.Name = "panel1";
			this.panel1.Size = new System.Drawing.Size(714, 358);
			this.panel1.Controls.SetChildIndex(this.cbo_SetupName, 0);
			this.panel1.Controls.SetChildIndex(this.tv_Tree, 0);
			this.panel1.Controls.SetChildIndex(this.spt_V, 0);
			this.panel1.Controls.SetChildIndex(this.grd_Top, 0);
			this.panel1.Controls.SetChildIndex(this.spt_H, 0);
			this.panel1.Controls.SetChildIndex(this.grd_Bottom, 0);
			this.panel1.Controls.SetChildIndex(this.btnDown, 0);
			// 
			// spt_H
			// 
			this.spt_H.Location = new System.Drawing.Point(3, 0);
			this.spt_H.Name = "spt_H";
			this.spt_H.Size = new System.Drawing.Size(711, 3);
			// 
			// 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, 358);
			// 
			// tv_Tree
			// 
			this.tv_Tree.Name = "tv_Tree";
			this.tv_Tree.Size = new System.Drawing.Size(0, 358);
			this.tv_Tree.AfterExpand += new System.Windows.Forms.TreeViewEventHandler(this.tv_Tree_AfterExpand);
			this.tv_Tree.DoubleClick += new System.EventHandler(this.tv_Tree_DoubleClick);
			this.tv_Tree.AfterSelect += new System.Windows.Forms.TreeViewEventHandler(this.tv_Tree_AfterSelect);
			this.tv_Tree.BeforeSelect += new System.Windows.Forms.TreeViewCancelEventHandler(this.tv_Tree_BeforeSelect);
			this.tv_Tree.BeforeExpand += new System.Windows.Forms.TreeViewCancelEventHandler(this.tv_Tree_BeforeExpand);
			// 
			// cbo_SetupName
			// 
			this.cbo_SetupName.Name = "cbo_SetupName";
			this.cbo_SetupName.Size = new System.Drawing.Size(124, 20);
			// 
			// t_Find
			// 
			this.t_Find.Visible = false;
			// 
			// pnl_Filter
			// 
			this.pnl_Filter.Name = "pnl_Filter";
			// 
			// cmd_Cancel
			// 
			this.cmd_Cancel.FlatStyle = System.Windows.Forms.FlatStyle.Popup;
			this.cmd_Cancel.Name = "cmd_Cancel";
			// 
			// cmd_ExeQuery
			// 
			this.cmd_ExeQuery.FlatStyle = System.Windows.Forms.FlatStyle.Popup;
			this.cmd_ExeQuery.Name = "cmd_ExeQuery";
			// 
			// grd_Filter
			// 
			this.grd_Filter.Name = "grd_Filter";
			// 
			// sbr_StatusBar
			// 
			this.sbr_StatusBar.Location = new System.Drawing.Point(0, 386);
			this.sbr_StatusBar.Name = "sbr_StatusBar";
			this.sbr_StatusBar.Size = new System.Drawing.Size(714, 25);
			// 
			// tbr_Toolbar
			// 
			this.tbr_Toolbar.Name = "tbr_Toolbar";
			this.tbr_Toolbar.Size = new System.Drawing.Size(714, 28);
			// 
			// grd_Top
			// 
			this.grd_Top.Location = new System.Drawing.Point(3, 0);
			this.grd_Top.Name = "grd_Top";
			this.grd_Top.Size = new System.Drawing.Size(711, 0);
			// 
			// grd_Bottom
			// 
			this.grd_Bottom.Location = new System.Drawing.Point(3, 3);
			this.grd_Bottom.Name = "grd_Bottom";
			this.grd_Bottom.Size = new System.Drawing.Size(709, 443);
			this.grd_Bottom.Row_Click += new ljs.FlexGridRow_Click(this.grd_Bottom_Row_Click);
			this.grd_Bottom.Load += new System.EventHandler(this.grd_Bottom_Load);
			this.grd_Bottom.Scroll += new ljs.FlexGrid_Scroll(this.grd_Bottom_Scroll);
			this.grd_Bottom.Cell_Enter += new ljs.FlexGridCell_Enter(this.grd_Bottom_Cell_Enter);
			// 
			// ctm_Menu
			// 
			this.ctm_Menu.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
																					 this.mnu_DetailColWidth,
																					 this.m_RecordBatch});
			// 
			// img_ImageList
			// 
			this.img_ImageList.ImageStream = ((System.Windows.Forms.ImageListStreamer)(resources.GetObject("img_ImageList.ImageStream")));
			// 
			// m_RecordBatch
			// 
			this.m_RecordBatch.Index = 1;
			this.m_RecordBatch.Text = "产品分批";
			this.m_RecordBatch.Click += new System.EventHandler(this.m_RecordBatch_Click);
			// 
			// mnu_DetailColWidth
			// 
			this.mnu_DetailColWidth.Index = 0;
			this.mnu_DetailColWidth.Text = "明细列宽设置";
			this.mnu_DetailColWidth.Click += new System.EventHandler(this.mnu_DetailColWidth_Click);
			// 
			// cmd_Start
			// 
			this.cmd_Start.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
			this.cmd_Start.Location = new System.Drawing.Point(472, 2);
			this.cmd_Start.Name = "cmd_Start";
			this.cmd_Start.Size = new System.Drawing.Size(84, 24);
			this.cmd_Start.TabIndex = 23;
			this.cmd_Start.Text = "开始备货(&S)";
			this.cmd_Start.Click += new System.EventHandler(this.cmd_Start_Click);
			// 
			// cmd_Save
			// 
			this.cmd_Save.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
			this.cmd_Save.Location = new System.Drawing.Point(554, 2);
			this.cmd_Save.Name = "cmd_Save";
			this.cmd_Save.Size = new System.Drawing.Size(76, 24);
			this.cmd_Save.TabIndex = 24;
			this.cmd_Save.Text = "保存(&S)";
			this.cmd_Save.Click += new System.EventHandler(this.cmd_Save_Click);
			// 
			// cmd_CancelReady
			// 
			this.cmd_CancelReady.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
			this.cmd_CancelReady.Location = new System.Drawing.Point(628, 2);
			this.cmd_CancelReady.Name = "cmd_CancelReady";
			this.cmd_CancelReady.Size = new System.Drawing.Size(84, 24);
			this.cmd_CancelReady.TabIndex = 25;
			this.cmd_CancelReady.Text = "取消备货(&C)";
			this.cmd_CancelReady.Click += new System.EventHandler(this.cmd_CancelReady_Click);
			// 
			// btnDown
			// 
			this.btnDown.BackColor = System.Drawing.Color.Transparent;
			this.btnDown.BackgroundImage = ((System.Drawing.Image)(resources.GetObject("btnDown.BackgroundImage")));
			this.btnDown.Font = new System.Drawing.Font("Marlett", 9F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(2)));
			this.btnDown.Location = new System.Drawing.Point(348, 162);
			this.btnDown.Name = "btnDown";
			this.btnDown.Size = new System.Drawing.Size(16, 18);
			this.btnDown.TabIndex = 62;
			this.btnDown.Visible = false;
			this.btnDown.Click += new System.EventHandler(this.btnDown_Click);
			// 
			// CboReceiptNo
			// 
			this.CboReceiptNo.Location = new System.Drawing.Point(380, 4);
			this.CboReceiptNo.Name = "CboReceiptNo";
			this.CboReceiptNo.Size = new System.Drawing.Size(86, 20);
			this.CboReceiptNo.TabIndex = 61;
			this.CboReceiptNo.Visible = false;
			// 
			// label1
			// 
			this.label1.Location = new System.Drawing.Point(240, 6);
			this.label1.Name = "label1";
			this.label1.Size = new System.Drawing.Size(228, 12);
			this.label1.TabIndex = 62;
			this.label1.Text = "备货人：";
			// 
			// cbo_Operator
			// 
			this.cbo_Operator.Location = new System.Drawing.Point(320, 4);
			this.cbo_Operator.Name = "cbo_Operator";
			this.cbo_Operator.Size = new System.Drawing.Size(140, 20);
			this.cbo_Operator.TabIndex = 63;
			// 
			// frmReadyGoods
			// 
			this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
			this.ClientSize = new System.Drawing.Size(714, 411);
			this.Controls.Add(this.cbo_Operator);
			this.Controls.Add(this.label1);
			this.Controls.Add(this.CboReceiptNo);
			this.Controls.Add(this.cmd_Start);
			this.Controls.Add(this.cmd_Save);
			this.Controls.Add(this.cmd_CancelReady);
			this.Name = "frmReadyGoods";
			this.Text = "备货单";
			this.Load += new System.EventHandler(this.frmReadyGoods_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.pnl_Filter, 0);
			this.Controls.SetChildIndex(this.cmd_CancelReady, 0);
			this.Controls.SetChildIndex(this.cmd_Save, 0);
			this.Controls.SetChildIndex(this.cmd_Start, 0);
			this.Controls.SetChildIndex(this.CboReceiptNo, 0);
			this.Controls.SetChildIndex(this.label1, 0);
			this.Controls.SetChildIndex(this.cbo_Operator, 0);
			this.panel1.ResumeLayout(false);
			this.ResumeLayout(false);

		}
		#endregion

		private void frmReadyGoods_Load(object sender, System.EventArgs e)
		{
			tv_Tree.Width =140;
			spt_H.Visible =true;
			this.grd_Top.Height =100;
			spt_H.BringToFront() ;
			this.ShowResize();
			grd_Top.OnlyRead=true;
			grd_Bottom.OnlyRead=true;
			cbo_Operator.Text =GlobalData.Operator ;
			newR_Attrib.LoadData("销售单") ;
			 MasterSql=newR_Attrib.MasterViewFeildName;
			 DetailSql=newR_Attrib.DetailViewFeildName;
			this.InitTreeData("SELECT fcSellNo+':'+ fcOperator FROM R_Sell where isnull(fcReady,'')=''order by fcSellNo");
			ShowData(grd_Top,MasterSql);
			ShowData(grd_Bottom,DetailSql);
			grd_Bottom.SetCellWidth =newR_Attrib.GetDetailColWidth("备货单");

		}
		protected override void InitTreeData(string p_TreeDataSource)
		{
			if (p_TreeDataSource!=null && p_TreeDataSource!="")
			{
				InitData.InitTreeView (tv_Tree,p_TreeDataSource,"待备货销售单");
			}

		}
		private  void ShowData(ljs.MyFlexGrid p_FlexGrid ,string p_Filter)
		{
			//添加行号
            p_FlexGrid.Clear();
            InitData.ShowGridData(p_FlexGrid,p_Filter);
			grd_Bottom.ColCommanFormat=newR_Attrib.PageDetailFormat ;
		}
		protected override void tv_Tree_Click(object sender, EventArgs e)
		{


		}
		private void tv_Tree_DoubleClick(object sender, System.EventArgs e)
		{
		
			TreeNode tn = new TreeNode();
			tn = tv_Tree.SelectedNode;
			if (tn != null)
			{
				string[] arrTemp=tn.Text.Split(':')  ;
				
				sReceiptNO=arrTemp[0];
				CboReceiptNo.Text=sReceiptNO;
				//替换主从SQL语句中的单据编号变量
				string MasterSql1=MasterSql.ToLower().Replace("@receiptno",sReceiptNO);
				string DetailSql1=DetailSql.ToLower().Replace("@receiptno",sReceiptNO);
				ShowData(grd_Top,MasterSql1);
				grd_Bottom.Rows=2;
				grd_Bottom.Row=1;
				grd_Bottom.RowSel =1;
				grd_Bottom.Col=1;
				grd_Bottom.ColSel =grd_Bottom.Cols -1;
				grd_Bottom.SetAreaForeColor(Color.Navy); 
				ShowData(grd_Bottom,DetailSql1);

			}
		}
		private void m_RecordBatch_Click(object sender, System.EventArgs e)
		{
//		  grd_Bottom.SetAreaBackColor(Color.Blue );
			grd_Bottom.AreaCopy();
			grd_Bottom.RowInsert("",grd_Bottom.Row+1);
			grd_Bottom.Col=1;
			grd_Bottom.ColSel =grd_Bottom.Cols -1;
			grd_Bottom.AreaPaste();
			grd_Bottom.SetAreaForeColor(Color.Black); 
		}
		private void mnu_DetailColWidth_Click(object sender, System.EventArgs e)
		{
			frmColWidthSetup f=new frmColWidthSetup();
			f.GridSource=this.grd_Bottom  ;
			f.ReceiptName ="备货单" ; 
			f.Show();

		}

		private void grd_Bottom_Cell_Enter(object sender, System.EventArgs e)
		{
			if (grd_Bottom.OnlyRead==true) return;
			if (grd_Bottom.Col==1 || grd_Bottom.Col==3 || grd_Bottom.Col==4 )
			{
				grd_Bottom.ColLocked=true;
			}
			else
			{
				grd_Bottom.ColLocked=false;
				TextBox control = (TextBox) sender ;
				TxtTemp =control;
				TxtTemp.Tag =grd_Bottom.GetCurColCommand(grd_Bottom.Col);//'   grd_Detail.GetCellText(0,grd_Detail.Col);
				newCellAttrib.FormatString =TxtTemp.Tag.ToString();   //解析列控制字符
				CellMouseDown(control);

			}


			//			if (newCellAttrib.ReadOnly ==true)   //是否保存
			//			{
			//				grd_Bottom.GetEditCell.ReadOnly=true;
			//			}
			//			else
			//			{
			//				grd_Bottom.GetEditCell.ReadOnly=false;
			//
			//			}
			m_MouseEnterPlace="Detail";

		}

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

		private void cmd_Start_Click(object sender, System.EventArgs e)
		{
			this.cmd_Start.Enabled =false;
			this.tv_Tree.Enabled =false;
			grd_Bottom.OnlyRead=false;
		}

		private void cmd_Save_Click(object sender, System.EventArgs e)
		{
			this.cmd_Start.Enabled =true;
			this.tv_Tree.Enabled =true;
			grd_Bottom.OnlyRead=true;
			ReadySave() ;

		}

		private void cmd_CancelReady_Click(object sender, System.EventArgs e)
		{
			this.cmd_Start.Enabled =true;
			this.tv_Tree.Enabled =true;
			grd_Bottom.OnlyRead=true;
		}
//		/// <summary>
//		/// 备货数据保存
//		/// </summary>
//		public void ReadySave() 
//		{
//			string [,] TempArrCell=null;
//			string sReceiptNo;
//			int n=0;			//数组计数器
//			string sCurColCommand;//当前列控制字符
//			string[] tempArr=null;//临时树组
//			string sSQL="";
//			int cs=grd_Bottom.Cols;
//			int rs=grd_Bottom.Rows;
//
//			newADO.BeginTrans(); 
//			sReceiptNo=CboReceiptNo.Text;
//			newADO.ExeSql("Delete From "+newR_Attrib.DetailTableName+" Where "+newR_Attrib.KeyFieldName+"='"+CboReceiptNo.Text +"'"); 
//			
//
//			//明细表数据保存
//			tempArr=newR_Attrib.DetailFeildName.Split(',');
//			TempArrCell=new string[tempArr.Length+1,2];
//
//			for (int r=1;r<rs;r++)
//			{
//				if (grd_Bottom.GetCellText(r,1)!="")
//				{
//					n=1;
//					TempArrCell[0,0]=sReceiptNo;
//					TempArrCell[0,1] ="";
//					for (int c=0;c<cs;c++)
//					{
//						sCurColCommand=grd_Bottom.GetCurColCommand(c);//列控制字符命令
//						newCellAttrib.FormatString =sCurColCommand;   //解析列控制字符
//						if (newCellAttrib.NotSave==false)   //是否保存
//						{
//							TempArrCell[n,0]=grd_Bottom.GetCellText(r,c);
//							TempArrCell[n,1] =sCurColCommand;
//							n++;
//						}
//					}
//					sSQL=newR_Method.GetInsertSQL(newR_Attrib.DetailTableName,newR_Attrib.KeyFieldName+","+newR_Attrib.DetailFeildName,TempArrCell);
//					if (newADO.ExeSql(sSQL)<0)
//					{
//						newADO.Rollback() ;
//						return ;
//					}
//				}
//
//			}
//			newADO.Commit(); 
//			TempArrCell=null;
//
//		}

		/// <summary>
		/// 备货数据保存
		/// </summary>
		public void ReadySave() 
		{
			string [,] TempArrCell=null;
			string[] tempArr=null;//临时树组
			string sCurColCommand;//当前列控制字符

			string sReceiptNo;
			int n=0;			//数组计数器
			string sSQL="";
			int cs=grd_Bottom.Cols;
			int rs=grd_Bottom.Rows;

			try
			{
				newADO.BeginTrans(); //事务开始
					 newADO.ExeSql("Update "+newR_Attrib.MasterTableName+" Set fcReady='"+cbo_Operator.Text+"' Where "+newR_Attrib.KeyFieldName+"='"+CboReceiptNo.Text +"'"); 
					if (newR_Attrib.DetailTableName!="") newADO.ExeSql("Delete From "+newR_Attrib.DetailTableName+" Where "+newR_Attrib.KeyFieldName+"='"+CboReceiptNo.Text +"'"); 
				sReceiptNo=CboReceiptNo.Text;

				//明细表数据保存
					tempArr=newR_Attrib.DetailFeildName.Split(',');
					TempArrCell=new string[tempArr.Length+1,2];

					for (int r=1;r<rs;r++)
					{
						if (grd_Bottom.GetCellText(r,1)!="")
						{
							n=1;
							TempArrCell[0,0]=sReceiptNo;
							TempArrCell[0,1] ="";
			
							for (int c=0;c<cs;c++)
							{
								sCurColCommand=grd_Bottom.GetCurColCommand(c);//列控制字符命令
								newCellAttrib.FormatString =sCurColCommand;   //解析列控制字符
								if (newCellAttrib.NotSave==false)			  //是否保存
								{
									TempArrCell[n,0]=grd_Bottom.GetCellText(r,c);
									TempArrCell[n,1] =sCurColCommand;
									n++;
								}
							}
							sSQL=newR_Method.GetInsertSQL(newR_Attrib.DetailTableName,newR_Attrib.KeyFieldName+","+newR_Attrib.DetailFeildName,TempArrCell);
							if (newADO.ExeSql(sSQL)<0)
							{
								newADO.Rollback() ;  //事务回滚
								return ;
							}
						}

					}
				newADO.Commit();					  //事务提交
				TempArrCell=null;
				System.Windows.Forms.MessageBox.Show("保存成功.","保存提示",System.Windows.Forms.MessageBoxButtons.OK,System.Windows.Forms.MessageBoxIcon.Information );

			}
			catch(System.Exception ex)
			{
				System.Windows.Forms.MessageBox.Show(ex.Message,"保存提示",System.Windows.Forms.MessageBoxButtons.OK,System.Windows.Forms.MessageBoxIcon.Warning);
				newADO.Rollback() ;        //事务回滚
				return ;
			}
		}

		/// <summary>
		/// 设置参照按钮
		/// </summary>
		private void CellMouseDown(TextBox sender)
		{
			try
			{
				m_ColExpress=null;
				newCellAttrib.FormatString =sender.Tag.ToString();
				m_ColExpress=newCellAttrib.ColExpress ;
				m_ShowFormat=newCellAttrib.ShowFormat ;
				if (newCellAttrib.RefertoType=="" || newCellAttrib.RefertoType==null)
				{
					btnDown.Visible =false;
				}
				else
				{
					btnDown.Top  =sender.Top+sender.Parent.Top+1 ;
					btnDown.Left  =sender.Left+sender.Parent.Left +sender.Width -btnDown.Width  ;
					btnDown.Height   =sender.Height-1 ;
					btnDown.Visible =true;
					btnDown.BringToFront() ;
				}
			}
			catch
			{
				return;
			}
		}
		/// <summary>
		/// 显示参照
		/// </summary>
		protected virtual void ShowReferto(int p_RefertoType)
		{  
			IReferto f=null; 
			f= new frmReferto();
			f.DataSource =newCellAttrib.RefertoDataSource ;
			f.OtherFilter=m_OtherFilter;//参照其他过滤条件

			f.Location = new Point(this.btnDown.Left + this.Left-TxtTemp.Width ,this.btnDown.Height*2+this.tbr_Toolbar.Height*2 +this.btnDown.Top + this.Top);
			f.DefaultValue=TxtTemp.Text ;
			f.RefertoType =p_RefertoType ;
			m_RefertoReturnCols=newCellAttrib.RefertoReturnCols   ;		       //参照返回列值
			m_RefertoInputCols=newCellAttrib.RefertoInputCols   ;			       //目标列对应列

			f.ShowDialog();
			System.Collections.Hashtable ReturnValues= f.GetReturnHashtable();
			if (ReturnValues==null  || ReturnValues.Count==0) return;
			TxtTemp.Text =ReturnValues[0].ToString().Trim() ;

			if (ReturnValues!=null && m_RefertoReturnCols!="")
			{
				string[] ArrTemp=null;
				string[] ArrTemp1=null;
				ArrTemp=m_RefertoReturnCols.Split(':');
				ArrTemp1=m_RefertoInputCols.Split(':');
				int a=ArrTemp.Length ;
				int b=ArrTemp1.Length ;
				if (a==b && a!=0)
				{
					for (int r=0;r<a;r++)
					{
						if (m_MouseEnterPlace=="Master")
						{
//							ArrCell[int.Parse(ArrTemp1[r])].Text=ReturnValues[int.Parse(ArrTemp[r])].ToString ();
						}
						if (m_MouseEnterPlace=="Detail")
						{
							grd_Bottom.SetCellText(this.grd_Bottom.Row,int.Parse(ArrTemp1[r]),ReturnValues[int.Parse(ArrTemp[r])].ToString ());
						}
					}
				}
			}
			this.TxtTemp.Focus();
			f=null;
		}
		
		private void LoadReferto()
		{
			try
			{
				int T=0;
				newCellAttrib.FormatString =TxtTemp.Tag.ToString();
				T=int.Parse(newCellAttrib.RefertoType);
				if (T>10)
				{
//					ShowOtherReferto();

				}
				else
				{
					ShowReferto(T)	;
				}
			}
			catch(System.Exception ex)
			{
				System.Windows.Forms.MessageBox.Show(ex.Message,"提示",System.Windows.Forms.MessageBoxButtons.OK,System.Windows.Forms.MessageBoxIcon.Warning);
				return;
			}
		}
		protected virtual void btnDown_Click(object sender, System.EventArgs e)
		{
			LoadReferto();
		}

		
		private void grd_Bottom_Scroll(object sender, System.EventArgs e)
		{
			btnDown.Visible =false;
		}

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

		private void tv_Tree_AfterExpand(object sender, System.Windows.Forms.TreeViewEventArgs e)
		{
//			System.Windows.Forms.MessageBox.Show("tv_Tree_AfterExpand"+e.Node.Text,"提示");
			tv_Tree.SelectedNode=null;
	
		}

		private void tv_Tree_AfterSelect(object sender, System.Windows.Forms.TreeViewEventArgs e)
		{
//			System.Windows.Forms.MessageBox.Show("tv_Tree_AfterSelect"+e.Node.Text,"提示");

		}

		private void tv_Tree_BeforeExpand(object sender, System.Windows.Forms.TreeViewCancelEventArgs e)
		{
//			System.Windows.Forms.MessageBox.Show("tv_Tree_BeforeExpand"+e.Node.Text,"提示");
		}

		private void tv_Tree_BeforeSelect(object sender, System.Windows.Forms.TreeViewCancelEventArgs e)
		{
//			System.Windows.Forms.MessageBox.Show("tv_Tree_BeforeSelect"+e.Node.Text,"提示");
		}

		

//		private  void ShowData(string p_Filter)
//		{
//			int rs;
////			if (p_Filter=="<全部>") { p_Filter="";} 
////			else { p_Filter=cbo_FliterValue.Text;}
//			dst= newADO.GetDataSet(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()+"行" ;
//
//		}


















	}
}

