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

namespace JXC_MIS.UserTier.ToolForm
{
	/// <summary>
	/// frmReceiptSetup 的摘要说明。
	/// </summary>
	public class frmReceiptSetup : System.Windows.Forms.Form
	{
//		ClsAccess AdoAccess=new ClsAccess();
		ClsDataBaseAccess AdoAccess=new ClsDataBaseAccess();
		private MyFlexGrid grd_Edit;
		private System.Windows.Forms.ImageList img_ImageList;
		private System.Windows.Forms.ToolBar tbr_Toolbar;
		private System.Windows.Forms.ToolBarButton t_new;
		private System.Windows.Forms.ToolBarButton t_Modify;
		private System.Windows.Forms.ToolBarButton t_Save;
		private System.Windows.Forms.ToolBarButton t_Cancel;
		private System.Windows.Forms.ToolBarButton t_S3;
		private System.Windows.Forms.ToolBarButton t_Preview;
		private System.Windows.Forms.ToolBarButton t_Print;
		private System.Windows.Forms.ToolBarButton T_S1;
		private System.Windows.Forms.ToolBarButton t_Refresh;
		private System.Windows.Forms.ToolBarButton t_Find;
		private System.Windows.Forms.ToolBarButton t_First;
		private System.Windows.Forms.ToolBarButton t_Up;
		private System.Windows.Forms.ToolBarButton t_Down;
		private System.Windows.Forms.ToolBarButton t_Last;
		private System.Windows.Forms.ToolBarButton t_S2;
		private System.Windows.Forms.ToolBarButton t_Exit;
		private System.Windows.Forms.StatusBar sbr_StatusBar;
		private System.Windows.Forms.TreeView tv_Tree;
		private System.Windows.Forms.Splitter spt_splitter;
		private System.Windows.Forms.Panel pnl_Border;
		private System.Windows.Forms.ToolBarButton t_Copy;
		private System.ComponentModel.IContainer components;
		private string 	strHeadFormat = "级别(0,1,2,3,4)|编号首字符|设置编号(N0...)|单据名称|标  题|副标题|文件号|明细宽高(像素)|字体大小|页顶属性|页顶列宽(像素)|页头属性|页头列宽(像素)|明细标题1|明细标题2[可选]|明细列属性|明细列求合计|页脚属性|页脚列宽(像素)|页底属性|页底列宽(像素)|页底其他属性|页底其他列宽(像素)|表与表关联主键|主表名称|主表保存字段|明细表名称|明细表保存字段|主显示视图|明细显示视图|查询过滤字段(描述;字段名;类型)|浏览过滤条件|隐含属性|主表隐含字段|其他表关联主键|其他表名|其他表字段";
//		private string  strFeildsName = "fstrClass,fstrFirstChar,fstrReceiptNo,fstrReceiptName, fstrReceiptTitle, fstrReceiptTitle2, fstrFileNo,"
//										+ "fstrReceiptSize, fstrFontSize, fstrTopTitle, fstrTopColWidth,"
//										+ "fstrHeaderTitle, fstrHeaderColWidth, fstrCaptionTitle1, fstrCaptionTitle2, fstrDetailTitle,"
//										+ "fstrDetailColWidth, fstrFooterTitle, fstrFooterColWidth, fstrBottomTitle, fstrBottomColWidth,"
//										+ "fstrOtherTitle, fstrOtherColWidth, fstrKeyFieldName, fstrMasterTable, fstrMasterFields, fstrDetailTable, fstrDetailFields,fstrOtherKeyFieldName, fstrOtherTable, fstrOtherFields, fstrViewKeyFieldName, fstrMasterView, fstrMasterViewFields, fstrDetailView, fstrDetailViewFields";
		private string  strFeildsName = "fcClass,fcFirstChar,fcReceiptNo,fcReceiptName, fcReceiptTitle, fcReceiptTitle2, fcFileNo,"
			+ "fcReceiptSize, fcFontSize, fcTopTitle, fcTopColWidth,"
			+ "fcHeaderTitle, fcHeaderColWidth, fcCaptionTitle1, fcCaptionTitle2, fcDetailTitle,"
			+ "fcDetailColSumNo, fcFooterTitle, fcFooterColWidth, fcBottomTitle, fcBottomColWidth,"
			+ "fcOtherTitle, fcOtherColWidth, fcKeyFieldName, fcMasterTable, fcMasterFields, fcDetailTable, fcDetailFields, fcMasterViewFields, fcDetailViewFields,fcFilterField, fcBrowseFilter,fcHideFiledsDetail,fcHideFiledsMaster,fcOtherKeyFieldName, fcOtherTable, fcOtherFields";

//fstrClass, fstrReceiptNo, fstrReceiptName, fstrReceiptTitle, fstrReceiptTitle2, fstrFileNo, fstrReceiptSize, fstrFontSize, fstrReceiptWidth, fstrReceiptHeight, fstrTopTitle, fstrTopColWidth, fstrHeaderTitle, fstrHeaderColWidth, fstrCaptionTitle1, fstrCaptionTitle2, fstrDetailTitle, fstrDetailColWidth, fstrFooterTitle, fstrFooterColWidth, fstrBottomTitle, fstrBottomColWidth, fstrOtherTitle, fstrOtherColWidth, fdblPrintWidth, fdblPrintHeight, fstrKeyFieldName, fstrMasterTable, fstrMasterFields, fstrDetailTable, fstrDetailFields, fstrOtherTable, fstrOtherFields, fstrViewKeyFieldName, fstrMasterView, fstrMasterViewFields, fstrDetailView, fstrDetailViewFields


//		private string strFeildsName;
		private string strTableKey="fcReceiptName";
		private string strTableKeyValue="";
		private string strTableName="S_ReceiptSetup";
		private System.Windows.Forms.ComboBox cbo_Class;
		private System.Windows.Forms.ToolBarButton t_DataFields;
		private System.Windows.Forms.ToolBarButton t_Setup;
		private System.Windows.Forms.ToolBarButton t_S4;
		private System.Windows.Forms.ToolBarButton t_TempNote;
		private System.Windows.Forms.ToolBarButton t_Delete;
		private bool blnEditFlag=true;//true 添加状态 false:修改状态
		public frmReceiptSetup()
		{
			//
			// Windows 窗体设计器支持所必需的
			//
			InitializeComponent();

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

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

		}

		#region Windows 窗体设计器生成的代码
		/// <summary>
		/// 设计器支持所需的方法 - 不要使用代码编辑器修改
		/// 此方法的内容。
		/// </summary>
		private void InitializeComponent()
		{
			this.components = new System.ComponentModel.Container();
			System.Resources.ResourceManager resources = new System.Resources.ResourceManager(typeof(frmReceiptSetup));
			this.grd_Edit = new ljs.MyFlexGrid();
			this.img_ImageList = new System.Windows.Forms.ImageList(this.components);
			this.tbr_Toolbar = new System.Windows.Forms.ToolBar();
			this.t_Copy = new System.Windows.Forms.ToolBarButton();
			this.t_new = new System.Windows.Forms.ToolBarButton();
			this.t_Modify = new System.Windows.Forms.ToolBarButton();
			this.t_Save = new System.Windows.Forms.ToolBarButton();
			this.t_Cancel = new System.Windows.Forms.ToolBarButton();
			this.t_Delete = new System.Windows.Forms.ToolBarButton();
			this.t_S3 = 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.t_First = new System.Windows.Forms.ToolBarButton();
			this.t_Up = new System.Windows.Forms.ToolBarButton();
			this.t_Down = new System.Windows.Forms.ToolBarButton();
			this.t_Last = new System.Windows.Forms.ToolBarButton();
			this.t_S2 = new System.Windows.Forms.ToolBarButton();
			this.t_DataFields = new System.Windows.Forms.ToolBarButton();
			this.t_Setup = new System.Windows.Forms.ToolBarButton();
			this.t_TempNote = new System.Windows.Forms.ToolBarButton();
			this.t_S4 = new System.Windows.Forms.ToolBarButton();
			this.t_Exit = new System.Windows.Forms.ToolBarButton();
			this.sbr_StatusBar = new System.Windows.Forms.StatusBar();
			this.pnl_Border = new System.Windows.Forms.Panel();
			this.spt_splitter = new System.Windows.Forms.Splitter();
			this.tv_Tree = new System.Windows.Forms.TreeView();
			this.cbo_Class = new System.Windows.Forms.ComboBox();
			this.pnl_Border.SuspendLayout();
			this.SuspendLayout();
			// 
			// grd_Edit
			// 
			this.grd_Edit.Anchor = System.Windows.Forms.AnchorStyles.None;
			this.grd_Edit.BackColor = System.Drawing.Color.White;
			this.grd_Edit.BorderStyle = false;
			this.grd_Edit.CellBackColor = System.Drawing.Color.White;
			this.grd_Edit.CellColLength = 0;
			this.grd_Edit.CellForeColor = System.Drawing.Color.Black;
			this.grd_Edit.CellMultiLine = false;
			this.grd_Edit.CellRowLength = 0;
			this.grd_Edit.CellTag = null;
			this.grd_Edit.Col = 0;
			this.grd_Edit.ColCommanFormat = null;
			this.grd_Edit.Cols = 2;
			this.grd_Edit.DetailFormat = null;
			this.grd_Edit.EnterToTab = true;
			this.grd_Edit.FixedBackColor = System.Drawing.Color.FromArgb(((System.Byte)(224)), ((System.Byte)(224)), ((System.Byte)(224)));
			this.grd_Edit.FixedCols = 1;
			this.grd_Edit.FormatString = null;
			this.grd_Edit.FormatString1 = null;
			this.grd_Edit.GridStyle = true;
			this.grd_Edit.Location = new System.Drawing.Point(152, 10);
			this.grd_Edit.MultiHead = false;
			this.grd_Edit.Name = "grd_Edit";
			this.grd_Edit.Row = 0;
			this.grd_Edit.Rows = 2;
			this.grd_Edit.SetCellWidth = null;
			this.grd_Edit.Size = new System.Drawing.Size(608, 520);
			this.grd_Edit.TabIndex = 0;
			this.grd_Edit.Row_DoubleClick += new ljs.FlexGridRow_DoubleClick(this.grd_Edit_Row_DoubleClick);
			this.grd_Edit.Load += new System.EventHandler(this.grd_Edit_Load);
			this.grd_Edit.Cell_DoubleClick += new ljs.FlexGridCell_DoubleClick(this.grd_Edit_Cell_DoubleClick);
			// 
			// 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;
			// 
			// tbr_Toolbar
			// 
			this.tbr_Toolbar.Appearance = System.Windows.Forms.ToolBarAppearance.Flat;
			this.tbr_Toolbar.Buttons.AddRange(new System.Windows.Forms.ToolBarButton[] {
																						   this.t_Copy,
																						   this.t_new,
																						   this.t_Modify,
																						   this.t_Save,
																						   this.t_Cancel,
																						   this.t_Delete,
																						   this.t_S3,
																						   this.t_Preview,
																						   this.t_Print,
																						   this.T_S1,
																						   this.t_Refresh,
																						   this.t_Find,
																						   this.t_First,
																						   this.t_Up,
																						   this.t_Down,
																						   this.t_Last,
																						   this.t_S2,
																						   this.t_DataFields,
																						   this.t_Setup,
																						   this.t_TempNote,
																						   this.t_S4,
																						   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(704, 41);
			this.tbr_Toolbar.TabIndex = 1;
			this.tbr_Toolbar.ButtonClick += new System.Windows.Forms.ToolBarButtonClickEventHandler(this.tbr_Toolbar_ButtonClick);
			this.tbr_Toolbar.MouseDown += new System.Windows.Forms.MouseEventHandler(this.tbr_Toolbar_MouseDown);
			// 
			// t_Copy
			// 
			this.t_Copy.ImageIndex = 3;
			this.t_Copy.Text = "复制";
			// 
			// t_new
			// 
			this.t_new.ImageIndex = 19;
			this.t_new.Text = "新增";
			// 
			// t_Modify
			// 
			this.t_Modify.ImageIndex = 23;
			this.t_Modify.Text = "修改";
			// 
			// t_Save
			// 
			this.t_Save.ImageIndex = 9;
			this.t_Save.Text = "保存";
			// 
			// t_Cancel
			// 
			this.t_Cancel.ImageIndex = 22;
			this.t_Cancel.Text = "放弃";
			// 
			// t_Delete
			// 
			this.t_Delete.ImageIndex = 25;
			this.t_Delete.Text = "删除";
			// 
			// t_S3
			// 
			this.t_S3.Style = System.Windows.Forms.ToolBarButtonStyle.Separator;
			// 
			// t_Preview
			// 
			this.t_Preview.ImageIndex = 15;
			this.t_Preview.Text = "预览";
			// 
			// t_Print
			// 
			this.t_Print.ImageIndex = 10;
			this.t_Print.Text = "打印";
			// 
			// T_S1
			// 
			this.T_S1.Style = System.Windows.Forms.ToolBarButtonStyle.Separator;
			// 
			// t_Refresh
			// 
			this.t_Refresh.ImageIndex = 6;
			this.t_Refresh.Text = "刷新";
			// 
			// t_Find
			// 
			this.t_Find.ImageIndex = 2;
			this.t_Find.Text = "查询";
			this.t_Find.Visible = false;
			// 
			// t_First
			// 
			this.t_First.ImageIndex = 11;
			this.t_First.Text = "首页";
			this.t_First.Visible = false;
			// 
			// t_Up
			// 
			this.t_Up.ImageIndex = 12;
			this.t_Up.Text = "上页";
			this.t_Up.Visible = false;
			// 
			// t_Down
			// 
			this.t_Down.ImageIndex = 13;
			this.t_Down.Text = "下页";
			this.t_Down.Visible = false;
			// 
			// t_Last
			// 
			this.t_Last.ImageIndex = 14;
			this.t_Last.Text = "末页";
			this.t_Last.Visible = false;
			// 
			// t_S2
			// 
			this.t_S2.Style = System.Windows.Forms.ToolBarButtonStyle.Separator;
			// 
			// t_DataFields
			// 
			this.t_DataFields.ImageIndex = 8;
			this.t_DataFields.Text = "字段";
			this.t_DataFields.ToolTipText = "数据表结构";
			// 
			// t_Setup
			// 
			this.t_Setup.ImageIndex = 7;
			this.t_Setup.Text = "设置";
			// 
			// t_TempNote
			// 
			this.t_TempNote.ImageIndex = 18;
			this.t_TempNote.Text = "编辑";
			// 
			// t_S4
			// 
			this.t_S4.Style = System.Windows.Forms.ToolBarButtonStyle.Separator;
			// 
			// t_Exit
			// 
			this.t_Exit.ImageIndex = 16;
			this.t_Exit.Text = "退出";
			// 
			// sbr_StatusBar
			// 
			this.sbr_StatusBar.Location = new System.Drawing.Point(0, 538);
			this.sbr_StatusBar.Name = "sbr_StatusBar";
			this.sbr_StatusBar.ShowPanels = true;
			this.sbr_StatusBar.Size = new System.Drawing.Size(704, 25);
			this.sbr_StatusBar.TabIndex = 4;
			this.sbr_StatusBar.Text = "statusBar1";
			// 
			// pnl_Border
			// 
			this.pnl_Border.Controls.Add(this.spt_splitter);
			this.pnl_Border.Controls.Add(this.tv_Tree);
			this.pnl_Border.Controls.Add(this.grd_Edit);
			this.pnl_Border.Dock = System.Windows.Forms.DockStyle.Fill;
			this.pnl_Border.Location = new System.Drawing.Point(0, 41);
			this.pnl_Border.Name = "pnl_Border";
			this.pnl_Border.Size = new System.Drawing.Size(704, 497);
			this.pnl_Border.TabIndex = 5;
			// 
			// spt_splitter
			// 
			this.spt_splitter.Location = new System.Drawing.Point(146, 0);
			this.spt_splitter.Name = "spt_splitter";
			this.spt_splitter.Size = new System.Drawing.Size(4, 497);
			this.spt_splitter.TabIndex = 4;
			this.spt_splitter.TabStop = false;
			this.spt_splitter.SplitterMoved += new System.Windows.Forms.SplitterEventHandler(this.spt_splitter_SplitterMoved);
			// 
			// tv_Tree
			// 
			this.tv_Tree.AccessibleRole = System.Windows.Forms.AccessibleRole.None;
			this.tv_Tree.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
			this.tv_Tree.Dock = System.Windows.Forms.DockStyle.Left;
			this.tv_Tree.ImageIndex = 4;
			this.tv_Tree.ImageList = this.img_ImageList;
			this.tv_Tree.Location = new System.Drawing.Point(0, 0);
			this.tv_Tree.Name = "tv_Tree";
			this.tv_Tree.Nodes.AddRange(new System.Windows.Forms.TreeNode[] {
																				new System.Windows.Forms.TreeNode("单据界面样式设置", 20, 4, new System.Windows.Forms.TreeNode[] {
																																											 new System.Windows.Forms.TreeNode("采购单"),
																																											 new System.Windows.Forms.TreeNode("销售单"),
																																											 new System.Windows.Forms.TreeNode("销售订单")})});
			this.tv_Tree.SelectedImageIndex = 4;
			this.tv_Tree.Size = new System.Drawing.Size(146, 497);
			this.tv_Tree.TabIndex = 3;
			this.tv_Tree.MouseDown += new System.Windows.Forms.MouseEventHandler(this.tv_Tree_MouseDown);
			this.tv_Tree.Click += new System.EventHandler(this.tv_Tree_Click);
			this.tv_Tree.AfterSelect += new System.Windows.Forms.TreeViewEventHandler(this.tv_Tree_AfterSelect);
			// 
			// cbo_Class
			// 
			this.cbo_Class.Items.AddRange(new object[] {
														   "业务单据界面设置",
														   "基础信息界面设置",
														   "报表查询设置",
														   "审核管理设置"});
			this.cbo_Class.Location = new System.Drawing.Point(528, 12);
			this.cbo_Class.Name = "cbo_Class";
			this.cbo_Class.Size = new System.Drawing.Size(168, 20);
			this.cbo_Class.TabIndex = 7;
			this.cbo_Class.TextChanged += new System.EventHandler(this.cbo_Class_TextChanged);
			this.cbo_Class.SelectedIndexChanged += new System.EventHandler(this.cbo_Class_SelectedIndexChanged);
			this.cbo_Class.SelectionChangeCommitted += new System.EventHandler(this.cbo_Class_SelectionChangeCommitted);
			// 
			// frmReceiptSetup
			// 
			this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
			this.ClientSize = new System.Drawing.Size(704, 563);
			this.Controls.Add(this.cbo_Class);
			this.Controls.Add(this.pnl_Border);
			this.Controls.Add(this.sbr_StatusBar);
			this.Controls.Add(this.tbr_Toolbar);
			this.Name = "frmReceiptSetup";
			this.Text = "单据页面设置";
			this.Resize += new System.EventHandler(this.frmReceiptSetup_Resize);
			this.Closing += new System.ComponentModel.CancelEventHandler(this.frmReceiptSetup_Closing);
			this.Load += new System.EventHandler(this.frmReceiptSetup_Load);
			this.pnl_Border.ResumeLayout(false);
			this.ResumeLayout(false);

		}
		#endregion

		private void frmReceiptSetup_Load(object sender, System.EventArgs e)
		{
			this.grd_Edit.FixedBackColor = System.Drawing.SystemColors.Control;

//         string strHeadFormat = "单据名称|标  题|副标题|文件号|明细宽高(像素)|字体大小|页顶标题|页顶列宽(厘米)|页头标题|页头列宽(厘米)|明细标题1|明细标题2|明细标题|明细列宽(厘米)|页脚标题|页脚列宽(厘米)|页底标题|页底列宽(厘米)|主表名和字段|明细表名和字段|其他表名和字段|表与表关联字段|主视图名和字段|明细视图名和字段|视图与视图关联字段";
			string[] sArr=null;
			sArr=strHeadFormat.Split('|');
			grd_Edit.Cols=4;
            int rs=sArr.Length ;
			grd_Edit.Rows=rs+1;
			grd_Edit.FormatString ="项目|内容|参考样式|说明";
			grd_Edit.FormatString1 ="项目|内容|参考样式|说明";
			grd_Edit.DetailFormat  ="项目|<内容|<参考样式|说明";
			grd_Edit.SetCellWidth="1600,10000,4000,2000"; 
			grd_Edit.SetCellText(1,0,"单据名称");		grd_Edit.SetCellText(1,2,"销售单");
			grd_Edit.SetCellText(2,0,"单据标题");		grd_Edit.SetCellText(2,2,"销售及备货单");
			grd_Edit.SetCellText(3,0,"单据副标题");		grd_Edit.SetCellText(3,2,"北京XX科技有限责任公司（副标题）");
			grd_Edit.SetCellText(4,0,"单据文件号");		grd_Edit.SetCellText(4,2,"文件号:OR/28936489");
		
			grd_Edit.SetCellText(5,0,"单据明细高度");	grd_Edit.SetCellText(5,2,"250");
			grd_Edit.SetCellText(6,0,"字体大小");	grd_Edit.SetCellText(6,2,"750     [对齐方式;是否编辑; 默认值;参照类型;参照数据源;是否保存;是否代码转换{表名,代码字段,名称字段}]");
			
			grd_Edit.SetCellText(7,0,"单据页顶样式");	grd_Edit.SetCellText(7,2,"日期：|<;2004-01-01;T;0;|制单人：|>|单据编号|");
			grd_Edit.SetCellText(8,0,"单据页顶宽度");	grd_Edit.SetCellText(8,2,"50,250,50,150,50,200");
			grd_Edit.SetCellText(9,0,"单据页头样式");	grd_Edit.SetCellText(9,2,"客户代码|>;北京;;1;|^;客户|^|^;地址|$|联系人|>|^;发票||^;税率|");
			grd_Edit.SetCellText(10,0,"单据页头宽度");	grd_Edit.SetCellText(10,2,"70,80,50,250,50,250");
			grd_Edit.SetCellText(11,0,"明细样式");		grd_Edit.SetCellText(11,2,"0序号|1产品代码|2产品名称|3产品型号|4需方型号|5包装形式|6最小包装量|7单位");
			grd_Edit.SetCellText(12,0,"明细宽度");		grd_Edit.SetCellText(12,2,"明细宽度");
			grd_Edit.SetCellText(13,0,"单据页脚样式");	grd_Edit.SetCellText(13,2,"合计大写金额||小写|$|^;部门||业务员|");
			grd_Edit.SetCellText(14,0,"单据页脚宽度");	grd_Edit.SetCellText(14,2,"100,400,100,150");
			grd_Edit.SetCellText(15,0,"单据页底样式");	grd_Edit.SetCellText(15,2,"审核人：|^|库管：|^|财务：|");
			grd_Edit.SetCellText(16,0,"单据页底宽度");	grd_Edit.SetCellText(16,2,"50,250,50,200,50,150");
			grd_Edit.SetCellText(17,0,"主表名称");		grd_Edit.SetCellText(17,2,"R_OutLib");
			grd_Edit.SetCellText(18,0,"主表字段");		grd_Edit.SetCellText(18,2,"主表字段");
			grd_Edit.SetCellText(19,0,"明细表名称");	grd_Edit.SetCellText(19,2,"明细表名称");
			grd_Edit.SetCellText(20,0,"明细表字段");	grd_Edit.SetCellText(20,2,"明细表字段");
			grd_Edit.SetCellText(21,0,"主表明细表关联字段");grd_Edit.SetCellText(21,2,"主表明细表关联字段");
			InitData("单据名称");
          
//			System.Data.DataRow dr =LoadData("单据名称");
		    for (int i=1;i<rs+1;i++)
				 {
					grd_Edit.SetCellText(i,0,sArr[i-1]);
//					grd_Edit.SetRowHeight(i,400);
//					if (dr!=null){grd_Edit.SetCellText(i,1,dr[i].ToString());}
				 }

			ShowResize();
           
			InitTreeData();
			ToolEnabled(false);
			
		}
		private System.Data.DataRow LoadData(string p_WhereValue)
		{
//			strFeildsName = "fstrClass,fstrReceiptNo,fstrReceiptName, fstrReceiptTitle, fstrReceiptTitle2, fstrFileNo,";
//			strFeildsName = strFeildsName + "fstrReceiptSize, fstrFontSize, fstrTopTitle, fstrTopColWidth,";
//			strFeildsName = strFeildsName + "fstrHeaderTitle, fstrHeaderColWidth, fstrCaptionTitle1, fstrCaptionTitle2, fstrDetailTitle,"; 
//			strFeildsName = strFeildsName + "fstrDetailColWidth, fstrFooterTitle, fstrFooterColWidth, fstrBottomTitle, fstrBottomColWidth,"; 
//			strFeildsName = strFeildsName + "fstrOtherTitle, fstrOtherColWidth, fdblPrintWidth, fdblPrintHeight, FstrKeyFieldName, fstrMasterTableAndFields, fstrDetailTableAndFields, fstrOtherTableAndFields, FstrViewKeyFieldName, fstrMasterViewAndFields, fstrDetailViewAndFields";
			string strSQL="Select "+strFeildsName+" From "+strTableName+" Where "+strTableKey+"='"+p_WhereValue+"'";
			System.Data.DataSet dst = new System.Data.DataSet();
			 dst= AdoAccess.GetDataSet(strSQL);
			
			if (dst.Tables[0].Rows.Count==0)
			{
                return null;
			}
			else
			{
				System.Data.DataRow dr = dst.Tables[0].Rows[0];
				return dr;
			}
			//			this.Width = (int) dr["Width"];
			//			this.Height = (int) dr["Height"];
			//			this.Top = (int) dr["Top"];
			//			this.Left = (int) dr["Left"];


		}
		private void InitTreeData()
		{
			ClsInitData nInitData=new ClsInitData();
			ClsDataBase newDb=new ClsDataBase();
			ClsDataBaseAccess newADO=new ClsDataBaseAccess();

			string strSQL="SELECT fcReceiptNo, fcReceiptName, fcClass FROM S_ReceiptSetup ORDER BY fcReceiptNo, fcClass";
			nInitData.InitTreeView (tv_Tree,newDb.GetDataArray(newADO.GetDataSet(strSQL)));
//			TreeNode tn = new TreeNode();
//			tn = tv_Tree.SelectedNode;
//			tn.Expand();

//			string strSQL="Select fcReceiptName,fcClass From "+strTableName;
//			System.Data.DataSet dst = new System.Data.DataSet();
//			dst= AdoAccess.GetDataSet(strSQL);
//			
//			int j=dst.Tables[0].Rows.Count ;
//			System.Data.DataRow dr =null;
//
//			tv_Tree.Nodes.Clear() ;
//			TreeNode tnRoot1 = new TreeNode("业务单据界面设置");
//			tv_Tree.Nodes.Add(tnRoot1);
//			TreeNode tnRoot2 = new TreeNode("基础信息界面设置");
//			tv_Tree.Nodes.Add(tnRoot2);
//			TreeNode tnRoot3 = new TreeNode("报表查询设置");
//			tv_Tree.Nodes.Add(tnRoot3);	
//			TreeNode tnRoot4 = new TreeNode("审核管理设置");
//			tv_Tree.Nodes.Add(tnRoot4);	
//			for (int i = 0 ; i < j  ; i++ )
//			{
//				 dr = dst.Tables[0].Rows[i];
//
//				if (dr[0].ToString() =="" || dr[0]==null)
//				{
//				}
//				else
//				{
//					TreeNode tn = new TreeNode(dr[0].ToString());
//					if (dr[1].ToString()=="1")
//					{
//						tnRoot1.Nodes.Add(tn);
//						tnRoot1.Expand();
//					}
//					if (dr[1].ToString()=="2")
//					{
//						tnRoot2.Nodes.Add(tn);
//						tnRoot2.Expand();
//					}
//					if (dr[1].ToString()=="3")
//					{
//						tnRoot3.Nodes.Add(tn);
//						tnRoot3.Expand();
//					}
//					if (dr[1].ToString()=="4")
//					{
//						tnRoot4.Nodes.Add(tn);
//						tnRoot4.Expand();
//					}
//				}
//			}
		}

		private void  ShowResize()
		{
			this.grd_Edit.Top  =this.tv_Tree.Top  ;
			this.grd_Edit.Height =this.tv_Tree.Height;
			grd_Edit.Left =spt_splitter.Left +spt_splitter.Width ;
			grd_Edit.Width =this.Width -this.grd_Edit.Left-6  ;
		}

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

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

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


		}
		private void LoadDetailSetup()
		{
			frmDetailSetup f=new frmDetailSetup();
			f.FormatString=grd_Edit.GetCellText(grd_Edit.Row,1); 
			//			f.MdiParent = this;

			f.ShowDialog() ;

			grd_Edit.SetCellText(grd_Edit.Row,1,f.FormatString);

		}
		private void grd_Edit_Cell_DoubleClick(object sender, System.EventArgs e)
		{
//			LoadDetailSetup()
		}
		/// <summary>
		/// 记录复制
		/// </summary>
		public void RecordCopy() 
		{
			ToolEnabled(true);
			blnEditFlag=true;
		}
		/// <summary>
		/// 记录新增
		/// </summary>
		public void RecordAdd() 
		{
			blnEditFlag=true;
			ToolEnabled(true);
			int j=grd_Edit.Rows;
			for (int i=0;i<j;i++)
			{
			grd_Edit.SetCellText(i,1,"");
			}

		}
		/// <summary>
		/// 记录保存
		/// </summary>
		public void RecordSave() 
		{
//			string sType;//数据类型
			string[] tempArr=strFeildsName.Split(',');
			int j=tempArr.Length ;
			string sSQL="INSERT INTO "+strTableName +" (";
			string sValue=" VALUES (";
			string sReplace="";    //临时保存插入值，等待替换“'”到 “''”
			AdoAccess.BeginTrans(); 

			//转换成合法的SQL语句
			//INSERT INTO T () VALUES ()
			j=grd_Edit.Rows;
			for (int i=1;i<j;i++)
			{
				sSQL=sSQL+tempArr[i-1]+",";
				sReplace=grd_Edit.GetCellText(i,1).Trim(); //替换 ' 到 ''SQL语句值中不许有限定符号'
				sValue=sValue+"'"+sReplace.Replace("'","''")+"',";
			}
			sSQL=sSQL.Substring(0,sSQL.Length -1)+")";
			sValue=sValue.Substring(0,sValue.Length -1)+")";
			sSQL=sSQL+sValue;
			if (blnEditFlag==false)
			{
			AdoAccess.ExeSql("Delete From "+strTableName+" Where "+strTableKey+"='"+strTableKeyValue+"'");
			}
			if (AdoAccess.ExeSql(sSQL)>=0)
			{
				ToolEnabled(false);
				AdoAccess.Commit();

//				InitTreeData();

			}
			else
			{
				AdoAccess.Rollback();
			}
		}


		/// <summary>
		/// 记录修改
		/// </summary>
		public void RecordModify() 
		{
			ToolEnabled(true);
			blnEditFlag=false;
			strTableKeyValue=grd_Edit.GetCellText(4,1).Trim();
		}
	
		/// <summary>
		/// 记录取消放弃
		/// </summary>
		public void RecordCancel() 
		{
			ToolEnabled(false);
		}

		/// <summary>
		/// 记录删除
		/// </summary>

		public void RecordDelete()
		{
			AdoAccess.ExeSql("Delete From "+strTableName+" Where "+strTableKey+"='"+grd_Edit.GetCellText(4,1).Trim()+"'");
				InitTreeData();
		}

		/// <summary>
		/// 记录刷新
		/// </summary>
		public void RecordRefresh() 
		{
			InitTreeData();

		}
 
		private void tbr_Toolbar_ButtonClick(object sender, System.Windows.Forms.ToolBarButtonClickEventArgs e)
		{
			switch (e.Button.Text)
			{
				case "复制":
					RecordCopy();
					break;
				case "新增":
					RecordAdd();
					break;
				case "修改":
					RecordModify();
					break;
				case "保存":
					RecordSave();
					break;
				case "放弃":
					RecordCancel();
					break;
				case "删除":
					RecordDelete();
					break;
				case "预览":
//					RecordPreview();
					break;
				case "打印":
//					RecordPrint();
					break;
				case "刷新":
					RecordRefresh();
					break;
				case "编辑":
					frmTempNote fe=new frmTempNote();
					fe.NoteText =grd_Edit.GetCellText(grd_Edit.Row,grd_Edit.Col);
					fe.ShowDialog() ;
					grd_Edit.SetCellText(grd_Edit.Row,grd_Edit.Col,fe.NoteText) ;
					break;
//				case "首页":
//					FirstPage();
//					break;
//				case "上页":
//					UpPage();
//					break;
//				case "下页":
//					DownPage();
//					break;
//				case "末页":
//					LastPage();
//					break;
				case "字段":
					frmDataTable f=new frmDataTable();
					f.Show() ;
					break;
				case "设置":
					LoadDetailSetup();
					break;

				case "退出":
					this.Close();
					break;

				default:
 
					break;
			}
		}
		/// <summary>
		/// 功能： 判断工具条项目是否可用 
		/// </summary>
		public void ToolEnabled(bool YesNo)
		{
			try
			{
				this.t_Copy.Enabled =! YesNo;
				this.t_new.Enabled =! YesNo;
				this.t_Modify.Enabled =! YesNo;
				this.t_Save.Enabled = YesNo;
				this.t_Cancel.Enabled = YesNo;
				this.t_Preview.Enabled =! YesNo;
				this.t_Print.Enabled =! YesNo;
//				this.t_R\efresh.Enabled =! YesNo;
				this.t_Delete.Enabled =! YesNo;
//				this.t_First.Enabled =! YesNo;
//				this.t_Up.Enabled =! YesNo;
//				this.t_Down.Enabled =! YesNo;
//				this.t_Last.Enabled =! YesNo;
				this.t_Exit.Enabled =! YesNo;
			}
			catch
			{
			
			}
		}

		private void tv_Tree_Click(object sender, System.EventArgs e)
		{
			TreeNode tn = new TreeNode();

			tn = tv_Tree.SelectedNode;

			if (tn != null)
			{
				InitData(tn.Text);
//				System.Data.DataRow dr =LoadData(tn.Text);
//				if (dr!=null)
//				{
//					for (int i=1;i<grd_Edit.Rows;i++)
//					{
//						grd_Edit.SetCellText(i,1,dr[i].ToString());
//					}
//				}
			}
		}

		private void InitData(string p_Where)
		{
			System.Data.DataRow dr =LoadData(p_Where);
			if (dr!=null)
			{
				for (int i=1;i<grd_Edit.Rows;i++)
				{
					grd_Edit.SetCellText(i,1,dr[i-1].ToString());
					grd_Edit.SetRowHeight(i,400);
				}
					
			}
		}

		private void tv_Tree_MouseDown(object sender, System.Windows.Forms.MouseEventArgs e)
		{
			try
			{
				tv_Tree.SelectedNode = tv_Tree.GetNodeAt(e.X,e.Y);	
				cbo_Class.Text =tv_Tree.SelectedNode.Parent.Text;
			}
			catch
			{
				return;
			}
		}

		private void frmReceiptSetup_Closing(object sender, System.ComponentModel.CancelEventArgs e)
		{
			int h=this.Height  ;
			int t=this.Top  ;
			int w=this.Width/2  ;
			int l=this.Left  ;
			for (int i=0;i<h;i++)
			{
				if (this.Height<20){ return;}
				this.Height=this.Height-20;
			
			}
		}

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

		}

		private void cbo_Class_TextChanged(object sender, System.EventArgs e)
		{
			int si=cbo_Class.SelectedIndex+1;
			grd_Edit.SetCellText(1,1,si.ToString());
		}

		private void cbo_Class_SelectionChangeCommitted(object sender, System.EventArgs e)
		{
			int si=cbo_Class.SelectedIndex+1;
			grd_Edit.SetCellText(1,1,si.ToString());
		}

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

		}

		private void tv_Tree_AfterSelect(object sender, System.Windows.Forms.TreeViewEventArgs e)
		{
		
		}

		private void tbr_Toolbar_MouseDown(object sender, System.Windows.Forms.MouseEventArgs e)
		{
			cbo_Class.Focus();
		}

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











	}
}
