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

namespace JXC_MIS.UserTier.CommonForm
{
	public class frmInitSetup : JXC_MIS.UserTier.BaseForm.frmTreeWindows
	{
		private System.ComponentModel.IContainer components = null;
//		private ClsInitData InitData=new ClsInitData();
//		private ClsDataBase newDb=new ClsDataBase();
		private ClsReceiptAttrib newR_Attrib=new ClsReceiptAttrib();
//		private ClsDataBaseAccess newADO=new ClsDataBaseAccess();
		public frmInitSetup()
		{
			// 该调用是 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.ComponentModel.ISupportInitialize)(this.grd_Bottom)).BeginInit();
			((System.ComponentModel.ISupportInitialize)(this.grd_Top)).BeginInit();
			// 
			// cbo_SetupName
			// 
			this.cbo_SetupName.Name = "cbo_SetupName";
			// 
			// t_Modify
			// 
			this.t_Modify.Visible = true;
			// 
			// 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, 41);
			// 
			// t_new
			// 
			this.t_new.Visible = true;
			// 
			// panel1
			// 
			this.panel1.Name = "panel1";
			this.panel1.Size = new System.Drawing.Size(714, 345);
			// 
			// spt_H
			// 
			this.spt_H.Location = new System.Drawing.Point(146, 3);
			this.spt_H.Name = "spt_H";
			this.spt_H.Size = new System.Drawing.Size(568, 8);
			// 
			// grd_Bottom
			// 
			this.grd_Bottom.Location = new System.Drawing.Point(146, 11);
			this.grd_Bottom.Name = "grd_Bottom";
			this.grd_Bottom.Size = new System.Drawing.Size(570, 334);
			// 
			// grd_Top
			// 
			this.grd_Top.Location = new System.Drawing.Point(146, 0);
			this.grd_Top.Name = "grd_Top";
			this.grd_Top.Size = new System.Drawing.Size(568, 3);
			this.grd_Top.Visible = false;
			// 
			// 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(6, 345);
			// 
			// tv_Tree
			// 
			this.tv_Tree.Name = "tv_Tree";
			this.tv_Tree.Size = new System.Drawing.Size(140, 345);
			// 
			// 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";
			// 
			// frmInitSetup
			// 
			this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
			this.ClientSize = new System.Drawing.Size(714, 411);
			this.Name = "frmInitSetup";
			this.Load += new System.EventHandler(this.frmInitSetup_Load);
			((System.ComponentModel.ISupportInitialize)(this.grd_Bottom)).EndInit();
			((System.ComponentModel.ISupportInitialize)(this.grd_Top)).EndInit();

		}
		#endregion

		private void frmInitSetup_Load(object sender, System.EventArgs e)
		{
			this.grd_Top.Visible =false;
			this.InitTreeData("Select fcReceiptName From S_receiptSetup where left(fcReceiptNo,3)='N02' and fcClass='1'");
		}
		protected override void InitTreeData(string p_TreeDataSource)
		{
			if (p_TreeDataSource!=null && p_TreeDataSource!="")
			{
				InitData.InitTreeView (tv_Tree,p_TreeDataSource,"初始信息设置");
			}

		}
		protected override 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 ;
                grd_Bottom.CaptionText =tn.Text ;
				LoadData(tn.Text);
			}
		}
		protected  void LoadData(string p_Where)
		{
			string strSQL="";
			newR_Attrib.LoadData(p_Where); 
			strSQL=newR_Attrib.MasterViewFeildName ;

			if (strSQL!="" && strSQL!=null)
			{
				System.Data.DataSet dst = new System.Data.DataSet();
				dst= newADO.GetDataSet(strSQL);
				grd_Bottom.DataSource=dst.Tables[0] ;
				
				
			}

		}
		protected override void tbr_Toolbar_ButtonClick(object sender, ToolBarButtonClickEventArgs e)
		{

						frmInput f=new frmInput();
				switch (e.Button.Tag.ToString() )
				{
					case "新增":
						//					f.MdiParent = this;
						f.RecordName=this.cbo_SetupName.Text ;
						f.Show() ;
						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); 
			}



		private void button1_Click(object sender, System.EventArgs e)
		{
		
		}
////		public System.Data.SqlClient.SqlDataAdapter GetDataAdapter(string strSQL)
////
////		{
////			//define Err info...
////			string strErrInfo="";
////
////			//define commmad object for Exeute SQL...
////			System.Data.SqlClient.SqlCommand SqlCmd=new System.Data.SqlClient.SqlCommand();
////
////			//define DataAdapter object for fill dataset...
////			System.Data.SqlClient.SqlDataAdapter SqlDtAdpt = new System.Data.SqlClient.SqlDataAdapter();
////
////
////			//Err.Clear()
////
////			//检查第二参数是否为数据库连接对象
////			if (Connection.GetType().ToString()!="System.Data.SqlClient.SqlConnection" && Connection.GetType().ToString()!="System.Data.OleDb.OleDbConnection")				 
////				throw new System.Exception("方法ExecuteSql(string,object)第二参数\n必须是类型为System.Data.SqlClient.SqlConnection或者\nSystem.Data.OleDb.OleDbConnection的数据库连接对象。");
////
////			try
////			{
////				if (Connection.GetType().ToString()  ==  "System.Data.SqlClient.SqlConnection")
////				{
////					SqlDtAdpt.SelectCommand = SqlCmd;
////					SqlCmd.Connection = (System.Data.SqlClient.SqlConnection)Connection;
////						
////					if (SqlCmd.Connection.State!=System.Data.ConnectionState.Open)
////						return null;
////
////					SqlCmd.CommandText = strSQL;
////					SqlCmd.CommandType = commandType;
////					
////					//填充数据集
////					SqlDtAdpt.Fill(dst);
////				}
////
////			}
////
////			catch(System.Exception ex)
////			{			                
////				strErrInfo="错误提示：获取数据信息失败！" + "\n" + ex.Message;
////			}	
////
////			finally
////			{
////				if (strErrInfo!="")
////					System.Windows.Forms.MessageBox.Show(strErrInfo,"提示",System.Windows.Forms.MessageBoxButtons.OK,System.Windows.Forms.MessageBoxIcon.Warning);
////
////				//释放资源，返回
////				SqlCmd = null;
////				SqlDtAdpt = null;
////			}
////			return SqlDtAdpt;
////
////		}









	}
}

