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

namespace JXC_MIS.UserTier.BaseForm
{
	/// <summary>
	/// frmTreeFormBase 的摘要说明。
	/// </summary>
	public class frmTreeFormBase : System.Windows.Forms.Form
	{
		protected System.Windows.Forms.ToolBarButton t_new;
		protected System.Windows.Forms.StatusBar sbr_StatusBar;
		protected System.Windows.Forms.ToolBarButton t_Modify;
		private System.Windows.Forms.ToolBarButton t_S3;
		protected System.Windows.Forms.ToolBarButton t_Save;
		protected System.Windows.Forms.ComboBox cbo_SetupName;
		protected System.Windows.Forms.Panel panel1;
		protected System.Windows.Forms.TreeView tv_Tree;
		protected System.Windows.Forms.ToolBarButton t_Cancel;
		protected System.Windows.Forms.ToolBarButton t_Exit;
		private System.Windows.Forms.ToolBarButton t_S2;
		protected System.Windows.Forms.ToolBar tbr_Toolbar;
		protected System.Windows.Forms.ToolBarButton t_Preview;
		private System.Windows.Forms.ToolBarButton t_Print;
		private System.Windows.Forms.ToolBarButton T_S1;
		protected System.Windows.Forms.ToolBarButton t_Refresh;
		protected System.Windows.Forms.ToolBarButton t_Find;
		private System.Windows.Forms.ImageList img_ImageList;
		private System.ComponentModel.IContainer components;
		protected System.Windows.Forms.ToolBarButton t_Output;
		private System.Windows.Forms.ToolBarButton t_s4;
		protected System.Windows.Forms.Splitter spt_V;
		protected System.Windows.Forms.Splitter spt_H;
		protected System.Windows.Forms.DataGrid grd_Top;
		protected System.Windows.Forms.DataGrid grd_Bottom;
		private System.Windows.Forms.Panel panel2;
		private System.Windows.Forms.Button button1;
		private bool m_TreeVisible=true;
		private string m_TreeDataSource;
		private string m_GridTopDataSource;
		private string m_GridBottomDataSource;
		private string m_GridTopFilter;
		private string m_GridBottomFilter;
			protected ClsDataBaseAccess newADO=new ClsDataBaseAccess();
			protected ClsInitData InitData=new ClsInitData();
		protected ClsDataBase newDb=new ClsDataBase();
/// <summary>
		/// 设置树形控件数据源
		/// </summary>
		public string TreeDataSource
		{ 
			get {return m_TreeDataSource;} 
			set 
			{ 
				m_TreeDataSource=value;
//				InitTreeData();

			} 
		} 
		/// <summary>
		/// 设置Gid_Top控件数据源
		/// </summary>
		public string GridTopDataSource
		{
			get {return m_GridTopDataSource;} 
			set 
			{ 
				m_GridTopDataSource=value;
			} 
		} 
		/// <summary>
		/// 设置Gid_Bottom控件数据源
		/// </summary>
		public string GridBottomDataSource
		{ 
			get {return m_GridBottomDataSource;} 
			set 
			{ 
				m_GridBottomDataSource=value;
			} 
		} 
		/// <summary>
		/// 设置Gid_Top控件数据源过滤条件
		/// </summary>
		public string GridTopFilter
		{ 
			get {return m_GridTopFilter;} 

			set 
			{ 
				m_GridTopFilter=value;
			} 
		} 
		/// <summary>
		/// 设置Gid_Bottom控件数据源过滤条件
		/// </summary>
		public string GridBottomFilter
		{ 
			get {return m_GridBottomFilter;} 
			set 
			{ 
				m_GridBottomFilter=value;
			} 
		} 
		/// <summary>
		/// 设置是否可见数形控件
		/// </summary>
		public bool TreeVisible
		{ 
			get {return m_TreeVisible;} 
			set 
			{ 
				m_TreeVisible=value;
			} 
		} 
		public frmTreeFormBase()
		{
			//
			// Windows 窗体设计器支持所必需的
			//
			InitializeComponent();

			//
			// TODO: 在 InitializeComponent 调用后添加任何构造函数代码
			//
		}

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

		#region Windows 窗体设计器生成的代码
		/// <summary>
		/// 设计器支持所需的方法 - 不要使用代码编辑器修改
		/// 此方法的内容。
		/// </summary>
		private void InitializeComponent()
		{
			this.components = new System.ComponentModel.Container();
			System.Resources.ResourceManager resources = new System.Resources.ResourceManager(typeof(frmTreeFormBase));
			this.t_new = new System.Windows.Forms.ToolBarButton();
			this.sbr_StatusBar = new System.Windows.Forms.StatusBar();
			this.t_Modify = new System.Windows.Forms.ToolBarButton();
			this.t_S3 = new System.Windows.Forms.ToolBarButton();
			this.t_Save = new System.Windows.Forms.ToolBarButton();
			this.cbo_SetupName = new System.Windows.Forms.ComboBox();
			this.panel1 = new System.Windows.Forms.Panel();
			this.spt_H = new System.Windows.Forms.Splitter();
			this.grd_Bottom = new System.Windows.Forms.DataGrid();
			this.grd_Top = new System.Windows.Forms.DataGrid();
			this.spt_V = new System.Windows.Forms.Splitter();
			this.tv_Tree = new System.Windows.Forms.TreeView();
			this.t_Cancel = new System.Windows.Forms.ToolBarButton();
			this.t_Exit = new System.Windows.Forms.ToolBarButton();
			this.t_S2 = new System.Windows.Forms.ToolBarButton();
			this.tbr_Toolbar = new System.Windows.Forms.ToolBar();
			this.t_s4 = new System.Windows.Forms.ToolBarButton();
			this.t_Output = new System.Windows.Forms.ToolBarButton();
			this.t_Preview = new System.Windows.Forms.ToolBarButton();
			this.t_Print = new System.Windows.Forms.ToolBarButton();
			this.T_S1 = new System.Windows.Forms.ToolBarButton();
			this.t_Refresh = new System.Windows.Forms.ToolBarButton();
			this.t_Find = new System.Windows.Forms.ToolBarButton();
			this.img_ImageList = new System.Windows.Forms.ImageList(this.components);
			this.panel2 = new System.Windows.Forms.Panel();
			this.button1 = new System.Windows.Forms.Button();
			this.panel1.SuspendLayout();
			((System.ComponentModel.ISupportInitialize)(this.grd_Bottom)).BeginInit();
			((System.ComponentModel.ISupportInitialize)(this.grd_Top)).BeginInit();
			this.panel2.SuspendLayout();
			this.SuspendLayout();
			// 
			// t_new
			// 
			this.t_new.ImageIndex = 19;
			this.t_new.Tag = "新增";
			// 
			// sbr_StatusBar
			// 
			this.sbr_StatusBar.Location = new System.Drawing.Point(0, 386);
			this.sbr_StatusBar.Name = "sbr_StatusBar";
			this.sbr_StatusBar.ShowPanels = true;
			this.sbr_StatusBar.Size = new System.Drawing.Size(714, 25);
			this.sbr_StatusBar.TabIndex = 11;
			this.sbr_StatusBar.Text = "statusBar1";
			// 
			// t_Modify
			// 
			this.t_Modify.ImageIndex = 7;
			this.t_Modify.Tag = "修改";
			// 
			// t_S3
			// 
			this.t_S3.Style = System.Windows.Forms.ToolBarButtonStyle.Separator;
			// 
			// t_Save
			// 
			this.t_Save.ImageIndex = 9;
			this.t_Save.Tag = "保存";
			// 
			// cbo_SetupName
			// 
			this.cbo_SetupName.AccessibleDescription = "垂直";
			this.cbo_SetupName.Location = new System.Drawing.Point(0, 0);
			this.cbo_SetupName.Name = "cbo_SetupName";
			this.cbo_SetupName.Size = new System.Drawing.Size(146, 20);
			this.cbo_SetupName.TabIndex = 13;
			this.cbo_SetupName.Visible = false;
			// 
			// panel1
			// 
			this.panel1.Controls.Add(this.spt_H);
			this.panel1.Controls.Add(this.grd_Bottom);
			this.panel1.Controls.Add(this.grd_Top);
			this.panel1.Controls.Add(this.spt_V);
			this.panel1.Controls.Add(this.panel2);
			this.panel1.Dock = System.Windows.Forms.DockStyle.Fill;
			this.panel1.Location = new System.Drawing.Point(0, 28);
			this.panel1.Name = "panel1";
			this.panel1.Size = new System.Drawing.Size(714, 358);
			this.panel1.TabIndex = 12;
			// 
			// spt_H
			// 
			this.spt_H.Dock = System.Windows.Forms.DockStyle.Top;
			this.spt_H.Location = new System.Drawing.Point(176, 178);
			this.spt_H.Name = "spt_H";
			this.spt_H.Size = new System.Drawing.Size(538, 8);
			this.spt_H.TabIndex = 4;
			this.spt_H.TabStop = false;
			this.spt_H.SplitterMoved += new System.Windows.Forms.SplitterEventHandler(this.spt_H_SplitterMoved);
			// 
			// grd_Bottom
			// 
			this.grd_Bottom.AlternatingBackColor = System.Drawing.Color.Silver;
			this.grd_Bottom.BackColor = System.Drawing.Color.White;
			this.grd_Bottom.CaptionBackColor = System.Drawing.Color.Silver;
			this.grd_Bottom.CaptionFont = new System.Drawing.Font("Tahoma", 9F);
			this.grd_Bottom.CaptionForeColor = System.Drawing.Color.FromArgb(((System.Byte)(0)), ((System.Byte)(0)), ((System.Byte)(192)));
			this.grd_Bottom.CaptionText = "标题";
			this.grd_Bottom.DataMember = "";
			this.grd_Bottom.Font = new System.Drawing.Font("Tahoma", 8F);
			this.grd_Bottom.ForeColor = System.Drawing.Color.Black;
			this.grd_Bottom.GridLineColor = System.Drawing.Color.Silver;
			this.grd_Bottom.HeaderBackColor = System.Drawing.Color.Silver;
			this.grd_Bottom.HeaderFont = new System.Drawing.Font("Tahoma", 8F);
			this.grd_Bottom.HeaderForeColor = System.Drawing.Color.Black;
			this.grd_Bottom.LinkColor = System.Drawing.Color.Maroon;
			this.grd_Bottom.Location = new System.Drawing.Point(346, 187);
			this.grd_Bottom.Name = "grd_Bottom";
			this.grd_Bottom.ParentRowsBackColor = System.Drawing.Color.Silver;
			this.grd_Bottom.ParentRowsForeColor = System.Drawing.Color.Black;
			this.grd_Bottom.SelectionBackColor = System.Drawing.Color.Maroon;
			this.grd_Bottom.SelectionForeColor = System.Drawing.Color.White;
			this.grd_Bottom.Size = new System.Drawing.Size(368, 157);
			this.grd_Bottom.TabIndex = 2;
			// 
			// grd_Top
			// 
			this.grd_Top.CaptionBackColor = System.Drawing.Color.Silver;
			this.grd_Top.CaptionForeColor = System.Drawing.Color.Red;
			this.grd_Top.CaptionText = "主表";
			this.grd_Top.DataMember = "";
			this.grd_Top.Dock = System.Windows.Forms.DockStyle.Top;
			this.grd_Top.HeaderForeColor = System.Drawing.SystemColors.ControlText;
			this.grd_Top.Location = new System.Drawing.Point(176, 0);
			this.grd_Top.Name = "grd_Top";
			this.grd_Top.Size = new System.Drawing.Size(538, 178);
			this.grd_Top.TabIndex = 3;
			this.grd_Top.Click += new System.EventHandler(this.grd_Top_Click);
			// 
			// spt_V
			// 
			this.spt_V.Location = new System.Drawing.Point(170, 0);
			this.spt_V.Name = "spt_V";
			this.spt_V.Size = new System.Drawing.Size(6, 358);
			this.spt_V.TabIndex = 1;
			this.spt_V.TabStop = false;
			this.spt_V.SplitterMoved += new System.Windows.Forms.SplitterEventHandler(this.spt_V_SplitterMoved);
			// 
			// tv_Tree
			// 
			this.tv_Tree.ForeColor = System.Drawing.Color.Black;
			this.tv_Tree.ImageIndex = -1;
			this.tv_Tree.Location = new System.Drawing.Point(-18, 20);
			this.tv_Tree.Name = "tv_Tree";
			this.tv_Tree.Nodes.AddRange(new System.Windows.Forms.TreeNode[] {
																				new System.Windows.Forms.TreeNode("基础信息设置", new System.Windows.Forms.TreeNode[] {
																																									new System.Windows.Forms.TreeNode("使用单位设置"),
																																									new System.Windows.Forms.TreeNode("客户信息设置"),
																																									new System.Windows.Forms.TreeNode("单位人员信息设置"),
																																									new System.Windows.Forms.TreeNode("部门设置"),
																																									new System.Windows.Forms.TreeNode("业务员设置"),
																																									new System.Windows.Forms.TreeNode("操作员设置"),
																																									new System.Windows.Forms.TreeNode("发票类型设置"),
																																									new System.Windows.Forms.TreeNode("税率设置"),
																																									new System.Windows.Forms.TreeNode("出入库类型设置"),
																																									new System.Windows.Forms.TreeNode("密码设置")})});
			this.tv_Tree.SelectedImageIndex = -1;
			this.tv_Tree.Size = new System.Drawing.Size(184, 366);
			this.tv_Tree.TabIndex = 0;
			this.tv_Tree.MouseDown += new System.Windows.Forms.MouseEventHandler(this.tv_Tree_MouseDown);
			this.tv_Tree.Click += new System.EventHandler(this.tv_Tree_Click);
			// 
			// t_Cancel
			// 
			this.t_Cancel.ImageIndex = 3;
			this.t_Cancel.Tag = "放弃";
			// 
			// t_Exit
			// 
			this.t_Exit.ImageIndex = 16;
			this.t_Exit.Tag = "退出";
			this.t_Exit.ToolTipText = "退出";
			// 
			// t_S2
			// 
			this.t_S2.Style = System.Windows.Forms.ToolBarButtonStyle.Separator;
			// 
			// tbr_Toolbar
			// 
			this.tbr_Toolbar.Appearance = System.Windows.Forms.ToolBarAppearance.Flat;
			this.tbr_Toolbar.Buttons.AddRange(new System.Windows.Forms.ToolBarButton[] {
																						   this.t_s4,
																						   this.t_Output,
																						   this.t_new,
																						   this.t_Modify,
																						   this.t_Save,
																						   this.t_Cancel,
																						   this.t_S3,
																						   this.t_Preview,
																						   this.t_Print,
																						   this.T_S1,
																						   this.t_Refresh,
																						   this.t_Find,
																						   this.t_S2,
																						   this.t_Exit});
			this.tbr_Toolbar.DropDownArrows = true;
			this.tbr_Toolbar.ImageList = this.img_ImageList;
			this.tbr_Toolbar.Location = new System.Drawing.Point(0, 0);
			this.tbr_Toolbar.Name = "tbr_Toolbar";
			this.tbr_Toolbar.ShowToolTips = true;
			this.tbr_Toolbar.Size = new System.Drawing.Size(714, 28);
			this.tbr_Toolbar.TabIndex = 10;
			this.tbr_Toolbar.Wrappable = false;
			this.tbr_Toolbar.ButtonClick += new System.Windows.Forms.ToolBarButtonClickEventHandler(this.tbr_Toolbar_ButtonClick);
			// 
			// t_s4
			// 
			this.t_s4.Style = System.Windows.Forms.ToolBarButtonStyle.Separator;
			// 
			// t_Output
			// 
			this.t_Output.ImageIndex = 22;
			this.t_Output.Tag = "导出";
			// 
			// t_Preview
			// 
			this.t_Preview.ImageIndex = 15;
			this.t_Preview.Tag = "预览";
			// 
			// t_Print
			// 
			this.t_Print.ImageIndex = 10;
			this.t_Print.Tag = "打印";
			// 
			// T_S1
			// 
			this.T_S1.Style = System.Windows.Forms.ToolBarButtonStyle.Separator;
			// 
			// t_Refresh
			// 
			this.t_Refresh.ImageIndex = 9;
			this.t_Refresh.Tag = "刷新";
			this.t_Refresh.ToolTipText = "刷新";
			// 
			// t_Find
			// 
			this.t_Find.ImageIndex = 2;
			this.t_Find.Tag = "查询";
			this.t_Find.ToolTipText = "查询";
			// 
			// img_ImageList
			// 
			this.img_ImageList.ImageSize = new System.Drawing.Size(16, 16);
			this.img_ImageList.ImageStream = ((System.Windows.Forms.ImageListStreamer)(resources.GetObject("img_ImageList.ImageStream")));
			this.img_ImageList.TransparentColor = System.Drawing.Color.Transparent;
			// 
			// panel2
			// 
			this.panel2.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D;
			this.panel2.Controls.Add(this.button1);
			this.panel2.Controls.Add(this.tv_Tree);
			this.panel2.Controls.Add(this.cbo_SetupName);
			this.panel2.Dock = System.Windows.Forms.DockStyle.Left;
			this.panel2.Location = new System.Drawing.Point(0, 0);
			this.panel2.Name = "panel2";
			this.panel2.Size = new System.Drawing.Size(170, 358);
			this.panel2.TabIndex = 5;
			// 
			// button1
			// 
			this.button1.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
			this.button1.Font = new System.Drawing.Font("宋体", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(134)));
			this.button1.Location = new System.Drawing.Point(146, 2);
			this.button1.Name = "button1";
			this.button1.Size = new System.Drawing.Size(24, 18);
			this.button1.TabIndex = 14;
			this.button1.Text = "X";
			// 
			// frmTreeFormBase
			// 
			this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
			this.ClientSize = new System.Drawing.Size(714, 411);
			this.Controls.Add(this.panel1);
			this.Controls.Add(this.sbr_StatusBar);
			this.Controls.Add(this.tbr_Toolbar);
			this.Name = "frmTreeFormBase";
			this.Text = "frmTreeFormBase";
			this.Resize += new System.EventHandler(this.frmInfSetup_Resize);
			this.Load += new System.EventHandler(this.frmTreeFormBase_Load);
			this.panel1.ResumeLayout(false);
			((System.ComponentModel.ISupportInitialize)(this.grd_Bottom)).EndInit();
			((System.ComponentModel.ISupportInitialize)(this.grd_Top)).EndInit();
			this.panel2.ResumeLayout(false);
			this.ResumeLayout(false);

		}
		#endregion

		private void frmTreeFormBase_Load(object sender, System.EventArgs e)
		{
			tv_Tree.Width =140;
			InitTreeData();
			ShowResize();
			tbr_Toolbar.SendToBack(); 
			//tv_Tree.BringToFront();
		}
		/// <summary>
		/// 设置是否可见树tv_Tree控件
		/// </summary>
		public void SetTreeVisible(bool p_TreeVisible)
		{
			tv_Tree.Visible =p_TreeVisible;
			spt_V.Visible =p_TreeVisible;	
			ShowResize();
		}
		/// <summary>
		/// 设置是否可见grd_Top控件
		/// </summary>
		public void SetGridVisible(bool p_GridTopVisible)
		{
			grd_Top.Visible =p_GridTopVisible;
			spt_H.Visible =p_GridTopVisible;	
			ShowResizeH();
		}

		protected virtual void tv_Tree_Click(object sender, System.EventArgs e)
		{
			TreeNode tn = new TreeNode();
			tn = tv_Tree.SelectedNode;
			if (tn != null)
			{
				cbo_SetupName.Text =tn.Text ;
				InitGridTopData(m_GridTopDataSource);
			}
		}

		protected virtual void InitTreeData()
		{
			if (m_TreeDataSource!=null && m_TreeDataSource!="")
			{
				InitData.InitTreeView (tv_Tree,newDb.GetDataArray(newADO.GetDataSet(m_TreeDataSource)));
			}

		}

		protected virtual void InitGridBottomData(string p_Filter)
		{
			if (m_GridBottomDataSource!="" && m_GridBottomDataSource!=null)
			{
				System.Data.DataSet dst = new System.Data.DataSet();
				dst= newADO.GetDataSet(m_GridBottomDataSource);
				grd_Bottom.DataSource=dst.Tables[0] ;
			}
		}

		protected virtual void grd_Top_Click(object sender, System.EventArgs e)
		{
			InitGridBottomData(m_GridBottomDataSource);
		}

		protected virtual void InitGridTopData(string p_Filter)
		{
			if (m_GridTopDataSource!="" && m_GridTopDataSource!=null)
			{
				System.Data.DataSet dst = new System.Data.DataSet();
				dst= newADO.GetDataSet(m_GridTopDataSource+"  "+p_Filter);
				grd_Top.DataSource=dst.Tables[0] ;
			}

		}
		private void tv_Tree_MouseDown(object sender, System.Windows.Forms.MouseEventArgs e)
		{
			try
			{
				tv_Tree.SelectedNode = tv_Tree.GetNodeAt(e.X,e.Y);	
			}
			catch
			{
				return;
			}
		}
		protected void  ShowResize()
		{
			if (grd_Top.Visible ==false){grd_Top.Width =0;spt_H.Visible =false;}
			if (spt_H.Visible ==false){spt_H.Height=0 ;spt_H.Top=0;}
			if (tv_Tree.Visible ==false){tv_Tree.Width =0;}
			if (spt_V.Visible ==false){spt_V.Width=0 ;spt_V.Left=0;}
			if (tv_Tree.Visible ==false)
			{
				grd_Bottom.Left =0 ;
			}
			else
			{
				grd_Bottom.Left =spt_V.Left +spt_V.Width ;
			}
			grd_Bottom.Width =this.Width -this.grd_Bottom.Left-6  ;
			ShowResizeH();
		}
		private void  ShowResizeH()
		{
			if (grd_Top.Visible ==false){grd_Top.Width =0;spt_H.Visible =false;}
			if (spt_H.Visible ==false){spt_H.Height=0 ;spt_H.Top=0;}
			if (grd_Top.Visible ==false)
			{
			this.grd_Bottom.Top  =0   ;
			}
			else
			{
				this.grd_Bottom.Top  =this.spt_H.Top+this.spt_H.Height   ;
			}
			this.grd_Bottom.Height =this.tv_Tree.Height-(this.spt_H.Top+this.spt_H.Height);//-this.grd_Bottom.Top;
		}
		private void spt_V_SplitterMoved(object sender, System.Windows.Forms.SplitterEventArgs e)
		{
			ShowResize();
		}

		private void frmInfSetup_Resize(object sender, System.EventArgs e)
		{
			ShowResize();
			ShowResizeH();
		}

	
		protected virtual void tbr_Toolbar_ButtonClick(object sender, System.Windows.Forms.ToolBarButtonClickEventArgs 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();
					break;
				case "退出":
					this.Close();
					break;

				default:
 
					break;
			}
		}

		private void spt_H_SplitterMoved(object sender, System.Windows.Forms.SplitterEventArgs e)
		{
			ShowResizeH();
		}















	}
}
