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

namespace JXC_MIS.UserTier.CommonForm
{
	/// <summary>
	/// frmColWidthSetup 的摘要说明。
	/// </summary>
	public class frmColWidthSetup : System.Windows.Forms.Form
	{
		private ljs.MyFlexGrid grd_ColList;

		/// <summary>
		/// 必需的设计器变量。
		/// </summary>
		private System.ComponentModel.Container components = null;

		private ljs.MyFlexGrid m_GridSource;
		private System.Windows.Forms.Button cmd_Cancel;
		private System.Windows.Forms.Button cmd_OK;
		private string m_ReceiptName;
		private System.Windows.Forms.ContextMenu contextMenu1;
		ClsAccess AdoAccess=new ClsAccess();
		/// <summary>
		/// 设置网格源
		/// </summary>
		public MyFlexGrid GridSource
		{ 
			get {return m_GridSource;} 
			set { m_GridSource=value;} 
		} 
		/// <summary>
		/// 设置单据名称
		/// </summary>
		public string ReceiptName
		{ 
			get {return m_ReceiptName;} 
			set { m_ReceiptName=value;} 
		} 

		public frmColWidthSetup()
		{
			//
			// 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.grd_ColList = new ljs.MyFlexGrid();
			this.cmd_Cancel = new System.Windows.Forms.Button();
			this.cmd_OK = new System.Windows.Forms.Button();
			this.contextMenu1 = new System.Windows.Forms.ContextMenu();
			this.SuspendLayout();
			// 
			// grd_ColList
			// 
			this.grd_ColList.BackColor = System.Drawing.Color.White;
			this.grd_ColList.BorderStyle = false;
			this.grd_ColList.CellBackColor = System.Drawing.Color.White;
			this.grd_ColList.CellColLength = 0;
			this.grd_ColList.CellForeColor = System.Drawing.Color.Black;
			this.grd_ColList.CellMultiLine = false;
			this.grd_ColList.CellRowLength = 0;
			this.grd_ColList.CellTag = null;
			this.grd_ColList.Col = 0;
			this.grd_ColList.ColCommanFormat = null;
			this.grd_ColList.Cols = 2;
			this.grd_ColList.ColSel = 1;
			this.grd_ColList.DetailFormat = null;
			this.grd_ColList.EnterToTab = true;
			this.grd_ColList.FixedBackColor = System.Drawing.SystemColors.ActiveBorder;
			this.grd_ColList.FixedCols = 1;
			this.grd_ColList.FormatString = null;
			this.grd_ColList.FormatString1 = null;
			this.grd_ColList.GridStyle = true;
			this.grd_ColList.Location = new System.Drawing.Point(0, 0);
			this.grd_ColList.MultiHead = false;
			this.grd_ColList.Name = "grd_ColList";
			this.grd_ColList.Row = 0;
			this.grd_ColList.Rows = 2;
			this.grd_ColList.RowSel = 0;
			this.grd_ColList.SetCellWidth = null;
			this.grd_ColList.Size = new System.Drawing.Size(440, 326);
			this.grd_ColList.TabIndex = 0;
			// 
			// cmd_Cancel
			// 
			this.cmd_Cancel.DialogResult = System.Windows.Forms.DialogResult.Cancel;
			this.cmd_Cancel.Location = new System.Drawing.Point(360, 344);
			this.cmd_Cancel.Name = "cmd_Cancel";
			this.cmd_Cancel.Size = new System.Drawing.Size(68, 26);
			this.cmd_Cancel.TabIndex = 49;
			this.cmd_Cancel.Text = "取消";
			this.cmd_Cancel.Click += new System.EventHandler(this.cmd_Cancel_Click);
			// 
			// cmd_OK
			// 
			this.cmd_OK.BackColor = System.Drawing.SystemColors.Control;
			this.cmd_OK.ForeColor = System.Drawing.SystemColors.ControlText;
			this.cmd_OK.Location = new System.Drawing.Point(258, 344);
			this.cmd_OK.Name = "cmd_OK";
			this.cmd_OK.Size = new System.Drawing.Size(72, 26);
			this.cmd_OK.TabIndex = 48;
			this.cmd_OK.Text = "确定";
			this.cmd_OK.Click += new System.EventHandler(this.cmd_OK_Click);
			// 
			// frmColWidthSetup
			// 
			this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
			this.ClientSize = new System.Drawing.Size(440, 381);
			this.Controls.Add(this.cmd_Cancel);
			this.Controls.Add(this.cmd_OK);
			this.Controls.Add(this.grd_ColList);
			this.Name = "frmColWidthSetup";
			this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
			this.Text = "frmColWidthSetup";
			this.Load += new System.EventHandler(this.frmColWidthSetup_Load);
			this.ResumeLayout(false);

		}
		#endregion

		private void frmColWidthSetup_Load(object sender, System.EventArgs e)
		{
			this.grd_ColList.FixedBackColor =System.Drawing.SystemColors.ActiveBorder;

			InitGridColWidth(m_GridSource);

		}



		private void  InitGridColWidth(ljs.MyFlexGrid objGrid)
		{
			string sHeadformat="列序|      列    标     题      |宽度/缇(1厘米=567缇)";
			string sFormat;
			string sFormat1;
			string sColWidth;
			string [] sArr=null ;
			string [] sArr1=null ;
			string [] sArr2=null ;
			grd_ColList.Cols=3;
			grd_ColList.FormatString =sHeadformat;
			grd_ColList.FormatString1 =sHeadformat;
			grd_ColList.DetailFormat  =sHeadformat;
			grd_ColList.SetCellWidth="500,3000,1500"; 
			sFormat=objGrid.FormatString;
			sFormat1=objGrid.FormatString1;
			sColWidth=objGrid.GetColWidth();
			//			sColWidth=objGrid.SetCellWidth;
			sArr=sFormat.Split('|') ;
			sArr1=sFormat1.Split('|') ;
			sArr2=sColWidth.Split(',') ;
			if (sFormat!=null)
			{
				int cs=sArr.Length;
				grd_ColList.Rows=cs+1;
				for (int i = 0;i< cs;i++)
						
				{
					grd_ColList.SetCellText(i+1,0,i.ToString() );

					if (sArr[i] == sArr1[i])
					{
						grd_ColList.SetCellText(i+1,1,sArr[i] );
					}		
					else
					{
						grd_ColList.SetCellText(i+1,1,sArr[i]+ "[" + sArr1[i]+"]" );
					}
					grd_ColList.SetCellText(i+1,2,sArr2[i] );
			
				}
			}

			//						.TextMatrix(i + 1, 3) = Format(objGrid.ColWidth(i) / 567, IIf(objGrid.ColWidth(i) / 567 < 1, "######0.00", "######0"))

		}

		private void cmd_Cancel_Click(object sender, System.EventArgs e)
		{
			this.Close();
		}

		private void cmd_OK_Click(object sender, System.EventArgs e)
		{
			string setcolWidth;
			setcolWidth=GetColWidth();
			m_GridSource.SetCellWidth=setcolWidth;
			ColWidthSave(setcolWidth);
			this.Close();
		}
		/// <summary>
		/// 得到网格当前列宽字符串
		/// </summary>

		private string GetColWidth()
		{
			string setcolWidth;
			int rs=grd_ColList.Rows;
			setcolWidth=grd_ColList.GetCellText(1,2);
			for (int i=2;i<rs;i++)
			{
				setcolWidth=setcolWidth+","+grd_ColList.GetCellText(i,2) ;
			}

			return setcolWidth;
		}

	
		//
		//		'保存列宽设置
		private void ColWidthSave(string p_colWidth)
	{
		string strSQL;
//					strSQL= "Update S_ColWidthSetup Set fcColWidth='" + p_colWidth + "' Where fcMarkName='" & m_ReceiptName + "'";
		     strSQL= "Delete from S_ColWidthSetup  Where fcMarkName='" + m_ReceiptName + "'";
			AdoAccess.ExeSql(strSQL);
			     
			strSQL = "Insert Into S_ColWidthSetup (fcMarkName,fcColWidth)";
			strSQL = strSQL + " Values ('" + m_ReceiptName + "','" + p_colWidth + "')";
		
		
			
			if (AdoAccess.ExeSql(strSQL)>=0)
			{

			}

		}
		//		Dim i As Long
		//				  Dim strSQL As String
		//								 Dim strDetailColWidth As String
		//														   If strReceiptID = "" Then Exit Sub
		//																							  ''     '删除原始记录
		//		''   ExeSQLTempData "Delete From sysAccountDesign Where flngAccountType=" & lngReceiptID & ""
		//		''     '重新保存设置
		//		''  For i = 0 To objGrid.Cols - 1
		//		''        strSql = "Insert Into sysAccountDesign (flngAccountType,flngCol,flngColWidth,fblnprint)"
		//		''        strSql = strSql & " Values (" & lngReceiptID & "," & i & "," & IIf(objGrid.ColWidth(i) <= 0, 0, objGrid.ColWidth(i)) & ",1)"
		//		''   ExeSQLTempData strSql
		//				 ''  Next
		//						 ''
		//		strDetailColWidth = RTrim(Round(objGrid.ColWidth(0) / 567, 1))
		//		For i = 1 To objGrid.Cols - 1
		//		strDetailColWidth = strDetailColWidth & "|" & RTrim(Round(objGrid.ColWidth(i) / 567, 1))
		//		Next
		//			strSQL = "Update tblReceiptSetup Set fstrDetailColWidth='" & strDetailColWidth & "' Where fstrReceiptName='" & strReceiptID & "'"
		//			ExeSQLTempData strSQL
		//				End Sub
		//
		//
		//







	}
}
