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 frmInfList : 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;
		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;

		public struct Cell
		{
			public string Tag;
			public string Text;
		}
		Cell ActiveCell=new Cell();

		public frmInfList()
		{
			// 该调用是 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.m_RecordBatch = new System.Windows.Forms.MenuItem();
			this.mnu_DetailColWidth = new System.Windows.Forms.MenuItem();
			this.btnDown = new System.Windows.Forms.Button();
			this.CboReceiptNo = 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, 232);
			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);
			// 
			// 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.Name = "cmd_Cancel";
			// 
			// cmd_ExeQuery
			// 
			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);
			// 
			// t_new
			// 
			this.t_new.Visible = true;
			// 
			// 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, 232);
			this.grd_Top.Row_Click += new ljs.FlexGridRow_Click(this.grd_Top_Row_Click);
			// 
			// grd_Bottom
			// 
			this.grd_Bottom.Location = new System.Drawing.Point(3, 235);
			this.grd_Bottom.Name = "grd_Bottom";
			this.grd_Bottom.Size = new System.Drawing.Size(709, 211);
			// 
			// ctm_Menu
			// 
			this.ctm_Menu.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
																					 this.mnu_DetailColWidth,
																					 this.m_RecordBatch});
			// 
			// img_ImageList
			// 
			this.img_ImageList.ImageStream = null;
			// 
			// m_RecordBatch
			// 
			this.m_RecordBatch.Index = 1;
			this.m_RecordBatch.Text = "产品分批";
			// 
			// mnu_DetailColWidth
			// 
			this.mnu_DetailColWidth.Index = 0;
			this.mnu_DetailColWidth.Text = "明细列宽设置";
			// 
			// btnDown
			// 
			this.btnDown.BackColor = System.Drawing.Color.Transparent;
			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;
			// 
			// CboReceiptNo
			// 
			this.CboReceiptNo.Location = new System.Drawing.Point(316, 4);
			this.CboReceiptNo.Name = "CboReceiptNo";
			this.CboReceiptNo.Size = new System.Drawing.Size(150, 20);
			this.CboReceiptNo.TabIndex = 61;
			// 
			// frmInfList
			// 
			this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
			this.ClientSize = new System.Drawing.Size(714, 411);
			this.Controls.Add(this.CboReceiptNo);
			this.Name = "frmInfList";
			this.Text = "信息设置";
			this.Load += new System.EventHandler(this.frmInfSetup_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.CboReceiptNo, 0);
			this.panel1.ResumeLayout(false);
			this.ResumeLayout(false);

		}
		#endregion

		private void frmInfSetup_Load(object sender, System.EventArgs e)
		{
			tv_Tree.Width =140;
			spt_H.Visible =true;
			this.grd_Top.Height =230;
			spt_H.BringToFront() ;
			this.ShowResize();
			grd_Top.OnlyRead=true;
			grd_Bottom.OnlyRead=true;
			this.InitTreeData("Select fcReceiptName From S_receiptSetup where left(fcReceiptNo,3)='N02' and fcClass='1'");
			this.ToolBarType(false);

		}
		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(':')  ;
							newR_Attrib.LoadData(tn.Text) ;
							MasterSql=newR_Attrib.MasterViewFeildName;
							DetailSql=newR_Attrib.DetailViewFeildName;
//
//				sReceiptNO=arrTemp[0];
				CboReceiptNo.Text=tn.Text;
				//替换主从SQL语句中的单据编号变量
				string MasterSql1=MasterSql.ToLower().Replace("='@receiptno'"," is not null");
//				 MasterSql1=MasterSql1.ToLower().Replace("from",","+newR_Attrib.KeyFieldName+ " As 唯一ID From ");
				string DetailSql1=DetailSql.ToLower().Replace("='@receiptno'"," is null");
				ShowData(grd_Top,MasterSql1);
				ShowData(grd_Bottom,DetailSql1);
				grd_Bottom.SetCellWidth =newR_Attrib.GetDetailColWidth(tn.Text);
			}

		}

		private void grd_Top_Row_Click(object sender, System.EventArgs e)
		{
			string sValue=grd_Top.GetCellText(grd_Top.Row ,grd_Top.Cols-2) ;
			 if (sValue=="") return;
			string DetailSql1=DetailSql.ToLower().Replace("@receiptno",sValue);
			ShowData(grd_Bottom,DetailSql1);

		}
              
		protected override void  tbr_Toolbar_ButtonClick(object sender, System.Windows.Forms.ToolBarButtonClickEventArgs e)
		{

			//			frmInput f=new frmInput();
			switch (e.Button.Tag.ToString() )
			{
				case "新增":
					//					f.MdiParent = this;
					JXC_MIS.UserTier.BaseForm.frmReceiptBase ff=new JXC_MIS.UserTier.BaseForm.frmReceiptBase ();
					ff.ToolBarType(false);
					ff.Show() ;
					ff.ReceiptName=CboReceiptNo.Text;
					ff.InitInterface();
					break;
					//				case "修改":
					//					//					if (grd_Edit[grd_Edit.CurrentCell.RowNumber ,0]==null){return;}
					//					try
					//					{
					//						f.RecordName=this.cbo_SetupName.Text ;
					//						f.EditFlag =true;
					//						f.IDValue =this.grd_Bottom[grd_Bottom.CurrentCell.RowNumber ,0].ToString();
					//						f.Show();
					//					}
					//					catch
					//					{}
					//
					//					//					RecordModify();
					//					break;
					//				case "放弃":
					//					////					RecordCancel();
					//					break;

				default:
 
					break;
			}
			base.tbr_Toolbar_ButtonClick(sender,e); 


		}

	















	}
}

