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

namespace JXC_MIS.UserTier.CommonForm
{
	/// <summary>
	/// frmLookList 的摘要说明。
	/// </summary>
	public class frmLookList : System.Windows.Forms.Form
	{
		private System.ComponentModel.IContainer components;
		private string m_Title;
//		private string m_DataSource;
		private System.Windows.Forms.ListView lv_List;
		private System.Windows.Forms.ColumnHeader columnHeader5;
		private System.Windows.Forms.ColumnHeader columnHeader6;
		private System.Windows.Forms.ColumnHeader columnHeader7;
		private System.Windows.Forms.DataGrid grd_List;
		private string m_SQLSource;
		private System.Windows.Forms.ContextMenu MenuTool;
		private System.Windows.Forms.MenuItem menuItem1;
		private System.Windows.Forms.MenuItem menuItem2;
		private System.Windows.Forms.MenuItem menuItem3;
		private System.Windows.Forms.MenuItem menuItem4;
		private System.Windows.Forms.StatusBar sbr_1;
		private System.Windows.Forms.ToolBar tbr_Tool;
		private System.Windows.Forms.ToolBarButton t_Preview;
		private System.Windows.Forms.ToolBarButton t_Print;
		private System.Windows.Forms.ToolBarButton t_Output;
		private System.Windows.Forms.ToolBarButton t_Filter;
		private System.Windows.Forms.ToolBarButton t_Quit;
		private System.Windows.Forms.ImageList img_ImageList;
		private string m_ShowListType="1";  //DataGrid=1 或 listView=2
		/// <summary>
		/// 设置显示数据的列表是 DataGrid=1 或 listView=2
		/// </summary>
		
		public string SetShowListType
		{ 
			set { m_ShowListType=value;} 
		} 
		/// <summary>
		/// 设置标题
		/// </summary>
		
		public string Title
		{ 
			set { m_Title=value;} 
		} 
	
		/// <summary>
		/// 设置下拉列表数据源
		/// </summary>
		public string SetSQLSource
		{ 
			set { m_SQLSource=value;} 
		} 
		public frmLookList()
		{
			//
			// 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(frmLookList));
			this.lv_List = new System.Windows.Forms.ListView();
			this.columnHeader5 = new System.Windows.Forms.ColumnHeader();
			this.columnHeader6 = new System.Windows.Forms.ColumnHeader();
			this.columnHeader7 = new System.Windows.Forms.ColumnHeader();
			this.grd_List = new System.Windows.Forms.DataGrid();
			this.MenuTool = new System.Windows.Forms.ContextMenu();
			this.menuItem1 = new System.Windows.Forms.MenuItem();
			this.menuItem2 = new System.Windows.Forms.MenuItem();
			this.menuItem3 = new System.Windows.Forms.MenuItem();
			this.menuItem4 = new System.Windows.Forms.MenuItem();
			this.sbr_1 = new System.Windows.Forms.StatusBar();
			this.tbr_Tool = new System.Windows.Forms.ToolBar();
			this.t_Preview = new System.Windows.Forms.ToolBarButton();
			this.t_Print = new System.Windows.Forms.ToolBarButton();
			this.t_Output = new System.Windows.Forms.ToolBarButton();
			this.t_Filter = new System.Windows.Forms.ToolBarButton();
			this.t_Quit = new System.Windows.Forms.ToolBarButton();
			this.img_ImageList = new System.Windows.Forms.ImageList(this.components);
			((System.ComponentModel.ISupportInitialize)(this.grd_List)).BeginInit();
			this.SuspendLayout();
			// 
			// lv_List
			// 
			this.lv_List.AllowColumnReorder = true;
			this.lv_List.AutoArrange = false;
			this.lv_List.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
			this.lv_List.Columns.AddRange(new System.Windows.Forms.ColumnHeader[] {
																					  this.columnHeader5,
																					  this.columnHeader6,
																					  this.columnHeader7});
			this.lv_List.ContextMenu = this.MenuTool;
			this.lv_List.Dock = System.Windows.Forms.DockStyle.Fill;
			this.lv_List.FullRowSelect = true;
			this.lv_List.GridLines = true;
			this.lv_List.HoverSelection = true;
			this.lv_List.LabelEdit = true;
			this.lv_List.Location = new System.Drawing.Point(0, 28);
			this.lv_List.Name = "lv_List";
			this.lv_List.Size = new System.Drawing.Size(554, 243);
			this.lv_List.TabIndex = 5;
			this.lv_List.View = System.Windows.Forms.View.Details;
			this.lv_List.ColumnClick += new System.Windows.Forms.ColumnClickEventHandler(this.lv_List_ColumnClick);
			this.lv_List.SelectedIndexChanged += new System.EventHandler(this.lv_List_SelectedIndexChanged);
			// 
			// columnHeader5
			// 
			this.columnHeader5.Text = "列1";
			// 
			// columnHeader6
			// 
			this.columnHeader6.Text = "列2";
			this.columnHeader6.Width = 92;
			// 
			// columnHeader7
			// 
			this.columnHeader7.Text = "列3";
			// 
			// grd_List
			// 
			this.grd_List.BackgroundColor = System.Drawing.SystemColors.ActiveCaptionText;
			this.grd_List.CaptionBackColor = System.Drawing.SystemColors.ActiveBorder;
			this.grd_List.CaptionVisible = false;
			this.grd_List.ContextMenu = this.MenuTool;
			this.grd_List.DataMember = "";
			this.grd_List.Dock = System.Windows.Forms.DockStyle.Fill;
			this.grd_List.HeaderForeColor = System.Drawing.SystemColors.ControlText;
			this.grd_List.Location = new System.Drawing.Point(0, 28);
			this.grd_List.Name = "grd_List";
			this.grd_List.Size = new System.Drawing.Size(554, 243);
			this.grd_List.TabIndex = 6;
			// 
			// MenuTool
			// 
			this.MenuTool.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
																					 this.menuItem1,
																					 this.menuItem2,
																					 this.menuItem3,
																					 this.menuItem4});
			// 
			// menuItem1
			// 
			this.menuItem1.Index = 0;
			this.menuItem1.Text = "预览";
			// 
			// menuItem2
			// 
			this.menuItem2.Index = 1;
			this.menuItem2.Text = "打印";
			// 
			// menuItem3
			// 
			this.menuItem3.Index = 2;
			this.menuItem3.Text = "导出";
			// 
			// menuItem4
			// 
			this.menuItem4.Index = 3;
			this.menuItem4.Text = "查询";
			// 
			// sbr_1
			// 
			this.sbr_1.Location = new System.Drawing.Point(0, 271);
			this.sbr_1.Name = "sbr_1";
			this.sbr_1.ShowPanels = true;
			this.sbr_1.Size = new System.Drawing.Size(554, 22);
			this.sbr_1.TabIndex = 8;
			this.sbr_1.Text = "statusBar1";
			// 
			// tbr_Tool
			// 
			this.tbr_Tool.AccessibleRole = System.Windows.Forms.AccessibleRole.None;
			this.tbr_Tool.Appearance = System.Windows.Forms.ToolBarAppearance.Flat;
			this.tbr_Tool.Buttons.AddRange(new System.Windows.Forms.ToolBarButton[] {
																						this.t_Preview,
																						this.t_Print,
																						this.t_Output,
																						this.t_Filter,
																						this.t_Quit});
			this.tbr_Tool.ButtonSize = new System.Drawing.Size(80, 22);
			this.tbr_Tool.DropDownArrows = true;
			this.tbr_Tool.ImageList = this.img_ImageList;
			this.tbr_Tool.Location = new System.Drawing.Point(0, 0);
			this.tbr_Tool.Name = "tbr_Tool";
			this.tbr_Tool.ShowToolTips = true;
			this.tbr_Tool.Size = new System.Drawing.Size(554, 28);
			this.tbr_Tool.TabIndex = 9;
			// 
			// t_Preview
			// 
			this.t_Preview.ImageIndex = 14;
			this.t_Preview.Tag = "导航";
			// 
			// t_Print
			// 
			this.t_Print.ImageIndex = 9;
			this.t_Print.Tag = "重新登录";
			// 
			// t_Output
			// 
			this.t_Output.ImageIndex = 31;
			this.t_Output.Tag = "计算器";
			// 
			// t_Filter
			// 
			this.t_Filter.ImageIndex = 7;
			this.t_Filter.Style = System.Windows.Forms.ToolBarButtonStyle.ToggleButton;
			this.t_Filter.Tag = "换背景";
			// 
			// t_Quit
			// 
			this.t_Quit.ImageIndex = 16;
			this.t_Quit.Tag = "退出";
			// 
			// 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;
			// 
			// frmLookList
			// 
			this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
			this.ClientSize = new System.Drawing.Size(554, 293);
			this.Controls.Add(this.lv_List);
			this.Controls.Add(this.grd_List);
			this.Controls.Add(this.tbr_Tool);
			this.Controls.Add(this.sbr_1);
			this.Name = "frmLookList";
			this.Text = "frmLookList";
			this.Load += new System.EventHandler(this.frmLookList_Load);
			((System.ComponentModel.ISupportInitialize)(this.grd_List)).EndInit();
			this.ResumeLayout(false);

		}
		#endregion

		private void frmLookList_Load(object sender, System.EventArgs e)
		{
			try
			{
				this.Text=m_Title;
				if (m_ShowListType=="1")
				{
					grd_List.Visible =true;
					lv_List.Visible =false;
				}
				else
				{
					grd_List.Visible =false;
					lv_List.Visible =true;

				}

				if (m_SQLSource!=null && m_SQLSource!="")
				{
					ClsDataBaseAccess AdoDB=new ClsDataBaseAccess();
					ClsDataBase newDb=new ClsDataBase();
					if (grd_List.Visible ==true)
					{
						System.Data.DataSet dst = new System.Data.DataSet();
						dst= AdoDB.GetDataSet(m_SQLSource);
						grd_List.DataSource=dst.Tables[0] ;
					}
					else
					{
						ClsInitData InitData=new ClsInitData();
						InitData.InitListView (lv_List,newDb.GetDataArray(m_SQLSource,1));
					}
				}
			}
			catch
			{
			
			}
		}

		private void lv_List_ColumnClick(object sender, System.Windows.Forms.ColumnClickEventArgs e)
		{
			this.lv_List.ListViewItemSorter = new ListViewItemComparer(e.Column);
			
			lv_List.Sort();

		}

		private void lv_List_SelectedIndexChanged(object sender, System.EventArgs e)
		{
		
		}
	}
	// Implements the manual sorting of items by columns.
	class ListViewItemComparer : IComparer 
	{
		private int col;
		public ListViewItemComparer() 
		{
			col=0;
		}
		public ListViewItemComparer(int column) 
		{
			col=column;
		}
		public int Compare(object x, object y) 
		{
			return String.Compare(((ListViewItem)x).SubItems[col].Text, ((ListViewItem)y).SubItems[col].Text);
		}
	}

}
