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

namespace JXC_MIS.UserTier.NewForm
{
	public class frmSellQuery : JXC_MIS.UserTier.BaseForm.frmTreeFlexGrid
	{
		private System.ComponentModel.IContainer components = null;
		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="";

		public frmSellQuery()
		{
			// 该调用是 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(frmSellQuery));
			// 
			// panel1
			// 
			this.panel1.Name = "panel1";
			// 
			// spt_H
			// 
			this.spt_H.Location = new System.Drawing.Point(144, 198);
			this.spt_H.Name = "spt_H";
			this.spt_H.Size = new System.Drawing.Size(528, 4);
			// 
			// spt_V
			// 
			this.spt_V.Location = new System.Drawing.Point(140, 0);
			this.spt_V.Name = "spt_V";
			this.spt_V.Size = new System.Drawing.Size(4, 444);
			// 
			// tv_Tree
			// 
			this.tv_Tree.Name = "tv_Tree";
			this.tv_Tree.Size = new System.Drawing.Size(140, 444);
			// 
			// cbo_SetupName
			// 
			this.cbo_SetupName.Name = "cbo_SetupName";
			this.cbo_SetupName.Size = new System.Drawing.Size(124, 20);
			// 
			// 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";
			// 
			// sbr_StatusBar
			// 
			this.sbr_StatusBar.Name = "sbr_StatusBar";
			// 
			// tbr_Toolbar
			// 
			this.tbr_Toolbar.Name = "tbr_Toolbar";
			// 
			// grd_Top
			// 
			this.grd_Top.Location = new System.Drawing.Point(144, 0);
			this.grd_Top.Name = "grd_Top";
			this.grd_Top.Size = new System.Drawing.Size(528, 198);
			// 
			// grd_Bottom
			// 
			this.grd_Bottom.Location = new System.Drawing.Point(144, 202);
			this.grd_Bottom.Name = "grd_Bottom";
			this.grd_Bottom.Size = new System.Drawing.Size(528, 242);
			this.grd_Bottom.BackColorChanged += new System.EventHandler(this.frmSellQuery_Load);
			// 
			// img_ImageList
			// 
			this.img_ImageList.ImageStream = ((System.Windows.Forms.ImageListStreamer)(resources.GetObject("img_ImageList.ImageStream")));
			// 
			// frmSellQuery
			// 
			this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
			this.ClientSize = new System.Drawing.Size(674, 499);
			this.Name = "frmSellQuery";
			this.Load += new System.EventHandler(this.frmSellQuery_Load);

		}
		#endregion
		private void frmSellQuery_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;

			newR_Attrib.LoadData("销售单") ;
			MasterSql=newR_Attrib.MasterViewFeildName;
			DetailSql=newR_Attrib.DetailViewFeildName;
			this.InitTreeData("SELECT fcSellNo+':'+ fcOperator FROM R_Sell 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);

		}
		protected override void tv_Tree_Click(object sender, 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);

			}

		}



	}
}

